don't report groovy type parameters as unused
authorpeter <peter@jetbrains.com>
Tue, 31 Jan 2012 21:53:36 +0000 (22:53 +0100)
committerpeter <peter@jetbrains.com>
Tue, 31 Jan 2012 21:53:36 +0000 (22:53 +0100)
java/java-impl/src/com/intellij/codeInsight/daemon/impl/GlobalUsageHelper.java
java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java
plugins/groovy/src/org/jetbrains/plugins/groovy/codeInspection/local/GroovyPostHighlightingPass.java
plugins/groovy/testdata/highlighting/GloballyUnusedSymbols.groovy

index 4f4e3e87c356337eb1ec740c020a3727a7e2a345..cf2b86fd242fb19249757339bda5a46b64ec6258 100644 (file)
@@ -31,5 +31,5 @@ public abstract class GlobalUsageHelper {
 
   public abstract boolean shouldCheckUsages(@NotNull PsiMember member);
   public abstract boolean isLocallyUsed(@NotNull PsiNamedElement member);
-  public abstract boolean shouldIgnoreUsagesInCurrentFile();
+  public abstract boolean isCurrentFileAlreadyChecked();
 }
index 84e741d7f1dd52e928d9d78fb9ca4c9ebdb0df51..815715a494fab317c22ae2f4327bae25112e57c3 100644 (file)
@@ -261,7 +261,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
       }
 
       @Override
-      public boolean shouldIgnoreUsagesInCurrentFile() {
+      public boolean isCurrentFileAlreadyChecked() {
         return true;
       }
 
@@ -585,7 +585,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
       if (isImplicitUsage(method, progress)) {
         return true;
       }
-      if (!helper.shouldIgnoreUsagesInCurrentFile()) {
+      if (!helper.isCurrentFileAlreadyChecked()) {
         return !weAreSureThereAreNoUsages(method, progress, helper);
       }
     }
@@ -622,7 +622,7 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
       }
 
       PsiSearchHelper.SearchCostResult cheapEnough = PsiSearchHelper.SERVICE.getInstance(project).isCheapEnoughToSearch(name, (GlobalSearchScope)useScope,
-                                                                                                                        helper.shouldIgnoreUsagesInCurrentFile() ? member.getContainingFile() : null,
+                                                                                                                        helper.isCurrentFileAlreadyChecked() ? member.getContainingFile() : null,
                                                                                                                         progress);
       if (cheapEnough == PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES) return false;
 
@@ -702,9 +702,11 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
 
   private static boolean isReallyUsed(PsiClass aClass, ProgressIndicator progress, GlobalUsageHelper helper) {
     if (isImplicitUsage(aClass, progress) || helper.isLocallyUsed(aClass)) return true;
-    if (aClass.getContainingClass() != null && aClass.hasModifierProperty(PsiModifier.PRIVATE) ||
-           aClass.getParent() instanceof PsiDeclarationStatement ||
-           aClass instanceof PsiTypeParameter) return false;
+    if (helper.isCurrentFileAlreadyChecked()) {
+      if (aClass.getContainingClass() != null && aClass.hasModifierProperty(PsiModifier.PRIVATE) ||
+             aClass.getParent() instanceof PsiDeclarationStatement ||
+             aClass instanceof PsiTypeParameter) return false;
+    }
     return !weAreSureThereAreNoUsages(aClass, progress, helper);
   }
 
index 46b37bb78a8d547bb990860dd6d16a3ea041f454..85ebd3864b35b69f63e1cf1fc28485c3ec2353ab 100644 (file)
@@ -87,7 +87,7 @@ public class GroovyPostHighlightingPass extends TextEditorHighlightingPass {
     }
     final UnusedDeclarationInspection deadCodeInspection = (UnusedDeclarationInspection)profile.getInspectionTool(UnusedDeclarationInspection.SHORT_NAME, myFile);
     final GlobalUsageHelper usageHelper = new GlobalUsageHelper() {
-      public boolean shouldIgnoreUsagesInCurrentFile() {
+      public boolean isCurrentFileAlreadyChecked() {
         return false;
       }
 
index af47b7500098bab5cc27785e3a2c5b5040dc090b..2d98c8e740066a9c2f02f12dd388d8c0ecde4e55 100644 (file)
@@ -1,8 +1,8 @@
 
 class <warning descr="Class UnusedClass is unused">UnusedClass</warning> {}
-class Bar {
+class Bar<T, <warning descr="Class Unused is unused">Unused</warning>> {
   int <warning descr="Property unusedProperty is unused">unusedProperty</warning> = 2
-  int usedProperty = 39
+  T usedProperty = null
   int usedProperty2 = 39
   int usedProperty3 = 39
   def <warning descr="Method unusedMethod is unused">unusedMethod</warning>() {}