import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-abstract class StatementContextVisitor {
- static final class Loose extends StatementContextVisitor {
- Loose(final String sourceName, final StatementWriter writer,
- final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes, final YangVersion yangVersion) {
- super(sourceName, writer, stmtDef, prefixes, yangVersion);
- }
-
- Loose(final String sourceName, final StatementWriter writer, final QNameToStatementDefinition stmtDef) {
- this(sourceName, writer, stmtDef, null, YangVersion.VERSION_1);
- }
- }
-
- static final class Strict extends StatementContextVisitor {
- Strict(final String sourceName, final StatementWriter writer,
- final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes, final YangVersion yangVersion) {
- super(sourceName, writer, stmtDef, prefixes, yangVersion);
- }
-
- @Override
- QName getValidStatementDefinition(final String keywordText, final StatementSourceReference ref) {
- return SourceException.throwIfNull(super.getValidStatementDefinition(keywordText, ref), ref,
- "%s is not a YANG statement or use of extension.", keywordText);
- }
- }
-
+class StatementContextVisitor {
private final QNameToStatementDefinition stmtDef;
private final StatementWriter writer;
private final YangVersion yangVersion;
private final PrefixToModule prefixes;
private final String sourceName;
- private StatementContextVisitor(final String sourceName, final StatementWriter writer,
+ StatementContextVisitor(final String sourceName, final StatementWriter writer,
final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes, final YangVersion yangVersion) {
this.writer = requireNonNull(writer);
this.stmtDef = requireNonNull(stmtDef);
}
final String localName = keywordText.substring(firstColon + 1);
- final StatementDefinition foundStmtDef;
- if (prefixes.isPreLinkageMap()) {
- foundStmtDef = stmtDef.getByNamespaceAndLocalName(qNameModule.getNamespace(), localName);
- } else {
- foundStmtDef = stmtDef.get(QName.create(qNameModule, localName));
- }
-
+ final StatementDefinition foundStmtDef = resolveStatement(qNameModule, localName);
return foundStmtDef != null ? foundStmtDef.getStatementName() : null;
}
+ StatementDefinition resolveStatement(final QNameModule module, final String localName) {
+ return stmtDef.get(QName.create(module, localName));
+ }
+
private void processStatement(final int myOffset, final StatementContext ctx) {
final String keywordTxt = verifyNotNull(ctx.getChild(KeywordContext.class, 0)).getText();
final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(),
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementLexer;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.YangVersion;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
@Override
public void writePreLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) {
- new StatementContextVisitor.Loose(sourceName, writer, stmtDef).visit(context);
+ new StatementContextVisitor(sourceName, writer, stmtDef, null, YangVersion.VERSION_1).visit(context);
}
@Override
@Override
public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
final PrefixToModule preLinkagePrefixes, final YangVersion yangVersion) {
- new StatementContextVisitor.Loose(sourceName, writer, stmtDef, preLinkagePrefixes, yangVersion).visit(context);
+ new StatementContextVisitor(sourceName, writer, stmtDef, preLinkagePrefixes, yangVersion) {
+ @Override
+ StatementDefinition resolveStatement(final QNameModule module, final String localName) {
+ return stmtDef.getByNamespaceAndLocalName(module.getNamespace(), localName);
+ }
+ }.visit(context);
}
@Override
@Override
public void writeLinkageAndStatementDefinitions(final StatementWriter writer,
final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes, final YangVersion yangVersion) {
- new StatementContextVisitor.Loose(sourceName, writer, stmtDef, prefixes, yangVersion).visit(context);
+ new StatementContextVisitor(sourceName, writer, stmtDef, prefixes, yangVersion).visit(context);
}
@Override
@Override
public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef,
final PrefixToModule prefixes, final YangVersion yangVersion) {
- new StatementContextVisitor.Strict(sourceName, writer, stmtDef, prefixes, yangVersion).visit(context);
+ new StatementContextVisitor(sourceName, writer, stmtDef, prefixes, yangVersion) {
+ @Override
+ QName getValidStatementDefinition(final String keywordText, final StatementSourceReference ref) {
+ return SourceException.throwIfNull(super.getValidStatementDefinition(keywordText, ref), ref,
+ "%s is not a YANG statement or use of extension.", keywordText);
+ }
+ }.visit(context);
}
@Override
* Pre-linkage map does not consider revision-dates of modules and it contains module namespaces only.
*
* @return true if it is the pre-linkage map.
+ *
+ * @deprecated This property is bound to the currently-executing stage and so should be statically-wired.
*/
+ @Deprecated
boolean isPreLinkageMap();
}
this(false);
}
- public PrefixToModuleMap(boolean preLinkageMap) {
+ @Deprecated
+ public PrefixToModuleMap(final boolean preLinkageMap) {
this.preLinkageMap = preLinkageMap;
}
- public void put(String prefix, QNameModule module) {
+ public void put(final String prefix, final QNameModule module) {
prefixToModuleMap.put(prefix, module);
namespaceToModuleMap.put(module.getNamespace(), module);
}
@Nullable
@Override
- public QNameModule get(@Nonnull String prefix) {
+ public QNameModule get(@Nonnull final String prefix) {
return prefixToModuleMap.get(prefix);
}
@Nullable
@Override
- public QNameModule getByNamespace(String namespace) throws URISyntaxException {
+ public QNameModule getByNamespace(final String namespace) throws URISyntaxException {
return namespaceToModuleMap.get(new URI(namespace));
}
@Override
+ @Deprecated
public boolean isPreLinkageMap() {
return preLinkageMap;
}