diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java index 242c60f71d16..4c14757e881d 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConcatenationInsideStringBufferAppendInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2015 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. @@ -27,6 +27,8 @@ import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; +import com.siyeh.ig.psiutils.ExpressionUtils; +import com.siyeh.ig.psiutils.ParenthesesUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -117,7 +119,8 @@ public class StringConcatenationInsideStringBufferAppendInspection extends BaseI return; } final PsiExpression argument = arguments[0]; - if (!isConcatenation(argument)) { + if (!ExpressionUtils.isConcatenation(ParenthesesUtils.stripParentheses(argument)) || + PsiUtil.isConstantExpression(argument)) { return; } final PsiMethod method = expression.resolveMethod(); @@ -145,23 +148,5 @@ public class StringConcatenationInsideStringBufferAppendInspection extends BaseI } registerMethodCallError(expression, containingClass); } - - private static boolean isConcatenation(PsiExpression expression) { - if (expression instanceof PsiParenthesizedExpression) { - final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression; - return isConcatenation(parenthesizedExpression.getExpression()); - } - if (!(expression instanceof PsiPolyadicExpression)) { - return false; - } - if (PsiUtil.isConstantExpression(expression)) { - return false; - } - final PsiType type = expression.getType(); - if (type == null) { - return false; - } - return type.equalsToText(CommonClassNames.JAVA_LANG_STRING); - } } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java index cd2fea0db92e..950d97de397c 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java @@ -638,4 +638,13 @@ public class ExpressionUtils { } return (PsiVariable)target; } + + public static boolean isConcatenation(PsiElement element) { + if (!(element instanceof PsiPolyadicExpression)) { + return false; + } + final PsiPolyadicExpression expression = (PsiPolyadicExpression)element; + final PsiType type = expression.getType(); + return type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING); + } } \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java index 8da78eb1d6d9..dc2a3880f9db 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 Bas Leijdekkers + * Copyright 2008-2015 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,9 +19,9 @@ import com.intellij.psi.*; import com.intellij.psi.util.PsiConcatenationUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.ig.PsiReplacementUtil; +import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ConcatenationUtils; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -39,7 +39,7 @@ public class ReplaceConcatenationWithFormatStringIntention extends Intention { protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException { PsiPolyadicExpression expression = (PsiPolyadicExpression)element; PsiElement parent = expression.getParent(); - while (ConcatenationUtils.isConcatenation(parent)) { + while (ExpressionUtils.isConcatenation(parent)) { expression = (PsiPolyadicExpression)parent; parent = expression.getParent(); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java index 6cdfdebf8419..9939dc19c81e 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2015 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.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.IntentionPowerPackBundle; import com.siyeh.ig.PsiReplacementUtil; +import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ig.psiutils.ParenthesesUtils; import com.siyeh.ipp.base.MutablyNamedIntention; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ConcatenationUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -51,7 +51,7 @@ public class ReplaceConcatenationWithStringBufferIntention extends MutablyNamedI public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException { PsiPolyadicExpression expression = (PsiPolyadicExpression)element; PsiElement parent = expression.getParent(); - while (ConcatenationUtils.isConcatenation(parent)) { + while (ExpressionUtils.isConcatenation(parent)) { expression = (PsiPolyadicExpression)parent; parent = expression.getParent(); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java index dfe8a8a4bd67..1b5e41ed0fb7 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/SimpleStringConcatenationPredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2015 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,8 +17,8 @@ package com.siyeh.ipp.concatenation; import com.intellij.codeInsight.AnnotationUtil; import com.intellij.psi.PsiElement; +import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ConcatenationUtils; class SimpleStringConcatenationPredicate implements PsiElementPredicate { @@ -30,7 +30,7 @@ class SimpleStringConcatenationPredicate implements PsiElementPredicate { @Override public boolean satisfiedBy(PsiElement element) { - if (!ConcatenationUtils.isConcatenation(element)) { + if (!ExpressionUtils.isConcatenation(element)) { return false; } return !(excludeConcatenationsInsideAnnotations && AnnotationUtil.isInsideAnnotation(element)); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java index 3c847869a129..0596234ea9ff 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2013 Dave Griffith, Bas Leijdekkers + * Copyright 2007-2015 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. @@ -24,9 +24,9 @@ import com.intellij.psi.PsiPolyadicExpression; import com.intellij.psi.tree.IElementType; import com.siyeh.IntentionPowerPackBundle; import com.siyeh.ig.PsiReplacementUtil; +import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ipp.base.MutablyNamedIntention; import com.siyeh.ipp.base.PsiElementPredicate; -import com.siyeh.ipp.psiutils.ConcatenationUtils; import com.siyeh.ig.psiutils.ParenthesesUtils; import org.jetbrains.annotations.NotNull; @@ -40,7 +40,7 @@ public class FlipExpressionIntention extends MutablyNamedIntention { final String operatorText = sign == null ? "" : sign.getText(); final IElementType tokenType = expression.getOperationTokenType(); final boolean commutative = ParenthesesUtils.isCommutativeOperator(tokenType); - if (commutative && !ConcatenationUtils.isConcatenation(expression)) { + if (commutative && !ExpressionUtils.isConcatenation(expression)) { return IntentionPowerPackBundle.message("flip.smth.intention.name", operatorText); } else { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConcatenationUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConcatenationUtils.java deleted file mode 100644 index 0a62b3181b88..000000000000 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConcatenationUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2003-2013 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.*; -import com.intellij.psi.tree.IElementType; - -public class ConcatenationUtils { - - private ConcatenationUtils() {} - - public static boolean isConcatenation(PsiElement element) { - if (!(element instanceof PsiPolyadicExpression)) { - return false; - } - final PsiPolyadicExpression expression = (PsiPolyadicExpression)element; - final IElementType tokenType = expression.getOperationTokenType(); - if (!tokenType.equals(JavaTokenType.PLUS)) { - return false; - } - final PsiExpression[] operands = expression.getOperands(); - if (operands.length <= 1) { - return false; - } - final PsiType type = expression.getType(); - if (type == null) { - for (PsiExpression operand : operands) { - if (hasStringType(operand)) { - return true; - } - } - return false; - } - return type.equalsToText(CommonClassNames.JAVA_LANG_STRING); - } - - private static boolean hasStringType(PsiExpression expression) { - final PsiType type = expression.getType(); - return type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING); - } -}