mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[codeinsight] IDEA-236413 Java: incorrect text for unused public fields with Inject
IDEA used did not use to check the visibility of a field and if there is the javax.inject.Inject or similar annotations added to the field IDEA used to always reported the the Private field is not used. This patch adds a new method that generates the error messages based on the visibility level of the field. Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com> GitOrigin-RevId: 89d7e2f783b1e54b239d15a2007d9e7376ffdbfa
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1433e69669
commit
c5914f53b9
+12
-2
@@ -28,6 +28,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.PomNamedTarget;
|
||||
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
|
||||
@@ -297,7 +298,7 @@ class PostHighlightingVisitor {
|
||||
|
||||
final boolean readReferenced = myRefCountHolder.isReferencedForRead(field);
|
||||
if (!readReferenced && !UnusedSymbolUtil.isImplicitRead(project, field)) {
|
||||
String message = JavaErrorBundle.message("private.field.is.not.used.for.reading", identifier.getText());
|
||||
String message = getNotUsedForReadingMessage(field, identifier);
|
||||
return suggestionsToMakeFieldUsed(field, identifier, message);
|
||||
}
|
||||
|
||||
@@ -326,7 +327,7 @@ class PostHighlightingVisitor {
|
||||
}
|
||||
else if (UnusedSymbolUtil.isFieldUnused(myProject, myFile, field, progress, helper)) {
|
||||
if (UnusedSymbolUtil.isImplicitWrite(myProject, field)) {
|
||||
String message = JavaErrorBundle.message("private.field.is.not.used.for.reading", identifier.getText());
|
||||
String message = getNotUsedForReadingMessage(field, identifier);
|
||||
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
|
||||
QuickFixAction.registerQuickFixAction(highlightInfo, QuickFixFactory.getInstance().createSafeDeleteFix(field), myDeadCodeKey);
|
||||
return highlightInfo;
|
||||
@@ -336,6 +337,15 @@ class PostHighlightingVisitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getNotUsedForReadingMessage(@NotNull final PsiField field, @NotNull final PsiIdentifier identifier) {
|
||||
final String visibility = VisibilityUtil.getVisibilityStringToDisplay(field);
|
||||
|
||||
final String message = JavaErrorBundle.message("field.is.not.used.for.reading", visibility, identifier.getText());
|
||||
|
||||
return StringUtil.capitalize(message);
|
||||
}
|
||||
|
||||
private HighlightInfo suggestionsToMakeFieldUsed(@NotNull PsiField field, @NotNull PsiIdentifier identifier, @NotNull String message) {
|
||||
HighlightInfo highlightInfo = UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
|
||||
SpecialAnnotationsUtilBase.createAddToSpecialAnnotationFixes(field, annoName -> {
|
||||
|
||||
@@ -275,7 +275,7 @@ local.variable.is.not.used.for.reading=Variable ''{0}'' is assigned but never ac
|
||||
local.variable.is.not.assigned=Variable ''{0}'' is never assigned
|
||||
private.field.is.not.used=Private field ''{0}'' is never used
|
||||
field.is.not.used=Field ''{0}'' is never used
|
||||
private.field.is.not.used.for.reading=Private field ''{0}'' is assigned but never accessed
|
||||
field.is.not.used.for.reading={0} field ''{1}'' is assigned but never accessed
|
||||
private.field.is.not.assigned=Private field ''{0}'' is never assigned
|
||||
parameter.is.not.used=Parameter ''{0}'' is never used
|
||||
pattern.variable.is.not.used=Pattern variable ''{0}'' is never used
|
||||
|
||||
+1
-1
@@ -1,4 +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>;
|
||||
public String <warning descr="Public field 'implicitWrite' is assigned but never accessed">implicitWrite</warning>;
|
||||
}
|
||||
Reference in New Issue
Block a user