コード例 #1
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();
  }
コード例 #2
0
 public void positionStmtsAfterEnumInitStmts(List<Statement> staticFieldStatements) {
   MethodNode method = getOrAddStaticConstructorNode();
   Statement statement = method.getCode();
   if (statement instanceof BlockStatement) {
     BlockStatement block = (BlockStatement) statement;
     // add given statements for explicitly declared static fields just after enum-special fields
     // are found - the $VALUES binary expression marks the end of such fields.
     List<Statement> blockStatements = block.getStatements();
     ListIterator<Statement> litr = blockStatements.listIterator();
     while (litr.hasNext()) {
       Statement stmt = litr.next();
       if (stmt instanceof ExpressionStatement
           && ((ExpressionStatement) stmt).getExpression() instanceof BinaryExpression) {
         BinaryExpression bExp = (BinaryExpression) ((ExpressionStatement) stmt).getExpression();
         if (bExp.getLeftExpression() instanceof FieldExpression) {
           FieldExpression fExp = (FieldExpression) bExp.getLeftExpression();
           if (fExp.getFieldName().equals("$VALUES")) {
             for (Statement tmpStmt : staticFieldStatements) {
               litr.add(tmpStmt);
             }
           }
         }
       }
     }
   }
 }
コード例 #3
0
  public void addStaticInitializerStatements(List<Statement> staticStatements, boolean fieldInit) {
    MethodNode method = getOrAddStaticConstructorNode();
    BlockStatement block = null;
    Statement statement = method.getCode();
    if (statement == null) {
      block = new BlockStatement();
    } else if (statement instanceof BlockStatement) {
      block = (BlockStatement) statement;
    } else {
      block = new BlockStatement();
      block.addStatement(statement);
    }

    // while anything inside a static initializer block is appended
    // we don't want to append in the case we have a initialization
    // expression of a static field. In that case we want to add
    // before the other statements
    if (!fieldInit) {
      block.addStatements(staticStatements);
    } else {
      List<Statement> blockStatements = block.getStatements();
      staticStatements.addAll(blockStatements);
      blockStatements.clear();
      blockStatements.addAll(staticStatements);
    }
  }
コード例 #4
0
 private Statement getMethodBody(MethodNode methodNode) {
   Statement code = methodNode.getCode();
   if (!(code instanceof BlockStatement)) {
     BlockStatement body = new BlockStatement();
     body.addStatement(code);
     code = body;
   }
   return code;
 }
コード例 #5
0
  protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) {
    pushState(node.isStatic());
    inConstructor = isConstructor;
    node.setVariableScope(currentScope);
    visitAnnotations(node);

    // GROOVY-2156
    Parameter[] parameters = node.getParameters();
    for (Parameter parameter : parameters) {
      visitAnnotations(parameter);
    }

    declare(node.getParameters(), node);
    visitClassCodeContainer(node.getCode());

    popState();
  }