コード例 #1
0
  @Override
  public void visitConstructorCallExpression(final ConstructorCallExpression call) {
    super.visitConstructorCallExpression(call);

    MethodNode target = (MethodNode) call.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
    if (target == null && call.getLineNumber() > 0) {
      addError("Target constructor for constructor call expression hasn't been set", call);
    } else {
      if (target == null) {
        // try to find a target
        ArgumentListExpression argumentListExpression =
            InvocationWriter.makeArgumentList(call.getArguments());
        List<Expression> expressions = argumentListExpression.getExpressions();
        ClassNode[] args = new ClassNode[expressions.size()];
        for (int i = 0; i < args.length; i++) {
          args[i] = typeChooser.resolveType(expressions.get(i), classNode);
        }
        MethodNode constructor =
            findMethodOrFail(
                call, call.isSuperCall() ? classNode.getSuperClass() : classNode, "<init>", args);
        call.putNodeMetaData(DIRECT_METHOD_CALL_TARGET, constructor);
        target = constructor;
      }
    }
    if (target != null) {
      memorizeInitialExpressions(target);
    }
  }
コード例 #2
0
  public void visitConstructorCallExpression(ConstructorCallExpression call) {
    isSpecialConstructorCall = call.isSpecialCall();
    super.visitConstructorCallExpression(call);
    isSpecialConstructorCall = false;
    if (!call.isUsingAnonymousInnerClass()) return;

    pushState();
    InnerClassNode innerClass = (InnerClassNode) call.getType();
    innerClass.setVariableScope(currentScope);
    for (MethodNode method : innerClass.getMethods()) {
      Parameter[] parameters = method.getParameters();
      if (parameters.length == 0) parameters = null; // null means no implicit "it"
      ClosureExpression cl = new ClosureExpression(parameters, method.getCode());
      visitClosureExpression(cl);
    }

    for (FieldNode field : innerClass.getFields()) {
      final Expression expression = field.getInitialExpression();
      if (expression != null) {
        expression.visit(this);
      }
    }

    for (Statement statement : innerClass.getObjectInitializerStatements()) {
      statement.visit(this);
    }
    markClosureSharedVariables();
    popState();
  }
コード例 #3
0
 protected Expression transformConstructorCallExpression(ConstructorCallExpression cce) {
   inSpecialConstructorCall = cce.isSpecialCall();
   Expression expression = cce.getArguments();
   if (expression instanceof TupleExpression) {
     TupleExpression tuple = (TupleExpression) expression;
     if (tuple.getExpressions().size() == 1) {
       expression = tuple.getExpression(0);
       if (expression instanceof NamedArgumentListExpression) {
         NamedArgumentListExpression namedArgs = (NamedArgumentListExpression) expression;
         List<MapEntryExpression> entryExpressions = namedArgs.getMapEntryExpressions();
         for (int i = 0; i < entryExpressions.size(); i++) {
           entryExpressions.set(
               i,
               (MapEntryExpression)
                   transformMapEntryExpression(entryExpressions.get(i), cce.getType()));
         }
       }
     }
   }
   Expression ret = cce.transformExpression(this);
   inSpecialConstructorCall = false;
   return ret;
 }