本文整理汇总了Java中com.siyeh.ig.psiutils.EquivalenceChecker类的典型用法代码示例。如果您正苦于以下问题:Java EquivalenceChecker类的具体用法?Java EquivalenceChecker怎么用?Java EquivalenceChecker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EquivalenceChecker类属于com.siyeh.ig.psiutils包,在下文中一共展示了EquivalenceChecker类的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: 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.getCanonicalPsiEquivalence().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);
}
示例4: visitMethod
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入依赖的package包/类
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
final PsiCodeBlock body = method.getBody();
if (body == null) {
return;
}
if (method.getNameIdentifier() == null) {
return;
}
final Query<MethodSignatureBackedByPsiMethod> superMethodQuery =
SuperMethodsSearch.search(method, null, true, false);
final MethodSignatureBackedByPsiMethod signature =
superMethodQuery.findFirst();
if (signature == null) {
return;
}
final PsiMethod superMethod = signature.getMethod();
final PsiCodeBlock superBody = superMethod.getBody();
if (superBody == null) {
return;
}
if (!modifierListsAreEquivalent(method.getModifierList(), superMethod.getModifierList())) {
return;
}
final PsiType superReturnType = superMethod.getReturnType();
if (superReturnType == null || !superReturnType.equals(method.getReturnType())) {
return;
}
if (!EquivalenceChecker.codeBlocksAreEquivalent(body, superBody)) {
return;
}
registerMethodError(method);
}
示例5: 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;
}
示例6: visitConditionalExpression
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入依赖的package包/类
@Override
public void visitConditionalExpression(PsiConditionalExpression expression) {
super.visitConditionalExpression(expression);
final PsiExpression thenExpression = expression.getThenExpression();
if (thenExpression == null) {
return;
}
final PsiExpression elseExpression = expression.getElseExpression();
if (elseExpression == null) {
return;
}
final PsiType thenType = thenExpression.getType();
if (!PsiType.BOOLEAN.equals(thenType)) {
return;
}
final PsiType elseType = elseExpression.getType();
if (!PsiType.BOOLEAN.equals(elseType)) {
return;
}
final boolean thenConstant = BoolUtils.isFalse(thenExpression) || BoolUtils.isTrue(thenExpression);
final boolean elseConstant = BoolUtils.isFalse(elseExpression) || BoolUtils.isTrue(elseExpression);
if (thenConstant == elseConstant) {
if (EquivalenceChecker.expressionsAreEquivalent(BoolUtils.getNegated(thenExpression), elseExpression) ||
EquivalenceChecker.expressionsAreEquivalent(thenExpression, BoolUtils.getNegated(elseExpression))) {
registerError(expression, expression);
}
return;
}
registerError(expression, expression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:SimplifiableConditionalExpressionInspection.java
示例7: 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
示例8: checkIfStatementWithoutElseBranch
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入依赖的package包/类
private void checkIfStatementWithoutElseBranch(
PsiIfStatement ifStatement) {
final PsiStatement thenBranch = ifStatement.getThenBranch();
if (ControlFlowUtils.statementMayCompleteNormally(thenBranch)) {
return;
}
PsiStatement nextStatement = getNextStatement(ifStatement);
if (thenBranch instanceof PsiBlockStatement) {
final PsiBlockStatement blockStatement =
(PsiBlockStatement)thenBranch;
final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
final PsiStatement[] statements = codeBlock.getStatements();
final PsiStatement lastStatement =
statements[statements.length - 1];
for (PsiStatement statement : statements) {
if (nextStatement == null) {
if (statement == lastStatement &&
statement instanceof PsiReturnStatement) {
final PsiReturnStatement returnStatement =
(PsiReturnStatement)statement;
if (returnStatement.getReturnValue() == null) {
registerStatementError(ifStatement);
}
}
return;
}
else if (!EquivalenceChecker.statementsAreEquivalent(
statement, nextStatement)) {
return;
}
nextStatement = getNextStatement(nextStatement);
}
}
else if (!EquivalenceChecker.statementsAreEquivalent(
thenBranch, nextStatement)) {
return;
}
registerStatementError(ifStatement);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:IfStatementWithIdenticalBranchesInspection.java
示例9: 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
示例10: 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;
}
}
示例11: 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;
}
}
}
}
示例12: 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
示例13: 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
示例14: 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);
}
示例15: isMergableExplicitIf
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入依赖的package包/类
public static boolean isMergableExplicitIf(PsiElement element) {
if (!(element instanceof PsiJavaToken)) {
return false;
}
final PsiJavaToken token = (PsiJavaToken)element;
final PsiElement parent = token.getParent();
if (!(parent instanceof PsiIfStatement)) {
return false;
}
final PsiIfStatement ifStatement = (PsiIfStatement)parent;
final PsiStatement thenBranch = ifStatement.getThenBranch();
final PsiStatement elseBranch = ifStatement.getElseBranch();
if (thenBranch == null) {
return false;
}
if (elseBranch == null) {
return false;
}
if (!(elseBranch instanceof PsiIfStatement)) {
return false;
}
if (ErrorUtil.containsError(ifStatement)) {
return false;
}
final PsiIfStatement childIfStatement = (PsiIfStatement)elseBranch;
final PsiStatement childThenBranch = childIfStatement.getThenBranch();
return EquivalenceChecker.statementsAreEquivalent(thenBranch, childThenBranch);
}