From 0962b21e5ffa4198105a356f95982560dd28da0d Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 26 Jun 2024 10:46:44 -0400 Subject: [PATCH] Fix isNested for type parameters Signed-off-by: David Thompson --- .../internal/javac/dom/JavacTypeBinding.java | 36 +++++++++++++++---- 1 file changed, 30 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 805483cf3bf..5e4ba89c6e0 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 @@ -24,6 +24,7 @@ import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.IAnnotationBinding; import org.eclipse.jdt.core.dom.IBinding; @@ -221,8 +222,8 @@ static void getKey(StringBuilder builder, Type typeToBuild, boolean isLeaf) { @Override public boolean isEqualTo(final IBinding binding) { - return binding instanceof final JavacTypeBinding other && - Objects.equals(this.resolver, other.resolver) && + return binding instanceof final JavacTypeBinding other && + Objects.equals(this.resolver, other.resolver) && Objects.equals(this.typeSymbol, other.typeSymbol); } @@ -439,7 +440,15 @@ public String getName() { } return builder.toString(); } - return this.typeSymbol.getSimpleName().toString(); + StringBuilder builder = new StringBuilder(this.typeSymbol.getSimpleName().toString()); + if (this.getTypeArguments().length > 0) { + builder.append("<"); + for (var typeArgument : this.getTypeArguments()) { + builder.append(typeArgument.getName()); + } + builder.append(">"); + } + return builder.toString(); } @Override @@ -528,7 +537,7 @@ public IAnnotationBinding[] getTypeAnnotations() { @Override public ITypeBinding[] getTypeArguments() { - if (this.type.getTypeArguments().isEmpty()) { + if (this.type.getTypeArguments().isEmpty() || this.type == this.typeSymbol.type || isTargettingPreGenerics()) { return NO_TYPE_ARGUMENTS; } return this.type.getTypeArguments() @@ -537,6 +546,18 @@ public ITypeBinding[] getTypeArguments() { .toArray(ITypeBinding[]::new); } + private boolean isTargettingPreGenerics() { + if (this.resolver.javaProject == null) { + return false; + } + String target = this.resolver.javaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); + return JavaCore.VERSION_1_1.equals(target) + || JavaCore.VERSION_CLDC_1_1.equals(target) + || JavaCore.VERSION_1_2.equals(target) + || JavaCore.VERSION_1_3.equals(target) + || JavaCore.VERSION_1_4.equals(target); + } + @Override public ITypeBinding[] getTypeBounds() { if (this.type instanceof ClassType classType) { @@ -680,6 +701,9 @@ public boolean isMember() { @Override public boolean isNested() { + if (this.isTypeVariable()) { + return false; + } return getDeclaringClass() != null; } @@ -746,8 +770,8 @@ public IModuleBinding getModule() { @Override public String toString() { return Arrays.stream(getAnnotations()) - .map(Object::toString) - .map(ann -> ann + " ") + .map(Object::toString) + .map(ann -> ann + " ") .collect(Collectors.joining()) + getQualifiedName(); }