List of usage examples for org.eclipse.jdt.core.dom Statement getAST
public final AST getAST()
From source file:com.google.devtools.j2objc.util.ASTUtil.java
License:Apache License
/** * Returns the given statement as a list of statements that can be added to. * If node is a Block, then returns it's statement list. If node is the direct * child of a Block, returns the sublist containing node as the only element. * Otherwise, creates a new Block node in the place of node and returns its * list of statements.//from www. j ava2s . c om */ public static List<Statement> asStatementList(Statement node) { if (node instanceof Block) { return getStatements((Block) node); } ASTNode parent = node.getParent(); if (parent instanceof Block) { List<Statement> stmts = getStatements((Block) parent); for (int i = 0; i < stmts.size(); i++) { if (stmts.get(i) == node) { return stmts.subList(i, i + 1); } } } Block block = node.getAST().newBlock(); setProperty(node, block); getStatements(block).add(node); return getStatements(block); }
From source file:de.ovgu.cide.export.physical.ahead.JakFeatureRefactorer.java
License:Open Source License
static void replaceStatement(Statement target, Statement replacement) { ASTNode p = target.getParent();/*from w ww . j a v a2 s. c o m*/ if (target instanceof Block && !(replacement instanceof Block)) { Block b = replacement.getAST().newBlock(); b.statements().add(replacement); replacement = b; } StructuralPropertyDescriptor prop = target.getLocationInParent(); if (prop.isSimpleProperty() || prop.isChildProperty()) { p.setStructuralProperty(prop, replacement); } else if (prop.isChildListProperty()) { assert false; } }
From source file:de.ovgu.cide.export.physical.ahead.JakHookMethodHelper.java
License:Open Source License
private Statement copyStatement(Statement stmt) { return (Statement) ASTNode.copySubtree(stmt.getAST(), stmt); }
From source file:de.ovgu.cide.export.physical.ahead.RefactoringUtils.java
License:Open Source License
public static Statement copyStatement(Statement stmt) { return (Statement) ASTNode.copySubtree(stmt.getAST(), stmt); }
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.spoofax.interpreter.adapter.ecj.ECJFactory.java
License:LGPL
private Statement asStatement(IStrategoTerm term) { Statement x = ((WrappedStatement) term).getWrappee(); return x.getParent() == null && x.getAST() == ast ? x : (Statement) ASTNode.copySubtree(ast, x); }