use of org.mule.mvel2.CompileException in project mvel by mvel.
the class ExpressionCompiler method compile.
public CompiledExpression compile() {
try {
this.debugSymbols = pCtx.isDebugSymbols();
return _compile();
} finally {
if (pCtx.isFatalError()) {
StringAppender err = new StringAppender();
Iterator<ErrorDetail> iter = pCtx.getErrorList().iterator();
ErrorDetail e;
while (iter.hasNext()) {
e = iter.next();
e = ErrorUtil.rewriteIfNeeded(e, expr, cursor);
if (e.getExpr() != expr) {
iter.remove();
} else {
err.append("\n - ").append("(").append(e.getLineNumber()).append(",").append(e.getColumn()).append(")").append(" ").append(e.getMessage());
}
}
// noinspection ThrowFromFinallyBlock
throw new CompileException("Failed to compileShared: " + pCtx.getErrorList().size() + " compilation error(s): " + err.toString(), pCtx.getErrorList(), expr, cursor, pCtx);
}
}
}
use of org.mule.mvel2.CompileException in project mvel by mvel.
the class PropertyVerifier method getBeanProperty.
/**
* Process bean property
*
* @param ctx - the ingress type
* @param property - the property component
* @return known egress type.
*/
private Class getBeanProperty(Class ctx, String property) {
if (first) {
if (pCtx.hasVarOrInput(property)) {
if (pCtx.isStrictTypeEnforcement()) {
recordTypeParmsForProperty(property);
}
return pCtx.getVarOrInputType(property);
} else if (pCtx.hasImport(property)) {
resolvedExternally = false;
return pCtx.getImport(property);
} else if (!pCtx.isStrongTyping()) {
return Object.class;
} else if (pCtx.hasVarOrInput("this")) {
if (pCtx.isStrictTypeEnforcement()) {
recordTypeParmsForProperty("this");
}
ctx = pCtx.getVarOrInputType("this");
resolvedExternally = false;
}
}
st = cursor;
boolean switchStateReg;
Member member = ctx != null ? getFieldOrAccessor(ctx, property) : null;
if (MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS) {
if ("class".equals(property)) {
return Class.class;
}
}
if (member instanceof Field) {
if (pCtx.isStrictTypeEnforcement()) {
Field f = ((Field) member);
if (f.getGenericType() != null) {
if (f.getGenericType() instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) f.getGenericType();
pCtx.setLastTypeParameters(pt.getActualTypeArguments());
Type[] gpt = pt.getActualTypeArguments();
Type[] classArgs = type2Class(pt.getRawType()).getTypeParameters();
if (gpt.length > 0 && paramTypes == null)
paramTypes = new HashMap<String, Type>();
for (int i = 0; i < gpt.length; i++) {
paramTypes.put(classArgs[i].toString(), gpt[i]);
}
} else if (f.getGenericType() instanceof TypeVariable) {
TypeVariable tv = (TypeVariable) f.getGenericType();
Type paramType = paramTypes.remove(tv.getName());
if (paramType != null && paramType instanceof Class) {
return (Class) paramType;
}
}
}
return f.getType();
} else {
return ((Field) member).getType();
}
}
if (member != null) {
return getReturnType(ctx, (Method) member);
}
if (pCtx != null && first && pCtx.hasImport(property)) {
Class<?> importedClass = pCtx.getImport(property);
if (importedClass != null)
return pCtx.getImport(property);
}
if (pCtx != null && pCtx.getLastTypeParameters() != null && pCtx.getLastTypeParameters().length != 0 && ((Collection.class.isAssignableFrom(ctx) && !(switchStateReg = false)) || (Map.class.isAssignableFrom(ctx) && (switchStateReg = true)))) {
Type parm = pCtx.getLastTypeParameters()[switchStateReg ? 1 : 0];
pCtx.setLastTypeParameters(null);
return parm instanceof ParameterizedType ? Object.class : (Class) parm;
}
if (pCtx != null && "length".equals(property) && ctx.isArray()) {
return Integer.class;
}
Object tryStaticMethodRef = tryStaticAccess();
if (tryStaticMethodRef != null) {
fqcn = true;
resolvedExternally = false;
if (tryStaticMethodRef instanceof Class) {
classLiteral = !(MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS && new String(expr, end - 6, 6).equals(".class"));
return classLiteral ? (Class) tryStaticMethodRef : Class.class;
} else if (tryStaticMethodRef instanceof Field) {
try {
return ((Field) tryStaticMethodRef).get(null).getClass();
} catch (Exception e) {
throw new CompileException("in verifier: ", expr, start, e);
}
} else {
try {
return ((Method) tryStaticMethodRef).getReturnType();
} catch (Exception e) {
throw new CompileException("in verifier: ", expr, start, e);
}
}
}
if (ctx != null) {
try {
return findClass(variableFactory, ctx.getName() + "$" + property, pCtx);
} catch (ClassNotFoundException cnfe) {
// fall through.
}
}
if (pCtx != null && pCtx.getParserConfiguration() != null ? pCtx.getParserConfiguration().isAllowNakedMethCall() : MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL) {
Class cls = getMethod(ctx, property);
if (cls != Object.class) {
return cls;
}
}
if (pCtx.isStrictTypeEnforcement()) {
throw new CompileException("unqualified type in strict mode for: " + property, expr, tkStart);
}
return Object.class;
}
use of org.mule.mvel2.CompileException in project mvel by mvel.
the class ASTNode method setName.
@SuppressWarnings({ "SuspiciousMethodCalls" })
protected void setName(char[] name) {
if (isNumber(name, start, offset)) {
egressType = (literal = handleNumericConversion(name, start, offset)).getClass();
if (((fields |= NUMERIC | LITERAL | IDENTIFIER) & INVERT) != 0) {
try {
literal = ~((Integer) literal);
} catch (ClassCastException e) {
throw new CompileException("bitwise (~) operator can only be applied to integers", expr, start);
}
}
return;
}
this.literal = new String(name, start, offset);
int end = start + offset;
Scan: for (int i = start; i < end; i++) {
switch(name[i]) {
case '.':
if (firstUnion == 0) {
firstUnion = i;
}
break;
case '[':
case '(':
if (firstUnion == 0) {
firstUnion = i;
}
if (endOfName == 0) {
endOfName = i;
if (i < name.length && name[i + 1] == ']')
fields |= ARRAY_TYPE_LITERAL;
break Scan;
}
}
}
if ((fields & INLINE_COLLECTION) != 0) {
return;
}
if (firstUnion > start) {
fields |= DEEP_PROPERTY | IDENTIFIER;
} else {
fields |= IDENTIFIER;
}
}
use of org.mule.mvel2.CompileException in project mvel by mvel.
the class Fold method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver("$");
ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
List list;
if (constraintEx != null) {
Object x = dataEx.getValue(ctx, thisValue, factory);
if (!(x instanceof Collection))
throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
list = new ArrayList(((Collection) x).size());
for (Object o : (Collection) x) {
itemR.value = o;
if ((Boolean) constraintEx.getValue(ctx, thisValue, itemFactory)) {
list.add(subEx.getValue(o, thisValue, itemFactory));
}
}
} else {
Object x = dataEx.getValue(ctx, thisValue, factory);
if (!(x instanceof Collection))
throw new CompileException("was expecting type: Collection; but found type: " + (x == null ? "null" : x.getClass().getName()), expr, start);
list = new ArrayList(((Collection) x).size());
for (Object o : (Collection) x) {
list.add(subEx.getValue(itemR.value = o, thisValue, itemFactory));
}
}
return list;
}
use of org.mule.mvel2.CompileException in project mvel by mvel.
the class ForEachNode method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item);
ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
Object iterCond = MVEL.eval(expr, start, offset, thisValue, factory);
if (itemType != null && itemType.isArray())
enforceTypeSafety(itemType, getBaseComponentType(iterCond.getClass()));
this.compiledBlock = (ExecutableStatement) subCompileExpression(expr, blockStart, blockOffset, pCtx);
Object v;
if (iterCond instanceof Iterable) {
for (Object o : (Iterable) iterCond) {
itemR.setValue(o);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else if (iterCond != null && iterCond.getClass().isArray()) {
int len = Array.getLength(iterCond);
for (int i = 0; i < len; i++) {
itemR.setValue(Array.get(iterCond, i));
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else if (iterCond instanceof CharSequence) {
for (Object o : iterCond.toString().toCharArray()) {
itemR.setValue(o);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else if (iterCond instanceof Integer) {
int max = (Integer) iterCond + 1;
for (int i = 1; i != max; i++) {
itemR.setValue(i);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
} else {
throw new CompileException("non-iterable type: " + (iterCond != null ? iterCond.getClass().getName() : "null"), expr, start);
}
return null;
}
Aggregations