Example #1
0
 public RecoveredElement updateOnClosingBrace(int braceStart, int braceEnd) {
   if (this.methodDeclaration.isAnnotationMethod()) {
     this.updateSourceEndIfNecessary(braceStart, braceEnd);
     if (!this.foundOpeningBrace && this.parent != null) {
       return this.parent.updateOnClosingBrace(braceStart, braceEnd);
     }
     return this;
   }
   if (this.parent != null && this.parent instanceof RecoveredType) {
     int mods = ((RecoveredType) this.parent).typeDeclaration.modifiers;
     if (TypeDeclaration.kind(mods) == TypeDeclaration.INTERFACE_DECL) {
       if (!this.foundOpeningBrace) {
         this.updateSourceEndIfNecessary(braceStart - 1, braceStart - 1);
         return this.parent.updateOnClosingBrace(braceStart, braceEnd);
       }
     }
   }
   return super.updateOnClosingBrace(braceStart, braceEnd);
 }
Example #2
0
  public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue) {

    /* do not consider a type starting passed the type end (if set)
    it must be belonging to an enclosing type */
    if (methodDeclaration.declarationSourceEnd != 0
        && typeDeclaration.declarationSourceStart > methodDeclaration.declarationSourceEnd) {

      if (this.parent == null) {
        return this; // ignore
      }
      return this.parent.add(typeDeclaration, bracketBalanceValue);
    }
    if ((typeDeclaration.bits & ASTNode.IsLocalType) != 0
        || this.parser().methodRecoveryActivated
        || this.parser().statementRecoveryActivated) {
      if (methodBody == null) {
        Block block = new Block(0);
        block.sourceStart = methodDeclaration.bodyStart;
        this.add(block, 1);
      }
      methodBody.attachPendingModifiers(
          this.pendingAnnotations,
          this.pendingAnnotationCount,
          this.pendingModifiers,
          this.pendingModifersSourceStart);
      this.resetPendingModifiers();
      return methodBody.add(typeDeclaration, bracketBalanceValue, true);
    }
    switch (TypeDeclaration.kind(typeDeclaration.modifiers)) {
      case TypeDeclaration.INTERFACE_DECL:
      case TypeDeclaration.ANNOTATION_TYPE_DECL:
        resetPendingModifiers();
        this.updateSourceEndIfNecessary(
            this.previousAvailableLineEnd(typeDeclaration.declarationSourceStart - 1));
        if (this.parent == null) {
          return this; // ignore
        }
        // close the constructor
        return this.parent.add(typeDeclaration, bracketBalanceValue);
    }
    if (localTypes == null) {
      localTypes = new RecoveredType[5];
      localTypeCount = 0;
    } else {
      if (localTypeCount == localTypes.length) {
        System.arraycopy(
            localTypes, 0, (localTypes = new RecoveredType[2 * localTypeCount]), 0, localTypeCount);
      }
    }
    RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue);
    localTypes[localTypeCount++] = element;

    if (this.pendingAnnotationCount > 0) {
      element.attach(
          pendingAnnotations, pendingAnnotationCount, pendingModifiers, pendingModifersSourceStart);
    }
    this.resetPendingModifiers();

    /* consider that if the opening brace was not found, it is there */
    if (!foundOpeningBrace) {
      foundOpeningBrace = true;
      this.bracketBalance++;
    }
    return element;
  }