@Override
 @Nullable
 public QuickFixAction[] extractActiveFixes(
     @NotNull RefEntity[] refElements, @NotNull Map<RefEntity, Set<QuickFix>> actions) {
   Map<Class, QuickFixAction> result =
       new com.intellij.util.containers.HashMap<Class, QuickFixAction>();
   for (RefEntity refElement : refElements) {
     final Set<QuickFix> localQuickFixes = actions.get(refElement);
     if (localQuickFixes == null) continue;
     for (QuickFix fix : localQuickFixes) {
       if (fix == null) continue;
       final Class klass =
           fix instanceof ActionClassHolder
               ? ((ActionClassHolder) fix).getActionClass()
               : fix.getClass();
       final QuickFixAction quickFixAction = result.get(klass);
       if (quickFixAction != null) {
         try {
           String familyName = fix.getFamilyName();
           familyName = !familyName.isEmpty() ? "\'" + familyName + "\'" : familyName;
           ((LocalQuickFixWrapper) quickFixAction)
               .setText(
                   InspectionsBundle.message(
                       "inspection.descriptor.provider.apply.fix", familyName));
         } catch (AbstractMethodError e) {
           // for plugin compatibility
           ((LocalQuickFixWrapper) quickFixAction)
               .setText(InspectionsBundle.message("inspection.descriptor.provider.apply.fix", ""));
         }
       } else {
         LocalQuickFixWrapper quickFixWrapper = new LocalQuickFixWrapper(fix, myToolWrapper);
         result.put(klass, quickFixWrapper);
       }
     }
   }
   return result.values().isEmpty()
       ? null
       : result.values().toArray(new QuickFixAction[result.size()]);
 }
コード例 #2
0
 private void performFix(
     final RefEntity element,
     final CommonProblemDescriptor descriptor,
     final int idx,
     final QuickFix fix) {
   final Runnable command =
       new Runnable() {
         @Override
         public void run() {
           ApplicationManager.getApplication()
               .runWriteAction(
                   new Runnable() {
                     @Override
                     public void run() {
                       final PsiModificationTracker tracker =
                           PsiManager.getInstance(myView.getProject()).getModificationTracker();
                       final long startCount = tracker.getModificationCount();
                       CommandProcessor.getInstance()
                           .markCurrentCommandAsGlobal(myView.getProject());
                       // CCE here means QuickFix was incorrectly inherited
                       fix.applyFix(myView.getProject(), descriptor);
                       if (startCount != tracker.getModificationCount()) {
                         final DescriptorProviderInspection tool =
                             ((DescriptorProviderInspection) myView.getTree().getSelectedTool());
                         if (tool != null) {
                           tool.ignoreProblem(element, descriptor, idx);
                         }
                         myView.updateView(false);
                       }
                     }
                   });
         }
       };
   CommandProcessor.getInstance()
       .executeCommand(myView.getProject(), command, fix.getName(), null);
 }