mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove ComparisonUtils duplication
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 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.
|
||||
@@ -22,13 +22,10 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ipp.psiutils.BoolUtils;
|
||||
import com.siyeh.ipp.psiutils.ComparisonUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2005 Dave Griffith
|
||||
* Copyright 2003-2014 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.
|
||||
@@ -18,8 +18,8 @@ package com.siyeh.ipp.bool;
|
||||
import com.intellij.psi.PsiBinaryExpression;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import com.siyeh.ipp.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ipp.psiutils.ErrorUtil;
|
||||
|
||||
class ComparisonPredicate implements PsiElementPredicate {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 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.
|
||||
@@ -19,11 +19,11 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ipp.base.MutablyNamedIntention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import com.siyeh.ipp.psiutils.BoolUtils;
|
||||
import com.siyeh.ipp.psiutils.ComparisonUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DemorgansIntention extends MutablyNamedIntention {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 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.
|
||||
@@ -23,9 +23,9 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import com.siyeh.ig.PsiReplacementUtil;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ipp.base.MutablyNamedIntention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import com.siyeh.ipp.psiutils.ComparisonUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FlipComparisonIntention extends MutablyNamedIntention {
|
||||
@@ -38,7 +38,7 @@ public class FlipComparisonIntention extends MutablyNamedIntention {
|
||||
final PsiJavaToken sign = expression.getOperationSign();
|
||||
operatorText = sign.getText();
|
||||
flippedOperatorText =
|
||||
ComparisonUtils.getFlippedComparison(sign);
|
||||
ComparisonUtils.getFlippedComparison(sign.getTokenType());
|
||||
}
|
||||
if (operatorText.equals(flippedOperatorText)) {
|
||||
return IntentionPowerPackBundle.message("flip.smth.intention.name",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2006 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 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.
|
||||
@@ -20,10 +20,10 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiJavaToken;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ipp.base.MutablyNamedIntention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import com.siyeh.ipp.psiutils.ComparisonUtils;
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NegateComparisonIntention extends MutablyNamedIntention {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2007-2014 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,9 +15,12 @@
|
||||
*/
|
||||
package com.siyeh.ipp.expression;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiJavaToken;
|
||||
import com.intellij.psi.PsiPolyadicExpression;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import com.siyeh.ipp.psiutils.ComparisonUtils;
|
||||
|
||||
class ExpressionPredicate implements PsiElementPredicate {
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2013 Bas Leijdekkers
|
||||
* Copyright 2009-2014 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,11 +19,11 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ipp.base.Intention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import com.siyeh.ipp.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ipp.psiutils.VariableAccessUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 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.
|
||||
@@ -17,6 +17,7 @@ package com.siyeh.ipp.psiutils;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ipp.psiutils;
|
||||
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiBinaryExpression;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiJavaToken;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ComparisonUtils {
|
||||
|
||||
private static final Set<IElementType> comparisons =
|
||||
new HashSet<IElementType>(6);
|
||||
private static final Map<IElementType, String> flippedComparisons =
|
||||
new HashMap<IElementType, String>(6);
|
||||
private static final Map<IElementType, String> negatedComparisons =
|
||||
new HashMap<IElementType, String>(6);
|
||||
|
||||
private ComparisonUtils() {
|
||||
}
|
||||
|
||||
static {
|
||||
comparisons.add(JavaTokenType.EQEQ);
|
||||
comparisons.add(JavaTokenType.NE);
|
||||
comparisons.add(JavaTokenType.GT);
|
||||
comparisons.add(JavaTokenType.LT);
|
||||
comparisons.add(JavaTokenType.GE);
|
||||
comparisons.add(JavaTokenType.LE);
|
||||
|
||||
flippedComparisons.put(JavaTokenType.EQEQ, "==");
|
||||
flippedComparisons.put(JavaTokenType.NE, "!=");
|
||||
flippedComparisons.put(JavaTokenType.GT, "<");
|
||||
flippedComparisons.put(JavaTokenType.LT, ">");
|
||||
flippedComparisons.put(JavaTokenType.GE, "<=");
|
||||
flippedComparisons.put(JavaTokenType.LE, ">=");
|
||||
|
||||
negatedComparisons.put(JavaTokenType.EQEQ, "!=");
|
||||
negatedComparisons.put(JavaTokenType.NE, "==");
|
||||
negatedComparisons.put(JavaTokenType.GT, "<=");
|
||||
negatedComparisons.put(JavaTokenType.LT, ">=");
|
||||
negatedComparisons.put(JavaTokenType.GE, "<");
|
||||
negatedComparisons.put(JavaTokenType.LE, ">");
|
||||
}
|
||||
|
||||
public static boolean isComparison(@Nullable PsiExpression expression) {
|
||||
if (!(expression instanceof PsiBinaryExpression)) {
|
||||
return false;
|
||||
}
|
||||
final PsiBinaryExpression binaryExpression =
|
||||
(PsiBinaryExpression)expression;
|
||||
final IElementType tokenType = binaryExpression.getOperationTokenType();
|
||||
return isComparison(tokenType);
|
||||
}
|
||||
|
||||
public static boolean isComparison(@NotNull IElementType tokenType) {
|
||||
return comparisons.contains(tokenType);
|
||||
}
|
||||
|
||||
public static String getFlippedComparison(@NotNull PsiJavaToken sign) {
|
||||
final IElementType text = sign.getTokenType();
|
||||
return getFlippedComparison(text);
|
||||
}
|
||||
|
||||
public static String getFlippedComparison(IElementType text) {
|
||||
return flippedComparisons.get(text);
|
||||
}
|
||||
|
||||
public static String getNegatedComparison(IElementType tokenType) {
|
||||
return negatedComparisons.get(tokenType);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2013 Bas Leijdekkers
|
||||
* Copyright 2009-2014 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package com.siyeh.ipp.psiutils;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.ig.psiutils.ComparisonUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -39,7 +40,7 @@ public class VariableAccessUtils {
|
||||
final PsiBinaryExpression binaryExpression =
|
||||
(PsiBinaryExpression)expression;
|
||||
final IElementType tokenType = binaryExpression.getOperationTokenType();
|
||||
if (!ComparisonUtils.isComparison(tokenType)) {
|
||||
if (!ComparisonUtils.isComparisonOperation(tokenType)) {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression lhs = binaryExpression.getLOperand();
|
||||
|
||||
Reference in New Issue
Block a user