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>"));
}
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);
}
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);
}
use of japa.parser.ast.CompilationUnit in project Japid by branaway.
the class CompilerTests method testGetDirective.
@Test
public void testGetDirective() throws IOException, ParseException {
String srcFile = "tests/getTag.html";
String src = readFile(srcFile);
JapidTemplate bt = new JapidTemplate("tests/getTag.html", src);
JapidAbstractCompiler cp = new JapidLayoutCompiler();
cp.compile(bt);
System.out.println(bt.javaSource);
// assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
CompilationUnit cu = JavaSyntaxTool.parse(bt.javaSource);
assertTrue("method is not declared", JavaSyntaxTool.hasMethod(cu, "title", Modifier.PROTECTED, "void", ""));
assertTrue("method is not declared", JavaSyntaxTool.hasMethod(cu, "footer", Modifier.PROTECTED, "void", ""));
assertTrue("method is not declared", JavaSyntaxTool.hasMethod(cu, "doLayout", Modifier.PROTECTED | Modifier.ABSTRACT, "void", ""));
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() {"));
}
use of japa.parser.ast.CompilationUnit in project Japid by branaway.
the class CompilerTests method testOpenForInDef.
@Test
public void testOpenForInDef() throws IOException, ParseException {
String src = readFile("tests/openForInDef.html");
JapidTemplate bt = new JapidTemplate("tests/openForInDef.html", src);
JapidAbstractCompiler cp = new JapidTemplateCompiler();
cp.compile(bt);
System.out.println(bt.javaSource);
CompilationUnit cu = JavaSyntaxTool.parse(bt.javaSource);
System.out.println(cu);
// assertTrue("invalid java code", JavaSyntaxValidator.isValid(bt.javaSource));
}
Aggregations