Bug 2366: new parser - Types & TypeDefs support & resolution implemented 86/19386/1
authorMartin Ciglan <mciglan@cisco.com>
Fri, 24 Apr 2015 09:24:54 +0000 (11:24 +0200)
committerMartin Ciglan <mciglan@cisco.com>
Thu, 30 Apr 2015 14:30:06 +0000 (16:30 +0200)
Identity, IdentityRef support & resolution preparation
Minor sonar issues fixed
Some of effective statements related to types implemented

Change-Id: I7efeb36e5eb103014fc07ba20ab245332eb53c7b
Signed-off-by: Martin Ciglan <mciglan@cisco.com>
46 files changed:
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Rfc6020Mapping.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/TypeStatement.java
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/IdentityNamespace.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/rfc6020/BinarySpecificationImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/BitStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/BitsSpecificationImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Decimal64SpecificationImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/EnumSpecificationImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/EnumStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ExtensionStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IdentityRefSpecificationImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/IdentityStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/InstanceIdentifierSpecificationImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/LeafrefSpecificationImpl.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/NumericalRestrictionsImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/PathStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/RequireInstanceStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/StringRestrictionsImpl.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/TypedefStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UnionSpecificationImpl.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/effective/BitEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/BitsSpecificationEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/Decimal64SpecificationEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EnumSpecificationEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IdentityRefSpecificationEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/InstanceIdentifierSpecificationEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafrefSpecificationEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NumericalRestrictionsEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/PathEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/RequireInstanceEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/StringRestrictionsEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/TypeDefEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/TypeEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnionSpecificationEffectiveStatementImpl.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnitsEffectiveStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/WhenEffectiveStatementImpl.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypesStmtTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/simple-types.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/semantic-statement-parser/types.yang [new file with mode: 0644]

index 1bf809567dbc5d91ed5d3ef8b2e4b5d80ea7ae24..453ca4669914bea831a6d3a63022e204db831bca 100644 (file)
@@ -156,21 +156,21 @@ public enum Rfc6020Mapping implements StatementDefinition {
     private final QName argument;
     private final boolean yinElement;
 
-    private Rfc6020Mapping(Class<? extends DeclaredStatement<?>> clz, final String nameStr) {
+    Rfc6020Mapping(Class<? extends DeclaredStatement<?>> clz, final String nameStr) {
         type = Preconditions.checkNotNull(clz);
         name = yinQName(nameStr);
         argument = null;
         yinElement = false;
     }
 
-    private Rfc6020Mapping(Class<? extends DeclaredStatement<?>> clz, final String nameStr, final String argumentStr) {
+    Rfc6020Mapping(Class<? extends DeclaredStatement<?>> clz, final String nameStr, final String argumentStr) {
         type = Preconditions.checkNotNull(clz);
         name = yinQName(nameStr);
         argument = yinQName(argumentStr);
         this.yinElement = false;
     }
 
-    private Rfc6020Mapping(Class<? extends DeclaredStatement<?>> clz, final String nameStr, final String argumentStr,
+    Rfc6020Mapping(Class<? extends DeclaredStatement<?>> clz, final String nameStr, final String argumentStr,
             final boolean yinElement) {
         type = Preconditions.checkNotNull(clz);
         name = yinQName(nameStr);
index 42b45c38b4e17f8d66c856e57ff13586511dad1d..cfb9d13124da9bbbbdc1c9a0dcd2cf0ebfa1a067 100644 (file)
@@ -51,28 +51,40 @@ public interface TypeStatement extends DeclaredStatement<String> {
     @Rfc6020AbnfRule("leafref-specification")
     interface LeafrefSpecification extends TypeStatement {
 
-        @Nullable PathStatement getPath();
+        @Nonnull PathStatement getPath();
 
     }
 
+    @Rfc6020AbnfRule("instanceidentifier-specification")
     interface InstanceIdentifierSpecification extends TypeStatement {
 
         @Nullable RequireInstanceStatement getRequireInstance();
     }
 
-
+    @Rfc6020AbnfRule("identityref-specification")
     interface IdentityRefSpecification extends TypeStatement {
 
+        @Nonnull BaseStatement getBase();
+
     }
+
+    @Rfc6020AbnfRule("bits-specification")
     interface BitsSpecification extends TypeStatement {
 
         @Nonnull Collection<? extends BitStatement> getBits();
 
     }
 
+    @Rfc6020AbnfRule("union-specification")
     interface UnionSpecification extends TypeStatement {
 
         @Nonnull Collection<? extends TypeStatement> getTypes();
 
     }
+
+    @Rfc6020AbnfRule("binary-specification")
+    interface BinarySpecification extends TypeStatement {
+
+        @Nullable LengthStatement getLength();
+    }
 }
index b5b3cf02915647a449fb6b25d3086f9fcb7ed44b..b6ee244501ec86cd5e28b01d1cf358c6e579162f 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
@@ -11,7 +11,6 @@ import java.util.ArrayList;
 import java.util.List;
 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;
@@ -23,6 +22,7 @@ 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.Utils;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 
 import javax.annotation.concurrent.Immutable;
 
@@ -34,6 +34,7 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
     private QNameToStatementDefinition stmtDef;
     private PrefixToModule prefixes;
     private List<String> toBeSkipped = new ArrayList<>();
+    private boolean isType = false;
     private static final Logger LOG = LoggerFactory.getLogger(YangStatementParserListenerImpl.class);
 
     public YangStatementParserListenerImpl(StatementSourceReference ref) {
@@ -51,17 +52,31 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
         this.prefixes = prefixes;
     }
 
+    private static boolean hasNotEmptyBody(List<ParseTree> children) {
+        for (ParseTree child : children) {
+            if (child instanceof YangStatementParser.StatementContext) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     @Override
     public void enterStatement(YangStatementParser.StatementContext ctx) {
         boolean action = true;
+        QName identifier;
         for (int i = 0; i < ctx.getChildCount(); i++) {
             ParseTree child = ctx.getChild(i);
             if (child instanceof YangStatementParser.KeywordContext) {
                 try {
-                    QName identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE,
+                    identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE,
                             ((YangStatementParser.KeywordContext) child).children.get(0).getText());
                     if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
-                        writer.startStatement(identifier, ref);
+                        if (identifier.equals(Rfc6020Mapping.TYPE.getStatementName()) && hasNotEmptyBody(((YangStatementParser.KeywordContext) child).getParent().children)) {
+                            isType = true;
+                        } else {
+                            writer.startStatement(identifier, ref);
+                        }
                     } else {
                         action = false;
                         toBeSkipped.add(((YangStatementParser.KeywordContext) child).children.get(0).getText());
@@ -71,9 +86,13 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                 }
             } else if (child instanceof YangStatementParser.ArgumentContext) {
                 try {
-                    if (action) {
-                        writer.argumentValue(
-                                Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
+                    final String argument = Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child);
+                    if (isType) {
+                        writer.startStatement(new QName(YangConstants.RFC6020_YIN_NAMESPACE, argument), ref);
+                        writer.argumentValue(argument, ref);
+                        isType = false;
+                    } else if (action) {
+                        writer.argumentValue(Utils.stringFromStringContext((YangStatementParser.ArgumentContext) child), ref);
                     } else {
                         action = true;
                     }
index fc0e3783d8560ad2e46333632dc249118722306e..b3d9118731205be50f57a8eb8b772b1b04f1b15d 100644 (file)
@@ -8,8 +8,10 @@
 package org.opendaylight.yangtools.yang.parser.spi;
 
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 /**
  *
@@ -19,6 +21,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.IdentityStatement;
  * identity identifier namespace.
  *
  */
-public interface IdentityNamespace extends IdentifierNamespace<QName, IdentityStatement> {
+public interface IdentityNamespace extends IdentifierNamespace<QName, StmtContext.Mutable<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>>> {
 
 }
index 847f8e988e43040f221fbcd064af34cefd225d37..bf00b764a5eb3a0751ab8c4bc45434425e25f1c0 100644 (file)
@@ -7,25 +7,19 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.YangConstants;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-
 import com.google.common.base.Preconditions;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Multimap;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Objects;
-import javax.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.YangConstants;
 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.meta.IdentifierNamespace;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ImportedNamespaceContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
@@ -43,9 +37,25 @@ 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.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase.ContextBuilder;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.BitsSpecificationImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Decimal64SpecificationImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.EnumSpecificationImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.IdentityRefSpecificationImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.InstanceIdentifierSpecificationImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.LeafrefSpecificationImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.NumericalRestrictionsImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.StringRestrictionsImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnionSpecificationImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.UnknownStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
 
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+
 public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBehaviour.Registry, Mutable {
 
     public enum PhaseCompletionProgress {
@@ -79,8 +89,11 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     ContextBuilder<?, ?, ?> createDeclaredChild(StatementContextBase<?, ?, ?> current, QName name, StatementSourceReference ref) {
         StatementDefinitionContext<?,?,?> def = getDefinition(name);
 
-        //extensions
-        if (def == null) {
+        if (def == null && BaseTypes.isYangBuildInType(name.getLocalName())) {
+            //type-body-stmts
+            def = resolveTypeBodyStmts(name.getLocalName());
+        } else if (def == null) {
+            //extensions
             if (Utils.isValidStatementDefinition(prefixToModuleMap, qNameToStmtDefMap, name)) {
                 def = new StatementDefinitionContext<>(new UnknownStatementImpl.Definition(qNameToStmtDefMap.get(Utils.trimPrefix(name))));
             }
@@ -246,6 +259,32 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
         }
     }
 
+    private StatementDefinitionContext<?,?,?> resolveTypeBodyStmts(String typeArgument) {
+        switch (typeArgument) {
+            case "int8": case "int16": case "int32": case "int64": case "uint8": case "uint16": case "uint32": case "uint64":
+                return new StatementDefinitionContext<>(new NumericalRestrictionsImpl.Definition());
+            case "decimal64":
+                return new StatementDefinitionContext<>(new Decimal64SpecificationImpl.Definition());
+            case "union":
+                return new StatementDefinitionContext<>(new UnionSpecificationImpl.Definition());
+            case "string":
+                return new StatementDefinitionContext<>(new StringRestrictionsImpl.Definition());
+            case "enumeration":
+                return new StatementDefinitionContext<>(new EnumSpecificationImpl.Definition());
+            case "leafref":
+                return new StatementDefinitionContext<>(new LeafrefSpecificationImpl.Definition());
+            case "bits":
+                return new StatementDefinitionContext<>(new BitsSpecificationImpl.Definition());
+            case "identityref":
+                return new StatementDefinitionContext<>(new IdentityRefSpecificationImpl.Definition());
+            case "instance-identifier":
+                return new StatementDefinitionContext<>(new InstanceIdentifierSpecificationImpl.Definition());
+            default:
+                return null;
+        }
+    }
+
+
     private PrefixToModule prefixes() {
         Map<String, QNameModule> prefixes = (Map<String, QNameModule>) currentContext.getAllFromNamespace(PrefixToModule.class);
         for (Map.Entry<String, QNameModule> prefix : prefixes.entrySet()) {
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
new file mode 100644 (file)
index 0000000..dcc57ab
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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 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 javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+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 null;
+        }
+    }
+
+    @Nullable
+    @Override
+    public LengthStatement getLength() {
+        return firstDeclared(LengthStatement.class);
+    }
+
+    @Nonnull
+    @Override
+    public String getName() {
+        return argument();
+    }
+}
index 93e227ac00c80ac80a8398f336b8b4e783a155e5..f2831bfd30aa5d6e6c35558bd06bdce559c35dd4 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
@@ -28,9 +28,7 @@ public class BitStatementImpl extends AbstractDeclaredStatement<String>
         super(context);
     }
 
-    public static class Definition
-            extends
-            AbstractStatementSupport<String, BitStatement, EffectiveStatement<String, BitStatement>> {
+    public static class Definition extends AbstractStatementSupport<String, BitStatement, EffectiveStatement<String, BitStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.BIT);
index 53215e76f72df5de239caf31ff6189b8d7ae3f26..5138e0b22538ce185f305cc0e7b3a8539d37065b 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
@@ -17,6 +17,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 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.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.BitsSpecificationEffectiveStatementImpl;
 
 public class BitsSpecificationImpl extends AbstractDeclaredStatement<String>
         implements TypeStatement.BitsSpecification {
@@ -49,7 +50,7 @@ public class BitsSpecificationImpl extends AbstractDeclaredStatement<String>
         @Override
         public EffectiveStatement<String, TypeStatement.BitsSpecification> createEffective(
                 StmtContext<String, TypeStatement.BitsSpecification, EffectiveStatement<String, TypeStatement.BitsSpecification>> ctx) {
-            throw new UnsupportedOperationException();
+            return new BitsSpecificationEffectiveStatementImpl(ctx);
         }
     }
 
index 985b18d1a0f9074c28a0351adef8932a93d4d6f1..15d91a4d144c16b0e04507c2815625ef5f8dc1b2 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,7 +8,6 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import org.opendaylight.yangtools.yang.model.api.stmt.FractionDigitsStatement;
-
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
@@ -17,6 +16,7 @@ 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.RangeStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.Decimal64SpecificationEffectiveStatementImpl;
 
 public class Decimal64SpecificationImpl extends AbstractDeclaredStatement<String> implements TypeStatement.Decimal64Specification{
 
@@ -27,7 +27,7 @@ public class Decimal64SpecificationImpl extends AbstractDeclaredStatement<String
     public static class Definition extends AbstractStatementSupport<String,TypeStatement.Decimal64Specification,EffectiveStatement<String,TypeStatement.Decimal64Specification>> {
 
         public Definition() {
-            super(Rfc6020Mapping.FRACTION_DIGITS);
+            super(Rfc6020Mapping.TYPE);
         }
 
         @Override public String parseArgumentValue(StmtContext<?, ?, ?> ctx,
@@ -42,7 +42,7 @@ public class Decimal64SpecificationImpl extends AbstractDeclaredStatement<String
 
         @Override public EffectiveStatement<String, TypeStatement.Decimal64Specification> createEffective(
                 StmtContext<String, TypeStatement.Decimal64Specification, EffectiveStatement<String, TypeStatement.Decimal64Specification>> ctx) {
-            throw new UnsupportedOperationException();
+            return new Decimal64SpecificationEffectiveStatementImpl(ctx);
         }
     }
 
index 8a1a9738e3e50d8fa6cde10279efa2e4e526a435..f56e9a4739b4a72d26409784bc4415a0d150f0ae 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
@@ -17,6 +17,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 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.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EnumSpecificationEffectiveStatementImpl;
 
 public class EnumSpecificationImpl extends AbstractDeclaredStatement<String>
         implements TypeStatement.EnumSpecification {
@@ -31,7 +32,7 @@ public class EnumSpecificationImpl extends AbstractDeclaredStatement<String>
             AbstractStatementSupport<String, TypeStatement.EnumSpecification, EffectiveStatement<String, TypeStatement.EnumSpecification>> {
 
         public Definition() {
-            super(Rfc6020Mapping.ENUM);
+            super(Rfc6020Mapping.TYPE);
         }
 
         @Override
@@ -49,7 +50,7 @@ public class EnumSpecificationImpl extends AbstractDeclaredStatement<String>
         @Override
         public EffectiveStatement<String, TypeStatement.EnumSpecification> createEffective(
                 StmtContext<String, TypeStatement.EnumSpecification, EffectiveStatement<String, TypeStatement.EnumSpecification>> ctx) {
-            throw new UnsupportedOperationException();
+            return new EnumSpecificationEffectiveStatementImpl(ctx);
         }
     }
 
index 3fa1b1ce7f303e8e00c191d101cafbe12d6493c1..7c5ae5a58799e881a0d3c0eea920a3f64dae07c6 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
index e3ff0d39fb7a3092fc9b6e062ac8c95252eb904c..e7bebeee0e14a2b638073fdd89dd5c4a90a160c7 100644 (file)
@@ -19,7 +19,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
 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.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
@@ -51,7 +50,7 @@ public class ExtensionStatementImpl extends AbstractDeclaredStatement<QName> imp
         }
 
         @Override
-        public void onStatementDefinitionDeclared(final StmtContext.Mutable<QName, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> stmt) throws InferenceException, SourceException {
+        public void onStatementDefinitionDeclared(final StmtContext.Mutable<QName, ExtensionStatement, EffectiveStatement<QName, ExtensionStatement>> stmt) throws SourceException {
             stmt.addContext(ExtensionNamespace.class, stmt.getStatementArgument(), stmt);
         }
     }
index 30d6ef0769c46e933d3bf28edf829299c98469eb..98a5667df0375d96fbf5097bcc80e929f24aa553 100644 (file)
@@ -60,9 +60,10 @@ public class GroupingStatementImpl extends AbstractDeclaredStatement<QName>
         }
 
         @Override
-        public void onFullDefinitionDeclared(
-                Mutable<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> stmt) throws SourceException {
-            stmt.getParentContext().addContext(GroupingNamespace.class, stmt.getStatementArgument(),stmt);
+        public void onFullDefinitionDeclared(Mutable<QName, GroupingStatement, EffectiveStatement<QName, GroupingStatement>> stmt) throws SourceException {
+            if (stmt != null && stmt.getParentContext() != null) {
+                stmt.getParentContext().addContext(GroupingNamespace.class, stmt.getStatementArgument(), stmt);
+            }
         }
 
     }
index bd2b1e7c0a67a5a05fdcd86f7073d5b93697edc8..37df53b9b6b34d91061d6e24781859bcbd9fc746 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
@@ -7,6 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
+import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
@@ -14,10 +19,13 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 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.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.IdentityRefSpecificationEffectiveStatementImpl;
 
-public class IdentityRefSpecificationImpl extends
-        AbstractDeclaredStatement<String> implements
-        TypeStatement.IdentityRefSpecification {
+import javax.annotation.Nonnull;
+import java.util.Map;
+
+public class IdentityRefSpecificationImpl extends AbstractDeclaredStatement<String> implements TypeStatement.IdentityRefSpecification {
 
     protected IdentityRefSpecificationImpl(
             StmtContext<String, TypeStatement.IdentityRefSpecification, ?> context) {
@@ -29,7 +37,7 @@ public class IdentityRefSpecificationImpl extends
             AbstractStatementSupport<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement.IdentityRefSpecification>> {
 
         public Definition() {
-            super(Rfc6020Mapping.BASE);
+            super(Rfc6020Mapping.TYPE);
         }
 
         @Override
@@ -47,7 +55,14 @@ public class IdentityRefSpecificationImpl extends
         @Override
         public EffectiveStatement<String, TypeStatement.IdentityRefSpecification> createEffective(
                 StmtContext<String, TypeStatement.IdentityRefSpecification, EffectiveStatement<String, TypeStatement.IdentityRefSpecification>> ctx) {
-            throw new UnsupportedOperationException();
+            return new IdentityRefSpecificationEffectiveStatementImpl(ctx);
+        }
+
+        @Override
+        public void onFullDefinitionDeclared(StmtContext.Mutable<String, IdentityRefSpecification, EffectiveStatement<String, IdentityRefSpecification>> stmt) throws SourceException {
+            //FIXME:
+//            StatementContextBase<?, ?, ?> stmtCtx = (StatementContextBase<?, ?, ?>) stmt.getFromNamespace(IdentityNamespace.class, Utils.qNameFromArgument(StmtContextUtils.findFirstDeclaredSubstatement(stmt, BaseStatement.class), (String) StmtContextUtils.findFirstDeclaredSubstatement(stmt, BaseStatement.class).getStatementArgument()));
+//            Preconditions.checkArgument(stmtCtx != null, "Identity '%s' doesn't exist in given scope (module, imported submodules)", stmt.getStatementArgument());
         }
     }
 
@@ -56,4 +71,10 @@ public class IdentityRefSpecificationImpl extends
         return argument();
     }
 
+    @Nonnull
+    @Override
+    public BaseStatement getBase() {
+        return firstDeclared(BaseStatement.class);
+    }
+
 }
index 092cc411e3a5bc64fa0c7c7c0e4ea4bf983fd16b..ada4c730958c2aa93e5ab42498c479d41eaea486 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
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser;
+import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.IdentityEffectiveStatementImpl;
-
 import org.opendaylight.yangtools.yang.model.api.stmt.BaseStatement;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
@@ -29,9 +32,7 @@ public class IdentityStatementImpl extends AbstractDeclaredStatement<QName>
         super(context);
     }
 
-    public static class Definition
-            extends
-            AbstractStatementSupport<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> {
+    public static class Definition extends AbstractStatementSupport<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.IDENTITY);
@@ -54,6 +55,10 @@ public class IdentityStatementImpl extends AbstractDeclaredStatement<QName>
             return new IdentityEffectiveStatementImpl(ctx);
         }
 
+        @Override
+        public void onStatementDefinitionDeclared(final StmtContext.Mutable<QName, IdentityStatement, EffectiveStatement<QName, IdentityStatement>> stmt) throws SourceException {
+            stmt.addToNs(IdentityNamespace.class, stmt.getStatementArgument(), stmt);
+        }
     }
 
     @Override
index 504498db3479e701221e00702e8c06b16fe4b4a1..d51ae869ac2f276bd03668d8b122923f232f36aa 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
@@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 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.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.InstanceIdentifierSpecificationEffectiveStatementImpl;
 
 public class InstanceIdentifierSpecificationImpl extends
         AbstractDeclaredStatement<String> implements
@@ -31,7 +32,7 @@ public class InstanceIdentifierSpecificationImpl extends
             AbstractStatementSupport<String, TypeStatement.InstanceIdentifierSpecification, EffectiveStatement<String, TypeStatement.InstanceIdentifierSpecification>> {
 
         public Definition() {
-            super(Rfc6020Mapping.REQUIRE_INSTANCE);
+            super(Rfc6020Mapping.TYPE);
         }
 
         @Override
@@ -49,7 +50,7 @@ public class InstanceIdentifierSpecificationImpl extends
         @Override
         public EffectiveStatement<String, TypeStatement.InstanceIdentifierSpecification> createEffective(
                 StmtContext<String, TypeStatement.InstanceIdentifierSpecification, EffectiveStatement<String, TypeStatement.InstanceIdentifierSpecification>> ctx) {
-            throw new UnsupportedOperationException();
+            return new InstanceIdentifierSpecificationEffectiveStatementImpl(ctx);
         }
     }
 
index 58b7d5cacf3c475aaa755148624cc5b6c45fa566..d01ed15de3218bc90038bdd8524078333f6c4931 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,7 +8,6 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
-
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
@@ -16,6 +15,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 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.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafrefSpecificationEffectiveStatementImpl;
 
 public class LeafrefSpecificationImpl extends AbstractDeclaredStatement<String>
         implements TypeStatement.LeafrefSpecification {
@@ -30,7 +30,7 @@ public class LeafrefSpecificationImpl extends AbstractDeclaredStatement<String>
             AbstractStatementSupport<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> {
 
         public Definition() {
-            super(Rfc6020Mapping.PATH);
+            super(Rfc6020Mapping.TYPE);
         }
 
         @Override
@@ -48,7 +48,7 @@ public class LeafrefSpecificationImpl extends AbstractDeclaredStatement<String>
         @Override
         public EffectiveStatement<String, TypeStatement.LeafrefSpecification> createEffective(
                 StmtContext<String, TypeStatement.LeafrefSpecification, EffectiveStatement<String, TypeStatement.LeafrefSpecification>> ctx) {
-            throw new UnsupportedOperationException();
+            return new LeafrefSpecificationEffectiveStatementImpl(ctx);
         }
     }
 
index 5df5575050d930ef3383899b2a54b87ce3ff4e6e..0db8c69f4105c4d6875be7cda19b769e2d644cc3 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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 org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.MustEffectiveStatementImpl;
@@ -34,7 +41,7 @@ public class MustStatementImpl extends AbstractDeclaredStatement<RevisionAwareXP
 
         @Override public RevisionAwareXPath parseArgumentValue(
                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return new RevisionAwareXPathImpl(value, false);
+            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
         }
 
         @Override public MustStatement createDeclared(
index 2415db62d8f19319f5477331ac374299d45a6fc5..bcf5b34962aa42a8173656a81c4d8462d91de773 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
@@ -15,6 +15,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.RangeStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.NumericalRestrictionsEffectiveStatementImpl;
 
 public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String> implements TypeStatement.NumericalRestrictions{
 
@@ -25,7 +26,7 @@ public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String>
     public static class Definition extends AbstractStatementSupport<String,TypeStatement.NumericalRestrictions,EffectiveStatement<String,TypeStatement.NumericalRestrictions>> {
 
         public Definition() {
-            super(Rfc6020Mapping.RANGE);
+            super(Rfc6020Mapping.TYPE);
         }
 
         @Override public String parseArgumentValue(StmtContext<?, ?, ?> ctx,
@@ -40,7 +41,7 @@ public class NumericalRestrictionsImpl extends AbstractDeclaredStatement<String>
 
         @Override public EffectiveStatement<String, TypeStatement.NumericalRestrictions> createEffective(
                 StmtContext<String, TypeStatement.NumericalRestrictions, EffectiveStatement<String, TypeStatement.NumericalRestrictions>> ctx) {
-            throw new UnsupportedOperationException();
+            return new NumericalRestrictionsEffectiveStatementImpl(ctx);
         }
     }
 
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/PathStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/PathStatementImpl.java
new file mode 100644 (file)
index 0000000..d0bc47e
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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 org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+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.DescriptionStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MustStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+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.MustEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PathEffectiveStatementImpl;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+public class PathStatementImpl extends AbstractDeclaredStatement<RevisionAwareXPath> implements
+        PathStatement {
+
+    protected PathStatementImpl(StmtContext<RevisionAwareXPath, PathStatement, ?> context) {
+        super(context);
+    }
+
+    public static class Definition extends AbstractStatementSupport<RevisionAwareXPath,PathStatement,EffectiveStatement<RevisionAwareXPath,PathStatement>> {
+
+        public Definition() {
+            super(Rfc6020Mapping.PATH);
+        }
+
+        @Override public RevisionAwareXPath parseArgumentValue(
+                StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
+        }
+
+        @Override public PathStatement createDeclared(
+                StmtContext<RevisionAwareXPath, PathStatement, ?> ctx) {
+            return new PathStatementImpl(ctx);
+        }
+
+        @Override public EffectiveStatement<RevisionAwareXPath, PathStatement> createEffective(
+                StmtContext<RevisionAwareXPath, PathStatement, EffectiveStatement<RevisionAwareXPath, PathStatement>> ctx) {
+           return new PathEffectiveStatementImpl(ctx);
+        }
+    }
+
+    @Nonnull
+    @Override
+    public String getValue() {
+        return rawArgument();
+    }
+
+}
index 0573fc310d25da9303390f040ba257ba1f873a2c..cd192b9f9ae345a61bdb64417cbb9cbd3ad80491 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
index 7a85c177787394d17f1e0602ec275100c4fdcb04..0a9cfffcb42ea32206d93db9ca907c1424f4b445 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
@@ -18,6 +18,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 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.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.StringRestrictionsEffectiveStatementImpl;
 
 public class StringRestrictionsImpl extends AbstractDeclaredStatement<String>
         implements TypeStatement.StringRestrictions {
@@ -50,7 +51,7 @@ public class StringRestrictionsImpl extends AbstractDeclaredStatement<String>
         @Override
         public EffectiveStatement<String, TypeStatement.StringRestrictions> createEffective(
                 StmtContext<String, TypeStatement.StringRestrictions, EffectiveStatement<String, TypeStatement.StringRestrictions>> ctx) {
-            throw new UnsupportedOperationException();
+            return new StringRestrictionsEffectiveStatementImpl(ctx);
         }
     }
 
index e96db5e9d836c284cb7b1409853891d70bc9635e..6f87836f94ba0529c8c8cecfe23bcdeef6594f38 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
@@ -7,13 +7,18 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
+import com.google.common.base.Preconditions;
 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.TypeStatement;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
 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.reactor.StatementContextBase;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.TypeEffectiveStatementImpl;
 
 import javax.annotation.Nonnull;
 
@@ -41,7 +46,17 @@ public class TypeStatementImpl extends AbstractDeclaredStatement<String> impleme
 
         @Override public EffectiveStatement<String, TypeStatement> createEffective(
                 StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx) {
-            throw new UnsupportedOperationException();
+            return new TypeEffectiveStatementImpl(ctx);
+        }
+
+        @Override
+        public void onFullDefinitionDeclared(StmtContext.Mutable<String, TypeStatement, EffectiveStatement<String, TypeStatement>> stmt) throws SourceException {
+            if (!BaseTypes.isYangBuildInType(stmt.getStatementArgument())) {
+                if (stmt.getParentContext() != null) {
+                    StatementContextBase<?, ?, ?> stmtCtx = (StatementContextBase<?, ?, ?>) stmt.getParentContext().getFromNamespace(TypeNamespace.class, Utils.qNameFromArgument(stmt, stmt.getStatementArgument()));
+                    Preconditions.checkArgument(stmtCtx != null, "Typedef '%s' doesn't exist in given scope", stmt.getStatementArgument());
+                }
+            }
         }
     }
 
index 595c280e87109b6d05c519b2f878a3b20996c36b..96c87db15a000948ea5f9a68d05b7fa813685406 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
@@ -17,10 +17,13 @@ import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
+import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
 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.TypeDefEffectiveStatementImpl;
+
 import javax.annotation.Nullable;
 
 public class TypedefStatementImpl extends AbstractDeclaredStatement<QName>
@@ -54,7 +57,14 @@ public class TypedefStatementImpl extends AbstractDeclaredStatement<QName>
         @Override
         public EffectiveStatement<QName, TypedefStatement> createEffective(
                 StmtContext<QName, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> ctx) {
-            throw new UnsupportedOperationException();
+            return new TypeDefEffectiveStatementImpl(ctx);
+        }
+
+        @Override
+        public void onStatementDefinitionDeclared(StmtContext.Mutable<QName, TypedefStatement, EffectiveStatement<QName, TypedefStatement>> stmt) throws SourceException {
+            if (stmt != null && stmt.getParentContext() != null) {
+                stmt.getParentContext().addContext(TypeNamespace.class, stmt.getStatementArgument(), stmt);
+            }
         }
     }
 
index 36ca6f5854f1a6bf0dfb0d9b28d69e81aea7b744..22d00f0a686513dc1f6282a65b7c1863a8216d50 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,13 +8,15 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import java.util.Collection;
+
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-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.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnionSpecificationEffectiveStatementImpl;
 
 public class UnionSpecificationImpl extends AbstractDeclaredStatement<String>
         implements TypeStatement.UnionSpecification {
@@ -24,9 +26,7 @@ public class UnionSpecificationImpl extends AbstractDeclaredStatement<String>
         super(context);
     }
 
-    public static class Definition
-            extends
-            AbstractStatementSupport<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> {
+    public static class Definition extends AbstractStatementSupport<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> {
 
         public Definition() {
             super(Rfc6020Mapping.TYPE);
@@ -47,7 +47,7 @@ public class UnionSpecificationImpl extends AbstractDeclaredStatement<String>
         @Override
         public EffectiveStatement<String, TypeStatement.UnionSpecification> createEffective(
                 StmtContext<String, TypeStatement.UnionSpecification, EffectiveStatement<String, TypeStatement.UnionSpecification>> ctx) {
-            throw new UnsupportedOperationException();
+            return new UnionSpecificationEffectiveStatementImpl(ctx);
         }
     }
 
index 7e5fc5646ff568a760f622c523021f84857a1576..78d60b19326d513d136ef31e525b3a21ab53fa42 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
@@ -39,7 +39,7 @@ public class WhenStatementImpl extends AbstractDeclaredStatement<RevisionAwareXP
 
         @Override public RevisionAwareXPath parseArgumentValue(
                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
-            return new RevisionAwareXPathImpl(value, false);
+            return new RevisionAwareXPathImpl(value, Utils.isXPathAbsolute(value));
         }
 
         @Override public WhenStatement createDeclared(
index 87bfe2b3f4f9bb5cbf5cd261cebcfcb7876057db..29fddc0b1cf6f64ca0f5cda434c1d54f4f5e2e8c 100644 (file)
@@ -12,6 +12,8 @@ import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour
 import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
 
 import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.IdentityNamespace;
+import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
 
 import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
@@ -27,7 +29,6 @@ import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
-import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 
 public final class YangInferencePipeline {
@@ -58,7 +59,6 @@ public final class YangInferencePipeline {
             .addSupport(sourceLocal(IncludedModuleContext.class))
             .addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
             .addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
-            .addSupport(sourceLocal(QNameToStatementDefinition.class))
             .build();
 
     private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle.
@@ -67,6 +67,10 @@ public final class YangInferencePipeline {
             .addSupport(new ArgumentStatementImpl.Definition())
             .addSupport(new ExtensionStatementImpl.Definition())
             .addSupport(global(ExtensionNamespace.class))
+            .addSupport(new TypedefStatementImpl.Definition())
+            .addSupport(treeScoped(TypeNamespace.class))
+            .addSupport(new IdentityStatementImpl.Definition())
+            .addSupport(global(IdentityNamespace.class))
             .build();
 
     private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle.
@@ -82,7 +86,6 @@ public final class YangInferencePipeline {
             .addSupport(new DefaultStatementImpl.Definition())
             .addSupport(new MustStatementImpl.Definition())
             .addSupport(new MandatoryStatementImpl.Definition())
-            .addSupport(new TypedefStatementImpl.Definition())
             .addSupport(new AnyxmlStatementImpl.Definition())
             .addSupport(new IfFeatureStatementImpl.Definition())
             .addSupport(new UsesStatementImpl.Definition())
@@ -101,7 +104,6 @@ public final class YangInferencePipeline {
             .addSupport(new WhenStatementImpl.Definition())
             .addSupport(new AugmentStatementImpl.Definition())
             .addSupport(new RefineStatementImpl.Definition())
-            .addSupport(new IdentityStatementImpl.Definition())
             .addSupport(new BaseStatementImpl.Definition())
             .addSupport(new FractionDigitsStatementImpl.Definition())
             .addSupport(new EnumStatementImpl.Definition())
@@ -117,16 +119,8 @@ public final class YangInferencePipeline {
             .addSupport(new ValueStatementImpl.Definition())
             .addSupport(new UnitsStatementImpl.Definition())
             .addSupport(new RequireInstanceStatementImpl.Definition())
-            //TODO: add mapping to Rfc6020Mapping class and uncomment following. Please test it.
-//            .addSupport(new EnumSpecificationImpl.Definition())
-//            .addSupport(new Decimal64SpecificationImpl.Definition())
-//            .addSupport(new IdentityRefSpecificationImpl.Definition())
-//            .addSupport(new InstanceIdentifierSpecificationImpl.Definition())
-//            .addSupport(new LeafrefSpecificationImpl.Definition())
-//            .addSupport(new NumericalRestrictionsImpl.Definition())
-//            .addSupport(new StringRestrictionsImpl.Definition())
-//            .addSupport(new UnionSpecificationImpl.Definition())
-//            .addSupport(new BitStatementImpl.Definition())
+            .addSupport(new BitStatementImpl.Definition())
+            .addSupport(new PathStatementImpl.Definition())
             .build();
 
     public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/BitsSpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/BitsSpecificationEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..36ad297
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class BitsSpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.BitsSpecification> {
+
+    public BitsSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.BitsSpecification, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/Decimal64SpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/Decimal64SpecificationEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..8d367a4
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class Decimal64SpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.Decimal64Specification> {
+
+    public Decimal64SpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.Decimal64Specification, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EnumSpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/EnumSpecificationEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..c94c79f
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class EnumSpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.EnumSpecification> {
+
+    public EnumSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.EnumSpecification, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IdentityRefSpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/IdentityRefSpecificationEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..f06597a
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class IdentityRefSpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.IdentityRefSpecification> {
+
+    public IdentityRefSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.IdentityRefSpecification, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/InstanceIdentifierSpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/InstanceIdentifierSpecificationEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..68c3476
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class InstanceIdentifierSpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.InstanceIdentifierSpecification> {
+
+    public InstanceIdentifierSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.InstanceIdentifierSpecification, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafrefSpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/LeafrefSpecificationEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..15b36dd
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class LeafrefSpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.LeafrefSpecification> {
+
+    public LeafrefSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.LeafrefSpecification, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NumericalRestrictionsEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/NumericalRestrictionsEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..98c6dcd
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class NumericalRestrictionsEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.NumericalRestrictions> {
+
+    public NumericalRestrictionsEffectiveStatementImpl(StmtContext<String, TypeStatement.NumericalRestrictions, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/PathEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/PathEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..5fa69b0
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.PathStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class PathEffectiveStatementImpl extends
+        EffectiveStatementBase<RevisionAwareXPath, PathStatement> {
+
+    public PathEffectiveStatementImpl(
+            StmtContext<RevisionAwareXPath, PathStatement, ?> ctx) {
+        super(ctx);
+
+    }
+
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/StringRestrictionsEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/StringRestrictionsEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..139a7d4
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class StringRestrictionsEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.StringRestrictions> {
+
+    public StringRestrictionsEffectiveStatementImpl(StmtContext<String, TypeStatement.StringRestrictions, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/TypeDefEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/TypeDefEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..05070c0
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.stmt.TypedefStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class TypeDefEffectiveStatementImpl extends EffectiveStatementBase<QName, TypedefStatement> {
+
+    public TypeDefEffectiveStatementImpl(StmtContext<QName, TypedefStatement, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/TypeEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/TypeEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..b627725
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class TypeEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement> {
+
+    public TypeEffectiveStatementImpl(StmtContext<String, TypeStatement, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnionSpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnionSpecificationEffectiveStatementImpl.java
new file mode 100644 (file)
index 0000000..12b8ba9
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.effective;
+
+import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+public class UnionSpecificationEffectiveStatementImpl extends EffectiveStatementBase<String, TypeStatement.UnionSpecification> {
+
+    public UnionSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.UnionSpecification, ?> ctx) {
+        super(ctx);
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypesStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/YangTypesStmtTest.java
new file mode 100644 (file)
index 0000000..68fd50f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.stmt.test;
+
+import org.junit.Test;
+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.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+
+import static org.junit.Assert.assertNotNull;
+
+public class YangTypesStmtTest {
+
+    private static final YangStatementSourceImpl TYPEFILE1 = new YangStatementSourceImpl("/semantic-statement-parser/types.yang");
+    private static final YangStatementSourceImpl TYPEFILE2 = new YangStatementSourceImpl("/semantic-statement-parser/simple-types.yang");
+
+    @Test
+    public void readAndParseYangFileTest() throws SourceException, ReactorException {
+        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        addSources(reactor, TYPEFILE1, TYPEFILE2);
+        EffectiveModelContext result = reactor.build();
+        assertNotNull(result);
+    }
+
+    private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
+        for (StatementStreamSource source : sources) {
+            reactor.addSource(source);
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/simple-types.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/simple-types.yang
new file mode 100644 (file)
index 0000000..30d0b13
--- /dev/null
@@ -0,0 +1,103 @@
+module simple-types {
+
+    yang-version 1;
+    namespace "urn:simple.types";
+    prefix "st";
+
+    organization "opendaylight";
+    contact "WILL-BE-DEFINED-LATER";
+    revision 2015-04-16;
+
+    typedef myint8 {
+        type int8 {
+            range "1..20";
+        }
+    }
+
+    identity my-base;
+
+    typedef myint32 {
+         type int32 {
+            range "1..2000";
+         }
+    }
+
+    container mycontainer {
+       leaf mynumerical {
+          type int32 {
+            range "1..3000";
+          }
+       }
+
+       leaf mynorestrictions {
+           type string;
+       }
+
+       leaf mytypedefuse1 {
+           type myint32;
+       }
+
+       leaf mytypedefuse2 {
+           type myint8;
+       }
+
+        leaf myunion {
+            type union {
+                type int8;
+                type int32;
+            }
+        }
+
+        leaf mydecimal64 {
+            type decimal64 {
+                fraction-digits 2;
+                range "1 .. 3.14 | 10 | 20..max";
+            }
+        }
+
+        leaf mystring {
+            type string {
+                length "1..255";
+                pattern "[0-9a-fA-F]*";
+            }
+        }
+
+        leaf myenum {
+            type enumeration {
+                enum zero;
+                enum one;
+                enum seven {
+                    value 7;
+                }
+            }
+        }
+
+        leaf mybits {
+            type bits {
+                bit disable-nagle {
+                    position 0;
+                }
+                bit auto-sense-speed {
+                    position 1;
+                }
+                bit 10-Mb-only {
+                    position 2;
+                }
+            }
+            default "auto-sense-speed";
+        }
+
+        leaf mgmt-interface {
+            type leafref {
+               path "../myenum";
+            }
+        }
+
+        leaf crypto {
+            type identityref {
+                base "my-base";
+            }
+        }
+
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/types.yang b/yang/yang-parser-impl/src/test/resources/semantic-statement-parser/types.yang
new file mode 100644 (file)
index 0000000..eff282a
--- /dev/null
@@ -0,0 +1,132 @@
+module custom-types-test {
+
+    yang-version 1;
+    namespace "urn:custom.types.demo";
+    prefix "iit";
+
+    organization "opendaylight";
+    contact "WILL-BE-DEFINED-LATER";
+        revision 2012-04-16 {
+    }
+
+    extension mountpoint {
+        description "enter point";
+        argument "name" {
+            yin-element "true";
+        }
+    }
+
+    typedef access-operations-type {
+        type bits {
+            bit create {
+                description "Any protocol operation that creates a new data node.";
+            }
+            bit read {
+                description "Any protocol operation or notification that returns the value of a data node.";
+                position 500;
+            }
+            bit update {
+                description "Any protocol operation that alters an existing data node.";
+            }
+            bit delete {
+                description "Any protocol operation that removes a data node.";
+                position 365;
+            }
+            bit exec {
+                description "Execution access to the specified protocol operation.";
+            }
+        }
+        description "NETCONF Access Operation.";
+    }
+
+    leaf inst-id-leaf1 {
+        type instance-identifier {
+            require-instance false;
+        }
+        iit:mountpoint "mnt-extension";
+    }
+
+    leaf inst-id-leaf2 {
+        type instance-identifier;
+    }
+
+    leaf type {
+        type service-type-ref;
+    }
+
+    identity crypto-id {
+        base "crypto-base";
+        description "crypto-id description";
+        iit:mountpoint "mnt-extension";
+    }
+
+    identity crypto-base {
+        description "crypto-base description";
+    }
+
+    identity crypto-alg {
+        base "crypto-base";
+        description "crypto-alg description";
+    }
+
+    identity crypto-def {
+        base "crypto-base";
+        description "crypto-def description";
+    }
+
+    leaf mybits {
+        type bits {
+            bit disable-nagle {
+                position 0;
+            }
+            bit auto-sense-speed {
+                position 1;
+            }
+            bit 10-Mb-only {
+                position 2;
+            }
+        }
+        default "auto-sense-speed";
+    }
+
+    typedef ip-version {
+        type enumeration {
+            enum unknown {
+                description "An unknown or unspecified version of the Internet protocol.";
+            }
+            enum ipv4 {
+                value "19";
+                description "The IPv4 protocol as defined in RFC 791.";
+            }
+            enum ipv6 {
+                value "7";
+                description "The IPv6 protocol as defined in RFC 2460.";
+            }
+            enum default {
+                description "default ip";
+            }
+        }
+    }
+
+    identity service-type {
+        description
+            "Service identity base type. All service identities must be
+             derived from this type. A service type uniquely defines a single
+             atomic API contract, such as a Java interface, a set of C
+             function declarations, or similar.
+
+             If the service type has a corresponding Java interface, the name
+             of that interface should be attached to the derived identity MUST
+             include a java-class keyword, whose name argument points to that
+             interface.";
+    }
+
+    typedef service-type-ref {
+        description
+            "Internal type of references to service type identity.";
+        type identityref {
+            base service-type;
+        }
+    }
+
+}