diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java index 70274d587d7..51ab03cba58 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacMethodBinding.java @@ -35,22 +35,24 @@ import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.JavacBindingResolver; -import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.TypeParameter; +import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import org.eclipse.jdt.internal.core.Member; +import org.eclipse.jdt.internal.core.ResolvedSourceMethod; +import org.eclipse.jdt.internal.core.SourceMethod; import org.eclipse.jdt.internal.core.util.Util; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; -import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.ForAll; import com.sun.tools.javac.code.Type.JCNoType; import com.sun.tools.javac.code.Type.MethodType; @@ -276,7 +278,7 @@ private IJavaElement getJavaElementForMethodDeclaration(IType currentType, Metho }).toArray(String[]::new); IMethod result = currentType.getMethod(getName(), params); if (currentType.isBinary() || result.exists()) { - return result; + return resolved(result); } IMethod[] methods = null; try { @@ -288,9 +290,16 @@ private IJavaElement getJavaElementForMethodDeclaration(IType currentType, Metho IMethod[] candidates = Member.findMethods(result, methods); if (candidates == null || candidates.length == 0) return null; - return candidates[0]; + return resolved(candidates[0]); } - + + private IMethod resolved(IMethod from) { + if (from instanceof SourceMethod sourceMethod && !(from instanceof ResolvedSourceMethod)) { + return new ResolvedSourceMethod(sourceMethod.getParent(), sourceMethod.getElementName(), sourceMethod.getParameterTypes(), getKey(), sourceMethod.getOccurrenceCount()); + } + return from; + } + private IJavaElement getJavaElementForAnnotationTypeMemberDeclaration(IType currentType, AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration) { IMethod result = currentType.getMethod(getName(), new String[0]); if (currentType.isBinary() || result.exists()) { diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java index e0110d61b73..88a2e8ec610 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeBinding.java @@ -52,20 +52,25 @@ import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.JavacBindingResolver; -import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.RecordDeclaration; import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import org.eclipse.jdt.internal.compiler.codegen.ConstantPool; +import org.eclipse.jdt.internal.core.JavaElement; +import org.eclipse.jdt.internal.core.ResolvedSourceType; import org.eclipse.jdt.internal.core.SourceType; import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Kinds; +import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Type; +import com.sun.tools.javac.code.TypeTag; +import com.sun.tools.javac.code.Types; import com.sun.tools.javac.code.Kinds.Kind; import com.sun.tools.javac.code.Kinds.KindSelector; -import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.code.Symbol.MethodSymbol; @@ -74,7 +79,6 @@ import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symbol.TypeVariableSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; -import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.ArrayType; import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ErrorType; @@ -84,8 +88,6 @@ import com.sun.tools.javac.code.Type.MethodType; import com.sun.tools.javac.code.Type.TypeVar; import com.sun.tools.javac.code.Type.WildcardType; -import com.sun.tools.javac.code.TypeTag; -import com.sun.tools.javac.code.Types; import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError; import com.sun.tools.javac.util.Name; @@ -198,17 +200,17 @@ public IJavaElement getJavaElement() { if (isAnonymous()) { if (getDeclaringMethod() != null && getDeclaringMethod().getJavaElement() instanceof IMethod method) { // TODO find proper occurenceCount (eg checking the source range) - return method.getType("", 1); + return resolved(method.getType("", 1)); } else if( getDeclaringMember() instanceof IBinding gdm && gdm != null && gdm.getJavaElement() instanceof IField field) { - return field.getType("", 1); + return resolved(field.getType("", 1)); } else if (getDeclaringClass() != null && getDeclaringClass().getJavaElement() instanceof IType type) { - return type.getType("", 1); + return resolved(type.getType("", 1)); } } if( this.typeSymbol.owner instanceof MethodSymbol) { if (getDeclaringMethod() != null && getDeclaringMethod().getJavaElement() instanceof IMethod method) { // TODO find proper occurenceCount (eg checking the source range) - return method.getType(this.typeSymbol.name.toString(), 1); + return resolved(method.getType(this.typeSymbol.name.toString(), 1)); } } @@ -247,22 +249,29 @@ public IJavaElement getJavaElement() { done |= (candidate == null); } if(candidate != null && candidate.exists()) { - return candidate; + return resolved(candidate); } } try { IType ret = this.resolver.javaProject.findType(cleanedUpName(this.type), this.resolver.getWorkingCopyOwner(), new NullProgressMonitor()); if (ret != null) { - return ret; + return resolved(ret); } } catch (JavaModelException ex) { ILog.get().error(ex.getMessage(), ex); } - return candidate; + return resolved(candidate); } return null; } + private IType resolved(IType type) { + if (type instanceof SourceType && !(type instanceof ResolvedSourceType)) { + return new ResolvedSourceType((JavaElement)type.getParent(), type.getElementName(), getKey(), type.getOccurrenceCount()); + } + return type; + } + private static String cleanedUpName(Type type) { if (type instanceof ClassType classType && classType.getEnclosingType() instanceof ClassType enclosing) { return cleanedUpName(enclosing) + "$" + type.tsym.getSimpleName().toString(); diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacVariableBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacVariableBinding.java index 071fb616e21..6a8b6be38a1 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacVariableBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacVariableBinding.java @@ -14,6 +14,7 @@ import java.util.Objects; import org.eclipse.core.runtime.ILog; +import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; @@ -27,7 +28,6 @@ import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.JavacBindingResolver; -import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import org.eclipse.jdt.core.dom.LambdaExpression; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; @@ -35,20 +35,23 @@ import org.eclipse.jdt.core.dom.VariableDeclarationExpression; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import org.eclipse.jdt.internal.core.DOMToModelPopulator; import org.eclipse.jdt.internal.core.JavaElement; import org.eclipse.jdt.internal.core.LambdaMethod; import org.eclipse.jdt.internal.core.LocalVariable; +import org.eclipse.jdt.internal.core.ResolvedSourceField; +import org.eclipse.jdt.internal.core.SourceField; import org.eclipse.jdt.internal.core.util.Util; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Kinds; import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; -import com.sun.tools.javac.code.Type; public abstract class JavacVariableBinding implements IVariableBinding { @@ -115,7 +118,7 @@ public IJavaElement getJavaElement() { if (this.variableSymbol.owner instanceof TypeSymbol parentType // field && parentType.type != null && this.resolver.bindings.getTypeBinding(parentType.type).getJavaElement() instanceof IType type) { - return type.getField(this.variableSymbol.name.toString()); + return resolved(type.getField(this.variableSymbol.name.toString())); } IMethodBinding methodBinding = getDeclaringMethod(); if (methodBinding != null && methodBinding.getJavaElement() instanceof IMethod method) { @@ -153,6 +156,13 @@ public IJavaElement getJavaElement() { return null; } + private IField resolved(IField field) { + if (field instanceof SourceField sourceField && !(sourceField instanceof ResolvedSourceField)) { + return new ResolvedSourceField(sourceField.getParent(), sourceField.getElementName(), getKey(), sourceField.getOccurrenceCount()); + } + return field; + } + @Override public String getKey() { try {