本文整理汇总了Java中org.eclipse.jdt.core.dom.Block.statements方法的典型用法代码示例。如果您正苦于以下问题:Java Block.statements方法的具体用法?Java Block.statements怎么用?Java Block.statements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.Block
的用法示例。
在下文中一共展示了Block.statements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findUnnecessaryStore
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private void findUnnecessaryStore(ReturnStatement node) {
Block block = TraversalUtil.findClosestAncestor(node, Block.class);
@SuppressWarnings("unchecked")
List<Statement> blockStatements = block.statements();
for (int i = 1; i < blockStatements.size(); i++) {
Statement statement = blockStatements.get(i);
if (statement == this.originalReturn) {
for (int j = i - 1; j >= 0; j--) {
Statement storeStatement = blockStatements.get(j);
if (storeStatement instanceof VariableDeclarationStatement) {
splitStatementAndInitializer((VariableDeclarationStatement) storeStatement);
return;
} else if (storeStatement instanceof ExpressionStatement) {
if (splitStatementAndInitializer((ExpressionStatement) storeStatement)) {
// we found our extra storage statement
return;
}
}
}
}
}
}
示例2: calculateMethodCalls
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
/**
* Method to calculate method calls in the method's body.
*/
@SuppressWarnings("unchecked")
private void calculateMethodCalls(){
Iterator<MethodDeclaration> itMethods = methodsList.iterator();
while (itMethods.hasNext()){
MethodDeclaration firstMethod = itMethods.next();
Block firstMethodBody = firstMethod.getBody();
if (firstMethodBody != null){
List<Statement> firstMethodStatements = firstMethodBody.statements();
if (!firstMethodStatements.isEmpty()){
for (IMethod mtd : listOfMethodsName){
if (firstMethodStatements.toString().contains(mtd.getElementName())){
numberMethodCalls++;
}
}
}
}
}
}
示例3: analyzeBaseMethod
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private void analyzeBaseMethod(IMethod method, Method tmlMethod)
throws IllegalArgumentException, JavaModelException {
CompilationUnit cu = JDTUtils
.createASTRoot(method.getCompilationUnit());
MethodDeclaration md = JDTUtils.createMethodDeclaration(cu, method);
Block body = md.getBody();
if (body != null) {
for (Object statement : body.statements()) {
if (statement instanceof Statement) {
Statement st = (Statement) statement;
processIfStatements(st, tmlMethod);
}
}
}
}
示例4: collectIfStatements
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private List<IfStatement> collectIfStatements(MethodDeclaration md) {
List<IfStatement> ifStatements = new ArrayList<IfStatement>();
Block body = md.getBody();
if (body == null) {
return ifStatements;
}
for (Object statement : body.statements()) {
if (statement instanceof Statement) {
Statement st = (Statement) statement;
ifStatements.addAll(collectIfStatements(st));
}
}
return ifStatements;
}
示例5: getCopyOfInner
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
public static ASTNode getCopyOfInner(ASTRewrite rewrite, ASTNode statement, boolean toControlStatementBody) {
if (statement.getNodeType() == ASTNode.BLOCK) {
Block block= (Block) statement;
List<Statement> innerStatements= block.statements();
int nStatements= innerStatements.size();
if (nStatements == 1) {
return rewrite.createCopyTarget(innerStatements.get(0));
} else if (nStatements > 1) {
if (toControlStatementBody) {
return rewrite.createCopyTarget(block);
}
ListRewrite listRewrite= rewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY);
ASTNode first= innerStatements.get(0);
ASTNode last= innerStatements.get(nStatements - 1);
return listRewrite.createCopyTarget(first, last);
}
return null;
} else {
return rewrite.createCopyTarget(statement);
}
}
示例6: computeLastStatementSelected
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private void computeLastStatementSelected() {
ASTNode[] nodes= getSelectedNodes();
if (nodes.length == 0) {
fIsLastStatementSelected= false;
} else {
Block body= null;
if (fEnclosingBodyDeclaration instanceof MethodDeclaration) {
body= ((MethodDeclaration) fEnclosingBodyDeclaration).getBody();
} else if (fEnclosingBodyDeclaration instanceof Initializer) {
body= ((Initializer) fEnclosingBodyDeclaration).getBody();
}
if (body != null) {
List<Statement> statements= body.statements();
fIsLastStatementSelected= nodes[nodes.length - 1] == statements.get(statements.size() - 1);
}
}
}
示例7: findLastTryStatementUsingVariable
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static TryStatement findLastTryStatementUsingVariable(SimpleName variable) {
// looks for the last try statement that has a reference to the variable referred to
// by the included simpleName.
// If we can't find such a try block, we give up trying to fix
Block parentBlock = TraversalUtil.findClosestAncestor(variable, Block.class);
List<Statement> statements = parentBlock.statements();
for (int i = statements.size() - 1; i >= 0; i--) {
Statement s = statements.get(i);
if (s instanceof TryStatement) {
TryStatement tryStatement = (TryStatement) s;
if (tryRefersToVariable(tryStatement, variable)) {
return tryStatement;
}
}
}
return null;
}
示例8: checkStatementsInMethodsDeclaration
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
/**
* Method that check statements like try/catch, while, if/else in method's declaration,
* where weights are unspecified complexity factors.
* @author Mariana Azevedo
* @since 13/07/2014
* @param itItem
*/
@SuppressWarnings("unchecked")
private void checkStatementsInMethodsDeclaration(Object itItem) {
Block block = ((MethodDeclaration) itItem).getBody();
if (block != null){
List<Statement> statementsList = block.statements();
Iterator<Statement> itStatements = statementsList.iterator();
coveringStatements(itStatements);
}
}
示例9: visit
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
@Override
public boolean visit(MethodDeclaration methodDecl) {
int modifiers = methodDecl.getModifiers();
if(Modifier.isPublic(modifiers) && !methodDecl.isConstructor() && !methodDecl.getReturnType2().isPrimitiveType()){
Block body = methodDecl.getBody();
if(body!=null){
List<Statement> statements = body.statements();
for (Statement stmnt : statements) {
if(stmnt instanceof ReturnStatement){
ReturnStatement retStmnt = (ReturnStatement)stmnt;
Expression expression = retStmnt.getExpression();
if(expression instanceof SimpleName){
SimpleName simpleExpr = (SimpleName)expression;
IBinding resolveBinding = simpleExpr.resolveBinding();
Variable variable = context.getAllBindingKeyToVariableMap(resolveBinding.getKey());
if(variable!=null){
context.removeEncapsulatedVariable(variable);
}
}
}
}
}
}
return super.visit(methodDecl);
}
示例10: callsWritingConstructor
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private boolean callsWritingConstructor(
MethodDeclaration methodDeclaration,
HashSet<IMethodBinding> writingConstructorBindings,
Set<MethodDeclaration> visitedMethodDeclarations) {
Block body = methodDeclaration.getBody();
if (body == null) return false;
List<Statement> statements = body.statements();
if (statements.size() == 0) return false;
Statement statement = statements.get(0);
if (!(statement instanceof ConstructorInvocation)) return false;
ConstructorInvocation invocation = (ConstructorInvocation) statement;
IMethodBinding constructorBinding = invocation.resolveConstructorBinding();
if (constructorBinding == null) return false;
if (writingConstructorBindings.contains(constructorBinding)) {
return true;
} else {
ASTNode declaration =
ASTNodes.findDeclaration(constructorBinding, methodDeclaration.getParent());
if (!(declaration instanceof MethodDeclaration)) return false;
if (visitedMethodDeclarations.contains(declaration)) {
return false;
}
visitedMethodDeclarations.add(methodDeclaration);
return callsWritingConstructor(
(MethodDeclaration) declaration, writingConstructorBindings, visitedMethodDeclarations);
}
}
示例11: checkMethodBody
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
protected static RefactoringStatus checkMethodBody(IMethod method, IProgressMonitor pm) {
RefactoringStatus status = new RefactoringStatus();
ITypeRoot root = method.getCompilationUnit();
CompilationUnit unit = RefactoringASTParser.parseWithASTProvider(root, false, new SubProgressMonitor(pm, 1));
MethodDeclaration declaration;
try {
declaration = ASTNodeSearchUtil.getMethodDeclarationNode(method, unit);
if (declaration != null) {
Block body = declaration.getBody();
if (body != null) {
@SuppressWarnings("rawtypes")
List statements = body.statements();
if (!statements.isEmpty()) {
// TODO for now.
addWarning(status, Messages.ForEachLoopToLambdaRefactoring_NoMethodsWithStatements, method);
}
}
}
} catch (JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return status;
}
开发者ID:mdarefin,项目名称:Convert-For-Each-Loop-to-Lambda-Expression-Eclipse-Plugin,代码行数:30,代码来源:ForeachLoopToLambdaRefactoring.java
示例12: getSuperConstructorCallNode
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private static SuperConstructorInvocation getSuperConstructorCallNode(IMethod constructor, CompilationUnit cuNode) throws JavaModelException {
Assert.isTrue(constructor.isConstructor());
MethodDeclaration constructorNode= ASTNodeSearchUtil.getMethodDeclarationNode(constructor, cuNode);
Assert.isTrue(constructorNode.isConstructor());
Block body= constructorNode.getBody();
Assert.isNotNull(body);
List<Statement> statements= body.statements();
if (! statements.isEmpty() && statements.get(0) instanceof SuperConstructorInvocation)
return (SuperConstructorInvocation)statements.get(0);
return null;
}
示例13: callsWritingConstructor
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private boolean callsWritingConstructor(MethodDeclaration methodDeclaration, HashSet<IMethodBinding> writingConstructorBindings, Set<MethodDeclaration> visitedMethodDeclarations) {
Block body= methodDeclaration.getBody();
if (body == null)
return false;
List<Statement> statements= body.statements();
if (statements.size() == 0)
return false;
Statement statement= statements.get(0);
if (!(statement instanceof ConstructorInvocation))
return false;
ConstructorInvocation invocation= (ConstructorInvocation)statement;
IMethodBinding constructorBinding= invocation.resolveConstructorBinding();
if (constructorBinding == null)
return false;
if (writingConstructorBindings.contains(constructorBinding)) {
return true;
} else {
ASTNode declaration= ASTNodes.findDeclaration(constructorBinding, methodDeclaration.getParent());
if (!(declaration instanceof MethodDeclaration))
return false;
if (visitedMethodDeclarations.contains(declaration)) {
return false;
}
visitedMethodDeclarations.add(methodDeclaration);
return callsWritingConstructor((MethodDeclaration)declaration, writingConstructorBindings, visitedMethodDeclarations);
}
}
示例14: markReferences
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private void markReferences() {
fCaughtExceptions= new ArrayList<ITypeBinding>();
boolean isVoid= true;
Type returnType= fMethodDeclaration.getReturnType2();
if (returnType != null) {
ITypeBinding returnTypeBinding= returnType.resolveBinding();
isVoid= returnTypeBinding != null && Bindings.isVoidType(returnTypeBinding);
}
fMethodDeclaration.accept(this);
Block block= fMethodDeclaration.getBody();
if (block != null) {
List<Statement> statements= block.statements();
if (statements.size() > 0) {
Statement last= statements.get(statements.size() - 1);
int maxVariableId= LocalVariableIndex.perform(fMethodDeclaration);
FlowContext flowContext= new FlowContext(0, maxVariableId + 1);
flowContext.setConsiderAccessMode(false);
flowContext.setComputeMode(FlowContext.ARGUMENTS);
InOutFlowAnalyzer flowAnalyzer= new InOutFlowAnalyzer(flowContext);
FlowInfo info= flowAnalyzer.perform(new ASTNode[] {last});
if (!info.isNoReturn() && !isVoid) {
if (!info.isPartialReturn())
return;
}
}
int offset= fMethodDeclaration.getStartPosition() + fMethodDeclaration.getLength() - 1; // closing bracket
fResult.add(new OccurrenceLocation(offset, 1, 0, fExitDescription));
}
}
示例15: prepareConversionToLambda
import org.eclipse.jdt.core.dom.Block; //导入方法依赖的package包/类
private boolean prepareConversionToLambda(CompilationUnit cu, AST ast, ASTRewrite rewriter, ImportRewrite importRewrite, ClassInstanceCreation classInstanceCreation) {
AnonymousClassDeclaration anonymTypeDecl = classInstanceCreation.getAnonymousClassDeclaration();
List<BodyDeclaration> bodyDeclarations = anonymTypeDecl.bodyDeclarations();
Object object = bodyDeclarations.get(0);
if (!(object instanceof MethodDeclaration)) {
return false;
}
MethodDeclaration methodDeclaration = (MethodDeclaration) object;
Optional<IMethodBinding> methodInInterface = findMethodInInterface(classInstanceCreation, ast.newSimpleName(methodDeclaration.getName() + ADAPTER_METHOD_POSTFIX), methodDeclaration.parameters());
if (!methodInInterface.isPresent()) {
return false;
}
LambdaExpression lambdaExpression = ast.newLambdaExpression();
List<SingleVariableDeclaration> methodParameters = methodDeclaration.parameters();
// use short form with inferred parameter types and without parentheses if possible
boolean createExplicitlyTypedParameters = hasAnnotation(methodParameters);
prepareLambdaParameters(ast, rewriter, methodParameters, createExplicitlyTypedParameters, lambdaExpression);
Block body = methodDeclaration.getBody();
List<Statement> statements = body.statements();
ASTNode lambdaBody = prepareLambdaBody(body, statements);
lambdaExpression.setBody(getCopyOrReplacement(rewriter, lambdaBody, textEditGroup));
MethodInvocation methodInvocation = prepareMethodInvocation(ast, methodDeclaration, lambdaExpression);
// TODO(fap): insert cast if necessary
try {
prepareChanges(cu, rewriter, importRewrite, classInstanceCreation, textEditGroup, methodInInterface.get(), methodInvocation);
} catch (MalformedTreeException | CoreException | BadLocationException e) {
return false;
}
return true;
}