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

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


    } else {
      return this.parent.add(statement, 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(statement, bracketBalanceValue);
  }
View Full Code Here


    }
    return this.parent.add(typeDeclaration, bracketBalanceValue);
  }
  if ((typeDeclaration.bits & ASTNode.IsLocalType) != 0 || parser().methodRecoveryActivated || parser().statementRecoveryActivated){
    if (this.methodBody == null){
      Block block = new Block(0);
      block.sourceStart = this.methodDeclaration.bodyStart;
      this.add(block, 1);
    }
    this.methodBody.attachPendingModifiers(
        this.pendingAnnotations,
View Full Code Here

      this.methodDeclaration.declarationSourceStart = start;
    }
  }

  if (this.methodBody != null){
    Block block = this.methodBody.updatedBlock(depth, knownTypes);
    if (block != null){
      this.methodDeclaration.statements = block.statements;

      if (this.methodDeclaration.declarationSourceEnd == 0) {
        this.methodDeclaration.declarationSourceEnd = block.sourceEnd;
View Full Code Here

    if(start > 0 &&
        start < end &&
        kind != TypeDeclaration.INTERFACE_DECL &&
        kind != TypeDeclaration.ANNOTATION_TYPE_DECL) {
      // the } of the last type can be considered as the end of an initializer
      Initializer initializer = new Initializer(new Block(0), 0);
      initializer.bodyStart = end;
      initializer.bodyEnd = end;
      initializer.declarationSourceStart = end;
      initializer.declarationSourceEnd = end;
      initializer.sourceStart = end;
View Full Code Here

        this.bracketBalance = 1; // pretend the brace was already there
    }
  }
  // might be an initializer
  if (this.bracketBalance == 1){
    Block block = new Block(0);
    Parser parser = parser();
    block.sourceStart = parser.scanner.startPosition;
    Initializer init;
    if (parser.recoveredStaticInitializerStart == 0){
      init = new Initializer(block, ClassFileConstants.AccDefault);
View Full Code Here

  if (this.parent == null) return this; // ignore
  this.updateSourceEndIfNecessary(previousAvailableLineEnd(typeDeclaration.declarationSourceStart - 1));
  return this.parent.add(typeDeclaration, bracketBalanceValue);
}
protected void addBlockStatement(RecoveredBlock recoveredBlock) {
  Block block = recoveredBlock.blockDeclaration;
  if(block.statements != null) {
    Statement[] statements = block.statements;
    for (int i = 0; i < statements.length; i++) {
      recoveredBlock.add(statements[i], 0);
    }
View Full Code Here

  }

  if (element == null) return element;

  /* add initial block */
  Block block = new Block(0);
  int lastStart = this.blockStarts[0];
  block.sourceStart = lastStart;
  element = element.add(block, 1);
  int blockIndex = 1// ignore first block start, since manually rebuilt here

  ASTNode node = null, lastNode = null;
  for (int i = 0; i <= this.astPtr; i++, lastNode = node) {
    node = this.astStack[i];
    if(node instanceof ForeachStatement && ((ForeachStatement)node).action == null) {
      node = ((ForeachStatement)node).elementVariable;
    }
    /* check for intermediate block creation, so recovery can properly close them afterwards */
    int nodeStart = node.sourceStart;
    for (int j = blockIndex; j <= this.realBlockPtr; j++){
      if (this.blockStarts[j] >= 0) {
        if (this.blockStarts[j] > nodeStart){
          blockIndex = j; // shift the index to the new block
          break;
        }
        if (this.blockStarts[j] != lastStart){ // avoid multiple block if at same position
          block = new Block(0, lastNode instanceof LambdaExpression);
          block.sourceStart = lastStart = this.blockStarts[j];
          element = element.add(block, 1);
        }
      } else {
        if (-this.blockStarts[j] > nodeStart){
          blockIndex = j; // shift the index to the new block
          break;
        }
        block = new Block(0);
        block.sourceStart = lastStart = -this.blockStarts[j];
        element = element.add(block, 1);
      }
      blockIndex = j+1; // shift the index to the new block
    }
   
    if (node instanceof LocalDeclaration){
      LocalDeclaration local = (LocalDeclaration) node;
      if (local.declarationSourceEnd == 0){
        element = element.add(local, 0);
        if (local.initialization == null){
          this.lastCheckPoint = local.sourceEnd + 1;
        } else {
          this.lastCheckPoint = local.initialization.sourceEnd + 1;
        }
      } else {
        element = element.add(local, 0);
        this.lastCheckPoint = local.declarationSourceEnd + 1;
      }
      continue;
    }
    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;
      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.declarationSourceEnd == 0){
        element = element.add(type, 0);
        this.lastCheckPoint = type.bodyStart;
      } else {
        element = element.add(type, 0);
        this.lastCheckPoint = type.declarationSourceEnd + 1;
      }
      continue;
    }
    if (this.assistNode != null && node instanceof Statement) {
      Statement stmt = (Statement) node;
      if (!(stmt instanceof Expression) || ((Expression) stmt).statementExpression()) {
        if (this.assistNode.sourceStart >= stmt.sourceStart && this.assistNode.sourceEnd <= stmt.sourceEnd) {
          element.add(stmt, 0);
          this.lastCheckPoint = stmt.sourceEnd + 1;
          this.isOrphanCompletionNode = false;
        }
      }
      continue;
    }
    if (node instanceof ImportReference){
      ImportReference importRef = (ImportReference) node;
      element = element.add(importRef, 0);
      this.lastCheckPoint = importRef.declarationSourceEnd + 1;
    }
  }
  if (this.currentToken == TokenNameRBRACE && !isIndirectlyInsideLambdaExpression()) {
    this.currentToken = 0; // closing brace has already been taken care of
  }

  /* might need some extra block (after the last reduced node) */
  /* For block bodied lambdas we should create a block even though the lambda header appears before it, so elements from within don't get misattributed. */
  int pos = this.assistNode == null ? this.lastCheckPoint : this.assistNode.sourceStart;
  boolean createLambdaBlock = lastNode instanceof LambdaExpression && ((LambdaExpression) node).body() instanceof Block;
  for (int j = blockIndex; j <= this.realBlockPtr; j++){
    if (this.blockStarts[j] >= 0) {
      if ((this.blockStarts[j] < pos || createLambdaBlock) && (this.blockStarts[j] != lastStart)){ // avoid multiple block if at same position
        block = new Block(0, createLambdaBlock);
        block.sourceStart = lastStart = this.blockStarts[j];
        element = element.add(block, 1);
        createLambdaBlock = false;
      }
    } else {
      if ((this.blockStarts[j] < pos)){ // avoid multiple block if at same position
        block = new Block(0);
        block.sourceStart = lastStart = -this.blockStarts[j];
        element = element.add(block, 1);
      }
    }
  }
View Full Code Here

* in which case the bodyStart is updated.
*/
public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){

  // create a nested block
  Block block = new Block(0);
  block.sourceStart = parser().scanner.startPosition;
  return this.add(block, 1);
}
View Full Code Here

* in which case the bodyStart is updated.
*/
public RecoveredElement updateOnOpeningBrace(int braceStart, int braceEnd){

  // create a nested block
  Block block = new Block(0);
  block.sourceStart = parser().scanner.startPosition;
  return this.add(block, 1);
}
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.