Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semantic Tokens ext point #1683

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions org.eclipse.jdt.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ JavaSelectRulerAction.label= Java Editor Ruler Single-Click

importExportWizards.category=Java
elementFiltersName=Java Element Filters
semanticTokens=Java Editor Semantic Tokens for Syntax Highlighting

classpathContainerPageExtensionPoint=Classpath Container Configuration
classpathAttributeConfiguration=Classpath Attribute Configuration
Expand All @@ -38,6 +39,8 @@ javadocExportWizardPageExtensionPoint=Javadoc Export Wizard Page

cleanUpExtensionPoint=Clean Ups

semanticTokensExtensionPoint=Semantic Tokens

queryParticipantsExtensionPoint=Java Query Participants

defaultClasspathContainerPage=Default Classpath Container
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.jdt.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<extension-point id="classpathAttributeConfiguration" name="%classpathAttributeConfiguration" schema="schema/classpathAttributeConfiguration.exsd"/>
<extension-point id="javadocExportWizardPage" name="%javadocExportWizardPageExtensionPoint" schema="schema/javadocExportWizardPage.exsd"/>
<extension-point id="cleanUps" name="%cleanUpExtensionPoint" schema="schema/cleanUps.exsd"/>
<extension-point id="semanticTokens" name="%semanticTokensExtensionPoint" schema="schema/semanticTokens.exsd"/>

<extension
point="org.eclipse.ui.decorators">
Expand Down
122 changes: 122 additions & 0 deletions org.eclipse.jdt.ui/schema/semanticTokens.exsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.jdt.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.jdt.ui" id="semanticTokens" name="%semanticTokens"/>
</appInfo>
<documentation>
Allows contributions of semantic tokens into Java source editor. Contributions are not sorted. This extension point is experimental.
</documentation>
</annotation>

<element name="extension">
<annotation>
<appInfo>
<meta.element />
</appInfo>
<documentation>
Allows contributions of semantic tokens into Java source editor. Contributions are not sorted. This extension point is experimental.
</documentation>
</annotation>
<complexType>
<sequence>
<element ref="provider" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
a fully qualified identifier of the target extension point
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
an optional identifier of the extension instance
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
an optional name of the extension instance
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="provider">
<annotation>
<documentation>
Contributed provider of semantic tokens
</documentation>
</annotation>
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
Instance of the class able to compute Semantic Tokens for a given Java source AST
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jdt.ui.text.java.SemanticTokensProvider"/>
</appInfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
3.34
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="examples"/>
</appInfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="apiinfo"/>
</appInfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="implementation"/>
</appInfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>

<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
Copyright (c) 2024 Broadcom Inc. and others.&lt;br&gt;

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which accompanies this distribution, and is available at &lt;a href=&quot;https://www.eclipse.org/legal/epl-2.0&quot;&gt;https://www.eclipse.org/legal/epl-v20.html&lt;/a&gt;/

SPDX-License-Identifier: EPL-2.0
</documentation>
</annotation>

</schema>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
Expand All @@ -40,6 +41,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
Expand Down Expand Up @@ -109,6 +111,7 @@
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.text.JavaTextTools;
import org.eclipse.jdt.ui.text.java.ISemanticTokensProvider;

import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
import org.eclipse.jdt.internal.ui.javaeditor.ClassFileDocumentProvider;
Expand Down Expand Up @@ -141,6 +144,8 @@
*/
public class JavaPlugin extends AbstractUIPlugin implements DebugOptionsListener {

private static final String JAVA_EDITOR_SEMANTIC_TOKENS_EXTENSION_POINT= "org.eclipse.jdt.ui.semanticTokens"; //$NON-NLS-1$

/**
* The key to store customized templates.
* @since 3.0
Expand Down Expand Up @@ -177,7 +182,7 @@
* The code template context type registry for the java editor.
* @since 3.0
*/
private volatile ContextTypeRegistry fCodeTemplateContextTypeRegistry;

Check warning on line 185 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Deprecation

NORMAL: The type ContextTypeRegistry is deprecated

/**
* The template store for the java editor.
Expand Down Expand Up @@ -274,6 +279,7 @@
private BundleContext fBundleContext;

private ServiceRegistration<DebugOptionsListener> fDebugRegistration;
private ISemanticTokensProvider[] fSemanticTokensProviders;

public static JavaPlugin getDefault() {
return fgJavaPlugin;
Expand Down Expand Up @@ -656,8 +662,8 @@
* @return the Java Core plug-in preferences
* @since 3.7
*/
public static org.eclipse.core.runtime.Preferences getJavaCorePluginPreferences() {

Check warning on line 665 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Deprecation

NORMAL: The type Preferences is deprecated
return JavaCore.getPlugin().getPluginPreferences();

Check warning on line 666 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Deprecation

NORMAL: The method getPluginPreferences() from the type Plugin is deprecated
}

/**
Expand Down Expand Up @@ -742,6 +748,24 @@
}
}

public ISemanticTokensProvider[] getContributedSemanticTokensProviders() {
if (fSemanticTokensProviders == null) {
synchronized(this) {
IExtensionRegistry registry= Platform.getExtensionRegistry();
IConfigurationElement[] elements= registry.getConfigurationElementsFor(JAVA_EDITOR_SEMANTIC_TOKENS_EXTENSION_POINT);
fSemanticTokensProviders = Arrays.stream(elements).map(ce -> {
try {
return (ISemanticTokensProvider) ce.createExecutableExtension("class"); //$NON-NLS-1$
} catch (Exception e) {
getLog().error("Cannot instatiate semantic tokens provider", e); //$NON-NLS-1$
return null;
}
}).filter(Objects::nonNull).toArray(ISemanticTokensProvider[]::new);
}
}
return fSemanticTokensProviders;
}

/**
* Resets the Java editor text hovers contributed to the workbench.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -36,6 +36,7 @@
import org.eclipse.jdt.ui.text.IColorManagerExtension;
import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;

import org.eclipse.jdt.internal.ui.preferences.SyntaxColorHighlighting;
import org.eclipse.jdt.internal.ui.text.JavaPresentationReconciler;

/**
Expand Down Expand Up @@ -252,6 +253,7 @@ public int hashCode() {
private SemanticHighlighting[] fSemanticHighlightings;
/** Highlightings */
private Highlighting[] fHighlightings;
private Highlighting[] fEditorHighlightings;

/** The editor */
private JavaEditor fEditor;
Expand Down Expand Up @@ -338,7 +340,7 @@ private void enable() {

if (fEditor != null) {
fReconciler= createSemanticHighlightingReconciler();
fReconciler.install(fEditor, fSourceViewer, fPresenter, fSemanticHighlightings, fHighlightings);
fReconciler.install(fEditor, fSourceViewer, fPresenter, fSemanticHighlightings, fHighlightings, fEditorHighlightings);
} else {
fPresenter.updatePresentation(null, createHardcodedPositions(), new HighlightedPosition[0]);
}
Expand Down Expand Up @@ -432,33 +434,44 @@ private boolean isEnabled() {
private void initializeHighlightings() {
fSemanticHighlightings= SemanticHighlightings.getSemanticHighlightings();
fHighlightings= new Highlighting[fSemanticHighlightings.length];

for (int i= 0, n= fSemanticHighlightings.length; i < n; i++) {
SemanticHighlighting semanticHighlighting= fSemanticHighlightings[i];
String colorKey= SemanticHighlightings.getColorPreferenceKey(semanticHighlighting);
addColor(colorKey);

String colorKey= SemanticHighlightings.getColorPreferenceKey(semanticHighlighting);
String boldKey= SemanticHighlightings.getBoldPreferenceKey(semanticHighlighting);
int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;

String italicKey= SemanticHighlightings.getItalicPreferenceKey(semanticHighlighting);
if (fPreferenceStore.getBoolean(italicKey))
style |= SWT.ITALIC;

String strikethroughKey= SemanticHighlightings.getStrikethroughPreferenceKey(semanticHighlighting);
if (fPreferenceStore.getBoolean(strikethroughKey))
style |= TextAttribute.STRIKETHROUGH;

String underlineKey= SemanticHighlightings.getUnderlinePreferenceKey(semanticHighlighting);
if (fPreferenceStore.getBoolean(underlineKey))
style |= TextAttribute.UNDERLINE;

boolean isEnabled= fPreferenceStore.getBoolean(SemanticHighlightings.getEnabledPreferenceKey(semanticHighlighting));

fHighlightings[i]= new Highlighting(new TextAttribute(fColorManager.getColor(PreferenceConverter.getColor(fPreferenceStore, colorKey)), null, style), isEnabled);
fHighlightings[i]= createHighlightingFromPereferences(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());
}
}

private Highlighting createHighlightingFromPereferences(boolean isEnabled, String colorKey, String boldKey, String italicKey, String strikethroughKey, String underlineKey) {
addColor(colorKey);

int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;

if (fPreferenceStore.getBoolean(italicKey))
style |= SWT.ITALIC;

if (fPreferenceStore.getBoolean(strikethroughKey))
style |= TextAttribute.STRIKETHROUGH;

if (fPreferenceStore.getBoolean(underlineKey))
style |= TextAttribute.UNDERLINE;

return new Highlighting(new TextAttribute(fColorManager.getColor(PreferenceConverter.getColor(fPreferenceStore, colorKey)), null, style), isEnabled);
}

/**
* Dispose the semantic highlightings.
*/
Expand All @@ -468,6 +481,7 @@ private void disposeHighlightings() {

fSemanticHighlightings= null;
fHighlightings= null;
fEditorHighlightings= null;
}

/*
Expand Down Expand Up @@ -554,6 +568,52 @@ private void handlePropertyChangeEvent(PropertyChangeEvent event) {
}
}

SyntaxColorHighlighting[] editorHighlightings= SyntaxColorHighlighting.getSyntaxColorHighlightings();
for (int i= 0, n= editorHighlightings.length; i < n; i++) {
SyntaxColorHighlighting h= editorHighlightings[i];

String colorKey= h.preferenceKey();
if (colorKey.equals(event.getProperty())) {
adaptToTextForegroundChange(fEditorHighlightings[i], event);
fPresenter.highlightingStyleChanged(fEditorHighlightings[i]);
refreshNeeded= true;
continue;
}

String boldKey= h.getBoldPreferenceKey();
if (boldKey.equals(event.getProperty())) {
adaptToTextStyleChange(fEditorHighlightings[i], event, SWT.BOLD);
fPresenter.highlightingStyleChanged(fEditorHighlightings[i]);
refreshNeeded= true;
continue;
}

String italicKey= h.getItalicPreferenceKey();
if (italicKey.equals(event.getProperty())) {
adaptToTextStyleChange(fEditorHighlightings[i], event, SWT.ITALIC);
fPresenter.highlightingStyleChanged(fEditorHighlightings[i]);
refreshNeeded= true;
continue;
}

String strikethroughKey= h.getStrikethroughPreferenceKey();
if (strikethroughKey.equals(event.getProperty())) {
adaptToTextStyleChange(fEditorHighlightings[i], event, TextAttribute.STRIKETHROUGH);
fPresenter.highlightingStyleChanged(fEditorHighlightings[i]);
refreshNeeded= true;
continue;
}

String underlineKey= h.getUnderlinePreferenceKey();
if (underlineKey.equals(event.getProperty())) {
adaptToTextStyleChange(fEditorHighlightings[i], event, TextAttribute.UNDERLINE);
fPresenter.highlightingStyleChanged(fEditorHighlightings[i]);
refreshNeeded= true;
continue;
}

}

if (refreshNeeded && fReconciler != null)
fReconciler.refresh();
}
Expand Down
Loading
Loading