Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
| 19 | import java.io.File; |
| 20 | import java.io.IOException; |
| 21 | import java.util.List; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 22 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; |
| 31 | import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.utils.io.impl.CopyrightHeader; |
| 33 | import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame^] | 34 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 35 | |
| 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
| 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS; |
| 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
| 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 51 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK; |
| 53 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK; |
| 54 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK; |
| 55 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK; |
| 56 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK; |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 57 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +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; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 61 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 62 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 63 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 64 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
| 65 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
| 66 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 67 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame^] | 68 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath; |
| 69 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 70 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
| 71 | import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION; |
| 72 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 73 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 74 | import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 75 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 76 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 77 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 78 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 79 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 80 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 81 | import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 82 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 83 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 84 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
| 85 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 86 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 87 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; |
| 88 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 89 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 90 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT; |
| 91 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 92 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 93 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; |
| 94 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 95 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE; |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 96 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER; |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 97 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 98 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 99 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.parsePkg; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 100 | |
| 101 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 102 | * Represents utilities for java file generator. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 103 | */ |
| 104 | public final class JavaFileGeneratorUtils { |
| 105 | |
| 106 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 107 | * Creates an instance of java file generator util. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 108 | */ |
| 109 | private JavaFileGeneratorUtils() { |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns a file object for generated file. |
| 114 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 115 | * @param fileName file name |
| 116 | * @param filePath file package path |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 117 | * @param extension file extension |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 118 | * @param handle cached file handle |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 119 | * @return file object |
| 120 | */ |
| 121 | public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) { |
| 122 | |
| 123 | return new File(handle.getBaseCodeGenPath() + filePath + SLASH + fileName + extension); |
| 124 | } |
| 125 | |
| 126 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 127 | * Returns data stored in temporary files. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 128 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 129 | * @param generatedTempFiles temporary file types |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 130 | * @param tempJavaFragmentFiles temp java fragment files |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 131 | * @return data stored in temporary files |
| 132 | * @throws IOException when failed to get the data from temporary file handle |
| 133 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 134 | public static String getDataFromTempFileHandle(int generatedTempFiles, |
| 135 | TempJavaFragmentFiles tempJavaFragmentFiles) |
| 136 | throws IOException { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 137 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 138 | TempJavaTypeFragmentFiles typeFragmentFiles = null; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 139 | |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 140 | if (tempJavaFragmentFiles instanceof TempJavaTypeFragmentFiles) { |
| 141 | typeFragmentFiles = (TempJavaTypeFragmentFiles) tempJavaFragmentFiles; |
| 142 | } |
| 143 | |
| 144 | TempJavaBeanFragmentFiles beanFragmentFiles = null; |
| 145 | |
| 146 | if (tempJavaFragmentFiles instanceof TempJavaBeanFragmentFiles) { |
| 147 | beanFragmentFiles = (TempJavaBeanFragmentFiles) tempJavaFragmentFiles; |
| 148 | } |
| 149 | |
| 150 | TempJavaServiceFragmentFiles serviceFragmentFiles = null; |
| 151 | if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) { |
| 152 | serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles; |
| 153 | } |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 154 | |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 155 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
| 156 | return tempJavaFragmentFiles |
| 157 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle()); |
| 158 | } else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 159 | return tempJavaFragmentFiles |
| 160 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 161 | } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 162 | return tempJavaFragmentFiles |
| 163 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterInterfaceTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 164 | } else if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 165 | return tempJavaFragmentFiles |
| 166 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterImplTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 167 | } else if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 168 | return tempJavaFragmentFiles |
| 169 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 170 | } else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 171 | if (beanFragmentFiles == null) { |
| 172 | throw new TranslatorException("Required constructor info is missing."); |
| 173 | } |
| 174 | return beanFragmentFiles |
| 175 | .getTemporaryDataFromFileHandle(beanFragmentFiles.getConstructorImplTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 176 | } else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 177 | return tempJavaFragmentFiles |
| 178 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getHashCodeImplTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 179 | } else if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 180 | return tempJavaFragmentFiles |
| 181 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEqualsImplTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 182 | } else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 183 | return tempJavaFragmentFiles |
| 184 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 185 | } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 186 | if (typeFragmentFiles == null) { |
| 187 | throw new TranslatorException("Required of string implementation info is missing."); |
| 188 | } |
| 189 | return typeFragmentFiles |
| 190 | .getTemporaryDataFromFileHandle(typeFragmentFiles.getOfStringImplTempFileHandle()); |
| 191 | } else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { |
| 192 | if (typeFragmentFiles == null) { |
| 193 | throw new TranslatorException("Required constructor implementation info is missing."); |
| 194 | } |
| 195 | return typeFragmentFiles |
| 196 | .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle()); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 197 | } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 198 | return tempJavaFragmentFiles |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 199 | .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle()); |
| 200 | } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { |
| 201 | if (!(tempJavaFragmentFiles instanceof TempJavaEnumerationFragmentFiles)) { |
| 202 | throw new TranslatorException("Required enum info is missing."); |
| 203 | } |
| 204 | TempJavaEnumerationFragmentFiles enumFragmentFiles = |
| 205 | (TempJavaEnumerationFragmentFiles) tempJavaFragmentFiles; |
| 206 | return enumFragmentFiles |
| 207 | .getTemporaryDataFromFileHandle(enumFragmentFiles.getEnumClassTempFileHandle()); |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 208 | } else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) { |
| 209 | if (serviceFragmentFiles == null) { |
| 210 | throw new TranslatorException("Required rpc interface info is missing."); |
| 211 | } |
| 212 | return serviceFragmentFiles |
| 213 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcInterfaceTempFileHandle()); |
Gaurav Agrawal | 02a60de | 2016-04-20 15:49:17 +0530 | [diff] [blame] | 214 | } else if ((generatedTempFiles & RPC_IMPL_MASK) != 0) { |
VinodKumarS-Huawei | 6266db3 | 2016-05-10 17:58:57 +0530 | [diff] [blame] | 215 | if (serviceFragmentFiles == null) { |
| 216 | throw new TranslatorException("Required rpc implementation info is missing."); |
| 217 | } |
| 218 | return serviceFragmentFiles |
| 219 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle()); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 220 | } else if ((generatedTempFiles & EVENT_ENUM_MASK) != 0) { |
| 221 | if (serviceFragmentFiles == null) { |
| 222 | throw new TranslatorException("Required rpc implementation info is missing."); |
| 223 | } |
| 224 | return serviceFragmentFiles |
| 225 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventEnumTempFileHandle()); |
| 226 | } else if ((generatedTempFiles & EVENT_METHOD_MASK) != 0) { |
| 227 | if (serviceFragmentFiles == null) { |
| 228 | throw new TranslatorException("Required rpc implementation info is missing."); |
| 229 | } |
| 230 | return serviceFragmentFiles |
| 231 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventMethodTempFileHandle()); |
| 232 | } else if ((generatedTempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) { |
| 233 | if (serviceFragmentFiles == null) { |
| 234 | throw new TranslatorException("Required rpc implementation info is missing."); |
| 235 | } |
| 236 | return serviceFragmentFiles |
| 237 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectGetterTempFileHandle()); |
| 238 | } else if ((generatedTempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) { |
| 239 | if (serviceFragmentFiles == null) { |
| 240 | throw new TranslatorException("Required rpc implementation info is missing."); |
| 241 | } |
| 242 | return serviceFragmentFiles |
| 243 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectSetterTempFileHandle()); |
| 244 | } else if ((generatedTempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) { |
| 245 | if (serviceFragmentFiles == null) { |
| 246 | throw new TranslatorException("Required rpc implementation info is missing."); |
| 247 | } |
| 248 | return serviceFragmentFiles |
| 249 | .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectAttributeTempFileHandle()); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 250 | } |
| 251 | return null; |
| 252 | } |
| 253 | |
| 254 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 255 | * Initiates generation of file based on generated file type. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 256 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 257 | * @param file generated file |
| 258 | * @param className generated file class name |
| 259 | * @param genType generated file type |
| 260 | * @param imports imports for the file |
| 261 | * @param pkg generated file package |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 262 | * @param pluginConfig plugin configurations |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 263 | * @throws IOException when fails to generate a file |
| 264 | */ |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 265 | public static void initiateJavaFileGeneration(File file, String className, int genType, List<String> imports, |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 266 | String pkg, YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 267 | throws IOException { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 268 | |
| 269 | try { |
| 270 | file.createNewFile(); |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 271 | appendContents(file, className, genType, imports, pkg, pluginConfig); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 272 | } catch (IOException e) { |
| 273 | throw new IOException("Failed to create " + file.getName() + " class file."); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 278 | * Initiates generation of file based on generated file type. |
| 279 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 280 | * @param file generated file |
| 281 | * @param genType generated file type |
| 282 | * @param imports imports for the file |
| 283 | * @param curNode current YANG node |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 284 | * @param className class name |
| 285 | * @throws IOException when fails to generate a file |
| 286 | */ |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 287 | public static void initiateJavaFileGeneration(File file, int genType, List<String> imports, |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 288 | YangNode curNode, String className) |
| 289 | throws IOException { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 290 | |
| 291 | try { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 292 | if (file.exists()) { |
| 293 | throw new IOException(file.getName() + " is reused due to YANG naming"); |
| 294 | } |
| 295 | |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 296 | file.createNewFile(); |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 297 | appendContents(file, genType, imports, curNode, className); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 298 | } catch (IOException e) { |
| 299 | throw new IOException("Failed to create " + file.getName() + " class file."); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 304 | * Appends all the contents into a generated java file. |
| 305 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 306 | * @param file generated file |
| 307 | * @param genType generated file type |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 308 | * @param importsList list of java imports |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 309 | * @param curNode current YANG node |
| 310 | * @param className class name |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 311 | * @throws IOException |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 312 | */ |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 313 | private static void appendContents(File file, int genType, List<String> importsList, YangNode curNode, |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 314 | String className) |
| 315 | throws IOException { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 316 | |
| 317 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
| 318 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 319 | String name = javaFileInfo.getJavaName(); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 320 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 321 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 322 | String pkgString = null; |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 323 | if (genType == GENERATE_EVENT_CLASS |
| 324 | || genType == GENERATE_EVENT_LISTENER_INTERFACE |
| 325 | || genType == GENERATE_EVENT_SUBJECT_CLASS) { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 326 | pkgString = parsePackageString((path + PERIOD + name).toLowerCase(), importsList); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 327 | } else { |
| 328 | pkgString = parsePackageString(path, importsList); |
| 329 | } |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 330 | switch (genType) { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 331 | case INTERFACE_MASK: |
| 332 | appendHeaderContents(file, pkgString, importsList); |
| 333 | write(file, genType, INTERFACE, curNode, className); |
| 334 | break; |
| 335 | case GENERATE_SERVICE_AND_MANAGER: |
| 336 | appendHeaderContents(file, pkgString, importsList); |
| 337 | write(file, genType, RPC_INTERFACE, curNode, className); |
| 338 | break; |
| 339 | case GENERATE_EVENT_CLASS: |
| 340 | appendHeaderContents(file, pkgString, importsList); |
| 341 | write(file, genType, EVENT, curNode, className); |
| 342 | break; |
| 343 | case GENERATE_EVENT_LISTENER_INTERFACE: |
| 344 | appendHeaderContents(file, pkgString, importsList); |
| 345 | write(file, genType, EVENT_LISTENER, curNode, className); |
| 346 | break; |
| 347 | case GENERATE_EVENT_SUBJECT_CLASS: |
| 348 | appendHeaderContents(file, pkgString, importsList); |
| 349 | write(file, genType, EVENT_SUBJECT_CLASS, curNode, className); |
| 350 | break; |
| 351 | default: |
| 352 | break; |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Appends all the contents into a generated java file. |
| 358 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 359 | * @param file generated file |
| 360 | * @param fileName generated file name |
| 361 | * @param genType generated file type |
| 362 | * @param importsList list of java imports |
| 363 | * @param pkg generated file package |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 364 | * @param pluginConfig plugin configurations |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 365 | * @throws IOException when fails to append contents |
| 366 | */ |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 367 | private static void appendContents(File file, String fileName, int genType, List<String> importsList, String pkg, |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 368 | YangPluginConfig pluginConfig) |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 369 | throws IOException { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 370 | |
| 371 | String pkgString = parsePackageString(pkg, importsList); |
| 372 | |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 373 | switch (genType) { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 374 | case IMPL_CLASS_MASK: |
| 375 | write(file, fileName, genType, IMPL_CLASS, pluginConfig); |
| 376 | break; |
| 377 | case BUILDER_INTERFACE_MASK: |
| 378 | write(file, fileName, genType, BUILDER_INTERFACE, pluginConfig); |
| 379 | break; |
| 380 | case GENERATE_TYPEDEF_CLASS: |
| 381 | appendHeaderContents(file, pkgString, importsList); |
| 382 | write(file, fileName, genType, IMPL_CLASS, pluginConfig); |
| 383 | break; |
| 384 | case BUILDER_CLASS_MASK: |
| 385 | appendHeaderContents(file, pkgString, importsList); |
| 386 | write(file, fileName, genType, BUILDER_CLASS, pluginConfig); |
| 387 | break; |
| 388 | case GENERATE_UNION_CLASS: |
| 389 | appendHeaderContents(file, pkgString, importsList); |
| 390 | write(file, fileName, genType, IMPL_CLASS, pluginConfig); |
| 391 | break; |
| 392 | case GENERATE_ENUM_CLASS: |
| 393 | appendHeaderContents(file, pkgString, importsList); |
| 394 | write(file, fileName, genType, ENUM_CLASS, pluginConfig); |
| 395 | break; |
| 396 | default: |
| 397 | break; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * Removes base directory path from package and generates package string for file. |
| 403 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 404 | * @param javaPkg generated java package |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 405 | * @param importsList list of imports |
| 406 | * @return package string |
| 407 | */ |
| 408 | private static String parsePackageString(String javaPkg, List<String> importsList) { |
| 409 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 410 | javaPkg = parsePkg(getJavaPackageFromPackagePath(javaPkg)); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 411 | if (importsList != null) { |
| 412 | if (!importsList.isEmpty()) { |
| 413 | return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE; |
| 414 | } else { |
| 415 | return PACKAGE + SPACE + javaPkg + SEMI_COLAN; |
| 416 | } |
| 417 | } else { |
| 418 | return PACKAGE + SPACE + javaPkg + SEMI_COLAN; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Appends other contents to interface, builder and typedef classes. |
| 424 | * for example : ONOS copyright, imports and package. |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 425 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 426 | * @param file generated file |
| 427 | * @param pkg generated package |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 428 | * @param importsList list of imports |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 429 | * @throws IOException when fails to append contents |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 430 | */ |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 431 | private static void appendHeaderContents(File file, String pkg, List<String> importsList) |
| 432 | throws IOException { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 433 | |
| 434 | insertDataIntoJavaFile(file, CopyrightHeader.getCopyrightHeader()); |
| 435 | insertDataIntoJavaFile(file, pkg); |
| 436 | |
| 437 | /* |
| 438 | * TODO: add the file header using |
| 439 | * JavaCodeSnippetGen.getFileHeaderComment |
| 440 | */ |
| 441 | |
| 442 | if (importsList != null) { |
| 443 | insertDataIntoJavaFile(file, NEW_LINE); |
| 444 | for (String imports : importsList) { |
| 445 | insertDataIntoJavaFile(file, imports); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 451 | * Writes data to the specific generated file. |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 452 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 453 | * @param file generated file |
| 454 | * @param genType generated file type |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 455 | * @param javaDocType java doc type |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 456 | * @param curNode current YANG node |
| 457 | * @param fileName file name |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 458 | * @throws IOException when fails to write into a file |
| 459 | */ |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 460 | private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName) |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 461 | throws IOException { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 462 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 463 | YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig(); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 464 | if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 465 | if (!fileName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) { |
| 466 | insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName, false, pluginConfig)); |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 467 | insertDataIntoJavaFile(file, addComponentString()); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 468 | } else { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 469 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 470 | } |
| 471 | } else { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 472 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 473 | } |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 474 | insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode)); |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Writes data to the specific generated file. |
| 479 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 480 | * @param file generated file |
| 481 | * @param fileName file name |
| 482 | * @param genType generated file type |
| 483 | * @param javaDocType java doc type |
sangyun-han | f352f53 | 2016-05-30 19:33:27 +0900 | [diff] [blame] | 484 | * @param pluginConfig plugin configurations |
sangyun-han | 54cb832 | 2016-06-01 14:12:07 +0900 | [diff] [blame] | 485 | * @throws IOException when fails to write into a file |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 486 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 487 | private static void write(File file, String fileName, int genType, JavaDocType javaDocType, |
| 488 | YangPluginConfig pluginConfig) |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 489 | throws IOException { |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 490 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 491 | insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName)); |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 492 | } |
| 493 | |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 494 | /** |
| 495 | * Returns integer attribute for enum's class to get the values. |
| 496 | * |
| 497 | * @param className enum's class name |
| 498 | * @return enum's attribute |
| 499 | */ |
| 500 | public static String getEnumsValueAttribute(String className) { |
Bharat saraswal | 4aaab4d | 2016-05-17 14:19:38 +0530 | [diff] [blame] | 501 | return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) |
| 502 | + SEMI_COLAN + NEW_LINE; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 503 | } |
| 504 | |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 505 | /** |
| 506 | * Returns component string. |
| 507 | * |
| 508 | * @return component string |
| 509 | */ |
| 510 | public static String addComponentString() { |
| 511 | return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE |
| 512 | + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION; |
| 513 | } |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 514 | } |