Propagate @Nonnull and @Nullable annotations
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / SubmoduleEffectiveStatementImpl.java
index 762d408b7882a1de318e0a19fec777eaa1fee8f4..dc3af809c769606b4cf19caeffabb80a734243a2 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,17 +7,71 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
 
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
-
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import java.util.Objects;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+public final class SubmoduleEffectiveStatementImpl extends AbstractEffectiveModule<SubmoduleStatement> {
 
-public class SubmoduleEffectiveStatementImpl extends
-        ModuleEffectiveStatementImpl {
+    private final QNameModule qNameModule;
 
     public SubmoduleEffectiveStatementImpl(
-            StmtContext<String, ModuleStatement, ?> ctx) {
+            final StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
         super(ctx);
 
+        String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
+        final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class,
+                belongsToModuleName);
+        RevisionEffectiveStatementImpl submoduleRevision = firstEffective(RevisionEffectiveStatementImpl.class);
+
+        this.qNameModule = (submoduleRevision == null ?
+                QNameModule.create(belongsToModuleQName.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV) :
+                    QNameModule.create(belongsToModuleQName.getNamespace(), submoduleRevision.argument())).intern();
+    }
+
+    @Override
+    public QNameModule getQNameModule() {
+        return qNameModule;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + Objects.hashCode(getName());
+        result = prime * result + Objects.hashCode(getYangVersion());
+        result = prime * result + Objects.hashCode(qNameModule);
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
+        if (!Objects.equals(getName(), other.getName())) {
+            return false;
+        }
+        if (!qNameModule.equals(other.qNameModule)) {
+            return false;
+        }
+        if (!Objects.equals(getYangVersion(), other.getYangVersion())) {
+            return false;
+        }
+        return true;
     }
 
 }