use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class VisitorGenerator method generate.
public final void generate() throws Exception {
Log.info("Running %s", getClass().getSimpleName());
final CompilationUnit compilationUnit = sourceRoot.tryToParse(pkg, visitorClassName + ".java").getResult().get();
Optional<ClassOrInterfaceDeclaration> visitorClassOptional = compilationUnit.getClassByName(visitorClassName);
if (!visitorClassOptional.isPresent()) {
visitorClassOptional = compilationUnit.getInterfaceByName(visitorClassName);
}
final ClassOrInterfaceDeclaration visitorClass = visitorClassOptional.get();
JavaParserMetaModel.getNodeMetaModels().stream().filter((baseNodeMetaModel) -> !baseNodeMetaModel.isAbstract()).forEach(node -> generateVisitMethodForNode(node, visitorClass, compilationUnit));
after();
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class NoCommentHashCodeVisitorTest method testEquals.
@Test
public void testEquals() {
CompilationUnit p1 = JavaParser.parse("class X { }");
CompilationUnit p2 = JavaParser.parse("class X { }");
assertEquals(p1.hashCode(), p2.hashCode());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class NoCommentEqualsVisitorTest method testEquals.
@Test
public void testEquals() {
CompilationUnit p1 = JavaParser.parse("class X { }");
CompilationUnit p2 = JavaParser.parse("class X { }");
assertTrue(NoCommentEqualsVisitor.equals(p1, p2));
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ClassOrInterfaceDeclarationTest method staticNestedClass.
@Test
public void staticNestedClass() {
CompilationUnit cu = JavaParser.parse("class X{static class Y{}}");
ClassOrInterfaceDeclaration y = cu.getClassByName("X").get().getMembers().get(0).asClassOrInterfaceDeclaration();
assertFalse(y.isInnerClass());
assertTrue(y.isNestedType());
assertFalse(y.isLocalClassDeclaration());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ContextTest method resolveReferenceUsingQualifiedName.
@Test
public void resolveReferenceUsingQualifiedName() {
CompilationUnit cu = parseSample("Navigator2");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "Navigator");
MethodDeclaration method = Navigator.demandMethod(referencesToField, "findType");
Parameter param = method.getParameters().get(0);
ResolvedClassDeclaration compilationUnitDecl = mock(ResolvedClassDeclaration.class);
when(compilationUnitDecl.getName()).thenReturn("CompilationUnit");
when(compilationUnitDecl.getQualifiedName()).thenReturn("com.github.javaparser.ast.CompilationUnit");
TypeSolver typeSolver = mock(TypeSolver.class);
// when(typeSolver.tryToSolveType("java.lang.com.github.javaparser.ast.CompilationUnit")).thenReturn(SymbolReference.unsolved(ClassDeclaration.class));
when(typeSolver.getRoot()).thenReturn(typeSolver);
when(typeSolver.solveType("java.lang.Object")).thenReturn(new ReflectionClassDeclaration(Object.class, typeSolver));
when(typeSolver.tryToSolveType("com.github.javaparser.ast.CompilationUnit")).thenReturn(SymbolReference.solved(compilationUnitDecl));
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
SymbolReference<? extends ResolvedTypeDeclaration> ref = symbolSolver.solveType("com.github.javaparser.ast.CompilationUnit", param);
assertEquals(true, ref.isSolved());
assertEquals("CompilationUnit", ref.getCorrespondingDeclaration().getName());
assertEquals("com.github.javaparser.ast.CompilationUnit", ref.getCorrespondingDeclaration().getQualifiedName());
}
Aggregations