aboutsummaryrefslogtreecommitdiffstats
path: root/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/impl/SdFirstPhaseDefinitionMixin.java
blob: 2fb4fde4b1a71f7aeaf3ebabc91ba96819873f1a (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.intellij.schema.psi.impl;

import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
import com.intellij.navigation.ItemPresentation;
import com.intellij.psi.util.PsiTreeUtil;
import ai.vespa.intellij.schema.SdIcons;
import ai.vespa.intellij.schema.psi.SdRankProfileDefinition;

import javax.swing.Icon;

/**
 * This class is used for methods' implementations for SdFirstPhaseDefinition. Connected with "mixin" to 
 * FirstPhaseDefinition rule in sd.bnf
 *
 * @author Shahar Ariel
 */
public class SdFirstPhaseDefinitionMixin extends ASTWrapperPsiElement {
    
    public SdFirstPhaseDefinitionMixin(ASTNode node) {
        super(node);
    }
    
    public String getName() {
        SdRankProfileDefinition rankProfile = PsiTreeUtil.getParentOfType(this, SdRankProfileDefinition.class);
        if (rankProfile == null) {
            return "";
        }
        return "first-phase of " + rankProfile.getName();
    }
    
    public ItemPresentation getPresentation() {
        final SdFirstPhaseDefinitionMixin element = this;
        return new ItemPresentation() {
            @Override
            public String getPresentableText() {
                SdRankProfileDefinition rankProfile = PsiTreeUtil.getParentOfType(element, SdRankProfileDefinition.class);
                if (rankProfile == null) {
                    return "";
                }
                return "first-phase of " + rankProfile.getName();
            }
            
            @Override
            public String getLocationString() {
                return element.getContainingFile() != null ? element.getContainingFile().getName() : null;
            }
            
            @Override
            public Icon getIcon(boolean unused) {
                return SdIcons.FIRST_PHASE;
            }
        };
    }
}