Exemplo n.º 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);
 }
Exemplo n.º 2
0
 private IFunctionType convertToObjectSignature(BlockExpression blk) {
   IFunctionType functionType = blk.getType();
   IType[] iTypes = new IType[functionType.getParameterTypes().length];
   for (int i = 0; i < iTypes.length; i++) {
     iTypes[i] = JavaTypes.OBJECT();
   }
   return new FunctionType(blk.getFunctionName(), JavaTypes.OBJECT(), iTypes);
 }
Exemplo n.º 3
0
 private void initType(ICompilableType enclosingClass) {
   setEnclosingType(enclosingClass);
   BlockExpression block = getBlock();
   if (block.getArgs().size() < IBlock.MAX_ARGS) {
     IType functionClassForArity =
         FunctionClassUtil.getFunctionClassForArity(block.getArgs().size());
     setSuperType(functionClassForArity);
   } else {
     // This is a bad block that will have errors, so just set up a super type with zero args
     setSuperType(FunctionClassUtil.getFunctionClassForArity(0));
   }
 }
Exemplo n.º 4
0
 private List<ISymbol> convertToObjectSymbols(BlockExpression blk) {
   List<ISymbol> syms = new ArrayList<ISymbol>();
   for (ISymbol iSymbol : blk.getArgs()) {
     Symbol symbol = new Symbol((Symbol) iSymbol);
     symbol.setType(JavaTypes.OBJECT());
     syms.add(symbol);
   }
   return syms;
 }