IDEA-50121
[fedora-idea.git] / java / java-impl / src / com / intellij / slicer / SliceUsage.java
blobe4c6b5374befaabbfbb83f7b00db8918d3e22aba
1 /*
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.analysis.AnalysisScope;
19 import com.intellij.openapi.application.ApplicationManager;
20 import com.intellij.openapi.progress.ProgressIndicator;
21 import com.intellij.openapi.progress.ProgressManager;
22 import com.intellij.psi.PsiElement;
23 import com.intellij.psi.PsiSubstitutor;
24 import com.intellij.slicer.forward.SliceFUtil;
25 import com.intellij.usageView.UsageInfo;
26 import com.intellij.usages.UsageInfo2UsageAdapter;
27 import com.intellij.util.CommonProcessors;
28 import com.intellij.util.Processor;
29 import gnu.trove.TObjectHashingStrategy;
30 import org.jetbrains.annotations.NotNull;
32 /**
33 * @author cdr
35 public class SliceUsage extends UsageInfo2UsageAdapter {
36 private final SliceUsage myParent;
37 public final SliceAnalysisParams params;
38 private final PsiSubstitutor mySubstitutor;
40 public SliceUsage(@NotNull PsiElement element, @NotNull SliceUsage parent, @NotNull PsiSubstitutor substitutor) {
41 super(new UsageInfo(element));
42 myParent = parent;
43 mySubstitutor = substitutor;
44 params = parent.params;
45 assert params != null;
47 public SliceUsage(@NotNull PsiElement element, @NotNull SliceAnalysisParams params) {
48 super(new UsageInfo(element));
49 myParent = null;
50 this.params = params;
51 mySubstitutor = PsiSubstitutor.EMPTY;
54 public void processChildren(Processor<SliceUsage> processor) {
55 final PsiElement element = getElement();
56 ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
57 //indicator.setText2("<html><body>Searching for usages of "+ StringUtil.trimStart(SliceManager.getElementDescription(element),"<html><body>")+"</body></html>");
58 indicator.checkCanceled();
60 final Processor<SliceUsage> uniqueProcessor =
61 new CommonProcessors.UniqueProcessor<SliceUsage>(processor, new TObjectHashingStrategy<SliceUsage>() {
62 public int computeHashCode(final SliceUsage object) {
63 return object.getUsageInfo().hashCode();
66 public boolean equals(final SliceUsage o1, final SliceUsage o2) {
67 return o1.getUsageInfo().equals(o2.getUsageInfo());
69 });
71 ApplicationManager.getApplication().runReadAction(new Runnable() {
72 public void run() {
73 if (params.dataFlowToThis) {
74 SliceUtil.processUsagesFlownDownTo(element, uniqueProcessor, SliceUsage.this, mySubstitutor);
76 else {
77 SliceFUtil.processUsagesFlownFromThe(element, uniqueProcessor, SliceUsage.this);
80 });
83 public SliceUsage getParent() {
84 return myParent;
87 @NotNull
88 public AnalysisScope getScope() {
89 return params.scope;
92 SliceUsage copy() {
93 PsiElement element = getUsageInfo().getElement();
94 return getParent() == null ? new SliceUsage(element, params) : new SliceUsage(element, getParent(),mySubstitutor);
97 public PsiSubstitutor getSubstitutor() {
98 return mySubstitutor;