--- /dev/null
+/*
+ * Copyright (c) 2016 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.model.repo.api;
+
+import com.google.common.annotations.Beta;
+import java.util.function.Predicate;
+import org.opendaylight.yangtools.yang.common.QName;
+
+@Beta
+/**
+ * If-feature predicate constants.
+ */
+public final class IfFeaturePredicates {
+ /**
+ * All features predicate constant. Using of this constant improves
+ * performance of schema context resolution.
+ */
+ public static final Predicate<QName> ALL_FEATURES = t -> true;
+
+ private IfFeaturePredicates() {
+ throw new UnsupportedOperationException("Utility class");
+ }
+}
*/
default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
@Nonnull Collection<SourceIdentifier> requiredSources) {
- return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, t -> true);
+ return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
}
/**
*/
default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
Collection<SourceIdentifier> requiredSources, StatementParserMode statementParserMode) {
- return createSchemaContext(requiredSources, statementParserMode, t -> true);
+ return createSchemaContext(requiredSources, statementParserMode, IfFeaturePredicates.ALL_FEATURES);
}
/**
List<TypeOfCopy> getCopyHistory();
+ enum SupportedByFeatures {
+ UNDEFINED, SUPPORTED, NOT_SUPPORTED
+ }
+
+ SupportedByFeatures getSupportedByFeatures();
+
void addAllToCopyHistory(List<TypeOfCopy> typeOfCopyList);
void addToCopyHistory(TypeOfCopy typeOfCopy);
<K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
+ void setSupportedByFeatures(boolean isSupported);
}
}
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;
import org.opendaylight.yangtools.yang.common.QName;
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;
+import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
public final class StmtContextUtils {
public static final Splitter LIST_KEY_SPLITTER = Splitter.on(' ').omitEmptyStrings().trimResults();
- private static final Function<StmtContext<?, ?,?>, DeclaredStatement<?>> BUILD_DECLARED =
- new Function<StmtContext<?,?,?>, DeclaredStatement<?>>() {
+ private static final Function<StmtContext<?, ?, ?>, DeclaredStatement<?>> BUILD_DECLARED = new Function<StmtContext<?, ?, ?>, DeclaredStatement<?>>() {
@Override
public DeclaredStatement<?> apply(final StmtContext<?, ?, ?> input) {
return input.buildDeclared();
}
};
- private static final Function<StmtContext<?, ?,?>, EffectiveStatement<?,?>> BUILD_EFFECTIVE =
- new Function<StmtContext<?,?,?>, EffectiveStatement<?,?>>() {
+ private static final Function<StmtContext<?, ?, ?>, EffectiveStatement<?, ?>> BUILD_EFFECTIVE = new Function<StmtContext<?, ?, ?>, EffectiveStatement<?, ?>>() {
@Override
public EffectiveStatement<?, ?> apply(final StmtContext<?, ?, ?> input) {
return input.buildEffective();
@SuppressWarnings("unchecked")
public static <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(
final Iterable<? extends StmtContext<?, ?, ?>> contexts, final Class<DT> declaredType) {
- for (StmtContext<?, ?, ?> ctx : contexts) {
+ for (final StmtContext<?, ?, ?> ctx : contexts) {
if (producesDeclared(ctx, declaredType)) {
return (AT) ctx.getStatementArgument();
}
public static <AT, DT extends DeclaredStatement<AT>> AT firstSubstatementAttributeOf(
final StmtContext<?, ?, ?> ctx, final Class<DT> declaredType) {
- AT firstAttribute = firstAttributeOf(ctx.effectiveSubstatements(), declaredType);
+ final AT firstAttribute = firstAttributeOf(ctx.effectiveSubstatements(), declaredType);
return firstAttribute != null ? firstAttribute : firstAttributeOf(ctx.declaredSubstatements(), declaredType);
}
@SuppressWarnings("unchecked")
- public static <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstDeclaredSubstatement(
+ public static <AT, DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstDeclaredSubstatement(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
- for (StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
- if (producesDeclared(subStmtContext,declaredType)) {
+ for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
+ if (producesDeclared(subStmtContext, declaredType)) {
return (StmtContext<AT, ?, ?>) subStmtContext;
}
}
@SuppressWarnings("unchecked")
public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllDeclaredSubstatements(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
- ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
- for (StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
+ final ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
+ for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
if (producesDeclared(subStmtContext, declaredType)) {
listBuilder.add((StmtContext<AT, DT, ?>) subStmtContext);
}
@SuppressWarnings("unchecked")
public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllEffectiveSubstatements(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> type) {
- ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
- for (StmtContext<?, ?, ?> subStmtContext : stmtContext.effectiveSubstatements()) {
+ final ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
+ for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.effectiveSubstatements()) {
if (producesDeclared(subStmtContext, type)) {
listBuilder.add((StmtContext<AT, DT, ?>) subStmtContext);
}
public static <AT, DT extends DeclaredStatement<AT>> Collection<StmtContext<AT, DT, ?>> findAllSubstatements(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> type) {
- ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
+ final ImmutableList.Builder<StmtContext<AT, DT, ?>> listBuilder = ImmutableList.builder();
listBuilder.addAll(findAllDeclaredSubstatements(stmtContext, type));
listBuilder.addAll(findAllEffectiveSubstatements(stmtContext, type));
return listBuilder.build();
}
@SuppressWarnings("unchecked")
- public static <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstEffectiveSubstatement(
+ public static <AT, DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstEffectiveSubstatement(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
- for (StmtContext<?, ?, ?> subStmtContext : stmtContext.effectiveSubstatements()) {
- if (producesDeclared(subStmtContext,declaredType)) {
+ for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.effectiveSubstatements()) {
+ if (producesDeclared(subStmtContext, declaredType)) {
return (StmtContext<AT, ?, ?>) subStmtContext;
}
}
return null;
}
- public static <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstSubstatement(
+ public static <AT, DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstSubstatement(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
- StmtContext<AT, ?, ?> declaredSubstatement = findFirstDeclaredSubstatement(stmtContext, declaredType);
- return declaredSubstatement != null ? declaredSubstatement : findFirstEffectiveSubstatement(stmtContext, declaredType);
+ final StmtContext<AT, ?, ?> declaredSubstatement = findFirstDeclaredSubstatement(stmtContext, declaredType);
+ return declaredSubstatement != null ? declaredSubstatement : findFirstEffectiveSubstatement(stmtContext,
+ declaredType);
}
@SafeVarargs
return null;
}
- for (StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
- if (producesDeclared(subStmtContext,types[startIndex])) {
- return startIndex + 1 == types.length ? subStmtContext
- : findFirstDeclaredSubstatement(subStmtContext, ++startIndex, types);
+ for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
+ if (producesDeclared(subStmtContext, types[startIndex])) {
+ return startIndex + 1 == types.length ? subStmtContext : findFirstDeclaredSubstatement(subStmtContext,
+ ++startIndex, types);
}
}
return null;
public static <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findFirstDeclaredSubstatementOnSublevel(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType, int sublevel) {
- for (StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
+ for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
if (sublevel == 1 && producesDeclared(subStmtContext, declaredType)) {
return subStmtContext;
}
if (sublevel > 1) {
- final StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(
- subStmtContext, declaredType, --sublevel);
+ final StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(subStmtContext,
+ declaredType, --sublevel);
if (result != null) {
return result;
}
public static <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findDeepFirstDeclaredSubstatement(
final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
- for (StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
+ for (final StmtContext<?, ?, ?> subStmtContext : stmtContext.declaredSubstatements()) {
if (producesDeclared(subStmtContext, declaredType)) {
return subStmtContext;
}
return type.isAssignableFrom(ctx.getPublicDefinition().getDeclaredRepresentationClass());
}
- public static boolean isInExtensionBody(final StmtContext<?,?,?> stmtCtx) {
- StmtContext<?,?,?> current = stmtCtx;
+ public static boolean isInExtensionBody(final StmtContext<?, ?, ?> stmtCtx) {
+ StmtContext<?, ?, ?> current = stmtCtx;
while (!current.getParentContext().isRootContext()) {
current = current.getParentContext();
if (producesDeclared(current, UnknownStatementImpl.class)) {
final Builder<SchemaNodeIdentifier> builder = ImmutableSet.builder();
boolean replaced = false;
- for (SchemaNodeIdentifier arg : keyStmtCtx.getStatementArgument()) {
+ for (final SchemaNodeIdentifier arg : keyStmtCtx.getStatementArgument()) {
final QName qname = arg.getLastComponent();
if (!newQNameModule.equals(qname)) {
final QName newQname = keyStmtCtx.getFromNamespace(QNameCacheNamespace.class,
- QName.create(newQNameModule, qname.getLocalName()));
+ QName.create(newQNameModule, qname.getLocalName()));
builder.add(SchemaNodeIdentifier.create(false, newQname));
replaced = true;
} else {
}
}
- // This makes sure we reuse the collection when a grouping is instantiated in the same module
+ // This makes sure we reuse the collection when a grouping is
+ // instantiated in the same module
return replaced ? builder.build() : keyStmtCtx.getStatementArgument();
}
- public static boolean areFeaturesSupported(final StmtContext<?, ?, ?> stmtContext) {
- Predicate<QName> isFeatureSupported = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
+ public static boolean areFeaturesSupported(final StmtContext.Mutable<?, ?, ?> stmtContext) {
+ switch (stmtContext.getSupportedByFeatures()) {
+ case SUPPORTED:
+ return true;
+ case NOT_SUPPORTED:
+ return false;
+ default:
+ break;
+ }
+
+ final Predicate<QName> isFeatureSupported = stmtContext.getFromNamespace(SupportedFeaturesNamespace.class,
SupportedFeatures.SUPPORTED_FEATURES);
- Collection<StatementContextBase<?, ?, ?>> substatements = new ArrayList<>();
- substatements.addAll(stmtContext.declaredSubstatements());
- substatements.addAll(stmtContext.effectiveSubstatements());
+ if (IfFeaturePredicates.ALL_FEATURES.equals(isFeatureSupported)) {
+ stmtContext.setSupportedByFeatures(true);
+ return true;
+ }
+
+ final boolean result = checkFeatureSupport(stmtContext, isFeatureSupported);
+ stmtContext.setSupportedByFeatures(result);
+ return result;
+ }
+
+ private static boolean checkFeatureSupport(final StmtContext.Mutable<?, ?, ?> stmtContext,
+ final Predicate<QName> isFeatureSupported) {
+ final Collection<StatementContextBase<?, ?, ?>> substatements = stmtContext.declaredSubstatements();
boolean isSupported = false;
boolean containsIfFeature = false;
- for (StatementContextBase<?, ?, ?> stmt: substatements) {
+ for (final StatementContextBase<?, ?, ?> stmt : substatements) {
if (stmt.getPublicDefinition().equals(Rfc6020Mapping.IF_FEATURE)) {
containsIfFeature = true;
if (isFeatureSupported.test((QName) stmt.getStatementArgument())) {
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
}
public final BuildAction newBuild() {
- return newBuild(StatementParserMode.DEFAULT_MODE, t -> true);
+ return newBuild(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
}
public final BuildAction newBuild(final Predicate<QName> isFeatureSupported) {
}
public final BuildAction newBuild(final StatementParserMode statementParserMode) {
- return new BuildAction(statementParserMode, t -> true);
+ return new BuildAction(statementParserMode, IfFeaturePredicates.ALL_FEATURES);
}
public final BuildAction newBuild(final StatementParserMode statementParserMode,
private final BuildGlobalContext context;
public BuildAction() {
- this(StatementParserMode.DEFAULT_MODE, t -> true);
+ this(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
}
- public BuildAction(StatementParserMode statementParserMode) {
- this(statementParserMode, t -> true);
+ public BuildAction(final StatementParserMode statementParserMode) {
+ this(statementParserMode, IfFeaturePredicates.ALL_FEATURES);
}
- public BuildAction(Predicate<QName> isFeatureSupported) {
+ public BuildAction(final Predicate<QName> isFeatureSupported) {
this(StatementParserMode.DEFAULT_MODE, isFeatureSupported);
}
- public BuildAction(StatementParserMode statementParserMode, Predicate<QName> isFeatureSupported) {
+ public BuildAction(final StatementParserMode statementParserMode, final Predicate<QName> isFeatureSupported) {
this.context = new BuildGlobalContext(supportedTerminology, supportedValidation, statementParserMode,
isFeatureSupported);
}
}
public void addSources(final StatementStreamSource... sources) {
- for (StatementStreamSource source : sources) {
+ for (final StatementStreamSource source : sources) {
context.addSource(source);
}
}
public SchemaContext buildEffective(final Collection<ByteSource> yangByteSources) throws ReactorException,
IOException {
- for (ByteSource yangByteSource : yangByteSources) {
+ for (final ByteSource yangByteSource : yangByteSources) {
addSource(new YangStatementSourceImpl(yangByteSource.openStream()));
}
}
public SchemaContext buildEffective(final List<InputStream> yangInputStreams) throws ReactorException {
- for (InputStream yangInputStream : yangInputStreams) {
+ for (final InputStream yangInputStream : yangInputStreams) {
addSource(new YangStatementSourceImpl(yangInputStream));
}
return Collections.emptyMap();
}
- Map<String, File> pathToFile = new HashMap<>();
- Map<File, Module> sourceFileToModule = new HashMap<>();
+ final Map<String, File> pathToFile = new HashMap<>();
+ final Map<File, Module> sourceFileToModule = new HashMap<>();
- for (File yangFile : yangFiles) {
+ for (final File yangFile : yangFiles) {
addSource(new YangStatementSourceImpl(new NamedFileInputStream(yangFile, yangFile.getPath())));
pathToFile.put(yangFile.getPath(), yangFile);
}
- EffectiveSchemaContext schema = buildEffective();
- Set<Module> modules = schema.getModules();
- for (Module module : modules) {
+ final EffectiveSchemaContext schema = buildEffective();
+ final Set<Module> modules = schema.getModules();
+ for (final Module module : modules) {
sourceFileToModule.put(pathToFile.get(module.getModuleSourcePath()), module);
}
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
/**
* root statement class for a Yang source
*/
private void copyDeclaredStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
final TypeOfCopy typeOfCopy) {
- Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original.declaredSubstatements();
- for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
+ final Collection<StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original.declaredSubstatements();
+ for (final StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
+ if (!StmtContextUtils.areFeaturesSupported(stmtContext)) {
+ continue;
+ }
this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
}
}
*/
private void copyEffectiveStmts(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
final TypeOfCopy typeOfCopy) {
- Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original.effectiveSubstatements();
- for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
+ final Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original.effectiveSubstatements();
+ for (final StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
this.addEffectiveSubstatement(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
}
}
@Override
public StatementContextBase<A, D, E> createCopy(final QNameModule newQNameModule,
final StatementContextBase<?, ?, ?> newParent, final TypeOfCopy typeOfCopy) {
- RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
+ final RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
copy.addAllToCopyHistory(this.getCopyHistory());
copy.addToCopyHistory(typeOfCopy);
private final List<TypeOfCopy> copyHistory = new ArrayList<>(1);
private boolean isSupportedToBuildEffective = true;
+ private SupportedByFeatures supportedByFeatures = SupportedByFeatures.UNDEFINED;
+
+ @Override
+ public SupportedByFeatures getSupportedByFeatures() {
+ return supportedByFeatures;
+ }
+
+ @Override
+ public void setSupportedByFeatures(final boolean isSupported) {
+ this.supportedByFeatures = isSupported ? SupportedByFeatures.SUPPORTED : SupportedByFeatures.NOT_SUPPORTED;
+ }
@Override
public boolean isSupportedToBuildEffective() {
}
public void removeStatementFromEffectiveSubstatements(final StatementDefinition refineSubstatementDef) {
- Iterator<StatementContextBase<?, ?, ?>> iterator = effective.iterator();
+ final Iterator<StatementContextBase<?, ?, ?>> iterator = effective.iterator();
while (iterator.hasNext()) {
- StatementContextBase<?, ?, ?> next = iterator.next();
+ final StatementContextBase<?, ?, ?> next = iterator.next();
if (next.getPublicDefinition().equals(refineSubstatementDef)) {
iterator.remove();
}
public StatementContextBase build() throws SourceException {
StatementContextBase<?, ?, ?> potential = null;
- StatementDefinition stmtDef = getDefinition().getPublicView();
+ final StatementDefinition stmtDef = getDefinition().getPublicView();
if (stmtDef != Rfc6020Mapping.AUGMENT && stmtDef != Rfc6020Mapping.DEVIATION
&& stmtDef != Rfc6020Mapping.TYPE) {
potential = substatements.get(createIdentifier());
* when an error occured in source parsing
*/
boolean tryToCompletePhase(final ModelProcessingPhase phase) {
- Iterator<ContextMutation> openMutations = phaseMutation.get(phase).iterator();
+ final Iterator<ContextMutation> openMutations = phaseMutation.get(phase).iterator();
boolean finished = true;
while (openMutations.hasNext()) {
- ContextMutation current = openMutations.next();
+ final ContextMutation current = openMutations.next();
if (current.isFinished()) {
openMutations.remove();
} else {
finished = false;
}
}
- for (StatementContextBase<?, ?, ?> child : declared) {
+ for (final StatementContextBase<?, ?, ?> child : declared) {
finished &= child.tryToCompletePhase(phase);
}
- for (StatementContextBase<?, ?, ?> child : effective) {
+ for (final StatementContextBase<?, ?, ?> child : effective) {
finished &= child.tryToCompletePhase(phase);
}
*/
private void onPhaseCompleted(final ModelProcessingPhase phase) {
completedPhase = phase;
- Iterator<OnPhaseFinished> listener = phaseListeners.get(completedPhase).iterator();
+ final Iterator<OnPhaseFinished> listener = phaseListeners.get(completedPhase).iterator();
while (listener.hasNext()) {
- OnPhaseFinished next = listener.next();
+ final OnPhaseFinished next = listener.next();
if (next.phaseFinished(this, phase)) {
listener.remove();
}
<K, V, N extends IdentifierNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type, final K key,
final OnNamespaceItemAdded listener) throws SourceException {
- Object potential = getFromNamespace(type, key);
+ final Object potential = getFromNamespace(type, key);
if (potential != null) {
listener.namespaceItemAdded(this, type, key, potential);
return;
}
- NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
+ final NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
if (behaviour instanceof NamespaceBehaviourWithListeners) {
- NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) behaviour;
+ final NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) behaviour;
casted.addValueListener(new ValueAddedListener<K>(this, key) {
@Override
void onValueAdded(final Object key, final Object value) {
try {
listener.namespaceItemAdded(StatementContextBase.this, type, key, value);
- } catch (SourceException e) {
+ } catch (final SourceException e) {
throw Throwables.propagate(e);
}
}
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.GroupingUtils;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
- extends StatementContextBase<A, D, E> {
+final class SubstatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
+ StatementContextBase<A, D, E> {
private final StatementContextBase<?, ?, ?> parent;
private final A argument;
}
@SuppressWarnings("unchecked")
- SubstatementContext(final SubstatementContext<A, D, E> original,
- final QNameModule newQNameModule,
+ SubstatementContext(final SubstatementContext<A, D, E> original, final QNameModule newQNameModule,
final StatementContextBase<?, ?, ?> newParent, final TypeOfCopy typeOfCopy) {
super(original);
this.parent = newParent;
if (newQNameModule != null) {
if (original.argument instanceof QName) {
- QName originalQName = (QName) original.argument;
- this.argument = (A)
- getFromNamespace(QNameCacheNamespace.class,
- QName.create(newQNameModule, originalQName.getLocalName()));
+ final QName originalQName = (QName) original.argument;
+ this.argument = (A) getFromNamespace(QNameCacheNamespace.class,
+ QName.create(newQNameModule, originalQName.getLocalName()));
} else if (StmtContextUtils.producesDeclared(original, KeyStatement.class)) {
this.argument = (A) StmtContextUtils.replaceModuleQNameForKey(
- (StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?>) original,
- newQNameModule);
+ (StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?>) original, newQNameModule);
} else {
this.argument = original.argument;
}
}
}
-
- private void copyDeclaredStmts(final SubstatementContext<A, D, E> original,
- final QNameModule newQNameModule, final TypeOfCopy typeOfCopy) {
- Collection<? extends StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original
+ private void copyDeclaredStmts(final SubstatementContext<A, D, E> original, final QNameModule newQNameModule,
+ final TypeOfCopy typeOfCopy) {
+ final Collection<? extends StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original
.declaredSubstatements();
- for (StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
+ for (final StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
+ if (!StmtContextUtils.areFeaturesSupported(stmtContext)) {
+ continue;
+ }
if (GroupingUtils.needToCopyByUses(stmtContext)) {
- StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(
- newQNameModule, this, typeOfCopy);
+ final StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(newQNameModule, this, typeOfCopy);
this.addEffectiveSubstatement(copy);
} else if (GroupingUtils.isReusedByUses(stmtContext)) {
this.addEffectiveSubstatement(stmtContext);
}
}
- private void copyEffectiveStmts(final SubstatementContext<A, D, E> original,
- final QNameModule newQNameModule, final TypeOfCopy typeOfCopy) {
- Collection<? extends StatementContextBase<?, ?, ?>> originalEffectiveSubstatements = original
+ private void copyEffectiveStmts(final SubstatementContext<A, D, E> original, final QNameModule newQNameModule,
+ final TypeOfCopy typeOfCopy) {
+ final Collection<? extends StatementContextBase<?, ?, ?>> originalEffectiveSubstatements = original
.effectiveSubstatements();
- for (StatementContextBase<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
+ for (final StatementContextBase<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
if (GroupingUtils.needToCopyByUses(stmtContext)) {
- StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(
- newQNameModule, this, typeOfCopy);
+ final StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(newQNameModule, this, typeOfCopy);
this.addEffectiveSubstatement(copy);
} else if (GroupingUtils.isReusedByUses(stmtContext)) {
this.addEffectiveSubstatement(stmtContext);
}
@Override
- public StatementContextBase<?, ?, ?> createCopy(
- final StatementContextBase<?, ?, ?> newParent, final TypeOfCopy typeOfCopy) {
+ public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+ final TypeOfCopy typeOfCopy) {
return createCopy(null, newParent, typeOfCopy);
}
@Override
public StatementContextBase<A, D, E> createCopy(final QNameModule newQNameModule,
final StatementContextBase<?, ?, ?> newParent, final TypeOfCopy typeOfCopy) {
- SubstatementContext<A, D, E> copy = new SubstatementContext<>(this, newQNameModule, newParent, typeOfCopy);
+ final SubstatementContext<A, D, E> copy = new SubstatementContext<>(this, newQNameModule, newParent, typeOfCopy);
copy.addAllToCopyHistory(this.getCopyHistory());
copy.addToCopyHistory(typeOfCopy);
final SchemaPath parentPath = maybeParentPath.get();
if (argument instanceof QName) {
- QName qname = (QName) argument;
+ final QName qname = (QName) argument;
if (StmtContextUtils.producesDeclared(this, UsesStatement.class)) {
return maybeParentPath.orNull();
}
if (argument instanceof String) {
// FIXME: This may yield illegal argument exceptions
final StatementContextBase<?, ?, ?> originalCtx = getOriginalCtx();
- final QName qname = (originalCtx != null) ? Utils.qNameFromArgument(originalCtx, (String) argument)
- : Utils.qNameFromArgument(this, (String) argument);
+ final QName qname = (originalCtx != null) ? Utils.qNameFromArgument(originalCtx, (String) argument) : Utils
+ .qNameFromArgument(this, (String) argument);
return parentPath.createChild(qname);
}
- if (argument instanceof SchemaNodeIdentifier &&
- (StmtContextUtils.producesDeclared(this, AugmentStatement.class)
- || StmtContextUtils.producesDeclared(this, RefineStatement.class))) {
+ if (argument instanceof SchemaNodeIdentifier
+ && (StmtContextUtils.producesDeclared(this, AugmentStatement.class) || StmtContextUtils
+ .producesDeclared(this, RefineStatement.class))) {
return parentPath.createChild(((SchemaNodeIdentifier) argument).getPathFromRoot());
}
@Override
public boolean isConfiguration() {
- StmtContext<Boolean, ?, ?> configStatement = StmtContextUtils
- .findFirstSubstatement(this, ConfigStatement.class);
+ final StmtContext<Boolean, ?, ?> configStatement = StmtContextUtils.findFirstSubstatement(this,
+ ConfigStatement.class);
/*
* If "config" statement is not specified, the default is the same as
}
/*
- * If a parent node has "config" set to "true", the node underneath it can
- * have "config" set to "true" or "false".
+ * If a parent node has "config" set to "true", the node underneath it
+ * can have "config" set to "true" or "false".
*/
if (parent.isConfiguration()) {
return configStatement.getStatementArgument();
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.RootStatementContext;
private static void copyDeclaredStmts(final StatementContextBase<?, ?, ?> sourceCtx,
final StatementContextBase<?, ?, ?> targetCtx) {
- final TypeOfCopy typeOfCopy = sourceCtx.getParentContext().getPublicDefinition().getDeclaredRepresentationClass()
- .equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION : TypeOfCopy.ADDED_BY_AUGMENTATION;
+ final TypeOfCopy typeOfCopy = sourceCtx.getParentContext().getPublicDefinition()
+ .getDeclaredRepresentationClass().equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION
+ : TypeOfCopy.ADDED_BY_AUGMENTATION;
- for (StatementContextBase<?, ?, ?> originalStmtCtx : sourceCtx.declaredSubstatements()) {
+ for (final StatementContextBase<?, ?, ?> originalStmtCtx : sourceCtx.declaredSubstatements()) {
+ if (!StmtContextUtils.areFeaturesSupported(originalStmtCtx)) {
+ continue;
+ }
if (needToCopyByAugment(originalStmtCtx)) {
validateNodeCanBeCopiedByAugment(originalStmtCtx, targetCtx, typeOfCopy);
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(targetCtx, typeOfCopy);
+ final StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(targetCtx, typeOfCopy);
targetCtx.addEffectiveSubstatement(copy);
} else if (isReusedByAugment(originalStmtCtx)) {
targetCtx.addEffectiveSubstatement(originalStmtCtx);
private static void copyEffectiveStmts(final StatementContextBase<?, ?, ?> sourceCtx,
final StatementContextBase<?, ?, ?> targetCtx) {
- final TypeOfCopy typeOfCopy = sourceCtx.getParentContext().getPublicDefinition().getDeclaredRepresentationClass()
- .equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION : TypeOfCopy.ADDED_BY_AUGMENTATION;
+ final TypeOfCopy typeOfCopy = sourceCtx.getParentContext().getPublicDefinition()
+ .getDeclaredRepresentationClass().equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION
+ : TypeOfCopy.ADDED_BY_AUGMENTATION;
- for (StatementContextBase<?, ?, ?> originalStmtCtx : sourceCtx.effectiveSubstatements()) {
+ for (final StatementContextBase<?, ?, ?> originalStmtCtx : sourceCtx.effectiveSubstatements()) {
if (needToCopyByAugment(originalStmtCtx)) {
validateNodeCanBeCopiedByAugment(originalStmtCtx, targetCtx, typeOfCopy);
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(targetCtx, typeOfCopy);
+ final StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(targetCtx, typeOfCopy);
targetCtx.addEffectiveSubstatement(copy);
} else if (isReusedByAugment(originalStmtCtx)) {
targetCtx.addEffectiveSubstatement(originalStmtCtx);
.getPublicDefinition().getDeclaredRepresentationClass());
final boolean targetIsDataNode = DataDefinitionStatement.class.isAssignableFrom(subStatement
.getPublicDefinition().getDeclaredRepresentationClass());
- boolean qNamesEqual = sourceIsDataNode && targetIsDataNode
+ final boolean qNamesEqual = sourceIsDataNode && targetIsDataNode
&& Objects.equals(sourceCtx.getStatementArgument(), subStatement.getStatementArgument());
InferenceException.throwIf(qNamesEqual, sourceCtx.getStatementSourceReference(),
- "An augment cannot add node named '%s' because this name is already used in target",
- sourceCtx.rawStatementArgument());
+ "An augment cannot add node named '%s' because this name is already used in target",
+ sourceCtx.rawStatementArgument());
}
}
private static boolean reguiredCheckOfMandatoryNodes(final StatementContextBase<?, ?, ?> sourceCtx,
StatementContextBase<?, ?, ?> targetCtx) {
/*
- * If the statement argument is not QName, it cannot be mandatory statement,
- * therefore return false and skip mandatory nodes validation
+ * If the statement argument is not QName, it cannot be mandatory
+ * statement, therefore return false and skip mandatory nodes validation
*/
if (!(sourceCtx.getStatementArgument() instanceof QName)) {
return false;
}
- QName sourceStmtQName = (QName) sourceCtx.getStatementArgument();
+ final QName sourceStmtQName = (QName) sourceCtx.getStatementArgument();
- RootStatementContext<?, ?, ?> root = targetCtx.getRoot();
+ final RootStatementContext<?, ?, ?> root = targetCtx.getRoot();
do {
Verify.verify(targetCtx.getStatementArgument() instanceof QName,
"Argument of augment target statement must be QName.");
- QName targetStmtQName = (QName) targetCtx.getStatementArgument();
+ final QName targetStmtQName = (QName) targetCtx.getStatementArgument();
/*
* If target is from another module, return true and perform
* mandatory nodes validation
static boolean isSupportedAugmentTarget(final StatementContextBase<?, ?, ?> substatementCtx) {
/*
- * :TODO Substatement must be allowed augment target type e.g. Container, etc... and must not be for example
- * grouping, identity etc. It is problem in case when more than one substatements have the same QName, for
- * example Grouping and Container are siblings and they have the same QName. We must find the Container and the
- * Grouping must be ignored as disallowed augment target.
+ * :TODO Substatement must be allowed augment target type e.g.
+ * Container, etc... and must not be for example grouping, identity etc.
+ * It is problem in case when more than one substatements have the same
+ * QName, for example Grouping and Container are siblings and they have
+ * the same QName. We must find the Container and the Grouping must be
+ * ignored as disallowed augment target.
*/
- Collection<?> allowedAugmentTargets = substatementCtx.getFromNamespace(ValidationBundlesNamespace.class,
+ final Collection<?> allowedAugmentTargets = substatementCtx.getFromNamespace(ValidationBundlesNamespace.class,
ValidationBundleType.SUPPORTED_AUGMENT_TARGETS);
// if no allowed target is returned we consider all targets allowed
}
/**
- * @param sourceGrpStmtCtx source grouping statement context
- * @param targetCtx target context
- * @param usesNode uses node
- * @throws SourceException instance of SourceException
+ * @param sourceGrpStmtCtx
+ * source grouping statement context
+ * @param targetCtx
+ * target context
+ * @param usesNode
+ * uses node
+ * @throws SourceException
+ * instance of SourceException
*/
public static void copyFromSourceToTarget(final StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
final StatementContextBase<?, ?, ?> targetCtx,
final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode) {
- QNameModule newQNameModule = getNewQNameModule(targetCtx,
- sourceGrpStmtCtx);
+ final QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceGrpStmtCtx);
copyDeclaredStmts(sourceGrpStmtCtx, targetCtx, usesNode, newQNameModule);
- copyEffectiveStmts(sourceGrpStmtCtx, targetCtx, usesNode,
- newQNameModule);
+ copyEffectiveStmts(sourceGrpStmtCtx, targetCtx, usesNode, newQNameModule);
}
public static void copyDeclaredStmts(final StatementContextBase<?, ?, ?> sourceGrpStmtCtx,
final StatementContextBase<?, ?, ?> targetCtx,
final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode,
final QNameModule newQNameModule) {
- for (StatementContextBase<?, ?, ?> originalStmtCtx : sourceGrpStmtCtx.declaredSubstatements()) {
+ for (final StatementContextBase<?, ?, ?> originalStmtCtx : sourceGrpStmtCtx.declaredSubstatements()) {
+ if (!StmtContextUtils.areFeaturesSupported(originalStmtCtx)) {
+ continue;
+ }
if (needToCopyByUses(originalStmtCtx)) {
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx,
- TypeOfCopy.ADDED_BY_USES);
+ final StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx,
+ TypeOfCopy.ADDED_BY_USES);
targetCtx.addEffectiveSubstatement(copy);
usesNode.addAsEffectOfStatement(copy);
} else if (isReusedByUsesOnTop(originalStmtCtx)) {
final StatementContextBase<?, ?, ?> targetCtx,
final StmtContext.Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode,
final QNameModule newQNameModule) {
- for (StatementContextBase<?, ?, ?> originalStmtCtx : sourceGrpStmtCtx.effectiveSubstatements()) {
+ for (final StatementContextBase<?, ?, ?> originalStmtCtx : sourceGrpStmtCtx.effectiveSubstatements()) {
if (needToCopyByUses(originalStmtCtx)) {
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx,
- TypeOfCopy.ADDED_BY_USES);
+ final StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx,
+ TypeOfCopy.ADDED_BY_USES);
targetCtx.addEffectiveSubstatement(copy);
usesNode.addAsEffectOfStatement(copy);
} else if (isReusedByUsesOnTop(originalStmtCtx)) {
return targetCtx.getFromNamespace(ModuleCtxToModuleQName.class, targetCtx.getRoot());
}
- Object targetStmtArgument = targetCtx.getStatementArgument();
- Object sourceStmtArgument = stmtContext.getStatementArgument();
+ final Object targetStmtArgument = targetCtx.getStatementArgument();
+ final Object sourceStmtArgument = stmtContext.getStatementArgument();
if (targetStmtArgument instanceof QName && sourceStmtArgument instanceof QName) {
return ((QName) targetStmtArgument).getModule();
} else {
public static boolean needToCopyByUses(final StmtContext<?, ?, ?> stmtContext) {
final StatementDefinition def = stmtContext.getPublicDefinition();
- return !(NOCOPY_DEF_SET.contains(def) || (NOCOPY_FROM_GROUPING_SET.contains(def)
- && Rfc6020Mapping.GROUPING.equals(stmtContext.getParentContext().getPublicDefinition())));
+ return !(NOCOPY_DEF_SET.contains(def) || (NOCOPY_FROM_GROUPING_SET.contains(def) && Rfc6020Mapping.GROUPING
+ .equals(stmtContext.getParentContext().getPublicDefinition())));
}
public static boolean isReusedByUses(final StmtContext<?, ?, ?> stmtContext) {
public static void resolveUsesNode(
final Mutable<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> usesNode,
final StatementContextBase<?, ?, ?> targetNodeStmtCtx) {
- for (StatementContextBase<?, ?, ?> subStmtCtx : usesNode.declaredSubstatements()) {
+ for (final StatementContextBase<?, ?, ?> subStmtCtx : usesNode.declaredSubstatements()) {
if (StmtContextUtils.producesDeclared(subStmtCtx, RefineStatement.class)) {
performRefine(subStmtCtx, targetNodeStmtCtx);
}
private static void performRefine(final StatementContextBase<?, ?, ?> refineCtx,
final StatementContextBase<?, ?, ?> usesParentCtx) {
- Object refineArgument = refineCtx.getStatementArgument();
+ final Object refineArgument = refineCtx.getStatementArgument();
Preconditions.checkArgument(refineArgument instanceof SchemaNodeIdentifier,
- "Invalid refine argument %s. It must be instance of SchemaNodeIdentifier. At %s", refineArgument,
+ "Invalid refine argument %s. It must be instance of SchemaNodeIdentifier. At %s", refineArgument,
refineCtx.getStatementSourceReference());
- SchemaNodeIdentifier refineTargetNodeIdentifier = (SchemaNodeIdentifier) refineArgument;
- StatementContextBase<?, ?, ?> refineTargetNodeCtx = Utils.findNode(usesParentCtx, refineTargetNodeIdentifier);
+ final SchemaNodeIdentifier refineTargetNodeIdentifier = (SchemaNodeIdentifier) refineArgument;
+ final StatementContextBase<?, ?, ?> refineTargetNodeCtx = Utils.findNode(usesParentCtx,
+ refineTargetNodeIdentifier);
Preconditions.checkArgument(refineTargetNodeCtx != null, "Refine target node %s not found. At %s",
refineTargetNodeIdentifier, refineCtx.getStatementSourceReference());
if (StmtContextUtils.isUnknownStatement(refineTargetNodeCtx)) {
- LOG.debug("Refine node '{}' in uses '{}' has target node unknown statement '{}'. Refine has been skipped. At line: {}",
- refineCtx.getStatementArgument(), refineCtx.getParentContext().getStatementArgument(), refineTargetNodeCtx.getStatementArgument(),
- refineCtx.getStatementSourceReference());
+ LOG.debug(
+ "Refine node '{}' in uses '{}' has target node unknown statement '{}'. Refine has been skipped. At line: {}",
+ refineCtx.getStatementArgument(), refineCtx.getParentContext().getStatementArgument(),
+ refineTargetNodeCtx.getStatementArgument(), refineCtx.getStatementSourceReference());
refineCtx.addAsEffectOfStatement(refineTargetNodeCtx);
return;
}
private static void addOrReplaceNodes(final StatementContextBase<?, ?, ?> refineCtx,
final StatementContextBase<?, ?, ?> refineTargetNodeCtx) {
- for (StatementContextBase<?, ?, ?> refineSubstatementCtx : refineCtx.declaredSubstatements()) {
+ for (final StatementContextBase<?, ?, ?> refineSubstatementCtx : refineCtx.declaredSubstatements()) {
if (isSupportedRefineSubstatement(refineSubstatementCtx)) {
addOrReplaceNode(refineSubstatementCtx, refineTargetNodeCtx);
}
private static void addOrReplaceNode(final StatementContextBase<?, ?, ?> refineSubstatementCtx,
final StatementContextBase<?, ?, ?> refineTargetNodeCtx) {
- StatementDefinition refineSubstatementDef = refineSubstatementCtx.getPublicDefinition();
+ final StatementDefinition refineSubstatementDef = refineSubstatementCtx.getPublicDefinition();
SourceException.throwIf(!isSupportedRefineTarget(refineSubstatementCtx, refineTargetNodeCtx),
- refineSubstatementCtx.getStatementSourceReference(),
- "Error in module '%s' in the refine of uses '%s': can not perform refine of '%s' for the target '%s'.",
- refineSubstatementCtx.getRoot().getStatementArgument(),
- refineSubstatementCtx.getParentContext().getStatementArgument(),
- refineSubstatementCtx.getPublicDefinition(), refineTargetNodeCtx.getPublicDefinition());
+ refineSubstatementCtx.getStatementSourceReference(),
+ "Error in module '%s' in the refine of uses '%s': can not perform refine of '%s' for the target '%s'.",
+ refineSubstatementCtx.getRoot().getStatementArgument(), refineSubstatementCtx.getParentContext()
+ .getStatementArgument(), refineSubstatementCtx.getPublicDefinition(), refineTargetNodeCtx
+ .getPublicDefinition());
if (isAllowedToAddByRefine(refineSubstatementDef)) {
refineTargetNodeCtx.addEffectiveSubstatement(refineSubstatementCtx);
}
private static boolean isSupportedRefineSubstatement(final StatementContextBase<?, ?, ?> refineSubstatementCtx) {
- Collection<?> supportedRefineSubstatements = refineSubstatementCtx.getFromNamespace(
- ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS);
+ final Collection<?> supportedRefineSubstatements = refineSubstatementCtx.getFromNamespace(
+ ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_REFINE_SUBSTATEMENTS);
return supportedRefineSubstatements == null || supportedRefineSubstatements.isEmpty()
|| supportedRefineSubstatements.contains(refineSubstatementCtx.getPublicDefinition())
private static boolean isSupportedRefineTarget(final StatementContextBase<?, ?, ?> refineSubstatementCtx,
final StatementContextBase<?, ?, ?> refineTargetNodeCtx) {
- Collection<?> supportedRefineTargets = YangValidationBundles.SUPPORTED_REFINE_TARGETS.get(
- refineSubstatementCtx.getPublicDefinition());
+ final Collection<?> supportedRefineTargets = YangValidationBundles.SUPPORTED_REFINE_TARGETS
+ .get(refineSubstatementCtx.getPublicDefinition());
return supportedRefineTargets == null || supportedRefineTargets.isEmpty()
|| supportedRefineTargets.contains(refineTargetNodeCtx.getPublicDefinition());
public abstract class EffectiveStatementBase<A, D extends DeclaredStatement<A>> implements EffectiveStatement<A, D> {
- private static final Predicate<StmtContext<?, ?,?>> IS_SUPPORTED_TO_BUILD_EFFECTIVE =
- new Predicate<StmtContext<?,?,?>>() {
+ private static final Predicate<StmtContext<?, ?, ?>> IS_SUPPORTED_TO_BUILD_EFFECTIVE = new Predicate<StmtContext<?, ?, ?>>() {
@Override
public boolean apply(final StmtContext<?, ?, ?> input) {
return input.isSupportedToBuildEffective();
}
};
- private static final Predicate<StmtContext<?, ?,?>> IS_UNKNOWN_STATEMENT_CONTEXT =
- new Predicate<StmtContext<?,?,?>>() {
+ private static final Predicate<StmtContext<?, ?, ?>> IS_UNKNOWN_STATEMENT_CONTEXT = new Predicate<StmtContext<?, ?, ?>>() {
@Override
public boolean apply(final StmtContext<?, ?, ?> input) {
return StmtContextUtils.isUnknownStatement(input);
}
};
- private static final Predicate<StmtContext<?, ?, ?>> ARE_FEATURES_SUPPORTED =
- new Predicate<StmtContext<?, ?, ?>>() {
+ private static final Predicate<StatementContextBase<?, ?, ?>> ARE_FEATURES_SUPPORTED = new Predicate<StatementContextBase<?, ?, ?>>() {
- @Override
- public boolean apply(StmtContext<?, ?, ?> input) {
- return StmtContextUtils.areFeaturesSupported(input);
- }
- };
+ @Override
+ public boolean apply(final StatementContextBase<?, ?, ?> input) {
+ return StmtContextUtils.areFeaturesSupported(input);
+ }
+ };
private final List<? extends EffectiveStatement<?, ?>> substatements;
private final List<StatementContextBase<?, ?, ?>> unknownSubstatementsToBuild;
* method. The main purpose of this is to allow the build of
* recursive extension definitions.
*/
- protected EffectiveStatementBase(final StmtContext<A, D, ?> ctx, boolean buildUnknownSubstatements) {
+ protected EffectiveStatementBase(final StmtContext<A, D, ?> ctx, final boolean buildUnknownSubstatements) {
final Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements = ctx.effectiveSubstatements();
final Collection<StatementContextBase<?, ?, ?>> substatementsInit = new ArrayList<>();
- for (StatementContextBase<?, ?, ?> declaredSubstatement : ctx.declaredSubstatements()) {
+ final Collection<StatementContextBase<?, ?, ?>> supportedDeclaredSubStmts = Collections2.filter(
+ ctx.declaredSubstatements(), ARE_FEATURES_SUPPORTED);
+ for (final StatementContextBase<?, ?, ?> declaredSubstatement : supportedDeclaredSubStmts) {
if (declaredSubstatement.getPublicDefinition().equals(Rfc6020Mapping.USES)) {
substatementsInit.add(declaredSubstatement);
substatementsInit.addAll(declaredSubstatement.getEffectOfStatement());
this.unknownSubstatementsToBuild = ImmutableList.of();
}
- substatementsToBuild = Collections2.filter(substatementsToBuild, ARE_FEATURES_SUPPORTED);
-
- Function<StmtContext<?, ?, ? extends EffectiveStatement<?, ?>>, EffectiveStatement<?, ?>> buildEffective = StmtContextUtils.buildEffective();
+ final Function<StmtContext<?, ?, ? extends EffectiveStatement<?, ?>>, EffectiveStatement<?, ?>> buildEffective = StmtContextUtils
+ .buildEffective();
this.substatements = ImmutableList.copyOf(Collections2.transform(substatementsToBuild, buildEffective));
}
Collection<EffectiveStatement<?, ?>> getOmittedUnknownSubstatements() {
- Function<StmtContext<?, ?, ? extends EffectiveStatement<?, ?>>, EffectiveStatement<?, ?>> buildEffective = StmtContextUtils.buildEffective();
+ final Function<StmtContext<?, ?, ? extends EffectiveStatement<?, ?>>, EffectiveStatement<?, ?>> buildEffective = StmtContextUtils
+ .buildEffective();
return Collections2.transform(unknownSubstatementsToBuild, buildEffective);
}
}
protected final <S extends EffectiveStatement<?, ?>> S firstEffective(final Class<S> type) {
- Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
+ final Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
Predicates.instanceOf(type));
return possible.isPresent() ? type.cast(possible.get()) : null;
}
protected final <S extends SchemaNode> S firstSchemaNode(final Class<S> type) {
- Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
+ final Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
Predicates.instanceOf(type));
return possible.isPresent() ? type.cast(possible.get()) : null;
}
}
protected final <T> T firstSubstatementOfType(final Class<T> type) {
- Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
+ final Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
Predicates.instanceOf(type));
return possible.isPresent() ? type.cast(possible.get()) : null;
}
protected final <R> R firstSubstatementOfType(final Class<?> type, final Class<R> returnType) {
- Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
+ final Optional<? extends EffectiveStatement<?, ?>> possible = Iterables.tryFind(substatements,
Predicates.and(Predicates.instanceOf(type), Predicates.instanceOf(returnType)));
return possible.isPresent() ? returnType.cast(possible.get()) : null;
}