Search in sources :

Example 86 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class VisitorListTest method visitorListRetainAll.

@Test
public void visitorListRetainAll() {
    List<CompilationUnit> list = new ArrayList<>();
    list.add(JavaParser.parse("class X{}"));
    list.add(JavaParser.parse("class X{}"));
    VisitorList<CompilationUnit> vList = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    vList.addAll(list);
    vList.add(JavaParser.parse("class X{}"));
    vList.retainAll(list);
    assertTrue(vList.size() == 2);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ArrayList(java.util.ArrayList) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Example 87 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class VisitorSetTest method visitorSetRemove.

@Test
public void visitorSetRemove() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    Set<CompilationUnit> set = new VisitorSet<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    set.add(x1);
    assertTrue(set.remove(x1));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Example 88 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class VisitorSetTest method visitorSetContains.

@Test
public void visitorSetContains() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    Set<CompilationUnit> set = new VisitorSet<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    set.add(x1);
    assertTrue(set.contains(x1));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Example 89 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class CommentsInserterTest method issue234LosingCommentsInArrayInitializerExpr.

@Test
public void issue234LosingCommentsInArrayInitializerExpr() {
    CompilationUnit cu = parse("@Anno(stuff={" + EOL + "    // Just," + EOL + "    // an," + EOL + "    // example" + EOL + "})" + EOL + "class ABC {" + EOL + "" + EOL + "}");
    assertEqualsNoEol("@Anno(stuff = {// Just,\n" + "// an,\n" + "// example\n" + "})\n" + "class ABC {\n" + "}\n", cu.toString());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 90 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class CommentsInserterTest method issue200EnumConstantsWithCommentsForceVerticalAlignment.

@Test
public void issue200EnumConstantsWithCommentsForceVerticalAlignment() {
    CompilationUnit cu = parse("public enum X {" + EOL + "    /** const1 javadoc */" + EOL + "    BORDER_CONSTANT," + EOL + "    /** const2 javadoc */" + EOL + "    ANOTHER_CONSTANT" + EOL + "}");
    assertEqualsNoEol("public enum X {\n" + "\n" + "    /**\n" + "     * const1 javadoc\n" + "     */\n" + "    BORDER_CONSTANT,\n" + "    /**\n" + "     * const2 javadoc\n" + "     */\n" + "    ANOTHER_CONSTANT\n" + "}\n", cu.toString());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)489 Test (org.junit.Test)304 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)160 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)140 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)128 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)101 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)70 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)66 Context (com.github.javaparser.symbolsolver.core.resolution.Context)62 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)55 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)51 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)45 File (java.io.File)39 Expression (com.github.javaparser.ast.expr.Expression)38 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)38 MethodUsage (com.github.javaparser.resolution.MethodUsage)34 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)33 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)29 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)29 ArrayList (java.util.ArrayList)29