aboutsummaryrefslogtreecommitdiffstats
path: root/integration/intellij/src/main/java/ai/vespa/intellij/schema/psi/SdFunctionDefinitionInterface.java
blob: f55410cad174e760ecc15364805d8c778e61e870 (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
// 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;

import ai.vespa.intellij.schema.model.RankProfile;
import com.intellij.psi.util.PsiTreeUtil;

/**
 * A function's declaration in the SD language.
 *
 * @author Shahar Ariel
 */
public interface SdFunctionDefinitionInterface extends SdDeclaration {

    default boolean isOverride() {
        String functionName = this.getName();
        SdRankProfileDefinition thisRankProfile = PsiTreeUtil.getParentOfType(this, SdRankProfileDefinition.class);
        if (thisRankProfile == null) return false;
        for (var parentProfile : new RankProfile(thisRankProfile, null).parents().values()) {
            if (containsFunction(functionName, parentProfile))
                return true;
        }
        return false;
    }

    default boolean containsFunction(String functionName, RankProfile rankProfile) {
        if (rankProfile.definedFunctions().containsKey(functionName))
            return true;
        for (var parentProfile : rankProfile.parents().values()) {
            if (containsFunction(functionName, parentProfile))
                return true;
        }
        return false;
    }

}