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