diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java index d26fc85b0c2b..9e1ef7f75f7b 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java @@ -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; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ComparisonPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ComparisonPredicate.java index f8e39130f7c3..1712ea4572ec 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ComparisonPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ComparisonPredicate.java @@ -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 { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java index 6d7487523ac5..eb27f3e51bf3 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java @@ -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 { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java index 8f0d7936878f..97ea780f93f9 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java @@ -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", diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java index 2a5c9c413908..7844157e2186 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java @@ -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 { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/ExpressionPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/ExpressionPredicate.java index 7055f691077e..b22f285b539c 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/ExpressionPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/ExpressionPredicate.java @@ -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 { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java index 92a3df479ef4..35404ae2f77d 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReverseForLoopDirectionIntention.java @@ -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; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java index b5e01947a586..295ca9a8df63 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java @@ -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; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ComparisonUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ComparisonUtils.java deleted file mode 100644 index f2ffeda2513b..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ComparisonUtils.java +++ /dev/null @@ -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 comparisons = - new HashSet(6); - private static final Map flippedComparisons = - new HashMap(6); - private static final Map negatedComparisons = - new HashMap(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); - } -} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java index 46e221414a91..2ac8500bad4a 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java @@ -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();