public PrimArrayHandler(Class type) { this.primitiveType = getBaseComponentType(type); }
private static void enforceTypeSafety(Class required, Class actual) { if (!required.isAssignableFrom(actual)) { throw new CompileException("type mismatch in foreach: expected: " + required.getName() + "; but found: " + getBaseComponentType(actual)); } } }
private void enforceTypeSafety(Class required, Class actual) { if (!required.isAssignableFrom(actual) && !DataConversion.canConvert(actual, required)) { throw new CompileException("type mismatch in foreach: expected: " + required.getName() + "; but found: " + getBaseComponentType(actual), expr, start); } } }
private void enforceTypeSafety(Class required, Class actual) { if (!required.isAssignableFrom(actual) && !DataConversion.canConvert(actual, required)) { throw new CompileException("type mismatch in foreach: expected: " + required.getName() + "; but found: " + getBaseComponentType(actual), expr, start); } } }
/** * Messy method to handle primitive boxing for conversion. If someone can re-write this more * elegantly, be my guest. * * @param sourceType * @param input * @param targetType * @return */ private static Object handleLooseTypeConversion(Class sourceType, Object input, Class targetType) { Class targType = getBaseComponentType(targetType); int len = getLength(input); Object target = newInstance(targType, len); if (len > 0 && canConvert(targetType, getBaseComponentType(sourceType))) { for (int i = 0; i < len; i++) { set(target, i, convert(get(input,i), targType)); } } else { throw new ConversionException("cannot convert to type: " + targetType.getComponentType().getName() + "[] from " + getBaseComponentType(sourceType).getName()); } return target; } }
public Object parseCollection(char[] property, int start, int offset, boolean subcompile, Class colType, ParserContext pCtx) { if (colType != null) this.colType = getBaseComponentType(colType); this.property = property; this.end = start + offset; while (start < end && isWhitespace(property[start])) { start++; } this.start = this.cursor = start; this.pCtx = pCtx; return parseCollection(subcompile); }
public Object parseCollection(char[] property, int start, int offset, boolean subcompile, Class colType, ParserContext pCtx) { if (colType != null) this.colType = getBaseComponentType(colType); this.property = property; this.end = start + offset; while (start < end && isWhitespace(property[start])) { start++; } this.start = this.cursor = start; this.pCtx = pCtx; return parseCollection(subcompile); }
public Object parseCollection(char[] property, boolean subcompile, Class colType, ParserContext pCtx) { if (colType != null) this.colType = getBaseComponentType(colType); this.cursor = 0; this.pCtx = pCtx; if ((this.length = (this.property = property).length) > 0) while (length > 0 && isWhitespace(property[length - 1])) length--; return parseCollection(subcompile); }
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory vars, Object value) { if (nextNode != null) { return nextNode.setValue(((Object[]) ctx)[(Integer) index.getValue(ctx, elCtx, vars)], elCtx, vars, value); } else { if (baseComponentType == null) { baseComponentType = ParseTools.getBaseComponentType(ctx.getClass()); requireConversion = baseComponentType != value.getClass() && !baseComponentType.isAssignableFrom(value.getClass()); } if (requireConversion) { Object o = convert(value, baseComponentType); Array.set(ctx, (Integer) index.getValue(ctx, elCtx, vars), o); return o; } else { Array.set(ctx, (Integer) index.getValue(ctx, elCtx, vars), value); return value; } } }
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory vars, Object value) { if (nextNode != null) { return nextNode.setValue(((Object[]) ctx)[(Integer) index.getValue(ctx, elCtx, vars)], elCtx, vars, value); } else { if (baseComponentType == null) { baseComponentType = ParseTools.getBaseComponentType(ctx.getClass()); requireConversion = baseComponentType != value.getClass() && !baseComponentType.isAssignableFrom(value.getClass()); } if (requireConversion) { Object o = convert(value, baseComponentType); Array.set(ctx, (Integer) index.getValue(ctx, elCtx, vars), o); return o; } else { Array.set(ctx, (Integer) index.getValue(ctx, elCtx, vars), value); return value; } } }
public Object setValue(Object ctx, Object elCtx, VariableResolverFactory vars, Object value) { if (nextNode != null) { return nextNode.setValue(((Object[]) ctx)[(Integer) index.getValue(ctx, elCtx, vars)], elCtx, vars, value); } else { if (baseComponentType == null) { baseComponentType = ParseTools.getBaseComponentType(ctx.getClass()); requireConversion = baseComponentType != value.getClass() && !baseComponentType.isAssignableFrom(value.getClass()); } if (requireConversion) { Object o = convert(value, baseComponentType); Array.set(ctx, (Integer) index.getValue(ctx, elCtx, vars), o); return o; } else { Array.set(ctx, (Integer) index.getValue(ctx, elCtx, vars), value); return value; } } }
Class cls = dim > 1 ? findClass(null, repeatChar('[', dim - 1) + "L" + getBaseComponentType(type).getName() + ";", pCtx) : type; throw new RuntimeException("this error should never throw:" + getBaseComponentType(type).getName(), e); return MVEL.eval((String) o, ctx, factory, getBaseComponentType(type));
private void handleCond(char[] condition, int start, int offset, int fields, ParserContext pCtx) { int cursor = start; int end = start + offset; while (cursor < end && condition[cursor] != ':') cursor++; if (cursor == end || condition[cursor] != ':') throw new CompileException("expected : in foreach", condition, cursor); int x; if ((x = (item = createStringTrimmed(condition, start, cursor - start)).indexOf(' ')) != -1) { String tk = new String(condition, start, x).trim(); try { itemType = ParseTools.findClass(null, tk, pCtx); item = new String(condition, start + x, (cursor - start) - x).trim(); } catch (ClassNotFoundException e) { throw new CompileException("cannot resolve identifier: " + tk, condition, start); } } // this.start = ++cursor; this.start = cursor + 1; this.offset = offset - (cursor - start) - 1; if ((fields & COMPILE_IMMEDIATE) != 0) { Class egress = (this.condition = (ExecutableStatement) subCompileExpression(expr, this.start, this.offset, pCtx)).getKnownEgressType(); if (itemType != null && egress.isArray()) { enforceTypeSafety(itemType, getBaseComponentType(this.condition.getKnownEgressType())); } else if (pCtx.isStrongTyping()) { determineIterType(egress); } } }
Class base = getBaseComponentType(type); Class cls = dim > 1 ? findClass(null, repeatChar('[', dim - 1) + "L" + base.getName() + ";", pCtx) : type; throw new RuntimeException("this error should never throw:" + getBaseComponentType(type).getName(), e);
private void handleCond(char[] condition, int start, int offset, int fields, ParserContext pCtx) { int cursor = start; int end = start + offset; while (cursor < end && condition[cursor] != ':') cursor++; if (cursor == end || condition[cursor] != ':') throw new CompileException("expected : in foreach", condition, cursor); int x; if ((x = (item = createStringTrimmed(condition, start, cursor - start)).indexOf(' ')) != -1) { String tk = new String(condition, start, x).trim(); try { itemType = ParseTools.findClass(null, tk, pCtx); item = new String(condition, start + x, (cursor - start) - x).trim(); } catch (ClassNotFoundException e) { throw new CompileException("cannot resolve identifier: " + tk, condition, start); } } // this.start = ++cursor; this.start = cursor + 1; this.offset = offset - (cursor - start) - 1; if ((fields & COMPILE_IMMEDIATE) != 0) { Class egress = (this.condition = (ExecutableStatement) subCompileExpression(expr, this.start, this.offset, pCtx)).getKnownEgressType(); if (itemType != null && egress.isArray()) { enforceTypeSafety(itemType, getBaseComponentType(this.condition.getKnownEgressType())); } else if (pCtx.isStrongTyping()) { determineIterType(egress); } } }
private void handleCond(char[] condition, int fields, ParserContext pCtx) { int cursor = 0; while (cursor < condition.length && condition[cursor] != ':') cursor++; if (cursor == condition.length || condition[cursor] != ':') throw new CompileException("expected : in foreach"); int x; if ((x = (item = createStringTrimmed(condition, 0, cursor)).indexOf(' ')) != -1) { String tk = new String(condition, 0, x).trim(); try { itemType = ParseTools.findClass(null, tk, pCtx); item = new String(condition, x, cursor - x).trim(); } catch (ClassNotFoundException e) { throw new CompileException("cannot resolve identifier: " + tk); } } this.cond = subset(condition, ++cursor); if ((fields & COMPILE_IMMEDIATE) != 0) { Class egress = (this.condition = (ExecutableStatement) subCompileExpression(this.cond, pCtx)).getKnownEgressType(); if (itemType != null && egress.isArray()) { enforceTypeSafety(itemType, getBaseComponentType(this.condition.getKnownEgressType())); } else if (pCtx.isStrongTyping()) { determineIterType(egress); } } }
enforceTypeSafety(itemType, getBaseComponentType(iterCond.getClass()));
enforceTypeSafety(itemType, getBaseComponentType(iterCond.getClass()));
enforceTypeSafety(itemType, getBaseComponentType(iterCond.getClass()));
return (newObjectOptimizer = new NewObjectArray(getBaseComponentType(egressType.getComponentType()), typeDescr.getCompiledArraySize())) .getValue(ctx, thisValue, factory);