highlight unnecessary qualifier as unused instead of the full qualified name as yellow

This commit is contained in:
Alexey Kudravtsev
2015-06-19 13:33:12 +03:00
parent 7ed70cd928
commit 9edd99c42a
4 changed files with 23 additions and 32 deletions
@@ -959,8 +959,8 @@ unnecessary.this.problem.descriptor=<code>#ref</code> is unnecessary in this con
unnecessary.block.statement.problem.descriptor=Braces around this statement are unnecessary #loc
unnecessary.continue.problem.descriptor=<code>#ref</code> is unnecessary as the last statement in a loop #loc
unnecessary.semicolon.problem.descriptor=Unnecessary semicolon <code>#ref</code> #loc
unnecessary.fully.qualified.name.problem.descriptor1=Fully qualified name <code>#ref</code> is unnecessary, and can be replaced with an import #loc
unnecessary.fully.qualified.name.problem.descriptor2=Fully qualified name <code>#ref</code> is unnecessary, and the qualification can be removed #loc
unnecessary.fully.qualified.name.problem.descriptor1=Qualifier <code>#ref</code> is unnecessary, and can be replaced with an import #loc
unnecessary.fully.qualified.name.problem.descriptor2=Qualifier <code>#ref</code> is unnecessary and can be removed #loc
unnecessary.qualifier.for.this.problem.descriptor=Qualifier <code>#ref</code> on 'this' is unnecessary in this context #loc
unused.label.problem.descriptor=Unused label <code>#ref</code> #loc
redundant.field.initialization.problem.descriptor=Field initialization to <code>#ref</code> is redundant #loc
@@ -1368,8 +1368,7 @@ redundant.implements.remove.quickfix=Remove redundant interface declaration
unnecessary.constructor.remove.quickfix=Remove redundant constructor
unnecessary.fully.qualified.name.replace.quickfix=Replace with import
unnecessary.fully.qualified.name.remove.quickfix=Remove qualification
unnecessary.fully.qualified.name.status.bar.escape.highlighting.message1=1 fully qualified name replaced with import (press Escape to remove highlighting)
unnecessary.fully.qualified.name.status.bar.escape.highlighting.message2={0} fully qualified names replaced with import (press Escape to remove highlighting)
unnecessary.fully.qualified.name.status.bar.escape.highlighting.message={0} fully qualified {0, choice, 1#name|2#names} replaced with import (press Escape to remove highlighting)
unnecessary.parentheses.remove.quickfix=Remove unnecessary parentheses
unnecessary.qualifier.for.this.remove.quickfix=Remove unnecessary qualifier
unnecessary.semicolon.remove.quickfix=Remove unnecessary semicolon
@@ -17,6 +17,7 @@ package com.siyeh.ig.style;
import com.intellij.codeInspection.CleanupLocalInspectionTool;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.StatusBar;
@@ -88,17 +89,14 @@ public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection impl
@Override
@NotNull
public String getName() {
if (inSameFile) {
return InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.remove.quickfix");
}
else {
return InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.replace.quickfix");
}
return inSameFile
? InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.remove.quickfix")
: InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.replace.quickfix");
}
@Override
public void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)descriptor.getPsiElement();
final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)descriptor.getPsiElement().getParent();
final PsiFile file = referenceElement.getContainingFile();
final PsiElement target = referenceElement.resolve();
if (!(target instanceof PsiClass)) {
@@ -122,25 +120,19 @@ public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection impl
if (statusBar == null) {
return;
}
if (elementCount == 1) {
statusBar.setInfo(InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.status.bar.escape.highlighting.message1"));
}
else {
statusBar.setInfo(InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.status.bar.escape.highlighting.message2",
Integer.valueOf(elementCount - 1)));
}
statusBar.setInfo(InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.status.bar.escape.highlighting.message",
elementCount));
}
private static class QualificationRemover extends JavaRecursiveElementVisitor {
private final String fullyQualifiedText;
private final List<PsiElement> shortenedElements = new ArrayList();
private final List<PsiElement> shortenedElements = new ArrayList<PsiElement>();
QualificationRemover(String fullyQualifiedText) {
private QualificationRemover(String fullyQualifiedText) {
this.fullyQualifiedText = fullyQualifiedText;
}
public Collection<PsiElement> getShortenedElements() {
private Collection<PsiElement> getShortenedElements() {
return Collections.unmodifiableCollection(shortenedElements);
}
@@ -224,7 +216,7 @@ public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection impl
if (!(qualifierTarget instanceof PsiPackage)) {
return;
}
final List<PsiJavaCodeReferenceElement> references = new ArrayList(2);
List<PsiJavaCodeReferenceElement> references = new ArrayList<PsiJavaCodeReferenceElement>(2);
references.add(reference);
if (styleSettings.INSERT_INNER_CLASS_IMPORTS) {
collectInnerClassNames(reference, references);
@@ -244,7 +236,7 @@ public class UnnecessaryFullyQualifiedNameInspection extends BaseInspection impl
continue;
}
final boolean inSameFile = aClass.getContainingFile() == containingFile;
registerError(aReference, Boolean.valueOf(inSameFile));
registerError(aReference.getQualifier(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, inSameFile);
break;
}
}
@@ -5,7 +5,7 @@
<file>DoubleQualify.java</file>
<line>4</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java.util.HashMap&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java.util&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>
</problems>
@@ -5,49 +5,49 @@
<file>UnnecessaryFullyQualifiedName.java</file>
<line>14</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java.util.List&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java.util&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>
<problem>
<file>UnnecessaryFullyQualifiedName.java</file>
<line>15</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java.util.Map&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java.util&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>
<problem>
<file>UnnecessaryFullyQualifiedName.java</file>
<line>17</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java.lang.System&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java.lang&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>
<problem>
<file>UnnecessaryFullyQualifiedName.java</file>
<line>18</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java.lang.System&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java.lang&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>
<problem>
<file>UnnecessaryFullyQualifiedName.java</file>
<line>41</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java. util. List&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java. util&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>
<problem>
<file>UnnecessaryFQNJavadoc.java</file>
<line>4</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java.util.Map&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java.util&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>
<problem>
<file>UnnecessaryFQNJavadoc.java</file>
<line>5</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary fully qualified name</problem_class>
<description>Fully qualified name &lt;code&gt;java.util.HashMap&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
<description>Qualifier &lt;code&gt;java.util&lt;/code&gt; is unnecessary, and can be replaced with an import #loc</description>
</problem>