[ONOS-5527,ONOS-5529] process sub tree filtering in generted code changes.

Change-Id: I2b5562ee57d887c25f4a6b55cd25006e288563c0
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
index fc2bc6a..76a10e1 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -307,7 +307,7 @@
             throw new DataModelException("Child to be added is not atomic, " +
                                                  "it already has a previous " +
                                                  "sibling " + getName() +
-                                                 " in " +    getLineNumber() +
+                                                 " in " + getLineNumber() +
                                                  " at " + getCharPosition() +
                                                  " in " + getFileName() + "\"");
         }
@@ -607,10 +607,10 @@
         if (newSibling.getNodeType() == null) {
             throw new DataModelException("Cloned abstract node cannot be " +
                                                  "inserted into a tree "
-                    + getName() + " in " +
-                    getLineNumber() + " at " +
-                    getCharPosition()
-                    + " in " + getFileName() + "\"");
+                                                 + getName() + " in " +
+                                                 getLineNumber() + " at " +
+                                                 getCharPosition()
+                                                 + " in " + getFileName() + "\"");
         }
 
         if (newSibling.getParent() == null) {
@@ -788,7 +788,7 @@
      */
     public void addToYsnContextInfoMap(YangSchemaNodeIdentifier
                                                yangSchemaNodeIdentifier, YangSchemaNodeContextInfo
-            yangSchemaNodeContextInfo) {
+                                               yangSchemaNodeContextInfo) {
         getYsnContextInfoMap().put(yangSchemaNodeIdentifier, yangSchemaNodeContextInfo);
     }
 
@@ -796,10 +796,10 @@
     public void isValueValid(String value)
             throws DataModelException {
         throw new DataModelException("Value validation asked for YANG node. "
-                + getName() + " in " +
-                getLineNumber() + " at " +
-                getCharPosition()
-                + " in " + getFileName() + "\"");
+                                             + getName() + " in " +
+                                             getLineNumber() + " at " +
+                                             getCharPosition()
+                                             + " in " + getFileName() + "\"");
     }
 
     @Override
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index 4b8ca9c..00a7baf 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -92,9 +92,7 @@
 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getChoiceChildNodes;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getNodesImports;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
 import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
 import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
@@ -607,14 +605,8 @@
             throws IOException {
         TempJavaBeanFragmentFiles tempFiles =
                 getBeanFiles((JavaCodeGeneratorInfo) parent);
-        if (curNode instanceof YangChoice) {
-            tempFiles.setAttrNode(curNode);
-            for (JavaQualifiedTypeInfoTranslator info : getNodesImports(
-                    getChoiceChildNodes((YangChoice) curNode), config))
-                tempFiles.addToSubTreeImports(info);
-        } else {
-            tempFiles.setAttrNode(null);
-        }
+        tempFiles.setAttrNode(curNode);
+
         JavaAttributeInfo attr =
                 getCurNodeAsAttributeInTarget(curNode, parent, isList,
                                               tempFiles);
@@ -1779,9 +1771,6 @@
         if (curNode.isOpTypeReq()) {
             addSubTreeImportStrings(imports);
         }
-        if (curNode instanceof YangCase) {
-            removeCaseParentImport(curNode, imports);
-        }
 
         if ((fileType & BUILDER_CLASS_MASK) != 0 ||
                 (fileType & DEFAULT_CLASS_MASK) != 0) {
@@ -1828,15 +1817,6 @@
         freeTemporaryResources(false);
     }
 
-    //Removes case's parent import.
-    private void removeCaseParentImport(YangNode node, List<String> imports) {
-        YangNode parent = node.getParent();
-        JavaFileInfo info = ((JavaFileInfoContainer) parent).getJavaFileInfo();
-        String impt = getImportString(info.getPackage(),
-                                      getCapitalCase(info.getJavaName()));
-        imports.remove(impt);
-    }
-
     //Adds import for array list.
     private void addArrayListImport(List<String> imports) {
         if (imports.contains(javaImportData.getImportForList())) {
@@ -2143,4 +2123,5 @@
         }
         sortImports(imports);
     }
+
 }
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
index ab1c8f4..51aec14 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
@@ -147,7 +147,7 @@
 
         translator.setJavaName(getAugmentClassName(
                 (YangJavaAugmentTranslator) info, config));
-        translator.setPackage(getAugmentsNodePackage((YangNode) info, config));
+        translator.setPackage(getAugmentsNodePackage((YangNode) info));
         updateCommonPackageInfo(translator, info, config);
     }
 
@@ -155,24 +155,24 @@
      * Returns package for augment node.
      *
      * @param yangNode augment node
-     * @param config   plugin configurations
      * @return package for augment node
      */
-    private static String getAugmentsNodePackage(YangNode yangNode,
-                                                 YangPluginConfig config) {
+    private static String getAugmentsNodePackage(YangNode yangNode) {
         YangAugment augment = (YangAugment) yangNode;
         StringBuilder augmentPkg = new StringBuilder();
-        augmentPkg.append(getCurNodePackage(augment));
+        augmentPkg.append(getCurNodePackage(augment)).append(PERIOD)
+                .append(getPkgFromAugment(augment));
+        return augmentPkg.toString();
+    }
 
+    private static String getPkgFromAugment(YangAugment augment) {
         StringBuilder pkg = new StringBuilder();
-        pkg.append(PERIOD);
         for (YangAtomicPath atomicPath : augment.getTargetNode()) {
             pkg.append(getCamelCase(atomicPath.getNodeIdentifier().getName(),
-                                    config.getConflictResolver()))
+                                    null))
                     .append(PERIOD);
         }
-        augmentPkg.append(trimAtLast(pkg.toString(), PERIOD).toLowerCase());
-        return augmentPkg.toString();
+        return trimAtLast(pkg.toString(), PERIOD).toLowerCase();
     }
 
     /**
@@ -630,17 +630,12 @@
 
         List<String> clsInfo = new ArrayList<>();
         String add = null;
-        if (node instanceof YangCase) {
-            YangNode parent = node.getParent();
-            if (parent instanceof YangAugment) {
-                add = getCamelCase(((YangAugment) parent)
-                                           .getAugmentedNode().getName(), null);
-            }
-        }
         while (node.getParent() != null) {
             if (node instanceof YangJavaAugmentTranslator) {
-                clsInfo.add(getAugmentClassName((YangAugment) node,
-                                                config));
+                YangJavaAugmentTranslator augment =
+                        (YangJavaAugmentTranslator) node;
+                clsInfo.add(getAugmentClassName(augment, config));
+                clsInfo.add(getPkgFromAugment(augment));
             } else {
                 clsInfo.add(getCamelCase(node.getName(), config
                         .getConflictResolver()));
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
index a63bca0..9161afe 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
@@ -15,10 +15,6 @@
  */
 package org.onosproject.yangutils.translator.tojava.javamodel;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
 import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaIdentity;
 import org.onosproject.yangutils.translator.exception.TranslatorException;
 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
@@ -29,12 +25,21 @@
 import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
 import org.onosproject.yangutils.utils.io.YangPluginConfig;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
 import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_FILE_EXTENSION;
 import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
@@ -45,9 +50,6 @@
 public class YangJavaIdentityTranslator extends YangJavaIdentity
         implements JavaCodeGeneratorInfo, JavaCodeGenerator {
 
-    //File type extension for java classes.
-    private static final String JAVA_FILE_EXTENSION = ".java";
-
     //Contains the information of the imported.
     private transient JavaImportData importData;
 
@@ -74,11 +76,8 @@
     @Override
     public JavaFileInfoTranslator getJavaFileInfo() {
         if (javaFileInfo == null) {
-            throw new TranslatorException("Missing java info in java datamodel node " +
-                    getName() + " in " +
-                    getLineNumber() + " at " +
-                    getCharPosition()
-                    + " in " + getFileName());
+            throw new TranslatorException("Missing java info in java identity" +
+                                                  " node " + getName());
         }
         return (JavaFileInfoTranslator) javaFileInfo;
     }
@@ -125,48 +124,53 @@
         try {
 
             updatePackageInfo(this, yangPlugin);
-            JavaQualifiedTypeInfoTranslator basePkgInfo = new JavaQualifiedTypeInfoTranslator();
-            String className = getCapitalCase(getJavaFileInfo().getJavaName());
-            String path = getJavaFileInfo().getPackageFilePath();
+            JavaQualifiedTypeInfoTranslator basePkgInfo =
+                    new JavaQualifiedTypeInfoTranslator();
+            JavaFileInfoTranslator itsInfo = getJavaFileInfo();
+            String className = getCapitalCase(itsInfo.getJavaName());
+            String path = itsInfo.getPackageFilePath();
             createPackage(this);
             List<String> imports = null;
             boolean isQualified;
 
             if (getBaseNode() != null && getBaseNode().getReferredIdentity() != null) {
                 if (!(getBaseNode().getReferredIdentity() instanceof YangJavaIdentityTranslator)) {
-                    throw new TranslatorException("Failed to prepare generate code entry for base node "
-                            + getName() + " in " +
-                            getLineNumber() + " at " +
-                            getCharPosition()
-                            + " in " + getFileName());
+                    throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
+                                                              EMPTY_STRING));
+
                 }
-                YangJavaIdentityTranslator baseIdentity = (YangJavaIdentityTranslator) getBaseNode()
-                        .getReferredIdentity();
-                String baseClassName = getCapitalCase(baseIdentity.getJavaFileInfo().getJavaName());
-                String basePkg = baseIdentity.getJavaFileInfo().getPackage();
+                YangJavaIdentityTranslator base =
+                        (YangJavaIdentityTranslator) getBaseNode().getReferredIdentity();
+                JavaFileInfoTranslator info = base.getJavaFileInfo();
+                String baseClassName = getCapitalCase(info.getJavaName());
+                String basePkg = info.getPackage();
                 basePkgInfo.setClassInfo(baseClassName);
                 basePkgInfo.setPkgInfo(basePkg);
-                isQualified = importData.addImportInfo(basePkgInfo, className, getJavaFileInfo().getPackage());
+                isQualified = importData.addImportInfo(basePkgInfo, className,
+                                                       javaFileInfo.getPackage());
                 if (!isQualified) {
                     imports = importData.getImports();
                 }
             }
 
-            File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
+            File file = getFileObject(path, className, JAVA_FILE_EXTENSION, itsInfo);
 
             initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
             file = validateLineLength(file);
+            //Add to string and from string method to class
+            addStringMethodsToClass(file);
+
             closeFile(file, false);
         } catch (IOException e) {
-            throw new TranslatorException(
-                    "Failed to prepare generate code entry for identity node " +
-                            getName() + " in " +
-                            getLineNumber() + " at " +
-                            getCharPosition()
-                            + " in " + getFileName());
+            throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
+                                                      e.getLocalizedMessage()));
         }
     }
 
+    private void addStringMethodsToClass(File file) {
+        //TODO: add implementation.
+    }
+
     /**
      * Create a java file using the YANG container info.
      *
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index ed14647..4f8c94d 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -134,6 +134,7 @@
 import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafListSubtreeFiltering;
 import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafSubtreeFiltering;
 import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubTreeFilteringEnd;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubTreeForChoiceInterface;
 import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFilteringStart;
 import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFunctionBody;
 import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.addDefaultConstructor;
@@ -231,6 +232,12 @@
         }
         List<String> methods = new ArrayList<>();
 
+        //Add only for choice class
+        if (curNode instanceof YangChoice) {
+            insertDataIntoJavaFile(file, getProcessSubTreeForChoiceInterface(
+                    curNode));
+        }
+
         if (attrPresent) {
             // Add getter methods to interface file.
             try {
@@ -529,18 +536,18 @@
                 if (curNode instanceof YangLeavesHolder) {
                     if (((YangLeavesHolder) curNode).getListOfLeaf() != null &&
                             !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
-                        methods.add(getProcessLeafSubtreeFiltering(curNode, config,
+                        methods.add(getProcessLeafSubtreeFiltering(curNode,
                                                                    path));
                     }
                     if (((YangLeavesHolder) curNode).getListOfLeafList() != null &&
                             !((YangLeavesHolder) curNode).getListOfLeafList().isEmpty()) {
-                        methods.add(getProcessLeafListSubtreeFiltering(curNode, config,
+                        methods.add(getProcessLeafListSubtreeFiltering(curNode,
                                                                        path));
                     }
                 }
 
                 if (curNode.getChild() != null) {
-                    methods.add(getProcessChildNodeSubtreeFiltering(curNode, config,
+                    methods.add(getProcessChildNodeSubtreeFiltering(curNode,
                                                                     path));
                 }
             }
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 5fc99c0..a93a5cf 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -117,6 +117,7 @@
 import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
 import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_STRING;
 import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
 import static org.onosproject.yangutils.utils.UtilConstants.FOR;
 import static org.onosproject.yangutils.utils.UtilConstants.FOR_TYPE_STRING;
@@ -133,6 +134,7 @@
 import static org.onosproject.yangutils.utils.UtilConstants.IF;
 import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
 import static org.onosproject.yangutils.utils.UtilConstants.INT;
+import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
 import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF;
 import static org.onosproject.yangutils.utils.UtilConstants.LEAF;
 import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
@@ -181,6 +183,7 @@
 import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
 import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
 import static org.onosproject.yangutils.utils.UtilConstants.THIS;
+import static org.onosproject.yangutils.utils.UtilConstants.THROW_NEW;
 import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
 import static org.onosproject.yangutils.utils.UtilConstants.TO_CAPS;
 import static org.onosproject.yangutils.utils.UtilConstants.TO_STRING_METHOD;
@@ -1135,8 +1138,8 @@
                 .append(methodBody(SETTER, attr1, null,
                                    TWELVE_SPACE_INDENTATION, EMPTY_STRING,
                                    null, false, attr1));
-        String str = EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE +
-                ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+        String str = EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+                ELSE + OPEN_CURLY_BRACKET + NEW_LINE;
         constructor.append(str)
                 .append(methodBody(SETTER, attr2, null,
                                    TWELVE_SPACE_INDENTATION, EMPTY_STRING,
@@ -1612,6 +1615,21 @@
      * @return generated fromString code for bits.
      */
     private static String getFromStringForBits(String bitClassName) {
+     /* generate code will look like this.
+       public static BitSet fromString(String valInString) {
+            BitSet tmpVal = new BitSet();
+            String[] bitNames = valInString.trim().split(Pattern.quote(" "));
+            for (String bitName : bitNames) {
+                Bits bits = of(bitName);
+                if (bits != null) {
+                    tmpVal.set(bits.bits());
+                }
+            }
+            if (tmpVal.isEmpty()) {
+                throw new NoSuchElementException("no such element found in bits");
+            }
+            return tmpVal;
+        }*/
         StringBuilder sBuild = new StringBuilder();
         sBuild.append(methodSignature(FROM_STRING_METHOD_NAME, null,
                                       PUBLIC + SPACE + STATIC,
@@ -1632,18 +1650,23 @@
         String small = getSmallCase(bitClassName);
         sBuild.append(TWELVE_SPACE_INDENTATION).append(bitClassName).append(
                 SPACE).append(small).append(SPACE).append(EQUAL).append(
-                SPACE).append(bitClassName).append(PERIOD).append(OF).append(
+                SPACE).append(OF).append(
                 getOpenCloseParaWithValue(BIT_NAME_VAR)).append(signatureClose());
         String condition = small + SPACE + NOT + EQUAL + SPACE + NULL;
         sBuild.append(getIfConditionBegin(TWELVE_SPACE_INDENTATION, condition))
-                .append(TWELVE_SPACE_INDENTATION)
+                .append(SIXTEEN_SPACE_INDENTATION)
                 .append(TMP_VAL).append(PERIOD).append(SET_METHOD_PREFIX)
                 .append(OPEN_PARENTHESIS)
                 .append(small).append(PERIOD).append(small).append(
                 OPEN_CLOSE_BRACKET_STRING).append(CLOSE_PARENTHESIS)
                 .append(signatureClose()).append(methodClose(TWELVE_SPACE))
                 .append(methodClose(EIGHT_SPACE));
-        sBuild.append(getReturnString(TMP_VAL, EIGHT_SPACE_INDENTATION))
+
+        condition = TMP_VAL + PERIOD + IS_EMPTY;
+        sBuild.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION, condition));
+        sBuild.append(TWELVE_SPACE_INDENTATION).append(THROW_NEW)
+                .append(EXCEPTION_STRING).append(methodClose(EIGHT_SPACE))
+                .append(getReturnString(TMP_VAL, EIGHT_SPACE_INDENTATION))
                 .append(signatureClose()).append(methodClose(FOUR_SPACE));
         return sBuild.toString();
     }
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
index 2ab8bc3..f680b50 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
@@ -16,20 +16,13 @@
 
 package org.onosproject.yangutils.translator.tojava.utils;
 
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangChoice;
 import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangType;
 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
 import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -49,7 +42,6 @@
 import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE;
 import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIfConditionForAddToListMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getQualifiedInfo;
 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
 import static org.onosproject.yangutils.utils.UtilConstants.AND;
 import static org.onosproject.yangutils.utils.UtilConstants.APPEND;
@@ -887,7 +879,7 @@
      */
     static String getElseIfConditionBegin(String indentation,
                                           String condition) {
-        return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE +
+        return indentation + CLOSE_CURLY_BRACKET + ELSE +
                 getIfConditionBegin(EMPTY_STRING, condition);
     }
 
@@ -1305,48 +1297,4 @@
     static String getQualifiedString(String pkg, String cls) {
         return pkg + PERIOD + cls;
     }
-
-    /**
-     * Returns import list for node list.
-     *
-     * @param nodes  node list
-     * @param config plugin config
-     * @return import list
-     */
-    public static List<JavaQualifiedTypeInfoTranslator> getNodesImports(List<YangNode> nodes,
-                                                                        YangPluginConfig config) {
-        List<JavaQualifiedTypeInfoTranslator> imports = new ArrayList<>();
-        for (YangNode node : nodes) {
-            JavaQualifiedTypeInfoTranslator qInfo = getQualifiedInfo(node,
-                                                                     config);
-            imports.add(qInfo);
-        }
-        return imports;
-    }
-
-    /**
-     * Returns list of child node for choice.
-     *
-     * @param choice choice node
-     * @return list of child nodes
-     */
-    public static List<YangNode> getChoiceChildNodes(YangChoice choice) {
-        List<YangNode> childs = new ArrayList<>();
-        YangNode child = choice.getChild();
-        while (child != null) {
-            childs.add(child);
-            child = child.getNextSibling();
-        }
-
-        List<YangAugment> augments = choice.getAugmentedInfoList();
-        YangNode augmentCase;
-        for (YangAugment augment : augments) {
-            augmentCase = augment.getChild();
-            while (augmentCase != null) {
-                childs.add(augmentCase);
-                augmentCase = augmentCase.getNextSibling();
-            }
-        }
-        return childs;
-    }
 }
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
index c815027..fb7b732 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
@@ -18,21 +18,19 @@
 
 import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
 import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangCase;
 import org.onosproject.yangutils.datamodel.YangChoice;
 import org.onosproject.yangutils.datamodel.YangLeafRef;
 import org.onosproject.yangutils.datamodel.YangLeavesHolder;
 import org.onosproject.yangutils.datamodel.YangNode;
 import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
 import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
 import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
 import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
 import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
 
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -40,22 +38,22 @@
 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getNodesPackage;
 import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.EIGHT_SPACE;
 import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
 import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.SIXTEEN_SPACE;
 import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWELVE_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_EIGHT_SPACE;
 import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_FOUR_SPACE;
 import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_SPACE;
 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
 import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getAppInstanceAttrString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getChoiceChildNodes;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getCollectionIteratorForLoopBegin;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getElseIfConditionBegin;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getEqualEqualString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getForLoopString;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIfConditionBegin;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getLeafFlagSetString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getNewInstance;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOpenCloseParaWithValue;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getReturnString;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getTwoParaEqualsString;
@@ -63,6 +61,7 @@
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
 import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.valueAssign;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
 import static org.onosproject.yangutils.utils.UtilConstants.AND_OPERATION;
 import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
@@ -72,10 +71,10 @@
 import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
 import static org.onosproject.yangutils.utils.UtilConstants.BUILD_FOR_FILTER;
-import static org.onosproject.yangutils.utils.UtilConstants.CHOICE_STF_METHOD_NAME;
 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
 import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
 import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
 import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
 import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
 import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
@@ -83,14 +82,12 @@
 import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
 import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
 import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.FLAG;
 import static org.onosproject.yangutils.utils.UtilConstants.GET;
-import static org.onosproject.yangutils.utils.UtilConstants.IF;
-import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
+import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE;
 import static org.onosproject.yangutils.utils.UtilConstants.IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG;
 import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
 import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_ALL_SCHEMA_CHILD_FLAG;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW;
 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
 import static org.onosproject.yangutils.utils.UtilConstants.NOT;
 import static org.onosproject.yangutils.utils.UtilConstants.NULL;
@@ -102,9 +99,12 @@
 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
 import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
 import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_CHILD_NODE_STF_PARAM;
+import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_LEAF_LIST_STF_PARAM;
+import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_LEAF_STF_PARAM;
 import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
 import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
+import static org.onosproject.yangutils.utils.UtilConstants.RESULT;
+import static org.onosproject.yangutils.utils.UtilConstants.SELECT_ALL_CHILD;
 import static org.onosproject.yangutils.utils.UtilConstants.SELECT_ALL_CHILD_SCHEMA_PARAM;
 import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
 import static org.onosproject.yangutils.utils.UtilConstants.SELECT_OR_CONTAINMENT_NODE_PARAM;
@@ -120,6 +120,7 @@
 import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_EIGHT_SPACE_INDENTATION;
 import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_FOUR_SPACE_INDENTATION;
 import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.TWO;
 import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF;
 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
@@ -128,7 +129,6 @@
  * Represents generator for subtree filtering methods of generated files
  * based on the file type.
  */
-//TODO: improve class to use string generator.
 public final class SubtreeFilteringMethodsGenerator {
 
     /**
@@ -138,6 +138,48 @@
     }
 
     /**
+     * Returns process sub tree for choice interface class.
+     *
+     * @param node choice node
+     * @return process sub tree for choice interface class
+     */
+    static String getProcessSubTreeForChoiceInterface(YangNode node) {
+        if (!(node instanceof YangChoice)) {
+            throw new TranslatorException("process sub tree for interface is " +
+                                                  "only allowed in choice " +
+                                                  "node.");
+        }
+        JavaFileInfoTranslator info = ((JavaCodeGeneratorInfo) node)
+                .getJavaFileInfo();
+
+        String name = info.getJavaName();
+        String returnType = getCapitalCase(name);
+
+        String javadoc = "\n   /**\n" +
+                "     * Applications need not to implement process subtree " +
+                "of " + name + "\n     * it will be overridden by " +
+                "corresponding case class.\n" +
+                "     *\n" +
+                "     * @param " + APP_INSTANCE + SPACE +
+                APP_INSTANCE + SPACE + "being passed to check" +
+                " for" +
+                " content match\n" +
+                "     * @param isSelectAllSchemaChild is select all schema child\n" +
+                "     * @return match result\n" +
+                "     */\n";
+        StringBuilder builder = new StringBuilder(javadoc);
+        Map<String, String> param = new LinkedHashMap<>();
+        param.put(APP_INSTANCE, returnType);
+        param.put(SELECT_ALL_CHILD_SCHEMA_PARAM, BOOLEAN_DATA_TYPE);
+        builder.append(multiAttrMethodSignature(PROCESS_SUBTREE_FILTERING, null,
+                                                DEFAULT, returnType, param,
+                                                CLASS_TYPE))
+                .append(getReturnString(NULL, EIGHT_SPACE_INDENTATION))
+                .append(signatureClose()).append(methodClose(FOUR_SPACE));
+        return builder.toString();
+    }
+
+    /**
      * Returns is filter content match for leaf.
      *
      * @param javaAttributeInfo java attribute
@@ -166,12 +208,11 @@
                 getIfConditionBegin(TWELVE_SPACE_INDENTATION, attrQualifiedType) +
                 getReturnString(FALSE, SIXTEEN_SPACE_INDENTATION) +
                 signatureClose() +
-                TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + ELSE +
-                SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+                TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + ELSE +
+                OPEN_CURLY_BRACKET + NEW_LINE +
                 getSubTreeBuilderCallString(SIXTEEN_SPACE_INDENTATION, attributeName,
                                             TWELVE_SPACE) +
-                EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + ELSE +
-                getIfConditionBegin(SPACE, getLeafFlagSetString(
+                getElseIfConditionBegin(EIGHT_SPACE_INDENTATION, getLeafFlagSetString(
                         attributeName, SELECT_LEAF, EMPTY_STRING, GET) + SPACE +
                         OR_OPERATION + SPACE + IS_SELECT_ALL_SCHEMA_CHILD_FLAG) +
                 valueAssign(IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG, TRUE,
@@ -255,144 +296,126 @@
     /**
      * Returns is filter content match for child node.
      *
-     * @param curNode      current node
-     * @param pluginConfig plugin configurations
-     * @param path         path of temp file
+     * @param curNode current node
+     * @param path    path of temp file
      * @return is filter content match for child node
      */
-    static String getProcessChildNodeSubtreeFiltering(YangNode curNode,
-                                                      YangPluginConfig
-                                                              pluginConfig,
-                                                      String path)
+    static String getProcessChildNodeSubtreeFiltering(YangNode curNode, String path)
             throws IOException {
-        JavaFileInfoTranslator javaFileInfo =
-                ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-        String instance = APP_INSTANCE;
-        String name = getCapitalCase(javaFileInfo.getJavaName());
-        String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
-
-        Map<String, String> param = new HashMap<>();
-        param.put(PROCESS_CHILD_NODE_STF_PARAM, BOOLEAN_DATA_TYPE);
-        param.put(instance, name);
-        param.put(STF_BUILDER_PARAM, builderNamePrefix + BUILDER);
-        param.put(SELECT_OR_CONTAINMENT_NODE_PARAM, BOOLEAN_WRAPPER);
-        param.put(SELECT_ALL_CHILD_SCHEMA_PARAM, BOOLEAN_WRAPPER);
-
-
-        String method = FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
-                SPACE + PROCESS_CHILD_NODE_STF_PARAM +
-                OPEN_PARENTHESIS + name + SPACE + instance + COMMA +
-                SPACE + builderNamePrefix + BUILDER + SPACE +
-                STF_BUILDER_PARAM + COMMA +
-                " Boolean " +
-                "isAnySelectOrContainmentNode, " + "boolean " +
-                SELECT_ALL_CHILD_SCHEMA_PARAM + CLOSE_PARENTHESIS +
-                SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
-
-        method +=
-                getDataFromTempFileHandle(FILTER_CONTENT_MATCH_FOR_NODES_MASK,
-                                          ((TempJavaCodeFragmentFilesContainer) curNode)
-                                                  .getTempJavaCodeFragmentFiles()
-                                                  .getBeanTempFiles(), path);
-
-        method +=
-                EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
-                        NEW_LINE + FOUR_SPACE_INDENTATION +
-                        CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
-        YangNode child = curNode.getChild();
-        while (child != null) {
-            if (child instanceof YangChoice) {
-                method += getChoiceInstanceForPstMethod(child, name);
+       /* Generate code will look like this.
+        private boolean processChildNodesSubTreeFiltering(Link
+ appInstance, LinkBuilder subTreeFilteringResultBuilder,
+                Boolean isAnySelectOrContainmentNode, boolean isSelectAllSchemaChild) {
+            if (isSelectAllSchemaChild) {
+                for (Areas areas : appInstance.areas()) {
+                    subTreeFilteringResultBuilder.addToAreas(areas);
+                }
+            } else if (areas() != null) {
+                isAnySelectOrContainmentNode = true;
+                if (!areas().isEmpty()) {
+                    if (appInstance.areas() != null && !appInstance.areas().isEmpty()) {
+                        for (Areas areas : areas()) {
+                            for (Areas areas2 : appInstance.areas()) {
+                                Areas result = areas.processSubtreeFiltering(areas2, false);
+                                if (result != null) {
+                                    subTreeFilteringResultBuilder.addToAreas(result);
+                                }
+                            }
+                        }
+                    }
+                } else {
+                    if (appInstance.areas() != null && !appInstance.areas().isEmpty()) {
+                        for (Areas areas : appInstance.areas()) {
+                            subTreeFilteringResultBuilder.addToAreas(areas);
+                        }
+                    }
+                }
             }
-            child = child.getNextSibling();
-        }
 
-        return method;
+            return true;
+        }*/
+        return getProcessStfMethods(PROCESS_CHILD_NODE_STF_PARAM, curNode,
+                                    path,
+                                    FILTER_CONTENT_MATCH_FOR_NODES_MASK);
     }
 
     /**
      * Returns is filter content match for leaf list.
      *
-     * @param curNode      current node
-     * @param pluginConfig plugin configurations
-     * @param path         path of temp file
+     * @param curNode current node
+     * @param path    path of temp file
      * @return is filter content match for leaf list
      */
-    static String getProcessLeafListSubtreeFiltering(YangNode curNode,
-                                                     YangPluginConfig
-                                                             pluginConfig,
-                                                     String path)
+    static String getProcessLeafListSubtreeFiltering(YangNode curNode, String path)
             throws IOException {
-        JavaFileInfoTranslator javaFileInfo =
-                ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-        String name = getCapitalCase(javaFileInfo.getJavaName());
-        String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
+       /* Generate code will look like this.
+        private boolean processLeafListSubTreeFiltering(Link appInstance, LinkBuilder subTreeFilteringResultBuilder,
+                Boolean isAnySelectOrContainmentNode, boolean isSelectAllSchemaChild) {
+            if (isSelectAllSchemaChild) {
+                for (String portId : appInstance.portId()) {
+                    subTreeFilteringResultBuilder.addToPortId(portId);
+                }
+            } else if (portId() != null) {
+                if (!portId().isEmpty()) {
+                    if (appInstance.portId() == null || appInstance.portId().isEmpty()) {
+                        return false;
+                    }
+                    for (String portId : portId()) {
+                        boolean flag = false;
+                        for (String portId2 : appInstance.portId()) {
+                            if (portId.equals(portId2)) {
+                                flag = true;
+                                subTreeFilteringResultBuilder.addToPortId(portId2);
+                                break;
+                            }
+                        }
+                        if (!flag) {
+                            return false;
+                        }
+                    }
+                } else {
+                    isAnySelectOrContainmentNode = true;
+                    if (appInstance.portId() != null && !appInstance.portId().isEmpty()) {
+                        for (String portId : appInstance.portId()) {
+                            subTreeFilteringResultBuilder.addToPortId(portId);
+                        }
+                    }
+                }
+            }
 
-        String processSubtreeFilteringMethod =
-                FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
-                        SPACE + "processLeafListSubTreeFiltering" +
-                        OPEN_PARENTHESIS + name + SPACE + APP_INSTANCE + COMMA +
-                        SPACE + builderNamePrefix + BUILDER + SPACE +
-                        "subTreeFilteringResultBuilder" + COMMA +
-                        " Boolean " +
-                        "isAnySelectOrContainmentNode, " + "boolean " +
-                        "isSelectAllSchemaChild" + CLOSE_PARENTHESIS +
-                        SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
-
-        processSubtreeFilteringMethod += getDataFromTempFileHandle(
-                FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK,
-                ((TempJavaCodeFragmentFilesContainer) curNode)
-                        .getTempJavaCodeFragmentFiles()
-                        .getBeanTempFiles(), path);
-
-        processSubtreeFilteringMethod +=
-                EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
-                        NEW_LINE + FOUR_SPACE_INDENTATION +
-                        CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
-
-        return processSubtreeFilteringMethod;
+            return true;
+        }*/
+        return getProcessStfMethods(PROCESS_LEAF_LIST_STF_PARAM, curNode, path,
+                                    FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK);
     }
 
     /**
      * Returns is filter content match for leaf.
      *
-     * @param curNode      current node
-     * @param pluginConfig plugin configurations
-     * @param path         path of temp file
+     * @param curNode current node
+     * @param path    path of temp file
      * @return is filter content match for leaf
      */
-    static String getProcessLeafSubtreeFiltering(YangNode curNode,
-                                                 YangPluginConfig pluginConfig,
-                                                 String path)
+    static String getProcessLeafSubtreeFiltering(YangNode curNode, String path)
             throws IOException {
-        JavaFileInfoTranslator javaFileInfo =
-                ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-        String name = getCapitalCase(javaFileInfo.getJavaName());
-        String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
+     /* Generate code will look like this.
+      private boolean processLeafSubtreeFiltering(Link appInstance, LinkBuilder subTreeFilteringResultBuilder,
+                Boolean isAnySelectOrContainmentNode, boolean isSelectAllSchemaChild) {
+            if (valueLeafFlags.get(LeafIdentifier.PORT.getLeafIndex())) {
+                if (appInstance.port() != port()) {
+                    return false;
+                } else {
+                    subTreeFilteringResultBuilder.port(appInstance.port());
+                }
+            } else if (selectLeafFlags.get(LeafIdentifier.PORT.getLeafIndex()) || isSelectAllSchemaChild) {
+                isAnySelectOrContainmentNode = true;
+                subTreeFilteringResultBuilder.port(appInstance.port());
+            }
 
-        String processSubtreeFilteringMethod =
-                FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
-                        SPACE + "processLeafSubtreeFiltering" +
-                        OPEN_PARENTHESIS + name + SPACE + APP_INSTANCE + COMMA +
-                        SPACE + builderNamePrefix + BUILDER + SPACE +
-                        "subTreeFilteringResultBuilder" + COMMA +
-                        " Boolean " +
-                        "isAnySelectOrContainmentNode, " + "boolean " +
-                        "isSelectAllSchemaChild" + CLOSE_PARENTHESIS +
-                        SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
-
-        processSubtreeFilteringMethod +=
-                getDataFromTempFileHandle(FILTER_CONTENT_MATCH_FOR_LEAF_MASK,
-                                          ((TempJavaCodeFragmentFilesContainer) curNode)
-                                                  .getTempJavaCodeFragmentFiles()
-                                                  .getBeanTempFiles(), path);
-
-        processSubtreeFilteringMethod +=
-                EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
-                        NEW_LINE + FOUR_SPACE_INDENTATION +
-                        CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
-
-        return processSubtreeFilteringMethod;
+            return true;
+        }*/
+        return getProcessStfMethods(PROCESS_LEAF_STF_PARAM, curNode, path,
+                                    FILTER_CONTENT_MATCH_FOR_LEAF_MASK);
     }
 
     /**
@@ -402,17 +425,31 @@
      * @return is filter content match for leaf
      */
     static String getProcessSubtreeFilteringStart(YangNode curNode) {
+
+       /* Generate code will look like this.
+       public Link processSubtreeFiltering(Link appInstance, boolean isSelectAllSchemaChild) {
+            LinkBuilder subTreeFilteringResultBuilder = new LinkBuilder();
+            Boolean isAnySelectOrContainmentNode = false;
+        */
+        StringBuilder builder = new StringBuilder();
         JavaFileInfoTranslator javaFileInfo =
                 ((JavaFileInfoContainer) curNode).getJavaFileInfo();
         String instance = APP_INSTANCE;
         String name = getCapitalCase(javaFileInfo.getJavaName());
         String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
+        String caseName = getNameOfClassForIfCase(curNode);
+        String returnType;
         if (curNode instanceof RpcNotificationContainer) {
-            name = getCapitalCase(javaFileInfo.getJavaName()) + OP_PARAM;
+            returnType = name + OP_PARAM;
         } else {
-            name = DEFAULT_CAPS + name;
+            returnType = DEFAULT_CAPS + name;
         }
-        String javadoc = "   /**\n" +
+        if (caseName != null) {
+            instance = INSTANCE;
+            name = caseName;
+        }
+
+        String javadoc = "\n   /**\n" +
                 "     * Checks if the passed " + name +
                 " maps the content match query condition.\n" +
                 "     *\n" +
@@ -423,88 +460,130 @@
                 "     * @param isSelectAllSchemaChild is select all schema child\n" +
                 "     * @return match result\n" +
                 "     */\n";
+        Map<String, String> param = new LinkedHashMap<>();
+        param.put(instance, name);
+        param.put(SELECT_ALL_CHILD_SCHEMA_PARAM, BOOLEAN_DATA_TYPE);
+        builder.append(javadoc)
+                .append(multiAttrMethodSignature(PROCESS_SUBTREE_FILTERING, null,
+                                                 PUBLIC, returnType, param,
+                                                 CLASS_TYPE));
 
-        String processSubtreeFilteringMethod =
-                javadoc + FOUR_SPACE_INDENTATION +
-                        PUBLIC + SPACE + name + SPACE +
-                        PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + name +
-                        SPACE + instance + COMMA + SPACE + BOOLEAN_DATA_TYPE +
-                        SPACE + "isSelectAllSchemaChild" +
-                        CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
-                        NEW_LINE + EIGHT_SPACE_INDENTATION +
-                        builderNamePrefix + BUILDER + SPACE +
-                        SUBTREE_FILTERING_RESULT_BUILDER + SPACE + EQUAL +
-                        SPACE + NEW + SPACE + builderNamePrefix + BUILDER +
-                        OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLON +
-                        NEW_LINE + EIGHT_SPACE_INDENTATION + "Boolean" + SPACE +
-                        IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE +
-                        EQUAL + SPACE + FALSE + SEMI_COLON + NEW_LINE;
-        return processSubtreeFilteringMethod;
+        builder.append(getNewInstance(builderNamePrefix + BUILDER,
+                                      SUBTREE_FILTERING_RESULT_BUILDER,
+                                      EIGHT_SPACE_INDENTATION, EMPTY_STRING));
+        builder.append(getNewInstance(BOOLEAN_WRAPPER,
+                                      IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG,
+                                      EIGHT_SPACE_INDENTATION, FALSE));
+        if (caseName != null) {
+            builder.append(getCaseCastString(javaFileInfo, instance, curNode));
+        }
+
+        return builder.toString();
     }
 
     /**
-     * Get the body for process subtree filtering.
+     * Returns all process sub tree method implementations.
+     *
+     * @param methodName method name
+     * @param curNode    current node
+     * @param path       path for temporary file
+     * @param file       temp file
+     * @return method implementations
+     * @throws IOException when fails to fetch data from temp files
+     */
+    private static String getProcessStfMethods(
+            String methodName, YangNode curNode, String path, int file)
+            throws IOException {
+        StringBuilder builder = new StringBuilder();
+        JavaFileInfoTranslator javaFileInfo =
+                ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+        String instance = APP_INSTANCE;
+        String name = getCapitalCase(javaFileInfo.getJavaName());
+        String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
+        String caseName = getNameOfClassForIfCase(curNode);
+        if (caseName != null) {
+            instance = INSTANCE;
+            name = caseName;
+        }
+
+        Map<String, String> param = new LinkedHashMap<>();
+        param.put(instance, name);
+        param.put(STF_BUILDER_PARAM, builderNamePrefix + BUILDER);
+        param.put(SELECT_OR_CONTAINMENT_NODE_PARAM, BOOLEAN_WRAPPER);
+        param.put(SELECT_ALL_CHILD_SCHEMA_PARAM, BOOLEAN_WRAPPER);
+
+        builder.append(multiAttrMethodSignature(methodName, null,
+                                                PRIVATE, BOOLEAN_DATA_TYPE, param, CLASS_TYPE));
+
+        if (caseName != null) {
+            builder.append(getCaseCastString(javaFileInfo, instance, curNode));
+        }
+        builder.append(getDataFromTempFileHandle(file,
+                                                 getBeanFiles(curNode), path))
+                .append(getReturnString(TRUE, EIGHT_SPACE_INDENTATION)).append(
+                signatureClose()).append(methodClose(FOUR_SPACE))
+                .append(NEW_LINE);
+        return builder.toString();
+    }
+
+    /**
+     * Returns the body for process subtree filtering.
      *
      * @param curNode node for which the code is being generated
      * @return body of subtree filtering
      */
     static String getProcessSubtreeFunctionBody(YangNode curNode) {
+        StringBuilder builder = new StringBuilder();
 
-        String method = "";
-
+       /* if (!processLeafSubtreeFiltering(appInstance, subTreeFilteringResultBuilder,
+                                         isAnySelectOrContainmentNode, isSelectAllSchemaChild)) {
+            return null;
+        }
+        if (!processLeafListSubTreeFiltering(appInstance, subTreeFilteringResultBuilder,
+                                             isAnySelectOrContainmentNode, isSelectAllSchemaChild)) {
+            return null;
+        }
+        if (!processChildNodesSubTreeFiltering(appInstance, subTreeFilteringResultBuilder,
+                                               isAnySelectOrContainmentNode, isSelectAllSchemaChild)) {
+            return null;
+        }
+      */
         if (curNode instanceof YangLeavesHolder) {
-            if (((YangLeavesHolder) curNode).getListOfLeaf() != null
-                    &&
-                    !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
-                method +=
-                        getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
-                                "processLeafSubtreeFiltering(appInstance, " +
-                                "subTreeFilteringResultBuilder, " +
-                                "isAnySelectOrContainmentNode, " +
-                                "isSelectAllSchemaChild)");
-
-                method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
-                        SEMI_COLON + NEW_LINE;
-
-                method += methodClose(EIGHT_SPACE);
+            YangLeavesHolder holder = (YangLeavesHolder) curNode;
+            if (!holder.getListOfLeaf().isEmpty()) {
+                builder.append(getInnerStfMethodClass(PROCESS_LEAF_STF_PARAM));
+            }
+            if (!holder.getListOfLeafList().isEmpty()) {
+                builder.append(getInnerStfMethodClass(PROCESS_LEAF_LIST_STF_PARAM));
             }
         }
-
-        if (curNode instanceof YangLeavesHolder) {
-            if (((YangLeavesHolder) curNode).getListOfLeafList() != null
-                    &&
-                    !((YangLeavesHolder) curNode).getListOfLeafList()
-                            .isEmpty()) {
-                method +=
-                        getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
-                                "processLeafListSubTreeFiltering(appInstance," +
-                                " subTreeFilteringResultBuilder, " +
-                                "isAnySelectOrContainmentNode, " +
-                                "isSelectAllSchemaChild)");
-
-                method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
-                        SEMI_COLON + NEW_LINE;
-
-                method += methodClose(EIGHT_SPACE);
-            }
-        }
-
         if (curNode.getChild() != null) {
-
-            method +=
-                    getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
-                            "processChildNodesSubTreeFiltering(appInstance, " +
-                            "subTreeFilteringResultBuilder, " +
-                            "isAnySelectOrContainmentNode, " +
-                            "isSelectAllSchemaChild)");
-
-            method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
-                    SEMI_COLON + NEW_LINE;
-
-            method += methodClose(EIGHT_SPACE);
+            builder.append(getInnerStfMethodClass(PROCESS_CHILD_NODE_STF_PARAM));
         }
 
-        return method;
+        return builder.toString();
+    }
+
+    //Method calls for process subtree filtering method.
+    private static String getInnerStfMethodClass(String name) {
+        StringBuilder builder = new StringBuilder()
+                .append(getIfConditionBegin(EIGHT_SPACE_INDENTATION,
+                                            getMethodCallsConditionsForStfMethods(name)))
+                .append(getReturnString(NULL, TWELVE_SPACE_INDENTATION)).append(
+                        signatureClose()).append(methodClose(EIGHT_SPACE));
+        return builder.toString();
+    }
+
+    // Condition for if check in process sub tree method.
+    private static String getMethodCallsConditionsForStfMethods(String name) {
+        return NOT + name + getOpenCloseParaWithValue(getConditionString());
+    }
+
+    //variable call for conditional method call
+    private static String getConditionString() {
+        return APP_INSTANCE + COMMA + SPACE + SUBTREE_FILTERING_RESULT_BUILDER +
+                COMMA + SPACE + SELECT_OR_CONTAINMENT_NODE_PARAM + COMMA + SPACE +
+                SELECT_ALL_CHILD;
     }
 
     /**
@@ -514,8 +593,7 @@
      * @param node YANG node
      * @return is filter content match for node
      */
-    public static String getSubtreeFilteringForNode(JavaAttributeInfo attr,
-                                                    YangNode node) {
+    public static String getSubtreeFilteringForNode(JavaAttributeInfo attr, YangNode node) {
         boolean isList = attr.isListAttr();
         if (isList) {
             return getSubtreeFilteringForList(attr, false, node);
@@ -532,111 +610,112 @@
      * @return is filter content match close
      */
     static String getProcessSubTreeFilteringEnd(String name, YangNode curNode) {
-        String method = getIfConditionBegin(EIGHT_SPACE_INDENTATION,
-                                            NOT + IS_SELECT_ALL_SCHEMA_CHILD_FLAG +
-                                                    SPACE + AND_OPERATION + SPACE +
-                                                    NOT +
-                                                    IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG);
+        /* generate code will look like this.
+        if (!isSelectAllSchemaChild && !isAnySelectOrContainmentNode) {
+            return processSubtreeFiltering(appInstance, true);
+        }
+        return subTreeFilteringResultBuilder.build();
+        */
 
-        method += TWELVE_SPACE_INDENTATION + RETURN + SPACE +
-                PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + APP_INSTANCE +
-                COMMA + SPACE + TRUE + CLOSE_PARENTHESIS + SEMI_COLON +
-                NEW_LINE;
-
-        method += methodClose(EIGHT_SPACE);
+        StringBuilder builder = new StringBuilder();
+        String cond1 = NOT + IS_SELECT_ALL_SCHEMA_CHILD_FLAG + SPACE + AND_OPERATION +
+                SPACE + NOT + IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG;
+        String call = PROCESS_SUBTREE_FILTERING + getOpenCloseParaWithValue(
+                APP_INSTANCE + COMMA + SPACE + TRUE);
+        builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION, cond1))
+                .append(getReturnString(call, TWELVE_SPACE_INDENTATION))
+                .append(signatureClose()).append(methodClose(EIGHT_SPACE));
         String build = BUILD;
         if (curNode instanceof YangAugment) {
             build = BUILD_FOR_FILTER;
         }
-        method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + getOpenCloseParaWithValue(
-                name) + SPACE +
-                SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + build +
-                OPEN_CLOSE_BRACKET_STRING + SEMI_COLON + NEW_LINE +
-                FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
 
-        return method;
+        call = getOpenCloseParaWithValue(name) + SPACE +
+                SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + build +
+                OPEN_CLOSE_BRACKET_STRING;
+        builder.append(getReturnString(call, EIGHT_SPACE_INDENTATION))
+                .append(signatureClose()).append(methodClose(FOUR_SPACE))
+                .append(NEW_LINE);
+        return builder.toString();
     }
 
     /**
      * Returns filter content match for child nodes.
      *
-     * @param javaAttributeInfo attribute to be added
-     * @param node              YANG node
+     * @param attr attribute to be added
+     * @param node YANG node
      * @return filter content match for child nodes
      */
-    private static String getSubtreeFilteringForChildNode(
-            JavaAttributeInfo javaAttributeInfo, YangNode node) {
-        String name = javaAttributeInfo.getAttributeName();
-        String clsInfo = javaAttributeInfo.getImportInfo()
+    private static String getSubtreeFilteringForChildNode(JavaAttributeInfo attr,
+                                                          YangNode node) {
+        StringBuilder builder = new StringBuilder();
+        String name = attr.getAttributeName();
+        String clsInfo = attr.getImportInfo()
                 .getClassInfo();
-        String type = DEFAULT_CAPS + javaAttributeInfo.getImportInfo()
+        String type = DEFAULT_CAPS + attr.getImportInfo()
                 .getClassInfo();
-        if (javaAttributeInfo.isQualifiedName()) {
-            type = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
+        if (attr.isQualifiedName()) {
+            type = attr.getImportInfo().getPkgInfo() + PERIOD +
                     type;
-            clsInfo = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
+            clsInfo = attr.getImportInfo().getPkgInfo() + PERIOD +
                     clsInfo;
         }
         String classCast = getOpenCloseParaWithValue(type) + SPACE;
         String cast = getOpenCloseParaWithValue(classCast + name);
-        String resultString = cast +
-                PERIOD + PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS
-                + classCast +
-                APP_INSTANCE + PERIOD + name + OPEN_CLOSE_BRACKET_STRING
+        if (node != null && node instanceof YangChoice) {
+            cast = name;
+        }
+
+        String resultString = cast + PERIOD + PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS
+                + APP_INSTANCE + PERIOD + name + OPEN_CLOSE_BRACKET_STRING
                 + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
                 NEW_LINE;
 
-        if (node != null && node instanceof YangChoice) {
-            resultString = getReturnStringInCaseOfChoice(node);
-        }
-        String method =
-                getIfConditionBegin(EIGHT_SPACE_INDENTATION, name + "() != " +
-                        "null  || isSelectAllSchemaChild");
+        String cond1 = name + OPEN_CLOSE_BRACKET_STRING + SPACE + NOT + EQUAL +
+                SPACE + NULL + SPACE + OR_OPERATION + SPACE + SELECT_ALL_CHILD;
+        builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION, cond1))
+                .append(getSelectOrContainmentAssignString());
 
-        method += TWELVE_SPACE_INDENTATION +
-                IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL + SPACE +
-                TRUE + SEMI_COLON + NEW_LINE;
+        builder.append(getIfConditionBegin(TWELVE_SPACE_INDENTATION,
+                                           getAppInstanceCondition(name)));
 
-        method += TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
-                APP_INSTANCE + PERIOD + name + OPEN_PARENTHESIS +
-                CLOSE_PARENTHESIS + SPACE + NOT
-                + EQUAL + SPACE + NULL + CLOSE_PARENTHESIS + SPACE +
-                OPEN_CURLY_BRACKET + NEW_LINE;
+        String assignment = SIXTEEN_SPACE_INDENTATION + clsInfo + SPACE + RESULT +
+                signatureClose();
 
-        method += SIXTEEN_SPACE_INDENTATION + clsInfo + SPACE + "result" +
-                SEMI_COLON + NEW_LINE;
+        builder.append(assignment)
+                .append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
+                                            SELECT_ALL_CHILD));
 
-        method +=
-                getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
-                                    "isSelectAllSchemaChild");
+        assignment = TWENTY_SPACE_INDENTATION + RESULT + SPACE + EQUAL + SPACE +
+                getAppInstanceAttrString(name) + signatureClose();
 
-        method += TWENTY_SPACE_INDENTATION + "result" + SPACE + EQUAL + SPACE +
-                APP_INSTANCE + PERIOD + name + OPEN_PARENTHESIS +
-                CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
+        builder.append(assignment).append(SIXTEEN_SPACE_INDENTATION).append(
+                CLOSE_CURLY_BRACKET).append(ELSE).append(OPEN_CURLY_BRACKET)
+                .append(NEW_LINE);
 
-        method += SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE +
-                ELSE + SPACE +
-                OPEN_CURLY_BRACKET + NEW_LINE;
+        assignment = TWENTY_SPACE_INDENTATION + RESULT + SPACE + EQUAL + SPACE
+                + resultString;
+        cond1 = RESULT + SPACE + NOT + EQUAL + SPACE + NULL;
 
-        method += TWENTY_SPACE_INDENTATION + "result = " + resultString;
+        builder.append(assignment).append(methodClose(SIXTEEN_SPACE))
+                .append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond1));
 
-        method += SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+        assignment = TWENTY_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
+                PERIOD + name + getOpenCloseParaWithValue(RESULT) +
+                signatureClose();
+        builder.append(assignment).append(methodClose(SIXTEEN_SPACE)).append(
+                methodClose(TWELVE_SPACE)).append(methodClose(EIGHT_SPACE));
+        return builder.toString();
+    }
 
-        method += SIXTEEN_SPACE_INDENTATION + "if (result != null) {" +
-                NEW_LINE;
+    private static String getAppInstanceCondition(String name) {
+        return APP_INSTANCE + PERIOD + name + OPEN_CLOSE_BRACKET_STRING + SPACE +
+                NOT + EQUAL + SPACE + NULL;
+    }
 
-        method += TWENTY_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
-                PERIOD + name + OPEN_PARENTHESIS + "result" +
-                CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
-                SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
-
-        //if app instance is not null
-        method += methodClose(TWELVE_SPACE);
-
-        //if query instance is not null
-        method += methodClose(TWELVE_SPACE);
-
-        return method;
+    private static String getSelectOrContainmentAssignString() {
+        return TWELVE_SPACE_INDENTATION + IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG +
+                SPACE + EQUAL + SPACE + TRUE + signatureClose();
     }
 
     /**
@@ -650,11 +729,10 @@
     private static String getSubtreeFilteringForList(
             JavaAttributeInfo javaAttributeInfo, boolean isLeafList,
             YangNode node) {
-        String capitalCaseName =
-                getCapitalCase(javaAttributeInfo.getAttributeName());
+        StringBuilder builder = new StringBuilder();
+        String caps = getCapitalCase(javaAttributeInfo.getAttributeName());
         String name = javaAttributeInfo.getAttributeName();
-        String type = javaAttributeInfo.getImportInfo()
-                .getClassInfo();
+        String type = javaAttributeInfo.getImportInfo().getClassInfo();
         String clsInfo = DEFAULT_CAPS + type;
         if (javaAttributeInfo.isQualifiedName()) {
             type = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
@@ -665,219 +743,148 @@
 
         String classCast = getOpenCloseParaWithValue(clsInfo) + SPACE;
         String cast = getOpenCloseParaWithValue(classCast + name);
-        String resultString = cast + PERIOD +
-                PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + classCast +
-                name + "2" + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
-                NEW_LINE;
 
         if (node != null && node instanceof YangChoice) {
-            resultString = getReturnStringInCaseOfChoice(node);
+            cast = name;
         }
-
+        String resultString = cast + PERIOD +
+                PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS +
+                name + "2" + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
+                NEW_LINE;
         /*
          * If select all schema child
          */
-        String method =
-                getIfConditionBegin(EIGHT_SPACE_INDENTATION,
-                                    IS_SELECT_ALL_SCHEMA_CHILD_FLAG);
+        builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION,
+                                           IS_SELECT_ALL_SCHEMA_CHILD_FLAG))
+                .append(getForLoopString(TWELVE_SPACE_INDENTATION, type, name,
+                                         getAppInstanceAttrString(name)));
 
-        method = method + getCollectionIteratorForLoopBegin(TWELVE_SPACE_INDENTATION,
-                                                            type + SPACE + name,
-                                                            APP_INSTANCE + PERIOD +
-                                                                    name +
-                                                                    OPEN_CLOSE_BRACKET_STRING);
-
-        method = method + SIXTEEN_SPACE_INDENTATION +
+        String assignment = SIXTEEN_SPACE_INDENTATION +
                 SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
-                getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
-                name + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
+                getCapitalCase(TO) + caps + getOpenCloseParaWithValue(name) +
+                signatureClose();
+        builder.append(assignment).append(methodClose(TWELVE_SPACE));
 
-        method += methodClose(TWELVE_SPACE); // Close collection Iteration loop
+        String cond = name + OPEN_CLOSE_BRACKET_STRING + SPACE + NOT + EQUAL +
+                SPACE + NULL;
 
         //If need to explicitly participate in query
-        method += getElseIfConditionBegin(EIGHT_SPACE_INDENTATION,
-                                          name + OPEN_CLOSE_BRACKET_STRING +
-                                                  SPACE + NOT + EQUAL +
-                                                  SPACE + NULL);
+        builder.append(getElseIfConditionBegin(EIGHT_SPACE_INDENTATION, cond));
 
         if (!isLeafList) {
-            method += TWELVE_SPACE_INDENTATION +
-                    IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL +
-                    SPACE + TRUE + SEMI_COLON + NEW_LINE;
+            builder.append(getSelectOrContainmentAssignString());
         }
 
         //If there is any parameter in the query condition
-        method +=
-                getIfConditionBegin(TWELVE_SPACE_INDENTATION, NOT + name +
-                        OPEN_CLOSE_BRACKET_STRING + PERIOD + IS_EMPTY);
+        cond = NOT + name + OPEN_CLOSE_BRACKET_STRING + PERIOD + IS_EMPTY;
+        builder.append(getIfConditionBegin(TWELVE_SPACE_INDENTATION, cond));
 
         if (isLeafList) {
+            cond = getAppInstanceCondition(name) + SPACE + OR_OPERATION + SPACE +
+                    APP_INSTANCE + PERIOD + name + OPEN_CLOSE_BRACKET_STRING +
+                    PERIOD + IS_EMPTY;
             /*
              * If there is no app instance to perform content match
              */
-            method +=
-                    getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
-                                        APP_INSTANCE + PERIOD + name +
-                                                OPEN_CLOSE_BRACKET_STRING +
-                                                SPACE + EQUAL + EQUAL + SPACE +
-                                                NULL + SPACE + OR_OPERATION
-                                                + SPACE + APP_INSTANCE +
-                                                PERIOD + name +
-                                                OPEN_CLOSE_BRACKET_STRING +
-                                                PERIOD + IS_EMPTY);
+            builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond))
+                    .append(getReturnString(FALSE, TWENTY_SPACE_INDENTATION))
+                    .append(signatureClose())
+                    .append(methodClose(SIXTEEN_SPACE))
+                    // for instance iterator
+                    .append(getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
+                                             name + OPEN_CLOSE_BRACKET_STRING));
 
-            method += TWENTY_SPACE_INDENTATION + RETURN + SPACE + FALSE +
-                    SEMI_COLON + NEW_LINE;
+            assignment = TWENTY_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
+                    FLAG + SPACE + EQUAL + SPACE + FALSE + signatureClose();
+            builder.append(assignment)
+                    // for app instance iterator
+                    .append(getForLoopString(TWENTY_SPACE_INDENTATION, type,
+                                             name + TWO,
+                                             getAppInstanceAttrString(name)));
 
-            method += methodClose(SIXTEEN_SPACE);
-
-            // for instance iterator
-            method += getCollectionIteratorForLoopBegin(
-                    SIXTEEN_SPACE_INDENTATION, type + SPACE + name,
-                    name + OPEN_CLOSE_BRACKET_STRING);
-
-            method += TWENTY_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
-                    "flag" + SPACE + EQUAL + SPACE + FALSE + SEMI_COLON +
-                    NEW_LINE;
-
-            // for app instance iterator
-            method +=
-                    getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
-                                                      type + SPACE + name +
-                                                              "2",
-                                                      APP_INSTANCE + PERIOD +
-                                                              name +
-                                                              OPEN_CLOSE_BRACKET_STRING);
-
+            cond = name + PERIOD + EQUALS_STRING
+                    + OPEN_PARENTHESIS + name + TWO + CLOSE_PARENTHESIS;
             //the content match leaf list attribute value matches
-            method +=
-                    getIfConditionBegin(TWENTY_FOUR_SPACE_INDENTATION,
-                                        name + PERIOD + EQUALS_STRING
-                                                + OPEN_PARENTHESIS + name +
-                                                "2" + CLOSE_PARENTHESIS);
+            builder.append(getIfConditionBegin(TWENTY_FOUR_SPACE_INDENTATION,
+                                               cond));
 
-            method += TWENTY_EIGHT_SPACE_INDENTATION + "flag" + SPACE + EQUAL +
+            assignment = TWENTY_EIGHT_SPACE_INDENTATION + FLAG + SPACE + EQUAL +
                     SPACE + TRUE + SEMI_COLON + NEW_LINE;
-
-            method += TWENTY_EIGHT_SPACE_INDENTATION +
+            builder.append(assignment);
+            assignment = TWENTY_EIGHT_SPACE_INDENTATION +
                     SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
-                    getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
-                    name + "2" + CLOSE_PARENTHESIS +
-                    SEMI_COLON + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
-                    BREAK + SEMI_COLON + NEW_LINE;
+                    getCapitalCase(TO) + caps + getOpenCloseParaWithValue(
+                    name + TWO) + signatureClose();
+            builder.append(assignment).append(TWENTY_EIGHT_SPACE_INDENTATION)
+                    .append(BREAK).append(signatureClose())
+                    //the content match leaf list attribute value matches
+                    .append(methodClose(TWENTY_FOUR_SPACE))
+                    // for app instance iterator
+                    .append(methodClose(TWENTY_SPACE))
+                    //if the content match failed
+                    .append(getIfConditionBegin(TWENTY_SPACE_INDENTATION, NOT +
+                            FLAG))
+                    .append(getReturnString(FALSE, TWENTY_FOUR_SPACE_INDENTATION))
+                    .append(signatureClose()).append(methodClose(TWENTY_SPACE))// if flag == false
+                    .append(methodClose(SIXTEEN_SPACE)); // for instance iterator
 
-            //the content match leaf list attribute value matches
-            method += methodClose(TWENTY_FOUR_SPACE);
-
-            // for app instance iterator
-            method += methodClose(TWENTY_SPACE);
-
-            //if the content match failed
-            method +=
-                    getIfConditionBegin(TWENTY_SPACE_INDENTATION, "!flag");
-
-            method += TWENTY_FOUR_SPACE_INDENTATION + RETURN + SPACE + FALSE +
-                    SEMI_COLON + NEW_LINE;
-
-            method +=
-                    methodClose(TWENTY_SPACE); // if flag == false
-
-            method += methodClose(SIXTEEN_SPACE); // for instance iterator
         } else {
-
+            cond = getAppInstanceCondition(name) + SPACE + AND_OPERATION +
+                    SPACE + getAppInstanceAttrString(name) +
+                    PERIOD + IS_EMPTY;
             /*if there is any app instance entry*/
-            method +=
-                    getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
-                                        APP_INSTANCE + PERIOD + name +
-                                                OPEN_CLOSE_BRACKET_STRING +
-                                                SPACE + NOT + EQUAL + SPACE +
-                                                NULL + SPACE + AND_OPERATION +
-                                                SPACE + NOT + APP_INSTANCE +
-                                                PERIOD + name +
-                                                OPEN_CLOSE_BRACKET_STRING +
-                                                PERIOD + IS_EMPTY);
+            builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
+                                               cond))
+                    //loop all the app instance(s)
+                    .append(getForLoopString(SIXTEEN_SPACE_INDENTATION, type, name,
+                                             name + OPEN_CLOSE_BRACKET_STRING))
+                    .append(getForLoopString(TWENTY_SPACE_INDENTATION, type,
+                                             name + TWO,
+                                             getAppInstanceAttrString(name)));
 
-            /*
-             * loop all the query condition instance(s)
-             */
-            method +=
-                    getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
-                                                      type + SPACE + name,
-                                                      name +
-                                                              OPEN_CLOSE_BRACKET_STRING);
 
-            //loop all the app instance(s)
-            method += getCollectionIteratorForLoopBegin(
-                    TWENTY_FOUR_SPACE_INDENTATION, type + SPACE + name + "2",
-                    APP_INSTANCE + PERIOD + name +
-                            OPEN_CLOSE_BRACKET_STRING);
+            assignment = TWENTY_EIGHT_SPACE_INDENTATION + type + SPACE +
+                    RESULT + SPACE + EQUAL + SPACE + resultString;
+            builder.append(assignment);
+            cond = RESULT + SPACE + NOT + EQUAL + SPACE + NULL;
+            builder.append(getIfConditionBegin(TWENTY_EIGHT_SPACE_INDENTATION, cond));
 
-            method += TWENTY_EIGHT_SPACE_INDENTATION + type + SPACE +
-                    "result = " + resultString;
-
-            method += TWENTY_EIGHT_SPACE_INDENTATION + "if (result != null) {" +
-                    NEW_LINE;
-
-            method += THIRTY_TWO_SPACE_INDENTATION +
+            assignment = THIRTY_TWO_SPACE_INDENTATION +
                     SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
-                    getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
-                    "result" + CLOSE_PARENTHESIS +
-                    SEMI_COLON + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
-                    CLOSE_CURLY_BRACKET + NEW_LINE;
-
-            //loop all the app instance(s)
-            method +=
-                    methodClose(TWENTY_FOUR_SPACE);
-
-            //loop all the query condition instance(s)
-            method += methodClose(TWENTY_SPACE);
-
+                    getCapitalCase(TO) + caps + getOpenCloseParaWithValue(
+                    name) + signatureClose();
+            builder.append(assignment).append(methodClose(TWENTY_EIGHT_SPACE))
+                    //loop all the app instance(s)
+                    .append(methodClose(TWENTY_FOUR_SPACE))
+                    //loop all the query condition instance(s)
+                    .append(methodClose(TWENTY_SPACE))
+                    .append(methodClose(SIXTEEN_SPACE));
             //if there is any app instance entry
-            method += methodClose(SIXTEEN_SPACE);
         }
 
-        method += TWELVE_SPACE_INDENTATION + "} else {" + NEW_LINE;
+        cond = TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+                + ELSE + OPEN_CURLY_BRACKET + NEW_LINE;
+        builder.append(cond);
 
         if (isLeafList) {
-            method += SIXTEEN_SPACE_INDENTATION +
-                    IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE +
-                    EQUAL + SPACE + TRUE + SEMI_COLON + NEW_LINE;
+            builder.append(getSelectOrContainmentAssignString());
         }
+        cond = getAppInstanceCondition(name) + SPACE + AND_OPERATION +
+                SPACE + NOT + getAppInstanceAttrString(name) + PERIOD + IS_EMPTY;
+        builder.append(getIfConditionBegin(SIXTEEN_SPACE_INDENTATION, cond))
+                .append(getForLoopString(SIXTEEN_SPACE_INDENTATION, type,
+                                         name, getAppInstanceAttrString(name)));
+        assignment = TWENTY_FOUR_SPACE_INDENTATION +
+                SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
+                getCapitalCase(TO) + caps + getOpenCloseParaWithValue(
+                name) + signatureClose();
+        builder.append(assignment).append(methodClose(TWENTY_SPACE))// Close collection Iteration loop
+                // close  if condition
+                .append(methodClose(SIXTEEN_SPACE))
+                .append(methodClose(TWELVE_SPACE))// close  else condition
+                .append(methodClose(EIGHT_SPACE));// close else if condition
 
-        method +=
-                getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
-                                    APP_INSTANCE + PERIOD + name
-                                            + OPEN_CLOSE_BRACKET_STRING +
-                                            SPACE + NOT + EQUAL + SPACE +
-                                            NULL + SPACE + AND_OPERATION +
-                                            SPACE + NOT + APP_INSTANCE +
-                                            PERIOD + name +
-                                            OPEN_CLOSE_BRACKET_STRING +
-                                            PERIOD + IS_EMPTY);
-
-        method = method +
-                getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
-                                                  type + SPACE + name,
-                                                  APP_INSTANCE + PERIOD +
-                                                          name +
-                                                          OPEN_CLOSE_BRACKET_STRING);
-
-        method = method + TWENTY_FOUR_SPACE_INDENTATION +
-                SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING
-                + getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
-                name + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
-
-        method += methodClose(TWENTY_SPACE);// Close collection Iteration loop
-
-        method +=
-                methodClose(SIXTEEN_SPACE); // close  if condition
-
-        method +=
-                methodClose(TWELVE_SPACE); // close  else condition
-
-        method += methodClose(EIGHT_SPACE); // close  else if condition
-
-        return method;
+        return builder.toString();
     }
 
     //Returns method string for op params augmented syntax
@@ -909,105 +916,39 @@
                 "        }\n";
     }
 
-    private static String getMethodBodyForChoicePstMethod(
-            YangNode node, YangPluginConfig config, YangNode choiceParent,
-            String choice) {
-        StringBuilder builder = new StringBuilder();
-        JavaCodeGeneratorInfo info = (JavaCodeGeneratorInfo) choiceParent;
-        JavaFileInfoTranslator pInfo = info.getJavaFileInfo();
-
-        JavaQualifiedTypeInfoTranslator qInfo = getQualifiedInfo(node, config);
-
-        String castVar = qInfo.getClassInfo();
-        boolean qualify = info.getTempJavaCodeFragmentFiles().getBeanTempFiles()
-                .getJavaImportData().addImportInfo(qInfo, pInfo.getJavaName(),
-                                                   pInfo.getPackage());
-        if (qualify) {
-            castVar = StringGenerator.getQualifiedString(qInfo.getPkgInfo(),
-                                                         qInfo.getClassInfo());
+    private static String getNameOfClassForIfCase(YangNode curNode) {
+        String name = null;
+        JavaFileInfoTranslator parentInfo;
+        if (curNode instanceof YangCase) {
+            YangNode parent = curNode.getParent();
+            if (parent instanceof YangChoice) {
+                parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+                name = getCapitalCase(parentInfo.getJavaName());
+            } else if (parent instanceof YangAugment) {
+                parentInfo = ((JavaFileInfoContainer) ((YangAugment) parent)
+                        .getAugmentedNode()).getJavaFileInfo();
+                if (parentInfo != null) {
+                    name = getCapitalCase(parentInfo.getJavaName());
+                } else {
+                    name = getCapitalCase(getCamelCase(
+                            ((YangAugment) parent).getAugmentedNode().getName(),
+                            null));
+                }
+            }
         }
-        String classCast = getOpenCloseParaWithValue(castVar) + SPACE;
-        String cast = getOpenCloseParaWithValue(classCast + choice);
-        String retString = cast + PERIOD + PROCESS_SUBTREE_FILTERING +
-                getOpenCloseParaWithValue(classCast + getAppInstanceAttrString
-                        (choice) + COMMA + SPACE + FALSE);
-        String cond = choice + INSTANCE_OF + castVar;
-        builder.append(getIfConditionBegin(EIGHT_SPACE_INDENTATION, cond))
-                .append(getReturnString(retString, TWELVE_SPACE_INDENTATION))
-                .append(signatureClose()).append(methodClose(EIGHT_SPACE));
-        return builder.toString();
+        return name;
     }
 
-    /**
-     * Returns choice instance for PST method.
-     *
-     * @param choice    choice node
-     * @param className class name
-     * @return choice instance for pst method
-     */
-    private static String getChoiceInstanceForPstMethod(YangNode choice,
-                                                        String className) {
-        /*
-         * private Choice1 getChoice1ResultOfProcessSubTree(Choice1 choice1, Test appInstance) {
-         *     if (choice1 instanceof DefaultCase1) {
-         *         return ((DefaultCase1) choice1).processSubtreeFiltering(
-         *          appInstance.choice1(), false);
-         * }
-         * return null;
-         * }
-         */
-
-        JavaFileInfoTranslator info = ((JavaFileInfoContainer) choice).getJavaFileInfo();
-        String name = info.getJavaName();
-        String caps = getCapitalCase(name);
-        StringBuilder builder = new StringBuilder();
-        String methodName = caps + CHOICE_STF_METHOD_NAME;
-        Map<String, String> param = new LinkedHashMap<>();
-        param.put(name, caps);
-        param.put(APP_INSTANCE, className);
-
-        builder.append(multiAttrMethodSignature(methodName, GET, PRIVATE, caps,
-                                                param, CLASS_TYPE));
-
-        for (YangNode cases : getChoiceChildNodes((YangChoice) choice)) {
-            builder.append(getMethodBodyForChoicePstMethod(cases, info.getPluginConfig(),
-                                                           choice.getParent(), name));
+    private static String getCaseCastString(
+            JavaFileInfoTranslator javaFileInfo, String instance, YangNode curNode) {
+        if (curNode instanceof YangCase) {
+            String caseName = DEFAULT_CAPS + getCapitalCase(
+                    javaFileInfo.getJavaName());
+            return EIGHT_SPACE_INDENTATION + caseName + SPACE + APP_INSTANCE + SPACE +
+                    EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
+                    CLOSE_PARENTHESIS + SPACE + instance + signatureClose();
         }
-        builder.append(getReturnString(NULL, FOUR_SPACE_INDENTATION))
-                .append(signatureClose()).append(methodClose(FOUR_SPACE));
-        return builder.toString();
-    }
-
-    private static String getReturnStringInCaseOfChoice(YangNode choice) {
-        JavaFileInfoTranslator info = ((JavaFileInfoContainer) choice)
-                .getJavaFileInfo();
-        String name = info.getJavaName();
-        String caps = getCapitalCase(name);
-        String methodName = caps + CHOICE_STF_METHOD_NAME;
-        return GET + methodName + getOpenCloseParaWithValue(
-                name + COMMA + SPACE + APP_INSTANCE) + signatureClose();
-    }
-
-    static JavaQualifiedTypeInfoTranslator getQualifiedInfo(
-            YangNode node, YangPluginConfig config) {
-        JavaFileInfoTranslator fileInfo = ((JavaCodeGeneratorInfo) node)
-                .getJavaFileInfo();
-        String name = fileInfo.getJavaName();
-        String pkg = fileInfo.getPackage();
-        if (config == null) {
-            config = new YangPluginConfig();
-        }
-        if (name == null) {
-            name = getCamelCase(node.getName(), config.getConflictResolver());
-            pkg = getNodesPackage(node, config);
-        }
-
-        name = DEFAULT_CAPS + getCapitalCase(name);
-        JavaQualifiedTypeInfoTranslator qInfo = new
-                JavaQualifiedTypeInfoTranslator();
-        qInfo.setClassInfo(name);
-        qInfo.setPkgInfo(pkg);
-        return qInfo;
+        return null;
     }
 
 }
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index e660573..8266eca 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -316,6 +316,18 @@
      * Static attribute for space.
      */
     public static final String SPACE = " ";
+    /**
+     * Static attribute for space.
+     */
+    public static final String TWO = "2";
+    /**
+     * Static attribute for space.
+     */
+    public static final String FLAG = "flag";
+    /**
+     * Static attribute for result.
+     */
+    public static final String RESULT = "result";
 
     /**
      * Static attribute for isSelectAllSchemaChild.
@@ -834,7 +846,7 @@
     /**
      * Static attribute for close curly bracket syntax.
      */
-    public static final String ELSE = "else";
+    public static final String ELSE = " else ";
 
     /**
      * From string parameter name.
@@ -943,9 +955,19 @@
     public static final String BREAK = "break";
 
     /**
-     * Static attribute for break prefix.
+     * Static attribute for isEmpty.
      */
     public static final String IS_EMPTY = "isEmpty()";
+    /**
+     * Static attribute for exception string in bits enum class.
+     */
+    public static final String EXCEPTION_STRING = "IllegalArgumentException(\"no" +
+            " such element found in bits\");\n";
+
+    /**
+     * Static attribute for "throw new ".
+     */
+    public static final String THROW_NEW = "throw new ";
 
     /**
      * Static attribute for is isLeafValueSet method prefix.
@@ -1222,7 +1244,9 @@
                           "package", "private", "protected", "public", "return",
                           "short", "static", "strictfp", "super", "switch",
                           "synchronized", "this", "throw", "throws", "transient",
-                          "true", "try", "void", "volatile", "while");
+                          "true", "try", "void", "volatile", "while", "list",
+                          "map", "arrayList", "hashMap", "linkedList",
+                          "collections");
 
     /**
      * Static attribute for regex for all the special characters.
@@ -1899,6 +1923,17 @@
      */
     public static final String PROCESS_CHILD_NODE_STF_PARAM =
             "processChildNodesSubTreeFiltering";
+
+    /**
+     * Static param for processLeafListSubTreeFiltering.
+     */
+    public static final String PROCESS_LEAF_LIST_STF_PARAM =
+            "processLeafListSubTreeFiltering";
+    /**
+     * Static param for processLeafListSubTreeFiltering.
+     */
+    public static final String PROCESS_LEAF_STF_PARAM =
+            "processLeafSubtreeFiltering";
     /**
      * Static param for subTreeFilteringResultBuilder.
      */
@@ -1921,6 +1956,8 @@
      */
     public static final String CHOICE_STF_METHOD_NAME =
             "ResultOfProcessSubTree";
+    //File type extension for java classes.
+    public static final String JAVA_FILE_EXTENSION = ".java";
 
     // No instantiation.
     private UtilConstants() {
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
index 5cc774a..c4a2341 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
@@ -57,7 +57,7 @@
         yangPluginConfig.setCodeGenDir(DIR);
         utilManager.translateToJava(yangPluginConfig);
         compileCode(COMP);
-        deleteDirectory(DIR);
+        //deleteDirectory(DIR);
     }
 
     /**
@@ -85,8 +85,6 @@
 
     /**
      * Checks augment translation should not result in any exception.
-     * compiler not added because it contains a notification which depends on
-     * onos api.
      *
      * @throws MojoExecutionException
      */
@@ -107,4 +105,29 @@
         deleteDirectory(DIR);
     }
 
+    /**
+     * Checks augment translation should not result in any exception.
+     *
+     * @throws MojoExecutionException
+     */
+    @Test
+    public void processChoiceAugmentInterTranslator() throws IOException,
+            ParserException, MojoExecutionException {
+        //FIXME: for augment having node with child nodes.
+        /*
+        deleteDirectory(DIR);
+        String searchDir = "src/test/resources/choiceAugment";
+        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+        utilManager.parseYangFileInfoSet();
+        utilManager.createYangNodeSet();
+        utilManager.resolveDependenciesUsingLinker();
+
+        YangPluginConfig yangPluginConfig = new YangPluginConfig();
+        yangPluginConfig.setCodeGenDir(DIR);
+        utilManager.translateToJava(yangPluginConfig);
+        compileCode(COMP);
+        deleteDirectory(DIR);
+        */
+    }
+
 }
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
new file mode 100644
index 0000000..4e9cdcb
--- /dev/null
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/IdentityTranslatorTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.plugin.manager;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.onosproject.yangutils.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Translator test case for identity.
+ */
+public class IdentityTranslatorTest {
+
+    private final YangUtilManager utilManager = new YangUtilManager();
+    private static final String DIR = "target/identity/";
+    private static final String COMP = System.getProperty("user.dir") + File
+            .separator + DIR;
+
+    /**
+     * Checks augment translation should not result in any exception.
+     *
+     * @throws MojoExecutionException
+     */
+    @Test
+    public void processChoiceAugmentInterTranslator() throws IOException,
+            ParserException, MojoExecutionException {
+        deleteDirectory(DIR);
+        String searchDir = "src/test/resources/identityTranslator";
+        utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+        utilManager.parseYangFileInfoSet();
+        utilManager.createYangNodeSet();
+        utilManager.resolveDependenciesUsingLinker();
+
+        YangPluginConfig yangPluginConfig = new YangPluginConfig();
+        yangPluginConfig.setCodeGenDir(DIR);
+        utilManager.translateToJava(yangPluginConfig);
+        compileCode(COMP);
+        //deleteDirectory(DIR);
+    }
+}
diff --git a/plugin/maven/src/test/resources/augmentTranslator/test.yang b/plugin/maven/src/test/resources/augmentTranslator/test.yang
index c112cef..20393a7 100644
--- a/plugin/maven/src/test/resources/augmentTranslator/test.yang
+++ b/plugin/maven/src/test/resources/augmentTranslator/test.yang
@@ -43,7 +43,21 @@
               }  
          }
      }
-                    
+
+     leaf leaf-a {
+       type int32;
+     }
+
+      leaf-list leaf-list-a {
+          type int32;
+      }
+
+      list list-a {
+         key "name";
+         leaf name {
+            type string;
+         }
+      }
 
     augment /cont3 {
         leaf leaf1 {
diff --git a/plugin/maven/src/test/resources/choiceAugment/all.yang b/plugin/maven/src/test/resources/choiceAugment/all.yang
new file mode 100644
index 0000000..4c08537
--- /dev/null
+++ b/plugin/maven/src/test/resources/choiceAugment/all.yang
@@ -0,0 +1,128 @@
+module ietf-inet {
+
+  namespace "yang:all";
+  prefix "inet";
+  yang-version 1;
+
+  choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+           }
+       }
+   }
+
+
+   container c {
+       choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+                 }
+             }
+         }
+   }
+
+   list l {
+   config false;
+choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+                 }
+             }
+         }
+   }
+
+
+   grouping g {
+    choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+                 }
+             }
+         }
+   }
+
+   notification n {
+    choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+                 }
+             }
+         }
+    }
+    rpc r {
+        input {
+           choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+                 }
+             }
+         }
+       }
+      output {
+        choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+                 }
+             }
+         }
+        }
+     }
+
+     augment /name {
+        choice name {
+             case a {
+                 leaf udp {
+                     type empty;
+                 }
+             }
+             case b {
+                 leaf tcp {
+                    type empty;
+                 }
+             }
+         }
+     }
+
+}
\ No newline at end of file
diff --git a/plugin/maven/src/test/resources/choiceAugment/test.yang b/plugin/maven/src/test/resources/choiceAugment/test.yang
new file mode 100644
index 0000000..ceee3d7
--- /dev/null
+++ b/plugin/maven/src/test/resources/choiceAugment/test.yang
@@ -0,0 +1,78 @@
+module test {
+    namespace "test:test";
+        prefix test ;
+
+    import test1{
+       prefix test1;
+    }
+    organization "";
+    contact "";
+
+    description
+       "Defines basic service types for L3VPN service.";
+
+    revision "2015-12-16" {
+       reference "";
+    }
+
+    augment /test1:rpc-input-output/test1:output/ {
+        choice choice1 {
+            container case1 {
+                leaf int-leaf {
+                    type int32;
+                }
+            }
+        }
+    }
+
+    list node {
+        key "node-id";
+        leaf node-id{
+           type string;
+        }
+        leaf-list node-prop{
+           type string;
+        }
+        container termination-points{
+           leaf number-of-tp {
+               type int16;
+            }
+            list termination-point {
+                key "tp-id";
+                leaf tp-id {
+                    type string;
+                }
+            }
+        }
+        choice choice1{
+           case case1a{
+               leaf leaf1a1{
+                   type string;
+               }
+               leaf leaf1a2{
+                  type string;
+               }
+           }
+           case case1b{
+               choice choice1b{
+                    case case1bi{
+                         leaf leaf1bia{
+                              type string;
+                          }
+                          leaf leaf1bib{
+                              type string;
+                          }
+                     }
+                    case case1bii{
+                         leaf leaf1biia{
+                               type string;
+                         }
+                         leaf leaf1biib{
+                               type string;
+                          }
+                    }
+               }
+           }
+        }
+    }
+}
\ No newline at end of file
diff --git a/plugin/maven/src/test/resources/choiceAugment/test2.yang b/plugin/maven/src/test/resources/choiceAugment/test2.yang
new file mode 100644
index 0000000..4caa38b
--- /dev/null
+++ b/plugin/maven/src/test/resources/choiceAugment/test2.yang
@@ -0,0 +1,26 @@
+module test1 {
+    namespace "test1:test1";
+    prefix test1 ;
+
+    organization "";
+    contact "";
+
+    description
+       "Defines basic service types for L3VPN service.";
+    revision "2015-12-16" {
+       reference "";
+    }
+
+    rpc rpc-input-output {
+       input {
+            leaf leaf1 {
+                 type int32;
+             }
+       }
+       output {
+            leaf leaf1 {
+                 type int32;
+             }
+       }
+    }
+}
\ No newline at end of file
diff --git a/plugin/maven/src/test/resources/identityTranslator/test.yang b/plugin/maven/src/test/resources/identityTranslator/test.yang
new file mode 100644
index 0000000..b8a3193
--- /dev/null
+++ b/plugin/maven/src/test/resources/identityTranslator/test.yang
@@ -0,0 +1,14 @@
+module IdentityInModule{
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix IdentityInModule;
+
+    identity ref-address-family {
+        reference "http://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml#address-family-numbers-2";
+    }
+    leaf tunnel {
+        type identityref {
+            base ref-address-family;
+        }
+    }
+}
\ No newline at end of file