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