import static com.google.common.base.Verify.verify;
+import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
+import org.opendaylight.yangtools.yang.parser.antlr.YangStatementLexer;
import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
public final class KeyStatementSupport
extends BaseStatementSupport<Set<QName>, KeyStatement, KeyEffectiveStatement> {
- private static final Splitter LIST_KEY_SPLITTER = Splitter.on(' ').omitEmptyStrings().trimResults();
+ /**
+ * This is equivalent to {@link YangStatementLexer#SEP}'s definition. Currently equivalent to the non-repeating
+ * part of:
+ *
+ * <p>
+ * {@code SEP: [ \n\r\t]+ -> type(SEP);}.
+ */
+ private static final CharMatcher SEP = CharMatcher.anyOf(" \n\r\t").precomputed();
+
+ /**
+ * Splitter corresponding to {@code key-arg} ABNF as defined
+ * in <a href="https://tools.ietf.org/html/rfc6020#section-12">RFC6020, section 12</a>:
+ *
+ * <p>
+ * {@code key-arg = node-identifier *(sep node-identifier)}
+ *
+ * <p>
+ * We also account for {@link #SEP} not handling repetition by ignoring empty strings.
+ */
+ private static final Splitter KEY_ARG_SPLITTER = Splitter.on(SEP).omitEmptyStrings();
+
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
YangStmtMapping.KEY)
.build();
private static final KeyStatementSupport INSTANCE = new KeyStatementSupport();
private KeyStatementSupport() {
- super(YangStmtMapping.KEY);
+ super(YangStmtMapping.KEY, CopyPolicy.DECLARED_COPY);
}
public static KeyStatementSupport getInstance() {
public ImmutableSet<QName> parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
final Builder<QName> builder = ImmutableSet.builder();
int tokens = 0;
- for (String keyToken : LIST_KEY_SPLITTER.split(value)) {
+ for (String keyToken : KEY_ARG_SPLITTER.split(value)) {
builder.add(StmtContextUtils.parseNodeIdentifier(ctx, keyToken));
tokens++;
}
// Throws NPE on nulls, retains first inserted value, cannot be modified
final ImmutableSet<QName> ret = builder.build();
- SourceException.throwIf(ret.size() != tokens, ctx.sourceReference(), "Key argument '%s' contains duplicates",
- value);
+ SourceException.throwIf(ret.size() != tokens, ctx, "Key argument '%s' contains duplicates", value);
return ret;
}