Example #1
0
  /**
   * Checks if the line is a method.
   *
   * @param par1 the par1
   * @return true, if is method
   */
  public boolean isMethod(CodeLine codeline) {
    String line = codeline.line.replace(";", "");
    if (line.contains(METHOD_PARAMETERS_START_CHAR) && line.endsWith(METHOD_PARAMETERS_END_CHAR)) {
      String methodName = line.substring(0, line.indexOf(METHOD_PARAMETERS_START_CHAR));

      if (this.getCustomMethod(methodName) != null) {
        return true;
      }

      TMLMethod executor = TextModHelper.getMethodExecutorFromName(methodName);
      return executor != null;
    }
    return false;
  }
Example #2
0
  /**
   * Reads a method from a line
   *
   * @param line the line
   * @return the method (with name and parameters)
   * @throws SyntaxException the parser exception
   */
  public Method readMethod(CodeLine codeline) throws SyntaxException {
    // Replaces the method identifier
    int parametersStart = codeline.line.indexOf(METHOD_PARAMETERS_START_CHAR);
    int parametersEnd = codeline.line.lastIndexOf(METHOD_PARAMETERS_END_CHAR);
    if (parametersStart == -1 || parametersEnd == -1) {
      throw new SyntaxException(
          "Invalid method signature: Missing parameter list",
          codeline,
          codeline.line.length() - 1,
          1);
    }

    String methodName = codeline.line.substring(0, parametersStart);
    String parameters = codeline.line.substring(parametersStart + 1, parametersEnd);
    String[] aparameters =
        TextModHelper.createParameterList(parameters, PARAMETER_SPLIT_CHAR.charAt(0));
    Object[] aparameters2 = this.parser.parse(codeline, aparameters);
    return new PredefinedMethod(methodName, aparameters2);
  }
Example #3
0
 /**
  * Gets the variable from a line.
  *
  * @param line the line
  * @return the variable
  * @throws SyntaxException the parser exception
  */
 public Variable readVariable(CodeLine codeline) throws SyntaxException {
   String line = codeline.line.substring(0, codeline.line.indexOf(';'));
   String[] split = TextModHelper.createParameterList(line, ' ');
   Variable var = null;
   if (this.isType(split[0])) // First part is a type declaration
   {
     Type type = Type.getTypeFromName(split[0]);
     String name = split[1];
     Object value = this.parser.parse(codeline, line.substring(line.indexOf("=") + 1));
     var = new Variable(type, name, value);
   } else // First part is an existing variable name
   {
     Variable var1 = this.getVariable(codeline, split[0]);
     String operator = split[1];
     Object value =
         this.parser.parse(codeline, line.substring(line.indexOf(operator) + operator.length()));
     var = this.operate(var1, operator, value);
   }
   return var;
 }