コード例 #1
0
 private void implementInvoke() {
   BlockExpression block = getBlock();
   IParsedElement body = block.getBody();
   DynamicFunctionSymbol value;
   if (body instanceof Expression) {
     Expression expression = (Expression) body;
     ReturnStatement syntheticReturnStatement = new ReturnStatement();
     syntheticReturnStatement.setValue(expression);
     syntheticReturnStatement.initLocation(
         expression.getLocation().getOffset(),
         expression.getLocation().getLength(),
         expression.getLineNum(),
         expression.getColumn(),
         expression.getLocation().getScriptPartId());
     value =
         new DynamicFunctionSymbol(
             null,
             INVOKE_METHOD_NAME,
             convertToObjectSignature(block),
             convertToObjectSymbols(block),
             syntheticReturnStatement);
   } else {
     value =
         new DynamicFunctionSymbol(
             null,
             INVOKE_METHOD_NAME,
             convertToObjectSignature(block),
             convertToObjectSymbols(block),
             (IStatement) body);
   }
   value.setClassMember(true);
   value.setPublic(true);
   value.setFinal(true);
   getParseInfo().addMemberFunction(value);
 }
コード例 #2
0
 public IType getReturnType() {
   ArrayList returnStatements = new ArrayList<ReturnStatement>();
   ArrayList<IType> returnTypes = new ArrayList<IType>();
   getContainedParsedElementsByTypesWithIgnoreSet(
       returnStatements, new HashSet(getExcludedReturnTypeElements()), ReturnStatement.class);
   for (int i = 0; i < returnStatements.size(); i++) {
     ReturnStatement returnStmt = (ReturnStatement) returnStatements.get(i);
     returnTypes.add(returnStmt.getValue().getType());
   }
   return TypeLord.findLeastUpperBound(returnTypes);
 }
コード例 #3
0
  private void implementToString() {
    Identifier thisId = new Identifier();
    thisId.setSymbol(new Symbol(Keyword.KW_this.getName(), this, null), new StandardSymbolTable());
    thisId.setType(this);

    BeanMethodCallExpression toStrCall = new BeanMethodCallExpression();
    toStrCall.setMethodDescriptor(JavaTypes.IBLOCK().getTypeInfo().getMethod("toString"));
    toStrCall.setRootExpression(thisId);
    toStrCall.setType(JavaTypes.STRING());

    ReturnStatement returnStmt = new ReturnStatement();
    returnStmt.setValue(toStrCall);
  }