Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / TypeStatementImpl.java
index e96db5e9d836c284cb7b1409853891d70bc9635e..199c6ee897261c31f292628e4a9841ec41a2a3e7 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 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;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
@@ -14,38 +19,91 @@ 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.BooleanEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EmptyEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int16EffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int32EffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int64EffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int8EffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.StringEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt16EffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt32EffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt64EffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt8EffectiveStatementImpl;
 
-import javax.annotation.Nonnull;
-
-public class TypeStatementImpl extends AbstractDeclaredStatement<String> implements TypeStatement {
+public class TypeStatementImpl extends AbstractDeclaredStatement<String>
+        implements TypeStatement {
 
     protected TypeStatementImpl(StmtContext<String, TypeStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition extends AbstractStatementSupport<String,TypeStatement,EffectiveStatement<String,TypeStatement>> {
+    public static class Definition
+            extends
+            AbstractStatementSupport<String, TypeStatement, EffectiveStatement<String, TypeStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.TYPE);
         }
 
-        @Override public String parseArgumentValue(StmtContext<?, ?, ?> ctx,
-                String value) throws SourceException {
+        @Override
+        public String parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
+                throws SourceException {
             return value;
         }
 
-        @Override public TypeStatement createDeclared(
+        @Override
+        public TypeStatement createDeclared(
                 StmtContext<String, TypeStatement, ?> ctx) {
             return new TypeStatementImpl(ctx);
         }
 
-        @Override public EffectiveStatement<String, TypeStatement> createEffective(
+        @Override
+        public EffectiveStatement<String, TypeStatement> createEffective(
                 StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx) {
-            throw new UnsupportedOperationException();
+
+            // :FIXME improve the test of isExtended - e.g. unknown statements,
+            // etc..
+            Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = ctx
+                    .declaredSubstatements();
+            boolean isExtended = declaredSubstatements.isEmpty() ? false
+                    : true;
+            if (isExtended)
+                return new ExtendedTypeEffectiveStatementImpl(ctx, true);
+
+            switch (ctx.getStatementArgument()) {
+            case TypeUtils.INT8:
+                return new Int8EffectiveStatementImpl(ctx);
+            case TypeUtils.INT16:
+                return new Int16EffectiveStatementImpl(ctx);
+            case TypeUtils.INT32:
+                return new Int32EffectiveStatementImpl(ctx);
+            case TypeUtils.INT64:
+                return new Int64EffectiveStatementImpl(ctx);
+            case TypeUtils.UINT8:
+                return new UInt8EffectiveStatementImpl(ctx);
+            case TypeUtils.UINT16:
+                return new UInt16EffectiveStatementImpl(ctx);
+            case TypeUtils.UINT32:
+                return new UInt32EffectiveStatementImpl(ctx);
+            case TypeUtils.UINT64:
+                return new UInt64EffectiveStatementImpl(ctx);
+            case TypeUtils.STRING:
+                return new StringEffectiveStatementImpl(ctx);
+            case TypeUtils.BOOLEAN:
+                return new BooleanEffectiveStatementImpl(ctx);
+            case TypeUtils.EMPTY:
+                return new EmptyEffectiveStatementImpl(ctx);
+            default:
+                // :FIXME try to resolve original typedef context here and
+                // return buildEffective of original typedef context
+                return new ExtendedTypeEffectiveStatementImpl(ctx, false);
+            }
         }
     }
 
-    @Nonnull @Override
+    @Nonnull
+    @Override
     public String getName() {
         return argument();
     }