2 * Copyright 2000-2013 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.SimpleTextAttributes;
25 import com.intellij.usages.TextChunk;
26 import com.intellij.util.FontUtil;
27 import com.intellij.util.Processor;
28 import com.intellij.util.SmartList;
29 import org.jetbrains.annotations.NotNull;
32 import java.util.List;
37 public class SliceUsageCellRenderer extends SliceUsageCellRendererBase {
40 public void customizeCellRendererFor(@NotNull SliceUsage sliceUsage) {
41 boolean isForcedLeaf = sliceUsage instanceof JavaSliceDereferenceUsage;
42 //might come SliceTooComplexDFAUsage
43 JavaSliceUsage javaSliceUsage = sliceUsage instanceof JavaSliceUsage ? (JavaSliceUsage)sliceUsage : null;
45 TextChunk[] text = sliceUsage.getText();
46 final List<TextRange> usageRanges = new SmartList<TextRange>();
47 sliceUsage.processRangeMarkers(new Processor<Segment>() {
49 public boolean process(Segment segment) {
50 usageRanges.add(TextRange.create(segment));
54 boolean isInsideContainer = javaSliceUsage != null && javaSliceUsage.indexNesting != 0;
55 for (int i = 0, length = text.length; i < length; i++) {
56 TextChunk textChunk = text[i];
57 SimpleTextAttributes attributes = textChunk.getSimpleAttributesIgnoreBackground();
59 attributes = attributes.derive(attributes.getStyle(), Color.LIGHT_GRAY, attributes.getBgColor(), attributes.getWaveColor());
61 boolean inUsage = (attributes.getFontStyle() & Font.BOLD) != 0;
62 if (isInsideContainer && inUsage) {
63 //Color darker = Color.BLACK;//attributes.getBgColor() == null ? Color.BLACK : attributes.getBgColor().darker();
64 //attributes = attributes.derive(SimpleTextAttributes.STYLE_OPAQUE, attributes.getFgColor(), UIUtil.getTreeBackground().brighter(), attributes.getWaveColor());
65 //setMyBorder(IdeBorderFactory.createRoundedBorder(10, 3));
66 //setPaintFocusBorder(true);
68 append(textChunk.getText(), attributes);
70 append(FontUtil.spaceAndThinSpace());
74 if (javaSliceUsage != null) {
75 for (int i = 0; i < javaSliceUsage.indexNesting; i++) {
77 " (Tracking container contents" +
78 (javaSliceUsage.syntheticField.isEmpty() ? "" : " '" + javaSliceUsage.syntheticField + "'") +
80 SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
84 PsiElement element = sliceUsage.getElement();
88 method = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
89 aClass = method == null ? PsiTreeUtil.getParentOfType(element, PsiClass.class) : method.getContainingClass();
90 if (aClass instanceof PsiAnonymousClass) {
97 int methodOptions = PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS | PsiFormatUtilBase.SHOW_CONTAINING_CLASS;
98 String location = method != null
99 ? PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, methodOptions, PsiFormatUtilBase.SHOW_TYPE, 2)
100 : aClass != null ? PsiFormatUtil.formatClass(aClass, PsiFormatUtilBase.SHOW_NAME) : null;
101 if (location != null) {
102 SimpleTextAttributes attributes = SimpleTextAttributes.GRAY_ATTRIBUTES;
103 append(" in " + location, attributes);