Package org.eclipse.jdt.core.dom

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


   * @param manager
   *            the variable binding manager
   * @return the index position within the statement list
   */
  protected int getFirstReferenceListIndex(VariableBindingManager manager) {
    Block block = Helper.getParentBlock(manager.getFirstReference());
    return block.statements().indexOf(manager.getFirstReference());
  }
View Full Code Here


        AST ast = rewrite.getAST();

        MethodDeclaration methodDeclaration = ast.newMethodDeclaration();
        SimpleName methodName = ast.newSimpleName("run");
        Type returnType = (Type) rewrite.createCopyTarget(classLoaderCreation.getType());
        Block methodBody = createRunMethodBody(rewrite, classLoaderCreation);
        List<Modifier> modifiers = checkedList(methodDeclaration.modifiers());

        modifiers.add(ast.newModifier(PUBLIC_KEYWORD));
        methodDeclaration.setName(methodName);
        methodDeclaration.setReturnType2(returnType);
View Full Code Here

    }

    private Block createRunMethodBody(ASTRewrite rewrite, ClassInstanceCreation classLoaderCreation) {
        AST ast = rewrite.getAST();

        Block methodBody = ast.newBlock();
        ReturnStatement returnStatement = ast.newReturnStatement();
        List<Statement> statements = checkedList(methodBody.statements());

        statements.add(returnStatement);
        returnStatement.setExpression((ClassInstanceCreation) rewrite.createCopyTarget(classLoaderCreation));

        return methodBody;
View Full Code Here

   *            the reference to be tested
   * @return {@code true}, if reference is within the same or underlying
   *         block. {@code false} otherwise.
   */
  private boolean isReferenceWhithinScope(SimpleName reference) {
    Block firstReferenceBlock = Helper.getParentBlock(firstReference);
    // get the block that contains the first reference statement

    ASTNode node = reference;

    // step down in the ast parent-child-node hierarchy. If
View Full Code Here

  protected void addNewVariableDeclaration(VariableBindingManager manager) {
    AST ast = manager.getFirstReference().getAST();
    VariableDeclarationStatement statement = createNewVariableDeclarationStatement(
        manager, ast);
    int firstReferenceIndex = getFirstReferenceListIndex(manager);
    Block block = Helper.getParentBlock(manager.getFirstReference());
    block.statements().add(firstReferenceIndex, statement);
  }
View Full Code Here

  protected void deleteOldVariableDeclaration(VariableBindingManager manager) {
    AST ast = manager.getFirstReference().getAST();
    VariableDeclarationStatement statement = createNewVariableDeclarationStatement(
        manager, ast);
    int firstReferenceIndex = getFirstReferenceListIndex(manager);
    Block block = Helper.getParentBlock(manager.getFirstReference());
    // get the list rewriter for the statments list
    ListRewrite statementsListRewrite = rewrite.getListRewrite(block,
        Block.STATEMENTS_PROPERTY);
    // add insert-at command to the protocol
    statementsListRewrite.insertAt(statement, firstReferenceIndex, null);
View Full Code Here

   * @param manager
   *            the variable binding manager
   * @return the index position within the statement list
   */
  protected int getFirstReferenceListIndex(VariableBindingManager manager) {
    Block block = Helper.getParentBlock(manager.getFirstReference());
    return block.statements().indexOf(manager.getFirstReference());
  }
View Full Code Here

           
            if (!methBinding.isConstructor()) {
              // Method is a getter or setter. Check if there is only
              // one statement in the method so that there can be no
              // computations.
              Block body = meth.getBody();
              if (body != null) {
                if (body.statements().size() != 1) {
                  generateResultsForASTNode(history, meth, resource, "The getter "+
                      methBinding.getName() + " in the Model class "+
                      binding.getName() + " must include exactly one statement.");
                }
              }
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

    var.setType(ast.newSimpleType(ast.newSimpleName("String")));
    var.setName(ast.newSimpleName("a"));
    md.parameters().add(var);
    td.bodyDeclarations().add(md);

    Block block = ast.newBlock();
    md.setBody(block);

    MethodInvocation mi = ast.newMethodInvocation();
    mi.setName(ast.newSimpleName("x"));

    ExpressionStatement e = ast.newExpressionStatement(mi);
    block.statements().add(e);

    System.out.println(cu);
  }
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.