コード例 #1
0
  @Override
  public void customizeCellRendererFor(@NotNull SliceUsage sliceUsage) {
    boolean isForcedLeaf = sliceUsage instanceof JavaSliceDereferenceUsage;
    // might come SliceTooComplexDFAUsage
    JavaSliceUsage javaSliceUsage =
        sliceUsage instanceof JavaSliceUsage ? (JavaSliceUsage) sliceUsage : null;

    TextChunk[] text = sliceUsage.getText();
    final List<TextRange> usageRanges = new SmartList<TextRange>();
    sliceUsage.processRangeMarkers(
        new Processor<Segment>() {
          @Override
          public boolean process(Segment segment) {
            usageRanges.add(TextRange.create(segment));
            return true;
          }
        });
    boolean isInsideContainer = javaSliceUsage != null && javaSliceUsage.indexNesting != 0;
    for (int i = 0, length = text.length; i < length; i++) {
      TextChunk textChunk = text[i];
      SimpleTextAttributes attributes = textChunk.getSimpleAttributesIgnoreBackground();
      if (isForcedLeaf) {
        attributes =
            attributes.derive(
                attributes.getStyle(),
                JBColor.LIGHT_GRAY,
                attributes.getBgColor(),
                attributes.getWaveColor());
      }
      boolean inUsage = (attributes.getFontStyle() & Font.BOLD) != 0;
      if (isInsideContainer && inUsage) {
        // Color darker = Color.BLACK;//attributes.getBgColor() == null ? Color.BLACK :
        // attributes.getBgColor().darker();
        // attributes = attributes.derive(SimpleTextAttributes.STYLE_OPAQUE,
        // attributes.getFgColor(), UIUtil.getTreeBackground().brighter(),
        // attributes.getWaveColor());
        // setMyBorder(IdeBorderFactory.createRoundedBorder(10, 3));
        // setPaintFocusBorder(true);
      }
      append(textChunk.getText(), attributes);
      if (i == 0) {
        append(FontUtil.spaceAndThinSpace());
      }
    }

    if (javaSliceUsage != null) {
      for (int i = 0; i < javaSliceUsage.indexNesting; i++) {
        append(
            " (Tracking container contents"
                + (javaSliceUsage.syntheticField.isEmpty()
                    ? ""
                    : " '" + javaSliceUsage.syntheticField + "'")
                + ")",
            SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
      }
    }

    PsiElement element = sliceUsage.getElement();
    PsiMethod method;
    PsiClass aClass;
    while (true) {
      method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
      aClass =
          method == null
              ? PsiTreeUtil.getParentOfType(element, PsiClass.class)
              : method.getContainingClass();
      if (aClass instanceof PsiAnonymousClass) {
        element = aClass;
      } else {
        break;
      }
    }
    int methodOptions =
        PsiFormatUtilBase.SHOW_NAME
            | PsiFormatUtilBase.SHOW_PARAMETERS
            | PsiFormatUtilBase.SHOW_CONTAINING_CLASS;
    String location =
        method != null
            ? PsiFormatUtil.formatMethod(
                method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE, 2)
            : aClass != null
                ? PsiFormatUtil.formatClass(aClass, PsiFormatUtilBase.SHOW_NAME)
                : null;
    if (location != null) {
      SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES;
      append(" in " + location, attributes);
    }
  }