Skip to content

Commit

Permalink
Extension point docs and minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Oct 18, 2024
1 parent 9332408 commit a0c21c6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
2 changes: 2 additions & 0 deletions org.eclipse.jdt.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ javadocExportWizardPageExtensionPoint=Javadoc Export Wizard Page

cleanUpExtensionPoint=Clean Ups

semanticTokensExtensionPoint=Semantic Tokens

queryParticipantsExtensionPoint=Java Query Participants

defaultClasspathContainerPage=Default Classpath Container
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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="%semanticTokens" schema="schema/semanticTokens.exsd"/>
<extension-point id="semanticTokens" name="%semanticTokensExtensionPoint" schema="schema/semanticTokens.exsd"/>

<extension
point="org.eclipse.ui.decorators">
Expand Down
32 changes: 26 additions & 6 deletions org.eclipse.jdt.ui/schema/semanticTokens.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta.schema plugin="org.eclipse.jdt.ui" id="semanticTokens" name="%semanticTokens"/>
</appInfo>
<documentation>
[Enter description of this extension point.]
Allows contributions of semantic tokens into Java source editor. Contributions are not sorted. This extension point is experimental.
</documentation>
</annotation>

Expand All @@ -15,6 +15,9 @@
<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>
Expand All @@ -23,21 +26,21 @@
<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"/>
Expand All @@ -48,11 +51,16 @@
</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"/>
Expand All @@ -67,7 +75,7 @@
<meta.section type="since"/>
</appInfo>
<documentation>
[Enter the first release in which this extension point appears.]
3.34
</documentation>
</annotation>

Expand Down Expand Up @@ -98,5 +106,17 @@
</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
Expand Up @@ -111,7 +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.SemanticTokensProvider;
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 @@ -279,7 +279,7 @@ protected boolean removeEldestEntry(java.util.Map.Entry<String, Long> eldest) {
private BundleContext fBundleContext;

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

public static JavaPlugin getDefault() {
return fgJavaPlugin;
Expand Down Expand Up @@ -748,19 +748,19 @@ public IConfigurationElement getConfigurationElement(Object object) {
}
}

public SemanticTokensProvider[] getContributedSemanticTokensProviders() {
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 (SemanticTokensProvider) ce.createExecutableExtension("class"); //$NON-NLS-1$
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(SemanticTokensProvider[]::new);
}).filter(Objects::nonNull).toArray(ISemanticTokensProvider[]::new);
}
}
return fSemanticTokensProviders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import org.eclipse.jdt.core.manipulation.SharedASTProviderCore;

import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.text.java.SemanticTokensProvider;
import org.eclipse.jdt.ui.text.java.ISemanticTokensProvider;

import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingManager.HighlightedPosition;
Expand Down Expand Up @@ -394,9 +394,9 @@ public void aboutToBeReconciled() {
// Do nothing
}

private List<SemanticTokensProvider.SemanticToken> getContributedSemanticTokens(CompilationUnit ast) {
List<SemanticTokensProvider.SemanticToken> contributedTokens = new ArrayList<>();
for (SemanticTokensProvider provider : JavaPlugin.getDefault().getContributedSemanticTokensProviders()) {
private List<ISemanticTokensProvider.SemanticToken> getContributedSemanticTokens(CompilationUnit ast) {
List<ISemanticTokensProvider.SemanticToken> contributedTokens = new ArrayList<>();
for (ISemanticTokensProvider provider : JavaPlugin.getDefault().getContributedSemanticTokensProviders()) {
contributedTokens.addAll(provider.computeSemanticTokens(ast));
}
return contributedTokens;
Expand Down Expand Up @@ -491,13 +491,13 @@ private void startReconcilingPositions() {
* @param subtrees the AST subtrees
* @param contributedTokens contributed semantic tokens data
*/
private void reconcilePositions(ASTNode[] subtrees, List<SemanticTokensProvider.SemanticToken> contributedTokens) {
private void reconcilePositions(ASTNode[] subtrees, List<ISemanticTokensProvider.SemanticToken> contributedTokens) {
// FIXME: remove positions not covered by subtrees

for (ASTNode subtree : subtrees)
subtree.accept(fCollector);

for (SemanticTokensProvider.SemanticToken t : contributedTokens) {
for (ISemanticTokensProvider.SemanticToken t : contributedTokens) {
Highlighting h = fromSemanticTokenType(t.tokenType());
if (h == null) {
JavaPlugin.logErrorMessage("Cannot find semantic highlighting for %s".formatted(t)); //$NON-NLS-1$
Expand All @@ -514,7 +514,7 @@ private void reconcilePositions(ASTNode[] subtrees, List<SemanticTokensProvider.
fRemovedPositions= newPositions;
}

private Highlighting fromSemanticTokenType(SemanticTokensProvider.TokenType type) {
private Highlighting fromSemanticTokenType(ISemanticTokensProvider.TokenType type) {
if (type != null) {
switch (type) {
case OPERATOR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

Check warning on line 17 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/java/ISemanticTokensProvider.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Other

ERROR: Missing @SInCE tag on org.eclipse.jdt.ui.text.java.ISemanticTokensProvider
public interface SemanticTokensProvider {
public interface ISemanticTokensProvider {

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

Expand Down

0 comments on commit a0c21c6

Please sign in to comment.