use of lucee.transformer.expression.Invoker in project Lucee by lucee.
the class AbstrCFMLExprTransformer method subDynamic.
private Expression subDynamic(ExprData data, Expression expr, boolean tryStatic, boolean isStaticChild) throws TemplateException {
String name = null;
Invoker invoker = null;
// Loop over nested Variables
boolean safeNavigation;
while (data.srcCode.isValidIndex()) {
safeNavigation = false;
ExprString nameProp = null, namePropUC = null;
// []
if (data.srcCode.forwardIfCurrent('[')) {
isStaticChild = false;
// get Next Var
nameProp = structElement(data);
namePropUC = nameProp;
// Valid Syntax ???
if (!data.srcCode.forwardIfCurrent(']'))
throw new TemplateException(data.srcCode, "Invalid Syntax Closing []] not found");
} else // .
if (isStaticChild || data.srcCode.forwardIfCurrent('.') || (safeNavigation = data.srcCode.forwardIfCurrent('?', '.'))) {
isStaticChild = false;
// Extract next Var String
comments(data);
Position line = data.srcCode.getPosition();
name = identifier(data, true);
if (name == null)
throw new TemplateException(data.srcCode, "Invalid identifier");
comments(data);
nameProp = Identifier.toIdentifier(data.factory, name, line, data.srcCode.getPosition());
namePropUC = Identifier.toIdentifier(data.factory, name, data.settings.dotNotationUpper ? Identifier.CASE_UPPER : Identifier.CASE_ORIGNAL, line, data.srcCode.getPosition());
} else // finish
{
break;
}
comments(data);
if (expr instanceof Invoker) {
invoker = (Invoker) expr;
} else {
invoker = new ExpressionInvoker(expr);
expr = invoker;
}
// safe navigation
Member member;
if (safeNavigation) {
List<Member> members = invoker.getMembers();
if (members.size() > 0) {
member = members.get(members.size() - 1);
member.setSafeNavigated(true);
}
}
// Method
if (data.srcCode.isCurrent('(')) {
// properly this is never used
if (nameProp == null && name != null)
nameProp = Identifier.toIdentifier(data.factory, name, Identifier.CASE_ORIGNAL, null, null);
invoker.addMember(member = getFunctionMember(data, nameProp, false));
} else
// property
invoker.addMember(member = data.factory.createDataMember(namePropUC));
if (safeNavigation) {
member.setSafeNavigated(true);
}
}
// STATIC SCOPE CALL
if (tryStatic) {
comments(data);
Expression staticCall = staticScope(data, expr);
if (staticCall != null)
return staticCall;
}
return expr;
}
Aggregations