aboutsummaryrefslogtreecommitdiffstats
path: root/integration/intellij/src/main/java/ai/vespa/intellij/schema/findUsages/SdDocumentSummaryGroupingRule.java
blob: d8bfabd786bcc49038eb2ca58ce288da2c7817f0 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.intellij.schema.findUsages;

import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.PsiElement;
import com.intellij.usages.Usage;
import com.intellij.usages.UsageGroup;
import com.intellij.usages.UsageTarget;
import com.intellij.usages.rules.PsiElementUsage;
import com.intellij.usages.rules.SingleParentUsageGroupingRule;
import ai.vespa.intellij.schema.SdLanguage;
import ai.vespa.intellij.schema.psi.SdDocumentSummaryDefinition;

/**
 * A grouping rule that groups elements in the "Find Usages" window.
 *
 * @author Shahar Ariel
 */
public class SdDocumentSummaryGroupingRule extends SingleParentUsageGroupingRule implements DumbAware {
    
    @Override
    protected UsageGroup getParentGroupFor(Usage usage, UsageTarget[] targets) {
        PsiElement psiElement = usage instanceof PsiElementUsage ? ((PsiElementUsage)usage).getElement() : null;
        if (psiElement == null || psiElement.getLanguage() != SdLanguage.INSTANCE) return null;
    
        while (psiElement != null) {
            if (psiElement instanceof SdDocumentSummaryDefinition) {
                SdDocumentSummaryDefinition componentElement = (SdDocumentSummaryDefinition) psiElement;
                return new SdUsageGroup(componentElement);
            }
            psiElement = psiElement.getParent();
        }
    
        return null;
    }

}