From 429b2acb177b24ca8b06ec48fc187740d2bdd63d Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Sun, 29 Jul 2012 20:08:10 +0400 Subject: [PATCH] groovy field can be used if it implicitly overrides getter or setter of base class --- .../local/GroovyPostHighlightingPass.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java index 8f5a2d5a3f25..0979ce3ea7c8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java @@ -61,6 +61,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement; import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; @@ -140,7 +141,7 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass { unusedDeclarations.add(highlightInfo); } } - else if (element instanceof GrField && PostHighlightingPass.isFieldUnused((GrField)element, progress, usageHelper)) { + else if (element instanceof GrField && isFieldUnused((GrField)element, progress, usageHelper)) { HighlightInfo highlightInfo = PostHighlightingPass.createUnusedSymbolInfo(nameId, "Property " + name + " is unused", HighlightInfoType.UNUSED_SYMBOL); QuickFixAction.registerQuickFixAction(highlightInfo, new SafeDeleteFix(element)); @@ -206,6 +207,26 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass { } + private static boolean isFieldUnused(GrField field, ProgressIndicator progress, GlobalUsageHelper usageHelper) { + if (!PostHighlightingPass.isFieldUnused(field, progress, usageHelper)) return false; + final GrAccessorMethod[] getters = field.getGetters(); + final GrAccessorMethod setter = field.getSetter(); + + for (GrAccessorMethod getter : getters) { + if (getter.findSuperMethods().length > 0) { + return false; + } + } + + if (setter != null) { + if (setter.findSuperMethods().length > 0) { + return false; + } + } + + return true; + } + private static boolean isOverriddenOrOverrides(PsiMethod method) { boolean overrides = SuperMethodsSearch.search(method, null, true, false).findFirst() != null; return overrides || OverridingMethodsSearch.search(method).findFirst() != null;