UnresolvedReferenceQuickFixProvider generalized
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Tue, 29 Dec 2009 09:36:42 +0000 (12:36 +0300)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Tue, 29 Dec 2009 09:36:42 +0000 (12:36 +0300)
java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java
java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DefaultQuickFixProvider.java
java/openapi/src/com/intellij/codeInsight/quickfix/UnresolvedReferenceQuickFixProvider.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/intentions/ResolveReferenceQuickFixProvider.java

index 1884d46fd5a3f96ec3377eeac0307dcd5a790d4c..4c2731c6ca0ef48171e467680a9a54d5995be7ee 100644 (file)
@@ -23,21 +23,18 @@ package com.intellij.codeInsight.daemon.impl.analysis;
 
 import com.intellij.codeInsight.ExceptionUtil;
 import com.intellij.codeInsight.daemon.JavaErrorMessages;
-import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
 import com.intellij.codeInsight.daemon.impl.HighlightInfo;
 import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
 import com.intellij.codeInsight.daemon.impl.quickfix.*;
 import com.intellij.codeInsight.highlighting.HighlightUsagesDescriptionLocation;
 import com.intellij.codeInsight.intention.IntentionAction;
 import com.intellij.codeInsight.intention.QuickFixFactory;
-import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
 import com.intellij.codeInsight.quickfix.ChangeVariableTypeQuickFixProvider;
+import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
 import com.intellij.lang.StdLanguages;
 import com.intellij.lang.findUsages.LanguageFindUsages;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.extensions.Extensions;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.DumbService;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.Key;
@@ -1873,17 +1870,8 @@ public class HighlightUtil {
         if (PsiUtil.isInsideJavadocComment(ref)) return null;
 
         HighlightInfo info = HighlightInfo.createHighlightInfo(type, refName, description);
-        QuickFixActionRegistrar registrar = new QuickFixActionRegistrarImpl(info);
-
-        final boolean dumb = DumbService.getInstance(ref.getProject()).isDumb();
-        UnresolvedReferenceQuickFixProvider[] fixProviders = Extensions.getExtensions(UnresolvedReferenceQuickFixProvider.EXTENSION_NAME);
-        for (UnresolvedReferenceQuickFixProvider each : fixProviders) {
-          if (dumb && !(each instanceof DumbAware)) {
-            continue;
-          }
-          each.registerFixes(ref, registrar);
-        }
 
+        UnresolvedReferenceQuickFixProvider.registerFixes(ref, new QuickFixActionRegistrarImpl(info), PsiJavaCodeReferenceElement.class);
         return info;
       }
 
index f8f7ec2566511143add9b09ecaf0c5eba3c2a2bf..8f27e8c151a2246dc13dc4f81d3635a8fc08b26e 100644 (file)
@@ -22,8 +22,9 @@ import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiTreeUtil;
 import com.intellij.psi.util.PsiUtil;
+import org.jetbrains.annotations.NotNull;
 
-public class DefaultQuickFixProvider implements UnresolvedReferenceQuickFixProvider{
+public class DefaultQuickFixProvider extends UnresolvedReferenceQuickFixProvider<PsiJavaCodeReferenceElement> {
   public void registerFixes(PsiJavaCodeReferenceElement ref, QuickFixActionRegistrar registrar) {
     registrar.register(new ImportClassFix(ref));
     registrar.register(SetupJDKFix.getInstnace());
@@ -60,4 +61,9 @@ public class DefaultQuickFixProvider implements UnresolvedReferenceQuickFixProvi
       registrar.register(new CreateInnerClassFromUsageFix(ref, CreateClassKind.CLASS));
     }
   }
+
+  @NotNull
+  public Class<PsiJavaCodeReferenceElement> getReferenceClass() {
+    return PsiJavaCodeReferenceElement.class;
+  }
 }
\ No newline at end of file
index 7840700b2b7c971412baa5a84207afb0c01d48ab..b3463f2f65925307c8292b91f8d822a267ce5112 100644 (file)
  */
 package com.intellij.codeInsight.quickfix;
 
-import com.intellij.openapi.extensions.ExtensionPointName;
-import com.intellij.psi.PsiJavaCodeReferenceElement;
 import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.project.DumbAware;
+import com.intellij.openapi.project.DumbService;
+import com.intellij.psi.PsiReference;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class UnresolvedReferenceQuickFixProvider<T extends PsiReference> {
+
+  public static <T extends PsiReference> void registerFixes(T ref, QuickFixActionRegistrar registrar, Class<T> refClass) {
+
+    final boolean dumb = DumbService.getInstance(ref.getElement().getProject()).isDumb();
+    UnresolvedReferenceQuickFixProvider[] fixProviders = Extensions.getExtensions(EXTENSION_NAME);
+    for (UnresolvedReferenceQuickFixProvider each : fixProviders) {
+      if (dumb && !(each instanceof DumbAware)) {
+        continue;
+      }
+      if (refClass.equals(each.getReferenceClass())) {
+        each.registerFixes(ref, registrar);
+      }
+    }
+  }
 
-public interface UnresolvedReferenceQuickFixProvider {
-  ExtensionPointName<UnresolvedReferenceQuickFixProvider> EXTENSION_NAME =
+  private static final ExtensionPointName<UnresolvedReferenceQuickFixProvider> EXTENSION_NAME =
       ExtensionPointName.create("com.intellij.codeInsight.unresolvedReferenceQuickFixProvider");
 
+  public abstract void registerFixes(T ref, QuickFixActionRegistrar registrar);
 
-  void registerFixes(PsiJavaCodeReferenceElement ref, QuickFixActionRegistrar registrar);
+  @NotNull
+  public abstract Class<T> getReferenceClass();
 }
index 04a6a795473dd754867a405153d7772387e864a5..15cb9f90f7808f5a2116f34d4714cfb60221a5d1 100644 (file)
  */
 package org.jetbrains.idea.maven.dom.intentions;
 
-import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
 import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
+import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
 import com.intellij.psi.PsiJavaCodeReferenceElement;
+import org.jetbrains.annotations.NotNull;
+
+public class ResolveReferenceQuickFixProvider extends UnresolvedReferenceQuickFixProvider<PsiJavaCodeReferenceElement> {
 
-public class ResolveReferenceQuickFixProvider implements UnresolvedReferenceQuickFixProvider{
   public void registerFixes(PsiJavaCodeReferenceElement ref, QuickFixActionRegistrar registrar) {
     registrar.register(new AddMavenDependencyQuickFix(ref));
   }
+
+  @NotNull
+  public Class<PsiJavaCodeReferenceElement> getReferenceClass() {
+    return PsiJavaCodeReferenceElement.class;
+  }
 }