Java Code Examples for org.eclipse.jdt.core.dom.IBinding#isEqualTo()

The following examples show how to use org.eclipse.jdt.core.dom.IBinding#isEqualTo() . 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: ASTNodeMatcher.java    From JDeodorant with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 6 votes vote down vote up
private static List<SimpleName> getOccurrencesOfSimpleName(Expression expression, SimpleName simpleName)
{
	List<SimpleName> returnList = new ArrayList<SimpleName>();
	ExpressionExtractor expressionExtractor = new ExpressionExtractor();
	List<Expression> simpleNames = expressionExtractor.getVariableInstructions(expression);
	for (Expression currentExpression : simpleNames)
	{
		SimpleName currentSimpleName = (SimpleName)currentExpression;
		IBinding currentSimpleNameBinding = currentSimpleName.resolveBinding();
		if (currentSimpleNameBinding != null && currentSimpleNameBinding.isEqualTo(simpleName.resolveBinding()))
		{
			returnList.add(currentSimpleName);
		}
	}
	return returnList;
}
 
Example 3
Source File: AbstractControlStructureUtilities.java    From JDeodorant with MIT License 6 votes vote down vote up
private static boolean isSameAssignee(Assignment assignment1, Assignment assignment2)
{
	Expression assignee1 = assignment1.getLeftHandSide();
	Expression assignee2 = assignment2.getLeftHandSide();
	IBinding binding1 = null;
	IBinding binding2 = null;
	if (assignee1 instanceof Name && assignee2 instanceof Name)
	{
		binding1 = ((Name)assignee1).resolveBinding();
		binding2 = ((Name)assignee2).resolveBinding();
	}
	else if (assignee1 instanceof FieldAccess && assignee2 instanceof FieldAccess)
	{
		binding1 = ((FieldAccess)assignee1).resolveFieldBinding();
		binding2 = ((FieldAccess)assignee2).resolveFieldBinding();
	}
	return (binding1 != null && binding2 != null &&
			binding1.getKind() == IBinding.VARIABLE && binding2.getKind() == IBinding.VARIABLE &&
			binding1.isEqualTo(binding2));
}
 
Example 4
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 4 votes vote down vote up
private static Integer assignmentUpdateValue(Assignment assignment)
{
	Integer updateValue          = null;
	Expression leftHandSide      = assignment.getLeftHandSide();
	Assignment.Operator operator = assignment.getOperator();
	Expression rightHandSide     = assignment.getRightHandSide();
	if (operator == Assignment.Operator.PLUS_ASSIGN)
	{			
		updateValue = AbstractLoopUtilities.getIntegerValue(rightHandSide);
	}
	else if (operator == Assignment.Operator.MINUS_ASSIGN)
	{
		Integer rightHandSideIntegerValue = AbstractLoopUtilities.getIntegerValue(rightHandSide);
		if (rightHandSideIntegerValue != null)
		{
			updateValue = (-1) * rightHandSideIntegerValue;
		}
	}
	else if (leftHandSide instanceof SimpleName && operator == Assignment.Operator.ASSIGN && rightHandSide instanceof InfixExpression)
	{
		SimpleName leftHandSideSimpleName      = (SimpleName) leftHandSide;
		IBinding leftHandSideBinding           = leftHandSideSimpleName.resolveBinding();
		InfixExpression infixExpression        = (InfixExpression) rightHandSide;
		InfixExpression.Operator infixOperator = infixExpression.getOperator();
		Expression rightOperand                = infixExpression.getRightOperand();
		Expression leftOperand                 = infixExpression.getLeftOperand();
		if (infixOperator.toString().equals("+") || infixOperator.toString().equals("-"))
		{
			if (leftOperand instanceof SimpleName)
			{
				SimpleName leftOperandSimpleName = (SimpleName) leftOperand;
				IBinding leftOperandBinding      = leftOperandSimpleName.resolveBinding();
				if (leftOperandBinding.isEqualTo(leftHandSideBinding))
				{
					Integer rightOperandIntegerValue = AbstractLoopUtilities.getIntegerValue(rightOperand);
					if (infixOperator.toString().equals("+") && rightOperandIntegerValue != null)
					{
						updateValue = rightOperandIntegerValue;
					}
					else if (infixOperator.toString().equals("-") && rightOperandIntegerValue != null)
					{
						updateValue = (-1) * rightOperandIntegerValue;
					}
				}
			}
			else if (rightOperand instanceof SimpleName)
			{
				SimpleName rightOperandSimpleName = (SimpleName) rightOperand;
				IBinding rightOperandBinding      = rightOperandSimpleName.resolveBinding();
				if (rightOperandBinding.isEqualTo(leftHandSideBinding))
				{
					Integer leftOperandIntegerValue = AbstractLoopUtilities.getIntegerValue(leftOperand);
					if (infixOperator.toString().equals("+") && leftOperandIntegerValue != null)
					{
						updateValue = leftOperandIntegerValue;
					}
				}
			}
		}
	}
	return updateValue;
}
 
Example 5
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 4 votes vote down vote up
public static boolean isVariableLeftOperand(SimpleName variable, InfixExpression infixExpression)
{
	boolean leftOperandIsVariable     = false;
	Expression leftOperand            = infixExpression.getLeftOperand();
	//Expression rightOperand           = infixExpression.getRightOperand();
	IBinding infixVariableBinding     = variable.resolveBinding();
	if (leftOperand instanceof SimpleName)
	{
		SimpleName leftOperandSimpleName = (SimpleName) leftOperand;
		IBinding leftOperandBinding      = leftOperandSimpleName.resolveBinding();
		if (leftOperandBinding.isEqualTo(infixVariableBinding))
		{
			leftOperandIsVariable = true;
		}
	}
	else if (leftOperand instanceof InfixExpression)
	{
		InfixExpression infixLeftOperand = (InfixExpression) leftOperand;
		boolean left = isVariableLeftOperand(variable, infixLeftOperand);
		boolean right = isVariableRightOperand(variable, infixLeftOperand);
		List<Expression> extendedOperands = infixLeftOperand.extendedOperands();
		boolean variableFoundInExtendedOperands = false;
		for (Expression expression : extendedOperands)
		{
			if (expression instanceof SimpleName)
			{
				SimpleName simpleName = (SimpleName) expression;
				IBinding simpleNameBinding = simpleName.resolveBinding();
				if (simpleNameBinding.isEqualTo(infixVariableBinding))
				{
					variableFoundInExtendedOperands = true;
					break;
				}
			}
		}
		if (left || right || variableFoundInExtendedOperands)
		{
			leftOperandIsVariable = true;
		}
	}
	return leftOperandIsVariable;
}
 
Example 6
Source File: AbstractLoopUtilities.java    From JDeodorant with MIT License 4 votes vote down vote up
private static boolean isVariableRightOperand(SimpleName variable, InfixExpression infixExpression)
{
	boolean rightOperandIsVariable     = false;
	//Expression leftOperand            = infixExpression.getLeftOperand();
	Expression rightOperand           = infixExpression.getRightOperand();
	IBinding infixVariableBinding     = variable.resolveBinding();
	if (rightOperand instanceof SimpleName)
	{
		SimpleName rightOperandSimpleName = (SimpleName) rightOperand;
		IBinding rightOperandBinding      = rightOperandSimpleName.resolveBinding();
		if (rightOperandBinding.isEqualTo(infixVariableBinding))
		{
			rightOperandIsVariable = true;
		}
	}
	else if (rightOperand instanceof InfixExpression)
	{
		InfixExpression infixRightOperand = (InfixExpression) rightOperand;
		boolean left = isVariableLeftOperand(variable, infixRightOperand);
		boolean right = isVariableRightOperand(variable, infixRightOperand);
		List<Expression> extendedOperands = infixRightOperand.extendedOperands();
		boolean variableFoundInExtendedOperands = false;
		for (Expression expression : extendedOperands)
		{
			if (expression instanceof SimpleName)
			{
				SimpleName simpleName = (SimpleName) expression;
				IBinding simpleNameBinding = simpleName.resolveBinding();
				if (simpleNameBinding.isEqualTo(infixVariableBinding))
				{
					variableFoundInExtendedOperands = true;
					break;
				}
			}
		}
		if (left || right || variableFoundInExtendedOperands)
		{
			rightOperandIsVariable = true;
		}
	}
	return rightOperandIsVariable;
}
 
Example 7
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Checks if the two bindings are equals. Also works across binding environments.
 * @param b1 first binding treated as <code>this</code>. So it must
 *  not be <code>null</code>
 * @param b2 the second binding.
 * @return boolean
 */
public static boolean equals(IBinding b1, IBinding b2) {
	return b1.isEqualTo(b2);
}