blob: 4d6a475c3756fc504b10bc36c325d2cc7e892fe4 [file] [log] [blame]
Bharat saraswal870c56f2016-02-20 21:57:16 +05301/*
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
17package org.onosproject.yangutils.translator.tojava.utils;
18
Bharat saraswal870c56f2016-02-20 21:57:16 +053019import org.onosproject.yangutils.translator.GeneratedFileType;
Bharat saraswal870c56f2016-02-20 21:57:16 +053020import org.onosproject.yangutils.translator.tojava.ImportInfo;
21import org.onosproject.yangutils.utils.UtilConstants;
22
23/**
24 * Utility class to generate the java snippet.
25 */
26public final class JavaCodeSnippetGen {
27
28 /**
29 * Default constructor.
30 */
31 private JavaCodeSnippetGen() {
32 }
33
34 /**
35 * Get the java file header comment.
36 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053037 * @return the java file header comment
Bharat saraswal870c56f2016-02-20 21:57:16 +053038 */
39 public static String getFileHeaderComment() {
40
41 /**
42 * TODO return the file header.
43 */
44 return null;
45 }
46
47 /**
Bharat saraswal870c56f2016-02-20 21:57:16 +053048 * Get the textual java code information corresponding to the import list.
49 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053050 * @param importInfo import info
Bharat saraswal870c56f2016-02-20 21:57:16 +053051 * @return the textual java code information corresponding to the import
Vinod Kumar Sc4216002016-03-03 19:55:30 +053052 * list
Bharat saraswal870c56f2016-02-20 21:57:16 +053053 */
Bharat saraswal594bc6d2016-02-22 22:15:21 +053054 public static String getImportText(ImportInfo importInfo) {
55 return UtilConstants.IMPORT + importInfo.getPkgInfo() + UtilConstants.PERIOD + importInfo.getClassInfo()
Vinod Kumar Sc4216002016-03-03 19:55:30 +053056 + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE;
Bharat saraswal870c56f2016-02-20 21:57:16 +053057 }
58
59 /**
60 * Based on the file type and the YANG name of the file, generate the class
61 * / interface definition start.
62 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053063 * @param genFileTypes type of file being generated
64 * @param yangName YANG name
65 * @return corresponding textual java code information
Bharat saraswal870c56f2016-02-20 21:57:16 +053066 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +053067 public static String getJavaClassDefStart(int genFileTypes, String yangName) {
Bharat saraswal870c56f2016-02-20 21:57:16 +053068 /*
69 * get the camel case name for java class / interface.
70 */
71 yangName = JavaIdentifierSyntax.getCamelCase(yangName);
72 return ClassDefinitionGenerator.generateClassDefinition(genFileTypes, yangName);
73 }
74
75 /**
76 * Get the textual java code for attribute definition in class.
77 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +053078 * @param javaAttributeTypePkg Package of the attribute type
79 * @param javaAttributeType java attribute type
80 * @param javaAttributeName name of the attribute
81 * @return the textual java code for attribute definition in class
Bharat saraswal870c56f2016-02-20 21:57:16 +053082 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +053083 public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
84 String javaAttributeName) {
85
86 String attributeDefination = UtilConstants.PRIVATE
87 + UtilConstants.SPACE;
88
89 if (javaAttributeTypePkg != null) {
90 attributeDefination = attributeDefination
91 + javaAttributeTypePkg + ".";
Bharat saraswal594bc6d2016-02-22 22:15:21 +053092 }
Vinod Kumar Sc4216002016-03-03 19:55:30 +053093
94 attributeDefination = attributeDefination
95 + javaAttributeType
96 + UtilConstants.SPACE
97 + javaAttributeName
98 + UtilConstants.SEMI_COLAN;
99
100 return attributeDefination;
Bharat saraswal594bc6d2016-02-22 22:15:21 +0530101 }
102
103 /**
104 * Returns list attribute string.
105 *
106 * @param type attribute type
107 * @return list attribute string
108 */
109 public static String getListAttribute(String type) {
110 return UtilConstants.LIST + UtilConstants.DIAMOND_OPEN_BRACKET + type + UtilConstants.DIAMOND_CLOSE_BRACKET;
Bharat saraswal870c56f2016-02-20 21:57:16 +0530111 }
112
113 /**
Bharat saraswal870c56f2016-02-20 21:57:16 +0530114 * Based on the file type and the YANG name of the file, generate the class
115 * / interface definition close.
116 *
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530117 * @param genFileTypes type of file being generated
118 * @param yangName YANG name
119 * @return corresponding textual java code information
Bharat saraswal870c56f2016-02-20 21:57:16 +0530120 */
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530121 public static String getJavaClassDefClose(int genFileTypes, String yangName) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530122
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530123 if ((genFileTypes & GeneratedFileType.INTERFACE_MASK) != 0) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530124
125 return UtilConstants.CLOSE_CURLY_BRACKET;
Vinod Kumar Sc4216002016-03-03 19:55:30 +0530126 } else if ((genFileTypes & GeneratedFileType.BUILDER_CLASS_MASK) != 0) {
Bharat saraswal870c56f2016-02-20 21:57:16 +0530127
128 return UtilConstants.CLOSE_CURLY_BRACKET;
129 }
130 return null;
131 }
132
133}