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