Esempio n. 1
0
  public AbstractMethodDeclaration updatedMethodDeclaration() {
    /* update annotations */
    if (modifiers != 0) {
      this.methodDeclaration.modifiers |= modifiers;
      if (this.modifiersStart < this.methodDeclaration.declarationSourceStart) {
        this.methodDeclaration.declarationSourceStart = modifiersStart;
      }
    }
    /* update annotations */
    if (annotationCount > 0) {
      int existingCount =
          methodDeclaration.annotations == null ? 0 : methodDeclaration.annotations.length;
      Annotation[] annotationReferences = new Annotation[existingCount + annotationCount];
      if (existingCount > 0) {
        System.arraycopy(
            methodDeclaration.annotations, 0, annotationReferences, annotationCount, existingCount);
      }
      for (int i = 0; i < annotationCount; i++) {
        annotationReferences[i] = annotations[i].updatedAnnotationReference();
      }
      methodDeclaration.annotations = annotationReferences;

      int start = this.annotations[0].annotation.sourceStart;
      if (start < this.methodDeclaration.declarationSourceStart) {
        this.methodDeclaration.declarationSourceStart = start;
      }
    }

    if (methodBody != null) {
      Block block = methodBody.updatedBlock();
      if (block != null) {
        methodDeclaration.statements = block.statements;

        if (methodDeclaration.declarationSourceEnd == 0) {
          methodDeclaration.declarationSourceEnd = block.sourceEnd;
          methodDeclaration.bodyEnd = block.sourceEnd;
        }

        /* first statement might be an explict constructor call destinated to a special slot */
        if (methodDeclaration.isConstructor()) {
          ConstructorDeclaration constructor = (ConstructorDeclaration) methodDeclaration;
          if (methodDeclaration.statements != null
              && methodDeclaration.statements[0] instanceof ExplicitConstructorCall) {
            constructor.constructorCall = (ExplicitConstructorCall) methodDeclaration.statements[0];
            int length = methodDeclaration.statements.length;
            System.arraycopy(
                methodDeclaration.statements,
                1,
                (methodDeclaration.statements = new Statement[length - 1]),
                0,
                length - 1);
          }
          if (constructor.constructorCall == null) { // add implicit constructor call
            constructor.constructorCall = SuperReference.implicitSuperConstructorCall();
          }
        }
      }
    } else {
      if (methodDeclaration.declarationSourceEnd == 0) {
        if (methodDeclaration.sourceEnd + 1 == methodDeclaration.bodyStart) {
          // right brace is missing
          methodDeclaration.declarationSourceEnd = methodDeclaration.sourceEnd;
          methodDeclaration.bodyStart = methodDeclaration.sourceEnd;
          methodDeclaration.bodyEnd = methodDeclaration.sourceEnd;
        } else {
          methodDeclaration.declarationSourceEnd = methodDeclaration.bodyStart;
          methodDeclaration.bodyEnd = methodDeclaration.bodyStart;
        }
      }
    }
    if (localTypeCount > 0) methodDeclaration.bits |= ASTNode.HasLocalType;
    return methodDeclaration;
  }