Propagate delegate.toString() as symbolic name 27/74727/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Aug 2018 10:31:22 +0000 (12:31 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Aug 2018 10:31:22 +0000 (12:31 +0200)
With use of delegated ByteSources we are losing location of the
source, as there is no symbolic name being filled in.

Change-Id: Ie53207ca3af13de49a8b45d11b78ebb828145e66
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYangTextSchemaSource.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYinTextSchemaSource.java [new file with mode: 0644]
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextSchemaSource.java

index d1ff274914c043e3b2ebb993aaa25acc0eb5b747..86077842a0ac6c6b2631db1eb91b142832a06d84 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.io.ByteSource;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Optional;
 import org.opendaylight.yangtools.concepts.Delegator;
 
 final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implements Delegator<ByteSource> {
@@ -33,6 +34,11 @@ final class DelegatedYangTextSchemaSource extends YangTextSchemaSource implement
         return delegate.openStream();
     }
 
+    @Override
+    public Optional<String> getSymbolicName() {
+        return Optional.of(delegate.toString());
+    }
+
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
         return toStringHelper.add("delegate", delegate);
diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYinTextSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/DelegatedYinTextSchemaSource.java
new file mode 100644 (file)
index 0000000..59160e9
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.repo.api;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.io.ByteSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+import org.opendaylight.yangtools.concepts.Delegator;
+
+final class DelegatedYinTextSchemaSource extends YinTextSchemaSource
+        implements Delegator<ByteSource> {
+    private final ByteSource delegate;
+
+    DelegatedYinTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
+        super(identifier);
+        this.delegate = requireNonNull(delegate);
+    }
+
+    @Override
+    public ByteSource getDelegate() {
+        return delegate;
+    }
+
+    @Override
+    public InputStream openStream() throws IOException {
+        return delegate.openStream();
+    }
+
+    @Override
+    public Optional<String> getSymbolicName() {
+        return Optional.of(delegate.toString());
+    }
+
+    @Override
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return toStringHelper.add("delegate", delegate);
+    }
+}
\ No newline at end of file
index e5f5f4e597a79752efde791b2ad5d814dd292b65..b13c26ab47e50c3ecc0c4d6711456e7e1fc6525d 100644 (file)
@@ -16,12 +16,10 @@ import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.io.ByteSource;
 import com.google.common.io.Resources;
 import java.io.File;
-import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Map.Entry;
 import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.concepts.Delegator;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.common.YangNames;
@@ -109,29 +107,4 @@ public abstract class YinTextSchemaSource extends ByteSource implements YinSchem
         final URL url = Resources.getResource(clazz, resourceName);
         return new ResourceYinTextSchemaSource(identifier, url);
     }
-
-    private static final class DelegatedYinTextSchemaSource extends YinTextSchemaSource
-            implements Delegator<ByteSource> {
-        private final ByteSource delegate;
-
-        private DelegatedYinTextSchemaSource(final SourceIdentifier identifier, final ByteSource delegate) {
-            super(identifier);
-            this.delegate = requireNonNull(delegate);
-        }
-
-        @Override
-        public ByteSource getDelegate() {
-            return delegate;
-        }
-
-        @Override
-        public InputStream openStream() throws IOException {
-            return delegate.openStream();
-        }
-
-        @Override
-        protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-            return toStringHelper.add("delegate", delegate);
-        }
-    }
 }