Bug 3670 (part 1/5): Use of new statement parser in yang-maven-plugin 20/25520/3
authorPeter Kajsa <pkajsa@cisco.com>
Thu, 20 Aug 2015 09:21:38 +0000 (11:21 +0200)
committerPeter Kajsa <pkajsa@cisco.com>
Mon, 31 Aug 2015 13:31:18 +0000 (13:31 +0000)
Parser fixes:
- error message fix
- SchemaContextUtilTest fix
- module source path fix
- module source prep.
- import of multiple revision module without revision specifying fix
- minor fixes of BaseStatementImpl class
- adjustment of decimal64 type to original yang parser behavior
- restrictions to leaf return type fix
- range constraints in decimal64 typedef fix
- xpath validation bug fix
- case short hand augmenting fix
- augment order fix
- module dependency sort in effective schema context fix
- get original statement context fix
- statement context copy type fix
- unknown statements QName resolution fix
- extension definition fix in test models
- moduleImport default revision replace
- default revision fix
- sourcePath resolved correctly via NamedFileInputStream

Change-Id: I54656ff50f681bb1357f7df4e606af3c925341eb
Signed-off-by: Peter Kajsa <pkajsa@cisco.com>
65 files changed:
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangStatementParserListenerImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/StmtOrderingNamespace.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/BaseStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/BinarySpecificationImpl.java [deleted file]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/DeviationStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/MustStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/PathStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/RefineStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/TypeStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/TypeUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/WhenStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangStatementSourceImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AnyXmlEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AugmentEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/CaseShorthandImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ChoiceEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ContainerEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveSchemaContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EffectiveStatementBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ExtendedTypeEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/GroupingEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/InputEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafListEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ListEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ModuleEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/OutputEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SubmoduleEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/TypeDefEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UsesEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/BinaryEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/Decimal64SpecificationEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2291Test.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextUtilTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/TestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentProcessTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/MoreRevisionsTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/StmtTestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefConstraintsTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypes2StmtTest.java
yang/yang-parser-impl/src/test/resources/choice-case-type-test-models/augment-monitoring@2013-07-01.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/choice-case-type-test-models/choice-monitoring@2013-07-01.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-05-02.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-06-02.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-08-02.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-09-02.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/testrev.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/stmt-test/constraints/foo.yang [new file with mode: 0644]

index 04f54c624cb0bf587c9b1b817f4d1f542d8eefaf..526f9d1adcbdec90ddc4ee95d33e46510d999a2a 100644 (file)
@@ -9,26 +9,25 @@ package org.opendaylight.yangtools.yang.parser.impl;
 
 import java.util.ArrayList;
 import java.util.List;
-
-import javax.annotation.concurrent.Immutable;
-
+import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
+import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.antlr.v4.runtime.tree.ParseTree;
 import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
 import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParserBaseListener;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
-import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+
+import javax.annotation.concurrent.Immutable;
 
 @Immutable
 public class YangStatementParserListenerImpl extends YangStatementParserBaseListener {
@@ -43,9 +42,6 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
 
     public YangStatementParserListenerImpl(String sourceName) {
         this.sourceName = sourceName;
-        // TODO
-        // this.sourceName = Preconditions.checkNotNull(sourceName, "YangStatementParserListenerImpl#sourceName cannot "
-        //        + "be null");
     }
 
     public void setAttributes(StatementWriter writer, QNameToStatementDefinition stmtDef) {
@@ -61,8 +57,8 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
 
     @Override
     public void enterStatement(YangStatementParser.StatementContext ctx) {
-        final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(),
-                ctx.getStart().getCharPositionInLine());
+        final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx
+                .getStart().getLine(), ctx.getStart().getCharPositionInLine());
         boolean action = true;
         QName identifier;
         for (int i = 0; i < ctx.getChildCount(); i++) {
@@ -71,8 +67,7 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                 try {
                     identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE,
                             ((YangStatementParser.KeywordContext) child).children.get(0).getText());
-                    if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier)
-                            && toBeSkipped.isEmpty()) {
+                    if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
                         if (identifier.equals(Rfc6020Mapping.TYPE.getStatementName())) {
                             isType = true;
                         } else {
@@ -80,10 +75,9 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                         }
                     } else {
                         if (writer.getPhase().equals(ModelProcessingPhase.FULL_DECLARATION)) {
-                            throw new IllegalArgumentException(identifier.getLocalName() + " is not a YANG statement "
-                                    + "or use of extension. Source: " + ref);
-                        }
-                        else {
+                            throw new IllegalArgumentException(identifier.getLocalName() + " is not a YANG statement " +
+                                    "or use of extension. Source: " + ref);
+                        } else {
                             action = false;
                             toBeSkipped.add(((YangStatementParser.KeywordContext) child).children.get(0).getText());
                         }
@@ -95,17 +89,16 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                 try {
                     final String argument = Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child);
                     if (isType) {
-                        if (TypeUtils.isYangTypeBodyStmt(argument)) {
-                            writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, argument), ref);
-                        } else {
-                            writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, Rfc6020Mapping.TYPE
-                                    .getStatementName().getLocalName()), ref);
-                        }
+                            if (TypeUtils.isYangTypeBodyStmtString(argument)) {
+                                writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, argument), ref);
+                            } else {
+                                writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, Rfc6020Mapping
+                                        .TYPE.getStatementName().getLocalName()), ref);
+                            }
                         writer.argumentValue(argument, ref);
                         isType = false;
                     } else if (action) {
-                        writer.argumentValue(
-                                Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
+                        writer.argumentValue(Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
                     } else {
                         action = true;
                     }
@@ -119,16 +112,15 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
 
     @Override
     public void exitStatement(YangStatementParser.StatementContext ctx) {
-        final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(),
-                ctx.getStart().getCharPositionInLine());
+        final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx.getStart().getLine(), ctx
+                .getStart().getCharPositionInLine());
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree child = ctx.getChild(i);
             if (child instanceof YangStatementParser.KeywordContext) {
                 try {
                     String statementName = ((YangStatementParser.KeywordContext) child).children.get(0).getText();
                     QName identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE, statementName);
-                    if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier)
-                            && toBeSkipped.isEmpty()) {
+                    if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
                         writer.endStatement(ref);
                     }
 
index d46e2716a73a4027fed0685c8425fc31187887d5..46cdb16628a66e541dae07331608aba44233bb54 100644 (file)
@@ -88,9 +88,11 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
         ORIGINAL, ADDED_BY_USES, ADDED_BY_AUGMENTATION, ADDED_BY_USES_AUGMENTATION
     }
 
-    TypeOfCopy getTypeOfCopy();
+    List<TypeOfCopy> getCopyHistory();
 
-    void setTypeOfCopy(TypeOfCopy typeOfCopy);
+    void addAllToCopyHistory(List<TypeOfCopy> typeOfCopyList);
+
+    void addToCopyHistory(TypeOfCopy typeOfCopy);
 
     StatementContextBase<?, ?, ?> getOriginalCtx();
 
@@ -98,6 +100,10 @@ public interface StmtContext<A, D extends DeclaredStatement<A>, E extends Effect
 
     boolean isRootContext();
 
+    void setOrder(int order);
+
+    int getOrder();
+
     void setCompletedPhase(ModelProcessingPhase completedPhase);
 
     ModelProcessingPhase getCompletedPhase();
index eccbaca07d4bc14093b6a60b8b17f76e9c4280a5..0c1169a5f99a0a4ef104d7150360a200cb281cda 100644 (file)
@@ -7,42 +7,41 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
+import org.opendaylight.yangtools.yang.common.QName;
 import com.google.common.base.Splitter;
-import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-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.parser.spi.meta.StmtContext.TypeOfCopy;
+import java.util.HashSet;
+import java.util.Set;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
+import com.google.common.base.Predicate;
+import java.util.Collection;
+import com.google.common.base.Function;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 
 public final class StmtContextUtils {
 
     public static final char LIST_KEY_SEPARATOR = ' ';
     private static final Splitter KEY_SPLITTER = Splitter.on(LIST_KEY_SEPARATOR).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();
         }
     };
 
-    public static final Predicate<StmtContext<?, ?, ?>> IS_SUPPORTED_TO_BUILD_EFFECTIVE = new Predicate<StmtContext<?, ?, ?>>() {
+    public static final Predicate<StmtContext<?, ?,?>> IS_SUPPORTED_TO_BUILD_EFFECTIVE = new Predicate<StmtContext<?,?,?>>() {
         @Override
         public boolean apply(StmtContext<?, ?, ?> input) {
             return input.isSupportedToBuildEffective();
@@ -65,7 +64,8 @@ public final class StmtContextUtils {
 
     @SuppressWarnings("unchecked")
     public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(
-            final Iterable<? extends StmtContext<?, ?, ?>> contexts, final Class<DT> declaredType) {
+            final Iterable<? extends StmtContext<?, ?, ?>> contexts,
+            final Class<DT> declaredType) {
         for (StmtContext<?, ?, ?> ctx : contexts) {
             if (producesDeclared(ctx, declaredType)) {
                 return (AT) ctx.getStatementArgument();
@@ -75,8 +75,8 @@ public final class StmtContextUtils {
     }
 
     @SuppressWarnings("unchecked")
-    public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(final StmtContext<?, ?, ?> ctx,
-            final Class<DT> declaredType) {
+    public static final <AT, DT extends DeclaredStatement<AT>> AT firstAttributeOf(
+            final StmtContext<?, ?, ?> ctx, final Class<DT> declaredType) {
 
         if (producesDeclared(ctx, declaredType)) {
             return (AT) ctx.getStatementArgument();
@@ -86,31 +86,34 @@ public final class StmtContextUtils {
     }
 
     @SuppressWarnings("unchecked")
-    public static final <AT, DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstDeclaredSubstatement(
+    public static final <AT,DT extends DeclaredStatement<AT>> StmtContext<AT, ?, ?> findFirstDeclaredSubstatement(
             StmtContext<?, ?, ?> stmtContext, Class<DT> declaredType) {
-        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+                .declaredSubstatements();
         for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
-            if (producesDeclared(subStmtContext, declaredType)) {
+            if (producesDeclared(subStmtContext,declaredType)) {
                 return (StmtContext<AT, ?, ?>) subStmtContext;
             }
         }
         return null;
     }
 
-    public static final StmtContext<?, ?, ?> findFirstDeclaredSubstatement(final StmtContext<?, ?, ?> stmtContext,
-            int startIndex, final Class<? extends DeclaredStatement<?>>... types) {
+    public static final StmtContext<?, ?, ?> findFirstDeclaredSubstatement(
+            final StmtContext<?, ?, ?> stmtContext, int startIndex, final Class<? extends DeclaredStatement<?>>... types) {
 
         if (startIndex >= types.length) {
             return null;
         }
 
-        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+                .declaredSubstatements();
         for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
-            if (producesDeclared(subStmtContext, types[startIndex])) {
+            if (producesDeclared(subStmtContext,types[startIndex])) {
                 if (startIndex + 1 == types.length) {
                     return subStmtContext;
                 } else {
-                    return findFirstDeclaredSubstatement(subStmtContext, ++startIndex, types);
+                    return findFirstDeclaredSubstatement(subStmtContext,
+                            ++startIndex, types);
                 }
             }
         }
@@ -118,15 +121,17 @@ public final class StmtContextUtils {
     }
 
     public static final <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findFirstDeclaredSubstatementOnSublevel(
-            final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType, int sublevel) {
-        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+            final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType,
+            int sublevel) {
+        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+                .declaredSubstatements();
         for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
-            if (sublevel == 1 && producesDeclared(subStmtContext, declaredType)) {
+            if (sublevel == 1 && producesDeclared(subStmtContext,declaredType)) {
                 return subStmtContext;
             } else {
                 if (sublevel > 1) {
-                    StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(subStmtContext, declaredType,
-                            --sublevel);
+                    StmtContext<?, ?, ?> result = findFirstDeclaredSubstatementOnSublevel(
+                            subStmtContext, declaredType, --sublevel);
                     if (result != null) {
                         return result;
                     }
@@ -139,13 +144,15 @@ public final class StmtContextUtils {
     public static final <DT extends DeclaredStatement<?>> StmtContext<?, ?, ?> findDeepFirstDeclaredSubstatement(
             final StmtContext<?, ?, ?> stmtContext, final Class<DT> declaredType) {
 
-        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext.declaredSubstatements();
+        Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements = stmtContext
+                .declaredSubstatements();
 
         for (StmtContext<?, ?, ?> subStmtContext : declaredSubstatements) {
-            if (producesDeclared(subStmtContext, declaredType)) {
+            if (producesDeclared(subStmtContext,declaredType)) {
                 return subStmtContext;
             } else {
-                StmtContext<?, ?, ?> result = findDeepFirstDeclaredSubstatement(subStmtContext, declaredType);
+                StmtContext<?, ?, ?> result = findDeepFirstDeclaredSubstatement(
+                        subStmtContext, declaredType);
                 if (result != null) {
                     return result;
                 }
@@ -157,15 +164,17 @@ public final class StmtContextUtils {
 
     public static final boolean producesDeclared(final StmtContext<?, ?, ?> ctx,
             final Class<? extends DeclaredStatement<?>> type) {
-        return type.isAssignableFrom(ctx.getPublicDefinition().getDeclaredRepresentationClass());
+        return type.isAssignableFrom(ctx.getPublicDefinition()
+                .getDeclaredRepresentationClass());
     }
 
-    public static boolean isInExtensionBody(StmtContext<?, ?, ?> stmtCtx) {
+    public static boolean isInExtensionBody(
+            StmtContext<?,?,?> stmtCtx) {
 
-        StmtContext<?, ?, ?> current = stmtCtx;
-        while (!current.getParentContext().isRootContext()) {
+        StmtContext<?,?,?> current = stmtCtx;
+        while(!current.getParentContext().isRootContext()) {
             current = current.getParentContext();
-            if (producesDeclared(current, UnknownStatementImpl.class)) {
+            if(producesDeclared(current, UnknownStatementImpl.class)) {
                 return true;
             }
         }
@@ -174,24 +183,15 @@ public final class StmtContextUtils {
     }
 
     public static boolean isUnknownStatement(StmtContext<?, ?, ?> stmtCtx) {
-        return producesDeclared(stmtCtx, UnknownStatementImpl.class);
-    }
-
-    public static Set<TypeOfCopy> getCopyTypesFromOriginal(StmtContext<?, ?, ?> ctx) {
-
-        Set<TypeOfCopy> copyTypesFromOriginal = new HashSet<>();
-        StmtContext<?, ?, ?> current = ctx;
-
-        while (current.getOriginalCtx() != null) {
-            copyTypesFromOriginal.add(current.getTypeOfCopy());
-            current = current.getOriginalCtx();
+        if (producesDeclared(stmtCtx, UnknownStatementImpl.class)) {
+            return true;
+        } else {
+            return false;
         }
-
-        return copyTypesFromOriginal;
     }
 
-    public static Collection<SchemaNodeIdentifier> replaceModuleQNameForKey(
-            StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> keyStmtCtx, QNameModule newQNameModule) {
+    public static Collection<SchemaNodeIdentifier> replaceModuleQNameForKey(StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> keyStmtCtx,
+            QNameModule newQNameModule) {
 
         List<String> keyTokens = KEY_SPLITTER.splitToList(keyStmtCtx.rawStatementArgument());
 
@@ -199,7 +199,8 @@ public final class StmtContextUtils {
 
         for (String keyToken : keyTokens) {
             QName keyQName = QName.create(newQNameModule, keyToken);
-            SchemaNodeIdentifier keyIdentifier = SchemaNodeIdentifier.create(false, keyQName);
+            SchemaNodeIdentifier keyIdentifier = SchemaNodeIdentifier
+                    .create(false, keyQName);
             newKeys.add(keyIdentifier);
         }
 
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/StmtOrderingNamespace.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/StmtOrderingNamespace.java
new file mode 100644 (file)
index 0000000..200870a
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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.spi.source;
+
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+
+/**
+ *
+ * Source-specific mapping of prefixes to namespaces
+ *
+ */
+public interface StmtOrderingNamespace extends
+        IdentifierNamespace<Rfc6020Mapping, Integer> {
+
+}
index c8040809941da736e6b7928e629f8dd2a83cf421..fc3b31222e1260c3e77e2d00d47cd1bac6a85782 100644 (file)
@@ -7,8 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
-import java.util.Collection;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
 
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Collection;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
 import com.google.common.collect.ImmutableMap;
@@ -94,6 +98,15 @@ public class CrossSourceStatementReactor {
             return context.buildEffective();
         }
 
+        public SchemaContext buildEffective(List<InputStream> yangInputStreams) throws SourceException, ReactorException {
+
+            for(InputStream yangInputStream : yangInputStreams) {
+                addSource(new YangStatementSourceImpl(yangInputStream));
+            }
+
+            return buildEffective();
+        }
+
     }
 
 
index 6b876c71f607d7f215d0aef2cbad582b2f521aec..8108cd810e6339ac946c7a534cc47538997dc6c6 100644 (file)
@@ -137,8 +137,16 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
     public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
             StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy) throws SourceException {
         RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
-        copy.setTypeOfCopy(typeOfCopy);
-        copy.setOriginalCtx(this);
+
+        copy.addAllToCopyHistory(this.getCopyHistory());
+        copy.addToCopyHistory(typeOfCopy);
+
+        if(this.getOriginalCtx() != null) {
+            copy.setOriginalCtx(this.getOriginalCtx());
+        } else {
+            copy.setOriginalCtx(this);
+        }
+
         return copy;
     }
 
index 24315021f34f5ee879e0b960cad463dd871e429e..a5b7f53dc7fee412769e69df9bc93b221c150464 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
 import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.BinarySpecificationImpl;
 import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import com.google.common.base.Preconditions;
@@ -341,8 +340,6 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
                 return new StatementDefinitionContext<>(new IdentityRefSpecificationImpl.Definition());
             case TypeUtils.INSTANCE_IDENTIFIER:
                 return new StatementDefinitionContext<>(new InstanceIdentifierSpecificationImpl.Definition());
-            case TypeUtils.BINARY:
-                return new StatementDefinitionContext<>(new BinarySpecificationImpl.Definition());
             default:
                 return null;
         }
index 02e37329d81a0675bbffb4f0c402031f103a5e23..83356ed615814456088921510963fd803709a5c8 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
+import java.util.LinkedList;
+
+import java.util.List;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.HashMultimap;
@@ -71,6 +74,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     private final StatementDefinitionContext<A, D, E> definition;
     private final StatementIdentifier identifier;
     private final StatementSourceReference statementDeclSource;
+    private int order = 0;
 
     private Map<StatementIdentifier, StatementContextBase<?, ?, ?>> substatements = new LinkedHashMap<>();
 
@@ -95,7 +99,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     private E effectiveInstance;
 
     private StatementContextBase<?, ?, ?> originalCtx;
-    private TypeOfCopy typeOfCopy = TypeOfCopy.ORIGINAL;
+    private List<TypeOfCopy> copyHistory;
 
     private boolean isSupportedToBuildEffective = true;
 
@@ -110,13 +114,18 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
     }
 
     @Override
-    public TypeOfCopy getTypeOfCopy() {
-        return typeOfCopy;
+    public List<TypeOfCopy> getCopyHistory() {
+        return copyHistory;
+    }
+
+    @Override
+    public void addToCopyHistory(TypeOfCopy typeOfCopy) {
+        this.copyHistory.add(typeOfCopy);
     }
 
     @Override
-    public void setTypeOfCopy(TypeOfCopy typeOfCopy) {
-        this.typeOfCopy = typeOfCopy;
+    public void addAllToCopyHistory(List<TypeOfCopy> typeOfCopyList) {
+        this.copyHistory.addAll(typeOfCopyList);
     }
 
     @Override
@@ -129,6 +138,16 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         this.originalCtx = originalCtx;
     }
 
+    @Override
+    public void setOrder(int order) {
+        this.order = order;
+    }
+
+    @Override
+    public int getOrder() {
+        return order;
+    }
+
     @Override
     public ModelProcessingPhase getCompletedPhase() {
         return completedPhase;
@@ -144,6 +163,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         this.identifier = builder.createIdentifier();
         this.statementDeclSource = builder.getStamementSource();
         this.completedPhase = null;
+        initCopyHistory();
     }
 
     StatementContextBase(StatementContextBase<A, D, E> original) {
@@ -154,6 +174,12 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         this.statementDeclSource = Preconditions.checkNotNull(original.statementDeclSource,
                 "Statement context statementDeclSource cannot be null");
         this.completedPhase = null;
+        initCopyHistory();
+    }
+
+    private void initCopyHistory() {
+        this.copyHistory = new LinkedList<>();
+        this.copyHistory.add(TypeOfCopy.ORIGINAL);
     }
 
     /**
index 76e3a45baa9d5992cc516721ca6a8420ed85e48c..d0a6967f42392cf4fa6c0854060322981d61107b 100644 (file)
@@ -139,8 +139,16 @@ class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Effective
             throws SourceException {
         SubstatementContext<A, D, E> copy = new SubstatementContext<>(this,
                 newQNameModule, newParent, typeOfCopy);
-        copy.setTypeOfCopy(typeOfCopy);
-        copy.setOriginalCtx(this);
+
+        copy.addAllToCopyHistory(this.getCopyHistory());
+        copy.addToCopyHistory(typeOfCopy);
+
+        if(this.getOriginalCtx() != null) {
+            copy.setOriginalCtx(this.getOriginalCtx());
+        } else {
+            copy.setOriginalCtx(this);
+        }
+
         return copy;
     }
 
index ec649af8663a6b31042d8503f31d632d355888d1..f1219b7504eb1b7dff60930ac8dd047084a3422f 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import java.util.Collection;
 import org.slf4j.Logger;
@@ -52,7 +53,7 @@ public class AugmentStatementImpl extends
                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
             return SchemaNodeIdentifier.create(
                     AugmentUtils.parseAugmentPath(ctx, value),
-                    Utils.isXPathAbsolute(value));
+                    Utils.isXPathAbsolute(ctx, value));
         }
 
         @Override
@@ -72,7 +73,7 @@ public class AugmentStatementImpl extends
                 final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
                 throws SourceException {
 
-            if(StmtContextUtils.isInExtensionBody(augmentNode)) {
+            if (StmtContextUtils.isInExtensionBody(augmentNode)) {
                 return;
             }
 
@@ -91,7 +92,10 @@ public class AugmentStatementImpl extends
                             .getAugmentTargetCtx(augmentNode);
 
                     if (augmentTargetCtx == null) {
-                        throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(), augmentNode.getStatementSourceReference());
+                        throw new InferenceException(
+                                "Augment target not found: "
+                                        + augmentNode.getStatementArgument(),
+                                augmentNode.getStatementSourceReference());
                     }
                     if (StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
                         augmentNode.setIsSupportedToBuildEffective(false);
@@ -103,19 +107,37 @@ public class AugmentStatementImpl extends
                     try {
                         AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
                                 augmentTargetCtx);
-                        augmentTargetCtx.addEffectiveSubstatement(augmentSourceCtx);
+                        augmentTargetCtx
+                                .addEffectiveSubstatement(augmentSourceCtx);
+                        updateAugmentOrder(augmentSourceCtx);
                     } catch (SourceException e) {
                         LOG.warn(e.getMessage(), e);
                     }
 
                 }
 
+                private void updateAugmentOrder(
+                        final StatementContextBase<?, ?, ?> augmentSourceCtx) {
+                    Integer currentOrder = augmentSourceCtx
+                            .getFromNamespace(StmtOrderingNamespace.class,
+                                    Rfc6020Mapping.AUGMENT);
+                    if (currentOrder == null) {
+                        currentOrder = 1;
+                    } else {
+                        currentOrder++;
+                    }
+                    augmentSourceCtx.setOrder(currentOrder);
+                    augmentSourceCtx.addToNs(StmtOrderingNamespace.class,
+                            Rfc6020Mapping.AUGMENT, currentOrder);
+                }
+
                 @Override
                 public void prerequisiteFailed(
                         final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
                         throws InferenceException {
-                        throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(),
-                                augmentNode.getStatementSourceReference());
+                    throw new InferenceException("Augment target not found: "
+                            + augmentNode.getStatementArgument(), augmentNode
+                            .getStatementSourceReference());
                 }
             });
         }
index aa4085a5092edbfc8a8bbdc157dbad3fc9b9c965..3a80844b2b17d2f5e8606b5276cba0097ddd9025 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -8,16 +8,15 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
 import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
-import java.util.LinkedList;
-import java.util.List;
 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
@@ -73,7 +72,8 @@ public class BaseStatementImpl extends AbstractDeclaredStatement<QName>
                 final QName baseIdentityQName = baseStmtCtx.getStatementArgument();
                 ModelActionBuilder baseIdentityAction = baseStmtCtx.newInferenceAction(ModelProcessingPhase.STATEMENT_DEFINITION);
                 final Prerequisite<StmtContext<?, ?, ?>> requiresPrereq = baseIdentityAction.requiresCtx(baseStmtCtx, IdentityNamespace.class, baseIdentityQName, ModelProcessingPhase.STATEMENT_DEFINITION);
-                final Prerequisite<?> mutatesPrereq = baseIdentityAction.mutatesCtx(baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
+                final Prerequisite<StmtContext.Mutable<?, ?, ?>> mutatesPrereq = baseIdentityAction.mutatesCtx
+                        (baseParentCtx, ModelProcessingPhase.STATEMENT_DEFINITION);
 
                 baseIdentityAction.apply( new InferenceAction() {
 
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/BinarySpecificationImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/BinarySpecificationImpl.java
deleted file mode 100644 (file)
index 6410b05..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.stmt.rfc6020;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.LengthStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BinaryEffectiveStatementImpl;
-
-public class BinarySpecificationImpl extends AbstractDeclaredStatement<String> implements
-        TypeStatement.BinarySpecification {
-
-    protected BinarySpecificationImpl(StmtContext<String, ?, ?> context) {
-        super(context);
-    }
-
-    public static class Definition extends
-            AbstractStatementSupport<String, BinarySpecification, EffectiveStatement<String, BinarySpecification>> {
-
-        public Definition() {
-            super(Rfc6020Mapping.TYPE);
-        }
-
-        @Override
-        public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return value;
-        }
-
-        @Override
-        public BinarySpecification createDeclared(StmtContext<String, BinarySpecification, ?> ctx) {
-            return new BinarySpecificationImpl(ctx);
-        }
-
-        @Override
-        public EffectiveStatement<String, BinarySpecification> createEffective(
-                StmtContext<String, BinarySpecification, EffectiveStatement<String, BinarySpecification>> ctx) {
-            return new BinaryEffectiveStatementImpl(ctx);
-        }
-    }
-
-    @Nullable
-    @Override
-    public LengthStatement getLength() {
-        return firstDeclared(LengthStatement.class);
-    }
-
-    @Nonnull
-    @Override
-    public String getName() {
-        return argument();
-    }
-}
index 8dea301b7145163b3dab5827f5f5ff9f1378af0b..8ba3ef03acfcb179b9e6b9d7fb615a089ed971e5 100644 (file)
@@ -34,7 +34,7 @@ public class DeviationStatementImpl extends AbstractDeclaredStatement<SchemaNode
 
         @Override public SchemaNodeIdentifier parseArgumentValue(
                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(value));
+            return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(ctx, value));
         }
 
         @Override public DeviationStatement createDeclared(
index c1fc892c0ef359b4c8385b93875b5852dc9969d9..05b74316906d8fc4b16445eb424246d5d092a569 100644 (file)
@@ -9,6 +9,12 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.SOURCE_LINKAGE;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+
+import java.util.Set;
+
+import java.util.Map.Entry;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
 import com.google.common.base.Optional;
 import java.net.URI;
 import java.util.Collection;
@@ -33,7 +39,8 @@ import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdenti
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ImportEffectiveStatementImpl;
 
-public class ImportStatementDefinition extends
+public class ImportStatementDefinition
+        extends
         AbstractStatementSupport<String, ImportStatement, EffectiveStatement<String, ImportStatement>> {
 
     public ImportStatementDefinition() {
@@ -46,7 +53,8 @@ public class ImportStatementDefinition extends
     }
 
     @Override
-    public ImportStatement createDeclared(StmtContext<String, ImportStatement, ?> ctx) {
+    public ImportStatement createDeclared(
+            StmtContext<String, ImportStatement, ?> ctx) {
         return new ImportStatementImpl(ctx);
     }
 
@@ -61,43 +69,94 @@ public class ImportStatementDefinition extends
             final Mutable<String, ImportStatement, EffectiveStatement<String, ImportStatement>> stmt)
             throws SourceException {
         final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt);
-        ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE);
+        ModelActionBuilder importAction = stmt
+                .newInferenceAction(SOURCE_LINKAGE);
         final Prerequisite<StmtContext<?, ?, ?>> imported;
         final Prerequisite<Mutable<?, ?, ?>> linkageTarget;
-        imported = importAction.requiresCtx(stmt, ModuleNamespace.class, impIdentifier, SOURCE_LINKAGE);
+        imported = importAction.requiresCtx(stmt, ModuleNamespace.class,
+                impIdentifier, SOURCE_LINKAGE);
         linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE);
 
-        String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
-        stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, impIdentifier);
-
         importAction.apply(new InferenceAction() {
 
             @Override
             public void apply() throws InferenceException {
-                StmtContext<?, ?, ?> importedModule = imported.get();
-                linkageTarget.get().addToNs(ImportedModuleContext.class, impIdentifier, importedModule);
+                StmtContext<?, ?, ?> importedModule = null;
+                ModuleIdentifier importedModuleIdentifier = null;
+                if (impIdentifier.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP) {
+                    Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> recentModuleEntry = findRecentModule(
+                            impIdentifier,
+                            stmt.getAllFromNamespace(ModuleNamespace.class));
+                    if (recentModuleEntry != null) {
+                        importedModuleIdentifier = recentModuleEntry.getKey();
+                        importedModule = recentModuleEntry.getValue();
+                    }
+                }
+
+                if(importedModule == null || importedModuleIdentifier == null) {
+                    importedModule = imported.get();
+                    importedModuleIdentifier = impIdentifier;
+                }
+
+                linkageTarget.get().addToNs(ImportedModuleContext.class,
+                        importedModuleIdentifier, importedModule);
+                String impPrefix = firstAttributeOf(stmt.declaredSubstatements(),
+                        PrefixStatement.class);
+                stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix,
+                        importedModuleIdentifier);
+            }
+
+            private Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> findRecentModule(
+                    ModuleIdentifier impIdentifier,
+                    Map<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> allModules) {
+
+                ModuleIdentifier recentModuleIdentifier = impIdentifier;
+                Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> recentModuleEntry = null;
+
+                Set<Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>>> moduleEntrySet = allModules
+                        .entrySet();
+                for (Entry<ModuleIdentifier, StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>>> moduleEntry : moduleEntrySet) {
+                    if (moduleEntry.getKey().getName()
+                            .equals(impIdentifier.getName())
+                            && moduleEntry
+                                    .getKey()
+                                    .getRevision()
+                                    .compareTo(
+                                            recentModuleIdentifier
+                                                    .getRevision()) > 0) {
+                        recentModuleIdentifier = moduleEntry.getKey();
+                        recentModuleEntry = moduleEntry;
+                    }
+                }
+
+                return recentModuleEntry;
             }
 
             @Override
-            public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
+            public void prerequisiteFailed(
+                    Collection<? extends Prerequisite<?>> failed)
+                    throws InferenceException {
                 if (failed.contains(imported)) {
-                    throw new InferenceException(String.format("Imported module [%s] was not found.", impIdentifier),
-                            stmt.getStatementSourceReference());
+                    throw new InferenceException(String.format(
+                            "Imported module [%s] was not found.",
+                            impIdentifier), stmt.getStatementSourceReference());
                 }
             }
         });
     }
 
-    private static ModuleIdentifier getImportedModuleIdentifier(Mutable<String, ImportStatement, ?> stmt)
-            throws SourceException {
+    private static ModuleIdentifier getImportedModuleIdentifier(
+            Mutable<String, ImportStatement, ?> stmt) throws SourceException {
 
         String moduleName = stmt.getStatementArgument();
-        Date revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class);
+        Date revision = firstAttributeOf(stmt.declaredSubstatements(),
+                RevisionDateStatement.class);
         if (revision == null) {
             revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP;
         }
 
-        return new ModuleIdentifierImpl(moduleName, Optional.<URI> absent(), Optional.<Date> of(revision));
+        return new ModuleIdentifierImpl(moduleName, Optional.<URI> absent(),
+                Optional.<Date> of(revision));
     }
 
 }
\ No newline at end of file
index 0db8c69f4105c4d6875be7cda19b769e2d644cc3..1768a2d37da70ce0bf2b7904f09649963e08d1c5 100644 (file)
@@ -41,7 +41,7 @@ public class MustStatementImpl extends AbstractDeclaredStatement<RevisionAwareXP
 
         @Override public RevisionAwareXPath parseArgumentValue(
                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
+            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(ctx, value));
         }
 
         @Override public MustStatement createDeclared(
index 990d33ac24bb7890bf5b404ece004d3ff57c00e2..2fc61b472702e9064cf3187f40251b788148a42d 100644 (file)
@@ -36,7 +36,7 @@ public class PathStatementImpl extends AbstractDeclaredStatement<RevisionAwareXP
 
         @Override
         public RevisionAwareXPath parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
+            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(ctx, value));
         }
 
         @Override
index 9c433f20efdf0ebc012cd062cd3b625d0746b0d8..29232ff95656cd651430a89a09c37dc5fcc322f3 100644 (file)
@@ -38,7 +38,7 @@ public class RefineStatementImpl extends AbstractDeclaredStatement<SchemaNodeIde
 
         @Override
         public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(value));
+            return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(ctx, value));
         }
 
         @Override
index 199c6ee897261c31f292628e4a9841ec41a2a3e7..e3a4cf58db00022389b3f4e6da3b2bffef26ec7c 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BinaryEffectiveStatementImpl;
+
 import java.util.Collection;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ExtendedTypeEffectiveStatementImpl;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
@@ -94,6 +95,8 @@ public class TypeStatementImpl extends AbstractDeclaredStatement<String>
                 return new BooleanEffectiveStatementImpl(ctx);
             case TypeUtils.EMPTY:
                 return new EmptyEffectiveStatementImpl(ctx);
+            case TypeUtils.BINARY:
+                return new BinaryEffectiveStatementImpl(ctx);
             default:
                 // :FIXME try to resolve original typedef context here and
                 // return buildEffective of original typedef context
index 9aa2e1d3607139f8076e46054fd8c383634d88aa..6dc11f6d424eeb953f9f1acf1620d2f99cf48a33 100644 (file)
@@ -9,10 +9,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
-
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -24,7 +21,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
@@ -71,9 +67,9 @@ public final class TypeUtils {
     public static final String UINT64 = "uint64";
     public static final String UNION = "union";
 
-    private static final ImmutableSet<String> BUILT_IN_TYPES = initBuiltInTypesSet();
-    private static final ImmutableSet<String> TYPE_BODY_STMTS = initTypeBodyStmtsSet();
-    private static final ImmutableMap<String, TypeDefinition> BASE_TYPES_MAP = initBaseTypesMap();
+    private static final Set<String> BUILT_IN_TYPES = new HashSet<>();
+    public static final Set<String> TYPE_BODY_STMTS = new HashSet<>();
+    public static final Map<String, TypeDefinition<?>> PRIMITIVE_TYPES_MAP = new HashMap<>();
 
     private static final Comparator<TypeDefinition<?>> TYPE_SORT_COMPARATOR = new Comparator<TypeDefinition<?>>() {
         @Override
@@ -87,65 +83,68 @@ public final class TypeUtils {
             return 0;
         }
     };
-
-    private static ImmutableSet<String> initBuiltInTypesSet() {
-
-        final Set<String> builtInTypesInit = new HashSet<>();
-        builtInTypesInit.add(BINARY);
-        builtInTypesInit.add(BITS);
-        builtInTypesInit.add(BOOLEAN);
-        builtInTypesInit.add(DECIMAL64);
-        builtInTypesInit.add(EMPTY);
-        builtInTypesInit.add(ENUMERATION);
-        builtInTypesInit.add(IDENTITY_REF);
-        builtInTypesInit.add(INSTANCE_IDENTIFIER);
-        builtInTypesInit.add(INT8);
-        builtInTypesInit.add(INT16);
-        builtInTypesInit.add(INT32);
-        builtInTypesInit.add(INT64);
-        builtInTypesInit.add(LEAF_REF);
-        builtInTypesInit.add(STRING);
-        builtInTypesInit.add(UINT8);
-        builtInTypesInit.add(UINT16);
-        builtInTypesInit.add(UINT32);
-        builtInTypesInit.add(UINT64);
-        builtInTypesInit.add(UNION);
-
-        return ImmutableSet.copyOf(builtInTypesInit);
-    }
-
-    private static ImmutableSet<String> initTypeBodyStmtsSet() {
-
-        final Set<String> typeBodyStmtsInit = new HashSet<>();
-        typeBodyStmtsInit.add(DECIMAL64);
-        typeBodyStmtsInit.add(ENUMERATION);
-        typeBodyStmtsInit.add(LEAF_REF);
-        typeBodyStmtsInit.add(IDENTITY_REF);
-        typeBodyStmtsInit.add(INSTANCE_IDENTIFIER);
-        typeBodyStmtsInit.add(BITS);
-        typeBodyStmtsInit.add(UNION);
-        typeBodyStmtsInit.add(BINARY);
-
-        return ImmutableSet.copyOf(typeBodyStmtsInit);
-    }
-
-    private static ImmutableMap<String, TypeDefinition> initBaseTypesMap() {
-
-        final Map<String, TypeDefinition> baseTypesMapInit = new HashMap<>();
-        baseTypesMapInit.put(BINARY, BinaryType.getInstance());
-        baseTypesMapInit.put(BOOLEAN, BooleanType.getInstance());
-        baseTypesMapInit.put(EMPTY, EmptyType.getInstance());
-        baseTypesMapInit.put(INT8, Int8.getInstance());
-        baseTypesMapInit.put(INT16, Int16.getInstance());
-        baseTypesMapInit.put(INT32, Int32.getInstance());
-        baseTypesMapInit.put(INT64, Int64.getInstance());
-        baseTypesMapInit.put(STRING, StringType.getInstance());
-        baseTypesMapInit.put(UINT8, Uint8.getInstance());
-        baseTypesMapInit.put(UINT16, Uint16.getInstance());
-        baseTypesMapInit.put(UINT32, Uint32.getInstance());
-        baseTypesMapInit.put(UINT64, Uint64.getInstance());
-
-        return ImmutableMap.copyOf(baseTypesMapInit);
+    static {
+
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,BINARY));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,BITS));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,BOOLEAN));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,DECIMAL64));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,EMPTY));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,ENUMERATION));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,IDENTITY_REF));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INSTANCE_IDENTIFIER));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT8));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT16));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT32));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,INT64));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,LEAF_REF));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,STRING));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT8));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT16));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT32));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UINT64));
+//        BUILT_IN_TYPES.add(QName.create(YangConstants.RFC6020_YANG_MODULE,UNION));
+
+        BUILT_IN_TYPES.add(BINARY);
+        BUILT_IN_TYPES.add(BITS);
+        BUILT_IN_TYPES.add(BOOLEAN);
+        BUILT_IN_TYPES.add(DECIMAL64);
+        BUILT_IN_TYPES.add(EMPTY);
+        BUILT_IN_TYPES.add(ENUMERATION);
+        BUILT_IN_TYPES.add(IDENTITY_REF);
+        BUILT_IN_TYPES.add(INSTANCE_IDENTIFIER);
+        BUILT_IN_TYPES.add(INT8);
+        BUILT_IN_TYPES.add(INT16);
+        BUILT_IN_TYPES.add(INT32);
+        BUILT_IN_TYPES.add(INT64);
+        BUILT_IN_TYPES.add(LEAF_REF);
+        BUILT_IN_TYPES.add(STRING);
+        BUILT_IN_TYPES.add(UINT8);
+        BUILT_IN_TYPES.add(UINT16);
+        BUILT_IN_TYPES.add(UINT32);
+        BUILT_IN_TYPES.add(UINT64);
+        BUILT_IN_TYPES.add(UNION);
+
+        TYPE_BODY_STMTS.add(DECIMAL64);
+        TYPE_BODY_STMTS.add(ENUMERATION);
+        TYPE_BODY_STMTS.add(LEAF_REF);
+        TYPE_BODY_STMTS.add(IDENTITY_REF);
+        TYPE_BODY_STMTS.add(INSTANCE_IDENTIFIER);
+        TYPE_BODY_STMTS.add(BITS);
+        TYPE_BODY_STMTS.add(UNION);
+
+        PRIMITIVE_TYPES_MAP.put(BINARY, BinaryType.getInstance());
+        PRIMITIVE_TYPES_MAP.put(BOOLEAN, BooleanType.getInstance());
+        PRIMITIVE_TYPES_MAP.put(EMPTY, EmptyType.getInstance());
+        PRIMITIVE_TYPES_MAP.put(INT8, Int8.getInstance());
+        PRIMITIVE_TYPES_MAP.put(INT16, Int16.getInstance());
+        PRIMITIVE_TYPES_MAP.put(INT32, Int32.getInstance());
+        PRIMITIVE_TYPES_MAP.put(INT64, Int64.getInstance());
+        PRIMITIVE_TYPES_MAP.put(STRING, StringType.getInstance());
+        PRIMITIVE_TYPES_MAP.put(UINT8, Uint8.getInstance());
+        PRIMITIVE_TYPES_MAP.put(UINT16, Uint16.getInstance());
+        PRIMITIVE_TYPES_MAP.put(UINT32, Uint32.getInstance());
+        PRIMITIVE_TYPES_MAP.put(UINT64, Uint64.getInstance());
     }
 
     private TypeUtils() {
@@ -166,7 +165,7 @@ public final class TypeUtils {
         }
     }
 
-    private static int compareNumbers(Number n1, Number n2) {
+    public static int compareNumbers(Number n1, Number n2) {
 
         final BigDecimal num1 = yangConstraintToBigDecimal(n1);
         final BigDecimal num2 = yangConstraintToBigDecimal(n2);
@@ -292,38 +291,41 @@ public final class TypeUtils {
         return rangeConstraints;
     }
 
-    public static boolean isYangBaseTypeString(String typeName) {
+    public static boolean isBuiltInType(TypeDefinition<?> o1) {
+        return BUILT_IN_TYPES.contains(o1.getQName().getLocalName());
+    }
+
+    public static boolean isYangBuiltInTypeString(String typeName) {
         return BUILT_IN_TYPES.contains(typeName);
     }
 
-    public static boolean isYangTypeBodyStmt(String typeName) {
+    public static boolean isYangPrimitiveTypeString(String typeName) {
+        return PRIMITIVE_TYPES_MAP.containsKey(typeName);
+    }
+
+    public static boolean isYangTypeBodyStmtString(String typeName) {
         return TYPE_BODY_STMTS.contains(typeName);
     }
 
+    public static TypeDefinition<?> getYangPrimitiveTypeFromString(String typeName) {
+        if (PRIMITIVE_TYPES_MAP.containsKey(typeName)) {
+            return PRIMITIVE_TYPES_MAP.get(typeName);
+        }
+        return null;
+    }
+
     public static TypeDefinition<?> getTypeFromEffectiveStatement(EffectiveStatement<?, ?> effectiveStatement) {
         if (effectiveStatement instanceof TypeDefinitionEffectiveBuilder) {
             TypeDefinitionEffectiveBuilder typeDefEffectiveBuilder = (TypeDefinitionEffectiveBuilder) effectiveStatement;
             return typeDefEffectiveBuilder.buildType();
         } else {
-            final String typeName = ((TypeDefinition) effectiveStatement).getQName().getLocalName();
-            return BASE_TYPES_MAP.get(typeName);
-        }
-    }
-
-    public static TypeDefinition<?> getYangBaseTypeFromString(String typeName) {
-
-        if (BASE_TYPES_MAP.containsKey(typeName)) {
-            return BASE_TYPES_MAP.get(typeName);
+            final String typeName = ((TypeDefinition<?>) effectiveStatement).getQName().getLocalName();
+            return PRIMITIVE_TYPES_MAP.get(typeName);
         }
-
-        return null;
     }
 
     public static void sortTypes(List<TypeDefinition<?>> typesInit) {
         Collections.sort(typesInit, TYPE_SORT_COMPARATOR);
     }
 
-    public static boolean isBuiltInType(TypeDefinition<?> o1) {
-        return BUILT_IN_TYPES.contains(o1.getQName().getLocalName());
-    }
 }
index 1d6a8e84ff1e8f28d7fe34f20357d58e11a07ac0..6efbe5ffe776626eaaf72f71e1535659313a607b 100644 (file)
@@ -9,10 +9,10 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
 
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
-
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -22,16 +22,19 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
+
 import javax.annotation.Nullable;
 import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
+
 import org.antlr.v4.runtime.tree.TerminalNode;
 import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.common.YangConstants;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Deviation;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
@@ -43,10 +46,13 @@ import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Relative;
 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
 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.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
 import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
@@ -61,8 +67,7 @@ public final class Utils {
 
     private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
     private static final CharMatcher DOUBLE_QUOTE_MATCHER = CharMatcher.is('"');
-    private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher
-            .is('\'');
+    private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher.is('\'');
 
     public static final QName EMPTY_QNAME = QName.create("empty", "empty");
 
@@ -75,8 +80,8 @@ public final class Utils {
     private Utils() {
     }
 
-    public static Collection<SchemaNodeIdentifier.Relative> transformKeysStringToKeyNodes(StmtContext<?, ?, ?> ctx, String
-            value) {
+    public static Collection<SchemaNodeIdentifier.Relative> transformKeysStringToKeyNodes(StmtContext<?, ?, ?> ctx,
+            String value) {
         Splitter keySplitter = Splitter.on(SEPARATOR).omitEmptyStrings().trimResults();
         List<String> keyTokens = keySplitter.splitToList(value);
 
@@ -89,8 +94,8 @@ public final class Utils {
 
         for (String keyToken : keyTokens) {
 
-            SchemaNodeIdentifier.Relative keyNode = (Relative) SchemaNodeIdentifier.Relative
-                    .create(false, Utils.qNameFromArgument(ctx, keyToken));
+            SchemaNodeIdentifier.Relative keyNode = (Relative) SchemaNodeIdentifier.Relative.create(false,
+                    Utils.qNameFromArgument(ctx, keyToken));
             keyNodes.add(keyNode);
         }
 
@@ -99,26 +104,29 @@ public final class Utils {
 
     public static List<String> splitPathToNodeNames(String path) {
 
-        Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME)
-                .omitEmptyStrings().trimResults();
+        Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME).omitEmptyStrings().trimResults();
         return keySplitter.splitToList(path);
     }
 
-    public static void validateXPath(String path) {
+    public static void validateXPath(final StmtContext<?, ?, ?> ctx, String path) {
 
         final XPath xPath = XPathFactory.newInstance().newXPath();
 
         try {
             xPath.compile(path);
         } catch (XPathExpressionException e) {
-            throw new IllegalArgumentException(
-                    "Argument is not valid XPath string", e);
+            throw new IllegalArgumentException(String.format("Argument %s is not valid XPath string at %s", path, ctx
+                    .getStatementSourceReference().toString()), e);
         }
     }
 
-    public static boolean isXPathAbsolute(String path) {
+    private static String trimSingleLastSlashFromXPath(final String path) {
+        return path.replaceAll("/$", "");
+    }
 
-        validateXPath(path);
+    public static boolean isXPathAbsolute(final StmtContext<?, ?, ?> ctx, String path) {
+
+        validateXPath(ctx, trimSingleLastSlashFromXPath(path));
 
         return path.matches(REGEX_PATH_ABS);
     }
@@ -143,8 +151,8 @@ public final class Utils {
         return null;
     }
 
-    public static boolean isValidStatementDefinition(PrefixToModule prefixes,
-            QNameToStatementDefinition stmtDef, QName identifier) {
+    public static boolean isValidStatementDefinition(PrefixToModule prefixes, QNameToStatementDefinition stmtDef,
+            QName identifier) {
         if (stmtDef.get(identifier) != null) {
             return true;
         } else {
@@ -154,16 +162,11 @@ public final class Utils {
             if (namesParts.length == 2) {
                 String prefix = namesParts[0];
                 String localName = namesParts[1];
-                if (prefixes != null
-                        && prefixes.get(prefix) != null
-                        && stmtDef
-                                .get(new QName(
-                                        YangConstants.RFC6020_YIN_NAMESPACE,
-                                        localName)) != null) {
+                if (prefixes != null && prefixes.get(prefix) != null
+                        && stmtDef.get(new QName(YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
                     return true;
                 } else {
-                    if (stmtDef.get(new QName(
-                            YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
+                    if (stmtDef.get(new QName(YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
                         return true;
                     }
                 }
@@ -172,12 +175,13 @@ public final class Utils {
         return false;
     }
 
-    public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx,
-            String path) {
+    public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx, String path) {
+
+        String trimmedPath = trimSingleLastSlashFromXPath(path);
 
-        validateXPath(path);
+        validateXPath(ctx, trimmedPath);
 
-        List<String> nodeNames = splitPathToNodeNames(path);
+        List<String> nodeNames = splitPathToNodeNames(trimmedPath);
         List<QName> qNames = new ArrayList<>();
 
         for (String nodeName : nodeNames) {
@@ -192,8 +196,7 @@ public final class Utils {
         return qNames;
     }
 
-    public static String stringFromStringContext(
-            final YangStatementParser.ArgumentContext context) {
+    public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {
         StringBuilder sb = new StringBuilder();
         List<TerminalNode> strings = context.STRING();
         if (strings.isEmpty()) {
@@ -236,14 +239,15 @@ public final class Utils {
             prefix = namesParts[0];
             localName = namesParts[1];
             qNameModule = getModuleQNameByPrefix(ctx, prefix);
-            //in case of unknown statement argument, we're not going to parse it
-            if (qNameModule == null && ctx.getPublicDefinition().getDeclaredRepresentationClass().isAssignableFrom
-                    (UnknownStatementImpl.class)) {
+            // in case of unknown statement argument, we're not going to parse it
+            if (qNameModule == null
+                    && ctx.getPublicDefinition().getDeclaredRepresentationClass()
+                    .isAssignableFrom(UnknownStatementImpl.class)) {
                 localName = value;
                 qNameModule = getRootModuleQName(ctx);
             }
-            //:FIXME test and verify this...
-            if(qNameModule == null && ctx.getTypeOfCopy() == StmtContext.TypeOfCopy.ADDED_BY_AUGMENTATION) {
+            if (qNameModule == null
+                    && Iterables.getLast(ctx.getCopyHistory()) == StmtContext.TypeOfCopy.ADDED_BY_AUGMENTATION) {
                 ctx = ctx.getOriginalCtx();
                 qNameModule = getModuleQNameByPrefix(ctx, prefix);
             }
@@ -253,33 +257,24 @@ public final class Utils {
         }
 
         if (qNameModule == null) {
-            throw new IllegalArgumentException("Error in module '"
-                    + ctx.getRoot().rawStatementArgument()
+            throw new IllegalArgumentException("Error in module '" + ctx.getRoot().rawStatementArgument()
                     + "': can not resolve QNameModule for '" + value + "'.");
         }
 
-        QNameModule resultQNameModule = qNameModule.getRevision() == null ? QNameModule
-                .create(qNameModule.getNamespace(),
-                        SimpleDateFormatUtil.DEFAULT_DATE_REV) : qNameModule;
+        QNameModule resultQNameModule = qNameModule.getRevision() == null ? QNameModule.create(
+                qNameModule.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV) : qNameModule;
 
         return QName.create(resultQNameModule, localName);
     }
 
-    public static QNameModule getModuleQNameByPrefix(StmtContext<?, ?, ?> ctx,
-            String prefix) {
+    public static QNameModule getModuleQNameByPrefix(StmtContext<?, ?, ?> ctx, String prefix) {
         QNameModule qNameModule;
-        ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(
-                ImpPrefixToModuleIdentifier.class, prefix);
-        qNameModule = ctx.getFromNamespace(ModuleIdentifierToModuleQName.class,
-                impModIdentifier);
-
-        if (qNameModule == null
-                && StmtContextUtils.producesDeclared(ctx.getRoot(),
-                        SubmoduleStatement.class)) {
-            String moduleName = ctx.getRoot().getFromNamespace(
-                    BelongsToPrefixToModuleName.class, prefix);
-            qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class,
-                    moduleName);
+        ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(ImpPrefixToModuleIdentifier.class, prefix);
+        qNameModule = ctx.getFromNamespace(ModuleIdentifierToModuleQName.class, impModIdentifier);
+
+        if (qNameModule == null && StmtContextUtils.producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) {
+            String moduleName = ctx.getRoot().getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
+            qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
         }
         return qNameModule;
     }
@@ -294,25 +289,19 @@ public final class Utils {
         QNameModule qNameModule = null;
 
         if (StmtContextUtils.producesDeclared(rootCtx, ModuleStatement.class)) {
-            qNameModule = rootCtx.getFromNamespace(
-                    ModuleCtxToModuleQName.class,
-                    rootCtx);
-        } else if (StmtContextUtils.producesDeclared(rootCtx,
-                SubmoduleStatement.class)) {
-            String belongsToModuleName = firstAttributeOf(ctx.getRoot()
-                    .declaredSubstatements(), BelongsToStatement.class);
-            qNameModule = rootCtx.getFromNamespace(
-                    ModuleNameToModuleQName.class, belongsToModuleName);
+            qNameModule = rootCtx.getFromNamespace(ModuleCtxToModuleQName.class, rootCtx);
+        } else if (StmtContextUtils.producesDeclared(rootCtx, SubmoduleStatement.class)) {
+            String belongsToModuleName = firstAttributeOf(ctx.getRoot().declaredSubstatements(),
+                    BelongsToStatement.class);
+            qNameModule = rootCtx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
         }
 
-        return qNameModule.getRevision() == null ? QNameModule.create(
-                qNameModule.getNamespace(),
+        return qNameModule.getRevision() == null ? QNameModule.create(qNameModule.getNamespace(),
                 SimpleDateFormatUtil.DEFAULT_DATE_REV) : qNameModule;
     }
 
     @Nullable
-    public static StatementContextBase<?, ?, ?> findNode(
-            StatementContextBase<?, ?, ?> rootStmtCtx,
+    public static StatementContextBase<?, ?, ?> findNode(StatementContextBase<?, ?, ?> rootStmtCtx,
             final Iterable<QName> path) {
 
         StatementContextBase<?, ?, ?> parent = rootStmtCtx;
@@ -320,8 +309,7 @@ public final class Utils {
         Iterator<QName> 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;
@@ -336,13 +324,11 @@ public final class Utils {
         return null;
     }
 
-    public static StatementContextBase<?, ?, ?> getSubstatementByQName(
-            StatementContextBase<?, ?, ?> parent, QName nextPathQName) {
+    public static StatementContextBase<?, ?, ?> getSubstatementByQName(StatementContextBase<?, ?, ?> parent,
+            QName nextPathQName) {
 
-        Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent
-                .declaredSubstatements();
-        Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent
-                .effectiveSubstatements();
+        Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent.declaredSubstatements();
+        Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent.effectiveSubstatements();
 
         Collection<StatementContextBase<?, ?, ?>> allSubstatements = new LinkedList<>();
         allSubstatements.addAll(declaredSubstatement);
@@ -358,20 +344,18 @@ public final class Utils {
     }
 
     @Nullable
-    public static StatementContextBase<?, ?, ?> findNode(
-            StatementContextBase<?, ?, ?> rootStmtCtx,
+    public static StatementContextBase<?, ?, ?> findNode(StatementContextBase<?, ?, ?> rootStmtCtx,
             final SchemaNodeIdentifier node) {
         return findNode(rootStmtCtx, node.getPathFromRoot());
     }
 
     public static SchemaPath getSchemaPath(StmtContext<?, ?, ?> ctx) {
 
-        if(ctx == null) {
+        if (ctx == null) {
             return null;
         }
 
-        Iterator<StmtContext<?, ?, ?>> iteratorFromRoot = ctx
-                .getStmtContextsFromRoot().iterator();
+        Iterator<StmtContext<?, ?, ?>> iteratorFromRoot = ctx.getStmtContextsFromRoot().iterator();
 
         if (iteratorFromRoot.hasNext()) {
             iteratorFromRoot.next(); // skip root argument
@@ -383,8 +367,10 @@ public final class Utils {
             Object nextStmtArgument = nextStmtCtx.getStatementArgument();
             if (nextStmtArgument instanceof QName) {
                 QName qname = (QName) nextStmtArgument;
-                if (StmtContextUtils.producesDeclared(
-                        nextStmtCtx.getParentContext(), ChoiceStatement.class)
+                if (StmtContextUtils.producesDeclared(nextStmtCtx, UsesStatement.class)) {
+                    continue;
+                }
+                if (StmtContextUtils.producesDeclared(nextStmtCtx.getParentContext(), ChoiceStatement.class)
                         && isSupportedAsShorthandCase(nextStmtCtx)) {
                     qNamesFromRoot.add(qname);
                 }
@@ -392,14 +378,11 @@ public final class Utils {
             } else if (nextStmtArgument instanceof String) {
                 final QName qName = qNameFromArgument(ctx, (String) nextStmtArgument);
                 qNamesFromRoot.add(qName);
-            }
-            else if (StmtContextUtils.producesDeclared(nextStmtCtx,
-                    AugmentStatement.class)
+            } else if (StmtContextUtils.producesDeclared(nextStmtCtx, AugmentStatement.class)
                     && nextStmtArgument instanceof SchemaNodeIdentifier) {
-                addQNamesFromSchemaNodeIdentifierToList(qNamesFromRoot,
-                        (SchemaNodeIdentifier) nextStmtArgument);
-            } else if (nextStmtCtx.getPublicDefinition().getDeclaredRepresentationClass().isAssignableFrom
-                    (UnknownStatementImpl.class)) {
+                addQNamesFromSchemaNodeIdentifierToList(qNamesFromRoot, (SchemaNodeIdentifier) nextStmtArgument);
+            } else if (nextStmtCtx.getPublicDefinition().getDeclaredRepresentationClass()
+                    .isAssignableFrom(UnknownStatementImpl.class)) {
                 qNamesFromRoot.add(nextStmtCtx.getPublicDefinition().getStatementName());
             } else {
                 return SchemaPath.SAME;
@@ -410,22 +393,17 @@ public final class Utils {
         return schemaPath;
     }
 
-    private static boolean isSupportedAsShorthandCase(
-            StmtContext<?, ?, ?> statementCtx) {
+    private static boolean isSupportedAsShorthandCase(StmtContext<?, ?, ?> statementCtx) {
 
-        Collection<?> supportedCaseShorthands = statementCtx.getFromNamespace(
-                ValidationBundlesNamespace.class,
+        Collection<?> supportedCaseShorthands = statementCtx.getFromNamespace(ValidationBundlesNamespace.class,
                 ValidationBundleType.SUPPORTED_CASE_SHORTHANDS);
 
-        return supportedCaseShorthands == null
-                || supportedCaseShorthands.contains(statementCtx
-                        .getPublicDefinition());
+        return supportedCaseShorthands == null || supportedCaseShorthands.contains(statementCtx.getPublicDefinition());
     }
 
-    private static void addQNamesFromSchemaNodeIdentifierToList(
-            List<QName> qNamesFromRoot, SchemaNodeIdentifier augmentTargetPath) {
-        Iterator<QName> augmentTargetPathIterator = augmentTargetPath
-                .getPathFromRoot().iterator();
+    private static void addQNamesFromSchemaNodeIdentifierToList(List<QName> qNamesFromRoot,
+            SchemaNodeIdentifier augmentTargetPath) {
+        Iterator<QName> augmentTargetPathIterator = augmentTargetPath.getPathFromRoot().iterator();
         while (augmentTargetPathIterator.hasNext()) {
             qNamesFromRoot.add(augmentTargetPathIterator.next());
         }
@@ -437,16 +415,14 @@ public final class Utils {
         // suit this
         String deviateUpper = deviate.toUpperCase();
         if (Objects.equals(deviate, deviateUpper)) {
-            throw new IllegalArgumentException(String.format(
-                    "String %s is not valid deviate argument", deviate));
+            throw new IllegalArgumentException(String.format("String %s is not valid deviate argument", deviate));
         }
 
         // but Java enum is uppercase so we cannot use lowercase here
         try {
             return Deviation.Deviate.valueOf(deviateUpper);
         } catch (IllegalArgumentException e) {
-            throw new IllegalArgumentException(String.format(
-                    "String %s is not valid deviate argument", deviate), e);
+            throw new IllegalArgumentException(String.format("String %s is not valid deviate argument", deviate), e);
         }
     }
 
@@ -470,10 +446,8 @@ public final class Utils {
         return status;
     }
 
-    public static SchemaPath SchemaNodeIdentifierToSchemaPath(
-            SchemaNodeIdentifier identifier) {
-        return SchemaPath.create(identifier.getPathFromRoot(),
-                identifier.isAbsolute());
+    public static SchemaPath SchemaNodeIdentifierToSchemaPath(SchemaNodeIdentifier identifier) {
+        return SchemaPath.create(identifier.getPathFromRoot(), identifier.isAbsolute());
     }
 
 }
index 78d60b19326d513d136ef31e525b3a21ab53fa42..20a4417711949ed3d69e3b8a5ae53e20b8c485a5 100644 (file)
@@ -39,7 +39,7 @@ public class WhenStatementImpl extends AbstractDeclaredStatement<RevisionAwareXP
 
         @Override public RevisionAwareXPath parseArgumentValue(
                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
+            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(ctx, value));
         }
 
         @Override public WhenStatement createDeclared(
index ddf81a82922891dea474ea63c97dc615e12d746b..fd990136a0538abe786acd248b047171d767e2e0 100644 (file)
@@ -12,8 +12,9 @@ import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour
 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
 import static org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
 
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.StmtOrderingNamespace;
 
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace;
@@ -141,6 +142,7 @@ public final class YangInferencePipeline {
             .addSupport(new FeatureStatementImpl.Definition())
             .addSupport(new PositionStatementImpl.Definition())
             .addSupport(new ValueStatementImpl.Definition())
+            .addSupport(global(StmtOrderingNamespace.class))
             .build();
 
     public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
index 96746e8b51496a7d7c52172e3d029800e744edea..9bcc6717ed01e3edad2c9388e4ded9492daab15c 100644 (file)
@@ -7,9 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URISyntaxException;
@@ -25,6 +24,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinit
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter;
+import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,13 +40,15 @@ public final class YangStatementSourceImpl implements StatementStreamSource {
     private YangStatementParser.StatementContext statementContext;
     private ParseTreeWalker walker;
     private String sourceName;
+//    private String source;
+//    private InputStream sourceStream;
     private static final Logger LOG = LoggerFactory.getLogger(YangStatementSourceImpl.class);
 
     public YangStatementSourceImpl(final String fileName, boolean isAbsolute) {
         try {
             statementContext = parseYangSource(loadFile(fileName, isAbsolute));
             walker = new ParseTreeWalker();
-            yangStatementModelParser = new YangStatementParserListenerImpl(fileName);
+            yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
         } catch (Exception e) {
             LOG.warn(e.getMessage(), e);
         }
@@ -62,6 +64,17 @@ public final class YangStatementSourceImpl implements StatementStreamSource {
         }
     }
 
+    public YangStatementSourceImpl(SourceIdentifier identifier, YangStatementParser.StatementContext statementContext) {
+        try {
+            this.statementContext = statementContext;
+            this.sourceName = identifier.getName();
+            walker = new ParseTreeWalker();
+            yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
+        } catch (Exception e) {
+            LOG.warn(e.getMessage(), e);
+        }
+    }
+
     @Override
     public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) throws SourceException {
         yangStatementModelParser.setAttributes(writer, stmtDef);
@@ -80,15 +93,46 @@ public final class YangStatementSourceImpl implements StatementStreamSource {
         walker.walk(yangStatementModelParser, statementContext);
     }
 
-    private FileInputStream loadFile(final String fileName, boolean isAbsolute) throws URISyntaxException, FileNotFoundException {
-        return isAbsolute ? new FileInputStream(new File(fileName)) : new FileInputStream(new File(getClass().getResource(fileName).toURI()));
+    private NamedFileInputStream loadFile(final String fileName, boolean isAbsolute) throws URISyntaxException,
+            IOException {
+        //TODO: we need absolute path first!
+        return isAbsolute ? new NamedFileInputStream(new File(fileName), fileName) : new NamedFileInputStream(new File
+                (getClass().getResource(fileName).toURI()), fileName);
+
+//        final File file = new File(fileName);
+//        final ByteSource byteSource = BuilderUtils.fileToByteSource(file);
+//        source = byteSource.asCharSource(Charsets.UTF_8).read();
+//        return isAbsolute ? new NamedFileInputStream(file, fileName) : new NamedFileInputStream(new File
+//                (getClass().getResource(fileName).toURI()), fileName);
     }
 
-    private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException, YangSyntaxErrorException {
+    private YangStatementParser.StatementContext parseYangSource(final InputStream stream) throws IOException,
+            YangSyntaxErrorException {
         final YangStatementLexer lexer = new YangStatementLexer(new ANTLRInputStream(stream));
         final CommonTokenStream tokens = new CommonTokenStream(lexer);
         final YangStatementParser parser = new YangStatementParser(tokens);
-        sourceName = parser.getSourceName();
+
+        if(stream instanceof NamedFileInputStream) {
+            sourceName = stream.toString();
+        } else {
+            sourceName = null;
+        }
+
+//        sourceStream = stream;
+//        sourceName = parser.getSourceName();
+//
+//        if (sourceName == null) {
+//            sourceName = stream.toString();
+//        }
+
         return parser.statement();
     }
+
+    public YangStatementParser.StatementContext getYangAST() {
+        return statementContext;
+    }
+
+//    public InputStream getSourceStream() {
+//        return sourceStream;
+//    }
 }
index ed1e6db53bcf18dd4d85e00a850f730c0cf09150..f69bc0dfde051cd6783f40793e1ef710aab26634 100644 (file)
@@ -7,9 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -37,7 +34,7 @@ public class AnyXmlEffectiveStatementImpl extends
     AnyXmlSchemaNode original;
     ConstraintDefinition constraintsDef;
     boolean augmenting;
-    boolean addedByUses;
+    private boolean addedByUses;
 
     ImmutableList<UnknownSchemaNode> unknownNodes;
 
@@ -55,7 +52,7 @@ public class AnyXmlEffectiveStatementImpl extends
     private void initCopyType(
             StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -67,7 +64,7 @@ public class AnyXmlEffectiveStatementImpl extends
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index 425ab74123d97d1da966b219f6cf3d695b554fb4..9b790100db5ace1d21f567437c83d5de3fba0752 100644 (file)
@@ -59,7 +59,7 @@ public class AugmentEffectiveStatementImpl
         this.namespace = rootModuleQName.getNamespace();
         this.revision = rootModuleQName.getRevision();
 
-        this.order = 1;
+        this.order = ctx.getOrder();
 
         initCopyOf(ctx);
         initSubstatementCollections();
index 8cbd4135906a1253a59c1293f53fe1411b4d6b14..b57ae3c02f4cbe3be63fd2b91af54cb4317707d4 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import java.util.Collection;
 import java.util.HashSet;
@@ -58,7 +56,7 @@ public class CaseEffectiveStatementImpl extends
     private void initCopyType(
             StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -70,7 +68,7 @@ public class CaseEffectiveStatementImpl extends
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index 8554da34dfb3c8e4e2a7b5e9fb4f1a00168c976f..54d927f617b657cb5f4d717a348381d10d7cc6a1 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
 import com.google.common.collect.Iterables;
 import java.util.Collections;
 import java.util.Arrays;
@@ -25,12 +29,23 @@ import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 
-public class CaseShorthandImpl implements ChoiceCaseNode {
+public class CaseShorthandImpl implements ChoiceCaseNode, DerivableSchemaNode {
 
     private final DataSchemaNode caseShorthandNode;
     private final QName qName;
     private final SchemaPath path;
 
+    private final String description;
+    private final String reference;
+    private final Status status;
+
+    private final boolean augmenting;
+    private final boolean addedByUses;
+    ConstraintDefinition constraints;
+    private ChoiceCaseNode original;
+
+    ImmutableList<UnknownSchemaNode> unknownNodes;
+
     public CaseShorthandImpl(DataSchemaNode caseShorthandNode) {
         this.caseShorthandNode = caseShorthandNode;
         this.qName = caseShorthandNode.getQName();
@@ -41,31 +56,40 @@ public class CaseShorthandImpl implements ChoiceCaseNode {
                 .create(Iterables.limit(pathFromRoot,
                         Iterables.size(pathFromRoot) - 1),
                         caseShorthandNodePath.isAbsolute());
+
+        this.description = caseShorthandNode.getDescription();
+        this.reference = caseShorthandNode.getReference();
+        this.status = caseShorthandNode.getStatus();
+
+        this.augmenting = caseShorthandNode.isAugmenting();
+        this.addedByUses = caseShorthandNode.isAddedByUses();
+        this.constraints = caseShorthandNode.getConstraints();
+        this.unknownNodes = ImmutableList.copyOf(caseShorthandNode.getUnknownSchemaNodes());
     }
 
     @Override
     public boolean isAugmenting() {
-        return caseShorthandNode.isAugmenting();
+        return augmenting;
     }
 
     @Override
     public boolean isAddedByUses() {
-        return caseShorthandNode.isAddedByUses();
+        return addedByUses;
     }
 
     @Override
     public boolean isConfiguration() {
-        return caseShorthandNode.isConfiguration();
+        return false;
     }
 
     @Override
     public ConstraintDefinition getConstraints() {
-        return caseShorthandNode.getConstraints();
+        return constraints;
     }
 
     @Override
     public QName getQName() {
-        return caseShorthandNode.getQName();
+        return qName;
     }
 
     @Override
@@ -75,22 +99,22 @@ public class CaseShorthandImpl implements ChoiceCaseNode {
 
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
-        return caseShorthandNode.getUnknownSchemaNodes();
+        return unknownNodes;
     }
 
     @Override
     public String getDescription() {
-        return caseShorthandNode.getDescription();
+        return description;
     }
 
     @Override
     public String getReference() {
-        return caseShorthandNode.getReference();
+        return reference;
     }
 
     @Override
     public Status getStatus() {
-        return caseShorthandNode.getStatus();
+        return status;
     }
 
     @Override
@@ -135,4 +159,59 @@ public class CaseShorthandImpl implements ChoiceCaseNode {
     public Set<AugmentationSchema> getAvailableAugmentations() {
         return Collections.emptySet();
     }
+
+    @Override
+    public Optional<? extends SchemaNode> getOriginal() {
+        return Optional.fromNullable(original);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((qName == null) ? 0 : qName.hashCode());
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        CaseShorthandImpl other = (CaseShorthandImpl) obj;
+        if (qName == null) {
+            if (other.qName != null) {
+                return false;
+            }
+        } else if (!qName.equals(other.qName)) {
+            return false;
+        }
+        if (path == null) {
+            if (other.path != null) {
+                return false;
+            }
+        } else if (!path.equals(other.path)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(
+                CaseShorthandImpl.class.getSimpleName());
+        sb.append("[");
+        sb.append("qname=");
+        sb.append(qName);
+        sb.append("]");
+        return sb.toString();
+    }
+
 }
\ No newline at end of file
index fc87e1bd2af3de51404705a40658fae4eb97ba31..6b3f848ec7f61951b8f96d22e0fe3d2d1dce61a3 100644 (file)
@@ -7,14 +7,15 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
+import java.util.SortedSet;
+import java.util.TreeSet;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.parser.builder.util.Comparators;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import java.util.Collection;
 import java.util.HashSet;
@@ -62,26 +63,27 @@ public class ChoiceEffectiveStatementImpl extends
         this.path = Utils.getSchemaPath(ctx);
         this.constraints = new EffectiveConstraintDefinitionImpl(this);
 
-        initSubstatementCollectionsAndFields();
         initCopyType(ctx);
+        initSubstatementCollectionsAndFields();
     }
 
     private void initCopyType(
             StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> 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;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
@@ -91,7 +93,7 @@ public class ChoiceEffectiveStatementImpl extends
 
         List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
         Set<AugmentationSchema> augmentationsInit = new HashSet<>();
-        Set<ChoiceCaseNode> casesInit = new HashSet<>();
+        SortedSet<ChoiceCaseNode> casesInit = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
 
         boolean configurationInit = false;
         boolean defaultInit = false;
@@ -113,9 +115,16 @@ public class ChoiceEffectiveStatementImpl extends
                     || effectiveStatement instanceof ListSchemaNode
                     || effectiveStatement instanceof LeafListSchemaNode
                     || effectiveStatement instanceof LeafSchemaNode) {
+
+                DataSchemaNode dataSchemaNode = (DataSchemaNode) effectiveStatement;
                 ChoiceCaseNode shorthandCase = new CaseShorthandImpl(
-                        (DataSchemaNode) effectiveStatement);
+                        dataSchemaNode);
                 casesInit.add(shorthandCase);
+
+                if (dataSchemaNode.isAugmenting() == true
+                        && this.augmenting == false) {
+                    resetAugmenting(dataSchemaNode);
+                }
             }
             if (!configurationInit
                     && effectiveStatement instanceof ConfigEffectiveStatementImpl) {
@@ -136,6 +145,25 @@ public class ChoiceEffectiveStatementImpl extends
         this.cases = ImmutableSet.copyOf(casesInit);
     }
 
+    private void resetAugmenting(DataSchemaNode dataSchemaNode) {
+        if (dataSchemaNode instanceof LeafEffectiveStatementImpl) {
+            LeafEffectiveStatementImpl leaf = (LeafEffectiveStatementImpl) dataSchemaNode;
+            leaf.augmenting = false;
+        } else if (dataSchemaNode instanceof ContainerEffectiveStatementImpl) {
+            ContainerEffectiveStatementImpl container = (ContainerEffectiveStatementImpl) dataSchemaNode;
+            container.augmenting = false;
+        } else if (dataSchemaNode instanceof LeafListEffectiveStatementImpl) {
+            LeafListEffectiveStatementImpl leafList = (LeafListEffectiveStatementImpl) dataSchemaNode;
+            leafList.augmenting = false;
+        } else if (dataSchemaNode instanceof ListEffectiveStatementImpl) {
+            ListEffectiveStatementImpl list = (ListEffectiveStatementImpl) dataSchemaNode;
+            list.augmenting = false;
+        } else if (dataSchemaNode instanceof AnyXmlEffectiveStatementImpl) {
+            AnyXmlEffectiveStatementImpl anyXml = (AnyXmlEffectiveStatementImpl) dataSchemaNode;
+            anyXml.augmenting = false;
+        }
+    }
+
     @Override
     public QName getQName() {
         return qname;
index 58b31c72d44ef1824015a97fe5fee71160dbb17c..7f73373a1dc30f8aebe24c8dc97bb4cb2f604028 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableList;
@@ -38,7 +36,7 @@ public class ContainerEffectiveStatementImpl extends
     private final SchemaPath path;
 
     private boolean presence;
-    private boolean augmenting;
+    boolean augmenting;
     private boolean addedByUses;
     private boolean configuration = true;
     private ContainerSchemaNode original;
@@ -62,7 +60,7 @@ public class ContainerEffectiveStatementImpl extends
     private void initCopyType(
             StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -74,7 +72,7 @@ public class ContainerEffectiveStatementImpl extends
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index ff89f81d14b05ea6d86a49df5f2ff5fc9cbd66fb..2f885e788bd620d8d5c23d955541a39edfcb58fc 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
+
 import java.util.HashSet;
 import com.google.common.collect.ImmutableList;
 import java.util.List;
@@ -49,7 +51,10 @@ public class EffectiveSchemaContext extends AbstractEffectiveSchemaContext {
                 modulesInit.add(module);
             }
         }
-        this.modules = ImmutableSet.copyOf(modulesInit);
+
+        Module[] moduleArray = new Module[modulesInit.size()];
+        List<Module> sortedModuleList = ModuleDependencySort.sort(modulesInit.toArray(moduleArray));
+        this.modules = ImmutableSet.copyOf(sortedModuleList);
 
         final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
                 new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER);
index b0a342916656fcf8763365144d3da78b075e709e..5b0c94cc98d9c97b31c63a787375d56950150bcc 100644 (file)
@@ -165,4 +165,19 @@ abstract public class EffectiveStatementBase<A, D extends DeclaredStatement<A>>
         }
         return result;
     }
+
+    protected final <R> R firstSubstatementOfType(Class<?> type,
+            Class<R> returnType) {
+        R result = null;
+        try {
+            result = returnType.cast(Iterables.find(
+                    substatements,
+                    Predicates.and(Predicates.instanceOf(type),
+                            Predicates.instanceOf(returnType))));
+        } catch (NoSuchElementException e) {
+            result = null;
+        }
+        return result;
+    }
+
 }
index bc379501a7116b266b5f33a3200b068b10fbc696..8ae39ae7de07e4fc1ea652865382a2becffb7257 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
@@ -124,8 +123,8 @@ public class ExtendedTypeEffectiveStatementImpl extends EffectiveStatementBase<S
         TypeDefinition<?> baseType;
 
         final QName baseTypeQName = Utils.qNameFromArgument(ctx, ctx.getStatementArgument());
-        if (TypeUtils.isYangBaseTypeString(baseTypeQName.getLocalName())) {
-            baseType = TypeUtils.getYangBaseTypeFromString(baseTypeQName.getLocalName());
+        if (TypeUtils.isYangPrimitiveTypeString(baseTypeQName.getLocalName())) {
+            baseType = TypeUtils.getYangPrimitiveTypeFromString(baseTypeQName.getLocalName());
         } else {
             StmtContext<?, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> baseTypeCtx = ctx
                     .getParentContext().getFromNamespace(TypeNamespace.class, baseTypeQName);
@@ -163,37 +162,39 @@ public class ExtendedTypeEffectiveStatementImpl extends EffectiveStatementBase<S
 
         if (baseType instanceof IntegerTypeDefinition) {
             final IntegerTypeDefinition intType = (IntegerTypeDefinition) TypeUtils
-                    .getYangBaseTypeFromString(baseTypeName);
+                    .getYangPrimitiveTypeFromString(baseTypeName);
             typeConstraints.addRanges(intType.getRangeConstraints());
         } else if (baseType instanceof UnsignedIntegerTypeDefinition) {
             final UnsignedIntegerTypeDefinition uintType = (UnsignedIntegerTypeDefinition) TypeUtils
-                    .getYangBaseTypeFromString(baseTypeName);
+                    .getYangPrimitiveTypeFromString(baseTypeName);
             typeConstraints.addRanges(uintType.getRangeConstraints());
         } else if (baseType instanceof StringTypeDefinition) {
             final StringTypeDefinition stringType = (StringTypeDefinition) TypeUtils
-                    .getYangBaseTypeFromString(baseTypeName);
+                    .getYangPrimitiveTypeFromString(baseTypeName);
             typeConstraints.addLengths(stringType.getLengthConstraints());
             typeConstraints.addPatterns(stringType.getPatternConstraints());
-        } else if (baseType instanceof DecimalTypeDefinition) {
-            final DecimalTypeDefinition decimalType = (DecimalTypeDefinition) TypeUtils
-                    .getYangBaseTypeFromString(baseTypeName);
-            typeConstraints.addRanges(decimalType.getRangeConstraints());
-            typeConstraints.addFractionDigits(decimalType.getFractionDigits());
         } else if (baseType instanceof BinaryTypeDefinition) {
             final BinaryTypeDefinition binaryType = (BinaryTypeDefinition) TypeUtils
-                    .getYangBaseTypeFromString(baseTypeName);
+                    .getYangPrimitiveTypeFromString(baseTypeName);
             typeConstraints.addLengths(binaryType.getLengthConstraints());
         } else if (baseType instanceof TypeDefEffectiveStatementImpl) {
             typeConstraints.addRanges(((TypeDefEffectiveStatementImpl) baseType).getRangeConstraints());
             typeConstraints.addLengths(((TypeDefEffectiveStatementImpl) baseType).getLengthConstraints());
             typeConstraints.addPatterns(((TypeDefEffectiveStatementImpl) baseType).getPatternConstraints());
             typeConstraints.addFractionDigits(((TypeDefEffectiveStatementImpl) baseType).getFractionDigits());
-        } else if (baseType instanceof ExtendedTypeEffectiveStatementImpl) {
-            typeConstraints.addRanges(((ExtendedTypeEffectiveStatementImpl) baseType).getRangeConstraints());
-            typeConstraints.addLengths(((ExtendedTypeEffectiveStatementImpl) baseType).getLengthConstraints());
-            typeConstraints.addPatterns(((ExtendedTypeEffectiveStatementImpl) baseType).getPatternConstraints());
-            typeConstraints.addFractionDigits(((ExtendedTypeEffectiveStatementImpl) baseType).getFractionDigits());
         }
+//        else if (baseType instanceof DecimalTypeDefinition) {
+//            final DecimalTypeDefinition decimalType = (DecimalTypeDefinition) TypeUtils
+//                    .getYangBaseTypeFromString(baseTypeName);
+//            typeConstraints.addRanges(decimalType.getRangeConstraints());
+//            typeConstraints.addFractionDigits(decimalType.getFractionDigits());
+//        }
+//        else if (baseType instanceof ExtendedTypeEffectiveStatementImpl) {
+//            typeConstraints.addRanges(((ExtendedTypeEffectiveStatementImpl) baseType).getRangeConstraints());
+//            typeConstraints.addLengths(((ExtendedTypeEffectiveStatementImpl) baseType).getLengthConstraints());
+//            typeConstraints.addPatterns(((ExtendedTypeEffectiveStatementImpl) baseType).getPatternConstraints());
+//            typeConstraints.addFractionDigits(((ExtendedTypeEffectiveStatementImpl) baseType).getFractionDigits());
+//        }
 
         return typeConstraints;
     }
index e4a5f89db7b3a35b8209a1ae889e6a2f876d3602..17483701607ea4667b896f6547ff2413b49d62f5 100644 (file)
@@ -8,9 +8,6 @@
 
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
@@ -46,7 +43,7 @@ public class GroupingEffectiveStatementImpl extends
     private void initCopyType(
             StmtContext<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
             addedByUses = true;
index 293f0ebd56ff988e0f937c9632e46b21df026daa..6757ba567e9d2fbe344e5b053277964218a3d5cc 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -62,7 +60,7 @@ public class InputEffectiveStatementImpl extends
     private void initCopyType(
             StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -74,7 +72,7 @@ public class InputEffectiveStatementImpl extends
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index 0676661c2f0a7df9a7804604be8aa53e13329b15..7926636dc160e2fc8d8bdf54cb4cb68a627a674b 100644 (file)
@@ -7,9 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
@@ -34,7 +31,7 @@ public class LeafEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<
     private final QName qname;
     private final SchemaPath path;
 
-    private boolean augmenting;
+    boolean augmenting;
     private boolean addedByUses;
     private LeafSchemaNode original;
     private boolean configuration = true;
@@ -58,7 +55,7 @@ public class LeafEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<
     private void initCopyType(
             StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -70,7 +67,7 @@ public class LeafEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index 8840670ea3fb99240708b3a0a06007b7226d9ad3..218e845f6bccdd3c0c730e55688bbc304267a57a 100644 (file)
@@ -7,9 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
@@ -34,7 +31,7 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN
     private final QName qname;
     private final SchemaPath path;
 
-    private boolean augmenting;
+    boolean augmenting;
     private boolean addedByUses;
     private LeafListSchemaNode original;
     private boolean configuration = true;
@@ -60,7 +57,7 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN
     private void initCopyType(
             StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -72,7 +69,7 @@ public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedN
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (LeafListSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index 84451a4c5748e77f82f8d903691a214239883098..1f9644cf0b5c134195633cd4bd8629574793c9cf 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -39,7 +38,7 @@ public class ListEffectiveStatementImpl extends AbstractEffectiveDocumentedDataN
     private final SchemaPath path;
 
     boolean augmenting;
-    boolean addedByUses;
+    private boolean addedByUses;
     ListSchemaNode original;
     boolean configuration = true;
     ConstraintDefinition constraints;
@@ -65,7 +64,7 @@ public class ListEffectiveStatementImpl extends AbstractEffectiveDocumentedDataN
     private void initCopyType(
             StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -77,7 +76,7 @@ public class ListEffectiveStatementImpl extends AbstractEffectiveDocumentedDataN
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index db3f31110a7dbdf42e67d04cb380fd28820b12d1..95f6a15c8d2a35144d533be6688694156bab2d99 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
+import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -27,6 +29,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import java.util.Map;
+import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
 import java.net.URI;
 import java.util.Collection;
@@ -51,12 +54,12 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 public class ModuleEffectiveStatementImpl extends
-        AbstractEffectiveDocumentedNode<String, ModuleStatement>
-        implements Module, Immutable {
+        AbstractEffectiveDocumentedNode<String, ModuleStatement> implements
+        Module, Immutable {
 
     private final QNameModule qNameModule;
     private final String name;
-    private String sourcePath; // TODO fill
+    private String sourcePath;
     private String prefix;
     private String yangVersion;
     private String organization;
@@ -72,7 +75,7 @@ public class ModuleEffectiveStatementImpl extends
     private ImmutableSet<IdentitySchemaNode> identities;
     private ImmutableList<UnknownSchemaNode> unknownNodes;
     private String source;
-    private ImmutableList<EffectiveStatement<?,?>> substatementsOfSubmodules;
+    private ImmutableList<EffectiveStatement<?, ?>> substatementsOfSubmodules;
 
     private ImmutableMap<QName, DataSchemaNode> childNodes;
     private ImmutableSet<GroupingDefinition> groupings;
@@ -111,8 +114,14 @@ public class ModuleEffectiveStatementImpl extends
             }
         }
 
-        // TODO init source, sourcePath
-        source = ctx.getStatementSource().name();
+        if (yangVersion == null) {
+            yangVersion = "1";
+        }
+
+        sourcePath = ((DeclarationInTextSource) ctx
+                .getStatementSourceReference()).getSourceName();
+        // TODO source
+        // source =
 
         initSubmodules(ctx);
         initSubstatementCollections(ctx);
@@ -133,21 +142,25 @@ public class ModuleEffectiveStatementImpl extends
                 .values();
 
         Set<Module> submodulesInit = new HashSet<>();
-        List<EffectiveStatement<?,?>> substatementsOfSubmodulesInit = new LinkedList<>();
+        List<EffectiveStatement<?, ?>> substatementsOfSubmodulesInit = new LinkedList<>();
         for (ModuleIdentifier submoduleIdentifier : includedSubmodules) {
             Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> submoduleCtx = (Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>>) ctx
                     .getFromNamespace(SubmoduleNamespace.class,
                             submoduleIdentifier);
-            SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx.buildEffective();
+            SubmoduleEffectiveStatementImpl submodule = (SubmoduleEffectiveStatementImpl) submoduleCtx
+                    .buildEffective();
             submodulesInit.add(submodule);
-            substatementsOfSubmodulesInit.addAll(submodule.effectiveSubstatements());
+            substatementsOfSubmodulesInit.addAll(submodule
+                    .effectiveSubstatements());
         }
 
         this.submodules = ImmutableSet.copyOf(submodulesInit);
-        this.substatementsOfSubmodules = ImmutableList.copyOf(substatementsOfSubmodulesInit);
+        this.substatementsOfSubmodules = ImmutableList
+                .copyOf(substatementsOfSubmodulesInit);
     }
 
-    private void initSubstatementCollections(StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+    private void initSubstatementCollections(
+            StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
         List<EffectiveStatement<?, ?>> effectiveSubstatements = new LinkedList<>();
 
         effectiveSubstatements.addAll(effectiveSubstatements());
@@ -206,7 +219,9 @@ public class ModuleEffectiveStatementImpl extends
                             dataSchemaNode);
                     mutablePublicChildNodes.add(dataSchemaNode);
                 } else {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+                    throw EffectiveStmtUtils
+                            .createNameCollisionSourceException(ctx,
+                                    effectiveStatement);
                 }
             }
             if (effectiveStatement instanceof UsesNode) {
@@ -214,7 +229,9 @@ public class ModuleEffectiveStatementImpl extends
                 if (!mutableUses.contains(usesNode)) {
                     mutableUses.add(usesNode);
                 } else {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+                    throw EffectiveStmtUtils
+                            .createNameCollisionSourceException(ctx,
+                                    effectiveStatement);
                 }
             }
             if (effectiveStatement instanceof TypeDefEffectiveStatementImpl) {
@@ -223,7 +240,9 @@ public class ModuleEffectiveStatementImpl extends
                 if (!mutableTypeDefinitions.contains(extendedType)) {
                     mutableTypeDefinitions.add(extendedType);
                 } else {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+                    throw EffectiveStmtUtils
+                            .createNameCollisionSourceException(ctx,
+                                    effectiveStatement);
                 }
             }
             if (effectiveStatement instanceof GroupingDefinition) {
@@ -231,14 +250,17 @@ public class ModuleEffectiveStatementImpl extends
                 if (!mutableGroupings.contains(grp)) {
                     mutableGroupings.add(grp);
                 } else {
-                    throw EffectiveStmtUtils.createNameCollisionSourceException(ctx, effectiveStatement);
+                    throw EffectiveStmtUtils
+                            .createNameCollisionSourceException(ctx,
+                                    effectiveStatement);
                 }
             }
         }
 
         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
-        this.imports = ImmutableSet.copyOf(importsInit);
+        this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit,
+                ctx));
         this.notifications = ImmutableSet.copyOf(notificationsInit);
         this.rpcs = ImmutableSet.copyOf(rpcsInit);
         this.deviations = ImmutableSet.copyOf(deviationsInit);
@@ -253,6 +275,30 @@ public class ModuleEffectiveStatementImpl extends
         this.uses = ImmutableSet.copyOf(mutableUses);
     }
 
+    private Set<ModuleImport> resolveModuleImports(
+            Set<ModuleImport> importsInit,
+            StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
+        Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
+        for (ModuleImport moduleImport : importsInit) {
+            if (moduleImport.getRevision().equals(
+                    SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
+                QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx,
+                        moduleImport.getPrefix());
+                if (!impModuleQName.getRevision().equals(
+                        SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
+                    ModuleImport resolvedModuleImport = new ModuleImportImpl(
+                            moduleImport.getModuleName(),
+                            impModuleQName.getRevision(),
+                            moduleImport.getPrefix());
+                    resolvedModuleImports.add(resolvedModuleImport);
+                }
+            } else {
+                resolvedModuleImports.add(moduleImport);
+            }
+        }
+        return resolvedModuleImports;
+    }
+
     @Override
     public String getModuleSourcePath() {
         return sourcePath;
@@ -430,7 +476,8 @@ public class ModuleEffectiveStatementImpl extends
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder(ModuleEffectiveStatementImpl.class.getSimpleName());
+        StringBuilder sb = new StringBuilder(
+                ModuleEffectiveStatementImpl.class.getSimpleName());
         sb.append("[");
         sb.append("name=").append(name);
         sb.append(", namespace=").append(getNamespace());
index 7f8133cad412a15f3c9968abfb53ef05068b4bcd..56d74d17df84f4e437a50f6cb62a8238edccef90 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -62,7 +60,7 @@ public class OutputEffectiveStatementImpl extends
     private void initCopyType(
             StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -74,7 +72,7 @@ public class OutputEffectiveStatementImpl extends
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index 4af5525e95a157de1c43c81f742223343cb69884..b530c55c50c60dbd153cc36364848979644a3d0d 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 
+import org.opendaylight.yangtools.yang.model.util.ModuleImportImpl;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import java.util.LinkedHashSet;
 import java.util.LinkedHashMap;
 import com.google.common.collect.ImmutableMap;
@@ -22,6 +24,7 @@ import java.util.Map;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
+import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier;
 import java.net.URI;
 import java.util.Collection;
@@ -119,8 +122,9 @@ public class SubmoduleEffectiveStatementImpl
             }
         }
 
-        //:TODO init source, sourcePath
-        source = ctx.getStatementSource().name();
+        //:TODO init source
+//        source = ctx.getStatementSource().name();
+        sourcePath = ((DeclarationInTextSource) ctx.getStatementSourceReference()).getSourceName();
 
         initSubmodules(ctx);
         initSubstatementCollections(ctx);
@@ -247,7 +251,7 @@ public class SubmoduleEffectiveStatementImpl
 
         this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
         this.augmentations = ImmutableSet.copyOf(augmentationsInit);
-        this.imports = ImmutableSet.copyOf(importsInit);
+        this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit,ctx));
         this.notifications = ImmutableSet.copyOf(notificationsInit);
         this.rpcs = ImmutableSet.copyOf(rpcsInit);
         this.deviations = ImmutableSet.copyOf(deviationsInit);
@@ -262,6 +266,30 @@ public class SubmoduleEffectiveStatementImpl
         this.uses = ImmutableSet.copyOf(mutableUses);
     }
 
+    private Set<ModuleImport> resolveModuleImports(
+            Set<ModuleImport> importsInit,
+            StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
+        Set<ModuleImport> resolvedModuleImports = new LinkedHashSet<>();
+        for (ModuleImport moduleImport : importsInit) {
+            if (moduleImport.getRevision().equals(
+                    SimpleDateFormatUtil.DEFAULT_DATE_IMP)) {
+                QNameModule impModuleQName = Utils.getModuleQNameByPrefix(ctx,
+                        moduleImport.getPrefix());
+                if (!impModuleQName.getRevision().equals(
+                        SimpleDateFormatUtil.DEFAULT_DATE_REV)) {
+                    ModuleImport resolvedModuleImport = new ModuleImportImpl(
+                            moduleImport.getModuleName(),
+                            impModuleQName.getRevision(),
+                            moduleImport.getPrefix());
+                    resolvedModuleImports.add(resolvedModuleImport);
+                }
+            } else {
+                resolvedModuleImports.add(moduleImport);
+            }
+        }
+        return resolvedModuleImports;
+    }
+
     @Override
     public String getModuleSourcePath() {
         return sourcePath;
index ee0ec2007a91e7ca7f39fd9f7476266bd7b1f7c5..fe9e1389c70f88b58abed5acfddce84866e01e02 100644 (file)
@@ -7,6 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Decimal64SpecificationEffectiveStatementImpl;
+import java.util.ArrayList;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LengthEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.PatternEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.RangeEffectiveStatementImpl;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import java.util.Collections;
@@ -17,7 +25,6 @@ import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 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.TypeStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
@@ -26,12 +33,12 @@ import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType.Builder;
 import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.TypeDefinitionEffectiveBuilder;
 
-public class TypeDefEffectiveStatementImpl extends EffectiveStatementBase<QName, TypedefStatement> implements
+public class TypeDefEffectiveStatementImpl extends
+        EffectiveStatementBase<QName, TypedefStatement> implements
         TypeDefinition<TypeDefinition<?>>, TypeDefinitionEffectiveBuilder {
 
     private final QName qName;
@@ -54,72 +61,132 @@ public class TypeDefEffectiveStatementImpl extends EffectiveStatementBase<QName,
 
     private ExtendedType extendedType = null;
 
-    public TypeDefEffectiveStatementImpl(StmtContext<QName, TypedefStatement, ?> ctx) {
+    public TypeDefEffectiveStatementImpl(
+            StmtContext<QName, TypedefStatement, ?> ctx) {
         super(ctx);
 
         qName = ctx.getStatementArgument();
         path = Utils.getSchemaPath(ctx);
+        baseType = parseBaseTypeFromCtx(ctx);
+
+        EffectiveStatementBase<?, ?> typeEffectiveStmt = firstSubstatementOfType(
+                TypeDefinition.class, EffectiveStatementBase.class);
+
+        ranges = initRanges(typeEffectiveStmt);
+        lengths = initLengths(typeEffectiveStmt);
+        patterns = initPatterns(typeEffectiveStmt);
 
-        ExtendedTypeEffectiveStatementImpl type = null;
+        //due to compatibility problems with original yang parser
+        //:FIXME try to find out better solution
+        if (typeEffectiveStmt.argument().equals(TypeUtils.DECIMAL64)
+                && ranges.isEmpty()) {
+            fractionDigits = null;
+        } else {
+            fractionDigits = initFractionDigits(typeEffectiveStmt);
+        }
 
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
-            if (effectiveStatement instanceof ExtendedTypeEffectiveStatementImpl) {
-                type = ((ExtendedTypeEffectiveStatementImpl) effectiveStatement);
-            }
             if (effectiveStatement instanceof DefaultEffectiveStatementImpl) {
-                defaultValue = ((DefaultEffectiveStatementImpl) effectiveStatement).argument();
+                defaultValue = ((DefaultEffectiveStatementImpl) effectiveStatement)
+                        .argument();
             }
             if (effectiveStatement instanceof UnitsEffectiveStatementImpl) {
-                units = ((UnitsEffectiveStatementImpl) effectiveStatement).argument();
+                units = ((UnitsEffectiveStatementImpl) effectiveStatement)
+                        .argument();
             }
             if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
-                description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
+                description = ((DescriptionEffectiveStatementImpl) effectiveStatement)
+                        .argument();
             }
             if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
-                reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
+                reference = ((ReferenceEffectiveStatementImpl) effectiveStatement)
+                        .argument();
             }
             if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
-                status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
+                status = ((StatusEffectiveStatementImpl) effectiveStatement)
+                        .argument();
             }
         }
+    }
 
-        if (type != null) {
+    private TypeDefinition<?> parseBaseTypeFromCtx(
+            final StmtContext<QName, TypedefStatement, ?> ctx) {
 
-            ranges = ImmutableList.copyOf(type.getRangeConstraints());
-            lengths = ImmutableList.copyOf(type.getLengthConstraints());
-            patterns = ImmutableList.copyOf(type.getPatternConstraints());
-            fractionDigits = type.getFractionDigits();
-        } else {
+        TypeDefinition<?> baseType;
 
-            ranges = Collections.emptyList();
-            lengths = Collections.emptyList();
-            patterns = Collections.emptyList();
-            fractionDigits = null;
+        QName baseTypeQName = Utils.qNameFromArgument(ctx, StmtContextUtils
+                .firstAttributeOf(ctx.declaredSubstatements(),
+                        TypeStatement.class));
+
+        if (TypeUtils.isYangBuiltInTypeString(baseTypeQName.getLocalName())) {
+            baseType = TypeUtils.getYangPrimitiveTypeFromString(baseTypeQName
+                    .getLocalName());
+            if (baseType == null) {
+                baseType = firstSubstatementOfType(TypeDefinition.class);
+
+                //due to compatibility problems with original yang parser
+                //:FIXME try to find out better solution
+                if(baseType instanceof Decimal64SpecificationEffectiveStatementImpl) {
+                    Decimal64SpecificationEffectiveStatementImpl decimal64 = (Decimal64SpecificationEffectiveStatementImpl) baseType;
+                    if(decimal64.isExtended()) {
+                        baseType = decimal64.getBaseType();
+                    }
+                }
+            }
+        } else {
+            StmtContext<?, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> baseTypeCtx = ctx
+                    .getParentContext().getFromNamespace(TypeNamespace.class,
+                            baseTypeQName);
+            baseType = (TypeDefEffectiveStatementImpl) baseTypeCtx
+                    .buildEffective();
         }
 
-        baseType = parseBaseTypeFromCtx(ctx);
+        return baseType;
     }
 
-    private TypeDefinition<?> parseBaseTypeFromCtx(final StmtContext<QName, TypedefStatement, ?> ctx) {
+    protected Integer initFractionDigits(
+            EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+        final FractionDigitsEffectiveStatementImpl fractionDigitsEffStmt = typeEffectiveStmt
+                .firstEffective(FractionDigitsEffectiveStatementImpl.class);
+        return fractionDigitsEffStmt != null ? fractionDigitsEffStmt.argument()
+                : null;
+    }
 
-        TypeDefinition<?> baseType;
+    protected List<RangeConstraint> initRanges(
+            EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+        final RangeEffectiveStatementImpl rangeConstraints = typeEffectiveStmt
+                .firstEffective(RangeEffectiveStatementImpl.class);
+        return rangeConstraints != null ? rangeConstraints.argument()
+                : Collections.<RangeConstraint> emptyList();
+    }
 
-        QName baseTypeQName = Utils.qNameFromArgument(ctx,
-                StmtContextUtils.firstAttributeOf(ctx.declaredSubstatements(), TypeStatement.class));
+    protected List<LengthConstraint> initLengths(
+            EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+        final LengthEffectiveStatementImpl lengthConstraints = typeEffectiveStmt
+                .firstEffective(LengthEffectiveStatementImpl.class);
+        return lengthConstraints != null ? lengthConstraints.argument()
+                : Collections.<LengthConstraint> emptyList();
+    }
 
-        if (TypeUtils.isYangBaseTypeString(baseTypeQName.getLocalName())) {
-            baseType = TypeUtils.getYangBaseTypeFromString(baseTypeQName.getLocalName());
-        } else {
-            StmtContext<?, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> baseTypeCtx = ctx
-                    .getParentContext().getFromNamespace(TypeNamespace.class, baseTypeQName);
-            baseType = (TypeDefEffectiveStatementImpl) baseTypeCtx.buildEffective();
-        }
+    protected List<PatternConstraint> initPatterns(
+            EffectiveStatementBase<?, ?> typeEffectiveStmt) {
+        final List<PatternConstraint> patternConstraints = new ArrayList<>();
 
-        if (baseType == null) {
-            baseType = firstSubstatementOfType(TypeDefinition.class);
+        for (final EffectiveStatement<?, ?> effectiveStatement : typeEffectiveStmt
+                .effectiveSubstatements()) {
+            if (effectiveStatement instanceof PatternEffectiveStatementImpl) {
+                final PatternConstraint pattern = ((PatternEffectiveStatementImpl) effectiveStatement)
+                        .argument();
+
+                if (pattern != null) {
+                    patternConstraints.add(pattern);
+                }
+            }
         }
 
-        return baseType;
+        return !patternConstraints.isEmpty() ? ImmutableList
+                .copyOf(patternConstraints) : Collections
+                .<PatternConstraint> emptyList();
     }
 
     @Override
@@ -193,10 +260,13 @@ public class TypeDefEffectiveStatementImpl extends EffectiveStatementBase<QName,
         Builder extendedTypeBuilder;
         if (baseType instanceof TypeDefinitionEffectiveBuilder) {
             TypeDefinitionEffectiveBuilder typeDefBaseType = (TypeDefinitionEffectiveBuilder) baseType;
-            extendedTypeBuilder = ExtendedType.builder(qName, typeDefBaseType.buildType(),
-                    Optional.fromNullable(description), Optional.fromNullable(reference), path);
+            extendedTypeBuilder = ExtendedType.builder(qName,
+                    typeDefBaseType.buildType(),
+                    Optional.fromNullable(description),
+                    Optional.fromNullable(reference), path);
         } else {
-            extendedTypeBuilder = ExtendedType.builder(qName, baseType, Optional.fromNullable(description),
+            extendedTypeBuilder = ExtendedType.builder(qName, baseType,
+                    Optional.fromNullable(description),
                     Optional.fromNullable(reference), path);
         }
 
index 0493465c190ea5e26c8fc3973964f25ad959957d..00737b3feb3721006c263f91934bcd7d84a85d2a 100644 (file)
@@ -8,9 +8,6 @@
 
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import java.util.Set;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -50,7 +47,7 @@ public class UnknownEffectiveStatementImpl extends EffectiveStatementBase<String
 
         nodeType = extension.getQName();
         nodeParameter = argument();
-        qName = argument() != null ? QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()) : null;
+        qName = argument() != null ? QName.create(Utils.qNameFromArgument(ctx, ctx.getStatementArgument()).getModule(), argument()) : extension.getQName();
         path = Utils.getSchemaPath(ctx);
 
         // TODO init other fields (see Bug1412Test)
@@ -73,7 +70,7 @@ public class UnknownEffectiveStatementImpl extends EffectiveStatementBase<String
     private void initCopyType(
             final StmtContext<String, UnknownStatement<String>, ?> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
 
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_AUGMENTATION)) {
             augmenting = true;
@@ -85,7 +82,7 @@ public class UnknownEffectiveStatementImpl extends EffectiveStatementBase<String
             addedByUses = augmenting = true;
         }
 
-        if (ctx.getTypeOfCopy() != TypeOfCopy.ORIGINAL) {
+        if (ctx.getOriginalCtx() != null) {
             original = (UnknownSchemaNode) ctx.getOriginalCtx().buildEffective();
         }
     }
index bd61e97e1ebe3a17cb48b9a0ddd648c1cc663bf3..9403ca1e6babde17dc2ca90263237b5672e8f6c3 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
-
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
@@ -86,7 +84,7 @@ public class UsesEffectiveStatementImpl extends EffectiveStatementBase<QName, Us
     private void initCopyType(
             StmtContext<QName, UsesStatement, EffectiveStatement<QName, UsesStatement>> ctx) {
 
-        Set<TypeOfCopy> copyTypesFromOriginal = StmtContextUtils.getCopyTypesFromOriginal(ctx);
+        List<TypeOfCopy> copyTypesFromOriginal = ctx.getCopyHistory();
         if(copyTypesFromOriginal.contains(TypeOfCopy.ADDED_BY_USES)) {
             addedByUses = true;
         }
index 5306b32664eb584c154ffb18993ea014939e3851..821edb9fa3ca8e2b39ee3e5b01a7406234c15a11 100644 (file)
@@ -25,7 +25,7 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 public class BinaryEffectiveStatementImpl extends
-        EffectiveStatementBase<String, TypeStatement.BinarySpecification> implements
+        EffectiveStatementBase<String, TypeStatement> implements
         BinaryTypeDefinition {
 
     private static final String DESCRIPTION = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
@@ -40,7 +40,7 @@ public class BinaryEffectiveStatementImpl extends
     private final List<LengthConstraint> lengthConstraints;
 
     public BinaryEffectiveStatementImpl(
-            final StmtContext<String, TypeStatement.BinarySpecification, EffectiveStatement<String, TypeStatement.BinarySpecification>> ctx) {
+            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx) {
         super(ctx);
 
         final LengthConstraint lengthConstraint = new LengthConstraintEffectiveImpl(
index 73d6d34ad09686cad14f4d0b29c12e46c717c8ca..6dddaafa30b9fe70a897e255123ca0670ac95bf0 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
 
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType.Builder;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
-
 import org.opendaylight.yangtools.yang.model.util.Decimal64;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
 import com.google.common.base.Optional;
@@ -31,11 +33,13 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.FractionDigitsEffectiveStatementImpl;
 
 public class Decimal64SpecificationEffectiveStatementImpl extends
-        EffectiveStatementBase<String, TypeStatement.Decimal64Specification> implements DecimalTypeDefinition, TypeDefinitionEffectiveBuilder {
+        EffectiveStatementBase<String, TypeStatement.Decimal64Specification>
+        implements DecimalTypeDefinition, TypeDefinitionEffectiveBuilder {
 
     private static final String UNITS = "";
     private static final BigDecimal DEFAULT_VALUE = null;
-    private static final QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, TypeUtils.DECIMAL64);
+    private static final QName QNAME = QName.create(
+            YangConstants.RFC6020_YANG_MODULE, TypeUtils.DECIMAL64);
 
     private static final String DESCRIPTION = "The decimal64 type represents a subset of the real numbers, which can "
             + "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
@@ -43,39 +47,84 @@ public class Decimal64SpecificationEffectiveStatementImpl extends
             + "'i x 10^-n' where i is an integer64 and n is an integer between 1 and 18, inclusively.";
 
     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.3";
-    private static final BigDecimal MIN_VALUE = new BigDecimal("-922337203685477580.8");
-    private static final BigDecimal MAX_VALUE = new BigDecimal("922337203685477580.7");
+    private static final BigDecimal MIN_VALUE = new BigDecimal(
+            "-922337203685477580.8");
+    private static final BigDecimal MAX_VALUE = new BigDecimal(
+            "922337203685477580.7");
 
     private List<RangeConstraint> rangeConstraints;
     private Integer fractionDigits;
     private SchemaPath path;
+    private QName extendedTypeQName;
 
-    public Decimal64SpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.Decimal64Specification, EffectiveStatement<String, TypeStatement.Decimal64Specification>> ctx) {
-        super(ctx);
+    private ExtendedType extendedType;
+    private final boolean isExtended;
 
-        path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
+    public Decimal64SpecificationEffectiveStatementImpl(
+            StmtContext<String, TypeStatement.Decimal64Specification, EffectiveStatement<String, TypeStatement.Decimal64Specification>> ctx) {
+        super(ctx);
 
         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
             if (effectiveStatement instanceof FractionDigitsEffectiveStatementImpl) {
-                fractionDigits = ((FractionDigitsEffectiveStatementImpl) effectiveStatement).argument();
+                fractionDigits = ((FractionDigitsEffectiveStatementImpl) effectiveStatement)
+                        .argument();
+            }
+        }
+
+        List<RangeConstraint> initRanges = initRanges();
+
+        if (!initRanges.isEmpty() && validateRanges(initRanges)) {
+            isExtended = true;
+            rangeConstraints = ImmutableList.copyOf(initRanges);
+            SchemaPath parentPath = Utils.getSchemaPath(ctx.getParentContext());
+            extendedTypeQName = QName.create(parentPath.getLastComponent().getModule(), QNAME.getLocalName());
+            path = parentPath.createChild(extendedTypeQName);
+        } else {
+            isExtended = false;
+            rangeConstraints = defaultRangeStatements();
+            path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
+        }
+    }
+
+    private boolean validateRanges(List<RangeConstraint> initRanges) {
+        for (RangeConstraint rangeConstraint : initRanges) {
+
+            String maxValueString = rangeConstraint.getMax().toString();
+            String minValueString = rangeConstraint.getMin().toString();
+
+            if ((!maxValueString.equals("max") && new BigDecimal(maxValueString)
+                    .compareTo(MAX_VALUE) > 0)
+                    || (!minValueString.equals("min") && new BigDecimal(
+                            minValueString).compareTo(MIN_VALUE) < 0)) {
+                return false;
             }
         }
-        
-        rangeConstraints = defaultRangeStatements();
+        return true;
+    }
+
+    protected List<RangeConstraint> initRanges() {
+        final RangeEffectiveStatementImpl rangeConstraints = firstEffective(RangeEffectiveStatementImpl.class);
+        return rangeConstraints != null ? rangeConstraints.argument()
+                : Collections.<RangeConstraint> emptyList();
     }
 
     private List<RangeConstraint> defaultRangeStatements() {
 
         final List<RangeConstraint> rangeStmts = new ArrayList<>();
-        final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + MAX_VALUE + ", inclusively.";
+        final String rangeDescription = "Integer values between " + MIN_VALUE
+                + " and " + MAX_VALUE + ", inclusively.";
         final String rangeReference = RangeConstraintEffectiveImpl.DEFAULT_REFERENCE;
 
-        rangeStmts.add(new RangeConstraintEffectiveImpl(MIN_VALUE, MAX_VALUE, Optional.of(rangeDescription), Optional
-                .of(rangeReference)));
+        rangeStmts.add(new RangeConstraintEffectiveImpl(MIN_VALUE, MAX_VALUE,
+                Optional.of(rangeDescription), Optional.of(rangeReference)));
 
         return ImmutableList.copyOf(rangeStmts);
     }
 
+    public boolean isExtended() {
+        return isExtended;
+    }
+
     @Override
     public List<RangeConstraint> getRangeConstraints() {
         return rangeConstraints;
@@ -88,7 +137,14 @@ public class Decimal64SpecificationEffectiveStatementImpl extends
 
     @Override
     public DecimalTypeDefinition getBaseType() {
-        return null;
+        if(isExtended) {
+            if (decimal64Instance == null) {
+                decimal64Instance = Decimal64.create(path, fractionDigits);
+            }
+            return decimal64Instance;
+        } else {
+            return null;
+        }
     }
 
     @Override
@@ -164,20 +220,39 @@ public class Decimal64SpecificationEffectiveStatementImpl extends
 
     @Override
     public String toString() {
-        return Decimal64SpecificationEffectiveStatementImpl.class.getSimpleName() + "[qName=" + QNAME
-                + ", fractionDigits=" + fractionDigits + "]";
+        return Decimal64SpecificationEffectiveStatementImpl.class
+                .getSimpleName()
+                + "[qName="
+                + QNAME
+                + ", fractionDigits="
+                + fractionDigits + "]";
     }
 
     private Decimal64 decimal64Instance = null;
 
     @Override
-    public Decimal64 buildType() {
+    public TypeDefinition<?> buildType() {
 
-        if (decimal64Instance != null) {
+        if (decimal64Instance == null) {
+            decimal64Instance = Decimal64.create(path, fractionDigits);
+        }
+
+        if(!isExtended) {
             return decimal64Instance;
         }
-        decimal64Instance = Decimal64.create(path, fractionDigits);
 
-        return decimal64Instance;
+        if (extendedType != null) {
+            return extendedType;
+        }
+
+        Builder extendedTypeBuilder = ExtendedType.builder(path.getLastComponent(), decimal64Instance, Optional.<String>absent(),
+                Optional.<String>absent(), path);
+
+        extendedTypeBuilder.fractionDigits(fractionDigits);
+        extendedTypeBuilder.ranges(rangeConstraints);
+
+        extendedType = extendedTypeBuilder.build();
+
+        return extendedType;
     }
 }
index 3df9231c6f23a92cd79cd76d9a29a019bfc995a9..03979a1a47b4f9fb0e2a8044176b33fe1ab66a16 100644 (file)
@@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
  */
 public final class ModuleDependencySort {
 
-    private static final Date DEFAULT_REVISION = new Date(0);
+    private static final Date DEFAULT_REVISION = SimpleDateFormatUtil.DEFAULT_DATE_REV;
     private static final Logger LOGGER = LoggerFactory.getLogger(ModuleDependencySort.class);
     private static final Function<Node, Module> TOPOLOGY_FUNCTION = new Function<TopologicalSort.Node, Module>() {
         @Override
index db1278b48abe3851975d32e4e47026ae1bd28fe3..e53afc975d858d9f67c5c47002393586378dd72e 100644 (file)
@@ -436,4 +436,22 @@ public class AugmentTest {
         assertTrue(id.isAugmenting());
     }
 
+    @Test
+    public void caseShortHandAugmentingTest() throws Exception {
+        modules = TestUtils.loadModules(getClass().getResource("/choice-case-type-test-models").toURI());
+
+        Module findModule = TestUtils.findModule(modules, "choice-monitoring");
+
+        ContainerSchemaNode netconf =  (ContainerSchemaNode) findModule.getDataChildByName("netconf-state");
+        ContainerSchemaNode datastores =  (ContainerSchemaNode) netconf.getDataChildByName("datastores");
+        ListSchemaNode datastore =  (ListSchemaNode) datastores.getDataChildByName("datastore");
+        ContainerSchemaNode locks =  (ContainerSchemaNode) datastore.getDataChildByName("locks");
+        ChoiceSchemaNode lockType =  (ChoiceSchemaNode)locks.getDataChildByName("lock-type");
+
+        ChoiceCaseNode leafAugCase = lockType.getCaseNodeByName("leaf-aug-case");
+        assertTrue(leafAugCase.isAugmenting());
+        DataSchemaNode leafAug = leafAugCase.getDataChildByName("leaf-aug-case");
+        assertFalse(leafAug.isAugmenting());
+    }
+
 }
index cc8950d244bd653aa46dec406916a67c4b8ad9b8..3b7bcb60fb1a476c92ecbaeee5f055f169ca8390 100644 (file)
@@ -133,7 +133,7 @@ public class SchemaContextUtilTest {
         assertNotNull(foundNode);
         assertEquals(testNode, foundNode);
 
-        GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+        GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
         testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
                 .getDataChildByName("my-leaf-in-grouping");
 
@@ -235,7 +235,7 @@ public class SchemaContextUtilTest {
         assertNull(testNode);
         assertNull(foundNode);
 
-        GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+        GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
         testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
                 .getDataChildByName("no-leaf-in-grouping");
 
@@ -327,7 +327,7 @@ public class SchemaContextUtilTest {
         assertNotNull(foundNode);
         assertEquals(testNode, foundNode);
 
-        testNode = myModule.getGroupings().iterator().next();
+        testNode = getGroupingByName(myModule,"my-grouping");
 
         path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"));
         foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
@@ -459,7 +459,7 @@ public class SchemaContextUtilTest {
         Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
                 QName.parseRevision("2014-10-07"));
 
-        GroupingDefinition grouping = module.getGroupings().iterator().next();
+        GroupingDefinition grouping = getGroupingByName(module,"my-grouping");
         SchemaNode testNode = grouping.getDataChildByName("my-leaf-in-gouping2");
 
         RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2291Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/Bug2291Test.java
new file mode 100644 (file)
index 0000000..ad6a0dd
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013 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.stmt.retest;
+
+import static org.junit.Assert.assertNotNull;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+import java.io.File;
+import org.junit.Test;
+
+public class Bug2291Test {
+
+    @Test
+    public void testRevisionWithExt() throws Exception {
+        File extdef = new File(getClass().getResource("/bugs/bug2291/bug2291-ext.yang").toURI());
+        File bug = new File(getClass().getResource("/bugs/bug2291/bug2291.yang").toURI());
+        File inet = new File(getClass().getResource("/ietf/ietf-inet-types@2010-09-24.yang").toURI());
+
+        SchemaContext context = TestUtils.parseYangSources(extdef, bug, inet);
+        assertNotNull(context);
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextUtilTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/retest/SchemaContextUtilTest.java
new file mode 100644 (file)
index 0000000..bd614c1
--- /dev/null
@@ -0,0 +1,866 @@
+/*
+ * Copyright (c) 2014 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.stmt.retest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.Int32;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+
+public class SchemaContextUtilTest {
+    @Mock
+    private SchemaContext mockSchemaContext;
+    @Mock
+    private Module mockModule;
+
+    @Test
+    public void testFindDummyData() {
+        MockitoAnnotations.initMocks(this);
+
+        QName qName = QName.create("TestQName");
+        SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+        assertEquals("Should be null. Module TestQName not found", null,
+                SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
+
+        RevisionAwareXPath xPath = new RevisionAwareXPathImpl("/bookstore/book/title", true);
+        assertEquals("Should be null. Module bookstore not found", null,
+                SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
+
+        SchemaNode schemaNode = Int32.getInstance();
+        RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
+        assertEquals("Should be null, Module prefix not found", null,
+                SchemaContextUtil.findDataSchemaNodeForRelativeXPath(mockSchemaContext, mockModule, schemaNode,
+                        xPathRelative));
+
+        assertEquals("Should be null. Module TestQName not found", null,
+                SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName)));
+
+        assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));
+    }
+
+    @Test
+    public void findNodeInSchemaContextTest() throws URISyntaxException, IOException,
+             SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-leaf-in-container");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-leaf-in-container"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        RpcDefinition rpc = getRpcByName(myModule,"my-rpc");
+        testNode = rpc.getInput().getDataChildByName("my-input-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "input"),
+                QName.create(myModule.getQNameModule(), "my-input-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        rpc = getRpcByName(myModule,"my-rpc");
+        testNode = rpc.getOutput().getDataChildByName("my-output-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "output"),
+                QName.create(myModule.getQNameModule(), "my-output-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        NotificationDefinition notification = myModule.getNotifications().iterator().next();
+        testNode = notification.getDataChildByName("my-notification-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+                QName.create(myModule.getQNameModule(), "my-notification-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
+        testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+                .getDataChildByName("my-leaf-in-grouping");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+                QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+                QName.create(myModule.getQNameModule(), "my-leaf-in-grouping"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+                "my-choice-leaf-one");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+                QName.create(myModule.getQNameModule(), "one"),
+                QName.create(myModule.getQNameModule(), "my-choice-leaf-one"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("my-leaf-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "my-leaf-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("my-leaf-list-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "my-leaf-list-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test
+    public void findNodeInSchemaContextTest2() throws URISyntaxException, IOException,
+             SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-leaf-not-in-container");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-leaf-not-in-container"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        RpcDefinition rpc = getRpcByName(myModule,"my-rpc");
+        testNode = rpc.getInput().getDataChildByName("no-input-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "input"),
+                QName.create(myModule.getQNameModule(), "no-input-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        NotificationDefinition notification = myModule.getNotifications().iterator().next();
+        testNode = notification.getDataChildByName("no-notification-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+                QName.create(myModule.getQNameModule(), "no-notification-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        GroupingDefinition grouping = getGroupingByName(myModule,"my-grouping");
+        testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+                .getDataChildByName("no-leaf-in-grouping");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+                QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+                QName.create(myModule.getQNameModule(), "no-leaf-in-grouping"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        testNode = ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+                "no-choice-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+                QName.create(myModule.getQNameModule(), "one"),
+                QName.create(myModule.getQNameModule(), "no-choice-leaf"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("no-leaf-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "no-leaf-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("no-leaf-list-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "no-leaf-list-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+    }
+
+    @Test
+    public void findNodeInSchemaContextTest3() throws URISyntaxException, IOException,
+             SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = myModule.getDataChildByName("my-container");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = getRpcByName(myModule,"my-rpc");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = myModule.getNotifications().iterator().next();
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = getGroupingByName(myModule,"my-grouping");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = myModule.getDataChildByName("my-choice");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container")).getDataChildByName("my-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test
+    public void findParentModuleTest() throws URISyntaxException, IOException,   SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        DataSchemaNode node = myModule.getDataChildByName("my-container");
+
+        Module foundModule = SchemaContextUtil.findParentModule(context, node);
+
+        assertEquals(myModule, foundModule);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findParentModuleIllegalArgumentTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        SchemaContextUtil.findParentModule(mockContext, null);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findParentModuleIllegalArgumentTest2() {
+
+        SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+        SchemaContextUtil.findParentModule(null, mockSchemaNode);
+
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void findParentModuleIllegalStateTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+        Mockito.when(mockSchemaNode.getPath()).thenReturn(null);
+        SchemaContextUtil.findParentModule(mockContext, mockSchemaNode);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeIllegalArgumentTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        SchemaContextUtil.findDataSchemaNode(mockContext, null);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeIllegalArgumentTest2() {
+
+        SchemaPath mockSchemaPath = Mockito.mock(SchemaPath.class);
+        SchemaContextUtil.findDataSchemaNode(null, mockSchemaPath);
+
+    }
+
+    @Test
+    public void findDataSchemaNodeTest() throws URISyntaxException, IOException,  SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+        Module importedModule = context.findModuleByNamespaceAndRevision(new URI("uri:imported-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName("my-imported-container"))
+                .getDataChildByName("my-imported-leaf");
+
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("imp:my-imported-container/imp:my-imported-leaf", true);
+
+        SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+        assertNotNull(foundNode);
+        assertNotNull(testNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test
+    public void findDataSchemaNodeTest2() throws URISyntaxException, IOException,  SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        GroupingDefinition grouping = getGroupingByName(module,"my-grouping");
+        SchemaNode testNode = grouping.getDataChildByName("my-leaf-in-gouping2");
+
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+        SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+        assertNotNull(foundNode);
+        assertNotNull(testNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+
+        SchemaContextUtil.findDataSchemaNode(mockContext, module, null);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest2() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+        SchemaContextUtil.findDataSchemaNode(mockContext, null, xpath);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest3() {
+
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+        SchemaContextUtil.findDataSchemaNode(null, module, xpath);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest4() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping[@con='NULL']/my:my-leaf-in-gouping2",
+                true);
+
+        SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath);
+
+    }
+
+    @Test
+    public void findDataSchemaNodeFromXPathNullTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = Mockito.mock(RevisionAwareXPath.class);
+
+        Mockito.when(xpath.toString()).thenReturn(null);
+        assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+    }
+
+    @Test
+    public void findDataSchemaNodeFromXPathNullTest2() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", false);
+
+        assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+    }
+
+    @Test
+    public void findNodeInSchemaContextGroupingsTest() throws URISyntaxException, IOException,
+              SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        // find grouping in container
+        DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName("my-container");
+        SchemaNode testNode = getGroupingByName(dataContainer, "my-grouping-in-container");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-container"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-container");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-container"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        // find grouping in list
+        dataContainer = (DataNodeContainer) ((DataNodeContainer) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-list");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-list"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        // find grouping in grouping
+        dataContainer = getGroupingByName(myModule, "my-grouping");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-grouping");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-grouping"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-grouping");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-grouping"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        // find grouping in rpc
+        RpcDefinition rpc = getRpcByName(myModule, "my-rpc");
+        for (GroupingDefinition grouping : rpc.getGroupings()) {
+            if (grouping.getQName().getLocalName().equals("my-grouping-in-rpc")) {
+                testNode = grouping;
+            }
+        }
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-rpc"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-rpc");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-rpc"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        // find grouping in output
+        dataContainer = getRpcByName(myModule, "my-rpc").getOutput();
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-output");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "output"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-output"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-output");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-output"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        // find grouping in input
+        dataContainer = getRpcByName(myModule, "my-rpc").getInput();
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-input");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "input"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-input"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-input");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-input"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        // find grouping in notification
+        dataContainer = getNotificationByName(myModule, "my-notification");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-notification");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-notification"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-notification");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-notification"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        // find grouping in case
+        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName(
+                "one").getDataChildByName("my-container-in-case");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-case");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+                QName.create(myModule.getQNameModule(), "one"),
+                QName.create(myModule.getQNameModule(), "my-container-in-case"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-case"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((GroupingDefinition) testNode).getDataChildByName("my-leaf-in-grouping-in-case");
+        path = path.createChild(QName.create(myModule.getQNameModule(), "my-leaf-in-grouping-in-case"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test
+    public void findNodeInSchemaContextGroupingsTest2() throws URISyntaxException, IOException,
+              SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        // find grouping in container
+        DataNodeContainer dataContainer = (DataNodeContainer) myModule.getDataChildByName("my-container");
+        SchemaNode testNode = getGroupingByName(dataContainer, "my-grouping-in-container2");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-container2"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        // find grouping in list
+        dataContainer = (DataNodeContainer) ((DataNodeContainer) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-list2");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-list2"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        // find grouping in grouping
+        dataContainer = getGroupingByName(myModule, "my-grouping");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-grouping2");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-grouping2"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        // find grouping in rpc
+        RpcDefinition rpc = getRpcByName(myModule, "my-rpc");
+        for (GroupingDefinition grouping : rpc.getGroupings()) {
+            if (grouping.getQName().getLocalName().equals("my-grouping-in-rpc2")) {
+                testNode = grouping;
+            }
+        }
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-rpc2"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        // find grouping in output
+        dataContainer = getRpcByName(myModule, "my-rpc").getOutput();
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-output2");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "output"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-output2"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        // find grouping in input
+        dataContainer = getRpcByName(myModule, "my-rpc").getInput();
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-input2");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "input"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-input2"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        // find grouping in notification
+        dataContainer = getNotificationByName(myModule, "my-notification");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-notification2");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-notification2"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        // find grouping in case
+        dataContainer = (DataNodeContainer) ((ChoiceSchemaNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName(
+                "one").getDataChildByName("my-container-in-case");
+        testNode = getGroupingByName(dataContainer, "my-grouping-in-case2");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+                QName.create(myModule.getQNameModule(), "one"),
+                QName.create(myModule.getQNameModule(), "my-container-in-case"),
+                QName.create(myModule.getQNameModule(), "my-grouping-in-case2"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+    }
+
+    private static GroupingDefinition getGroupingByName(final DataNodeContainer dataNodeContainer, final String name) {
+        for (GroupingDefinition grouping : dataNodeContainer.getGroupings()) {
+            if (grouping.getQName().getLocalName().equals(name)) {
+                return grouping;
+            }
+        }
+        return null;
+    }
+
+    private static RpcDefinition getRpcByName(final Module module, final String name) {
+        for (RpcDefinition rpc : module.getRpcs()) {
+            if (rpc.getQName().getLocalName().equals(name)) {
+                return rpc;
+            }
+        }
+        return null;
+    }
+
+    private static NotificationDefinition getNotificationByName(final Module module, final String name) {
+        for (NotificationDefinition notification : module.getNotifications()) {
+            if (notification.getQName().getLocalName().equals(name)) {
+                return notification;
+            }
+        }
+        return null;
+    }
+
+    @Test
+    public void findNodeInSchemaContextTheSameNameOfSiblingsTest() throws URISyntaxException, IOException,
+              SourceException, ReactorException {
+
+        SchemaContext context = TestUtils.parseYangSources("/schema-context-util-test");
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        ChoiceSchemaNode choice = (ChoiceSchemaNode)getRpcByName(myModule,"my-name").getInput().getDataChildByName("my-choice");
+        SchemaNode testNode = choice.getCaseNodeByName("case-two").getDataChildByName("two");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-name"),
+                QName.create(myModule.getQNameModule(), "input"),
+                QName.create(myModule.getQNameModule(), "my-choice"),
+                QName.create(myModule.getQNameModule(), "case-two"),
+                QName.create(myModule.getQNameModule(), "two"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+}
\ No newline at end of file
index 21326d67c838b920c99fc42799aa2c1391597c7e..5878f492aae4bdaa9495c5d4f713423445b33d9b 100644 (file)
@@ -8,6 +8,16 @@
 package org.opendaylight.yangtools.yang.stmt.retest;
 
 import static org.junit.Assert.assertEquals;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
+import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils;
+
 import java.io.File;
 import java.io.InputStream;
 import java.net.URI;
@@ -40,20 +50,25 @@ final class TestUtils {
     private TestUtils() {
     }
 
-    public static Set<Module> loadModules(final URI resourceDirectory) throws SourceException, ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+    public static Set<Module> loadModules(final URI resourceDirectory)
+            throws SourceException, ReactorException {
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
         File[] files = new File(resourceDirectory).listFiles();
 
         for (File file : files) {
-            addSources(reactor, new YangStatementSourceImpl(file.getPath(), true));
+            addSources(reactor, new YangStatementSourceImpl(file.getPath(),
+                    true));
         }
 
         EffectiveSchemaContext ctx = reactor.buildEffective();
         return ctx.getModules();
     }
 
-    public static Set<Module> loadModules(final List<InputStream> streams) throws SourceException, ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+    public static Set<Module> loadModules(final List<InputStream> streams)
+            throws SourceException, ReactorException {
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
         for (InputStream inputStream : streams) {
             addSources(reactor, new YangStatementSourceImpl(inputStream));
         }
@@ -62,14 +77,17 @@ final class TestUtils {
         return ctx.getModules();
     }
 
-    public static Module loadModule(final InputStream stream) throws SourceException, ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+    public static Module loadModule(final InputStream stream)
+            throws SourceException, ReactorException {
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
         addSources(reactor, new YangStatementSourceImpl(stream));
         EffectiveSchemaContext ctx = reactor.buildEffective();
         return ctx.getModules().iterator().next();
     }
 
-    public static Module findModule(final Set<Module> modules, final String moduleName) {
+    public static Module findModule(final Set<Module> modules,
+            final String moduleName) {
         Module result = null;
         for (Module module : modules) {
             if (module.getName().equals(moduleName)) {
@@ -80,7 +98,8 @@ final class TestUtils {
         return result;
     }
 
-    public static ModuleImport findImport(final Set<ModuleImport> imports, final String prefix) {
+    public static ModuleImport findImport(final Set<ModuleImport> imports,
+            final String prefix) {
         ModuleImport result = null;
         for (ModuleImport moduleImport : imports) {
             if (moduleImport.getPrefix().equals(prefix)) {
@@ -91,7 +110,8 @@ final class TestUtils {
         return result;
     }
 
-    public static TypeDefinition<?> findTypedef(final Set<TypeDefinition<?>> typedefs, final String name) {
+    public static TypeDefinition<?> findTypedef(
+            final Set<TypeDefinition<?>> typedefs, final String name) {
         TypeDefinition<?> result = null;
         for (TypeDefinition<?> td : typedefs) {
             if (td.getQName().getLocalName().equals(name)) {
@@ -102,8 +122,9 @@ final class TestUtils {
         return result;
     }
 
-    public static SchemaPath createPath(final boolean absolute, final URI namespace, final Date revision,
-            final String prefix, final String... names) {
+    public static SchemaPath createPath(final boolean absolute,
+            final URI namespace, final Date revision, final String prefix,
+            final String... names) {
         List<QName> path = new ArrayList<>();
         for (String name : names) {
             path.add(QName.create(namespace, revision, name));
@@ -123,18 +144,20 @@ final class TestUtils {
     }
 
     /**
-     * Test if node has augmenting flag set to expected value. In case this is DataNodeContainer/ChoiceNode, check its
-     * child nodes/case nodes too.
+     * Test if node has augmenting flag set to expected value. In case this is
+     * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
      *
      * @param node
      *            node to check
      * @param expected
      *            expected value
      */
-    public static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) {
+    public static void checkIsAugmenting(final DataSchemaNode node,
+            final boolean expected) {
         assertEquals(expected, node.isAugmenting());
         if (node instanceof DataNodeContainer) {
-            for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+            for (DataSchemaNode child : ((DataNodeContainer) node)
+                    .getChildNodes()) {
                 checkIsAugmenting(child, expected);
             }
         } else if (node instanceof ChoiceSchemaNode) {
@@ -145,18 +168,20 @@ final class TestUtils {
     }
 
     /**
-     * Check if node has addedByUses flag set to expected value. In case this is DataNodeContainer/ChoiceNode, check its
-     * child nodes/case nodes too.
+     * Check if node has addedByUses flag set to expected value. In case this is
+     * DataNodeContainer/ChoiceNode, check its child nodes/case nodes too.
      *
      * @param node
      *            node to check
      * @param expected
      *            expected value
      */
-    public static void checkIsAddedByUses(final DataSchemaNode node, final boolean expected) {
+    public static void checkIsAddedByUses(final DataSchemaNode node,
+            final boolean expected) {
         assertEquals(expected, node.isAddedByUses());
         if (node instanceof DataNodeContainer) {
-            for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
+            for (DataSchemaNode child : ((DataNodeContainer) node)
+                    .getChildNodes()) {
                 checkIsAddedByUses(child, expected);
             }
         } else if (node instanceof ChoiceSchemaNode) {
@@ -166,14 +191,16 @@ final class TestUtils {
         }
     }
 
-    public static void checkIsAddedByUses(final GroupingDefinition node, final boolean expected) {
+    public static void checkIsAddedByUses(final GroupingDefinition node,
+            final boolean expected) {
         assertEquals(expected, node.isAddedByUses());
         for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
             checkIsAddedByUses(child, expected);
         }
     }
 
-    public static List<Module> findModules(final Set<Module> modules, final String moduleName) {
+    public static List<Module> findModules(final Set<Module> modules,
+            final String moduleName) {
         List<Module> result = new ArrayList<>();
         for (Module module : modules) {
             if (module.getName().equals(moduleName)) {
@@ -183,10 +210,63 @@ final class TestUtils {
         return result;
     }
 
-    private static void addSources(CrossSourceStatementReactor.BuildAction reactor, YangStatementSourceImpl... sources) {
+    private static void addSources(
+            CrossSourceStatementReactor.BuildAction reactor,
+            YangStatementSourceImpl... sources) {
         for (YangStatementSourceImpl source : sources) {
             reactor.addSource(source);
         }
     }
 
+    public static SchemaContext parseYangSources(
+            StatementStreamSource... sources) throws SourceException,
+            ReactorException {
+
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
+        reactor.addSources(sources);
+
+        return reactor.buildEffective();
+    }
+
+    public static SchemaContext parseYangSources(File... files)
+            throws SourceException, ReactorException, FileNotFoundException {
+
+        StatementStreamSource[] sources = new StatementStreamSource[files.length];
+
+        for (int i = 0; i < files.length; i++) {
+            sources[i] = new YangStatementSourceImpl(new FileInputStream(
+                    files[i]));
+        }
+
+        return parseYangSources(sources);
+    }
+
+    public static SchemaContext parseYangSources(Collection<File> files)
+            throws SourceException, ReactorException, FileNotFoundException {
+        return parseYangSources(files.toArray(new File[files.size()]));
+    }
+
+    public static SchemaContext parseYangSources(String yangSourcesDirectoryPath)
+            throws SourceException, ReactorException, FileNotFoundException,
+            URISyntaxException {
+
+        URL resourceDir = StmtTestUtils.class
+                .getResource(yangSourcesDirectoryPath);
+        File testSourcesDir = new File(resourceDir.toURI());
+
+        return parseYangSources(testSourcesDir.listFiles());
+    }
+
+    public static SchemaContext parseYangSource(String yangSourceFilePath)
+            throws SourceException, ReactorException, FileNotFoundException,
+            URISyntaxException {
+
+        URL resourceFile = StmtTestUtils.class
+                .getResource(yangSourceFilePath);
+        File testSourcesFile = new File(resourceFile.toURI());
+
+        return parseYangSources(testSourcesFile);
+    }
+
 }
index fb6bd84e3389c2054b50707b2967dea90f38d53f..fdc1802e684dad99614b367e5738a15d6bccaecf 100644 (file)
@@ -9,9 +9,18 @@
 package org.opendaylight.yangtools.yang.stmt.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
+import java.net.URISyntaxException;
+
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import java.io.FileNotFoundException;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import com.google.common.collect.ImmutableList;
 import java.net.URI;
 import org.junit.Test;
@@ -247,4 +256,24 @@ public class AugmentProcessTest {
             reactor.addSource(source);
         }
     }
+
+    @Test
+    public void caseShortHandAugmentingTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+
+        SchemaContext context = StmtTestUtils.parseYangSources("/choice-case-type-test-models");
+
+        assertNotNull(context);
+
+        ContainerSchemaNode netconf =  (ContainerSchemaNode) context.getDataChildByName("netconf-state");
+        ContainerSchemaNode datastores =  (ContainerSchemaNode) netconf.getDataChildByName("datastores");
+        ListSchemaNode datastore =  (ListSchemaNode) datastores.getDataChildByName("datastore");
+        ContainerSchemaNode locks =  (ContainerSchemaNode) datastore.getDataChildByName("locks");
+        ChoiceSchemaNode lockType =  (ChoiceSchemaNode)locks.getDataChildByName("lock-type");
+
+        ChoiceCaseNode leafAugCase = lockType.getCaseNodeByName("leaf-aug-case");
+        assertTrue(leafAugCase.isAugmenting());
+        DataSchemaNode leafAug = leafAugCase.getDataChildByName("leaf-aug-case");
+        assertFalse(leafAug.isAugmenting());
+    }
+
 }
index e5d774ff3d94f5ec4c17efea55b088decdd2f2ba..b46e65ebbfa790845239dac378d4264c8c936aac 100644 (file)
@@ -11,8 +11,11 @@ package org.opendaylight.yangtools.yang.stmt.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.util.Set;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
 
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -112,10 +115,21 @@ public class MoreRevisionsTest {
                 .newBuild();
 
         reactor.addSources(TED_20130712, TED_20131021, ISIS_20130712,
-                ISIS_20131021, L3_20130712, L3_20131021, IETF_TYPES, NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
+                ISIS_20131021, L3_20130712, L3_20131021, IETF_TYPES,
+                NETWORK_TOPOLOGY_20130712, NETWORK_TOPOLOGY_20131021);
 
         EffectiveSchemaContext result = reactor.buildEffective();
         assertNotNull(result);
     }
 
+    @Test
+    public void multipleRevisionsTest() throws SourceException,
+            ReactorException, FileNotFoundException, URISyntaxException {
+        for (int i = 0; i < 25; i++) {
+            SchemaContext context = StmtTestUtils
+                    .parseYangSources("/semantic-statement-parser/multiple-revisions");
+            assertNotNull(context);
+        }
+    }
+
 }
index f612850e447d355d9337ee705f9d84c47028ea68..9cbe4d4dbc89b32ec107add21d821eb6a6e436e4 100644 (file)
@@ -8,9 +8,19 @@
 
 package org.opendaylight.yangtools.yang.stmt.test;
 
+import java.net.URISyntaxException;
+
+import java.net.URL;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import java.util.Collection;
@@ -23,7 +33,8 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceIm
 
 public class StmtTestUtils {
 
-    private static final Logger LOG = LoggerFactory.getLogger(StmtTestUtils.class);
+    private static final Logger LOG = LoggerFactory
+            .getLogger(StmtTestUtils.class);
 
     private StmtTestUtils() {
 
@@ -38,7 +49,8 @@ public class StmtTestUtils {
         }
     }
 
-    public static List<Module> findModules(final Set<Module> modules, final String moduleName) {
+    public static List<Module> findModules(final Set<Module> modules,
+            final String moduleName) {
         List<Module> result = new ArrayList<>();
         for (Module module : modules) {
             if (module.getName().equals(moduleName)) {
@@ -71,12 +83,49 @@ public class StmtTestUtils {
             String indent) {
 
         for (DataSchemaNode child : childNodes) {
-            LOG.debug(indent + "Child "
-                    + child.getQName().getLocalName());
+            LOG.debug(indent + "Child " + child.getQName().getLocalName());
             if (child instanceof DataNodeContainer) {
                 printChilds(((DataNodeContainer) child).getChildNodes(), indent
                         + "      ");
             }
         }
     }
+
+    public static SchemaContext parseYangSources(
+            StatementStreamSource... sources) throws SourceException,
+            ReactorException {
+
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+                .newBuild();
+        reactor.addSources(sources);
+
+        return reactor.buildEffective();
+    }
+
+    public static SchemaContext parseYangSources(File... files)
+            throws SourceException, ReactorException, FileNotFoundException {
+
+        StatementStreamSource[] sources = new StatementStreamSource[files.length];
+
+        for (int i = 0; i < files.length; i++) {
+            sources[i] = new YangStatementSourceImpl(new FileInputStream(
+                    files[i]));
+        }
+
+        return parseYangSources(sources);
+    }
+
+    public static SchemaContext parseYangSources(Collection<File> files)
+            throws SourceException, ReactorException, FileNotFoundException {
+        return parseYangSources(files.toArray(new File[files.size()]));
+    }
+
+    public static SchemaContext parseYangSources(String yangSourcesDirectoryPath)
+            throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
+
+        URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath);
+        File testSourcesDir = new File(resourceDir.toURI());
+
+        return parseYangSources(testSourcesDir.listFiles());
+    }
 }
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefConstraintsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/TypedefConstraintsTest.java
new file mode 100644 (file)
index 0000000..263c179
--- /dev/null
@@ -0,0 +1,73 @@
+package org.opendaylight.yangtools.yang.stmt.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
+import org.opendaylight.yangtools.yang.model.util.Decimal64;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.junit.Test;
+
+public class TypedefConstraintsTest {
+
+    @Test
+    public void decimalRangeConstraintsTest() throws SourceException,
+            FileNotFoundException, ReactorException, URISyntaxException {
+        SchemaContext context = StmtTestUtils
+                .parseYangSources("/stmt-test/constraints");
+
+        assertNotNull(context);
+
+        Set<TypeDefinition<?>> typeDefinitions = context.getTypeDefinitions();
+        assertNotNull(typeDefinitions);
+        assertEquals(1, typeDefinitions.size());
+
+        TypeDefinition<?> myDecimal = typeDefinitions.iterator().next();
+
+        assertNotNull(myDecimal);
+        assertTrue(myDecimal instanceof ExtendedType);
+
+        List<RangeConstraint> rangeConstraints = ((ExtendedType) myDecimal)
+                .getRangeConstraints();
+
+        assertNotNull(rangeConstraints);
+        assertEquals(1, rangeConstraints.size());
+
+        DataSchemaNode dataNode = context.getDataChildByName("id-decimal64");
+        assertNotNull(dataNode);
+        assertTrue(dataNode instanceof LeafSchemaNode);
+
+        LeafSchemaNode leafDecimal = (LeafSchemaNode) dataNode;
+        TypeDefinition<?> type = leafDecimal.getType();
+
+        assertTrue(type instanceof ExtendedType);
+        ExtendedType decType = (ExtendedType) type;
+
+        List<RangeConstraint> decRangeConstraints = decType.getRangeConstraints();
+
+        assertEquals(1, decRangeConstraints.size());
+
+        RangeConstraint range = decRangeConstraints.iterator().next();
+        assertEquals(new BigDecimal(1.5), range.getMin());
+        assertEquals(new BigDecimal(5.5), range.getMax());
+
+        assertTrue(decType.getQName().getModule().equals(leafDecimal.getQName().getModule()));
+        assertTrue(decType.getQName().getLocalName().equals(TypeUtils.DECIMAL64));
+        assertTrue(decType.getBaseType() instanceof Decimal64);
+    }
+
+}
index 835eeb13ae4ef8e6e0e19032979c906a874a7386..d6203a555b2c106bd30effe73b9049de99a29071 100644 (file)
@@ -9,6 +9,9 @@ package org.opendaylight.yangtools.yang.stmt.test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+
 import java.net.URI;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -16,7 +19,6 @@ import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.util.BooleanType;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
 import org.opendaylight.yangtools.yang.model.util.Int16;
 import org.opendaylight.yangtools.yang.model.util.Int32;
 import org.opendaylight.yangtools.yang.model.util.Int64;
@@ -68,8 +70,8 @@ public class YangTypes2StmtTest {
 
         final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(lfDecimal);
         assertNotNull(lfDecimalNode);
-        final Decimal64 lfDecimalNodeType = (Decimal64) lfDecimalNode.getType();
-        assertEquals(Decimal64.class, lfDecimalNodeType.getClass());
+        final ExtendedType lfDecimalNodeType = (ExtendedType) lfDecimalNode.getType();
+        assertEquals(ExtendedType.class, lfDecimalNodeType.getClass());
         assertEquals(2, lfDecimalNodeType.getFractionDigits().intValue());
 
         final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(lfInt8);
diff --git a/yang/yang-parser-impl/src/test/resources/choice-case-type-test-models/augment-monitoring@2013-07-01.yang b/yang/yang-parser-impl/src/test/resources/choice-case-type-test-models/augment-monitoring@2013-07-01.yang
new file mode 100644 (file)
index 0000000..5c48c1c
--- /dev/null
@@ -0,0 +1,25 @@
+module augment-monitoring {
+    yang-version 1;
+    namespace "urn:ietf:params:xml:ns:yang:augment-monitoring";
+    prefix "amon";
+
+    import choice-monitoring { prefix nm; }
+
+    revision "2013-07-01" {
+            reference "NO REF";
+    }
+
+    augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type" {
+
+        case anonymous-lock {
+            leaf lock-time {
+                type uint32;
+            }
+        }
+
+        leaf leaf-aug-case {
+            type string;
+        }
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/choice-case-type-test-models/choice-monitoring@2013-07-01.yang b/yang/yang-parser-impl/src/test/resources/choice-case-type-test-models/choice-monitoring@2013-07-01.yang
new file mode 100644 (file)
index 0000000..03a518c
--- /dev/null
@@ -0,0 +1,30 @@
+module choice-monitoring {
+  yang-version 1;
+  namespace "urn:ietf:params:xml:ns:yang:choice-monitoring";
+  prefix "ncm";
+
+  revision 2013-07-01 {
+  }
+
+  container netconf-state {
+    config false;
+
+    container datastores {
+      list datastore {
+        key name;
+
+        leaf name {
+          type string;
+        }
+        container locks {
+          choice lock-type {
+
+            case original-lock {
+            }
+            
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev.yang
new file mode 100644 (file)
index 0000000..9be77d0
--- /dev/null
@@ -0,0 +1,13 @@
+module importedrevtest {
+    yang-version 1;
+    namespace "urn:imprevtst:yang";
+    prefix "imprevtst";
+
+    description "This is a test module";
+
+    revision 2015-07-02;
+
+    typedef date-and-time {
+      type string;
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-05-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-05-02.yang
new file mode 100644 (file)
index 0000000..283fd41
--- /dev/null
@@ -0,0 +1,13 @@
+module importedrevtest {
+    yang-version 1;
+    namespace "urn:imprevtst:yang";
+    prefix "imprevtst";
+
+    description "This is a test module";
+
+    revision 2015-05-02;
+
+    typedef date-and-time {
+      type string;
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-06-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-06-02.yang
new file mode 100644 (file)
index 0000000..6c02503
--- /dev/null
@@ -0,0 +1,13 @@
+module importedrevtest {
+    yang-version 1;
+    namespace "urn:imprevtst:yang";
+    prefix "imprevtst";
+
+    description "This is a test module";
+
+    revision 2015-06-02;
+
+    typedef date-and-time {
+      type string;
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-08-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-08-02.yang
new file mode 100644 (file)
index 0000000..d532636
--- /dev/null
@@ -0,0 +1,13 @@
+module importedrevtest {
+    yang-version 1;
+    namespace "urn:imprevtst:yang";
+    prefix "imprevtst";
+
+    description "This is a test module";
+
+    revision 2015-08-02;
+
+    typedef date-and-time {
+      type string;
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-09-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/importedtestrev@2015-09-02.yang
new file mode 100644 (file)
index 0000000..5ad34ec
--- /dev/null
@@ -0,0 +1,13 @@
+module importedrevtest {
+    yang-version 1;
+    namespace "urn:imprevtst:yang";
+    prefix "imprevtst";
+
+    description "This is a test module";
+
+    revision 2015-09-02;
+
+    typedef date-and-time {
+      type string;
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/testrev.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/multiple-revisions/testrev.yang
new file mode 100644 (file)
index 0000000..2600dd4
--- /dev/null
@@ -0,0 +1,19 @@
+module testrev {
+    yang-version 1;
+    namespace "urn:tstrev:yang";
+    prefix "tstrev";
+
+    import importedrevtest {
+        prefix "imprevtst";
+    }
+
+    description "This is a test module";
+
+    revision 2015-07-02;
+
+    container mycontainer {
+        leaf myleaf {
+            type imprevtst:date-and-time;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/stmt-test/constraints/foo.yang b/yang/yang-parser-impl/src/test/resources/stmt-test/constraints/foo.yang
new file mode 100644 (file)
index 0000000..a27f9fe
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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
+ */
+module foo {
+    yang-version 1;
+    namespace "urn:opendaylight.foo";
+    prefix "foo";
+
+    revision "2013-10-08" {
+    }
+
+    typedef my-decimal-type {
+        type decimal64 {
+            fraction-digits 6;
+            range "1.5..5.5";
+        }
+    }
+
+    leaf id-decimal64 {
+        type decimal64 {
+            fraction-digits 4;
+            range "1.5..5.5";
+        }
+    }
+}