*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules;
import org.opendaylight.yangtools.yang.parser.spi.source.ModulesDeviatedByModules.SupportedModules;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviateEffectiveStatementImpl;
import org.slf4j.Logger;
public static class Definition extends AbstractStatementSupport<DeviateKind, DeviateStatement,
EffectiveStatement<DeviateKind, DeviateStatement>> {
+ private static final Map<String, DeviateKind> KEYWORD_TO_DEVIATE_MAP;
+ static {
+ final Builder<String, DeviateKind> keywordToDeviateMapBuilder = ImmutableMap.builder();
+ for (final DeviateKind deviate : DeviateKind.values()) {
+ keywordToDeviateMapBuilder.put(deviate.getKeyword(), deviate);
+ }
+ KEYWORD_TO_DEVIATE_MAP = keywordToDeviateMapBuilder.build();
+ }
private static final Set<YangStmtMapping> SINGLETON_STATEMENTS = ImmutableSet.of(
YangStmtMapping.UNITS, YangStmtMapping.CONFIG, YangStmtMapping.MANDATORY,
super(YangStmtMapping.DEVIATE);
}
- @Override public DeviateKind parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
- return Utils.parseDeviateFromString(ctx, value);
+ @Override
+ public DeviateKind parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
+ return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(value),
+ ctx.getStatementSourceReference(), "String '%s' is not valid deviate argument", value);
}
- @Override public DeviateStatement createDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx) {
+ @Override
+ public DeviateStatement createDeclared(final StmtContext<DeviateKind, DeviateStatement, ?> ctx) {
return new DeviateStatementImpl(ctx);
}
- @Override public EffectiveStatement<DeviateKind, DeviateStatement> createEffective(
+ @Override
+ public EffectiveStatement<DeviateKind, DeviateStatement> createEffective(
final StmtContext<DeviateKind, DeviateStatement, EffectiveStatement<DeviateKind,
DeviateStatement>> ctx) {
return new DeviateEffectiveStatementImpl(ctx);
deviateAction.requiresCtx(deviateStmtCtx, ModelProcessingPhase.EFFECTIVE_MODEL);
final Prerequisite<StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>> targetCtxPrerequisite =
- (Prerequisite<StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>>) deviateAction
- .mutatesEffectiveCtx(deviateStmtCtx.getRoot(), SchemaNodeIdentifierBuildNamespace.class,
- deviationTarget);
+ deviateAction
+ .mutatesEffectiveCtx(deviateStmtCtx.getRoot(), SchemaNodeIdentifierBuildNamespace.class,
+ deviationTarget);
deviateAction.apply(new InferenceAction() {
@Override
}
@Override
- public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) {
+ public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
throw new InferenceException(deviateStmtCtx.getParentContext().getStatementSourceReference(),
"Deviation target '%s' not found.", deviationTarget);
}
final StatementDefinition stmtToBeAdded = stmtCtxToBeAdded.getPublicDefinition();
- if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || (YangStmtMapping.DEFAULT.equals(stmtToBeAdded)
- && YangStmtMapping.LEAF.equals(targetCtx.getPublicDefinition()))) {
+ if (SINGLETON_STATEMENTS.contains(stmtToBeAdded) || YangStmtMapping.DEFAULT.equals(stmtToBeAdded)
+ && YangStmtMapping.LEAF.equals(targetCtx.getPublicDefinition())) {
final Iterable<StatementContextBase<?, ?, ?>> targetCtxSubstatements = Iterables.concat(
targetCtx.declaredSubstatements(), targetCtx.effectiveSubstatements());
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.common.YangVersion;
-import org.opendaylight.yangtools.yang.model.api.DeviateKind;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
"(re-match|deref|derived-from(-or-self)?|enum-value|bit-is-set)(\\()";
private static final Pattern YANG_XPATH_FUNCTIONS_PATTERN = Pattern.compile(YANG_XPATH_FUNCTIONS_STRING);
- private static final Map<String, DeviateKind> KEYWORD_TO_DEVIATE_MAP;
- static {
- final Builder<String, DeviateKind> keywordToDeviateMapBuilder = ImmutableMap.builder();
- for (final DeviateKind deviate : DeviateKind.values()) {
- keywordToDeviateMapBuilder.put(deviate.getKeyword(), deviate);
- }
- KEYWORD_TO_DEVIATE_MAP = keywordToDeviateMapBuilder.build();
- }
-
private static final ThreadLocal<XPathFactory> XPATH_FACTORY = new ThreadLocal<XPathFactory>() {
@Override
protected XPathFactory initialValue() {
.isAssignableFrom(UnknownStatementImpl.class);
}
- public static DeviateKind parseDeviateFromString(final StmtContext<?, ?, ?> ctx, final String deviateKeyword) {
- return SourceException.throwIfNull(KEYWORD_TO_DEVIATE_MAP.get(deviateKeyword),
- ctx.getStatementSourceReference(), "String '%s' is not valid deviate argument", deviateKeyword);
- }
-
static String internBoolean(final String input) {
if ("true".equals(input)) {
return "true";
}
public static boolean belongsToTheSameModule(final QName targetStmtQName, final QName sourceStmtQName) {
- if (targetStmtQName.getModule().equals(sourceStmtQName.getModule())) {
- return true;
- }
- return false;
+ return targetStmtQName.getModule().equals(sourceStmtQName.getModule());
}
public static SourceIdentifier createSourceIdentifier(final RootStatementContext<?, ?, ?> root) {