Fix InstanceIdentifier.toReference() return
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / source / YangTextSource.java
1 /*
2  * Copyright (c) 2014 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.model.api.source;
9
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import com.google.common.io.CharSource;
13 import java.io.Reader;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15
16 /**
17  * YANG text schema source representation. Exposes an RFC6020 or RFC7950 text representation as a {@link Reader}.
18  */
19 @NonNullByDefault
20 public abstract class YangTextSource extends CharSource implements YangSourceRepresentation {
21     @Override
22     public final Class<YangTextSource> getType() {
23         return YangTextSource.class;
24     }
25
26     @Override
27     public final String toString() {
28         return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
29     }
30
31     /**
32      * Add subclass-specific attributes to the output {@link #toString()} output. Since
33      * subclasses are prevented from overriding {@link #toString()} for consistency
34      * reasons, they can add their specific attributes to the resulting string by attaching
35      * attributes to the supplied {@link ToStringHelper}.
36      *
37      * @param toStringHelper ToStringHelper onto the attributes can be added
38      * @return ToStringHelper supplied as input argument.
39      */
40     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
41         return toStringHelper.add("identifier", sourceId());
42     }
43 }