Skip to content

Commit 2128d55

Browse files
azoitlruspl-afed
authored andcommitted
Minor Clean-ups in MarkupEditor suggested by Sonar
1 parent 3fc9532 commit 2128d55

1 file changed

Lines changed: 24 additions & 34 deletions

File tree

  • mylyn.docs/wikitext/ui/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor

mylyn.docs/wikitext/ui/org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/editor/MarkupEditor.java

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2021 David Green and others.
2+
* Copyright (c) 2007, 2026 David Green and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -168,7 +168,7 @@ public class MarkupEditor extends TextEditor implements IShowInTarget, IShowInSo
168168
"org.eclipse.ui.navigator.ProjectExplorer", // 3.5 //$NON-NLS-1$
169169
IPageLayout.ID_OUTLINE };
170170

171-
private static IShowInTargetList SHOW_IN_TARGET_LIST = () -> SHOW_IN_TARGETS;
171+
private static final IShowInTargetList SHOW_IN_TARGET_LIST = () -> SHOW_IN_TARGETS;
172172

173173
private IDocument document;
174174

@@ -313,9 +313,9 @@ public void changing(LocationEvent event) {
313313
}
314314
try {
315315
PlatformUI.getWorkbench()
316-
.getBrowserSupport()
317-
.createBrowser("org.eclipse.ui.browser") //$NON-NLS-1$
318-
.openURL(new URL(event.location));
316+
.getBrowserSupport()
317+
.createBrowser("org.eclipse.ui.browser") //$NON-NLS-1$
318+
.openURL(new URL(event.location));
319319
} catch (Exception e) {
320320
new URLHyperlink(new Region(0, 1), event.location).open();
321321
}
@@ -363,7 +363,7 @@ public void widgetSelected(SelectionEvent selectionevent) {
363363
}
364364
});
365365
viewer.getTextWidget()
366-
.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> updateOutlineSelection()));
366+
.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> updateOutlineSelection()));
367367
viewer.getTextWidget().addKeyListener(new KeyAdapter() {
368368
@Override
369369
public void keyReleased(KeyEvent e) {
@@ -374,16 +374,10 @@ public void keyReleased(KeyEvent e) {
374374

375375
private boolean isRelevantKeyCode(int keyCode) {
376376
// for some reason not all key presses result in a selection change
377-
switch (keyCode) {
378-
case SWT.ARROW_DOWN:
379-
case SWT.ARROW_LEFT:
380-
case SWT.ARROW_RIGHT:
381-
case SWT.ARROW_UP:
382-
case SWT.PAGE_DOWN:
383-
case SWT.PAGE_UP:
384-
return true;
385-
}
386-
return false;
377+
return switch (keyCode) {
378+
case SWT.ARROW_DOWN, SWT.ARROW_LEFT, SWT.ARROW_RIGHT, SWT.ARROW_UP, SWT.PAGE_DOWN, SWT.PAGE_UP -> true;
379+
default -> false;
380+
};
387381
}
388382
});
389383
viewer.getTextWidget().addMouseListener(new MouseAdapter() {
@@ -493,11 +487,8 @@ private void reloadPreferences() {
493487
}
494488

495489
private boolean isFontPreferenceChange(PropertyChangeEvent event) {
496-
if (event.getProperty().equals(sourceViewerConfiguration.getFontPreference())
497-
|| event.getProperty().equals(sourceViewerConfiguration.getMonospaceFontPreference())) {
498-
return true;
499-
}
500-
return false;
490+
return event.getProperty().equals(sourceViewerConfiguration.getFontPreference())
491+
|| event.getProperty().equals(sourceViewerConfiguration.getMonospaceFontPreference());
501492
}
502493

503494
@Override
@@ -603,7 +594,7 @@ public void documentChanged(DocumentEvent event) {
603594
}
604595
document.addDocumentListener(documentListener);
605596
if (documentPartitioningListener == null) {
606-
documentPartitioningListener = document -> scheduleOutlineUpdate();
597+
documentPartitioningListener = doc -> scheduleOutlineUpdate();
607598
}
608599
document.addDocumentPartitioningListener(documentPartitioningListener);
609600
}
@@ -696,7 +687,7 @@ public void beginBlock(BlockType type, Attributes attributes) {
696687
}
697688

698689
String css = WikiTextUiPlugin.getDefault().getPreferences().getMarkupViewerCss();
699-
if (css != null && css.length() > 0) {
690+
if (css != null && !css.isEmpty()) {
700691
builder.addCssStylesheet(new HtmlDocumentBuilder.Stylesheet(new StringReader(css)));
701692
}
702693

@@ -1008,16 +999,15 @@ private void updateProjectionAnnotations() {
1008999
Iterator<Annotation> annotationIt = projectionAnnotationModel.getAnnotationIterator();
10091000
while (annotationIt.hasNext()) {
10101001
Annotation annotation = annotationIt.next();
1011-
if (annotation instanceof HeadingProjectionAnnotation projectionAnnotation) {
1012-
if (!projectionAnnotationById.containsKey(projectionAnnotation.getHeadingId())
1013-
&& !toDelete.contains(projectionAnnotation)) {
1014-
toDelete.add(projectionAnnotation);
1015-
}
1002+
if (annotation instanceof HeadingProjectionAnnotation projectionAnnotation
1003+
&& !projectionAnnotationById.containsKey(projectionAnnotation.getHeadingId())
1004+
&& !toDelete.contains(projectionAnnotation)) {
1005+
toDelete.add(projectionAnnotation);
10161006
}
10171007
}
10181008
projectionAnnotationModel.modifyAnnotations(
10191009
toDelete.isEmpty() ? null : toDelete.toArray(new Annotation[toDelete.size()]),
1020-
annotationToPosition, null);
1010+
annotationToPosition, null);
10211011
} else {
10221012
projectionAnnotationModel.modifyAnnotations(null, annotationToPosition, null);
10231013
for (HeadingProjectionAnnotation annotation : annotationToPosition.keySet()) {
@@ -1037,7 +1027,8 @@ private void createProjectionAnnotations(List<Annotation> newProjectionAnnotatio
10371027
final int lastIndex = size - 1;
10381028
for (int x = 0; x < size; ++x) {
10391029
OutlineItem child = children.get(x);
1040-
if (child.getId() == null || child.getId().length() == 0) {
1030+
1031+
if (child.getId() == null || child.getId().isEmpty()) {
10411032
continue;
10421033
}
10431034
int offset = child.getOffset();
@@ -1168,9 +1159,9 @@ private void updateSourceTabLabel() {
11681159
sourceTab.setToolTipText(Messages.MarkupEditor_markupSource_tooltip);
11691160
} else {
11701161
sourceTab.setText(
1171-
NLS.bind(Messages.MarkupEditor_markupSource_named, new Object[] { markupLanguage.getName() }));
1162+
NLS.bind(Messages.MarkupEditor_markupSource_named, markupLanguage.getName()));
11721163
sourceTab.setToolTipText(NLS.bind(Messages.MarkupEditor_markupSource_tooltip_named,
1173-
new Object[] { markupLanguage.getName() }));
1164+
markupLanguage.getName()));
11741165
}
11751166
}
11761167
}
@@ -1233,8 +1224,7 @@ private void storeMarkupLanguagePreference(MarkupLanguage markupLanguage) {
12331224
new QualifiedName(WikiTextUiPlugin.getDefault().getPluginId(), MARKUP_LANGUAGE), preference);
12341225
} catch (CoreException e) {
12351226
WikiTextUiPlugin.getDefault()
1236-
.log(IStatus.ERROR,
1237-
NLS.bind(Messages.MarkupEditor_markupPreferenceError2, new Object[] { preference }), e);
1227+
.log(IStatus.ERROR, NLS.bind(Messages.MarkupEditor_markupPreferenceError2, preference), e);
12381228
}
12391229
}
12401230
}

0 commit comments

Comments
 (0)