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