1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package org.intellij.sdk.language.hierarchy;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiTreeUtil;
import org.intellij.sdk.language.psi.SdExpressionDefinition;
import org.intellij.sdk.language.psi.SdFunctionDefinition;
import org.intellij.sdk.language.psi.SdIdentifier;
import org.intellij.sdk.language.psi.SdRankProfileDefinition;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
/**
* This class represents a Callee tree in the "Call Hierarchy" window.
* @author Shahar Ariel
*/
public class SdCalleeTreeStructure extends SdCallTreeStructure {
public SdCalleeTreeStructure(Project project, PsiElement element, String currentScopeType) {
super(project, element, currentScopeType);
}
@NotNull
@Override
protected HashSet<PsiElement> getChildren(@NotNull SdFunctionDefinition element) {
return getCallees(element, macrosMap);
}
private HashSet<PsiElement> getCallees(@NotNull SdFunctionDefinition macro, HashMap<String, List<PsiElement>> macrosMap) {
final HashSet<PsiElement> results = new HashSet<>();
SdExpressionDefinition expression = PsiTreeUtil.findChildOfType(macro, SdExpressionDefinition.class);
if (expression == null) {
return results;
}
for (SdIdentifier identifier : PsiTreeUtil.collectElementsOfType(expression, SdIdentifier.class)) {
if (macrosMap.containsKey(((PsiNamedElement) identifier).getName())) {
PsiReference identifierRef = identifier.getReference();
if (identifierRef != null) {
results.add(identifierRef.resolve());
}
}
}
SdRankProfileDefinition rankProfile = PsiTreeUtil.getParentOfType(macro, SdRankProfileDefinition.class);
if (rankProfile == null) {
return results;
}
String rankProfileName = rankProfile.getName();
if (!ranksHeritageMap.containsKey(rankProfileName)) {
ranksHeritageMap.put(rankProfileName, SdHierarchyUtil.getRankProfileChildren(myFile, rankProfile));
}
HashSet<SdRankProfileDefinition> inheritedRanks = ranksHeritageMap.get(rankProfileName);
for (PsiElement macroImpl : macrosMap.get(macro.getName())) {
if (inheritedRanks.contains(PsiTreeUtil.getParentOfType(macroImpl, SdRankProfileDefinition.class))) {
results.add(macroImpl);
}
}
return results;
}
}
|