2 * Copyright 2000-2014 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 org.jetbrains.idea.devkit.inspections.quickfix;
18 import com.intellij.codeInsight.intention.IntentionAction;
19 import com.intellij.codeInspection.GlobalInspectionTool;
20 import com.intellij.codeInspection.InspectionEP;
21 import com.intellij.codeInspection.LocalInspectionEP;
22 import com.intellij.codeInspection.LocalInspectionTool;
23 import com.intellij.codeInspection.reference.UnusedDeclarationFixProvider;
24 import com.intellij.psi.PsiClass;
25 import com.intellij.psi.PsiElement;
26 import com.intellij.psi.PsiIdentifier;
27 import com.intellij.psi.util.InheritanceUtil;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.idea.devkit.util.ExtensionPointCandidate;
30 import org.jetbrains.idea.devkit.util.ExtensionPointLocator;
34 public class RegisterExtensionFixProvider implements UnusedDeclarationFixProvider {
38 public IntentionAction[] getQuickFixes(@NotNull PsiElement element) {
39 if (!(element instanceof PsiIdentifier)) return IntentionAction.EMPTY_ARRAY;
40 PsiElement parent = element.getParent();
41 if (!(parent instanceof PsiClass)) return IntentionAction.EMPTY_ARRAY;
43 PsiClass psiClass = (PsiClass)parent;
44 if (InheritanceUtil.isInheritor(psiClass, LocalInspectionTool.class.getName())) {
45 return new IntentionAction[]{new RegisterInspectionFix(psiClass, LocalInspectionEP.LOCAL_INSPECTION)};
47 if (InheritanceUtil.isInheritor(psiClass, GlobalInspectionTool.class.getName())) {
48 return new IntentionAction[]{new RegisterInspectionFix(psiClass, InspectionEP.GLOBAL_INSPECTION)};
51 ExtensionPointLocator extensionPointLocator = new ExtensionPointLocator(psiClass);
52 Set<ExtensionPointCandidate> candidateList = extensionPointLocator.findSuperCandidates();
53 if (!candidateList.isEmpty()) {
54 return new IntentionAction[]{new RegisterExtensionFix(psiClass, candidateList)};
56 return IntentionAction.EMPTY_ARRAY;