Search in sources :

Example 81 with CompilationUnit

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

the class MethodChanger_2 method main.

public static void main(String[] args) throws Exception {
    // creates an input stream for the file to be parsed
    FileInputStream in = new FileInputStream("test.java");
    // parse the file
    CompilationUnit cu = JavaParser.parse(in);
    // change the methods names and parameters
    changeMethods(cu);
    // prints the changed compilation unit
    System.out.println(cu.toString());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) FileInputStream(java.io.FileInputStream)

Example 82 with CompilationUnit

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

the class MyVisitor method main.

public static void main(String... args) throws Exception {
    // parse the file
    CompilationUnit cu = JavaParser.parse(new FileInputStream("forGitHubTest.java"));
    // The visitor should remove all a=20 variable declarations.
    cu.accept(new MyVisitor(), null);
    System.out.println(cu.toString());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) FileInputStream(java.io.FileInputStream)

Example 83 with CompilationUnit

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

the class VisitorListTest method visitorListIterator.

@Test
public void visitorListIterator() {
    VisitorList<CompilationUnit> list = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    CompilationUnit x1 = JavaParser.parse("class X{}");
    list.add(x1);
    CompilationUnit x2 = JavaParser.parse("class X{}");
    list.add(x2);
    Iterator<CompilationUnit> itr = list.iterator();
    assertEquals(x1, itr.next());
    itr.remove();
    assertTrue(list.size() == 1);
    assertEquals(x2, itr.next());
    itr.remove();
    assertTrue(list.size() == 0);
}
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 84 with CompilationUnit

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

the class VisitorListTest method visitorListRemove.

@Test
public void visitorListRemove() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    VisitorList<CompilationUnit> list = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    list.add(x1);
    assertTrue(list.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 85 with CompilationUnit

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

the class VisitorListTest method visitorListContains.

@Test
public void visitorListContains() {
    CompilationUnit x1 = JavaParser.parse("class X{}");
    VisitorList<CompilationUnit> list = new VisitorList<>(new ObjectIdentityHashCodeVisitor(), new ObjectIdentityEqualsVisitor());
    list.add(x1);
    assertTrue(list.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)

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