Package org.mvel2

Examples of org.mvel2.CompileException


          true, classLoader );

      methodName = new String(expr, ++mark, offset - (mark - start));

      if (resolveMethod() == null) {
        throw new CompileException("can not find method for static import: "
            + declaringClass.getName() + "." + methodName, expr, start);
      }
    }
    catch (Exception e) {
      throw new CompileException("unable to import class", expr, start, e);
    }
  }
View Full Code Here


          while (endRange < end && isWhitespace(name[endRange])) endRange++;

          if (endRange == end || name[endRange] == '{') break;

          if (name[endRange] != '[') {
            throw new CompileException("unexpected token in constructor", name, endRange);
          }
          to = balancedCapture(name, endRange, start + offset, '[');
          sizes.add(subset(name, ++endRange, to - endRange));
          endRange = to + 1;
        }
View Full Code Here

      cursor++;

      cursor = ParseTools.skipWhitespace(expr, cursor);

      if (cursor >= end) {
        throw new CompileException("incomplete statement", expr, cursor);
      }
      else if (expr[cursor] == '{') {
        blockEnd = cursor = balancedCaptureWithLineAccounting(expr, blockStart = cursor, end, '{', pCtx);
      }
      else {
View Full Code Here

        try {
          p = compile(valueOf(patternStmt.getValue(null, null)));
        }
        catch (PatternSyntaxException e) {
          throw new CompileException("bad regular expression", expr, patternStart, e);
        }
      }
    }
  }
View Full Code Here

  public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    try {
      return compile(valueOf(eval(expr, patternStart, patternOffset, ctx, factory))).matcher(valueOf(eval(expr, start, offset, ctx, factory))).matches();
    }
    catch (PatternSyntaxException e) {
      throw new CompileException("bad regular expression", expr, patternStart, e);
    }
  }
View Full Code Here

          stack.push(((VariableResolver) instruction.cache).getValue());
          break;
        case Operator.GETFIELD:
          try {
            if (stack.isEmpty() || !(stack.peek() instanceof Class)) {
              throw new CompileException("getfield without class", expr, blockStart);
            }

            Field field;
            if (instruction.cache == null) {
              instruction.cache = field = ((Class) stack.pop()).getField(instruction.expr);
            }
            else {
              stack.discard();
              field = (Field) instruction.cache;
            }

            stack.push(field.get(stack.pop()));
          }
          catch (Exception e) {
            throw new CompileException("field access error", expr, blockStart, e);
          }
          break;
        case Operator.STOREFIELD:
          try {
            if (stack.isEmpty() || !(stack.peek() instanceof Class)) {
              throw new CompileException("storefield without class", expr, blockStart);
            }

            Class cls = (Class) stack.pop();
            Object val = stack.pop();
            cls.getField(instruction.expr).set(stack.pop(), val);
            stack.push(val);
          }
          catch (Exception e) {
            throw new CompileException("field access error", expr, blockStart, e);
          }
          break;

        case Operator.LDTYPE:
          try {
            if (instruction.cache == null) {
              instruction.cache = ParseTools.createClass(instruction.expr, pCtx);
            }
            stack.push(instruction.cache);
          }
          catch (ClassNotFoundException e) {
            throw new CompileException("error", expr, blockStart, e);
          }
          break;

        case Operator.INVOKE:
          Object[] parms;
          ExecutionStack call = new ExecutionStack();
          while (!stack.isEmpty() && !(stack.peek() instanceof Class)) {
            call.push(stack.pop());
          }
          if (stack.isEmpty()) {
            throw new CompileException("invoke without class", expr, blockStart);
          }

          parms = new Object[call.size()];
          for (int i = 0; !call.isEmpty(); i++) parms[i] = call.pop();

          if ("<init>".equals(instruction.expr)) {
            Constructor c;
            if (instruction.cache == null) {
              instruction.cache = c = ParseTools.getBestConstructorCandidate(parms, (Class) stack.pop(), false);
            }
            else {
              c = (Constructor) instruction.cache;
            }

            try {
              stack.push(c.newInstance(parms));
            }
            catch (Exception e) {
              throw new CompileException("instantiation error", expr, blockStart, e);
            }
          }
          else {
            Method m;
            if (instruction.cache == null) {
              Class cls = (Class) stack.pop();

              instruction.cache = m = ParseTools.getBestCandidate(parms, instruction.expr, cls,
                  cls.getDeclaredMethods(), false);
            }
            else {
              stack.discard();
              m = (Method) instruction.cache;
            }

            try {
              stack.push(m.invoke(stack.isEmpty() ? null : stack.pop(), parms));
            }
            catch (Exception e) {
              throw new CompileException("invokation error", expr, blockStart, e);
            }
          }
          break;
        case Operator.PUSH:
          if (instruction.cache == null) {
View Full Code Here

        if ((start + 1) != end) {
          switch (expr[cursor = ++tkStart]) {
            case '?':
              skipWhitespace();
              if ((cursor = ++tkStart) == end) {
                throw new CompileException("unexpected end of statement", expr, start);
              }
              nullSafe = true;

              fields = -1;
              break;
            case '{':
              return WITH;
            default:
              if (isWhitespace(expr[tkStart])) {
                skipWhitespace();
                tkStart = cursor;
              }
          }
        }
        else {
          throw new CompileException("unexpected end of statement", expr, start);
        }
        break;
      case '?':
        if (start == cursor) {
          tkStart++;
View Full Code Here

    }
  }

  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);
    }
  }
View Full Code Here

    this.offset = offset;

    if ((fields & COMPILE_IMMEDIATE) != 0) {
      if (((this.stmt = (ExecutableStatement) subCompileExpression(expr, start, offset, pCtx)).getKnownEgressType() != null)
          && (!ParseTools.boxPrimitive(stmt.getKnownEgressType()).isAssignableFrom(Boolean.class))) {
        throw new CompileException("negation operator cannot be applied to non-boolean type", expr, start);
      }
    }
  }
View Full Code Here

  public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
    try {
      return !((Boolean) MVEL.eval(expr, start, offset, ctx, factory));
    }
    catch (NullPointerException e) {
      throw new CompileException("negation operator applied to a null value", expr, start, e);
    }
    catch (ClassCastException e) {
      throw new CompileException("negation operator applied to non-boolean expression", expr, start, e);
    }
  }
View Full Code Here

TOP

Related Classes of org.mvel2.CompileException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.