import com.google.common.util.concurrent.Futures;
import java.io.IOException;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.ir.IRStatement;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceTransformer;
+import org.opendaylight.yangtools.yang.model.spi.source.YangIRSource;
import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.rfc7950.antlr.IRSupport;
@Beta
-public final class TextToIRTransformer extends SchemaSourceTransformer<YangTextSchemaSource, IRSchemaSource> {
+public final class TextToIRTransformer extends SchemaSourceTransformer<YangTextSource, YangIRSource> {
private TextToIRTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
- super(provider, YangTextSchemaSource.class, consumer, IRSchemaSource.class,
+ super(provider, YangTextSource.class, consumer, YangIRSource.class,
input -> Futures.immediateFuture(transformText(input)));
}
return new TextToIRTransformer(provider, consumer);
}
- public static @NonNull IRSchemaSource transformText(final YangTextSchemaSource text)
+ public static @NonNull YangIRSource transformText(final YangTextSource text)
throws YangSyntaxErrorException, IOException {
- final IRStatement rootStatement = IRSupport.createStatement(YangStatementStreamSource.parseYangSource(text));
- final String name = YangModelDependencyInfo.safeStringArgument(text.getIdentifier(), rootStatement, "name");
- final String latestRevision = YangModelDependencyInfo.getLatestRevision(rootStatement, text.getIdentifier());
- final SourceIdentifier sourceId = new SourceIdentifier(name, latestRevision);
-
- return new IRSchemaSource(sourceId, rootStatement, text.getSymbolicName().orElse(null));
+ final var rootStatement = IRSupport.createStatement(YangStatementStreamSource.parseYangSource(text));
+ final var info = YangIRSourceInfoExtractor.forIR(rootStatement, text.sourceId());
+ return new YangIRSource(info.sourceId(), rootStatement, text.symbolicName());
}
}