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.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public Block convert(org.eclipse.jdt.internal.compiler.ast.Block statement) { Block block = new Block(this.ast); if (statement.sourceEnd > 0) { block.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1); }/* www . j a v a 2s . c om*/ org.eclipse.jdt.internal.compiler.ast.Statement[] statements = statement.statements; if (statements != null) { int statementsLength = statements.length; for (int i = 0; i < statementsLength; i++) { if (statements[i] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) { checkAndAddMultipleLocalDeclaration(statements, i, block.statements()); } else { Statement statement2 = convert(statements[i]); if (statement2 != null) { block.statements().add(statement2); } } } } return block; }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java
License:Open Source License
@Override public void endVisit(final org.eclipse.jdt.core.dom.Block node) { if (!this.isFULLLEVELANALYSIS) { return;/*from ww w . j a va 2 s . c o m*/ } Block element = (Block) this.binding.get(node); initializeNode(element, node); for (Iterator<?> i = node.statements().iterator(); i.hasNext();) { Statement itElement = (Statement) this.binding.get(i.next()); if (itElement != null) { element.getStatements().add(itElement); } } }
From source file:org.eclipse.objectteams.otdt.debug.ui.internal.actions.OTValidBreakpointLocationLocator.java
License:Open Source License
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.Block) */// ww w . j av a 2 s .c om public boolean visit(Block node) { if (visit(node, false)) { if (node.statements().isEmpty() && node.getParent().getNodeType() == ASTNode.METHOD_DECLARATION) { // in case of an empty method, set the breakpoint on the last line of the empty block. fLineLocation = lineNumber(node.getStartPosition() + node.getLength() - 1); fLocationFound = true; fLocationType = LOCATION_LINE; fTypeName = computeTypeName(node); return false; } return true; } return false; }
From source file:org.eclipse.objectteams.otdt.internal.ui.text.correction.TypeProposalSubProcessor.java
License:Open Source License
/** * Find all local variables within block prior to current that match typeToMatch. * Return the variables' names. //from w w w . j a va 2 s . c o m */ @SuppressWarnings("rawtypes") // block.statements() is raw type private static ArrayList<String> getMatchingLocalsPriorTo(Block block, String enclosingTeamName, ASTNode current) { ArrayList<String> result = new ArrayList<String>(); if (current != null) { List statements = block.statements(); for (int i = 0; i < statements.size(); i++) { Object statement = statements.get(i); if (statement instanceof VariableDeclarationStatement) { VariableDeclarationStatement var = (VariableDeclarationStatement) statement; addFragmentsIfMatch(var.getType(), enclosingTeamName, var.fragments(), result); } if (statement == current) break; } } return result; }
From source file:org.eclipse.objectteams.otdt.ui.tests.dom.converter.BaseCallMessageSendTest2.java
License:Open Source License
public void testGetName1() { MethodDeclaration method = _role.getMethods()[0]; TryStatement tryStatement = (TryStatement) method.getBody().statements().get(0); Block block = tryStatement.getBody(); ExpressionStatement exprStatement = (ExpressionStatement) block.statements().get(0); _testObj = (BaseCallMessageSend) exprStatement.getExpression(); String actual = _testObj.getName().getIdentifier(); assertEquals("Base call has wrong name ", "roleMethod0", actual); }
From source file:org.eclipse.objectteams.otdt.ui.tests.dom.converter.WithinStatementTest.java
License:Open Source License
/** Tests if statements in body belong to the same AST as the within statement */ public void testStatements_ASTIdentity() { MethodDeclaration methodDecl = WithinStatementTest.getMethodDeclarationByName(_typeDecl, "withinSimple"); List statements = methodDecl.getBody().statements(); Statement firstStatement = (Statement) statements.get(0); _testObj = (WithinStatement) firstStatement; Block body = (Block) _testObj.getBody(); Statement bodyStatement = (Statement) body.statements().get(0); assertTrue("within: statements don't belong to AST", _testObj.getAST() == bodyStatement.getAST()); }
From source file:org.eclipse.objectteams.otdt.ui.tests.dom.rewrite.ASTRewritingModifyingTeamTest.java
License:Open Source License
public void test0004() throws Exception { // generate some AST: String generated = "public team class MyTeam {\n" + " protected class DisposeWatcher playedBy Item {\n" + " void bar() { nop(); }\n" + " }\n" + "}\n"; ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setKind(ASTParser.K_STATEMENTS); parser.setSource(generated.toCharArray()); Block block = (Block) parser.createAST(null); TypeDeclarationStatement st = (TypeDeclarationStatement) block.statements().get(0); TypeDeclaration decl = (TypeDeclaration) st.getDeclaration(); ASTNode[] myNodes = (ASTNode[]) decl.bodyDeclarations().toArray(new ASTNode[1]); // create a CU to copy into: String existing = "public team class MyTeam {\n" + " protected class OtherRole {}\n" + " void foo() { System.out.println(this); }\n" + "}\n"; parser = ASTParser.newParser(AST.JLS4); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(existing.toCharArray()); CompilationUnit _astCU = (CompilationUnit) parser.createAST(null); TypeDeclaration teamDecl = (TypeDeclaration) _astCU.types().get(0); // copy generated into CU: _astCU.recordModifications();// w w w . ja va 2 s . c om teamDecl.bodyDeclarations().add(ASTNode.copySubtree(_astCU.getAST(), myNodes[0])); // apply change: Document doc = new Document(existing); TextEdit edits = _astCU.rewrite(doc, null); edits.apply(doc); // compare result with expected: String newSource = doc.get(); String expected = "public team class MyTeam {\n" + " protected class OtherRole {}\n" + " void foo() { System.out.println(this); }\n" + " protected class DisposeWatcher playedBy Item {\n" + " void bar() {\n" + " nop();\n" + " }\n" + " }\n" + "}\n"; assertEquals(expected, newSource); }
From source file:org.eclipse.objectteams.otdt.ui.tests.dom.rewrite.ASTRewritingModifyingTeamTest.java
License:Open Source License
public void test0005() throws Exception { // generate some AST: String generated = "public team class MyTeam {\n" + " protected class DisposeWatcher playedBy Item \n" + " base when (hasRole(base)) {\n" + " void bar() { nop(); }\n" + " }\n" + "}\n"; ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setKind(ASTParser.K_STATEMENTS); parser.setSource(generated.toCharArray()); Block block = (Block) parser.createAST(null); TypeDeclarationStatement st = (TypeDeclarationStatement) block.statements().get(0); TypeDeclaration decl = (TypeDeclaration) st.getDeclaration(); ASTNode[] myNodes = (ASTNode[]) decl.bodyDeclarations().toArray(new ASTNode[1]); // create a CU to copy into: String existing = "public team class MyTeam {\n" + " protected class OtherRole {}\n" + " void foo() { System.out.println(this); }\n" + "}\n"; parser = ASTParser.newParser(AST.JLS4); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(existing.toCharArray()); CompilationUnit _astCU = (CompilationUnit) parser.createAST(null); TypeDeclaration teamDecl = (TypeDeclaration) _astCU.types().get(0); // copy generated into CU: _astCU.recordModifications();/* www.ja va 2s.c o m*/ teamDecl.bodyDeclarations().add(ASTNode.copySubtree(_astCU.getAST(), myNodes[0])); // apply change: Document doc = new Document(existing); TextEdit edits = _astCU.rewrite(doc, null); edits.apply(doc); // compare result with expected: String newSource = doc.get(); String expected = "public team class MyTeam {\n" + " protected class OtherRole {}\n" + " void foo() { System.out.println(this); }\n" + " protected class DisposeWatcher playedBy Item\n" + " base when (hasRole(base))\n" + " {\n" + " void bar() {\n" + " nop();\n" + " }\n" + " }\n" + "}\n"; assertEquals(expected, newSource); }
From source file:org.eclipse.objectteams.otdt.ui.tests.dom.rewrite.ASTRewritingModifyingTeamTest.java
License:Open Source License
public void test0006() throws Exception { // generate some AST: String generated = "public team class MyTeam \n" + " when (isSunday(today())) {\n" + " void bar() { nop(); }\n" + "}\n"; ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setKind(ASTParser.K_STATEMENTS); parser.setSource(generated.toCharArray()); Block block = (Block) parser.createAST(null); System.out.println(block);//from ww w.j ava 2s . c o m TypeDeclarationStatement st = (TypeDeclarationStatement) block.statements().get(0); TypeDeclaration decl = (TypeDeclaration) st.getDeclaration(); // create a CU to copy into: String existing = "import javax.swing.JFrame;\n"; parser = ASTParser.newParser(AST.JLS4); parser.setKind(ASTParser.K_COMPILATION_UNIT); parser.setSource(existing.toCharArray()); CompilationUnit _astCU = (CompilationUnit) parser.createAST(null); // copy generated into CU: _astCU.recordModifications(); _astCU.types().add(ASTNode.copySubtree(_astCU.getAST(), decl)); // apply change: Document doc = new Document(existing); TextEdit edits = _astCU.rewrite(doc, null); edits.apply(doc); // compare result with expected: String newSource = doc.get(); String expected = "import javax.swing.JFrame;\n\n" + "public team class MyTeam\n" + " when (isSunday(today()))\n" + "{\n" + " void bar() {\n" + " nop();\n" + " }\n" + "}\n"; assertEquals(expected, newSource); }
From source file:org.eclipse.umlgen.reverse.java.JavaReverseCUVisitor.java
License:Open Source License
/** * linkToLastStatement : look for last statement and call control flow creation simple statement. * * @param node/* w ww . j av a 2 s . c om*/ */ protected void linkToLastStatement(Statement node) { ActivityNode targetNode = null; ActivityNode sourceNode = null; // If last statement was a parent node, link its inner exit to us. if (lastStatement != null && parentStatements.contains(lastStatement)) { // if last statement has a designated exit map, use that if (innerExitMap.containsKey(lastStatement)) { sourceNode = innerExitMap.get(lastStatement); } else { // TODO Otherwise, we might be inside a region. Add a start point and link to it // FIXME maybe the parent can create the nodes instead } } else { LiteralString stringuard = UMLFactory.eINSTANCE.createLiteralString(); stringuard.setValue("else"); // Specific case : else statement // parentStatements does not contains lastStatement any more if (node.getParent().getNodeType() == ASTNode.IF_STATEMENT) { IfStatement parent = (IfStatement) node.getParent(); if (choiceMap.containsKey(parent) && parent.getElseStatement() != null && parent.getElseStatement().equals(node)) { sourceNode = choiceMap.get(parent); choiceMap.remove(parent); if (lastGuard == null) { lastGuard = stringuard; } } } if (node.getParent().getNodeType() == ASTNode.BLOCK && node.getParent().getParent().getNodeType() == ASTNode.IF_STATEMENT) { IfStatement parent = (IfStatement) node.getParent().getParent(); Block block; if (parent.getElseStatement() instanceof IfStatement) { AST ast = new AST(); block = (Block) ast.createInstance(ASTNode.BLOCK); List<Statement> elseblock = new ArrayList<Statement>(); elseblock.add(parent.getElseStatement()); } else { block = (Block) parent.getElseStatement(); } if (choiceMap.containsKey(parent) && block != null && block.statements().size() > 0 && block.statements().get(0).equals(node)) { sourceNode = choiceMap.get(parent); choiceMap.remove(parent); if (lastGuard == null) { lastGuard = stringuard; } } } } // if this has a registered entry node, use it if (entryNodeMap.containsKey(node)) { targetNode = entryNodeMap.get(node); // if we haven't yet found a sourceNode, use the exitMap's or a new one if (sourceNode == null) { if (lastActivityNode != null) { sourceNode = lastActivityNode; lastActivityNode = null; } else if (lastStatement == null || !exitNodeMap.containsKey(lastStatement)) { sourceNode = initNode; } else if (exitNodeMap.containsKey(lastStatement)) { sourceNode = exitNodeMap.get(lastStatement); } } } createControlFlow(targetNode, sourceNode); }