2 * Copyright 2000-2009 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
.ide
.projectView
.PresentationData
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.psi
.PsiElement
;
21 import com
.intellij
.ui
.SimpleTextAttributes
;
22 import com
.intellij
.usageView
.UsageViewBundle
;
23 import com
.intellij
.usages
.Usage
;
24 import com
.intellij
.usages
.UsageInfo2UsageAdapter
;
25 import org
.jetbrains
.annotations
.NotNull
;
28 import java
.util
.Collection
;
29 import java
.util
.List
;
34 public class SliceLeafValueRootNode
extends SliceNode
implements MyColoredTreeCellRenderer
{
35 protected final List
<SliceNode
> myCachedChildren
;
37 public SliceLeafValueRootNode(@NotNull Project project
, PsiElement leafExpression
, SliceNode root
, List
<SliceNode
> children
,
38 SliceAnalysisParams params
) {
39 super(project
, new SliceUsage(leafExpression
, params
), root
.targetEqualUsages
);
40 myCachedChildren
= children
;
44 public Collection
<SliceNode
> getChildren() {
45 return myCachedChildren
;
49 protected void update(PresentationData presentation
) {
53 public String
toString() {
54 Usage myLeafExpression
= getValue();
56 if (myLeafExpression
instanceof UsageInfo2UsageAdapter
) {
57 PsiElement element
= ((UsageInfo2UsageAdapter
)myLeafExpression
).getUsageInfo().getElement();
58 text
= element
== null ?
"" : element
.getText();
63 return "Value: "+ text
;
66 public boolean isValid() {
67 return getValue().isValid();
70 public void customizeCellRenderer(SliceUsageCellRenderer renderer
,
78 Usage usage
= getValue();
79 renderer
.append("Value: ", SimpleTextAttributes
.REGULAR_ATTRIBUTES
);
81 if (usage
instanceof UsageInfo2UsageAdapter
) {
82 PsiElement element
= ((UsageInfo2UsageAdapter
)usage
).getElement();
83 if (element
== null) {
84 renderer
.append(UsageViewBundle
.message("node.invalid") + " ", SliceUsageCellRenderer
.ourInvalidAttributes
);
87 renderer
.append(element
.getText(), SimpleTextAttributes
.REGULAR_BOLD_ATTRIBUTES
);
91 renderer
.append("Other", SimpleTextAttributes
.REGULAR_BOLD_ATTRIBUTES
);