import com.google.common.base.Verify;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Multimap;
+import com.google.common.collect.Table;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnionSpecificationImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc7950.LeafrefSpecificationRfc7950Support;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
&& inProgressPhase == ModelProcessingPhase.SOURCE_LINKAGE) {
root = new RootStatementContext(this, SourceSpecificContext.this, root.getRootVersion());
} else {
- Preconditions.checkState(root.getIdentifier().equals(createIdentifier()),
- "Root statement was already defined as %s.", root.getIdentifier());
+ final QName rootStatement = root.definition().getStatementName();
+ final String rootArgument = root.rawStatementArgument();
+
+ Preconditions.checkState(Objects.equals(getDefinition().getStatementName(), rootStatement)
+ && Objects.equals(getRawArgument(), rootArgument),
+ "Root statement was already defined as '%s %s'.", rootStatement, rootArgument);
}
root.resetLists();
return root;
}
private static final Logger LOG = LoggerFactory.getLogger(SourceSpecificContext.class);
- private static final Map<String, StatementSupport<?, ?, ?>> BUILTIN_TYPE_SUPPORTS =
- ImmutableMap.<String, StatementSupport<?, ?, ?>>builder()
- .put(TypeUtils.DECIMAL64, new Decimal64SpecificationImpl.Definition())
- .put(TypeUtils.UNION, new UnionSpecificationImpl.Definition())
- .put(TypeUtils.ENUMERATION, new EnumSpecificationImpl.Definition())
- .put(TypeUtils.LEAF_REF, new LeafrefSpecificationImpl.Definition())
- .put(TypeUtils.BITS, new BitsSpecificationImpl.Definition())
- .put(TypeUtils.IDENTITY_REF, new IdentityRefSpecificationImpl.Definition())
- .put(TypeUtils.INSTANCE_IDENTIFIER, new InstanceIdentifierSpecificationImpl.Definition())
- .build();
+ private static final Table<YangVersion, String, StatementSupport<?, ?, ?>> BUILTIN_TYPE_SUPPORTS =
+ ImmutableTable.<YangVersion, String, StatementSupport<?, ?, ?>>builder()
+ .put(YangVersion.VERSION_1, TypeUtils.DECIMAL64, new Decimal64SpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.UNION, new UnionSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.ENUMERATION, new EnumSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.LEAF_REF, new LeafrefSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1_1, TypeUtils.LEAF_REF, new LeafrefSpecificationRfc7950Support())
+ .put(YangVersion.VERSION_1, TypeUtils.BITS, new BitsSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.IDENTITY_REF, new IdentityRefSpecificationImpl.Definition())
+ .put(YangVersion.VERSION_1, TypeUtils.INSTANCE_IDENTIFIER, new InstanceIdentifierSpecificationImpl.Definition())
+ .build();
+
private static final QName TYPE = YangStmtMapping.TYPE.getStatementName();
private final Multimap<ModelProcessingPhase, ModifierImpl> modifiers = HashMultimap.create();
def = new StatementDefinitionContext<>(extension);
} else {
// type-body-stmts
- def = resolveTypeBodyStmts(name.getLocalName());
+ def = resolveTypeBodyStmts(name.getLocalName(), getRootVersion());
}
} else if (current != null && current.definition().getRepresentingClass().equals(UnknownStatementImpl.class)) {
/*
}
}
- private static StatementDefinitionContext<?, ?, ?> resolveTypeBodyStmts(final String typeArgument) {
- final StatementSupport<?, ?, ?> support = BUILTIN_TYPE_SUPPORTS.get(typeArgument);
+ private static StatementDefinitionContext<?, ?, ?> resolveTypeBodyStmts(final String typeArgument,
+ final YangVersion version) {
+ StatementSupport<?, ?, ?> support = BUILTIN_TYPE_SUPPORTS.get(version, typeArgument);
+
+ if (support == null) {
+ support = BUILTIN_TYPE_SUPPORTS.get(YangVersion.VERSION_1, typeArgument);
+ }
+
return support == null ? null : new StatementDefinitionContext<>(support);
}