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