From 006dc667312cf5095df0c957062f7a876a44fc4a Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 1 Nov 2011 10:04:57 +0100 Subject: [PATCH] IDEA-76287 (Incorrect "Instance method access not qualified with 'this'" inspection warning) --- .../siyeh/InspectionGadgetsBundle.properties | 8 ++----- .../UnqualifiedMethodAccessInspection.java | 2 +- .../UnqualifiedMethodAccess.java | 18 ++++++++++++++++ .../unqualified_method_access/expected.xml | 9 ++++++++ .../UnqualifiedFieldAccessInspectionTest.java | 21 ++----------------- ...UnqualifiedMethodAccessInspectionTest.java | 11 ++++++++++ 6 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/UnqualifiedMethodAccess.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/expected.xml create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedMethodAccessInspectionTest.java diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 7ce879c02537..20bd985d098e 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1564,8 +1564,6 @@ reflection.for.unavailable.annotation.problem.descriptor=Annotation '#ref' is no access.to.static.field.locked.on.instance.display.name=Access to static field locked on instance data access.to.static.field.locked.on.instance.problem.descriptor=Access to static field #ref locked on instance data #loc make.method.ctr.quickfix=Make method constructor -annotate.with.nonnls.quickfix=Annotate ''{0}'' with @NonNls -annotate.method.with.nonnls.quickfix=Annotate ''{0}()'' with @NonNls replace.all.dot.display.name=Call to String.replaceAll(".", ...) replace.all.dot.problem.descriptor=Call to String.#ref(".", ...) #loc constant.string.intern.display.name=Call to 'intern()' on String constant @@ -1579,7 +1577,6 @@ type.parameter.extends.final.class.display.name=Type parameter extends final cla type.parameter.extends.final.class.problem.descriptor1=Type parameter #ref extends final class ''{0}'' #loc type.parameter.extends.final.class.problem.descriptor2=Wildcard type argument #ref extends final class ''{0}'' #loc type.parameter.extends.final.class.quickfix=Replace type parameter with actual class -non.serializable.field.in.serializable.ignore.option=Ignore classes serializable due to inheritance double.negation.display.name=Double negation double.negation.problem.descriptor=Double negation in #ref #loc double.negation.quickfix=Remove double negation @@ -1588,8 +1585,8 @@ comparable.implemented.but.equals.not.overridden.display.name=Comparable impleme comparable.implemented.but.equals.not.overridden.problem.descriptor=Class #ref implements 'java.lang.Comparable' but does not override 'equals()' #loc unqualified.field.access.display.name=Instance field access not qualified with 'this' unqualified.field.access.problem.descriptor=Instance field access #ref is not qualified with 'this' #loc -unqualified.method.access.display.name=Instance method access not qualified with 'this' -unqualified.method.access.problem.descriptor=Instance field access #ref is not qualified with 'this' #loc +unqualified.method.access.display.name=Instance method call not qualified with 'this' +unqualified.method.access.problem.descriptor=Instance method call #ref is not qualified with 'this' #loc add.this.qualifier.quickfix=Add 'this' qualifier feature.envy.ignore.test.cases.option=Ignore feature envy in tests while.loop.spins.on.field.ignore.non.empty.loops.option=Only warn if the loop is empty @@ -1605,7 +1602,6 @@ assertequals.between.inconvertible.types.problem.descriptor=#ref() enumeration.can.be.iteration.display.name=Enumeration can be iteration enumeration.can.be.iteration.problem.descriptor=#ref() can be replaced with ''{0}'' construct #loc enumeration.can.be.iteration.quickfix=Replace with 'Iterator' construct -missing.override.annotation.jdk6.option=Use JDK6 @Override rules equals.hashcode.called.on.url.display.name='equals()' or 'hashCode()' called on java.net.URL object equals.hashcode.called.on.url.problem.descriptor=Call to #ref() on URL object #loc collection.contains.url.problem.decriptor={0} #ref may contain URL objects #loc diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnqualifiedMethodAccessInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnqualifiedMethodAccessInspection.java index cec8ce1a1b26..12ceb5425306 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnqualifiedMethodAccessInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnqualifiedMethodAccessInspection.java @@ -65,7 +65,7 @@ public class UnqualifiedMethodAccessInspection extends BaseInspection { return; } final PsiMethod method = (PsiMethod)element; - if (method.hasModifierProperty(PsiModifier.STATIC)) { + if (method.isConstructor() || method.hasModifierProperty(PsiModifier.STATIC)) { return; } registerError(expression); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/UnqualifiedMethodAccess.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/UnqualifiedMethodAccess.java new file mode 100644 index 000000000000..0e3b456c86c5 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/UnqualifiedMethodAccess.java @@ -0,0 +1,18 @@ +package com.siyeh.igtest.style.unqualified_method_access; + +import javax.swing.*; + +public class UnqualifiedMethodAccess extends JPanel { + public UnqualifiedMethodAccess(boolean isDoubleBuffered) { + super(isDoubleBuffered); + } + + void foo() {} + void bar() { + foo(); + } + + void foo(String s) { + this.foo(); + } +} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/expected.xml new file mode 100644 index 000000000000..a2183473e31a --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unqualified_method_access/expected.xml @@ -0,0 +1,9 @@ + + + + UnqualifiedMethodAccess.java + 12 + Instance method call not qualified with 'this' + Instance method call <code>foo</code> is not qualified with 'this' #loc + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedFieldAccessInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedFieldAccessInspectionTest.java index 426264e46aac..07d99ddb4de4 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedFieldAccessInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedFieldAccessInspectionTest.java @@ -1,27 +1,10 @@ -/* - * Copyright 2000-2011 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.style; import com.siyeh.ig.IGInspectionTestCase; -public class UnqualifiedFieldAccessInspectionTest - extends IGInspectionTestCase { +public class UnqualifiedFieldAccessInspectionTest extends IGInspectionTestCase { public void test() throws Exception { - doTest("com/siyeh/igtest/style/unqualified_field_access", - new UnqualifiedFieldAccessInspection()); + doTest("com/siyeh/igtest/style/unqualified_field_access", new UnqualifiedFieldAccessInspection()); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedMethodAccessInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedMethodAccessInspectionTest.java new file mode 100644 index 000000000000..57128c4e694d --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/UnqualifiedMethodAccessInspectionTest.java @@ -0,0 +1,11 @@ +package com.siyeh.ig.style; + +import com.siyeh.ig.IGInspectionTestCase; + +public class UnqualifiedMethodAccessInspectionTest + extends IGInspectionTestCase { + + public void test() throws Exception { + doTest("com/siyeh/igtest/style/unqualified_method_access", new UnqualifiedMethodAccessInspection()); + } +} \ No newline at end of file