Skip to content

Commit

Permalink
Polish and debug failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Oct 28, 2024
1 parent a0c21c6 commit 43ebedf
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public void pluginsNotLoaded() {
buf.append('\n');
}
}
System.out.println(buf.toString());
assertEquals("Wrong bundles loaded:\n" + buf, 0, buf.length());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -93,6 +96,11 @@ public boolean isEnabled() {
public void setEnabled(boolean isEnabled) {
fIsEnabled= isEnabled;
}

public String getKey() {
return fKey;
}

}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand All @@ -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;
}

/*
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Position> fAddedPositions= new ArrayList<>();
Expand Down Expand Up @@ -376,16 +377,14 @@ 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(*))
* @since 3.5
*/
private Highlighting fJobDeprecatedMemberHighlighting;

private Highlighting[] fEditorHighlightings;

/*
* @see org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener#aboutToBeReconciled()
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

import org.eclipse.jdt.core.dom.CompilationUnit;

/**
* Computes semantic tokens contributed to the Java source editor via extension point <code>semanticTokens</code>
*
* @since 3.34
*/
public interface ISemanticTokensProvider {

record SemanticToken(int ofset, int length, TokenType tokenType) {}
Expand Down

0 comments on commit 43ebedf

Please sign in to comment.