Example usage for org.eclipse.jdt.core.dom Block statements

List of usage examples for org.eclipse.jdt.core.dom Block statements

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Block statements.

Prototype

ASTNode.NodeList statements

To view the source code for org.eclipse.jdt.core.dom Block statements.

Click Source Link

Document

The list of statements (element type: Statement ).

Usage

From source file:org.smeup.sys.dk.compiler.rpj.writer.JDTStatementWriter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w  ww  . j a  va  2s .  c o m
public boolean visit(QReturn statement) {

    Block block = blocks.peek();

    ReturnStatement returnSt = ast.newReturnStatement();
    if (statement.getValue() != null) {
        QExpression returnExpression = expressionParser.parseExpression(statement.getValue());

        QProcedure procedure = (QProcedure) this.compilationUnit.getNode();

        QPrototype prototype = compilationUnit.getPrototype(procedure.getName(), true);
        if (prototype.getDefinition().getDataClass().equals(procedure.getReturnType().getDataClass())) {
            returnSt.setExpression(JDTStatementHelper.buildExpression(ast, compilationUnit, returnExpression,
                    procedure.getReturnType().getDataClass()));
        } else {
            returnSt.setExpression(JDTStatementHelper.buildExpression(ast, compilationUnit, returnExpression,
                    prototype.getDefinition().getDataClass()));
        }

        block.statements().add(returnSt);
    } else {
        // dummy condition

        IfStatement ifSt = ast.newIfStatement();
        ifSt.setExpression(ast.newName(new String[] { "RPJProgramSupport", "TRUE" }));
        ifSt.setThenStatement(returnSt);

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

    return false;
}

From source file:org.smeup.sys.dk.compiler.rpj.writer.JDTStatementWriter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  w  ww  . j  av a  2  s  .c om
public boolean visit(QFor statement) {

    Block block = blocks.peek();

    ForStatement forSt = ast.newForStatement();

    // initialization
    QAssignmentExpression assignment = expressionParser.parseAssignment(statement.getInitialization());
    forSt.initializers().add(buildAssignmentMethod(assignment, false));

    // condition
    QPredicateExpression condition = buildIterationCondition(statement.getCondition());
    Expression expression = JDTStatementHelper.buildExpression(ast, compilationUnit, condition,
            RPJContextHelper.getTargetClass(compilationUnit, condition, true));
    forSt.setExpression(expression);

    // increment
    QAssignmentExpression increment = expressionParser.parseAssignment(statement.getIncrement());
    forSt.updaters().add(buildAssignmentMethod(increment, false));

    block.statements().add(forSt);

    // body
    Block bodyBlock = ast.newBlock();
    forSt.setBody(bodyBlock);

    blocks.push(bodyBlock);

    return super.visit(statement);
}

From source file:org.smeup.sys.dk.compiler.rpj.writer.JDTStatementWriter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w w  w  .ja v a 2s  .c  om*/
public boolean visit(QUntil statement) {

    Block block = blocks.peek();

    DoStatement doSt = ast.newDoStatement();

    QLogicalExpression logicalExpression = QIntegratedLanguageExpressionFactory.eINSTANCE
            .createLogicalExpression();
    logicalExpression.setOperator(LogicalOperator.NOT);
    QBlockExpression blockExpression = QIntegratedLanguageExpressionFactory.eINSTANCE.createBlockExpression();

    QPredicateExpression condition = buildIterationCondition(statement.getCondition());
    blockExpression.setExpression(condition);

    logicalExpression.setLeftOperand(blockExpression);

    Expression expression = JDTStatementHelper.buildExpression(ast, compilationUnit, logicalExpression,
            RPJContextHelper.getTargetClass(compilationUnit, logicalExpression, true));
    doSt.setExpression(expression);

    block.statements().add(doSt);

    // body
    Block bodyBlock = ast.newBlock();
    doSt.setBody(bodyBlock);

    blocks.push(bodyBlock);

    return super.visit(statement);
}

From source file:org.smeup.sys.dk.compiler.rpj.writer.JDTStatementWriter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w w  w . ja v a  2 s .  c om*/
public boolean visit(QWhile statement) {

    Block block = blocks.peek();

    WhileStatement whileSt = ast.newWhileStatement();

    QPredicateExpression condition = buildIterationCondition(statement.getCondition());
    Expression expression = JDTStatementHelper.buildExpression(ast, compilationUnit, condition,
            RPJContextHelper.getTargetClass(compilationUnit, condition, true));
    whileSt.setExpression(expression);

    block.statements().add(whileSt);

    // body
    Block bodyBlock = ast.newBlock();
    whileSt.setBody(bodyBlock);

    blocks.push(bodyBlock);

    return super.visit(statement);
}

From source file:org.smeup.sys.dk.compiler.rpj.writer.JDTStatementWriter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//www.ja  va2  s .c  om
public boolean visit(QRoutineExec statement) {
    Block block = blocks.peek();

    MethodInvocation methodInvocation = ast.newMethodInvocation();

    QNamedNode routine = compilationUnit.getRoutine(statement.getRoutine(), true);
    if (routine == null)
        throw new IntegratedLanguageExpressionRuntimeException("Invalid routine: " + statement.getRoutine());

    methodInvocation.setName(ast.newSimpleName(compilationUnit.normalizeRoutineName(routine.getName())));

    if (!isOwner(routine)) {
        QNode parent = routine.getParent();
        if (parent instanceof QModule) {
            methodInvocation.setExpression(
                    ast.newSimpleName(compilationUnit.normalizeModuleName(((QModule) parent).getName())));
        } else if (parent instanceof QNamedNode) {
            // invoke on module
            String qualifiedParent = compilationUnit.getQualifiedName((QNamedNode) parent);
            methodInvocation.setExpression(JDTStatementHelper.buildExpression(ast, compilationUnit,
                    expressionParser.parseTerm(qualifiedParent), null));
        } else
            throw new IntegratedLanguageExpressionRuntimeException(
                    "Invalid procedure: " + statement.getRoutine());

    }

    ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
    block.statements().add(expressionStatement);

    // test annotations
    for (QAnnotationTest annotationTest : statement.getFacets(QAnnotationTest.class))
        writeAssertion(annotationTest, statement.toString());

    return super.visit(statement);
}

From source file:org.smeup.sys.dk.compiler.rpj.writer.JDTStatementWriter.java

License:Open Source License

@SuppressWarnings("unchecked")
private void writeAssertionTrue(Block target, String message, Expression expression) {
    MethodInvocation methodInvocation = ast.newMethodInvocation();
    methodInvocation.setExpression(ast.newSimpleName("testAsserter"));
    methodInvocation.setName(ast.newSimpleName("assertTrue"));

    StringLiteral literal = ast.newStringLiteral();
    literal.setLiteralValue(message);/*from w w  w  . j  a  v a2 s  . c om*/

    methodInvocation.arguments().add(literal);
    methodInvocation.arguments().add(expression);

    ExpressionStatement assertStatement = ast.newExpressionStatement(methodInvocation);
    target.statements().add(assertStatement);
}

From source file:org.smeup.sys.dk.compiler.rpj.writer.JDTStatementWriter.java

License:Open Source License

@SuppressWarnings({ "unchecked", "unused" })
private void writeAssertionEquals(Block target, String message, Expression leftExpression,
        Expression rightExpression, RelationalOperator operator) {

    MethodInvocation methodInvocation = ast.newMethodInvocation();
    methodInvocation.setExpression(ast.newSimpleName("testAsserter"));

    switch (operator) {
    case EQUAL://from w  ww .  j  a  v a 2s  .c o  m
        methodInvocation.setName(ast.newSimpleName("assertEquals"));
        break;
    case GREATER_THAN:
        break;
    case GREATER_THAN_EQUAL:
        break;
    case LESS_THAN:
        break;
    case LESS_THAN_EQUAL:
        break;
    case NOT_EQUAL:
        break;
    }

    StringLiteral literal = ast.newStringLiteral();
    literal.setLiteralValue(message);

    methodInvocation.arguments().add(literal);
    methodInvocation.arguments().add(leftExpression);
    methodInvocation.arguments().add(rightExpression);

    ExpressionStatement assertStatement = ast.newExpressionStatement(methodInvocation);
    target.statements().add(assertStatement);
}

From source file:org.springframework.ide.eclipse.internal.bestpractices.quickfix.AbstractCreateMethodMarkerResolution.java

License:Open Source License

protected Expression getMockMethodInvocation() {
    ASTParser fooParser = ASTParser.newParser(AST.JLS3);
    fooParser.setKind(ASTParser.K_STATEMENTS);
    String mockMethodInvocationCode = getNewMethodName() + "(" + getNewMethodParameters() + ");";
    fooParser.setSource(mockMethodInvocationCode.toCharArray());
    fooParser.setResolveBindings(true);//from   ww w  .j a v  a 2 s  .  co m
    ASTNode parsedAstNode = fooParser.createAST(null);
    Block codeBlock = (Block) parsedAstNode;
    ExpressionStatement methodInvocationExpressionStatement = (ExpressionStatement) codeBlock.statements()
            .get(0);
    return methodInvocationExpressionStatement.getExpression();
}

From source file:org.whole.lang.java.util.JDT2JavaBuilder.java

License:Open Source License

public boolean visit(Block node) {
    acceptChildren(node.statements(), JavaEntityDescriptorEnum.Block);
    return false;
}

From source file:org.whole.lang.java.util.JDTTransformerVisitor.java

License:Open Source License

public boolean visit(Block node) {
    org.whole.lang.java.model.Block blockStm = lf.create(JavaEntityDescriptorEnum.Block);

    List<?> statements = node.statements();
    Iterator<?> i = statements.iterator();
    while (i.hasNext()) {
        ((ASTNode) i.next()).accept(this);
        commentsMapper.appendOrphanCommentsToBlock(blockStm);
        blockStm.wAdd(stm);//ww w . ja  v  a2  s. co  m
    }
    for (Comment comment : commentsMapper.extractContainerComments(node)) {
        comment.accept(this);
        blockStm.wAdd(this.comment);
    }
    stm = block = blockStm;
    return false;
}