Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-4070] Translator of YANG union.

Change-Id: I5216687b6ea7cb6baeb3ef8e905719468370a1f4
Showing 25 changed files with 786 additions and 313 deletions
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 +
17 +package org.onosproject.yangutils.datamodel;
18 +
19 +import java.util.List;
20 +
21 +/**
22 + * Represents the holder with type(s).
23 + */
24 +public interface HasType {
25 +
26 + /**
27 + * Returns type list.
28 + *
29 + * @return type list
30 + */
31 + List<YangType<?>> getTypeList();
32 +}
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.yangutils.datamodel; 16 package org.onosproject.yangutils.datamodel;
17 17
18 +import java.util.LinkedList;
19 +import java.util.List;
18 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 20 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
19 import org.onosproject.yangutils.parser.Parsable; 21 import org.onosproject.yangutils.parser.Parsable;
20 import org.onosproject.yangutils.utils.YangConstructType; 22 import org.onosproject.yangutils.utils.YangConstructType;
...@@ -48,10 +50,11 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -48,10 +50,11 @@ import org.onosproject.yangutils.utils.YangConstructType;
48 * | units | 7.3.3 | 0..1 |-string | 50 * | units | 7.3.3 | 0..1 |-string |
49 * +--------------+---------+-------------+------------------+ 51 * +--------------+---------+-------------+------------------+
50 */ 52 */
53 +
51 /** 54 /**
52 * Represents data model node to maintain information defined in YANG typedef. 55 * Represents data model node to maintain information defined in YANG typedef.
53 */ 56 */
54 -public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { 57 +public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, HasType {
55 58
56 /** 59 /**
57 * Default value in string, needs to be converted to the target object, 60 * Default value in string, needs to be converted to the target object,
...@@ -90,10 +93,17 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -90,10 +93,17 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
90 private String units; 93 private String units;
91 94
92 /** 95 /**
96 + * List of YANG type, for typedef it will have single type.
97 + * This is done to unify the code with union.
98 + */
99 + private List<YangType<?>> typeList;
100 +
101 + /**
93 * Creates a typedef node. 102 * Creates a typedef node.
94 */ 103 */
95 public YangTypeDef() { 104 public YangTypeDef() {
96 super(YangNodeType.TYPEDEF_NODE); 105 super(YangNodeType.TYPEDEF_NODE);
106 + typeList = new LinkedList<>();
97 } 107 }
98 108
99 /** 109 /**
...@@ -180,7 +190,10 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -180,7 +190,10 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
180 * @return the data type 190 * @return the data type
181 */ 191 */
182 public YangType<?> getTypeDefBaseType() { 192 public YangType<?> getTypeDefBaseType() {
183 - return dataType; 193 + if (!(getTypeList().isEmpty())) {
194 + return getTypeList().get(0);
195 + }
196 + return null;
184 } 197 }
185 198
186 /** 199 /**
...@@ -189,7 +202,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -189,7 +202,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
189 * @param dataType the data type 202 * @param dataType the data type
190 */ 203 */
191 public void setDataType(YangType<?> dataType) { 204 public void setDataType(YangType<?> dataType) {
192 - this.dataType = dataType; 205 + getTypeList().add(0, dataType);
193 } 206 }
194 207
195 /** 208 /**
...@@ -259,4 +272,9 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable { ...@@ -259,4 +272,9 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
259 public void setName(String name) { 272 public void setName(String name) {
260 this.name = name; 273 this.name = name;
261 } 274 }
275 +
276 + @Override
277 + public List<YangType<?>> getTypeList() {
278 + return typeList;
279 + }
262 } 280 }
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel;
18 18
19 import java.util.LinkedList; 19 import java.util.LinkedList;
20 import java.util.List; 20 import java.util.List;
21 -
22 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 21 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 import org.onosproject.yangutils.parser.Parsable; 22 import org.onosproject.yangutils.parser.Parsable;
24 import org.onosproject.yangutils.utils.YangConstructType; 23 import org.onosproject.yangutils.utils.YangConstructType;
...@@ -48,7 +47,7 @@ import org.onosproject.yangutils.utils.YangConstructType; ...@@ -48,7 +47,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
48 /** 47 /**
49 * Represents data model node to maintain information defined in YANG union. 48 * Represents data model node to maintain information defined in YANG union.
50 */ 49 */
51 -public class YangUnion extends YangNode implements Parsable { 50 +public class YangUnion extends YangNode implements Parsable, HasType {
52 51
53 // List of YANG type. 52 // List of YANG type.
54 private List<YangType<?>> typeList; 53 private List<YangType<?>> typeList;
...@@ -68,11 +67,7 @@ public class YangUnion extends YangNode implements Parsable { ...@@ -68,11 +67,7 @@ public class YangUnion extends YangNode implements Parsable {
68 childUnionNumber = 1; 67 childUnionNumber = 1;
69 } 68 }
70 69
71 - /** 70 + @Override
72 - * Returns list of YANG type.
73 - *
74 - * @return the list of YANG type
75 - */
76 public List<YangType<?>> getTypeList() { 71 public List<YangType<?>> getTypeList() {
77 return typeList; 72 return typeList;
78 } 73 }
...@@ -105,11 +100,11 @@ public class YangUnion extends YangNode implements Parsable { ...@@ -105,11 +100,11 @@ public class YangUnion extends YangNode implements Parsable {
105 } 100 }
106 101
107 /** 102 /**
108 - * Add YANG type to type list. 103 + * Adds YANG type to type list.
109 * 104 *
110 * @param yangType YANG type to be added to list 105 * @param yangType YANG type to be added to list
111 * @throws DataModelException union member type must not be one of the 106 * @throws DataModelException union member type must not be one of the
112 - * built-in types "empty" or "leafref" 107 + * built-in types "empty" or "leafref"
113 */ 108 */
114 public void addType(YangType<?> yangType) throws DataModelException { 109 public void addType(YangType<?> yangType) throws DataModelException {
115 if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) { 110 if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) {
...@@ -144,11 +139,21 @@ public class YangUnion extends YangNode implements Parsable { ...@@ -144,11 +139,21 @@ public class YangUnion extends YangNode implements Parsable {
144 return YangConstructType.UNION_DATA; 139 return YangConstructType.UNION_DATA;
145 } 140 }
146 141
142 + /**
143 + * Validates the data on entering the corresponding parse tree node.
144 + *
145 + * @throws DataModelException a violation of data model rules
146 + */
147 @Override 147 @Override
148 public void validateDataOnEntry() throws DataModelException { 148 public void validateDataOnEntry() throws DataModelException {
149 //TODO: implement the method. 149 //TODO: implement the method.
150 } 150 }
151 151
152 + /**
153 + * Validates the data on exiting the corresponding parse tree node.
154 + *
155 + * @throws DataModelException a violation of data model rules
156 + */
152 @Override 157 @Override
153 public void validateDataOnExit() throws DataModelException { 158 public void validateDataOnExit() throws DataModelException {
154 //TODO: implement the method. 159 //TODO: implement the method.
......
...@@ -25,6 +25,7 @@ import org.onosproject.yangutils.datamodel.YangList; ...@@ -25,6 +25,7 @@ import org.onosproject.yangutils.datamodel.YangList;
25 import org.onosproject.yangutils.datamodel.YangModule; 25 import org.onosproject.yangutils.datamodel.YangModule;
26 import org.onosproject.yangutils.datamodel.YangSubModule; 26 import org.onosproject.yangutils.datamodel.YangSubModule;
27 import org.onosproject.yangutils.datamodel.YangTypeDef; 27 import org.onosproject.yangutils.datamodel.YangTypeDef;
28 +import org.onosproject.yangutils.datamodel.YangUnion;
28 import org.onosproject.yangutils.datamodel.YangUses; 29 import org.onosproject.yangutils.datamodel.YangUses;
29 import org.onosproject.yangutils.datamodel.YangNotification; 30 import org.onosproject.yangutils.datamodel.YangNotification;
30 import org.onosproject.yangutils.datamodel.YangRpc; 31 import org.onosproject.yangutils.datamodel.YangRpc;
...@@ -40,6 +41,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList; ...@@ -40,6 +41,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
40 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; 41 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
41 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; 42 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
42 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; 43 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
44 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
43 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses; 45 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
44 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; 46 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
45 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc; 47 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
...@@ -53,7 +55,7 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; ...@@ -53,7 +55,7 @@ import org.onosproject.yangutils.translator.exception.TranslatorException;
53 public final class YangDataModelFactory { 55 public final class YangDataModelFactory {
54 56
55 /** 57 /**
56 - * Utility class, hence private to prevent creating objects. 58 + * Creates a YANG data model factory object.
57 */ 59 */
58 private YangDataModelFactory() { 60 private YangDataModelFactory() {
59 } 61 }
...@@ -224,7 +226,25 @@ public final class YangDataModelFactory { ...@@ -224,7 +226,25 @@ public final class YangDataModelFactory {
224 * Returns based on the target language generate the inherited data model node. 226 * Returns based on the target language generate the inherited data model node.
225 * 227 *
226 * @param targetLanguage target language in which YANG mapping needs to be 228 * @param targetLanguage target language in which YANG mapping needs to be
227 - * generated 229 + * generated
230 + * @return the corresponding inherited node based on the target language
231 + */
232 + public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
233 + switch (targetLanguage) {
234 + case JAVA_GENERATION: {
235 + return new YangJavaUnion();
236 + }
237 + default: {
238 + throw new TranslatorException("Only YANG to Java is supported.");
239 + }
240 + }
241 + }
242 +
243 + /**
244 + * Returns based on the target language generate the inherited data model node.
245 + *
246 + * @param targetLanguage target language in which YANG mapping needs to be
247 + * generated
228 * @return the corresponding inherited node based on the target language 248 * @return the corresponding inherited node based on the target language
229 */ 249 */
230 public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) { 250 public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
......
...@@ -146,7 +146,7 @@ public final class TypeListener { ...@@ -146,7 +146,7 @@ public final class TypeListener {
146 * in resolution list. 146 * in resolution list.
147 */ 147 */
148 if (yangDataTypes == YangDataTypes.DERIVED) { 148 if (yangDataTypes == YangDataTypes.DERIVED) {
149 - // Parent YANG node of leaf to be added in resolution information. 149 + // Parent YANG node of leaf list to be added in resolution information.
150 Parsable leafListData = listener.getParsedDataStack().pop(); 150 Parsable leafListData = listener.getParsedDataStack().pop();
151 Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek(); 151 Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
152 listener.getParsedDataStack().push(leafListData); 152 listener.getParsedDataStack().push(leafListData);
...@@ -181,6 +181,26 @@ public final class TypeListener { ...@@ -181,6 +181,26 @@ public final class TypeListener {
181 parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); 181 parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
182 throw parserException; 182 throw parserException;
183 } 183 }
184 +
185 + /*
186 + * If data type is derived, resolution information to be added
187 + * in resolution list.
188 + */
189 + if (yangDataTypes == YangDataTypes.DERIVED) {
190 +
191 + // Get the prefix information
192 + String prefix = ((YangType<?>) type).getPrefix();
193 +
194 + // Create empty derived info and attach it to type extended info.
195 + YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
196 + ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
197 +
198 + // Add resolution information to the list
199 + YangResolutionInfo resolutionInfo =
200 + new YangResolutionInfo<YangType>(type, (YangNode) unionNode, errorLine, errorPosition);
201 + addToResolutionList(resolutionInfo, ctx);
202 + }
203 +
184 break; 204 break;
185 case TYPEDEF_DATA: 205 case TYPEDEF_DATA:
186 /* Prepare the base type info and set in derived type */ 206 /* Prepare the base type info and set in derived type */
...@@ -244,7 +264,7 @@ public final class TypeListener { ...@@ -244,7 +264,7 @@ public final class TypeListener {
244 * @param ctx context object of the grammar rule 264 * @param ctx context object of the grammar rule
245 */ 265 */
246 private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo, 266 private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo,
247 - GeneratedYangParser.TypeStatementContext ctx) { 267 + GeneratedYangParser.TypeStatementContext ctx) {
248 try { 268 try {
249 addResolutionInfo(resolutionInfo); 269 addResolutionInfo(resolutionInfo);
250 } catch (DataModelException e) { 270 } catch (DataModelException e) {
......
...@@ -53,6 +53,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; ...@@ -53,6 +53,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
53 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 53 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
54 import org.onosproject.yangutils.utils.YangConstructType; 54 import org.onosproject.yangutils.utils.YangConstructType;
55 55
56 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
57 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUnionNode;
56 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 58 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
57 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; 59 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
58 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; 60 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
...@@ -96,7 +98,7 @@ public final class UnionListener { ...@@ -96,7 +98,7 @@ public final class UnionListener {
96 checkStackIsNotEmpty(listener, MISSING_HOLDER, UNION_DATA, "", ENTRY); 98 checkStackIsNotEmpty(listener, MISSING_HOLDER, UNION_DATA, "", ENTRY);
97 99
98 if (listener.getParsedDataStack().peek() instanceof YangType) { 100 if (listener.getParsedDataStack().peek() instanceof YangType) {
99 - YangUnion unionNode = new YangUnion(); 101 + YangUnion unionNode = getYangUnionNode(JAVA_GENERATION);
100 Parsable typeData = listener.getParsedDataStack().pop(); 102 Parsable typeData = listener.getParsedDataStack().pop();
101 103
102 // Check for stack to be non empty. 104 // Check for stack to be non empty.
......
...@@ -22,12 +22,6 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -22,12 +22,6 @@ package org.onosproject.yangutils.translator.tojava;
22 public final class GeneratedJavaFileType { 22 public final class GeneratedJavaFileType {
23 23
24 /** 24 /**
25 - * Creates an instance of generate java file type.
26 - */
27 - private GeneratedJavaFileType() {
28 - }
29 -
30 - /**
31 * Interface file. 25 * Interface file.
32 */ 26 */
33 public static final int INTERFACE_MASK = 1; 27 public static final int INTERFACE_MASK = 1;
...@@ -56,4 +50,15 @@ public final class GeneratedJavaFileType { ...@@ -56,4 +50,15 @@ public final class GeneratedJavaFileType {
56 * Java class corresponding to typedef. 50 * Java class corresponding to typedef.
57 */ 51 */
58 public static final int GENERATE_TYPEDEF_CLASS = 16; 52 public static final int GENERATE_TYPEDEF_CLASS = 16;
53 +
54 + /**
55 + * Java class corresponding to union.
56 + */
57 + public static final int GENERATE_UNION_CLASS = 32;
58 +
59 + /**
60 + * Creates an instance of generate java file type.
61 + */
62 + private GeneratedJavaFileType() {
63 + }
59 } 64 }
......
...@@ -22,53 +22,68 @@ package org.onosproject.yangutils.translator.tojava; ...@@ -22,53 +22,68 @@ package org.onosproject.yangutils.translator.tojava;
22 public final class GeneratedTempFileType { 22 public final class GeneratedTempFileType {
23 23
24 /** 24 /**
25 - * Creates an instance of generated temp file type. 25 + * Attributes definition temporary file.
26 - */
27 - private GeneratedTempFileType() {
28 - }
29 -
30 - /**
31 - * attributes definition temporary file.
32 */ 26 */
33 public static final int ATTRIBUTES_MASK = 1; 27 public static final int ATTRIBUTES_MASK = 1;
34 28
35 /** 29 /**
36 - * getter methods for interface. 30 + * Getter methods for interface.
37 */ 31 */
38 public static final int GETTER_FOR_INTERFACE_MASK = 2; 32 public static final int GETTER_FOR_INTERFACE_MASK = 2;
39 33
40 /** 34 /**
41 - * getter methods for class. 35 + * Getter methods for class.
42 */ 36 */
43 public static final int GETTER_FOR_CLASS_MASK = 4; 37 public static final int GETTER_FOR_CLASS_MASK = 4;
44 38
45 /** 39 /**
46 - * setter methods for interface. 40 + * Setter methods for interface.
47 */ 41 */
48 public static final int SETTER_FOR_INTERFACE_MASK = 8; 42 public static final int SETTER_FOR_INTERFACE_MASK = 8;
49 43
50 /** 44 /**
51 - * setter methods for class. 45 + * Setter methods for class.
52 */ 46 */
53 public static final int SETTER_FOR_CLASS_MASK = 16; 47 public static final int SETTER_FOR_CLASS_MASK = 16;
54 48
55 /** 49 /**
56 - * constructor method of class. 50 + * Constructor method of class.
57 */ 51 */
58 public static final int CONSTRUCTOR_IMPL_MASK = 32; 52 public static final int CONSTRUCTOR_IMPL_MASK = 32;
59 53
60 /** 54 /**
61 - * hash code implementation of class. 55 + * Hash code implementation of class.
62 */ 56 */
63 public static final int HASH_CODE_IMPL_MASK = 64; 57 public static final int HASH_CODE_IMPL_MASK = 64;
64 58
65 /** 59 /**
66 - * equals implementation of class. 60 + * Equals implementation of class.
67 */ 61 */
68 public static final int EQUALS_IMPL_MASK = 128; 62 public static final int EQUALS_IMPL_MASK = 128;
69 63
70 /** 64 /**
71 - * to string implementation of class. 65 + * To string implementation of class.
72 */ 66 */
73 public static final int TO_STRING_IMPL_MASK = 256; 67 public static final int TO_STRING_IMPL_MASK = 256;
68 +
69 + /**
70 + * Of string implementation of class.
71 + */
72 + public static final int OF_STRING_IMPL_MASK = 512;
73 +
74 + /**
75 + * Constructor for type class like typedef, union.
76 + */
77 + public static final int CONSTRUCTOR_FOR_TYPE_MASK = 1024;
78 +
79 + /**
80 + * From string implementation of class.
81 + */
82 + public static final int UNION_FROM_STRING_IMPL_MASK = 2048;
83 +
84 + /**
85 + * Creates an instance of generated temp file type.
86 + */
87 + private GeneratedTempFileType() {
88 + }
74 } 89 }
......
...@@ -21,8 +21,9 @@ import org.onosproject.yangutils.datamodel.YangType; ...@@ -21,8 +21,9 @@ import org.onosproject.yangutils.datamodel.YangType;
21 import org.onosproject.yangutils.translator.exception.TranslatorException; 21 import org.onosproject.yangutils.translator.exception.TranslatorException;
22 22
23 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; 23 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList;
24 +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
25 +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfAttribute;
24 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; 26 import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
25 -import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfLeafAttribute;
26 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 27 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
27 28
28 /** 29 /**
...@@ -65,9 +66,9 @@ public final class JavaAttributeInfo { ...@@ -65,9 +66,9 @@ public final class JavaAttributeInfo {
65 /** 66 /**
66 * Creates object of java attribute info. 67 * Creates object of java attribute info.
67 * 68 *
68 - * @param attrType YANG type 69 + * @param attrType YANG type
69 - * @param name attribute name 70 + * @param name attribute name
70 - * @param isListAttr is list attribute 71 + * @param isListAttr is list attribute
71 * @param isQualifiedName is qualified name 72 * @param isQualifiedName is qualified name
72 */ 73 */
73 public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) { 74 public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) {
...@@ -78,6 +79,51 @@ public final class JavaAttributeInfo { ...@@ -78,6 +79,51 @@ public final class JavaAttributeInfo {
78 } 79 }
79 80
80 /** 81 /**
82 + * Creates an attribute info object corresponding to the passed type's attribute
83 + * information and return it.
84 + *
85 + * @param curNode current data model node for which the java file is being generated
86 + * @param referredTypesAttrInfo attribute of referred type
87 + * @return JavaAttributeInfo attribute details required to add in temporary files
88 + */
89 + public static JavaAttributeInfo getFromStringAttributeInfo(YangNode curNode,
90 + JavaAttributeInfo referredTypesAttrInfo) {
91 +
92 + JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(referredTypesAttrInfo);
93 + /*
94 + * Create a new java attribute info with qualified information of
95 + * wrapper classes.
96 + */
97 + return getAttributeInfoForTheData(qualifiedInfoOfFromString, referredTypesAttrInfo.getAttributeName(),
98 + referredTypesAttrInfo.getAttributeType(), curNode, false);
99 + }
100 +
101 + /**
102 + * Creates an attribute info object corresponding to the passed type attribute
103 + * information and return it.
104 + *
105 + * @param curNode current data model node for which the java file is being
106 + * generated
107 + * @param attributeType leaf data type
108 + * @param attributeName leaf name
109 + * @param isListAttribute is the current added attribute needs to be a list
110 + * @return AttributeInfo attribute details required to add in temporary
111 + * files
112 + */
113 + public static JavaAttributeInfo getAttributeInfoOfType(YangNode curNode,
114 + YangType<?> attributeType, String attributeName,
115 + boolean isListAttribute) {
116 + /*
117 + * Get the import info corresponding to the attribute for import in
118 + * generated java files or qualified access
119 + */
120 + JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfAttribute(curNode,
121 + attributeType, attributeName, isListAttribute);
122 +
123 + return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
124 + }
125 +
126 + /**
81 * Returns the data type info of attribute. 127 * Returns the data type info of attribute.
82 * 128 *
83 * @return the data type info of attribute 129 * @return the data type info of attribute
...@@ -144,7 +190,7 @@ public final class JavaAttributeInfo { ...@@ -144,7 +190,7 @@ public final class JavaAttributeInfo {
144 * manner. 190 * manner.
145 * 191 *
146 * @return the if the added attribute has to be accessed in a fully 192 * @return the if the added attribute has to be accessed in a fully
147 - * qualified manner. 193 + * qualified manner.
148 */ 194 */
149 public boolean isQualifiedName() { 195 public boolean isQualifiedName() {
150 return isQualifiedName; 196 return isQualifiedName;
...@@ -155,7 +201,7 @@ public final class JavaAttributeInfo { ...@@ -155,7 +201,7 @@ public final class JavaAttributeInfo {
155 * manner. 201 * manner.
156 * 202 *
157 * @param isQualified if the added attribute has to be accessed in a fully 203 * @param isQualified if the added attribute has to be accessed in a fully
158 - * qualified manner 204 + * qualified manner
159 */ 205 */
160 public void setIsQualifiedAccess(boolean isQualified) { 206 public void setIsQualifiedAccess(boolean isQualified) {
161 isQualifiedName = isQualified; 207 isQualifiedName = isQualified;
...@@ -184,23 +230,23 @@ public final class JavaAttributeInfo { ...@@ -184,23 +230,23 @@ public final class JavaAttributeInfo {
184 * Creates an attribute info object corresponding to the passed leaf 230 * Creates an attribute info object corresponding to the passed leaf
185 * information and return it. 231 * information and return it.
186 * 232 *
187 - * @param curNode current data model node for which the java file is being 233 + * @param curNode current data model node for which the java file is being
188 - * generated 234 + * generated
189 - * @param attributeType leaf data type 235 + * @param attributeType leaf data type
190 - * @param attributeName leaf name 236 + * @param attributeName leaf name
191 * @param isListAttribute is the current added attribute needs to be a list 237 * @param isListAttribute is the current added attribute needs to be a list
192 * @return AttributeInfo attribute details required to add in temporary 238 * @return AttributeInfo attribute details required to add in temporary
193 - * files 239 + * files
194 */ 240 */
195 public static JavaAttributeInfo getAttributeInfoOfLeaf(YangNode curNode, 241 public static JavaAttributeInfo getAttributeInfoOfLeaf(YangNode curNode,
196 - YangType<?> attributeType, String attributeName, 242 + YangType<?> attributeType, String attributeName,
197 - boolean isListAttribute) { 243 + boolean isListAttribute) {
198 244
199 /* 245 /*
200 * Get the import info corresponding to the attribute for import in 246 * Get the import info corresponding to the attribute for import in
201 * generated java files or qualified access 247 * generated java files or qualified access
202 */ 248 */
203 - JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, 249 + JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfAttribute(curNode,
204 attributeType, attributeName, isListAttribute); 250 attributeType, attributeName, isListAttribute);
205 251
206 return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute); 252 return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
...@@ -210,12 +256,12 @@ public final class JavaAttributeInfo { ...@@ -210,12 +256,12 @@ public final class JavaAttributeInfo {
210 * Creates an attribute info object corresponding to a data model node and 256 * Creates an attribute info object corresponding to a data model node and
211 * return it. 257 * return it.
212 * 258 *
213 - * @param curNode current data model node for which the java code generation 259 + * @param curNode current data model node for which the java code generation
214 - * is being handled 260 + * is being handled
215 * @param parentNode parent node in which the current node is an attribute 261 * @param parentNode parent node in which the current node is an attribute
216 * @param isListNode is the current added attribute needs to be a list 262 * @param isListNode is the current added attribute needs to be a list
217 * @return AttributeInfo attribute details required to add in temporary 263 * @return AttributeInfo attribute details required to add in temporary
218 - * files 264 + * files
219 */ 265 */
220 public static JavaAttributeInfo getCurNodeAsAttributeInParent( 266 public static JavaAttributeInfo getCurNodeAsAttributeInParent(
221 YangNode curNode, YangNode parentNode, boolean isListNode) { 267 YangNode curNode, YangNode parentNode, boolean isListNode) {
...@@ -233,43 +279,18 @@ public final class JavaAttributeInfo { ...@@ -233,43 +279,18 @@ public final class JavaAttributeInfo {
233 } 279 }
234 280
235 /** 281 /**
236 - * Creates an attribute info object corresponding to the passed type def attribute
237 - * information and return it.
238 - *
239 - * @param curNode current data model node for which the java file is being
240 - * generated
241 - * @param attributeType leaf data type
242 - * @param attributeName leaf name
243 - * @param isListAttribute is the current added attribute needs to be a list
244 - * @return AttributeInfo attribute details required to add in temporary
245 - * files
246 - */
247 - public static JavaAttributeInfo getAttributeInfoOfTypeDef(YangNode curNode,
248 - YangType<?> attributeType, String attributeName,
249 - boolean isListAttribute) {
250 -
251 - /*
252 - * Get the import info corresponding to the attribute for import in
253 - * generated java files or qualified access
254 - */
255 - JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
256 - attributeType, attributeName, isListAttribute);
257 -
258 - return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
259 - }
260 -
261 - /**
262 * Returns java attribute info. 282 * Returns java attribute info.
263 * 283 *
264 - * @param importInfo java qualified type info 284 + * @param importInfo java qualified type info
265 - * @param attributeName attribute name 285 + * @param attributeName attribute name
266 - * @param attributeType attribute type 286 + * @param attributeType attribute type
267 - * @param curNode current YANG node 287 + * @param curNode current YANG node
268 * @param isListAttribute is list attribute 288 * @param isListAttribute is list attribute
269 * @return java attribute info. 289 * @return java attribute info.
270 */ 290 */
271 private static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName, 291 private static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName,
272 - YangType<?> attributeType, YangNode curNode, boolean isListAttribute) { 292 + YangType<?> attributeType, YangNode curNode,
293 + boolean isListAttribute) {
273 294
274 JavaAttributeInfo newAttr = new JavaAttributeInfo(); 295 JavaAttributeInfo newAttr = new JavaAttributeInfo();
275 newAttr.setImportInfo(importInfo); 296 newAttr.setImportInfo(importInfo);
......
...@@ -17,14 +17,15 @@ ...@@ -17,14 +17,15 @@
17 package org.onosproject.yangutils.translator.tojava; 17 package org.onosproject.yangutils.translator.tojava;
18 18
19 import java.util.Objects; 19 import java.util.Objects;
20 -
21 import org.onosproject.yangutils.datamodel.YangNode; 20 import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.datamodel.YangType; 21 import org.onosproject.yangutils.datamodel.YangType;
23 import org.onosproject.yangutils.translator.exception.TranslatorException; 22 import org.onosproject.yangutils.translator.exception.TranslatorException;
24 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; 23 import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
25 -
26 import com.google.common.base.MoreObjects; 24 import com.google.common.base.MoreObjects;
27 25
26 +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
27 +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
28 +
28 /** 29 /**
29 * Represents the information about individual imports in the generated file. 30 * Represents the information about individual imports in the generated file.
30 */ 31 */
...@@ -86,18 +87,18 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> ...@@ -86,18 +87,18 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
86 * Returns the import info for an attribute, which needs to be used for code 87 * Returns the import info for an attribute, which needs to be used for code
87 * generation for import or for qualified access. 88 * generation for import or for qualified access.
88 * 89 *
89 - * @param curNode current data model node for which the java file is being 90 + * @param curNode current data model node for which the java file is being
90 - * generated 91 + * generated
91 - * @param attrType type of attribute being added, it will be null, when the 92 + * @param attrType type of attribute being added, it will be null, when the
92 - * child class is added as an attribute 93 + * child class is added as an attribute
93 * @param attributeName name of the attribute being added, it will used in 94 * @param attributeName name of the attribute being added, it will used in
94 - * import info for child class 95 + * import info for child class
95 - * @param isListAttr is the added attribute going to be used as a list 96 + * @param isListAttr is the added attribute going to be used as a list
96 * @return return the import info for this attribute 97 * @return return the import info for this attribute
97 */ 98 */
98 - public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfLeafAttribute(YangNode curNode, 99 + public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfAttribute(YangNode curNode,
99 - YangType<?> attrType, String attributeName, 100 + YangType<?> attrType, String attributeName,
100 - boolean isListAttr) { 101 + boolean isListAttr) {
101 102
102 JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); 103 JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
103 104
...@@ -139,15 +140,15 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> ...@@ -139,15 +140,15 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
139 * Returns the import info for an attribute, which needs to be used for code 140 * Returns the import info for an attribute, which needs to be used for code
140 * generation for import or for qualified access. 141 * generation for import or for qualified access.
141 * 142 *
142 - * @param curNode current data model node for which the java file is being 143 + * @param curNode current data model node for which the java file is being
143 - * generated 144 + * generated
144 * @param attributeName name of the attribute being added, it will used in 145 * @param attributeName name of the attribute being added, it will used in
145 - * import info for child class 146 + * import info for child class
146 - * @param isListAttr is the added attribute going to be used as a list 147 + * @param isListAttr is the added attribute going to be used as a list
147 * @return return the import info for this attribute 148 * @return return the import info for this attribute
148 */ 149 */
149 public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfCurNode(YangNode curNode, 150 public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfCurNode(YangNode curNode,
150 - String attributeName, boolean isListAttr) { 151 + String attributeName, boolean isListAttr) {
151 152
152 JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo(); 153 JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
153 154
...@@ -168,16 +169,35 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> ...@@ -168,16 +169,35 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
168 } 169 }
169 170
170 /** 171 /**
172 + * Get the java qualified type information for the wrapper classes.
173 + *
174 + * @param referredTypesAttrInfo attribute of referred type
175 + * @return return the import info for this attribute
176 + */
177 + public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) {
178 + /*
179 + * Get the java qualified type information for the wrapper classes and
180 + * set it in new java attribute information.
181 + */
182 + JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo();
183 + qualifiedInfoOfFromString.setClassInfo(
184 + getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true));
185 + qualifiedInfoOfFromString.setPkgInfo(
186 + getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null));
187 + return qualifiedInfoOfFromString;
188 + }
189 +
190 + /**
171 * Returns if the attribute needs to be accessed in a qualified manner or not, 191 * Returns if the attribute needs to be accessed in a qualified manner or not,
172 * if it needs to be imported, then the same needs to be done. 192 * if it needs to be imported, then the same needs to be done.
173 * 193 *
174 - * @param curNode current cache of the data model node for which java file 194 + * @param curNode current cache of the data model node for which java file
175 - * is bing generated 195 + * is bing generated
176 * @param importInfo import info for the current attribute being added 196 * @param importInfo import info for the current attribute being added
177 * @return status of the qualified access to the attribute 197 * @return status of the qualified access to the attribute
178 */ 198 */
179 public static boolean getIsQualifiedAccessOrAddToImportList(YangNode curNode, 199 public static boolean getIsQualifiedAccessOrAddToImportList(YangNode curNode,
180 - JavaQualifiedTypeInfo importInfo) { 200 + JavaQualifiedTypeInfo importInfo) {
181 201
182 boolean isImportPkgEqualCurNodePkg; 202 boolean isImportPkgEqualCurNodePkg;
183 if (!(curNode instanceof HasJavaFileInfo)) { 203 if (!(curNode instanceof HasJavaFileInfo)) {
...@@ -229,10 +249,10 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> ...@@ -229,10 +249,10 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
229 * Checks if the import info is same as the package of the current generated 249 * Checks if the import info is same as the package of the current generated
230 * java file. 250 * java file.
231 * 251 *
232 - * @param curNode Java identifier of the current data model node 252 + * @param curNode Java identifier of the current data model node
233 * @param importInfo import info for an attribute 253 * @param importInfo import info for an attribute
234 * @return true if the import info is same as the current nodes package 254 * @return true if the import info is same as the current nodes package
235 - * false otherwise 255 + * false otherwise
236 */ 256 */
237 public static boolean isImportPkgEqualCurNodePkg( 257 public static boolean isImportPkgEqualCurNodePkg(
238 YangNode curNode, JavaQualifiedTypeInfo importInfo) { 258 YangNode curNode, JavaQualifiedTypeInfo importInfo) {
......
...@@ -16,12 +16,8 @@ ...@@ -16,12 +16,8 @@
16 package org.onosproject.yangutils.translator.tojava.javamodel; 16 package org.onosproject.yangutils.translator.tojava.javamodel;
17 17
18 import java.io.IOException; 18 import java.io.IOException;
19 -
20 import org.onosproject.yangutils.datamodel.YangTypeDef; 19 import org.onosproject.yangutils.datamodel.YangTypeDef;
21 import org.onosproject.yangutils.translator.exception.TranslatorException; 20 import org.onosproject.yangutils.translator.exception.TranslatorException;
22 -import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
23 -import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
24 -import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
25 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; 21 import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
26 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 22 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
27 import org.onosproject.yangutils.translator.tojava.JavaImportData; 23 import org.onosproject.yangutils.translator.tojava.JavaImportData;
...@@ -29,17 +25,12 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; ...@@ -29,17 +25,12 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
29 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; 25 import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
30 26
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 27 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
32 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 28 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType;
33 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
34 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
35 -import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
36 -import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
37 29
38 /** 30 /**
39 * Represents type define information extended to support java code generation. 31 * Represents type define information extended to support java code generation.
40 */ 32 */
41 -public class YangJavaTypeDef extends YangTypeDef 33 +public class YangJavaTypeDef extends YangTypeDef implements JavaCodeGeneratorInfo, JavaCodeGenerator {
42 - implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData, HasTempJavaCodeFragmentFiles {
43 34
44 /** 35 /**
45 * Contains the information of the java file being generated. 36 * Contains the information of the java file being generated.
...@@ -106,7 +97,7 @@ public class YangJavaTypeDef extends YangTypeDef ...@@ -106,7 +97,7 @@ public class YangJavaTypeDef extends YangTypeDef
106 * Sets the data of java imports to be included in generated file. 97 * Sets the data of java imports to be included in generated file.
107 * 98 *
108 * @param javaImportData data of java imports to be included in generated 99 * @param javaImportData data of java imports to be included in generated
109 - * file 100 + * file
110 */ 101 */
111 @Override 102 @Override
112 public void setJavaImportData(JavaImportData javaImportData) { 103 public void setJavaImportData(JavaImportData javaImportData) {
...@@ -142,23 +133,7 @@ public class YangJavaTypeDef extends YangTypeDef ...@@ -142,23 +133,7 @@ public class YangJavaTypeDef extends YangTypeDef
142 */ 133 */
143 @Override 134 @Override
144 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { 135 public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
145 - 136 + generateCodeOfType(this, yangPlugin, false);
146 - getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
147 - getJavaFileInfo().setPackage(getCurNodePackage(this));
148 -
149 - getJavaFileInfo().setPackageFilePath(
150 - getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
151 - getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
152 - String absloutePath = getAbsolutePackagePath(
153 - getJavaFileInfo().getBaseCodeGenPath(),
154 - getJavaFileInfo().getPackageFilePath());
155 -
156 - setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
157 - getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
158 - getJavaFileInfo().getJavaName()));
159 -
160 - getTempJavaCodeFragmentFiles().addTypeDefAttributeToTempFiles(this);
161 -
162 } 137 }
163 138
164 /** 139 /**
......
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.javamodel;
17 +
18 +import java.io.IOException;
19 +import org.onosproject.yangutils.datamodel.YangUnion;
20 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
21 +import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
22 +import org.onosproject.yangutils.translator.tojava.JavaImportData;
23 +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
24 +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
25 +
26 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
27 +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType;
28 +
29 +/**
30 + * Represents union information extended to support java code generation.
31 + */
32 +public class YangJavaUnion extends YangUnion implements JavaCodeGeneratorInfo, JavaCodeGenerator {
33 +
34 + /**
35 + * Contains the information of the java file being generated.
36 + */
37 + private JavaFileInfo javaFileInfo;
38 +
39 + /**
40 + * Contains information of the imports to be inserted in the java file
41 + * generated.
42 + */
43 + private JavaImportData javaImportData;
44 +
45 + /**
46 + * File handle to maintain temporary java code fragments as per the code
47 + * snippet types.
48 + */
49 + private TempJavaCodeFragmentFiles tempFileHandle;
50 +
51 + /**
52 + * Creates an instance of YANG java union.
53 + */
54 + public YangJavaUnion() {
55 + super();
56 + setJavaFileInfo(new JavaFileInfo());
57 + setJavaImportData(new JavaImportData());
58 + getJavaFileInfo().setGeneratedFileTypes(GENERATE_UNION_CLASS);
59 + }
60 +
61 + /**
62 + * Returns the generated java file information.
63 + *
64 + * @return generated java file information
65 + */
66 + @Override
67 + public JavaFileInfo getJavaFileInfo() {
68 + if (javaFileInfo == null) {
69 + throw new RuntimeException("Missing java info in java datamodel node");
70 + }
71 + return javaFileInfo;
72 + }
73 +
74 + /**
75 + * Sets the java file info object.
76 + *
77 + * @param javaInfo java file info object
78 + */
79 + @Override
80 + public void setJavaFileInfo(JavaFileInfo javaInfo) {
81 + javaFileInfo = javaInfo;
82 + }
83 +
84 + /**
85 + * Returns the data of java imports to be included in generated file.
86 + *
87 + * @return data of java imports to be included in generated file
88 + */
89 + @Override
90 + public JavaImportData getJavaImportData() {
91 + return javaImportData;
92 + }
93 +
94 + /**
95 + * Sets the data of java imports to be included in generated file.
96 + *
97 + * @param javaImportData data of java imports to be included in generated
98 + * file
99 + */
100 + @Override
101 + public void setJavaImportData(JavaImportData javaImportData) {
102 + this.javaImportData = javaImportData;
103 + }
104 +
105 + /**
106 + * Returns the temporary file handle.
107 + *
108 + * @return temporary file handle
109 + */
110 + @Override
111 + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
112 + if (tempFileHandle == null) {
113 + throw new RuntimeException("Missing temp file hand for current node "
114 + + getJavaFileInfo().getJavaName());
115 + }
116 + return tempFileHandle;
117 + }
118 +
119 + /**
120 + * Sets temporary file handle.
121 + *
122 + * @param fileHandle temporary file handle
123 + */
124 + @Override
125 + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
126 + tempFileHandle = fileHandle;
127 + }
128 +
129 + /**
130 + * Prepare the information for java code generation corresponding to YANG
131 + * union info.
132 + *
133 + * @param yangPlugin YANG plugin config
134 + * @throws IOException IO operations fails
135 + */
136 + @Override
137 + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
138 + generateCodeOfType(this, yangPlugin, false);
139 + }
140 +
141 + /**
142 + * Creates a java file using the YANG union info.
143 + *
144 + * @throws IOException IO operations fails
145 + */
146 + @Override
147 + public void generateCodeExit() throws IOException {
148 + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this);
149 + }
150 +}
...@@ -21,10 +21,12 @@ import org.onosproject.yangutils.datamodel.YangDerivedInfo; ...@@ -21,10 +21,12 @@ import org.onosproject.yangutils.datamodel.YangDerivedInfo;
21 import org.onosproject.yangutils.datamodel.YangNode; 21 import org.onosproject.yangutils.datamodel.YangNode;
22 import org.onosproject.yangutils.datamodel.YangType; 22 import org.onosproject.yangutils.datamodel.YangType;
23 import org.onosproject.yangutils.datamodel.YangTypeDef; 23 import org.onosproject.yangutils.datamodel.YangTypeDef;
24 +import org.onosproject.yangutils.datamodel.YangUnion;
24 import org.onosproject.yangutils.translator.exception.TranslatorException; 25 import org.onosproject.yangutils.translator.exception.TranslatorException;
25 import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; 26 import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
26 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 27 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
27 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; 28 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
29 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
28 30
29 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; 31 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
30 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; 32 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
...@@ -33,15 +35,23 @@ import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; ...@@ -33,15 +35,23 @@ import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
33 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; 35 import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
34 import static org.onosproject.yangutils.utils.UtilConstants.BYTE; 36 import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
35 import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; 37 import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
38 +import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
36 import static org.onosproject.yangutils.utils.UtilConstants.INT; 39 import static org.onosproject.yangutils.utils.UtilConstants.INT;
37 import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; 40 import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
38 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; 41 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
39 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; 42 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
40 import static org.onosproject.yangutils.utils.UtilConstants.LONG; 43 import static org.onosproject.yangutils.utils.UtilConstants.LONG;
41 import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; 44 import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
45 +import static org.onosproject.yangutils.utils.UtilConstants.NEW;
46 +import static org.onosproject.yangutils.utils.UtilConstants.OF;
47 +import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
48 +import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
49 +import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
50 +import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
42 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 51 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
43 import static org.onosproject.yangutils.utils.UtilConstants.SHORT; 52 import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
44 import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; 53 import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
54 +import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
45 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; 55 import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
46 56
47 /** 57 /**
...@@ -94,9 +104,56 @@ public final class AttributesJavaDataType { ...@@ -94,9 +104,56 @@ public final class AttributesJavaDataType {
94 } 104 }
95 105
96 /** 106 /**
107 + * Returns from string method parsed string.
108 + *
109 + * @param targetDataType target data type
110 + * @param yangType YANG type
111 + * @return parsed string
112 + */
113 + public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
114 +
115 + YangDataTypes type = yangType.getDataType();
116 +
117 + switch (type) {
118 + case INT8:
119 + return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
120 + case INT16:
121 + return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
122 + case INT32:
123 + return INTEGER_WRAPPER + PERIOD + PARSE_INT;
124 + case INT64:
125 + return LONG_WRAPPER + PERIOD + PARSE_LONG;
126 + case UINT8:
127 + return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
128 + case UINT16:
129 + return INTEGER_WRAPPER + PERIOD + PARSE_INT;
130 + case UINT32:
131 + return LONG_WRAPPER + PERIOD + PARSE_LONG;
132 + case UINT64:
133 + return NEW + SPACE + BIG_INTEGER;
134 + case DECIMAL64:
135 + //TODO: DECIMAL64.
136 + case STRING:
137 + return EMPTY_STRING;
138 + case BOOLEAN:
139 + return BOOLEAN_DATA_TYPE;
140 + case ENUMERATION:
141 + //TODO:ENUMERATION.
142 + case BITS:
143 + //TODO:BITS
144 + case BINARY:
145 + //TODO:BINARY
146 + case DERIVED:
147 + return targetDataType + PERIOD + OF;
148 + default:
149 + throw new TranslatorException("given data type is not supported.");
150 + }
151 + }
152 +
153 + /**
97 * Returns java import class. 154 * Returns java import class.
98 * 155 *
99 - * @param yangType YANG type 156 + * @param yangType YANG type
100 * @param isListAttr if the attribute need to be a list 157 * @param isListAttr if the attribute need to be a list
101 * @return java import class 158 * @return java import class
102 */ 159 */
...@@ -141,13 +198,14 @@ public final class AttributesJavaDataType { ...@@ -141,13 +198,14 @@ public final class AttributesJavaDataType {
141 case EMPTY: 198 case EMPTY:
142 return BOOLEAN_WRAPPER; 199 return BOOLEAN_WRAPPER;
143 case UNION: 200 case UNION:
144 - //TODO:UNION 201 + return getCaptialCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
202 + null));
145 case INSTANCE_IDENTIFIER: 203 case INSTANCE_IDENTIFIER:
146 //TODO:INSTANCE_IDENTIFIER 204 //TODO:INSTANCE_IDENTIFIER
147 case DERIVED: 205 case DERIVED:
148 return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); 206 return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
149 default: 207 default:
150 - throw new TranslatorException("given data type is not supported."); 208 + return null;
151 } 209 }
152 } else { 210 } else {
153 switch (type) { 211 switch (type) {
...@@ -170,7 +228,8 @@ public final class AttributesJavaDataType { ...@@ -170,7 +228,8 @@ public final class AttributesJavaDataType {
170 case EMPTY: 228 case EMPTY:
171 //TODO:EMPTY 229 //TODO:EMPTY
172 case UNION: 230 case UNION:
173 - //TODO:UNION 231 + return getCaptialCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
232 + null));
174 case INSTANCE_IDENTIFIER: 233 case INSTANCE_IDENTIFIER:
175 //TODO:INSTANCE_IDENTIFIER 234 //TODO:INSTANCE_IDENTIFIER
176 case DERIVED: 235 case DERIVED:
...@@ -184,9 +243,9 @@ public final class AttributesJavaDataType { ...@@ -184,9 +243,9 @@ public final class AttributesJavaDataType {
184 /** 243 /**
185 * Returns java import package. 244 * Returns java import package.
186 * 245 *
187 - * @param yangType YANG type 246 + * @param yangType YANG type
188 * @param isListAttr if the attribute is of list type 247 * @param isListAttr if the attribute is of list type
189 - * @param classInfo java import class info 248 + * @param classInfo java import class info
190 * @return java import package 249 * @return java import package
191 */ 250 */
192 public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) { 251 public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
...@@ -222,13 +281,13 @@ public final class AttributesJavaDataType { ...@@ -222,13 +281,13 @@ public final class AttributesJavaDataType {
222 case EMPTY: 281 case EMPTY:
223 //TODO:EMPTY 282 //TODO:EMPTY
224 case UNION: 283 case UNION:
225 - //TODO:UNION 284 + return getUnionPackage(yangType);
226 case INSTANCE_IDENTIFIER: 285 case INSTANCE_IDENTIFIER:
227 //TODO:INSTANCE_IDENTIFIER 286 //TODO:INSTANCE_IDENTIFIER
228 case DERIVED: 287 case DERIVED:
229 return getTypDefsPackage(yangType); 288 return getTypDefsPackage(yangType);
230 default: 289 default:
231 - throw new TranslatorException("given data type is not supported."); 290 + return null;
232 } 291 }
233 } else { 292 } else {
234 switch (type) { 293 switch (type) {
...@@ -251,7 +310,7 @@ public final class AttributesJavaDataType { ...@@ -251,7 +310,7 @@ public final class AttributesJavaDataType {
251 case EMPTY: 310 case EMPTY:
252 //TODO:EMPTY 311 //TODO:EMPTY
253 case UNION: 312 case UNION:
254 - //TODO:UNION 313 + return getUnionPackage(yangType);
255 case INSTANCE_IDENTIFIER: 314 case INSTANCE_IDENTIFIER:
256 //TODO:INSTANCE_IDENTIFIER 315 //TODO:INSTANCE_IDENTIFIER
257 case DERIVED: 316 case DERIVED:
...@@ -286,6 +345,25 @@ public final class AttributesJavaDataType { ...@@ -286,6 +345,25 @@ public final class AttributesJavaDataType {
286 } 345 }
287 346
288 /** 347 /**
348 + * Returns java package for union node.
349 + *
350 + * @param type YANG type
351 + * @return java package for union node
352 + */
353 + private static String getUnionPackage(YangType<?> type) {
354 +
355 + if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) {
356 + throw new TranslatorException("type should have been union.");
357 + }
358 +
359 + YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo();
360 + if (union.getJavaFileInfo().getPackage() == null) {
361 + return getPackageFromParent(union.getParent());
362 + }
363 + return union.getJavaFileInfo().getPackage();
364 + }
365 +
366 + /**
289 * Returns package from parent node. 367 * Returns package from parent node.
290 * 368 *
291 * @param parent parent YANG node 369 * @param parent parent YANG node
...@@ -293,7 +371,7 @@ public final class AttributesJavaDataType { ...@@ -293,7 +371,7 @@ public final class AttributesJavaDataType {
293 */ 371 */
294 private static String getPackageFromParent(YangNode parent) { 372 private static String getPackageFromParent(YangNode parent) {
295 if (!(parent instanceof HasJavaFileInfo)) { 373 if (!(parent instanceof HasJavaFileInfo)) {
296 - throw new TranslatorException("Invalid child node is being processed."); 374 + throw new TranslatorException("invalid child node is being processed.");
297 } 375 }
298 JavaFileInfo parentInfo = ((HasJavaFileInfo) parent).getJavaFileInfo(); 376 JavaFileInfo parentInfo = ((HasJavaFileInfo) parent).getJavaFileInfo();
299 return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase(); 377 return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
......
...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
19 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 19 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
20 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 20 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
21 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 21 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
22 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
22 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 23 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
23 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 24 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
24 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList; 25 import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
...@@ -54,7 +55,7 @@ public final class ClassDefinitionGenerator { ...@@ -54,7 +55,7 @@ public final class ClassDefinitionGenerator {
54 * / interface definition start. 55 * / interface definition start.
55 * 56 *
56 * @param genFileTypes generated file type 57 * @param genFileTypes generated file type
57 - * @param yangName class name 58 + * @param yangName class name
58 * @return class definition 59 * @return class definition
59 */ 60 */
60 public static String generateClassDefinition(int genFileTypes, String yangName) { 61 public static String generateClassDefinition(int genFileTypes, String yangName) {
...@@ -64,20 +65,17 @@ public final class ClassDefinitionGenerator { ...@@ -64,20 +65,17 @@ public final class ClassDefinitionGenerator {
64 * class / interface definition start. 65 * class / interface definition start.
65 */ 66 */
66 if ((genFileTypes & INTERFACE_MASK) != 0) { 67 if ((genFileTypes & INTERFACE_MASK) != 0) {
67 -
68 return getInterfaceDefinition(yangName); 68 return getInterfaceDefinition(yangName);
69 } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) { 69 } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) {
70 -
71 return getBuilderClassDefinition(yangName); 70 return getBuilderClassDefinition(yangName);
72 } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) { 71 } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) {
73 -
74 return getImplClassDefinition(yangName); 72 return getImplClassDefinition(yangName);
75 } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) { 73 } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) {
76 -
77 return getBuilderInterfaceDefinition(yangName); 74 return getBuilderInterfaceDefinition(yangName);
78 } else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) { 75 } else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) {
79 - 76 + return getTypeClassDefinition(yangName);
80 - return getTypeDefClassDefinition(yangName); 77 + } else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) {
78 + return getTypeClassDefinition(yangName);
81 } 79 }
82 return null; 80 return null;
83 } 81 }
...@@ -105,7 +103,7 @@ public final class ClassDefinitionGenerator { ...@@ -105,7 +103,7 @@ public final class ClassDefinitionGenerator {
105 * Returns builder interface file class definition. 103 * Returns builder interface file class definition.
106 * 104 *
107 * @param yangName java class name, corresponding to which the builder class 105 * @param yangName java class name, corresponding to which the builder class
108 - * is being generated 106 + * is being generated
109 * @return definition 107 * @return definition
110 */ 108 */
111 private static String getBuilderInterfaceDefinition(String yangName) { 109 private static String getBuilderInterfaceDefinition(String yangName) {
...@@ -135,12 +133,12 @@ public final class ClassDefinitionGenerator { ...@@ -135,12 +133,12 @@ public final class ClassDefinitionGenerator {
135 } 133 }
136 134
137 /** 135 /**
138 - * Returns typeDef file class definition. 136 + * Returns type file class definition.
139 * 137 *
140 * @param yangName file name 138 * @param yangName file name
141 * @return definition 139 * @return definition
142 */ 140 */
143 - private static String getTypeDefClassDefinition(String yangName) { 141 + private static String getTypeClassDefinition(String yangName) {
144 return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; 142 return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
145 } 143 }
146 } 144 }
......
...@@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils; ...@@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils;
19 import java.io.File; 19 import java.io.File;
20 import java.io.IOException; 20 import java.io.IOException;
21 import java.util.List; 21 import java.util.List;
22 -
23 import org.onosproject.yangutils.datamodel.YangNode; 22 import org.onosproject.yangutils.datamodel.YangNode;
24 import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; 23 import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
25 import org.onosproject.yangutils.translator.tojava.JavaFileInfo; 24 import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
...@@ -30,17 +29,21 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; ...@@ -30,17 +29,21 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; 29 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; 30 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
32 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; 31 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
32 +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; 33 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; 34 import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
35 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; 35 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
36 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
36 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; 37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
37 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; 38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
38 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; 39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
39 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; 40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
40 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; 41 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
42 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
41 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; 43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
42 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; 44 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
43 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; 45 import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
46 +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK;
44 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; 47 import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
45 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; 48 import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
46 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; 49 import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
...@@ -49,11 +52,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; ...@@ -49,11 +52,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
49 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; 52 import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
50 import static org.onosproject.yangutils.utils.UtilConstants.SLASH; 53 import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
51 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 54 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
52 -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
53 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; 55 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
54 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; 56 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
55 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; 57 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
56 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; 58 import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
59 +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
57 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; 60 import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
58 61
59 /** 62 /**
...@@ -70,10 +73,10 @@ public final class JavaFileGeneratorUtils { ...@@ -70,10 +73,10 @@ public final class JavaFileGeneratorUtils {
70 /** 73 /**
71 * Returns a file object for generated file. 74 * Returns a file object for generated file.
72 * 75 *
73 - * @param fileName file name 76 + * @param fileName file name
74 - * @param filePath file package path 77 + * @param filePath file package path
75 * @param extension file extension 78 * @param extension file extension
76 - * @param handle cached file handle 79 + * @param handle cached file handle
77 * @return file object 80 * @return file object
78 */ 81 */
79 public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) { 82 public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) {
...@@ -85,7 +88,7 @@ public final class JavaFileGeneratorUtils { ...@@ -85,7 +88,7 @@ public final class JavaFileGeneratorUtils {
85 * Returns data stored in temporary files. 88 * Returns data stored in temporary files.
86 * 89 *
87 * @param generatedTempFiles temporary file types 90 * @param generatedTempFiles temporary file types
88 - * @param curNode current YANG node 91 + * @param curNode current YANG node
89 * @return data stored in temporary files 92 * @return data stored in temporary files
90 * @throws IOException when failed to get the data from temporary file handle 93 * @throws IOException when failed to get the data from temporary file handle
91 */ 94 */
...@@ -121,6 +124,16 @@ public final class JavaFileGeneratorUtils { ...@@ -121,6 +124,16 @@ public final class JavaFileGeneratorUtils {
121 } else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { 124 } else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
122 return tempJavaCodeFragmentFiles 125 return tempJavaCodeFragmentFiles
123 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getToStringImplTempFileHandle()); 126 .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getToStringImplTempFileHandle());
127 + } else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
128 + return tempJavaCodeFragmentFiles
129 + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles
130 + .getConstructorForTypeTempFileHandle());
131 + } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
132 + return tempJavaCodeFragmentFiles
133 + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getOfStringImplTempFileHandle());
134 + } else if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) {
135 + return tempJavaCodeFragmentFiles
136 + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getUnionFromStringImplTempFileHandle());
124 } 137 }
125 return null; 138 return null;
126 } 139 }
...@@ -128,15 +141,15 @@ public final class JavaFileGeneratorUtils { ...@@ -128,15 +141,15 @@ public final class JavaFileGeneratorUtils {
128 /** 141 /**
129 * Initiates generation of file based on generated file type. 142 * Initiates generation of file based on generated file type.
130 * 143 *
131 - * @param file generated file 144 + * @param file generated file
132 * @param className generated file class name 145 * @param className generated file class name
133 - * @param type generated file type 146 + * @param type generated file type
134 - * @param imports imports for the file 147 + * @param imports imports for the file
135 - * @param pkg generated file package 148 + * @param pkg generated file package
136 * @throws IOException when fails to generate a file 149 * @throws IOException when fails to generate a file
137 */ 150 */
138 public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports, 151 public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports,
139 - String pkg) throws IOException { 152 + String pkg) throws IOException {
140 153
141 try { 154 try {
142 file.createNewFile(); 155 file.createNewFile();
...@@ -149,42 +162,41 @@ public final class JavaFileGeneratorUtils { ...@@ -149,42 +162,41 @@ public final class JavaFileGeneratorUtils {
149 /** 162 /**
150 * Appends all the contents into a generated java file. 163 * Appends all the contents into a generated java file.
151 * 164 *
152 - * @param file generated file 165 + * @param file generated file
153 - * @param fileName generated file name 166 + * @param fileName generated file name
154 - * @param type generated file type 167 + * @param type generated file type
155 - * @param pkg generated file package 168 + * @param pkg generated file package
156 * @param importsList list of java imports. 169 * @param importsList list of java imports.
157 * @throws IOException when fails to append contents 170 * @throws IOException when fails to append contents
158 */ 171 */
159 private static void appendContents(File file, String fileName, int type, List<String> importsList, 172 private static void appendContents(File file, String fileName, int type, List<String> importsList,
160 - String pkg) throws IOException { 173 + String pkg) throws IOException {
161 174
162 String pkgString = parsePackageString(pkg, importsList); 175 String pkgString = parsePackageString(pkg, importsList);
163 176
164 if ((type & IMPL_CLASS_MASK) != 0) { 177 if ((type & IMPL_CLASS_MASK) != 0) {
165 -
166 write(file, fileName, type, IMPL_CLASS); 178 write(file, fileName, type, IMPL_CLASS);
167 } else if ((type & BUILDER_INTERFACE_MASK) != 0) { 179 } else if ((type & BUILDER_INTERFACE_MASK) != 0) {
168 -
169 write(file, fileName, type, BUILDER_INTERFACE); 180 write(file, fileName, type, BUILDER_INTERFACE);
170 } else if ((type & GENERATE_TYPEDEF_CLASS) != 0) { 181 } else if ((type & GENERATE_TYPEDEF_CLASS) != 0) {
171 appendHeaderContents(file, pkgString, importsList); 182 appendHeaderContents(file, pkgString, importsList);
172 write(file, fileName, type, IMPL_CLASS); 183 write(file, fileName, type, IMPL_CLASS);
173 } else if ((type & INTERFACE_MASK) != 0) { 184 } else if ((type & INTERFACE_MASK) != 0) {
174 -
175 appendHeaderContents(file, pkgString, importsList); 185 appendHeaderContents(file, pkgString, importsList);
176 write(file, fileName, type, INTERFACE); 186 write(file, fileName, type, INTERFACE);
177 } else if ((type & BUILDER_CLASS_MASK) != 0) { 187 } else if ((type & BUILDER_CLASS_MASK) != 0) {
178 -
179 appendHeaderContents(file, pkgString, importsList); 188 appendHeaderContents(file, pkgString, importsList);
180 write(file, fileName, type, BUILDER_CLASS); 189 write(file, fileName, type, BUILDER_CLASS);
190 + } else if ((type & GENERATE_UNION_CLASS) != 0) {
191 + appendHeaderContents(file, pkgString, importsList);
192 + write(file, fileName, type, IMPL_CLASS);
181 } 193 }
182 } 194 }
183 195
184 /** 196 /**
185 * Removes base directory path from package and generates package string for file. 197 * Removes base directory path from package and generates package string for file.
186 * 198 *
187 - * @param javaPkg generated java package 199 + * @param javaPkg generated java package
188 * @param importsList list of imports 200 * @param importsList list of imports
189 * @return package string 201 * @return package string
190 */ 202 */
...@@ -208,10 +220,11 @@ public final class JavaFileGeneratorUtils { ...@@ -208,10 +220,11 @@ public final class JavaFileGeneratorUtils {
208 /** 220 /**
209 * Appends other contents to interface, builder and typedef classes. 221 * Appends other contents to interface, builder and typedef classes.
210 * for example : ONOS copyright, imports and package. 222 * for example : ONOS copyright, imports and package.
211 - * @param file generated file 223 + *
212 - * @param pkg generated package 224 + * @param file generated file
225 + * @param pkg generated package
213 * @param importsList list of imports 226 * @param importsList list of imports
214 - * @throws IOException when fails to append contents. 227 + * @throws IOException when fails to append contents
215 */ 228 */
216 private static void appendHeaderContents(File file, String pkg, List<String> importsList) throws IOException { 229 private static void appendHeaderContents(File file, String pkg, List<String> importsList) throws IOException {
217 230
...@@ -234,15 +247,14 @@ public final class JavaFileGeneratorUtils { ...@@ -234,15 +247,14 @@ public final class JavaFileGeneratorUtils {
234 /** 247 /**
235 * Writes data to the specific generated file. 248 * Writes data to the specific generated file.
236 * 249 *
237 - * @param file generated file 250 + * @param file generated file
238 - * @param fileName file name 251 + * @param fileName file name
239 - * @param genType generated file type 252 + * @param genType generated file type
240 * @param javaDocType java doc type 253 * @param javaDocType java doc type
241 * @throws IOException when fails to write into a file 254 * @throws IOException when fails to write into a file
242 */ 255 */
243 private static void write(File file, String fileName, int genType, JavaDocType javaDocType) 256 private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
244 throws IOException { 257 throws IOException {
245 -
246 insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false)); 258 insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
247 insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); 259 insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName));
248 } 260 }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 package org.onosproject.yangutils.translator.tojava.utils; 17 package org.onosproject.yangutils.translator.tojava.utils;
18 18
19 import java.io.IOException; 19 import java.io.IOException;
20 - 20 +import org.onosproject.yangutils.datamodel.HasType;
21 import org.onosproject.yangutils.datamodel.YangAugment; 21 import org.onosproject.yangutils.datamodel.YangAugment;
22 import org.onosproject.yangutils.datamodel.YangCase; 22 import org.onosproject.yangutils.datamodel.YangCase;
23 import org.onosproject.yangutils.datamodel.YangChoice; 23 import org.onosproject.yangutils.datamodel.YangChoice;
...@@ -54,7 +54,7 @@ public final class YangJavaModelUtils { ...@@ -54,7 +54,7 @@ public final class YangJavaModelUtils {
54 * Updates YANG java file package information. 54 * Updates YANG java file package information.
55 * 55 *
56 * @param javaCodeGeneratorInfo YANG java file info node 56 * @param javaCodeGeneratorInfo YANG java file info node
57 - * @param yangPlugin YANG plugin config 57 + * @param yangPlugin YANG plugin config
58 * @throws IOException IO operations fails 58 * @throws IOException IO operations fails
59 */ 59 */
60 private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin) 60 private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
...@@ -72,11 +72,11 @@ public final class YangJavaModelUtils { ...@@ -72,11 +72,11 @@ public final class YangJavaModelUtils {
72 * Updates YANG java file package information for specified package. 72 * Updates YANG java file package information for specified package.
73 * 73 *
74 * @param javaCodeGeneratorInfo YANG java file info node 74 * @param javaCodeGeneratorInfo YANG java file info node
75 - * @param yangPlugin YANG plugin config 75 + * @param yangPlugin YANG plugin config
76 * @throws IOException IO operations fails 76 * @throws IOException IO operations fails
77 */ 77 */
78 private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin, 78 private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
79 - String pkg) 79 + String pkg)
80 throws IOException { 80 throws IOException {
81 javaCodeGeneratorInfo.getJavaFileInfo() 81 javaCodeGeneratorInfo.getJavaFileInfo()
82 .setJavaName(getCaptialCase( 82 .setJavaName(getCaptialCase(
...@@ -113,9 +113,11 @@ public final class YangJavaModelUtils { ...@@ -113,9 +113,11 @@ public final class YangJavaModelUtils {
113 if (javaCodeGeneratorInfo instanceof YangLeavesHolder) { 113 if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
114 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() 114 javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
115 .addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo); 115 .addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
116 + } else if (javaCodeGeneratorInfo instanceof HasType) {
117 + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
118 + .addTypeInfoToTempFiles((HasType) javaCodeGeneratorInfo);
116 } else { 119 } else {
117 - // TODO: either write a util for ENUM and UNION or, call the 120 + //TODO throw exception
118 - // corresponding implementation in ENUM and UNION
119 } 121 }
120 } 122 }
121 123
...@@ -123,7 +125,7 @@ public final class YangJavaModelUtils { ...@@ -123,7 +125,7 @@ public final class YangJavaModelUtils {
123 * Process generate code entry of YANG node. 125 * Process generate code entry of YANG node.
124 * 126 *
125 * @param javaCodeGeneratorInfo YANG java file info node 127 * @param javaCodeGeneratorInfo YANG java file info node
126 - * @param codeGenDir code generation directory 128 + * @param codeGenDir code generation directory
127 * @throws IOException IO operations fails 129 * @throws IOException IO operations fails
128 */ 130 */
129 private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir) 131 private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir)
...@@ -140,12 +142,12 @@ public final class YangJavaModelUtils { ...@@ -140,12 +142,12 @@ public final class YangJavaModelUtils {
140 * Process generate code entry of YANG node. 142 * Process generate code entry of YANG node.
141 * 143 *
142 * @param javaCodeGeneratorInfo YANG java file info node 144 * @param javaCodeGeneratorInfo YANG java file info node
143 - * @param yangPlugin YANG plugin config 145 + * @param yangPlugin YANG plugin config
144 - * @param isMultiInstance flag to indicate whether it's a list 146 + * @param isMultiInstance flag to indicate whether it's a list
145 * @throws IOException IO operations fails 147 * @throws IOException IO operations fails
146 */ 148 */
147 public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin, 149 public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
148 - boolean isMultiInstance) throws IOException { 150 + boolean isMultiInstance) throws IOException {
149 if (!(javaCodeGeneratorInfo instanceof YangNode)) { 151 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
150 // TODO:throw exception 152 // TODO:throw exception
151 } 153 }
...@@ -172,15 +174,32 @@ public final class YangJavaModelUtils { ...@@ -172,15 +174,32 @@ public final class YangJavaModelUtils {
172 } 174 }
173 175
174 /** 176 /**
177 + * Process generate code entry of YANG type.
178 + *
179 + * @param javaCodeGeneratorInfo YANG java file info node
180 + * @param yangPlugin YANG plugin config
181 + * @param isMultiInstance flag to indicate whether it's a list
182 + * @throws IOException IO operations fails
183 + */
184 + public static void generateCodeOfType(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
185 + boolean isMultiInstance) throws IOException {
186 + if (!(javaCodeGeneratorInfo instanceof YangNode)) {
187 + // TODO:throw exception
188 + }
189 + updatePackageInfo(javaCodeGeneratorInfo, yangPlugin);
190 + generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
191 + }
192 +
193 + /**
175 * Process generate code entry of root node. 194 * Process generate code entry of root node.
176 * 195 *
177 * @param javaCodeGeneratorInfo YANG java file info node 196 * @param javaCodeGeneratorInfo YANG java file info node
178 - * @param yangPlugin YANG plugin config 197 + * @param yangPlugin YANG plugin config
179 - * @param rootPkg package of the root node 198 + * @param rootPkg package of the root node
180 * @throws IOException IO operations fails 199 * @throws IOException IO operations fails
181 */ 200 */
182 public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin, 201 public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
183 - String rootPkg) throws IOException { 202 + String rootPkg) throws IOException {
184 if (!(javaCodeGeneratorInfo instanceof YangNode)) { 203 if (!(javaCodeGeneratorInfo instanceof YangNode)) {
185 // TODO:throw exception 204 // TODO:throw exception
186 } 205 }
......
...@@ -34,18 +34,18 @@ public final class UtilConstants { ...@@ -34,18 +34,18 @@ public final class UtilConstants {
34 /** 34 /**
35 * JavaDocs for impl class. 35 * JavaDocs for impl class.
36 */ 36 */
37 - public static final String IMPL_CLASS_JAVA_DOC = " * Reperesents the implementation of "; 37 + public static final String IMPL_CLASS_JAVA_DOC = " * Represents the implementation of ";
38 38
39 /** 39 /**
40 * JavaDocs for builder class. 40 * JavaDocs for builder class.
41 */ 41 */
42 - public static final String BUILDER_CLASS_JAVA_DOC = " * Reperesents the builder implementation of "; 42 + public static final String BUILDER_CLASS_JAVA_DOC = " * Represents the builder implementation of ";
43 43
44 /** 44 /**
45 * JavaDocs for interface class. 45 * JavaDocs for interface class.
46 */ 46 */
47 - public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which Reperesents the" 47 + public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the"
48 - + " functionalities of "; 48 + + " functionality of ";
49 49
50 /** 50 /**
51 * JavaDocs for builder interface class. 51 * JavaDocs for builder interface class.
...@@ -148,6 +148,31 @@ public final class UtilConstants { ...@@ -148,6 +148,31 @@ public final class UtilConstants {
148 public static final String PERIOD = "."; 148 public static final String PERIOD = ".";
149 149
150 /** 150 /**
151 + * Static attribute for parse byte.
152 + */
153 + public static final String PARSE_BYTE = "parseByte";
154 +
155 + /**
156 + * Static attribute for parse short.
157 + */
158 + public static final String PARSE_SHORT = "parseShort";
159 +
160 + /**
161 + * Static attribute for parse int.
162 + */
163 + public static final String PARSE_INT = "parseInt";
164 +
165 + /**
166 + * Static attribute for parse long.
167 + */
168 + public static final String PARSE_LONG = "parseLong";
169 +
170 + /**
171 + * Static attribute for omit null value.
172 + */
173 + public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()";
174 +
175 + /**
151 * Static attribute for colan. 176 * Static attribute for colan.
152 */ 177 */
153 public static final String COLAN = ":"; 178 public static final String COLAN = ":";
...@@ -173,9 +198,9 @@ public final class UtilConstants { ...@@ -173,9 +198,9 @@ public final class UtilConstants {
173 public static final String SPACE = " "; 198 public static final String SPACE = " ";
174 199
175 /** 200 /**
176 - * Static attribute for tab. 201 + * Static attribute for input string.
177 */ 202 */
178 - public static final String TAB = "\t"; 203 + public static final String INPUT = "input";
179 204
180 /** 205 /**
181 * Static attribute for new line. 206 * Static attribute for new line.
...@@ -223,6 +248,11 @@ public final class UtilConstants { ...@@ -223,6 +248,11 @@ public final class UtilConstants {
223 public static final String ADD_STRING = "add"; 248 public static final String ADD_STRING = "add";
224 249
225 /** 250 /**
251 + * Static attribute for from syntax.
252 + */
253 + public static final String FROM_STRING_METHOD_NAME = "fromString";
254 +
255 + /**
226 * Static attribute for check not null syntax. 256 * Static attribute for check not null syntax.
227 */ 257 */
228 public static final String CHECK_NOT_NULL_STRING = "checkNotNull"; 258 public static final String CHECK_NOT_NULL_STRING = "checkNotNull";
...@@ -333,14 +363,14 @@ public final class UtilConstants { ...@@ -333,14 +363,14 @@ public final class UtilConstants {
333 public static final String DIAMOND_CLOSE_BRACKET = ">"; 363 public static final String DIAMOND_CLOSE_BRACKET = ">";
334 364
335 /** 365 /**
336 - * Static attribute for square open bracket syntax. 366 + * Static attribute for exception syntax.
337 */ 367 */
338 - public static final String SQUARE_OPEN_BRACKET = "["; 368 + public static final String EXCEPTION = "Exception";
339 369
340 /** 370 /**
341 - * Static attribute for square close bracket syntax. 371 + * Static attribute for exception variable syntax.
342 */ 372 */
343 - public static final String SQUARE_CLOSE_BRACKET = "]"; 373 + public static final String EXCEPTION_VAR = "e";
344 374
345 /** 375 /**
346 * Static attribute for open parenthesis syntax. 376 * Static attribute for open parenthesis syntax.
...@@ -348,6 +378,21 @@ public final class UtilConstants { ...@@ -348,6 +378,21 @@ public final class UtilConstants {
348 public static final String OPEN_PARENTHESIS = "("; 378 public static final String OPEN_PARENTHESIS = "(";
349 379
350 /** 380 /**
381 + * Static attribute for clear syntax.
382 + */
383 + public static final String CLEAR = "clear";
384 +
385 + /**
386 + * Static attribute for temp val syntax.
387 + */
388 + public static final String TMP_VAL = "tmpVal";
389 +
390 + /**
391 + * From string parameter name.
392 + */
393 + public static final String FROM_STRING_PARAM_NAME = "valInString";
394 +
395 + /**
351 * Static attribute for close parenthesis syntax. 396 * Static attribute for close parenthesis syntax.
352 */ 397 */
353 public static final String CLOSE_PARENTHESIS = ")"; 398 public static final String CLOSE_PARENTHESIS = ")";
...@@ -378,6 +423,21 @@ public final class UtilConstants { ...@@ -378,6 +423,21 @@ public final class UtilConstants {
378 public static final String FOUR_SPACE_INDENTATION = " "; 423 public static final String FOUR_SPACE_INDENTATION = " ";
379 424
380 /** 425 /**
426 + * Static attribute for not syntax.
427 + */
428 + public static final String NOT = "!";
429 +
430 + /**
431 + * Static attribute for try syntax.
432 + */
433 + public static final String TRY = "try";
434 +
435 + /**
436 + * Static attribute for catch syntax.
437 + */
438 + public static final String CATCH = "catch";
439 +
440 + /**
381 * Static attribute for eight space indentation. 441 * Static attribute for eight space indentation.
382 */ 442 */
383 public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION; 443 public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
...@@ -518,14 +578,9 @@ public final class UtilConstants { ...@@ -518,14 +578,9 @@ public final class UtilConstants {
518 public static final String LONG_WRAPPER = "Long"; 578 public static final String LONG_WRAPPER = "Long";
519 579
520 /** 580 /**
521 - * Float java built in wrapper type. 581 + * YangUint64 java built in wrapper type.
522 - */
523 - public static final String FLOAT_WRAPPER = "Float";
524 -
525 - /**
526 - * Double java built in wrapper type.
527 */ 582 */
528 - public static final String DOUBLE_WRAPPER = "Double"; 583 + public static final String YANG_UINT64 = "YangUint64";
529 584
530 /** 585 /**
531 * List of keywords in java, this is used for checking if the input does not contain these keywords. 586 * List of keywords in java, this is used for checking if the input does not contain these keywords.
...@@ -733,92 +788,12 @@ public final class UtilConstants { ...@@ -733,92 +788,12 @@ public final class UtilConstants {
733 public static final String AUGMENTED_INFO = "AugmentedInfo"; 788 public static final String AUGMENTED_INFO = "AugmentedInfo";
734 789
735 /** 790 /**
736 - * Static attribute for abstract collection.
737 - */
738 - public static final String ABSTRACT_COLLECTION = "AbstractCollection";
739 -
740 - /**
741 * Static attribute for list. 791 * Static attribute for list.
742 */ 792 */
743 public static final String LIST = "List"; 793 public static final String LIST = "List";
744 794
745 /** 795 /**
746 - * Static attribute for linked list.
747 - */
748 - public static final String LINKED_LIST = "LinkedList";
749 -
750 - /**
751 * Static attribute for array list. 796 * Static attribute for array list.
752 */ 797 */
753 public static final String ARRAY_LIST = "ArrayList"; 798 public static final String ARRAY_LIST = "ArrayList";
754 -
755 - /**
756 - * Static attribute for abstract list.
757 - */
758 - public static final String ABSTRACT_LIST = "AbstractList";
759 -
760 - /**
761 - * Static attribute for abstract sequential list.
762 - */
763 - public static final String ABSTRACT_SEQUENTAIL_LIST = "AbstractSequentialList";
764 -
765 - /**
766 - * Static attribute for set.
767 - */
768 - public static final String SET = "Set";
769 -
770 - /**
771 - * Static attribute for hash set.
772 - */
773 - public static final String HASH_SET = "HashSet";
774 -
775 - /**
776 - * Static attribute for abstract set.
777 - */
778 - public static final String ABSTRACT_SET = "AbstractSet";
779 -
780 - /**
781 - * Static attribute for linked has set.
782 - */
783 - public static final String LINKED_HASH_SET = "LinkedHashSet";
784 -
785 - /**
786 - * Static attribute for tree set.
787 - */
788 - public static final String TREE_SET = "TreeSet";
789 -
790 - /**
791 - * Static attribute for map.
792 - */
793 - public static final String MAP = "Map";
794 -
795 - /**
796 - * Static attribute for abstract map.
797 - */
798 - public static final String ABSTRACT_MAP = "AbstractMap";
799 -
800 - /**
801 - * Static attribute for hash map.
802 - */
803 - public static final String HASH_MAP = "HashMap";
804 -
805 - /**
806 - * Static attribute for tree map.
807 - */
808 - public static final String TREE_MAP = "TreeMap";
809 -
810 - /**
811 - * Static attribute for concurrent map.
812 - */
813 - public static final String CONCURRENT_MAP = "ConcurrentMap";
814 -
815 - /**
816 - * Static attribute for eventually consistent map.
817 - */
818 - public static final String EVENTUALLY_CONSISTENT_MAP = "EventuallyConsitentMap";
819 -
820 - /**
821 - * Static attribute for stack syntax.
822 - */
823 - public static final String STACK = "stack";
824 } 799 }
......
...@@ -23,8 +23,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_D ...@@ -23,8 +23,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_D
23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; 23 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; 24 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
25 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; 25 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
26 +import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
27 +import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
26 import static org.onosproject.yangutils.utils.UtilConstants.IMPL; 28 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
27 import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC; 29 import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC;
30 +import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
28 import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC; 31 import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
29 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD; 32 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
30 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN; 33 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
...@@ -45,6 +48,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.OF; ...@@ -45,6 +48,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.OF;
45 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC; 48 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
46 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; 49 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
47 import static org.onosproject.yangutils.utils.UtilConstants.SPACE; 50 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
51 +import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
48 import static org.onosproject.yangutils.utils.UtilConstants.VALUE; 52 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
49 53
50 /** 54 /**
...@@ -104,11 +108,6 @@ public final class JavaDocGen { ...@@ -104,11 +108,6 @@ public final class JavaDocGen {
104 TYPE_DEF_SETTER_METHOD, 108 TYPE_DEF_SETTER_METHOD,
105 109
106 /** 110 /**
107 - * For type def's constructor.
108 - */
109 - TYPE_DEF_CONSTRUCTOR,
110 -
111 - /**
112 * For of method. 111 * For of method.
113 */ 112 */
114 OF_METHOD, 113 OF_METHOD,
...@@ -124,6 +123,16 @@ public final class JavaDocGen { ...@@ -124,6 +123,16 @@ public final class JavaDocGen {
124 CONSTRUCTOR, 123 CONSTRUCTOR,
125 124
126 /** 125 /**
126 + * For union's from method.
127 + */
128 + UNION_FROM_METHOD,
129 +
130 + /**
131 + * For type constructor.
132 + */
133 + TYPE_CONSTRUCTOR,
134 +
135 + /**
127 * For build. 136 * For build.
128 */ 137 */
129 BUILD_METHOD 138 BUILD_METHOD
...@@ -132,8 +141,8 @@ public final class JavaDocGen { ...@@ -132,8 +141,8 @@ public final class JavaDocGen {
132 /** 141 /**
133 * Returns java docs. 142 * Returns java docs.
134 * 143 *
135 - * @param type java doc type 144 + * @param type java doc type
136 - * @param name name of the YangNode 145 + * @param name name of the YangNode
137 * @param isList is list attribute 146 * @param isList is list attribute
138 * @return javadocs. 147 * @return javadocs.
139 */ 148 */
...@@ -155,8 +164,6 @@ public final class JavaDocGen { ...@@ -155,8 +164,6 @@ public final class JavaDocGen {
155 javaDoc = generateForGetters(name, isList); 164 javaDoc = generateForGetters(name, isList);
156 } else if (type.equals(JavaDocType.TYPE_DEF_SETTER_METHOD)) { 165 } else if (type.equals(JavaDocType.TYPE_DEF_SETTER_METHOD)) {
157 javaDoc = generateForTypeDefSetter(name); 166 javaDoc = generateForTypeDefSetter(name);
158 - } else if (type.equals(JavaDocType.TYPE_DEF_CONSTRUCTOR)) {
159 - javaDoc = generateForTypeDefConstructor(name);
160 } else if (type.equals(JavaDocType.SETTER_METHOD)) { 167 } else if (type.equals(JavaDocType.SETTER_METHOD)) {
161 javaDoc = generateForSetters(name, isList); 168 javaDoc = generateForSetters(name, isList);
162 } else if (type.equals(JavaDocType.OF_METHOD)) { 169 } else if (type.equals(JavaDocType.OF_METHOD)) {
...@@ -165,6 +172,10 @@ public final class JavaDocGen { ...@@ -165,6 +172,10 @@ public final class JavaDocGen {
165 javaDoc = generateForDefaultConstructors(name); 172 javaDoc = generateForDefaultConstructors(name);
166 } else if (type.equals(JavaDocType.BUILD_METHOD)) { 173 } else if (type.equals(JavaDocType.BUILD_METHOD)) {
167 javaDoc = generateForBuild(name); 174 javaDoc = generateForBuild(name);
175 + } else if (type.equals(JavaDocType.TYPE_CONSTRUCTOR)) {
176 + javaDoc = generateForTypeConstructor(name);
177 + } else if (type.equals(JavaDocType.UNION_FROM_METHOD)) {
178 + javaDoc = generateForUnionFrom(name);
168 } else { 179 } else {
169 javaDoc = generateForConstructors(name); 180 javaDoc = generateForConstructors(name);
170 } 181 }
...@@ -175,7 +186,7 @@ public final class JavaDocGen { ...@@ -175,7 +186,7 @@ public final class JavaDocGen {
175 * Generate javaDocs for getter method. 186 * Generate javaDocs for getter method.
176 * 187 *
177 * @param attribute attribute 188 * @param attribute attribute
178 - * @param isList is list attribute 189 + * @param isList is list attribute
179 * @return javaDocs 190 * @return javaDocs
180 */ 191 */
181 private static String generateForGetters(String attribute, boolean isList) { 192 private static String generateForGetters(String attribute, boolean isList) {
...@@ -198,7 +209,7 @@ public final class JavaDocGen { ...@@ -198,7 +209,7 @@ public final class JavaDocGen {
198 * Generates javaDocs for setter method. 209 * Generates javaDocs for setter method.
199 * 210 *
200 * @param attribute attribute 211 * @param attribute attribute
201 - * @param isList is list attribute 212 + * @param isList is list attribute
202 * @return javaDocs 213 * @return javaDocs
203 */ 214 */
204 private static String generateForSetters(String attribute, boolean isList) { 215 private static String generateForSetters(String attribute, boolean isList) {
...@@ -232,6 +243,22 @@ public final class JavaDocGen { ...@@ -232,6 +243,22 @@ public final class JavaDocGen {
232 } 243 }
233 244
234 /** 245 /**
246 + * Generates javaDocs for from method.
247 + *
248 + * @param attribute attribute
249 + * @return javaDocs
250 + */
251 + private static String generateForUnionFrom(String attribute) {
252 +
253 + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
254 + + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD
255 + + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
256 + + FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD + NEW_LINE
257 + + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
258 + + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
259 + }
260 +
261 + /**
235 * Generates javaDocs for typedef setter method. 262 * Generates javaDocs for typedef setter method.
236 * 263 *
237 * @param attribute attribute 264 * @param attribute attribute
...@@ -347,4 +374,18 @@ public final class JavaDocGen { ...@@ -347,4 +374,18 @@ public final class JavaDocGen {
347 + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION 374 + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
348 + JAVA_DOC_END_LINE; 375 + JAVA_DOC_END_LINE;
349 } 376 }
377 +
378 + /**
379 + * Generates javaDocs for type constructor.
380 + *
381 + * @param attribute attribute string
382 + * @return javaDocs for type constructor
383 + */
384 + private static String generateForTypeConstructor(String attribute) {
385 +
386 + return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
387 + + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
388 + + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
389 + + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
390 + }
350 } 391 }
......
...@@ -43,7 +43,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator ...@@ -43,7 +43,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
43 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForInterface; 43 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForInterface;
44 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForTypeDefClass; 44 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForTypeDefClass;
45 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; 45 import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
46 -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeDefConstructor; 46 +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
47 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; 47 import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
48 import static org.onosproject.yangutils.utils.UtilConstants.BUILD; 48 import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
49 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; 49 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
...@@ -113,12 +113,12 @@ public final class MethodsGeneratorTest { ...@@ -113,12 +113,12 @@ public final class MethodsGeneratorTest {
113 } 113 }
114 114
115 /** 115 /**
116 - * Unit test case for checking the parse builder and typedef constructor. 116 + * Unit test case for checking the parse builder and type constructor.
117 */ 117 */
118 @Test 118 @Test
119 - public void getTypeDefConstructorTest() { 119 + public void getTypeConstructorTest() {
120 JavaAttributeInfo testAttr = getTestAttribute(); 120 JavaAttributeInfo testAttr = getTestAttribute();
121 - String test = getTypeDefConstructor(testAttr, CLASS_NAME); 121 + String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME);
122 assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS))); 122 assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
123 } 123 }
124 124
...@@ -178,7 +178,7 @@ public final class MethodsGeneratorTest { ...@@ -178,7 +178,7 @@ public final class MethodsGeneratorTest {
178 } 178 }
179 179
180 /** 180 /**
181 - * Test case for quals method. 181 + * Test case for equals method.
182 */ 182 */
183 @Test 183 @Test
184 public void getEqualsMethodTest() { 184 public void getEqualsMethodTest() {
......
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 +
17 +package org.onosproject.yangutils.translator.tojava.utils;
18 +
19 +import java.io.IOException;
20 +import org.junit.Test;
21 +import org.onosproject.yangutils.datamodel.YangNode;
22 +import org.onosproject.yangutils.parser.exceptions.ParserException;
23 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
24 +
25 +import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
26 +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
27 +
28 +/**
29 + * Unit tests for union translator.
30 + */
31 +public final class UnionTranslatorTest {
32 +
33 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
34 +
35 + /**
36 + * Checks union translation should not result in any exception.
37 + */
38 + @Test
39 + public void processUnionTranslator() throws IOException, ParserException {
40 +
41 + clean("src/test/org/onosproject/yang");
42 +
43 + YangNode node = manager.getDataModel("src/test/resources/UnionTranslator.yang");
44 +
45 + YangPluginConfig yangPluginConfig = new YangPluginConfig();
46 + yangPluginConfig.setCodeGenDir("target/UnionTestGenFile");
47 +
48 + generateJavaCode(node, yangPluginConfig);
49 +
50 + clean("target/UnionTestGenFile");
51 + }
52 +
53 + // TODO enhance the test cases, after having a framework of translator test.
54 +}
...@@ -56,7 +56,7 @@ public final class JavaDocGenTest { ...@@ -56,7 +56,7 @@ public final class JavaDocGenTest {
56 @Test 56 @Test
57 public void builderClassGenerationTest() { 57 public void builderClassGenerationTest() {
58 String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false); 58 String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false);
59 - assertThat(true, is(builderClassJavaDoc.contains("Reperesents the builder implementation of") 59 + assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of")
60 && builderClassJavaDoc.contains(END_STRING))); 60 && builderClassJavaDoc.contains(END_STRING)));
61 } 61 }
62 62
...@@ -138,7 +138,7 @@ public final class JavaDocGenTest { ...@@ -138,7 +138,7 @@ public final class JavaDocGenTest {
138 public void implClassGenerationTest() { 138 public void implClassGenerationTest() {
139 String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false); 139 String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false);
140 assertThat(true, 140 assertThat(true,
141 - is(implClassJavaDoc.contains("Reperesents the implementation of") 141 + is(implClassJavaDoc.contains("Represents the implementation of")
142 && implClassJavaDoc.contains(END_STRING))); 142 && implClassJavaDoc.contains(END_STRING)));
143 } 143 }
144 144
...@@ -149,7 +149,7 @@ public final class JavaDocGenTest { ...@@ -149,7 +149,7 @@ public final class JavaDocGenTest {
149 public void interfaceGenerationTest() { 149 public void interfaceGenerationTest() {
150 String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false); 150 String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false);
151 assertThat(true, 151 assertThat(true,
152 - is(interfaceJavaDoc.contains("Abstraction of an entity which Reperesents the functionalities of") 152 + is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of")
153 && interfaceJavaDoc.contains(END_STRING))); 153 && interfaceJavaDoc.contains(END_STRING)));
154 } 154 }
155 155
......
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + container valid {
6 + leaf invalid-interval {
7 + type union {
8 + type int32;
9 + type int8;
10 + }
11 + }
12 + }
13 +}
...\ No newline at end of file ...\ No newline at end of file