Search in sources :

Example 71 with CompilationUnit

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

the class JsonPrinterTest method testEscaping.

@Test
public void testEscaping() {
    JsonPrinter jsonPrinter = new JsonPrinter(false);
    CompilationUnit expression = parse("class X {//hi\"" + EOL + "int x;}");
    String output = jsonPrinter.output(expression);
    assertEquals("{\"types\":[{\"isInterface\":\"false\",\"name\":{\"identifier\":\"X\",\"comment\":{\"content\":\"hi\\\"\"}},\"members\":[{\"variables\":[{\"name\":{\"identifier\":\"x\"},\"type\":{\"type\":\"INT\"}}]}]}]}", output);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 72 with CompilationUnit

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

the class JsonPrinterTest method issue1338.

@Test
public void issue1338() {
    String code = "class Test {" + "  public void method() {" + "    String.format(\"I'm using %s\", \"JavaParser\");" + "  }" + "}";
    CompilationUnit unit = parse(code);
    JsonPrinter printer = new JsonPrinter(true);
    printer.output(unit);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 73 with CompilationUnit

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

the class VisitorSteps method whenTheCompilationUnitIsVisitedByTheVistor.

@When("the CompilationUnit is visited by the to uppercase visitor")
public void whenTheCompilationUnitIsVisitedByTheVistor() {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    toUpperCaseVariableNameVisitor.visit(compilationUnit, null);
    state.put("cu1", compilationUnit);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) When(org.jbehave.core.annotations.When)

Example 74 with CompilationUnit

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

the class VisitorSteps method whenTheCompilationUnitIsVisitedByTheVariableNameCollectorVisitor.

@When("the CompilationUnit is visited by the variable name collector visitor")
public void whenTheCompilationUnitIsVisitedByTheVariableNameCollectorVisitor() {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    collectedVariableName = new AtomicReference<>("");
    collectVariableNameVisitor.visit(compilationUnit, collectedVariableName);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) When(org.jbehave.core.annotations.When)

Example 75 with CompilationUnit

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

the class VisitorSteps method whenTheCompilationUnitIsVisitedByTheVisitorThatReturnsAllVariableNames.

@When("the CompilationUnit is visited by the visitor that returns all variable names")
public void whenTheCompilationUnitIsVisitedByTheVisitorThatReturnsAllVariableNames() {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    returnedVariableNames = allNameReturningVisitor.visit(compilationUnit, null);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) When(org.jbehave.core.annotations.When)

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