refactoring
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInsight / quickfix / UnresolvedReferenceQuickFixProvider.java
blobe177857f40775995c4408b754ad84bfcb485b2a3
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.codeInsight.quickfix;
18 import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
19 import com.intellij.openapi.extensions.ExtensionPointName;
20 import com.intellij.openapi.extensions.Extensions;
21 import com.intellij.openapi.project.DumbAware;
22 import com.intellij.openapi.project.DumbService;
23 import com.intellij.psi.PsiReference;
24 import com.intellij.util.ReflectionCache;
25 import org.jetbrains.annotations.NotNull;
27 public abstract class UnresolvedReferenceQuickFixProvider<T extends PsiReference> {
29 public static <T extends PsiReference> void registerReferenceFixes(T ref, QuickFixActionRegistrar registrar) {
31 final boolean dumb = DumbService.getInstance(ref.getElement().getProject()).isDumb();
32 UnresolvedReferenceQuickFixProvider[] fixProviders = Extensions.getExtensions(EXTENSION_NAME);
33 Class<? extends PsiReference> referenceClass = ref.getClass();
34 for (UnresolvedReferenceQuickFixProvider each : fixProviders) {
35 if (dumb && !(each instanceof DumbAware)) {
36 continue;
38 if (ReflectionCache.isAssignable(each.getReferenceClass(), referenceClass)) {
39 each.registerFixes(ref, registrar);
44 private static final ExtensionPointName<UnresolvedReferenceQuickFixProvider> EXTENSION_NAME =
45 ExtensionPointName.create("com.intellij.codeInsight.unresolvedReferenceQuickFixProvider");
47 public abstract void registerFixes(T ref, QuickFixActionRegistrar registrar);
49 @NotNull
50 public abstract Class<T> getReferenceClass();