Search in sources :

Example 6 with JapidLayoutCompiler

use of cn.bran.japid.compiler.JapidLayoutCompiler 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() {"));
}
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)

Example 7 with JapidLayoutCompiler

use of cn.bran.japid.compiler.JapidLayoutCompiler in project Japid by branaway.

the class CompilerTests method testOpenFor.

@Test
public void testOpenFor() throws IOException {
    String src = readFile("tests/openFor.html");
    JapidTemplate bt = new JapidTemplate("tests/openFor.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    System.out.println(bt.javaSource);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidLayoutCompiler(cn.bran.japid.compiler.JapidLayoutCompiler) Test(org.junit.Test)

Example 8 with JapidLayoutCompiler

use of cn.bran.japid.compiler.JapidLayoutCompiler in project Japid by branaway.

the class CompilerTests method testLayoutWithArgs.

@Test
public void testLayoutWithArgs() throws IOException {
    String src = readFile("JapidSample/app/japidviews/more/Perf/perfmain.html");
    JapidTemplate bt = new JapidTemplate("more/Perf/perfmain.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    System.out.println(bt.javaSource);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidLayoutCompiler(cn.bran.japid.compiler.JapidLayoutCompiler) Test(org.junit.Test)

Example 9 with JapidLayoutCompiler

use of cn.bran.japid.compiler.JapidLayoutCompiler in project Japid by branaway.

the class CompilerTests method testAnotherLayout.

@Test
public void testAnotherLayout() throws IOException, ParseException {
    String src = readFile("JapidSample/app/japidviews/_layouts/TagLayout.html");
    JapidTemplate bt = new JapidTemplate("japidviews/_layouts/TagLayout.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    String srccode = bt.javaSource;
    System.out.println(srccode);
    CompilationUnit cu = JavaSyntaxTool.parse(srccode);
    assertTrue(srccode.contains("package japidviews._layouts;"));
    assertTrue(srccode.contains("public abstract class TagLayout extends cn.bran.play.JapidTemplateBase"));
    assertTrue(srccode.contains("protected abstract void doLayout();"));
    assertTrue(srccode.contains("@Override public void layout()"));
}
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)

Example 10 with JapidLayoutCompiler

use of cn.bran.japid.compiler.JapidLayoutCompiler in project Japid by branaway.

the class CompilerTests method testIfCommand.

@Test
public void testIfCommand() throws IOException {
    String src = readFile("JapidSample/app/japidviews/Application/ifs.html");
    JapidTemplate bt = new JapidTemplate("Application/ifs.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    String javaSource = bt.javaSource;
    System.out.println(javaSource);
    assertTrue(javaSource.contains("if(!asBoolean(ss))"));
    assertTrue(javaSource.contains("else if(!asBoolean(ss))"));
    assertTrue("invalid java code", JavaSyntaxTool.isValid(javaSource));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidLayoutCompiler(cn.bran.japid.compiler.JapidLayoutCompiler) Test(org.junit.Test)

Aggregations

JapidAbstractCompiler (cn.bran.japid.compiler.JapidAbstractCompiler)10 JapidLayoutCompiler (cn.bran.japid.compiler.JapidLayoutCompiler)10 JapidTemplate (cn.bran.japid.template.JapidTemplate)10 Test (org.junit.Test)10 CompilationUnit (japa.parser.ast.CompilationUnit)3 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1