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