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

com.yahoo.schema.parser.ParsedAnnotation Maven / Gradle / Ivy

There is a newer version: 8.409.18
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.parser;

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

/**
 * This class holds the extracted information after parsing a
 * "annotation" block, using simple data structures as far as
 * possible.  Do not put advanced logic here!
 * @author arnej27959
 **/
class ParsedAnnotation extends ParsedBlock {

    private ParsedStruct wrappedStruct = null;
    private final List inherited = new ArrayList<>();
    private final List resolvedInherits = new ArrayList<>();
    private ParsedDocument ownedBy = null;

    ParsedAnnotation(String name) {
        super(name, "annotation");
    }

    public List getInherited() { return List.copyOf(inherited); }
    public List getResolvedInherits() {
        assert(inherited.size() == resolvedInherits.size());
        return List.copyOf(resolvedInherits);
    }


    public Optional getStruct() { return Optional.ofNullable(wrappedStruct); }
    public ParsedDocument getOwnerDoc() { return ownedBy; }
    public String getOwnerName() { return ownedBy.name(); }

    public ParsedStruct ensureStruct() {
        if (wrappedStruct == null) {
            wrappedStruct = new ParsedStruct("annotation." + name());
            wrappedStruct.tagOwner(ownedBy);
        }
        return wrappedStruct;
    }
    void setStruct(ParsedStruct struct) { this.wrappedStruct = struct; }

    void inherit(String other) { inherited.add(other); }

    void tagOwner(ParsedDocument owner) {
        verifyThat(ownedBy == null, "already owned by", ownedBy);
        this.ownedBy = owner;
        getStruct().ifPresent(s -> s.tagOwner(owner));
    }

    void resolveInherit(String name, ParsedAnnotation parsed) {
        verifyThat(inherited.contains(name), "resolveInherit for non-inherited name", name);
        verifyThat(name.equals(parsed.name()), "resolveInherit name mismatch for", name);
        resolvedInherits.add(parsed);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy