Package net.sf.laja.exception

Examples of net.sf.laja.exception.LajaException


          if (methodName.equals(field.getName())) {
            try {
                            field.setAccessible(true);
              return field.get(instance);
            } catch (IllegalArgumentException e) {
              throw new LajaException("Could not access field '" + methodName + "': " + e.getMessage());
            } catch (IllegalAccessException e) {
              throw new LajaException("Could not access field '" + methodName + "': " + e.getMessage());
            }
          }
        }
        if (clazz.isArray() && methodName.equals("length")) {
          return Array.getLength(instance);
        }
      }
     
      String message = "Could not find method " + methodName + "(";
      String separator = "";
      if (arguments.length > 0) {
        for (int i=0; i<arguments.length; i++) {
          message += separator + parameterTypes[i];
          separator = ", ";
        }
      }
      message += ") in class " + clazz.getCanonicalName() + ".";
     
      throw new LajaException(message);
    }
   
    try {
      if (methodTypelist.isVararg()) {
        Object[] varargArguments = new Object[methodTypelist.getVarargStartIndex() + 1];
        for (int i=0; i<methodTypelist.getVarargStartIndex(); i++) {
          varargArguments[i] = arguments[i];
        }
       
        int varargLength = arguments.length - methodTypelist.getVarargStartIndex();
        Object varargs = Array.newInstance(methodTypelist.getVarargType(), varargLength);
        System.arraycopy(arguments, methodTypelist.getVarargStartIndex(), varargs, 0, varargLength);

        varargArguments[methodTypelist.getVarargStartIndex()] = varargs;
       
        return methodTypelist.getMethod().invoke(instance, varargArguments);
      } else {
        return methodTypelist.getMethod().invoke(instance, arguments);
      }
    } catch (IllegalArgumentException e) {
      return new LajaException(e);
    } catch (IllegalAccessException e) {
      return new LajaException(e);
    } catch (InvocationTargetException e) {
      return new LajaException(e);
    }
  }
View Full Code Here


  }

  @Override
  public ILocal createLocal(ITemplate itemplate, IMacro imacro, IFunction ifunction) {
    if (imacro == null && ifunction == null) {
      throw new LajaException("#local variables can not exist outside a #macro or #function body.");
    }
    Macro macro = (Macro) imacro;

    if (macro == null) {
      macro = (Macro) ifunction;
View Full Code Here

  public Object evaluate() {
    try {
      return newInstance();
    } catch (Exception e) {
      throw new LajaException(e);
    }
  }
View Full Code Here

    ConstructorTypelistCollection constructorTypelistCollection = new ConstructorTypelistCollection(clazz);
    ConstructorTypelist constructorTypelist = (ConstructorTypelist)TypelistEvaluator.getBestTypelist(types, constructorTypelistCollection);

    if (constructorTypelist == null) {
      throw new LajaException("Could not find a constructor for class " + clazz.getCanonicalName() + " with the parameter list: " + Arrays.asList(types));
    }
   
    return constructorTypelist.getConstructor().newInstance(args);
  }
View Full Code Here

    private String calculateClassName(String classname) {
        final String stateTemplate = "StateTemplate";
        final int length = stateTemplate.length();

        if (!classname.endsWith(stateTemplate) || classname.length() == length) {
            throw new LajaException("The class name must end with '" + stateTemplate + "', but was: " + classname);
        }
        return classname.substring(0, classname.length() - length);
    }
View Full Code Here

    public void setClassname(String classname) {
        final String stateTemplate = "StateTemplate";
        final int length = stateTemplate.length();

        if (!classname.endsWith(stateTemplate) || classname.length() == length) {
            throw new LajaException("The class name must end with '" + stateTemplate + "', but was: " + classname);
        }
        this.classname = classname.substring(0, classname.length() - length);
    }
View Full Code Here

      return evaluateList((List)object, 0);
    }
    if (object.getClass().isArray()) {
      return evaluateList(new ArrayListAdapter<Object>(object), 0);
    }
    throw new LajaException("Element " + getListName(0) + " must be an array or List.");
  }
View Full Code Here

      return element;
    }
    // Multi dimentional array, e.g: list[0][1].
    // TODO: Add support for multi dimensional arrays
    if (!(element instanceof List)) {
      throw new LajaException("Element " + getListName(index) + " must be an array or List.");
    }
    return evaluateList((List)element, index+1);
  }
View Full Code Here

       throw new InterpretationException(source, indexInSource, "Missing return statement for function '" + macro.getName() + "'");
    }
    Object attribute = macro.getBlock().generate();
   
    if (!macro.getBlock().hasReturnBeenExecuted()) {
      throw new LajaException("No value was returned from macro '" + macro.getName() + "'");
    }

    attribute = evaluateExceptionAndListIndex(attribute);
    return nextAttributeRefs.evaluateNextAttributes(getContext(), attribute);
  }
View Full Code Here

  public Object evaluateMacro(AttributeRef attributeRef) {
    Macro macro = getMacro(attributeRef.getMethodName());

    if (macro == null) {
      throw new LajaException("Could not find macro '" + attributeRef.getMethodName() + "'");
    }

    getTemplateTextWriter().pushTextWriter();

    if (attributeRef.getMethodArguments() != null) {
      macro.populateDataArguments(attributeRef.getMethodArguments().getArguments());
    }

    Object result = null;

    if (macro.getBlock() != null) {
      if (macro.isFunction()) {
        if (macro.getBlock() == null) {
          throw new LajaException("Missing return statement for function '" + macro.getName() + "'");
        } else {
          result = macro.getBlock().generate();
          if (!macro.getBlock().hasReturnBeenExecuted()) {
            throw new LajaException("No value was returned from macro '" + macro.getName() + "'");
          }
          getTemplateTextWriter().popTextWriter();
          return result;
        }
      } else {
View Full Code Here

TOP

Related Classes of net.sf.laja.exception.LajaException

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.