diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java index c1abc4a49a8..c5ca09afe51 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java @@ -275,6 +275,7 @@ public void pluginsNotLoaded() { buf.append('\n'); } } + System.out.println(buf.toString()); assertEquals("Wrong bundles loaded:\n" + buf, 0, buf.length()); } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingManager.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingManager.java index 4a257f126f5..b78cdd3bbea 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingManager.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingManager.java @@ -55,15 +55,18 @@ static class Highlighting { // TODO: rename to HighlightingStyle private TextAttribute fTextAttribute; /** Enabled state */ private boolean fIsEnabled; + /** Preference Key */ + private String fKey; /** * Initialize with the given text attribute. * @param textAttribute The text attribute * @param isEnabled the enabled state */ - public Highlighting(TextAttribute textAttribute, boolean isEnabled) { + public Highlighting(String key, TextAttribute textAttribute, boolean isEnabled) { setTextAttribute(textAttribute); setEnabled(isEnabled); + this.fKey = key; } /** @@ -93,6 +96,11 @@ public boolean isEnabled() { public void setEnabled(boolean isEnabled) { fIsEnabled= isEnabled; } + + public String getKey() { + return fKey; + } + } /** @@ -253,7 +261,7 @@ public int hashCode() { private SemanticHighlighting[] fSemanticHighlightings; /** Highlightings */ private Highlighting[] fHighlightings; - private Highlighting[] fEditorHighlightings; + private Highlighting[] fSyntaxHighlightings; /** The editor */ private JavaEditor fEditor; @@ -340,7 +348,7 @@ private void enable() { if (fEditor != null) { fReconciler= createSemanticHighlightingReconciler(); - fReconciler.install(fEditor, fSourceViewer, fPresenter, fSemanticHighlightings, fHighlightings, fEditorHighlightings); + fReconciler.install(fEditor, fSourceViewer, fPresenter, fSemanticHighlightings, fHighlightings, fSyntaxHighlightings); } else { fPresenter.updatePresentation(null, createHardcodedPositions(), new HighlightedPosition[0]); } @@ -376,9 +384,9 @@ private HighlightedPosition[] createHardcodedPositions() { * @return the corresponding highlighting */ private Highlighting getHighlighting(String key) { - for (int i= 0; i < fSemanticHighlightings.length; i++) { - SemanticHighlighting semanticHighlighting= fSemanticHighlightings[i]; - if (key.equals(semanticHighlighting.getPreferenceKey())) + for (int i= 0; i < fHighlightings.length; i++) { + Highlighting highlighting= fHighlightings[i]; + if (key.equals(highlighting.getKey())) return fHighlightings[i]; } return null; @@ -444,18 +452,18 @@ private void initializeHighlightings() { String underlineKey= SemanticHighlightings.getUnderlinePreferenceKey(semanticHighlighting); boolean isEnabled= fPreferenceStore.getBoolean(SemanticHighlightings.getEnabledPreferenceKey(semanticHighlighting)); - fHighlightings[i]= createHighlightingFromPereferences(isEnabled, colorKey, boldKey, italicKey, strikethroughKey, underlineKey); + fHighlightings[i]= createHighlightingFromPereferences(semanticHighlighting.getPreferenceKey(), isEnabled, colorKey, boldKey, italicKey, strikethroughKey, underlineKey); } - SyntaxColorHighlighting[] editorHighlightings= SyntaxColorHighlighting.getSyntaxColorHighlightings(); - fEditorHighlightings = new Highlighting[editorHighlightings.length]; - for (int i = 0; i < editorHighlightings.length; i++) { - SyntaxColorHighlighting h = editorHighlightings[i]; - fEditorHighlightings[i] = createHighlightingFromPereferences(true, h.preferenceKey(), h.getBoldPreferenceKey(), h.getItalicPreferenceKey(), h.getStrikethroughPreferenceKey(), h.getUnderlinePreferenceKey()); + SyntaxColorHighlighting[] syntaxHighlightings= SyntaxColorHighlighting.getSyntaxColorHighlightings(); + fSyntaxHighlightings = new Highlighting[syntaxHighlightings.length]; + for (int i = 0; i < syntaxHighlightings.length; i++) { + SyntaxColorHighlighting h = syntaxHighlightings[i]; + fSyntaxHighlightings[i] = createHighlightingFromPereferences(h.preferenceKey(), true, h.preferenceKey(), h.getBoldPreferenceKey(), h.getItalicPreferenceKey(), h.getStrikethroughPreferenceKey(), h.getUnderlinePreferenceKey()); } } - private Highlighting createHighlightingFromPereferences(boolean isEnabled, String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { + private Highlighting createHighlightingFromPereferences(String key, boolean isEnabled, String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) { addColor(colorKey); int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL; @@ -469,7 +477,7 @@ private Highlighting createHighlightingFromPereferences(boolean isEnabled, Strin if (fPreferenceStore.getBoolean(underlineKey)) style |= TextAttribute.UNDERLINE; - return new Highlighting(new TextAttribute(fColorManager.getColor(PreferenceConverter.getColor(fPreferenceStore, colorKey)), null, style), isEnabled); + return new Highlighting(key, new TextAttribute(fColorManager.getColor(PreferenceConverter.getColor(fPreferenceStore, colorKey)), null, style), isEnabled); } /** @@ -478,10 +486,12 @@ private Highlighting createHighlightingFromPereferences(boolean isEnabled, Strin private void disposeHighlightings() { for (SemanticHighlighting fSemanticHighlighting : fSemanticHighlightings) removeColor(SemanticHighlightings.getColorPreferenceKey(fSemanticHighlighting)); + for (Highlighting h : fSyntaxHighlightings) + removeColor(h.getKey()); fSemanticHighlightings= null; fHighlightings= null; - fEditorHighlightings= null; + fSyntaxHighlightings= null; } /* @@ -574,40 +584,40 @@ private void handlePropertyChangeEvent(PropertyChangeEvent event) { String colorKey= h.preferenceKey(); if (colorKey.equals(event.getProperty())) { - adaptToTextForegroundChange(fEditorHighlightings[i], event); - fPresenter.highlightingStyleChanged(fEditorHighlightings[i]); + adaptToTextForegroundChange(fSyntaxHighlightings[i], event); + fPresenter.highlightingStyleChanged(fSyntaxHighlightings[i]); refreshNeeded= true; continue; } String boldKey= h.getBoldPreferenceKey(); if (boldKey.equals(event.getProperty())) { - adaptToTextStyleChange(fEditorHighlightings[i], event, SWT.BOLD); - fPresenter.highlightingStyleChanged(fEditorHighlightings[i]); + adaptToTextStyleChange(fSyntaxHighlightings[i], event, SWT.BOLD); + fPresenter.highlightingStyleChanged(fSyntaxHighlightings[i]); refreshNeeded= true; continue; } String italicKey= h.getItalicPreferenceKey(); if (italicKey.equals(event.getProperty())) { - adaptToTextStyleChange(fEditorHighlightings[i], event, SWT.ITALIC); - fPresenter.highlightingStyleChanged(fEditorHighlightings[i]); + adaptToTextStyleChange(fSyntaxHighlightings[i], event, SWT.ITALIC); + fPresenter.highlightingStyleChanged(fSyntaxHighlightings[i]); refreshNeeded= true; continue; } String strikethroughKey= h.getStrikethroughPreferenceKey(); if (strikethroughKey.equals(event.getProperty())) { - adaptToTextStyleChange(fEditorHighlightings[i], event, TextAttribute.STRIKETHROUGH); - fPresenter.highlightingStyleChanged(fEditorHighlightings[i]); + adaptToTextStyleChange(fSyntaxHighlightings[i], event, TextAttribute.STRIKETHROUGH); + fPresenter.highlightingStyleChanged(fSyntaxHighlightings[i]); refreshNeeded= true; continue; } String underlineKey= h.getUnderlinePreferenceKey(); if (underlineKey.equals(event.getProperty())) { - adaptToTextStyleChange(fEditorHighlightings[i], event, TextAttribute.UNDERLINE); - fPresenter.highlightingStyleChanged(fEditorHighlightings[i]); + adaptToTextStyleChange(fSyntaxHighlightings[i], event, TextAttribute.UNDERLINE); + fPresenter.highlightingStyleChanged(fSyntaxHighlightings[i]); refreshNeeded= true; continue; } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java index 440ee738a92..2a9f3a9010d 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingReconciler.java @@ -61,7 +61,6 @@ import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingManager.Highlighting; import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.DeprecatedMemberHighlighting; import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.RestrictedIdentifiersHighlighting; -import org.eclipse.jdt.internal.ui.preferences.SyntaxColorHighlighting; import org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener; import org.eclipse.jdt.internal.ui.util.ASTHelper; @@ -346,6 +345,8 @@ private void addPosition(int offset, int length, Highlighting highlighting) { private SemanticHighlighting[] fSemanticHighlightings; /** Highlightings */ private Highlighting[] fHighlightings; + /** Syntax Highlightings */ + private Highlighting[] fSyntaxHighlightings; /** Background job's added highlighted positions */ private List fAddedPositions= new ArrayList<>(); @@ -376,7 +377,7 @@ private void addPosition(int offset, int length, Highlighting highlighting) { private SemanticHighlighting[] fJobSemanticHighlightings; /** Highlightings - cache for background thread, only valid during {@link #reconciled(CompilationUnit, boolean, IProgressMonitor)} */ private Highlighting[] fJobHighlightings; - private Highlighting[] fJobEditorHighlightings; + private Highlighting[] fJobSyntaxHighlightings; /** * XXX Hack for performance reasons (should loop over fJobSemanticHighlightings can call consumes(*)) @@ -384,8 +385,6 @@ private void addPosition(int offset, int length, Highlighting highlighting) { */ private Highlighting fJobDeprecatedMemberHighlighting; - private Highlighting[] fEditorHighlightings; - /* * @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled() */ @@ -417,7 +416,7 @@ public void reconciled(CompilationUnit ast, boolean forced, IProgressMonitor pro fJobPresenter= fPresenter; fJobSemanticHighlightings= fSemanticHighlightings; fJobHighlightings= fHighlightings; - fJobEditorHighlightings = fEditorHighlightings; + fJobSyntaxHighlightings = fSyntaxHighlightings; try { if (fJobPresenter == null || fJobSemanticHighlightings == null || fJobHighlightings == null) @@ -461,7 +460,7 @@ public void reconciled(CompilationUnit ast, boolean forced, IProgressMonitor pro fJobSemanticHighlightings= null; fJobHighlightings= null; fJobDeprecatedMemberHighlighting= null; - fJobEditorHighlightings = null; + fJobSyntaxHighlightings = null; synchronized (fReconcileLock) { fIsReconciling= false; } @@ -518,87 +517,86 @@ private Highlighting fromSemanticTokenType(ISemanticTokensProvider.TokenType typ if (type != null) { switch (type) { case OPERATOR: - return findEditorHighlighting(PreferenceConstants.EDITOR_JAVA_OPERATOR_COLOR); + return findSyntaxHighlighting(PreferenceConstants.EDITOR_JAVA_OPERATOR_COLOR); case SINGLE_LINE_COMMENT: - return findEditorHighlighting(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR); + return findSyntaxHighlighting(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR); case KEYWORD: - return findEditorHighlighting(PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR); + return findSyntaxHighlighting(PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR); case BRACKET: - return findEditorHighlighting(PreferenceConstants.EDITOR_JAVA_BRACKET_COLOR); + return findSyntaxHighlighting(PreferenceConstants.EDITOR_JAVA_BRACKET_COLOR); case MULTI_LINE_COMMENT: - return findEditorHighlighting(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR); + return findSyntaxHighlighting(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR); case STRING: - return findEditorHighlighting(PreferenceConstants.EDITOR_STRING_COLOR); + return findSyntaxHighlighting(PreferenceConstants.EDITOR_STRING_COLOR); case METHOD: - return findHighlighting(SemanticHighlightings.METHOD); + return findSemanticHighlighting(SemanticHighlightings.METHOD); case ABSTRACT_CLASS: - return findHighlighting(SemanticHighlightings.ABSTRACT_CLASS); + return findSemanticHighlighting(SemanticHighlightings.ABSTRACT_CLASS); case ABSTRACT_METHOD_INVOCATION: - return findHighlighting(SemanticHighlightings.ABSTRACT_METHOD_INVOCATION); + return findSemanticHighlighting(SemanticHighlightings.ABSTRACT_METHOD_INVOCATION); case ANNOTATION: - return findHighlighting(SemanticHighlightings.ANNOTATION); + return findSemanticHighlighting(SemanticHighlightings.ANNOTATION); case ANNOTATION_ELEMENT_REFERENCE: - return findHighlighting(SemanticHighlightings.ANNOTATION_ELEMENT_REFERENCE); + return findSemanticHighlighting(SemanticHighlightings.ANNOTATION_ELEMENT_REFERENCE); case AUTOBOXING: - return findHighlighting(SemanticHighlightings.AUTOBOXING); + return findSemanticHighlighting(SemanticHighlightings.AUTOBOXING); case CLASS: - return findHighlighting(SemanticHighlightings.CLASS); + return findSemanticHighlighting(SemanticHighlightings.CLASS); case DEPRECATED_MEMBER: - return findHighlighting(SemanticHighlightings.DEPRECATED_MEMBER); + return findSemanticHighlighting(SemanticHighlightings.DEPRECATED_MEMBER); case ENUM: - return findHighlighting(SemanticHighlightings.ENUM); + return findSemanticHighlighting(SemanticHighlightings.ENUM); case FIELD: - return findHighlighting(SemanticHighlightings.FIELD); + return findSemanticHighlighting(SemanticHighlightings.FIELD); case INHERITED_FIELD: - return findHighlighting(SemanticHighlightings.INHERITED_FIELD); + return findSemanticHighlighting(SemanticHighlightings.INHERITED_FIELD); case INHERITED_METHOD_INVOCATION: - return findHighlighting(SemanticHighlightings.INHERITED_METHOD_INVOCATION); + return findSemanticHighlighting(SemanticHighlightings.INHERITED_METHOD_INVOCATION); case INTERFACE: - return findHighlighting(SemanticHighlightings.INTERFACE); + return findSemanticHighlighting(SemanticHighlightings.INTERFACE); case LOCAL_VARIABLE: - return findHighlighting(SemanticHighlightings.LOCAL_VARIABLE); + return findSemanticHighlighting(SemanticHighlightings.LOCAL_VARIABLE); case LOCAL_VARIABLE_DECLARATION: - return findHighlighting(SemanticHighlightings.LOCAL_VARIABLE_DECLARATION); + return findSemanticHighlighting(SemanticHighlightings.LOCAL_VARIABLE_DECLARATION); case METHOD_DECLARATION: - return findHighlighting(SemanticHighlightings.METHOD_DECLARATION); + return findSemanticHighlighting(SemanticHighlightings.METHOD_DECLARATION); case NUMBER: - return findHighlighting(SemanticHighlightings.NUMBER); + return findSemanticHighlighting(SemanticHighlightings.NUMBER); case PARAMETER_VARIABLE: - return findHighlighting(SemanticHighlightings.PARAMETER_VARIABLE); + return findSemanticHighlighting(SemanticHighlightings.PARAMETER_VARIABLE); case STATIC_FIELD: - return findHighlighting(SemanticHighlightings.STATIC_FIELD); + return findSemanticHighlighting(SemanticHighlightings.STATIC_FIELD); case STATIC_FINAL_FIELD: - return findHighlighting(SemanticHighlightings.STATIC_FINAL_FIELD); + return findSemanticHighlighting(SemanticHighlightings.STATIC_FINAL_FIELD); case STATIC_METHOD_INVOCATION: - return findHighlighting(SemanticHighlightings.STATIC_METHOD_INVOCATION); + return findSemanticHighlighting(SemanticHighlightings.STATIC_METHOD_INVOCATION); case TYPE_ARGUMENT: - return findHighlighting(SemanticHighlightings.TYPE_ARGUMENT); + return findSemanticHighlighting(SemanticHighlightings.TYPE_ARGUMENT); case TYPE_VARIABLE: - return findHighlighting(SemanticHighlightings.TYPE_VARIABLE); + return findSemanticHighlighting(SemanticHighlightings.TYPE_VARIABLE); case RESTRICTED_IDENTIFIER: - return findHighlighting(SemanticHighlightingsCore.RESTRICTED_KEYWORDS); + return findSemanticHighlighting(SemanticHighlightingsCore.RESTRICTED_KEYWORDS); case DEFAULT: default: - return findEditorHighlighting(PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR); + return findSyntaxHighlighting(PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR); } } return null; } - private Highlighting findHighlighting(String preferenceKey) { - for (int i = 0; i < fJobSemanticHighlightings.length; i++) { - if (Objects.equals(preferenceKey, fJobSemanticHighlightings[i].getPreferenceKey())) { + private Highlighting findSemanticHighlighting(String preferenceKey) { + for (int i = 0; i < fJobHighlightings.length; i++) { + if (Objects.equals(preferenceKey, fJobHighlightings[i].getKey())) { return fJobHighlightings[i]; } } return null; } - private Highlighting findEditorHighlighting(String key) { - SyntaxColorHighlighting[] h= SyntaxColorHighlighting.getSyntaxColorHighlightings(); - for (int i = 0; i < h.length; i++) { - if (Objects.equals(key, h[i].preferenceKey())) { - return fJobEditorHighlightings[i]; + private Highlighting findSyntaxHighlighting(String key) { + for (int i = 0; i < fJobSyntaxHighlightings.length; i++) { + if (Objects.equals(key, fJobSyntaxHighlightings[i].getKey())) { + return fJobSyntaxHighlightings[i]; } } return null; @@ -657,13 +655,13 @@ private void stopReconcilingPositions() { * @param presenter the semantic highlighting presenter * @param semanticHighlightings the semantic highlightings * @param highlightings the highlightings - * @param editorHighlightings editor highlightings + * @param syntaxHighlightings editor syntax highlightings */ - public void install(JavaEditor editor, ISourceViewer sourceViewer, SemanticHighlightingPresenter presenter, SemanticHighlighting[] semanticHighlightings, Highlighting[] highlightings, Highlighting[] editorHighlightings) { + public void install(JavaEditor editor, ISourceViewer sourceViewer, SemanticHighlightingPresenter presenter, SemanticHighlighting[] semanticHighlightings, Highlighting[] highlightings, Highlighting[] syntaxHighlightings) { fPresenter= presenter; fSemanticHighlightings= semanticHighlightings; fHighlightings= highlightings; - fEditorHighlightings= editorHighlightings; + fSyntaxHighlightings= syntaxHighlightings; fEditor= editor; fSourceViewer= sourceViewer; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/ISemanticTokensProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/ISemanticTokensProvider.java index 37f9bc01566..1dbb69824d0 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/ISemanticTokensProvider.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/ISemanticTokensProvider.java @@ -15,6 +15,11 @@ import org.eclipse.jdt.core.dom.CompilationUnit; +/** + * Computes semantic tokens contributed to the Java source editor via extension point semanticTokens + * + * @since 3.34 + */ public interface ISemanticTokensProvider { record SemanticToken(int ofset, int length, TokenType tokenType) {}