@Override
 protected boolean findAdditionalMembers(final Set<UsageInfo> toMakeStatic) {
   if (!toMakeStatic.isEmpty()) {
     myAdditionalMethods = new ArrayList<PsiMethod>();
     if (ApplicationManager.getApplication().isUnitTestMode()) {
       for (UsageInfo usageInfo : toMakeStatic) {
         myAdditionalMethods.add((PsiMethod) usageInfo.getElement());
       }
     } else {
       final JavaCallerChooser chooser =
           new MakeStaticJavaCallerChooser(
               myMember, myProject, methods -> myAdditionalMethods.addAll(methods)) {
             @Override
             protected ArrayList<UsageInfo> getTopLevelItems() {
               return new ArrayList<UsageInfo>(toMakeStatic);
             }
           };
       TreeUtil.expand(chooser.getTree(), 2);
       if (!chooser.showAndGet()) {
         return false;
       }
     }
   }
   return true;
 }
예제 #2
0
파일: TreeUtil.java 프로젝트: jexp/idea2
 private static void expand(JTree tree, TreePath path, int levels) {
   if (levels == 0) return;
   tree.expandPath(path);
   TreeNode node = (TreeNode) path.getLastPathComponent();
   Enumeration children = node.children();
   while (children.hasMoreElements()) {
     expand(tree, path.pathByAddingChild(children.nextElement()), levels - 1);
   }
 }
 public void restoreState() {
   myStructureViewState = myFileEditor.getUserData(STRUCTURE_VIEW_STATE_KEY);
   if (myStructureViewState == null) {
     TreeUtil.expand(getTree(), 2);
   } else {
     expandStoredElements();
     selectStoredElements();
     myFileEditor.putUserData(STRUCTURE_VIEW_STATE_KEY, null);
     myStructureViewState = null;
   }
 }
  void reset() {
    ToolsGroup[] groups = ToolManager.getInstance().getGroups();

    for (ToolsGroup group : groups) {
      insertNewGroup((ToolsGroup) group.copy());
    }

    if ((getTreeRoot()).getChildCount() > 0) {
      myTree.setSelectionInterval(0, 0);
    } else {
      myTree.getSelectionModel().clearSelection();
    }
    (getModel()).nodeStructureChanged(null);

    TreeUtil.expand(myTree, 5);

    myIsModified = false;

    update();
  }
예제 #5
0
  public JsonTreeTableView(TreeNode rootNode, ColumnInfo[] columnInfos) {
    super(new ListTreeTableModelOnColumns(rootNode, columnInfos));
    this.columns = columnInfos;

    final TreeTableTree tree = getTree();

    tree.setShowsRootHandles(true);
    tree.setRootVisible(false);
    UIUtil.setLineStyleAngled(tree);
    setTreeCellRenderer(new KeyCellRenderer());

    TreeUtil.expand(tree, 2);

    new TreeTableSpeedSearch(
        this,
        new Convertor<TreePath, String>() {
          @Override
          public String convert(final TreePath path) {
            final NoSqlTreeNode node = (NoSqlTreeNode) path.getLastPathComponent();
            NodeDescriptor descriptor = node.getDescriptor();
            return descriptor.getFormattedKey();
          }
        });
  }
 public void setActionActive(String name, boolean state) {
   StructureViewFactoryEx.getInstanceEx(myProject).setActiveAction(name, state);
   rebuild();
   TreeUtil.expand(getTree(), 2);
 }
  @Nullable
  public UsageInfo[] preprocessUsages(final Project project, final UsageInfo[] usages) {
    final ArrayList<UsageInfo> result = new ArrayList<>();
    final ArrayList<UsageInfo> overridingMethods = new ArrayList<>();
    final ArrayList<SafeDeleteParameterCallHierarchyUsageInfo> delegatingParams = new ArrayList<>();
    final ArrayList<SafeDeleteMethodCalleeUsageInfo> calleesSafeToDelete = new ArrayList<>();
    for (UsageInfo usage : usages) {
      if (usage.isNonCodeUsage) {
        result.add(usage);
      } else if (usage instanceof SafeDeleteMethodCalleeUsageInfo) {
        calleesSafeToDelete.add((SafeDeleteMethodCalleeUsageInfo) usage);
      } else if (usage instanceof SafeDeleteOverridingMethodUsageInfo) {
        overridingMethods.add(usage);
      } else if (usage instanceof SafeDeleteParameterCallHierarchyUsageInfo) {
        delegatingParams.add((SafeDeleteParameterCallHierarchyUsageInfo) usage);
      } else if (usage instanceof SafeDeleteAnnotation) {
        result.add(
            new SafeDeleteAnnotation(
                (PsiAnnotation) usage.getElement(),
                ((SafeDeleteAnnotation) usage).getReferencedElement(),
                true));
      } else {
        result.add(usage);
      }
    }

    if (!overridingMethods.isEmpty()) {
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        result.addAll(overridingMethods);
      } else {
        OverridingMethodsDialog dialog = new OverridingMethodsDialog(project, overridingMethods);
        if (!dialog.showAndGet()) {
          return null;
        }
        final ArrayList<UsageInfo> selected = dialog.getSelected();
        final Set<UsageInfo> unselected = new HashSet<>(overridingMethods);
        unselected.removeAll(selected);

        if (!unselected.isEmpty()) {
          final List<PsiMethod> unselectedMethods =
              ContainerUtil.map(
                  unselected,
                  info -> ((SafeDeleteOverridingMethodUsageInfo) info).getOverridingMethod());

          for (Iterator<UsageInfo> iterator = result.iterator(); iterator.hasNext(); ) {
            final UsageInfo info = iterator.next();
            if (info instanceof SafeDeleteOverrideAnnotation
                && !allSuperMethodsSelectedToDelete(
                    unselectedMethods, ((SafeDeleteOverrideAnnotation) info).getMethod())) {
              iterator.remove();
            }
          }
        }

        result.addAll(selected);
      }
    }

    if (!delegatingParams.isEmpty()) {
      final SafeDeleteParameterCallHierarchyUsageInfo parameterHierarchyUsageInfo =
          delegatingParams.get(0);
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        result.addAll(delegatingParams);
      } else {
        final PsiMethod method = parameterHierarchyUsageInfo.getCalledMethod();
        final PsiParameter parameter = parameterHierarchyUsageInfo.getReferencedElement();
        final int parameterIndex = method.getParameterList().getParameterIndex(parameter);
        final JavaCallerChooser chooser =
            new SafeDeleteJavaCallerChooser(method, project, result) {
              @Override
              protected ArrayList<SafeDeleteParameterCallHierarchyUsageInfo> getTopLevelItems() {
                return delegatingParams;
              }

              @Override
              protected int getParameterIdx() {
                return parameterIndex;
              }
            };
        TreeUtil.expand(chooser.getTree(), 2);
        if (!chooser.showAndGet()) {
          return null;
        }
      }
    }

    if (!calleesSafeToDelete.isEmpty()) {
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        result.addAll(calleesSafeToDelete);
      } else {
        final PsiMethod method = calleesSafeToDelete.get(0).getCallerMethod();
        final ArrayList<UsageInfo> list = new ArrayList<>();
        JavaCallerChooser chooser =
            new SafeDeleteJavaCalleeChooser(method, project, list) {
              @Override
              protected ArrayList<SafeDeleteMethodCalleeUsageInfo> getTopLevelItems() {
                return calleesSafeToDelete;
              }
            };
        TreeUtil.expand(chooser.getTree(), 2);
        if (!chooser.showAndGet()) {
          return null;
        }
        result.addAll(list);
        final List<PsiElement> methodsToDelete = new ArrayList<>();
        for (UsageInfo info : list) {
          methodsToDelete.add(info.getElement());
        }
        methodsToDelete.add(method);
        final Condition<PsiElement> insideDeletedCondition =
            getUsageInsideDeletedFilter(
                methodsToDelete.toArray(new PsiElement[methodsToDelete.size()]));
        for (UsageInfo info : list) {
          SafeDeleteProcessor.addNonCodeUsages(
              info.getElement(),
              result,
              insideDeletedCondition,
              JavaRefactoringSettings.getInstance().RENAME_SEARCH_FOR_TEXT_FOR_METHOD,
              JavaRefactoringSettings.getInstance().RENAME_SEARCH_IN_COMMENTS_FOR_METHOD);
        }
      }
    }

    return result.toArray(new UsageInfo[result.size()]);
  }
예제 #8
0
파일: TreeUtil.java 프로젝트: jexp/idea2
 /**
  * Expands n levels of the tree counting from the root
  *
  * @param tree to expand nodes of
  * @param levels depths of the expantion
  */
 public static void expand(JTree tree, int levels) {
   expand(tree, new TreePath(tree.getModel().getRoot()), levels);
 }
 private void collapseAll() {
   TreeUtil.collapseAll(myTree, 3);
   TreeUtil.expand(myTree, 2);
 }