List of usage examples for org.eclipse.jdt.core.dom Block statements
ASTNode.NodeList statements
To view the source code for org.eclipse.jdt.core.dom Block statements.
Click Source Link
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w. j a v a 2s .c o m*/ 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)); // condition QPredicateExpression condition = expressionParser.parsePredicate(statement.getCondition()); Expression expression = buildExpression(ast, condition, CompilationContextHelper.getJavaClass(compilationUnit, condition)); forSt.setExpression(expression); // increment QAssignmentExpression increment = expressionParser.parseAssignment(statement.getIncrement()); forSt.updaters().add(buildAssignmentMethod(increment)); block.statements().add(forSt); // body Block bodyBlock = ast.newBlock(); forSt.setBody(bodyBlock); blocks.push(bodyBlock); return super.visit(statement); }
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w ww. ja va2s . c o m*/ public boolean visit(QProcedureExec statement) { Block block = blocks.peek(); MethodInvocation methodInvocation = ast.newMethodInvocation(); QPrototype<?> prototype = compilationUnit.getPrototype(statement.getProcedure(), true); if (prototype == null) throw new IntegratedLanguageExpressionRuntimeException("Binding error: " + statement.getProcedure()); methodInvocation.setName(ast.newSimpleName(compilationUnit.normalizeTermName(prototype.getName()))); if (prototype.isChild() && prototype.getParent() != compilationUnit.getRoot()) { QNode parent = prototype.getParent(); if (parent instanceof QNamedNode) { String qualifiedParent = compilationUnit.getQualifiedName((QNamedNode) parent); methodInvocation .setExpression(buildExpression(ast, expressionParser.parseTerm(qualifiedParent), null)); } else throw new IntegratedLanguageExpressionRuntimeException( "Invalid procedure: " + statement.getProcedure()); } // entry if (prototype.getEntry() != null) { Iterator<QEntryParameter<?>> entryParameters = prototype.getEntry().getParameters().iterator(); for (String parameter : statement.getParameters()) { QExpression expression = expressionParser.parseExpression(parameter); if (entryParameters.hasNext()) { QEntryParameter<?> entryParameter = entryParameters.next(); QTerm parameterDelegate = entryParameter.getDelegate(); if (parameterDelegate instanceof QDataTerm) { QDataTerm<?> dataTerm = (QDataTerm<?>) parameterDelegate; if (dataTerm.isConstant()) { Expression jdtExpression = buildExpression(ast, expression, dataTerm.getDefinition().getJavaClass()); methodInvocation.arguments().add(jdtExpression); } else { Expression jdtExpression = buildExpression(ast, expression, dataTerm.getDefinition().getDataClass()); methodInvocation.arguments().add(jdtExpression); } } else if (parameterDelegate instanceof QDataSetTerm) { Expression jdtExpression = buildExpression(ast, expression, QDataSet.class); methodInvocation.arguments().add(jdtExpression); } else throw new IntegratedLanguageExpressionRuntimeException( "Invalid procedure invocation: " + statement.getProcedure()); } else throw new IntegratedLanguageExpressionRuntimeException( "Invalid procedure invocation: " + statement.getProcedure()); } while (entryParameters.hasNext()) { QEntryParameter<?> entryParameter = entryParameters.next(); if (entryParameter.isNullable()) methodInvocation.arguments().add(ast.newNullLiteral()); else throw new IntegratedLanguageExpressionRuntimeException( "Invalid procedure invocation: " + statement.getProcedure()); } } ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); return super.visit(statement); }
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . jav a2 s. co m public boolean visit(QJump statement) { Block block = blocks.peek(); // dummy break if (isParentFor(statement)) { IfStatement ifSt = ast.newIfStatement(); ifSt.setExpression(ast.newBooleanLiteral(false)); ifSt.setThenStatement(ast.newBreakStatement()); block.statements().add(ifSt); } MethodInvocation methodInvocation = ast.newMethodInvocation(); methodInvocation.setExpression(ast.newSimpleName("qRPJ")); methodInvocation.setName(ast.newSimpleName("qJump")); Name labelName = ast.newName(new String[] { "TAG", statement.getLabel() }); methodInvocation.arguments().add(0, labelName); ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); return super.visit(statement); }
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//w ww . j a v a 2s .co m public boolean visit(QLabel statement) { Block block = blocks.peek(); MethodInvocation methodInvocation = ast.newMethodInvocation(); methodInvocation.setExpression(ast.newSimpleName("qRPJ")); methodInvocation.setName(ast.newSimpleName("qLabel")); Name labelName = ast.newName(new String[] { "TAG", statement.getName() }); methodInvocation.arguments().add(0, labelName); ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); return super.visit(statement); }
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w w w. ja v a 2 s . c o m*/ public boolean visit(QMethodExec statement) { try { if (statement.getObject() != null) { Block block = blocks.peek(); MethodInvocation methodInvocation = ast.newMethodInvocation(); methodInvocation .setName(ast.newSimpleName(compilationUnit.normalizeTermName(statement.getMethod()))); QNamedNode namedNode = compilationUnit.getNamedNode(statement.getObject(), true); // display and print if ((namedNode != null && (namedNode.getParent() instanceof QDisplayTerm || namedNode.getParent() instanceof QPrintTerm))) { methodInvocation.setExpression( ast.newName(compilationUnit.getQualifiedName((QNamedNode) namedNode.getParent()))); TypeLiteral typeLiteral = ast.newTypeLiteral(); String fileName = compilationUnit .normalizeTypeName(((QNamedNode) namedNode.getParent()).getName()); String formatName = compilationUnit.normalizeTypeName(namedNode.getName()); typeLiteral.setType(ast.newSimpleType(ast.newName(new String[] { fileName, formatName }))); methodInvocation.arguments().add(typeLiteral); } else { methodInvocation.setExpression( buildExpression(ast, expressionParser.parseExpression(statement.getObject()), null)); } if (statement.getParameters() != null) { for (String parameter : statement.getParameters()) { QExpression expression = expressionParser.parseExpression(parameter); Expression jdtExpression = buildExpression(ast, expression, null); methodInvocation.arguments().add(jdtExpression); } } ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); } else { QProcedureExec procedureExec = QIntegratedLanguageFlowFactory.eINSTANCE.createProcedureExec(); procedureExec.setProcedure(statement.getMethod()); procedureExec.getParameters().addAll(statement.getParameters()); visit(procedureExec); } return false; } catch (Exception e) { throw new OperatingSystemRuntimeException(e); } }
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w .j a va2s .c o m public boolean visit(QMonitor statement) { Block block = blocks.peek(); // -> try TryStatement tryStatement = ast.newTryStatement(); blocks.push(tryStatement.getBody()); if (statement.getBody() != null) statement.getBody().accept(this); // catch CatchClause catchClause = ast.newCatchClause(); SingleVariableDeclaration exceptionDeclaration = ast.newSingleVariableDeclaration(); Type exception = ast .newSimpleType(ast.newSimpleName(OperatingSystemRuntimeException.class.getSimpleName())); exceptionDeclaration.setType(exception); exceptionDeclaration.setName(ast.newSimpleName("e")); catchClause.setException(exceptionDeclaration); tryStatement.catchClauses().add(catchClause); // -> catch blocks.push(catchClause.getBody()); // switch SwitchStatement switchStatement = ast.newSwitchStatement(); MethodInvocation methodInvocation = ast.newMethodInvocation(); methodInvocation.setExpression(ast.newSimpleName("e")); methodInvocation.setName(ast.newSimpleName("toString")); switchStatement.setExpression(methodInvocation); blocks.peek().statements().add(switchStatement); for (QOnError error : statement.getOnErrors()) { if (error.getBody() != null) { // Case SwitchCase switchCase = ast.newSwitchCase(); StringLiteral caseLiteral = ast.newStringLiteral(); if (error.getError() != null) caseLiteral.setLiteralValue(error.getError()); else caseLiteral.setLiteralValue("*ALL"); switchCase.setExpression(caseLiteral); switchStatement.statements().add(switchCase); // Case body // -> Case Block caseBlock = ast.newBlock(); blocks.push(caseBlock); if (error.getBody() != null) error.getBody().accept(this); // copy case block to switch statement for (int i = 0; i < caseBlock.statements().size(); i++) { switchStatement.statements().add(caseBlock.statements().remove(i)); } BreakStatement switchBreak = ast.newBreakStatement(); caseBlock.statements().add(switchBreak); // <- case blocks.pop(); } } // <-catch blocks.pop(); // <-try blocks.pop(); block.statements().add(tryStatement); return false; }
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from www . j a v a 2 s. c o m public boolean visit(QReturn statement) { Block block = blocks.peek(); ReturnStatement returnSt = ast.newReturnStatement(); if (isParentProcedure(statement)) { block.statements().add(returnSt); } else { // dummy condition IfStatement ifSt = ast.newIfStatement(); ifSt.setExpression(ast.newBooleanLiteral(true)); ifSt.setThenStatement(returnSt); block.statements().add(ifSt); } return false; }
From source file:org.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//w w w.j a va 2 s . com public boolean visit(QUntil statement) { Block block = blocks.peek(); DoStatement doSt = ast.newDoStatement(); QPredicateExpression condition = expressionParser.parsePredicate(statement.getCondition()); Expression expression = buildExpression(ast, condition, CompilationContextHelper.getJavaClass(compilationUnit, condition)); 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.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2 s . c om public boolean visit(QWhile statement) { if (statement.getCondition() == null) statement.setCondition("true"); Block block = blocks.peek(); WhileStatement whileSt = ast.newWhileStatement(); QPredicateExpression condition = expressionParser.parsePredicate(statement.getCondition()); Expression expression = buildExpression(ast, condition, CompilationContextHelper.getJavaClass(compilationUnit, condition)); 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.asup.dk.compiler.rpj.writer.JDTStatementWriter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from www. ja v a 2s. c o m*/ 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.normalizeTermName(routine.getName()))); if (routine.isChild() && routine.getParent() != compilationUnit.getRoot()) { QNode parent = routine.getParent(); if (parent instanceof QNamedNode) { // invoke on module String qualifiedParent = compilationUnit.getQualifiedName((QNamedNode) parent); methodInvocation .setExpression(buildExpression(ast, expressionParser.parseTerm(qualifiedParent), null)); } else throw new IntegratedLanguageExpressionRuntimeException( "Invalid routine: " + statement.getRoutine()); } ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation); block.statements().add(expressionStatement); return super.visit(statement); }