Switch Import/Include/BelongsTo statements to use Unqualified
[yangtools.git] / parser / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / source / ImplicitSubstatement.java
1 /*
2  * Copyright (c) 2017 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.spi.source;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
14 import org.opendaylight.yangtools.yang.model.api.meta.StatementOrigin;
15
16 /**
17  * An implicit sub-statement, which is implied to be always present in its parent, even if it does not appear in model
18  * source.
19  */
20 @Beta
21 public final class ImplicitSubstatement extends StatementSourceReference {
22     private final StatementSourceReference parentRef;
23
24     private ImplicitSubstatement(final StatementSourceReference parentRef) {
25         this.parentRef = requireNonNull(parentRef);
26     }
27
28     /**
29      * Create a new {@link ImplicitSubstatement}.
30      *
31      * @param parentRef Parent source reference
32      * @return A new reference
33      * @throws NullPointerException if parentRef is null
34      */
35     public static ImplicitSubstatement of(final StatementSourceReference parentRef) {
36         return new ImplicitSubstatement(parentRef);
37     }
38
39     @Override
40     public StatementOrigin statementOrigin() {
41         return StatementOrigin.CONTEXT;
42     }
43
44     @Override
45     public DeclarationReference declarationReference() {
46         return null;
47     }
48
49     @Override
50     public int hashCode() {
51         return parentRef.hashCode();
52     }
53
54     @Override
55     public boolean equals(final Object obj) {
56         return obj instanceof ImplicitSubstatement && parentRef.equals(((ImplicitSubstatement) obj).parentRef);
57     }
58
59     @Override
60     public String toString() {
61         return parentRef.toString();
62     }
63 }