Propagate @Nonnull and @Nullable annotations
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / YangTextSchemaSource.java
index e3083456ef16302008384266cdbc56cdfa9dbb1b..26884d9ff40f6e64d661571231180ca334f917a1 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import static com.google.common.base.Preconditions.checkArgument;
+
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
@@ -16,14 +17,18 @@ import com.google.common.base.Preconditions;
 import com.google.common.io.ByteSource;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map.Entry;
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.concepts.Delegator;
+import org.opendaylight.yangtools.yang.common.YangConstants;
+import org.opendaylight.yangtools.yang.common.YangNames;
 
 /**
  * YANG text schema source representation. Exposes an RFC6020 text representation
  * as an {@link InputStream}.
  */
 @Beta
-public abstract class YangTextSchemaSource extends ByteSource implements SchemaSourceRepresentation {
+public abstract class YangTextSchemaSource extends ByteSource implements YangSchemaSourceRepresentation {
     private final SourceIdentifier identifier;
 
     protected YangTextSchemaSource(final SourceIdentifier identifier) {
@@ -31,9 +36,12 @@ public abstract class YangTextSchemaSource extends ByteSource implements SchemaS
     }
 
     public static SourceIdentifier identifierFromFilename(final String name) {
-        checkArgument(name.endsWith(".yang"), "Filename %s does not have a .yang extension", name);
-        // FIXME: add revision-awareness
-        return SourceIdentifier.create(name.substring(0, name.length() - 5), Optional.<String>absent());
+        checkArgument(name.endsWith(YangConstants.RFC6020_YANG_FILE_EXTENSION), "Filename %s does not have a .yang extension",
+            name);
+
+        final String baseName = name.substring(0, name.length() - YangConstants.RFC6020_YANG_FILE_EXTENSION.length());
+        final Entry<String, String> parsed = YangNames.parseFilename(baseName);
+        return RevisionSourceIdentifier.create(parsed.getKey(), Optional.fromNullable(parsed.getValue()));
     }
 
     /**
@@ -47,6 +55,7 @@ public abstract class YangTextSchemaSource extends ByteSource implements SchemaS
     /**
      * {@inheritDoc}
      */
+    @Nonnull
     @Override
     public Class<? extends YangTextSchemaSource> getType() {
         return YangTextSchemaSource.class;
@@ -89,7 +98,7 @@ public abstract class YangTextSchemaSource extends ByteSource implements SchemaS
         }
 
         @Override
-        public final ByteSource getDelegate() {
+        public ByteSource getDelegate() {
             return delegate;
         }