mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight unused fields implicitly assigned by extension (IDEA-166091)
This commit is contained in:
+7
-1
@@ -339,10 +339,16 @@ class PostHighlightingVisitor {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
else if (UnusedSymbolUtil.isImplicitUsage(myProject, field, progress)) {
|
||||
else if (UnusedSymbolUtil.isImplicitRead(myProject, field, progress)) {
|
||||
return null;
|
||||
}
|
||||
else if (UnusedSymbolUtil.isFieldUnused(myProject, myFile, field, progress, helper)) {
|
||||
if (UnusedSymbolUtil.isImplicitWrite(myProject, field, progress)) {
|
||||
String message = JavaErrorMessages.message("private.field.is.not.used.for.reading", identifier.getText());
|
||||
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createSafeDeleteFix(field), myDeadCodeKey);
|
||||
return highlightInfo;
|
||||
}
|
||||
return formatUnusedSymbolHighlightInfo(project, "field.is.not.used", field, "fields", myDeadCodeKey, myDeadCodeInfoType, identifier);
|
||||
}
|
||||
return null;
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
public class <warning descr="Class 'MarkFieldsWhichAreExplicitlyWrittenAsUnused' is never used">MarkFieldsWhichAreExplicitlyWrittenAsUnused</warning> {
|
||||
|
||||
public String <warning descr="Private field 'implicitWrite' is assigned but never accessed">implicitWrite</warning>;
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LightUnusedHighlightingFixtureTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new UnusedDeclarationInspection(true));
|
||||
}
|
||||
|
||||
public void testMarkFieldsWhichAreExplicitlyWrittenAsUnused() throws Exception {
|
||||
PlatformTestUtil.registerExtension(ImplicitUsageProvider.EP_NAME, new ImplicitUsageProvider() {
|
||||
@Override
|
||||
public boolean isImplicitUsage(PsiElement element) {
|
||||
return isImplicitWrite(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isImplicitRead(PsiElement element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isImplicitWrite(PsiElement element) {
|
||||
return element instanceof PsiField && "implicitWrite".equals(((PsiNamedElement)element).getName());
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
myFixture.checkHighlighting();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/advFixture";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user