2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.rfc7952.parser;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.collect.ImmutableList;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.rfc7952.model.api.AnnotationEffectiveStatement;
16 import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
17 import org.opendaylight.yangtools.rfc7952.model.api.AnnotationStatement;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaNodeDefaults;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.ri.type.ConcreteTypeBuilder;
26 import org.opendaylight.yangtools.yang.model.ri.type.ConcreteTypes;
27 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
28 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.SchemaPathSupport;
30 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
32 final class AnnotationEffectiveStatementImpl extends UnknownEffectiveStatementBase<QName, AnnotationStatement>
33 implements AnnotationEffectiveStatement, AnnotationSchemaNode {
34 private final @NonNull TypeDefinition<?> type;
35 private final @Nullable SchemaPath path;
37 AnnotationEffectiveStatementImpl(final Current<QName, AnnotationStatement> stmt,
38 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
39 super(stmt, substatements);
40 final QName qname = stmt.getArgument();
42 // FIXME: move this into onFullDefinitionDeclared()
43 final TypeEffectiveStatement<?> typeStmt = SourceException.throwIfNull(
44 firstSubstatementOfType(TypeEffectiveStatement.class), stmt,
45 "AnnotationStatementSupport %s is missing a 'type' statement", qname);
47 final ConcreteTypeBuilder<?> builder = ConcreteTypes.concreteTypeBuilder(typeStmt.getTypeDefinition(),
49 final UnitsEffectiveStatement unitsStmt = firstSubstatementOfType(UnitsEffectiveStatement.class);
50 if (unitsStmt != null) {
51 builder.setUnits(unitsStmt.argument());
53 type = builder.build();
55 path = SchemaPathSupport.toOptionalPath(stmt.getEffectiveParent().getSchemaPath().createChild(qname));
59 public QName getQName() {
60 return verifyNotNull(argument());
65 public SchemaPath getPath() {
66 return SchemaNodeDefaults.throwUnsupportedIfNull(this, path);
70 public TypeDefinition<?> getType() {
75 public TypeDefinition<?> getTypeDefinition() {
80 public AnnotationEffectiveStatement asEffectiveStatement() {