2 * Copyright (c) 2017 Cisco Systems, Inc. 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.yang.parser.spi.source;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
15 * An implicit sub-statement, which is implied to be always present in its parent, even if it does not appear
18 * @author Robert Varga
21 public final class ImplicitSubstatement implements StatementSourceReference {
23 private final StatementSourceReference parentRef;
25 private ImplicitSubstatement(final StatementSourceReference parentRef) {
26 this.parentRef = Preconditions.checkNotNull(parentRef);
30 * Create a new {@link ImplicitSubstatement}.
32 * @param parentRef Parent source reference
33 * @return A new reference
34 * @throws NullPointerException if parentRef is null
36 public static ImplicitSubstatement of(final StatementSourceReference parentRef) {
37 return new ImplicitSubstatement(parentRef);
41 public StatementSource getStatementSource() {
42 return StatementSource.CONTEXT;
46 public int hashCode() {
47 return parentRef.hashCode();
51 public boolean equals(final Object obj) {
52 return obj instanceof ImplicitSubstatement && parentRef.equals(((ImplicitSubstatement) obj).parentRef);
56 public String toString() {
57 return parentRef.toString();