本文整理汇总了Java中com.siyeh.ig.psiutils.EquivalenceChecker.expressionsAreEquivalent方法的典型用法代码示例。如果您正苦于以下问题:Java EquivalenceChecker.expressionsAreEquivalent方法的具体用法?Java EquivalenceChecker.expressionsAreEquivalent怎么用?Java EquivalenceChecker.expressionsAreEquivalent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.siyeh.ig.psiutils.EquivalenceChecker
的用法示例。
在下文中一共展示了EquivalenceChecker.expressionsAreEquivalent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitMethodCallExpression
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
if (!MethodCallUtils.isEqualsCall(expression)) {
return;
}
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 1) {
return;
}
final PsiExpression argument = arguments[0];
if (!EquivalenceChecker.expressionsAreEquivalent(qualifier, argument) ||
SideEffectChecker.mayHaveSideEffects(qualifier)) {
return;
}
registerMethodCallError(expression);
}
示例2: ifStatementsCanBeMerged
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
public static boolean ifStatementsCanBeMerged(PsiIfStatement statement1,
PsiIfStatement statement2) {
final PsiStatement thenBranch = statement1.getThenBranch();
final PsiStatement elseBranch = statement1.getElseBranch();
if (thenBranch == null) {
return false;
}
final PsiExpression firstCondition = statement1.getCondition();
final PsiExpression secondCondition = statement2.getCondition();
if (!EquivalenceChecker.expressionsAreEquivalent(firstCondition,
secondCondition)) {
return false;
}
final PsiStatement nextThenBranch = statement2.getThenBranch();
if (!canBeMerged(thenBranch, nextThenBranch)) {
return false;
}
final PsiStatement nextElseBranch = statement2.getElseBranch();
return elseBranch == null || nextElseBranch == null ||
canBeMerged(elseBranch, nextElseBranch);
}
示例3: booleanExpressionIsPointless
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
private boolean booleanExpressionIsPointless(PsiExpression[] operands) {
PsiExpression previousExpression = null;
for (PsiExpression operand : operands) {
if (isZero(operand) || isAllOnes(operand) || EquivalenceChecker.expressionsAreEquivalent(previousExpression, operand)) {
return true;
}
previousExpression = operand;
}
return false;
}
示例4: visitBinaryExpression
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
@Override
public void visitBinaryExpression(PsiBinaryExpression expression) {
super.visitBinaryExpression(expression);
final IElementType tokenType = expression.getOperationTokenType();
if (!JavaTokenType.OROR.equals(tokenType)) {
return;
}
final PsiExpression lhs = ParenthesesUtils.stripParentheses(expression.getLOperand());
final PsiExpression rhs = ParenthesesUtils.stripParentheses(expression.getROperand());
if (!(lhs instanceof PsiBinaryExpression) || !(rhs instanceof PsiBinaryExpression)) {
return;
}
final PsiBinaryExpression lBinaryExpression = (PsiBinaryExpression)lhs;
final PsiBinaryExpression rBinaryExpression = (PsiBinaryExpression)rhs;
final IElementType lTokenType = lBinaryExpression.getOperationTokenType();
final IElementType rTokenType = rBinaryExpression.getOperationTokenType();
if (!JavaTokenType.ANDAND.equals(lTokenType) || !JavaTokenType.ANDAND.equals(rTokenType)) {
return;
}
final PsiExpression expression1 = ParenthesesUtils.stripParentheses(lBinaryExpression.getLOperand());
final PsiExpression expression2 = ParenthesesUtils.stripParentheses(rBinaryExpression.getLOperand());
if (expression1 == null || expression2 == null ||
ParenthesesUtils.stripParentheses(lBinaryExpression.getROperand()) == null ||
ParenthesesUtils.stripParentheses(rBinaryExpression.getROperand()) == null) {
return;
}
if (EquivalenceChecker.expressionsAreEquivalent(BoolUtils.getNegated(expression1), expression2) &&
!SideEffectChecker.mayHaveSideEffects(expression2)) {
registerError(expression);
}
else if (EquivalenceChecker.expressionsAreEquivalent(expression1, BoolUtils.getNegated(expression2)) &&
!SideEffectChecker.mayHaveSideEffects(expression1)) {
registerError(expression);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:BooleanExpressionMayBeConditionalInspection.java
示例5: isReplaceableAssignment
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
public static boolean isReplaceableAssignment(PsiIfStatement ifStatement) {
final PsiStatement thenBranch = ControlFlowUtils.stripBraces(ifStatement.getThenBranch());
final PsiStatement elseBranch = ControlFlowUtils.stripBraces(ifStatement.getElseBranch());
if (thenBranch == null || elseBranch == null) {
return false;
}
if (!(thenBranch instanceof PsiExpressionStatement) || !(elseBranch instanceof PsiExpressionStatement)) {
return false;
}
final PsiExpressionStatement thenExpressionStatement = (PsiExpressionStatement)thenBranch;
final PsiExpressionStatement elseExpressionStatement = (PsiExpressionStatement)elseBranch;
final PsiExpression thenExpression = thenExpressionStatement.getExpression();
final PsiExpression elseExpression = elseExpressionStatement.getExpression();
if (!(thenExpression instanceof PsiAssignmentExpression) || !(elseExpression instanceof PsiAssignmentExpression)) {
return false;
}
final PsiAssignmentExpression thenAssignmentExpression = (PsiAssignmentExpression)thenExpression;
final PsiAssignmentExpression elseAssignmentExpression = (PsiAssignmentExpression)elseExpression;
final PsiExpression thenRhs = thenAssignmentExpression.getRExpression();
final PsiExpression elseRhs = elseAssignmentExpression.getRExpression();
if (thenRhs == null || elseRhs == null) {
return false;
}
final IElementType thenTokenType = thenAssignmentExpression.getOperationTokenType();
final IElementType elseTokenType = elseAssignmentExpression.getOperationTokenType();
if (!thenTokenType.equals(elseTokenType)) {
return false;
}
final PsiExpression thenLhs = thenAssignmentExpression.getLExpression();
final PsiExpression elseLhs = elseAssignmentExpression.getLExpression();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs, elseLhs);
}
示例6: visitConditionalExpression
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
@Override
public void visitConditionalExpression(PsiConditionalExpression expression) {
super.visitConditionalExpression(expression);
final PsiExpression thenExpression = expression.getThenExpression();
final PsiExpression elseExpression = expression.getElseExpression();
if (thenExpression != null && EquivalenceChecker.expressionsAreEquivalent(thenExpression, elseExpression)) {
registerError(expression);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ConditionalExpressionWithIdenticalBranchesInspection.java
示例7: isSimplifiableAssignment
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
private static boolean isSimplifiableAssignment(PsiStatement thenBranch,
PsiStatement elseBranch,
String thenAssignment,
String elseAssignment) {
if (ConditionalUtils.isAssignment(thenBranch, thenAssignment) &&
ConditionalUtils.isAssignment(elseBranch, elseAssignment)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs, elseLhs);
}
else {
return false;
}
}
示例8: visitIfStatement
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
@Override
public void visitIfStatement(@NotNull PsiIfStatement statement) {
super.visitIfStatement(statement);
if (ControlFlowUtils.isElseIf(statement)) {
return;
}
final Set<PsiExpression> conditions = new HashSet<PsiExpression>();
collectConditionsForIfStatement(statement, conditions, 0);
final int numConditions = conditions.size();
if (numConditions < 2) {
return;
}
final PsiExpression[] conditionArray = conditions.toArray(new PsiExpression[numConditions]);
final boolean[] matched = new boolean[conditionArray.length];
Arrays.fill(matched, false);
for (int i = 0; i < conditionArray.length; i++) {
if (matched[i]) {
continue;
}
final PsiExpression condition = conditionArray[i];
for (int j = i + 1; j < conditionArray.length; j++) {
if (matched[j]) {
continue;
}
final PsiExpression testCondition = conditionArray[j];
final boolean areEquivalent = EquivalenceChecker.expressionsAreEquivalent(condition, testCondition);
if (areEquivalent) {
if (!ignoreMethodCalls || !containsMethodCallExpression(testCondition)) {
registerError(testCondition);
if (!matched[i]) {
registerError(condition);
}
}
matched[i] = true;
matched[j] = true;
}
}
}
}
示例9: calculateReplacementExpression
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
@NonNls
String calculateReplacementExpression(PsiExpression expression) {
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
final PsiExpression[] operands = polyadicExpression.getOperands();
final IElementType tokenType = polyadicExpression.getOperationTokenType();
PsiElement fromTarget = null;
PsiElement untilTarget = null;
PsiExpression previousOperand = null;
@NonNls String replacement = "";
for (int i = 0, length = operands.length; i < length; i++) {
final PsiExpression operand = operands[i];
if (tokenType.equals(JavaTokenType.PLUS) && isZero(operand) ||
tokenType.equals(JavaTokenType.MINUS) && isZero(operand) && i > 0 ||
tokenType.equals(JavaTokenType.ASTERISK) && isOne(operand) ||
tokenType.equals(JavaTokenType.DIV) && isOne(operand) && i > 0) {
fromTarget = (i == length - 1) ? polyadicExpression.getTokenBeforeOperand(operand) : operand;
break;
}
else if ((tokenType.equals(JavaTokenType.MINUS) && i == 1 || tokenType.equals(JavaTokenType.DIV)) &&
EquivalenceChecker.expressionsAreEquivalent(previousOperand, operand)) {
fromTarget = previousOperand;
untilTarget = operand;
replacement = PsiType.LONG.equals(polyadicExpression.getType())
? tokenType.equals(JavaTokenType.DIV) ? "1L" : "0L"
: tokenType.equals(JavaTokenType.DIV) ? "1" : "0";
break;
}
else if (tokenType.equals(JavaTokenType.ASTERISK) && isZero(operand) ||
tokenType.equals(JavaTokenType.PERC) && (isOne(operand) || EquivalenceChecker.expressionsAreEquivalent(previousOperand, operand))) {
fromTarget = operands[0];
untilTarget = operands[length - 1];
replacement = PsiType.LONG.equals(polyadicExpression.getType()) ? "0L" : "0";
break;
}
previousOperand = operand;
}
return getText(polyadicExpression, fromTarget, untilTarget, replacement).trim();
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:PointlessArithmeticExpressionInspection.java
示例10: satisfiedBy
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiAssignmentExpression)) {
return false;
}
final PsiAssignmentExpression assignment = (PsiAssignmentExpression)element;
final IElementType tokenType = assignment.getOperationTokenType();
if (!JavaTokenType.EQ.equals(tokenType)) {
return false;
}
final PsiExpression rhs = assignment.getRExpression();
final PsiExpression expression = PsiUtil.deparenthesizeExpression(rhs);
if (!(expression instanceof PsiPolyadicExpression)) {
return false;
}
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
final PsiExpression[] operands = polyadicExpression.getOperands();
if (operands.length < 2) {
return false;
}
final IElementType rhsTokenType = polyadicExpression.getOperationTokenType();
if (JavaTokenType.OROR.equals(rhsTokenType) || JavaTokenType.ANDAND.equals(rhsTokenType) ||
JavaTokenType.EQEQ.equals(rhsTokenType) || JavaTokenType.NE.equals(rhsTokenType)) {
return false;
}
final PsiExpression lhs = assignment.getLExpression();
if (SideEffectChecker.mayHaveSideEffects(lhs)) {
return false;
}
if (!EquivalenceChecker.expressionsAreEquivalent(lhs, operands[0])) {
return false;
}
return !ErrorUtil.containsError(element);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:ReplaceableWithOperatorAssignmentPredicate.java
示例11: visitConditionalExpression
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
@Override
public void visitConditionalExpression(
PsiConditionalExpression expression) {
super.visitConditionalExpression(expression);
final PsiExpression thenExpression = expression.getThenExpression();
final PsiExpression elseExpression = expression.getElseExpression();
if (EquivalenceChecker.expressionsAreEquivalent(thenExpression,
elseExpression)) {
registerError(expression);
}
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:12,代码来源:ConditionalExpressionWithIdenticalBranchesInspection.java
示例12: isSimplifiableAssignment
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
public static boolean isSimplifiableAssignment(PsiIfStatement ifStatement) {
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
PsiStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.TRUE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.FALSE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}
示例13: isSimplifiableAssignmentNegated
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
public static boolean isSimplifiableAssignmentNegated(
PsiIfStatement ifStatement) {
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
PsiStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.FALSE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.TRUE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}
示例14: isSimplifiableImplicitAssignment
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
public static boolean isSimplifiableImplicitAssignment(
PsiIfStatement ifStatement) {
if (ifStatement.getElseBranch() != null) {
return false;
}
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
final PsiElement nextStatement =
PsiTreeUtil.skipSiblingsBackward(ifStatement,
PsiWhiteSpace.class);
if (!(nextStatement instanceof PsiStatement)) {
return false;
}
PsiStatement elseBranch = (PsiStatement)nextStatement;
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.TRUE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.FALSE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}
示例15: isSimplifiableImplicitAssignmentNegated
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
public static boolean isSimplifiableImplicitAssignmentNegated(
PsiIfStatement ifStatement) {
if (ifStatement.getElseBranch() != null) {
return false;
}
PsiStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ControlFlowUtils.stripBraces(thenBranch);
final PsiElement nextStatement =
PsiTreeUtil.skipSiblingsBackward(ifStatement,
PsiWhiteSpace.class);
if (!(nextStatement instanceof PsiStatement)) {
return false;
}
PsiStatement elseBranch = (PsiStatement)nextStatement;
elseBranch = ControlFlowUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, PsiKeyword.FALSE) &&
ConditionalUtils.isAssignment(elseBranch, PsiKeyword.TRUE)) {
final PsiExpressionStatement thenExpressionStatement =
(PsiExpressionStatement)thenBranch;
final PsiAssignmentExpression thenExpression =
(PsiAssignmentExpression)
thenExpressionStatement.getExpression();
final PsiExpressionStatement elseExpressionStatement =
(PsiExpressionStatement)elseBranch;
final PsiAssignmentExpression elseExpression =
(PsiAssignmentExpression)
elseExpressionStatement.getExpression();
final IElementType thenTokenType = thenExpression.getOperationTokenType();
if (!thenTokenType.equals(elseExpression.getOperationTokenType())) {
return false;
}
final PsiExpression thenLhs = thenExpression.getLExpression();
final PsiExpression elseLhs = elseExpression.getLExpression();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs,
elseLhs);
}
else {
return false;
}
}