MDSAL-301: Binding v2 - Rework javadoc generation
[mdsal.git] / binding2 / mdsal-binding2-generator-impl / src / main / java / org / opendaylight / mdsal / binding / javav2 / generator / impl / ModuleToGenType.java
index 5f49ccc91b2262a8870f9f32303b3f0fc2ee4b37..fadecdb08f1864fe108992e6d90d8d5e7e237121 100644 (file)
@@ -9,9 +9,9 @@
 package org.opendaylight.mdsal.binding.javav2.generator.impl;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.mdsal.binding.javav2.generator.impl.AuxiliaryGenUtils.createDescription;
 import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.groupingsToGenTypes;
 import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.moduleTypeBuilder;
+import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.processUsesImplements;
 import static org.opendaylight.mdsal.binding.javav2.generator.impl.GenHelperUtil.resolveNotification;
 import static org.opendaylight.mdsal.binding.javav2.generator.util.BindingTypes.NOTIFICATION_LISTENER;
 
@@ -19,17 +19,18 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
 import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
-import org.opendaylight.mdsal.binding.javav2.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
+import org.opendaylight.mdsal.binding.javav2.generator.util.TypeComments;
 import org.opendaylight.mdsal.binding.javav2.generator.yang.types.TypeProviderImpl;
 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
+import org.opendaylight.mdsal.binding.javav2.model.api.YangSourceDefinition;
 import org.opendaylight.mdsal.binding.javav2.model.api.type.builder.GeneratedTypeBuilder;
+import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingNamespaceType;
 import org.opendaylight.mdsal.binding.javav2.util.BindingMapping;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -55,16 +56,19 @@ final class ModuleToGenType {
         genCtx = groupingsToGenTypes(module, module.getGroupings(), genCtx, schemaContext, verboseClassComments,
                 genTypeBuilders, typeProvider);
         genCtx = allIdentitiesToGenTypes(module, schemaContext, genCtx, verboseClassComments,  genTypeBuilders, typeProvider);
-        genCtx = notificationsToGenType(module, genCtx, schemaContext, genTypeBuilders, verboseClassComments, typeProvider);
 
         if (!module.getChildNodes().isEmpty()) {
             final GeneratedTypeBuilder moduleType = GenHelperUtil.moduleToDataType(module, genCtx, verboseClassComments);
             genCtx.get(module).addModuleNode(moduleType);
             final String basePackageName = BindingMapping.getRootPackageName(module);
             GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, moduleType, moduleType, module
-                    .getChildNodes(), genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider);
+                    .getChildNodes(), genCtx, schemaContext, verboseClassComments, genTypeBuilders, typeProvider,
+                    BindingNamespaceType.Data);
+            processUsesImplements(module, module, schemaContext, genCtx, BindingNamespaceType.Data);
         }
 
+        genCtx = notificationsToGenType(module, genCtx, schemaContext, genTypeBuilders, verboseClassComments, typeProvider);
+
         //after potential parent data schema nodes
         genCtx = actionsAndRPCMethodsToGenType(module, genCtx, schemaContext, verboseClassComments,
                 genTypeBuilders, typeProvider);
@@ -127,7 +131,7 @@ final class ModuleToGenType {
      *            iterate over them
      * @param schemaContext
      *            schema context only used as input parameter for method
-     *            {@link GenHelperUtil#identityToGenType(Module, String, IdentitySchemaNode, SchemaContext, Map, boolean, Map, TypeProvider, Map)}
+     *            {@link GenHelperUtil#identityToGenType(Module, String, IdentitySchemaNode, SchemaContext, Map, boolean)}
      * @param genCtx generated context
      * @return returns generated context
      *
@@ -140,10 +144,9 @@ final class ModuleToGenType {
         final String basePackageName = BindingMapping.getRootPackageName(module);
 
         if (schemaIdentities != null && !schemaIdentities.isEmpty()) {
-            Map<QName, GeneratedTOBuilderImpl> generatedIdentities = new HashMap<>();
             for (final IdentitySchemaNode identity : schemaIdentities) {
                 GenHelperUtil.identityToGenType(module, basePackageName, identity, schemaContext, genCtx,
-                    verboseClassComments, genTypeBuilders, typeProvider, generatedIdentities);
+                    verboseClassComments);
             }
         }
 
@@ -176,7 +179,8 @@ final class ModuleToGenType {
             return genCtx;
         }
 
-        final GeneratedTypeBuilder listenerInterface = moduleTypeBuilder(module, "Listener", verboseClassComments);
+        final GeneratedTypeBuilder listenerInterface = moduleTypeBuilder(module, "Listener", verboseClassComments,
+                genCtx.get(module));
         listenerInterface.addImplementsType(NOTIFICATION_LISTENER);
         final String basePackageName = BindingMapping.getRootPackageName(module);
 
@@ -184,6 +188,7 @@ final class ModuleToGenType {
             if (notification != null) {
                 resolveNotification(listenerInterface, null, basePackageName, notification, module, schemaContext,
                         verboseClassComments, genTypeBuilders, typeProvider, genCtx);
+                processUsesImplements(notification, module, schemaContext, genCtx, BindingNamespaceType.Data);
             }
         }
 
@@ -200,16 +205,23 @@ final class ModuleToGenType {
                         resolveNotification(listenerInterface, potential.getQName().getLocalName(), basePackageName,
                                 tiedNotification, module, schemaContext, verboseClassComments, genTypeBuilders,
                                 typeProvider, genCtx);
+                        processUsesImplements(tiedNotification, module, schemaContext, genCtx, BindingNamespaceType.Data);
                     }
                 }
             }
         }
 
-        if (tiedNotifications != null) {
-            listenerInterface.setDescription(createDescription(ImmutableSet.<NotificationDefinition>builder()
-                .addAll(notifications).addAll(tiedNotifications).build(), module, verboseClassComments));
-        } else {
-            listenerInterface.setDescription(createDescription(notifications, module, verboseClassComments));
+        if (verboseClassComments) {
+            if (tiedNotifications != null) {
+                listenerInterface.setYangSourceDefinition(YangSourceDefinition.of(module,
+                    ImmutableSet.<NotificationDefinition>builder().addAll(notifications).addAll(tiedNotifications)
+                        .build()));
+            } else {
+                listenerInterface.setYangSourceDefinition(YangSourceDefinition.of(module, notifications));
+            }
+            listenerInterface.addComment(TypeComments.javadoc(
+                "Interface for receiving the following YANG notifications defined in module <b>" + module.getName()
+                    + "</b>").get());
         }
 
         genCtx.get(module).addTopLevelNodeType(listenerInterface);