コード例 #1
0
  protected void classInstanceCreation(boolean alwaysQualified) {
    // ClassInstanceCreationExpression ::= 'new' ClassType '(' ArgumentListopt ')' ClassBodyopt

    // ClassBodyopt produces a null item on the astStak if it produces NO class body
    // An empty class body produces a 0 on the length stack.....

    AllocationExpression alloc;
    int length;
    if (((length = this.astLengthStack[this.astLengthPtr--]) == 1)
        && (this.astStack[this.astPtr] == null)) {
      // NO ClassBody
      this.astPtr--;
      if (alwaysQualified) {
        alloc = new QualifiedAllocationExpression();
      } else {
        alloc = new CodeSnippetAllocationExpression(this.evaluationContext);
      }
      alloc.sourceEnd = this.endPosition; // the position has been stored explicitly

      if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
        this.expressionPtr -= length;
        System.arraycopy(
            this.expressionStack,
            this.expressionPtr + 1,
            alloc.arguments = new Expression[length],
            0,
            length);
      }
      alloc.type = getTypeReference(0);
      // the default constructor with the correct number of argument
      // will be created and added by the TC (see createsInternalConstructorWithBinding)
      alloc.sourceStart = this.intStack[this.intPtr--];
      pushOnExpressionStack(alloc);
    } else {
      dispatchDeclarationInto(length);
      TypeDeclaration anonymousTypeDeclaration = (TypeDeclaration) this.astStack[this.astPtr];
      anonymousTypeDeclaration.declarationSourceEnd = this.endStatementPosition;
      if (anonymousTypeDeclaration.allocation != null) {
        anonymousTypeDeclaration.allocation.sourceEnd = this.endStatementPosition;
      }
      this.astPtr--;
      this.astLengthPtr--;

      // mark initializers with local type mark if needed
      markInitializersWithLocalType(anonymousTypeDeclaration);
    }
  }