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