Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | package org.onosproject.yangutils.translator.tojava; |
| 17 | |
| 18 | import java.io.File; |
| 19 | import java.io.IOException; |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.List; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 22 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.RpcNotificationContainer; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangCase; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 26 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 27 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
| 28 | import org.onosproject.yangutils.datamodel.YangNode; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 30 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 33 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
| 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
| 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
| 50 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; |
| 54 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
| 55 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; |
| 56 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 57 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; |
| 58 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
| 60 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
| 63 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 65 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; |
| 66 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 67 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 68 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
| 69 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
| 70 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; |
| 71 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 72 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
| 74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
| 75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
| 77 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentationHoldersImport; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 79 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 80 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 81 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.detectCollisionBwParentAndChildForImport; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 82 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 83 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 84 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 85 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
| 86 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 87 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
| 88 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
| 89 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
| 90 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; |
| 91 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 92 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
| 93 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
| 94 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 95 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
| 96 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 97 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 98 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
| 99 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 100 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
| 101 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
| 102 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; |
| 103 | |
| 104 | /** |
| 105 | * Represents implementation of java code fragments temporary implementations. |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 106 | * Manages the common temp file required for Java file(s) generated. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 107 | */ |
| 108 | public class TempJavaFragmentFiles { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 109 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 110 | /** |
| 111 | * Information about the java files being generated. |
| 112 | */ |
| 113 | private JavaFileInfo javaFileInfo; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 114 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 115 | /** |
| 116 | * Imported class info. |
| 117 | */ |
| 118 | private JavaImportData javaImportData; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 119 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 120 | /** |
| 121 | * The variable which guides the types of temporary files generated using |
| 122 | * the temporary generated file types mask. |
| 123 | */ |
| 124 | private int generatedTempFiles; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 125 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 126 | /** |
| 127 | * Absolute path where the target java file needs to be generated. |
| 128 | */ |
| 129 | private String absoluteDirPath; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 130 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 131 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 132 | * Contains all the interface(s)/class name which will be extended by generated files. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 133 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 134 | private JavaExtendsListHolder javaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 135 | /** |
| 136 | * File type extension for java classes. |
| 137 | */ |
| 138 | private static final String JAVA_FILE_EXTENSION = ".java"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 139 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 140 | /** |
| 141 | * File type extension for temporary classes. |
| 142 | */ |
| 143 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 144 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 145 | /** |
| 146 | * Folder suffix for temporary files folder. |
| 147 | */ |
| 148 | private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 149 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 150 | /** |
| 151 | * File name for getter method. |
| 152 | */ |
| 153 | private static final String GETTER_METHOD_FILE_NAME = "GetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 154 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 155 | /** |
| 156 | * File name for setter method. |
| 157 | */ |
| 158 | private static final String SETTER_METHOD_FILE_NAME = "SetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * File name for getter method implementation. |
| 162 | */ |
| 163 | private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl"; |
| 164 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 165 | /** |
| 166 | * File name for setter method implementation. |
| 167 | */ |
| 168 | private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 169 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 170 | /** |
| 171 | * File name for attributes. |
| 172 | */ |
| 173 | private static final String ATTRIBUTE_FILE_NAME = "Attributes"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 174 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 175 | /** |
| 176 | * File name for to string method. |
| 177 | */ |
| 178 | private static final String TO_STRING_METHOD_FILE_NAME = "ToString"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 179 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 180 | /** |
| 181 | * File name for hash code method. |
| 182 | */ |
| 183 | private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 184 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 185 | /** |
| 186 | * File name for equals method. |
| 187 | */ |
| 188 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 189 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 190 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 191 | * File name for from string method. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 192 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 193 | private static final String FROM_STRING_METHOD_FILE_NAME = "FromString"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 194 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 195 | /** |
| 196 | * File name for interface java file name suffix. |
| 197 | */ |
| 198 | private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 199 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 200 | /** |
| 201 | * File name for builder interface file name suffix. |
| 202 | */ |
| 203 | private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 204 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 205 | /** |
| 206 | * File name for builder class file name suffix. |
| 207 | */ |
| 208 | private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 209 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 210 | /** |
| 211 | * File name for impl class file name suffix. |
| 212 | */ |
| 213 | private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 214 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 215 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 216 | * Java file handle for interface file. |
| 217 | */ |
| 218 | private File interfaceJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 219 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 220 | /** |
| 221 | * Java file handle for builder interface file. |
| 222 | */ |
| 223 | private File builderInterfaceJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 224 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 225 | /** |
| 226 | * Java file handle for builder class file. |
| 227 | */ |
| 228 | private File builderClassJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 229 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 230 | /** |
| 231 | * Java file handle for impl class file. |
| 232 | */ |
| 233 | private File implClassJavaFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 234 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 235 | /** |
| 236 | * Temporary file handle for attribute. |
| 237 | */ |
| 238 | private File attributesTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 239 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 240 | /** |
| 241 | * Temporary file handle for getter of interface. |
| 242 | */ |
| 243 | private File getterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 244 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 245 | /** |
| 246 | * Temporary file handle for setter of interface. |
| 247 | */ |
| 248 | private File setterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * Temporary file handle for getter of class. |
| 252 | */ |
| 253 | private File getterImplTempFileHandle; |
| 254 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 255 | /** |
| 256 | * Temporary file handle for setter of class. |
| 257 | */ |
| 258 | private File setterImplTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 259 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 260 | /** |
| 261 | * Temporary file handle for hash code method of class. |
| 262 | */ |
| 263 | private File hashCodeImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 264 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 265 | /** |
| 266 | * Temporary file handle for equals method of class. |
| 267 | */ |
| 268 | private File equalsImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 269 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 270 | /** |
| 271 | * Temporary file handle for to string method of class. |
| 272 | */ |
| 273 | private File toStringImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 274 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 275 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 276 | * Temporary file handle for from string method of class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 277 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 278 | private File fromStringImplTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 279 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 280 | /** |
| 281 | * Import info for case. |
| 282 | */ |
| 283 | private JavaQualifiedTypeInfo caseImportInfo; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 284 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 285 | /** |
| 286 | * Is attribute added. |
| 287 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 288 | private boolean isAttributePresent; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 289 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 290 | /** |
| 291 | * Creates an instance of temp java fragment files. |
| 292 | */ |
Ray Milkey | 85971c6 | 2016-05-11 18:39:39 +0000 | [diff] [blame] | 293 | public TempJavaFragmentFiles() { |
| 294 | } |
| 295 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 296 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 297 | * Retrieves the absolute path where the file needs to be generated. |
| 298 | * |
| 299 | * @return absolute path where the file needs to be generated |
| 300 | */ |
| 301 | private String getAbsoluteDirPath() { |
| 302 | return absoluteDirPath; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Sets absolute path where the file needs to be generated. |
| 307 | * |
| 308 | * @param absoluteDirPath absolute path where the file needs to be |
| 309 | * generated. |
| 310 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 311 | void setAbsoluteDirPath(String absoluteDirPath) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 312 | this.absoluteDirPath = absoluteDirPath; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Sets the generated java file information. |
| 317 | * |
| 318 | * @param javaFileInfo generated java file information |
| 319 | */ |
| 320 | public void setJavaFileInfo(JavaFileInfo javaFileInfo) { |
| 321 | this.javaFileInfo = javaFileInfo; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Retrieves the generated java file information. |
| 326 | * |
| 327 | * @return generated java file information |
| 328 | */ |
| 329 | public JavaFileInfo getJavaFileInfo() { |
| 330 | return javaFileInfo; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Retrieves the generated temp files. |
| 335 | * |
| 336 | * @return generated temp files |
| 337 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 338 | int getGeneratedTempFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 339 | return generatedTempFiles; |
| 340 | } |
| 341 | |
| 342 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 343 | * Clears the generated file mask. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 344 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 345 | void clearGeneratedTempFileMask() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 346 | generatedTempFiles = 0; |
| 347 | } |
| 348 | |
| 349 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 350 | * Adds to generated temporary files. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 351 | * |
| 352 | * @param generatedTempFile generated file |
| 353 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 354 | void addGeneratedTempFile(int generatedTempFile) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 355 | generatedTempFiles |= generatedTempFile; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 356 | setGeneratedTempFiles(generatedTempFiles); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Sets generated file files. |
| 361 | * |
| 362 | * @param generatedTempFile generated file |
| 363 | */ |
| 364 | void setGeneratedTempFiles(int fileType) { |
| 365 | generatedTempFiles = fileType; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Retrieves the generated Java files. |
| 370 | * |
| 371 | * @return generated Java files |
| 372 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 373 | int getGeneratedJavaFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 374 | return getJavaFileInfo().getGeneratedFileTypes(); |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Retrieves the mapped Java class name. |
| 379 | * |
| 380 | * @return mapped Java class name |
| 381 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 382 | String getGeneratedJavaClassName() { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 383 | return getCapitalCase(getJavaFileInfo().getJavaName()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Retrieves the import data for the generated Java file. |
| 388 | * |
| 389 | * @return import data for the generated Java file |
| 390 | */ |
| 391 | public JavaImportData getJavaImportData() { |
| 392 | return javaImportData; |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Sets import data for the generated Java file. |
| 397 | * |
| 398 | * @param javaImportData import data for the generated Java file |
| 399 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 400 | void setJavaImportData(JavaImportData javaImportData) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 401 | this.javaImportData = javaImportData; |
| 402 | } |
| 403 | |
| 404 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 405 | * Retrieves the status of any attributes added. |
| 406 | * |
| 407 | * @return status of any attributes added |
| 408 | */ |
| 409 | public boolean isAttributePresent() { |
| 410 | return isAttributePresent; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Sets status of any attributes added. |
| 415 | * |
| 416 | * @param attributePresent status of any attributes added |
| 417 | */ |
| 418 | public void setAttributePresent(boolean attributePresent) { |
| 419 | isAttributePresent = attributePresent; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Returns getter methods's temporary file handle. |
| 424 | * |
| 425 | * @return temporary file handle |
| 426 | */ |
| 427 | public File getGetterInterfaceTempFileHandle() { |
| 428 | return getterInterfaceTempFileHandle; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Sets to getter method's temporary file handle. |
| 433 | * |
| 434 | * @param getterForInterface file handle for to getter method |
| 435 | */ |
| 436 | private void setGetterInterfaceTempFileHandle(File getterForInterface) { |
| 437 | getterInterfaceTempFileHandle = getterForInterface; |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * Returns setter method's temporary file handle. |
| 442 | * |
| 443 | * @return temporary file handle |
| 444 | */ |
| 445 | public File getSetterInterfaceTempFileHandle() { |
| 446 | return setterInterfaceTempFileHandle; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Sets to setter method's temporary file handle. |
| 451 | * |
| 452 | * @param setterForInterface file handle for to setter method |
| 453 | */ |
| 454 | private void setSetterInterfaceTempFileHandle(File setterForInterface) { |
| 455 | setterInterfaceTempFileHandle = setterForInterface; |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Returns setter method's impl's temporary file handle. |
| 460 | * |
| 461 | * @return temporary file handle |
| 462 | */ |
| 463 | public File getSetterImplTempFileHandle() { |
| 464 | return setterImplTempFileHandle; |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * Sets to setter method's impl's temporary file handle. |
| 469 | * |
| 470 | * @param setterImpl file handle for to setter method's implementation class |
| 471 | */ |
| 472 | private void setSetterImplTempFileHandle(File setterImpl) { |
| 473 | setterImplTempFileHandle = setterImpl; |
| 474 | } |
| 475 | |
| 476 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 477 | * Returns from string method's temporary file handle. |
| 478 | * |
| 479 | * @return from string method's temporary file handle |
| 480 | */ |
| 481 | public File getFromStringImplTempFileHandle() { |
| 482 | return fromStringImplTempFileHandle; |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Sets from string method's temporary file handle. |
| 487 | * |
| 488 | * @param fromStringImplTempFileHandle from string method's temporary file |
| 489 | * handle |
| 490 | */ |
| 491 | private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) { |
| 492 | this.fromStringImplTempFileHandle = fromStringImplTempFileHandle; |
| 493 | } |
| 494 | |
| 495 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 496 | * Creates an instance of temporary java code fragment. |
| 497 | * |
| 498 | * @param javaFileInfo generated java file information |
| 499 | * @throws IOException when fails to create new file handle |
| 500 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 501 | TempJavaFragmentFiles(JavaFileInfo javaFileInfo) throws IOException { |
| 502 | setJavaExtendsListHolder(new JavaExtendsListHolder()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 503 | setJavaImportData(new JavaImportData()); |
| 504 | setJavaFileInfo(javaFileInfo); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 505 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
| 506 | getJavaFileInfo().getPackageFilePath())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 507 | |
| 508 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 509 | * Initialize getter when generation file type matches to interface |
| 510 | * mask. |
| 511 | */ |
| 512 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
| 513 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 514 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 515 | |
| 516 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 517 | * Initialize getter and setter when generation file type matches to |
| 518 | * builder interface mask. |
| 519 | */ |
| 520 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 521 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 522 | addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK); |
| 523 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 524 | |
| 525 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 526 | * Initialize getterImpl, setterImpl and attributes when generation file |
| 527 | * type matches to builder class mask. |
| 528 | */ |
| 529 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
| 530 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 531 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 532 | addGeneratedTempFile(SETTER_FOR_CLASS_MASK); |
| 533 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 534 | |
| 535 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 536 | * Initialize getterImpl, attributes, constructor, hash code, equals and |
| 537 | * to strings when generation file type matches to impl class mask. |
| 538 | */ |
| 539 | if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) { |
| 540 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 541 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 542 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 543 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 544 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
| 545 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 546 | |
| 547 | /* |
| 548 | * Initialize temp files to generate type class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 549 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 550 | if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 551 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 552 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 553 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 554 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 555 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 556 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 557 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 558 | |
| 559 | /* |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 560 | * Initialize temp files to generate enum class. |
| 561 | */ |
| 562 | if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) { |
| 563 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); |
| 564 | } |
| 565 | /* |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 566 | * Initialize getter and setter when generation file type matches to |
| 567 | * builder interface mask. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 568 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 569 | if ((getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
| 570 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 571 | addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 572 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 573 | addGeneratedTempFile(SETTER_FOR_CLASS_MASK); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 574 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 575 | |
| 576 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 577 | * Set temporary file handles. |
| 578 | */ |
| 579 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 580 | setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); |
| 581 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 582 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 583 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 584 | setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME)); |
| 585 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 586 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 587 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 588 | setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME)); |
| 589 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 590 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 591 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 592 | setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME)); |
| 593 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 594 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 595 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 596 | setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME)); |
| 597 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 598 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 599 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 600 | setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME)); |
| 601 | } |
| 602 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 603 | setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME)); |
| 604 | } |
| 605 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 606 | setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); |
| 607 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 608 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
| 609 | setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME)); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 610 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 611 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** |
| 615 | * Returns java file handle for interface file. |
| 616 | * |
| 617 | * @return java file handle for interface file |
| 618 | */ |
| 619 | private File getInterfaceJavaFileHandle() { |
| 620 | return interfaceJavaFileHandle; |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Sets the java file handle for interface file. |
| 625 | * |
| 626 | * @param interfaceJavaFileHandle java file handle |
| 627 | */ |
| 628 | private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { |
| 629 | this.interfaceJavaFileHandle = interfaceJavaFileHandle; |
| 630 | } |
| 631 | |
| 632 | /** |
| 633 | * Returns java file handle for builder interface file. |
| 634 | * |
| 635 | * @return java file handle for builder interface file |
| 636 | */ |
| 637 | private File getBuilderInterfaceJavaFileHandle() { |
| 638 | return builderInterfaceJavaFileHandle; |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Sets the java file handle for builder interface file. |
| 643 | * |
| 644 | * @param builderInterfaceJavaFileHandle java file handle |
| 645 | */ |
| 646 | private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { |
| 647 | this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * Returns java file handle for builder class file. |
| 652 | * |
| 653 | * @return java file handle for builder class file |
| 654 | */ |
| 655 | private File getBuilderClassJavaFileHandle() { |
| 656 | return builderClassJavaFileHandle; |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * Sets the java file handle for builder class file. |
| 661 | * |
| 662 | * @param builderClassJavaFileHandle java file handle |
| 663 | */ |
| 664 | private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { |
| 665 | this.builderClassJavaFileHandle = builderClassJavaFileHandle; |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Returns java file handle for impl class file. |
| 670 | * |
| 671 | * @return java file handle for impl class file |
| 672 | */ |
| 673 | private File getImplClassJavaFileHandle() { |
| 674 | return implClassJavaFileHandle; |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Sets the java file handle for impl class file. |
| 679 | * |
| 680 | * @param implClassJavaFileHandle java file handle |
| 681 | */ |
| 682 | private void setImplClassJavaFileHandle(File implClassJavaFileHandle) { |
| 683 | this.implClassJavaFileHandle = implClassJavaFileHandle; |
| 684 | } |
| 685 | |
| 686 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 687 | * Returns attribute's temporary file handle. |
| 688 | * |
| 689 | * @return temporary file handle |
| 690 | */ |
| 691 | public File getAttributesTempFileHandle() { |
| 692 | return attributesTempFileHandle; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * Sets attribute's temporary file handle. |
| 697 | * |
| 698 | * @param attributeForClass file handle for attribute |
| 699 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 700 | void setAttributesTempFileHandle(File attributeForClass) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 701 | attributesTempFileHandle = attributeForClass; |
| 702 | } |
| 703 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 704 | /** |
| 705 | * Returns getter method's impl's temporary file handle. |
| 706 | * |
| 707 | * @return temporary file handle |
| 708 | */ |
| 709 | public File getGetterImplTempFileHandle() { |
| 710 | return getterImplTempFileHandle; |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * Sets to getter method's impl's temporary file handle. |
| 715 | * |
| 716 | * @param getterImpl file handle for to getter method's impl |
| 717 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 718 | void setGetterImplTempFileHandle(File getterImpl) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 719 | getterImplTempFileHandle = getterImpl; |
| 720 | } |
| 721 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 722 | /** |
| 723 | * Returns hash code method's temporary file handle. |
| 724 | * |
| 725 | * @return temporary file handle |
| 726 | */ |
| 727 | public File getHashCodeImplTempFileHandle() { |
| 728 | return hashCodeImplTempFileHandle; |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Sets hash code method's temporary file handle. |
| 733 | * |
| 734 | * @param hashCodeMethod file handle for hash code method |
| 735 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 736 | void setHashCodeImplTempFileHandle(File hashCodeMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 737 | hashCodeImplTempFileHandle = hashCodeMethod; |
| 738 | } |
| 739 | |
| 740 | /** |
| 741 | * Returns equals mehtod's temporary file handle. |
| 742 | * |
| 743 | * @return temporary file handle |
| 744 | */ |
| 745 | public File getEqualsImplTempFileHandle() { |
| 746 | return equalsImplTempFileHandle; |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * Sets equals method's temporary file handle. |
| 751 | * |
| 752 | * @param equalsMethod file handle for to equals method |
| 753 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 754 | void setEqualsImplTempFileHandle(File equalsMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 755 | equalsImplTempFileHandle = equalsMethod; |
| 756 | } |
| 757 | |
| 758 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 759 | * Returns to string method's temporary file handle. |
| 760 | * |
| 761 | * @return temporary file handle |
| 762 | */ |
| 763 | public File getToStringImplTempFileHandle() { |
| 764 | return toStringImplTempFileHandle; |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * Sets to string method's temporary file handle. |
| 769 | * |
| 770 | * @param toStringMethod file handle for to string method |
| 771 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 772 | void setToStringImplTempFileHandle(File toStringMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 773 | toStringImplTempFileHandle = toStringMethod; |
| 774 | } |
| 775 | |
| 776 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 777 | * Returns java extends list holder. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 778 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 779 | * @return java extends list holder |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 780 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 781 | public JavaExtendsListHolder getJavaExtendsListHolder() { |
| 782 | return javaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 786 | * Sets java extends list holder. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 787 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 788 | * @param javaExtendsListHolder java extends list holder |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 789 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 790 | public void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) { |
| 791 | this.javaExtendsListHolder = javaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 795 | * Adds attribute for class. |
| 796 | * |
| 797 | * @param attr attribute info |
| 798 | * @throws IOException when fails to append to temporary file |
| 799 | */ |
| 800 | private void addAttribute(JavaAttributeInfo attr) |
| 801 | throws IOException { |
| 802 | appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * Adds getter for interface. |
| 807 | * |
| 808 | * @param attr attribute info |
| 809 | * @throws IOException when fails to append to temporary file |
| 810 | */ |
| 811 | private void addGetterForInterface(JavaAttributeInfo attr) |
| 812 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 813 | appendToFile(getGetterInterfaceTempFileHandle(), |
| 814 | getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Adds setter for interface. |
| 819 | * |
| 820 | * @param attr attribute info |
| 821 | * @throws IOException when fails to append to temporary file |
| 822 | */ |
| 823 | private void addSetterForInterface(JavaAttributeInfo attr) |
| 824 | throws IOException { |
| 825 | appendToFile(getSetterInterfaceTempFileHandle(), |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 826 | getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Adds setter's implementation for class. |
| 831 | * |
| 832 | * @param attr attribute info |
| 833 | * @throws IOException when fails to append to temporary file |
| 834 | */ |
| 835 | private void addSetterImpl(JavaAttributeInfo attr) |
| 836 | throws IOException { |
| 837 | appendToFile(getSetterImplTempFileHandle(), |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 838 | getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) |
| 839 | + |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 840 | NEW_LINE); |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * Adds getter method's impl for class. |
| 845 | * |
| 846 | * @param attr attribute info |
| 847 | * @throws IOException when fails to append to temporary file |
| 848 | */ |
| 849 | private void addGetterImpl(JavaAttributeInfo attr) |
| 850 | throws IOException { |
| 851 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0 |
| 852 | || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
| 853 | appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr, |
| 854 | getGeneratedJavaFiles()) + NEW_LINE); |
| 855 | } else { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 856 | appendToFile(getGetterImplTempFileHandle(), |
| 857 | getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false) |
| 858 | + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 859 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | /** |
| 863 | * Adds build method for interface. |
| 864 | * |
| 865 | * @return build method for interface |
| 866 | * @throws IOException when fails to append to temporary file |
| 867 | */ |
| 868 | String addBuildMethodForInterface() |
| 869 | throws IOException { |
| 870 | return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName()); |
| 871 | } |
| 872 | |
| 873 | /** |
| 874 | * Adds build method's implementation for class. |
| 875 | * |
| 876 | * @return build method implementation for class |
| 877 | * @throws IOException when fails to append to temporary file |
| 878 | */ |
| 879 | String addBuildMethodImpl() |
| 880 | throws IOException { |
| 881 | return getBuildString(getGeneratedJavaClassName()) + NEW_LINE; |
| 882 | } |
| 883 | |
| 884 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 885 | * Adds default constructor for class. |
| 886 | * |
| 887 | * @param modifier modifier for constructor. |
| 888 | * @param toAppend string which need to be appended with the class name |
| 889 | * @return default constructor for class |
| 890 | * @throws IOException when fails to append to file |
| 891 | */ |
| 892 | String addDefaultConstructor(String modifier, String toAppend) |
| 893 | throws IOException { |
| 894 | return NEW_LINE + getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier); |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Adds default constructor for class. |
| 899 | * |
| 900 | * @return default constructor for class |
| 901 | * @throws IOException when fails to append to file |
| 902 | */ |
| 903 | public String addOfMethod() |
| 904 | throws IOException { |
| 905 | return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false) |
| 906 | + getOfMethod(getGeneratedJavaClassName(), null); |
| 907 | } |
| 908 | |
| 909 | /** |
| 910 | * Adds hash code method for class. |
| 911 | * |
| 912 | * @param attr attribute info |
| 913 | * @throws IOException when fails to append to temporary file |
| 914 | */ |
| 915 | private void addHashCodeMethod(JavaAttributeInfo attr) |
| 916 | throws IOException { |
| 917 | appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * Adds equals method for class. |
| 922 | * |
| 923 | * @param attr attribute info |
| 924 | * @throws IOException when fails to append to temporary file |
| 925 | */ |
| 926 | private void addEqualsMethod(JavaAttributeInfo attr) |
| 927 | throws IOException { |
| 928 | appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * Adds ToString method for class. |
| 933 | * |
| 934 | * @param attr attribute info |
| 935 | * @throws IOException when fails to append to temporary file |
| 936 | */ |
| 937 | private void addToStringMethod(JavaAttributeInfo attr) |
| 938 | throws IOException { |
| 939 | appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); |
| 940 | } |
| 941 | |
| 942 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 943 | * Adds from string method for union class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 944 | * |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 945 | * @param javaAttributeInfo type attribute info |
| 946 | * @param fromStringAttributeInfo from string attribute info |
| 947 | * @throws IOException when fails to append to temporary file |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 948 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 949 | private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo, |
| 950 | JavaAttributeInfo fromStringAttributeInfo) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 951 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 952 | appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo, |
| 953 | fromStringAttributeInfo) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 954 | } |
| 955 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 956 | /** |
| 957 | * Returns a temporary file handle for the specific file type. |
| 958 | * |
| 959 | * @param fileName file name |
| 960 | * @return temporary file handle |
| 961 | * @throws IOException when fails to create new file handle |
| 962 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 963 | File getTemporaryFileHandle(String fileName) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 964 | throws IOException { |
| 965 | String path = getTempDirPath(); |
| 966 | File dir = new File(path); |
| 967 | if (!dir.exists()) { |
| 968 | dir.mkdirs(); |
| 969 | } |
| 970 | File file = new File(path + fileName + TEMP_FILE_EXTENSION); |
| 971 | if (!file.exists()) { |
| 972 | file.createNewFile(); |
| 973 | } |
| 974 | return file; |
| 975 | } |
| 976 | |
| 977 | /** |
| 978 | * Returns a temporary file handle for the specific file type. |
| 979 | * |
| 980 | * @param fileName file name |
| 981 | * @return temporary file handle |
| 982 | * @throws IOException when fails to create new file handle |
| 983 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 984 | File getJavaFileHandle(String fileName) throws IOException { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 985 | return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * Returns data from the temporary files. |
| 990 | * |
| 991 | * @param file temporary file handle |
| 992 | * @return stored data from temporary files |
| 993 | * @throws IOException when failed to get data from the given file |
| 994 | */ |
| 995 | public String getTemporaryDataFromFileHandle(File file) |
| 996 | throws IOException { |
| 997 | String path = getTempDirPath(); |
| 998 | if (new File(path + file.getName()).exists()) { |
| 999 | return readAppendFile(path + file.getName(), EMPTY_STRING); |
| 1000 | } else { |
| 1001 | throw new IOException("Unable to get data from the given " |
| 1002 | + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * Returns temporary directory path. |
| 1008 | * |
| 1009 | * @return directory path |
| 1010 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1011 | String getTempDirPath() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1012 | return getPackageDirPathFromJavaJPackage(getAbsoluteDirPath()) + SLASH + getGeneratedJavaClassName() |
| 1013 | + TEMP_FOLDER_NAME_SUFIX + SLASH; |
| 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * Parses attribute to get the attribute string. |
| 1018 | * |
| 1019 | * @param attr attribute info |
| 1020 | * @return attribute string |
| 1021 | */ |
| 1022 | private String parseAttribute(JavaAttributeInfo attr) { |
| 1023 | /* |
| 1024 | * TODO: check if this utility needs to be called or move to the caller |
| 1025 | */ |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1026 | String attributeName = getCamelCase(attr.getAttributeName(), null); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1027 | if (attr.isQualifiedName()) { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1028 | return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), |
| 1029 | attr.getImportInfo().getClassInfo(), |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1030 | attributeName, attr.isListAttr()); |
| 1031 | } else { |
| 1032 | return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName, |
| 1033 | attr.isListAttr()); |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * Appends content to temporary file. |
| 1039 | * |
| 1040 | * @param file temporary file |
| 1041 | * @param data data to be appended |
| 1042 | * @throws IOException when fails to append to file |
| 1043 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1044 | void appendToFile(File file, String data) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1045 | throws IOException { |
| 1046 | try { |
| 1047 | insertDataIntoJavaFile(file, data); |
| 1048 | } catch (IOException ex) { |
| 1049 | throw new IOException("failed to write in temp file."); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * Adds current node info as and attribute to the parent generated file. |
| 1055 | * |
| 1056 | * @param curNode current node which needs to be added as an attribute in |
| 1057 | * the parent generated code |
| 1058 | * @param isList is list construct |
| 1059 | * @throws IOException IO operation exception |
| 1060 | */ |
| 1061 | public static void addCurNodeInfoInParentTempFile(YangNode curNode, |
| 1062 | boolean isList) |
| 1063 | throws IOException { |
| 1064 | YangNode parent = getParentNodeInGenCode(curNode); |
| 1065 | if (!(parent instanceof JavaCodeGenerator)) { |
| 1066 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 1067 | } |
| 1068 | JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode, |
| 1069 | parent, isList); |
| 1070 | if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) { |
| 1071 | throw new TranslatorException("missing parent temp file handle"); |
| 1072 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1073 | getNodesInterfaceFragmentFiles(parent) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1074 | .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1075 | } |
| 1076 | |
| 1077 | /** |
| 1078 | * Creates an attribute info object corresponding to a data model node and |
| 1079 | * return it. |
| 1080 | * |
| 1081 | * @param curNode current data model node for which the java code generation |
| 1082 | * is being handled |
| 1083 | * @param parentNode parent node in which the current node is an attribute |
| 1084 | * @param isListNode is the current added attribute needs to be a list |
| 1085 | * @return AttributeInfo attribute details required to add in temporary |
| 1086 | * files |
| 1087 | */ |
| 1088 | public static JavaAttributeInfo getCurNodeAsAttributeInParent( |
| 1089 | YangNode curNode, YangNode parentNode, boolean isListNode) { |
| 1090 | String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); |
| 1091 | /* |
| 1092 | * Get the import info corresponding to the attribute for import in |
| 1093 | * generated java files or qualified access |
| 1094 | */ |
| 1095 | JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode, |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1096 | getCapitalCase(curNodeName)); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1097 | if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) { |
| 1098 | throw new TranslatorException("Parent node does not have file info"); |
| 1099 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1100 | TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1101 | boolean isQualified = true; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1102 | JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1103 | if (isListNode) { |
| 1104 | parentImportData.setIfListImported(true); |
| 1105 | } |
| 1106 | if (!detectCollisionBwParentAndChildForImport(curNode, qualifiedTypeInfo)) { |
| 1107 | parentImportData.addImportInfo(qualifiedTypeInfo); |
| 1108 | isQualified = false; |
| 1109 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1110 | return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode); |
| 1111 | } |
| 1112 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1113 | /** |
| 1114 | * Returns interface fragment files for node. |
| 1115 | * |
| 1116 | * @param node YANG node |
| 1117 | * @return interface fragment files for node |
| 1118 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1119 | public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) { |
| 1120 | TempJavaFragmentFiles tempJavaFragmentFiles; |
| 1121 | if (node instanceof RpcNotificationContainer) { |
| 1122 | tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node) |
| 1123 | .getTempJavaCodeFragmentFiles() |
| 1124 | .getServiceTempFiles(); |
| 1125 | } else { |
| 1126 | tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node) |
| 1127 | .getTempJavaCodeFragmentFiles() |
| 1128 | .getBeanTempFiles(); |
| 1129 | } |
| 1130 | return tempJavaFragmentFiles; |
| 1131 | } |
| 1132 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1133 | /** |
| 1134 | * Adds parent's info to current node import list. |
| 1135 | * |
| 1136 | * @param curNode current node for which import list needs to be updated |
| 1137 | */ |
| 1138 | public void addParentInfoInCurNodeTempFile(YangNode curNode) { |
| 1139 | caseImportInfo = new JavaQualifiedTypeInfo(); |
| 1140 | YangNode parent = getParentNodeInGenCode(curNode); |
| 1141 | if (!(parent instanceof JavaCodeGenerator)) { |
| 1142 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 1143 | } |
| 1144 | if (!(curNode instanceof JavaFileInfoContainer)) { |
| 1145 | throw new TranslatorException("missing java file information to get the package details " |
| 1146 | + "of attribute corresponding to child node"); |
| 1147 | } |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1148 | caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), null))); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1149 | caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage()); |
| 1150 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1151 | .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Adds leaf attributes in generated files. |
| 1156 | * |
| 1157 | * @param listOfLeaves list of YANG leaf |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1158 | * @param yangPluginConfig |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1159 | * @throws IOException IO operation fail |
| 1160 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1161 | private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves, |
| 1162 | YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1163 | throws IOException { |
| 1164 | if (listOfLeaves != null) { |
| 1165 | for (YangLeaf leaf : listOfLeaves) { |
| 1166 | if (!(leaf instanceof JavaLeafInfoContainer)) { |
| 1167 | throw new TranslatorException("Leaf does not have java information"); |
| 1168 | } |
| 1169 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; |
| 1170 | javaLeaf.updateJavaQualifiedInfo(); |
| 1171 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
| 1172 | javaLeaf.getJavaQualifiedInfo(), |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1173 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 1174 | javaLeaf.getDataType(), |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1175 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 1176 | false); |
| 1177 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | /** |
| 1183 | * Adds leaf list's attributes in generated files. |
| 1184 | * |
| 1185 | * @param listOfLeafList list of YANG leaves |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1186 | * @param yangPluginConfig |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1187 | * @throws IOException IO operation fail |
| 1188 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1189 | private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1190 | throws IOException { |
| 1191 | if (listOfLeafList != null) { |
| 1192 | for (YangLeafList leafList : listOfLeafList) { |
| 1193 | if (!(leafList instanceof JavaLeafInfoContainer)) { |
| 1194 | throw new TranslatorException("Leaf-list does not have java information"); |
| 1195 | } |
| 1196 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; |
| 1197 | javaLeaf.updateJavaQualifiedInfo(); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1198 | getJavaImportData().setIfListImported(true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1199 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
| 1200 | javaLeaf.getJavaQualifiedInfo(), |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1201 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 1202 | javaLeaf.getDataType(), |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1203 | getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 1204 | true); |
| 1205 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
| 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Adds all the leaves in the current data model node as part of the |
| 1212 | * generated temporary file. |
| 1213 | * |
| 1214 | * @param curNode java file info of the generated file |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1215 | * @param yangPluginConfig plugin config |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1216 | * @throws IOException IO operation fail |
| 1217 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1218 | public void addCurNodeLeavesInfoToTempFiles(YangNode curNode, |
| 1219 | YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1220 | throws IOException { |
| 1221 | if (!(curNode instanceof YangLeavesHolder)) { |
| 1222 | throw new TranslatorException("Data model node does not have any leaves"); |
| 1223 | } |
| 1224 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1225 | addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig); |
| 1226 | addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1230 | * Adds the new attribute info to the target generated temporary files. |
| 1231 | * |
| 1232 | * @param newAttrInfo the attribute info that needs to be added to temporary |
| 1233 | * files |
| 1234 | * @throws IOException IO operation fail |
| 1235 | */ |
| 1236 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) |
| 1237 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1238 | setAttributePresent(true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1239 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 1240 | addAttribute(newAttrInfo); |
| 1241 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1242 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1243 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 1244 | addGetterForInterface(newAttrInfo); |
| 1245 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1246 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1247 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 1248 | addSetterForInterface(newAttrInfo); |
| 1249 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1250 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1251 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 1252 | addSetterImpl(newAttrInfo); |
| 1253 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1254 | |
| 1255 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1256 | addGetterImpl(newAttrInfo); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1257 | } |
| 1258 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1259 | addHashCodeMethod(newAttrInfo); |
| 1260 | } |
| 1261 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1262 | addEqualsMethod(newAttrInfo); |
| 1263 | } |
| 1264 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1265 | addToStringMethod(newAttrInfo); |
| 1266 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1267 | |
| 1268 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
| 1269 | JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo); |
| 1270 | /* |
| 1271 | * Create a new java attribute info with qualified information of |
| 1272 | * wrapper classes. |
| 1273 | */ |
| 1274 | JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString, |
| 1275 | newAttrInfo.getAttributeName(), |
| 1276 | newAttrInfo.getAttributeType(), |
| 1277 | getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false); |
| 1278 | |
| 1279 | addFromStringMethod(newAttrInfo, fromStringAttributeInfo); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1280 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * Returns java class name. |
| 1285 | * |
| 1286 | * @param suffix for the class name based on the file type |
| 1287 | * @return java class name |
| 1288 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1289 | String getJavaClassName(String suffix) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1290 | return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | /** |
| 1294 | * Returns the directory path. |
| 1295 | * |
| 1296 | * @return directory path |
| 1297 | */ |
| 1298 | private String getDirPath() { |
| 1299 | return getJavaFileInfo().getPackageFilePath(); |
| 1300 | } |
| 1301 | |
| 1302 | /** |
| 1303 | * Constructs java code exit. |
| 1304 | * |
| 1305 | * @param fileType generated file type |
| 1306 | * @param curNode current YANG node |
| 1307 | * @throws IOException when fails to generate java files |
| 1308 | */ |
| 1309 | public void generateJavaFile(int fileType, YangNode curNode) |
| 1310 | throws IOException { |
| 1311 | List<String> imports = new ArrayList<>(); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1312 | if (isAttributePresent()) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1313 | imports = getJavaImportData().getImports(); |
| 1314 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1315 | createPackage(curNode); |
| 1316 | |
| 1317 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1318 | * Generate java code. |
| 1319 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1320 | if ((fileType & INTERFACE_MASK) != 0 || (fileType & |
| 1321 | BUILDER_INTERFACE_MASK) != 0) { |
| 1322 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1323 | * Adds import for case. |
| 1324 | */ |
| 1325 | if (curNode instanceof YangCase) { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1326 | List<String> importData = |
| 1327 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
| 1328 | .getBeanTempFiles().getJavaImportData().getImports(); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1329 | for (String importInfo : importData) { |
| 1330 | if (!imports.contains(importInfo)) { |
| 1331 | imports.add(importInfo); |
| 1332 | } |
| 1333 | } |
| 1334 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1335 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1336 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1337 | * Create interface file. |
| 1338 | */ |
| 1339 | setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); |
| 1340 | setInterfaceJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1341 | generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent())); |
| 1342 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1343 | * Create builder interface file. |
| 1344 | */ |
| 1345 | if ((fileType & BUILDER_INTERFACE_MASK) != 0) { |
| 1346 | setBuilderInterfaceJavaFileHandle( |
| 1347 | getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); |
| 1348 | setBuilderInterfaceJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1349 | generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, |
| 1350 | isAttributePresent())); |
| 1351 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1352 | * Append builder interface file to interface file and close it. |
| 1353 | */ |
| 1354 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); |
| 1355 | } |
| 1356 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1357 | if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) { |
| 1358 | addAugmentationHoldersImport(curNode, imports, false); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1359 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1360 | if (isAugmentedInfoExtended(getJavaExtendsListHolder().getExtendsList())) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1361 | addAugmentedInfoImport(curNode, imports, false); |
| 1362 | } |
| 1363 | if (curNode instanceof YangCase) { |
| 1364 | removeCaseImport(imports); |
| 1365 | } |
| 1366 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1367 | if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1368 | if (isAttributePresent()) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1369 | addImportsToStringAndHasCodeMethods(curNode, imports); |
| 1370 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1371 | if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1372 | addAugmentedInfoImport(curNode, imports, true); |
| 1373 | addArrayListImport(curNode, imports, true); |
| 1374 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1375 | sortImports(imports); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1376 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1377 | * Create builder class file. |
| 1378 | */ |
| 1379 | setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); |
| 1380 | setBuilderClassJavaFileHandle( |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1381 | generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, |
| 1382 | isAttributePresent())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1383 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1384 | * Create impl class file. |
| 1385 | */ |
| 1386 | if ((fileType & IMPL_CLASS_MASK) != 0) { |
| 1387 | setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); |
| 1388 | setImplClassJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1389 | generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent())); |
| 1390 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1391 | * Append impl class to builder class and close it. |
| 1392 | */ |
| 1393 | mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); |
| 1394 | } |
| 1395 | insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose()); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1396 | if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) { |
| 1397 | addAugmentedInfoImport(curNode, imports, false); |
| 1398 | addArrayListImport(curNode, imports, false); |
| 1399 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1400 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1401 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1402 | * Close all the file handles. |
| 1403 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1404 | freeTemporaryResources(false); |
| 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * Adds imports for ToString and HashCodeMethod. |
| 1409 | * |
| 1410 | * @param curNode current YANG node |
| 1411 | * @param imports import list |
| 1412 | * @return import list |
| 1413 | */ |
| 1414 | public List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) { |
| 1415 | imports.add(getJavaImportData().getImportForHashAndEquals()); |
| 1416 | imports.add(getJavaImportData().getImportForToString()); |
| 1417 | return imports; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | /** |
| 1421 | * Removes case import info from import list. |
| 1422 | * |
| 1423 | * @param imports list of imports |
| 1424 | * @return import for class |
| 1425 | */ |
| 1426 | private List<String> removeCaseImport(List<String> imports) { |
| 1427 | if (imports != null && caseImportInfo != null) { |
| 1428 | String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() + |
| 1429 | SEMI_COLAN + NEW_LINE; |
| 1430 | imports.remove(caseImport); |
| 1431 | } |
| 1432 | return imports; |
| 1433 | } |
| 1434 | |
| 1435 | /** |
| 1436 | * Removes all temporary file handles. |
| 1437 | * |
| 1438 | * @param isErrorOccurred when translator fails to generate java files we |
| 1439 | * need to close all open file handles include temporary files |
| 1440 | * and java files. |
| 1441 | * @throws IOException when failed to delete the temporary files |
| 1442 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1443 | public void freeTemporaryResources(boolean isErrorOccurred) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1444 | throws IOException { |
| 1445 | boolean isError = isErrorOccurred; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1446 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1447 | * Close all java file handles and when error occurs delete the files. |
| 1448 | */ |
| 1449 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
| 1450 | closeFile(getInterfaceJavaFileHandle(), isError); |
| 1451 | } |
| 1452 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
| 1453 | closeFile(getBuilderClassJavaFileHandle(), isError); |
| 1454 | } |
| 1455 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 1456 | closeFile(getBuilderInterfaceJavaFileHandle(), true); |
| 1457 | } |
| 1458 | if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) { |
| 1459 | closeFile(getImplClassJavaFileHandle(), true); |
| 1460 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1461 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1462 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1463 | * Close all temporary file handles and delete the files. |
| 1464 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1465 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1466 | closeFile(getGetterImplTempFileHandle(), true); |
| 1467 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1468 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 1469 | closeFile(getAttributesTempFileHandle(), true); |
| 1470 | } |
| 1471 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1472 | closeFile(getHashCodeImplTempFileHandle(), true); |
| 1473 | } |
| 1474 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1475 | closeFile(getToStringImplTempFileHandle(), true); |
| 1476 | } |
| 1477 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1478 | closeFile(getEqualsImplTempFileHandle(), true); |
| 1479 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1480 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
| 1481 | closeFile(getFromStringImplTempFileHandle(), true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1482 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * Returns if the attribute needs to be accessed in a qualified manner or |
| 1487 | * not, if it needs to be imported, then the same needs to be done. |
| 1488 | * |
| 1489 | * @param importInfo import info for the current attribute being added |
| 1490 | * @return status of the qualified access to the attribute |
| 1491 | */ |
| 1492 | public boolean getIsQualifiedAccessOrAddToImportList( |
| 1493 | JavaQualifiedTypeInfo importInfo) { |
| 1494 | boolean isImportPkgEqualCurNodePkg; |
| 1495 | if (importInfo.getClassInfo().contentEquals( |
| 1496 | getGeneratedJavaClassName())) { |
| 1497 | /* |
| 1498 | * if the current class name is same as the attribute class name, |
| 1499 | * then the attribute must be accessed in a qualified manner. |
| 1500 | */ |
| 1501 | return true; |
| 1502 | } else if (importInfo.getPkgInfo() != null) { |
| 1503 | /* |
| 1504 | * If the attribute type is having the package info, it is contender |
| 1505 | * for import list and also need to check if it needs to be a |
| 1506 | * qualified access. |
| 1507 | */ |
| 1508 | isImportPkgEqualCurNodePkg = isImportPkgEqualCurNodePkg(importInfo); |
| 1509 | if (!isImportPkgEqualCurNodePkg) { |
| 1510 | /* |
| 1511 | * If the package of the attribute added is not same as the |
| 1512 | * current class package, then it must either be imported for |
| 1513 | * access or it must be a qualified access. |
| 1514 | */ |
| 1515 | boolean isImportAdded = getJavaImportData().addImportInfo(importInfo); |
| 1516 | if (!isImportAdded) { |
| 1517 | /* |
| 1518 | * If the attribute type info is not imported, then it must |
| 1519 | * be a qualified access. |
| 1520 | */ |
| 1521 | return true; |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | return false; |
| 1526 | } |
| 1527 | |
| 1528 | /** |
| 1529 | * Checks if the import info is same as the package of the current generated |
| 1530 | * java file. |
| 1531 | * |
| 1532 | * @param importInfo import info for an attribute |
| 1533 | * @return true if the import info is same as the current nodes package |
| 1534 | * false otherwise |
| 1535 | */ |
| 1536 | public boolean isImportPkgEqualCurNodePkg(JavaQualifiedTypeInfo importInfo) { |
| 1537 | return getJavaFileInfo().getPackage() |
| 1538 | .contentEquals(importInfo.getPkgInfo()); |
| 1539 | } |
| 1540 | } |