use of com.github.javaparser.ast.CompilationUnit 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.ast.CompilationUnit in project javaparser by javaparser.
the class Issue276 method testSolveStaticallyImportedMemberType.
@Test
public void testSolveStaticallyImportedMemberType() throws FileNotFoundException {
CompilationUnit cu = JavaParser.parse(new File(adaptPath("src/test/resources/issue276/foo/C.java")));
ClassOrInterfaceDeclaration cls = Navigator.demandClassOrInterface(cu, "C");
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(adaptPath(new File("src/test/resources/issue276"))));
List<MethodDeclaration> methods = cls.findAll(MethodDeclaration.class);
boolean isSolved = false;
for (MethodDeclaration method : methods) {
if (method.getNameAsString().equals("overrideMe")) {
MethodContext context = new MethodContext(method, typeSolver);
isSolved = context.solveType("FindMeIfYouCan", typeSolver).isSolved();
}
}
Assert.assertTrue(isSolved);
}
use of com.github.javaparser.ast.CompilationUnit 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.ast.CompilationUnit in project javaparser by javaparser.
the class Issue347 method resolvingReferenceToEnumDeclarationInSameFile.
@Test
public void resolvingReferenceToEnumDeclarationInSameFile() {
String code = "package foo.bar;\nenum Foo {\n" + " FOO_A, FOO_B\n" + "}\n" + "\n" + "class UsingFoo {\n" + " Foo myFooField;\n" + "}";
CompilationUnit cu = JavaParser.parse(code);
FieldDeclaration fieldDeclaration = Navigator.findNodeOfGivenClass(cu, FieldDeclaration.class);
ResolvedType fieldType = javaParserFacade.getType(fieldDeclaration);
assertEquals(true, fieldType.isReferenceType());
assertEquals(true, fieldType.asReferenceType().getTypeDeclaration().isEnum());
assertEquals("foo.bar.Foo", fieldType.asReferenceType().getQualifiedName());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class JavaParserAPIIntegrationTest method enumConstantDeclarationResolve.
@Test
public void enumConstantDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/test_sourcecode/javaparser_new_src/javaparser-core/com/github/javaparser/ast/AccessSpecifier.java"));
CompilationUnit cu = parseWithSymbolResolution(f);
EnumDeclaration enumDeclaration = (EnumDeclaration) cu.getType(0);
assertEquals("AccessSpecifier", enumDeclaration.getNameAsString());
EnumConstantDeclaration declaration = enumDeclaration.getEntry(0);
assertEquals("PUBLIC", declaration.getNameAsString());
ResolvedEnumConstantDeclaration resolvedDeclaration = declaration.resolve();
}
Aggregations