Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.translator.tojava; |
| 18 | |
| 19 | import java.io.File; |
| 20 | import java.io.IOException; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 21 | import java.util.ArrayList; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 22 | import java.util.List; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 23 | import java.util.Set; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.HasType; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangEnum; |
| 26 | import org.onosproject.yangutils.datamodel.YangEnumeration; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 28 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 29 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
| 30 | import org.onosproject.yangutils.datamodel.YangNode; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.datamodel.YangType; |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.datamodel.YangCase; |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 34 | |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 35 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 52 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 54 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 58 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfEnumAttribute; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 60 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 61 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getFromStringAttributeInfo; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 63 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 65 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 66 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; |
| 67 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 68 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 69 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; |
| 70 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 71 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateRpcInterfaceFile; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 72 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 74 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
| 76 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
| 77 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 79 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 80 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; |
| 81 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor; |
| 82 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; |
| 83 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 84 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 85 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
| 86 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
| 87 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 88 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 89 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 90 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 91 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcStringMethod; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 92 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
| 93 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
| 94 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 95 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 96 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 97 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; |
| 98 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; |
| 99 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport; |
| 100 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addImportsToStringAndHasCodeMethods; |
| 101 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
| 102 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended; |
| 103 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; |
| 104 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 105 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 106 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 107 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 108 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
| 109 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; |
| 110 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 111 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 112 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 113 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 114 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
| 115 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 116 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 117 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 118 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 119 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 120 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc; |
| 121 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 122 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; |
| 123 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
| 124 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 125 | |
| 126 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 127 | * Represents implementation of java code fragments temporary implementations. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 128 | */ |
| 129 | public class TempJavaCodeFragmentFiles { |
| 130 | |
| 131 | /** |
| 132 | * The variable which guides the types of temporary files generated using |
| 133 | * the temporary generated file types mask. |
| 134 | */ |
| 135 | private int generatedTempFiles; |
| 136 | |
| 137 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 138 | * The variable which guides the types of files generated using |
| 139 | * the generated file types mask. |
| 140 | */ |
| 141 | private int generatedJavaFiles; |
| 142 | |
| 143 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 144 | * Absolute path where the target java file needs to be generated. |
| 145 | */ |
| 146 | private String absoluteDirPath; |
| 147 | |
| 148 | /** |
| 149 | * Name of java file that needs to be generated. |
| 150 | */ |
| 151 | private String generatedJavaClassName; |
| 152 | |
| 153 | /** |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 154 | * Contains all the class name which will be extended by generated files. |
| 155 | */ |
| 156 | private List<String> extendsList = new ArrayList<>(); |
| 157 | |
| 158 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 159 | * File type extension for java classes. |
| 160 | */ |
| 161 | private static final String JAVA_FILE_EXTENSION = ".java"; |
| 162 | |
| 163 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 164 | * File type extension for temporary classes. |
| 165 | */ |
| 166 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
| 167 | |
| 168 | /** |
| 169 | * Folder suffix for temporary files folder. |
| 170 | */ |
| 171 | private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp"; |
| 172 | |
| 173 | /** |
| 174 | * File name for getter method. |
| 175 | */ |
| 176 | private static final String GETTER_METHOD_FILE_NAME = "GetterMethod"; |
| 177 | |
| 178 | /** |
| 179 | * File name for getter method implementation. |
| 180 | */ |
| 181 | private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl"; |
| 182 | |
| 183 | /** |
| 184 | * File name for setter method. |
| 185 | */ |
| 186 | private static final String SETTER_METHOD_FILE_NAME = "SetterMethod"; |
| 187 | |
| 188 | /** |
| 189 | * File name for setter method implementation. |
| 190 | */ |
| 191 | private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl"; |
| 192 | |
| 193 | /** |
| 194 | * File name for constructor. |
| 195 | */ |
| 196 | private static final String CONSTRUCTOR_FILE_NAME = "Constructor"; |
| 197 | |
| 198 | /** |
| 199 | * File name for attributes. |
| 200 | */ |
| 201 | private static final String ATTRIBUTE_FILE_NAME = "Attributes"; |
| 202 | |
| 203 | /** |
| 204 | * File name for to string method. |
| 205 | */ |
| 206 | private static final String TO_STRING_METHOD_FILE_NAME = "ToString"; |
| 207 | |
| 208 | /** |
| 209 | * File name for hash code method. |
| 210 | */ |
| 211 | private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode"; |
| 212 | |
| 213 | /** |
| 214 | * File name for equals method. |
| 215 | */ |
| 216 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; |
| 217 | |
| 218 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 219 | * File name for of string method. |
| 220 | */ |
| 221 | private static final String OF_STRING_METHOD_FILE_NAME = "OfString"; |
| 222 | |
| 223 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 224 | * File name for temporary enum class. |
| 225 | */ |
| 226 | private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass"; |
| 227 | |
| 228 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 229 | * File name for construction for special type like union, typedef. |
| 230 | */ |
| 231 | private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType"; |
| 232 | |
| 233 | /** |
| 234 | * File name for from string method. |
| 235 | */ |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 236 | private static final String FROM_STRING_METHOD_FILE_NAME = "FromString"; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 237 | |
| 238 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 239 | * File name for interface java file name suffix. |
| 240 | */ |
| 241 | private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; |
| 242 | |
| 243 | /** |
| 244 | * File name for builder interface file name suffix. |
| 245 | */ |
| 246 | private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE; |
| 247 | |
| 248 | /** |
| 249 | * File name for builder class file name suffix. |
| 250 | */ |
| 251 | private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER; |
| 252 | |
| 253 | /** |
| 254 | * File name for impl class file name suffix. |
| 255 | */ |
| 256 | private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL; |
| 257 | |
| 258 | /** |
| 259 | * File name for typedef class file name suffix. |
| 260 | */ |
| 261 | private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; |
| 262 | |
| 263 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 264 | * File name for enum class file name suffix. |
| 265 | */ |
| 266 | private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; |
| 267 | |
| 268 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 269 | * File name for rpc method. |
| 270 | */ |
| 271 | private static final String RPC_FILE_NAME = "Rpc"; |
| 272 | |
| 273 | /** |
| 274 | * File name for generated class file for special type like union, typedef suffix. |
| 275 | */ |
| 276 | private static final String RPC_INTERFACE_FILE_NAME_SUFFIX = "Service"; |
| 277 | |
| 278 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 279 | * File name for generated class file for special type like union, typedef suffix. |
| 280 | */ |
| 281 | private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; |
| 282 | |
| 283 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 284 | * Java file handle for interface file. |
| 285 | */ |
| 286 | private File interfaceJavaFileHandle; |
| 287 | |
| 288 | /** |
| 289 | * Java file handle for builder interface file. |
| 290 | */ |
| 291 | private File builderInterfaceJavaFileHandle; |
| 292 | |
| 293 | /** |
| 294 | * Java file handle for builder class file. |
| 295 | */ |
| 296 | private File builderClassJavaFileHandle; |
| 297 | |
| 298 | /** |
| 299 | * Java file handle for impl class file. |
| 300 | */ |
| 301 | private File implClassJavaFileHandle; |
| 302 | |
| 303 | /** |
| 304 | * Java file handle for typedef class file. |
| 305 | */ |
| 306 | private File typedefClassJavaFileHandle; |
| 307 | |
| 308 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 309 | * Java file handle for type class like union, typedef file. |
| 310 | */ |
| 311 | private File typeClassJavaFileHandle; |
| 312 | |
| 313 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 314 | * Temporary file handle for attribute. |
| 315 | */ |
| 316 | private File attributesTempFileHandle; |
| 317 | |
| 318 | /** |
| 319 | * Temporary file handle for getter of interface. |
| 320 | */ |
| 321 | private File getterInterfaceTempFileHandle; |
| 322 | |
| 323 | /** |
| 324 | * Temporary file handle for getter of class. |
| 325 | */ |
| 326 | private File getterImplTempFileHandle; |
| 327 | |
| 328 | /** |
| 329 | * Temporary file handle for setter of interface. |
| 330 | */ |
| 331 | private File setterInterfaceTempFileHandle; |
| 332 | |
| 333 | /** |
| 334 | * Temporary file handle for setter of class. |
| 335 | */ |
| 336 | private File setterImplTempFileHandle; |
| 337 | |
| 338 | /** |
| 339 | * Temporary file handle for constructor of class. |
| 340 | */ |
| 341 | private File constructorImplTempFileHandle; |
| 342 | |
| 343 | /** |
| 344 | * Temporary file handle for hash code method of class. |
| 345 | */ |
| 346 | private File hashCodeImplTempFileHandle; |
| 347 | |
| 348 | /** |
| 349 | * Temporary file handle for equals method of class. |
| 350 | */ |
| 351 | private File equalsImplTempFileHandle; |
| 352 | |
| 353 | /** |
| 354 | * Temporary file handle for to string method of class. |
| 355 | */ |
| 356 | private File toStringImplTempFileHandle; |
| 357 | |
| 358 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 359 | * Temporary file handle for enum class file. |
| 360 | */ |
| 361 | private File enumClassTempFileHandle; |
| 362 | |
| 363 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 364 | * Temporary file handle for of string method of class. |
| 365 | */ |
| 366 | private File ofStringImplTempFileHandle; |
| 367 | |
| 368 | /** |
| 369 | * Temporary file handle for constructor for type class. |
| 370 | */ |
| 371 | private File constructorForTypeTempFileHandle; |
| 372 | |
| 373 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 374 | * Temporary file handle for from string method of class. |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 375 | */ |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 376 | private File fromStringImplTempFileHandle; |
| 377 | |
| 378 | /** |
| 379 | * Temporary file handle for rpc interface. |
| 380 | */ |
| 381 | private File rpcInterfaceImplTempFileHandle; |
| 382 | |
| 383 | /** |
| 384 | * Java file handle for rpc interface file. |
| 385 | */ |
| 386 | private File rpcInterfaceJavaFileHandle; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 387 | |
| 388 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 389 | * Java attribute info. |
| 390 | */ |
| 391 | private JavaAttributeInfo newAttrInfo; |
| 392 | |
| 393 | /** |
| 394 | * Current YANG node. |
| 395 | */ |
| 396 | private YangNode curYangNode; |
| 397 | |
| 398 | /** |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 399 | * Import info for case. |
| 400 | */ |
| 401 | private JavaQualifiedTypeInfo caseImportInfo; |
| 402 | |
| 403 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 404 | * Current enum's value. |
| 405 | */ |
| 406 | private int enumValue; |
| 407 | |
| 408 | /** |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 409 | * Is attribute added. |
| 410 | */ |
| 411 | private boolean isAttributePresent = false; |
| 412 | |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 413 | /* |
| 414 | * Java file handle for enum class. |
| 415 | */ |
| 416 | private File enumClassJavaFileHandle; |
| 417 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 418 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 419 | * Creates an instance of temporary java code fragment. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 420 | * |
| 421 | * @param genFileType file generation type |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 422 | * @param genDir file generation directory |
| 423 | * @param className class name |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 424 | * @throws IOException when fails to create new file handle |
| 425 | */ |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 426 | public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className) |
| 427 | throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 428 | |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 429 | setExtendsList(new ArrayList<>()); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 430 | generatedTempFiles = 0; |
| 431 | absoluteDirPath = genDir; |
| 432 | generatedJavaClassName = className; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 433 | generatedJavaFiles = genFileType; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 434 | /** |
| 435 | * Initialize getter when generation file type matches to interface |
| 436 | * mask. |
| 437 | */ |
| 438 | if ((genFileType & INTERFACE_MASK) != 0) { |
| 439 | generatedTempFiles |= GETTER_FOR_INTERFACE_MASK; |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Initialize getter and setter when generation file type matches to |
| 444 | * builder interface mask. |
| 445 | */ |
| 446 | if ((genFileType & BUILDER_INTERFACE_MASK) != 0) { |
| 447 | generatedTempFiles |= GETTER_FOR_INTERFACE_MASK; |
| 448 | generatedTempFiles |= SETTER_FOR_INTERFACE_MASK; |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Initialize getterImpl, setterImpl and attributes when generation file |
| 453 | * type matches to builder class mask. |
| 454 | */ |
| 455 | if ((genFileType & BUILDER_CLASS_MASK) != 0) { |
| 456 | generatedTempFiles |= ATTRIBUTES_MASK; |
| 457 | generatedTempFiles |= GETTER_FOR_CLASS_MASK; |
| 458 | generatedTempFiles |= SETTER_FOR_CLASS_MASK; |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Initialize getterImpl, attributes, constructor, hash code, equals and |
| 463 | * to strings when generation file type matches to impl class mask. |
| 464 | */ |
| 465 | if ((genFileType & IMPL_CLASS_MASK) != 0) { |
| 466 | generatedTempFiles |= ATTRIBUTES_MASK; |
| 467 | generatedTempFiles |= GETTER_FOR_CLASS_MASK; |
| 468 | generatedTempFiles |= CONSTRUCTOR_IMPL_MASK; |
| 469 | generatedTempFiles |= HASH_CODE_IMPL_MASK; |
| 470 | generatedTempFiles |= EQUALS_IMPL_MASK; |
| 471 | generatedTempFiles |= TO_STRING_IMPL_MASK; |
| 472 | } |
| 473 | |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 474 | if ((genFileType & GENERATE_RPC_INTERFACE) != 0) { |
| 475 | generatedTempFiles |= RPC_IMPL_MASK; |
| 476 | } |
| 477 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 478 | /** |
| 479 | * Initialize getterImpl, attributes, hash code, equals and |
| 480 | * to strings when generation file type matches to typeDef class mask. |
| 481 | */ |
| 482 | if ((genFileType & GENERATE_TYPEDEF_CLASS) != 0) { |
| 483 | generatedTempFiles |= ATTRIBUTES_MASK; |
| 484 | generatedTempFiles |= GETTER_FOR_CLASS_MASK; |
| 485 | generatedTempFiles |= HASH_CODE_IMPL_MASK; |
| 486 | generatedTempFiles |= EQUALS_IMPL_MASK; |
| 487 | generatedTempFiles |= TO_STRING_IMPL_MASK; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 488 | generatedTempFiles |= OF_STRING_IMPL_MASK; |
| 489 | generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 490 | generatedTempFiles |= FROM_STRING_IMPL_MASK; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Initialize getterImpl, attributes, hash code, equals, of string, |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 495 | * constructor, union's to string, from string when generation |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 496 | * file type matches to union class mask. |
| 497 | */ |
| 498 | if ((genFileType & GENERATE_UNION_CLASS) != 0) { |
| 499 | generatedTempFiles |= ATTRIBUTES_MASK; |
| 500 | generatedTempFiles |= GETTER_FOR_CLASS_MASK; |
| 501 | generatedTempFiles |= HASH_CODE_IMPL_MASK; |
| 502 | generatedTempFiles |= EQUALS_IMPL_MASK; |
| 503 | generatedTempFiles |= OF_STRING_IMPL_MASK; |
| 504 | generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK; |
| 505 | generatedTempFiles |= TO_STRING_IMPL_MASK; |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 506 | generatedTempFiles |= FROM_STRING_IMPL_MASK; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 507 | } |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 508 | /** |
| 509 | * Initialize enum when generation file type matches to enum class mask. |
| 510 | */ |
| 511 | if ((genFileType & GENERATE_ENUM_CLASS) != 0) { |
| 512 | generatedTempFiles |= ENUM_IMPL_MASK; |
| 513 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 514 | |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 515 | /** |
| 516 | * Set temporary file handles. |
| 517 | */ |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 518 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
| 519 | setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); |
| 520 | } |
| 521 | |
| 522 | if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 523 | setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME)); |
| 524 | } |
| 525 | |
| 526 | if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 527 | setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME)); |
| 528 | } |
| 529 | |
| 530 | if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { |
| 531 | setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME)); |
| 532 | } |
| 533 | |
| 534 | if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { |
| 535 | setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME)); |
| 536 | } |
| 537 | |
| 538 | if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) { |
| 539 | setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME)); |
| 540 | } |
| 541 | |
| 542 | if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) { |
| 543 | setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME)); |
| 544 | } |
| 545 | |
| 546 | if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { |
| 547 | setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME)); |
| 548 | } |
| 549 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { |
| 550 | setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); |
| 551 | } |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 552 | if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { |
| 553 | setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME)); |
| 554 | } |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 555 | if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { |
| 556 | setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME)); |
| 557 | } |
| 558 | |
| 559 | if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { |
| 560 | setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME)); |
| 561 | } |
| 562 | |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 563 | if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) { |
| 564 | setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME)); |
| 565 | } |
| 566 | |
| 567 | if ((generatedTempFiles & RPC_IMPL_MASK) != 0) { |
| 568 | setRpcInterfaceImplTempFileHandle(getTemporaryFileHandle(RPC_FILE_NAME)); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 569 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 573 | * Returns java file handle for interface file. |
| 574 | * |
| 575 | * @return java file handle for interface file |
| 576 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 577 | private File getInterfaceJavaFileHandle() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 578 | return interfaceJavaFileHandle; |
| 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Sets the java file handle for interface file. |
| 583 | * |
| 584 | * @param interfaceJavaFileHandle java file handle |
| 585 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 586 | private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 587 | this.interfaceJavaFileHandle = interfaceJavaFileHandle; |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Returns java file handle for builder interface file. |
| 592 | * |
| 593 | * @return java file handle for builder interface file |
| 594 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 595 | private File getBuilderInterfaceJavaFileHandle() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 596 | return builderInterfaceJavaFileHandle; |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Sets the java file handle for builder interface file. |
| 601 | * |
| 602 | * @param builderInterfaceJavaFileHandle java file handle |
| 603 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 604 | private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 605 | this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Returns java file handle for builder class file. |
| 610 | * |
| 611 | * @return java file handle for builder class file |
| 612 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 613 | private File getBuilderClassJavaFileHandle() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 614 | return builderClassJavaFileHandle; |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Sets the java file handle for builder class file. |
| 619 | * |
| 620 | * @param builderClassJavaFileHandle java file handle |
| 621 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 622 | private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 623 | this.builderClassJavaFileHandle = builderClassJavaFileHandle; |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * Returns java file handle for impl class file. |
| 628 | * |
| 629 | * @return java file handle for impl class file |
| 630 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 631 | private File getImplClassJavaFileHandle() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 632 | return implClassJavaFileHandle; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * Sets the java file handle for impl class file. |
| 637 | * |
| 638 | * @param implClassJavaFileHandle java file handle |
| 639 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 640 | private void setImplClassJavaFileHandle(File implClassJavaFileHandle) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 641 | this.implClassJavaFileHandle = implClassJavaFileHandle; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Returns java file handle for typedef class file. |
| 646 | * |
| 647 | * @return java file handle for typedef class file |
| 648 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 649 | private File getTypedefClassJavaFileHandle() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 650 | return typedefClassJavaFileHandle; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Sets the java file handle for typedef class file. |
| 655 | * |
| 656 | * @param typedefClassJavaFileHandle java file handle |
| 657 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 658 | private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 659 | this.typedefClassJavaFileHandle = typedefClassJavaFileHandle; |
| 660 | } |
| 661 | |
| 662 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 663 | * Returns enum class java file handle. |
| 664 | * |
| 665 | * @return enum class java file handle |
| 666 | */ |
| 667 | private File getEnumClassJavaFileHandle() { |
| 668 | return enumClassJavaFileHandle; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * Sets enum class java file handle. |
| 673 | * |
| 674 | * @param enumClassJavaFileHandle enum class java file handle |
| 675 | */ |
| 676 | |
| 677 | private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) { |
| 678 | this.enumClassJavaFileHandle = enumClassJavaFileHandle; |
| 679 | } |
| 680 | |
| 681 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 682 | * Returns java file handle for type class file. |
| 683 | * |
| 684 | * @return java file handle for type class file |
| 685 | */ |
| 686 | private File getTypeClassJavaFileHandle() { |
| 687 | return typeClassJavaFileHandle; |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Sets the java file handle for type class file. |
| 692 | * |
| 693 | * @param typeClassJavaFileHandle type file handle |
| 694 | */ |
| 695 | private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) { |
| 696 | this.typeClassJavaFileHandle = typeClassJavaFileHandle; |
| 697 | } |
| 698 | |
| 699 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 700 | * Returns attribute's temporary file handle. |
| 701 | * |
| 702 | * @return temporary file handle |
| 703 | */ |
| 704 | public File getAttributesTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 705 | return attributesTempFileHandle; |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Sets attribute's temporary file handle. |
| 710 | * |
| 711 | * @param attributeForClass file handle for attribute |
| 712 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 713 | private void setAttributesTempFileHandle(File attributeForClass) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 714 | attributesTempFileHandle = attributeForClass; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * Returns getter methods's temporary file handle. |
| 719 | * |
| 720 | * @return temporary file handle |
| 721 | */ |
| 722 | public File getGetterInterfaceTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 723 | return getterInterfaceTempFileHandle; |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * Sets to getter method's temporary file handle. |
| 728 | * |
| 729 | * @param getterForInterface file handle for to getter method |
| 730 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 731 | private void setGetterInterfaceTempFileHandle(File getterForInterface) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 732 | getterInterfaceTempFileHandle = getterForInterface; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Returns getter method's impl's temporary file handle. |
| 737 | * |
| 738 | * @return temporary file handle |
| 739 | */ |
| 740 | public File getGetterImplTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 741 | return getterImplTempFileHandle; |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Sets to getter method's impl's temporary file handle. |
| 746 | * |
| 747 | * @param getterImpl file handle for to getter method's impl |
| 748 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 749 | private void setGetterImplTempFileHandle(File getterImpl) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 750 | getterImplTempFileHandle = getterImpl; |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * Returns setter method's temporary file handle. |
| 755 | * |
| 756 | * @return temporary file handle |
| 757 | */ |
| 758 | public File getSetterInterfaceTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 759 | return setterInterfaceTempFileHandle; |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Sets to setter method's temporary file handle. |
| 764 | * |
| 765 | * @param setterForInterface file handle for to setter method |
| 766 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 767 | private void setSetterInterfaceTempFileHandle(File setterForInterface) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 768 | setterInterfaceTempFileHandle = setterForInterface; |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * Returns setter method's impl's temporary file handle. |
| 773 | * |
| 774 | * @return temporary file handle |
| 775 | */ |
| 776 | public File getSetterImplTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 777 | return setterImplTempFileHandle; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Sets to setter method's impl's temporary file handle. |
| 782 | * |
| 783 | * @param setterImpl file handle for to setter method's implementation class |
| 784 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 785 | private void setSetterImplTempFileHandle(File setterImpl) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 786 | setterImplTempFileHandle = setterImpl; |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Returns constructor's temporary file handle. |
| 791 | * |
| 792 | * @return temporary file handle |
| 793 | */ |
| 794 | public File getConstructorImplTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 795 | return constructorImplTempFileHandle; |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Sets to constructor's temporary file handle. |
| 800 | * |
| 801 | * @param constructor file handle for to constructor |
| 802 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 803 | private void setConstructorImplTempFileHandle(File constructor) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 804 | constructorImplTempFileHandle = constructor; |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Returns hash code method's temporary file handle. |
| 809 | * |
| 810 | * @return temporary file handle |
| 811 | */ |
| 812 | public File getHashCodeImplTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 813 | return hashCodeImplTempFileHandle; |
| 814 | } |
| 815 | |
| 816 | /** |
| 817 | * Sets hash code method's temporary file handle. |
| 818 | * |
| 819 | * @param hashCodeMethod file handle for hash code method |
| 820 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 821 | private void setHashCodeImplTempFileHandle(File hashCodeMethod) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 822 | hashCodeImplTempFileHandle = hashCodeMethod; |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Returns equals mehtod's temporary file handle. |
| 827 | * |
| 828 | * @return temporary file handle |
| 829 | */ |
| 830 | public File getEqualsImplTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 831 | return equalsImplTempFileHandle; |
| 832 | } |
| 833 | |
| 834 | /** |
| 835 | * Sets equals method's temporary file handle. |
| 836 | * |
| 837 | * @param equalsMethod file handle for to equals method |
| 838 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 839 | private void setEqualsImplTempFileHandle(File equalsMethod) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 840 | equalsImplTempFileHandle = equalsMethod; |
| 841 | } |
| 842 | |
| 843 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 844 | * Returns rpc method's temporary file handle. |
| 845 | * |
| 846 | * @return temporary file handle |
| 847 | */ |
| 848 | public File getRpcInterfaceImplTempFileHandle() { |
| 849 | return rpcInterfaceImplTempFileHandle; |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Sets rpc method's temporary file handle. |
| 854 | * |
| 855 | * @param rpcInterfaceImplTempFileHandle file handle for to rpc method |
| 856 | */ |
| 857 | public void setRpcInterfaceImplTempFileHandle(File rpcInterfaceImplTempFileHandle) { |
| 858 | this.rpcInterfaceImplTempFileHandle = rpcInterfaceImplTempFileHandle; |
| 859 | } |
| 860 | |
| 861 | /** |
| 862 | * Returns rpc method's java file handle. |
| 863 | * |
| 864 | * @return java file handle |
| 865 | */ |
| 866 | public File getRpcInterfaceJavaFileHandle() { |
| 867 | return rpcInterfaceJavaFileHandle; |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * Sets rpc method's java file handle. |
| 872 | * |
| 873 | * @param rpcInterfaceJavaFileHandle file handle for to rpc method |
| 874 | */ |
| 875 | public void setRpcInterfaceJavaFileHandle(File rpcInterfaceJavaFileHandle) { |
| 876 | this.rpcInterfaceJavaFileHandle = rpcInterfaceJavaFileHandle; |
| 877 | } |
| 878 | |
| 879 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 880 | * Returns to string method's temporary file handle. |
| 881 | * |
| 882 | * @return temporary file handle |
| 883 | */ |
| 884 | public File getToStringImplTempFileHandle() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 885 | return toStringImplTempFileHandle; |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Sets to string method's temporary file handle. |
| 890 | * |
| 891 | * @param toStringMethod file handle for to string method |
| 892 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 893 | private void setToStringImplTempFileHandle(File toStringMethod) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 894 | toStringImplTempFileHandle = toStringMethod; |
| 895 | } |
| 896 | |
| 897 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 898 | * Returns temporary file handle for enum class file. |
| 899 | * |
| 900 | * @return temporary file handle for enum class file |
| 901 | */ |
| 902 | public File getEnumClassTempFileHandle() { |
| 903 | return enumClassTempFileHandle; |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * Sets temporary file handle for enum class file. |
| 908 | * |
| 909 | * @param enumClassTempFileHandle temporary file handle for enum class file |
| 910 | */ |
| 911 | |
| 912 | private void setEnumClassTempFileHandle(File enumClassTempFileHandle) { |
| 913 | this.enumClassTempFileHandle = enumClassTempFileHandle; |
| 914 | } |
| 915 | |
| 916 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 917 | * Returns of string method's temporary file handle. |
| 918 | * |
| 919 | * @return of string method's temporary file handle |
| 920 | */ |
| 921 | public File getOfStringImplTempFileHandle() { |
| 922 | return ofStringImplTempFileHandle; |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * Set of string method's temporary file handle. |
| 927 | * |
| 928 | * @param ofStringImplTempFileHandle of string method's temporary file handle |
| 929 | */ |
| 930 | private void setOfStringImplTempFileHandle(File ofStringImplTempFileHandle) { |
| 931 | this.ofStringImplTempFileHandle = ofStringImplTempFileHandle; |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Returns type class constructor method's temporary file handle. |
| 936 | * |
| 937 | * @return type class constructor method's temporary file handle |
| 938 | */ |
| 939 | public File getConstructorForTypeTempFileHandle() { |
| 940 | return constructorForTypeTempFileHandle; |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * Sets type class constructor method's temporary file handle. |
| 945 | * |
| 946 | * @param constructorForTypeTempFileHandle type class constructor method's temporary file handle |
| 947 | */ |
| 948 | private void setConstructorForTypeTempFileHandle(File constructorForTypeTempFileHandle) { |
| 949 | this.constructorForTypeTempFileHandle = constructorForTypeTempFileHandle; |
| 950 | } |
| 951 | |
| 952 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 953 | * Returns from string method's temporary file handle. |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 954 | * |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 955 | * @return from string method's temporary file handle |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 956 | */ |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 957 | public File getFromStringImplTempFileHandle() { |
| 958 | return fromStringImplTempFileHandle; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 962 | * Sets from string method's temporary file handle. |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 963 | * |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 964 | * @param fromStringImplTempFileHandle from string method's temporary file handle |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 965 | */ |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 966 | private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) { |
| 967 | this.fromStringImplTempFileHandle = fromStringImplTempFileHandle; |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 971 | * Returns java attribute info. |
| 972 | * |
| 973 | * @return java attribute info |
| 974 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 975 | private JavaAttributeInfo getNewAttrInfo() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 976 | return newAttrInfo; |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * Sets java attribute info. |
| 981 | * |
| 982 | * @param newAttrInfo java attribute info |
| 983 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 984 | private void setNewAttrInfo(JavaAttributeInfo newAttrInfo) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 985 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 986 | if (newAttrInfo != null) { |
| 987 | isAttributePresent = true; |
| 988 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 989 | this.newAttrInfo = newAttrInfo; |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * Returns current YANG node. |
| 994 | * |
| 995 | * @return current YANG node |
| 996 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 997 | private YangNode getCurYangNode() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 998 | return curYangNode; |
| 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * Sets current YANG node. |
| 1003 | * |
| 1004 | * @param curYangNode YANG node |
| 1005 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1006 | private void setCurYangNode(YangNode curYangNode) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1007 | this.curYangNode = curYangNode; |
| 1008 | } |
| 1009 | |
| 1010 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1011 | * Returns enum's value. |
| 1012 | * |
| 1013 | * @return enum's value |
| 1014 | */ |
| 1015 | public int getEnumValue() { |
| 1016 | return enumValue; |
| 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * Sets enum's value. |
| 1021 | * |
| 1022 | * @param enumValue enum's value |
| 1023 | */ |
| 1024 | public void setEnumValue(int enumValue) { |
| 1025 | this.enumValue = enumValue; |
| 1026 | } |
| 1027 | |
| 1028 | /** |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1029 | * Returns list of classes to be extended by generated files. |
| 1030 | * |
| 1031 | * @return list of classes to be extended by generated files |
| 1032 | */ |
| 1033 | private List<String> getExtendsList() { |
| 1034 | return extendsList; |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * Sets class to be extended by generated file. |
| 1039 | * |
| 1040 | * @param extendsList list of classes to be extended |
| 1041 | */ |
| 1042 | |
| 1043 | private void setExtendsList(List<String> extendsList) { |
| 1044 | this.extendsList = extendsList; |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Adds class to the extends list. |
| 1049 | * |
| 1050 | * @param extend class to be extended |
| 1051 | */ |
| 1052 | public void addToExtendsList(String extend) { |
| 1053 | getExtendsList().add(extend); |
| 1054 | } |
| 1055 | |
| 1056 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1057 | * Adds of string for type. |
| 1058 | * |
| 1059 | * @param attr attribute info |
| 1060 | * @throws IOException when fails to append to temporary file |
| 1061 | */ |
| 1062 | private void addOfStringMethod(JavaAttributeInfo attr) throws IOException { |
| 1063 | appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr, generatedJavaClassName) |
| 1064 | + NEW_LINE); |
| 1065 | } |
| 1066 | |
| 1067 | /** |
| 1068 | * Adds type constructor. |
| 1069 | * |
| 1070 | * @param attr attribute info |
| 1071 | * @throws IOException when fails to append to temporary file |
| 1072 | */ |
| 1073 | private void addTypeConstructor(JavaAttributeInfo attr) throws IOException { |
| 1074 | appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr, |
| 1075 | generatedJavaClassName) + NEW_LINE); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1079 | * Adds attribute for class. |
| 1080 | * |
| 1081 | * @param attr attribute info |
| 1082 | * @throws IOException when fails to append to temporary file |
| 1083 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1084 | private void addAttribute(JavaAttributeInfo attr) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1085 | appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | /** |
| 1089 | * Adds getter for interface. |
| 1090 | * |
| 1091 | * @param attr attribute info |
| 1092 | * @throws IOException when fails to append to temporary file |
| 1093 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1094 | private void addGetterForInterface(JavaAttributeInfo attr) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1095 | appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * Adds getter method's impl for class. |
| 1100 | * |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1101 | * @param attr attribute info |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1102 | * @param genFiletype generated file type |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1103 | * @throws IOException when fails to append to temporary file |
| 1104 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1105 | private void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1106 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1107 | if ((genFiletype & BUILDER_CLASS_MASK) != 0) { |
| 1108 | appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE); |
| 1109 | } else { |
| 1110 | appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false) |
| 1111 | + getGetterForClass(attr) + NEW_LINE); |
| 1112 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * Adds setter for interface. |
| 1117 | * |
| 1118 | * @param attr attribute info |
| 1119 | * @throws IOException when fails to append to temporary file |
| 1120 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1121 | private void addSetterForInterface(JavaAttributeInfo attr) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1122 | appendToFile(getSetterInterfaceTempFileHandle(), |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1123 | getSetterString(attr, generatedJavaClassName) + NEW_LINE); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * Adds setter's implementation for class. |
| 1128 | * |
| 1129 | * @param attr attribute info |
| 1130 | * @throws IOException when fails to append to temporary file |
| 1131 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1132 | private void addSetterImpl(JavaAttributeInfo attr) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1133 | appendToFile(getSetterImplTempFileHandle(), |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1134 | getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * Adds build method for interface. |
| 1139 | * |
| 1140 | * @return build method for interface |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1141 | */ |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1142 | public String addBuildMethodForInterface() { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1143 | return parseBuilderInterfaceBuildMethodString(generatedJavaClassName); |
| 1144 | } |
| 1145 | |
| 1146 | /** |
| 1147 | * Adds build method's implementation for class. |
| 1148 | * |
| 1149 | * @return build method implementation for class |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1150 | */ |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1151 | public String addBuildMethodImpl() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1152 | return getBuildString(generatedJavaClassName) + NEW_LINE; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * Adds constructor for class. |
| 1157 | * |
| 1158 | * @param attr attribute info |
| 1159 | * @throws IOException when fails to append to temporary file |
| 1160 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1161 | private void addConstructor(JavaAttributeInfo attr) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1162 | appendToFile(getConstructorImplTempFileHandle(), getConstructor(generatedJavaClassName, attr)); |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * Adds default constructor for class. |
| 1167 | * |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1168 | * @param modifier modifier for constructor. |
| 1169 | * @param toAppend string which need to be appended with the class name |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1170 | * @return default constructor for class |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1171 | */ |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1172 | public String addDefaultConstructor(String modifier, String toAppend) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1173 | return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier); |
| 1174 | } |
| 1175 | |
| 1176 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1177 | * Adds default constructor for class. |
| 1178 | * |
| 1179 | * @return default constructor for class |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1180 | */ |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1181 | public String addOfMethod() { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1182 | return getJavaDoc(OF_METHOD, generatedJavaClassName, false) |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1183 | + getOfMethod(generatedJavaClassName, newAttrInfo); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /** |
| 1187 | * Adds hash code method for class. |
| 1188 | * |
| 1189 | * @param attr attribute info |
| 1190 | * @throws IOException when fails to append to temporary file |
| 1191 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1192 | private void addHashCodeMethod(JavaAttributeInfo attr) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1193 | appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * Adds equals method for class. |
| 1198 | * |
| 1199 | * @param attr attribute info |
| 1200 | * @throws IOException when fails to append to temporary file |
| 1201 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1202 | private void addEqualsMethod(JavaAttributeInfo attr) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1203 | appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * Adds ToString method for class. |
| 1208 | * |
| 1209 | * @param attr attribute info |
| 1210 | * @throws IOException when fails to append to temporary file |
| 1211 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1212 | private void addToStringMethod(JavaAttributeInfo attr) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1213 | appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1217 | * Adds enum class attributes to temporary file. |
| 1218 | * |
| 1219 | * @param curEnum current YANG enum |
| 1220 | * @throws IOException when fails to do IO operations. |
| 1221 | */ |
| 1222 | private void addAttributesForEnumClass(JavaAttributeInfo curEnumInfo) throws IOException { |
| 1223 | appendToFile(getEnumClassTempFileHandle(), |
| 1224 | generateEnumAttributeString(curEnumInfo.getAttributeName(), getEnumValue())); |
| 1225 | } |
| 1226 | |
| 1227 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1228 | * Add from string method for union class. |
| 1229 | * |
| 1230 | * @param javaAttributeInfo type attribute info |
| 1231 | * @param fromStringAttributeInfo from string attribute info |
| 1232 | * @throws IOException when fails to append to temporary file |
| 1233 | */ |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1234 | private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo, |
| 1235 | JavaAttributeInfo fromStringAttributeInfo) throws IOException { |
| 1236 | appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo, |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1237 | fromStringAttributeInfo) + NEW_LINE); |
| 1238 | } |
| 1239 | |
| 1240 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1241 | * Adds rpc string information to applicable temp file. |
| 1242 | * |
| 1243 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
| 1244 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
| 1245 | * @param rpcName name of the rpc function |
| 1246 | * @throws IOException IO operation fail |
| 1247 | */ |
| 1248 | private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput, |
| 1249 | String rpcName) throws IOException { |
| 1250 | String rpcInput = ""; |
| 1251 | String rpcOutput = "void"; |
| 1252 | if (javaAttributeInfoOfInput != null) { |
| 1253 | rpcInput = javaAttributeInfoOfInput.getAttributeName(); |
| 1254 | } |
| 1255 | if (javaAttributeInfoOfOutput != null) { |
| 1256 | rpcOutput = javaAttributeInfoOfOutput.getAttributeName(); |
| 1257 | } |
| 1258 | appendToFile(getRpcInterfaceImplTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) + |
| 1259 | getRpcStringMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE); |
| 1260 | } |
| 1261 | |
| 1262 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1263 | * Returns a temporary file handle for the specific file type. |
| 1264 | * |
| 1265 | * @param fileName file name |
| 1266 | * @return temporary file handle |
| 1267 | * @throws IOException when fails to create new file handle |
| 1268 | */ |
| 1269 | private File getTemporaryFileHandle(String fileName) throws IOException { |
| 1270 | |
| 1271 | String path = getTempDirPath(); |
| 1272 | File dir = new File(path); |
| 1273 | if (!dir.exists()) { |
| 1274 | dir.mkdirs(); |
| 1275 | } |
| 1276 | |
| 1277 | File file = new File(path + fileName + TEMP_FILE_EXTENSION); |
| 1278 | if (!file.exists()) { |
| 1279 | file.createNewFile(); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1280 | } |
| 1281 | return file; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1285 | * Returns a temporary file handle for the specific file type. |
| 1286 | * |
| 1287 | * @param fileName file name |
| 1288 | * @return temporary file handle |
| 1289 | * @throws IOException when fails to create new file handle |
| 1290 | */ |
| 1291 | private File getJavaFileHandle(String fileName) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1292 | return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); |
| 1293 | } |
| 1294 | |
| 1295 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1296 | * Returns data from the temporary files. |
| 1297 | * |
| 1298 | * @param file temporary file handle |
| 1299 | * @return stored data from temporary files |
| 1300 | * @throws IOException when failed to get data from the given file |
| 1301 | */ |
| 1302 | public String getTemporaryDataFromFileHandle(File file) throws IOException { |
| 1303 | |
| 1304 | String path = getTempDirPath(); |
| 1305 | if (new File(path + file.getName()).exists()) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1306 | return readAppendFile(path + file.getName(), EMPTY_STRING); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1307 | } else { |
| 1308 | throw new IOException("Unable to get data from the given " |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1309 | + file.getName() + " file for " + generatedJavaClassName + PERIOD); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | /** |
| 1314 | * Returns temporary directory path. |
| 1315 | * |
| 1316 | * @return directory path |
| 1317 | */ |
| 1318 | private String getTempDirPath() { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1319 | return getPackageDirPathFromJavaJPackage(absoluteDirPath) + SLASH + generatedJavaClassName |
| 1320 | + TEMP_FOLDER_NAME_SUFIX + SLASH; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 1324 | * Parses attribute to get the attribute string. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1325 | * |
| 1326 | * @param attr attribute info |
| 1327 | * @return attribute string |
| 1328 | */ |
| 1329 | private String parseAttribute(JavaAttributeInfo attr) { |
| 1330 | |
| 1331 | /* |
| 1332 | * TODO: check if this utility needs to be called or move to the caller |
| 1333 | */ |
janani b | de4ffab | 2016-04-15 16:18:30 +0530 | [diff] [blame] | 1334 | String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()), null); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1335 | if (attr.isQualifiedName()) { |
| 1336 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(), |
| 1337 | attributeName, attr.isListAttr()); |
| 1338 | } else { |
| 1339 | return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName, |
| 1340 | attr.isListAttr()); |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 1345 | * Appends content to temporary file. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1346 | * |
| 1347 | * @param file temporary file |
| 1348 | * @param data data to be appended |
| 1349 | * @throws IOException when fails to append to file |
| 1350 | */ |
| 1351 | private void appendToFile(File file, String data) throws IOException { |
| 1352 | |
| 1353 | try { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1354 | insertDataIntoJavaFile(file, data); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1355 | } catch (IOException ex) { |
| 1356 | throw new IOException("failed to write in temp file."); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | /** |
| 1361 | * Adds current node info as and attribute to the parent generated file. |
| 1362 | * |
| 1363 | * @param curNode current node which needs to be added as an attribute in |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1364 | * the parent generated code |
| 1365 | * @param isList is list construct |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1366 | * @throws IOException IO operation exception |
| 1367 | */ |
| 1368 | public void addCurNodeInfoInParentTempFile(YangNode curNode, |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1369 | boolean isList) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1370 | |
| 1371 | YangNode parent = getParentNodeInGenCode(curNode); |
| 1372 | if (!(parent instanceof JavaCodeGenerator)) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1373 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1374 | } |
| 1375 | JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode, |
| 1376 | parent, isList); |
| 1377 | |
| 1378 | if (!(parent instanceof HasTempJavaCodeFragmentFiles)) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1379 | throw new TranslatorException("missing parent temp file handle"); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1380 | } |
| 1381 | ((HasTempJavaCodeFragmentFiles) parent) |
| 1382 | .getTempJavaCodeFragmentFiles() |
| 1383 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1384 | } |
| 1385 | |
| 1386 | /** |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1387 | * Adds parent's info to current node import list. |
| 1388 | * |
| 1389 | * @param curNode current node for which import list needs to be updated |
| 1390 | */ |
| 1391 | public void addParentInfoInCurNodeTempFile(YangNode curNode) { |
| 1392 | caseImportInfo = new JavaQualifiedTypeInfo(); |
| 1393 | YangNode parent = getParentNodeInGenCode(curNode); |
| 1394 | if (!(parent instanceof JavaCodeGenerator)) { |
| 1395 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 1396 | } |
| 1397 | |
| 1398 | if (!(curNode instanceof HasJavaFileInfo)) { |
| 1399 | throw new TranslatorException("missing java file information to get the package details " |
| 1400 | + "of attribute corresponding to child node"); |
| 1401 | } |
| 1402 | |
| 1403 | caseImportInfo.setClassInfo(getCaptialCase(getCamelCase(parent.getName(), null))); |
| 1404 | caseImportInfo.setPkgInfo(((HasJavaFileInfo) parent).getJavaFileInfo().getPackage()); |
| 1405 | ((HasJavaImportData) curNode).getJavaImportData().addImportInfo(curNode, caseImportInfo); |
| 1406 | } |
| 1407 | |
| 1408 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1409 | * Adds leaf attributes in generated files. |
| 1410 | * |
| 1411 | * @param listOfLeaves list of YANG leaf |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1412 | * @param curNode current data model node |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1413 | * @throws IOException IO operation fail |
| 1414 | */ |
| 1415 | private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves, |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1416 | YangNode curNode) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1417 | |
| 1418 | if (listOfLeaves != null) { |
| 1419 | for (YangLeaf leaf : listOfLeaves) { |
| 1420 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfLeaf(curNode, |
| 1421 | leaf.getDataType(), |
| 1422 | leaf.getLeafName(), false); |
| 1423 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Adds leaf list's attributes in generated files. |
| 1430 | * |
| 1431 | * @param listOfLeafList list of YANG leaves |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1432 | * @param curNode cached file handle |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1433 | * @throws IOException IO operation fail |
| 1434 | */ |
| 1435 | private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1436 | YangNode curNode) throws IOException { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1437 | |
| 1438 | if (listOfLeafList != null) { |
| 1439 | |
| 1440 | /* |
| 1441 | * Check if the attribute is of type list, then the java.lang.list |
| 1442 | * needs to be imported. |
| 1443 | */ |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1444 | if (!listOfLeafList.isEmpty()) { |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1445 | if (!(curNode instanceof HasJavaImportData)) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1446 | throw new TranslatorException("missing import info in current data model node"); |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1447 | |
| 1448 | } |
| 1449 | ((HasJavaImportData) curNode).getJavaImportData() |
| 1450 | .setIfListImported(true); |
| 1451 | |
| 1452 | } |
| 1453 | |
| 1454 | for (YangLeafList leafList : listOfLeafList) { |
| 1455 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfLeaf( |
| 1456 | curNode, leafList.getDataType(), leafList.getLeafName(), |
| 1457 | true); |
| 1458 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | /** |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1464 | * Adds all the leaves in the current data model node as part of the |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1465 | * generated temporary file. |
| 1466 | * |
| 1467 | * @param curNode java file info of the generated file |
| 1468 | * @throws IOException IO operation fail |
| 1469 | */ |
| 1470 | public void addCurNodeLeavesInfoToTempFiles(YangNode curNode) throws IOException { |
| 1471 | |
| 1472 | if (curNode instanceof YangLeavesHolder) { |
| 1473 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
| 1474 | addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), curNode); |
| 1475 | addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), curNode); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1480 | * Add all the type in the current data model node as part of the |
| 1481 | * generated temporary file. |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1482 | * |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1483 | * @param hasType YANG java data model node which has type info, eg union / typedef |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1484 | * @throws IOException IO operation fail |
| 1485 | */ |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1486 | public void addTypeInfoToTempFiles(HasType hasType) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1487 | |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1488 | List<YangType<?>> typeList = hasType.getTypeList(); |
| 1489 | if (typeList != null) { |
| 1490 | for (YangType<?> yangType : typeList) { |
| 1491 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfType((YangNode) hasType, |
| 1492 | yangType, getTypeName(yangType.getDataTypeName()), false); |
| 1493 | addJavaSnippetInfoToApplicableTempFiles((YangNode) hasType, javaAttributeInfo); |
| 1494 | } |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | private String getTypeName(String dataTypeName) { |
| 1499 | return dataTypeName; |
| 1500 | //TODO: implement the method. |
| 1501 | } |
| 1502 | |
| 1503 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1504 | * Adds enum attributes to temporary files. |
| 1505 | * |
| 1506 | * @param curNode current YANG node |
| 1507 | * @throws IOException when fails to do IO operations |
| 1508 | */ |
| 1509 | public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException { |
| 1510 | |
| 1511 | if (curNode instanceof YangEnumeration) { |
| 1512 | Set<YangEnum> enumSet = ((YangEnumeration) curNode).getEnumSet(); |
| 1513 | for (YangEnum curEnum : enumSet) { |
| 1514 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfEnumAttribute(curNode, curEnum.getNamedValue()); |
| 1515 | setEnumValue(curEnum.getValue()); |
| 1516 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1517 | } |
| 1518 | } else { |
| 1519 | throw new TranslatorException("curnode should be of type enum."); |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1524 | * Adds the new attribute info to the target generated temporary files for union class. |
| 1525 | * |
| 1526 | * @param hasType the node for which the type is being added as an attribute |
| 1527 | * @param javaAttributeInfo the attribute info that needs to be added to temporary |
| 1528 | * files |
| 1529 | * @throws IOException IO operation fail |
| 1530 | */ |
| 1531 | private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo) |
| 1532 | throws IOException { |
| 1533 | |
| 1534 | JavaAttributeInfo fromStringAttributeInfo = getFromStringAttributeInfo(hasType, javaAttributeInfo); |
| 1535 | |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1536 | if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) { |
| 1537 | addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1538 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1539 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1540 | } |
| 1541 | |
| 1542 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1543 | * Adds the JAVA rpc snippet information. |
| 1544 | * |
| 1545 | * @param javaAttributeInfoOfInput rpc's input node attribute info |
| 1546 | * @param javaAttributeInfoOfOutput rpc's output node attribute info |
| 1547 | * @param rpcName name of the rpc function |
| 1548 | * @throws IOException IO operation fail |
| 1549 | */ |
| 1550 | public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput, |
| 1551 | JavaAttributeInfo javaAttributeInfoOfOutput, |
| 1552 | String rpcName) throws IOException { |
| 1553 | if ((generatedTempFiles & RPC_IMPL_MASK) != 0) { |
| 1554 | addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName); |
| 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 1559 | * Adds the new attribute info to the target generated temporary files. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1560 | * |
| 1561 | * @param newAttrInfo the attribute info that needs to be added to temporary |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1562 | * files |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1563 | * @throws IOException IO operation fail |
| 1564 | */ |
| 1565 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) |
| 1566 | throws IOException { |
| 1567 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1568 | setNewAttrInfo(newAttrInfo); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1569 | if (isAttributePresent) { |
| 1570 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
| 1571 | addAttribute(newAttrInfo); |
| 1572 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1573 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1574 | if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 1575 | addGetterForInterface(newAttrInfo); |
| 1576 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1577 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1578 | if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 1579 | addSetterForInterface(newAttrInfo); |
| 1580 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1581 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1582 | if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { |
| 1583 | addGetterImpl(newAttrInfo, generatedJavaFiles); |
| 1584 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1585 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1586 | if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { |
| 1587 | addSetterImpl(newAttrInfo); |
| 1588 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1589 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1590 | if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) { |
| 1591 | addConstructor(newAttrInfo); |
| 1592 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1593 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1594 | if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) { |
| 1595 | addHashCodeMethod(newAttrInfo); |
| 1596 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1597 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1598 | if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { |
| 1599 | addEqualsMethod(newAttrInfo); |
| 1600 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1601 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1602 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { |
| 1603 | addToStringMethod(newAttrInfo); |
| 1604 | } |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1605 | |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1606 | if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { |
| 1607 | addAttributesForEnumClass(newAttrInfo); |
| 1608 | } |
| 1609 | |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1610 | if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { |
| 1611 | addOfStringMethod(newAttrInfo); |
| 1612 | } |
| 1613 | |
| 1614 | if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { |
| 1615 | addTypeConstructor(newAttrInfo); |
| 1616 | } |
| 1617 | |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1618 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /** |
Bharat saraswal | d9822e9 | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 1622 | * Returns java file info. |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1623 | * |
| 1624 | * @return java file info |
| 1625 | */ |
| 1626 | private JavaFileInfo getJavaFileInfo() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1627 | return ((HasJavaFileInfo) getCurYangNode()).getJavaFileInfo(); |
| 1628 | } |
| 1629 | |
| 1630 | /** |
| 1631 | * Returns java class name. |
| 1632 | * |
| 1633 | * @param suffix for the class name based on the file type |
| 1634 | * @return java class name |
| 1635 | */ |
| 1636 | private String getJavaClassName(String suffix) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1637 | return getCaptialCase(getJavaFileInfo().getJavaName()) + suffix; |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | /** |
| 1641 | * Returns the directory path. |
| 1642 | * |
| 1643 | * @return directory path |
| 1644 | */ |
| 1645 | private String getDirPath() { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1646 | return getJavaFileInfo().getPackageFilePath(); |
| 1647 | } |
| 1648 | |
| 1649 | /** |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1650 | * Constructs java code exit. |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1651 | * |
| 1652 | * @param fileType generated file type |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1653 | * @param curNode current YANG node |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1654 | * @throws IOException when fails to generate java files |
| 1655 | */ |
| 1656 | public void generateJavaFile(int fileType, YangNode curNode) throws IOException { |
| 1657 | |
| 1658 | setCurYangNode(curNode); |
| 1659 | List<String> imports = new ArrayList<>(); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1660 | if (curNode instanceof HasJavaImportData && isAttributePresent) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1661 | imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo()); |
| 1662 | } |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1663 | |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1664 | /** |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1665 | * Prepares java file generator for extends list. |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1666 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1667 | prepareJavaFileGeneratorForExtendsList(getExtendsList()); |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1668 | if (curNode.getNodeType().equals(MODULE_NODE)) { |
| 1669 | createPackage(absoluteDirPath, getJavaFileInfo().getJavaName()); |
| 1670 | } else { |
| 1671 | createPackage(absoluteDirPath, ((HasJavaFileInfo) curNode.getParent()).getJavaFileInfo().getJavaName() |
| 1672 | + PACKAGE_INFO_JAVADOC_OF_CHILD); |
| 1673 | } |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1674 | /** |
| 1675 | * Generate java code. |
| 1676 | */ |
| 1677 | if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) { |
| 1678 | |
| 1679 | /** |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1680 | * Adds import for case. |
| 1681 | */ |
| 1682 | if (curNode instanceof YangCase) { |
| 1683 | List<String> importData = ((HasJavaImportData) curNode).getJavaImportData().getImports(); |
| 1684 | for (String importInfo : importData) { |
| 1685 | if (!imports.contains(importInfo)) { |
| 1686 | imports.add(importInfo); |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | /** |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1692 | * Adds import for HasAugmentation class. |
| 1693 | */ |
| 1694 | if (isHasAugmentationExtended(getExtendsList())) { |
| 1695 | addHasAugmentationImport(curNode, imports, true); |
| 1696 | } |
| 1697 | |
| 1698 | if (isAugmentedInfoExtended(getExtendsList())) { |
| 1699 | addAugmentedInfoImport(curNode, imports, true); |
| 1700 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1701 | |
| 1702 | /** |
| 1703 | * Create interface file. |
| 1704 | */ |
| 1705 | setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1706 | setInterfaceJavaFileHandle( |
| 1707 | generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent)); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1708 | /** |
| 1709 | * Create builder interface file. |
| 1710 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1711 | if ((fileType & BUILDER_INTERFACE_MASK) != 0) { |
| 1712 | |
| 1713 | setBuilderInterfaceJavaFileHandle( |
| 1714 | getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); |
| 1715 | setBuilderInterfaceJavaFileHandle( |
| 1716 | generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent)); |
| 1717 | /** |
| 1718 | * Append builder interface file to interface file and close it. |
| 1719 | */ |
| 1720 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); |
| 1721 | } |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1722 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1723 | |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1724 | if (isHasAugmentationExtended(getExtendsList())) { |
| 1725 | addHasAugmentationImport(curNode, imports, false); |
| 1726 | } |
| 1727 | if (isAugmentedInfoExtended(getExtendsList())) { |
| 1728 | addAugmentedInfoImport(curNode, imports, false); |
| 1729 | } |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1730 | |
| 1731 | if (curNode instanceof YangCase) { |
| 1732 | removeCaseImport(imports); |
| 1733 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1734 | } |
| 1735 | |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1736 | if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1737 | |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1738 | if (isAttributePresent) { |
| 1739 | addImportsToStringAndHasCodeMethods(curNode, imports); |
| 1740 | } |
| 1741 | if (isHasAugmentationExtended(getExtendsList())) { |
| 1742 | addAugmentedInfoImport(curNode, imports, true); |
| 1743 | addArrayListImport(curNode, imports, true); |
| 1744 | } |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1745 | |
| 1746 | /** |
| 1747 | * Create builder class file. |
| 1748 | */ |
| 1749 | setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1750 | setBuilderClassJavaFileHandle( |
| 1751 | generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent)); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1752 | /** |
| 1753 | * Create impl class file. |
| 1754 | */ |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1755 | if ((fileType & IMPL_CLASS_MASK) != 0) { |
| 1756 | setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); |
| 1757 | setImplClassJavaFileHandle( |
| 1758 | generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent)); |
| 1759 | /** |
| 1760 | * Append impl class to builder class and close it. |
| 1761 | */ |
| 1762 | mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); |
| 1763 | } |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1764 | insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose()); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * Creates type def class file. |
| 1769 | */ |
| 1770 | if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) { |
Bharat saraswal | cc1cdab | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 1771 | addImportsToStringAndHasCodeMethods(curNode, imports); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1772 | setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX))); |
| 1773 | setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports)); |
| 1774 | } |
| 1775 | |
| 1776 | /** |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1777 | * Creates type class file. |
| 1778 | */ |
| 1779 | if ((fileType & GENERATE_UNION_CLASS) != 0) { |
| 1780 | addImportsToStringAndHasCodeMethods(curNode, imports); |
| 1781 | setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX))); |
| 1782 | setTypeClassJavaFileHandle(generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports)); |
| 1783 | } |
| 1784 | |
| 1785 | /** |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1786 | * Creates type enum class file. |
| 1787 | */ |
| 1788 | if ((fileType & GENERATE_ENUM_CLASS) != 0) { |
| 1789 | setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX))); |
| 1790 | setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode)); |
| 1791 | } |
| 1792 | |
| 1793 | /** |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1794 | * Creates rpc interface file. |
| 1795 | */ |
| 1796 | if ((fileType & GENERATE_RPC_INTERFACE) != 0) { |
| 1797 | setRpcInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(RPC_INTERFACE_FILE_NAME_SUFFIX))); |
| 1798 | setRpcInterfaceJavaFileHandle(generateRpcInterfaceFile(getRpcInterfaceJavaFileHandle(), curNode, imports)); |
| 1799 | } |
| 1800 | |
| 1801 | /** |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1802 | * Close all the file handles. |
| 1803 | */ |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1804 | close(false); |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | /** |
Vidyashree Rama | 7142d9c | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 1808 | * Removes case import info from import list. |
| 1809 | * |
| 1810 | * @param imports list of imports |
| 1811 | * @return import for class |
| 1812 | */ |
| 1813 | private List<String> removeCaseImport(List<String> imports) { |
| 1814 | if (imports != null && caseImportInfo != null) { |
| 1815 | String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() + |
| 1816 | SEMI_COLAN + NEW_LINE; |
| 1817 | imports.remove(caseImport); |
| 1818 | } |
| 1819 | return imports; |
| 1820 | } |
| 1821 | |
| 1822 | /** |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1823 | * Removes all temporary file handles. |
| 1824 | * |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1825 | * @param isErrorOccurred when translator fails to generate java files we need to close |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1826 | * all open file handles include temporary files and java files. |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1827 | * @throws IOException when failed to delete the temporary files |
| 1828 | */ |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1829 | public void close(boolean isErrorOccurred) throws IOException { |
Bharat saraswal | e2d51d6 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1830 | |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1831 | boolean isError = isErrorOccurred; |
| 1832 | /** |
| 1833 | * Close all java file handles and when error occurs delete the files. |
| 1834 | */ |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1835 | if ((generatedJavaFiles & INTERFACE_MASK) != 0) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1836 | closeFile(getInterfaceJavaFileHandle(), isError); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1837 | } |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1838 | if ((generatedJavaFiles & BUILDER_CLASS_MASK) != 0) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1839 | closeFile(getBuilderClassJavaFileHandle(), isError); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1840 | } |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1841 | if ((generatedJavaFiles & BUILDER_INTERFACE_MASK) != 0) { |
| 1842 | closeFile(getBuilderInterfaceJavaFileHandle(), true); |
| 1843 | } |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1844 | if ((generatedJavaFiles & IMPL_CLASS_MASK) != 0) { |
| 1845 | closeFile(getImplClassJavaFileHandle(), true); |
| 1846 | } |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1847 | if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) { |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1848 | closeFile(getTypedefClassJavaFileHandle(), isError); |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1849 | } |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1850 | if ((generatedJavaFiles & GENERATE_ENUM_CLASS) != 0) { |
| 1851 | closeFile(getEnumClassJavaFileHandle(), isError); |
| 1852 | } |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1853 | if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) { |
| 1854 | closeFile(getTypeClassJavaFileHandle(), isError); |
| 1855 | } |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1856 | if ((generatedJavaFiles & GENERATE_RPC_INTERFACE) != 0) { |
| 1857 | closeFile(getRpcInterfaceJavaFileHandle(), isError); |
| 1858 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1859 | |
Bharat saraswal | 2f11f65 | 2016-03-25 18:19:46 +0530 | [diff] [blame] | 1860 | /** |
| 1861 | * Close all temporary file handles and delete the files. |
| 1862 | */ |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1863 | if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 1864 | closeFile(getGetterInterfaceTempFileHandle(), true); |
| 1865 | } |
| 1866 | if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { |
| 1867 | closeFile(getGetterImplTempFileHandle(), true); |
| 1868 | } |
| 1869 | if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 1870 | closeFile(getSetterInterfaceTempFileHandle(), true); |
| 1871 | } |
| 1872 | if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { |
| 1873 | closeFile(getSetterImplTempFileHandle(), true); |
| 1874 | } |
| 1875 | if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) { |
| 1876 | closeFile(getConstructorImplTempFileHandle(), true); |
| 1877 | } |
| 1878 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
| 1879 | closeFile(getAttributesTempFileHandle(), true); |
| 1880 | } |
| 1881 | if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) { |
| 1882 | closeFile(getHashCodeImplTempFileHandle(), true); |
| 1883 | } |
| 1884 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { |
| 1885 | closeFile(getToStringImplTempFileHandle(), true); |
| 1886 | } |
| 1887 | if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { |
| 1888 | closeFile(getEqualsImplTempFileHandle(), true); |
| 1889 | } |
Bharat saraswal | d72411a | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 1890 | if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { |
| 1891 | closeFile(getEnumClassTempFileHandle(), true); |
| 1892 | } |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1893 | if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { |
| 1894 | closeFile(getConstructorForTypeTempFileHandle(), true); |
| 1895 | } |
| 1896 | if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { |
| 1897 | closeFile(getOfStringImplTempFileHandle(), true); |
| 1898 | } |
Gaurav Agrawal | 5652766 | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 1899 | if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) { |
| 1900 | closeFile(getFromStringImplTempFileHandle(), true); |
| 1901 | } |
| 1902 | if ((generatedTempFiles & RPC_IMPL_MASK) != 0) { |
| 1903 | closeFile(getRpcInterfaceImplTempFileHandle(), true); |
Gaurav Agrawal | 338735b | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 1904 | } |
Bharat saraswal | 6ef0b76 | 2016-04-05 12:45:45 +0530 | [diff] [blame] | 1905 | clean(getTempDirPath()); |
| 1906 | generatedTempFiles = 0; |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1907 | } |
Vinod Kumar S | 3804650 | 2016-03-23 15:30:27 +0530 | [diff] [blame] | 1908 | } |