Committed by
Gerrit Code Review
[ONOS-4286],[ONOS-3911] YANG typedef and YANG augment
translator implementation. Change-Id: I3e21d1cb52bcb90b935b672eee42b836c21f448b
Showing
29 changed files
with
930 additions
and
330 deletions
... | @@ -17,11 +17,13 @@ | ... | @@ -17,11 +17,13 @@ |
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | import java.util.List; | 19 | import java.util.List; |
20 | + | ||
20 | import org.onosproject.yangutils.datamodel.YangAugment; | 21 | import org.onosproject.yangutils.datamodel.YangAugment; |
21 | -import org.onosproject.yangutils.datamodel.YangNode; | ||
22 | import org.onosproject.yangutils.datamodel.YangModule; | 22 | import org.onosproject.yangutils.datamodel.YangModule; |
23 | -import org.onosproject.yangutils.datamodel.YangSubModule; | 23 | +import org.onosproject.yangutils.datamodel.YangNode; |
24 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; | 24 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
25 | +import org.onosproject.yangutils.datamodel.YangSubModule; | ||
26 | +import org.onosproject.yangutils.datamodel.YangUses; | ||
25 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 27 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
26 | import org.onosproject.yangutils.parser.Parsable; | 28 | import org.onosproject.yangutils.parser.Parsable; |
27 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 29 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
... | @@ -35,21 +37,22 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc | ... | @@ -35,21 +37,22 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc |
35 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
40 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | ||
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 43 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
41 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 44 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId; |
42 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
43 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne; |
44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; | 47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds; |
45 | -import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId; | 48 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
46 | import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA; | 49 | import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA; |
50 | +import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; | ||
47 | import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA; | 51 | import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA; |
48 | -import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | ||
49 | -import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | ||
50 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; | 52 | import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA; |
53 | +import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA; | ||
54 | +import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | ||
51 | import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA; | 55 | import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA; |
52 | -import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; | ||
53 | 56 | ||
54 | /* | 57 | /* |
55 | * Reference: RFC6020 and YANG ANTLR Grammar | 58 | * Reference: RFC6020 and YANG ANTLR Grammar |
... | @@ -73,11 +76,13 @@ import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; | ... | @@ -73,11 +76,13 @@ import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA; |
73 | */ | 76 | */ |
74 | 77 | ||
75 | /** | 78 | /** |
76 | - * Implements listener based call back function corresponding to the "augment" | 79 | + * Represents listener based call back function corresponding to the "augment" |
77 | * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. | 80 | * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020. |
78 | */ | 81 | */ |
79 | public final class AugmentListener { | 82 | public final class AugmentListener { |
80 | 83 | ||
84 | + private static final String AUGMENTED = "Augmented"; | ||
85 | + | ||
81 | /** | 86 | /** |
82 | * Creates a new augment listener. | 87 | * Creates a new augment listener. |
83 | */ | 88 | */ |
... | @@ -110,11 +115,12 @@ public final class AugmentListener { | ... | @@ -110,11 +115,12 @@ public final class AugmentListener { |
110 | detectCollidingChildUtil(listener, line, charPositionInLine, "", AUGMENT_DATA); | 115 | detectCollidingChildUtil(listener, line, charPositionInLine, "", AUGMENT_DATA); |
111 | 116 | ||
112 | Parsable curData = listener.getParsedDataStack().peek(); | 117 | Parsable curData = listener.getParsedDataStack().peek(); |
113 | - if (curData instanceof YangModule || curData instanceof YangSubModule) { | 118 | + if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) { |
114 | 119 | ||
115 | YangNode curNode = (YangNode) curData; | 120 | YangNode curNode = (YangNode) curData; |
116 | YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION); | 121 | YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION); |
117 | yangAugment.setTargetNode(targetNodes); | 122 | yangAugment.setTargetNode(targetNodes); |
123 | + yangAugment.setName(getValidNameForAugment(targetNodes)); | ||
118 | try { | 124 | try { |
119 | curNode.addChild(yangAugment); | 125 | curNode.addChild(yangAugment); |
120 | } catch (DataModelException e) { | 126 | } catch (DataModelException e) { |
... | @@ -163,4 +169,30 @@ public final class AugmentListener { | ... | @@ -163,4 +169,30 @@ public final class AugmentListener { |
163 | validateMutuallyExclusiveChilds(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(), | 169 | validateMutuallyExclusiveChilds(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(), |
164 | CASE_DATA, AUGMENT_DATA, ctx.augment().getText()); | 170 | CASE_DATA, AUGMENT_DATA, ctx.augment().getText()); |
165 | } | 171 | } |
172 | + | ||
173 | + /** | ||
174 | + * Returns a name identifier for augment. | ||
175 | + * | ||
176 | + * @param targetNode list of target nodes | ||
177 | + * @return name identifier | ||
178 | + */ | ||
179 | + private static String getValidNameForAugment(List<YangNodeIdentifier> targetNodes) { | ||
180 | + String name = ""; | ||
181 | + YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1); | ||
182 | + | ||
183 | + if (nodeId.getPrefix() != null) { | ||
184 | + name = AUGMENTED + getCaptialCase(nodeId.getPrefix()) + getCaptialCase(nodeId.getName()); | ||
185 | + } else { | ||
186 | + //TODO: name = name + ((HasAugmentation)getParentNode()).getAugmentPrefix(nodeId); | ||
187 | + } | ||
188 | + return name; | ||
189 | + } | ||
190 | + | ||
191 | + /** | ||
192 | + * Validates for the child nodes of augment node. | ||
193 | + */ | ||
194 | + private static void validateForChildNodes() { | ||
195 | + //TODO: implement with linker. | ||
196 | + return; | ||
197 | + } | ||
166 | } | 198 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentedInfo.java
0 → 100644
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; | ||
18 | + | ||
19 | +/** | ||
20 | + * Abstraction of an entity which represents augmented info. | ||
21 | + */ | ||
22 | +public interface AugmentedInfo { | ||
23 | +} |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/HasAugmentation.java
0 → 100644
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; | ||
18 | + | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +/** | ||
22 | + * Abstraction of an entity which represents augmentation of a YANG node. | ||
23 | + */ | ||
24 | +public interface HasAugmentation { | ||
25 | + | ||
26 | + /** | ||
27 | + * Adds augment info to the augment info list. | ||
28 | + * | ||
29 | + * @param augmentInfo augment info of node | ||
30 | + */ | ||
31 | + void addAugmentation(AugmentedInfo augmentInfo); | ||
32 | + | ||
33 | + /** | ||
34 | + * Removes augment info from the node. | ||
35 | + */ | ||
36 | + void removeAugmentation(); | ||
37 | + | ||
38 | + /** | ||
39 | + * Returns list of augment info. | ||
40 | + * | ||
41 | + * @return list of augment info | ||
42 | + */ | ||
43 | + List<AugmentedInfo> getAugmentedInfoList(); | ||
44 | +} |
... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava; | ... | @@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava; |
19 | import org.onosproject.yangutils.datamodel.YangNode; | 19 | import org.onosproject.yangutils.datamodel.YangNode; |
20 | import org.onosproject.yangutils.datamodel.YangType; | 20 | import org.onosproject.yangutils.datamodel.YangType; |
21 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 21 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
22 | -import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType; | ||
23 | 22 | ||
24 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; | 23 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList; |
25 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; | 24 | import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; |
... | @@ -163,7 +162,7 @@ public final class JavaAttributeInfo { | ... | @@ -163,7 +162,7 @@ public final class JavaAttributeInfo { |
163 | } | 162 | } |
164 | 163 | ||
165 | /** | 164 | /** |
166 | - * Returns the import info for the attribute type. It will be null, of the type | 165 | + * Returns the import info for the attribute type. It will be null, if the type |
167 | * is basic built-in java type. | 166 | * is basic built-in java type. |
168 | * | 167 | * |
169 | * @return import info | 168 | * @return import info |
... | @@ -255,7 +254,6 @@ public final class JavaAttributeInfo { | ... | @@ -255,7 +254,6 @@ public final class JavaAttributeInfo { |
255 | */ | 254 | */ |
256 | JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, | 255 | JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode, |
257 | attributeType, attributeName, isListAttribute); | 256 | attributeType, attributeName, isListAttribute); |
258 | - AttributesJavaDataType.addImportInfo(importInfo); | ||
259 | 257 | ||
260 | return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute); | 258 | return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute); |
261 | } | 259 | } | ... | ... |
... | @@ -16,8 +16,6 @@ | ... | @@ -16,8 +16,6 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava; | 17 | package org.onosproject.yangutils.translator.tojava; |
18 | 18 | ||
19 | -import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
20 | - | ||
21 | /** | 19 | /** |
22 | * Represents cached java file handle, which supports the addition of member attributes and | 20 | * Represents cached java file handle, which supports the addition of member attributes and |
23 | * methods. | 21 | * methods. |
... | @@ -36,7 +34,7 @@ public class JavaFileInfo { | ... | @@ -36,7 +34,7 @@ public class JavaFileInfo { |
36 | private String javaName; | 34 | private String javaName; |
37 | 35 | ||
38 | /** | 36 | /** |
39 | - * java Package of the mapped java class. | 37 | + * Java Package of the mapped java class. |
40 | */ | 38 | */ |
41 | private String pkg; | 39 | private String pkg; |
42 | 40 | ||
... | @@ -96,10 +94,6 @@ public class JavaFileInfo { | ... | @@ -96,10 +94,6 @@ public class JavaFileInfo { |
96 | * @return the java package | 94 | * @return the java package |
97 | */ | 95 | */ |
98 | public String getPackage() { | 96 | public String getPackage() { |
99 | - | ||
100 | - if (pkg == null) { | ||
101 | - throw new TranslatorException("Referencing package of a generated java file which is not set"); | ||
102 | - } | ||
103 | return pkg; | 97 | return pkg; |
104 | } | 98 | } |
105 | 99 | ... | ... |
... | @@ -24,10 +24,15 @@ import static java.util.Collections.sort; | ... | @@ -24,10 +24,15 @@ import static java.util.Collections.sort; |
24 | import org.onosproject.yangutils.datamodel.YangNode; | 24 | import org.onosproject.yangutils.datamodel.YangNode; |
25 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 25 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
26 | 26 | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; | ||
28 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG; | ||
27 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
29 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS; |
30 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG; |
34 | +import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_CLASS; | ||
35 | +import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_PKG; | ||
31 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
32 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; |
33 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS; |
... | @@ -88,7 +93,7 @@ public class JavaImportData { | ... | @@ -88,7 +93,7 @@ public class JavaImportData { |
88 | } | 93 | } |
89 | 94 | ||
90 | /** | 95 | /** |
91 | - * Assign the set containing the imported class/interface info. | 96 | + * Assigns the set containing the imported class/interface info. |
92 | * | 97 | * |
93 | * @param importSet the set containing the imported class/interface info | 98 | * @param importSet the set containing the imported class/interface info |
94 | */ | 99 | */ |
... | @@ -97,7 +102,7 @@ public class JavaImportData { | ... | @@ -97,7 +102,7 @@ public class JavaImportData { |
97 | } | 102 | } |
98 | 103 | ||
99 | /** | 104 | /** |
100 | - * Add an imported class/interface info if it is not already part of the | 105 | + * Adds an imported class/interface info if it is not already part of the |
101 | * collection. | 106 | * collection. |
102 | * | 107 | * |
103 | * If already part of the collection, check if the packages are same, if so | 108 | * If already part of the collection, check if the packages are same, if so |
... | @@ -177,10 +182,36 @@ public class JavaImportData { | ... | @@ -177,10 +182,36 @@ public class JavaImportData { |
177 | /** | 182 | /** |
178 | * Returns import for list attribute. | 183 | * Returns import for list attribute. |
179 | * | 184 | * |
180 | - * @return import for for list attribute | 185 | + * @return import for list attribute |
181 | */ | 186 | */ |
182 | - | 187 | + public static String getImportForList() { |
183 | - private static String getImportForList() { | ||
184 | return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; | 188 | return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE; |
185 | } | 189 | } |
190 | + | ||
191 | + /** | ||
192 | + * Returns import for array list attribute. | ||
193 | + * | ||
194 | + * @return import for array list attribute | ||
195 | + */ | ||
196 | + public static String getImportForArrayList() { | ||
197 | + return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE; | ||
198 | + } | ||
199 | + | ||
200 | + /** | ||
201 | + * Returns import string for HasAugmentation class. | ||
202 | + * | ||
203 | + * @return import string for HasAugmentation class | ||
204 | + */ | ||
205 | + public static String getHasAugmentationImport() { | ||
206 | + return IMPORT + HAS_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + HAS_AUGMENTATION_CLASS_IMPORT_CLASS; | ||
207 | + } | ||
208 | + | ||
209 | + /** | ||
210 | + * Returns import string for AugmentedInfo class. | ||
211 | + * | ||
212 | + * @return import string for AugmentedInfo class | ||
213 | + */ | ||
214 | + public static String getAugmentedInfoImport() { | ||
215 | + return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS; | ||
216 | + } | ||
186 | } | 217 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
... | @@ -87,11 +87,11 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -87,11 +87,11 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
87 | * generation for import or for qualified access. | 87 | * generation for import or for qualified access. |
88 | * | 88 | * |
89 | * @param curNode current data model node for which the java file is being | 89 | * @param curNode current data model node for which the java file is being |
90 | - * generated. | 90 | + * generated |
91 | * @param attrType type of attribute being added, it will be null, when the | 91 | * @param attrType type of attribute being added, it will be null, when the |
92 | * child class is added as an attribute | 92 | * child class is added as an attribute |
93 | * @param attributeName name of the attribute being added, it will used in | 93 | * @param attributeName name of the attribute being added, it will used in |
94 | - * import info for child class. | 94 | + * import info for child class |
95 | * @param isListAttr is the added attribute going to be used as a list | 95 | * @param isListAttr is the added attribute going to be used as a list |
96 | * @return return the import info for this attribute | 96 | * @return return the import info for this attribute |
97 | */ | 97 | */ |
... | @@ -140,9 +140,9 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -140,9 +140,9 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
140 | * generation for import or for qualified access. | 140 | * generation for import or for qualified access. |
141 | * | 141 | * |
142 | * @param curNode current data model node for which the java file is being | 142 | * @param curNode current data model node for which the java file is being |
143 | - * generated. | 143 | + * generated |
144 | * @param attributeName name of the attribute being added, it will used in | 144 | * @param attributeName name of the attribute being added, it will used in |
145 | - * import info for child class. | 145 | + * import info for child class |
146 | * @param isListAttr is the added attribute going to be used as a list | 146 | * @param isListAttr is the added attribute going to be used as a list |
147 | * @return return the import info for this attribute | 147 | * @return return the import info for this attribute |
148 | */ | 148 | */ |
... | @@ -241,8 +241,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -241,8 +241,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
241 | throw new TranslatorException("missing java file info for the data model node"); | 241 | throw new TranslatorException("missing java file info for the data model node"); |
242 | } | 242 | } |
243 | return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage() | 243 | return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage() |
244 | - .contentEquals(importInfo.getPkgInfo() | 244 | + .contentEquals(importInfo.getPkgInfo()); |
245 | - + "." + importInfo.getClassInfo()); | ||
246 | } | 245 | } |
247 | 246 | ||
248 | @Override | 247 | @Override |
... | @@ -265,7 +264,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> | ... | @@ -265,7 +264,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo> |
265 | } | 264 | } |
266 | 265 | ||
267 | /** | 266 | /** |
268 | - * checks if the import info matches. | 267 | + * Checks if the import info matches. |
269 | * | 268 | * |
270 | * @param importInfo matched import | 269 | * @param importInfo matched import |
271 | * @return if equal or not | 270 | * @return if equal or not | ... | ... |
... | @@ -30,7 +30,6 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; | ... | @@ -30,7 +30,6 @@ 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_INTERFACE_WITH_BUILDER; | ||
34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; |
... | @@ -74,6 +73,14 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -74,6 +73,14 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; | 73 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod; |
75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeDefConstructor; | 74 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeDefConstructor; |
76 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; | 75 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString; |
76 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport; | ||
77 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport; | ||
78 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport; | ||
79 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addImportsToStringAndHasCodeMethods; | ||
80 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | ||
81 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended; | ||
82 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; | ||
83 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList; | ||
77 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 84 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
78 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 85 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
79 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 86 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
... | @@ -84,7 +91,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ... | @@ -84,7 +91,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
84 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 91 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
85 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 92 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
86 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; | 93 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile; |
87 | -import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | ||
88 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | 94 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
89 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 95 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
90 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; | 96 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD; |
... | @@ -122,6 +128,11 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -122,6 +128,11 @@ public class TempJavaCodeFragmentFiles { |
122 | private String generatedJavaClassName; | 128 | private String generatedJavaClassName; |
123 | 129 | ||
124 | /** | 130 | /** |
131 | + * Contains all the class name which will be extended by generated files. | ||
132 | + */ | ||
133 | + private List<String> extendsList = new ArrayList<>(); | ||
134 | + | ||
135 | + /** | ||
125 | * File type extension for java classes. | 136 | * File type extension for java classes. |
126 | */ | 137 | */ |
127 | private static final String JAVA_FILE_EXTENSION = ".java"; | 138 | private static final String JAVA_FILE_EXTENSION = ".java"; |
... | @@ -302,6 +313,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -302,6 +313,7 @@ public class TempJavaCodeFragmentFiles { |
302 | public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className) | 313 | public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className) |
303 | throws IOException { | 314 | throws IOException { |
304 | 315 | ||
316 | + setExtendsList(new ArrayList<>()); | ||
305 | generatedTempFiles = 0; | 317 | generatedTempFiles = 0; |
306 | absoluteDirPath = genDir; | 318 | absoluteDirPath = genDir; |
307 | generatedJavaClassName = className; | 319 | generatedJavaClassName = className; |
... | @@ -399,7 +411,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -399,7 +411,7 @@ public class TempJavaCodeFragmentFiles { |
399 | * | 411 | * |
400 | * @return java file handle for interface file | 412 | * @return java file handle for interface file |
401 | */ | 413 | */ |
402 | - public File getInterfaceJavaFileHandle() { | 414 | + private File getInterfaceJavaFileHandle() { |
403 | return interfaceJavaFileHandle; | 415 | return interfaceJavaFileHandle; |
404 | } | 416 | } |
405 | 417 | ||
... | @@ -408,7 +420,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -408,7 +420,7 @@ public class TempJavaCodeFragmentFiles { |
408 | * | 420 | * |
409 | * @param interfaceJavaFileHandle java file handle | 421 | * @param interfaceJavaFileHandle java file handle |
410 | */ | 422 | */ |
411 | - public void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { | 423 | + private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) { |
412 | this.interfaceJavaFileHandle = interfaceJavaFileHandle; | 424 | this.interfaceJavaFileHandle = interfaceJavaFileHandle; |
413 | } | 425 | } |
414 | 426 | ||
... | @@ -417,7 +429,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -417,7 +429,7 @@ public class TempJavaCodeFragmentFiles { |
417 | * | 429 | * |
418 | * @return java file handle for builder interface file | 430 | * @return java file handle for builder interface file |
419 | */ | 431 | */ |
420 | - public File getBuilderInterfaceJavaFileHandle() { | 432 | + private File getBuilderInterfaceJavaFileHandle() { |
421 | return builderInterfaceJavaFileHandle; | 433 | return builderInterfaceJavaFileHandle; |
422 | } | 434 | } |
423 | 435 | ||
... | @@ -426,7 +438,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -426,7 +438,7 @@ public class TempJavaCodeFragmentFiles { |
426 | * | 438 | * |
427 | * @param builderInterfaceJavaFileHandle java file handle | 439 | * @param builderInterfaceJavaFileHandle java file handle |
428 | */ | 440 | */ |
429 | - public void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { | 441 | + private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) { |
430 | this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; | 442 | this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle; |
431 | } | 443 | } |
432 | 444 | ||
... | @@ -435,7 +447,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -435,7 +447,7 @@ public class TempJavaCodeFragmentFiles { |
435 | * | 447 | * |
436 | * @return java file handle for builder class file | 448 | * @return java file handle for builder class file |
437 | */ | 449 | */ |
438 | - public File getBuilderClassJavaFileHandle() { | 450 | + private File getBuilderClassJavaFileHandle() { |
439 | return builderClassJavaFileHandle; | 451 | return builderClassJavaFileHandle; |
440 | } | 452 | } |
441 | 453 | ||
... | @@ -444,7 +456,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -444,7 +456,7 @@ public class TempJavaCodeFragmentFiles { |
444 | * | 456 | * |
445 | * @param builderClassJavaFileHandle java file handle | 457 | * @param builderClassJavaFileHandle java file handle |
446 | */ | 458 | */ |
447 | - public void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { | 459 | + private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) { |
448 | this.builderClassJavaFileHandle = builderClassJavaFileHandle; | 460 | this.builderClassJavaFileHandle = builderClassJavaFileHandle; |
449 | } | 461 | } |
450 | 462 | ||
... | @@ -453,7 +465,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -453,7 +465,7 @@ public class TempJavaCodeFragmentFiles { |
453 | * | 465 | * |
454 | * @return java file handle for impl class file | 466 | * @return java file handle for impl class file |
455 | */ | 467 | */ |
456 | - public File getImplClassJavaFileHandle() { | 468 | + private File getImplClassJavaFileHandle() { |
457 | return implClassJavaFileHandle; | 469 | return implClassJavaFileHandle; |
458 | } | 470 | } |
459 | 471 | ||
... | @@ -462,7 +474,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -462,7 +474,7 @@ public class TempJavaCodeFragmentFiles { |
462 | * | 474 | * |
463 | * @param implClassJavaFileHandle java file handle | 475 | * @param implClassJavaFileHandle java file handle |
464 | */ | 476 | */ |
465 | - public void setImplClassJavaFileHandle(File implClassJavaFileHandle) { | 477 | + private void setImplClassJavaFileHandle(File implClassJavaFileHandle) { |
466 | this.implClassJavaFileHandle = implClassJavaFileHandle; | 478 | this.implClassJavaFileHandle = implClassJavaFileHandle; |
467 | } | 479 | } |
468 | 480 | ||
... | @@ -471,7 +483,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -471,7 +483,7 @@ public class TempJavaCodeFragmentFiles { |
471 | * | 483 | * |
472 | * @return java file handle for typedef class file | 484 | * @return java file handle for typedef class file |
473 | */ | 485 | */ |
474 | - public File getTypedefClassJavaFileHandle() { | 486 | + private File getTypedefClassJavaFileHandle() { |
475 | return typedefClassJavaFileHandle; | 487 | return typedefClassJavaFileHandle; |
476 | } | 488 | } |
477 | 489 | ||
... | @@ -480,7 +492,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -480,7 +492,7 @@ public class TempJavaCodeFragmentFiles { |
480 | * | 492 | * |
481 | * @param typedefClassJavaFileHandle java file handle | 493 | * @param typedefClassJavaFileHandle java file handle |
482 | */ | 494 | */ |
483 | - public void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) { | 495 | + private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) { |
484 | this.typedefClassJavaFileHandle = typedefClassJavaFileHandle; | 496 | this.typedefClassJavaFileHandle = typedefClassJavaFileHandle; |
485 | } | 497 | } |
486 | 498 | ||
... | @@ -498,7 +510,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -498,7 +510,7 @@ public class TempJavaCodeFragmentFiles { |
498 | * | 510 | * |
499 | * @param attributeForClass file handle for attribute | 511 | * @param attributeForClass file handle for attribute |
500 | */ | 512 | */ |
501 | - public void setAttributesTempFileHandle(File attributeForClass) { | 513 | + private void setAttributesTempFileHandle(File attributeForClass) { |
502 | attributesTempFileHandle = attributeForClass; | 514 | attributesTempFileHandle = attributeForClass; |
503 | } | 515 | } |
504 | 516 | ||
... | @@ -516,7 +528,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -516,7 +528,7 @@ public class TempJavaCodeFragmentFiles { |
516 | * | 528 | * |
517 | * @param getterForInterface file handle for to getter method | 529 | * @param getterForInterface file handle for to getter method |
518 | */ | 530 | */ |
519 | - public void setGetterInterfaceTempFileHandle(File getterForInterface) { | 531 | + private void setGetterInterfaceTempFileHandle(File getterForInterface) { |
520 | getterInterfaceTempFileHandle = getterForInterface; | 532 | getterInterfaceTempFileHandle = getterForInterface; |
521 | } | 533 | } |
522 | 534 | ||
... | @@ -534,7 +546,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -534,7 +546,7 @@ public class TempJavaCodeFragmentFiles { |
534 | * | 546 | * |
535 | * @param getterImpl file handle for to getter method's impl | 547 | * @param getterImpl file handle for to getter method's impl |
536 | */ | 548 | */ |
537 | - public void setGetterImplTempFileHandle(File getterImpl) { | 549 | + private void setGetterImplTempFileHandle(File getterImpl) { |
538 | getterImplTempFileHandle = getterImpl; | 550 | getterImplTempFileHandle = getterImpl; |
539 | } | 551 | } |
540 | 552 | ||
... | @@ -552,7 +564,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -552,7 +564,7 @@ public class TempJavaCodeFragmentFiles { |
552 | * | 564 | * |
553 | * @param setterForInterface file handle for to setter method | 565 | * @param setterForInterface file handle for to setter method |
554 | */ | 566 | */ |
555 | - public void setSetterInterfaceTempFileHandle(File setterForInterface) { | 567 | + private void setSetterInterfaceTempFileHandle(File setterForInterface) { |
556 | setterInterfaceTempFileHandle = setterForInterface; | 568 | setterInterfaceTempFileHandle = setterForInterface; |
557 | } | 569 | } |
558 | 570 | ||
... | @@ -570,7 +582,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -570,7 +582,7 @@ public class TempJavaCodeFragmentFiles { |
570 | * | 582 | * |
571 | * @param setterImpl file handle for to setter method's implementation class | 583 | * @param setterImpl file handle for to setter method's implementation class |
572 | */ | 584 | */ |
573 | - public void setSetterImplTempFileHandle(File setterImpl) { | 585 | + private void setSetterImplTempFileHandle(File setterImpl) { |
574 | setterImplTempFileHandle = setterImpl; | 586 | setterImplTempFileHandle = setterImpl; |
575 | } | 587 | } |
576 | 588 | ||
... | @@ -588,7 +600,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -588,7 +600,7 @@ public class TempJavaCodeFragmentFiles { |
588 | * | 600 | * |
589 | * @param constructor file handle for to constructor | 601 | * @param constructor file handle for to constructor |
590 | */ | 602 | */ |
591 | - public void setConstructorImplTempFileHandle(File constructor) { | 603 | + private void setConstructorImplTempFileHandle(File constructor) { |
592 | constructorImplTempFileHandle = constructor; | 604 | constructorImplTempFileHandle = constructor; |
593 | } | 605 | } |
594 | 606 | ||
... | @@ -606,7 +618,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -606,7 +618,7 @@ public class TempJavaCodeFragmentFiles { |
606 | * | 618 | * |
607 | * @param hashCodeMethod file handle for hash code method | 619 | * @param hashCodeMethod file handle for hash code method |
608 | */ | 620 | */ |
609 | - public void setHashCodeImplTempFileHandle(File hashCodeMethod) { | 621 | + private void setHashCodeImplTempFileHandle(File hashCodeMethod) { |
610 | hashCodeImplTempFileHandle = hashCodeMethod; | 622 | hashCodeImplTempFileHandle = hashCodeMethod; |
611 | } | 623 | } |
612 | 624 | ||
... | @@ -624,7 +636,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -624,7 +636,7 @@ public class TempJavaCodeFragmentFiles { |
624 | * | 636 | * |
625 | * @param equalsMethod file handle for to equals method | 637 | * @param equalsMethod file handle for to equals method |
626 | */ | 638 | */ |
627 | - public void setEqualsImplTempFileHandle(File equalsMethod) { | 639 | + private void setEqualsImplTempFileHandle(File equalsMethod) { |
628 | equalsImplTempFileHandle = equalsMethod; | 640 | equalsImplTempFileHandle = equalsMethod; |
629 | } | 641 | } |
630 | 642 | ||
... | @@ -642,7 +654,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -642,7 +654,7 @@ public class TempJavaCodeFragmentFiles { |
642 | * | 654 | * |
643 | * @param toStringMethod file handle for to string method | 655 | * @param toStringMethod file handle for to string method |
644 | */ | 656 | */ |
645 | - public void setToStringImplTempFileHandle(File toStringMethod) { | 657 | + private void setToStringImplTempFileHandle(File toStringMethod) { |
646 | toStringImplTempFileHandle = toStringMethod; | 658 | toStringImplTempFileHandle = toStringMethod; |
647 | } | 659 | } |
648 | 660 | ||
... | @@ -651,7 +663,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -651,7 +663,7 @@ public class TempJavaCodeFragmentFiles { |
651 | * | 663 | * |
652 | * @return java attribute info | 664 | * @return java attribute info |
653 | */ | 665 | */ |
654 | - public JavaAttributeInfo getNewAttrInfo() { | 666 | + private JavaAttributeInfo getNewAttrInfo() { |
655 | return newAttrInfo; | 667 | return newAttrInfo; |
656 | } | 668 | } |
657 | 669 | ||
... | @@ -660,7 +672,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -660,7 +672,7 @@ public class TempJavaCodeFragmentFiles { |
660 | * | 672 | * |
661 | * @param newAttrInfo java attribute info | 673 | * @param newAttrInfo java attribute info |
662 | */ | 674 | */ |
663 | - public void setNewAttrInfo(JavaAttributeInfo newAttrInfo) { | 675 | + private void setNewAttrInfo(JavaAttributeInfo newAttrInfo) { |
664 | 676 | ||
665 | if (newAttrInfo != null) { | 677 | if (newAttrInfo != null) { |
666 | isAttributePresent = true; | 678 | isAttributePresent = true; |
... | @@ -673,7 +685,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -673,7 +685,7 @@ public class TempJavaCodeFragmentFiles { |
673 | * | 685 | * |
674 | * @return current YANG node | 686 | * @return current YANG node |
675 | */ | 687 | */ |
676 | - public YangNode getCurYangNode() { | 688 | + private YangNode getCurYangNode() { |
677 | return curYangNode; | 689 | return curYangNode; |
678 | } | 690 | } |
679 | 691 | ||
... | @@ -682,17 +694,45 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -682,17 +694,45 @@ public class TempJavaCodeFragmentFiles { |
682 | * | 694 | * |
683 | * @param curYangNode YANG node | 695 | * @param curYangNode YANG node |
684 | */ | 696 | */ |
685 | - public void setCurYangNode(YangNode curYangNode) { | 697 | + private void setCurYangNode(YangNode curYangNode) { |
686 | this.curYangNode = curYangNode; | 698 | this.curYangNode = curYangNode; |
687 | } | 699 | } |
688 | 700 | ||
689 | /** | 701 | /** |
702 | + * Returns list of classes to be extended by generated files. | ||
703 | + * | ||
704 | + * @return list of classes to be extended by generated files | ||
705 | + */ | ||
706 | + private List<String> getExtendsList() { | ||
707 | + return extendsList; | ||
708 | + } | ||
709 | + | ||
710 | + /** | ||
711 | + * Sets class to be extended by generated file. | ||
712 | + * | ||
713 | + * @param extendsList list of classes to be extended | ||
714 | + */ | ||
715 | + | ||
716 | + private void setExtendsList(List<String> extendsList) { | ||
717 | + this.extendsList = extendsList; | ||
718 | + } | ||
719 | + | ||
720 | + /** | ||
721 | + * Adds class to the extends list. | ||
722 | + * | ||
723 | + * @param extend class to be extended | ||
724 | + */ | ||
725 | + public void addToExtendsList(String extend) { | ||
726 | + getExtendsList().add(extend); | ||
727 | + } | ||
728 | + | ||
729 | + /** | ||
690 | * Adds attribute for class. | 730 | * Adds attribute for class. |
691 | * | 731 | * |
692 | * @param attr attribute info | 732 | * @param attr attribute info |
693 | * @throws IOException when fails to append to temporary file | 733 | * @throws IOException when fails to append to temporary file |
694 | */ | 734 | */ |
695 | - public void addAttribute(JavaAttributeInfo attr) throws IOException { | 735 | + private void addAttribute(JavaAttributeInfo attr) throws IOException { |
696 | appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); | 736 | appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION); |
697 | } | 737 | } |
698 | 738 | ||
... | @@ -702,7 +742,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -702,7 +742,7 @@ public class TempJavaCodeFragmentFiles { |
702 | * @param attr attribute info | 742 | * @param attr attribute info |
703 | * @throws IOException when fails to append to temporary file | 743 | * @throws IOException when fails to append to temporary file |
704 | */ | 744 | */ |
705 | - public void addGetterForInterface(JavaAttributeInfo attr) throws IOException { | 745 | + private void addGetterForInterface(JavaAttributeInfo attr) throws IOException { |
706 | appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE); | 746 | appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE); |
707 | } | 747 | } |
708 | 748 | ||
... | @@ -713,7 +753,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -713,7 +753,7 @@ public class TempJavaCodeFragmentFiles { |
713 | * @param genFiletype generated file type | 753 | * @param genFiletype generated file type |
714 | * @throws IOException when fails to append to temporary file | 754 | * @throws IOException when fails to append to temporary file |
715 | */ | 755 | */ |
716 | - public void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException { | 756 | + private void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException { |
717 | 757 | ||
718 | if ((genFiletype & BUILDER_CLASS_MASK) != 0) { | 758 | if ((genFiletype & BUILDER_CLASS_MASK) != 0) { |
719 | appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE); | 759 | appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE); |
... | @@ -729,7 +769,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -729,7 +769,7 @@ public class TempJavaCodeFragmentFiles { |
729 | * @param attr attribute info | 769 | * @param attr attribute info |
730 | * @throws IOException when fails to append to temporary file | 770 | * @throws IOException when fails to append to temporary file |
731 | */ | 771 | */ |
732 | - public void addSetterForInterface(JavaAttributeInfo attr) throws IOException { | 772 | + private void addSetterForInterface(JavaAttributeInfo attr) throws IOException { |
733 | appendToFile(getSetterInterfaceTempFileHandle(), | 773 | appendToFile(getSetterInterfaceTempFileHandle(), |
734 | getSetterString(attr, generatedJavaClassName) + NEW_LINE); | 774 | getSetterString(attr, generatedJavaClassName) + NEW_LINE); |
735 | } | 775 | } |
... | @@ -740,7 +780,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -740,7 +780,7 @@ public class TempJavaCodeFragmentFiles { |
740 | * @param attr attribute info | 780 | * @param attr attribute info |
741 | * @throws IOException when fails to append to temporary file | 781 | * @throws IOException when fails to append to temporary file |
742 | */ | 782 | */ |
743 | - public void addSetterImpl(JavaAttributeInfo attr) throws IOException { | 783 | + private void addSetterImpl(JavaAttributeInfo attr) throws IOException { |
744 | appendToFile(getSetterImplTempFileHandle(), | 784 | appendToFile(getSetterImplTempFileHandle(), |
745 | getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE); | 785 | getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE); |
746 | } | 786 | } |
... | @@ -771,7 +811,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -771,7 +811,7 @@ public class TempJavaCodeFragmentFiles { |
771 | * @param attr attribute info | 811 | * @param attr attribute info |
772 | * @throws IOException when fails to append to temporary file | 812 | * @throws IOException when fails to append to temporary file |
773 | */ | 813 | */ |
774 | - public void addConstructor(JavaAttributeInfo attr) throws IOException { | 814 | + private void addConstructor(JavaAttributeInfo attr) throws IOException { |
775 | appendToFile(getConstructorImplTempFileHandle(), getConstructor(generatedJavaClassName, attr)); | 815 | appendToFile(getConstructorImplTempFileHandle(), getConstructor(generatedJavaClassName, attr)); |
776 | } | 816 | } |
777 | 817 | ||
... | @@ -826,7 +866,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -826,7 +866,7 @@ public class TempJavaCodeFragmentFiles { |
826 | * @param attr attribute info | 866 | * @param attr attribute info |
827 | * @throws IOException when fails to append to temporary file | 867 | * @throws IOException when fails to append to temporary file |
828 | */ | 868 | */ |
829 | - public void addHashCodeMethod(JavaAttributeInfo attr) throws IOException { | 869 | + private void addHashCodeMethod(JavaAttributeInfo attr) throws IOException { |
830 | appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); | 870 | appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE); |
831 | } | 871 | } |
832 | 872 | ||
... | @@ -836,7 +876,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -836,7 +876,7 @@ public class TempJavaCodeFragmentFiles { |
836 | * @param attr attribute info | 876 | * @param attr attribute info |
837 | * @throws IOException when fails to append to temporary file | 877 | * @throws IOException when fails to append to temporary file |
838 | */ | 878 | */ |
839 | - public void addEqualsMethod(JavaAttributeInfo attr) throws IOException { | 879 | + private void addEqualsMethod(JavaAttributeInfo attr) throws IOException { |
840 | appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); | 880 | appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE); |
841 | } | 881 | } |
842 | 882 | ||
... | @@ -846,7 +886,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -846,7 +886,7 @@ public class TempJavaCodeFragmentFiles { |
846 | * @param attr attribute info | 886 | * @param attr attribute info |
847 | * @throws IOException when fails to append to temporary file | 887 | * @throws IOException when fails to append to temporary file |
848 | */ | 888 | */ |
849 | - public void addToStringMethod(JavaAttributeInfo attr) throws IOException { | 889 | + private void addToStringMethod(JavaAttributeInfo attr) throws IOException { |
850 | appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); | 890 | appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE); |
851 | } | 891 | } |
852 | 892 | ||
... | @@ -1031,7 +1071,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1031,7 +1071,7 @@ public class TempJavaCodeFragmentFiles { |
1031 | } | 1071 | } |
1032 | 1072 | ||
1033 | /** | 1073 | /** |
1034 | - * Add all the leaves in the current data model node as part of the | 1074 | + * Adds all the leaves in the current data model node as part of the |
1035 | * generated temporary file. | 1075 | * generated temporary file. |
1036 | * | 1076 | * |
1037 | * @param curNode java file info of the generated file | 1077 | * @param curNode java file info of the generated file |
... | @@ -1139,7 +1179,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1139,7 +1179,7 @@ public class TempJavaCodeFragmentFiles { |
1139 | } | 1179 | } |
1140 | 1180 | ||
1141 | /** | 1181 | /** |
1142 | - * Construct java code exit. | 1182 | + * Constructs java code exit. |
1143 | * | 1183 | * |
1144 | * @param fileType generated file type | 1184 | * @param fileType generated file type |
1145 | * @param curNode current YANG node | 1185 | * @param curNode current YANG node |
... | @@ -1152,11 +1192,27 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1152,11 +1192,27 @@ public class TempJavaCodeFragmentFiles { |
1152 | if (curNode instanceof HasJavaImportData && isAttributePresent) { | 1192 | if (curNode instanceof HasJavaImportData && isAttributePresent) { |
1153 | imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo()); | 1193 | imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo()); |
1154 | } | 1194 | } |
1195 | + | ||
1196 | + /** | ||
1197 | + * Prepares java file generator for extends list. | ||
1198 | + */ | ||
1199 | + prepareJavaFileGeneratorForExtendsList(getExtendsList()); | ||
1200 | + | ||
1155 | /** | 1201 | /** |
1156 | - * Start generation of files. | 1202 | + * Generate java code. |
1157 | */ | 1203 | */ |
1158 | - if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0 | 1204 | + if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) { |
1159 | - | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | 1205 | + |
1206 | + /** | ||
1207 | + * Adds import for HasAugmentation class. | ||
1208 | + */ | ||
1209 | + if (isHasAugmentationExtended(getExtendsList())) { | ||
1210 | + addHasAugmentationImport(curNode, imports, true); | ||
1211 | + } | ||
1212 | + | ||
1213 | + if (isAugmentedInfoExtended(getExtendsList())) { | ||
1214 | + addAugmentedInfoImport(curNode, imports, true); | ||
1215 | + } | ||
1160 | 1216 | ||
1161 | /** | 1217 | /** |
1162 | * Create interface file. | 1218 | * Create interface file. |
... | @@ -1167,25 +1223,36 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1167,25 +1223,36 @@ public class TempJavaCodeFragmentFiles { |
1167 | /** | 1223 | /** |
1168 | * Create builder interface file. | 1224 | * Create builder interface file. |
1169 | */ | 1225 | */ |
1170 | - setBuilderInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); | 1226 | + if ((fileType & BUILDER_INTERFACE_MASK) != 0) { |
1227 | + | ||
1228 | + setBuilderInterfaceJavaFileHandle( | ||
1229 | + getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX))); | ||
1171 | setBuilderInterfaceJavaFileHandle( | 1230 | setBuilderInterfaceJavaFileHandle( |
1172 | generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent)); | 1231 | generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent)); |
1173 | /** | 1232 | /** |
1174 | * Append builder interface file to interface file and close it. | 1233 | * Append builder interface file to interface file and close it. |
1175 | */ | 1234 | */ |
1176 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); | 1235 | mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle()); |
1236 | + } | ||
1177 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); | 1237 | insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose()); |
1178 | 1238 | ||
1239 | + if (isHasAugmentationExtended(getExtendsList())) { | ||
1240 | + addHasAugmentationImport(curNode, imports, false); | ||
1241 | + } | ||
1242 | + if (isAugmentedInfoExtended(getExtendsList())) { | ||
1243 | + addAugmentedInfoImport(curNode, imports, false); | ||
1179 | } | 1244 | } |
1180 | - | ||
1181 | - if (curNode instanceof HasJavaImportData && isAttributePresent) { | ||
1182 | - imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals()); | ||
1183 | - imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString()); | ||
1184 | - java.util.Collections.sort(imports); | ||
1185 | } | 1245 | } |
1186 | 1246 | ||
1187 | - if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0 | 1247 | + if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) { |
1188 | - | fileType == GENERATE_INTERFACE_WITH_BUILDER) { | 1248 | + |
1249 | + if (isAttributePresent) { | ||
1250 | + addImportsToStringAndHasCodeMethods(curNode, imports); | ||
1251 | + } | ||
1252 | + if (isHasAugmentationExtended(getExtendsList())) { | ||
1253 | + addAugmentedInfoImport(curNode, imports, true); | ||
1254 | + addArrayListImport(curNode, imports, true); | ||
1255 | + } | ||
1189 | 1256 | ||
1190 | /** | 1257 | /** |
1191 | * Create builder class file. | 1258 | * Create builder class file. |
... | @@ -1196,6 +1263,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1196,6 +1263,7 @@ public class TempJavaCodeFragmentFiles { |
1196 | /** | 1263 | /** |
1197 | * Create impl class file. | 1264 | * Create impl class file. |
1198 | */ | 1265 | */ |
1266 | + if ((fileType & IMPL_CLASS_MASK) != 0) { | ||
1199 | setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); | 1267 | setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX))); |
1200 | setImplClassJavaFileHandle( | 1268 | setImplClassJavaFileHandle( |
1201 | generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent)); | 1269 | generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent)); |
... | @@ -1203,6 +1271,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1203,6 +1271,7 @@ public class TempJavaCodeFragmentFiles { |
1203 | * Append impl class to builder class and close it. | 1271 | * Append impl class to builder class and close it. |
1204 | */ | 1272 | */ |
1205 | mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); | 1273 | mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle()); |
1274 | + } | ||
1206 | insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose()); | 1275 | insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose()); |
1207 | } | 1276 | } |
1208 | 1277 | ||
... | @@ -1210,6 +1279,7 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1210,6 +1279,7 @@ public class TempJavaCodeFragmentFiles { |
1210 | * Creates type def class file. | 1279 | * Creates type def class file. |
1211 | */ | 1280 | */ |
1212 | if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) { | 1281 | if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) { |
1282 | + addImportsToStringAndHasCodeMethods(curNode, imports); | ||
1213 | setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX))); | 1283 | setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX))); |
1214 | setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports)); | 1284 | setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports)); |
1215 | } | 1285 | } |
... | @@ -1285,19 +1355,4 @@ public class TempJavaCodeFragmentFiles { | ... | @@ -1285,19 +1355,4 @@ public class TempJavaCodeFragmentFiles { |
1285 | generatedTempFiles = 0; | 1355 | generatedTempFiles = 0; |
1286 | } | 1356 | } |
1287 | 1357 | ||
1288 | - /** | ||
1289 | - * Closes the file handle for temporary file. | ||
1290 | - * | ||
1291 | - * @param fileName temporary file's name | ||
1292 | - * @throws IOException when failed to close the file handle | ||
1293 | - */ | ||
1294 | - private void closeFile(File file, boolean toBeDeleted) throws IOException { | ||
1295 | - | ||
1296 | - if (file != null) { | ||
1297 | - updateFileHandle(file, null, true); | ||
1298 | - if (toBeDeleted) { | ||
1299 | - file.delete(); | ||
1300 | - } | ||
1301 | - } | ||
1302 | - } | ||
1303 | } | 1358 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
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 | + | ||
19 | import org.onosproject.yangutils.datamodel.YangAugment; | 20 | import org.onosproject.yangutils.datamodel.YangAugment; |
20 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 21 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
21 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | 22 | import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; |
... | @@ -137,11 +138,12 @@ public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInf | ... | @@ -137,11 +138,12 @@ public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInf |
137 | } | 138 | } |
138 | 139 | ||
139 | /** | 140 | /** |
140 | - * Creates a java file using the YANG grouping info. | 141 | + * Create a java file using the YANG augment info. |
142 | + * | ||
143 | + * @throws IOException when failed to do IO operations | ||
141 | */ | 144 | */ |
142 | @Override | 145 | @Override |
143 | - public void generateCodeExit() { | 146 | + public void generateCodeExit() throws IOException { |
144 | - // TODO Auto-generated method stub | 147 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this); |
145 | - | ||
146 | } | 148 | } |
147 | } | 149 | } | ... | ... |
... | @@ -136,7 +136,7 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav | ... | @@ -136,7 +136,7 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav |
136 | } | 136 | } |
137 | 137 | ||
138 | /** | 138 | /** |
139 | - * Creates a java file using the YANG grouping info. | 139 | + * Creates a java file using the YANG case info. |
140 | */ | 140 | */ |
141 | @Override | 141 | @Override |
142 | public void generateCodeExit() { | 142 | public void generateCodeExit() { | ... | ... |
... | @@ -125,7 +125,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, | ... | @@ -125,7 +125,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Prepare the information for java code generation corresponding to YANG | 127 | * Prepare the information for java code generation corresponding to YANG |
128 | - * case info. | 128 | + * choice info. |
129 | * | 129 | * |
130 | * @param yangPlugin YANG plugin config | 130 | * @param yangPlugin YANG plugin config |
131 | * @throws IOException IO operation fail | 131 | * @throws IOException IO operation fail |
... | @@ -137,7 +137,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, | ... | @@ -137,7 +137,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, |
137 | } | 137 | } |
138 | 138 | ||
139 | /** | 139 | /** |
140 | - * Creates a java file using the YANG grouping info. | 140 | + * Creates a java file using the YANG choice info. |
141 | */ | 141 | */ |
142 | @Override | 142 | @Override |
143 | public void generateCodeExit() { | 143 | public void generateCodeExit() { | ... | ... |
... | @@ -125,7 +125,7 @@ public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorI | ... | @@ -125,7 +125,7 @@ public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorI |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Prepare the information for java code generation corresponding to YANG | 127 | * Prepare the information for java code generation corresponding to YANG |
128 | - * container info. | 128 | + * grouping info. |
129 | * | 129 | * |
130 | * @param yangPlugin YANG plugin config | 130 | * @param yangPlugin YANG plugin config |
131 | * @throws IOException IO operation fail | 131 | * @throws IOException IO operation fail | ... | ... |
... | @@ -126,7 +126,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J | ... | @@ -126,7 +126,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Prepare the information for java code generation corresponding to YANG | 128 | * Prepare the information for java code generation corresponding to YANG |
129 | - * container info. | 129 | + * input info. |
130 | * | 130 | * |
131 | * @param yangPlugin YANG plugin config | 131 | * @param yangPlugin YANG plugin config |
132 | * @throws IOException IO operation fail | 132 | * @throws IOException IO operation fail |
... | @@ -137,7 +137,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J | ... | @@ -137,7 +137,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J |
137 | } | 137 | } |
138 | 138 | ||
139 | /** | 139 | /** |
140 | - * Creates a java file using the YANG grouping info. | 140 | + * Creates a java file using the YANG input info. |
141 | * | 141 | * |
142 | * @throws IOException IO operation fail | 142 | * @throws IOException IO operation fail |
143 | */ | 143 | */ | ... | ... |
... | @@ -125,7 +125,7 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav | ... | @@ -125,7 +125,7 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Prepare the information for java code generation corresponding to YANG | 127 | * Prepare the information for java code generation corresponding to YANG |
128 | - * container info. | 128 | + * list info. |
129 | * | 129 | * |
130 | * @param yangPlugin YANG plugin config | 130 | * @param yangPlugin YANG plugin config |
131 | * @throws IOException IO operation fail | 131 | * @throws IOException IO operation fail |
... | @@ -136,7 +136,7 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav | ... | @@ -136,7 +136,7 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav |
136 | } | 136 | } |
137 | 137 | ||
138 | /** | 138 | /** |
139 | - * Creates a java file using the YANG grouping info. | 139 | + * Creates a java file using the YANG list info. |
140 | * | 140 | * |
141 | * @throws IOException IO operation fail | 141 | * @throws IOException IO operation fail |
142 | */ | 142 | */ | ... | ... |
... | @@ -165,7 +165,7 @@ public class YangJavaNotification extends YangNotification | ... | @@ -165,7 +165,7 @@ public class YangJavaNotification extends YangNotification |
165 | } | 165 | } |
166 | 166 | ||
167 | /** | 167 | /** |
168 | - * Create a java file using the YANG notification info. | 168 | + * Creates a java file using the YANG notification info. |
169 | */ | 169 | */ |
170 | @Override | 170 | @Override |
171 | public void generateCodeExit() { | 171 | public void generateCodeExit() { | ... | ... |
... | @@ -126,7 +126,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, | ... | @@ -126,7 +126,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Prepare the information for java code generation corresponding to YANG | 128 | * Prepare the information for java code generation corresponding to YANG |
129 | - * container info. | 129 | + * output info. |
130 | * | 130 | * |
131 | * @param yangPlugin YANG plugin config | 131 | * @param yangPlugin YANG plugin config |
132 | * @throws IOException IO operation fail | 132 | * @throws IOException IO operation fail |
... | @@ -137,7 +137,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, | ... | @@ -137,7 +137,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, |
137 | } | 137 | } |
138 | 138 | ||
139 | /** | 139 | /** |
140 | - * Creates a java file using the YANG grouping info. | 140 | + * Creates a java file using the YANG output info. |
141 | * | 141 | * |
142 | * @throws IOException IO operation fail | 142 | * @throws IOException IO operation fail |
143 | */ | 143 | */ | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
... | @@ -34,7 +34,7 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator { | ... | @@ -34,7 +34,7 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator { |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Prepares the information for java code generation corresponding to YANG | 36 | * Prepares the information for java code generation corresponding to YANG |
37 | - * rpc info. | 37 | + * RPC info. |
38 | * | 38 | * |
39 | * @param yangPlugin YANG plugin config | 39 | * @param yangPlugin YANG plugin config |
40 | * @throws IOException IO operation fail | 40 | * @throws IOException IO operation fail |
... | @@ -45,7 +45,7 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator { | ... | @@ -45,7 +45,7 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator { |
45 | } | 45 | } |
46 | 46 | ||
47 | /** | 47 | /** |
48 | - * Creates a java file using the YANG rpc info. | 48 | + * Creates a java file using the YANG RPC info. |
49 | * | 49 | * |
50 | * @throws IOException IO operation fail | 50 | * @throws IOException IO operation fail |
51 | */ | 51 | */ | ... | ... |
... | @@ -139,7 +139,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato | ... | @@ -139,7 +139,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Prepare the information for java code generation corresponding to YANG | 141 | * Prepare the information for java code generation corresponding to YANG |
142 | - * container info. | 142 | + * submodule info. |
143 | * | 143 | * |
144 | * @param yangPlugin YANG plugin config | 144 | * @param yangPlugin YANG plugin config |
145 | * @throws IOException IO operation fail | 145 | * @throws IOException IO operation fail |
... | @@ -152,7 +152,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato | ... | @@ -152,7 +152,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato |
152 | } | 152 | } |
153 | 153 | ||
154 | /** | 154 | /** |
155 | - * Creates a java file using the YANG grouping info. | 155 | + * Creates a java file using the YANG submodule info. |
156 | */ | 156 | */ |
157 | @Override | 157 | @Override |
158 | public void generateCodeExit() { | 158 | public void generateCodeExit() { | ... | ... |
... | @@ -135,7 +135,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -135,7 +135,7 @@ public class YangJavaTypeDef extends YangTypeDef |
135 | 135 | ||
136 | /** | 136 | /** |
137 | * Prepare the information for java code generation corresponding to YANG | 137 | * Prepare the information for java code generation corresponding to YANG |
138 | - * container info. | 138 | + * typedef info. |
139 | * | 139 | * |
140 | * @param yangPlugin YANG plugin config | 140 | * @param yangPlugin YANG plugin config |
141 | * @throws IOException IO operations fails | 141 | * @throws IOException IO operations fails |
... | @@ -162,7 +162,7 @@ public class YangJavaTypeDef extends YangTypeDef | ... | @@ -162,7 +162,7 @@ public class YangJavaTypeDef extends YangTypeDef |
162 | } | 162 | } |
163 | 163 | ||
164 | /** | 164 | /** |
165 | - * Create a java file using the YANG grouping info. | 165 | + * Create a java file using the YANG typedef info. |
166 | * | 166 | * |
167 | * @throws IOException IO operations fails | 167 | * @throws IOException IO operations fails |
168 | */ | 168 | */ | ... | ... |
... | @@ -103,7 +103,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava | ... | @@ -103,7 +103,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * Prepare the information for java code generation corresponding to YANG | 105 | * Prepare the information for java code generation corresponding to YANG |
106 | - * container info. | 106 | + * uses info. |
107 | * | 107 | * |
108 | * @param yangPlugin YANG plugin config | 108 | * @param yangPlugin YANG plugin config |
109 | */ | 109 | */ |
... | @@ -120,7 +120,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava | ... | @@ -120,7 +120,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava |
120 | } | 120 | } |
121 | 121 | ||
122 | /** | 122 | /** |
123 | - * Create a java file using the YANG grouping info. | 123 | + * Create a java file using the YANG uses info. |
124 | */ | 124 | */ |
125 | @Override | 125 | @Override |
126 | public void generateCodeExit() { | 126 | public void generateCodeExit() { | ... | ... |
... | @@ -16,35 +16,19 @@ | ... | @@ -16,35 +16,19 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.translator.tojava.utils; | 17 | package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | -import java.util.Set; | ||
20 | -import java.util.TreeSet; | ||
21 | - | ||
22 | import org.onosproject.yangutils.datamodel.YangDataTypes; | 19 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
20 | +import org.onosproject.yangutils.datamodel.YangDerivedInfo; | ||
21 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
23 | import org.onosproject.yangutils.datamodel.YangType; | 22 | import org.onosproject.yangutils.datamodel.YangType; |
24 | -import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | 23 | +import org.onosproject.yangutils.datamodel.YangTypeDef; |
24 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
25 | +import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | ||
26 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
27 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; | ||
25 | 28 | ||
26 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY; | ||
27 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS; | ||
28 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; | ||
29 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.DECIMAL64; | ||
30 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; | ||
31 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.EMPTY; | ||
32 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.ENUMERATION; | ||
33 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF; | ||
34 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.INSTANCE_IDENTIFIER; | ||
35 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.INT16; | ||
36 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; | ||
37 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.INT64; | ||
38 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.INT8; | ||
39 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF; | ||
40 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; | ||
41 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT16; | ||
42 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT32; | ||
43 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT64; | ||
44 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8; | ||
45 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION; | ||
46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 29 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 30 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
31 | +import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; | ||
48 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
49 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; |
50 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE; |
... | @@ -52,8 +36,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; | ... | @@ -52,8 +36,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; |
52 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
53 | import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; |
54 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; |
39 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; | ||
55 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; |
56 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; |
42 | +import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ||
57 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT; |
58 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; |
59 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | 45 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
... | @@ -63,8 +49,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | ... | @@ -63,8 +49,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
63 | */ | 49 | */ |
64 | public final class AttributesJavaDataType { | 50 | public final class AttributesJavaDataType { |
65 | 51 | ||
66 | - private static Set<JavaQualifiedTypeInfo> importInfo = new TreeSet<>(); | ||
67 | - | ||
68 | /** | 52 | /** |
69 | * Creates an instance of attribute java data type. | 53 | * Creates an instance of attribute java data type. |
70 | */ | 54 | */ |
... | @@ -72,26 +56,6 @@ public final class AttributesJavaDataType { | ... | @@ -72,26 +56,6 @@ public final class AttributesJavaDataType { |
72 | } | 56 | } |
73 | 57 | ||
74 | /** | 58 | /** |
75 | - * Returns import info. | ||
76 | - * | ||
77 | - * @return import info | ||
78 | - */ | ||
79 | - public static Set<JavaQualifiedTypeInfo> getImportInfo() { | ||
80 | - | ||
81 | - return importInfo; | ||
82 | - } | ||
83 | - | ||
84 | - /** | ||
85 | - * Adds import info to the import info set. | ||
86 | - * | ||
87 | - * @param importData import info | ||
88 | - */ | ||
89 | - public static void addImportInfo(JavaQualifiedTypeInfo importData) { | ||
90 | - | ||
91 | - getImportInfo().add(importData); | ||
92 | - } | ||
93 | - | ||
94 | - /** | ||
95 | * Returns java type. | 59 | * Returns java type. |
96 | * | 60 | * |
97 | * @param yangType YANG type | 61 | * @param yangType YANG type |
... | @@ -101,48 +65,32 @@ public final class AttributesJavaDataType { | ... | @@ -101,48 +65,32 @@ public final class AttributesJavaDataType { |
101 | 65 | ||
102 | YangDataTypes type = yangType.getDataType(); | 66 | YangDataTypes type = yangType.getDataType(); |
103 | 67 | ||
104 | - if (type.equals(INT8)) { | 68 | + switch (type) { |
69 | + case INT8: | ||
105 | return BYTE; | 70 | return BYTE; |
106 | - } else if (type.equals(INT16)) { | 71 | + case INT16: |
107 | return SHORT; | 72 | return SHORT; |
108 | - } else if (type.equals(INT32)) { | 73 | + case INT32: |
109 | return INT; | 74 | return INT; |
110 | - } else if (type.equals(INT64)) { | 75 | + case INT64: |
111 | return LONG; | 76 | return LONG; |
112 | - } else if (type.equals(UINT8)) { | 77 | + case UINT8: |
113 | return SHORT; | 78 | return SHORT; |
114 | - } else if (type.equals(UINT16)) { | 79 | + case UINT16: |
115 | return INT; | 80 | return INT; |
116 | - } else if (type.equals(UINT32)) { | 81 | + case UINT32: |
117 | return LONG; | 82 | return LONG; |
118 | - } else if (type.equals(UINT64)) { | 83 | + case UINT64: |
119 | - //TODO: BIGINTEGER. | 84 | + return BIG_INTEGER; |
120 | - } else if (type.equals(DECIMAL64)) { | 85 | + case DECIMAL64: |
121 | //TODO: DECIMAL64. | 86 | //TODO: DECIMAL64. |
122 | - } else if (type.equals(STRING)) { | 87 | + case STRING: |
123 | return STRING_DATA_TYPE; | 88 | return STRING_DATA_TYPE; |
124 | - } else if (type.equals(BOOLEAN)) { | 89 | + case BOOLEAN: |
125 | return BOOLEAN_DATA_TYPE; | 90 | return BOOLEAN_DATA_TYPE; |
126 | - } else if (type.equals(ENUMERATION)) { | 91 | + default: |
127 | - //TODO: ENUMERATION. | 92 | + throw new TranslatorException("given data type is not supported."); |
128 | - } else if (type.equals(BITS)) { | ||
129 | - //TODO:BITS | ||
130 | - } else if (type.equals(BINARY)) { | ||
131 | - //TODO:BINARY | ||
132 | - } else if (type.equals(LEAFREF)) { | ||
133 | - //TODO:LEAFREF | ||
134 | - } else if (type.equals(IDENTITYREF)) { | ||
135 | - //TODO:IDENTITYREF | ||
136 | - } else if (type.equals(EMPTY)) { | ||
137 | - //TODO:EMPTY | ||
138 | - } else if (type.equals(UNION)) { | ||
139 | - //TODO:UNION | ||
140 | - } else if (type.equals(INSTANCE_IDENTIFIER)) { | ||
141 | - //TODO:INSTANCE_IDENTIFIER | ||
142 | - } else if (type.equals(DERIVED)) { | ||
143 | - return yangType.getDataTypeName(); | ||
144 | } | 93 | } |
145 | - return null; | ||
146 | } | 94 | } |
147 | 95 | ||
148 | /** | 96 | /** |
... | @@ -157,75 +105,80 @@ public final class AttributesJavaDataType { | ... | @@ -157,75 +105,80 @@ public final class AttributesJavaDataType { |
157 | YangDataTypes type = yangType.getDataType(); | 105 | YangDataTypes type = yangType.getDataType(); |
158 | 106 | ||
159 | if (isListAttr) { | 107 | if (isListAttr) { |
160 | - if (type.equals(INT8)) { | 108 | + switch (type) { |
109 | + case INT8: | ||
161 | return BYTE_WRAPPER; | 110 | return BYTE_WRAPPER; |
162 | - } else if (type.equals(INT16)) { | 111 | + case INT16: |
163 | return SHORT_WRAPPER; | 112 | return SHORT_WRAPPER; |
164 | - } else if (type.equals(INT32)) { | 113 | + case INT32: |
165 | return INTEGER_WRAPPER; | 114 | return INTEGER_WRAPPER; |
166 | - } else if (type.equals(INT64)) { | 115 | + case INT64: |
167 | return LONG_WRAPPER; | 116 | return LONG_WRAPPER; |
168 | - } else if (type.equals(UINT8)) { | 117 | + case UINT8: |
169 | return SHORT_WRAPPER; | 118 | return SHORT_WRAPPER; |
170 | - } else if (type.equals(UINT16)) { | 119 | + case UINT16: |
171 | return INTEGER_WRAPPER; | 120 | return INTEGER_WRAPPER; |
172 | - } else if (type.equals(UINT32)) { | 121 | + case UINT32: |
173 | return LONG_WRAPPER; | 122 | return LONG_WRAPPER; |
174 | - } else if (type.equals(UINT64)) { | 123 | + case UINT64: |
175 | - //TODO: BIGINTEGER. | 124 | + return BIG_INTEGER; |
176 | - } else if (type.equals(DECIMAL64)) { | 125 | + case DECIMAL64: |
177 | //TODO: DECIMAL64. | 126 | //TODO: DECIMAL64. |
178 | - } else if (type.equals(STRING)) { | 127 | + case STRING: |
179 | return STRING_DATA_TYPE; | 128 | return STRING_DATA_TYPE; |
180 | - } else if (type.equals(BOOLEAN)) { | 129 | + case BOOLEAN: |
181 | return BOOLEAN_WRAPPER; | 130 | return BOOLEAN_WRAPPER; |
182 | - } else if (type.equals(ENUMERATION)) { | 131 | + case ENUMERATION: |
183 | //TODO: ENUMERATION. | 132 | //TODO: ENUMERATION. |
184 | - } else if (type.equals(BITS)) { | 133 | + case BITS: |
185 | //TODO:BITS | 134 | //TODO:BITS |
186 | - } else if (type.equals(BINARY)) { | 135 | + case BINARY: |
187 | //TODO:BINARY | 136 | //TODO:BINARY |
188 | - } else if (type.equals(LEAFREF)) { | 137 | + case LEAFREF: |
189 | //TODO:LEAFREF | 138 | //TODO:LEAFREF |
190 | - } else if (type.equals(IDENTITYREF)) { | 139 | + case IDENTITYREF: |
191 | //TODO:IDENTITYREF | 140 | //TODO:IDENTITYREF |
192 | - } else if (type.equals(EMPTY)) { | 141 | + case EMPTY: |
193 | - //TODO:EMPTY | 142 | + return BOOLEAN_WRAPPER; |
194 | - } else if (type.equals(UNION)) { | 143 | + case UNION: |
195 | //TODO:UNION | 144 | //TODO:UNION |
196 | - } else if (type.equals(INSTANCE_IDENTIFIER)) { | 145 | + case INSTANCE_IDENTIFIER: |
197 | //TODO:INSTANCE_IDENTIFIER | 146 | //TODO:INSTANCE_IDENTIFIER |
198 | - } else if (type.equals(DERIVED)) { | 147 | + case DERIVED: |
199 | return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); | 148 | return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); |
149 | + default: | ||
150 | + throw new TranslatorException("given data type is not supported."); | ||
200 | } | 151 | } |
201 | } else { | 152 | } else { |
202 | - if (type.equals(UINT64)) { | 153 | + switch (type) { |
203 | - //TODO: BIGINTEGER. | 154 | + case UINT64: |
204 | - } else if (type.equals(DECIMAL64)) { | 155 | + return BIG_INTEGER; |
156 | + case DECIMAL64: | ||
205 | //TODO: DECIMAL64. | 157 | //TODO: DECIMAL64. |
206 | - } else if (type.equals(STRING)) { | 158 | + case STRING: |
207 | return STRING_DATA_TYPE; | 159 | return STRING_DATA_TYPE; |
208 | - } else if (type.equals(ENUMERATION)) { | 160 | + case ENUMERATION: |
209 | //TODO: ENUMERATION. | 161 | //TODO: ENUMERATION. |
210 | - } else if (type.equals(BITS)) { | 162 | + case BITS: |
211 | //TODO:BITS | 163 | //TODO:BITS |
212 | - } else if (type.equals(BINARY)) { | 164 | + case BINARY: |
213 | //TODO:BINARY | 165 | //TODO:BINARY |
214 | - } else if (type.equals(LEAFREF)) { | 166 | + case LEAFREF: |
215 | //TODO:LEAFREF | 167 | //TODO:LEAFREF |
216 | - } else if (type.equals(IDENTITYREF)) { | 168 | + case IDENTITYREF: |
217 | //TODO:IDENTITYREF | 169 | //TODO:IDENTITYREF |
218 | - } else if (type.equals(EMPTY)) { | 170 | + case EMPTY: |
219 | //TODO:EMPTY | 171 | //TODO:EMPTY |
220 | - } else if (type.equals(UNION)) { | 172 | + case UNION: |
221 | //TODO:UNION | 173 | //TODO:UNION |
222 | - } else if (type.equals(INSTANCE_IDENTIFIER)) { | 174 | + case INSTANCE_IDENTIFIER: |
223 | //TODO:INSTANCE_IDENTIFIER | 175 | //TODO:INSTANCE_IDENTIFIER |
224 | - } else if (type.equals(DERIVED)) { | 176 | + case DERIVED: |
225 | return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); | 177 | return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); |
178 | + default: | ||
179 | + return null; | ||
226 | } | 180 | } |
227 | } | 181 | } |
228 | - return null; | ||
229 | } | 182 | } |
230 | 183 | ||
231 | /** | 184 | /** |
... | @@ -241,75 +194,108 @@ public final class AttributesJavaDataType { | ... | @@ -241,75 +194,108 @@ public final class AttributesJavaDataType { |
241 | YangDataTypes type = yangType.getDataType(); | 194 | YangDataTypes type = yangType.getDataType(); |
242 | 195 | ||
243 | if (isListAttr) { | 196 | if (isListAttr) { |
244 | - if (type.equals(INT8) | 197 | + switch (type) { |
245 | - || type.equals(INT16) | 198 | + case INT8: |
246 | - || type.equals(INT32) | 199 | + case INT16: |
247 | - || type.equals(INT64) | 200 | + case INT32: |
248 | - || type.equals(UINT8) | 201 | + case INT64: |
249 | - || type.equals(UINT16) | 202 | + case UINT8: |
250 | - || type.equals(UINT32) | 203 | + case UINT16: |
251 | - || type.equals(STRING) | 204 | + case UINT32: |
252 | - || type.equals(BOOLEAN)) { | 205 | + case STRING: |
206 | + case BOOLEAN: | ||
253 | return JAVA_LANG; | 207 | return JAVA_LANG; |
254 | - } else if (type.equals(UINT64)) { | 208 | + case UINT64: |
255 | - //TODO: BIGINTEGER. | 209 | + return JAVA_MATH; |
256 | - } else if (type.equals(DECIMAL64)) { | 210 | + case DECIMAL64: |
257 | //TODO: DECIMAL64. | 211 | //TODO: DECIMAL64. |
258 | - } else if (type.equals(ENUMERATION)) { | 212 | + case ENUMERATION: |
259 | //TODO: ENUMERATION. | 213 | //TODO: ENUMERATION. |
260 | - } else if (type.equals(BITS)) { | 214 | + case BITS: |
261 | //TODO:BITS | 215 | //TODO:BITS |
262 | - } else if (type.equals(BINARY)) { | 216 | + case BINARY: |
263 | //TODO:BINARY | 217 | //TODO:BINARY |
264 | - } else if (type.equals(LEAFREF)) { | 218 | + case LEAFREF: |
265 | //TODO:LEAFREF | 219 | //TODO:LEAFREF |
266 | - } else if (type.equals(IDENTITYREF)) { | 220 | + case IDENTITYREF: |
267 | //TODO:IDENTITYREF | 221 | //TODO:IDENTITYREF |
268 | - } else if (type.equals(EMPTY)) { | 222 | + case EMPTY: |
269 | //TODO:EMPTY | 223 | //TODO:EMPTY |
270 | - } else if (type.equals(UNION)) { | 224 | + case UNION: |
271 | //TODO:UNION | 225 | //TODO:UNION |
272 | - } else if (type.equals(INSTANCE_IDENTIFIER)) { | 226 | + case INSTANCE_IDENTIFIER: |
273 | //TODO:INSTANCE_IDENTIFIER | 227 | //TODO:INSTANCE_IDENTIFIER |
274 | - } else if (type.equals(DERIVED)) { | 228 | + case DERIVED: |
275 | - for (JavaQualifiedTypeInfo imports : getImportInfo()) { | 229 | + return getTypDefsPackage(yangType); |
276 | - if (imports.getClassInfo().equals(classInfo)) { | 230 | + default: |
277 | - return imports.getPkgInfo(); | 231 | + throw new TranslatorException("given data type is not supported."); |
278 | - } | ||
279 | - } | ||
280 | } | 232 | } |
281 | } else { | 233 | } else { |
282 | - | 234 | + switch (type) { |
283 | - if (type.equals(UINT64)) { | 235 | + case UINT64: |
284 | //TODO: BIGINTEGER. | 236 | //TODO: BIGINTEGER. |
285 | - } else if (type.equals(DECIMAL64)) { | 237 | + case DECIMAL64: |
286 | - //TODO: DECIMAL64. | 238 | + //TODO: DECIMAL64 |
287 | - } else if (type.equals(STRING)) { | 239 | + case STRING: |
288 | return JAVA_LANG; | 240 | return JAVA_LANG; |
289 | - } else if (type.equals(ENUMERATION)) { | 241 | + case ENUMERATION: |
290 | //TODO: ENUMERATION. | 242 | //TODO: ENUMERATION. |
291 | - } else if (type.equals(BITS)) { | 243 | + case BITS: |
292 | //TODO:BITS | 244 | //TODO:BITS |
293 | - } else if (type.equals(BINARY)) { | 245 | + case BINARY: |
294 | //TODO:BINARY | 246 | //TODO:BINARY |
295 | - } else if (type.equals(LEAFREF)) { | 247 | + case LEAFREF: |
296 | //TODO:LEAFREF | 248 | //TODO:LEAFREF |
297 | - } else if (type.equals(IDENTITYREF)) { | 249 | + case IDENTITYREF: |
298 | //TODO:IDENTITYREF | 250 | //TODO:IDENTITYREF |
299 | - } else if (type.equals(EMPTY)) { | 251 | + case EMPTY: |
300 | //TODO:EMPTY | 252 | //TODO:EMPTY |
301 | - } else if (type.equals(UNION)) { | 253 | + case UNION: |
302 | //TODO:UNION | 254 | //TODO:UNION |
303 | - } else if (type.equals(INSTANCE_IDENTIFIER)) { | 255 | + case INSTANCE_IDENTIFIER: |
304 | //TODO:INSTANCE_IDENTIFIER | 256 | //TODO:INSTANCE_IDENTIFIER |
305 | - } else if (type.equals(DERIVED)) { | 257 | + case DERIVED: |
306 | - for (JavaQualifiedTypeInfo imports : getImportInfo()) { | 258 | + return getTypDefsPackage(yangType); |
307 | - if (imports.getClassInfo().equals(classInfo)) { | 259 | + default: |
308 | - return imports.getPkgInfo(); | 260 | + return null; |
309 | } | 261 | } |
310 | } | 262 | } |
311 | } | 263 | } |
264 | + | ||
265 | + /** | ||
266 | + * Returns java package for typedef node. | ||
267 | + * | ||
268 | + * @param type YANG type | ||
269 | + * @return java package for typedef node | ||
270 | + */ | ||
271 | + private static String getTypDefsPackage(YangType<?> type) { | ||
272 | + Object var = type.getDataTypeExtendedInfo(); | ||
273 | + if (!(var instanceof YangDerivedInfo)) { | ||
274 | + throw new TranslatorException("type should have been derived."); | ||
312 | } | 275 | } |
313 | - return null; | 276 | + |
277 | + if (!(((YangDerivedInfo<?>) var).getReferredTypeDef() instanceof YangTypeDef)) { | ||
278 | + throw new TranslatorException("derived info is not an instance of typedef."); | ||
279 | + } | ||
280 | + | ||
281 | + YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef(); | ||
282 | + if (typedef.getJavaFileInfo().getPackage() == null) { | ||
283 | + return getPackageFromParent(typedef.getParent()); | ||
284 | + } | ||
285 | + return typedef.getJavaFileInfo().getPackage(); | ||
286 | + } | ||
287 | + | ||
288 | + /** | ||
289 | + * Returns package from parent node. | ||
290 | + * | ||
291 | + * @param parent parent YANG node | ||
292 | + * @return java package from parent node | ||
293 | + */ | ||
294 | + private static String getPackageFromParent(YangNode parent) { | ||
295 | + if (!(parent instanceof HasJavaFileInfo)) { | ||
296 | + throw new TranslatorException("Invalid child node is being processed."); | ||
297 | + } | ||
298 | + JavaFileInfo parentInfo = ((HasJavaFileInfo) parent).getJavaFileInfo(); | ||
299 | + return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase(); | ||
314 | } | 300 | } |
315 | } | 301 | } | ... | ... |
... | @@ -21,8 +21,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -21,8 +21,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
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.IMPL_CLASS_MASK; | 22 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
23 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK; | 23 | 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.isExtendsList; | ||
24 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 26 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
25 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | 27 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; |
28 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
29 | +import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; | ||
26 | import static org.onosproject.yangutils.utils.UtilConstants.FINAL; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.FINAL; |
27 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS; |
... | @@ -32,6 +36,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | ... | @@ -32,6 +36,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
32 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
33 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
34 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
39 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | ||
35 | 40 | ||
36 | /** | 41 | /** |
37 | * Represents generator for class definition of generated files. | 42 | * Represents generator for class definition of generated files. |
... | @@ -84,9 +89,17 @@ public final class ClassDefinitionGenerator { | ... | @@ -84,9 +89,17 @@ public final class ClassDefinitionGenerator { |
84 | * @return definition | 89 | * @return definition |
85 | */ | 90 | */ |
86 | private static String getInterfaceDefinition(String yangName) { | 91 | private static String getInterfaceDefinition(String yangName) { |
87 | - | 92 | + if (!isExtendsList()) { |
88 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 93 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
89 | } | 94 | } |
95 | + String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE; | ||
96 | + for (String extend : getExtendsList()) { | ||
97 | + def = def + extend + COMMA; | ||
98 | + } | ||
99 | + def = trimAtLast(def, COMMA); | ||
100 | + | ||
101 | + return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
102 | + } | ||
90 | 103 | ||
91 | /** | 104 | /** |
92 | * Returns builder interface file class definition. | 105 | * Returns builder interface file class definition. |
... | @@ -96,7 +109,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -96,7 +109,6 @@ public final class ClassDefinitionGenerator { |
96 | * @return definition | 109 | * @return definition |
97 | */ | 110 | */ |
98 | private static String getBuilderInterfaceDefinition(String yangName) { | 111 | private static String getBuilderInterfaceDefinition(String yangName) { |
99 | - | ||
100 | return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE; | 112 | return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE; |
101 | } | 113 | } |
102 | 114 | ||
... | @@ -107,7 +119,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -107,7 +119,6 @@ public final class ClassDefinitionGenerator { |
107 | * @return definition | 119 | * @return definition |
108 | */ | 120 | */ |
109 | private static String getBuilderClassDefinition(String yangName) { | 121 | private static String getBuilderClassDefinition(String yangName) { |
110 | - | ||
111 | return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD | 122 | return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD |
112 | + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 123 | + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
113 | } | 124 | } |
... | @@ -119,7 +130,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -119,7 +130,6 @@ public final class ClassDefinitionGenerator { |
119 | * @return definition | 130 | * @return definition |
120 | */ | 131 | */ |
121 | private static String getImplClassDefinition(String yangName) { | 132 | private static String getImplClassDefinition(String yangName) { |
122 | - | ||
123 | return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName | 133 | return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName |
124 | + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 134 | + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
125 | } | 135 | } |
... | @@ -131,7 +141,6 @@ public final class ClassDefinitionGenerator { | ... | @@ -131,7 +141,6 @@ public final class ClassDefinitionGenerator { |
131 | * @return definition | 141 | * @return definition |
132 | */ | 142 | */ |
133 | private static String getTypeDefClassDefinition(String yangName) { | 143 | private static String getTypeDefClassDefinition(String yangName) { |
134 | - | ||
135 | return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 144 | return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
136 | } | 145 | } |
137 | } | 146 | } | ... | ... |
... | @@ -20,12 +20,20 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ... | @@ -20,12 +20,20 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; |
20 | 20 | ||
21 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; | 21 | import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition; |
22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 22 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
23 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | ||
24 | +import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST; | ||
25 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ||
23 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 26 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
27 | +import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | ||
24 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
25 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
30 | +import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
26 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; |
27 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.LIST; |
34 | +import static org.onosproject.yangutils.utils.UtilConstants.NEW; | ||
28 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
36 | +import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; | ||
29 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 37 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
30 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
31 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
... | @@ -127,6 +135,18 @@ public final class JavaCodeSnippetGen { | ... | @@ -127,6 +135,18 @@ public final class JavaCodeSnippetGen { |
127 | } | 135 | } |
128 | 136 | ||
129 | /** | 137 | /** |
138 | + * Returns attribute of augmented info for generated impl file. | ||
139 | + * | ||
140 | + * @return attribute of augmented info for generated impl file | ||
141 | + */ | ||
142 | + public static String getAugmentedInfoAttribute() { | ||
143 | + return FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE | ||
144 | + + getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST | ||
145 | + + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN | ||
146 | + + NEW_LINE; | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
130 | * Returns based on the file type and the YANG name of the file, generate the class | 150 | * Returns based on the file type and the YANG name of the file, generate the class |
131 | * / interface definition close. | 151 | * / interface definition close. |
132 | * | 152 | * | ... | ... |
... | @@ -40,16 +40,21 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -40,16 +40,21 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; | 40 | 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; | 41 | 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; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
43 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute; | ||
43 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; | 44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; |
44 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; | 45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; |
45 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
47 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; | ||
48 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; | ||
46 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; | 49 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
47 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; | 50 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
48 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; | 51 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
49 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; | 52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; |
50 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; | 53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; |
54 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl; | ||
51 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; | 55 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose; |
52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; | 56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen; |
57 | +import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; | ||
53 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 58 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
54 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
55 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
... | @@ -67,12 +72,58 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; | ... | @@ -67,12 +72,58 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; |
67 | public final class JavaFileGenerator { | 72 | public final class JavaFileGenerator { |
68 | 73 | ||
69 | /** | 74 | /** |
75 | + * Flag to check whether generated interface file need to extends any class. | ||
76 | + */ | ||
77 | + private static boolean isExtendsList = false; | ||
78 | + | ||
79 | + /** | ||
80 | + * List of classes to be extended by generated interface file. | ||
81 | + */ | ||
82 | + private static List<String> extendsList = new ArrayList<>(); | ||
83 | + | ||
84 | + /** | ||
70 | * Creates an instance of java file generator. | 85 | * Creates an instance of java file generator. |
71 | */ | 86 | */ |
72 | private JavaFileGenerator() { | 87 | private JavaFileGenerator() { |
73 | } | 88 | } |
74 | 89 | ||
75 | /** | 90 | /** |
91 | + * Returns true if extends list is not empty. | ||
92 | + * | ||
93 | + * @return true or false | ||
94 | + */ | ||
95 | + public static boolean isExtendsList() { | ||
96 | + return isExtendsList; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Sets the value of is extends list. | ||
101 | + * | ||
102 | + * @param isExtends true or false | ||
103 | + */ | ||
104 | + public static void setIsExtendsList(boolean isExtends) { | ||
105 | + isExtendsList = isExtends; | ||
106 | + } | ||
107 | + | ||
108 | + /** | ||
109 | + * Returns list of extended classes. | ||
110 | + * | ||
111 | + * @return list of extended classes | ||
112 | + */ | ||
113 | + public static List<String> getExtendsList() { | ||
114 | + return extendsList; | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * Sets the list of extended classes. | ||
119 | + * | ||
120 | + * @param extendList list of extended classes | ||
121 | + */ | ||
122 | + public static void setExtendsList(List<String> extendList) { | ||
123 | + extendsList = extendList; | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
76 | * Returns generated interface file for current node. | 127 | * Returns generated interface file for current node. |
77 | * | 128 | * |
78 | * @param file file | 129 | * @param file file |
... | @@ -91,6 +142,7 @@ public final class JavaFileGenerator { | ... | @@ -91,6 +142,7 @@ public final class JavaFileGenerator { |
91 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 142 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
92 | 143 | ||
93 | initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path); | 144 | initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path); |
145 | + | ||
94 | if (isAttrPresent) { | 146 | if (isAttrPresent) { |
95 | /** | 147 | /** |
96 | * Add getter methods to interface file. | 148 | * Add getter methods to interface file. |
... | @@ -258,6 +310,12 @@ public final class JavaFileGenerator { | ... | @@ -258,6 +310,12 @@ public final class JavaFileGenerator { |
258 | + " while impl class file generation"); | 310 | + " while impl class file generation"); |
259 | } | 311 | } |
260 | 312 | ||
313 | + /** | ||
314 | + * Add attribute for augmented info's list. | ||
315 | + */ | ||
316 | + if (isHasAugmentationExtended(getExtendsList())) { | ||
317 | + insertDataIntoJavaFile(file, getAugmentedInfoAttribute()); | ||
318 | + } | ||
261 | insertDataIntoJavaFile(file, NEW_LINE); | 319 | insertDataIntoJavaFile(file, NEW_LINE); |
262 | try { | 320 | try { |
263 | /** | 321 | /** |
... | @@ -298,6 +356,16 @@ public final class JavaFileGenerator { | ... | @@ -298,6 +356,16 @@ public final class JavaFileGenerator { |
298 | throw new IOException("No data found in temporary java code fragment files for " + className | 356 | throw new IOException("No data found in temporary java code fragment files for " + className |
299 | + " while impl class file generation"); | 357 | + " while impl class file generation"); |
300 | } | 358 | } |
359 | + | ||
360 | + /** | ||
361 | + * Add method for augment info's list. | ||
362 | + */ | ||
363 | + if (isHasAugmentationExtended(getExtendsList())) { | ||
364 | + methods.add(getAddAugmentInfoMethodImpl()); | ||
365 | + methods.add(getAugmentInfoListImpl()); | ||
366 | + methods.add(getRemoveAugmentationImpl()); | ||
367 | + } | ||
368 | + | ||
301 | /** | 369 | /** |
302 | * Add methods in impl class. | 370 | * Add methods in impl class. |
303 | */ | 371 | */ |
... | @@ -310,7 +378,7 @@ public final class JavaFileGenerator { | ... | @@ -310,7 +378,7 @@ public final class JavaFileGenerator { |
310 | } | 378 | } |
311 | 379 | ||
312 | /** | 380 | /** |
313 | - * Generate class file for type def. | 381 | + * Generates class file for type def. |
314 | * | 382 | * |
315 | * @param file generated file | 383 | * @param file generated file |
316 | * @param curNode current YANG node | 384 | * @param curNode current YANG node |
... | @@ -364,11 +432,6 @@ public final class JavaFileGenerator { | ... | @@ -364,11 +432,6 @@ public final class JavaFileGenerator { |
364 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); | 432 | methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode)); |
365 | 433 | ||
366 | /** | 434 | /** |
367 | - * Setter method. | ||
368 | - */ | ||
369 | - methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().addTypeDefsSetter()); | ||
370 | - | ||
371 | - /** | ||
372 | * Hash code method. | 435 | * Hash code method. |
373 | */ | 436 | */ |
374 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( | 437 | methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString( |
... | @@ -388,7 +451,7 @@ public final class JavaFileGenerator { | ... | @@ -388,7 +451,7 @@ public final class JavaFileGenerator { |
388 | 451 | ||
389 | } catch (IOException e) { | 452 | } catch (IOException e) { |
390 | throw new IOException("No data found in temporary java code fragment files for " + className | 453 | throw new IOException("No data found in temporary java code fragment files for " + className |
391 | - + " while tyoe def class file generation"); | 454 | + + " while type def class file generation"); |
392 | } | 455 | } |
393 | 456 | ||
394 | for (String method : methods) { | 457 | for (String method : methods) { | ... | ... |
... | @@ -23,6 +23,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -23,6 +23,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; |
24 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; | 24 | import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
25 | import static org.onosproject.yangutils.utils.UtilConstants.AND; | 25 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
26 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; | ||
27 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ||
26 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
27 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.BUILD; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
... | @@ -100,7 +102,6 @@ public final class MethodsGenerator { | ... | @@ -100,7 +102,6 @@ public final class MethodsGenerator { |
100 | * @return method string for builder interface | 102 | * @return method string for builder interface |
101 | */ | 103 | */ |
102 | public static String parseBuilderInterfaceBuildMethodString(String name) { | 104 | public static String parseBuilderInterfaceBuildMethodString(String name) { |
103 | - | ||
104 | return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name); | 105 | return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name); |
105 | } | 106 | } |
106 | 107 | ||
... | @@ -142,7 +143,6 @@ public final class MethodsGenerator { | ... | @@ -142,7 +143,6 @@ public final class MethodsGenerator { |
142 | * @return constructor string | 143 | * @return constructor string |
143 | */ | 144 | */ |
144 | public static String getConstructorString(String name) { | 145 | public static String getConstructorString(String name) { |
145 | - | ||
146 | return getJavaDoc(CONSTRUCTOR, name, false); | 146 | return getJavaDoc(CONSTRUCTOR, name, false); |
147 | } | 147 | } |
148 | 148 | ||
... | @@ -154,7 +154,6 @@ public final class MethodsGenerator { | ... | @@ -154,7 +154,6 @@ public final class MethodsGenerator { |
154 | * @return default constructor string | 154 | * @return default constructor string |
155 | */ | 155 | */ |
156 | public static String getDefaultConstructorString(String name, String modifierType) { | 156 | public static String getDefaultConstructorString(String name, String modifierType) { |
157 | - | ||
158 | return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType); | 157 | return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType); |
159 | } | 158 | } |
160 | 159 | ||
... | @@ -186,7 +185,6 @@ public final class MethodsGenerator { | ... | @@ -186,7 +185,6 @@ public final class MethodsGenerator { |
186 | * @return setter for type def's attribute | 185 | * @return setter for type def's attribute |
187 | */ | 186 | */ |
188 | private static String getTypeDefConstructorString(String type, String name, String className) { | 187 | private static String getTypeDefConstructorString(String type, String name, String className) { |
189 | - | ||
190 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE | 188 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE |
191 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD | 189 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD |
192 | + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION | 190 | + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION |
... | @@ -200,7 +198,6 @@ public final class MethodsGenerator { | ... | @@ -200,7 +198,6 @@ public final class MethodsGenerator { |
200 | * @return check not null string | 198 | * @return check not null string |
201 | */ | 199 | */ |
202 | public static String getCheckNotNull(String name) { | 200 | public static String getCheckNotNull(String name) { |
203 | - | ||
204 | return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name | 201 | return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name |
205 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | 202 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
206 | } | 203 | } |
... | @@ -212,7 +209,6 @@ public final class MethodsGenerator { | ... | @@ -212,7 +209,6 @@ public final class MethodsGenerator { |
212 | * @return build string | 209 | * @return build string |
213 | */ | 210 | */ |
214 | public static String getBuildString(String name) { | 211 | public static String getBuildString(String name) { |
215 | - | ||
216 | return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name); | 212 | return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name); |
217 | } | 213 | } |
218 | 214 | ||
... | @@ -242,7 +238,6 @@ public final class MethodsGenerator { | ... | @@ -242,7 +238,6 @@ public final class MethodsGenerator { |
242 | * @return getter for attribute | 238 | * @return getter for attribute |
243 | */ | 239 | */ |
244 | private static String getGetter(String type, String name) { | 240 | private static String getGetter(String type, String name) { |
245 | - | ||
246 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name) | 241 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name) |
247 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | 242 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
248 | + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 243 | + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
... | @@ -275,7 +270,6 @@ public final class MethodsGenerator { | ... | @@ -275,7 +270,6 @@ public final class MethodsGenerator { |
275 | * @return setter for attribute | 270 | * @return setter for attribute |
276 | */ | 271 | */ |
277 | private static String getSetter(String className, String name, String type) { | 272 | private static String getSetter(String className, String name, String type) { |
278 | - | ||
279 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + SET_METHOD_PREFIX | 273 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + SET_METHOD_PREFIX |
280 | + getCaptialCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE | 274 | + getCaptialCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE |
281 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE | 275 | + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE |
... | @@ -304,7 +298,6 @@ public final class MethodsGenerator { | ... | @@ -304,7 +298,6 @@ public final class MethodsGenerator { |
304 | * @return setter for type def's attribute | 298 | * @return setter for type def's attribute |
305 | */ | 299 | */ |
306 | private static String getTypeDefSetter(String type, String name) { | 300 | private static String getTypeDefSetter(String type, String name) { |
307 | - | ||
308 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCaptialCase(name) | 301 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCaptialCase(name) |
309 | + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | 302 | + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
310 | + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE | 303 | + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE |
... | @@ -317,7 +310,6 @@ public final class MethodsGenerator { | ... | @@ -317,7 +310,6 @@ public final class MethodsGenerator { |
317 | * @return override string | 310 | * @return override string |
318 | */ | 311 | */ |
319 | public static String getOverRideString() { | 312 | public static String getOverRideString() { |
320 | - | ||
321 | return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE; | 313 | return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE; |
322 | } | 314 | } |
323 | 315 | ||
... | @@ -346,7 +338,6 @@ public final class MethodsGenerator { | ... | @@ -346,7 +338,6 @@ public final class MethodsGenerator { |
346 | * @return getter for interface | 338 | * @return getter for interface |
347 | */ | 339 | */ |
348 | private static String getGetterInterfaceString(String returnType, String yangName) { | 340 | private static String getGetterInterfaceString(String returnType, String yangName) { |
349 | - | ||
350 | return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCaptialCase(yangName) | 341 | return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCaptialCase(yangName) |
351 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; | 342 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN; |
352 | } | 343 | } |
... | @@ -378,7 +369,6 @@ public final class MethodsGenerator { | ... | @@ -378,7 +369,6 @@ public final class MethodsGenerator { |
378 | * @return setter string | 369 | * @return setter string |
379 | */ | 370 | */ |
380 | private static String getSetterInterfaceString(String className, String attrName, String attrType) { | 371 | private static String getSetterInterfaceString(String className, String attrName, String attrType) { |
381 | - | ||
382 | return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName) | 372 | return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName) |
383 | + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; | 373 | + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN; |
384 | } | 374 | } |
... | @@ -389,7 +379,6 @@ public final class MethodsGenerator { | ... | @@ -389,7 +379,6 @@ public final class MethodsGenerator { |
389 | * @return list string | 379 | * @return list string |
390 | */ | 380 | */ |
391 | private static String getListString() { | 381 | private static String getListString() { |
392 | - | ||
393 | return LIST + DIAMOND_OPEN_BRACKET; | 382 | return LIST + DIAMOND_OPEN_BRACKET; |
394 | } | 383 | } |
395 | 384 | ||
... | @@ -416,7 +405,6 @@ public final class MethodsGenerator { | ... | @@ -416,7 +405,6 @@ public final class MethodsGenerator { |
416 | * @return build method for interface | 405 | * @return build method for interface |
417 | */ | 406 | */ |
418 | public static String getBuildForInterface(String yangName) { | 407 | public static String getBuildForInterface(String yangName) { |
419 | - | ||
420 | return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN | 408 | return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN |
421 | + NEW_LINE; | 409 | + NEW_LINE; |
422 | } | 410 | } |
... | @@ -462,7 +450,6 @@ public final class MethodsGenerator { | ... | @@ -462,7 +450,6 @@ public final class MethodsGenerator { |
462 | * @return build method string for class | 450 | * @return build method string for class |
463 | */ | 451 | */ |
464 | public static String getBuild(String yangName) { | 452 | public static String getBuild(String yangName) { |
465 | - | ||
466 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS | 453 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
467 | + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE | 454 | + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE |
468 | + yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE | 455 | + yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE |
... | @@ -477,7 +464,6 @@ public final class MethodsGenerator { | ... | @@ -477,7 +464,6 @@ public final class MethodsGenerator { |
477 | * @return Default constructor for class | 464 | * @return Default constructor for class |
478 | */ | 465 | */ |
479 | private static String getDefaultConstructor(String name, String modifierType) { | 466 | private static String getDefaultConstructor(String name, String modifierType) { |
480 | - | ||
481 | return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE | 467 | return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE |
482 | + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 468 | + OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
483 | } | 469 | } |
... | @@ -488,7 +474,6 @@ public final class MethodsGenerator { | ... | @@ -488,7 +474,6 @@ public final class MethodsGenerator { |
488 | * @return to string method open string | 474 | * @return to string method open string |
489 | */ | 475 | */ |
490 | public static String getToStringMethodOpen() { | 476 | public static String getToStringMethodOpen() { |
491 | - | ||
492 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO | 477 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO |
493 | + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | 478 | + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
494 | + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE; | 479 | + EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE; |
... | @@ -500,7 +485,6 @@ public final class MethodsGenerator { | ... | @@ -500,7 +485,6 @@ public final class MethodsGenerator { |
500 | * @return to string method close string | 485 | * @return to string method close string |
501 | */ | 486 | */ |
502 | public static String getToStringMethodClose() { | 487 | public static String getToStringMethodClose() { |
503 | - | ||
504 | return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS | 488 | return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS |
505 | + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; | 489 | + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
506 | } | 490 | } |
... | @@ -514,10 +498,8 @@ public final class MethodsGenerator { | ... | @@ -514,10 +498,8 @@ public final class MethodsGenerator { |
514 | public static String getToStringMethod(JavaAttributeInfo attr) { | 498 | public static String getToStringMethod(JavaAttributeInfo attr) { |
515 | 499 | ||
516 | String attributeName = getSmallCase(attr.getAttributeName()); | 500 | String attributeName = getSmallCase(attr.getAttributeName()); |
517 | - | ||
518 | return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES | 501 | return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES |
519 | + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; | 502 | + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS; |
520 | - | ||
521 | } | 503 | } |
522 | 504 | ||
523 | /** | 505 | /** |
... | @@ -526,7 +508,6 @@ public final class MethodsGenerator { | ... | @@ -526,7 +508,6 @@ public final class MethodsGenerator { |
526 | * @return hash code method open string | 508 | * @return hash code method open string |
527 | */ | 509 | */ |
528 | public static String getHashCodeMethodOpen() { | 510 | public static String getHashCodeMethodOpen() { |
529 | - | ||
530 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING | 511 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING |
531 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | 512 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
532 | + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS; | 513 | + RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS; |
... | @@ -539,7 +520,6 @@ public final class MethodsGenerator { | ... | @@ -539,7 +520,6 @@ public final class MethodsGenerator { |
539 | * @return to hash code method close string | 520 | * @return to hash code method close string |
540 | */ | 521 | */ |
541 | public static String getHashCodeMethodClose(String hashcodeString) { | 522 | public static String getHashCodeMethodClose(String hashcodeString) { |
542 | - | ||
543 | hashcodeString = trimAtLast(hashcodeString, COMMA); | 523 | hashcodeString = trimAtLast(hashcodeString, COMMA); |
544 | hashcodeString = trimAtLast(hashcodeString, SPACE); | 524 | hashcodeString = trimAtLast(hashcodeString, SPACE); |
545 | return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET | 525 | return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
... | @@ -553,7 +533,6 @@ public final class MethodsGenerator { | ... | @@ -553,7 +533,6 @@ public final class MethodsGenerator { |
553 | * @return hash code method | 533 | * @return hash code method |
554 | */ | 534 | */ |
555 | public static String getHashCodeMethod(JavaAttributeInfo attr) { | 535 | public static String getHashCodeMethod(JavaAttributeInfo attr) { |
556 | - | ||
557 | return getSmallCase(attr.getAttributeName()) + COMMA + SPACE; | 536 | return getSmallCase(attr.getAttributeName()) + COMMA + SPACE; |
558 | } | 537 | } |
559 | 538 | ||
... | @@ -564,7 +543,6 @@ public final class MethodsGenerator { | ... | @@ -564,7 +543,6 @@ public final class MethodsGenerator { |
564 | * @return equals method open string | 543 | * @return equals method open string |
565 | */ | 544 | */ |
566 | public static String getEqualsMethodOpen(String className) { | 545 | public static String getEqualsMethodOpen(String className) { |
567 | - | ||
568 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING | 546 | return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING |
569 | + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET | 547 | + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET |
570 | + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className); | 548 | + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className); |
... | @@ -576,7 +554,6 @@ public final class MethodsGenerator { | ... | @@ -576,7 +554,6 @@ public final class MethodsGenerator { |
576 | * @return if condition string | 554 | * @return if condition string |
577 | */ | 555 | */ |
578 | private static String getEqualsMethodsCommonIfCondition() { | 556 | private static String getEqualsMethodsCommonIfCondition() { |
579 | - | ||
580 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ | 557 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ |
581 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE | 558 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE |
582 | + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; | 559 | + TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
... | @@ -589,7 +566,6 @@ public final class MethodsGenerator { | ... | @@ -589,7 +566,6 @@ public final class MethodsGenerator { |
589 | * @return if condition string | 566 | * @return if condition string |
590 | */ | 567 | */ |
591 | private static String getEqualsMethodsSpecificIfCondition(String className) { | 568 | private static String getEqualsMethodsSpecificIfCondition(String className) { |
592 | - | ||
593 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className | 569 | return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className |
594 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className | 570 | + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className |
595 | + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE | 571 | + SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE |
... | @@ -603,7 +579,6 @@ public final class MethodsGenerator { | ... | @@ -603,7 +579,6 @@ public final class MethodsGenerator { |
603 | * @return equals method close string | 579 | * @return equals method close string |
604 | */ | 580 | */ |
605 | public static String getEqualsMethodClose(String equalMethodString) { | 581 | public static String getEqualsMethodClose(String equalMethodString) { |
606 | - | ||
607 | equalMethodString = trimAtLast(equalMethodString, AND); | 582 | equalMethodString = trimAtLast(equalMethodString, AND); |
608 | equalMethodString = trimAtLast(equalMethodString, AND); | 583 | equalMethodString = trimAtLast(equalMethodString, AND); |
609 | equalMethodString = trimAtLast(equalMethodString, SPACE); | 584 | equalMethodString = trimAtLast(equalMethodString, SPACE); |
... | @@ -622,11 +597,9 @@ public final class MethodsGenerator { | ... | @@ -622,11 +597,9 @@ public final class MethodsGenerator { |
622 | public static String getEqualsMethod(JavaAttributeInfo attr) { | 597 | public static String getEqualsMethod(JavaAttributeInfo attr) { |
623 | 598 | ||
624 | String attributeName = getSmallCase(attr.getAttributeName()); | 599 | String attributeName = getSmallCase(attr.getAttributeName()); |
625 | - | ||
626 | return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS | 600 | return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS |
627 | + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND | 601 | + attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND |
628 | + AND; | 602 | + AND; |
629 | - | ||
630 | } | 603 | } |
631 | 604 | ||
632 | /** | 605 | /** |
... | @@ -639,11 +612,57 @@ public final class MethodsGenerator { | ... | @@ -639,11 +612,57 @@ public final class MethodsGenerator { |
639 | public static String getOfMethod(String name, JavaAttributeInfo attr) { | 612 | public static String getOfMethod(String name, JavaAttributeInfo attr) { |
640 | 613 | ||
641 | String attrQuaifiedType = getReturnType(attr); | 614 | String attrQuaifiedType = getReturnType(attr); |
642 | - | ||
643 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS | 615 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS |
644 | + attrQuaifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | 616 | + attrQuaifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE |
645 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE | 617 | + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE |
646 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; | 618 | + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; |
647 | } | 619 | } |
648 | 620 | ||
621 | + /** | ||
622 | + * Returns implementation of add augmentation method of HasAugmentation class. | ||
623 | + * | ||
624 | + * @return implementation of add augmentation method of HasAugmentation class | ||
625 | + */ | ||
626 | + public static String getAddAugmentInfoMethodImpl() { | ||
627 | + String method = FOUR_SPACE_INDENTATION; | ||
628 | + method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING | ||
629 | + + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE | ||
630 | + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST | ||
631 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE | ||
632 | + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
633 | + | ||
634 | + return method; | ||
635 | + } | ||
636 | + | ||
637 | + /** | ||
638 | + * Returns implementation of get augment info list method of HasAugmentation class. | ||
639 | + * | ||
640 | + * @return implementation of get augment info list method of HasAugmentation class | ||
641 | + */ | ||
642 | + public static String getAugmentInfoListImpl() { | ||
643 | + | ||
644 | + String method = FOUR_SPACE_INDENTATION; | ||
645 | + method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + LIST + DIAMOND_OPEN_BRACKET | ||
646 | + + AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST | ||
647 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
648 | + + RETURN + SPACE + getSmallCase(AUGMENTED_INFO) + LIST + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION | ||
649 | + + CLOSE_CURLY_BRACKET; | ||
650 | + return method; | ||
651 | + } | ||
652 | + | ||
653 | + /** | ||
654 | + * Returns implementation of remove augmentation method of HasAugmentation class. | ||
655 | + * | ||
656 | + * @return implementation of remove augmentation method of HasAugmentation class | ||
657 | + */ | ||
658 | + public static String getRemoveAugmentationImpl() { | ||
659 | + String method = FOUR_SPACE_INDENTATION; | ||
660 | + method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove" | ||
661 | + + AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE | ||
662 | + + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS | ||
663 | + + CLOSE_PARENTHESIS + PERIOD + "clear" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE | ||
664 | + + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
665 | + return method; | ||
666 | + } | ||
667 | + | ||
649 | } | 668 | } | ... | ... |
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.File; | ||
20 | +import java.io.IOException; | ||
21 | +import java.util.List; | ||
22 | + | ||
23 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
24 | +import org.onosproject.yangutils.translator.tojava.HasJavaImportData; | ||
25 | + | ||
26 | +import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport; | ||
27 | +import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport; | ||
28 | +import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForArrayList; | ||
29 | +import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForList; | ||
30 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ||
31 | +import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; | ||
32 | +import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | ||
33 | + | ||
34 | +/** | ||
35 | + * Represents utilities for temporary java code fragments. | ||
36 | + */ | ||
37 | +public final class TempJavaCodeFragmentFilesUtils { | ||
38 | + | ||
39 | + /** | ||
40 | + * Creates a private instance of temporary java code fragment utils. | ||
41 | + */ | ||
42 | + private TempJavaCodeFragmentFilesUtils() { | ||
43 | + } | ||
44 | + | ||
45 | + /** | ||
46 | + * Adds imports for ToString and HashCodeMethod. | ||
47 | + * | ||
48 | + * @param curNode current YANG node | ||
49 | + * @param imports import list | ||
50 | + * @return import list | ||
51 | + */ | ||
52 | + public static List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) { | ||
53 | + if (curNode instanceof HasJavaImportData) { | ||
54 | + imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals()); | ||
55 | + imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString()); | ||
56 | + } | ||
57 | + return imports; | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Adds import for HasAugmentation class. | ||
62 | + * | ||
63 | + * @param curNode current YANG node | ||
64 | + * @param imports list of imports | ||
65 | + * @param operation add or delete import | ||
66 | + * @return import for HasAugmentation class | ||
67 | + */ | ||
68 | + public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports, boolean operation) { | ||
69 | + if (curNode instanceof HasJavaImportData) { | ||
70 | + String thisImport = getHasAugmentationImport(); | ||
71 | + performOperationOnImports(imports, thisImport, operation); | ||
72 | + } | ||
73 | + return imports; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Adds import for AugmentedInfo class. | ||
78 | + * | ||
79 | + * @param curNode current YANG node | ||
80 | + * @param imports list of imports | ||
81 | + * @param operation add or delete import | ||
82 | + * @return import for AugmentedInfo class | ||
83 | + */ | ||
84 | + public static List<String> addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) { | ||
85 | + if (curNode instanceof HasJavaImportData) { | ||
86 | + String thisImport = getAugmentedInfoImport(); | ||
87 | + performOperationOnImports(imports, thisImport, operation); | ||
88 | + } | ||
89 | + return imports; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Adds import for array list. | ||
94 | + * | ||
95 | + * @param curNode current YANG node | ||
96 | + * @param imports list of imports | ||
97 | + * @param operation add or delete import | ||
98 | + * @return import for HasAugmentation class | ||
99 | + */ | ||
100 | + public static List<String> addArrayListImport(YangNode curNode, List<String> imports, boolean operation) { | ||
101 | + if (curNode instanceof HasJavaImportData) { | ||
102 | + String arrayListImport = getImportForArrayList(); | ||
103 | + String listImport = getImportForList(); | ||
104 | + performOperationOnImports(imports, arrayListImport, operation); | ||
105 | + if (!imports.contains(listImport)) { | ||
106 | + /** | ||
107 | + * List can be there because of attribute also , so no need to remove it and operation will | ||
108 | + * always be add(true). | ||
109 | + */ | ||
110 | + performOperationOnImports(imports, listImport, true); | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | + return imports; | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * Performs given operations on import list. | ||
119 | + * | ||
120 | + * @param imports list of imports | ||
121 | + * @param curImport current import | ||
122 | + * @param operation add or remove | ||
123 | + * @return import list | ||
124 | + */ | ||
125 | + private static List<String> performOperationOnImports(List<String> imports, String curImport, boolean operation) { | ||
126 | + if (operation) { | ||
127 | + imports.add(curImport); | ||
128 | + } else { | ||
129 | + imports.remove(curImport); | ||
130 | + } | ||
131 | + java.util.Collections.sort(imports); | ||
132 | + return imports; | ||
133 | + } | ||
134 | + | ||
135 | + /** | ||
136 | + * Prepares java file generator for extends list. | ||
137 | + * | ||
138 | + * @param extendsList list of classes need to be extended | ||
139 | + */ | ||
140 | + public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) { | ||
141 | + | ||
142 | + if (!extendsList.isEmpty() && !extendsList.equals(null)) { | ||
143 | + JavaFileGenerator.setExtendsList(extendsList); | ||
144 | + JavaFileGenerator.setIsExtendsList(true); | ||
145 | + } else { | ||
146 | + JavaFileGenerator.getExtendsList().clear(); | ||
147 | + JavaFileGenerator.setIsExtendsList(false); | ||
148 | + } | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Returns true if HasAugmentation class needs to be extended. | ||
153 | + * | ||
154 | + * @param extendsList list of classes need to be extended | ||
155 | + * @return true or false | ||
156 | + */ | ||
157 | + public static boolean isHasAugmentationExtended(List<String> extendsList) { | ||
158 | + if (extendsList != null && extendsList.contains(HAS_AUGMENTATION)) { | ||
159 | + return true; | ||
160 | + } | ||
161 | + return false; | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * Returns true if AugmentedInfo class needs to be extended. | ||
166 | + * | ||
167 | + * @param extendsList list of classes need to be extended | ||
168 | + * @return true or false | ||
169 | + */ | ||
170 | + public static boolean isAugmentedInfoExtended(List<String> extendsList) { | ||
171 | + if (extendsList != null && extendsList.contains(AUGMENTED_INFO)) { | ||
172 | + return true; | ||
173 | + } | ||
174 | + return false; | ||
175 | + } | ||
176 | + | ||
177 | + /** | ||
178 | + * Closes the file handle for temporary file. | ||
179 | + * | ||
180 | + * @param file file to be closed | ||
181 | + * @param toBeDeleted flag to indicate if file needs to be deleted | ||
182 | + * @throws IOException when failed to close the file handle | ||
183 | + */ | ||
184 | + public static void closeFile(File file, boolean toBeDeleted) throws IOException { | ||
185 | + | ||
186 | + if (file != null) { | ||
187 | + updateFileHandle(file, null, true); | ||
188 | + if (toBeDeleted) { | ||
189 | + file.delete(); | ||
190 | + } | ||
191 | + } | ||
192 | + } | ||
193 | +} |
... | @@ -17,8 +17,17 @@ | ... | @@ -17,8 +17,17 @@ |
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 | + | ||
21 | +import org.onosproject.yangutils.datamodel.YangAugment; | ||
22 | +import org.onosproject.yangutils.datamodel.YangCase; | ||
23 | +import org.onosproject.yangutils.datamodel.YangChoice; | ||
24 | +import org.onosproject.yangutils.datamodel.YangContainer; | ||
25 | +import org.onosproject.yangutils.datamodel.YangInput; | ||
20 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 26 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
27 | +import org.onosproject.yangutils.datamodel.YangList; | ||
21 | import org.onosproject.yangutils.datamodel.YangNode; | 28 | import org.onosproject.yangutils.datamodel.YangNode; |
29 | +import org.onosproject.yangutils.datamodel.YangNotification; | ||
30 | +import org.onosproject.yangutils.datamodel.YangOutput; | ||
22 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 31 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
23 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; | 32 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; |
24 | 33 | ||
... | @@ -26,6 +35,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy | ... | @@ -26,6 +35,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy |
26 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
27 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; | 36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage; |
28 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; | 37 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage; |
38 | +import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ||
39 | +import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; | ||
29 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; | 40 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath; |
30 | 41 | ||
31 | /** | 42 | /** |
... | @@ -143,6 +154,21 @@ public final class YangJavaModelUtils { | ... | @@ -143,6 +154,21 @@ public final class YangJavaModelUtils { |
143 | 154 | ||
144 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 155 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
145 | .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); | 156 | .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance); |
157 | + | ||
158 | + /** | ||
159 | + * For augmentation of nodes. | ||
160 | + */ | ||
161 | + if (javaCodeGeneratorInfo instanceof YangContainer | ||
162 | + || javaCodeGeneratorInfo instanceof YangCase | ||
163 | + || javaCodeGeneratorInfo instanceof YangChoice | ||
164 | + || javaCodeGeneratorInfo instanceof YangInput | ||
165 | + || javaCodeGeneratorInfo instanceof YangList | ||
166 | + || javaCodeGeneratorInfo instanceof YangNotification | ||
167 | + || javaCodeGeneratorInfo instanceof YangOutput) { | ||
168 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(HAS_AUGMENTATION); | ||
169 | + } else if (javaCodeGeneratorInfo instanceof YangAugment) { | ||
170 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO); | ||
171 | + } | ||
146 | } | 172 | } |
147 | 173 | ||
148 | /** | 174 | /** | ... | ... |
... | @@ -441,58 +441,69 @@ public final class UtilConstants { | ... | @@ -441,58 +441,69 @@ public final class UtilConstants { |
441 | * String built in java type. | 441 | * String built in java type. |
442 | */ | 442 | */ |
443 | public static final String STRING_DATA_TYPE = "String"; | 443 | public static final String STRING_DATA_TYPE = "String"; |
444 | + | ||
444 | /** | 445 | /** |
445 | - * java.lang.* packages. | 446 | + * Java.lang.* packages. |
446 | */ | 447 | */ |
447 | public static final String JAVA_LANG = "java.lang"; | 448 | public static final String JAVA_LANG = "java.lang"; |
448 | 449 | ||
449 | /** | 450 | /** |
450 | - * boolean built in java type. | 451 | + * Java.math.* packages. |
452 | + */ | ||
453 | + public static final String JAVA_MATH = "java.math"; | ||
454 | + | ||
455 | + /** | ||
456 | + * Boolean built in java type. | ||
451 | */ | 457 | */ |
452 | public static final String BOOLEAN_DATA_TYPE = "boolean"; | 458 | public static final String BOOLEAN_DATA_TYPE = "boolean"; |
453 | 459 | ||
454 | /** | 460 | /** |
455 | - * byte java built in type. | 461 | + * BigInteger built in java type. |
462 | + */ | ||
463 | + public static final String BIG_INTEGER = "BigInteger"; | ||
464 | + | ||
465 | + /** | ||
466 | + * Byte java built in type. | ||
456 | */ | 467 | */ |
457 | public static final String BYTE = "byte"; | 468 | public static final String BYTE = "byte"; |
458 | 469 | ||
459 | /** | 470 | /** |
460 | - * short java built in type. | 471 | + * Short java built in type. |
461 | */ | 472 | */ |
462 | public static final String SHORT = "short"; | 473 | public static final String SHORT = "short"; |
463 | 474 | ||
464 | /** | 475 | /** |
465 | - * int java built in type. | 476 | + * Int java built in type. |
466 | */ | 477 | */ |
467 | public static final String INT = "int"; | 478 | public static final String INT = "int"; |
468 | 479 | ||
469 | /** | 480 | /** |
470 | - * long java built in type. | 481 | + * Long java built in type. |
471 | */ | 482 | */ |
472 | public static final String LONG = "long"; | 483 | public static final String LONG = "long"; |
473 | 484 | ||
474 | /** | 485 | /** |
475 | - * float java built in type. | 486 | + * Float java built in type. |
476 | */ | 487 | */ |
477 | public static final String FLOAT = "float"; | 488 | public static final String FLOAT = "float"; |
478 | 489 | ||
479 | /** | 490 | /** |
480 | - * double java built in type. | 491 | + * Double java built in type. |
481 | */ | 492 | */ |
482 | public static final String DOUBLE = "double"; | 493 | public static final String DOUBLE = "double"; |
483 | 494 | ||
484 | /** | 495 | /** |
485 | - * boolean built in java wrapper type. | 496 | + * Boolean built in java wrapper type. |
486 | */ | 497 | */ |
487 | public static final String BOOLEAN_WRAPPER = "Boolean"; | 498 | public static final String BOOLEAN_WRAPPER = "Boolean"; |
488 | 499 | ||
489 | /** | 500 | /** |
490 | - * byte java built in wrapper type. | 501 | + * Byte java built in wrapper type. |
491 | */ | 502 | */ |
492 | public static final String BYTE_WRAPPER = "Byte"; | 503 | public static final String BYTE_WRAPPER = "Byte"; |
493 | 504 | ||
494 | /** | 505 | /** |
495 | - * short java built in wrapper type. | 506 | + * Short java built in wrapper type. |
496 | */ | 507 | */ |
497 | public static final String SHORT_WRAPPER = "Short"; | 508 | public static final String SHORT_WRAPPER = "Short"; |
498 | 509 | ||
... | @@ -502,17 +513,17 @@ public final class UtilConstants { | ... | @@ -502,17 +513,17 @@ public final class UtilConstants { |
502 | public static final String INTEGER_WRAPPER = "Integer"; | 513 | public static final String INTEGER_WRAPPER = "Integer"; |
503 | 514 | ||
504 | /** | 515 | /** |
505 | - * long java built in wrapper type. | 516 | + * Long java built in wrapper type. |
506 | */ | 517 | */ |
507 | public static final String LONG_WRAPPER = "Long"; | 518 | public static final String LONG_WRAPPER = "Long"; |
508 | 519 | ||
509 | /** | 520 | /** |
510 | - * float java built in wrapper type. | 521 | + * Float java built in wrapper type. |
511 | */ | 522 | */ |
512 | public static final String FLOAT_WRAPPER = "Float"; | 523 | public static final String FLOAT_WRAPPER = "Float"; |
513 | 524 | ||
514 | /** | 525 | /** |
515 | - * double java built in wrapper type. | 526 | + * Double java built in wrapper type. |
516 | */ | 527 | */ |
517 | public static final String DOUBLE_WRAPPER = "Double"; | 528 | public static final String DOUBLE_WRAPPER = "Double"; |
518 | 529 | ||
... | @@ -687,6 +698,41 @@ public final class UtilConstants { | ... | @@ -687,6 +698,41 @@ public final class UtilConstants { |
687 | public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n"; | 698 | public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n"; |
688 | 699 | ||
689 | /** | 700 | /** |
701 | + * Static attribute for HasAugmentation class import package. | ||
702 | + */ | ||
703 | + public static final String HAS_AUGMENTATION_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava"; | ||
704 | + | ||
705 | + /** | ||
706 | + * Static attribute for HasAugmentation class import class. | ||
707 | + */ | ||
708 | + public static final String HAS_AUGMENTATION_CLASS_IMPORT_CLASS = "HasAugmentation;\n"; | ||
709 | + | ||
710 | + /** | ||
711 | + * Static attribute for AugmentedInfo class import package. | ||
712 | + */ | ||
713 | + public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava"; | ||
714 | + | ||
715 | + /** | ||
716 | + * Static attribute for AugmentedInfo class import class. | ||
717 | + */ | ||
718 | + public static final String AUGMENTED_INFO_CLASS_IMPORT_CLASS = "AugmentedInfo;\n"; | ||
719 | + | ||
720 | + /** | ||
721 | + * Static attribute for augmentation class. | ||
722 | + */ | ||
723 | + public static final String AUGMENTATION = "Augmentation"; | ||
724 | + | ||
725 | + /** | ||
726 | + * Static attribute for HasAugmentation class. | ||
727 | + */ | ||
728 | + public static final String HAS_AUGMENTATION = "HasAugmentation"; | ||
729 | + | ||
730 | + /** | ||
731 | + * Static attribute for AugmentedInfo class. | ||
732 | + */ | ||
733 | + public static final String AUGMENTED_INFO = "AugmentedInfo"; | ||
734 | + | ||
735 | + /** | ||
690 | * Static attribute for abstract collection. | 736 | * Static attribute for abstract collection. |
691 | */ | 737 | */ |
692 | public static final String ABSTRACT_COLLECTION = "AbstractCollection"; | 738 | public static final String ABSTRACT_COLLECTION = "AbstractCollection"; | ... | ... |
... | @@ -21,12 +21,19 @@ import java.lang.reflect.InvocationTargetException; | ... | @@ -21,12 +21,19 @@ import java.lang.reflect.InvocationTargetException; |
21 | 21 | ||
22 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | import org.onosproject.yangutils.datamodel.YangDataTypes; | 23 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
24 | +import org.onosproject.yangutils.datamodel.YangDerivedInfo; | ||
25 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
24 | import org.onosproject.yangutils.datamodel.YangType; | 26 | import org.onosproject.yangutils.datamodel.YangType; |
27 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
28 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
29 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule; | ||
30 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; | ||
25 | 31 | ||
26 | import static org.hamcrest.core.Is.is; | 32 | import static org.hamcrest.core.Is.is; |
27 | import static org.hamcrest.core.IsNot.not; | 33 | import static org.hamcrest.core.IsNot.not; |
28 | import static org.junit.Assert.assertThat; | 34 | import static org.junit.Assert.assertThat; |
29 | import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; | 35 | import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN; |
36 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; | ||
30 | import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; | 37 | import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; |
31 | import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; | 38 | import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; |
32 | import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8; | 39 | import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8; |
... | @@ -44,11 +51,13 @@ public class AttributesJavaDataTypeTest { | ... | @@ -44,11 +51,13 @@ public class AttributesJavaDataTypeTest { |
44 | private static final YangDataTypes TYPE2 = INT32; | 51 | private static final YangDataTypes TYPE2 = INT32; |
45 | private static final YangDataTypes TYPE3 = BOOLEAN; | 52 | private static final YangDataTypes TYPE3 = BOOLEAN; |
46 | private static final YangDataTypes TYPE4 = UINT8; | 53 | private static final YangDataTypes TYPE4 = UINT8; |
54 | + private static final YangDataTypes TYPE_DEF = DERIVED; | ||
47 | private static final String CLASS_INFO1 = "String"; | 55 | private static final String CLASS_INFO1 = "String"; |
48 | private static final String CLASS_INFO2 = "int"; | 56 | private static final String CLASS_INFO2 = "int"; |
49 | private static final String CLASS_INFO3 = "boolean"; | 57 | private static final String CLASS_INFO3 = "boolean"; |
50 | private static final String CLASS_INFO4 = "short"; | 58 | private static final String CLASS_INFO4 = "short"; |
51 | private static final String CLASS_INFO5 = "Integer"; | 59 | private static final String CLASS_INFO5 = "Integer"; |
60 | + private static final String TYPE_DEF_PKG = "target.test"; | ||
52 | private static String test = ""; | 61 | private static String test = ""; |
53 | 62 | ||
54 | /** | 63 | /** |
... | @@ -128,14 +137,65 @@ public class AttributesJavaDataTypeTest { | ... | @@ -128,14 +137,65 @@ public class AttributesJavaDataTypeTest { |
128 | } | 137 | } |
129 | 138 | ||
130 | /** | 139 | /** |
140 | + * Unit test case for typedef. | ||
141 | + * | ||
142 | + * @throws DataModelException when fails to do data model operations | ||
143 | + */ | ||
144 | + @Test | ||
145 | + public void testForTypeDef() throws DataModelException { | ||
146 | + test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, TYPE_DEF_PKG); | ||
147 | + assertThat(true, is(test.equals(TYPE_DEF_PKG))); | ||
148 | + } | ||
149 | + | ||
150 | + /** | ||
131 | * Returns stub YANG type for test. | 151 | * Returns stub YANG type for test. |
132 | * | 152 | * |
133 | * @param dataTypes YANG data types | 153 | * @param dataTypes YANG data types |
134 | * @return YANG type | 154 | * @return YANG type |
135 | */ | 155 | */ |
136 | private YangType<?> getStubYangType(YangDataTypes dataTypes) { | 156 | private YangType<?> getStubYangType(YangDataTypes dataTypes) { |
137 | - YangType<?> type = new YangType(); | 157 | + YangType<?> type = new YangType<>(); |
138 | type.setDataType(dataTypes); | 158 | type.setDataType(dataTypes); |
139 | return type; | 159 | return type; |
140 | } | 160 | } |
161 | + | ||
162 | + /** | ||
163 | + * Returns YANG type with extended info. | ||
164 | + * | ||
165 | + * @param type YANG type | ||
166 | + * @return YANG type with extended info | ||
167 | + * @throws DataModelException when fails to do data model operations | ||
168 | + */ | ||
169 | + @SuppressWarnings("unchecked") | ||
170 | + private YangType<?> getStubExtendedInfo(YangType<?> type) throws DataModelException { | ||
171 | + YangJavaTypeDef typedef = new YangJavaTypeDef(); | ||
172 | + getStubParent().addChild(typedef); | ||
173 | + YangDerivedInfo<?> derInfo = new YangDerivedInfo<>(); | ||
174 | + derInfo.setReferredTypeDef(typedef); | ||
175 | + ((YangType<YangDerivedInfo<?>>) type).setDataTypeExtendedInfo(derInfo); | ||
176 | + return type; | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Returns java file info. | ||
181 | + * | ||
182 | + * @return java file info | ||
183 | + */ | ||
184 | + private JavaFileInfo addStubJavaFileInfo() { | ||
185 | + JavaFileInfo fileInfo = new JavaFileInfo(); | ||
186 | + fileInfo.setJavaName("test"); | ||
187 | + fileInfo.setPackage("target"); | ||
188 | + return fileInfo; | ||
189 | + } | ||
190 | + | ||
191 | + /** | ||
192 | + * Adds stub parent module for typedef. | ||
193 | + * | ||
194 | + * @return stub parent module | ||
195 | + */ | ||
196 | + private YangNode getStubParent() { | ||
197 | + YangJavaModule parent = new YangJavaModule(); | ||
198 | + parent.setJavaFileInfo(addStubJavaFileInfo()); | ||
199 | + return parent; | ||
200 | + } | ||
141 | } | 201 | } | ... | ... |
-
Please register or login to post a comment