Search in sources :

Example 16 with JapidAbstractCompiler

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

the class CompilerTests method testSubLayout.

@Test
public void testSubLayout() throws IOException {
    String src = readFile("JapidSample/app/japidviews/_layouts/SubLayout.html");
    JapidTemplate bt = new JapidTemplate("japidviews/_layouts/SubLayout.html", src);
    JapidAbstractCompiler cp = new JapidLayoutCompiler();
    cp.compile(bt);
    String srccode = bt.javaSource;
    System.out.println(srccode);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
    assertTrue(srccode.contains("package japidviews._layouts;"));
    assertTrue(srccode.contains("public abstract class SubLayout extends Layout"));
    assertTrue(srccode.contains("protected abstract void doLayout();"));
    assertTrue(srccode.contains("@Override public void layout()"));
}
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 17 with JapidAbstractCompiler

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

the class CompilerTests method testCompileLayout.

@Test
public void testCompileLayout() throws IOException {
    String src = readFile("JapidSample/app/japidviews/_layouts/Layout.html");
    JapidTemplate bt = new JapidTemplate("tag/Layout.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 18 with JapidAbstractCompiler

use of cn.bran.japid.compiler.JapidAbstractCompiler 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 19 with JapidAbstractCompiler

use of cn.bran.japid.compiler.JapidAbstractCompiler 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));
}
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 20 with JapidAbstractCompiler

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

the class CompilerTests method testTagBlock.

@Test
public void testTagBlock() throws IOException {
    String srcFile = "JapidSample/app/japidviews/templates/tagBody.html";
    String src = readFile(srcFile);
    JapidTemplate bt = new JapidTemplate("japidviews/templates/tagBody.html", src);
    JapidAbstractCompiler cp = new JapidTemplateCompiler();
    cp.compile(bt);
    System.out.println(bt.javaSource);
    assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
    //		assertTrue(bt.javaSource.contains("((anotherTag)(new anotherTag(getOut())).setActionRunners(getActionRunners())).render(echo, new anotherTag.DoBody<String>(){"));
    assertTrue(bt.javaSource.contains("new moreTag(tagBody.this)"));
}
Also used : JapidAbstractCompiler(cn.bran.japid.compiler.JapidAbstractCompiler) JapidTemplate(cn.bran.japid.template.JapidTemplate) JapidTemplateCompiler(cn.bran.japid.compiler.JapidTemplateCompiler) Test(org.junit.Test)

Aggregations

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