Make getOriginalCtx() give out an Optional
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / RootStatementContext.java
index 0ecbd93df1e1a8abaab8595edb7164e5ff2ee439..16d82e7fc5ceca617983218c3674a55f340da588 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
 import com.google.common.collect.ImmutableList;
@@ -16,6 +15,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Optional;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -31,8 +31,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.MutableStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
 import org.opendaylight.yangtools.yang.parser.spi.source.IncludedModuleContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
 
@@ -72,29 +70,6 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         this.setRootIdentifier(identifier);
     }
 
-    RootStatementContext(final RootStatementContext<A, D, E> original, final QNameModule newQNameModule,
-        final CopyType typeOfCopy) {
-        super(original);
-
-        sourceContext = Preconditions.checkNotNull(original.sourceContext);
-        this.argument = original.argument;
-
-        final Collection<StatementContextBase<?, ?, ?>> declared = original.declaredSubstatements();
-        final Collection<StatementContextBase<?, ?, ?>> effective = original.effectiveSubstatements();
-        final Collection<StatementContextBase<?, ?, ?>> buffer = new ArrayList<>(declared.size() + effective.size());
-
-        for (final StatementContextBase<?, ?, ?> stmtContext : declared) {
-            if (StmtContextUtils.areFeaturesSupported(stmtContext)) {
-                buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
-            }
-        }
-        for (final StmtContext<?, ?, ?> stmtContext : effective) {
-            buffer.add(stmtContext.createCopy(newQNameModule, this, typeOfCopy));
-        }
-
-        addEffectiveSubstatements(buffer);
-    }
-
     /**
      * @return null as root cannot have parent
      */
@@ -138,36 +113,16 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         return argument;
     }
 
-    /**
-     * @return copy of this considering {@link CopyType} (augment, uses)
-     *
-     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
-     */
     @Override
-    public StatementContextBase<?, ?, ?> createCopy(final StatementContextBase<?, ?, ?> newParent,
+    public StatementContextBase<A, D, E> createCopy(final StatementContextBase<?, ?, ?> newParent,
             final CopyType typeOfCopy) {
-        return createCopy(null, newParent, typeOfCopy);
+        throw new UnsupportedOperationException("Root context cannot be copied");
     }
 
-    /**
-     * @return copy of this considering {@link CopyType} (augment, uses)
-     *
-     * @throws org.opendaylight.yangtools.yang.parser.spi.source.SourceException instance of SourceException
-     */
     @Override
     public StatementContextBase<A, D, E> createCopy(final QNameModule newQNameModule,
             final StatementContextBase<?, ?, ?> newParent, final CopyType typeOfCopy) {
-        final RootStatementContext<A, D, E> copy = new RootStatementContext<>(this, newQNameModule, typeOfCopy);
-
-        copy.appendCopyHistory(typeOfCopy, this.getCopyHistory());
-
-        if (this.getOriginalCtx() != null) {
-            copy.setOriginalCtx(this.getOriginalCtx());
-        } else {
-            copy.setOriginalCtx(this);
-        }
-        definition().onStatementAdded(copy);
-        return copy;
+        throw new UnsupportedOperationException("Root context cannot be copied");
     }
 
     @Nonnull
@@ -176,14 +131,6 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         return Optional.of(SchemaPath.ROOT);
     }
 
-    /**
-     * @return true
-     */
-    @Override
-    public boolean isRootContext() {
-        return true;
-    }
-
     @Override
     public boolean isConfiguration() {
         return true;