예제 #1
0
  private SliceTreeStructure configureTree(@NonNls final String name) throws Exception {
    configureByFile("/codeInsight/slice/backward/" + name + ".java");
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    PsiElement element = new SliceHandler(true).getExpressionAtCaret(getEditor(), getFile());
    assertNotNull(element);
    Collection<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);

    SliceAnalysisParams params = new SliceAnalysisParams();
    params.scope = new AnalysisScope(getProject());
    params.dataFlowToThis = true;

    SliceUsage usage = SliceUsage.createRootUsage(element, params);

    SlicePanel panel =
        new SlicePanel(
            getProject(),
            true,
            new SliceRootNode(getProject(), new DuplicateMap(), usage),
            false,
            ToolWindowHeadlessManagerImpl.HEADLESS_WINDOW) {
          @Override
          protected void close() {}

          @Override
          public boolean isAutoScroll() {
            return false;
          }

          @Override
          public void setAutoScroll(boolean autoScroll) {}

          @Override
          public boolean isPreview() {
            return false;
          }

          @Override
          public void setPreview(boolean preview) {}
        };
    Disposer.register(getProject(), panel);
    return (SliceTreeStructure) panel.getBuilder().getTreeStructure();
  }
  private static boolean processValuesFlownTo(
      @NotNull final PsiExpression argument,
      PsiElement scope,
      @NotNull final Processor<PsiExpression> processor) {
    SliceAnalysisParams params = new SliceAnalysisParams();
    params.dataFlowToThis = true;
    params.scope = new AnalysisScope(new LocalSearchScope(scope), argument.getProject());

    SliceRootNode rootNode =
        new SliceRootNode(
            scope.getProject(), new DuplicateMap(), SliceManager.createRootUsage(argument, params));

    Collection<? extends AbstractTreeNode> children =
        rootNode.getChildren().iterator().next().getChildren();
    for (AbstractTreeNode child : children) {
      SliceUsage usage = (SliceUsage) child.getValue();
      PsiElement element = usage.getElement();
      if (element instanceof PsiExpression && !processor.process((PsiExpression) element))
        return false;
    }

    return !children.isEmpty();
  }