use of cn.bran.japid.template.JapidTemplate 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)"));
}
use of cn.bran.japid.template.JapidTemplate 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));
}
use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.
the class CompilerTests method testEachDirective.
@Test
public void testEachDirective() throws IOException {
String srcFile = "tests/eachTag.html";
String src = readFile(srcFile);
JapidTemplate bt = new JapidTemplate("eachTag.html", src);
JapidAbstractCompiler cp = new JapidTemplateCompiler();
cp.compile(bt);
System.out.println(bt.javaSource);
assertTrue("invalid java code", JavaSyntaxTool.isValid(bt.javaSource));
assertFalse(bt.javaSource.contains("setActionRunners"));
}
use of cn.bran.japid.template.JapidTemplate 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));
}
use of cn.bran.japid.template.JapidTemplate in project Japid by branaway.
the class CompilerRequestor method acceptResult.
@Override
public void acceptResult(CompilationResult result) {
// If error
if (result.hasErrors()) {
// bran: sort the problems and report the first one
CategorizedProblem[] errors = result.getErrors();
Arrays.sort(errors, new Comparator<CategorizedProblem>() {
@Override
public int compare(CategorizedProblem o1, CategorizedProblem o2) {
return o1.getSourceLineNumber() - o2.getSourceLineNumber();
}
});
for (IProblem problem : errors) {
String className = new String(problem.getOriginatingFileName()).replace("/", ".");
className = className.substring(0, className.length() - 5);
String message = problem.getMessage();
if (problem.getID() == IProblem.CannotImportPackage) {
// Non sense !
message = problem.getArguments()[0] + " cannot be resolved";
}
RendererClass rc = this.rendererCompiler.japidClasses.get(className);
if (rc.getSrcFile() == null)
throw new RuntimeException("no source file for compiling " + className);
if (rc.getOriSourceCode() == null)
throw new RuntimeException("no original source code for compiling " + className);
JapidTemplate tmpl = new JapidTemplate(rc.getSrcFile().getPath(), rc.getOriSourceCode());
throw new JapidCompilationException(tmpl, DirUtil.mapJavaLineToSrcLine(rc.getSourceCode(), problem.getSourceLineNumber()), message + " while compiling " + className);
}
}
// Something has been compiled
ClassFile[] clazzFiles = result.getClassFiles();
for (int i = 0; i < clazzFiles.length; i++) {
final ClassFile clazzFile = clazzFiles[i];
final char[][] compoundName = clazzFile.getCompoundName();
final StringBuffer clazzName = new StringBuffer();
for (int j = 0; j < compoundName.length; j++) {
if (j != 0) {
clazzName.append('.');
}
clazzName.append(compoundName[j]);
}
byte[] bytes = clazzFile.getBytes();
JapidFlags.debug("Bytecode generated for " + clazzName);
// XXX address anonymous inner class issue!! ....$1...
String cname = clazzName.toString();
RendererClass rc = this.rendererCompiler.japidClasses.get(cname);
if (rc == null) {
if (cname.contains("$")) {
// inner class
rc = new RendererClass();
rc.setClassName(cname);
this.rendererCompiler.japidClasses.put(cname, rc);
} else {
throw new RuntimeException("name not in the classes container: " + cname);
}
}
rc.setBytecode(bytes);
}
}
Aggregations