private final YangModelDependencyInfo depInfo;
private final ParserRuleContext tree;
private final SourceIdentifier id;
+ private final String text;
- private ASTSchemaSource(final @Nonnull SourceIdentifier id, @Nonnull final ParserRuleContext tree, final @Nonnull YangModelDependencyInfo depInfo) {
+ private ASTSchemaSource(final @Nonnull SourceIdentifier id, @Nonnull final ParserRuleContext tree, final @Nonnull YangModelDependencyInfo depInfo, final @Nonnull String text) {
this.depInfo = Preconditions.checkNotNull(depInfo);
this.tree = Preconditions.checkNotNull(tree);
this.id = Preconditions.checkNotNull(id);
+ this.text = Preconditions.checkNotNull(text);
}
/**
public static final ASTSchemaSource create(final @Nonnull String name, final @Nonnull ParserRuleContext tree) throws YangSyntaxErrorException {
final YangModelDependencyInfo depInfo = YangModelDependencyInfo.fromAST(name, tree);
final SourceIdentifier id = new SourceIdentifier(depInfo.getName(), Optional.of(depInfo.getFormattedRevision()));
- return new ASTSchemaSource(id, tree, depInfo);
+ return new ASTSchemaSource(id, tree, depInfo, null);
}
+ /**
+ * Create a new instance of AST representation for a abstract syntax tree,
+ * performing minimal semantic analysis to acquire dependency information.
+ *
+ * @param name YANG source name. Used only for error reporting.
+ * @param tree ANTLR abstract syntax tree
+ * @return A new representation instance.
+ * @throws YangSyntaxErrorException if we fail to extract dependency information.
+ *
+ * @deprecated Migration only, will be removed as soon as the migration is completed.
+ */
+ @Deprecated
+ public static final ASTSchemaSource create(final @Nonnull String name, final @Nonnull ParserRuleContext tree, final String text) throws YangSyntaxErrorException {
+ final YangModelDependencyInfo depInfo = YangModelDependencyInfo.fromAST(name, tree);
+ final SourceIdentifier id = new SourceIdentifier(depInfo.getName(), Optional.of(depInfo.getFormattedRevision()));
+ return new ASTSchemaSource(id, tree, depInfo, text);
+ }
+
+
@Override
public SourceIdentifier getIdentifier() {
return id;
public @Nonnull YangModelDependencyInfo getDependencyInformation() {
return depInfo;
}
+
+ /**
+ * Return the semantically-equivalent text YANG text source.
+ *
+ * @return YANG text source
+ * @deprecated Used for migration purposes. Users are advised to use the
+ * schema repository to acquire the representation of their
+ * choice. Will be removed as soon as the migration is completed.
+ */
+ @Deprecated
+ public @Nonnull String getYangText() {
+ return text;
+ }
}
*/
package org.opendaylight.yangtools.yang.parser.util;
+import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
+import com.google.common.io.CharStreams;
+import com.google.common.io.InputSupplier;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListeningExecutorService;
walker.walk(validator, ctx);
LOG.debug("Model {} validated successfully", source);
- return ASTSchemaSource.create(source.getIdentifier().getName(), ctx);
+ // Backwards compatibility
+ final String text = CharStreams.toString(
+ CharStreams.newReaderSupplier(new InputSupplier<InputStream>() {
+ @Override
+ public InputStream getInput() throws IOException {
+ return source.openStream();
+ }
+ }, Charsets.UTF_8));
+
+ return ASTSchemaSource.create(source.getIdentifier().getName(), ctx, text);
}
}
}), MAPPER);