use of lucee.transformer.bytecode.statement.tag.Tag in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method _propertyStatement.
private final Tag _propertyStatement(ExprData data, Body parent) throws TemplateException {
if (data.context != CTX_CFC || !data.srcCode.forwardIfCurrent("property "))
return null;
Position line = data.srcCode.getPosition();
TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode, "property", data.config.getIdentification());
Tag property = new TagOther(data.factory, line, null);
addMetaData(data, property, IGNORE_LIST_PROPERTY);
boolean hasName = false, hasType = false;
int pos = data.srcCode.getPos();
String tmp = variableDec(data, true);
if (!StringUtil.isEmpty(tmp)) {
if (tmp.indexOf('.') != -1) {
property.addAttribute(new Attribute(false, "type", data.factory.createLitString(tmp), "string"));
hasType = true;
} else {
data.srcCode.setPos(pos);
}
} else
data.srcCode.setPos(pos);
// folgend wird tlt extra nicht uebergeben, sonst findet pruefung statt
Attribute[] attrs = attributes(property, tlt, data, SEMI, data.factory.NULL(), Boolean.FALSE, "name", true, NO_ATTR_SEP, false);
checkSemiColonLineFeed(data, true, true, false);
property.setTagLibTag(tlt);
property.setScriptBase(true);
Attribute attr;
// first fill all regular attribute -> name="value"
for (int i = attrs.length - 1; i >= 0; i--) {
attr = attrs[i];
if (!attr.getValue().equals(data.factory.NULL())) {
if (attr.getName().equalsIgnoreCase("name")) {
hasName = true;
} else if (attr.getName().equalsIgnoreCase("type")) {
hasType = true;
}
property.addAttribute(attr);
}
}
// now fill name named attributes -> attr1 attr2
String first = null, second = null;
for (int i = 0; i < attrs.length; i++) {
attr = attrs[i];
if (attr.getValue().equals(data.factory.NULL())) {
// type
if (first == null && ((!hasName && !hasType) || !hasName)) {
first = attr.getNameOC();
} else // name
if (second == null && !hasName && !hasType) {
second = attr.getNameOC();
} else // attr with no value
{
attr = new Attribute(true, attr.getName(), data.factory.EMPTY(), "string");
property.addAttribute(attr);
}
}
}
if (first != null) {
hasName = true;
if (second != null) {
hasType = true;
property.addAttribute(new Attribute(false, "name", data.factory.createLitString(second), "string"));
property.addAttribute(new Attribute(false, "type", data.factory.createLitString(first), "string"));
} else {
property.addAttribute(new Attribute(false, "name", data.factory.createLitString(first), "string"));
}
}
if (!hasType) {
property.addAttribute(new Attribute(false, "type", data.factory.createLitString("any"), "string"));
}
if (!hasName)
throw new TemplateException(data.srcCode, "missing name declaration for property");
/*Tag property=new TagBase(line);
property.setTagLibTag(tlt);
property.addAttribute(new Attribute(false,"name",data.factory.createLitString(name),"string"));
property.addAttribute(new Attribute(false,"type",data.factory.createLitString(type),"string"));
*/
property.setEnd(data.srcCode.getPosition());
return property;
}
use of lucee.transformer.bytecode.statement.tag.Tag in project Lucee by lucee.
the class ASMUtil method removeLiterlChildren.
public static void removeLiterlChildren(Tag tag, boolean recursive) {
Body body = tag.getBody();
if (body != null) {
List<Statement> list = body.getStatements();
Statement[] stats = list.toArray(new Statement[list.size()]);
PrintOut po;
Tag t;
for (int i = 0; i < stats.length; i++) {
if (stats[i] instanceof PrintOut) {
po = (PrintOut) stats[i];
if (po.getExpr() instanceof Literal) {
body.getStatements().remove(po);
}
} else if (recursive && stats[i] instanceof Tag) {
t = (Tag) stats[i];
if (t.getTagLibTag().isAllowRemovingLiteral()) {
removeLiterlChildren(t, recursive);
}
}
}
}
}
use of lucee.transformer.bytecode.statement.tag.Tag in project Lucee by lucee.
the class ASMUtil method getParentTag.
/**
* Gibt das uebergeordnete CFXD Tag Element zurueck, falls dies nicht existiert wird null zurueckgegeben.
* @param el Element von dem das parent Element zurueckgegeben werden soll.
* @return uebergeordnete CFXD Tag Element
*/
public static Tag getParentTag(Tag tag) {
Statement p = tag.getParent();
if (p == null)
return null;
p = p.getParent();
if (p instanceof Tag)
return (Tag) p;
return null;
}
use of lucee.transformer.bytecode.statement.tag.Tag in project Lucee by lucee.
the class ASMUtil method hasSisterTagWithSameName.
/**
* Prueft ob das angegebene Tag innerhalb seiner Ebene einmalig ist oder nicht.
* @param tag Ausgangspunkt, nach diesem tag darf das angegebene nicht vorkommen.
* @return kommt das Tag vor.
*/
public static boolean hasSisterTagWithSameName(Tag tag) {
Body body = (Body) tag.getParent();
List<Statement> stats = body.getStatements();
Iterator<Statement> it = stats.iterator();
Statement other;
String name = tag.getTagLibTag().getName();
while (it.hasNext()) {
other = it.next();
if (other != tag && other instanceof Tag && ((Tag) other).getTagLibTag().getName().equals(name))
return true;
}
return false;
}
use of lucee.transformer.bytecode.statement.tag.Tag in project Lucee by lucee.
the class ASMUtil method hasSisterTagAfter.
/**
* Prueft ob das das angegebene Tag in der gleichen Ebene nach dem angegebenen Tag vorkommt.
* @param tag Ausgangspunkt, nach diesem tag darf das angegebene nicht vorkommen.
* @param nameToFind Tag Name der nicht vorkommen darf
* @return kommt das Tag vor.
*/
public static boolean hasSisterTagAfter(Tag tag, String nameToFind) {
Body body = (Body) tag.getParent();
List<Statement> stats = body.getStatements();
Iterator<Statement> it = stats.iterator();
Statement other;
boolean isAfter = false;
while (it.hasNext()) {
other = it.next();
if (other instanceof Tag) {
if (isAfter) {
if (((Tag) other).getTagLibTag().getName().equals(nameToFind))
return true;
} else if (other == tag)
isAfter = true;
}
}
return false;
}
Aggregations