Search in sources :

Example 76 with CompilationUnit

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

the class VisitorMapTest method visitorMapContainsKey.

@Test
public void visitorMapContainsKey() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    Map<CompilationUnit, Integer> map = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    map.put(x1, 1);
    assertTrue(map.containsKey(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 77 with CompilationUnit

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

the class VisitorMapTest method normalEqualsDoesDeepCompare.

@Test
public void normalEqualsDoesDeepCompare() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    CompilationUnit x2 = JavaParser.parse("class X{}");
    Map<CompilationUnit, Integer> map = new HashMap<>();
    map.put(x1, 1);
    map.put(x2, 2);
    assertEquals(1, map.size());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 78 with CompilationUnit

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

the class VisitorMapTest method visitorMapPutAll.

@Test
public void visitorMapPutAll() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    CompilationUnit x2 = JavaParser.parse("class Y{}");
    Map<CompilationUnit, Integer> map = new HashMap<>();
    map.put(x1, 1);
    map.put(x2, 2);
    Map<CompilationUnit, Integer> visitorMap = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    visitorMap.putAll(map);
    assertEquals(2, visitorMap.size());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) HashMap(java.util.HashMap) ObjectIdentityHashCodeVisitor(com.github.javaparser.ast.visitor.ObjectIdentityHashCodeVisitor) ObjectIdentityEqualsVisitor(com.github.javaparser.ast.visitor.ObjectIdentityEqualsVisitor) Test(org.junit.Test)

Example 79 with CompilationUnit

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

the class VisitorMapTest method visitorMapGet.

@Test
public void visitorMapGet() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    Map<CompilationUnit, Integer> map = new VisitorMap<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    map.put(x1, 1);
    assertEquals(1, (int) map.get(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 80 with CompilationUnit

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

the class MethodChanger_1 method main.

public static void main(String[] args) throws Exception {
    // parse a file
    CompilationUnit cu = JavaParser.parse(new File("test.java"));
    // visit and change the methods names and parameters
    cu.accept(new MethodChangerVisitor(), null);
    // prints the changed compilation unit
    System.out.println(cu);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) File(java.io.File)

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