Remove unused import statements in yang-parser-impl
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / YangParserImpl.java
index d47ba8c837e341e95ecd0af7dcd4fdad8b93bfe0..c50aa3344f2cb877493c826bdc68904209ffc5ea 100644 (file)
@@ -58,7 +58,6 @@ import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
@@ -1029,7 +1028,8 @@ public final class YangParserImpl implements YangContextParser {
         }
     }
 
-    private void resolveIdentity(final ModuleBuilder module, final IdentitySchemaNodeBuilder identity) {
+    private void resolveIdentity(final ModuleBuilder module,
+            final IdentitySchemaNodeBuilder identity) {
         final String baseIdentityName = identity.getBaseIdentityName();
         if (baseIdentityName != null) {
             IdentitySchemaNodeBuilder result = null;
@@ -1037,15 +1037,34 @@ public final class YangParserImpl implements YangContextParser {
                 final int line = identity.getLine();
                 String[] splittedBase = baseIdentityName.split(":");
                 if (splittedBase.length > 2) {
-                    throw new YangParseException(module.getName(), line, "Failed to parse identityref base: "
-                            + baseIdentityName);
+                    throw new YangParseException(module.getName(), line,
+                            "Failed to parse identityref base: "
+                                    + baseIdentityName);
                 }
                 String prefix = splittedBase[0];
                 String name = splittedBase[1];
-                ModuleBuilder dependentModule = BuilderUtils.getModuleByPrefix(module, prefix);
-                result = BuilderUtils.findIdentity(dependentModule.getAddedIdentities(), name);
+
+                if (prefix.equals(module.getPrefix())
+                        && name.equals(identity.getQName().getLocalName())) {
+                    throw new YangParseException(module.getName(),
+                            identity.getLine(),
+                            "Failed to parse base, identity name equals base identity name: "
+                                    + baseIdentityName);
+                }
+
+                ModuleBuilder dependentModule = BuilderUtils.getModuleByPrefix(
+                        module, prefix);
+                result = BuilderUtils.findIdentity(
+                        dependentModule.getAddedIdentities(), name);
             } else {
-                result = BuilderUtils.findIdentity(module.getAddedIdentities(), baseIdentityName);
+                if (baseIdentityName.equals(identity.getQName().getLocalName())) {
+                    throw new YangParseException(module.getName(),
+                            identity.getLine(),
+                            "Failed to parse base, identity name equals base identity name: "
+                                    + baseIdentityName);
+                }
+                result = BuilderUtils.findIdentity(module.getAddedIdentities(),
+                        baseIdentityName);
             }
             identity.setBaseIdentity(result);
         }