コード例 #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
 @Override
 public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
   if (!FileModificationService.getInstance()
       .preparePsiElementForWrite(descriptor.getPsiElement())) return;
   final PsiElement psiElement = descriptor.getPsiElement();
   if (psiElement instanceof PsiInstanceOfExpression) {
     try {
       final PsiExpression compareToNull =
           JavaPsiFacade.getInstance(psiElement.getProject())
               .getElementFactory()
               .createExpressionFromText(
                   ((PsiInstanceOfExpression) psiElement).getOperand().getText() + " != null",
                   psiElement.getParent());
       psiElement.replace(compareToNull);
     } catch (IncorrectOperationException e) {
       LOG.error(e);
     }
   }
 }
コード例 #3
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);
           }
         });
   }
 }