Bug 5884: Augmenting a choice without a case results in no getter
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / YangInferencePipeline.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
9
10 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.global;
11 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.sourceLocal;
12 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
13
14 import com.google.common.collect.ImmutableMap;
15 import java.util.Map;
16 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
17 import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
18 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
19 import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
20 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
21 import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace;
22 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
23 import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
30 import org.opendaylight.yangtools.yang.parser.spi.source.AnyxmlSchemaLocationNamespace;
31 import org.opendaylight.yangtools.yang.parser.spi.source.AugmentToChoiceNamespace;
32 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext;
33 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleIdentifier;
34 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
35 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
36 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace;
37 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToSemVerModuleIdentifier;
38 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
39 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleIdentifier;
40 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
41 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
42 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
43 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace;
44 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNamespaceForBelongsTo;
45 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
46 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
47 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
48 import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
49 import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
50 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
51 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
52 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
53
54 public final class YangInferencePipeline {
55
56     public static final StatementSupportBundle INIT_BUNDLE = StatementSupportBundle
57             .builder().addSupport(global(ValidationBundlesNamespace.class))
58             .addSupport(global(SupportedFeaturesNamespace.class))
59             .build();
60
61     public static final StatementSupportBundle PRE_LINKAGE_BUNDLE = StatementSupportBundle
62             .derivedFrom(INIT_BUNDLE)
63             .addSupport(new ModuleStatementSupport())
64             .addSupport(new SubmoduleStatementImpl.Definition())
65             .addSupport(new NamespaceStatementImpl.Definition())
66             .addSupport(new ImportStatementDefinition())
67             .addSupport(new IncludeStatementImpl.Definition())
68             .addSupport(new PrefixStatementImpl.Definition())
69             .addSupport(new YangVersionStatementImpl.Definition())
70             .addSupport(global(ModuleNameToNamespace.class))
71             .addSupport(global(PreLinkageModuleNamespace.class))
72             .addSupport(sourceLocal(ImpPrefixToNamespace.class))
73             .build();
74
75     public static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle
76             .derivedFrom(PRE_LINKAGE_BUNDLE)
77             .addSupport(new DescriptionStatementImpl.Definition())
78             .addSupport(new RevisionStatementImpl.Definition())
79             .addSupport(new RevisionDateStatementImpl.Definition())
80             .addSupport(new ReferenceStatementImpl.Definition())
81             .addSupport(new ContactStatementImpl.Definition())
82             .addSupport(new OrganizationStatementImpl.Definition())
83             .addSupport(new BelongsToStatementImpl.Definition())
84             .addSupport(global(ModuleNamespace.class))
85             .addSupport(global(ModuleNamespaceForBelongsTo.class))
86             .addSupport(global(SubmoduleNamespace.class))
87             .addSupport(global(NamespaceToModule.class))
88             .addSupport(global(ModuleNameToModuleQName.class))
89             .addSupport(global(ModuleCtxToModuleQName.class))
90             .addSupport(global(ModuleCtxToModuleIdentifier.class))
91             .addSupport(global(ModuleQNameToModuleName.class))
92             .addSupport(global(PrefixToModule.class))
93             .addSupport(global(ModuleIdentifierToModuleQName.class))
94             .addSupport(QNameCacheNamespace.getInstance())
95             .addSupport(sourceLocal(ImportedModuleContext.class))
96             .addSupport(sourceLocal(IncludedModuleContext.class))
97             .addSupport(sourceLocal(IncludedSubmoduleNameToIdentifier.class))
98             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
99             .addSupport(sourceLocal(BelongsToPrefixToModuleIdentifier.class))
100             .addSupport(sourceLocal(URIStringToImpPrefix.class))
101             .addSupport(sourceLocal(BelongsToModuleContext.class))
102             .addSupport(sourceLocal(QNameToStatementDefinition.class))
103             .addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
104             .addSupport(new SemanticVersionStatementImpl.SemanticVersionSupport())
105             .addSupport(global(SemanticVersionNamespace.class))
106             .addSupport(global(SemanticVersionModuleNamespace.class))
107             .addSupport(sourceLocal(ImpPrefixToSemVerModuleIdentifier.class))
108             .build();
109
110     private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle
111             .derivedFrom(LINKAGE_BUNDLE)
112             .addSupport(new YinElementStatementImpl.Definition())
113             .addSupport(new ArgumentStatementImpl.Definition())
114             .addSupport(new ExtensionStatementImpl.Definition())
115             .addSupport(new ChildSchemaNodes<>())
116             .addSupport(new SchemaNodeIdentifierBuildNamespace())
117             .addSupport(global(ExtensionNamespace.class))
118             .addSupport(new TypedefStatementImpl.Definition())
119             .addSupport(treeScoped(TypeNamespace.class))
120             .addSupport(new IdentityStatementImpl.Definition())
121             .addSupport(global(IdentityNamespace.class))
122             .addSupport(new DefaultStatementImpl.Definition())
123             .addSupport(new StatusStatementImpl.Definition())
124             .addSupport(new TypeStatementImpl.Definition())
125             .addSupport(new UnitsStatementImpl.Definition())
126             .addSupport(new RequireInstanceStatementImpl.Definition())
127             .addSupport(new BitStatementImpl.Definition())
128             .addSupport(new PathStatementImpl.Definition())
129             .addSupport(new EnumStatementImpl.Definition())
130             .addSupport(new LengthStatementImpl.Definition())
131             .addSupport(new PatternStatementImpl.Definition())
132             .addSupport(new RangeStatementImpl.Definition())
133             .addSupport(new ContainerStatementImpl.Definition())
134             .addSupport(new GroupingStatementImpl.Definition())
135             .addSupport(new ListStatementImpl.Definition())
136             .addSupport(new UniqueStatementImpl.Definition())
137             .addSupport(new RpcStatementImpl.Definition())
138             .addSupport(new InputStatementImpl.Definition())
139             .addSupport(new OutputStatementImpl.Definition())
140             .addSupport(new NotificationStatementImpl.Definition())
141             .addSupport(new FractionDigitsStatementImpl.Definition())
142             .addSupport(new BaseStatementImpl.Definition())
143             .addSupport(global(DerivedIdentitiesNamespace.class))
144             .build();
145
146     private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle
147             .derivedFrom(STMT_DEF_BUNDLE)
148             .addSupport(new LeafStatementImpl.Definition())
149             .addSupport(new ConfigStatementImpl.Definition())
150             .addSupport(new DeviationStatementImpl.Definition())
151             .addSupport(new DeviateStatementImpl.Definition())
152             .addSupport(new ChoiceStatementImpl.Definition())
153             .addSupport(new CaseStatementImpl.Definition())
154             .addSupport(new MustStatementImpl.Definition())
155             .addSupport(new MandatoryStatementImpl.Definition())
156             .addSupport(new AnyxmlStatementImpl.Definition())
157             .addSupport(new IfFeatureStatementImpl.Definition())
158             .addSupport(new UsesStatementImpl.Definition())
159             .addSupport(treeScoped(GroupingNamespace.class)) //treeScoped
160             .addSupport(new ErrorMessageStatementImpl.Definition())
161             .addSupport(new ErrorAppTagStatementImpl.Definition())
162             .addSupport(new LeafListStatementImpl.Definition())
163             .addSupport(new PresenceStatementImpl.Definition())
164             .addSupport(new KeyStatementImpl.Definition())
165             .addSupport(new MaxElementsStatementImpl.Definition())
166             .addSupport(new MinElementsStatementImpl.Definition())
167             .addSupport(new OrderedByStatementImpl.Definition())
168             .addSupport(new WhenStatementImpl.Definition())
169             .addSupport(new AugmentStatementImpl.Definition())
170             .addSupport(treeScoped(AugmentToChoiceNamespace.class))
171             .addSupport(new RefineStatementImpl.Definition())
172             .addSupport(new FeatureStatementImpl.Definition())
173             .addSupport(new PositionStatementImpl.Definition())
174             .addSupport(new ValueStatementImpl.Definition())
175             .addSupport(new AnyxmlSchemaLocationStatementImpl.AnyxmlSchemaLocationSupport())
176             .addSupport(treeScoped(AnyxmlSchemaLocationNamespace.class))
177             .addSupport(global(StmtOrderingNamespace.class))
178             .build();
179
180     public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
181             .<ModelProcessingPhase, StatementSupportBundle> builder()
182             .put(ModelProcessingPhase.SOURCE_PRE_LINKAGE, PRE_LINKAGE_BUNDLE)
183             .put(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
184             .put(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
185             .put(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
186             .put(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
187             .build();
188
189     public static final CrossSourceStatementReactor RFC6020_REACTOR = CrossSourceStatementReactor
190             .builder()
191             .setBundle(ModelProcessingPhase.INIT, INIT_BUNDLE)
192             .setBundle(ModelProcessingPhase.SOURCE_PRE_LINKAGE, PRE_LINKAGE_BUNDLE)
193             .setBundle(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
194             .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION,
195                     STMT_DEF_BUNDLE)
196             .setBundle(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
197             .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE)
198             .setValidationBundle(
199                     ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS,
200                     YangValidationBundles.SUPPORTED_REFINE_SUBSTATEMENTS)
201             .setValidationBundle(ValidationBundleType.SUPPORTED_AUGMENT_TARGETS,
202                     YangValidationBundles.SUPPORTED_AUGMENT_TARGETS)
203             .setValidationBundle(ValidationBundleType.SUPPORTED_CASE_SHORTHANDS,
204                     YangValidationBundles.SUPPORTED_CASE_SHORTHANDS)
205             .setValidationBundle(ValidationBundleType.SUPPORTED_DATA_NODES,
206                     YangValidationBundles.SUPPORTED_DATA_NODES)
207              .build();
208
209     private YangInferencePipeline() {
210         throw new UnsupportedOperationException("Utility class");
211     }
212 }