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