From 26267c3c9b4bd4e4ead26d7373ae1c1752876bde Mon Sep 17 00:00:00 2001 From: Peter Kajsa Date: Thu, 20 Aug 2015 11:32:25 +0200 Subject: [PATCH] Bug 3670 (part 2/5): Use of new statement parser in yang-maven-plugin Parser fixes: - Bug 1412 - AugmentToExtensionTest with new parser use fix Change-Id: I68fc81089267d32f9c5b41d3957c7652d3f7b743 Signed-off-by: Peter Kajsa --- .../stmt/reactor/SourceSpecificContext.java | 6 + .../stmt/rfc6020/AugmentStatementImpl.java | 3 +- .../parser/stmt/rfc6020/AugmentUtils.java | 176 +++++++----------- .../stmt/rfc6020/UnknownStatementImpl.java | 2 +- .../yang/parser/stmt/rfc6020/Utils.java | 14 +- .../UnknownEffectiveStatementImpl.java | 37 +++- .../parser/impl/YangParserSimpleTest.java | 1 - .../stmt/retest/AugmentToExtensionTest.java | 8 +- .../yang/stmt/retest/Bug1412Test.java | 75 ++++---- 9 files changed, 150 insertions(+), 172 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java index a5b7f53dc7..7a5f7be94d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java @@ -116,6 +116,12 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh def = resolveTypeBodyStmts(name.getLocalName()); } } + else if (current != null && current.definition().getRepresentingClass().equals(UnknownStatementImpl.class)) { + QName qName = Utils.qNameFromArgument(current, name.getLocalName()); + + def = new StatementDefinitionContext<>(new UnknownStatementImpl.Definition + (getNewStatementDefinition(qName))); + } Preconditions.checkArgument(def != null, "Statement %s does not have type mapping defined.", name); if (current == null) { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java index f1219b7504..b79f75709e 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java @@ -97,7 +97,8 @@ public class AugmentStatementImpl extends + augmentNode.getStatementArgument(), augmentNode.getStatementSourceReference()); } - if (StmtContextUtils.isInExtensionBody(augmentTargetCtx)) { + + if (!AugmentUtils.isSupportedAugmentTarget(augmentTargetCtx) || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) { augmentNode.setIsSupportedToBuildEffective(false); return; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java index 36ab9e341f..5a92e31c6e 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java @@ -7,10 +7,6 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020; -import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.ImmutableList.Builder; import java.util.Collection; import java.util.HashSet; @@ -37,10 +33,13 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable; 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.source.ModuleCtxToModuleQName; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; 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.StatementContextBase; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class AugmentUtils { @@ -52,8 +51,7 @@ public final class AugmentUtils { private AugmentUtils() { } - public static Iterable parseAugmentPath(StmtContext ctx, - String path) { + public static Iterable parseAugmentPath(StmtContext ctx, String path) { if (path.matches(REGEX_PATH_REL1) || path.matches(REGEX_PATH_REL2)) { throw new IllegalArgumentException( @@ -63,38 +61,30 @@ public final class AugmentUtils { return Utils.parseXPath(ctx, path); } - public static void copyFromSourceToTarget( - StatementContextBase sourceCtx, + public static void copyFromSourceToTarget(StatementContextBase sourceCtx, StatementContextBase targetCtx) throws SourceException { copyDeclaredStmts(sourceCtx, targetCtx); copyEffectiveStmts(sourceCtx, targetCtx); } - public static void copyDeclaredStmts( - StatementContextBase sourceCtx, + public static void copyDeclaredStmts(StatementContextBase sourceCtx, StatementContextBase targetCtx) throws SourceException { - Collection> declaredSubStatements = sourceCtx - .declaredSubstatements(); + Collection> declaredSubStatements = sourceCtx.declaredSubstatements(); final List subStatements = new Builder() - .addAll(targetCtx.declaredSubstatements()) - .addAll(targetCtx.effectiveSubstatements()).build(); - boolean sourceAndTargetInSameModule = Utils.getRootModuleQName( - sourceCtx).equals(Utils.getRootModuleQName(targetCtx)); + .addAll(targetCtx.declaredSubstatements()).addAll(targetCtx.effectiveSubstatements()).build(); + boolean sourceAndTargetInSameModule = Utils.getRootModuleQName(sourceCtx).equals( + Utils.getRootModuleQName(targetCtx)); - TypeOfCopy typeOfCopy = sourceCtx.getParentContext() - .getPublicDefinition().getDeclaredRepresentationClass() - .equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION - : TypeOfCopy.ADDED_BY_AUGMENTATION; + TypeOfCopy typeOfCopy = sourceCtx.getParentContext().getPublicDefinition().getDeclaredRepresentationClass() + .equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION : TypeOfCopy.ADDED_BY_AUGMENTATION; for (StatementContextBase originalStmtCtx : declaredSubStatements) { if (needToCopyByAugment(originalStmtCtx)) { - validateNodeCanBeCopiedByAugment(originalStmtCtx, - subStatements, sourceAndTargetInSameModule); + validateNodeCanBeCopiedByAugment(originalStmtCtx, subStatements, sourceAndTargetInSameModule); - StatementContextBase copy = originalStmtCtx - .createCopy(targetCtx, typeOfCopy); + StatementContextBase copy = originalStmtCtx.createCopy(targetCtx, typeOfCopy); targetCtx.addEffectiveSubstatement(copy); } else if (isReusedByAugment(originalStmtCtx)) { targetCtx.addEffectiveSubstatement(originalStmtCtx); @@ -102,30 +92,23 @@ public final class AugmentUtils { } } - public static void copyEffectiveStmts( - StatementContextBase sourceCtx, + public static void copyEffectiveStmts(StatementContextBase sourceCtx, StatementContextBase targetCtx) throws SourceException { - Collection> effectiveSubstatements = sourceCtx - .effectiveSubstatements(); + Collection> effectiveSubstatements = sourceCtx.effectiveSubstatements(); final List subStatements = new Builder() - .addAll(targetCtx.declaredSubstatements()) - .addAll(targetCtx.effectiveSubstatements()).build(); - boolean sourceAndTargetInSameModule = Utils.getRootModuleQName( - sourceCtx).equals(Utils.getRootModuleQName(targetCtx)); + .addAll(targetCtx.declaredSubstatements()).addAll(targetCtx.effectiveSubstatements()).build(); + boolean sourceAndTargetInSameModule = Utils.getRootModuleQName(sourceCtx).equals( + Utils.getRootModuleQName(targetCtx)); - TypeOfCopy typeOfCopy = sourceCtx.getParentContext() - .getPublicDefinition().getDeclaredRepresentationClass() - .equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION - : TypeOfCopy.ADDED_BY_AUGMENTATION; + TypeOfCopy typeOfCopy = sourceCtx.getParentContext().getPublicDefinition().getDeclaredRepresentationClass() + .equals(UsesStatement.class) ? TypeOfCopy.ADDED_BY_USES_AUGMENTATION : TypeOfCopy.ADDED_BY_AUGMENTATION; for (StatementContextBase originalStmtCtx : effectiveSubstatements) { if (needToCopyByAugment(originalStmtCtx)) { - validateNodeCanBeCopiedByAugment(originalStmtCtx, - subStatements, sourceAndTargetInSameModule); + validateNodeCanBeCopiedByAugment(originalStmtCtx, subStatements, sourceAndTargetInSameModule); - StatementContextBase copy = originalStmtCtx - .createCopy(targetCtx, typeOfCopy); + StatementContextBase copy = originalStmtCtx.createCopy(targetCtx, typeOfCopy); targetCtx.addEffectiveSubstatement(copy); } else if (isReusedByAugment(originalStmtCtx)) { targetCtx.addEffectiveSubstatement(originalStmtCtx); @@ -133,24 +116,19 @@ public final class AugmentUtils { } } - private static void validateNodeCanBeCopiedByAugment( - final StatementContextBase sourceCtx, - final List targetSubStatements, - boolean sourceAndTargetInSameModule) { + private static void validateNodeCanBeCopiedByAugment(final StatementContextBase sourceCtx, + final List targetSubStatements, boolean sourceAndTargetInSameModule) { - if (sourceCtx.getPublicDefinition().getDeclaredRepresentationClass() - .equals(WhenStatement.class)) { + if (sourceCtx.getPublicDefinition().getDeclaredRepresentationClass().equals(WhenStatement.class)) { return; } if (!sourceAndTargetInSameModule) { final List sourceSubStatements = new Builder() - .addAll(sourceCtx.declaredSubstatements()) - .addAll(sourceCtx.effectiveSubstatements()).build(); + .addAll(sourceCtx.declaredSubstatements()).addAll(sourceCtx.effectiveSubstatements()).build(); for (final StatementContextBase sourceSubStatement : sourceSubStatements) { - if (sourceSubStatement.getPublicDefinition() - .getDeclaredRepresentationClass() + if (sourceSubStatement.getPublicDefinition().getDeclaredRepresentationClass() .equals(MandatoryStatement.class)) { throw new IllegalArgumentException( String.format( @@ -162,34 +140,27 @@ public final class AugmentUtils { for (final StatementContextBase subStatement : targetSubStatements) { - final boolean sourceIsDataNode = DataDefinitionStatement.class - .isAssignableFrom(sourceCtx.getPublicDefinition() - .getDeclaredRepresentationClass()); - final boolean targetIsDataNode = DataDefinitionStatement.class - .isAssignableFrom(subStatement.getPublicDefinition() - .getDeclaredRepresentationClass()); - boolean qNamesEqual = sourceIsDataNode - && targetIsDataNode - && Objects.equals(sourceCtx.getStatementArgument(), - subStatement.getStatementArgument()); + final boolean sourceIsDataNode = DataDefinitionStatement.class.isAssignableFrom(sourceCtx + .getPublicDefinition().getDeclaredRepresentationClass()); + final boolean targetIsDataNode = DataDefinitionStatement.class.isAssignableFrom(subStatement + .getPublicDefinition().getDeclaredRepresentationClass()); + boolean qNamesEqual = sourceIsDataNode && targetIsDataNode + && Objects.equals(sourceCtx.getStatementArgument(), subStatement.getStatementArgument()); if (qNamesEqual) { - throw new IllegalStateException( - String.format( - "An augment cannot add node named '%s' because this name is already used in target", - sourceCtx.rawStatementArgument())); + throw new IllegalStateException(String.format( + "An augment cannot add node named '%s' because this name is already used in target", + sourceCtx.rawStatementArgument())); } } } - public static QNameModule getNewQNameModule( - StatementContextBase targetCtx, + public static QNameModule getNewQNameModule(StatementContextBase targetCtx, StatementContextBase sourceCtx) { Object targetStmtArgument = targetCtx.getStatementArgument(); final StatementContextBase root = sourceCtx.getRoot(); - final QNameModule sourceQNameModule = root.getFromNamespace( - ModuleCtxToModuleQName.class, root); + final QNameModule sourceQNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root); if (targetStmtArgument instanceof QName) { QName targetQName = (QName) targetStmtArgument; @@ -227,8 +198,7 @@ public final class AugmentUtils { public static StatementContextBase getAugmentTargetCtx( final Mutable> augmentNode) { - final SchemaNodeIdentifier augmentTargetNode = augmentNode - .getStatementArgument(); + final SchemaNodeIdentifier augmentTargetNode = augmentNode.getStatementArgument(); if (augmentTargetNode == null) { throw new IllegalArgumentException( "Augment argument null, something bad happened in some of previous parsing phases"); @@ -237,24 +207,19 @@ public final class AugmentUtils { List> rootStatementCtxList = new LinkedList<>(); if (augmentTargetNode.isAbsolute()) { - QNameModule module = augmentTargetNode.getPathFromRoot().iterator() - .next().getModule(); + QNameModule module = augmentTargetNode.getPathFromRoot().iterator().next().getModule(); StatementContextBase rootStatementCtx = (StatementContextBase) augmentNode .getFromNamespace(NamespaceToModule.class, module); rootStatementCtxList.add(rootStatementCtx); - final Map subModules = rootStatementCtx - .getAllFromNamespace(IncludedModuleContext.class); + final Map subModules = rootStatementCtx.getAllFromNamespace(IncludedModuleContext.class); if (subModules != null) { - rootStatementCtxList - .addAll((Collection>) subModules - .values()); + rootStatementCtxList.addAll((Collection>) subModules.values()); } } else { - StatementContextBase parent = (StatementContextBase) augmentNode - .getParentContext(); + StatementContextBase parent = (StatementContextBase) augmentNode.getParentContext(); if (StmtContextUtils.producesDeclared(parent, UsesStatement.class)) { rootStatementCtxList.add(parent.getParentContext()); } else { @@ -264,8 +229,7 @@ public final class AugmentUtils { StatementContextBase augmentTargetCtx = null; for (final StatementContextBase rootStatementCtx : rootStatementCtxList) { - augmentTargetCtx = findCtxOfNodeInRoot(rootStatementCtx, - augmentTargetNode); + augmentTargetCtx = findCtxOfNodeInRoot(rootStatementCtx, augmentTargetNode); if (augmentTargetCtx != null) break; } @@ -274,8 +238,7 @@ public final class AugmentUtils { } @Nullable - public static StatementContextBase findCtxOfNodeInSubstatements( - StatementContextBase rootStmtCtx, + public static StatementContextBase findCtxOfNodeInSubstatements(StatementContextBase rootStmtCtx, final Iterable path) { StatementContextBase parent = rootStmtCtx; @@ -283,8 +246,7 @@ public final class AugmentUtils { Iterator pathIter = path.iterator(); while (pathIter.hasNext()) { QName nextPathQName = pathIter.next(); - StatementContextBase foundSubstatement = getSubstatementByQName( - parent, nextPathQName); + StatementContextBase foundSubstatement = getSubstatementByQName(parent, nextPathQName); if (foundSubstatement == null) { return null; @@ -299,13 +261,11 @@ public final class AugmentUtils { return null; } - public static StatementContextBase getSubstatementByQName( - StatementContextBase parent, QName nextPathQName) { + public static StatementContextBase getSubstatementByQName(StatementContextBase parent, + QName nextPathQName) { - Collection> declaredSubstatement = parent - .declaredSubstatements(); - Collection> effectiveSubstatement = parent - .effectiveSubstatements(); + Collection> declaredSubstatement = parent.declaredSubstatements(); + Collection> effectiveSubstatement = parent.effectiveSubstatements(); Collection> allSubstatements = new LinkedList<>(); allSubstatements.addAll(declaredSubstatement); @@ -318,16 +278,19 @@ public final class AugmentUtils { substatementQName = (QName) substatementArgument; if (isSupportedAugmentTarget(substatement) - && nextPathQName.getLocalName().equals( - substatementQName.getLocalName())) { + && nextPathQName.getLocalName().equals(substatementQName.getLocalName())) { return substatement; } } // augment to extension - else if (StmtContextUtils.producesDeclared(substatement, - UnknownStatementImpl.class) + else if (StmtContextUtils.producesDeclared(substatement, UnknownStatementImpl.class) && substatementArgument instanceof String) { - if (nextPathQName.getLocalName().equals(substatementArgument)) { - String message = "Module '"+substatement.getRoot().getStatementArgument()+"': augment into extension '"+substatementArgument+"'."; + + final String nextPathName = nextPathQName.getLocalName(); + + if (nextPathName.equals(substatementArgument) + || nextPathName.equals(substatement.getPublicDefinition().getStatementName().getLocalName())) { + String message = "Module '" + substatement.getRoot().getStatementArgument() + + "': augment into extension '" + substatementArgument + "'."; LOG.warn(message); return substatement; } @@ -337,20 +300,16 @@ public final class AugmentUtils { return null; } - public static boolean isSupportedAugmentTarget( - StatementContextBase substatementCtx) { + public static boolean isSupportedAugmentTarget(StatementContextBase substatementCtx) { /* - * :TODO Substatement must be allowed augment target type e.g. - * Container, etc... and must be not 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 be not 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, + Collection allowedAugmentTargets = substatementCtx.getFromNamespace(ValidationBundlesNamespace.class, ValidationBundleType.SUPPORTED_AUGMENT_TARGETS); // if no allowed target is returned we consider all targets allowed @@ -359,8 +318,7 @@ public final class AugmentUtils { } @Nullable - public static StatementContextBase findCtxOfNodeInRoot( - StatementContextBase rootStmtCtx, + public static StatementContextBase findCtxOfNodeInRoot(StatementContextBase rootStmtCtx, final SchemaNodeIdentifier node) { return findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot()); } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java index 7b9dccf828..f3aa9357af 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnknownStatementImpl.java @@ -33,7 +33,7 @@ public class UnknownStatementImpl extends AbstractDeclaredStatement impl @Override public String parseArgumentValue(final StmtContext ctx, final String value) throws SourceException { - return value; + return value == null ? "" : value; } @Override diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java index 6efbe5ffe7..2f4c55be38 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java @@ -257,8 +257,15 @@ public final class Utils { } if (qNameModule == null) { - throw new IllegalArgumentException("Error in module '" + ctx.getRoot().rawStatementArgument() - + "': can not resolve QNameModule for '" + value + "'."); + if (StmtContextUtils.producesDeclared(ctx, UnknownStatementImpl.class) + && StmtContextUtils.producesDeclared(ctx.getParentContext(), UnknownStatementImpl.class)) { + + qNameModule = getRootModuleQName(ctx); + localName = value; + } else { + throw new IllegalArgumentException("Error in module '" + ctx.getRoot().rawStatementArgument() + + "': can not resolve QNameModule for '" + value + "'."); + } } QNameModule resultQNameModule = qNameModule.getRevision() == null ? QNameModule.create( @@ -376,7 +383,7 @@ public final class Utils { } qNamesFromRoot.add(qname); } else if (nextStmtArgument instanceof String) { - final QName qName = qNameFromArgument(ctx, (String) nextStmtArgument); + QName qName = qNameFromArgument(ctx, ((String) nextStmtArgument)); qNamesFromRoot.add(qName); } else if (StmtContextUtils.producesDeclared(nextStmtCtx, AugmentStatement.class) && nextStmtArgument instanceof SchemaNodeIdentifier) { @@ -449,5 +456,4 @@ public final class Utils { public static SchemaPath SchemaNodeIdentifierToSchemaPath(SchemaNodeIdentifier identifier) { return SchemaPath.create(identifier.getPathFromRoot(), identifier.isAbsolute()); } - } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java index 00737b3feb..220b5d8305 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java @@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement; import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement; import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; @@ -42,13 +43,30 @@ public class UnknownEffectiveStatementImpl extends EffectiveStatementBase, ?> ctx) { super(ctx); - extension = (ExtensionEffectiveStatementImpl) ctx.getAllFromNamespace(ExtensionNamespace.class).get(ctx - .getPublicDefinition().getStatementName()).buildEffective(); + final StmtContext> extensionInit = ctx + .getAllFromNamespace(ExtensionNamespace.class).get(ctx.getPublicDefinition().getStatementName()); + if (extensionInit == null) { + extension = null; + nodeType = ctx.getPublicDefinition().getArgumentName(); + + if (argument() == null || argument().isEmpty()) { + qName = nodeType; + } else { + qName = QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()); + } + } else { + extension = (ExtensionEffectiveStatementImpl) extensionInit.buildEffective(); + nodeType = extension.getQName(); + + if (argument() == null || argument().isEmpty()) { + qName = extension.getQName(); + } else { + qName = QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()); + } + } - nodeType = extension.getQName(); - nodeParameter = argument(); - qName = argument() != null ? QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()) : extension.getQName(); path = Utils.getSchemaPath(ctx); + nodeParameter = argument(); // TODO init other fields (see Bug1412Test) @@ -67,18 +85,17 @@ public class UnknownEffectiveStatementImpl extends EffectiveStatementBase, ?> ctx) { + private void initCopyType(final StmtContext, ?> ctx) { List copyTypesFromOriginal = ctx.getCopyHistory(); - if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) { + if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) { augmenting = true; } - if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) { + if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) { addedByUses = true; } - if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) { + if (copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES_AUGMENTATION)) { addedByUses = augmenting = true; } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java index 4fd15c2cc3..afc6de24e0 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java @@ -46,7 +46,6 @@ public class YangParserSimpleTest { private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); private Set modules; - //TODO: uncomment and run this test once commits are merged @Before public void init() throws Exception { snRev = simpleDateFormat.parse("2013-07-30"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java index b76583b3c5..644514beb7 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/AugmentToExtensionTest.java @@ -41,15 +41,9 @@ public class AugmentToExtensionTest { ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName("my-container"); Set uses = devicesContainer.getUses(); - boolean augmentationIsInContainer = false; for (UsesNode usesNode : uses) { - Set augmentations = usesNode.getAugmentations(); - for (AugmentationSchema augmentationSchema : augmentations) { - augmentationIsInContainer = true; - } + assertTrue(usesNode.getAugmentations().isEmpty()); } - - assertFalse(augmentationIsInContainer); } @Test diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1412Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1412Test.java index 7d51847c02..674900de1b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1412Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug1412Test.java @@ -55,45 +55,42 @@ public class Bug1412Test { assertEquals(expectedQName, action.getQName()); unknownNodes = action.getUnknownSchemaNodes(); - assertEquals(2, unknownNodes.size()); - //FIXME: do fix in UnknownEffectiveStatementImpl class & uncomment once nature of nodes within unknown stmts is - //FIXME: clarified (new statement parser approach) -// assertEquals(4, unknownNodes.size()); -// UnknownSchemaNode info = null; -// UnknownSchemaNode description = null; -// UnknownSchemaNode actionPoint = null; -// UnknownSchemaNode output = null; -// for (UnknownSchemaNode un : unknownNodes) { -// if ("info".equals(un.getNodeType().getLocalName())) { -// info = un; -// } else if ("description".equals(un.getNodeType().getLocalName())) { -// description = un; -// } else if ("actionpoint".equals(un.getNodeType().getLocalName())) { -// actionPoint = un; -// } else if ("output".equals(un.getNodeType().getLocalName())) { -// output = un; -// } -// } -// assertNotNull(info); -// assertNotNull(description); -// assertNotNull(actionPoint); -// assertNotNull(output); - -// expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info"); -// assertEquals(expectedNodeType, info.getNodeType()); -// assertEquals("greeting", info.getNodeParameter()); -// -// expectedNodeType = QName.create(qm, "description"); -// assertEquals(expectedNodeType, description.getNodeType()); -// assertEquals("say greeting", description.getNodeParameter()); -// -// expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint"); -// assertEquals(expectedNodeType, actionPoint.getNodeType()); -// assertEquals("entry", actionPoint.getNodeParameter()); -// -// expectedNodeType = QName.create(qm, "output"); -// assertEquals(expectedNodeType, output.getNodeType()); -// assertEquals("", output.getNodeParameter()); + assertEquals(4, unknownNodes.size()); + UnknownSchemaNode info = null; + UnknownSchemaNode description = null; + UnknownSchemaNode actionPoint = null; + UnknownSchemaNode output = null; + for (UnknownSchemaNode un : unknownNodes) { + if ("info".equals(un.getNodeType().getLocalName())) { + info = un; + } else if ("description".equals(un.getNodeType().getLocalName())) { + description = un; + } else if ("actionpoint".equals(un.getNodeType().getLocalName())) { + actionPoint = un; + } else if ("output".equals(un.getNodeType().getLocalName())) { + output = un; + } + } + assertNotNull(info); + assertNotNull(description); + assertNotNull(actionPoint); + assertNotNull(output); + + expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "info"); + assertEquals(expectedNodeType, info.getNodeType()); + assertEquals("greeting", info.getNodeParameter()); + + expectedNodeType = QName.create(qm, "description"); + assertEquals(expectedNodeType, description.getNodeType()); + assertEquals("say greeting", description.getNodeParameter()); + + expectedNodeType = QName.create("urn:test:bug1412:ext:definitions", "2014-07-25", "actionpoint"); + assertEquals(expectedNodeType, actionPoint.getNodeType()); + assertEquals("entry", actionPoint.getNodeParameter()); + + expectedNodeType = QName.create(qm, "output"); + assertEquals(expectedNodeType, output.getNodeType()); + assertEquals("", output.getNodeParameter()); } } -- 2.36.6