use of lucee.transformer.bytecode.statement.tag.TagImport in project Lucee by lucee.
the class Import method execute.
@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
TagImport ti = (TagImport) tag;
Attribute p = tag.getAttribute("prefix");
Attribute t = tag.getAttribute("taglib");
Attribute path = tag.getAttribute("path");
if (p != null || t != null) {
if (p == null)
throw new TemplateException(data.srcCode, "Wrong Context, missing attribute [prefix] for tag " + tag.getFullname());
if (t == null)
throw new TemplateException(data.srcCode, "Wrong Context, missing attribute [taglib] for tag " + tag.getFullname());
if (path != null)
throw new TemplateException(data.srcCode, "Wrong context, you have an invalid attributes constellation for the tag " + tag.getFullname() + ", " + "you cannot mix attribute [path] with attributes [taglib] and [prefix]");
return executePT(config, tag, libTag, flibs, data.srcCode);
}
if (path == null)
throw new TemplateException(data.srcCode, "Wrong context, you have an invalid attributes constellation for the tag " + tag.getFullname() + ", " + "you need to define the attributes [prefix] and [taglib], the attribute [path] or simply define a attribute value");
String strPath = ASMUtil.getAttributeString(tag, "path", null);
if (strPath == null)
throw new TemplateException(data.srcCode, "attribute [path] must be a constant value");
ti.setPath(strPath);
return null;
}
use of lucee.transformer.bytecode.statement.tag.TagImport in project Lucee by lucee.
the class Interface method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
super.evaluate(tag, libTag);
Body body = tag.getBody();
List<Statement> statments = body.getStatements();
Statement stat;
Iterator<Statement> it = statments.iterator();
Tag t;
while (it.hasNext()) {
stat = it.next();
if (stat instanceof PrintOut) {
// body.remove(stat);
} else if (stat instanceof Tag) {
t = (Tag) stat;
if (stat instanceof TagImport) {
// ignore
} else if (stat instanceof TagFunction) {
Function.throwIfNotEmpty(t);
Attribute attr = t.getAttribute("access");
if (attr != null) {
ExprString expr = t.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
String access = ((LitString) expr).getString().trim();
if (!"public".equalsIgnoreCase(access))
throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
} else
t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
} else
throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
}
}
}
use of lucee.transformer.bytecode.statement.tag.TagImport in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method getImports.
private static void getImports(List<String> list, Body body) throws TransformerException {
if (ASMUtil.isEmpty(body))
return;
Statement stat;
List stats = body.getStatements();
int len = stats.size();
for (int i = 0; i < len; i++) {
stat = (Statement) stats.get(i);
// IFunction
if (stat instanceof TagImport && !StringUtil.isEmpty(((TagImport) stat).getPath(), true)) {
ImportDefintion id = ImportDefintionImpl.getInstance(((TagImport) stat).getPath(), null);
if (id != null && (!list.contains(id.toString()) && !list.contains(id.getPackage() + ".*"))) {
list.add(id.toString());
}
stats.remove(i);
len--;
i--;
} else if (stat instanceof HasBody)
getImports(list, ((HasBody) stat).getBody());
else if (stat instanceof HasBodies) {
Body[] bodies = ((HasBodies) stat).getBodies();
for (int y = 0; y < bodies.length; y++) {
getImports(list, bodies[y]);
}
}
}
}
Aggregations