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