Package org.eclipse.jdt.core.dom

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


    MethodDeclaration constructor = ast.newMethodDeclaration();
    constructor.setConstructor(true);
    constructor.setName(ast.newSimpleName(clazz.getName()));
    constructor.modifiers().add(
        ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
    Block block = ast.newBlock();

    constructor.setBody(block);
    td.bodyDeclarations().add(constructor);
  }
View Full Code Here


      // Public
      methodDeclaration.modifiers().add(
          ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));

      // Content of getter method
      Block block = ast.newBlock();
      ReturnStatement returnStatement = ast.newReturnStatement();
      SimpleName simpleName = ast.newSimpleName(property.getName());
      returnStatement.setExpression(simpleName);
      block.statements().add(returnStatement);
      methodDeclaration.setBody(block);
    }
  }
View Full Code Here

    // We need to build contructor parameters for each properties
    generateContructorParameters(clazz, ast, md);

    // Content of constructor
    Block block = ast.newBlock();

    EList<Property> properties = clazz.getAttributes();
    for (Property property : properties) {
      logger.log(Level.FINE, "Class: " + clazz.getName() + " - "
          + "Property: " + property.getName() + " - "
          + "Property Upper: " + property.getUpper() + " - "
          + "Property Lower: " + property.getLower());

      // Left expression
      SimpleName simpleName = ast.newSimpleName(property.getName());
      ThisExpression thisExpression = ast.newThisExpression();
      FieldAccess fieldAccess = ast.newFieldAccess();
      fieldAccess.setName(simpleName);
      fieldAccess.setExpression(thisExpression);

      // Right expression
      SimpleName parameter = ast.newSimpleName(property.getName());

      Assignment assignment = ast.newAssignment();
      assignment
          .setOperator(org.eclipse.jdt.core.dom.Assignment.Operator.ASSIGN);
      assignment.setLeftHandSide(fieldAccess);
      assignment.setRightHandSide(parameter);

      // Expression
      ExpressionStatement expressionStatement = ast
          .newExpressionStatement(assignment);

      block.statements().add(expressionStatement);
    }

    // Set Body to MethodDeclaration
    md.setBody(block);
  }
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

     * @throws Exception if there is a problem
     */
    protected void record( final Initializer initializer,
                           final String nodeName,
                           final Node parentNode ) throws Exception {
        final Block block = initializer.getBody();

        if (block != null) {
            @SuppressWarnings( "unchecked" )
            final List<Statement> statements = block.statements();

            if ((statements != null) && !statements.isEmpty()) {
                final Node initializerNode = parentNode.addNode(nodeName, ClassFileSequencerLexicon.STATEMENTS);
                record(block, initializerNode);
            }
View Full Code Here

                methodNode.setProperty(ClassFileSequencerLexicon.THROWN_EXCEPTIONS, errorNames);
            }
        }

        { // body
            final Block body = method.getBody();

            if ((body != null) && (body.statements() != null) && !body.statements().isEmpty()) {
                final Node bodyNode = methodNode.addNode(ClassFileSequencerLexicon.BODY, ClassFileSequencerLexicon.STATEMENTS);
                record(body, bodyNode);
            }
        }
View Full Code Here

            .getListRewrite(stub, MethodDeclaration.MODIFIERS2_PROPERTY)
            .insertFirst(marker, null);

          stub.setName(ast.newSimpleName(name));

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

          String todoTask = "";
          String todoTaskTag = JUnitStubUtility.getTodoTaskTag(javaProject);
          if (todoTaskTag != null) {
            todoTask = " // " + todoTaskTag;
          }
          String message = WizardMessages
            .NewTestCaseWizardPageOne_not_yet_implemented_string;
          body.statements().add(astRewrite.createStringPlaceholder(
                todoTask,
                ASTNode.RETURN_STATEMENT));
          body.statements().add(astRewrite.createStringPlaceholder(
                Messages.format("fail(\"{0}\");", message),
                ASTNode.RETURN_STATEMENT));

          memberRewriter.insertLast(stub, null);
        }
View Full Code Here

    ASTNode placeholder= nodeStore.newPlaceholderNode(first.getNodeType()); // revisit: could use list type
    if (placeholder == null) {
      throw new IllegalArgumentException("Creating a target node is not supported for nodes of type" + first.getClass().getName()); //$NON-NLS-1$
    }

    Block internalPlaceHolder= nodeStore.createCollapsePlaceholder();
    CopySourceInfo info= getRewriteStore().createRangeCopy(this.parent, this.childListProperty, first, last, isMove, internalPlaceHolder, replacingNode, editGroup);
    nodeStore.markAsCopyTarget(placeholder, info);

    return placeholder;
  }
View Full Code Here

   */
  public final ASTNode createGroupNode(ASTNode[] targetNodes) {
    if (targetNodes == null || targetNodes.length == 0) {
      throw new IllegalArgumentException();
    }
    Block res= getNodeStore().createCollapsePlaceholder();
    ListRewrite listRewrite= getListRewrite(res, Block.STATEMENTS_PROPERTY);
    for (int i= 0; i < targetNodes.length; i++) {
      listRewrite.insertLast(targetNodes[i], null);
    }
    return res;
View Full Code Here

   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

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.