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