Fix checkstyle in mdsal-binding-dom-codec
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / gen / impl / AbstractStreamWriterGenerator.java
index 9f07fefc23a487c1cef58cdace7a278c6f498720..b54256c1a50059907df43b70548fa729c22b273b 100644 (file)
@@ -60,19 +60,18 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
          * fix the static declared fields to final once we initialize them. If we
          * cannot get access, that's fine, too.
          */
-        Field f = null;
+        Field field = null;
         try {
-            f = Field.class.getDeclaredField("modifiers");
-            f.setAccessible(true);
+            field = Field.class.getDeclaredField("modifiers");
+            field.setAccessible(true);
         } catch (NoSuchFieldException | SecurityException e) {
             LOG.warn("Could not get Field modifiers field, serializers run at decreased efficiency", e);
         }
 
-        FIELD_MODIFIERS = f;
+        FIELD_MODIFIERS = field;
     }
 
     protected AbstractStreamWriterGenerator(final JavassistUtils utils) {
-        super();
         this.javassist = Preconditions.checkNotNull(utils,"JavassistUtils instance is required.");
         this.serializeArguments = new CtClass[] {
                 javassist.asCtClass(DataObjectSerializerRegistry.class),
@@ -98,7 +97,8 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
         return implementations.getUnchecked(cls).getClass().getName();
     }
 
-    private final class SerializerImplementationLoader extends CacheLoader<Class<?>, DataObjectSerializerImplementation> {
+    private final class SerializerImplementationLoader
+            extends CacheLoader<Class<?>, DataObjectSerializerImplementation> {
 
         private static final String GETINSTANCE_METHOD_NAME = "getInstance";
         private static final String SERIALIZER_SUFFIX = "$StreamWriter";
@@ -111,7 +111,8 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
         @SuppressWarnings("unchecked")
         public DataObjectSerializerImplementation load(final Class<?> type) throws Exception {
             Preconditions.checkArgument(BindingReflections.isBindingClass(type));
-            Preconditions.checkArgument(DataContainer.class.isAssignableFrom(type),"DataContainer is not assingnable from %s from classloader %s.",type,type.getClassLoader());
+            Preconditions.checkArgument(DataContainer.class.isAssignableFrom(type),
+                "DataContainer is not assingnable from %s from classloader %s.", type, type.getClassLoader());
 
             final String serializerName = getSerializerName(type);
 
@@ -130,11 +131,14 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
         }
 
         private Class<? extends DataObjectSerializerImplementation> generateSerializer(final Class<?> type,
-                final String serializerName) throws CannotCompileException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, NoSuchFieldException {
+                final String serializerName) throws CannotCompileException, IllegalAccessException,
+                IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException,
+                NoSuchFieldException {
             final DataObjectSerializerSource source = generateEmitterSource(type, serializerName);
             final CtClass poolClass = generateEmitter0(type, source, serializerName);
             @SuppressWarnings("unchecked")
-            final Class<? extends DataObjectSerializerImplementation> cls = poolClass.toClass(type.getClassLoader(), type.getProtectionDomain());
+            final Class<? extends DataObjectSerializerImplementation> cls = poolClass.toClass(type.getClassLoader(),
+                type.getProtectionDomain());
 
             /*
              * Due to OSGi class loader rules we cannot initialize the fields during
@@ -166,18 +170,18 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
         final DataObjectSerializerSource source;
         if (schema instanceof ContainerSchemaNode) {
             source = generateContainerSerializer(generatedType, (ContainerSchemaNode) schema);
-        } else if (schema instanceof ListSchemaNode){
+        } else if (schema instanceof ListSchemaNode) {
             final ListSchemaNode casted = (ListSchemaNode) schema;
             if (casted.getKeyDefinition().isEmpty()) {
                 source = generateUnkeyedListEntrySerializer(generatedType, casted);
             } else {
                 source = generateMapEntrySerializer(generatedType, casted);
             }
-        } else if(schema instanceof AugmentationSchema) {
+        } else if (schema instanceof AugmentationSchema) {
             source = generateSerializer(generatedType,(AugmentationSchema) schema);
-        } else if(schema instanceof ChoiceCaseNode) {
+        } else if (schema instanceof ChoiceCaseNode) {
             source = generateCaseSerializer(generatedType,(ChoiceCaseNode) schema);
-        } else if(schema instanceof NotificationDefinition) {
+        } else if (schema instanceof NotificationDefinition) {
             source = generateNotificationSerializer(generatedType,(NotificationDefinition) schema);
         } else {
             throw new UnsupportedOperationException("Schema type " + schema.getClass() + " is not supported");
@@ -185,7 +189,8 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
         return source;
     }
 
-    private CtClass generateEmitter0(final Class<?> type, final DataObjectSerializerSource source, final String serializerName) {
+    private CtClass generateEmitter0(final Class<?> type, final DataObjectSerializerSource source,
+            final String serializerName) {
         final CtClass product;
 
         /*
@@ -200,21 +205,22 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
             (Supplier<String>) () -> source.getSerializerBody().toString());
 
         try {
-            product = javassist.instantiatePrototype(DataObjectSerializerPrototype.class.getName(), serializerName, cls -> {
-                // Generate any static fields
-                for (final StaticConstantDefinition def : source.getStaticConstants()) {
-                    final CtField field = new CtField(javassist.asCtClass(def.getType()), def.getName(), cls);
-                    field.setModifiers(Modifier.PRIVATE + Modifier.STATIC);
-                    cls.addField(field);
-                }
-
-                // Replace serialize() -- may reference static fields
-                final CtMethod serializeTo = cls.getDeclaredMethod(SERIALIZE_METHOD_NAME, serializeArguments);
-                serializeTo.setBody(body);
-
-                // The prototype is not visible, so we need to take care of that
-                cls.setModifiers(Modifier.setPublic(cls.getModifiers()));
-            });
+            product = javassist.instantiatePrototype(DataObjectSerializerPrototype.class.getName(), serializerName,
+                cls -> {
+                    // Generate any static fields
+                    for (final StaticConstantDefinition def : source.getStaticConstants()) {
+                        final CtField field = new CtField(javassist.asCtClass(def.getType()), def.getName(), cls);
+                        field.setModifiers(Modifier.PRIVATE + Modifier.STATIC);
+                        cls.addField(field);
+                    }
+
+                    // Replace serialize() -- may reference static fields
+                    final CtMethod serializeTo = cls.getDeclaredMethod(SERIALIZE_METHOD_NAME, serializeArguments);
+                    serializeTo.setBody(body);
+
+                    // The prototype is not visible, so we need to take care of that
+                    cls.setModifiers(Modifier.setPublic(cls.getModifiers()));
+                });
         } catch (final NotFoundException e) {
             LOG.error("Failed to instatiate serializer {}", source, e);
             throw new LinkageError("Unexpected instantation problem: serializer prototype not found", e);
@@ -223,26 +229,25 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
     }
 
     /**
-     * Generates serializer source code for supplied container node,
-     * which will read supplied binding type and invoke proper methods
-     * on supplied {@link BindingStreamEventWriter}.
+     * Generates serializer source code for supplied container node, which will read supplied binding type and invoke
+     * proper methods on supplied {@link BindingStreamEventWriter}.
+     *
      * <p>
-     * Implementation is required to recursively invoke events
-     * for all reachable binding objects.
+     * Implementation is required to recursively invoke events for all reachable binding objects.
      *
      * @param type Binding type of container
      * @param node Schema of container
      * @return Source for container node writer
      */
-    protected abstract DataObjectSerializerSource generateContainerSerializer(GeneratedType type, ContainerSchemaNode node);
+    protected abstract DataObjectSerializerSource generateContainerSerializer(GeneratedType type,
+            ContainerSchemaNode node);
 
     /**
-     * Generates serializer source for supplied case node,
-     * which will read supplied binding type and invoke proper methods
-     * on supplied {@link BindingStreamEventWriter}.
+     * Generates serializer source for supplied case node, which will read supplied binding type and invoke proper
+     * methods on supplied {@link BindingStreamEventWriter}.
+     *
      * <p>
-     * Implementation is required to recursively invoke events
-     * for all reachable binding objects.
+     * Implementation is required to recursively invoke events for all reachable binding objects.
      *
      * @param type Binding type of case
      * @param node Schema of case
@@ -251,12 +256,11 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
     protected abstract DataObjectSerializerSource generateCaseSerializer(GeneratedType type, ChoiceCaseNode node);
 
     /**
-     * Generates serializer source for supplied list node,
-     * which will read supplied binding type and invoke proper methods
-     * on supplied {@link BindingStreamEventWriter}.
+     * Generates serializer source for supplied list node, which will read supplied binding type and invoke proper
+     * methods on supplied {@link BindingStreamEventWriter}.
+     *
      * <p>
-     * Implementation is required to recursively invoke events
-     * for all reachable binding objects.
+     * Implementation is required to recursively invoke events for all reachable binding objects.
      *
      * @param type Binding type of list
      * @param node Schema of list
@@ -265,26 +269,25 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
     protected abstract DataObjectSerializerSource generateMapEntrySerializer(GeneratedType type, ListSchemaNode node);
 
     /**
-     * Generates serializer source for supplied list node,
-     * which will read supplied binding type and invoke proper methods
-     * on supplied {@link BindingStreamEventWriter}.
+     * Generates serializer source for supplied list node, which will read supplied binding type and invoke proper
+     * methods on supplied {@link BindingStreamEventWriter}.
+     *
      * <p>
-     * Implementation is required to recursively invoke events
-     * for all reachable binding objects.
+     * Implementation is required to recursively invoke events for all reachable binding objects.
      *
      * @param type Binding type of list
      * @param node Schema of list
      * @return Source for list node writer
      */
-    protected abstract DataObjectSerializerSource generateUnkeyedListEntrySerializer(GeneratedType type, ListSchemaNode node);
+    protected abstract DataObjectSerializerSource generateUnkeyedListEntrySerializer(GeneratedType type,
+            ListSchemaNode node);
 
     /**
-     * Generates serializer source for supplied augmentation node,
-     * which will read supplied binding type and invoke proper methods
-     * on supplied {@link BindingStreamEventWriter}.
+     * Generates serializer source for supplied augmentation node, which will read supplied binding type and invoke
+     * proper methods on supplied {@link BindingStreamEventWriter}.
+     *
      * <p>
-     * Implementation is required to recursively invoke events
-     * for all reachable binding objects.
+     * Implementation is required to recursively invoke events for all reachable binding objects.
      *
      * @param type Binding type of augmentation
      * @param schema Schema of augmentation
@@ -293,17 +296,16 @@ abstract class AbstractStreamWriterGenerator extends AbstractGenerator implement
     protected abstract DataObjectSerializerSource generateSerializer(GeneratedType type, AugmentationSchema schema);
 
     /**
-     * Generates serializer source for notification node,
-     * which will read supplied binding type and invoke proper methods
-     * on supplied {@link BindingStreamEventWriter}.
+     * Generates serializer source for notification node, which will read supplied binding type and invoke proper
+     * methods on supplied {@link BindingStreamEventWriter}.
+     *
      * <p>
-     * Implementation is required to recursively invoke events
-     * for all reachable binding objects.
+     * Implementation is required to recursively invoke events for all reachable binding objects.
      *
      * @param type Binding type of notification
      * @param node Schema of notification
      * @return Source for notification node writer
      */
-    protected abstract DataObjectSerializerSource generateNotificationSerializer(GeneratedType type, NotificationDefinition node);
-
+    protected abstract DataObjectSerializerSource generateNotificationSerializer(GeneratedType type,
+            NotificationDefinition node);
 }