2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.slicer;
18 import com.intellij.openapi.util.Segment;
19 import com.intellij.openapi.util.TextRange;
20 import com.intellij.psi.*;
21 import com.intellij.psi.util.PsiFormatUtil;
22 import com.intellij.psi.util.PsiFormatUtilBase;
23 import com.intellij.psi.util.PsiTreeUtil;
24 import com.intellij.ui.JBColor;
25 import com.intellij.ui.SimpleTextAttributes;
26 import com.intellij.usages.TextChunk;
27 import com.intellij.util.FontUtil;
28 import com.intellij.util.Processor;
29 import com.intellij.util.SmartList;
30 import org.jetbrains.annotations.NotNull;
33 import java.util.List;
38 public class SliceUsageCellRenderer extends SliceUsageCellRendererBase {
41 public void customizeCellRendererFor(@NotNull SliceUsage sliceUsage) {
42 boolean isForcedLeaf = sliceUsage instanceof JavaSliceDereferenceUsage;
43 //might come SliceTooComplexDFAUsage
44 JavaSliceUsage javaSliceUsage = sliceUsage instanceof JavaSliceUsage ? (JavaSliceUsage)sliceUsage : null;
46 TextChunk[] text = sliceUsage.getText();
47 final List<TextRange> usageRanges = new SmartList<TextRange>();
48 sliceUsage.processRangeMarkers(new Processor<Segment>() {
50 public boolean process(Segment segment) {
51 usageRanges.add(TextRange.create(segment));
55 boolean isInsideContainer = javaSliceUsage != null && javaSliceUsage.indexNesting != 0;
56 for (int i = 0, length = text.length; i < length; i++) {
57 TextChunk textChunk = text[i];
58 SimpleTextAttributes attributes = textChunk.getSimpleAttributesIgnoreBackground();
60 attributes = attributes.derive(attributes.getStyle(), JBColor.LIGHT_GRAY, attributes.getBgColor(), attributes.getWaveColor());
62 boolean inUsage = (attributes.getFontStyle() & Font.BOLD) != 0;
63 if (isInsideContainer && inUsage) {
64 //Color darker = Color.BLACK;//attributes.getBgColor() == null ? Color.BLACK : attributes.getBgColor().darker();
65 //attributes = attributes.derive(SimpleTextAttributes.STYLE_OPAQUE, attributes.getFgColor(), UIUtil.getTreeBackground().brighter(), attributes.getWaveColor());
66 //setMyBorder(IdeBorderFactory.createRoundedBorder(10, 3));
67 //setPaintFocusBorder(true);
69 append(textChunk.getText(), attributes);
71 append(FontUtil.spaceAndThinSpace());
75 if (javaSliceUsage != null) {
76 for (int i = 0; i < javaSliceUsage.indexNesting; i++) {
78 " (Tracking container contents" +
79 (javaSliceUsage.syntheticField.isEmpty() ? "" : " '" + javaSliceUsage.syntheticField + "'") +
81 SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
85 PsiElement element = sliceUsage.getElement();
89 method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
90 aClass = method == null ? PsiTreeUtil.getParentOfType(element, PsiClass.class) : method.getContainingClass();
91 if (aClass instanceof PsiAnonymousClass) {
98 int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_CONTAINING_CLASS;
99 String location = method != null
100 ? PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE, 2)
101 : aClass != null ? PsiFormatUtil.formatClass(aClass, PsiFormatUtilBase.SHOW_NAME) : null;
102 if (location != null) {
103 SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES;
104 append(" in " + location, attributes);