All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.vespa.schemals.schemadocument.resolvers.ResolverTraversal Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
package ai.vespa.schemals.schemadocument.resolvers;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.lsp4j.Diagnostic;

import ai.vespa.schemals.context.ParseContext;
import ai.vespa.schemals.index.Symbol.SymbolStatus;
import ai.vespa.schemals.parser.ast.fieldElm;
import ai.vespa.schemals.tree.Node;
import ai.vespa.schemals.tree.SchemaNode;
import ai.vespa.schemals.tree.Node.LanguageType;

/**
 * ResolverTraversal
 * Traversing the CST after initial parsing step and inheritance has been resolved to resolve symbol references etc.
 */
public class ResolverTraversal {
    public static List traverse(ParseContext context, SchemaNode CST) {
        List diagnostics = new ArrayList<>();
        traverse(context, CST, diagnostics, false);
        return diagnostics;
    }

    private static void traverse(ParseContext context, SchemaNode currentNode, List diagnostics, boolean insideRankExpression) {

        if (currentNode.getLanguageType() == LanguageType.RANK_EXPRESSION && !insideRankExpression) {
            RankExpressionSymbolResolver.resolveRankExpression(currentNode, context);
        }

        if (currentNode.hasSymbol() && currentNode.getSymbol().getStatus() == SymbolStatus.UNRESOLVED) {
            SymbolReferenceResolver.resolveSymbolReference(currentNode, context, diagnostics);
        }

        if (currentNode.containsOtherLanguageData(LanguageType.INDEXING)) {
            IndexingLanguageResolver.resolveIndexingLanguage(context, currentNode, diagnostics);
        }

        for (Node child : currentNode) {
            traverse(context, child.getSchemaNode(), diagnostics, insideRankExpression || currentNode.getLanguageType() == LanguageType.RANK_EXPRESSION);
        }

        // Some things need run after the children has run.
        // If it becomes a lot, put into its own file
        // TODO: solution for field in struct
        if (currentNode.isASTInstance(fieldElm.class)) {
            ValidateFieldSettings.validateFieldSettings(context, currentNode, diagnostics);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy