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