Refactor typedef implementations
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / type / BuiltinEffectiveStatement.java
1 /*
2  * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.rfc7950.stmt.type;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableMap;
14 import java.util.Collection;
15 import java.util.Map;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
21 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
22 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
24 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
25
26 /**
27  * Common shared effective statements for built-in types.
28  */
29 enum BuiltinEffectiveStatement implements TypeEffectiveStatement<TypeStatement> {
30     BINARY(BaseTypes.binaryType()),
31     BOOLEAN(BaseTypes.booleanType()),
32     EMPTY(BaseTypes.emptyType()),
33     INSTANCE_IDENTIFIER(BaseTypes.instanceIdentifierType()),
34     INT8(BaseTypes.int8Type()),
35     INT16(BaseTypes.int16Type()),
36     INT32(BaseTypes.int32Type()),
37     INT64(BaseTypes.int64Type()),
38     STRING(BaseTypes.stringType()),
39     UINT8(BaseTypes.uint8Type()),
40     UINT16(BaseTypes.uint16Type()),
41     UINT32(BaseTypes.uint32Type()),
42     UINT64(BaseTypes.uint64Type());
43
44     private final @NonNull TypeDefinition<?> typedef;
45
46     BuiltinEffectiveStatement(final TypeDefinition<?> typedef) {
47         this.typedef = requireNonNull(typedef);
48     }
49
50     @Override
51     public TypeDefinition<?> getTypeDefinition() {
52         return typedef;
53     }
54
55     @Override
56     public final TypeStatement getDeclared() {
57         return null;
58     }
59
60     @Override
61     public final <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends V> get(final Class<N> namespace,
62             final K identifier) {
63         // FIXME: 5.0.0: implement this
64         return Optional.empty();
65     }
66
67     @Override
68     public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAll(final Class<N> namespace) {
69         // FIXME: 5.0.0: implement this
70         return ImmutableMap.of();
71     }
72
73     @Override
74     public final Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
75         return ImmutableList.of();
76     }
77
78     @Override
79     public final String argument() {
80         return getTypeDefinition().getQName().getLocalName();
81     }
82
83     @Override
84     public final StatementSource getStatementSource() {
85         return StatementSource.CONTEXT;
86     }
87 }