[ONOS-4627] Rpc empty folder structure issue fixed.

Change-Id: Icc383958b178bc5f5bcb1c7ddbac14c9b63272d8
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
index 78c4f64..c3bd23a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
@@ -28,6 +28,7 @@
 import org.onosproject.yangutils.datamodel.YangOutput;
 import org.onosproject.yangutils.datamodel.YangRpc;
 import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangUses;
 import org.onosproject.yangutils.translator.exception.TranslatorException;
 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
@@ -48,8 +49,10 @@
 import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
 import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
 
 /**
  * Represents rpc information extended to support java code generation.
@@ -189,11 +192,37 @@
          * Add the rpc information to the parent's service temp file.
          */
         try {
+            String rpcsChildNodePkg = getPackageDirPathFromJavaJPackage(getJavaFileInfo().getBaseCodeGenPath() +
+                    (getJavaFileInfo().getPackage() + "." + getJavaFileInfo().getJavaName()).toLowerCase());
+
             ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
                     .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
                             ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(),
                             ((YangNode) this).getName(), isInputLeafHolder(), isOutputLeafHolder(),
                             isInputSingleChildHolder(), isOutputSingleChildHolder());
+
+            if (javaAttributeInfoOfInput != null && javaAttributeInfoOfOutput != null
+                    && isInputLeafHolder() && isOutputLeafHolder()) {
+                deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
+            } else if (javaAttributeInfoOfInput != null && javaAttributeInfoOfOutput == null
+                    && isInputLeafHolder()) {
+                deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
+            } else if (javaAttributeInfoOfInput == null && javaAttributeInfoOfOutput != null
+                    && isOutputLeafHolder()) {
+                deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
+            } else {
+                YangNode node = this.getChild();
+                while (node != null) {
+                    YangNode tempNode = node.getChild();
+                    while (tempNode != null) {
+                        if (tempNode instanceof YangUses) {
+                            deleteDirectoryWhenNoFileIsGeneratedForInputOutput(rpcsChildNodePkg);
+                        }
+                        tempNode = tempNode.getNextSibling();
+                    }
+                    node = node.getNextSibling();
+                }
+            }
         } catch (IOException e) {
             throw new TranslatorException("Failed to generate code for RPC node " + this.getName());
         }
@@ -201,6 +230,17 @@
     }
 
     /**
+     * When there is no file generation for input output node we should delete the directory generated
+     * for RPC.
+     *
+     * @param emptyPkg empty package
+     * @throws IOException when fails to do IO operations
+     */
+    private void deleteDirectoryWhenNoFileIsGeneratedForInputOutput(String emptyPkg) throws IOException {
+        deleteDirectory(emptyPkg);
+    }
+
+    /**
      * Creates an attribute info object corresponding to a data model node and
      * return it.
      *
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentationHolder.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/AugmentationHolder.java
similarity index 95%
rename from utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentationHolder.java
rename to utils/yangutils/src/main/java/org/onosproject/yangutils/utils/AugmentationHolder.java
index 324a27f..b306fe2 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentationHolder.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/AugmentationHolder.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yangutils.translator.tojava;
+package org.onosproject.yangutils.utils;
 
 import java.util.List;
 
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentedInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/AugmentedInfo.java
similarity index 92%
rename from utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentedInfo.java
rename to utils/yangutils/src/main/java/org/onosproject/yangutils/utils/AugmentedInfo.java
index 64053c9..566caf0 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentedInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/AugmentedInfo.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.yangutils.translator.tojava;
+package org.onosproject.yangutils.utils;
 
 /**
  * Abstraction of an entity which represents augmented info.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 9ca906f..7e89998 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -930,7 +930,7 @@
      * Static attribute for AugmentationHolder class import package.
      */
     public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG =
-            "org.onosproject.yangutils.translator.tojava";
+            "org.onosproject.yangutils.utils";
 
     /**
      * Static attribute for AugmentationHolder class import class.
@@ -940,7 +940,7 @@
     /**
      * Static attribute for AugmentedInfo class import package.
      */
-    public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava";
+    public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.utils";
 
     /**
      * Static attribute for AugmentedInfo class import class.