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 ad8c236bfb2..a42212f9599 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 @@ -42,7 +42,6 @@ import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Attribute.Compound; import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.code.Symbol.PackageSymbol; @@ -98,61 +97,109 @@ public class JavacBindingResolver extends BindingResolver { private JavacConverter converter; boolean isRecoveringBindings = false; + public static class BindingKeyException extends Exception { + private static final long serialVersionUID = -4468681148041117634L; + public BindingKeyException(Throwable t) { + super(t); + } + public BindingKeyException(String message, Throwable cause) { + super(message, cause); + } + } + public class Bindings { private Map annotationBindings = new HashMap<>(); public JavacAnnotationBinding getAnnotationBinding(Compound ann, IBinding recipient) { JavacAnnotationBinding newInstance = new JavacAnnotationBinding(ann, JavacBindingResolver.this, recipient) { }; - annotationBindings.putIfAbsent(newInstance.getKey(), newInstance); - return annotationBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + annotationBindings.putIfAbsent(k, newInstance); + return annotationBindings.get(k); + } + return null; } // private Map memberValuePairBindings = new HashMap<>(); public JavacMemberValuePairBinding getMemberValuePairBinding(MethodSymbol key, Attribute value) { JavacMemberValuePairBinding newInstance = new JavacMemberValuePairBinding(key, value, JavacBindingResolver.this) { }; - memberValuePairBindings.putIfAbsent(newInstance.getKey(), newInstance); - return memberValuePairBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + memberValuePairBindings.putIfAbsent(k, newInstance); + return memberValuePairBindings.get(k); + } + return null; } // private Map methodBindings = new HashMap<>(); public JavacMethodBinding getMethodBinding(MethodType methodType, MethodSymbol methodSymbol) { JavacMethodBinding newInstance = new JavacMethodBinding(methodType, methodSymbol, JavacBindingResolver.this) { }; - methodBindings.putIfAbsent(newInstance.getKey(), newInstance); - return methodBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + methodBindings.putIfAbsent(k, newInstance); + return methodBindings.get(k); + } + return null; } public JavacMethodBinding getErrorMethodBinding(MethodType methodType, Symbol originatingSymbol) { JavacMethodBinding newInstance = new JavacErrorMethodBinding(originatingSymbol, methodType, JavacBindingResolver.this) { }; - methodBindings.putIfAbsent(newInstance.getKey(), newInstance); - return methodBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + methodBindings.putIfAbsent(k, newInstance); + return methodBindings.get(k); + } + return null; } // private Map moduleBindings = new HashMap<>(); public JavacModuleBinding getModuleBinding(ModuleType moduleType) { JavacModuleBinding newInstance = new JavacModuleBinding(moduleType, JavacBindingResolver.this) { }; - moduleBindings.putIfAbsent(newInstance.getKey(), newInstance); - return moduleBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + moduleBindings.putIfAbsent(k, newInstance); + return moduleBindings.get(k); + } + return null; } public JavacModuleBinding getModuleBinding(ModuleSymbol moduleSymbol) { JavacModuleBinding newInstance = new JavacModuleBinding(moduleSymbol, JavacBindingResolver.this) { }; - moduleBindings.putIfAbsent(newInstance.getKey(), newInstance); - return moduleBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + moduleBindings.putIfAbsent(k, newInstance); + return moduleBindings.get(k); + } + return null; } public JavacModuleBinding getModuleBinding(JCModuleDecl moduleDecl) { JavacModuleBinding newInstance = new JavacModuleBinding(moduleDecl, JavacBindingResolver.this) { }; // Overwrite existing - moduleBindings.put(newInstance.getKey(), newInstance); - return moduleBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + moduleBindings.put(k, newInstance); + return moduleBindings.get(k); + } + return null; } // private Map packageBindings = new HashMap<>(); public JavacPackageBinding getPackageBinding(PackageSymbol packageSymbol) { JavacPackageBinding newInstance = new JavacPackageBinding(packageSymbol, JavacBindingResolver.this) { }; - packageBindings.putIfAbsent(newInstance.getKey(), newInstance); - return packageBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + packageBindings.putIfAbsent(k, newInstance); + return packageBindings.get(k); + } + return null; } // private Map typeBinding = new HashMap<>(); + public JavacTypeBinding getTypeBinding(JCTree tree, com.sun.tools.javac.code.Type type) { + return getTypeBinding(type, tree instanceof JCClassDecl); + } public JavacTypeBinding getTypeBinding(com.sun.tools.javac.code.Type type) { + return getTypeBinding(type, false); + } + public JavacTypeBinding getTypeBinding(com.sun.tools.javac.code.Type type, boolean isDeclaration) { if (type instanceof com.sun.tools.javac.code.Type.TypeVar typeVar) { return getTypeVariableBinding(typeVar); } @@ -164,36 +211,52 @@ public JavacTypeBinding getTypeBinding(com.sun.tools.javac.code.Type type) { && !(errorType.getOriginalType() instanceof com.sun.tools.javac.code.Type.MethodType) && !(errorType.getOriginalType() instanceof com.sun.tools.javac.code.Type.ForAll) && !(errorType.getOriginalType() instanceof com.sun.tools.javac.code.Type.ErrorType)) { - JavacTypeBinding newInstance = new JavacTypeBinding(errorType.getOriginalType(), type.tsym, JavacBindingResolver.this) { }; + JavacTypeBinding newInstance = new JavacTypeBinding(errorType.getOriginalType(), type.tsym, isDeclaration, JavacBindingResolver.this) { }; typeBinding.putIfAbsent(newInstance.getKey(), newInstance); JavacTypeBinding jcb = typeBinding.get(newInstance.getKey()); jcb.setRecovered(true); return jcb; } - JavacTypeBinding newInstance = new JavacTypeBinding(type, type.tsym, JavacBindingResolver.this) { }; - typeBinding.putIfAbsent(newInstance.getKey(), newInstance); - return typeBinding.get(newInstance.getKey()); + JavacTypeBinding newInstance = new JavacTypeBinding(type, type.tsym, isDeclaration, JavacBindingResolver.this) { }; + String k = newInstance.getKey(); + if( k != null ) { + typeBinding.putIfAbsent(k, newInstance); + return typeBinding.get(k); + } + return null; } // private Map typeVariableBindings = new HashMap<>(); public JavacTypeVariableBinding getTypeVariableBinding(TypeVar typeVar) { JavacTypeVariableBinding newInstance = new JavacTypeVariableBinding(typeVar, (TypeVariableSymbol)typeVar.tsym, JavacBindingResolver.this) { }; - typeVariableBindings.putIfAbsent(newInstance.getKey(), newInstance); - return typeVariableBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + typeVariableBindings.putIfAbsent(k, newInstance); + return typeVariableBindings.get(k); + } + return null; } // private Map variableBindings = new HashMap<>(); public JavacVariableBinding getVariableBinding(VarSymbol varSymbol) { JavacVariableBinding newInstance = new JavacVariableBinding(varSymbol, JavacBindingResolver.this) { }; - variableBindings.putIfAbsent(newInstance.getKey(), newInstance); - return variableBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + variableBindings.putIfAbsent(k, newInstance); + return variableBindings.get(k); + } + return null; } // private Map lambdaBindings = new HashMap<>(); public JavacLambdaBinding getLambdaBinding(JavacMethodBinding javacMethodBinding) { JavacLambdaBinding newInstance = new JavacLambdaBinding(javacMethodBinding); - lambdaBindings.putIfAbsent(newInstance.getKey(), newInstance); - return lambdaBindings.get(newInstance.getKey()); + String k = newInstance.getKey(); + if( k != null ) { + lambdaBindings.putIfAbsent(k, newInstance); + return lambdaBindings.get(k); + } + return null; } public IBinding getBinding(final Symbol owner, final com.sun.tools.javac.code.Type type) { @@ -445,7 +508,7 @@ ITypeBinding resolveType(TypeDeclaration type) { resolve(); JCTree javacNode = this.converter.domToJavac.get(type); if (javacNode instanceof JCClassDecl jcClassDecl && jcClassDecl.type != null) { - return this.bindings.getTypeBinding(jcClassDecl.type); + return this.bindings.getTypeBinding(jcClassDecl.type, true); } return null; } diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java index 8069ab92751..b0a4e85201e 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacAnnotationBinding.java @@ -103,6 +103,7 @@ public boolean isEqualTo(IBinding binding) { public IMemberValuePairBinding[] getAllMemberValuePairs() { return this.annotation.getElementValues().entrySet().stream() .map(entry -> this.resolver.bindings.getMemberValuePairBinding(entry.getKey(), entry.getValue())) + .filter(Objects::nonNull) .toArray(IMemberValuePairBinding[]::new); } diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacErrorMethodBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacErrorMethodBinding.java index 074267f8673..3efd199de34 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacErrorMethodBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacErrorMethodBinding.java @@ -16,6 +16,7 @@ import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.JavacBindingResolver; +import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; @@ -35,6 +36,13 @@ public JavacErrorMethodBinding(Symbol originatingSymbol, MethodType methodType, @Override public String getKey() { + try { + return getKeyImpl(); + } catch(BindingKeyException bke) { + return null; + } + } + private String getKeyImpl() throws BindingKeyException { StringBuilder builder = new StringBuilder(); if (this.originatingSymbol instanceof TypeSymbol typeSymbol) { JavacTypeBinding.getKey(builder, resolver.getTypes().erasure(typeSymbol.type), false); 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 695399481f1..f92e656e19e 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 @@ -33,6 +33,7 @@ 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; @@ -254,12 +255,16 @@ private String resolveTypeName(com.sun.tools.javac.code.Type type, boolean binar @Override public String getKey() { - StringBuilder builder = new StringBuilder(); - getKey(builder, this.methodSymbol, this.methodType, this.resolver); - return builder.toString(); + try { + StringBuilder builder = new StringBuilder(); + getKey(builder, this.methodSymbol, this.methodType, this.resolver); + return builder.toString(); + } catch(BindingKeyException bke) { + return null; + } } - static void getKey(StringBuilder builder, MethodSymbol methodSymbol, MethodType methodType, JavacBindingResolver resolver) { + static void getKey(StringBuilder builder, MethodSymbol methodSymbol, MethodType methodType, JavacBindingResolver resolver) throws BindingKeyException { Symbol ownerSymbol = methodSymbol.owner; while (ownerSymbol != null && !(ownerSymbol instanceof TypeSymbol)) { ownerSymbol = ownerSymbol.owner; @@ -267,7 +272,7 @@ static void getKey(StringBuilder builder, MethodSymbol methodSymbol, MethodType if (ownerSymbol instanceof TypeSymbol ownerTypeSymbol) { JavacTypeBinding.getKey(builder, resolver.getTypes().erasure(ownerTypeSymbol.type), false); } else { - throw new IllegalArgumentException("Method has no owning class"); + throw new BindingKeyException(new IllegalArgumentException("Method has no owning class")); } builder.append('.'); if (!methodSymbol.isConstructor()) { 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 1e68834c17b..4e92c74ca6e 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 @@ -46,6 +46,7 @@ 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.Modifier; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.internal.compiler.codegen.ConstantPool; @@ -58,6 +59,7 @@ 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; import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.code.Symbol.RootPackageSymbol; @@ -88,13 +90,15 @@ public abstract class JavacTypeBinding implements ITypeBinding { public final TypeSymbol typeSymbol; private final Types types; private final Type type; + private boolean isDeclaration; private boolean recovered = false; - public JavacTypeBinding(final Type type, final TypeSymbol typeSymbol, JavacBindingResolver resolver) { + public JavacTypeBinding(final Type type, final TypeSymbol typeSymbol, boolean isDeclaration, JavacBindingResolver resolver) { if (type instanceof PackageType) { throw new IllegalArgumentException("Use JavacPackageBinding"); } this.type = type; + this.isDeclaration = isDeclaration; this.resolver = resolver; this.types = Types.instance(this.resolver.context); // TODO: consider getting rid of typeSymbol in constructor and always derive it from type @@ -250,16 +254,24 @@ public String getKey(Type t) { return getKey(t, this.typeSymbol.flatName()); } public String getKey(Type t, Name n) { - StringBuilder builder = new StringBuilder(); - getKey(builder, t, n, false); - return builder.toString(); + try { + StringBuilder builder = new StringBuilder(); + getKey(builder, t, n, false, true); + return builder.toString(); + } catch(BindingKeyException bke) { + return null; + } } - static void getKey(StringBuilder builder, Type typeToBuild, boolean isLeaf) { - getKey(builder, typeToBuild, typeToBuild.asElement().flatName(), isLeaf); + static void getKey(StringBuilder builder, Type typeToBuild, boolean isLeaf) throws BindingKeyException { + getKey(builder, typeToBuild, typeToBuild.asElement().flatName(), isLeaf, false); + } + + static void getKey(StringBuilder builder, Type typeToBuild, boolean isLeaf, boolean includeParameters) throws BindingKeyException { + getKey(builder, typeToBuild, typeToBuild.asElement().flatName(), isLeaf, includeParameters); } - static void getKey(StringBuilder builder, Type typeToBuild, Name n, boolean isLeaf) { + static void getKey(StringBuilder builder, Type typeToBuild, Name n, boolean isLeaf, boolean includeParameters) throws BindingKeyException { if (typeToBuild instanceof Type.JCNoType) { return; } @@ -269,7 +281,7 @@ static void getKey(StringBuilder builder, Type typeToBuild, Name n, boolean isLe } if (typeToBuild instanceof ArrayType arrayType) { builder.append('['); - getKey(builder, arrayType.elemtype, isLeaf); + getKey(builder, arrayType.elemtype, isLeaf, includeParameters); return; } if (typeToBuild instanceof Type.WildcardType wildcardType) { @@ -277,10 +289,10 @@ static void getKey(StringBuilder builder, Type typeToBuild, Name n, boolean isLe builder.append('*'); } else if (wildcardType.isExtendsBound()) { builder.append('+'); - getKey(builder, wildcardType.getExtendsBound(), isLeaf); + getKey(builder, wildcardType.getExtendsBound(), isLeaf, includeParameters); } else if (wildcardType.isSuperBound()) { builder.append('-'); - getKey(builder, wildcardType.getSuperBound(), isLeaf); + getKey(builder, wildcardType.getSuperBound(), isLeaf, includeParameters); } return; } @@ -293,10 +305,17 @@ static void getKey(StringBuilder builder, Type typeToBuild, Name n, boolean isLe } } builder.append(n.toString().replace('.', '/')); - if (typeToBuild.isParameterized()) { + boolean b1 = typeToBuild.isParameterized(); + boolean b2 = false; + try { + b2 = typeToBuild.tsym != null && typeToBuild.tsym.type != null && typeToBuild.tsym.type.isParameterized(); + } catch( CompletionFailure cf1) { + throw new BindingKeyException(cf1); + } + if ((b1 || b2) && includeParameters) { builder.append('<'); for (var typeArgument : typeToBuild.getTypeArguments()) { - getKey(builder, typeArgument, false); + getKey(builder, typeArgument, false, includeParameters); } builder.append('>'); } @@ -429,6 +448,7 @@ public IMethodBinding[] getDeclaredMethods() { Type.MethodType methodType = this.types.memberType(this.type, sym).asMethodType(); return this.resolver.bindings.getMethodBinding(methodType, sym); }) + .filter(Objects::nonNull) .toArray(IMethodBinding[]::new); } @@ -566,9 +586,11 @@ public String getName() { return builder.toString(); } StringBuilder builder = new StringBuilder(this.typeSymbol.getSimpleName().toString()); - if (this.getTypeArguments().length > 0) { + ITypeBinding[] types = this.getUncheckedTypeArguments(this.type, this.typeSymbol); + + if (types != null && types.length > 0) { builder.append("<"); - for (var typeArgument : this.getTypeArguments()) { + for (var typeArgument : types) { builder.append(typeArgument.getName()); } builder.append(">"); @@ -588,9 +610,9 @@ public IPackageBinding getPackage() { @Override public String getQualifiedName() { - return getQualifiedNameImpl(this.type, this.typeSymbol, this.typeSymbol.owner); + return getQualifiedNameImpl(this.type, this.typeSymbol, this.typeSymbol.owner, !this.isDeclaration); } - private String getQualifiedNameImpl(Type type, TypeSymbol typeSymbol, Symbol owner) { + private String getQualifiedNameImpl(Type type, TypeSymbol typeSymbol, Symbol owner, boolean includeParameters) { if (owner instanceof MethodSymbol) { return ""; } @@ -629,7 +651,7 @@ private String getQualifiedNameImpl(Type type, TypeSymbol typeSymbol, Symbol own return type == null || type.tsym == null || type.tsym.name == null ? "" : type.tsym.name.toString(); } else if( owner instanceof TypeSymbol tss) { Type parentType = (type instanceof ClassType ct && ct.getEnclosingType() != Type.noType ? ct.getEnclosingType() : tss.type); - String parentName = getQualifiedNameImpl(parentType, tss, tss.owner); + String parentName = getQualifiedNameImpl(parentType, tss, tss.owner, includeParameters); res.append(parentName); if( !"".equals(parentName)) { res.append("."); @@ -638,18 +660,22 @@ private String getQualifiedNameImpl(Type type, TypeSymbol typeSymbol, Symbol own } else { res.append(typeSymbol.toString()); } - ITypeBinding[] typeArguments = getUncheckedTypeArguments(type, typeSymbol); - boolean isTypeDeclaration = typeSymbol != null && typeSymbol.type == type; - if (!isTypeDeclaration && typeArguments.length > 0) { - res.append("<"); - int i; - for (i = 0; i < typeArguments.length - 1; i++) { + + if( includeParameters ) { + ITypeBinding[] typeArguments = getUncheckedTypeArguments(type, typeSymbol); + boolean isTypeDeclaration = typeSymbol != null && typeSymbol.type == type; + if (!isTypeDeclaration && typeArguments.length > 0) { + res.append("<"); + int i; + for (i = 0; i < typeArguments.length - 1; i++) { + res.append(typeArguments[i].getQualifiedName()); + res.append(","); + } res.append(typeArguments[i].getQualifiedName()); - res.append(","); + res.append(">"); } - res.append(typeArguments[i].getQualifiedName()); - res.append(">"); } + // remove annotations here int annotationIndex = -1; while ((annotationIndex = res.lastIndexOf("@")) >= 0) { @@ -715,7 +741,7 @@ public ITypeBinding[] getTypeArguments() { } private ITypeBinding[] getTypeArguments(Type t, TypeSymbol ts) { - if (t.getTypeArguments().isEmpty() || t == ts.type || isTargettingPreGenerics()) { + if (t == ts.type || t.getTypeArguments().isEmpty() || isTargettingPreGenerics()) { return NO_TYPE_ARGUMENTS; } return getUncheckedTypeArguments(t, ts); @@ -781,11 +807,12 @@ public ITypeBinding getTypeDeclaration() { @Override public ITypeBinding[] getTypeParameters() { - return !isRawType() && this.type instanceof ClassType classType - ? classType.getTypeArguments() + if( isRawType() || getTypeArguments() == NO_TYPE_ARGUMENTS || !(this.type instanceof ClassType)) { + return new ITypeBinding[0]; + } + return ((ClassType)this.type).getTypeArguments() .map(this.resolver.bindings::getTypeBinding) - .toArray(ITypeBinding[]::new) - : new ITypeBinding[0]; + .toArray(ITypeBinding[]::new); } @Override @@ -859,7 +886,7 @@ public boolean isFromSource() { @Override public boolean isGenericType() { - return this.type.isParameterized() && this.type.getTypeArguments().stream().anyMatch(TypeVar.class::isInstance); + return this.type.isParameterized() && getTypeArguments() != NO_TYPE_ARGUMENTS && this.type.getTypeArguments().stream().anyMatch(TypeVar.class::isInstance); } @Override diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeVariableBinding.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeVariableBinding.java index 0cc86e78974..d0a470a77d6 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeVariableBinding.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/dom/JavacTypeVariableBinding.java @@ -15,6 +15,7 @@ import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.JavacBindingResolver; +import org.eclipse.jdt.core.dom.JavacBindingResolver.BindingKeyException; import com.sun.tools.javac.code.Symbol.TypeVariableSymbol; import com.sun.tools.javac.code.Type.TypeVar; @@ -28,7 +29,7 @@ public abstract class JavacTypeVariableBinding extends JavacTypeBinding { private final JavacBindingResolver bindingResolver; public JavacTypeVariableBinding(TypeVar type, TypeVariableSymbol sym, JavacBindingResolver bindingResolver) { - super(type, sym, bindingResolver); + super(type, sym, false, bindingResolver); this.sym = sym; this.bindingResolver = bindingResolver; } @@ -57,8 +58,9 @@ public String getQualifiedName() { * this is the one that's used in method params and such, not the one that's actually used as it's final resting place (RIP) * @param sym * @return + * @throws BindingKeyException */ - static String getTypeVariableKey(TypeVariableSymbol sym) { + static String getTypeVariableKey(TypeVariableSymbol sym) throws BindingKeyException { StringBuilder builder = new StringBuilder(); builder.append(sym.getSimpleName()); builder.append(':'); 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 980eec73da8..f69d921d46d 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 @@ -25,6 +25,7 @@ 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.Modifier; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.VariableDeclaration; @@ -137,6 +138,13 @@ public IJavaElement getJavaElement() { @Override public String getKey() { + try { + return getKeyImpl(); + } catch(BindingKeyException bke) { + return null; + } + } + private String getKeyImpl() throws BindingKeyException { StringBuilder builder = new StringBuilder(); if (this.variableSymbol.owner instanceof ClassSymbol classSymbol) { JavacTypeBinding.getKey(builder, classSymbol.type, false);