Search in sources :

Example 6 with CompilationUnit

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

the class CompilerTests method testVerbatim.

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

Example 7 with CompilationUnit

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

the class CompilerTests method testDefDirective.

@Test
public void testDefDirective() throws IOException, ParseException {
    String srcFile = "JapidSample/app/japidviews/templates/def.html";
    String src = readFile(srcFile);
    JapidTemplate bt = new JapidTemplate("japidviews/templates/def.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    //		System.out.println(bt.javaSource);
    //		assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
    CompilationUnit cu = JavaSyntaxTool.parse(bt.javaSource);
    System.out.println(cu);
    assertTrue("method is not declared", JavaSyntaxTool.hasMethod(cu, "foo", "public", "String", null));
    assertTrue("method is not declared", JavaSyntaxTool.hasMethod(cu, "foo2", "public", "String", "String"));
    assertTrue("method is not declared", JavaSyntaxTool.hasMethod(cu, "bar", "public", "String", null));
//		assertTrue("method is never called", JavaSyntaxTool.hasMethodInvocatioin(cu, "title"));
//		assertTrue("method is never called", JavaSyntaxTool.hasMethodInvocatioin(cu, "footer"));
//		assertTrue(bt.javaSource.contains("@Override protected void message() {"));
//		assertTrue(bt.javaSource.contains("@Override protected void title() {"));
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 8 with CompilationUnit

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

the class CompilerTests method testCompileTagWithDoubleDispatch.

@Test
public void testCompileTagWithDoubleDispatch() throws IOException, ParseException {
    String src = readFile("JapidSample/app/japidviews/_tags/Display.html");
    JapidTemplate bt = new JapidTemplate("tags/Display.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    String srcCode = bt.javaSource;
    System.out.println(srcCode);
    CompilationUnit cu = JavaSyntaxTool.parse(srcCode);
    assertTrue(srcCode.contains("package tags;"));
    assertTrue(srcCode.contains("public class Display extends TagLayout"));
    assertTrue(srcCode.contains("public cn.bran.japid.template.RenderResult render(models.japidsample.Post post,String as, DoBody body) {"));
    assertTrue(srcCode.contains("public cn.bran.japid.template.RenderResult render(models.japidsample.Post post,String as) {"));
    assertTrue(srcCode.contains("@Override protected void doLayout() {"));
    assertTrue("doBody is not presenting", srcCode.contains("body.render(post.getTitle() + \"!\");"));
    assertTrue(srcCode.contains("public static interface DoBody<A>"));
}
Also used : CompilationUnit(japa.parser.ast.CompilationUnit) JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 9 with CompilationUnit

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

the class CompilerTests method testOpenIf.

@Test
public void testOpenIf() throws IOException, ParseException {
    String src = readFile("tests/openif.html");
    JapidTemplate bt = new JapidTemplate("tests/openif.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    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) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Example 10 with CompilationUnit

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

the class CompilerTests method testSwitch.

@Test
public void testSwitch() throws IOException, ParseException {
    String src = readFile("tests/switchCase.html");
    JapidTemplate bt = new JapidTemplate("tests/switchCase.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    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) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) 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