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