Java Code Examples for org.eclipse.jdt.core.dom.Expression#equals()

The following examples show how to use org.eclipse.jdt.core.dom.Expression#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDGNodeMapping.java    From JDeodorant with MIT License 6 votes vote down vote up
public boolean isVoidMethodCallDifferenceCoveringEntireStatement() {
	boolean expression1IsVoidMethodCallDifference = false;
	boolean expression2IsVoidMethodCallDifference = false;
	for(ASTNodeDifference difference : nodeDifferences) {
		Expression expr1 = ASTNodeDifference.getParentExpressionOfMethodNameOrTypeName(difference.getExpression1().getExpression());
		Expression expr2 = ASTNodeDifference.getParentExpressionOfMethodNameOrTypeName(difference.getExpression2().getExpression());
		for(PreconditionViolation violation : getPreconditionViolations()) {
			if(violation instanceof ExpressionPreconditionViolation && violation.getType().equals(PreconditionViolationType.EXPRESSION_DIFFERENCE_IS_VOID_METHOD_CALL)) {
				ExpressionPreconditionViolation expressionViolation = (ExpressionPreconditionViolation)violation;
				Expression expression = ASTNodeDifference.getParentExpressionOfMethodNameOrTypeName(expressionViolation.getExpression().getExpression());
				if(expression.equals(expr1)) {
					if(expr1.getParent() instanceof ExpressionStatement) {
						expression1IsVoidMethodCallDifference = true;
					}
				}
				if(expression.equals(expr2)) {
					if(expr2.getParent() instanceof ExpressionStatement) {
						expression2IsVoidMethodCallDifference = true;
					}
				}
			}
		}
	}
	return expression1IsVoidMethodCallDifference && expression2IsVoidMethodCallDifference;
}
 
Example 2
Source File: AdvancedQuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Expression getNextSiblingExpression(Expression expression) {
	InfixExpression parentInfixExpression= (InfixExpression) expression.getParent();
	Expression sibiling;
	if (expression.equals(parentInfixExpression.getLeftOperand())) {
		sibiling= parentInfixExpression.getRightOperand();
	} else if (expression.equals(parentInfixExpression.getRightOperand())) {
		if (parentInfixExpression.getParent() instanceof InfixExpression)
			sibiling= getNextSiblingExpression(parentInfixExpression);
		else
			sibiling= null;
	} else {
		sibiling= null;
	}
	return sibiling;
}
 
Example 3
Source File: IfStatementExpressionAnalyzer.java    From JDeodorant with MIT License 5 votes vote down vote up
public DefaultMutableTreeNode getRemainingExpression(Expression expressionToBeRemoved) {
	DefaultMutableTreeNode newRoot = new DefaultMutableTreeNode();
	processExpression(newRoot, completeExpression);
	DefaultMutableTreeNode leaf = newRoot.getFirstLeaf();
	while(leaf != null) {
		Expression expression = (Expression)leaf.getUserObject();
		if(expression.equals(expressionToBeRemoved)) {
			DefaultMutableTreeNode parent = (DefaultMutableTreeNode)leaf.getParent();
			if(parent != null) {
				DefaultMutableTreeNode grandParent = (DefaultMutableTreeNode)parent.getParent();
				DefaultMutableTreeNode sibling = null;
				if(leaf.getNextSibling() != null) {
					sibling = leaf.getNextSibling();
				}
				else if(leaf.getPreviousSibling() != null) {
					sibling = leaf.getPreviousSibling();
				}
				if(grandParent != null) {
					int parentIndex = grandParent.getIndex(parent);
					grandParent.remove(parent);
					grandParent.insert(sibling, parentIndex);
				}
				else {
					newRoot = sibling;
				}
				break;
			}
			else {
				newRoot = null;
				break;
			}
		}
		leaf = leaf.getNextLeaf();
	}
	return newRoot;
}
 
Example 4
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 5 votes vote down vote up
private static boolean isExpressionAnArgument(Expression expression, MethodInvocation methodInvocation)
{
	List<Expression> arguments = methodInvocation.arguments();
	for (Expression currentArgument : arguments)
	{
		Expression unparenthesizedArgument = AbstractControlStructureUtilities.unparenthesize(currentArgument);
		if (currentArgument.equals(expression) || unparenthesizedArgument.equals(expression))
		{
			return true;
		}
	}
	return false;
}