@Nullable
private HighlightInfo processMethod(final PsiMethod method, ProgressIndicator progress, GlobalUsageHelper helper) {
- boolean isPrivate = method.hasModifierProperty(PsiModifier.PRIVATE);
- PsiClass containingClass = method.getContainingClass();
- if (isMethodReferenced(method, progress, isPrivate, containingClass, helper)) return null;
+ if (isMethodReferenced(method, progress, helper)) return null;
HighlightInfoType highlightInfoType;
HighlightDisplayKey highlightDisplayKey;
String key;
- if (isPrivate) {
+ if (method.hasModifierProperty(PsiModifier.PRIVATE)) {
highlightInfoType = HighlightInfoType.UNUSED_SYMBOL;
highlightDisplayKey = myUnusedSymbolKey;
key = method.isConstructor() ? "private.constructor.is.not.used" : "private.method.is.not.used";
return true;
}
});
+ PsiClass containingClass = method.getContainingClass();
if (method.getReturnType() != null || containingClass != null && Comparing.strEqual(containingClass.getName(), method.getName())) {
//ignore methods with deleted return types as they are always marked as unused without any reason
ChangeSignatureGestureDetector.getInstance(myProject).dismissForElement(method);
return highlightInfo;
}
- private static boolean isMethodReferenced(PsiMethod method,
+ public static boolean isMethodReferenced(PsiMethod method,
ProgressIndicator progress,
- boolean aPrivate,
- PsiClass containingClass,
GlobalUsageHelper helper) {
if (helper.isLocallyUsed(method)) return true;
+ boolean aPrivate = method.hasModifierProperty(PsiModifier.PRIVATE);
+ PsiClass containingClass = method.getContainingClass();
if (HighlightMethodUtil.isSerializationRelatedMethod(method, containingClass)) return true;
if (aPrivate) {
if (isIntentionalPrivateConstructor(method, containingClass)) {
if (containingClass == null) return true;
final PsiMethod valuesMethod = containingClass.getValuesMethod();
if (valuesMethod == null) return true;
- boolean isPrivate = valuesMethod.hasModifierProperty(PsiModifier.PRIVATE);
- return isMethodReferenced(valuesMethod, progress, isPrivate, containingClass, helper);
+ return isMethodReferenced(valuesMethod, progress, helper);
}
private static boolean canBeReferencedViaWeirdNames(PsiMember member) {
import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
import org.jetbrains.plugins.groovy.codeInspection.GroovyUnusedDeclarationInspection;
import org.jetbrains.plugins.groovy.lang.editor.GroovyImportOptimizer;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement;
import java.util.ArrayList;
if (deadCodeEnabled && element instanceof GrNamedElement && !PostHighlightingPass.isImplicitUsage((GrNamedElement)element, progress)) {
PsiElement nameId = ((GrNamedElement)element).getNameIdentifierGroovy();
- String name = ((GrNamedElement)element).getName();
- if (element instanceof GrTypeDefinition && PostHighlightingPass.isClassUsed((GrTypeDefinition)element, progress, usageHelper)) {
- unusedDeclarations.add(
- PostHighlightingPass.createUnusedSymbolInfo(nameId, "Class " + name + " is unused", HighlightInfoType.UNUSED_SYMBOL));
+ if (nameId.getNode().getElementType() == GroovyTokenTypes.mIDENT) {
+ String name = ((GrNamedElement)element).getName();
+ if (element instanceof GrTypeDefinition && PostHighlightingPass.isClassUsed((GrTypeDefinition)element, progress, usageHelper)) {
+ unusedDeclarations.add(
+ PostHighlightingPass.createUnusedSymbolInfo(nameId, "Class " + name + " is unused", HighlightInfoType.UNUSED_SYMBOL));
+ }
+ else if (element instanceof GrMethod) {
+ GrMethod method = (GrMethod)element;
+ if (!PostHighlightingPass.isMethodReferenced(method, progress, usageHelper)) {
+ unusedDeclarations.add(
+ PostHighlightingPass.createUnusedSymbolInfo(nameId, (method.isConstructor() ? "Constructor" : "Method") +" " + name + " is unused", HighlightInfoType.UNUSED_SYMBOL));
+ }
+ }
}
}