diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java index 6250d9ab83e..33919fac008 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacBindingResolver.java @@ -30,7 +30,9 @@ import org.eclipse.jdt.internal.javac.dom.JavacTypeVariableBinding; import org.eclipse.jdt.internal.javac.dom.JavacVariableBinding; +import com.sun.source.util.DocTreePath; import com.sun.source.util.JavacTask; +import com.sun.tools.javac.api.JavacTrees; import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Attribute.Compound; import com.sun.tools.javac.code.Symbol; @@ -515,6 +517,10 @@ IBinding resolveName(Name name) { if( tree != null ) { return resolveNameToJavac(name, tree); } + DocTreePath path = this.converter.findDocTreePath(name); // TODO + if (path != null && JavacTrees.instance(this.context).getElement(path) instanceof Symbol symbol) { + return this.bindings.getBinding(symbol, null); + } if (tree == null && (name.getFlags() & ASTNode.ORIGINAL) != 0) { tree = this.converter.domToJavac.get(name.getParent()); if( tree instanceof JCFieldAccess jcfa) { diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index 9aa8dc057b4..b1117784d82 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -39,6 +39,8 @@ import com.sun.source.tree.CaseTree.CaseKind; import com.sun.source.tree.ModuleTree.ModuleKind; import com.sun.source.tree.Tree.Kind; +import com.sun.source.util.DocTreePath; +import com.sun.source.util.TreePath; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.parser.Tokens.Comment; @@ -135,6 +137,7 @@ class JavacConverter { final Map domToJavac = new HashMap<>(); final String rawText; final Set javadocDiagnostics = new HashSet<>(); + private final List javadocConverters = new ArrayList<>(); public JavacConverter(AST ast, JCCompilationUnit javacCompilationUnit, Context context, String rawText) { this.ast = ast; @@ -2882,7 +2885,8 @@ private Name convert(com.sun.tools.javac.util.Name javac, String selected) { public org.eclipse.jdt.core.dom.Comment convert(Comment javac, JCTree context) { if (javac.getStyle() == CommentStyle.JAVADOC && context != null) { var docCommentTree = this.javacCompilationUnit.docComments.getCommentTree(context); - JavadocConverter javadocConverter = new JavadocConverter(this, docCommentTree); + JavadocConverter javadocConverter = new JavadocConverter(this, docCommentTree, TreePath.getPath(this.javacCompilationUnit, context)); + this.javadocConverters.add(javadocConverter); Javadoc javadoc = javadocConverter.convertJavadoc(); this.javadocDiagnostics.addAll(javadocConverter.getDiagnostics()); return javadoc; @@ -3055,5 +3059,13 @@ private static List childrenOf(ASTNode node) { .toList(); } + public DocTreePath findDocTreePath(ASTNode node) { + return this.javadocConverters.stream() + .map(javadocConverter -> javadocConverter.converted.get(node)) + .filter(Objects::nonNull) + .findFirst() + .orElse(null); + } + } diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavadocConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavadocConverter.java index d985dcf489c..0570c79bdf5 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavadocConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavadocConverter.java @@ -13,8 +13,10 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -23,6 +25,10 @@ import org.eclipse.core.runtime.ILog; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.Tree; +import com.sun.source.util.DocTreePath; +import com.sun.source.util.TreePath; import com.sun.tools.javac.parser.UnicodeReader; import com.sun.tools.javac.tree.DCTree; import com.sun.tools.javac.tree.DCTree.DCAuthor; @@ -61,6 +67,9 @@ class JavadocConverter { private final DCDocComment docComment; private final int initialOffset; private final int endOffset; + private final TreePath contextTreePath; + + public final Map converted = new HashMap<>(); final private Set diagnostics = new HashSet<>(); @@ -75,10 +84,11 @@ class JavadocConverter { } } - JavadocConverter(JavacConverter javacConverter, DCDocComment docComment) { + JavadocConverter(JavacConverter javacConverter, DCDocComment docComment, TreePath contextTreePath) { this.javacConverter = javacConverter; this.ast = javacConverter.ast; this.docComment = docComment; + this.contextTreePath = contextTreePath; int startPos = -1; if (UNICODE_READER_CLASS_OFFSET_FIELD != null) { @@ -107,6 +117,7 @@ private void commonSettings(ASTNode res, DCTree javac) { length++; } res.setSourceRange(startPosition, length); + this.converted.put(res, DocTreePath.getPath(this.contextTreePath, this.docComment, javac)); } } @@ -379,6 +390,7 @@ private Stream convertElement(DCTree javac) { } else if (!signature.contains("#")) { Name res = this.ast.newName(signature); res.setSourceRange(this.docComment.getSourcePosition(javac.getStartPosition()), signature.length()); + this.converted.put(res, DocTreePath.getPath(this.contextTreePath, this.docComment, reference)); return Stream.of(res); } } else if (javac instanceof DCStartElement || javac instanceof DCEndElement || javac instanceof DCEntity) {