--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
+
+import static com.google.common.base.Verify.verify;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement;
+
+abstract class AbstractKeyEffectiveStatement
+ extends AbstractDeclaredEffectiveStatement.Default<Collection<SchemaNodeIdentifier>, KeyStatement>
+ implements KeyEffectiveStatement {
+ abstract static class Foreign extends AbstractKeyEffectiveStatement {
+ // Polymorphic, with single value or a collection
+ private final Object argument;
+
+ Foreign(final KeyStatement declared, final Collection<SchemaNodeIdentifier> argument) {
+ super(declared);
+ this.argument = argument.size() == 1 ? argument.iterator().next() : argument;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public final Collection<SchemaNodeIdentifier> argument() {
+ if (argument instanceof Collection) {
+ return (Collection<SchemaNodeIdentifier>) argument;
+ }
+ verify(argument instanceof SchemaNodeIdentifier, "Unexpected argument %s", argument);
+ return ImmutableSet.of((SchemaNodeIdentifier) argument);
+ }
+ }
+
+ abstract static class Local extends AbstractKeyEffectiveStatement {
+ Local(final KeyStatement declared) {
+ super(declared);
+ }
+
+ @Override
+ public final Collection<SchemaNodeIdentifier> argument() {
+ return getDeclared().argument();
+ }
+ }
+
+ AbstractKeyEffectiveStatement(final KeyStatement declared) {
+ super(declared);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+
+final class EmptyForeignKeyEffectiveStatement extends AbstractKeyEffectiveStatement.Foreign {
+ EmptyForeignKeyEffectiveStatement(final KeyStatement declared, final Collection<SchemaNodeIdentifier> argument) {
+ super(declared, argument);
+ }
+
+ @Override
+ public ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return ImmutableList.of();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
+
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
+
+final class EmptyLocalKeyEffectiveStatement extends AbstractKeyEffectiveStatement.Local {
+ EmptyLocalKeyEffectiveStatement(final KeyStatement declared) {
+ super(declared);
+ }
+
+ @Override
+ public ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return ImmutableList.of();
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
-
-import java.util.Collection;
-import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-final class KeyEffectiveStatementImpl
- extends DeclaredEffectiveStatementBase<Collection<SchemaNodeIdentifier>, KeyStatement>
- implements KeyEffectiveStatement {
- KeyEffectiveStatementImpl(final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> ctx) {
- super(ctx);
- }
-}
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import java.util.Collection;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
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.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public final class KeyStatementSupport
- extends AbstractStatementSupport<Collection<SchemaNodeIdentifier>, KeyStatement,
- EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> {
+ extends BaseStatementSupport<Collection<SchemaNodeIdentifier>, KeyStatement, KeyEffectiveStatement> {
private static final Splitter LIST_KEY_SPLITTER = Splitter.on(' ').omitEmptyStrings().trimResults();
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
YangStmtMapping.KEY)
@Override
public Collection<SchemaNodeIdentifier> adaptArgumentValue(
- final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement,
- EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx,
+ final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, KeyEffectiveStatement> ctx,
final QNameModule targetModule) {
final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder();
boolean replaced = false;
}
@Override
- public EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement> createEffective(
- final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement,
- EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> ctx) {
- return new KeyEffectiveStatementImpl(ctx);
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
}
@Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
+ protected KeyEffectiveStatement createEffective(
+ final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, KeyEffectiveStatement> ctx,
+ final KeyStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ final Collection<SchemaNodeIdentifier> arg = ctx.coerceStatementArgument();
+ return arg.equals(declared.argument()) ? new RegularLocalKeyEffectiveStatement(declared, substatements)
+ : new RegularForeignKeyEffectiveStatement(declared, arg, substatements);
+ }
+
+ @Override
+ protected KeyEffectiveStatement createEmptyEffective(
+ final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, KeyEffectiveStatement> ctx,
+ final KeyStatement declared) {
+ final Collection<SchemaNodeIdentifier> arg = ctx.coerceStatementArgument();
+ return arg.equals(declared.argument()) ? new EmptyLocalKeyEffectiveStatement(declared)
+ : new EmptyForeignKeyEffectiveStatement(declared, arg);
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+
+final class RegularForeignKeyEffectiveStatement extends AbstractKeyEffectiveStatement.Foreign {
+ private final @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements;
+
+ RegularForeignKeyEffectiveStatement(final KeyStatement declared, final Collection<SchemaNodeIdentifier> argument,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared, argument);
+ this.substatements = requireNonNull(substatements);
+ }
+
+ @Override
+ public ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return substatements;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.key;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ImmutableList;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.KeyStatement;
+
+final class RegularLocalKeyEffectiveStatement extends AbstractKeyEffectiveStatement.Local {
+ private final @NonNull ImmutableList<? extends EffectiveStatement<?, ?>> substatements;
+
+ RegularLocalKeyEffectiveStatement(final KeyStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared);
+ this.substatements = requireNonNull(substatements);
+ }
+
+ @Override
+ public ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return substatements;
+ }
+}