IDEA-65831 ("instance field accessed not qualified with this"-inspection is broken)

This commit is contained in:
Bas Leijdekkers
2011-02-26 12:23:43 +01:00
parent d005c90dfa
commit a6d4294ee0
4 changed files with 59 additions and 10 deletions
@@ -112,11 +112,9 @@ public class UnqualifiedFieldAccessInspection extends BaseInspection {
@Override public void visitReferenceExpression(
@NotNull PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
final PsiElement parent =
expression.getParent();
if (parent instanceof PsiReferenceExpression ||
parent instanceof PsiCallExpression) {
// optimization
final PsiExpression qualifierExpression =
expression.getQualifierExpression();
if (qualifierExpression != null) {
return;
}
final PsiReferenceParameterList parameterList =
@@ -129,11 +127,6 @@ public class UnqualifiedFieldAccessInspection extends BaseInspection {
// definitely not references to fields.
return;
}
final PsiExpression qualifierExpression =
expression.getQualifierExpression();
if (qualifierExpression != null) {
return;
}
final PsiElement element = expression.resolve();
if (!(element instanceof PsiField)) {
return;
@@ -0,0 +1,12 @@
package com.siyeh.igtest.style.unqualified_field_access;
public class UnqualifiedFieldAccess {
private String field;
public void x () {
field = "foofoo";
final String s = String.valueOf(field.hashCode());
System.out.println(s);
}
}
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>UnqualifiedFieldAccess.java</file>
<line>8</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Instance field access not qualified with 'this'</problem_class>
<description>Instance field access &lt;code&gt;field&lt;/code&gt; is not qualified with 'this' #loc</description>
</problem>
<problem>
<file>UnqualifiedFieldAccess.java</file>
<line>9</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Instance field access not qualified with 'this'</problem_class>
<description>Instance field access &lt;code&gt;field&lt;/code&gt; is not qualified with 'this' #loc</description>
</problem>
</problems>
@@ -0,0 +1,27 @@
/*
* 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.IGInspectionTestCase;
public class UnqualifiedFieldAccessInspectionTest
extends IGInspectionTestCase {
public void test() throws Exception {
doTest("com/siyeh/igtest/style/unqualified_field_access",
new UnqualifiedFieldAccessInspection());
}
}