use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class Issue200 method issue200.
@Test
public void issue200() {
CompilationUnit cu = parseSample("Issue200");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
List<ReturnStmt> nodesByType = methodDeclaration.findAll(ReturnStmt.class);
assertEquals("java.util.stream.Stream<JavaTest.Solved>", javaParserFacade.getType((nodesByType.get(0)).getExpression().get()).describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class Issue228 method testSolvingMethodWitPrimitiveParameterTypeAsUsage.
@Test
public void testSolvingMethodWitPrimitiveParameterTypeAsUsage() {
String code = "class Test { " + " long l = call(1); " + " long call(final long i) { " + " return i; " + " }" + "}";
CompilationUnit cu = JavaParser.parse(code);
MethodCallExpr methodCall = cu.findAll(MethodCallExpr.class).get(0);
JavaParserFacade parserFacade = JavaParserFacade.get(new ReflectionTypeSolver());
MethodUsage solvedCall = parserFacade.solveMethodAsUsage(methodCall);
assertEquals("long", solvedCall.getParamType(0).describe());
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class Issue128 method setup.
@Before
public void setup() throws IOException {
File srcDir = adaptPath(new File("src/test/resources/issue128"));
typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(srcDir));
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class TypeCompatibleWithType method reduce.
@Override
public ReductionResult reduce(BoundSet currentBoundSet) {
if (isProperType(s) && isProperType(t)) {
if (isCompatibleInALooseInvocationContext(s, t)) {
return ReductionResult.trueResult();
} else {
return ReductionResult.falseResult();
}
}
if (s.isPrimitive()) {
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType sFirst = new ReferenceTypeImpl(typeSolver.solveType(s.asPrimitive().getBoxTypeQName()), typeSolver);
return ReductionResult.oneConstraint(new TypeCompatibleWithType(typeSolver, sFirst, t));
}
if (t.isPrimitive()) {
ReflectionTypeSolver typeSolver = new ReflectionTypeSolver();
ResolvedType tFirst = new ReferenceTypeImpl(typeSolver.solveType(t.asPrimitive().getBoxTypeQName()), typeSolver);
return ReductionResult.oneConstraint(new TypeSameAsType(s, tFirst));
}
if (t.isReferenceType() && !t.asReferenceType().getTypeDeclaration().getTypeParameters().isEmpty()) {
// FIXME I really cannot understand what the specification means...
// there exists a type of the form G<...> that is a supertype of S?
boolean condition1 = t.isAssignableBy(s);
// the raw type G is a supertype of S
ResolvedType G = t.asReferenceType().toRawType();
boolean condition2 = G.isAssignableBy(s);
if (!condition1 && condition2) {
return ReductionResult.trueResult();
}
// throw new UnsupportedOperationException();
}
if (t.isArray()) {
throw new UnsupportedOperationException();
}
return ReductionResult.empty().withConstraint(new TypeSubtypeOfType(typeSolver, s, t));
}
use of com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver in project javaparser by javaparser.
the class EnumResolutionTest method enumAndStaticInitializer.
@Test
public void enumAndStaticInitializer() {
CompilationUnit cu = parseSample("EnumAndStaticInitializer");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "MyClass");
MethodCallExpr call = Navigator.findMethodCall(clazz, "put").get();
ResolvedType ref = JavaParserFacade.get(new ReflectionTypeSolver()).getType(call);
assertEquals("MyClass.Primitive", ref.describe());
}
Aggregations