final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(),
ctx.getStart().getCharPositionInLine());
final String keywordTxt = Verify.verifyNotNull(ctx.getChild(KeywordContext.class, 0)).getText();
- final QName validStatementDefinition = getValidStatementDefinition(prefixes, stmtDef, keywordTxt);
+ final QName validStatementDefinition = getValidStatementDefinition(prefixes, stmtDef, keywordTxt, ref);
final int childId = counters.peek().getAndIncrement();
counters.push(new Counter());
final KeywordContext keyword = ctx.getChild(KeywordContext.class, 0);
final String statementName = keyword.getText();
- if (stmtDef != null && getValidStatementDefinition(prefixes, stmtDef, statementName) != null
+ if (stmtDef != null && getValidStatementDefinition(prefixes, stmtDef, statementName, ref) != null
&& toBeSkipped.isEmpty()) {
writer.endStatement(ref);
}
* @param prefixes collection of all relevant prefix mappings supplied for actual parsing phase
* @param stmtDef collection of all relevant statement definition mappings provided for actual parsing phase
* @param keywordText statement keyword text to parse from source
+ * @param ref Source reference
* @return valid QName for declared statement to be written, or null
*/
private static QName getValidStatementDefinition(final PrefixToModule prefixes,
- final QNameToStatementDefinition stmtDef, final String keywordText) {
+ final QNameToStatementDefinition stmtDef, final String keywordText, final StatementSourceReference ref) {
final int firstColon = keywordText.indexOf(':');
if (firstColon == -1) {
final StatementDefinition statementDefinition = stmtDef.get(
return statementDefinition != null ? statementDefinition.getStatementName() : null;
}
- final int secondColon = keywordText.indexOf(':', firstColon + 1);
- if (secondColon != -1) {
- // Malformed string
- return null;
- }
+ SourceException.throwIf(firstColon == keywordText.length() - 1
+ || keywordText.indexOf(':', firstColon + 1) != -1, ref, "Malformed statement '%s'", keywordText);
+
if (prefixes == null) {
// No prefixes to look up from
return null;
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.concepts.Identifiable;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
* @author Robert Varga
*/
@Beta
-public final class YangStatementStreamSource implements Identifiable<SourceIdentifier>, StatementStreamSource {
+public final class YangStatementStreamSource implements StatementStreamSource {
private static final ParseTreeListener MAKE_IMMUTABLE_LISTENER = new ParseTreeListener() {
@Override
public void enterEveryRule(final ParserRuleContext ctx) {
import java.net.URISyntaxException;
import javax.annotation.Nonnull;
import javax.xml.transform.TransformerException;
-import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
* @author Robert Varga
*/
@Beta
-public final class YinStatementStreamSource implements Identifiable<SourceIdentifier>, StatementStreamSource {
+public final class YinStatementStreamSource implements StatementStreamSource {
private static final Logger LOG = LoggerFactory.getLogger(YinStatementStreamSource.class);
private static final LoadingCache<String, URI> URI_CACHE = CacheBuilder.newBuilder().weakValues().build(
new CacheLoader<String, URI>() {
*/
package org.opendaylight.yangtools.yang.parser.spi.source;
+import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.common.YangVersion;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
/**
* Statement stream source, which is used for inference of effective model.
* build full declared statement model of source.</li>
* </ol>
*/
-public interface StatementStreamSource {
+public interface StatementStreamSource extends Identifiable<SourceIdentifier> {
/**
* Emits only pre-linkage-related statements to supplied {@code writer}.