Add better messages to getTypeWithSchema() 96/42296/2
authorRobert Varga <rovarga@cisco.com>
Fri, 22 Jul 2016 09:27:35 +0000 (11:27 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 22 Jul 2016 12:51:52 +0000 (12:51 +0000)
This will aid debugging issues.

Change-Id: Ic1562e092a073ee2066172efbebd2ca9a64fa9b4
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/util/BindingRuntimeContext.java

index 7fbdcd61492bbfb52ba041379c36a99b53c740eb..d1335f945a0558a6d1d636212705854092eeabd9 100644 (file)
@@ -287,10 +287,12 @@ public class BindingRuntimeContext implements Immutable {
 
     private Entry<GeneratedType, Object> getTypeWithSchema(final Type referencedType) {
         final Object schema = typeToDefiningSchema.get(referencedType);
+        Preconditions.checkNotNull(schema, "Failed to find schema for type %s", referencedType);
+
         final Type definedType = typeToDefiningSchema.inverse().get(schema);
-        Preconditions.checkNotNull(schema);
-        Preconditions.checkNotNull(definedType);
-        if(definedType instanceof GeneratedTypeBuilder) {
+        Preconditions.checkNotNull(definedType, "Failed to find defined type for %s schema %s", referencedType, schema);
+
+        if (definedType instanceof GeneratedTypeBuilder) {
             return new SimpleEntry<>(((GeneratedTypeBuilder) definedType).toInstance(), schema);
         }
         Preconditions.checkArgument(definedType instanceof GeneratedType,"Type {} is not GeneratedType", referencedType);
@@ -410,7 +412,7 @@ public class BindingRuntimeContext implements Immutable {
     }
 
     private static Type referencedType(final Type type) {
-        if(type instanceof ReferencedTypeImpl) {
+        if (type instanceof ReferencedTypeImpl) {
             return type;
         }
         return new ReferencedTypeImpl(type.getPackageName(), type.getName());
@@ -419,10 +421,10 @@ public class BindingRuntimeContext implements Immutable {
     private static Set<Type> collectAllContainerTypes(final GeneratedType type, final Set<Type> collection) {
         for (final MethodSignature definition : type.getMethodDefinitions()) {
             Type childType = definition.getReturnType();
-            if(childType instanceof ParameterizedType) {
+            if (childType instanceof ParameterizedType) {
                 childType = ((ParameterizedType) childType).getActualTypeArguments()[0];
             }
-            if(childType instanceof GeneratedType || childType instanceof GeneratedTypeBuilder) {
+            if (childType instanceof GeneratedType || childType instanceof GeneratedTypeBuilder) {
                 collection.add(referencedType(childType));
             }
         }