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