Search in sources :

Example 11 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.

the class CompilerTests method testDoBodyInDef.

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

Example 12 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.

the class CompilerTests method testOldInvoke.

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

Example 13 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate 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 14 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate 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 15 with JapidTemplate

use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.

the class CompilerTests method testSetDirective.

@Test
public void testSetDirective() throws IOException {
    String srcFile = "tests/setTag.html";
    String src = readFile(srcFile);
    JapidTemplate bt = new JapidTemplate("tests/setTag.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("@Override protected void message() {"));
    assertTrue(bt.javaSource.contains("@Override protected void title() {"));
}
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

JapidTemplate (cn.bran.japid.template.JapidTemplate)44 JapidAbstractCompiler (cn.bran.japid.compiler.JapidAbstractCompiler)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 TagIf (cn.bran.japid.compiler.Tag.TagIf)2 TagInTag (cn.bran.japid.compiler.Tag.TagInTag)2 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)1