当前位置: 首页>>代码示例>>Java>>正文


Java Statement类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.Statement的典型用法代码示例。如果您正苦于以下问题:Java Statement类的具体用法?Java Statement怎么用?Java Statement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Statement类属于org.eclipse.jdt.core.dom包,在下文中一共展示了Statement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: asClosure

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
public static Optional<GroovyClosure> asClosure(ASTNodeFactory nodeFactory, GroovyClosureBuilder groovyClosureBuilder,
                                      Expression expression, String methodName) {
    if (expression instanceof ClassInstanceCreation) {
        ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
        if (classInstanceCreation.getAnonymousClassDeclaration() != null) {
            AnonymousClassDeclaration classDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
            if (classDeclaration.bodyDeclarations().size() == 1 &&
                    classDeclaration.bodyDeclarations().get(0) instanceof MethodDeclaration &&
                    ((MethodDeclaration) classDeclaration.bodyDeclarations().get(0))
                            .getName().getIdentifier().equals(methodName)) {
                MethodDeclaration methodDeclaration = (MethodDeclaration) classDeclaration.bodyDeclarations().get(0);
                List<Statement> statements = nodeFactory.clone(methodDeclaration.getBody()).statements();
                GroovyClosure closure = groovyClosureBuilder.aClosure()
                        .withBodyStatements(statements)
                        .withTypeLiteral(nodeFactory.typeLiteral(type(nodeFactory, classInstanceCreation)))
                        .withArgument(nodeFactory.clone((SingleVariableDeclaration) methodDeclaration.parameters().get(0)))
                        .build();
                return Optional.of(closure);
            }
        }
    }
    return empty();
}
 
开发者ID:opaluchlukasz,项目名称:junit2spock,代码行数:24,代码来源:ClosureHelper.java

示例2: calculateMethodCalls

import org.eclipse.jdt.core.dom.Statement; //导入依赖的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++;
					}
				}
			}
		}
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:29,代码来源:ResponseForClassVisitor.java

示例3: splitUpDeclarations

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
private void splitUpDeclarations(ASTRewrite rewrite, TextEditGroup group, VariableDeclarationFragment frag, VariableDeclarationStatement originalStatement, List<Expression> sideEffects) {
	if (sideEffects.size() > 0) {
		ListRewrite statementRewrite= rewrite.getListRewrite(originalStatement.getParent(), (ChildListPropertyDescriptor) originalStatement.getLocationInParent());

		Statement previousStatement= originalStatement;
		for (int i= 0; i < sideEffects.size(); i++) {
			Expression sideEffect= sideEffects.get(i);
			Expression movedInit= (Expression) rewrite.createMoveTarget(sideEffect);
			ExpressionStatement wrapped= rewrite.getAST().newExpressionStatement(movedInit);
			statementRewrite.insertAfter(wrapped, previousStatement, group);
			previousStatement= wrapped;
		}

		VariableDeclarationStatement newDeclaration= null;
		List<VariableDeclarationFragment> fragments= originalStatement.fragments();
		int fragIndex= fragments.indexOf(frag);
		ListIterator<VariableDeclarationFragment> fragmentIterator= fragments.listIterator(fragIndex+1);
		while (fragmentIterator.hasNext()) {
			VariableDeclarationFragment currentFragment= fragmentIterator.next();
			VariableDeclarationFragment movedFragment= (VariableDeclarationFragment) rewrite.createMoveTarget(currentFragment);
			if (newDeclaration == null) {
				newDeclaration= rewrite.getAST().newVariableDeclarationStatement(movedFragment);
				Type copiedType= (Type) rewrite.createCopyTarget(originalStatement.getType());
				newDeclaration.setType(copiedType);
			} else {
				newDeclaration.fragments().add(movedFragment);
			}
		}
		if (newDeclaration != null){
			statementRewrite.insertAfter(newDeclaration, previousStatement, group);
			if (originalStatement.fragments().size() == newDeclaration.fragments().size() + 1){
				rewrite.remove(originalStatement, group);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:UnusedCodeFix.java

示例4: getParentLoopBody

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
private Statement getParentLoopBody(ASTNode node) {
	Statement stmt = null;
	ASTNode start = node;
	while (start != null && !(start instanceof ForStatement) && !(start instanceof DoStatement) && !(start instanceof WhileStatement) && !(start instanceof EnhancedForStatement) && !(start instanceof SwitchStatement)) {
		start = start.getParent();
	}
	if (start instanceof ForStatement) {
		stmt = ((ForStatement) start).getBody();
	} else if (start instanceof DoStatement) {
		stmt = ((DoStatement) start).getBody();
	} else if (start instanceof WhileStatement) {
		stmt = ((WhileStatement) start).getBody();
	} else if (start instanceof EnhancedForStatement) {
		stmt = ((EnhancedForStatement) start).getBody();
	}
	if (start != null && start.getParent() instanceof LabeledStatement) {
		LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
		fEnclosingLoopLabel = labeledStatement.getLabel();
	}
	return stmt;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:ExtractMethodAnalyzer.java

示例5: analyzeBaseMethod

import org.eclipse.jdt.core.dom.Statement; //导入依赖的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);
	}
    }
}

   }
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:19,代码来源:TestCasesGenerator.java

示例6: collectIfStatements

import org.eclipse.jdt.core.dom.Statement; //导入依赖的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;
   }
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:19,代码来源:MethodAnalyzer.java

示例7: createMethodInvocation

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
/**
 * Creates the corresponding statement for the method invocation, based on the return type.
 *
 * @param declaration the method declaration where the invocation statement is inserted
 * @param invocation the method invocation being encapsulated by the resulting statement
 * @return the corresponding statement
 */
protected Statement createMethodInvocation(
    final MethodDeclaration declaration, final MethodInvocation invocation) {
  Assert.isNotNull(declaration);
  Assert.isNotNull(invocation);
  Statement statement = null;
  final Type type = declaration.getReturnType2();
  if (type == null) statement = createExpressionStatement(invocation);
  else {
    if (type instanceof PrimitiveType) {
      final PrimitiveType primitive = (PrimitiveType) type;
      if (primitive.getPrimitiveTypeCode().equals(PrimitiveType.VOID))
        statement = createExpressionStatement(invocation);
      else statement = createReturnStatement(invocation);
    } else statement = createReturnStatement(invocation);
  }
  return statement;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:DelegateMethodCreator.java

示例8: newFieldAssignment

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
private Statement newFieldAssignment(
    AST ast, SimpleName fieldNameNode, Expression initializer, boolean useThisAccess) {
  Assignment assignment = ast.newAssignment();
  if (useThisAccess) {
    FieldAccess access = ast.newFieldAccess();
    access.setExpression(ast.newThisExpression());
    access.setName(fieldNameNode);
    assignment.setLeftHandSide(access);
  } else {
    assignment.setLeftHandSide(fieldNameNode);
  }
  assignment.setOperator(Assignment.Operator.ASSIGN);
  assignment.setRightHandSide(initializer);

  return ast.newExpressionStatement(assignment);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:ConvertAnonymousToNestedRefactoring.java

示例9: isSingleControlStatementWithoutBlock

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
private boolean isSingleControlStatementWithoutBlock() {
  List<Statement> statements = fDeclaration.getBody().statements();
  int size = statements.size();
  if (size != 1) return false;
  Statement statement = statements.get(size - 1);
  int nodeType = statement.getNodeType();
  if (nodeType == ASTNode.IF_STATEMENT) {
    IfStatement ifStatement = (IfStatement) statement;
    return !(ifStatement.getThenStatement() instanceof Block)
        && !(ifStatement.getElseStatement() instanceof Block);
  } else if (nodeType == ASTNode.FOR_STATEMENT) {
    return !(((ForStatement) statement).getBody() instanceof Block);
  } else if (nodeType == ASTNode.WHILE_STATEMENT) {
    return !(((WhileStatement) statement).getBody() instanceof Block);
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:SourceProvider.java

示例10: getParentLoopBody

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
private Statement getParentLoopBody(ASTNode node) {
  Statement stmt = null;
  ASTNode start = node;
  while (start != null
      && !(start instanceof ForStatement)
      && !(start instanceof DoStatement)
      && !(start instanceof WhileStatement)
      && !(start instanceof EnhancedForStatement)
      && !(start instanceof SwitchStatement)) {
    start = start.getParent();
  }
  if (start instanceof ForStatement) {
    stmt = ((ForStatement) start).getBody();
  } else if (start instanceof DoStatement) {
    stmt = ((DoStatement) start).getBody();
  } else if (start instanceof WhileStatement) {
    stmt = ((WhileStatement) start).getBody();
  } else if (start instanceof EnhancedForStatement) {
    stmt = ((EnhancedForStatement) start).getBody();
  }
  if (start != null && start.getParent() instanceof LabeledStatement) {
    LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
    fEnclosingLoopLabel = labeledStatement.getLabel();
  }
  return stmt;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:ExtractMethodAnalyzer.java

示例11: visit

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
/**
 * The first thing we do is add the variable to the node aliases if it is
 * present in a statement.
 */
public boolean visit(SimpleName node){
	/* All we really need from this is the variable binding. */
	IBinding binding = node.resolveBinding();
	
	/* Make sure this is a variable. */
	if(binding instanceof IVariableBinding){
		LinkedList<String> variables;
		
		/* Get the statement. */
		Statement statement = Slicer.getStatement(node);
		
		if(this.aliases.containsKey(statement)){
			variables = this.aliases.get(statement);
		}
		else{
			variables = new LinkedList<String>();
			this.aliases.put(new Integer(statement.getStartPosition()), variables);
		}
		variables.add(binding.getKey());
	}
	
	return true;
}
 
开发者ID:qhanam,项目名称:Slicer,代码行数:28,代码来源:AliasVisitor.java

示例12: instrumentStart

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Statement instrumentStart(final CodeSection codeSection, final AST nodeFactory) {
	final EclipseStatementCreationHelper helper = new EclipseStatementCreationHelper(nodeFactory);
	final MethodInvocation startInvocation = nodeFactory.newMethodInvocation();
	startInvocation.setExpression(helper.getName("de", "uka", "ipd", "sdq", "beagle", "measurement", "kieker",
		"remote", "MeasurementCentral"));
	startInvocation.setName(nodeFactory.newSimpleName("startResourceDemand"));
	startInvocation.arguments().add(nodeFactory.newNumberLiteral("" + this.identifier.getIdOf(codeSection)));
	return nodeFactory.newExpressionStatement(startInvocation);
}
 
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:12,代码来源:ResourceDemandInstrumentationStrategy.java

示例13: instrumentEnd

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
@Override
public Statement instrumentEnd(final CodeSection codeSection, final AST nodeFactory) {
	final EclipseStatementCreationHelper helper = new EclipseStatementCreationHelper(nodeFactory);
	final MethodInvocation endInvocation = nodeFactory.newMethodInvocation();
	endInvocation.setExpression(helper.getName("de", "uka", "ipd", "sdq", "beagle", "measurement", "kieker",
		"remote", "MeasurementCentral"));
	endInvocation.setName(nodeFactory.newSimpleName("stopResourceDemand"));
	return nodeFactory.newExpressionStatement(endInvocation);
}
 
开发者ID:Beagle-PSE,项目名称:Beagle,代码行数:10,代码来源:ResourceDemandInstrumentationStrategy.java

示例14: preNext

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
@Override
public boolean preNext(IfStatement curElement) {

	Statement thenStatement = curElement.getThenStatement();
	Statement elseStatement = curElement.getElseStatement();
	Expression condition = curElement.getExpression();

	if (elseStatement == null) {
		compiler.println("opt " + condition.toString());
		return true;
	} else {
		compiler.println("alt " + condition.toString());
		thenStatement.accept(compiler);
		if (elseStatement instanceof IfStatement) {
			processAltStatement((IfStatement) elseStatement);
		} else {
			compiler.println("else");
			elseStatement.accept(compiler);
		}
		return false;
	}
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:23,代码来源:OptAltFragment.java

示例15: processAltStatement

import org.eclipse.jdt.core.dom.Statement; //导入依赖的package包/类
private void processAltStatement(IfStatement statement) {
	Statement thenStatement = statement.getThenStatement();
	Statement elseStatement = statement.getElseStatement();
	Expression condition = statement.getExpression();

	compiler.println("else " + condition.toString());
	thenStatement.accept(compiler);
	if (elseStatement != null) {
		if (elseStatement instanceof IfStatement) {
			processAltStatement((IfStatement) elseStatement);
		} else {
			compiler.println("else");
			elseStatement.accept(compiler);
		}
	}
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:17,代码来源:OptAltFragment.java


注:本文中的org.eclipse.jdt.core.dom.Statement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。