use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue241 method testSolveStaticallyImportedMemberType.
@Test
public void testSolveStaticallyImportedMemberType() {
File src = adaptPath(new File("src/test/resources"));
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(src));
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
CompilationUnit cu = parseSample("Issue241");
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "Main");
VariableDeclarator v = Navigator.demandVariableDeclaration(cls, "foo").get();
Type t = v.getType();
ResolvedType t2 = javaParserFacade.convert(t, t);
String typeName = t2.asReferenceType().getQualifiedName();
assertEquals("issue241.TypeWithMemberType.MemberInterface", typeName);
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue300 method fieldAccessIssue.
@Test
public void fieldAccessIssue() throws ParseException, FileNotFoundException {
String pathToSourceFile = adaptPath("src/test/resources/issue300/Issue300.java");
CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
final FieldAccessExpr fieldAccess = Navigator.findNodeOfGivenClass(cu, FieldAccessExpr.class);
assertNotNull(fieldAccess);
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(adaptPath(new File("src/test/resources/issue300"))));
final JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
final SymbolReference<? extends ResolvedValueDeclaration> ref = javaParserFacade.solve(fieldAccess);
assertEquals(ResolvedPrimitiveType.INT, ref.getCorrespondingDeclaration().getType().asPrimitive());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue144 method issue144.
@Test(expected = UnsolvedSymbolException.class)
public void issue144() {
CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
ExpressionStmt expressionStmt = (ExpressionStmt) clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
Expression firstParameter = methodCallExpr.getArgument(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
javaParserFacade.solve(firstParameter).isSolved();
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue144 method issue144WithReflectionTypeSolver.
@Test
public void issue144WithReflectionTypeSolver() {
CompilationUnit cu = parseSampleWithStandardExtension("issue144/HelloWorld");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "HelloWorld");
ExpressionStmt expressionStmt = (ExpressionStmt) clazz.getMethodsByName("main").get(0).getBody().get().getStatement(0);
MethodCallExpr methodCallExpr = (MethodCallExpr) expressionStmt.getExpression();
Expression firstParameter = methodCallExpr.getArgument(0);
JavaParserFacade javaParserFacade = JavaParserFacade.get(new ReflectionTypeSolver(true));
assertEquals(true, javaParserFacade.solve(firstParameter).isSolved());
}
use of com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade in project javaparser by javaparser.
the class Issue186 method lambdaPrimitivesIssue.
@Test
public void lambdaPrimitivesIssue() {
CompilationUnit cu = parseSample("Issue186");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "bar");
List<LambdaExpr> lambdas = methodDeclaration.findAll(LambdaExpr.class);
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
assertEquals("java.util.function.Predicate<? super java.lang.String>", javaParserFacade.getType(lambdas.get(0)).describe());
assertEquals("java.util.function.Function<? super java.lang.String, ? extends java.lang.Integer>", javaParserFacade.getType(lambdas.get(1)).describe());
assertEquals("java.util.function.Predicate<? super java.lang.Integer>", javaParserFacade.getType(lambdas.get(2)).describe());
}
Aggregations