private ReRunAction() {
   super(
       UsageViewBundle.message("action.rerun"),
       UsageViewBundle.message("action.description.rerun"),
       IconLoader.getIcon("/actions/refreshUsages.png"));
   registerCustomShortcutSet(CommonShortcuts.getRerun(), myRootPanel);
 }
Beispiel #2
0
 public static String getProgressTitle(UsageViewPresentation presentation) {
   final String scopeText = presentation.getScopeText();
   if (scopeText == null) {
     return UsageViewBundle.message(
         "progress.searching.for", StringUtil.capitalize(presentation.getUsagesString()));
   }
   return UsageViewBundle.message(
       "progress.searching.for.in",
       StringUtil.capitalize(presentation.getUsagesString()),
       scopeText);
 }
 @NotNull
 private static String getFullTitle(
     @NotNull List<Usage> usages,
     @NotNull String title,
     boolean hadMoreSeparator,
     int visibleNodesCount,
     boolean findUsagesInProgress) {
   String s;
   if (hadMoreSeparator) {
     s =
         "<b>Some</b> "
             + title
             + " "
             + "<b>(Only "
             + visibleNodesCount
             + " usages shown"
             + (findUsagesInProgress ? " so far" : "")
             + ")</b>";
   } else {
     s =
         title
             + " ("
             + UsageViewBundle.message("usages.n", usages.size())
             + (findUsagesInProgress ? " so far" : "")
             + ")";
   }
   return "<html><nobr>" + s + "</nobr></html>";
 }
  @Override
  @NotNull
  public String getPlainText() {
    int startOffset = getNavigationOffset();
    final PsiElement element = getElement();
    if (element != null && startOffset != -1) {
      final Document document = getDocument();
      if (document != null) {
        int lineNumber = document.getLineNumber(startOffset);
        int lineStart = document.getLineStartOffset(lineNumber);
        int lineEnd = document.getLineEndOffset(lineNumber);
        String prefixSuffix = null;

        if (lineEnd - lineStart > ChunkExtractor.MAX_LINE_LENGTH_TO_SHOW) {
          prefixSuffix = "...";
          lineStart =
              Math.max(
                  startOffset - ChunkExtractor.OFFSET_BEFORE_TO_SHOW_WHEN_LONG_LINE, lineStart);
          lineEnd =
              Math.min(startOffset + ChunkExtractor.OFFSET_AFTER_TO_SHOW_WHEN_LONG_LINE, lineEnd);
        }
        String s = document.getCharsSequence().subSequence(lineStart, lineEnd).toString();
        if (prefixSuffix != null) s = prefixSuffix + s + prefixSuffix;
        return s;
      }
    }
    return UsageViewBundle.message("node.invalid");
  }
 private MergeDupLines() {
   super(
       UsageViewImpl.this,
       UsageViewBundle.message("action.merge.same.line"),
       IconLoader.getIcon("/toolbar/filterdups.png"));
   setShortcutSet(
       new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK)));
 }
    @Override
    public void run() {
      if (!checkReadonlyUsages()) return;
      PsiDocumentManager.getInstance(myProject).commitAllDocuments();
      if (myCannotMakeString != null && myChangesDetected) {
        String title = UsageViewBundle.message("changes.detected.error.title");
        if (canPerformReRun() && allTargetsAreValid()) {
          String[] options = {
            UsageViewBundle.message("action.description.rerun"),
            UsageViewBundle.message("usage.view.cancel.button")
          };
          String message =
              myCannotMakeString + "\n\n" + UsageViewBundle.message("dialog.rerun.search");
          int answer =
              Messages.showOkCancelDialog(
                  myProject, message, title, options[0], options[1], Messages.getErrorIcon());
          if (answer == 0) {
            refreshUsages();
          }
        } else {
          Messages.showMessageDialog(myProject, myCannotMakeString, title, Messages.getErrorIcon());
          // todo[myakovlev] request focus to tree
          // myUsageView.getTree().requestFocus();
        }
        return;
      }

      close();

      CommandProcessor.getInstance()
          .executeCommand(
              myProject,
              new Runnable() {
                @Override
                public void run() {
                  myProcessRunnable.run();
                }
              },
              myCommandName,
              null);
    }
Beispiel #7
0
 public static String getPackageName(PsiDirectory directory, boolean includeRootDir) {
   PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
   if (aPackage == null) {
     return directory.getVirtualFile().getPresentableUrl();
   } else {
     String packageName = getPackageName(aPackage);
     if (includeRootDir) {
       String rootDir = getRootDirectoryForPackage(directory);
       if (rootDir != null) {
         return UsageViewBundle.message("usage.target.package.in.directory", packageName, rootDir);
       }
     }
     return packageName;
   }
 }
 @NotNull
 private static List<UsageNode> collectData(
     @NotNull List<Usage> usages,
     @NotNull Collection<UsageNode> visibleNodes,
     @NotNull UsageViewImpl usageView,
     @NotNull UsageViewPresentation presentation) {
   @NotNull List<UsageNode> data = new ArrayList<UsageNode>();
   int filtered = filtered(usages, usageView);
   if (filtered != 0) {
     data.add(createStringNode(UsageViewBundle.message("usages.were.filtered.out", filtered)));
   }
   data.addAll(visibleNodes);
   if (data.isEmpty()) {
     String progressText = UsageViewManagerImpl.getProgressTitle(presentation);
     data.add(createStringNode(progressText));
   }
   Collections.sort(data, USAGE_NODE_COMPARATOR);
   return data;
 }
 @Override
 public void customizeCellRenderer(
     @NotNull SliceUsageCellRenderer renderer,
     @NotNull JTree tree,
     Object value,
     boolean selected,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   renderer.setIcon(getPresentation().getIcon(expanded));
   if (isValid()) {
     SliceUsage sliceUsage = getValue();
     renderer.customizeCellRendererFor(sliceUsage);
     renderer.setToolTipText(sliceUsage.getPresentation().getTooltipText());
   } else {
     renderer.append(
         UsageViewBundle.message("node.invalid") + " ",
         SliceUsageCellRenderer.ourInvalidAttributes);
   }
 }
  @NotNull
  private ActionToolbar createToolbar() {
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    actionGroup.add(new MyRefreshAction(myTree));
    if (isToShowAutoScrollButton()) {
      actionGroup.add(myAutoScrollToSourceHandler.createToggleAction());
    }
    if (isToShowCloseButton()) {
      actionGroup.add(new CloseAction());
    }
    if (isToShowPreviewButton()) {
      actionGroup.add(
          new ToggleAction(
              UsageViewBundle.message("preview.usages.action.text"),
              "preview",
              AllIcons.Actions.PreviewDetails) {
            @Override
            public boolean isSelected(AnActionEvent e) {
              return isPreview();
            }

            @Override
            public void setSelected(AnActionEvent e, boolean state) {
              setPreview(state);
              layoutPanel();
            }
          });
    }

    if (myBuilder.dataFlowToThis) {
      actionGroup.add(new GroupByLeavesAction(myBuilder));
      actionGroup.add(new CanItBeNullAction(myBuilder));
    }

    // actionGroup.add(new ContextHelpAction(HELP_ID));

    return ActionManager.getInstance()
        .createActionToolbar(ActionPlaces.TYPE_HIERARCHY_VIEW_TOOLBAR, actionGroup, false);
  }
 public void customizeCellRenderer(
     JTree tree,
     Object value,
     boolean selected,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   PackageDependenciesNode node = (PackageDependenciesNode) value;
   if (node.isValid()) {
     setIcon(node.getIcon());
   } else {
     append(
         UsageViewBundle.message("node.invalid") + " ", SimpleTextAttributes.ERROR_ATTRIBUTES);
   }
   append(
       node.toString(),
       node.hasMarked() && !selected
           ? SimpleTextAttributes.ERROR_ATTRIBUTES
           : SimpleTextAttributes.REGULAR_ATTRIBUTES);
   append(node.getPresentableFilesCount(), SimpleTextAttributes.GRAYED_ATTRIBUTES);
 }
Beispiel #12
0
/** @author ven */
public class JavaFindUsagesProvider implements FindUsagesProvider {
  public static final String DEFAULT_PACKAGE_NAME =
      UsageViewBundle.message("default.package.presentable.name");

  @Override
  public boolean canFindUsagesFor(@NotNull PsiElement element) {
    if (element instanceof PsiDirectory) {
      PsiPackage psiPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
      return psiPackage != null && psiPackage.getQualifiedName().length() != 0;
    }

    return element instanceof PsiClass
        || element instanceof PsiVariable
        || element instanceof PsiMethod
        || element instanceof PsiPackage
        || element instanceof PsiJavaModule
        || element instanceof PsiLabeledStatement
        || ThrowSearchUtil.isSearchable(element)
        || element instanceof PsiMetaOwner && ((PsiMetaOwner) element).getMetaData() != null;
  }

  @Override
  public String getHelpId(@NotNull PsiElement element) {
    if (element instanceof PsiPackage) {
      return HelpID.FIND_PACKAGE_USAGES;
    }
    if (element instanceof PsiClass) {
      return HelpID.FIND_CLASS_USAGES;
    }
    if (element instanceof PsiMethod) {
      return HelpID.FIND_METHOD_USAGES;
    }
    if (ThrowSearchUtil.isSearchable(element)) {
      return HelpID.FIND_THROW_USAGES;
    }
    return com.intellij.lang.HelpID.FIND_OTHER_USAGES;
  }

  @Override
  @NotNull
  public String getType(@NotNull PsiElement element) {
    if (element instanceof PsiDirectory) {
      return LangBundle.message("terms.directory");
    }
    if (element instanceof PsiFile) {
      return LangBundle.message("terms.file");
    }
    if (ThrowSearchUtil.isSearchable(element)) {
      return LangBundle.message("java.terms.exception");
    }
    if (element instanceof PsiPackage) {
      return LangBundle.message("java.terms.package");
    }
    if (element instanceof PsiLabeledStatement) {
      return LangBundle.message("java.terms.label");
    }
    if (element instanceof PsiClass) {
      if (((PsiClass) element).isAnnotationType()) {
        return LangBundle.message("java.terms.annotation.interface");
      }
      if (((PsiClass) element).isEnum()) {
        return LangBundle.message("java.terms.enum");
      }
      if (((PsiClass) element).isInterface()) {
        return LangBundle.message("java.terms.interface");
      }
      if (element instanceof PsiTypeParameter) {
        return LangBundle.message("java.terms.type.parameter");
      }
      return LangBundle.message("java.terms.class");
    }
    if (element instanceof PsiField) {
      return LangBundle.message("java.terms.field");
    }
    if (element instanceof PsiParameter) {
      return LangBundle.message("java.terms.parameter");
    }
    if (element instanceof PsiLocalVariable) {
      return LangBundle.message("java.terms.variable");
    }
    if (element instanceof PsiMethod) {
      final PsiMethod psiMethod = (PsiMethod) element;
      final boolean isConstructor = psiMethod.isConstructor();
      if (isConstructor) {
        return LangBundle.message("java.terms.constructor");
      }
      return LangBundle.message("java.terms.method");
    }
    if (element instanceof PsiExpression) {
      return LangBundle.message("java.terms.expression");
    }
    if (element instanceof PsiJavaModule) {
      return LangBundle.message("java.terms.module");
    }

    final String name =
        TypePresentationService.getService().getTypePresentableName(element.getClass());
    if (name != null) {
      return name;
    }
    return "";
  }

  @Override
  @NotNull
  public String getDescriptiveName(@NotNull final PsiElement element) {
    if (ThrowSearchUtil.isSearchable(element)) {
      return ThrowSearchUtil.getSearchableTypeName(element);
    }
    if (element instanceof PsiDirectory) {
      return getPackageName((PsiDirectory) element, false);
    }
    if (element instanceof PsiPackage) {
      return getPackageName((PsiPackage) element);
    }
    if (element instanceof PsiFile) {
      return ((PsiFile) element).getVirtualFile().getPresentableUrl();
    }
    if (element instanceof PsiLabeledStatement) {
      return ((PsiLabeledStatement) element).getLabelIdentifier().getText();
    }
    if (element instanceof PsiClass) {
      if (element instanceof PsiAnonymousClass) {
        String name = ((PsiAnonymousClass) element).getBaseClassReference().getReferenceName();
        return "anonymous " + StringUtil.notNullize(name, "class");
      } else {
        PsiClass aClass = (PsiClass) element;
        String qName = aClass.getQualifiedName();
        return qName != null ? qName : aClass.getName() != null ? aClass.getName() : "<unknown>";
      }
    }
    if (element instanceof PsiMethod) {
      PsiMethod psiMethod = (PsiMethod) element;
      String formatted =
          PsiFormatUtil.formatMethod(
              psiMethod,
              PsiSubstitutor.EMPTY,
              PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS,
              PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_RAW_NON_TOP_TYPE);
      PsiClass psiClass = psiMethod.getContainingClass();
      if (psiClass != null) {
        return getContainingClassDescription(psiClass, formatted);
      }

      return formatted;
    }
    if (element instanceof PsiField) {
      PsiField psiField = (PsiField) element;
      String formatted =
          PsiFormatUtil.formatVariable(psiField, PsiFormatUtilBase.SHOW_NAME, PsiSubstitutor.EMPTY);
      PsiClass psiClass = psiField.getContainingClass();
      if (psiClass != null) {
        return getContainingClassDescription(psiClass, formatted);
      }

      return formatted;
    }
    if (element instanceof PsiVariable) {
      return PsiFormatUtil.formatVariable(
          (PsiVariable) element, PsiFormatUtilBase.SHOW_NAME, PsiSubstitutor.EMPTY);
    }
    if (element instanceof PsiLiteralExpression) {
      return element.getText();
    }
    if (element instanceof PsiJavaModule) {
      return ((PsiJavaModule) element).getModuleName();
    }

    return "";
  }

  private static String getContainingClassDescription(PsiClass aClass, String formatted) {
    if (aClass instanceof PsiAnonymousClass) {
      return LangBundle.message("java.terms.of.anonymous.class", formatted);
    } else {
      final String qualifiedName = aClass.getQualifiedName();
      final String className = qualifiedName != null ? qualifiedName : aClass.getName();
      if (aClass.isInterface()) {
        return LangBundle.message("java.terms.of.interface", formatted, className);
      }
      if (aClass.isEnum()) {
        return LangBundle.message("java.terms.of.enum", formatted, className);
      }
      if (aClass.isAnnotationType()) {
        return LangBundle.message("java.terms.of.annotation.type", formatted, className);
      }
      return LangBundle.message("java.terms.of.class", formatted, className);
    }
  }

  @Override
  @NotNull
  public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
    if (element instanceof PsiDirectory) {
      return getPackageName((PsiDirectory) element, false);
    }

    if (element instanceof PsiPackage) {
      return getPackageName((PsiPackage) element);
    }

    if (element instanceof PsiFile) {
      return useFullName
          ? ((PsiFile) element).getVirtualFile().getPresentableUrl()
          : ((PsiFile) element).getName();
    }

    if (element instanceof PsiLabeledStatement) {
      return ((PsiLabeledStatement) element).getLabelIdentifier().getText();
    }

    if (ThrowSearchUtil.isSearchable(element)) {
      return ThrowSearchUtil.getSearchableTypeName(element);
    }

    if (element instanceof PsiClass) {
      String name = ((PsiClass) element).getQualifiedName();
      if (name == null || !useFullName) {
        name = ((PsiClass) element).getName();
      }
      if (name != null) return name;
    }

    if (element instanceof PsiMethod) {
      PsiMethod psiMethod = (PsiMethod) element;
      if (useFullName) {
        int options =
            PsiFormatUtilBase.TYPE_AFTER
                | PsiFormatUtilBase.SHOW_TYPE
                | PsiFormatUtilBase.SHOW_NAME
                | PsiFormatUtilBase.SHOW_PARAMETERS;
        String s =
            PsiFormatUtil.formatMethod(
                (PsiMethod) element,
                PsiSubstitutor.EMPTY,
                options,
                PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME);
        return appendClassName(s, psiMethod.getContainingClass());
      } else {
        int options = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
        return PsiFormatUtil.formatMethod(
            psiMethod, PsiSubstitutor.EMPTY, options, PsiFormatUtilBase.SHOW_TYPE);
      }
    }

    if (element instanceof PsiParameter
        && ((PsiParameter) element).getDeclarationScope() instanceof PsiMethod) {
      PsiMethod method = (PsiMethod) ((PsiParameter) element).getDeclarationScope();
      int varOptions =
          PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
      int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS;
      String s =
          LangBundle.message(
              "java.terms.variable.of.method",
              PsiFormatUtil.formatVariable((PsiVariable) element, varOptions, PsiSubstitutor.EMPTY),
              PsiFormatUtil.formatMethod(
                  method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE));
      return appendClassName(s, method.getContainingClass());
    }

    if (element instanceof PsiField) {
      PsiField psiField = (PsiField) element;
      int options =
          PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
      String s = PsiFormatUtil.formatVariable(psiField, options, PsiSubstitutor.EMPTY);
      return appendClassName(s, psiField.getContainingClass());
    }

    if (element instanceof PsiVariable) {
      int options =
          PsiFormatUtilBase.TYPE_AFTER | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_NAME;
      return PsiFormatUtil.formatVariable((PsiVariable) element, options, PsiSubstitutor.EMPTY);
    }

    return "";
  }

  private static String appendClassName(String s, PsiClass psiClass) {
    if (psiClass != null) {
      String qName = psiClass.getQualifiedName();
      if (qName != null) {
        s =
            LangBundle.message(
                psiClass.isInterface() ? "java.terms.of.interface" : "java.terms.of.class",
                s,
                qName);
      }
    }
    return s;
  }

  public static String getPackageName(PsiDirectory directory, boolean includeRootDir) {
    PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
    if (aPackage == null) {
      return directory.getVirtualFile().getPresentableUrl();
    } else {
      String packageName = getPackageName(aPackage);
      if (includeRootDir) {
        String rootDir = getRootDirectoryForPackage(directory);
        if (rootDir != null) {
          return UsageViewBundle.message("usage.target.package.in.directory", packageName, rootDir);
        }
      }
      return packageName;
    }
  }

  public static String getRootDirectoryForPackage(PsiDirectory directory) {
    PsiManager manager = directory.getManager();
    final VirtualFile virtualFile = directory.getVirtualFile();
    final ProjectFileIndex fileIndex =
        ProjectRootManager.getInstance(manager.getProject()).getFileIndex();
    VirtualFile root = fileIndex.getSourceRootForFile(virtualFile);

    if (root == null) {
      root = fileIndex.getClassRootForFile(virtualFile);
    }
    if (root != null) {
      return root.getPresentableUrl();
    }
    return null;
  }

  public static String getPackageName(PsiPackage psiPackage) {
    if (psiPackage == null) {
      return null;
    }
    String name = psiPackage.getQualifiedName();
    if (name.length() > 0) {
      return name;
    }
    return DEFAULT_PACKAGE_NAME;
  }

  @Override
  public WordsScanner getWordsScanner() {
    return null;
  }
}
 @Override
 public String getCommentReferencesText(int usagesCount, int filesCount) {
   return RefactoringBundle.message(
       "comments.elements.header", UsageViewBundle.getOccurencesString(usagesCount, filesCount));
 }
 @Override
 public String getCodeReferencesText(int usagesCount, int filesCount) {
   return RefactoringBundle.message(
       "references.to.be.changed", UsageViewBundle.getReferencesString(usagesCount, filesCount));
 }
Beispiel #15
0
 @Override
 public String getPreviousOccurenceActionName() {
   return UsageViewBundle.message("action.previous.occurrence");
 }
Beispiel #16
0
 @Override
 public String getNextOccurenceActionName() {
   return UsageViewBundle.message("action.next.occurrence");
 }