mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
+22
-38
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.VariableAccessUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,18 +33,21 @@ public class WhileLoopSpinsOnFieldInspection extends BaseInspection {
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean ignoreNonEmtpyLoops = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"while.loop.spins.on.field.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"while.loop.spins.on.field.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message(
|
||||
@@ -51,16 +55,15 @@ public class WhileLoopSpinsOnFieldInspection extends BaseInspection {
|
||||
this, "ignoreNonEmtpyLoops");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new WhileLoopSpinsOnFieldVisitor();
|
||||
}
|
||||
|
||||
private class WhileLoopSpinsOnFieldVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
private class WhileLoopSpinsOnFieldVisitor extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
public void visitWhileStatement(
|
||||
@NotNull PsiWhileStatement statement) {
|
||||
public void visitWhileStatement(@NotNull PsiWhileStatement statement) {
|
||||
super.visitWhileStatement(statement);
|
||||
final PsiStatement body = statement.getBody();
|
||||
if (ignoreNonEmtpyLoops && !statementIsEmpty(body)) {
|
||||
@@ -71,16 +74,14 @@ public class WhileLoopSpinsOnFieldInspection extends BaseInspection {
|
||||
if (field == null) {
|
||||
return;
|
||||
}
|
||||
if (body != null &&
|
||||
VariableAccessUtils.variableIsAssigned(field, body)) {
|
||||
if (body != null && VariableAccessUtils.variableIsAssigned(field, body)) {
|
||||
return;
|
||||
}
|
||||
registerStatementError(statement);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiField getFieldIfSimpleFieldComparison(
|
||||
PsiExpression condition) {
|
||||
private PsiField getFieldIfSimpleFieldComparison(PsiExpression condition) {
|
||||
condition = PsiUtil.deparenthesizeExpression(condition);
|
||||
if (condition == null) {
|
||||
return null;
|
||||
@@ -90,28 +91,23 @@ public class WhileLoopSpinsOnFieldInspection extends BaseInspection {
|
||||
return field;
|
||||
}
|
||||
if (condition instanceof PsiPrefixExpression) {
|
||||
final PsiPrefixExpression prefixExpression =
|
||||
(PsiPrefixExpression)condition;
|
||||
final PsiExpression operand =
|
||||
prefixExpression.getOperand();
|
||||
final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)condition;
|
||||
final PsiExpression operand = prefixExpression.getOperand();
|
||||
return getFieldIfSimpleFieldComparison(operand);
|
||||
}
|
||||
if (condition instanceof PsiPostfixExpression) {
|
||||
final PsiPostfixExpression postfixExpression =
|
||||
(PsiPostfixExpression)condition;
|
||||
final PsiExpression operand =
|
||||
postfixExpression.getOperand();
|
||||
final PsiPostfixExpression postfixExpression = (PsiPostfixExpression)condition;
|
||||
final PsiExpression operand = postfixExpression.getOperand();
|
||||
return getFieldIfSimpleFieldComparison(operand);
|
||||
}
|
||||
if (condition instanceof PsiBinaryExpression) {
|
||||
final PsiBinaryExpression binaryExpression =
|
||||
(PsiBinaryExpression)condition;
|
||||
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition;
|
||||
final PsiExpression lOperand = binaryExpression.getLOperand();
|
||||
final PsiExpression rOperand = binaryExpression.getROperand();
|
||||
if (isLiteral(rOperand)) {
|
||||
if (ExpressionUtils.isLiteral(rOperand)) {
|
||||
return getFieldIfSimpleFieldComparison(lOperand);
|
||||
}
|
||||
else if (isLiteral(lOperand)) {
|
||||
else if (ExpressionUtils.isLiteral(lOperand)) {
|
||||
return getFieldIfSimpleFieldComparison(rOperand);
|
||||
}
|
||||
else {
|
||||
@@ -121,14 +117,6 @@ public class WhileLoopSpinsOnFieldInspection extends BaseInspection {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isLiteral(PsiExpression expression) {
|
||||
expression = PsiUtil.deparenthesizeExpression(expression);
|
||||
if (expression == null) {
|
||||
return false;
|
||||
}
|
||||
return expression instanceof PsiLiteralExpression;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiField getFieldIfSimpleFieldAccess(PsiExpression expression) {
|
||||
expression = PsiUtil.deparenthesizeExpression(expression);
|
||||
@@ -138,10 +126,8 @@ public class WhileLoopSpinsOnFieldInspection extends BaseInspection {
|
||||
if (!(expression instanceof PsiReferenceExpression)) {
|
||||
return null;
|
||||
}
|
||||
final PsiReferenceExpression reference =
|
||||
(PsiReferenceExpression)expression;
|
||||
final PsiExpression qualifierExpression =
|
||||
reference.getQualifierExpression();
|
||||
final PsiReferenceExpression reference = (PsiReferenceExpression)expression;
|
||||
final PsiExpression qualifierExpression = reference.getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
return null;
|
||||
}
|
||||
@@ -166,11 +152,9 @@ public class WhileLoopSpinsOnFieldInspection extends BaseInspection {
|
||||
return true;
|
||||
}
|
||||
if (statement instanceof PsiBlockStatement) {
|
||||
final PsiBlockStatement blockStatement =
|
||||
(PsiBlockStatement)statement;
|
||||
final PsiBlockStatement blockStatement = (PsiBlockStatement)statement;
|
||||
final PsiCodeBlock codeBlock = blockStatement.getCodeBlock();
|
||||
final PsiStatement[] codeBlockStatements =
|
||||
codeBlock.getStatements();
|
||||
final PsiStatement[] codeBlockStatements = codeBlock.getStatements();
|
||||
for (PsiStatement codeBlockStatement : codeBlockStatements) {
|
||||
if (!statementIsEmpty(codeBlockStatement)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user