Added support to generate interfaces from Choices and Cases.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / controller / sal / java / api / generator / GeneratorJavaFile.java
index ab103b4..55b8d77 100644 (file)
@@ -7,38 +7,28 @@
  */
 package org.opendaylight.controller.sal.java.api.generator;
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class GeneratorJavaFile {
 
-    private static final Logger log = LoggerFactory
-            .getLogger(GeneratorJavaFile.class);
+    private static final Logger log = LoggerFactory.getLogger(GeneratorJavaFile.class);
     private final CodeGenerator interfaceGenerator;
     private final ClassCodeGenerator classGenerator;
     private final EnumGenerator enumGenerator;
-    
+
     private final Set<GeneratedType> genTypes;
     private final Set<GeneratedTransferObject> genTransferObjects;
-    private final Set<Enumeration> enumerations; 
+    private final Set<Enumeration> enumerations;
 
-    public GeneratorJavaFile(final CodeGenerator codeGenerator,
-            final Set<GeneratedType> types) {
+    public GeneratorJavaFile(final CodeGenerator codeGenerator, final Set<GeneratedType> types) {
         this.interfaceGenerator = codeGenerator;
         this.genTypes = types;
         this.genTransferObjects = new HashSet<>();
@@ -47,13 +37,12 @@ public final class GeneratorJavaFile {
         this.enumGenerator = new EnumGenerator();
     }
 
-    public GeneratorJavaFile(final Set<GeneratedType> types,
-            final Set<GeneratedTransferObject> genTransferObjects,
+    public GeneratorJavaFile(final Set<GeneratedType> types, final Set<GeneratedTransferObject> genTransferObjects,
             final Set<Enumeration> enumerations) {
         this.interfaceGenerator = new InterfaceGenerator();
         this.classGenerator = new ClassCodeGenerator();
         this.enumGenerator = new EnumGenerator();
-        
+
         this.genTypes = types;
         this.genTransferObjects = genTransferObjects;
         this.enumerations = enumerations;
@@ -62,52 +51,46 @@ public final class GeneratorJavaFile {
     public List<File> generateToFile(final File parentDirectory) throws IOException {
         final List<File> result = new ArrayList<>();
         for (GeneratedType type : genTypes) {
-            final File genFile = generateTypeToJavaFile(parentDirectory, type,
-                    interfaceGenerator);
+            final File genFile = generateTypeToJavaFile(parentDirectory, type, interfaceGenerator);
 
             if (genFile != null) {
                 result.add(genFile);
             }
         }
         for (GeneratedTransferObject transferObject : genTransferObjects) {
-            final File genFile = generateTypeToJavaFile(parentDirectory,
-                    transferObject, classGenerator);
+            final File genFile = generateTypeToJavaFile(parentDirectory, transferObject, classGenerator);
 
             if (genFile != null) {
                 result.add(genFile);
             }
         }
-        
+
         for (Enumeration enumeration : enumerations) {
-            final File genFile = generateTypeToJavaFile(parentDirectory,
-                    enumeration, enumGenerator);
+            final File genFile = generateTypeToJavaFile(parentDirectory, enumeration, enumGenerator);
 
             if (genFile != null) {
                 result.add(genFile);
             }
         }
-        
+
         return result;
     }
 
-    private File generateTypeToJavaFile(final File parentDir, final Type type,
-            final CodeGenerator generator) throws IOException {
+    private File generateTypeToJavaFile(final File parentDir, final Type type, final CodeGenerator generator)
+            throws IOException {
         if (parentDir == null) {
             log.warn("Parent Directory not specified, files will be generated "
                     + "accordingly to generated Type package path.");
         }
         if (type == null) {
-            log.error("Cannot generate Type into Java File because " +
-                       "Generated Type is NULL!");
+            log.error("Cannot generate Type into Java File because " + "Generated Type is NULL!");
             throw new IllegalArgumentException("Generated Type Cannot be NULL!");
         }
         if (generator == null) {
-            log.error("Cannot generate Type into Java File because " +
-                       "Code Generator instance is NULL!");
+            log.error("Cannot generate Type into Java File because " + "Code Generator instance is NULL!");
             throw new IllegalArgumentException("Code Generator Cannot be NULL!");
         }
-        final File packageDir = packageToDirectory(parentDir,
-                type.getPackageName());
+        final File packageDir = packageToDirectory(parentDir, type.getPackageName());
 
         if (!packageDir.exists()) {
             packageDir.mkdirs();
@@ -127,8 +110,7 @@ public final class GeneratorJavaFile {
         return file;
     }
 
-    private File packageToDirectory(final File parentDirectory,
-            final String packageName) {
+    private File packageToDirectory(final File parentDirectory, final String packageName) {
         if (packageName == null) {
             throw new IllegalArgumentException("Package Name cannot be NULL!");
         }