本文整理汇总了Java中com.siyeh.ig.psiutils.EquivalenceChecker.statementsAreEquivalent方法的典型用法代码示例。如果您正苦于以下问题:Java EquivalenceChecker.statementsAreEquivalent方法的具体用法?Java EquivalenceChecker.statementsAreEquivalent怎么用?Java EquivalenceChecker.statementsAreEquivalent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.siyeh.ig.psiutils.EquivalenceChecker
的用法示例。
在下文中一共展示了EquivalenceChecker.statementsAreEquivalent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: 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);
}
示例3: isMergableImplicitIf
import com.siyeh.ig.psiutils.EquivalenceChecker; //导入方法依赖的package包/类
private static boolean isMergableImplicitIf(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();
if (thenBranch == null) {
return false;
}
final PsiStatement elseBranch = ifStatement.getElseBranch();
if (elseBranch != null) {
return false;
}
if (ControlFlowUtils.statementMayCompleteNormally(thenBranch)) {
return false;
}
final PsiElement nextStatement = PsiTreeUtil.skipSiblingsForward(ifStatement, PsiWhiteSpace.class);
if (!(nextStatement instanceof PsiIfStatement)) {
return false;
}
final PsiIfStatement nextIfStatement = (PsiIfStatement)nextStatement;
final PsiStatement nextThenBranch = nextIfStatement.getThenBranch();
return EquivalenceChecker.statementsAreEquivalent(thenBranch, nextThenBranch);
}