Ejemplo n.º 1
0
  @RequiredReadAction
  @Override
  public void compose(StringBuffer buf, RefEntity refElement, CommonProblemDescriptor descriptor) {
    CommonProblemDescriptor[] descriptions = myTool.getDescriptions(refElement);

    int problemIdx = 0;
    if (descriptions != null) { // server-side inspections
      problemIdx = -1;
      for (int i = 0; i < descriptions.length; i++) {
        CommonProblemDescriptor description = descriptions[i];
        if (description == descriptor) {
          problemIdx = i;
          break;
        }
      }
      if (problemIdx == -1) return;
    }

    genPageHeader(buf, refElement);
    appendHeading(buf, InspectionsBundle.message("inspection.problem.synopsis"));
    //noinspection HardCodedStringLiteral
    buf.append("<br>");
    appendAfterHeaderIndention(buf);

    composeDescription(descriptor, problemIdx, buf, refElement);

    if (refElement instanceof RefElement && !refElement.isValid()) return;

    final QuickFix[] fixes = descriptor.getFixes();
    if (fixes != null && fixes.length > 0) {
      //noinspection HardCodedStringLiteral
      buf.append("<br><br>");
      appendHeading(buf, InspectionsBundle.message("inspection.problem.resolution"));
      //noinspection HardCodedStringLiteral
      buf.append("<br>");
      appendAfterHeaderIndention(buf);

      int idx = 0;
      for (QuickFix fix : fixes) {
        //noinspection HardCodedStringLiteral
        //noinspection HardCodedStringLiteral
        buf.append("<a HREF=\"file://bred.txt#invokelocal:").append(idx++);
        buf.append("\">");
        buf.append(fix.getName());
        //noinspection HardCodedStringLiteral
        buf.append("</a>");
        //noinspection HardCodedStringLiteral
        buf.append("<br>");
        appendAfterHeaderIndention(buf);
      }
    }
  }
 public QuickFixAction[] extractActiveFixes(
     final RefEntity[] refElements, final Map<RefEntity, Set<QuickFix>> actions) {
   if (refElements == null) return null;
   Map<Class, QuickFixAction> result = new java.util.HashMap<Class, QuickFixAction>();
   for (RefEntity refElement : refElements) {
     final Set<QuickFix> localQuickFixes = actions.get(refElement);
     if (localQuickFixes != null) {
       for (QuickFix fix : localQuickFixes) {
         if (fix == null) continue;
         final Class klass =
             fix instanceof IntentionWrapper
                 ? ((IntentionWrapper) fix).getAction().getClass()
                 : fix.getClass();
         final QuickFixAction quickFixAction = result.get(klass);
         if (quickFixAction != null) {
           try {
             String familyName = fix.getFamilyName();
             familyName =
                 familyName != null && familyName.length() > 0
                     ? "\'" + 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, this);
           result.put(klass, quickFixWrapper);
         }
       }
     }
   }
   return result.values().isEmpty()
       ? null
       : result.values().toArray(new QuickFixAction[result.size()]);
 }
 @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()]);
 }
Ejemplo n.º 4
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);
 }