Skip to content

Commit

Permalink
Fix isNested for type parameters
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Jul 8, 2024
1 parent 0ad2048 commit 0962b21
Showing 1 changed file with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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) {
Expand Down Expand Up @@ -680,6 +701,9 @@ public boolean isMember() {

@Override
public boolean isNested() {
if (this.isTypeVariable()) {
return false;
}
return getDeclaringClass() != null;
}

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 0962b21

Please sign in to comment.