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