From 4cb1274aaf47ea4db1dd8b0a9a3997e29cb99eec Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Fri, 19 Apr 2024 11:10:43 -0400 Subject: [PATCH] Fix part of testAnnotateClassTypeParameter1 Signed-off-by: Rob Stryker --- .../internal/javac/dom/JavacTypeBinding.java | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) 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 d90d5b57a0f..ce33b1849c9 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 @@ -27,20 +27,23 @@ import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.JavacBindingResolver; import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.codegen.ConstantPool; 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.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.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.TypeVar; import com.sun.tools.javac.code.Type.WildcardType; -import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError; import com.sun.tools.javac.code.Types; -import com.sun.tools.javac.code.Kinds; +import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError; public class JavacTypeBinding implements ITypeBinding { @@ -109,8 +112,11 @@ public IType getJavaElement() { @Override public String getKey() { + return getKey(this.typeSymbol.type); + } + public String getKey(Type t) { StringBuilder builder = new StringBuilder(); - getKey(builder, this.typeSymbol.type, false); + getKey(builder, t, false); return builder.toString(); } @@ -322,9 +328,20 @@ public IMethodBinding getFunctionalInterfaceMethod() { @Override public ITypeBinding[] getInterfaces() { - return this.typeSymbol instanceof final ClassSymbol classSymbol && classSymbol.getInterfaces() != null ? - classSymbol.getInterfaces().map(t -> new JavacTypeBinding(t, this.resolver, null)).toArray(ITypeBinding[]::new) : - null; + if (this.typeSymbol instanceof final TypeVariableSymbol typeVarSymb && typeVarSymb.type instanceof TypeVar tv) { + Type t = tv.getUpperBound(); + if( t.tsym instanceof ClassSymbol cs) { + JavacTypeBinding jtb = new JavacTypeBinding(t, this.resolver, null); + if( jtb.isInterface()) { + return new ITypeBinding[] {jtb}; + } + } + } + + if( this.typeSymbol instanceof final ClassSymbol classSymbol && classSymbol.getInterfaces() != null ) { + return classSymbol.getInterfaces().map(t -> new JavacTypeBinding(t, this.resolver, null)).toArray(ITypeBinding[]::new); + } + return new ITypeBinding[0]; } @Override @@ -351,9 +368,29 @@ public String getQualifiedName() { @Override public ITypeBinding getSuperclass() { + if (this.typeSymbol instanceof final TypeVariableSymbol classSymbol && classSymbol.type instanceof TypeVar tv) { + Type t = tv.getUpperBound(); + JavacTypeBinding possible = new JavacTypeBinding(t.tsym, this.resolver, null); + if( !possible.isInterface()) { + return possible; + } + if( t instanceof ClassType ct ) { + // we need to return java.lang.object + ClassType working = ct; + while( working != null ) { + Type wt = working.supertype_field; + String sig = getKey(wt); + if( new String(ConstantPool.JavaLangObjectSignature).equals(sig)) { + return new JavacTypeBinding(wt.tsym, this.resolver, null); + } + working = wt instanceof ClassType ? (ClassType)wt : null; + } + } + } if (this.typeSymbol instanceof final ClassSymbol classSymbol && classSymbol.getSuperclass() != null && classSymbol.getSuperclass().tsym != null) { return new JavacTypeBinding(classSymbol.getSuperclass().tsym, this.resolver, null); } + return null; }