Search in sources :

Example 1 with CompilationUnit

use of japa.parser.ast.CompilationUnit in project enumerable by hraberg.

the class InMemoryCompilerTest method inMemoryCompilationFromJavaParserAST.

@Test
public void inMemoryCompilationFromJavaParserAST() throws Exception {
    CompilationUnit cu = createCU();
    assertEquals("Hello World from AST", invokeMain(compiler.compile(getFullyQualifiedName(cu), cu.toString())).trim());
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) Test(org.junit.Test)

Example 2 with CompilationUnit

use of japa.parser.ast.CompilationUnit in project Japid by branaway.

the class JavaSyntaxToolTest method testHasMathod.

@Test
public void testHasMathod() throws ParseException {
    String src = "class A { private static void foo(int i, B b); }";
    CompilationUnit cu = JavaSyntaxTool.parse(src);
    assertTrue(JavaSyntaxTool.hasMethod(cu, "foo", "static private", "void", " int , B "));
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) Test(org.junit.Test)

Example 3 with CompilationUnit

use of japa.parser.ast.CompilationUnit in project Japid by branaway.

the class JavaSyntaxValidatorTest method testBuildValidAst.

@Test
public void testBuildValidAst() {
    String validSrc = "package testdir.d1;\r\n" + "\r\n" + "public class A {\r\n" + " Boo 不不 = new Boo('不'); \n" + "}\r\n" + "";
    CompilationUnit cu = null;
    try {
        cu = JavaSyntaxTool.parse(validSrc);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    assertNotNull(cu);
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) ParseException(japa.parser.ParseException) Test(org.junit.Test)

Example 4 with CompilationUnit

use of japa.parser.ast.CompilationUnit in project Japid by branaway.

the class JavaSyntaxValidatorTest method testParamList.

@Test
public void testParamList() throws UnsupportedEncodingException, ParseException {
    String src = "class A { void m  (String[ ] a, cc.B f) {m(1 + \"s\", 2);}}";
    ByteArrayInputStream in = new ByteArrayInputStream(src.getBytes("UTF-8"));
    CompilationUnit cu = JavaParser.parse(in, "UTF-8");
    assertNotNull(cu);
    // System.out.println(cu.toString());
    new MethodVisitor().visit(cu, null);
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 5 with CompilationUnit

use of japa.parser.ast.CompilationUnit in project Japid by branaway.

the class CompilerTests method testNoPlayCommand.

@Test
public void testNoPlayCommand() throws IOException, ParseException {
    String src = readFile("JapidSample/app/japidviews/templates/noplay.html");
    JapidTemplate bt = new JapidTemplate("japidviews/templates/noplay.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    String srccode = bt.javaSource;
    System.out.println(srccode);
    CompilationUnit cu = JavaSyntaxTool.parse(srccode);
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidLayoutCompiler(cn.bran.japid.compiler.JapidLayoutCompiler) Test(org.junit.Test)

Aggregations

CompilationUnit (japa.parser.ast.CompilationUnit)34 Test (org.junit.Test)17 ParseException (japa.parser.ParseException)15 JapidAbstractCompiler (cn.bran.japid.compiler.JapidAbstractCompiler)12 JapidTemplate (cn.bran.japid.template.JapidTemplate)12 VoidVisitorAdapter (japa.parser.ast.visitor.VoidVisitorAdapter)10 JapidTemplateCompiler (cn.bran.japid.compiler.JapidTemplateCompiler)9 MethodCallExpr (japa.parser.ast.expr.MethodCallExpr)7 ArrayList (java.util.ArrayList)6 Parameter (japa.parser.ast.body.Parameter)5 TypeParameter (japa.parser.ast.TypeParameter)4 AssignExpr (japa.parser.ast.expr.AssignExpr)4 Expression (japa.parser.ast.expr.Expression)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 JapidLayoutCompiler (cn.bran.japid.compiler.JapidLayoutCompiler)3 PackageDeclaration (japa.parser.ast.PackageDeclaration)3 ClassOrInterfaceDeclaration (japa.parser.ast.body.ClassOrInterfaceDeclaration)3 MethodDeclaration (japa.parser.ast.body.MethodDeclaration)3 TokenMgrError (japa.parser.TokenMgrError)2 BlockComment (japa.parser.ast.BlockComment)2