RegisterInspectionFixProvider
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Fri, 20 Jan 2012 10:34:59 +0000 (14:34 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Fri, 20 Jan 2012 10:36:12 +0000 (14:36 +0400)
16 files changed:
java/java-impl/src/com/intellij/codeInsight/daemon/impl/PostHighlightingPass.java
platform/lang-api/src/com/intellij/codeInspection/reference/UnusedDeclarationFixProvider.java [new file with mode: 0644]
plugins/devkit/resources/META-INF/plugin.xml
plugins/devkit/src/dom/Extension.java
plugins/devkit/src/dom/Extensions.java
plugins/devkit/src/dom/impl/ExtensionImpl.java
plugins/devkit/src/dom/impl/ExtensionsImpl.java [new file with mode: 0644]
plugins/devkit/src/inspections/quickfix/RegisterInspectionFix.java [new file with mode: 0644]
plugins/devkit/src/inspections/quickfix/RegisterInspectionFixProvider.java [new file with mode: 0644]
plugins/devkit/testData/extensions/GlobalInspection.java [new file with mode: 0644]
plugins/devkit/testData/extensions/LocalInspection.java [new file with mode: 0644]
plugins/devkit/testData/extensions/globalInspection.xml [new file with mode: 0644]
plugins/devkit/testData/extensions/localInspection.xml [new file with mode: 0644]
plugins/devkit/testData/extensions/plugin.xml [new file with mode: 0644]
plugins/devkit/testSources/codeInsight/CreateExtensionTest.java [new file with mode: 0644]
resources/src/META-INF/IdeaPlugin.xml

index 95b91fa3da8592ae05047a3e3e31aeed8cedfb99..de3dd9049601927db39860129d6ee657b8f33632 100644 (file)
@@ -37,6 +37,7 @@ import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
 import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
 import com.intellij.codeInspection.ex.InspectionManagerEx;
 import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
+import com.intellij.codeInspection.reference.UnusedDeclarationFixProvider;
 import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection;
 import com.intellij.codeInspection.unusedParameters.UnusedParametersInspection;
 import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
@@ -374,7 +375,15 @@ public class PostHighlightingPass extends TextEditorHighlightingPass {
   }
 
   private static HighlightInfo createUnusedSymbolInfo(PsiElement element, String message, final HighlightInfoType highlightInfoType) {
-    return HighlightInfo.createHighlightInfo(highlightInfoType, element, message);
+    HighlightInfo info = HighlightInfo.createHighlightInfo(highlightInfoType, element, message);
+    UnusedDeclarationFixProvider[] fixProviders = Extensions.getExtensions(UnusedDeclarationFixProvider.EP_NAME);
+    for (UnusedDeclarationFixProvider provider : fixProviders) {
+      IntentionAction[] fixes = provider.getQuickFixes(element);
+      for (IntentionAction fix : fixes) {
+        QuickFixAction.registerQuickFixAction(info, fix);
+      }
+    }
+    return info;
   }
 
   @Nullable
diff --git a/platform/lang-api/src/com/intellij/codeInspection/reference/UnusedDeclarationFixProvider.java b/platform/lang-api/src/com/intellij/codeInspection/reference/UnusedDeclarationFixProvider.java
new file mode 100644 (file)
index 0000000..d9b88b6
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInspection.reference;
+
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Provides quick fixes for "Unused declaration" inspection
+ * 
+ * @author Dmitry Avdeev
+ *         Date: 1/19/12
+ */
+public interface UnusedDeclarationFixProvider {
+
+  ExtensionPointName<UnusedDeclarationFixProvider> EP_NAME = ExtensionPointName.create("com.intellij.unusedDeclarationFixProvider");
+
+  @NotNull
+  IntentionAction[] getQuickFixes(PsiElement unusedElement);
+}
index 2eebbbd6fc27b8f103edf83bc54b59cbfd60d193..330e83d18fec7352cafaa9a7046a6d57bcf8b758 100644 (file)
@@ -24,6 +24,8 @@
                         implementationClass="org.jetbrains.idea.devkit.dom.impl.IdeaPluginImpl"/>
     <dom.implementation interfaceClass="org.jetbrains.idea.devkit.dom.Extension"
                         implementationClass="org.jetbrains.idea.devkit.dom.impl.ExtensionImpl"/>
+    <dom.implementation interfaceClass="org.jetbrains.idea.devkit.dom.Extensions"
+                        implementationClass="org.jetbrains.idea.devkit.dom.impl.ExtensionsImpl"/>
     <useScopeEnlarger implementation="org.jetbrains.idea.devkit.DevKitUseScopeEnlarger"/>
 
     <configurationType implementation="org.jetbrains.idea.devkit.run.PluginConfigurationType"/>
@@ -73,6 +75,7 @@
     <moduleConfigurationEditorProvider implementation="org.jetbrains.idea.devkit.module.PluginModuleEditorsProvider"/>
     <implicitUsageProvider implementation="org.jetbrains.idea.devkit.inspections.DevKitEntryPoints"/>
     <psi.referenceContributor implementation="org.jetbrains.idea.devkit.dom.impl.InspectionsPropertiesReferenceProviderContributor"/>
+    <unusedDeclarationFixProvider implementation="org.jetbrains.idea.devkit.inspections.quickfix.RegisterInspectionFixProvider"/>
   </extensions>
 
   <module-components>
index 97b32d1760ff3481dc896b6ccbe994df94efcbd3..e7b5d66edc0f4a07c88f618f299e62edd9999922 100644 (file)
@@ -18,6 +18,7 @@ package org.jetbrains.idea.devkit.dom;
 import com.intellij.util.xml.DomElement;
 import com.intellij.util.xml.GenericAttributeValue;
 import com.intellij.util.xml.NameValue;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * @author mike
@@ -29,5 +30,6 @@ public interface Extension extends DomElement {
 
   GenericAttributeValue<String> getOrder();
 
+  @Nullable
   ExtensionPoint getExtensionPoint();
 }
index e235fd9031e8a996bab2d5224eea5acfc5019669..6428d351a5b859cef759d0d246897ea0a62a8700 100644 (file)
@@ -26,6 +26,8 @@ import com.intellij.util.xml.GenericAttributeValue;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.idea.devkit.dom.impl.ExtensionNsConverter;
 
+import java.util.List;
+
 public interface Extensions extends DomElement {
   @NotNull
   @Attribute("defaultExtensionNs")
@@ -35,4 +37,9 @@ public interface Extensions extends DomElement {
   @NotNull
   @Convert(value=ExtensionNsConverter.class, soft=true)
   GenericAttributeValue<IdeaPlugin> getXmlns();
+
+  List<Extension> getExtensions();
+  Extension addExtension();
+
+  Extension addExtension(String name);
 }
index 5681f08402948713874ca88659770525eaf47512..28ff67f6a504116978b5554c13bee951820a75df 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.jetbrains.idea.devkit.dom.impl;
 
+import com.intellij.pom.PomTarget;
 import com.intellij.pom.PomTargetPsiElement;
 import com.intellij.psi.PsiElement;
 import com.intellij.util.xml.DomTarget;
@@ -31,7 +32,8 @@ public abstract class ExtensionImpl implements Extension {
   public ExtensionPoint getExtensionPoint() {
     PsiElement declaration = getChildDescription().getDeclaration(getManager().getProject());
     if (declaration instanceof PomTargetPsiElement) {
-      return (ExtensionPoint)((DomTarget)((PomTargetPsiElement)declaration).getTarget()).getDomElement();
+      PomTarget target = ((PomTargetPsiElement)declaration).getTarget();
+      return target instanceof DomTarget ? (ExtensionPoint)((DomTarget)target).getDomElement() : null;
     }
     return null;
   }
diff --git a/plugins/devkit/src/dom/impl/ExtensionsImpl.java b/plugins/devkit/src/dom/impl/ExtensionsImpl.java
new file mode 100644 (file)
index 0000000..2de0640
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.idea.devkit.dom.impl;
+
+import com.intellij.psi.xml.XmlTag;
+import org.jetbrains.idea.devkit.dom.Extension;
+import org.jetbrains.idea.devkit.dom.Extensions;
+
+/**
+ * @author Dmitry Avdeev
+ *         Date: 1/20/12
+ */
+public abstract class ExtensionsImpl implements Extensions {
+
+  @Override
+  public Extension addExtension(String name) {
+    Extension extension = addExtension();
+    XmlTag tag = extension.getXmlTag();
+    tag.setName(name.substring(getDefaultExtensionNs().getStringValue().length() + 1));
+    return extension;
+  }
+}
diff --git a/plugins/devkit/src/inspections/quickfix/RegisterInspectionFix.java b/plugins/devkit/src/inspections/quickfix/RegisterInspectionFix.java
new file mode 100644 (file)
index 0000000..1edffbc
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.idea.devkit.inspections.quickfix;
+
+import com.intellij.codeInsight.hint.HintManager;
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInspection.InspectionEP;
+import com.intellij.ide.TypePresentationService;
+import com.intellij.openapi.application.Result;
+import com.intellij.openapi.command.WriteCommandAction;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleUtil;
+import com.intellij.openapi.module.impl.ModuleImpl;
+import com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.ui.popup.JBPopupFactory;
+import com.intellij.openapi.ui.popup.PopupStep;
+import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.xml.XmlTag;
+import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.PsiNavigateUtil;
+import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.xml.DomFileElement;
+import com.intellij.util.xml.DomService;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.idea.devkit.DevKitBundle;
+import org.jetbrains.idea.devkit.dom.Extension;
+import org.jetbrains.idea.devkit.dom.Extensions;
+import org.jetbrains.idea.devkit.dom.IdeaPlugin;
+
+import javax.swing.*;
+import java.util.List;
+
+/**
+* @author Dmitry Avdeev
+*         Date: 1/20/12
+*/
+class RegisterInspectionFix implements IntentionAction {
+
+  private final PsiClass myPsiClass;
+  private final ExtensionPointName<? extends InspectionEP> myEp;
+
+  RegisterInspectionFix(PsiClass psiClass, ExtensionPointName<? extends InspectionEP> ep) {
+    myPsiClass = psiClass;
+    myEp = ep;
+  }
+
+  @NotNull
+  @Override
+  public String getText() {
+    return "Register inspection";
+  }
+
+  @NotNull
+  @Override
+  public String getFamilyName() {
+    return DevKitBundle.message("inspections.component.not.registered.quickfix.family");
+  }
+
+  @Override
+  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
+    return true;
+  }
+
+  @Override
+  public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
+    Module module = ModuleUtil.findModuleForPsiElement(file);
+    assert module != null;
+    List<DomFileElement<IdeaPlugin>> elements =
+      DomService.getInstance().getFileElements(IdeaPlugin.class, project, ((ModuleImpl)module).getCachedScope(ModuleWithDependenciesScope.CONTENT | ModuleWithDependenciesScope.MODULES));
+
+    elements = ContainerUtil.filter(elements, new Condition<DomFileElement<IdeaPlugin>>() {
+      @Override
+      public boolean value(DomFileElement<IdeaPlugin> element) {
+        VirtualFile virtualFile = element.getFile().getVirtualFile();
+        return virtualFile != null && ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile);
+      }
+    });
+
+    if (elements.isEmpty()) {
+      HintManager.getInstance().showErrorHint(editor, "Cannot find plugin descriptor");
+      return;
+    }
+
+    if (elements.size() == 1) {
+      doFix(elements.get(0), project, file);
+      return;
+    }
+
+    final BaseListPopupStep<DomFileElement<IdeaPlugin>> popupStep =
+      new BaseListPopupStep<DomFileElement<IdeaPlugin>>("Choose Plugin Descriptor", elements) {
+        @Override
+        public Icon getIconFor(DomFileElement<IdeaPlugin> aValue) {
+          return TypePresentationService.getService().getIcon(aValue);
+        }
+
+        @NotNull
+        @Override
+        public String getTextFor(DomFileElement<IdeaPlugin> value) {
+          return value.getFile().getName();
+        }
+
+        @Override
+        public PopupStep onChosen(DomFileElement<IdeaPlugin> selectedValue, boolean finalChoice) {
+          doFix(selectedValue, project, file);
+          return FINAL_CHOICE;
+        }
+      };
+    JBPopupFactory.getInstance().createListPopup(popupStep)
+      .showInBestPositionFor(editor);
+  }
+
+  private void doFix(DomFileElement<IdeaPlugin> selectedValue, final Project project, final PsiFile file) {
+    final IdeaPlugin plugin = selectedValue.getRootElement();
+    final List<Extensions> extensionsList = plugin.getExtensions();
+    Extension extension = new WriteCommandAction<Extension>(project, file) {
+
+      @Override
+      protected void run(Result<Extension> result) throws Throwable {
+        final Extensions extensions = getExtension(plugin, extensionsList);
+        Extension extension = extensions.addExtension(myEp.getName());
+        XmlTag tag = extension.getXmlTag();
+        tag.setAttribute("implementationClass", myPsiClass.getQualifiedName());
+        result.setResult(extension);
+      }
+    }.execute().throwException().getResultObject();
+    PsiNavigateUtil.navigate(extension.getXmlTag());
+  }
+
+  private Extensions getExtension(IdeaPlugin plugin, List<Extensions> extensionsList) {
+    Extensions extensions = null;
+    for (Extensions e : extensionsList) {
+      String s = e.getDefaultExtensionNs().getStringValue();
+      if (s != null && myEp.getName().startsWith(s)) {
+        extensions = e;
+        break;
+      }
+    }
+    if (extensions == null) {
+      extensions = plugin.addExtensions();
+      extensions.getDefaultExtensionNs().setStringValue("com.intellij");
+    }
+    return extensions;
+  }
+
+  @Override
+  public boolean startInWriteAction() {
+    return false;
+  }
+}
diff --git a/plugins/devkit/src/inspections/quickfix/RegisterInspectionFixProvider.java b/plugins/devkit/src/inspections/quickfix/RegisterInspectionFixProvider.java
new file mode 100644 (file)
index 0000000..c136d27
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.idea.devkit.inspections.quickfix;
+
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInspection.GlobalInspectionTool;
+import com.intellij.codeInspection.InspectionEP;
+import com.intellij.codeInspection.LocalInspectionEP;
+import com.intellij.codeInspection.LocalInspectionTool;
+import com.intellij.codeInspection.reference.UnusedDeclarationFixProvider;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiIdentifier;
+import com.intellij.psi.util.InheritanceUtil;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Dmitry Avdeev
+ *         Date: 1/19/12
+ */
+public class RegisterInspectionFixProvider implements UnusedDeclarationFixProvider {
+
+  @NotNull
+  @Override
+  public IntentionAction[] getQuickFixes(PsiElement element) {
+    if (!(element instanceof PsiIdentifier)) return IntentionAction.EMPTY_ARRAY;
+    PsiElement parent = element.getParent();
+    if (!(parent instanceof PsiClass)) return IntentionAction.EMPTY_ARRAY;
+    if (InheritanceUtil.isInheritor((PsiClass)parent, LocalInspectionTool.class.getName())) {
+      return new IntentionAction[] { new RegisterInspectionFix((PsiClass)parent, LocalInspectionEP.LOCAL_INSPECTION) };
+    }
+    if (InheritanceUtil.isInheritor((PsiClass)parent, GlobalInspectionTool.class.getName())) {
+      return new IntentionAction[] { new RegisterInspectionFix((PsiClass)parent, InspectionEP.GLOBAL_INSPECTION) };
+    }
+    return IntentionAction.EMPTY_ARRAY;
+  }
+}
diff --git a/plugins/devkit/testData/extensions/GlobalInspection.java b/plugins/devkit/testData/extensions/GlobalInspection.java
new file mode 100644 (file)
index 0000000..9fe0a4a
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import com.intellij.codeInspection.GlobalInspectionTool;
+
+public class <warning descr="Class 'GlobalInspection' is never used">Global<caret>Inspection</warning> extends GlobalInspectionTool {
+}
\ No newline at end of file
diff --git a/plugins/devkit/testData/extensions/LocalInspection.java b/plugins/devkit/testData/extensions/LocalInspection.java
new file mode 100644 (file)
index 0000000..a08a6c3
--- /dev/null
@@ -0,0 +1,4 @@
+import com.intellij.codeInspection.LocalInspectionTool;
+
+public class <warning descr="Class 'LocalInspection' is never used">Local<caret>Inspection</warning> extends LocalInspectionTool {
+}
\ No newline at end of file
diff --git a/plugins/devkit/testData/extensions/globalInspection.xml b/plugins/devkit/testData/extensions/globalInspection.xml
new file mode 100644 (file)
index 0000000..9f64986
--- /dev/null
@@ -0,0 +1,6 @@
+<idea-plugin>
+    <extensions defaultExtensionNs="com.intellij">
+        <localInspection implementationClass="LocalInspection"/>
+        <globalInspection implementationClass="GlobalInspection"/>
+    </extensions>
+</idea-plugin>
\ No newline at end of file
diff --git a/plugins/devkit/testData/extensions/localInspection.xml b/plugins/devkit/testData/extensions/localInspection.xml
new file mode 100644 (file)
index 0000000..b14a539
--- /dev/null
@@ -0,0 +1,5 @@
+<idea-plugin>
+    <extensions defaultExtensionNs="com.intellij">
+        <localInspection implementationClass="LocalInspection"/>
+    </extensions>
+</idea-plugin>
\ No newline at end of file
diff --git a/plugins/devkit/testData/extensions/plugin.xml b/plugins/devkit/testData/extensions/plugin.xml
new file mode 100644 (file)
index 0000000..6fb76a6
--- /dev/null
@@ -0,0 +1,2 @@
+<idea-plugin>
+</idea-plugin>
\ No newline at end of file
diff --git a/plugins/devkit/testSources/codeInsight/CreateExtensionTest.java b/plugins/devkit/testSources/codeInsight/CreateExtensionTest.java
new file mode 100644 (file)
index 0000000..41d5b96
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.idea.devkit.codeInsight;
+
+import com.intellij.codeInsight.intention.IntentionAction;
+import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
+import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
+import com.intellij.openapi.application.PluginPathManager;
+import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
+
+/**
+ * @author Dmitry Avdeev
+ *         Date: 1/20/12
+ */
+public class CreateExtensionTest extends JavaCodeInsightFixtureTestCase {
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    myFixture.addClass("package com.intellij.codeInspection; public class LocalInspectionTool {} ");
+    myFixture.addClass("package com.intellij.codeInspection; public class GlobalInspectionTool {} ");
+    myFixture.enableInspections(new UnusedDeclarationInspection(), new UnusedSymbolLocalInspection());
+  }
+
+  public void testCreateLocalInspectionMapping() throws Exception {
+    myFixture.testHighlighting("LocalInspection.java", "plugin.xml");
+    IntentionAction intention = myFixture.findSingleIntention("Register inspection");
+    myFixture.launchAction(intention);
+    myFixture.checkResultByFile("plugin.xml", "localInspection.xml", true);
+  }
+
+  public void testCreateGlobalInspectionMapping() throws Exception {
+    myFixture.testHighlighting("GlobalInspection.java", "localInspection.xml");
+    IntentionAction intention = myFixture.findSingleIntention("Register inspection");
+    myFixture.launchAction(intention);
+    myFixture.checkResultByFile("localInspection.xml", "globalInspection.xml", true);
+  }
+
+  @Override
+  protected String getBasePath() {
+    return PluginPathManager.getPluginHomePathRelative("devkit") + "/testData/extensions";
+  }
+
+}
index 270dff6a41b630073240525564454a25dc0c373e..bec0cf45f755f77d40f0eedd1226edf87c1c4aea 100644 (file)
@@ -62,6 +62,8 @@
 
     <extensionPoint name="deadCode"
                     interface="com.intellij.codeInspection.reference.EntryPoint"/>
+    <extensionPoint name="unusedDeclarationFixProvider"
+                    interface="com.intellij.codeInspection.reference.UnusedDeclarationFixProvider"/>
 
     <!-- PsiMember -->
     <extensionPoint name="javaDocNotNecessary"