From 01198d7ba27989e6015a2f01e301df9526ab59ad Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 13:05:48 +0200 Subject: [PATCH 1/8] refact: remove unused message keys --- .../internal/LanguageConfigurationMessages.java | 1 - .../java/org/eclipse/tm4e/ui/internal/TMUIMessages.java | 6 ------ .../org/eclipse/tm4e/ui/internal/TMUIMessages.properties | 5 ----- 3 files changed, 12 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java index 476df28f0..df27eb3b1 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/LanguageConfigurationMessages.java @@ -57,7 +57,6 @@ public final class LanguageConfigurationMessages extends NLS { public static String LanguageConfigurationPreferencePage_description; public static String LanguageConfigurationPreferencePage_description2; public static String LanguageConfigurationPreferencePage_button_add; - public static String LanguageConfigurationPreferencePage_path; public static String LanguageConfigurationPreferencePage_column_source; public static String LanguageConfigurationPreferencePage_button_remove; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java index 1e52556d5..a2c59ba26 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.java @@ -86,7 +86,6 @@ public final class TMUIMessages extends NLS { public static String SelectGrammarWizardPage_file_label; public static String SelectGrammarWizardPage_file_error_required; public static String SelectGrammarWizardPage_file_error_load; - public static String SelectGrammarWizardPage_file_error_invalid; public static String CreateThemeAssociationWizardPage_title; public static String CreateThemeAssociationWizardPage_description; @@ -96,12 +95,7 @@ public final class TMUIMessages extends NLS { public static String CreateThemeAssociationWizardPage_grammar_error_required; public static String CreateThemeAssociationWizardPage_whenDark_text; - // TMPresentationReconciler register dialog confirmation - public static String TMPresentationReconciler_register_dialog_title; - public static String TMPresentationReconciler_register_dialog_message; - static { NLS.initializeMessages(BUNDLE_NAME, TMUIMessages.class); } - } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties index 428f2f2a7..0ece72564 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/TMUIMessages.properties @@ -71,7 +71,6 @@ SelectGrammarWizardPage_description=Specify the TextMate grammar file *.tmLangua SelectGrammarWizardPage_file_label=File: SelectGrammarWizardPage_file_error_required=TextMate grammar file is required. SelectGrammarWizardPage_file_error_load=Error while loading the TextMate grammar file: "{0}". -SelectGrammarWizardPage_file_error_invalid=The file is not a TextMate grammar file. It cannot retrieve the scope name. CreateThemeAssociationWizardPage_title=Specify the theme to use with a given grammar CreateThemeAssociationWizardPage_description=Choose the theme to use for your grammar when an E4 Theme is activated. @@ -80,7 +79,3 @@ CreateThemeAssociationWizardPage_grammar_text= with the grammar: CreateThemeAssociationWizardPage_theme_error_required=Theme is required CreateThemeAssociationWizardPage_grammar_error_required=Grammar is required CreateThemeAssociationWizardPage_whenDark_text=when Eclipse Dark theme is activated? - -# TMPresentationReconciler dialog -TMPresentationReconciler_register_dialog_title=Register the grammar? -TMPresentationReconciler_register_dialog_message=TextMate grammar cannot be found for the file "{0}". Do you want to register it? From dde988dbc303f70a7f28d7dbd56785d022f96c96 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 13:14:27 +0200 Subject: [PATCH 2/8] refact: minor code cleanup of TMViewer --- .../preferences/GrammarPreferencePage.java | 2 +- .../preferences/ThemePreferencePage.java | 2 +- .../tm4e/ui/internal/widgets/TMViewer.java | 29 +++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index 4f8d5b241..be7847bd1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -344,7 +344,7 @@ private void createThemePreview(final Composite parent) { data.horizontalSpan = 2; label.setLayoutData(data); - grammarPreview = new TMViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + grammarPreview = new TMViewer(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); // Don't set caret to 'null' as this causes https://bugs.eclipse.org/293263 // viewer.getTextWidget().setCaret(null); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index cbd36cc2a..b98ef5d15 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -252,7 +252,7 @@ private void createThemePreview(final Composite parent) { grammarsCombo.getCombo().select(0); } - themePreview = new TMViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + themePreview = new TMViewer(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); // Don't set caret to 'null' as this causes https://bugs.eclipse.org/293263 // viewer.getTextWidget().setCaret(null); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java index dc2453aaf..880fab7dc 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TMViewer.java @@ -31,45 +31,44 @@ */ public final class TMViewer extends SourceViewer { + private final class TMSourceViewerConfiguration extends SourceViewerConfiguration { + @Override + public IPresentationReconciler getPresentationReconciler(final @Nullable ISourceViewer sourceViewer) { + return reconciler; + } + } + private final TMPresentationReconciler reconciler = new TMPresentationReconciler(); - public TMViewer(final Composite parent, final IVerticalRuler ruler, final int styles) { - this(parent, ruler, null, false, styles); + public TMViewer(final Composite parent, final int styles) { + this(parent, null, null, false, styles); } - public TMViewer(final Composite parent, @Nullable final IVerticalRuler verticalRuler, - @Nullable final IOverviewRuler overviewRuler, + public TMViewer(final Composite parent, final @Nullable IVerticalRuler verticalRuler, final @Nullable IOverviewRuler overviewRuler, final boolean showAnnotationsOverview, final int styles) { super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles); configure(new TMSourceViewerConfiguration()); } - private final class TMSourceViewerConfiguration extends SourceViewerConfiguration { - @Override - public IPresentationReconciler getPresentationReconciler(@Nullable final ISourceViewer sourceViewer) { - return reconciler; - } - } - - public void setGrammar(@Nullable final IGrammar grammar) { + public void setGrammar(final @Nullable IGrammar grammar) { reconciler.setGrammar(grammar); if (getDocument() == null) { - super.setDocument(new Document()); + setDocument(new Document()); } } public void setTheme(final ITheme theme) { reconciler.setTheme(theme); final StyledText styledText = getTextWidget(); + styledText.setFont(JFaceResources.getTextFont()); styledText.setForeground(null); styledText.setBackground(null); theme.initializeViewerColors(styledText); - getTextWidget().setFont(JFaceResources.getTextFont()); } public void setText(final String text) { if (getDocument() == null) { - super.setDocument(new Document()); + setDocument(new Document()); } getDocument().set(text); } From ab45255c4142b67be2106c2e68430e149dee41f1 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 14:34:07 +0200 Subject: [PATCH 3/8] refact: improve theme selection in GrammarPreferencePage --- .../preferences/GrammarPreferencePage.java | 19 ++++++++++--------- .../tm4e/ui/internal/widgets/TableWidget.java | 9 +++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index be7847bd1..647f3fcb4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -323,17 +323,18 @@ private void fillContentTypeTab(final IGrammarDefinition definition) { } private void fillThemeTab(final IGrammarDefinition definition) { - final var selectedAssociation = themeAssociationsWidget.getTable().getFirstSelectedElement(); + final TableWidget themeAssociationsTable = themeAssociationsWidget.getTable(); + final IThemeAssociation selectedAssociation = themeAssociationsTable.getFirstSelectedElement(); + themeAssociationsWidget.setGrammarDefinition(definition); - // restore theme selection - if (selectedAssociation != null) { - for (IThemeAssociation association : themeAssociationsWidget.getTable().getElements()) { - if (association.getThemeId().equals(selectedAssociation.getThemeId())) { - themeAssociationsWidget.getTable().setSelection(association); - break; - } - } + if (selectedAssociation == null) { + // ensure that by default a TM theme is selected that matches the Eclipse theme's dark/light mode + final boolean isDarkEclipse = themeManager.getDefaultTheme().isDark(); + themeAssociationsTable.setSelection(association -> association.isWhenDark() == isDarkEclipse); + } else { + // restore theme selection + themeAssociationsTable.setSelection(association -> association.getThemeId().equals(selectedAssociation.getThemeId())); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java index 92738c2dd..0bc4b73df 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Predicate; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.layout.TableColumnLayout; @@ -205,6 +206,14 @@ public void setSelection(@SuppressWarnings("unchecked") final T... selection) { setSelection(new StructuredSelection(selection)); } + public void setSelection(final List selection) { + setSelection(new StructuredSelection(selection)); + } + + public void setSelection(final Predicate selector) { + setSelection(getElements().stream().filter(selector).toList()); + } + public void setSelection(boolean reveal, @SuppressWarnings("unchecked") final T... selection) { setSelection(selection); if (reveal) { From 7f47e77bd4b20a20cd5500f802784de5504c92ab Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 14:53:47 +0200 Subject: [PATCH 4/8] refact: add final keyword where appropriate --- .../internal/model/FoldingRules.java | 4 ++-- .../ui/internal/preferences/GrammarPreferencePage.java | 4 ++-- .../ui/internal/preferences/ThemePreferencePage.java | 6 +++--- .../tm4e/ui/internal/themes/AbstractTokenProvider.java | 2 +- .../tm4e/ui/internal/themes/TMThemeTokenProvider.java | 2 +- .../tm4e/ui/internal/utils/ContentTypeHelper.java | 4 ++-- .../eclipse/tm4e/ui/internal/utils/MarkerUtils.java | 4 ++-- .../java/org/eclipse/tm4e/ui/internal/utils/UI.java | 2 +- .../eclipse/tm4e/ui/internal/widgets/TableWidget.java | 6 +++--- .../ui/internal/widgets/TableWithControlsWidget.java | 6 +++--- .../ui/internal/widgets/ThemeAssociationsWidget.java | 10 +++++----- .../tm4e/ui/internal/widgets/VerticalSplitPane.java | 2 +- .../eclipse/tm4e/ui/themes/css/CSSTokenProvider.java | 2 +- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/model/FoldingRules.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/model/FoldingRules.java index 1810b8d0f..3b22facf1 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/model/FoldingRules.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/model/FoldingRules.java @@ -28,11 +28,11 @@ public final class FoldingRules { * - the regex should start with '^' * - regexp flags (i, g) are ignored */ - public final class FoldingMarkers { + public static final class FoldingMarkers { public final RegExPattern start; public final RegExPattern end; - public FoldingMarkers(RegExPattern start, RegExPattern end) { + public FoldingMarkers(final RegExPattern start, final RegExPattern end) { this.start = start; this.end = end; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index 647f3fcb4..91b3a53e0 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -64,7 +64,7 @@ public final class GrammarPreferencePage extends AbstractPreferencePage { // Managers private IGrammarRegistryManager.EditSession grammarManager = TMEclipseRegistryPlugin.getGrammarRegistryManager().newEditSession(); private IThemeManager.EditSession themeManager = ThemeManager.getInstance().newEditSession(); - private ISnippetManager snippetManager = TMUIPlugin.getSnippetManager(); + private final ISnippetManager snippetManager = TMUIPlugin.getSnippetManager(); private TableWidget grammarsTable = lazyNonNull(); @@ -341,7 +341,7 @@ private void fillThemeTab(final IGrammarDefinition definition) { private void createThemePreview(final Composite parent) { final var label = new Label(parent, SWT.NONE); label.setText(TMUIMessages.GrammarPreferencePage_preview); - var data = new GridData(); + final var data = new GridData(); data.horizontalSpan = 2; label.setLayoutData(data); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java index b98ef5d15..5c53d2477 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/ThemePreferencePage.java @@ -81,13 +81,13 @@ protected Control createContents(final @NonNullByDefault({}) Composite parent) { final var control = new VerticalSplitPane(parent, 1, 1) { @Override - protected void configureUpperArea(Composite parent) { + protected void configureUpperArea(final Composite parent) { createThemesTable(parent); createThemeDetailsView(parent); } @Override - protected void configureLowerArea(Composite parent) { + protected void configureLowerArea(final Composite parent) { createThemePreview(parent); } }.getControl(); @@ -171,7 +171,7 @@ protected void createButtons() { ? themeFileName.substring(0, themeFileName.lastIndexOf('.')) : rawTheme.getName()); return new Theme(name, themePath.toAbsolutePath().toString(), name, false); - } catch (Exception ex) { + } catch (final Exception ex) { MessageDialog.openError(getShell(), "Invalid theme file", "Failed to parse [" + themePath + "]: " + ex); return null; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractTokenProvider.java index 19aad3cc2..c33fcce71 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/AbstractTokenProvider.java @@ -53,7 +53,7 @@ protected IToken getJFaceTextToken(final IStyle style) { return getJFaceTextTokenReturnValueCache.computeIfAbsent(style, this::getJFaceTextTokenUncached); } - private IToken getJFaceTextTokenUncached(IStyle style) { + private IToken getJFaceTextTokenUncached(final IStyle style) { final @Nullable RGB styleFGColor = style.getColor(); final @Nullable RGB styleBGColor = style.getBackgroundColor(); final var colors = ColorManager.getInstance(); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/TMThemeTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/TMThemeTokenProvider.java index 6f30c9809..9be4ba19f 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/TMThemeTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/themes/TMThemeTokenProvider.java @@ -83,7 +83,7 @@ public TMThemeTokenProvider(final IThemeSource.ContentType contentType, final In } protected @Nullable Color getEditorColor(final String... names) { - for (String name : names) { + for (final String name : names) { final String colorHexCode = castNullable(theme.getEditorColors().get(name)); if (colorHexCode == null) continue; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java index b50da2c25..d5278f2e1 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java @@ -150,10 +150,10 @@ private static InputStream getContents(final ITextFileBuffer buffer) throws Core if (path != null) { if (path.isAbsolute()) { final var file = path.toFile(); - if(file.exists()) { + if (file.exists()) { try { return new BufferedInputStream(new FileInputStream(file)); - } catch (FileNotFoundException ex) { + } catch (final FileNotFoundException ex) { TMUIPlugin.logError(ex); } } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java index 21843cd22..ca2c668f7 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/MarkerUtils.java @@ -186,7 +186,7 @@ private static void updateTextMarkers(final ITMDocumentModel docModel, final int final Object lineNumberAttr = marker.getAttribute(IMarker.LINE_NUMBER); if (lineNumberAttr instanceof final Integer lineNumber) return lineNumber; - } catch (CoreException ex) { + } catch (final CoreException ex) { if (marker.exists()) TMUIPlugin.logError(ex); } @@ -220,7 +220,7 @@ private static boolean removeMatchingMarker(final List markers, final S it.remove(); return true; } - } catch (CoreException ex) { + } catch (final CoreException ex) { if (marker.exists()) TMUIPlugin.logError(ex); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/UI.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/UI.java index bdc825f8d..e68c4cbb4 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/UI.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/UI.java @@ -144,7 +144,7 @@ public void modifyText(final @Nullable ModifyEvent e) { private static @Nullable FontMetrics fontMetrics; - public static int convertHeightInCharsToPixels(int chars) { + public static int convertHeightInCharsToPixels(final int chars) { if (fontMetrics == null) { final GC gc = new GC(getActiveShell()); try { diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java index 0bc4b73df..2ebfab649 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWidget.java @@ -134,7 +134,7 @@ protected Object[] getElements(final @Nullable Object input) { @SuppressWarnings("unchecked") @Override - public T getElementAt(int index) { + public T getElementAt(final int index) { return (T) super.getElementAt(index); } @@ -214,7 +214,7 @@ public void setSelection(final Predicate selector) { setSelection(getElements().stream().filter(selector).toList()); } - public void setSelection(boolean reveal, @SuppressWarnings("unchecked") final T... selection) { + public void setSelection(final boolean reveal, @SuppressWarnings("unchecked") final T... selection) { setSelection(selection); if (reveal) { reveal(selection[0]); @@ -225,7 +225,7 @@ public void setSelection(boolean reveal, @SuppressWarnings("unchecked") final T. * @param col 0-based column index * @param sortDirection {@link SWT#DOWN} or {@link SWT#UP} */ - public void setSortColumn(final int col, int sortDirection) { + public void setSortColumn(final int col, final int sortDirection) { viewerComparator.setColumns(col, secondarySortColumns.get(col)); viewerComparator.setDirection(sortDirection); getTable().setSortDirection(viewerComparator.getDirection()); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWithControlsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWithControlsWidget.java index c068386b1..dfe05a40e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWithControlsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/TableWithControlsWidget.java @@ -64,7 +64,7 @@ protected TableWithControlsWidget(final Composite parent, final @Nullable String protected void createButtons() { } - protected Button createButton(String title, Runnable onClick) { + protected Button createButton(final String title, final Runnable onClick) { final var button = new Button(buttonsArea, SWT.PUSH); button.setText(title); button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -81,7 +81,7 @@ private void createTitle(final String title, final Composite parent) { } private void createFilter(final Composite parent) { - var filterInput = new Text(this, SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH | SWT.FLAT); + final var filterInput = new Text(this, SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH | SWT.FLAT); filterInput.setMessage(" type filter text"); filterInput.addModifyListener(e -> onFilterChanged(filterInput.getText())); filterInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -104,7 +104,7 @@ protected void onFilterChanged(final String newFilterText) { table.setFilters(new ViewerFilter() { @NonNullByDefault({}) @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { + public boolean select(final Viewer viewer, final Object parentElement, final Object element) { for (int i = 0, l = swtTable.getItemCount(); i < l; i++) { if (table.getElementAt(i) == element) { final var row = swtTable.getItem(i); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java index ddf999737..2d49be108 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java @@ -42,7 +42,7 @@ public ThemeAssociationsWidget(final IThemeManager.EditSession themeManager, fin } @Override - protected TableWidget createTable(Composite parent) { + protected TableWidget createTable(final Composite parent) { return new TableWidget<>(parent, false) { { getTable().setHeaderVisible(false); @@ -75,8 +75,8 @@ protected void createColumns() { } @Override - protected Object[] getElements(@Nullable Object input) { - if (input instanceof IGrammarDefinition grammarDef) { + protected Object[] getElements(@Nullable final Object input) { + if (input instanceof final IGrammarDefinition grammarDef) { return themeManager .getThemeAssociationsForScope(grammarDef.getScope().getName()); } @@ -115,7 +115,7 @@ protected void createButtons() { } else { editButton.setEnabled(true); final IThemeAssociation association = associations.get(0); - boolean isDefaultThemeAssociation = association.getThemeId() + final boolean isDefaultThemeAssociation = association.getThemeId() .equals(themeManager.getDefaultTheme(association.isWhenDark()).getId()); removeButton.setEnabled(!isDefaultThemeAssociation); } @@ -123,7 +123,7 @@ protected void createButtons() { } public @Nullable IGrammarDefinition getGrammarDefinition() { - return getTable().getInput() instanceof IGrammarDefinition def + return getTable().getInput() instanceof final IGrammarDefinition def ? def : null; } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/VerticalSplitPane.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/VerticalSplitPane.java index a8fa11820..b6ed17f75 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/VerticalSplitPane.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/VerticalSplitPane.java @@ -23,7 +23,7 @@ public abstract class VerticalSplitPane { private final SashForm sash; - protected VerticalSplitPane(final Composite parent, int upperAreaWeight, int lowerAreaWeight) { + protected VerticalSplitPane(final Composite parent, final int upperAreaWeight, final int lowerAreaWeight) { sash = new SashForm(parent, SWT.VERTICAL | SWT.SMOOTH); sash.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY)); sash.setSashWidth(5); diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java index 21278ee4c..ecc89e3ab 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/themes/css/CSSTokenProvider.java @@ -53,7 +53,7 @@ public CSSTokenProvider(final InputStream in) { } @Override - protected @Nullable IStyle getBestStyle(String textMateTokenType) { + protected @Nullable IStyle getBestStyle(final String textMateTokenType) { return parser.getBestStyle(StringUtils.splitToArray(textMateTokenType, '.')); } From a53202ae5a9989a45cf0330717e3a8e841dd699f Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 14:56:14 +0200 Subject: [PATCH 5/8] refact: use enhanced for loop --- .../org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java | 3 +-- .../org/eclipse/tm4e/core/internal/grammar/ScopeStack.java | 4 ++-- .../main/java/org/eclipse/tm4e/core/internal/theme/Theme.java | 3 +-- .../org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java index ab96daff5..b4dcb4ad0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java @@ -371,8 +371,7 @@ private MatchInjectionsResult matchInjections(final List injections, final List scopes = stack.contentNameScopesList != null ? stack.contentNameScopesList.getScopeNames() : Collections.emptyList(); - for (int i = 0, len = injections.size(); i < len; i++) { - final var injection = injections.get(i); + for (final Injection injection : injections) { if (!injection.matches(scopes)) { // injection selector doesn't match stack continue; diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeStack.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeStack.java index c7a9e6e89..e47e624c0 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeStack.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeStack.java @@ -44,8 +44,8 @@ public static ScopeStack from(final String first) { @Nullable public static ScopeStack from(final String... segments) { ScopeStack result = null; - for (var i = 0; i < segments.length; i++) { - result = new ScopeStack(result, segments[i]); + for (final String segment : segments) { + result = new ScopeStack(result, segment); } return result; } diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/Theme.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/Theme.java index 4e6c08285..efadec9c7 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/Theme.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/theme/Theme.java @@ -268,8 +268,7 @@ public static Theme resolveParsedThemeRules(final List _parsedT final var defaults = StyleAttributes.of(defaultFontStyle, colorMap.getId(defaultForeground), colorMap.getId(defaultBackground)); final var root = new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, 0, 0), Collections.emptyList()); - for (int i = 0, len = parsedThemeRules.size(); i < len; i++) { - final var rule = parsedThemeRules.get(i); + for (final ParsedThemeRule rule : parsedThemeRules) { root.insert(0, rule.scope, rule.parentScopes, rule.fontStyle, colorMap.getId(rule.foreground), colorMap.getId(rule.background)); } diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java index d5278f2e1..43cc25410 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/utils/ContentTypeHelper.java @@ -226,8 +226,7 @@ private static IEditorInput getEditorInput(final IDocument document) { if (listeners != null) { // Get AbstractDocumentProvider#ElementInfo final Object[] l = listeners.getListeners(); - for (int i = 0; i < l.length; i++) { - final Object /* AbstractDocumentProvider#ElementInfo */ info = l[i]; + for (final Object /* AbstractDocumentProvider#ElementInfo */ info : l) { try { /* The element for which the info is stored */ final Object input = ClassHelper.getFieldValue(info, "fElement"); From 4ab0bc22e35979dd17b934ae722426f23e495ba0 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 14:58:28 +0200 Subject: [PATCH 6/8] refact: remove redundant parentheses --- .../internal/supports/OnEnterSupport.java | 2 +- .../tm4e/languageconfiguration/internal/utils/TextUtils.java | 2 +- .../tm4e/ui/internal/widgets/ThemeAssociationsWidget.java | 2 +- .../src/main/java/org/eclipse/tm4e/ui/text/Colorizer.java | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java index 28214d408..5594a67eb 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/supports/OnEnterSupport.java @@ -62,7 +62,7 @@ boolean matchClose(final String afterEnterText) { private final List regExpRules; public OnEnterSupport(final @Nullable List brackets, final @Nullable List regExpRules) { - for (final var charPair : (brackets != null ? brackets : DEFAULT_BRACKETS)) { + for (final var charPair : brackets != null ? brackets : DEFAULT_BRACKETS) { final var openRegExp = createOpenBracketRegExp(charPair.open); final var closeRegExp = createCloseBracketRegExp(charPair.close); if (openRegExp != null && closeRegExp != null) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java index 14ad0fbb5..987a94789 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/utils/TextUtils.java @@ -225,7 +225,7 @@ public boolean test(final int value) { /* * replace common indentation of all lines */ - final var sb = new StringBuilder(Math.max(0, multiLineString.length() - (indentDetector.lineCount * existingIndent))); + final var sb = new StringBuilder(Math.max(0, multiLineString.length() - indentDetector.lineCount * existingIndent)); final class IdentReplacer extends CharConsumer { int skippedIndentOfLine = 0; boolean isEmptyLine = true; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java index 2d49be108..3dfd9621e 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/widgets/ThemeAssociationsWidget.java @@ -67,7 +67,7 @@ protected void createColumns() { yield NLS.bind(association.isWhenDark() ? TMUIMessages.ThemeAssociationLabelProvider_dark : TMUIMessages.ThemeAssociationLabelProvider_light, - (isDefaultThemeAssociation ? "default " : ""), + isDefaultThemeAssociation ? "default " : "", themeName); } default -> null; diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/Colorizer.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/Colorizer.java index 95add4885..8155a651b 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/Colorizer.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/text/Colorizer.java @@ -115,7 +115,9 @@ void colorize(final IRegion damageRegion, final ITMDocumentModel tmModel) throws final int startLineOffset = doc.getLineOffset(lineIndex); for (int i = 0; i < tokens.size(); i++) { final TMToken currentToken = tokens.get(i); - final TMToken nextToken = (i + 1 < tokens.size()) ? tokens.get(i + 1) : null; + final TMToken nextToken = i + 1 < tokens.size() + ? tokens.get(i + 1) + : null; int tokenStartIndex = currentToken.startIndex; // check if the current token is before the damaged region From 18ef8e33577eeb8b9a0867877e6d1a23e30098fa Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 14:58:42 +0200 Subject: [PATCH 7/8] refact: fix indentation --- .../internal/ToggleLineCommentHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/ToggleLineCommentHandler.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/ToggleLineCommentHandler.java index 2fca0acb1..4e8cbd4a7 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/ToggleLineCommentHandler.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/ToggleLineCommentHandler.java @@ -77,8 +77,8 @@ public Object execute(@Nullable final ExecutionEvent event) throws ExecutionExce } final ContentTypeInfo info = ContentTypeHelper.findContentTypes(document); - if (info == null) - return null; + if (info == null) + return null; final var contentTypes = info.getContentTypes(); final var command = event.getCommand(); From bcf9e4552dead05421ec70a91d85563e077cc0d0 Mon Sep 17 00:00:00 2001 From: sebthom Date: Tue, 14 May 2024 14:59:25 +0200 Subject: [PATCH 8/8] refact: use method reference instead of lambda expression --- .../tm4e/ui/internal/preferences/GrammarPreferencePage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java index 91b3a53e0..a58839490 100644 --- a/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java +++ b/org.eclipse.tm4e.ui/src/main/java/org/eclipse/tm4e/ui/internal/preferences/GrammarPreferencePage.java @@ -123,7 +123,7 @@ protected void createColumns() { final var contentTypes = grammarManager.getContentTypesForScope(def.getScope()); yield contentTypes == null ? null - : contentTypes.stream().map(ct -> ct.getName()) + : contentTypes.stream().map(IContentType::getName) .distinct() .sorted() .collect(Collectors.joining(", "));