diff options
Diffstat (limited to 'plugins/InspectionGadgets/InspectionGadgetsAnalysis/src')
10 files changed, 237 insertions, 72 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml index 5581810b3f2c..c8854d4dbb26 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml @@ -2363,7 +2363,7 @@ implementationClass="com.siyeh.ig.style.UnnecessaryToStringCallInspection"/> <localInspection language="JAVA" suppressId="RedundantNoArgConstructor" shortName="UnnecessaryConstructor" bundle="com.siyeh.InspectionGadgetsBundle" key="unnecessary.constructor.display.name" groupBundle="messages.InspectionsBundle" - groupKey="group.names.code.style.issues" enabledByDefault="false" level="WARNING" cleanupTool="true" + groupKey="group.names.code.style.issues" enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.style.UnnecessaryConstructorInspection"/> <localInspection language="JAVA" shortName="UnnecessaryEnumModifier" bundle="com.siyeh.InspectionGadgetsBundle" key="unnecessary.enum.modifier.display.name" groupBundle="messages.InspectionsBundle" diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index 715bf898c50a..1dfdfb9eb50a 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1700,7 +1700,7 @@ this.class=this class assertequals.may.be.assertsame.display.name='assertEquals()' may be 'assertSame()' assertequals.may.be.assertsame.problem.descriptor=<code>#ref()</code> may be 'assertSame()' #loc logger.initialized.with.foreign.class.quickfix=Replace with ''{0}.class'' -logger.initialized.with.foreign.class.problem.descriptor=Logger initializer with foreign class <code>#ref</code> #loc +logger.initialized.with.foreign.class.problem.descriptor=Logger initialized with foreign class <code>#ref</code> #loc logger.initialized.with.foreign.class.display.name=Logger initialized with foreign class logger.factory.method.name=Logger factory method name logger.factory.class.name=Logger factory class name @@ -2018,8 +2018,8 @@ string.concatenation.argument.to.log.call.display.name=Non-constant string conca string.concatenation.argument.to.log.call.problem.descriptor=Non-constant string concatenation as argument to <code>#ref()</code> logging call #loc string.concatenation.argument.to.log.call.quickfix=Replace concatenation with parameterized log message placeholder.count.matches.argument.count.display.name=Number of placeholders does not match number of arguments in logging call -placeholder.count.matches.argument.count.more.problem.descriptor=<code>#ref()</code> call has more arguments ({0}) than placeholders ({1}) #loc -placeholder.count.matches.argument.count.fewer.problem.descriptor=<code>#ref()</code> call has fewer arguments ({0}) than placeholders ({1}) #loc +placeholder.count.matches.argument.count.more.problem.descriptor=More arguments provided ({0}) than placeholders specified ({1}) in ''{2}'' #loc +placeholder.count.matches.argument.count.fewer.problem.descriptor=Fewer arguments provided ({0}) than placeholders specified ({1}) in ''{2}'' #loc assignment.to.superclass.field.display.name=Constructor assigns value to field defined in superclass assignment.to.superclass.field.problem.descriptor=Assignment to field ''{0}'' defined in superclass ''{1}'' #loc junit.rule.display.name=Malformed @Rule/@ClassRule field diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeFieldFinalFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeFieldFinalFix.java index 80ebfa0ae7d3..00d9f04b8c02 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeFieldFinalFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/MakeFieldFinalFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2010 Bas Leijdekkers + * Copyright 2007-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. @@ -18,7 +18,6 @@ package com.siyeh.ig.fixes; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; -import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.FinalUtils; @@ -61,8 +60,7 @@ public class MakeFieldFinalFix extends InspectionGadgetsFix { } @Override - protected void doFix(Project project, ProblemDescriptor descriptor) - throws IncorrectOperationException { + protected void doFix(Project project, ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); final PsiField field; if (element instanceof PsiReferenceExpression) { @@ -81,6 +79,7 @@ public class MakeFieldFinalFix extends InspectionGadgetsFix { } field = (PsiField)parent; } + field.normalizeDeclaration(); final PsiModifierList modifierList = field.getModifierList(); if (modifierList == null) { return; diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/internationalization/ImplicitDefaultCharsetUsageInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/internationalization/ImplicitDefaultCharsetUsageInspection.java index a2a3b12bd8de..ef598f5d2216 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/internationalization/ImplicitDefaultCharsetUsageInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/internationalization/ImplicitDefaultCharsetUsageInspection.java @@ -19,6 +19,7 @@ import com.intellij.psi.*; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -143,9 +144,10 @@ public class ImplicitDefaultCharsetUsageInspection extends BaseInspection { } private static boolean hasCharsetType(PsiVariable variable) { - final PsiType lastType = variable.getType(); - return lastType.equalsToText(CommonClassNames.JAVA_LANG_STRING) || - lastType.equalsToText("java.nio.charset.Charset"); + return TypeUtils.variableHasTypeOrSubtype(variable, CommonClassNames.JAVA_LANG_STRING, + "java.nio.charset.Charset", + "java.nio.charset.CharsetEncoder", + "java.nio.charset.CharsetDecoder"); } } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java index 750b723031d4..08c54abce2a1 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/LoggerInitializedWithForeignClassInspectionBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,13 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.WriteExternalException; import com.intellij.psi.*; -import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.PsiReplacementUtil; +import com.siyeh.ig.psiutils.ClassUtils; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -157,7 +157,10 @@ public class LoggerInitializedWithForeignClassInspectionBase extends BaseInspect if (expressions.length != 1) { return; } - final PsiClass containingClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class); + PsiClass containingClass = ClassUtils.getContainingClass(expression); + while (containingClass instanceof PsiAnonymousClass) { + containingClass = ClassUtils.getContainingClass(containingClass); + } if (containingClass == null) { return; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java index a2c9307fc80c..711b0edb5c4b 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java @@ -45,13 +45,14 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti protected String buildErrorString(Object... infos) { final Integer argumentCount = (Integer)infos[0]; final Integer placeholderCount = (Integer)infos[1]; + final Object value = infos[2]; if (argumentCount.intValue() > placeholderCount.intValue()) { return InspectionGadgetsBundle.message("placeholder.count.matches.argument.count.more.problem.descriptor", - argumentCount, placeholderCount); + argumentCount, placeholderCount, value); } else { return InspectionGadgetsBundle.message("placeholder.count.matches.argument.count.fewer.problem.descriptor", - argumentCount, placeholderCount); + argumentCount, placeholderCount, value); } } @@ -83,25 +84,24 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti if (arguments.length == 0) { return; } - final PsiExpression firstArgument = arguments[0]; - final int placeholderCount; + PsiExpression logStringArgument = arguments[0]; final int argumentCount; - if (InheritanceUtil.isInheritor(firstArgument.getType(), "org.slf4j.Marker")) { + if (InheritanceUtil.isInheritor(logStringArgument.getType(), "org.slf4j.Marker")) { if (arguments.length < 2) { return; } - final PsiExpression secondArgument = arguments[1]; - placeholderCount = countPlaceholders(secondArgument); + logStringArgument = arguments[1]; argumentCount = countArguments(arguments, 2); } else { - placeholderCount = countPlaceholders(firstArgument); argumentCount = countArguments(arguments, 1); } + final Object value = ExpressionUtils.computeConstantExpression(logStringArgument); + final int placeholderCount = countPlaceholders(value); if (placeholderCount < 0 || argumentCount < 0 || placeholderCount == argumentCount) { return; } - registerMethodCallError(expression, Integer.valueOf(argumentCount), Integer.valueOf(placeholderCount)); + registerError(logStringArgument, Integer.valueOf(argumentCount), Integer.valueOf(placeholderCount), value); } private static boolean hasThrowableType(PsiExpression lastArgument) { @@ -118,8 +118,7 @@ public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspecti return InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_LANG_THROWABLE); } - public static int countPlaceholders(PsiExpression argument) { - final Object value = ExpressionUtils.computeConstantExpression(argument); + public static int countPlaceholders(Object value) { if (!(value instanceof String)) { return -1; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/MethodMayBeStaticInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/MethodMayBeStaticInspectionBase.java new file mode 100644 index 000000000000..2377e4e14c20 --- /dev/null +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/MethodMayBeStaticInspectionBase.java @@ -0,0 +1,181 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.ig.performance; + +import com.intellij.codeInspection.InspectionManager; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.WriteExternalException; +import com.intellij.psi.*; +import com.intellij.psi.search.searches.ClassInheritorsSearch; +import com.intellij.util.Processor; +import com.intellij.util.Query; +import com.siyeh.InspectionGadgetsBundle; +import com.siyeh.ig.BaseInspection; +import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.psiutils.ClassUtils; +import com.siyeh.ig.psiutils.MethodUtils; +import com.siyeh.ig.psiutils.SerializationUtils; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.atomic.AtomicInteger; + +public class MethodMayBeStaticInspectionBase extends BaseInspection { + protected static final String IGNORE_DEFAULT_METHODS_ATTR_NAME = "m_ignoreDefaultMethods"; + protected static final String ONLY_PRIVATE_OR_FINAL_ATTR_NAME = "m_onlyPrivateOrFinal"; + protected static final String IGNORE_EMPTY_METHODS_ATTR_NAME = "m_ignoreEmptyMethods"; + protected static final String REPLACE_QUALIFIER_ATTR_NAME = "m_replaceQualifier"; + /** + * @noinspection PublicField + */ + public boolean m_onlyPrivateOrFinal = false; + /** + * @noinspection PublicField + */ + public boolean m_ignoreEmptyMethods = true; + public boolean m_ignoreDefaultMethods = true; + public boolean m_replaceQualifier = true; + + @Override + @NotNull + public String getDisplayName() { + return InspectionGadgetsBundle.message("method.may.be.static.display.name"); + } + + @Override + @NotNull + protected String buildErrorString(Object... infos) { + return InspectionGadgetsBundle.message("method.may.be.static.problem.descriptor"); + } + + @Override + public BaseInspectionVisitor buildVisitor() { + return new MethodCanBeStaticVisitor(); + } + + @Override + public void writeSettings(@NotNull Element node) throws WriteExternalException { + node.addContent(new Element("option").setAttribute("name", ONLY_PRIVATE_OR_FINAL_ATTR_NAME).setAttribute("value", String.valueOf(m_onlyPrivateOrFinal))); + node.addContent(new Element("option").setAttribute("name", IGNORE_EMPTY_METHODS_ATTR_NAME).setAttribute("value", String.valueOf( + m_ignoreEmptyMethods))); + if (!m_ignoreDefaultMethods) { + node.addContent(new Element("option").setAttribute("name", IGNORE_DEFAULT_METHODS_ATTR_NAME).setAttribute("value", "false")); + } + if (!m_replaceQualifier) { + node.addContent(new Element("option").setAttribute("name", REPLACE_QUALIFIER_ATTR_NAME).setAttribute("value", "false")); + } + } + + private class MethodCanBeStaticVisitor extends BaseInspectionVisitor { + + @Override + public void visitMethod(@NotNull PsiMethod method) { + super.visitMethod(method); + if (method.hasModifierProperty(PsiModifier.STATIC) || + method.hasModifierProperty(PsiModifier.ABSTRACT) || + method.hasModifierProperty(PsiModifier.SYNCHRONIZED) || + method.hasModifierProperty(PsiModifier.NATIVE)) { + return; + } + if (method.isConstructor() || method.getNameIdentifier() == null) { + return; + } + if (m_ignoreDefaultMethods && method.hasModifierProperty(PsiModifier.DEFAULT)) { + return; + } + if (m_ignoreEmptyMethods && MethodUtils.isEmpty(method)) { + return; + } + final PsiClass containingClass = ClassUtils.getContainingClass(method); + if (containingClass == null) { + return; + } + final Condition<PsiElement>[] addins = InspectionManager.CANT_BE_STATIC_EXTENSION.getExtensions(); + for (Condition<PsiElement> addin : addins) { + if (addin.value(method)) { + return; + } + } + final PsiElement scope = containingClass.getScope(); + if (!(scope instanceof PsiJavaFile) && !containingClass.hasModifierProperty(PsiModifier.STATIC) && !containingClass.isInterface()) { + return; + } + if (m_onlyPrivateOrFinal && !method.hasModifierProperty(PsiModifier.FINAL) && !method.hasModifierProperty(PsiModifier.PRIVATE)) { + return; + } + if (isExcluded(method) || MethodUtils.hasSuper(method) || MethodUtils.isOverridden(method)) { + return; + } + if (implementsSurprisingInterface(method)) { + return; + } + final MethodReferenceVisitor visitor = new MethodReferenceVisitor(method); + method.accept(visitor); + if (!visitor.areReferencesStaticallyAccessible()) { + return; + } + registerMethodError(method); + } + + private boolean implementsSurprisingInterface(final PsiMethod method) { + final PsiClass containingClass = method.getContainingClass(); + if (containingClass == null) { + return false; + } + final Query<PsiClass> search = ClassInheritorsSearch.search(containingClass, method.getUseScope(), true, true, false); + final boolean[] result = new boolean[1]; + search.forEach(new Processor<PsiClass>() { + AtomicInteger count = new AtomicInteger(0); + + @Override + public boolean process(PsiClass subClass) { + if (count.incrementAndGet() > 5) { + result[0] = true; + return false; + } + final PsiReferenceList list = subClass.getImplementsList(); + if (list == null) { + return true; + } + final PsiJavaCodeReferenceElement[] referenceElements = list.getReferenceElements(); + for (PsiJavaCodeReferenceElement referenceElement : referenceElements) { + final PsiElement target = referenceElement.resolve(); + if (!(target instanceof PsiClass)) { + result[0] = true; + return false; + } + final PsiClass aClass = (PsiClass)target; + if (!aClass.isInterface()) { + result[0] = true; + return false; + } + if (aClass.findMethodBySignature(method, true) != null) { + result[0] = true; + return false; + } + } + return true; + } + }); + return result[0]; + } + + private boolean isExcluded(PsiMethod method) { + return SerializationUtils.isWriteObject(method) || SerializationUtils.isReadObject(method) || + SerializationUtils.isWriteReplace(method) || SerializationUtils.isReadResolve(method); + } + } +} diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentExcludedVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentExcludedVisitor.java index 69710a084904..f7778e0a89bc 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentExcludedVisitor.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentExcludedVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2012 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. @@ -44,49 +44,35 @@ class VariablePassedAsArgumentExcludedVisitor extends JavaRecursiveElementVisito } @Override - public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) { + public void visitCallExpression(PsiCallExpression callExpression) { if (passed) { return; } - super.visitMethodCallExpression(call); - final PsiExpressionList argumentList = call.getArgumentList(); - final PsiExpression[] arguments = argumentList.getExpressions(); - for (PsiExpression argument : arguments) { - if (!VariableAccessUtils.mayEvaluateToVariable(argument, variable, myBuilderPattern)) { - continue; - } - final PsiMethod method = call.resolveMethod(); - if (method != null) { - final PsiClass aClass = method.getContainingClass(); - if (aClass != null) { - final String name = aClass.getQualifiedName(); - if (excludes.contains(name)) { - continue; - } - } - } - passed = true; - } + super.visitCallExpression(callExpression); + visitCall(callExpression); } @Override - public void visitNewExpression(@NotNull PsiNewExpression newExpression) { + public void visitEnumConstant(PsiEnumConstant enumConstant) { if (passed) { return; } - super.visitNewExpression(newExpression); - final PsiExpressionList argumentList = newExpression.getArgumentList(); + super.visitEnumConstant(enumConstant); + visitCall(enumConstant); + } + + private void visitCall(PsiCall call) { + final PsiExpressionList argumentList = call.getArgumentList(); if (argumentList == null) { return; } - final PsiExpression[] arguments = argumentList.getExpressions(); - for (PsiExpression argument : arguments) { + for (PsiExpression argument : argumentList.getExpressions()) { if (!VariableAccessUtils.mayEvaluateToVariable(argument, variable, myBuilderPattern)) { continue; } - final PsiMethod constructor = newExpression.resolveConstructor(); - if (constructor != null) { - final PsiClass aClass = constructor.getContainingClass(); + final PsiMethod method = call.resolveMethod(); + if (method != null) { + final PsiClass aClass = method.getContainingClass(); if (aClass != null) { final String name = aClass.getQualifiedName(); if (excludes.contains(name)) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentVisitor.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentVisitor.java index 7938fbc5c696..92082cea9e27 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentVisitor.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/VariablePassedAsArgumentVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2011 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. @@ -37,33 +37,29 @@ class VariablePassedAsArgumentVisitor extends JavaRecursiveElementVisitor { } @Override - public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) { + public void visitCallExpression(PsiCallExpression callExpression) { + super.visitCallExpression(callExpression); if (passed) { return; } - super.visitMethodCallExpression(call); - final PsiExpressionList argumentList = call.getArgumentList(); - final PsiExpression[] arguments = argumentList.getExpressions(); - for (PsiExpression argument : arguments) { - if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) { - passed = true; - break; - } - } + visitCall(callExpression); } @Override - public void visitNewExpression(@NotNull PsiNewExpression newExpression) { + public void visitEnumConstant(PsiEnumConstant enumConstant) { if (passed) { return; } - super.visitNewExpression(newExpression); - final PsiExpressionList argumentList = newExpression.getArgumentList(); + super.visitEnumConstant(enumConstant); + visitCall(enumConstant); + } + + private void visitCall(PsiCall call) { + final PsiExpressionList argumentList = call.getArgumentList(); if (argumentList == null) { return; } - final PsiExpression[] arguments = argumentList.getExpressions(); - for (PsiExpression argument : arguments) { + for (PsiExpression argument : argumentList.getExpressions()) { if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) { passed = true; break; diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryConstructorInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryConstructorInspection.java index 126f5021a47f..8b7e23fa1547 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryConstructorInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnnecessaryConstructorInspection.java @@ -15,7 +15,6 @@ */ package com.siyeh.ig.style; -import com.intellij.codeInspection.CleanupLocalInspectionTool; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; import com.intellij.openapi.project.Project; @@ -30,7 +29,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; -public class UnnecessaryConstructorInspection extends BaseInspection implements CleanupLocalInspectionTool { +public class UnnecessaryConstructorInspection extends BaseInspection { @NonNls private static final String SUPER_CALL_TEXT = PsiKeyword.SUPER + "();"; |