Bharat saraswal
Committed by Gerrit Code Review

[ONOS-4286],[ONOS-3911] YANG typedef and YANG augment

                        translator implementation.

Change-Id: I3e21d1cb52bcb90b935b672eee42b836c21f448b
Showing 29 changed files with 621 additions and 81 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 }
......
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 +}
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 }
......
...@@ -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
......
...@@ -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 */
......
...@@ -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() {
......
...@@ -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) {
......
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 }
......