Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.Block


   public MethodSource<O> setBody(final String body)
   {
      String stub = "public class Stub { public void method() {" + body + "} }";
      JavaClassSource temp = (JavaClassSource) Roaster.parse(stub);
      List<MethodSource<JavaClassSource>> methods = temp.getMethods();
      Block block = ((MethodDeclaration) methods.get(0).getInternal()).getBody();

      block = (Block) ASTNode.copySubtree(method.getAST(), block);
      method.setBody(block);

      return this;
View Full Code Here


  // collapsed nodes: in source: use one node that represents many; to be used as
  // copy/move source or to replace at once.
  // in the target: one block node that is not flattened.

  public Block createCollapsePlaceholder() {
    Block placeHolder= this.ast.newBlock();
    if (this.collapsedNodes == null) {
      this.collapsedNodes= new HashSet();
    }
    this.collapsedNodes.add(placeHolder);
    return placeHolder;
View Full Code Here

      ASTNode node= (ASTNode) event.getOriginalValue();
      // check for ranges and add a placeholder for them
      while (nextInfo != null && node == nextInfo.getStartNode()) { // is this child the beginning of a range?
        nextInfo.updatePlaceholderSourceRanges(sourceRangeComputer);

        Block internalPlaceholder= nextInfo.getInternalPlaceholder();
        RewriteEvent newEvent;
        if (nextInfo.isMove()) {
          newEvent= new NodeRewriteEvent(internalPlaceholder, nextInfo.replacingNode); // remove or replace
        } else {
          newEvent= new NodeRewriteEvent(internalPlaceholder, internalPlaceholder); // unchanged
        }
        newChildEvents.add(newEvent);
        if (nextInfo.editGroup != null) {
          setEventEditGroup(newEvent, nextInfo.editGroup);
        }

        newChildrenStack.push(newChildEvents);
        topInfoStack.push(topInfo);

        newChildEvents= new ArrayList(childEvents.length);
        topInfo= nextInfo;

        nextInfo= rangeInfoIterator.hasNext() ? (NodeRangeInfo) rangeInfoIterator.next() : null;
      }

      newChildEvents.add(event);

      while (topInfo != null && node == topInfo.getEndNode()) {
        RewriteEvent[] placeholderChildEvents= (RewriteEvent[]) newChildEvents.toArray(new RewriteEvent[newChildEvents.size()]);
        Block internalPlaceholder= topInfo.getInternalPlaceholder();
        addEvent(internalPlaceholder, Block.STATEMENTS_PROPERTY, new ListRewriteEvent(placeholderChildEvents));

        newChildEvents= (List) newChildrenStack.pop();
        topInfo= (NodeRangeInfo) topInfoStack.pop();
      }
View Full Code Here

      TargetSourceRangeComputer.SourceRange startRange= sourceRangeComputer.computeSourceRange(getStartNode());
      TargetSourceRangeComputer.SourceRange endRange= sourceRangeComputer.computeSourceRange(getEndNode());
      int startPos= startRange.getStartPosition();
      int endPos= endRange.getStartPosition() + endRange.getLength();

      Block internalPlaceholder= getInternalPlaceholder();
      internalPlaceholder.setSourceRange(startPos, endPos - startPos);
    }
View Full Code Here

   public Method<O> setBody(final String body)
   {
      String stub = "public class Stub { public void method() {" + body + "} }";
      JavaClass temp = (JavaClass) JavaParser.parse(stub);
      List<Method<JavaClass>> methods = temp.getMethods();
      Block block = ((MethodDeclaration) methods.get(0).getInternal()).getBody();

      block = (Block) ASTNode.copySubtree(method.getAST(), block);
      method.setBody(block);

      return this;
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public MethodDeclaration visit(AST ast, MethodDeclaration input) {
    AccessInfo.PUBLIC.writeTo(input);

    Block body = ast.newBlock();
    input.setBody(body);

    SimpleName uoe = ast.newSimpleName("UnsupportedOperationException");
    SimpleType uoeType = ast.newSimpleType(uoe);
    ClassInstanceCreation newUoeType = ast.newClassInstanceCreation();
    newUoeType.setType(uoeType);

    ThrowStatement statement = ast.newThrowStatement();
    statement.setExpression(newUoeType);
    body.statements().add(statement);

    return input;
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public MethodDeclaration visit(AST ast, MethodDeclaration input) {
    AccessInfo.PUBLIC.writeTo(input);

    Block body = ast.newBlock();
    input.setBody(body);

    SimpleName uoe = ast.newSimpleName("UnsupportedOperationException");
    SimpleType uoeType = ast.newSimpleType(uoe);
    ClassInstanceCreation newUoeType = ast.newClassInstanceCreation();
    newUoeType.setType(uoeType);

    ThrowStatement statement = ast.newThrowStatement();
    statement.setExpression(newUoeType);
    body.statements().add(statement);

    return input;
  }
View Full Code Here

   public Method<O> setBody(final String body)
   {
      String stub = "public class Stub { public void method() {" + body + "} }";
      JavaClass temp = (JavaClass) JavaParser.parse(stub);
      List<Method<JavaClass>> methods = temp.getMethods();
      Block block = ((MethodDeclaration) methods.get(0).getInternal()).getBody();

      block = (Block) ASTNode.copySubtree(method.getAST(), block);
      method.setBody(block);

      return this;
View Full Code Here

          fLocationFound = true;
          return false;
        }
      }
      // visit only the body
      Block body = node.getBody();
      if (body != null) { // body is null for abstract methods
        body.accept(this);
      }
    }
    return false;
  }
View Full Code Here

      // Create the return statement
      ReturnStatement returnStatement = ast.newReturnStatement();
      returnStatement.setExpression(mi);

      Block block = ast.newBlock();
      block.statements().add(returnStatement);
      md.setBody(block);

      lr.insertFirst(md, null);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.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.