Implemented use of ChildOf interface in generated classes.
[yangtools.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / GeneratorJavaFile.java
index ea33be2e9ffc4af319e1828aefd9d1a5cff9fb7f..085fd1b018692b347cbd266bda4b56f1f95cd98a 100644 (file)
@@ -22,11 +22,11 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Generates files with JAVA source codes for every specified type.
- * 
+ *
  */
 public final class GeneratorJavaFile {
 
-    private static final Logger log = LoggerFactory.getLogger(GeneratorJavaFile.class);
+    private static final Logger LOG = LoggerFactory.getLogger(GeneratorJavaFile.class);
 
     /**
      * List of <code>CodeGenerator</code> instances.
@@ -41,9 +41,9 @@ public final class GeneratorJavaFile {
     /**
      * Creates instance of this class with the set of <code>types</code> for
      * which the JAVA code is generated.
-     * 
+     *
      * The instances of concrete JAVA code generator are created.
-     * 
+     *
      * @param types
      *            set of types for which JAVA code should be generated
      */
@@ -58,7 +58,7 @@ public final class GeneratorJavaFile {
     /**
      * Generates list of files with JAVA source code. Only the suitable code
      * generator is used to generate the source code for the concrete type.
-     * 
+     *
      * @param parentDirectory
      *            directory to which the output source codes should be generated
      * @return list of output files
@@ -68,10 +68,12 @@ public final class GeneratorJavaFile {
     public List<File> generateToFile(final File parentDirectory) throws IOException {
         final List<File> result = new ArrayList<>();
         for (Type type : types) {
-            for (CodeGenerator generator : generators) {
-                File generatedJavaFile = generateTypeToJavaFile(parentDirectory, type, generator);
-                if (generatedJavaFile != null) {
-                    result.add(generatedJavaFile);
+            if (type != null) {
+                for (CodeGenerator generator : generators) {
+                    File generatedJavaFile = generateTypeToJavaFile(parentDirectory, type, generator);
+                    if (generatedJavaFile != null) {
+                        result.add(generatedJavaFile);
+                    }
                 }
             }
         }
@@ -84,7 +86,7 @@ public final class GeneratorJavaFile {
      * are generated according to packages to which the type belongs (e. g. if
      * type belongs to the package <i>org.pcg</i> then in <code>parentDir</code>
      * is created directory <i>org</i> which contains <i>pcg</i>).
-     * 
+     *
      * @param parentDir
      *            directory where should be the new file generated
      * @param type
@@ -103,15 +105,15 @@ public final class GeneratorJavaFile {
     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 "
+            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());
@@ -132,8 +134,8 @@ public final class GeneratorJavaFile {
                     bw.write(generatedCode);
                 }
             } catch (IOException e) {
-                log.error(e.getMessage());
-                throw new IOException(e.getMessage());
+                LOG.error(e.getMessage());
+                throw new IOException(e);
             }
             return file;
         }
@@ -145,7 +147,7 @@ public final class GeneratorJavaFile {
      * <code>parentDirectory</code> and parsed <code>packageName</code>. The
      * parsing of <code>packageName</code> is realized as replacement of the
      * package name dots with the file system separator.
-     * 
+     *
      * @param parentDirectory
      *            <code>File</code> object with reference to parent directory
      * @param packageName