Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 17 | package org.onosproject.yangutils.translator.tojava.utils; |
| 18 | |
| 19 | import java.util.List; |
| 20 | import java.util.SortedSet; |
| 21 | |
| 22 | import org.onosproject.yangutils.datamodel.YangType; |
| 23 | import org.onosproject.yangutils.translator.GeneratedFileType; |
| 24 | import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes; |
| 25 | import org.onosproject.yangutils.translator.tojava.ImportInfo; |
| 26 | import org.onosproject.yangutils.utils.UtilConstants; |
| 27 | |
| 28 | /** |
| 29 | * Utility class to generate the java snippet. |
| 30 | */ |
| 31 | public final class JavaCodeSnippetGen { |
| 32 | |
| 33 | /** |
| 34 | * Default constructor. |
| 35 | */ |
| 36 | private JavaCodeSnippetGen() { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the java file header comment. |
| 41 | * |
| 42 | * @return the java file header comment. |
| 43 | */ |
| 44 | public static String getFileHeaderComment() { |
| 45 | |
| 46 | /** |
| 47 | * TODO return the file header. |
| 48 | */ |
| 49 | return null; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * reorder the import list based on the ONOS import rules. |
| 54 | * |
| 55 | * @param importInfo the set of classes/interfaces to be imported. |
| 56 | * @return string of import info. |
| 57 | */ |
| 58 | public List<ImportInfo> sortImportOrder(SortedSet<ImportInfo> importInfo) { |
| 59 | /* TODO: reorder the import list based on the ONOS import rules. */ |
| 60 | return null; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get the textual java code information corresponding to the import list. |
| 65 | * |
| 66 | * @param importInfo sorted list of import info. |
| 67 | * @return the textual java code information corresponding to the import |
| 68 | * list. |
| 69 | */ |
| 70 | public static String getImportText(List<ImportInfo> importInfo) { |
| 71 | /* |
| 72 | * TODO: get the textual java code information corresponding to the |
| 73 | * import list |
| 74 | */ |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Based on the file type and the YANG name of the file, generate the class |
| 80 | * / interface definition start. |
| 81 | * |
| 82 | * @param genFileTypes type of file being generated. |
| 83 | * @param yangName YANG name. |
| 84 | * @return corresponding textual java code information. |
| 85 | */ |
| 86 | public static String getJavaClassDefStart(GeneratedFileType genFileTypes, String yangName) { |
| 87 | /* |
| 88 | * get the camel case name for java class / interface. |
| 89 | */ |
| 90 | yangName = JavaIdentifierSyntax.getCamelCase(yangName); |
| 91 | return ClassDefinitionGenerator.generateClassDefinition(genFileTypes, yangName); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get the textual java code for attribute definition in class. |
| 96 | * |
| 97 | * @param genFileTypes type of file being generated. |
| 98 | * @param yangName YANG name of the the attribute. |
| 99 | * @param type type of the the attribute. |
| 100 | * @return the textual java code for attribute definition in class. |
| 101 | */ |
| 102 | public static String getJavaAttributeInfo(GeneratedFileType genFileTypes, String yangName, YangType<?> type) { |
| 103 | yangName = JavaIdentifierSyntax.getCamelCase(yangName); |
| 104 | return UtilConstants.PRIVATE + UtilConstants.SPACE + type.getDataTypeName() + UtilConstants.SPACE + yangName |
| 105 | + UtilConstants.SEMI_COLAN; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Based on the file type and method type(s) and the YANG name of the |
| 110 | * method, generate the method definitions(s). |
| 111 | * |
| 112 | * @param genFileTypes type of file being generated |
| 113 | * @param yangName name if the attribute whose getter / setter is required. |
| 114 | * @param methodTypes getter and / or setter type of method indicator. |
| 115 | * @param returnType type return type of the method. |
| 116 | * @return based on the file type and method type(s) the method |
| 117 | * definitions(s). |
| 118 | */ |
| 119 | public static String getJavaMethodInfo(GeneratedFileType genFileTypes, String yangName, |
| 120 | GeneratedMethodTypes methodTypes, YangType<?> returnType) { |
| 121 | |
| 122 | yangName = JavaIdentifierSyntax.getCamelCase(yangName); |
| 123 | return MethodsGenerator.constructMethodInfo(genFileTypes, yangName, methodTypes, returnType); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Based on the file type and the YANG name of the file, generate the class |
| 128 | * / interface definition close. |
| 129 | * |
| 130 | * @param genFileTypes type of file being generated. |
| 131 | * @param yangName YANG name. |
| 132 | * @return corresponding textual java code information. |
| 133 | */ |
| 134 | public static String getJavaClassDefClose(GeneratedFileType genFileTypes, String yangName) { |
| 135 | |
| 136 | if (genFileTypes.equals(GeneratedFileType.INTERFACE)) { |
| 137 | |
| 138 | return UtilConstants.CLOSE_CURLY_BRACKET; |
| 139 | } else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) { |
| 140 | |
| 141 | return UtilConstants.CLOSE_CURLY_BRACKET; |
| 142 | } |
| 143 | return null; |
| 144 | } |
| 145 | |
| 146 | } |