コード例 #1
0
 public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
   final PsiDocTag myTag =
       PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiDocTag.class);
   if (myTag == null) return;
   if (!CodeInsightUtilBase.preparePsiElementForWrite(myTag)) return;
   myTag.delete();
 }
コード例 #2
0
 public void applyFix(
     @NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
   final PsiElement element =
       PsiTreeUtil.getParentOfType(
           descriptor.getPsiElement(), PsiJavaCodeReferenceElement.class);
   if (element instanceof PsiJavaCodeReferenceElement) {
     final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement) element;
     Collections.sort(
         myClassesToImport, new PsiProximityComparator(referenceElement.getElement()));
     final JList list =
         new JBList(myClassesToImport.toArray(new PsiClass[myClassesToImport.size()]));
     list.setCellRenderer(new FQNameCellRenderer());
     final Runnable runnable =
         new Runnable() {
           public void run() {
             if (!element.isValid()) return;
             final int index = list.getSelectedIndex();
             if (index < 0) return;
             new WriteCommandAction(project, element.getContainingFile()) {
               protected void run(final Result result) throws Throwable {
                 final PsiClass psiClass = myClassesToImport.get(index);
                 if (psiClass.isValid()) {
                   PsiDocumentManager.getInstance(project).commitAllDocuments();
                   referenceElement.bindToElement(psiClass);
                 }
               }
             }.execute();
           }
         };
     final AsyncResult<DataContext> asyncResult =
         DataManager.getInstance().getDataContextFromFocus();
     asyncResult.doWhenDone(
         new AsyncResult.Handler<DataContext>() {
           @Override
           public void run(DataContext dataContext) {
             final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
             assert editor != null; // available for on the fly mode only
             new PopupChooserBuilder(list)
                 .setTitle(QuickFixBundle.message("class.to.import.chooser.title"))
                 .setItemChoosenCallback(runnable)
                 .createPopup()
                 .showInBestPositionFor(editor);
           }
         });
   }
 }