Committed by
Gerrit Code Review
[ONOS-4070] Translator of YANG union.
Change-Id: I5216687b6ea7cb6baeb3ef8e905719468370a1f4
Showing
25 changed files
with
1375 additions
and
449 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. | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
... | @@ -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 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
... | @@ -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); | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
... | @@ -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) { | ... | ... |
... | @@ -20,31 +20,36 @@ import java.io.File; | ... | @@ -20,31 +20,36 @@ import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
22 | import java.util.List; | 22 | import java.util.List; |
23 | - | 23 | +import org.onosproject.yangutils.datamodel.HasType; |
24 | import org.onosproject.yangutils.datamodel.YangLeaf; | 24 | import org.onosproject.yangutils.datamodel.YangLeaf; |
25 | import org.onosproject.yangutils.datamodel.YangLeafList; | 25 | import org.onosproject.yangutils.datamodel.YangLeafList; |
26 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 26 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
27 | import org.onosproject.yangutils.datamodel.YangNode; | 27 | import org.onosproject.yangutils.datamodel.YangNode; |
28 | -import org.onosproject.yangutils.datamodel.YangTypeDef; | 28 | +import org.onosproject.yangutils.datamodel.YangType; |
29 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 29 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
30 | 30 | ||
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
34 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | ||
34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
38 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | ||
37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
41 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
44 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; | ||
42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; | 45 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | 46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
48 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; | ||
45 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf; | 49 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfLeaf; |
46 | -import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfTypeDef; | 50 | +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfType; |
47 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent; | 51 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent; |
52 | +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getFromStringAttributeInfo; | ||
48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; | 53 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination; |
49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; | 54 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose; |
50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; | 55 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile; |
... | @@ -52,6 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato | ... | @@ -52,6 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato |
52 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; | 57 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile; |
53 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; | 58 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile; |
54 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; | 59 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile; |
60 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile; | ||
55 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; | 61 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject; |
56 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 62 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
57 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 63 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
... | @@ -62,16 +68,17 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -62,16 +68,17 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
62 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor; | 68 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor; |
63 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; | 69 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString; |
64 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; | 70 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod; |
71 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod; | ||
65 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; | 72 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass; |
66 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; | 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString; |
67 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; | 74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod; |
68 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod; | 75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod; |
76 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc; | ||
69 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; | 77 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString; |
70 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; | 78 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass; |
71 | -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForTypeDefClass; | ||
72 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; | 79 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString; |
73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; | 80 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
74 | -import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeDefConstructor; | 81 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc; |
75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; | 82 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
76 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; | 83 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; |
77 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; | 84 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; |
... | @@ -91,11 +98,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ... | @@ -91,11 +98,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
91 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 98 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
92 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 99 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
93 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; | 100 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
94 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
95 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 101 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
96 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; | 102 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
97 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_CONSTRUCTOR; | 103 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
98 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_SETTER_METHOD; | ||
99 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; | 104 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean; |
100 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 105 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
101 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; | 106 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles; |
... | @@ -193,6 +198,21 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -193,6 +198,21 @@ public class TempJavaCodeFragmentFiles { |
193 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; | 198 | private static final String EQUALS_METHOD_FILE_NAME = "Equals"; |
194 | 199 | ||
195 | /** | 200 | /** |
201 | + * File name for of string method. | ||
202 | + */ | ||
203 | + private static final String OF_STRING_METHOD_FILE_NAME = "OfString"; | ||
204 | + | ||
205 | + /** | ||
206 | + * File name for construction for special type like union, typedef. | ||
207 | + */ | ||
208 | + private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType"; | ||
209 | + | ||
210 | + /** | ||
211 | + * File name for from string method. | ||
212 | + */ | ||
213 | + private static final String UNION_FROM_STRING_METHOD_FILE_NAME = "UnionFromString"; | ||
214 | + | ||
215 | + /** | ||
196 | * File name for interface java file name suffix. | 216 | * File name for interface java file name suffix. |
197 | */ | 217 | */ |
198 | private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; | 218 | private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING; |
... | @@ -218,6 +238,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -218,6 +238,11 @@ public class TempJavaCodeFragmentFiles { |
218 | private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; | 238 | private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; |
219 | 239 | ||
220 | /** | 240 | /** |
241 | + * File name for generated class file for special type like union, typedef suffix. | ||
242 | + */ | ||
243 | + private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING; | ||
244 | + | ||
245 | + /** | ||
221 | * Java file handle for interface file. | 246 | * Java file handle for interface file. |
222 | */ | 247 | */ |
223 | private File interfaceJavaFileHandle; | 248 | private File interfaceJavaFileHandle; |
... | @@ -243,6 +268,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -243,6 +268,11 @@ public class TempJavaCodeFragmentFiles { |
243 | private File typedefClassJavaFileHandle; | 268 | private File typedefClassJavaFileHandle; |
244 | 269 | ||
245 | /** | 270 | /** |
271 | + * Java file handle for type class like union, typedef file. | ||
272 | + */ | ||
273 | + private File typeClassJavaFileHandle; | ||
274 | + | ||
275 | + /** | ||
246 | * Temporary file handle for attribute. | 276 | * Temporary file handle for attribute. |
247 | */ | 277 | */ |
248 | private File attributesTempFileHandle; | 278 | private File attributesTempFileHandle; |
... | @@ -288,6 +318,21 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -288,6 +318,21 @@ public class TempJavaCodeFragmentFiles { |
288 | private File toStringImplTempFileHandle; | 318 | private File toStringImplTempFileHandle; |
289 | 319 | ||
290 | /** | 320 | /** |
321 | + * Temporary file handle for of string method of class. | ||
322 | + */ | ||
323 | + private File ofStringImplTempFileHandle; | ||
324 | + | ||
325 | + /** | ||
326 | + * Temporary file handle for constructor for type class. | ||
327 | + */ | ||
328 | + private File constructorForTypeTempFileHandle; | ||
329 | + | ||
330 | + /** | ||
331 | + * Temporary file handle for union's from string method of class. | ||
332 | + */ | ||
333 | + private File unionFromStringImplTempFileHandle; | ||
334 | + | ||
335 | + /** | ||
291 | * Java attribute info. | 336 | * Java attribute info. |
292 | */ | 337 | */ |
293 | private JavaAttributeInfo newAttrInfo; | 338 | private JavaAttributeInfo newAttrInfo; |
... | @@ -306,8 +351,8 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -306,8 +351,8 @@ public class TempJavaCodeFragmentFiles { |
306 | * Creates an instance of temporary java code fragment. | 351 | * Creates an instance of temporary java code fragment. |
307 | * | 352 | * |
308 | * @param genFileType file generation type | 353 | * @param genFileType file generation type |
309 | - * @param genDir file generation directory | 354 | + * @param genDir file generation directory |
310 | - * @param className class name | 355 | + * @param className class name |
311 | * @throws IOException when fails to create new file handle | 356 | * @throws IOException when fails to create new file handle |
312 | */ | 357 | */ |
313 | public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className) | 358 | public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className) |
... | @@ -368,6 +413,24 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -368,6 +413,24 @@ public class TempJavaCodeFragmentFiles { |
368 | generatedTempFiles |= HASH_CODE_IMPL_MASK; | 413 | generatedTempFiles |= HASH_CODE_IMPL_MASK; |
369 | generatedTempFiles |= EQUALS_IMPL_MASK; | 414 | generatedTempFiles |= EQUALS_IMPL_MASK; |
370 | generatedTempFiles |= TO_STRING_IMPL_MASK; | 415 | generatedTempFiles |= TO_STRING_IMPL_MASK; |
416 | + generatedTempFiles |= OF_STRING_IMPL_MASK; | ||
417 | + generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK; | ||
418 | + } | ||
419 | + | ||
420 | + /** | ||
421 | + * Initialize getterImpl, attributes, hash code, equals, of string, | ||
422 | + * constructor, union's to string, union's from string when generation | ||
423 | + * file type matches to union class mask. | ||
424 | + */ | ||
425 | + if ((genFileType & GENERATE_UNION_CLASS) != 0) { | ||
426 | + generatedTempFiles |= ATTRIBUTES_MASK; | ||
427 | + generatedTempFiles |= GETTER_FOR_CLASS_MASK; | ||
428 | + generatedTempFiles |= HASH_CODE_IMPL_MASK; | ||
429 | + generatedTempFiles |= EQUALS_IMPL_MASK; | ||
430 | + generatedTempFiles |= OF_STRING_IMPL_MASK; | ||
431 | + generatedTempFiles |= CONSTRUCTOR_FOR_TYPE_MASK; | ||
432 | + generatedTempFiles |= TO_STRING_IMPL_MASK; | ||
433 | + generatedTempFiles |= UNION_FROM_STRING_IMPL_MASK; | ||
371 | } | 434 | } |
372 | 435 | ||
373 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { | 436 | if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) { |
... | @@ -404,6 +467,18 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -404,6 +467,18 @@ public class TempJavaCodeFragmentFiles { |
404 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { | 467 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { |
405 | setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); | 468 | setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME)); |
406 | } | 469 | } |
470 | + | ||
471 | + if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { | ||
472 | + setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME)); | ||
473 | + } | ||
474 | + | ||
475 | + if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { | ||
476 | + setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME)); | ||
477 | + } | ||
478 | + | ||
479 | + if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { | ||
480 | + setUnionFromStringImplTempFileHandle(getTemporaryFileHandle(UNION_FROM_STRING_METHOD_FILE_NAME)); | ||
481 | + } | ||
407 | } | 482 | } |
408 | 483 | ||
409 | /** | 484 | /** |
... | @@ -497,6 +572,24 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -497,6 +572,24 @@ public class TempJavaCodeFragmentFiles { |
497 | } | 572 | } |
498 | 573 | ||
499 | /** | 574 | /** |
575 | + * Returns java file handle for type class file. | ||
576 | + * | ||
577 | + * @return java file handle for type class file | ||
578 | + */ | ||
579 | + private File getTypeClassJavaFileHandle() { | ||
580 | + return typeClassJavaFileHandle; | ||
581 | + } | ||
582 | + | ||
583 | + /** | ||
584 | + * Sets the java file handle for type class file. | ||
585 | + * | ||
586 | + * @param typeClassJavaFileHandle type file handle | ||
587 | + */ | ||
588 | + private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) { | ||
589 | + this.typeClassJavaFileHandle = typeClassJavaFileHandle; | ||
590 | + } | ||
591 | + | ||
592 | + /** | ||
500 | * Returns attribute's temporary file handle. | 593 | * Returns attribute's temporary file handle. |
501 | * | 594 | * |
502 | * @return temporary file handle | 595 | * @return temporary file handle |
... | @@ -659,6 +752,60 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -659,6 +752,60 @@ public class TempJavaCodeFragmentFiles { |
659 | } | 752 | } |
660 | 753 | ||
661 | /** | 754 | /** |
755 | + * Returns of string method's temporary file handle. | ||
756 | + * | ||
757 | + * @return of string method's temporary file handle | ||
758 | + */ | ||
759 | + public File getOfStringImplTempFileHandle() { | ||
760 | + return ofStringImplTempFileHandle; | ||
761 | + } | ||
762 | + | ||
763 | + /** | ||
764 | + * Set of string method's temporary file handle. | ||
765 | + * | ||
766 | + * @param ofStringImplTempFileHandle of string method's temporary file handle | ||
767 | + */ | ||
768 | + private void setOfStringImplTempFileHandle(File ofStringImplTempFileHandle) { | ||
769 | + this.ofStringImplTempFileHandle = ofStringImplTempFileHandle; | ||
770 | + } | ||
771 | + | ||
772 | + /** | ||
773 | + * Returns type class constructor method's temporary file handle. | ||
774 | + * | ||
775 | + * @return type class constructor method's temporary file handle | ||
776 | + */ | ||
777 | + public File getConstructorForTypeTempFileHandle() { | ||
778 | + return constructorForTypeTempFileHandle; | ||
779 | + } | ||
780 | + | ||
781 | + /** | ||
782 | + * Sets type class constructor method's temporary file handle. | ||
783 | + * | ||
784 | + * @param constructorForTypeTempFileHandle type class constructor method's temporary file handle | ||
785 | + */ | ||
786 | + private void setConstructorForTypeTempFileHandle(File constructorForTypeTempFileHandle) { | ||
787 | + this.constructorForTypeTempFileHandle = constructorForTypeTempFileHandle; | ||
788 | + } | ||
789 | + | ||
790 | + /** | ||
791 | + * Returns union's from string method's temporary file handle. | ||
792 | + * | ||
793 | + * @return union's from string method's temporary file handle | ||
794 | + */ | ||
795 | + public File getUnionFromStringImplTempFileHandle() { | ||
796 | + return unionFromStringImplTempFileHandle; | ||
797 | + } | ||
798 | + | ||
799 | + /** | ||
800 | + * Sets union's from string method's temporary file handle. | ||
801 | + * | ||
802 | + * @param unionFromStringImplTempFileHandle union's from string method's temporary file handle | ||
803 | + */ | ||
804 | + private void setUnionFromStringImplTempFileHandle(File unionFromStringImplTempFileHandle) { | ||
805 | + this.unionFromStringImplTempFileHandle = unionFromStringImplTempFileHandle; | ||
806 | + } | ||
807 | + | ||
808 | + /** | ||
662 | * Returns java attribute info. | 809 | * Returns java attribute info. |
663 | * | 810 | * |
664 | * @return java attribute info | 811 | * @return java attribute info |
... | @@ -727,6 +874,28 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -727,6 +874,28 @@ public class TempJavaCodeFragmentFiles { |
727 | } | 874 | } |
728 | 875 | ||
729 | /** | 876 | /** |
877 | + * Adds of string for type. | ||
878 | + * | ||
879 | + * @param attr attribute info | ||
880 | + * @throws IOException when fails to append to temporary file | ||
881 | + */ | ||
882 | + private void addOfStringMethod(JavaAttributeInfo attr) throws IOException { | ||
883 | + appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr, generatedJavaClassName) | ||
884 | + + NEW_LINE); | ||
885 | + } | ||
886 | + | ||
887 | + /** | ||
888 | + * Adds type constructor. | ||
889 | + * | ||
890 | + * @param attr attribute info | ||
891 | + * @throws IOException when fails to append to temporary file | ||
892 | + */ | ||
893 | + private void addTypeConstructor(JavaAttributeInfo attr) throws IOException { | ||
894 | + appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr, | ||
895 | + generatedJavaClassName) + NEW_LINE); | ||
896 | + } | ||
897 | + | ||
898 | + /** | ||
730 | * Adds attribute for class. | 899 | * Adds attribute for class. |
731 | * | 900 | * |
732 | * @param attr attribute info | 901 | * @param attr attribute info |
... | @@ -749,7 +918,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -749,7 +918,7 @@ public class TempJavaCodeFragmentFiles { |
749 | /** | 918 | /** |
750 | * Adds getter method's impl for class. | 919 | * Adds getter method's impl for class. |
751 | * | 920 | * |
752 | - * @param attr attribute info | 921 | + * @param attr attribute info |
753 | * @param genFiletype generated file type | 922 | * @param genFiletype generated file type |
754 | * @throws IOException when fails to append to temporary file | 923 | * @throws IOException when fails to append to temporary file |
755 | */ | 924 | */ |
... | @@ -828,28 +997,6 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -828,28 +997,6 @@ public class TempJavaCodeFragmentFiles { |
828 | } | 997 | } |
829 | 998 | ||
830 | /** | 999 | /** |
831 | - * Adds typedef constructor for class. | ||
832 | - * | ||
833 | - * @return typedef constructor for class | ||
834 | - * @throws IOException when fails to append to file | ||
835 | - */ | ||
836 | - public String addTypeDefConstructor() throws IOException { | ||
837 | - return NEW_LINE + getJavaDoc(TYPE_DEF_CONSTRUCTOR, generatedJavaClassName, false) | ||
838 | - + getTypeDefConstructor(newAttrInfo, generatedJavaClassName) + NEW_LINE; | ||
839 | - } | ||
840 | - | ||
841 | - /** | ||
842 | - * Adds default constructor for class. | ||
843 | - * | ||
844 | - * @return default constructor for class | ||
845 | - * @throws IOException when fails to append to file | ||
846 | - */ | ||
847 | - public String addTypeDefsSetter() throws IOException { | ||
848 | - return getJavaDoc(TYPE_DEF_SETTER_METHOD, generatedJavaClassName, false) + getSetterForTypeDefClass(newAttrInfo) | ||
849 | - + NEW_LINE; | ||
850 | - } | ||
851 | - | ||
852 | - /** | ||
853 | * Adds default constructor for class. | 1000 | * Adds default constructor for class. |
854 | * | 1001 | * |
855 | * @return default constructor for class | 1002 | * @return default constructor for class |
... | @@ -891,6 +1038,19 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -891,6 +1038,19 @@ public class TempJavaCodeFragmentFiles { |
891 | } | 1038 | } |
892 | 1039 | ||
893 | /** | 1040 | /** |
1041 | + * Add from string method for union class. | ||
1042 | + * | ||
1043 | + * @param javaAttributeInfo type attribute info | ||
1044 | + * @param fromStringAttributeInfo from string attribute info | ||
1045 | + * @throws IOException when fails to append to temporary file | ||
1046 | + */ | ||
1047 | + private void addUnionFromStringMethod(JavaAttributeInfo javaAttributeInfo, | ||
1048 | + JavaAttributeInfo fromStringAttributeInfo) throws IOException { | ||
1049 | + appendToFile(getUnionFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo, | ||
1050 | + fromStringAttributeInfo) + NEW_LINE); | ||
1051 | + } | ||
1052 | + | ||
1053 | + /** | ||
894 | * Returns a temporary file handle for the specific file type. | 1054 | * Returns a temporary file handle for the specific file type. |
895 | * | 1055 | * |
896 | * @param fileName file name | 1056 | * @param fileName file name |
... | @@ -993,12 +1153,12 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -993,12 +1153,12 @@ public class TempJavaCodeFragmentFiles { |
993 | * Adds current node info as and attribute to the parent generated file. | 1153 | * Adds current node info as and attribute to the parent generated file. |
994 | * | 1154 | * |
995 | * @param curNode current node which needs to be added as an attribute in | 1155 | * @param curNode current node which needs to be added as an attribute in |
996 | - * the parent generated code | 1156 | + * the parent generated code |
997 | - * @param isList is list construct | 1157 | + * @param isList is list construct |
998 | * @throws IOException IO operation exception | 1158 | * @throws IOException IO operation exception |
999 | */ | 1159 | */ |
1000 | public void addCurNodeInfoInParentTempFile(YangNode curNode, | 1160 | public void addCurNodeInfoInParentTempFile(YangNode curNode, |
1001 | - boolean isList) throws IOException { | 1161 | + boolean isList) throws IOException { |
1002 | 1162 | ||
1003 | YangNode parent = getParentNodeInGenCode(curNode); | 1163 | YangNode parent = getParentNodeInGenCode(curNode); |
1004 | if (!(parent instanceof JavaCodeGenerator)) { | 1164 | if (!(parent instanceof JavaCodeGenerator)) { |
... | @@ -1019,11 +1179,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1019,11 +1179,11 @@ public class TempJavaCodeFragmentFiles { |
1019 | * Adds leaf attributes in generated files. | 1179 | * Adds leaf attributes in generated files. |
1020 | * | 1180 | * |
1021 | * @param listOfLeaves list of YANG leaf | 1181 | * @param listOfLeaves list of YANG leaf |
1022 | - * @param curNode current data model node | 1182 | + * @param curNode current data model node |
1023 | * @throws IOException IO operation fail | 1183 | * @throws IOException IO operation fail |
1024 | */ | 1184 | */ |
1025 | private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves, | 1185 | private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves, |
1026 | - YangNode curNode) throws IOException { | 1186 | + YangNode curNode) throws IOException { |
1027 | 1187 | ||
1028 | if (listOfLeaves != null) { | 1188 | if (listOfLeaves != null) { |
1029 | for (YangLeaf leaf : listOfLeaves) { | 1189 | for (YangLeaf leaf : listOfLeaves) { |
... | @@ -1039,11 +1199,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1039,11 +1199,11 @@ public class TempJavaCodeFragmentFiles { |
1039 | * Adds leaf list's attributes in generated files. | 1199 | * Adds leaf list's attributes in generated files. |
1040 | * | 1200 | * |
1041 | * @param listOfLeafList list of YANG leaves | 1201 | * @param listOfLeafList list of YANG leaves |
1042 | - * @param curNode cached file handle | 1202 | + * @param curNode cached file handle |
1043 | * @throws IOException IO operation fail | 1203 | * @throws IOException IO operation fail |
1044 | */ | 1204 | */ |
1045 | private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, | 1205 | private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, |
1046 | - YangNode curNode) throws IOException { | 1206 | + YangNode curNode) throws IOException { |
1047 | 1207 | ||
1048 | if (listOfLeafList != null) { | 1208 | if (listOfLeafList != null) { |
1049 | 1209 | ||
... | @@ -1087,16 +1247,45 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1087,16 +1247,45 @@ public class TempJavaCodeFragmentFiles { |
1087 | } | 1247 | } |
1088 | 1248 | ||
1089 | /** | 1249 | /** |
1090 | - * Adds leaf attributes in generated files. | 1250 | + * Add all the type in the current data model node as part of the |
1251 | + * generated temporary file. | ||
1091 | * | 1252 | * |
1092 | - * @param curNode current data model node | 1253 | + * @param hasType YANG java data model node which has type info, eg union / typedef |
1093 | * @throws IOException IO operation fail | 1254 | * @throws IOException IO operation fail |
1094 | */ | 1255 | */ |
1095 | - public void addTypeDefAttributeToTempFiles(YangNode curNode) throws IOException { | 1256 | + public void addTypeInfoToTempFiles(HasType hasType) throws IOException { |
1257 | + | ||
1258 | + List<YangType<?>> typeList = hasType.getTypeList(); | ||
1259 | + if (typeList != null) { | ||
1260 | + for (YangType<?> yangType : typeList) { | ||
1261 | + JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfType((YangNode) hasType, | ||
1262 | + yangType, getTypeName(yangType.getDataTypeName()), false); | ||
1263 | + addJavaSnippetInfoToApplicableTempFiles((YangNode) hasType, javaAttributeInfo); | ||
1264 | + } | ||
1265 | + } | ||
1266 | + } | ||
1267 | + | ||
1268 | + private String getTypeName(String dataTypeName) { | ||
1269 | + return dataTypeName; | ||
1270 | + //TODO: implement the method. | ||
1271 | + } | ||
1272 | + | ||
1273 | + /** | ||
1274 | + * Adds the new attribute info to the target generated temporary files for union class. | ||
1275 | + * | ||
1276 | + * @param hasType the node for which the type is being added as an attribute | ||
1277 | + * @param javaAttributeInfo the attribute info that needs to be added to temporary | ||
1278 | + * files | ||
1279 | + * @throws IOException IO operation fail | ||
1280 | + */ | ||
1281 | + private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo) | ||
1282 | + throws IOException { | ||
1096 | 1283 | ||
1097 | - JavaAttributeInfo javaAttributeInfo = getAttributeInfoOfTypeDef(curNode, | 1284 | + JavaAttributeInfo fromStringAttributeInfo = getFromStringAttributeInfo(hasType, javaAttributeInfo); |
1098 | - ((YangTypeDef) curNode).getTypeDefBaseType(), | 1285 | + |
1099 | - ((YangTypeDef) curNode).getName(), false); | 1286 | + if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { |
1287 | + addUnionFromStringMethod(javaAttributeInfo, fromStringAttributeInfo); | ||
1288 | + } | ||
1100 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); | 1289 | addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo); |
1101 | } | 1290 | } |
1102 | 1291 | ||
... | @@ -1104,7 +1293,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1104,7 +1293,7 @@ public class TempJavaCodeFragmentFiles { |
1104 | * Adds the new attribute info to the target generated temporary files. | 1293 | * Adds the new attribute info to the target generated temporary files. |
1105 | * | 1294 | * |
1106 | * @param newAttrInfo the attribute info that needs to be added to temporary | 1295 | * @param newAttrInfo the attribute info that needs to be added to temporary |
1107 | - * files | 1296 | + * files |
1108 | * @throws IOException IO operation fail | 1297 | * @throws IOException IO operation fail |
1109 | */ | 1298 | */ |
1110 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) | 1299 | void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo) |
... | @@ -1147,6 +1336,15 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1147,6 +1336,15 @@ public class TempJavaCodeFragmentFiles { |
1147 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { | 1336 | if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) { |
1148 | addToStringMethod(newAttrInfo); | 1337 | addToStringMethod(newAttrInfo); |
1149 | } | 1338 | } |
1339 | + | ||
1340 | + if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { | ||
1341 | + addOfStringMethod(newAttrInfo); | ||
1342 | + } | ||
1343 | + | ||
1344 | + if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { | ||
1345 | + addTypeConstructor(newAttrInfo); | ||
1346 | + } | ||
1347 | + | ||
1150 | } | 1348 | } |
1151 | } | 1349 | } |
1152 | 1350 | ||
... | @@ -1182,7 +1380,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1182,7 +1380,7 @@ public class TempJavaCodeFragmentFiles { |
1182 | * Constructs java code exit. | 1380 | * Constructs java code exit. |
1183 | * | 1381 | * |
1184 | * @param fileType generated file type | 1382 | * @param fileType generated file type |
1185 | - * @param curNode current YANG node | 1383 | + * @param curNode current YANG node |
1186 | * @throws IOException when fails to generate java files | 1384 | * @throws IOException when fails to generate java files |
1187 | */ | 1385 | */ |
1188 | public void generateJavaFile(int fileType, YangNode curNode) throws IOException { | 1386 | public void generateJavaFile(int fileType, YangNode curNode) throws IOException { |
... | @@ -1285,6 +1483,15 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1285,6 +1483,15 @@ public class TempJavaCodeFragmentFiles { |
1285 | } | 1483 | } |
1286 | 1484 | ||
1287 | /** | 1485 | /** |
1486 | + * Creates type class file. | ||
1487 | + */ | ||
1488 | + if ((fileType & GENERATE_UNION_CLASS) != 0) { | ||
1489 | + addImportsToStringAndHasCodeMethods(curNode, imports); | ||
1490 | + setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX))); | ||
1491 | + setTypeClassJavaFileHandle(generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports)); | ||
1492 | + } | ||
1493 | + | ||
1494 | + /** | ||
1288 | * Close all the file handles. | 1495 | * Close all the file handles. |
1289 | */ | 1496 | */ |
1290 | close(false); | 1497 | close(false); |
... | @@ -1294,8 +1501,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1294,8 +1501,7 @@ public class TempJavaCodeFragmentFiles { |
1294 | * Removes all temporary file handles. | 1501 | * Removes all temporary file handles. |
1295 | * | 1502 | * |
1296 | * @param isErrorOccurred when translator fails to generate java files we need to close | 1503 | * @param isErrorOccurred when translator fails to generate java files we need to close |
1297 | - * all open file handles include temporary files and java files. | 1504 | + * all open file handles include temporary files and java files. |
1298 | - * | ||
1299 | * @throws IOException when failed to delete the temporary files | 1505 | * @throws IOException when failed to delete the temporary files |
1300 | */ | 1506 | */ |
1301 | public void close(boolean isErrorOccurred) throws IOException { | 1507 | public void close(boolean isErrorOccurred) throws IOException { |
... | @@ -1319,6 +1525,9 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1319,6 +1525,9 @@ public class TempJavaCodeFragmentFiles { |
1319 | if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) { | 1525 | if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) { |
1320 | closeFile(getTypedefClassJavaFileHandle(), isError); | 1526 | closeFile(getTypedefClassJavaFileHandle(), isError); |
1321 | } | 1527 | } |
1528 | + if ((generatedJavaFiles & GENERATE_UNION_CLASS) != 0) { | ||
1529 | + closeFile(getTypeClassJavaFileHandle(), isError); | ||
1530 | + } | ||
1322 | 1531 | ||
1323 | /** | 1532 | /** |
1324 | * Close all temporary file handles and delete the files. | 1533 | * Close all temporary file handles and delete the files. |
... | @@ -1350,7 +1559,15 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1350,7 +1559,15 @@ public class TempJavaCodeFragmentFiles { |
1350 | if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { | 1559 | if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) { |
1351 | closeFile(getEqualsImplTempFileHandle(), true); | 1560 | closeFile(getEqualsImplTempFileHandle(), true); |
1352 | } | 1561 | } |
1353 | - | 1562 | + if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) { |
1563 | + closeFile(getConstructorForTypeTempFileHandle(), true); | ||
1564 | + } | ||
1565 | + if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) { | ||
1566 | + closeFile(getOfStringImplTempFileHandle(), true); | ||
1567 | + } | ||
1568 | + if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { | ||
1569 | + closeFile(getUnionFromStringImplTempFileHandle(), true); | ||
1570 | + } | ||
1354 | clean(getTempDirPath()); | 1571 | clean(getTempDirPath()); |
1355 | generatedTempFiles = 0; | 1572 | generatedTempFiles = 0; |
1356 | } | 1573 | } | ... | ... |
... | @@ -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 | } | ... | ... |
... | @@ -20,7 +20,6 @@ import java.io.File; | ... | @@ -20,7 +20,6 @@ import java.io.File; |
20 | import java.io.IOException; | 20 | import java.io.IOException; |
21 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
22 | import java.util.List; | 22 | import java.util.List; |
23 | - | ||
24 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
25 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 24 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
26 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; | 25 | import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles; |
... | @@ -29,17 +28,21 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ... | @@ -29,17 +28,21 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
31 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | ||
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
34 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
35 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | ||
35 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK; |
41 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK; | ||
40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
41 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | 43 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | 44 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
45 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; | ||
43 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute; | 46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute; |
44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; | 47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; |
45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; | 48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; |
... | @@ -49,8 +52,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -49,8 +52,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
49 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; | 52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
50 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; | 53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
51 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; | 54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
55 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; | ||
56 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature; | ||
52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; | 57 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; |
53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; | 58 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; |
59 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; | ||
54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; | 60 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; |
55 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; | 61 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; | 62 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
... | @@ -82,8 +88,8 @@ public final class JavaFileGenerator { | ... | @@ -82,8 +88,8 @@ public final class JavaFileGenerator { |
82 | private static List<String> extendsList = new ArrayList<>(); | 88 | private static List<String> extendsList = new ArrayList<>(); |
83 | 89 | ||
84 | /** | 90 | /** |
85 | - * Creates an instance of java file generator. | 91 | + * Creates an instance of java file generator. |
86 | - */ | 92 | + */ |
87 | private JavaFileGenerator() { | 93 | private JavaFileGenerator() { |
88 | } | 94 | } |
89 | 95 | ||
... | @@ -126,10 +132,10 @@ public final class JavaFileGenerator { | ... | @@ -126,10 +132,10 @@ public final class JavaFileGenerator { |
126 | /** | 132 | /** |
127 | * Returns generated interface file for current node. | 133 | * Returns generated interface file for current node. |
128 | * | 134 | * |
129 | - * @param file file | 135 | + * @param file file |
130 | - * @param imports imports for the file | 136 | + * @param imports imports for the file |
131 | - * @param curNode current YANG node | 137 | + * @param curNode current YANG node |
132 | - * @param isAttrPresent if any attribute is present or not | 138 | + * @param isAttrPresent if any attribute is present or not |
133 | * @return interface file | 139 | * @return interface file |
134 | * @throws IOException when fails to write in file | 140 | * @throws IOException when fails to write in file |
135 | */ | 141 | */ |
... | @@ -163,9 +169,9 @@ public final class JavaFileGenerator { | ... | @@ -163,9 +169,9 @@ public final class JavaFileGenerator { |
163 | /** | 169 | /** |
164 | * Return generated builder interface file for current node. | 170 | * Return generated builder interface file for current node. |
165 | * | 171 | * |
166 | - * @param file file | 172 | + * @param file file |
167 | - * @param curNode current YANG node | 173 | + * @param curNode current YANG node |
168 | - * @param isAttrPresent if any attribute is present or not | 174 | + * @param isAttrPresent if any attribute is present or not |
169 | * @return builder interface file | 175 | * @return builder interface file |
170 | * @throws IOException when fails to write in file | 176 | * @throws IOException when fails to write in file |
171 | */ | 177 | */ |
... | @@ -215,15 +221,15 @@ public final class JavaFileGenerator { | ... | @@ -215,15 +221,15 @@ public final class JavaFileGenerator { |
215 | /** | 221 | /** |
216 | * Returns generated builder class file for current node. | 222 | * Returns generated builder class file for current node. |
217 | * | 223 | * |
218 | - * @param file file | 224 | + * @param file file |
219 | - * @param imports imports for the file | 225 | + * @param imports imports for the file |
220 | - * @param curNode current YANG node | 226 | + * @param curNode current YANG node |
221 | - * @param isAttrPresent if any attribute is present or not | 227 | + * @param isAttrPresent if any attribute is present or not |
222 | * @return builder class file | 228 | * @return builder class file |
223 | * @throws IOException when fails to write in file | 229 | * @throws IOException when fails to write in file |
224 | */ | 230 | */ |
225 | public static File generateBuilderClassFile(File file, List<String> imports, YangNode curNode, | 231 | public static File generateBuilderClassFile(File file, List<String> imports, YangNode curNode, |
226 | - boolean isAttrPresent) throws IOException { | 232 | + boolean isAttrPresent) throws IOException { |
227 | 233 | ||
228 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | 234 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); |
229 | 235 | ||
... | @@ -281,8 +287,8 @@ public final class JavaFileGenerator { | ... | @@ -281,8 +287,8 @@ public final class JavaFileGenerator { |
281 | /** | 287 | /** |
282 | * Returns generated impl class file for current node. | 288 | * Returns generated impl class file for current node. |
283 | * | 289 | * |
284 | - * @param file file | 290 | + * @param file file |
285 | - * @param curNode current YANG node | 291 | + * @param curNode current YANG node |
286 | * @param isAttrPresent if any attribute is present or not | 292 | * @param isAttrPresent if any attribute is present or not |
287 | * @return impl class file | 293 | * @return impl class file |
288 | * @throws IOException when fails to write in file | 294 | * @throws IOException when fails to write in file |
... | @@ -378,14 +384,14 @@ public final class JavaFileGenerator { | ... | @@ -378,14 +384,14 @@ public final class JavaFileGenerator { |
378 | } | 384 | } |
379 | 385 | ||
380 | /** | 386 | /** |
381 | - * Generates class file for type def. | 387 | + * Generate class file for type def. |
382 | * | 388 | * |
383 | - * @param file generated file | 389 | + * @param file generated file |
384 | * @param curNode current YANG node | 390 | * @param curNode current YANG node |
385 | * @param imports imports for file | 391 | * @param imports imports for file |
386 | * @return type def class file | 392 | * @return type def class file |
387 | * @throws IOException when fails to generate class file | 393 | * @throws IOException when fails to generate class file |
388 | - */ | 394 | + */ |
389 | public static File generateTypeDefClassFile(File file, YangNode curNode, List<String> imports) throws IOException { | 395 | public static File generateTypeDefClassFile(File file, YangNode curNode, List<String> imports) throws IOException { |
390 | 396 | ||
391 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | 397 | JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); |
... | @@ -414,19 +420,104 @@ public final class JavaFileGenerator { | ... | @@ -414,19 +420,104 @@ public final class JavaFileGenerator { |
414 | methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() | 420 | methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() |
415 | .addDefaultConstructor(PRIVATE, EMPTY_STRING)); | 421 | .addDefaultConstructor(PRIVATE, EMPTY_STRING)); |
416 | 422 | ||
423 | + try { | ||
424 | + | ||
425 | + /** | ||
426 | + * Type constructor. | ||
427 | + */ | ||
428 | + methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, curNode)); | ||
429 | + | ||
430 | + /** | ||
431 | + * Of method. | ||
432 | + */ | ||
433 | + methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, curNode)); | ||
434 | + | ||
435 | + /** | ||
436 | + * Getter method. | ||
437 | + */ | ||
438 | + methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); | ||
439 | + | ||
440 | + /** | ||
441 | + * Hash code method. | ||
442 | + */ | ||
443 | + methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( | ||
444 | + getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, curNode).replace(NEW_LINE, EMPTY_STRING)))); | ||
445 | + | ||
446 | + /** | ||
447 | + * Equals method. | ||
448 | + */ | ||
449 | + methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING) | ||
450 | + + getDataFromTempFileHandle(EQUALS_IMPL_MASK, curNode))); | ||
451 | + | ||
452 | + /** | ||
453 | + * To string method. | ||
454 | + */ | ||
455 | + methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode) | ||
456 | + + getToStringMethodClose()); | ||
457 | + | ||
458 | + } catch (IOException e) { | ||
459 | + throw new IOException("No data found in temporary java code fragment files for " + className | ||
460 | + + " while type def class file generation"); | ||
461 | + } | ||
462 | + | ||
463 | + for (String method : methods) { | ||
464 | + insertDataIntoJavaFile(file, method); | ||
465 | + } | ||
466 | + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | ||
467 | + | ||
468 | + return file; | ||
469 | + } | ||
470 | + | ||
471 | + /** | ||
472 | + * Generate class file for union type. | ||
473 | + * | ||
474 | + * @param file generated file | ||
475 | + * @param curNode current YANG node | ||
476 | + * @param imports imports for file | ||
477 | + * @return type def class file | ||
478 | + * @throws IOException when fails to generate class file | ||
479 | + */ | ||
480 | + public static File generateUnionClassFile(File file, YangNode curNode, List<String> imports) throws IOException { | ||
481 | + | ||
482 | + JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | ||
483 | + | ||
484 | + String className = getCaptialCase(javaFileInfo.getJavaName()); | ||
485 | + String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | ||
486 | + | ||
487 | + initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS, imports, path); | ||
488 | + | ||
489 | + List<String> methods = new ArrayList<>(); | ||
490 | + | ||
417 | /** | 491 | /** |
418 | - * Constructor. | 492 | + * Add attribute strings. |
419 | */ | 493 | */ |
420 | - methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() | 494 | + try { |
421 | - .addTypeDefConstructor()); | 495 | + insertDataIntoJavaFile(file, |
496 | + NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode)); | ||
497 | + } catch (IOException e) { | ||
498 | + throw new IOException("No data found in temporary java code fragment files for " + className | ||
499 | + + " while union class file generation"); | ||
500 | + } | ||
422 | 501 | ||
423 | /** | 502 | /** |
424 | - * Of method. | 503 | + * Default constructor. |
425 | */ | 504 | */ |
426 | - methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().addOfMethod()); | 505 | + methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() |
506 | + .addDefaultConstructor(PRIVATE, EMPTY_STRING)); | ||
507 | + | ||
427 | try { | 508 | try { |
428 | 509 | ||
429 | /** | 510 | /** |
511 | + * Type constructor. | ||
512 | + */ | ||
513 | + methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK, curNode)); | ||
514 | + | ||
515 | + /** | ||
516 | + * Of string method. | ||
517 | + */ | ||
518 | + methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK, curNode)); | ||
519 | + | ||
520 | + /** | ||
430 | * Getter method. | 521 | * Getter method. |
431 | */ | 522 | */ |
432 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); | 523 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); |
... | @@ -446,12 +537,19 @@ public final class JavaFileGenerator { | ... | @@ -446,12 +537,19 @@ public final class JavaFileGenerator { |
446 | /** | 537 | /** |
447 | * To string method. | 538 | * To string method. |
448 | */ | 539 | */ |
449 | - methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode) | 540 | + methods.add(getToStringMethodOpen() + getOmitNullValueString() + |
450 | - + getToStringMethodClose()); | 541 | + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode) + getToStringMethodClose()); |
542 | + | ||
543 | + /** | ||
544 | + * From string method. | ||
545 | + */ | ||
546 | + methods.add(getFromStringMethodSignature(className) | ||
547 | + + getDataFromTempFileHandle(UNION_FROM_STRING_IMPL_MASK, curNode) | ||
548 | + + getFromStringMethodClose()); | ||
451 | 549 | ||
452 | } catch (IOException e) { | 550 | } catch (IOException e) { |
453 | throw new IOException("No data found in temporary java code fragment files for " + className | 551 | throw new IOException("No data found in temporary java code fragment files for " + className |
454 | - + " while type def class file generation"); | 552 | + + " while union class file generation"); |
455 | } | 553 | } |
456 | 554 | ||
457 | for (String method : methods) { | 555 | for (String method : methods) { | ... | ... |
... | @@ -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 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | 19 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
20 | 20 | ||
21 | +import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getParseFromStringMethod; | ||
21 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 24 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
... | @@ -28,7 +29,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ... | @@ -28,7 +29,9 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
29 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; |
30 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
32 | +import static org.onosproject.yangutils.utils.UtilConstants.CATCH; | ||
31 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING; |
34 | +import static org.onosproject.yangutils.utils.UtilConstants.CLEAR; | ||
32 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
33 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
34 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
... | @@ -38,8 +41,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTAT | ... | @@ -38,8 +41,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTAT |
38 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
39 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; |
44 | +import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR; | ||
41 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; | 46 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
42 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 47 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
48 | +import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; | ||
49 | +import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; | ||
43 | import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; | 50 | import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; |
44 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; | 51 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; |
45 | import static org.onosproject.yangutils.utils.UtilConstants.HASH; | 52 | import static org.onosproject.yangutils.utils.UtilConstants.HASH; |
... | @@ -51,10 +58,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.INT; | ... | @@ -51,10 +58,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.INT; |
51 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; | 58 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
52 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.NEW; |
53 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
61 | +import static org.onosproject.yangutils.utils.UtilConstants.NULL; | ||
54 | import static org.onosproject.yangutils.utils.UtilConstants.OBJ; | 62 | import static org.onosproject.yangutils.utils.UtilConstants.OBJ; |
55 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; | 63 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT; |
56 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING; | 64 | import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING; |
57 | import static org.onosproject.yangutils.utils.UtilConstants.OF; | 65 | import static org.onosproject.yangutils.utils.UtilConstants.OF; |
66 | +import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING; | ||
58 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | 67 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
59 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; | 68 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
60 | import static org.onosproject.yangutils.utils.UtilConstants.OTHER; | 69 | import static org.onosproject.yangutils.utils.UtilConstants.OTHER; |
... | @@ -71,17 +80,22 @@ import static org.onosproject.yangutils.utils.UtilConstants.STATIC; | ... | @@ -71,17 +80,22 @@ import static org.onosproject.yangutils.utils.UtilConstants.STATIC; |
71 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | 80 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
72 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; | 81 | import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S; |
73 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; | 82 | import static org.onosproject.yangutils.utils.UtilConstants.THIS; |
83 | +import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL; | ||
74 | import static org.onosproject.yangutils.utils.UtilConstants.TO; | 84 | import static org.onosproject.yangutils.utils.UtilConstants.TO; |
75 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | 85 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
86 | +import static org.onosproject.yangutils.utils.UtilConstants.TRY; | ||
76 | import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; | 87 | import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; |
77 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; | 88 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; |
78 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; | 89 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
79 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
80 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; | 90 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; |
81 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; | 91 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; |
82 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; | 92 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; |
83 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 93 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
94 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; | ||
84 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; | 95 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; |
96 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; | ||
97 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.UNION_FROM_METHOD; | ||
98 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
85 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | 99 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
86 | 100 | ||
87 | /** | 101 | /** |
... | @@ -123,7 +137,7 @@ public final class MethodsGenerator { | ... | @@ -123,7 +137,7 @@ public final class MethodsGenerator { |
123 | /** | 137 | /** |
124 | * Returns setter string. | 138 | * Returns setter string. |
125 | * | 139 | * |
126 | - * @param attr attribute info | 140 | + * @param attr attribute info |
127 | * @param className java class name | 141 | * @param className java class name |
128 | * @return setter string | 142 | * @return setter string |
129 | */ | 143 | */ |
... | @@ -149,46 +163,13 @@ public final class MethodsGenerator { | ... | @@ -149,46 +163,13 @@ public final class MethodsGenerator { |
149 | /** | 163 | /** |
150 | * Returns default constructor method string. | 164 | * Returns default constructor method string. |
151 | * | 165 | * |
152 | - * @param name class name | 166 | + * @param name class name |
153 | * @param modifierType modifier type | 167 | * @param modifierType modifier type |
154 | * @return default constructor string | 168 | * @return default constructor string |
155 | */ | 169 | */ |
156 | public static String getDefaultConstructorString(String name, String modifierType) { | 170 | public static String getDefaultConstructorString(String name, String modifierType) { |
157 | - return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType); | 171 | + return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType) |
158 | - } | 172 | + + NEW_LINE; |
159 | - | ||
160 | - /** | ||
161 | - * Returns default constructor method string. | ||
162 | - * | ||
163 | - * @param attr attribute info | ||
164 | - * @param className class name | ||
165 | - * @return default constructor string | ||
166 | - */ | ||
167 | - public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) { | ||
168 | - | ||
169 | - String attrQuaifiedType = getReturnType(attr); | ||
170 | - String attributeName = getSmallCase(attr.getAttributeName()); | ||
171 | - | ||
172 | - if (!attr.isListAttr()) { | ||
173 | - return getTypeDefConstructorString(attrQuaifiedType, attributeName, className); | ||
174 | - } | ||
175 | - String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET; | ||
176 | - return getTypeDefConstructorString(listAttr, attributeName, className); | ||
177 | - } | ||
178 | - | ||
179 | - /** | ||
180 | - * Returns type def's constructor for attribute. | ||
181 | - * | ||
182 | - * @param type data type | ||
183 | - * @param name attribute name | ||
184 | - * @param className class name | ||
185 | - * @return setter for type def's attribute | ||
186 | - */ | ||
187 | - private static String getTypeDefConstructorString(String type, String name, String className) { | ||
188 | - return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE | ||
189 | - + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD | ||
190 | - + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION | ||
191 | - + CLOSE_CURLY_BRACKET; | ||
192 | } | 173 | } |
193 | 174 | ||
194 | /** | 175 | /** |
... | @@ -246,7 +227,7 @@ public final class MethodsGenerator { | ... | @@ -246,7 +227,7 @@ public final class MethodsGenerator { |
246 | /** | 227 | /** |
247 | * Returns the setter method strings for class file. | 228 | * Returns the setter method strings for class file. |
248 | * | 229 | * |
249 | - * @param attr attribute info | 230 | + * @param attr attribute info |
250 | * @param className name of the class | 231 | * @param className name of the class |
251 | * @return setter method for class | 232 | * @return setter method for class |
252 | */ | 233 | */ |
... | @@ -265,8 +246,8 @@ public final class MethodsGenerator { | ... | @@ -265,8 +246,8 @@ public final class MethodsGenerator { |
265 | * Returns setter for attribute. | 246 | * Returns setter for attribute. |
266 | * | 247 | * |
267 | * @param className class name | 248 | * @param className class name |
268 | - * @param name attribute name | 249 | + * @param name attribute name |
269 | - * @param type return type | 250 | + * @param type return type |
270 | * @return setter for attribute | 251 | * @return setter for attribute |
271 | */ | 252 | */ |
272 | private static String getSetter(String className, String name, String type) { | 253 | private static String getSetter(String className, String name, String type) { |
... | @@ -316,9 +297,9 @@ public final class MethodsGenerator { | ... | @@ -316,9 +297,9 @@ public final class MethodsGenerator { |
316 | /** | 297 | /** |
317 | * Returns the getter method strings for interface file. | 298 | * Returns the getter method strings for interface file. |
318 | * | 299 | * |
319 | - * @param yangName name of the attribute | 300 | + * @param yangName name of the attribute |
320 | * @param returnType return type of attribute | 301 | * @param returnType return type of attribute |
321 | - * @param isList is list attribute | 302 | + * @param isList is list attribute |
322 | * @return getter method for interface | 303 | * @return getter method for interface |
323 | */ | 304 | */ |
324 | public static String getGetterForInterface(String yangName, String returnType, boolean isList) { | 305 | public static String getGetterForInterface(String yangName, String returnType, boolean isList) { |
... | @@ -334,7 +315,7 @@ public final class MethodsGenerator { | ... | @@ -334,7 +315,7 @@ public final class MethodsGenerator { |
334 | * Returns getter for attribute in interface. | 315 | * Returns getter for attribute in interface. |
335 | * | 316 | * |
336 | * @param returnType return type | 317 | * @param returnType return type |
337 | - * @param yangName attribute name | 318 | + * @param yangName attribute name |
338 | * @return getter for interface | 319 | * @return getter for interface |
339 | */ | 320 | */ |
340 | private static String getGetterInterfaceString(String returnType, String yangName) { | 321 | private static String getGetterInterfaceString(String returnType, String yangName) { |
... | @@ -345,10 +326,10 @@ public final class MethodsGenerator { | ... | @@ -345,10 +326,10 @@ public final class MethodsGenerator { |
345 | /** | 326 | /** |
346 | * Returns the setter method strings for interface file. | 327 | * Returns the setter method strings for interface file. |
347 | * | 328 | * |
348 | - * @param attrName name of the attribute | 329 | + * @param attrName name of the attribute |
349 | - * @param attrType return type of attribute | 330 | + * @param attrType return type of attribute |
350 | * @param className name of the java class being generated | 331 | * @param className name of the java class being generated |
351 | - * @param isList is list attribute | 332 | + * @param isList is list attribute |
352 | * @return setter method for interface | 333 | * @return setter method for interface |
353 | */ | 334 | */ |
354 | public static String getSetterForInterface(String attrName, String attrType, String className, boolean isList) { | 335 | public static String getSetterForInterface(String attrName, String attrType, String className, boolean isList) { |
... | @@ -364,8 +345,8 @@ public final class MethodsGenerator { | ... | @@ -364,8 +345,8 @@ public final class MethodsGenerator { |
364 | * Returns setter string for interface. | 345 | * Returns setter string for interface. |
365 | * | 346 | * |
366 | * @param className class name | 347 | * @param className class name |
367 | - * @param attrName attribute name | 348 | + * @param attrName attribute name |
368 | - * @param attrType attribute type | 349 | + * @param attrType attribute type |
369 | * @return setter string | 350 | * @return setter string |
370 | */ | 351 | */ |
371 | private static String getSetterInterfaceString(String className, String attrName, String attrType) { | 352 | private static String getSetterInterfaceString(String className, String attrName, String attrType) { |
... | @@ -428,7 +409,7 @@ public final class MethodsGenerator { | ... | @@ -428,7 +409,7 @@ public final class MethodsGenerator { |
428 | * Returns the constructor strings for class file. | 409 | * Returns the constructor strings for class file. |
429 | * | 410 | * |
430 | * @param yangName name of the class | 411 | * @param yangName name of the class |
431 | - * @param attr attribute info | 412 | + * @param attr attribute info |
432 | * @return constructor for class | 413 | * @return constructor for class |
433 | */ | 414 | */ |
434 | public static String getConstructor(String yangName, JavaAttributeInfo attr) { | 415 | public static String getConstructor(String yangName, JavaAttributeInfo attr) { |
... | @@ -459,7 +440,7 @@ public final class MethodsGenerator { | ... | @@ -459,7 +440,7 @@ public final class MethodsGenerator { |
459 | /** | 440 | /** |
460 | * Returns the Default constructor strings for class file. | 441 | * Returns the Default constructor strings for class file. |
461 | * | 442 | * |
462 | - * @param name name of the class | 443 | + * @param name name of the class |
463 | * @param modifierType modifier type for default constructor | 444 | * @param modifierType modifier type for default constructor |
464 | * @return Default constructor for class | 445 | * @return Default constructor for class |
465 | */ | 446 | */ |
... | @@ -469,9 +450,9 @@ public final class MethodsGenerator { | ... | @@ -469,9 +450,9 @@ public final class MethodsGenerator { |
469 | } | 450 | } |
470 | 451 | ||
471 | /** | 452 | /** |
472 | - * Returns to string method open strings. | 453 | + * Returns to string method's open strings. |
473 | * | 454 | * |
474 | - * @return to string method open string | 455 | + * @return string method's open string |
475 | */ | 456 | */ |
476 | public static String getToStringMethodOpen() { | 457 | public static String getToStringMethodOpen() { |
477 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO | 458 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO |
... | @@ -480,7 +461,16 @@ public final class MethodsGenerator { | ... | @@ -480,7 +461,16 @@ public final class MethodsGenerator { |
480 | } | 461 | } |
481 | 462 | ||
482 | /** | 463 | /** |
483 | - * Returns to string methods close string. | 464 | + * Returns omit null value string. |
465 | + * | ||
466 | + * @return omit null value string | ||
467 | + */ | ||
468 | + public static String getOmitNullValueString() { | ||
469 | + return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE; | ||
470 | + } | ||
471 | + | ||
472 | + /** | ||
473 | + * Returns to string method's close string. | ||
484 | * | 474 | * |
485 | * @return to string method close string | 475 | * @return to string method close string |
486 | */ | 476 | */ |
... | @@ -503,6 +493,90 @@ public final class MethodsGenerator { | ... | @@ -503,6 +493,90 @@ public final class MethodsGenerator { |
503 | } | 493 | } |
504 | 494 | ||
505 | /** | 495 | /** |
496 | + * Returns from string method's open string. | ||
497 | + * | ||
498 | + * @param className name of the class | ||
499 | + * @return from string method's open string | ||
500 | + */ | ||
501 | + public static String getFromStringMethodSignature(String className) { | ||
502 | + return getJavaDoc(UNION_FROM_METHOD, className, false) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE | ||
503 | + + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE | ||
504 | + + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
505 | + } | ||
506 | + | ||
507 | + /** | ||
508 | + * Return from string method's close string. | ||
509 | + * | ||
510 | + * @return from string method's close string | ||
511 | + */ | ||
512 | + public static String getFromStringMethodClose() { | ||
513 | + return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + | ||
514 | + CLOSE_CURLY_BRACKET + NEW_LINE; | ||
515 | + } | ||
516 | + | ||
517 | + /** | ||
518 | + * Return from string method's body string. | ||
519 | + * | ||
520 | + * @param attr attribute info | ||
521 | + * @param fromStringAttributeInfo attribute info for the from string | ||
522 | + * wrapper type | ||
523 | + * @return from string method's body string | ||
524 | + */ | ||
525 | + public static String getFromStringMethod(JavaAttributeInfo attr, | ||
526 | + JavaAttributeInfo fromStringAttributeInfo) { | ||
527 | + | ||
528 | + return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION | ||
529 | + + getParsedSubString(attr, fromStringAttributeInfo) + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION | ||
530 | + + getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString() | ||
531 | + + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
532 | + } | ||
533 | + | ||
534 | + /** | ||
535 | + * Returns sub string with try statement for union's from string method. | ||
536 | + * | ||
537 | + * @return sub string with try statement for union's from string method | ||
538 | + */ | ||
539 | + public static String getTrySubString() { | ||
540 | + return TRY + SPACE + OPEN_CURLY_BRACKET; | ||
541 | + } | ||
542 | + | ||
543 | + /** | ||
544 | + * Returns sub string with return statement for union's from string method. | ||
545 | + * | ||
546 | + * @return sub string with return statement for union's from string method | ||
547 | + */ | ||
548 | + public static String getReturnOfSubString() { | ||
549 | + return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN; | ||
550 | + } | ||
551 | + | ||
552 | + /** | ||
553 | + * Returns sub string with catch statement for union's from string method. | ||
554 | + * | ||
555 | + * @return sub string with catch statement for union's from string method | ||
556 | + */ | ||
557 | + public static String getCatchSubString() { | ||
558 | + return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR | ||
559 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET; | ||
560 | + } | ||
561 | + | ||
562 | + /** | ||
563 | + * Returns sub string with parsed statement for union's from string method. | ||
564 | + * | ||
565 | + * @param attr attribute info | ||
566 | + * @return sub string with parsed statement for union's from string method | ||
567 | + */ | ||
568 | + private static String getParsedSubString(JavaAttributeInfo attr, | ||
569 | + JavaAttributeInfo fromStringAttributeInfo) { | ||
570 | + | ||
571 | + String targetDataType = getReturnType(attr); | ||
572 | + String parseFromStringMethod = getParseFromStringMethod(targetDataType, | ||
573 | + fromStringAttributeInfo.getAttributeType()); | ||
574 | + return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod | ||
575 | + + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS; | ||
576 | + } | ||
577 | + | ||
578 | + | ||
579 | + /** | ||
506 | * Returns hash code method open strings. | 580 | * Returns hash code method open strings. |
507 | * | 581 | * |
508 | * @return hash code method open string | 582 | * @return hash code method open string |
... | @@ -611,9 +685,10 @@ public final class MethodsGenerator { | ... | @@ -611,9 +685,10 @@ public final class MethodsGenerator { |
611 | */ | 685 | */ |
612 | public static String getOfMethod(String name, JavaAttributeInfo attr) { | 686 | public static String getOfMethod(String name, JavaAttributeInfo attr) { |
613 | 687 | ||
614 | - String attrQuaifiedType = getReturnType(attr); | 688 | + String attrQualifiedType = getReturnType(attr); |
689 | + | ||
615 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS | 690 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS |
616 | - + attrQuaifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | 691 | + + attrQualifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
617 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE | 692 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE |
618 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; | 693 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
619 | } | 694 | } |
... | @@ -635,6 +710,69 @@ public final class MethodsGenerator { | ... | @@ -635,6 +710,69 @@ public final class MethodsGenerator { |
635 | } | 710 | } |
636 | 711 | ||
637 | /** | 712 | /** |
713 | + * Returns of method's string and java doc for special type. | ||
714 | + * | ||
715 | + * @param attr attribute info | ||
716 | + * @param generatedJavaClassName class name | ||
717 | + * @return of method's string and java doc for special type | ||
718 | + */ | ||
719 | + public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) { | ||
720 | + | ||
721 | + String attrType = getReturnType(attr); | ||
722 | + String attrName = getSmallCase(attr.getAttributeName()); | ||
723 | + | ||
724 | + return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false) | ||
725 | + + getOfMethodString(attrType, generatedJavaClassName); | ||
726 | + } | ||
727 | + | ||
728 | + /** | ||
729 | + * Returns of method's string. | ||
730 | + * | ||
731 | + * @param type data type | ||
732 | + * @param className class name | ||
733 | + * @return of method's string | ||
734 | + */ | ||
735 | + private static String getOfMethodString(String type, String className) { | ||
736 | + | ||
737 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS | ||
738 | + + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | ||
739 | + + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE | ||
740 | + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
741 | + } | ||
742 | + | ||
743 | + /** | ||
744 | + * Returns string and java doc for constructor of type class. | ||
745 | + * | ||
746 | + * @param attr attribute info | ||
747 | + * @param generatedJavaClassName class name | ||
748 | + * @return string and java doc for constructor of type class | ||
749 | + */ | ||
750 | + public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName) { | ||
751 | + | ||
752 | + String attrType = getReturnType(attr); | ||
753 | + String attrName = getSmallCase(attr.getAttributeName()); | ||
754 | + | ||
755 | + return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false) | ||
756 | + + getTypeConstructorString(attrType, attrName, generatedJavaClassName); | ||
757 | + } | ||
758 | + | ||
759 | + /** | ||
760 | + * Returns type constructor string. | ||
761 | + * | ||
762 | + * @param type data type | ||
763 | + * @param name attribute name | ||
764 | + * @param className class name | ||
765 | + * @return type constructor string | ||
766 | + */ | ||
767 | + private static String getTypeConstructorString(String type, String name, String className) { | ||
768 | + | ||
769 | + return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE | ||
770 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD | ||
771 | + + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION | ||
772 | + + CLOSE_CURLY_BRACKET; | ||
773 | + } | ||
774 | + | ||
775 | + /** | ||
638 | * Returns implementation of get augment info list method of HasAugmentation class. | 776 | * Returns implementation of get augment info list method of HasAugmentation class. |
639 | * | 777 | * |
640 | * @return implementation of get augment info list method of HasAugmentation class | 778 | * @return implementation of get augment info list method of HasAugmentation class |
... | @@ -660,7 +798,7 @@ public final class MethodsGenerator { | ... | @@ -660,7 +798,7 @@ public final class MethodsGenerator { |
660 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove" | 798 | method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove" |
661 | + AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | 799 | + AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
662 | + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS | 800 | + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS |
663 | - + CLOSE_PARENTHESIS + PERIOD + "clear" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE | 801 | + + CLOSE_PARENTHESIS + PERIOD + CLEAR + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE |
664 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 802 | + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
665 | return method; | 803 | return method; |
666 | } | 804 | } | ... | ... |
... | @@ -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 | ... | ... |
-
Please register or login to post a comment