类org.eclipse.jdt.core.dom.Statement源码实例Demo

下面列出了怎么用org.eclipse.jdt.core.dom.Statement的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	TextEditGroup group= createTextEditGroup(FixMessages.Java50Fix_ConvertToEnhancedForLoop_description, cuRewrite);
	ASTRewrite rewrite= cuRewrite.getASTRewrite();

	TightSourceRangeComputer rangeComputer;
	if (rewrite.getExtendedSourceRangeComputer() instanceof TightSourceRangeComputer) {
		rangeComputer= (TightSourceRangeComputer)rewrite.getExtendedSourceRangeComputer();
	} else {
		rangeComputer= new TightSourceRangeComputer();
	}
	rangeComputer.addTightSourceNode(getForStatement());
	rewrite.setTargetSourceRangeComputer(rangeComputer);

	Statement statement= convert(cuRewrite, group, positionGroups);
	rewrite.replace(getForStatement(), statement, group);
}
 
源代码2 项目: JDeodorant   文件: TypeCheckElimination.java
public double getAverageNumberOfStatements() {
	if(averageNumberOfStatements == 0) {
		List<ArrayList<Statement>> typeCheckStatements = new ArrayList<ArrayList<Statement>>(getTypeCheckStatements());
		ArrayList<Statement> defaultCaseStatements = getDefaultCaseStatements();
		if(!defaultCaseStatements.isEmpty())
			typeCheckStatements.add(defaultCaseStatements);
		StatementExtractor statementExtractor = new StatementExtractor();
		int numberOfCases = typeCheckStatements.size();
		int totalNumberOfStatements = 0;
		for(ArrayList<Statement> statements : typeCheckStatements) {
			for(Statement statement : statements) {
				totalNumberOfStatements += statementExtractor.getTotalNumberOfStatements(statement);
			}
		}
		averageNumberOfStatements = (double)totalNumberOfStatements/(double)numberOfCases;
	}
	return averageNumberOfStatements;
}
 
源代码3 项目: JDeodorant   文件: ASTNodeMatcher.java
private static List<SimpleName> getOccurrencesOfSimpleName(ASTNode node, SimpleName simpleName)
{
	List<SimpleName> returnList = new ArrayList<SimpleName>();
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
	List<Expression> simpleNames = new ArrayList<Expression>();
	if (node instanceof Expression)
	{
		simpleNames.addAll(expressionExtractor.getVariableInstructions((Expression)node));
	}
	else if (node instanceof Statement)
	{
		simpleNames.addAll(expressionExtractor.getVariableInstructions((Statement)node));
	}
	for (Expression currentExpression : simpleNames)
	{
		SimpleName currentSimpleName = (SimpleName)currentExpression;
		IBinding currentSimpleNameBinding = currentSimpleName.resolveBinding();
		if (currentSimpleNameBinding != null && currentSimpleNameBinding.isEqualTo(simpleName.resolveBinding()))
		{
			returnList.add(currentSimpleName);
		}
	}
	return returnList;
}
 
private static boolean isLastStatementInEnclosingMethodOrLambda(Statement statement) {
	ASTNode currentStructure= statement;
	ASTNode currentParent= statement.getParent();
	while (!(currentParent instanceof MethodDeclaration || currentParent instanceof LambdaExpression)) {
		// should not be in a loop
		if (currentParent instanceof ForStatement || currentParent instanceof EnhancedForStatement
				|| currentParent instanceof WhileStatement || currentParent instanceof DoStatement) {
			return false;
		}
		if (currentParent instanceof Block) {
			Block parentBlock= (Block) currentParent;
			if (parentBlock.statements().indexOf(currentStructure) != parentBlock.statements().size() - 1) { // not last statement in the block
				return false;
			}
		}
		currentStructure= currentParent;
		currentParent= currentParent.getParent();
	}
	return true;
}
 
源代码5 项目: JDeodorant   文件: PDG.java
private PDGNode findParentOfBlockNode(PDGBlockNode blockNode) {
	Statement statement = blockNode.getASTStatement();
	ASTNode parent = statement.getParent();
	while(parent instanceof Block) {
		parent = parent.getParent();
	}
	if(entryNode.getMethod().getMethodDeclaration().equals(parent)) {
		return entryNode;
	}
	for(GraphNode node : nodes) {
		PDGNode pdgNode = (PDGNode)node;
		if(pdgNode.getASTStatement().equals(parent)) {
			return pdgNode;
		}
	}
	return null;
}
 
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final TextEditGroup group= createTextEditGroup(FixMessages.Java50Fix_ConvertToEnhancedForLoop_description, cuRewrite);

	final ASTRewrite astRewrite= cuRewrite.getASTRewrite();

	TightSourceRangeComputer rangeComputer;
	if (astRewrite.getExtendedSourceRangeComputer() instanceof TightSourceRangeComputer) {
		rangeComputer= (TightSourceRangeComputer)astRewrite.getExtendedSourceRangeComputer();
	} else {
		rangeComputer= new TightSourceRangeComputer();
	}
	rangeComputer.addTightSourceNode(getForStatement());
	astRewrite.setTargetSourceRangeComputer(rangeComputer);

	Statement statement= convert(cuRewrite, group, positionGroups);
	astRewrite.replace(getForStatement(), statement, group);
}
 
源代码7 项目: eclipse.jdt.ls   文件: ExtractMethodAnalyzer.java
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;
}
 
private Statement createAddArrayHashCode(IVariableBinding binding) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	if (JavaModelUtil.is50OrHigher(fRewrite.getCu().getJavaProject())) {
		invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
		invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
		invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
	} else {
		invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
		final IJavaElement element= fType.getJavaElement();
		if (element != null && !"".equals(element.getElementName())) //$NON-NLS-1$
			invoc.setExpression(fAst.newSimpleName(element.getElementName()));
		invoc.arguments().add(getThisAccessForHashCode(binding.getName()));
		ITypeBinding type= binding.getType().getElementType();
		if (!Bindings.isVoidType(type)) {
			if (!type.isPrimitive() || binding.getType().getDimensions() >= 2)
				type= fAst.resolveWellKnownType(JAVA_LANG_OBJECT);
			if (!fCustomHashCodeTypes.contains(type))
				fCustomHashCodeTypes.add(type);
		}
	}
	return prepareAssignment(invoc);
}
 
源代码9 项目: JDeodorant   文件: StatementObject.java
public StatementObject(Statement statement, StatementType type, AbstractMethodFragment parent) {
	super(statement, type, parent);
	
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
       List<Expression> assignments = expressionExtractor.getAssignments(statement);
       List<Expression> postfixExpressions = expressionExtractor.getPostfixExpressions(statement);
       List<Expression> prefixExpressions = expressionExtractor.getPrefixExpressions(statement);
       processVariables(expressionExtractor.getVariableInstructions(statement), assignments, postfixExpressions, prefixExpressions);
	processMethodInvocations(expressionExtractor.getMethodInvocations(statement));
	processClassInstanceCreations(expressionExtractor.getClassInstanceCreations(statement));
	processArrayCreations(expressionExtractor.getArrayCreations(statement));
	//processArrayAccesses(expressionExtractor.getArrayAccesses(statement));
	processLiterals(expressionExtractor.getLiterals(statement));
	if(statement instanceof ThrowStatement) {
		processThrowStatement((ThrowStatement)statement);
	}
	if(statement instanceof ConstructorInvocation) {
		processConstructorInvocation((ConstructorInvocation)statement);
	}
}
 
源代码10 项目: JDeodorant   文件: TernaryControlStructure.java
private void initializeFields(Statement node)
{
	ConditionalExpression conditionalExpression = AbstractControlStructureUtilities.hasOneConditionalExpression(node);
	if (conditionalExpression != null)
	{
		this.conditionalExpression = conditionalExpression;
		this.condition             = conditionalExpression.getExpression();
		this.thenExpression        = conditionalExpression.getThenExpression();
		this.elseExpression        = conditionalExpression.getElseExpression();
	}
	else
	{
		this.conditionalExpression = null;
		this.condition             = null;
		this.thenExpression        = null;
		this.elseExpression        = null;
	}
}
 
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushTemporaryExpression();
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushTemporaryExpression();

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
public static List<Statement> unBlock(List<Statement> statements)
{
	List<Statement> returnList = new ArrayList<Statement>();
	for (Statement currentStatement : statements)
	{
		if (currentStatement instanceof Block)
		{
			List<Statement> subList = ((Block)currentStatement).statements();
			returnList.addAll(unBlock(subList));
		}
		else
		{
			returnList.add(currentStatement);
		}
	}
	return returnList;
}
 
源代码13 项目: txtUML   文件: SequenceDiagramVisitor.java
private void checkSendInIfNode(IfStatement ifNode) {
	boolean showErrorHere = placeOfError == ifNode;
	Statement thenStatement = ifNode.getThenStatement();
	if (showErrorHere) {
		placeOfError = thenStatement;
	}
	if (thenStatement instanceof Block) {
		checkSendInBlock((Block) thenStatement, showErrorHere);
	} else {
		checkSendInStatement(thenStatement);
	}
	Statement elseStatement = ifNode.getElseStatement();
	if (showErrorHere) {
		placeOfError = elseStatement;
	}
	if (elseStatement == null) {
		return;
	}
	if (elseStatement instanceof IfStatement) {
		checkSendInIfNode((IfStatement) elseStatement);
	} else if (elseStatement instanceof Block) {
		checkSendInBlock((Block) elseStatement, showErrorHere);
	} else {
		checkSendInStatement(elseStatement);
	}
}
 
源代码14 项目: txtUML   文件: SequenceDiagramVisitor.java
private boolean checkSendOrFragmentInBlock(Block block) {
	List<Statement> statements = (List<Statement>) block.statements();
	List<Statement> loops = Utils.getLoopNodes(statements);
	loops.forEach(loop -> {
		checkSendInLoopNode(loop);
	});
	List<IfStatement> ifNodes = Utils.getIfNodes(statements);
	ifNodes.forEach(ifNode -> {
		checkSendInIfNode(ifNode);
	});
	List<MethodInvocation> parFragments = Utils.getParFragments(statements);
	parFragments.forEach(parFragment -> {
		checkSendInPar(parFragment);
	});
	List<MethodInvocation> methodInvocations = Utils.getMethodInvocations(statements);
	final List<Boolean> containsSendOrFragment = new ArrayList<>();
	methodInvocations.forEach(methodInvocation -> {
		containsSendOrFragment.add(checkSendOrFragmentInMethodInvocation(methodInvocation));
	});
	boolean isLeaf = loops.isEmpty() && ifNodes.isEmpty() && parFragments.isEmpty();
	return !isLeaf || containsSendOrFragment.contains(true);
}
 
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushBuffer(null);
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushBuffer(thenBlock);

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
源代码16 项目: txtUML   文件: OptAltFragmentExporter.java
@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;
	}
}
 
源代码17 项目: JDeodorant   文件: MethodObject.java
public FieldInstructionObject isGetter() {
	if(getMethodBody() != null) {
 	List<AbstractStatement> abstractStatements = getMethodBody().getCompositeStatement().getStatements();
 	if(abstractStatements.size() == 1 && abstractStatements.get(0) instanceof StatementObject) {
 		StatementObject statementObject = (StatementObject)abstractStatements.get(0);
 		Statement statement = statementObject.getStatement();
 		if(statement instanceof ReturnStatement) {
 			ReturnStatement returnStatement = (ReturnStatement) statement;
 			if((returnStatement.getExpression() instanceof SimpleName || returnStatement.getExpression() instanceof FieldAccess) && statementObject.getFieldInstructions().size() == 1 && statementObject.getMethodInvocations().size() == 0 &&
  				statementObject.getLocalVariableDeclarations().size() == 0 && statementObject.getLocalVariableInstructions().size() == 0 && this.constructorObject.parameterList.size() == 0) {
 				return statementObject.getFieldInstructions().get(0);
 			}
 		}
 	}
	}
	return null;
}
 
/**
 * 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;
}
 
public Statement[] getSelectedStatements() {
	if (hasSelectedNodes()) {
		return internalGetSelectedNodes().toArray(new Statement[internalGetSelectedNodes().size()]);
	} else {
		return new Statement[0];
	}
}
 
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));
	}
}
 
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);
			}
		}
	}
}
 
源代码22 项目: JDeodorant   文件: CFG.java
private boolean directlyNestedNode(CFGNode node, CompositeStatementObject composite) {
	for(AbstractStatement statement : composite.getStatements()) {
		if(statement.equals(node.getStatement()))
			return true;
		if(statement instanceof CompositeStatementObject) {
			CompositeStatementObject composite2 = (CompositeStatementObject)statement;
			Statement astComposite2 = composite2.getStatement();
			if(astComposite2 instanceof Block) {
				if(directlyNestedNode(node, composite2))
					return true;
			}
		}
	}
	return false;
}
 
private Set<ITypeBinding> getRequiredImportDeclarationsBasedOnBranch(ArrayList<Statement> statements) {
	Set<ITypeBinding> typeBindings = new LinkedHashSet<ITypeBinding>();
	for(Statement statement : statements) {
		TypeVisitor typeVisitor = new TypeVisitor();
		statement.accept(typeVisitor);
		typeBindings.addAll(typeVisitor.getTypeBindings());
	}
	return typeBindings;
}
 
源代码24 项目: JDeodorant   文件: CFG.java
private boolean previousNodesContainBreakOrReturn(List<CFGNode> previousNodes, CompositeStatementObject composite) {
	for(CFGNode previousNode : previousNodes) {
		Statement statement = previousNode.getASTStatement();
		if((statement instanceof BreakStatement || statement instanceof ReturnStatement) &&
				directlyNestedNode(previousNode, composite))
			return true;
	}
	return false;
}
 
源代码25 项目: JDeodorant   文件: TypeCheckElimination.java
public boolean isTypeCheckMethodStateSetter() {
	InheritanceTree tree = null;
	if(existingInheritanceTree != null)
		tree = existingInheritanceTree;
	else if(inheritanceTreeMatchingWithStaticTypes != null)
		tree = inheritanceTreeMatchingWithStaticTypes;
	if(tree != null) {
		DefaultMutableTreeNode root = tree.getRootNode();
		DefaultMutableTreeNode leaf = root.getFirstLeaf();
		List<String> subclassNames = new ArrayList<String>();
		while(leaf != null) {
			subclassNames.add((String)leaf.getUserObject());
			leaf = leaf.getNextLeaf();
		}
		Block typeCheckMethodBody = typeCheckMethod.getBody();
		List<Statement> statements = typeCheckMethodBody.statements();
		if(statements.size() > 0 && statements.get(0) instanceof SwitchStatement) {
			SwitchStatement switchStatement = (SwitchStatement)statements.get(0);
			List<Statement> statements2 = switchStatement.statements();
			ExpressionExtractor expressionExtractor = new ExpressionExtractor();
			int matchCounter = 0;
			for(Statement statement2 : statements2) {
				if(!(statement2 instanceof SwitchCase) && !(statement2 instanceof BreakStatement)) {
					List<Expression> classInstanceCreations = expressionExtractor.getClassInstanceCreations(statement2);
					if(classInstanceCreations.size() == 1) {
						ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation)classInstanceCreations.get(0);
						Type classInstanceCreationType = classInstanceCreation.getType();
						if(subclassNames.contains(classInstanceCreationType.resolveBinding().getQualifiedName())) {
							matchCounter++;
						}
					}
				}
			}
			if(matchCounter == subclassNames.size())
				return true;
		}
	}
	return false;
}
 
源代码26 项目: JDeodorant   文件: ControlVariable.java
private static List<Expression> getAllFirstLevelUpdaters(Statement statement)
{
	List<Expression> updaters               = new ArrayList<Expression>();
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
	List<Statement> innerStatements         = new ArrayList<Statement>();
	innerStatements.add(statement);
	innerStatements = AbstractLoopUtilities.unBlock(innerStatements);
	// get all first level PrefixExpressions, PostfixExpressions, Assignments, and next() MethodInvocations from each inner statement
	for (Statement currentStatement : innerStatements)
	{
		// only updaters in an ExpressionStatment or VariableDeclaration are first level, unless a ConditionalExpression (handled in return statement)
		if (currentStatement instanceof ExpressionStatement || currentStatement instanceof VariableDeclarationStatement)
		{
			updaters.addAll(expressionExtractor.getPrefixExpressions(currentStatement));
			updaters.addAll(expressionExtractor.getPostfixExpressions(currentStatement));
			updaters.addAll(expressionExtractor.getAssignments(currentStatement));
			
			List<Expression> methodInvocations = expressionExtractor.getMethodInvocations(currentStatement);
			for (Expression currentExpression : methodInvocations)
			{
				if (currentExpression instanceof MethodInvocation)
				{
					MethodInvocation currentMethodInvocation      = (MethodInvocation) currentExpression;
					IMethodBinding currentMethodInvocationBinding = currentMethodInvocation.resolveMethodBinding();
					AbstractLoopBindingInformation bindingInformation = AbstractLoopBindingInformation.getInstance();
					if (bindingInformation.updateMethodValuesContains(currentMethodInvocationBinding.getMethodDeclaration().getKey()))
					{
						updaters.add(currentMethodInvocation);
					}
				}
			}
		}
	}
	return removeExpressionsInAConditionalExpression(updaters, statement);
}
 
private static int getIndex(int offset, List<Statement> statements) {
	for (int i= 0; i < statements.size(); i++) {
		Statement s= statements.get(i);
		if (offset <= s.getStartPosition()) {
			return i;
		}
		if (offset < s.getStartPosition() + s.getLength()) {
			return -1;
		}
	}
	return statements.size();
}
 
private Statement getCatchBody(String type, String name, String lineSeparator) throws CoreException {
	String s = StubUtility.getCatchBodyContent(fCUnit, type, name, fSelectedNodes[0], lineSeparator);
	if (s == null) {
		return null;
	} else {
		return (Statement) fRewriter.createStringPlaceholder(s, ASTNode.RETURN_STATEMENT);
	}
}
 
public static void getMissingEnumConstantCaseProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
	for (ChangeCorrectionProposal proposal : proposals) {
		if (CorrectionMessages.LocalCorrectionsSubProcessor_add_missing_cases_description.equals(proposal.getName())) {
			return;
		}
	}

	ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
	if (selectedNode instanceof Expression) {
		StructuralPropertyDescriptor locationInParent = selectedNode.getLocationInParent();
		ASTNode parent = selectedNode.getParent();
		ITypeBinding binding;
		List<Statement> statements;

		if (locationInParent == SwitchStatement.EXPRESSION_PROPERTY) {
			SwitchStatement statement = (SwitchStatement) parent;
			binding = statement.getExpression().resolveTypeBinding();
			statements = statement.statements();
		} else if (locationInParent == SwitchExpression.EXPRESSION_PROPERTY) {
			SwitchExpression switchExpression = (SwitchExpression) parent;
			binding = switchExpression.getExpression().resolveTypeBinding();
			statements = switchExpression.statements();
		} else {
			return;
		}

		if (binding == null || !binding.isEnum()) {
			return;
		}

		ArrayList<String> missingEnumCases = new ArrayList<>();
		boolean hasDefault = evaluateMissingSwitchCases(binding, statements, missingEnumCases);
		if (missingEnumCases.size() == 0 && hasDefault) {
			return;
		}

		createMissingCaseProposals(context, parent, missingEnumCases, proposals);
	}
}
 
源代码30 项目: JDeodorant   文件: TypeCheckElimination.java
public Expression getExpressionCorrespondingToTypeCheckStatementList(ArrayList<Statement> statements) {
	for(Expression expression : typeCheckMap.keySet()) {
		if(statements.equals(typeCheckMap.get(expression)))
			return expression;
	}
	return null;
}
 
 类所在包
 同包方法