Search in sources :

Example 1 with AbstractType

use of org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType in project sts4 by spring-projects.

the class BoshCloudConfigSchema method createNetworkBlockSchema.

private YType createNetworkBlockSchema(BoshModels models) {
    AbstractType t_manual_nw = f.ybean("ManualNetwork");
    {
        YBeanType t_subnet = f.ybean("Subnet[Manual]");
        addProp(t_subnet, "range", t_ip_range).isRequired(true);
        addProp(t_subnet, "gateway", t_ip_address).isRequired(true);
        addProp(t_subnet, "dns", f.yseq(t_ip_address));
        addProp(t_subnet, "reserved", f.yseq(t_ip_address_or_range));
        addProp(t_subnet, "static", f.yseq(t_ip_address_or_range));
        addProp(t_subnet, "az", t_az_ref);
        addProp(t_subnet, "azs", f.yseq(t_az_ref));
        addProp(t_subnet, "cloud_properties", t_params);
        addProp(t_manual_nw, "subnets", f.yseq(t_subnet)).isRequired(true);
    }
    AbstractType t_vip_nw = f.ybean("VipNetwork");
    addProp(t_vip_nw, "cloud_properties", t_params);
    AbstractType t_dynamic_nw = f.ybean("DynamicNetwork");
    addProp(t_dynamic_nw, "dns", f.yseq(t_ip_address));
    addProp(t_dynamic_nw, "cloud_properties", t_params);
    {
        YBeanType t_subnet = f.ybean("Subnet[Dynamic]");
        addProp(t_subnet, "dns", f.yseq(t_ip_address));
        addProp(t_subnet, "az", t_az_ref);
        addProp(t_subnet, "azs", f.yseq(t_az_ref));
        addProp(t_subnet, "cloud_properties", t_params);
        addProp(t_dynamic_nw, "subnets", f.yseq(t_subnet));
    }
    t_dynamic_nw.require(Constraints.mutuallyExclusive("dns", "subnets"));
    t_dynamic_nw.require(Constraints.mutuallyExclusive("cloud_properties", "subnets"));
    AbstractType t_network = f.contextAware("Network", dc -> {
        String type = models.getTypeTag(dc);
        if (StringUtil.hasText(type)) {
            switch(type) {
                case "manual":
                    return t_manual_nw;
                case "dynamic":
                    return t_dynamic_nw;
                case "vip":
                    return t_vip_nw;
                default:
            }
        }
        return null;
    }).treatAsBean();
    // Add shared properties to the 'super' type.
    addProp(t_network, "name", t_network_def).isPrimary(true);
    addProp(t_network, "type", f.yenum("NetworkType", "manual", "dynamic", "vip")).isRequired(true);
    // Add shared properties to all 'sub' types.
    for (AbstractType subtype : ImmutableList.of(t_dynamic_nw, t_manual_nw, t_vip_nw)) {
        for (YTypedProperty sharedProp : t_network.getProperties()) {
            subtype.addProperty(sharedProp);
        }
    }
    return t_network;
}
Also used : AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) YamlSchemaProblems(org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems) Collection(java.util.Collection) YamlSchema(org.springframework.ide.vscode.commons.yaml.schema.YamlSchema) YTypeUtil(org.springframework.ide.vscode.commons.yaml.schema.YTypeUtil) PartialCollection(org.springframework.ide.vscode.commons.util.PartialCollection) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) ASTTypeCache(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) YAtomicType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType) Constraints(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraints) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Pair(org.apache.commons.lang3.tuple.Pair) YTypeFactory(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory) ImmutableList(com.google.common.collect.ImmutableList) ValueParsers(org.springframework.ide.vscode.commons.util.ValueParsers) BoshModels(org.springframework.ide.vscode.bosh.models.BoshModels) Lazy(org.springframework.ide.vscode.commons.util.Lazy) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) YBeanType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Example 2 with AbstractType

use of org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType in project sts4 by spring-projects.

the class ConcourseModel method addExtraInsertion.

private YValueHint addExtraInsertion(YValueHint h, DynamicSchemaContext dc) {
    return new BasicYValueHint(h.getValue(), h.getLabel()).setExtraInsertion(() -> {
        String resourceTypeName = h.getValue();
        AbstractType sourceType = (AbstractType) resourceTypes.getSourceType(resourceTypeName);
        if (sourceType != null && getParentPropertyNode("source", dc) == null) {
            // don't auto insert what's already there!
            List<YTypedProperty> requiredProps = sourceType.getProperties().stream().filter(p -> p.isRequired()).collect(Collectors.toList());
            if (!requiredProps.isEmpty()) {
                SnippetBuilder snippet = snippetBuilderFactory.get();
                snippet.text("\nsource:");
                for (YTypedProperty p : requiredProps) {
                    snippet.text("\n  " + p.getName() + ": ");
                    snippet.placeHolder();
                }
                return snippet.toString();
            }
        }
        return null;
    });
}
Also used : AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) Arrays(java.util.Arrays) IDocument(org.springframework.ide.vscode.commons.util.text.IDocument) YamlPathSegment.valueAt(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.valueAt) ASTRootCursor(org.springframework.ide.vscode.commons.yaml.path.ASTRootCursor) NodeTypes(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache.NodeTypes) YamlSchemaProblems(org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems) Multiset(com.google.common.collect.Multiset) NodeUtil(org.springframework.ide.vscode.commons.yaml.ast.NodeUtil) NodeCursor(org.springframework.ide.vscode.commons.yaml.path.NodeCursor) Supplier(com.google.common.base.Supplier) YamlAstCache(org.springframework.ide.vscode.commons.yaml.ast.YamlAstCache) Function(java.util.function.Function) ASTTypeCache(org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) YamlTraversal(org.springframework.ide.vscode.commons.yaml.path.YamlTraversal) YTypeFactory(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory) BasicYValueHint(org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) IProblemCollector(org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) YamlPathSegment.anyChild(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.anyChild) YamlPathSegment.keyAt(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment.keyAt) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) YBeanUnionType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanUnionType) YamlPathSegment(org.springframework.ide.vscode.commons.yaml.path.YamlPathSegment) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) Log(org.springframework.ide.vscode.commons.util.Log) Builder(com.google.common.collect.ImmutableMultiset.Builder) Collection(java.util.Collection) Set(java.util.Set) Constraint(org.springframework.ide.vscode.commons.yaml.schema.constraints.Constraint) Collectors(java.util.stream.Collectors) Assert(org.springframework.ide.vscode.commons.util.Assert) YType(org.springframework.ide.vscode.commons.yaml.schema.YType) List(java.util.List) Stream(java.util.stream.Stream) Streams(org.springframework.ide.vscode.commons.yaml.util.Streams) Entry(java.util.Map.Entry) Optional(java.util.Optional) YValueHint(org.springframework.ide.vscode.commons.yaml.schema.YValueHint) SimpleLanguageServer(org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer) YAMLException(org.yaml.snakeyaml.error.YAMLException) BasicYValueHint(org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType) SnippetBuilder(org.springframework.ide.vscode.commons.languageserver.util.SnippetBuilder) YTypedProperty(org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)

Example 3 with AbstractType

use of org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType in project sts4 by spring-projects.

the class ConcourseModel method newStep.

public StepModel newStep(Node _node) {
    MappingNode node = (MappingNode) _node;
    Set<String> keys = NodeUtil.getScalarKeys(node);
    for (Entry<String, AbstractType> primary : stepType.typesByPrimary().entrySet()) {
        String stepType = primary.getKey();
        if (keys.contains(primary.getKey())) {
            return new StepModel(stepType, node);
        }
    }
    throw new IllegalArgumentException("Node does not look like step node: " + node);
}
Also used : MappingNode(org.yaml.snakeyaml.nodes.MappingNode) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType)

Example 4 with AbstractType

use of org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType in project sts4 by spring-projects.

the class ManifestYmlSchemaTest method getNestedProps.

private List<YTypedProperty> getNestedProps() {
    YSeqType applications = (YSeqType) schema.getTopLevelType().getPropertiesMap().get("applications").getType();
    AbstractType application = (AbstractType) applications.getDomainType();
    return application.getProperties();
}
Also used : YSeqType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YSeqType) AbstractType(org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType)

Aggregations

AbstractType (org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType)4 Collection (java.util.Collection)2 CollectorUtil (org.springframework.ide.vscode.commons.util.CollectorUtil)2 StringUtil (org.springframework.ide.vscode.commons.util.StringUtil)2 ASTTypeCache (org.springframework.ide.vscode.commons.yaml.reconcile.ASTTypeCache)2 YamlSchemaProblems (org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems)2 YType (org.springframework.ide.vscode.commons.yaml.schema.YType)2 YTypeFactory (org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory)2 YTypedProperty (org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty)2 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultiset (com.google.common.collect.ImmutableMultiset)1 Builder (com.google.common.collect.ImmutableMultiset.Builder)1 Multiset (com.google.common.collect.Multiset)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1