private Set<Function> getCallees(SdFunctionDefinition function, Map<String, List<Function>> functions) {
        Set<Function> results = new HashSet<>();
        SdExpressionDefinition expression = PsiTreeUtil.findChildOfType(function, SdExpressionDefinition.class);
        if (expression == null) {
            return results;
        }
        for (SdIdentifier identifier : PsiTreeUtil.collectElementsOfType(expression, SdIdentifier.class)) {
            if (functions.containsKey(((PsiNamedElement) identifier).getName())) {
                PsiReference identifierRef = identifier.getReference();
                if (identifierRef != null) {
                    results.add(Function.from((SdFunctionDefinition)identifierRef.resolve(), null));
                }
            }
        }
        
        SdRankProfileDefinition rankProfile = PsiTreeUtil.getParentOfType(function, SdRankProfileDefinition.class);
        if (rankProfile == null) {
            return results;
        }
        String rankProfileName = rankProfile.getName();
        if (!ranksHeritageMap.containsKey(rankProfileName)) {
            ranksHeritageMap.put(rankProfileName, SdHierarchyUtil.getRankProfileChildren(myFile, new RankProfile(rankProfile, null)));
        }
        
        Set<SdRankProfileDefinition> inheritedRanks = ranksHeritageMap.get(rankProfileName);
        
        for (Function functionImpl : functions.get(function.getName())) {
            if (inheritedRanks.contains(PsiTreeUtil.getParentOfType(functionImpl.definition(), SdRankProfileDefinition.class))) {
                results.add(functionImpl);
            }

        }
        
        return results;
    }
A Callee tree in the "Call Hierarchy" window.

@author Shahar Ariel
integration/intellij/src/main/java/ai/vespa/intellij/schema/hierarchy/SdCalleeTreeStructure.java