Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LazyType(Function<Void, ResolvedType> provider) {
this.provider = provider;
}

private ResolvedType getType() {
public ResolvedType getType() {
if (concrete == null) {
concrete = provider.apply(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration.Bound;
import com.github.javaparser.resolution.model.typesystem.LazyType;
import com.github.javaparser.resolution.model.typesystem.NullType;
import com.github.javaparser.resolution.types.ResolvedReferenceType;
import com.github.javaparser.resolution.types.ResolvedType;
Expand Down Expand Up @@ -38,7 +39,11 @@ public ResolvedType lub(Set<ResolvedType> types) {

// The direct supertypes of the null type are all reference types other than the null type itself.
// One way to handle this case is to remove the type null from the list of types.
Set<ResolvedType> resolvedTypes = types.stream().filter(type -> !(type instanceof NullType)).collect(Collectors.toSet());
// Provides the concret type of Lazy type if needed
Set<ResolvedType> resolvedTypes = types.stream()
.filter(type -> !(type instanceof NullType))
.map(type -> concreteType(type))
.collect(Collectors.toSet());

// reduces the set in the presence of enumeration type because members are
// not equal and they do not have an explicit super type.
Expand Down Expand Up @@ -199,6 +204,13 @@ public ResolvedType lub(Set<ResolvedType> types) {
}
return erasedBest;
}

/*
* Provides concrete type of Lazy type
*/
private ResolvedType concreteType(ResolvedType type) {
return type instanceof LazyType ? LazyType.class.cast(type).getType() : type;
}

/*
* Check the type declaration if it is an enum
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.javaparser.symbolsolver;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

import com.github.javaparser.JavaParserAdapter;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.expr.ConditionalExpr;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest;

public class Issue3278Test extends AbstractResolutionTest {

@Test
void test() {
String code =
"public class Foo {\n"
+ " public static void main(String[] args) {\n"
+ " A a = null;\n"
+ " m((a == null ? \"null\" : a.getB()));\n"
+ " }\n"
+ " void m(Comparable<? extends Comparable> obj) {}\n"
+ " }\n"
+ "\n"
+ " class A{\n"
+ " private B b;\n"
+ " public A(B b){\n"
+ " this.b = b;\n"
+ " }\n"
+ " public B getB(){\n"
+ " return b;\n"
+ " }\n"
+ " }\n"
+ "\n"
+ " class B implements Comparable<B>{\n"
+ "\n"
+ " @Override\n"
+ " public int compareTo(B o) {\n"
+ " return 0;\n"
+ " }\n"
+ " }";

JavaParserAdapter parser = JavaParserAdapter.of(createParserWithResolver(defaultTypeSolver()));

CompilationUnit cu = parser.parse(code);

ConditionalExpr expr = cu.findFirst(ConditionalExpr.class).get();

assertEquals("java.lang.Comparable<? extends java.lang.Comparable>", expr.calculateResolvedType().describe());
}
}