mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] cleanup: GroovyDoubleNegationInspection
GitOrigin-RevId: 2671a3e8e9ef6794b8f5247b10750e348ec77993
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b64c507ed9
commit
8f208ed054
+15
-21
@@ -25,13 +25,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspection;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovyFix;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.T_NEQ;
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.GroovyElementTypes.T_NOT;
|
||||
|
||||
public class GroovyDoubleNegationInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@@ -55,26 +57,22 @@ public class GroovyDoubleNegationInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final GrUnaryExpression expression =
|
||||
(GrUnaryExpression) descriptor.getPsiElement();
|
||||
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
|
||||
final GrUnaryExpression expression = (GrUnaryExpression)descriptor.getPsiElement();
|
||||
GrExpression operand = (GrExpression)PsiUtil.skipParentheses(expression.getOperand(), false);
|
||||
if (operand instanceof GrUnaryExpression) {
|
||||
final GrUnaryExpression prefixExpression =
|
||||
(GrUnaryExpression) operand;
|
||||
final GrUnaryExpression prefixExpression = (GrUnaryExpression)operand;
|
||||
final GrExpression innerOperand = prefixExpression.getOperand();
|
||||
if (innerOperand == null) {
|
||||
return;
|
||||
}
|
||||
replaceExpression(expression, innerOperand.getText());
|
||||
} else if (operand instanceof GrBinaryExpression) {
|
||||
final GrBinaryExpression binaryExpression =
|
||||
(GrBinaryExpression) operand;
|
||||
}
|
||||
else if (operand instanceof GrBinaryExpression) {
|
||||
final GrBinaryExpression binaryExpression = (GrBinaryExpression)operand;
|
||||
final GrExpression lhs = binaryExpression.getLeftOperand();
|
||||
final String lhsText = lhs.getText();
|
||||
final StringBuilder builder =
|
||||
new StringBuilder(lhsText);
|
||||
final StringBuilder builder = new StringBuilder(lhsText);
|
||||
builder.append("==");
|
||||
final GrExpression rhs = binaryExpression.getRightOperand();
|
||||
if (rhs != null) {
|
||||
@@ -96,9 +94,8 @@ public class GroovyDoubleNegationInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
public void visitUnaryExpression(@NotNull GrUnaryExpression expression) {
|
||||
super.visitUnaryExpression(expression);
|
||||
final IElementType tokenType = expression.getOperationTokenType();
|
||||
if (!GroovyTokenTypes.mLNOT.equals(tokenType)) {
|
||||
if (!T_NOT.equals(tokenType)) {
|
||||
return;
|
||||
}
|
||||
checkParent(expression);
|
||||
@@ -106,9 +103,8 @@ public class GroovyDoubleNegationInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
public void visitBinaryExpression(@NotNull GrBinaryExpression expression) {
|
||||
super.visitBinaryExpression(expression);
|
||||
final IElementType tokenType = expression.getOperationTokenType();
|
||||
if (!GroovyTokenTypes.mNOT_EQUAL.equals(tokenType)) {
|
||||
if (!T_NEQ.equals(tokenType)) {
|
||||
return;
|
||||
}
|
||||
checkParent(expression);
|
||||
@@ -122,11 +118,9 @@ public class GroovyDoubleNegationInspection extends BaseInspection {
|
||||
if (!(parent instanceof GrUnaryExpression)) {
|
||||
return;
|
||||
}
|
||||
final GrUnaryExpression prefixExpression =
|
||||
(GrUnaryExpression) parent;
|
||||
final IElementType parentTokenType =
|
||||
prefixExpression.getOperationTokenType();
|
||||
if (!GroovyTokenTypes.mLNOT.equals(parentTokenType)) {
|
||||
final GrUnaryExpression prefixExpression = (GrUnaryExpression)parent;
|
||||
final IElementType parentTokenType = prefixExpression.getOperationTokenType();
|
||||
if (!T_NOT.equals(parentTokenType)) {
|
||||
return;
|
||||
}
|
||||
registerError(prefixExpression);
|
||||
|
||||
Reference in New Issue
Block a user