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; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 20 | import java.util.List; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 21 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 22 | import org.onosproject.yangutils.datamodel.YangAugment; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.YangAugmentableNode; |
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; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangModule; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangSubModule; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 31 | import org.onosproject.yangutils.utils.io.YangPluginConfig; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
| 33 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 36 | |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
| 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK; |
| 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK; |
| 52 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK; |
| 53 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 54 | 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] | 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
| 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
| 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 58 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 59 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 60 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 61 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
| 62 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 63 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString; |
| 64 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 65 | import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 66 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; |
| 67 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 68 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 69 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 70 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; |
| 71 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 72 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 74 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl; |
| 77 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 79 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; |
| 80 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 81 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 82 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
| 83 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
| 84 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 85 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIsFilerContentMatchForLeaf; |
| 86 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIsFilerContentMatchForLeafList; |
| 87 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIsFilterContentForNodes; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 88 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 89 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
| 90 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
| 91 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 92 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 93 | import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 94 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 95 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 96 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
| 97 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 98 | import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 99 | import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 100 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 101 | import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 102 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 103 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
| 104 | import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED; |
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; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 107 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 108 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 109 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST; |
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; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 111 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 112 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 113 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 114 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 115 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 116 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
| 117 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; |
Bharat saraswal | c2d3be1 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 118 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 119 | |
| 120 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 121 | * Represents implementation of java code fragments temporary implementations. Manages the common temp file required for |
| 122 | * Java file(s) generated. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 123 | */ |
| 124 | public class TempJavaFragmentFiles { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 125 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 126 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 127 | * File type extension for java classes. |
| 128 | */ |
| 129 | private static final String JAVA_FILE_EXTENSION = ".java"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 130 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 131 | /** |
| 132 | * File type extension for temporary classes. |
| 133 | */ |
| 134 | private static final String TEMP_FILE_EXTENSION = ".tmp"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 135 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 136 | /** |
| 137 | * Folder suffix for temporary files folder. |
| 138 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 139 | private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 140 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 141 | /** |
| 142 | * File name for getter method. |
| 143 | */ |
| 144 | private static final String GETTER_METHOD_FILE_NAME = "GetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 145 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 146 | /** |
| 147 | * File name for setter method. |
| 148 | */ |
| 149 | private static final String SETTER_METHOD_FILE_NAME = "SetterMethod"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * File name for getter method implementation. |
| 153 | */ |
| 154 | private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl"; |
| 155 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 156 | /** |
| 157 | * File name for setter method implementation. |
| 158 | */ |
| 159 | private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 160 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 161 | /** |
| 162 | * File name for attributes. |
| 163 | */ |
| 164 | private static final String ATTRIBUTE_FILE_NAME = "Attributes"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 165 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 166 | /** |
| 167 | * File name for to string method. |
| 168 | */ |
| 169 | private static final String TO_STRING_METHOD_FILE_NAME = "ToString"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 170 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 171 | /** |
| 172 | * File name for hash code method. |
| 173 | */ |
| 174 | private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode"; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 175 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 176 | /** |
| 177 | * File name for equals method. |
| 178 | */ |
| 179 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 180 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 181 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 182 | * File name for from string method. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 183 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 184 | private static final String FROM_STRING_METHOD_FILE_NAME = "FromString"; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 185 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 186 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 187 | * File name for from add to list interface method. |
| 188 | */ |
| 189 | private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME = "addToList"; |
| 190 | |
| 191 | /** |
| 192 | * File name for from add to list impl method. |
| 193 | */ |
| 194 | private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME = "addToListImpl"; |
| 195 | |
| 196 | /** |
| 197 | * File name for from leaf identifier attributes. |
| 198 | */ |
| 199 | private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME = "leafIdentifierAtr"; |
| 200 | |
| 201 | /** |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 202 | * File name for is filter content leaf match. |
| 203 | */ |
| 204 | private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME = "isFilterContentMatchLeafMask"; |
| 205 | |
| 206 | /** |
| 207 | * File name for is filter content leaf-list match. |
| 208 | */ |
| 209 | private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME = "isFilterContentMatchLeafListMask"; |
| 210 | |
| 211 | /** |
| 212 | * File name for is filter content node match. |
| 213 | */ |
| 214 | private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME = "isFilterContentMatchNodeMask"; |
| 215 | |
| 216 | /** |
| 217 | * File name for edit content file. |
| 218 | */ |
| 219 | private static final String EDIT_CONTENT_FILE_NAME = "editContentFile"; |
| 220 | |
| 221 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 222 | * File name for interface java file name suffix. |
| 223 | */ |
| 224 | private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 225 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 226 | /** |
| 227 | * File name for builder interface file name suffix. |
| 228 | */ |
| 229 | private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 230 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 231 | /** |
| 232 | * File name for builder class file name suffix. |
| 233 | */ |
| 234 | private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 235 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 236 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 237 | * Information about the java files being generated. |
| 238 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 239 | private JavaFileInfoTranslator javaFileInfo; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * Imported class info. |
| 243 | */ |
| 244 | private JavaImportData javaImportData; |
| 245 | |
| 246 | /** |
| 247 | * The variable which guides the types of temporary files generated using the temporary generated file types mask. |
| 248 | */ |
| 249 | private int generatedTempFiles; |
| 250 | |
| 251 | /** |
| 252 | * Absolute path where the target java file needs to be generated. |
| 253 | */ |
| 254 | private String absoluteDirPath; |
| 255 | |
| 256 | /** |
| 257 | * Contains all the interface(s)/class name which will be extended by generated files. |
| 258 | */ |
| 259 | private JavaExtendsListHolder javaExtendsListHolder; |
| 260 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 261 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 262 | * Java file handle for interface file. |
| 263 | */ |
| 264 | private File interfaceJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 265 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 266 | /** |
| 267 | * Java file handle for builder interface file. |
| 268 | */ |
| 269 | private File builderInterfaceJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 270 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 271 | /** |
| 272 | * Java file handle for builder class file. |
| 273 | */ |
| 274 | private File builderClassJavaFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 275 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 276 | /** |
| 277 | * Java file handle for impl class file. |
| 278 | */ |
| 279 | private File implClassJavaFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 280 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 281 | /** |
| 282 | * Temporary file handle for attribute. |
| 283 | */ |
| 284 | private File attributesTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 285 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 286 | /** |
| 287 | * Temporary file handle for getter of interface. |
| 288 | */ |
| 289 | private File getterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 290 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 291 | /** |
| 292 | * Temporary file handle for setter of interface. |
| 293 | */ |
| 294 | private File setterInterfaceTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 295 | |
| 296 | /** |
| 297 | * Temporary file handle for getter of class. |
| 298 | */ |
| 299 | private File getterImplTempFileHandle; |
| 300 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 301 | /** |
| 302 | * Temporary file handle for setter of class. |
| 303 | */ |
| 304 | private File setterImplTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 305 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 306 | /** |
| 307 | * Temporary file handle for hash code method of class. |
| 308 | */ |
| 309 | private File hashCodeImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 310 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 311 | /** |
| 312 | * Temporary file handle for equals method of class. |
| 313 | */ |
| 314 | private File equalsImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 315 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 316 | /** |
| 317 | * Temporary file handle for to string method of class. |
| 318 | */ |
| 319 | private File toStringImplTempFileHandle; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 320 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 321 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 322 | * Temporary file handle for from string method of class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 323 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 324 | private File fromStringImplTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 325 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 326 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 327 | * Temporary file handle for add to list interface method of class. |
| 328 | */ |
| 329 | private File addToListInterfaceTempFileHandle; |
| 330 | |
| 331 | /** |
| 332 | * Temporary file handle for add to list impl method of class. |
| 333 | */ |
| 334 | private File addToListImplTempFileHandle; |
| 335 | |
| 336 | /** |
| 337 | * Temporary file handle for leaf id attributes of enum. |
| 338 | */ |
| 339 | private File leafIdAttributeTempFileHandle; |
| 340 | |
| 341 | /** |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 342 | * Temporary file handle for is content match method for leaf-list. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 343 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 344 | private File isContentMatchLeafListTempFileHandle; |
| 345 | |
| 346 | /** |
| 347 | * Temporary file handle for is content match method for node. |
| 348 | */ |
| 349 | private File isContentMatchNodeTempFileHandle; |
| 350 | |
| 351 | /** |
| 352 | * Temporary file handle for is content match method for leaf. |
| 353 | */ |
| 354 | private File isContentMatchLeafTempFileHandle; |
| 355 | |
| 356 | /** |
| 357 | * Temporary file handle for edit content file. |
| 358 | */ |
| 359 | private File editContentTempFileHandle; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 360 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 361 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 362 | * Leaf count. |
| 363 | */ |
| 364 | private int leafCount = 0; |
| 365 | |
| 366 | /** |
| 367 | * If current node is root node. |
| 368 | */ |
| 369 | private boolean isRooNode; |
| 370 | |
| 371 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 372 | * Is attribute added. |
| 373 | */ |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 374 | private boolean isAttributePresent; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 375 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 376 | TempJavaFragmentFiles() { |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Creates an instance of temporary java code fragment. |
| 381 | * |
| 382 | * @param javaFileInfo generated java file information |
| 383 | * @throws IOException when fails to create new file handle |
| 384 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 385 | TempJavaFragmentFiles(JavaFileInfoTranslator javaFileInfo) |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 386 | throws IOException { |
| 387 | setJavaExtendsListHolder(new JavaExtendsListHolder()); |
| 388 | setJavaImportData(new JavaImportData()); |
| 389 | setJavaFileInfo(javaFileInfo); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 390 | setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(), |
| 391 | getJavaFileInfo().getPackageFilePath())); |
| 392 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 393 | /* |
| 394 | * Initialize getter when generation file type matches to interface |
| 395 | * mask. |
| 396 | */ |
| 397 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
| 398 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 399 | addGeneratedTempFile(ADD_TO_LIST_INTERFACE_MASK); |
| 400 | addGeneratedTempFile(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /* |
| 404 | * Initialize getter and setter when generation file type matches to |
| 405 | * builder interface mask. |
| 406 | */ |
| 407 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 408 | addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK); |
| 409 | addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK); |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Initialize getterImpl, setterImpl and attributes when generation file |
| 414 | * type matches to builder class mask. |
| 415 | */ |
| 416 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
| 417 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 418 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 419 | addGeneratedTempFile(SETTER_FOR_CLASS_MASK); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Initialize getterImpl, attributes, constructor, hash code, equals and |
| 424 | * to strings when generation file type matches to impl class mask. |
| 425 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 426 | if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 427 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 428 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 429 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 430 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 431 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 432 | addGeneratedTempFile(ADD_TO_LIST_IMPL_MASK); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 433 | addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK); |
| 434 | addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_MASK); |
| 435 | addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_NODES_MASK); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* |
| 439 | * Initialize temp files to generate type class. |
| 440 | */ |
| 441 | if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) { |
| 442 | addGeneratedTempFile(ATTRIBUTES_MASK); |
| 443 | addGeneratedTempFile(GETTER_FOR_CLASS_MASK); |
| 444 | addGeneratedTempFile(HASH_CODE_IMPL_MASK); |
| 445 | addGeneratedTempFile(EQUALS_IMPL_MASK); |
| 446 | addGeneratedTempFile(TO_STRING_IMPL_MASK); |
| 447 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); |
| 448 | } |
| 449 | |
| 450 | /* |
| 451 | * Initialize temp files to generate enum class. |
| 452 | */ |
| 453 | if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) { |
| 454 | addGeneratedTempFile(FROM_STRING_IMPL_MASK); |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * Set temporary file handles. |
| 459 | */ |
| 460 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 461 | setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME)); |
| 462 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 463 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
| 464 | setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME)); |
| 465 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 466 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
| 467 | setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME)); |
| 468 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 469 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 470 | setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME)); |
| 471 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 472 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 473 | setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME)); |
| 474 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 475 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 476 | setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME)); |
| 477 | } |
| 478 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 479 | setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME)); |
| 480 | } |
| 481 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 482 | setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); |
| 483 | } |
| 484 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
| 485 | setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME)); |
| 486 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 487 | if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) { |
| 488 | setAddToListInterfaceTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME)); |
| 489 | } |
| 490 | if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) { |
| 491 | setAddToListImplTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME)); |
| 492 | } |
| 493 | if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) { |
| 494 | setLeafIdAttributeTempFileHandle(getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME)); |
| 495 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 496 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) { |
| 497 | setIsContentMatchLeafTempFileHandle(getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME)); |
| 498 | } |
| 499 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) { |
| 500 | setIsContentMatchLeafListTempFileHandle(getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME)); |
| 501 | } |
| 502 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) { |
| 503 | setIsContentMatchNodeTempFileHandle(getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME)); |
| 504 | } |
| 505 | if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) { |
| 506 | setEditContentTempFileHandle(getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME)); |
| 507 | } |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /** |
| 511 | * Adds current node info as and attribute to the parent generated file. |
| 512 | * |
| 513 | * @param curNode current node which needs to be added as an attribute in the parent generated code |
| 514 | * @param isList is list construct |
| 515 | * @param pluginConfig plugin configurations |
| 516 | * @throws IOException IO operation exception |
| 517 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 518 | static void addCurNodeInfoInParentTempFile(YangNode curNode, |
| 519 | boolean isList, YangPluginConfig pluginConfig) |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 520 | throws IOException { |
| 521 | YangNode parent = getParentNodeInGenCode(curNode); |
| 522 | if (!(parent instanceof JavaCodeGenerator)) { |
| 523 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 524 | } |
| 525 | |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 526 | if (parent instanceof YangJavaGroupingTranslator) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 527 | /* |
| 528 | * In case of grouping, there is no need to add the information, it |
| 529 | * will be taken care in uses |
| 530 | */ |
| 531 | return; |
| 532 | } |
| 533 | TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent) |
| 534 | .getTempJavaCodeFragmentFiles().getBeanTempFiles(); |
| 535 | |
| 536 | JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode, |
| 537 | parent, isList, tempJavaBeanFragmentFiles); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 538 | tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Creates an attribute info object corresponding to a data model node and return it. |
| 543 | * |
| 544 | * @param curNode current data model node for which the java code generation is being handled |
| 545 | * @param targetNode target node in which the current node is an attribute |
| 546 | * @param isListNode is the current added attribute needs to be a list |
| 547 | * @param tempJavaFragmentFiles temp java fragment files |
| 548 | * @return AttributeInfo attribute details required to add in temporary files |
| 549 | */ |
| 550 | public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode, |
| 551 | YangNode targetNode, boolean isListNode, |
| 552 | TempJavaFragmentFiles tempJavaFragmentFiles) { |
| 553 | String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); |
| 554 | if (curNodeName == null) { |
| 555 | updateJavaFileInfo(curNode, null); |
| 556 | curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName(); |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Get the import info corresponding to the attribute for import in |
| 561 | * generated java files or qualified access |
| 562 | */ |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 563 | JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 564 | getCapitalCase(curNodeName)); |
| 565 | if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) { |
| 566 | throw new TranslatorException("Parent node does not have file info"); |
| 567 | } |
| 568 | JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData(); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 569 | JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo(); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 570 | |
| 571 | boolean isQualified; |
Bharat saraswal | aab24b9 | 2016-08-02 18:43:16 +0530 | [diff] [blame] | 572 | if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 573 | && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)) |
| 574 | || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 575 | |
| 576 | isQualified = true; |
| 577 | } else { |
| 578 | String className; |
Bharat saraswal | aab24b9 | 2016-08-02 18:43:16 +0530 | [diff] [blame] | 579 | if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 580 | className = getCapitalCase(fileInfo.getJavaName()) + SERVICE; |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 581 | } else { |
| 582 | className = getCapitalCase(fileInfo.getJavaName()); |
| 583 | } |
| 584 | |
| 585 | isQualified = parentImportData.addImportInfo(qualifiedTypeInfo, |
| 586 | className, fileInfo.getPackage()); |
| 587 | } |
| 588 | |
| 589 | if (isListNode) { |
| 590 | parentImportData.setIfListImported(true); |
| 591 | } |
| 592 | |
| 593 | return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode); |
| 594 | } |
| 595 | |
| 596 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 597 | * Returns java attribute for leaf. |
| 598 | * |
| 599 | * @param tempJavaFragmentFiles temporary generated file |
| 600 | * @param leaf YANG leaf |
| 601 | * @param yangPluginConfig plugin configurations |
| 602 | * @return java attribute for leaf |
| 603 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 604 | private static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf, |
| 605 | YangPluginConfig yangPluginConfig) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 606 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf; |
| 607 | javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); |
| 608 | javaLeaf.updateJavaQualifiedInfo(); |
| 609 | return getAttributeInfoForTheData( |
| 610 | javaLeaf.getJavaQualifiedInfo(), |
| 611 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 612 | javaLeaf.getDataType(), |
| 613 | tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 614 | false); |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Returns java attribute for leaf-list. |
| 619 | * |
| 620 | * @param tempJavaFragmentFiles temporary generated file |
| 621 | * @param leafList YANG leaf-list |
| 622 | * @param yangPluginConfig plugin configurations |
| 623 | * @return java attribute for leaf-list |
| 624 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 625 | private static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles, |
| 626 | YangLeafList leafList, |
| 627 | YangPluginConfig yangPluginConfig) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 628 | JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList; |
| 629 | javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver()); |
| 630 | javaLeaf.updateJavaQualifiedInfo(); |
| 631 | tempJavaFragmentFiles.getJavaImportData().setIfListImported(true); |
| 632 | return getAttributeInfoForTheData( |
| 633 | javaLeaf.getJavaQualifiedInfo(), |
| 634 | javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()), |
| 635 | javaLeaf.getDataType(), |
| 636 | tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()), |
| 637 | true); |
| 638 | } |
| 639 | |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 640 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 641 | * Retrieves the absolute path where the file needs to be generated. |
| 642 | * |
| 643 | * @return absolute path where the file needs to be generated |
| 644 | */ |
| 645 | private String getAbsoluteDirPath() { |
| 646 | return absoluteDirPath; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Sets absolute path where the file needs to be generated. |
| 651 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 652 | * @param absoluteDirPath absolute path where the file needs to be generated. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 653 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 654 | void setAbsoluteDirPath(String absoluteDirPath) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 655 | this.absoluteDirPath = absoluteDirPath; |
| 656 | } |
| 657 | |
| 658 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 659 | * Retrieves the generated java file information. |
| 660 | * |
| 661 | * @return generated java file information |
| 662 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 663 | public JavaFileInfoTranslator getJavaFileInfo() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 664 | return javaFileInfo; |
| 665 | } |
| 666 | |
| 667 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 668 | * Sets the generated java file information. |
| 669 | * |
| 670 | * @param javaFileInfo generated java file information |
| 671 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 672 | public void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 673 | this.javaFileInfo = javaFileInfo; |
| 674 | } |
| 675 | |
| 676 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 677 | * Retrieves the generated temp files. |
| 678 | * |
| 679 | * @return generated temp files |
| 680 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 681 | int getGeneratedTempFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 682 | return generatedTempFiles; |
| 683 | } |
| 684 | |
| 685 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 686 | * Sets generated file files. |
| 687 | * |
| 688 | * @param fileType generated file type |
| 689 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 690 | private void setGeneratedTempFiles(int fileType) { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 691 | generatedTempFiles = fileType; |
| 692 | } |
| 693 | |
| 694 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 695 | * Adds to generated temporary files. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 696 | * |
| 697 | * @param generatedTempFile generated file |
| 698 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 699 | void addGeneratedTempFile(int generatedTempFile) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 700 | generatedTempFiles |= generatedTempFile; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 701 | setGeneratedTempFiles(generatedTempFiles); |
| 702 | } |
| 703 | |
| 704 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 705 | * Retrieves the generated Java files. |
| 706 | * |
| 707 | * @return generated Java files |
| 708 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 709 | int getGeneratedJavaFiles() { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 710 | return getJavaFileInfo().getGeneratedFileTypes(); |
| 711 | } |
| 712 | |
| 713 | /** |
| 714 | * Retrieves the mapped Java class name. |
| 715 | * |
| 716 | * @return mapped Java class name |
| 717 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 718 | String getGeneratedJavaClassName() { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 719 | return getCapitalCase(getJavaFileInfo().getJavaName()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Retrieves the import data for the generated Java file. |
| 724 | * |
| 725 | * @return import data for the generated Java file |
| 726 | */ |
| 727 | public JavaImportData getJavaImportData() { |
| 728 | return javaImportData; |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Sets import data for the generated Java file. |
| 733 | * |
| 734 | * @param javaImportData import data for the generated Java file |
| 735 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 736 | void setJavaImportData(JavaImportData javaImportData) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 737 | this.javaImportData = javaImportData; |
| 738 | } |
| 739 | |
| 740 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 741 | * Retrieves the status of any attributes added. |
| 742 | * |
| 743 | * @return status of any attributes added |
| 744 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 745 | boolean isAttributePresent() { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 746 | return isAttributePresent; |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * Sets status of any attributes added. |
| 751 | * |
| 752 | * @param attributePresent status of any attributes added |
| 753 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 754 | private void setAttributePresent(boolean attributePresent) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 755 | isAttributePresent = attributePresent; |
| 756 | } |
| 757 | |
| 758 | /** |
| 759 | * Returns getter methods's temporary file handle. |
| 760 | * |
| 761 | * @return temporary file handle |
| 762 | */ |
| 763 | public File getGetterInterfaceTempFileHandle() { |
| 764 | return getterInterfaceTempFileHandle; |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * Sets to getter method's temporary file handle. |
| 769 | * |
| 770 | * @param getterForInterface file handle for to getter method |
| 771 | */ |
| 772 | private void setGetterInterfaceTempFileHandle(File getterForInterface) { |
| 773 | getterInterfaceTempFileHandle = getterForInterface; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Returns setter method's temporary file handle. |
| 778 | * |
| 779 | * @return temporary file handle |
| 780 | */ |
| 781 | public File getSetterInterfaceTempFileHandle() { |
| 782 | return setterInterfaceTempFileHandle; |
| 783 | } |
| 784 | |
| 785 | /** |
| 786 | * Sets to setter method's temporary file handle. |
| 787 | * |
| 788 | * @param setterForInterface file handle for to setter method |
| 789 | */ |
| 790 | private void setSetterInterfaceTempFileHandle(File setterForInterface) { |
| 791 | setterInterfaceTempFileHandle = setterForInterface; |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * Returns setter method's impl's temporary file handle. |
| 796 | * |
| 797 | * @return temporary file handle |
| 798 | */ |
| 799 | public File getSetterImplTempFileHandle() { |
| 800 | return setterImplTempFileHandle; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Sets to setter method's impl's temporary file handle. |
| 805 | * |
| 806 | * @param setterImpl file handle for to setter method's implementation class |
| 807 | */ |
| 808 | private void setSetterImplTempFileHandle(File setterImpl) { |
| 809 | setterImplTempFileHandle = setterImpl; |
| 810 | } |
| 811 | |
| 812 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 813 | * Returns from string method's temporary file handle. |
| 814 | * |
| 815 | * @return from string method's temporary file handle |
| 816 | */ |
| 817 | public File getFromStringImplTempFileHandle() { |
| 818 | return fromStringImplTempFileHandle; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * Sets from string method's temporary file handle. |
| 823 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 824 | * @param fromStringImplTempFileHandle from string method's temporary file handle |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 825 | */ |
| 826 | private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) { |
| 827 | this.fromStringImplTempFileHandle = fromStringImplTempFileHandle; |
| 828 | } |
| 829 | |
| 830 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 831 | * Returns java file handle for interface file. |
| 832 | * |
| 833 | * @return java file handle for interface file |
| 834 | */ |
| 835 | private File getInterfaceJavaFileHandle() { |
| 836 | return interfaceJavaFileHandle; |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * Sets the java file handle for interface file. |
| 841 | * |
| 842 | * @param interfaceJavaFileHandle java file handle |
| 843 | */ |
| 844 | private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { |
| 845 | this.interfaceJavaFileHandle = interfaceJavaFileHandle; |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Returns java file handle for builder interface file. |
| 850 | * |
| 851 | * @return java file handle for builder interface file |
| 852 | */ |
| 853 | private File getBuilderInterfaceJavaFileHandle() { |
| 854 | return builderInterfaceJavaFileHandle; |
| 855 | } |
| 856 | |
| 857 | /** |
| 858 | * Sets the java file handle for builder interface file. |
| 859 | * |
| 860 | * @param builderInterfaceJavaFileHandle java file handle |
| 861 | */ |
| 862 | private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { |
| 863 | this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Returns java file handle for builder class file. |
| 868 | * |
| 869 | * @return java file handle for builder class file |
| 870 | */ |
| 871 | private File getBuilderClassJavaFileHandle() { |
| 872 | return builderClassJavaFileHandle; |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * Sets the java file handle for builder class file. |
| 877 | * |
| 878 | * @param builderClassJavaFileHandle java file handle |
| 879 | */ |
| 880 | private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { |
| 881 | this.builderClassJavaFileHandle = builderClassJavaFileHandle; |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Returns java file handle for impl class file. |
| 886 | * |
| 887 | * @return java file handle for impl class file |
| 888 | */ |
| 889 | private File getImplClassJavaFileHandle() { |
| 890 | return implClassJavaFileHandle; |
| 891 | } |
| 892 | |
| 893 | /** |
| 894 | * Sets the java file handle for impl class file. |
| 895 | * |
| 896 | * @param implClassJavaFileHandle java file handle |
| 897 | */ |
| 898 | private void setImplClassJavaFileHandle(File implClassJavaFileHandle) { |
| 899 | this.implClassJavaFileHandle = implClassJavaFileHandle; |
| 900 | } |
| 901 | |
| 902 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 903 | * Returns attribute's temporary file handle. |
| 904 | * |
| 905 | * @return temporary file handle |
| 906 | */ |
| 907 | public File getAttributesTempFileHandle() { |
| 908 | return attributesTempFileHandle; |
| 909 | } |
| 910 | |
| 911 | /** |
| 912 | * Sets attribute's temporary file handle. |
| 913 | * |
| 914 | * @param attributeForClass file handle for attribute |
| 915 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 916 | private void setAttributesTempFileHandle(File attributeForClass) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 917 | attributesTempFileHandle = attributeForClass; |
| 918 | } |
| 919 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 920 | /** |
| 921 | * Returns getter method's impl's temporary file handle. |
| 922 | * |
| 923 | * @return temporary file handle |
| 924 | */ |
| 925 | public File getGetterImplTempFileHandle() { |
| 926 | return getterImplTempFileHandle; |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Sets to getter method's impl's temporary file handle. |
| 931 | * |
| 932 | * @param getterImpl file handle for to getter method's impl |
| 933 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 934 | private void setGetterImplTempFileHandle(File getterImpl) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 935 | getterImplTempFileHandle = getterImpl; |
| 936 | } |
| 937 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 938 | /** |
| 939 | * Returns hash code method's temporary file handle. |
| 940 | * |
| 941 | * @return temporary file handle |
| 942 | */ |
| 943 | public File getHashCodeImplTempFileHandle() { |
| 944 | return hashCodeImplTempFileHandle; |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * Sets hash code method's temporary file handle. |
| 949 | * |
| 950 | * @param hashCodeMethod file handle for hash code method |
| 951 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 952 | private void setHashCodeImplTempFileHandle(File hashCodeMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 953 | hashCodeImplTempFileHandle = hashCodeMethod; |
| 954 | } |
| 955 | |
| 956 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 957 | * Returns equals method's temporary file handle. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 958 | * |
| 959 | * @return temporary file handle |
| 960 | */ |
| 961 | public File getEqualsImplTempFileHandle() { |
| 962 | return equalsImplTempFileHandle; |
| 963 | } |
| 964 | |
| 965 | /** |
| 966 | * Sets equals method's temporary file handle. |
| 967 | * |
| 968 | * @param equalsMethod file handle for to equals method |
| 969 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 970 | private void setEqualsImplTempFileHandle(File equalsMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 971 | equalsImplTempFileHandle = equalsMethod; |
| 972 | } |
| 973 | |
| 974 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 975 | * Returns to string method's temporary file handle. |
| 976 | * |
| 977 | * @return temporary file handle |
| 978 | */ |
| 979 | public File getToStringImplTempFileHandle() { |
| 980 | return toStringImplTempFileHandle; |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Sets to string method's temporary file handle. |
| 985 | * |
| 986 | * @param toStringMethod file handle for to string method |
| 987 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 988 | private void setToStringImplTempFileHandle(File toStringMethod) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 989 | toStringImplTempFileHandle = toStringMethod; |
| 990 | } |
| 991 | |
| 992 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 993 | * Returns java extends list holder. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 994 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 995 | * @return java extends list holder |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 996 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 997 | public JavaExtendsListHolder getJavaExtendsListHolder() { |
| 998 | return javaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1002 | * Sets java extends list holder. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1003 | * |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1004 | * @param javaExtendsListHolder java extends list holder |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1005 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1006 | void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 1007 | this.javaExtendsListHolder = javaExtendsListHolder; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | /** |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1011 | * Adds is filter content match for leaf. |
| 1012 | * |
| 1013 | * @param attr java attribute |
| 1014 | * @throws IOException when fails to do IO operations |
| 1015 | */ |
| 1016 | private void addIsFilerForLeaf(JavaAttributeInfo attr) |
| 1017 | throws IOException { |
| 1018 | appendToFile(getIsContentMatchLeafTempFileHandle(), |
| 1019 | getIsFilerContentMatchForLeaf(attr, attr.getAttributeType()) + NEW_LINE); |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Adds is filter content match for leaf-list. |
| 1024 | * |
| 1025 | * @param attr java attribute |
| 1026 | * @throws IOException when fails to do IO operations |
| 1027 | */ |
| 1028 | private void addIsFilerForLeafList(JavaAttributeInfo attr) |
| 1029 | throws IOException { |
| 1030 | appendToFile(getIsContentMatchLeafTempFileHandle(), |
| 1031 | getIsFilerContentMatchForLeafList(attr) + NEW_LINE); |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * Adds is filter content match for nodes. |
| 1036 | * |
| 1037 | * @param attr java attribute |
| 1038 | * @throws IOException when fails to do IO operations |
| 1039 | */ |
| 1040 | private void addIsFilerForNode(JavaAttributeInfo attr) |
| 1041 | throws IOException { |
| 1042 | appendToFile(getIsContentMatchLeafTempFileHandle(), |
| 1043 | getIsFilterContentForNodes(attr.getAttributeName(), attr.isListAttr()) + NEW_LINE); |
| 1044 | } |
| 1045 | |
| 1046 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1047 | * Adds attribute for class. |
| 1048 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1049 | * @param attr attribute info |
| 1050 | * @param yangPluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1051 | * @throws IOException when fails to append to temporary file |
| 1052 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1053 | private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1054 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1055 | appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig) |
| 1056 | + FOUR_SPACE_INDENTATION); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | /** |
| 1060 | * Adds getter for interface. |
| 1061 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1062 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1063 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1064 | * @throws IOException when fails to append to temporary file |
| 1065 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1066 | private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1067 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1068 | appendToFile(getGetterInterfaceTempFileHandle(), |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1069 | getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | /** |
| 1073 | * Adds setter for interface. |
| 1074 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1075 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1076 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1077 | * @throws IOException when fails to append to temporary file |
| 1078 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1079 | private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1080 | throws IOException { |
| 1081 | appendToFile(getSetterInterfaceTempFileHandle(), |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1082 | getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig) |
| 1083 | + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * Adds setter's implementation for class. |
| 1088 | * |
| 1089 | * @param attr attribute info |
| 1090 | * @throws IOException when fails to append to temporary file |
| 1091 | */ |
| 1092 | private void addSetterImpl(JavaAttributeInfo attr) |
| 1093 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1094 | if (isRooNode()) { |
| 1095 | appendToFile(getSetterImplTempFileHandle(), |
| 1096 | getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) |
| 1097 | + NEW_LINE); |
| 1098 | } else { |
| 1099 | appendToFile(getSetterImplTempFileHandle(), getOverRideString() + |
| 1100 | getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) |
| 1101 | + NEW_LINE); |
| 1102 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | /** |
| 1106 | * Adds getter method's impl for class. |
| 1107 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1108 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1109 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1110 | * @throws IOException when fails to append to temporary file |
| 1111 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1112 | void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig) |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1113 | throws IOException { |
| 1114 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0 |
| 1115 | || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1116 | if (!isRooNode()) { |
| 1117 | appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr, |
| 1118 | getGeneratedJavaFiles()) + NEW_LINE); |
| 1119 | } else { |
| 1120 | appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr, |
| 1121 | getGeneratedJavaFiles()) + NEW_LINE); |
| 1122 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1123 | } else { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1124 | appendToFile(getGetterImplTempFileHandle(), |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1125 | getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig) |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1126 | + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1127 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1131 | * Adds add to list interface method. |
| 1132 | * |
| 1133 | * @param attr attribute |
| 1134 | * @param pluginConfig plugin configurations |
| 1135 | * @throws IOException when fails to do IO operations |
| 1136 | */ |
| 1137 | private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException { |
| 1138 | appendToFile(getAddToListInterfaceTempFileHandle(), |
| 1139 | getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig) |
| 1140 | + getAddToListMethodInterface(attr) + NEW_LINE); |
| 1141 | } |
| 1142 | |
| 1143 | /** |
| 1144 | * Adds add to list interface method. |
| 1145 | * |
| 1146 | * @param attr attribute |
| 1147 | * @throws IOException when fails to do IO operations |
| 1148 | */ |
| 1149 | private void addAddToListImpl(JavaAttributeInfo attr) throws IOException { |
| 1150 | appendToFile(getAddToListImplTempFileHandle(), |
| 1151 | getAddToListMethodImpl(attr) + NEW_LINE); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Adds leaf identifier enum attributes. |
| 1156 | * |
| 1157 | * @param attr attribute |
| 1158 | * @param value value |
| 1159 | * @param yangPluginConfig plugin config |
| 1160 | * @throws IOException when fails to do IO operations |
| 1161 | */ |
| 1162 | private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig) |
| 1163 | throws IOException { |
| 1164 | appendToFile(getLeafIdAttributeTempFileHandle(), |
| 1165 | FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(), |
| 1166 | value, yangPluginConfig)); |
| 1167 | } |
| 1168 | |
| 1169 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1170 | * Adds build method for interface. |
| 1171 | * |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1172 | * @param pluginConfig plugin configurations |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1173 | * @return build method for interface |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1174 | * @throws IOException when fails to append to temporary file |
| 1175 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1176 | String addBuildMethodForInterface(YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1177 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1178 | return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | /** |
| 1182 | * Adds build method's implementation for class. |
| 1183 | * |
| 1184 | * @return build method implementation for class |
| 1185 | * @throws IOException when fails to append to temporary file |
| 1186 | */ |
| 1187 | String addBuildMethodImpl() |
| 1188 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1189 | return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1193 | * Adds default constructor for class. |
| 1194 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1195 | * @param modifier modifier for constructor. |
| 1196 | * @param toAppend string which need to be appended with the class name |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1197 | * @param pluginConfig plugin configurations |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1198 | * @param isSuffix is value need to be appended as suffix |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1199 | * @return default constructor for class |
| 1200 | * @throws IOException when fails to append to file |
| 1201 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1202 | String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1203 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1204 | String name = getGeneratedJavaClassName(); |
| 1205 | if (isRooNode() && !toAppend.equals(BUILDER)) { |
| 1206 | name = name + OP_PARAM; |
| 1207 | return NEW_LINE |
| 1208 | + getDefaultConstructorString(name, modifier, |
| 1209 | pluginConfig); |
| 1210 | } |
| 1211 | if (isSuffix) { |
| 1212 | return NEW_LINE + |
| 1213 | getDefaultConstructorString(name + toAppend, modifier, pluginConfig); |
| 1214 | } |
| 1215 | String appended; |
| 1216 | if (toAppend.equals(DEFAULT)) { |
| 1217 | appended = getCapitalCase(toAppend); |
| 1218 | } else { |
| 1219 | appended = toAppend; |
| 1220 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1221 | return NEW_LINE |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1222 | + getDefaultConstructorString(appended + name, modifier, |
| 1223 | pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1227 | * Adds hash code method for class. |
| 1228 | * |
| 1229 | * @param attr attribute info |
| 1230 | * @throws IOException when fails to append to temporary file |
| 1231 | */ |
| 1232 | private void addHashCodeMethod(JavaAttributeInfo attr) |
| 1233 | throws IOException { |
| 1234 | appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * Adds equals method for class. |
| 1239 | * |
| 1240 | * @param attr attribute info |
| 1241 | * @throws IOException when fails to append to temporary file |
| 1242 | */ |
| 1243 | private void addEqualsMethod(JavaAttributeInfo attr) |
| 1244 | throws IOException { |
| 1245 | appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); |
| 1246 | } |
| 1247 | |
| 1248 | /** |
| 1249 | * Adds ToString method for class. |
| 1250 | * |
| 1251 | * @param attr attribute info |
| 1252 | * @throws IOException when fails to append to temporary file |
| 1253 | */ |
| 1254 | private void addToStringMethod(JavaAttributeInfo attr) |
| 1255 | throws IOException { |
| 1256 | appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1260 | * Adds from string method for union class. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1261 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1262 | * @param javaAttributeInfo type attribute info |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1263 | * @param fromStringAttributeInfo from string attribute info |
| 1264 | * @throws IOException when fails to append to temporary file |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1265 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1266 | void addFromStringMethod(JavaAttributeInfo javaAttributeInfo, |
| 1267 | JavaAttributeInfo fromStringAttributeInfo) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1268 | throws IOException { |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1269 | appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo, |
| 1270 | fromStringAttributeInfo) + NEW_LINE); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1271 | } |
| 1272 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1273 | /** |
| 1274 | * Returns a temporary file handle for the specific file type. |
| 1275 | * |
| 1276 | * @param fileName file name |
| 1277 | * @return temporary file handle |
| 1278 | * @throws IOException when fails to create new file handle |
| 1279 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1280 | File getTemporaryFileHandle(String fileName) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1281 | throws IOException { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1282 | String path = getTempDirPath(getAbsoluteDirPath()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1283 | File dir = new File(path); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1284 | boolean isCreated; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1285 | if (!dir.exists()) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1286 | isCreated = dir.mkdirs(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1287 | if (!isCreated) { |
| 1288 | throw new IOException("failed to create temporary directory for " + fileName); |
| 1289 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1290 | } |
| 1291 | File file = new File(path + fileName + TEMP_FILE_EXTENSION); |
| 1292 | if (!file.exists()) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1293 | isCreated = file.createNewFile(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1294 | if (!isCreated) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1295 | throw new IOException("failed to create temporary file for " + fileName); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1296 | } |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1297 | } else { |
| 1298 | throw new IOException(fileName + " is reused due to YANG naming"); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1299 | } |
| 1300 | return file; |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * Returns a temporary file handle for the specific file type. |
| 1305 | * |
| 1306 | * @param fileName file name |
| 1307 | * @return temporary file handle |
| 1308 | * @throws IOException when fails to create new file handle |
| 1309 | */ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1310 | File getJavaFileHandle(String fileName) |
| 1311 | throws IOException { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1312 | return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | /** |
| 1316 | * Returns data from the temporary files. |
| 1317 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1318 | * @param file temporary file handle |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1319 | * @param absolutePath absolute path |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1320 | * @return stored data from temporary files |
| 1321 | * @throws IOException when failed to get data from the given file |
| 1322 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1323 | public String getTemporaryDataFromFileHandle(File file, String absolutePath) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1324 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1325 | |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1326 | String path = getTempDirPath(absolutePath); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1327 | if (new File(path + file.getName()).exists()) { |
| 1328 | return readAppendFile(path + file.getName(), EMPTY_STRING); |
| 1329 | } else { |
| 1330 | throw new IOException("Unable to get data from the given " |
| 1331 | + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD); |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | /** |
| 1336 | * Returns temporary directory path. |
| 1337 | * |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1338 | * @param absolutePath absolute path |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1339 | * @return directory path |
| 1340 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1341 | private String getTempDirPath(String absolutePath) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1342 | return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName() |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1343 | + TEMP_FOLDER_NAME_SUFFIX + SLASH; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * Parses attribute to get the attribute string. |
| 1348 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1349 | * @param attr attribute info |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1350 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1351 | * @return attribute string |
| 1352 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1353 | String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1354 | /* |
| 1355 | * TODO: check if this utility needs to be called or move to the caller |
| 1356 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1357 | String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver()); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1358 | String attributeAccessType = PRIVATE; |
| 1359 | if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) { |
| 1360 | attributeAccessType = PROTECTED; |
| 1361 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1362 | if (attr.isQualifiedName()) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1363 | return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(), |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1364 | attr.getImportInfo().getClassInfo(), |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1365 | attributeName, attr.isListAttr(), attributeAccessType); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1366 | } else { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1367 | return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName, |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1368 | attr.isListAttr(), attributeAccessType); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * Appends content to temporary file. |
| 1374 | * |
| 1375 | * @param file temporary file |
| 1376 | * @param data data to be appended |
| 1377 | * @throws IOException when fails to append to file |
| 1378 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1379 | void appendToFile(File file, String data) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1380 | throws IOException { |
| 1381 | try { |
| 1382 | insertDataIntoJavaFile(file, data); |
| 1383 | } catch (IOException ex) { |
| 1384 | throw new IOException("failed to write in temp file."); |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1389 | * Adds parent's info to current node import list. |
| 1390 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1391 | * @param curNode current node for which import list needs to be updated |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1392 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1393 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1394 | void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) { |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1395 | |
| 1396 | JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator(); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1397 | YangNode parent = getParentNodeInGenCode(curNode); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1398 | if (curNode instanceof YangCase && parent instanceof YangAugment) { |
| 1399 | return; |
| 1400 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1401 | if (!(parent instanceof JavaCodeGenerator)) { |
| 1402 | throw new TranslatorException("missing parent node to contain current node info in generated file"); |
| 1403 | } |
| 1404 | if (!(curNode instanceof JavaFileInfoContainer)) { |
| 1405 | throw new TranslatorException("missing java file information to get the package details " |
| 1406 | + "of attribute corresponding to child node"); |
| 1407 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1408 | caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(), |
| 1409 | pluginConfig.getConflictResolver()))); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1410 | caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage()); |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1411 | |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1412 | JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1413 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1414 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles() |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1415 | .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo, |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1416 | getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * Adds leaf attributes in generated files. |
| 1421 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1422 | * @param listOfLeaves list of YANG leaf |
| 1423 | * @param yangPluginConfig plugin config |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1424 | * @param curNode current node |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1425 | * @throws IOException IO operation fail |
| 1426 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1427 | private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves, |
| 1428 | YangPluginConfig yangPluginConfig, YangNode curNode) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1429 | throws IOException { |
| 1430 | if (listOfLeaves != null) { |
| 1431 | for (YangLeaf leaf : listOfLeaves) { |
| 1432 | if (!(leaf instanceof JavaLeafInfoContainer)) { |
| 1433 | throw new TranslatorException("Leaf does not have java information"); |
| 1434 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1435 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
| 1436 | TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 1437 | .getTempJavaCodeFragmentFiles().getBeanTempFiles(); |
| 1438 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf, |
| 1439 | yangPluginConfig), yangPluginConfig); |
| 1440 | } else { |
| 1441 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig), |
| 1442 | yangPluginConfig); |
| 1443 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | /** |
| 1449 | * Adds leaf list's attributes in generated files. |
| 1450 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1451 | * @param listOfLeafList list of YANG leaves |
| 1452 | * @param yangPluginConfig plugin config |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1453 | * @param curNode current node |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1454 | * @throws IOException IO operation fail |
| 1455 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1456 | private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig, |
| 1457 | YangNode curNode) throws IOException { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1458 | if (listOfLeafList != null) { |
| 1459 | for (YangLeafList leafList : listOfLeafList) { |
| 1460 | if (!(leafList instanceof JavaLeafInfoContainer)) { |
| 1461 | throw new TranslatorException("Leaf-list does not have java information"); |
| 1462 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1463 | if (curNode instanceof YangModule || curNode instanceof YangSubModule) { |
| 1464 | TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode) |
| 1465 | .getTempJavaCodeFragmentFiles().getBeanTempFiles(); |
| 1466 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles, |
| 1467 | leafList, yangPluginConfig), yangPluginConfig); |
| 1468 | } else { |
| 1469 | addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this, |
| 1470 | leafList, yangPluginConfig), yangPluginConfig); |
| 1471 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | /** |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1477 | * Adds all the leaves in the current data model node as part of the generated temporary file. |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1478 | * |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1479 | * @param curNode current node |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1480 | * @param yangPluginConfig plugin config |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1481 | * @throws IOException IO operation fail |
| 1482 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1483 | void addCurNodeLeavesInfoToTempFiles(YangNode curNode, |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1484 | YangPluginConfig yangPluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1485 | throws IOException { |
| 1486 | if (!(curNode instanceof YangLeavesHolder)) { |
| 1487 | throw new TranslatorException("Data model node does not have any leaves"); |
| 1488 | } |
| 1489 | YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode; |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1490 | addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode); |
| 1491 | addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig, curNode); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1495 | * Adds the new attribute info to the target generated temporary files. |
| 1496 | * |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1497 | * @param newAttrInfo the attribute info that needs to be added to temporary files |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1498 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1499 | * @throws IOException IO operation fail |
| 1500 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1501 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1502 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1503 | setAttributePresent(true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1504 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1505 | addAttribute(newAttrInfo, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1506 | } |
| 1507 | if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1508 | addGetterForInterface(newAttrInfo, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1509 | } |
| 1510 | if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 1511 | addSetterForInterface(newAttrInfo, pluginConfig); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1512 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1513 | if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) { |
| 1514 | addSetterImpl(newAttrInfo); |
| 1515 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1516 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1517 | addHashCodeMethod(newAttrInfo); |
| 1518 | } |
| 1519 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1520 | addEqualsMethod(newAttrInfo); |
| 1521 | } |
| 1522 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1523 | addToStringMethod(newAttrInfo); |
| 1524 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1525 | if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) { |
| 1526 | //TODO: add implementation for edit content match. |
| 1527 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1528 | if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) { |
| 1529 | addAddToListImpl(newAttrInfo); |
| 1530 | } |
| 1531 | if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) { |
| 1532 | addAddToListInterface(newAttrInfo, pluginConfig); |
| 1533 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1534 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0 |
| 1535 | && newAttrInfo.getAttributeType() == null) { |
| 1536 | addIsFilerForNode(newAttrInfo); |
| 1537 | } |
| 1538 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0 && !newAttrInfo.isListAttr() |
| 1539 | && newAttrInfo.getAttributeType() != null) { |
| 1540 | addIsFilerForLeaf(newAttrInfo); |
| 1541 | } |
| 1542 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0 && newAttrInfo.isListAttr() |
| 1543 | && newAttrInfo.getAttributeType() != null) { |
| 1544 | addIsFilerForLeafList(newAttrInfo); |
| 1545 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1546 | if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr() |
| 1547 | && newAttrInfo.getAttributeType() != null) { |
| 1548 | leafCount++; |
| 1549 | addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig); |
| 1550 | } |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1551 | if (!newAttrInfo.isIntConflict() && |
| 1552 | !newAttrInfo.isLongConflict()) { |
| 1553 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1554 | addGetterImpl(newAttrInfo, pluginConfig); |
| 1555 | } |
| 1556 | |
| 1557 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1558 | JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo, |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1559 | pluginConfig.getConflictResolver()); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1560 | /* |
| 1561 | * Create a new java attribute info with qualified information of |
| 1562 | * wrapper classes. |
| 1563 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1564 | JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString, |
| 1565 | newAttrInfo.getAttributeName(), |
| 1566 | newAttrInfo.getAttributeType(), |
| 1567 | getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1568 | |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1569 | addFromStringMethod(newAttrInfo, fromStringAttributeInfo); |
| 1570 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1571 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | /** |
| 1575 | * Returns java class name. |
| 1576 | * |
| 1577 | * @param suffix for the class name based on the file type |
| 1578 | * @return java class name |
| 1579 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1580 | String getJavaClassName(String suffix) { |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 1581 | return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /** |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1585 | * Returns java class name. |
| 1586 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1587 | * @param node YANG node |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1588 | * @return java class name |
| 1589 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1590 | private String getImplClassName(YangNode node) { |
| 1591 | if (node instanceof YangModule || node instanceof YangSubModule) { |
| 1592 | return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM; |
| 1593 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1594 | return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName()); |
| 1595 | } |
| 1596 | |
| 1597 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1598 | * Returns the directory path. |
| 1599 | * |
| 1600 | * @return directory path |
| 1601 | */ |
| 1602 | private String getDirPath() { |
| 1603 | return getJavaFileInfo().getPackageFilePath(); |
| 1604 | } |
| 1605 | |
| 1606 | /** |
| 1607 | * Constructs java code exit. |
| 1608 | * |
| 1609 | * @param fileType generated file type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1610 | * @param curNode current YANG node |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1611 | * @throws IOException when fails to generate java files |
| 1612 | */ |
| 1613 | public void generateJavaFile(int fileType, YangNode curNode) |
| 1614 | throws IOException { |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1615 | List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles() |
| 1616 | .getJavaImportData().getImports(); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1617 | if (curNode instanceof YangAugmentableNode) { |
| 1618 | addImportsForAugmentableClass(imports, true, true); |
| 1619 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1620 | createPackage(curNode); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1621 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1622 | * Generate java code. |
| 1623 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1624 | if ((fileType & INTERFACE_MASK) != 0 || (fileType & |
| 1625 | BUILDER_INTERFACE_MASK) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1626 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1627 | * Create interface file. |
| 1628 | */ |
| 1629 | setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX))); |
| 1630 | setInterfaceJavaFileHandle( |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1631 | generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent())); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1632 | if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1633 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1634 | * Create builder interface file. |
| 1635 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1636 | if ((fileType & BUILDER_INTERFACE_MASK) != 0) { |
| 1637 | setBuilderInterfaceJavaFileHandle( |
| 1638 | getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); |
| 1639 | setBuilderInterfaceJavaFileHandle( |
| 1640 | generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, |
| 1641 | isAttributePresent())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1642 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1643 | * Append builder interface file to interface file and close it. |
| 1644 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1645 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); |
| 1646 | validateLineLength(getInterfaceJavaFileHandle()); |
| 1647 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1648 | } |
| 1649 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1650 | if (curNode instanceof YangAugmentableNode) { |
| 1651 | addImportsForAugmentableClass(imports, false, true); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1652 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1653 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1654 | if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1655 | if (isAttributePresent()) { |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1656 | addImportsToStringAndHasCodeMethods(imports, true); |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1657 | addArrayListImport(imports); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1658 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1659 | addBitsetImport(imports); |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1660 | if (curNode instanceof YangAugmentableNode) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1661 | addImportsForAugmentableClass(imports, true, false); |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1662 | addInvocationExceptionImport(imports); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1663 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1664 | sortImports(imports); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1665 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1666 | * Create impl class file. |
| 1667 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1668 | setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode))); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1669 | setImplClassJavaFileHandle( |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1670 | generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports)); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1671 | /* |
| 1672 | * Create builder class file. |
| 1673 | */ |
| 1674 | if ((fileType & BUILDER_CLASS_MASK) != 0) { |
| 1675 | setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX))); |
| 1676 | setBuilderClassJavaFileHandle( |
| 1677 | generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode, |
| 1678 | isAttributePresent())); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1679 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1680 | * Append impl class to builder class and close it. |
| 1681 | */ |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1682 | mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle()); |
| 1683 | validateLineLength(getImplClassJavaFileHandle()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1684 | } |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1685 | insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose()); |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1686 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1687 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1688 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1689 | * Close all the file handles. |
| 1690 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1691 | freeTemporaryResources(false); |
| 1692 | } |
| 1693 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1694 | /*Adds import for array list.*/ |
| 1695 | private void addArrayListImport(List<String> imports) { |
| 1696 | if (imports.contains(getJavaImportData().getImportForList())) { |
| 1697 | imports.add(ARRAY_LIST_IMPORT); |
| 1698 | } |
| 1699 | } |
| 1700 | |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1701 | private void addBitsetImport(List<String> imports) { |
| 1702 | imports.add(getJavaImportData().getImportForToBitSet()); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | /** |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1706 | * Adds imports for ToString and HashCodeMethod. |
| 1707 | * |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1708 | * @param imports import list |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1709 | * @param operation add or remove |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1710 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1711 | void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) { |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1712 | if (operation) { |
| 1713 | imports.add(getJavaImportData().getImportForHashAndEquals()); |
| 1714 | imports.add(getJavaImportData().getImportForToString()); |
| 1715 | } else { |
| 1716 | imports.remove(getJavaImportData().getImportForHashAndEquals()); |
| 1717 | imports.remove(getJavaImportData().getImportForToString()); |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1722 | * Adds import for map and hash map. |
| 1723 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1724 | * @param imports import list |
| 1725 | * @param operations true for adding and false for deletion |
| 1726 | * @param isInterfaceFile if need to add in interface file |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1727 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1728 | private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile) { |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1729 | if (operations) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1730 | if (!isInterfaceFile) { |
| 1731 | imports.add(getJavaImportData().getHashMapImport()); |
| 1732 | } |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1733 | imports.add(getJavaImportData().getMapImport()); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1734 | } else { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1735 | if (!isInterfaceFile) { |
| 1736 | imports.remove(getJavaImportData().getHashMapImport()); |
| 1737 | } |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1738 | imports.remove(getJavaImportData().getMapImport()); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1739 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1740 | sortImports(imports); |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1744 | * Adds invocation exception import. |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1745 | * |
| 1746 | * @param imports list of imports |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1747 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1748 | private void addInvocationExceptionImport(List<String> imports) { |
| 1749 | imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT); |
Bharat saraswal | 039f59c | 2016-07-14 21:57:13 +0530 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | /** |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1753 | * Removes all temporary file handles. |
| 1754 | * |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1755 | * @param isErrorOccurred flag to tell translator that error has occurred while file generation |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1756 | * @throws IOException when failed to delete the temporary files |
| 1757 | */ |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1758 | public void freeTemporaryResources(boolean isErrorOccurred) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1759 | throws IOException { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1760 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1761 | * Close all java file handles and when error occurs delete the files. |
| 1762 | */ |
| 1763 | if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1764 | closeFile(getInterfaceJavaFileHandle(), isErrorOccurred); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1765 | } |
| 1766 | if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) { |
Bharat saraswal | d14cbe8 | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1767 | closeFile(getBuilderClassJavaFileHandle(), true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1768 | } |
| 1769 | if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) { |
| 1770 | closeFile(getBuilderInterfaceJavaFileHandle(), true); |
| 1771 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1772 | if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) { |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1773 | closeFile(getImplClassJavaFileHandle(), isErrorOccurred); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1774 | } |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 1775 | /* |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1776 | * Close all temporary file handles and delete the files. |
| 1777 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1778 | if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) { |
| 1779 | closeFile(getGetterImplTempFileHandle(), true); |
| 1780 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1781 | if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) { |
| 1782 | closeFile(getAttributesTempFileHandle(), true); |
| 1783 | } |
| 1784 | if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) { |
| 1785 | closeFile(getHashCodeImplTempFileHandle(), true); |
| 1786 | } |
| 1787 | if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) { |
| 1788 | closeFile(getToStringImplTempFileHandle(), true); |
| 1789 | } |
| 1790 | if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) { |
| 1791 | closeFile(getEqualsImplTempFileHandle(), true); |
| 1792 | } |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 1793 | if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) { |
| 1794 | closeFile(getFromStringImplTempFileHandle(), true); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1795 | } |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1796 | if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) { |
| 1797 | closeFile(getAddToListImplTempFileHandle(), true); |
| 1798 | } |
| 1799 | if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) { |
| 1800 | closeFile(getAddToListInterfaceTempFileHandle(), true); |
| 1801 | } |
| 1802 | if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) { |
| 1803 | closeFile(getLeafIdAttributeTempFileHandle(), true); |
| 1804 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1805 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) { |
| 1806 | closeFile(getIsContentMatchLeafTempFileHandle(), true); |
| 1807 | } |
| 1808 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) { |
| 1809 | closeFile(getIsContentMatchLeafListTempFileHandle(), true); |
| 1810 | } |
| 1811 | if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) { |
| 1812 | closeFile(getIsContentMatchNodeTempFileHandle(), true); |
| 1813 | } |
| 1814 | if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) { |
| 1815 | closeFile(getEditContentTempFileHandle(), true); |
| 1816 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | /** |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 1820 | * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the |
| 1821 | * same needs to be done. |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1822 | * |
| 1823 | * @param importInfo import info for the current attribute being added |
| 1824 | * @return status of the qualified access to the attribute |
| 1825 | */ |
Bharat saraswal | 64e7e23 | 2016-07-14 23:33:55 +0530 | [diff] [blame] | 1826 | boolean getIsQualifiedAccessOrAddToImportList( |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 1827 | JavaQualifiedTypeInfoTranslator importInfo) { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 1828 | return getJavaImportData().addImportInfo(importInfo, getGeneratedJavaClassName(), |
| 1829 | getJavaFileInfo().getPackage()); |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1830 | } |
| 1831 | |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1832 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1833 | * Returns temp file handle for add to list interface. |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1834 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1835 | * @return temp file handle for add to list interface |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1836 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1837 | public File getAddToListInterfaceTempFileHandle() { |
| 1838 | return addToListInterfaceTempFileHandle; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /** |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1842 | * Sets temp file handle for add to list interface. |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1843 | * |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1844 | * @param addToListInterfaceTempFileHandle temp file handle for add to list interface |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1845 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1846 | private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) { |
| 1847 | this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle; |
| 1848 | } |
| 1849 | |
| 1850 | /** |
| 1851 | * Returns temp file handle for add to list impl. |
| 1852 | * |
| 1853 | * @return temp file handle for add to list impl |
| 1854 | */ |
| 1855 | public File getAddToListImplTempFileHandle() { |
| 1856 | return addToListImplTempFileHandle; |
| 1857 | } |
| 1858 | |
| 1859 | /** |
| 1860 | * Sets temp file handle for add to list impl. |
| 1861 | * |
| 1862 | * @param addToListImplTempFileHandle temp file handle for add to list impl |
| 1863 | */ |
| 1864 | private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) { |
| 1865 | this.addToListImplTempFileHandle = addToListImplTempFileHandle; |
| 1866 | } |
| 1867 | |
| 1868 | /** |
| 1869 | * Returns temp file handle for leaf identifier attributes. |
| 1870 | * |
| 1871 | * @return temp file handle for leaf identifier attributes |
| 1872 | */ |
| 1873 | public File getLeafIdAttributeTempFileHandle() { |
| 1874 | return leafIdAttributeTempFileHandle; |
| 1875 | } |
| 1876 | |
| 1877 | /** |
| 1878 | * Sets temp file handle for leaf identifier attributes. |
| 1879 | * |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1880 | * @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1881 | */ |
| 1882 | private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) { |
| 1883 | this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle; |
| 1884 | } |
| 1885 | |
| 1886 | /** |
| 1887 | * Returns if root node is set. |
| 1888 | * |
| 1889 | * @return true if root node |
| 1890 | */ |
| 1891 | private boolean isRooNode() { |
| 1892 | return isRooNode; |
| 1893 | } |
| 1894 | |
| 1895 | /** |
| 1896 | * Sets true if root node. |
| 1897 | * |
| 1898 | * @param rooNode true if root node |
| 1899 | */ |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1900 | void setRooNode(boolean rooNode) { |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 1901 | isRooNode = rooNode; |
Shankara-Huawei | a1039e5 | 2016-07-14 16:53:09 +0530 | [diff] [blame] | 1902 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame^] | 1903 | |
| 1904 | /** |
| 1905 | * Returns temp file for is content match. |
| 1906 | * |
| 1907 | * @return temp file for is content match |
| 1908 | */ |
| 1909 | public File getIsContentMatchLeafTempFileHandle() { |
| 1910 | return isContentMatchLeafTempFileHandle; |
| 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * Sets temp file handle for is content match. |
| 1915 | * |
| 1916 | * @param isContentMatchLeafTempFileHandle temp file handle for is content match |
| 1917 | */ |
| 1918 | private void setIsContentMatchLeafTempFileHandle(File isContentMatchLeafTempFileHandle) { |
| 1919 | this.isContentMatchLeafTempFileHandle = isContentMatchLeafTempFileHandle; |
| 1920 | } |
| 1921 | |
| 1922 | /** |
| 1923 | * Returns temp file for edit content file. |
| 1924 | * |
| 1925 | * @return temp file for edit content file |
| 1926 | */ |
| 1927 | public File getEditContentTempFileHandle() { |
| 1928 | return editContentTempFileHandle; |
| 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * Sets temp file for edit content file. |
| 1933 | * |
| 1934 | * @param editContentTempFileHandle temp file for edit content file |
| 1935 | */ |
| 1936 | private void setEditContentTempFileHandle(File editContentTempFileHandle) { |
| 1937 | this.editContentTempFileHandle = editContentTempFileHandle; |
| 1938 | } |
| 1939 | |
| 1940 | /** |
| 1941 | * Returns temp file for is content match. |
| 1942 | * |
| 1943 | * @return temp file for is content match |
| 1944 | */ |
| 1945 | public File getIsContentMatchLeafListTempFileHandle() { |
| 1946 | return isContentMatchLeafListTempFileHandle; |
| 1947 | } |
| 1948 | |
| 1949 | /** |
| 1950 | * Sets temp file handle for is content match. |
| 1951 | * |
| 1952 | * @param isContentMatchLeafListTempFileHandle temp file handle for is content match |
| 1953 | */ |
| 1954 | private void setIsContentMatchLeafListTempFileHandle(File isContentMatchLeafListTempFileHandle) { |
| 1955 | this.isContentMatchLeafListTempFileHandle = isContentMatchLeafListTempFileHandle; |
| 1956 | } |
| 1957 | |
| 1958 | /** |
| 1959 | * Returns temp file for is content match. |
| 1960 | * |
| 1961 | * @return temp file for is content match |
| 1962 | */ |
| 1963 | public File getIsContentMatchNodeTempFileHandle() { |
| 1964 | return isContentMatchNodeTempFileHandle; |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Sets temp file handle for is content match. |
| 1969 | * |
| 1970 | * @param isContentMatchNodeTempFileHandle temp file handle for is content match |
| 1971 | */ |
| 1972 | private void setIsContentMatchNodeTempFileHandle(File isContentMatchNodeTempFileHandle) { |
| 1973 | this.isContentMatchNodeTempFileHandle = isContentMatchNodeTempFileHandle; |
| 1974 | } |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 1975 | } |