Package org.eclipse.jdt.internal.compiler.ast

Examples of org.eclipse.jdt.internal.compiler.ast.Block


  } else {
    if (this.referenceContext instanceof AbstractMethodDeclaration){
      element = new RecoveredMethod((AbstractMethodDeclaration) this.referenceContext, null, 0, this);
      this.lastCheckPoint = ((AbstractMethodDeclaration) this.referenceContext).bodyStart;
      if(this.statementRecoveryActivated) {
        element = element.add(new Block(0), 0);
      }
    } else {
      /* Initializer bodies are parsed in the context of the type declaration, we must thus search it inside */
      if (this.referenceContext instanceof TypeDeclaration){
        TypeDeclaration type = (TypeDeclaration) this.referenceContext;
        FieldDeclaration[] fieldDeclarations = type.fields;
        int length = fieldDeclarations == null ? 0 : fieldDeclarations.length;
        for (int i = 0; i < length; i++){
          FieldDeclaration field = fieldDeclarations[i];
          if (field != null
            && field.getKind() == AbstractVariableDeclaration.INITIALIZER
            && ((Initializer) field).block != null
            && field.declarationSourceStart <= this.scanner.initialPosition
            && this.scanner.initialPosition <= field.declarationSourceEnd
            && this.scanner.eofPosition <= field.declarationSourceEnd+1){
            element = new RecoveredInitializer(field, null, 1, this);
            this.lastCheckPoint = field.declarationSourceStart;
            break;
          }
        }
      }
    }
  }

  if (element == null) return element;

  for(int i = 0; i <= this.astPtr; i++){
    ASTNode node = this.astStack[i];
    if (node instanceof AbstractMethodDeclaration){
      AbstractMethodDeclaration method = (AbstractMethodDeclaration) node;
      if (method.declarationSourceEnd == 0){
        element = element.add(method, 0);
        this.lastCheckPoint = method.bodyStart;
      } else {
        element = element.add(method, 0);
        this.lastCheckPoint = method.declarationSourceEnd + 1;
      }
      continue;
    }
    if (node instanceof Initializer){
      Initializer initializer = (Initializer) node;
      // ignore initializer with no block
      if (initializer.block == null) continue;
      if (initializer.declarationSourceEnd == 0){
        element = element.add(initializer, 1);
        this.lastCheckPoint = initializer.sourceStart;
      } else {
        element = element.add(initializer, 0);
        this.lastCheckPoint = initializer.declarationSourceEnd + 1;
      }
      continue;
    }
    if (node instanceof FieldDeclaration){
      FieldDeclaration field = (FieldDeclaration) node;
      if (field.declarationSourceEnd == 0){
        element = element.add(field, 0);
        if (field.initialization == null){
          this.lastCheckPoint = field.sourceEnd + 1;
        } else {
          this.lastCheckPoint = field.initialization.sourceEnd + 1;
        }
      } else {
        element = element.add(field, 0);
        this.lastCheckPoint = field.declarationSourceEnd + 1;
      }
      continue;
    }
    if (node instanceof TypeDeclaration){
      TypeDeclaration type = (TypeDeclaration) node;
      if ((type.modifiers & ClassFileConstants.AccEnum) != 0) {
        // do not allow enums to be build as recovery types
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=340691
        continue;
      }
      if (type.declarationSourceEnd == 0){
        element = element.add(type, 0);
        this.lastCheckPoint = type.bodyStart;
      } else {
        element = element.add(type, 0);
        this.lastCheckPoint = type.declarationSourceEnd + 1;
      }
      continue;
    }
    if (node instanceof ImportReference){
      ImportReference importRef = (ImportReference) node;
      element = element.add(importRef, 0);
      this.lastCheckPoint = importRef.declarationSourceEnd + 1;
    }
    if(this.statementRecoveryActivated) {
      if(node instanceof Block) {
        Block block = (Block) node;
        element = element.add(block, 0);
        this.lastCheckPoint = block.sourceEnd + 1;
      } else if(node instanceof LocalDeclaration) {
        LocalDeclaration statement = (LocalDeclaration) node;
        element = element.add(statement, 0);
View Full Code Here


  // Block ::= OpenBlock '{' BlockStatementsopt '}'
  // LambdaBody ::= NestedType NestedMethod  '{' BlockStatementsopt '}'
  // simpler action for empty blocks

  int statementsLength = this.astLengthStack[this.astLengthPtr--];
  Block block;
  if (statementsLength == 0) { // empty block
    block = new Block(0);
    block.sourceStart = this.intStack[this.intPtr--];
    block.sourceEnd = this.endStatementPosition;
    // check whether this block at least contains some comment in it
    if (!containsComment(block.sourceStart, block.sourceEnd)) {
      block.bits |= ASTNode.UndocumentedEmptyBlock;
    }
    this.realBlockPtr--; // still need to pop the block variable counter
  } else {
    block = new Block(this.realBlockStack[this.realBlockPtr--]);
    this.astPtr -= statementsLength;
    System.arraycopy(
      this.astStack,
      this.astPtr + 1,
      block.statements = new Statement[statementsLength],
View Full Code Here

protected void consumeClassBodyDeclaration() {
  // ClassBodyDeclaration ::= Diet NestedMethod CreateInitializer Block
  //push an Initializer
  //optimize the push/pop
  this.nestedMethod[this.nestedType]--;
  Block block = (Block) this.astStack[this.astPtr--];
  this.astLengthPtr--;
  if (this.diet) block.bits &= ~ASTNode.UndocumentedEmptyBlock; // clear bit since was diet
  Initializer initializer = (Initializer) this.astStack[this.astPtr];
  initializer.declarationSourceStart = initializer.sourceStart = block.sourceStart;
  initializer.block = block;
View Full Code Here

 
  this.astLengthPtr--;   // pop length for LambdaBody (always 1)
  Statement body = (Statement) this.astStack[this.astPtr--];
  if (body instanceof Block) {
    if (this.options.ignoreMethodBodies) {
      body = new Block(0);
    }
    ((Block) body).lambdaBody = true; // for consistency's sakes.
  }

  LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr--];
View Full Code Here

}
protected void consumeStaticInitializer() {
  // StaticInitializer ::=  StaticOnly Block
  //push an Initializer
  //optimize the push/pop
  Block block = (Block) this.astStack[this.astPtr];
  if (this.diet) block.bits &= ~ASTNode.UndocumentedEmptyBlock; // clear bit set since was diet
  Initializer initializer = new Initializer(block, ClassFileConstants.AccStatic);
  this.astStack[this.astPtr] = initializer;
  initializer.sourceEnd = this.endStatementPosition;
  initializer.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition);
View Full Code Here

    resetPendingModifiers();
    if (this.parent == null) return this; // ignore
    return this.parent.add(localDeclaration, bracketBalanceValue);
  }
  /* method body should have been created */
  Block block = new Block(0);
  block.sourceStart = ((Initializer)this.fieldDeclaration).sourceStart;
  RecoveredElement element = this.add(block, 1);
  if (this.initializerBody != null) {
    this.initializerBody.attachPendingModifiers(
        this.pendingAnnotations,
View Full Code Here

    resetPendingModifiers();
    if (this.parent == null) return this; // ignore
    return this.parent.add(statement, bracketBalanceValue);
  }
  /* initializer body should have been created */
  Block block = new Block(0);
  block.sourceStart = ((Initializer)this.fieldDeclaration).sourceStart;
  RecoveredElement element = this.add(block, 1);

  if (this.initializerBody != null) {
    this.initializerBody.attachPendingModifiers(
View Full Code Here

    if (this.parent == null) return this; // ignore
    return this.parent.add(typeDeclaration, bracketBalanceValue);
  }
  if ((typeDeclaration.bits & ASTNode.IsLocalType) != || parser().methodRecoveryActivated || parser().statementRecoveryActivated){
    /* method body should have been created */
    Block block = new Block(0);
    block.sourceStart = ((Initializer)this.fieldDeclaration).sourceStart;
    RecoveredElement element = this.add(block, 1);
    if (this.initializerBody != null) {
      this.initializerBody.attachPendingModifiers(
          this.pendingAnnotations,
View Full Code Here

  return result.toString();
}
public FieldDeclaration updatedFieldDeclaration(int depth, Set knownTypes){

  if (this.initializerBody != null){
    Block block = this.initializerBody.updatedBlock(depth, knownTypes);
    if (block != null){
      Initializer initializer = (Initializer) this.fieldDeclaration;
      initializer.block = block;

      if (initializer.declarationSourceEnd == 0) {
View Full Code Here

    } else {
      return this.parent.add(localDeclaration, bracketBalanceValue);
    }
  }
  if (this.methodBody == null){
    Block block = new Block(0);
    block.sourceStart = this.methodDeclaration.bodyStart;
    RecoveredElement currentBlock = this.add(block, 1);
    if (this.bracketBalance > 0){
      for (int i = 0; i < this.bracketBalance - 1; i++){
        currentBlock = currentBlock.add(new Block(0), 1);
      }
      this.bracketBalance = 1;
    }
    return currentBlock.add(localDeclaration, bracketBalanceValue);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.ast.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.