Committed by
Gerrit Code Review
[ONOS-4073] YANG enum translator implementation.
Change-Id: I129eaec0c8f81c674a994a579650f18499340052
Showing
24 changed files
with
498 additions
and
46 deletions
... | @@ -35,6 +35,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; | ... | @@ -35,6 +35,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; |
35 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase; | 35 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase; |
36 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice; | 36 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice; |
37 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer; | 37 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainer; |
38 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; | ||
38 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping; | 39 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping; |
39 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf; | 40 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeaf; |
40 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList; | 41 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList; |
... | @@ -346,4 +347,22 @@ public final class YangDataModelFactory { | ... | @@ -346,4 +347,22 @@ public final class YangDataModelFactory { |
346 | } | 347 | } |
347 | } | 348 | } |
348 | } | 349 | } |
350 | + | ||
351 | + /** | ||
352 | + * Returns based on the target language generate the inherited data model node. | ||
353 | + * | ||
354 | + * @param targetLanguage target language in which YANG mapping needs to be | ||
355 | + * generated | ||
356 | + * @return the corresponding inherited node based on the target language | ||
357 | + */ | ||
358 | + public static YangJavaEnumeration getYangEnumerationNode(GeneratedLanguage targetLanguage) { | ||
359 | + switch (targetLanguage) { | ||
360 | + case JAVA_GENERATION: { | ||
361 | + return new YangJavaEnumeration(); | ||
362 | + } | ||
363 | + default: { | ||
364 | + throw new TranslatorException("Only YANG to Java is supported."); | ||
365 | + } | ||
366 | + } | ||
367 | + } | ||
349 | } | 368 | } | ... | ... |
... | @@ -55,6 +55,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; | ... | @@ -55,6 +55,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; |
55 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 55 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
56 | import org.onosproject.yangutils.utils.YangConstructType; | 56 | import org.onosproject.yangutils.utils.YangConstructType; |
57 | 57 | ||
58 | +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION; | ||
59 | +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangEnumerationNode; | ||
58 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 60 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
59 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 61 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
60 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 62 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
... | @@ -99,7 +101,7 @@ public final class EnumerationListener { | ... | @@ -99,7 +101,7 @@ public final class EnumerationListener { |
99 | checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY); | 101 | checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY); |
100 | 102 | ||
101 | if (listener.getParsedDataStack().peek() instanceof YangType) { | 103 | if (listener.getParsedDataStack().peek() instanceof YangType) { |
102 | - YangEnumeration enumerationNode = new YangEnumeration(); | 104 | + YangEnumeration enumerationNode = getYangEnumerationNode(JAVA_GENERATION); |
103 | Parsable typeData = listener.getParsedDataStack().pop(); | 105 | Parsable typeData = listener.getParsedDataStack().pop(); |
104 | 106 | ||
105 | // Check for stack to be non empty. | 107 | // Check for stack to be non empty. | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
... | @@ -57,6 +57,11 @@ public final class GeneratedJavaFileType { | ... | @@ -57,6 +57,11 @@ public final class GeneratedJavaFileType { |
57 | public static final int GENERATE_UNION_CLASS = 32; | 57 | public static final int GENERATE_UNION_CLASS = 32; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | + * Java class corresponding to YANG enumeration. | ||
61 | + */ | ||
62 | + public static final int GENERATE_ENUM_CLASS = 64; | ||
63 | + | ||
64 | + /** | ||
60 | * Creates an instance of generate java file type. | 65 | * Creates an instance of generate java file type. |
61 | */ | 66 | */ |
62 | private GeneratedJavaFileType() { | 67 | private GeneratedJavaFileType() { | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
... | @@ -82,6 +82,11 @@ public final class GeneratedTempFileType { | ... | @@ -82,6 +82,11 @@ public final class GeneratedTempFileType { |
82 | public static final int UNION_FROM_STRING_IMPL_MASK = 2048; | 82 | public static final int UNION_FROM_STRING_IMPL_MASK = 2048; |
83 | 83 | ||
84 | /** | 84 | /** |
85 | + * Enum implementation of class. | ||
86 | + */ | ||
87 | + public static final int ENUM_IMPL_MASK = 4096; | ||
88 | + | ||
89 | + /** | ||
85 | * Creates an instance of generated temp file type. | 90 | * Creates an instance of generated temp file type. |
86 | */ | 91 | */ |
87 | private GeneratedTempFileType() { | 92 | private GeneratedTempFileType() { | ... | ... |
... | @@ -124,6 +124,29 @@ public final class JavaAttributeInfo { | ... | @@ -124,6 +124,29 @@ public final class JavaAttributeInfo { |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | + * Creates an attribute info object corresponding to the passed enumeration attribute | ||
128 | + * information and return it. | ||
129 | + * | ||
130 | + * @param curNode current data model node for which the java file is being | ||
131 | + * generated | ||
132 | + * @param attributeName attribute name | ||
133 | + * @return AttributeInfo attribute details required to add in temporary | ||
134 | + * files | ||
135 | + */ | ||
136 | + public static JavaAttributeInfo getAttributeInfoOfEnumAttribute(YangNode curNode, String attributeName) { | ||
137 | + | ||
138 | + String curNodeName = ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName(); | ||
139 | + | ||
140 | + /* | ||
141 | + * Get the import info corresponding to the attribute for import in | ||
142 | + * generated java files or qualified access | ||
143 | + */ | ||
144 | + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, | ||
145 | + curNodeName, false); | ||
146 | + | ||
147 | + return getAttributeInfoForTheData(qualifiedTypeInfo, attributeName, null, curNode, false); | ||
148 | + } | ||
149 | + /** | ||
127 | * Returns the data type info of attribute. | 150 | * Returns the data type info of attribute. |
128 | * | 151 | * |
129 | * @return the data type info of attribute | 152 | * @return the data type info of attribute | ... | ... |
This diff is collapsed. Click to expand it.
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.javamodel; | ||
18 | + | ||
19 | +import java.io.IOException; | ||
20 | + | ||
21 | +import org.onosproject.yangutils.datamodel.YangEnumeration; | ||
22 | +import org.onosproject.yangutils.translator.exception.TranslatorException; | ||
23 | +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator; | ||
24 | +import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ||
25 | +import org.onosproject.yangutils.translator.tojava.JavaImportData; | ||
26 | +import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | ||
27 | +import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | ||
28 | + | ||
29 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; | ||
30 | +import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType; | ||
31 | + | ||
32 | +/** | ||
33 | + * Represents YANG java enumeration information extended to support java code generation. | ||
34 | + */ | ||
35 | +public class YangJavaEnumeration extends YangEnumeration implements JavaCodeGenerator, JavaCodeGeneratorInfo { | ||
36 | + | ||
37 | + /** | ||
38 | + * Contains the information of the java file being generated. | ||
39 | + */ | ||
40 | + private JavaFileInfo javaFileInfo; | ||
41 | + | ||
42 | + /** | ||
43 | + * Contains information of the imports to be inserted in the java file | ||
44 | + * generated. | ||
45 | + */ | ||
46 | + private JavaImportData javaImportData; | ||
47 | + | ||
48 | + /** | ||
49 | + * File handle to maintain temporary java code fragments as per the code | ||
50 | + * snippet types. | ||
51 | + */ | ||
52 | + private TempJavaCodeFragmentFiles tempFileHandle; | ||
53 | + | ||
54 | + /** | ||
55 | + * Creates YANG java enumeration object. | ||
56 | + */ | ||
57 | + public YangJavaEnumeration() { | ||
58 | + super(); | ||
59 | + setJavaFileInfo(new JavaFileInfo()); | ||
60 | + setJavaImportData(new JavaImportData()); | ||
61 | + getJavaFileInfo().setGeneratedFileTypes(GENERATE_ENUM_CLASS); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Returns the generated java file information. | ||
66 | + * | ||
67 | + * @return generated java file information | ||
68 | + */ | ||
69 | + @Override | ||
70 | + public JavaFileInfo getJavaFileInfo() { | ||
71 | + | ||
72 | + if (javaFileInfo == null) { | ||
73 | + throw new TranslatorException("Missing java info in java datamodel node"); | ||
74 | + } | ||
75 | + return javaFileInfo; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Sets the java file info object. | ||
80 | + * | ||
81 | + * @param javaInfo java file info object | ||
82 | + */ | ||
83 | + @Override | ||
84 | + public void setJavaFileInfo(JavaFileInfo javaInfo) { | ||
85 | + | ||
86 | + javaFileInfo = javaInfo; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns the data of java imports to be included in generated file. | ||
91 | + * | ||
92 | + * @return data of java imports to be included in generated file | ||
93 | + */ | ||
94 | + @Override | ||
95 | + public JavaImportData getJavaImportData() { | ||
96 | + | ||
97 | + return javaImportData; | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Sets the data of java imports to be included in generated file. | ||
102 | + * | ||
103 | + * @param javaImportData data of java imports to be included in generated | ||
104 | + * file | ||
105 | + */ | ||
106 | + @Override | ||
107 | + public void setJavaImportData(JavaImportData javaImportData) { | ||
108 | + | ||
109 | + this.javaImportData = javaImportData; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * Returns the temporary file handle. | ||
114 | + * | ||
115 | + * @return temporary file handle | ||
116 | + */ | ||
117 | + @Override | ||
118 | + public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() { | ||
119 | + | ||
120 | + return tempFileHandle; | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * Sets temporary file handle. | ||
125 | + * | ||
126 | + * @param fileHandle temporary file handle | ||
127 | + */ | ||
128 | + @Override | ||
129 | + public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) { | ||
130 | + | ||
131 | + tempFileHandle = fileHandle; | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * Prepare the information for java code generation corresponding to YANG | ||
136 | + * enumeration info. | ||
137 | + * | ||
138 | + * @param yangPlugin YANG plugin config | ||
139 | + * @throws IOException IO operations fails | ||
140 | + */ | ||
141 | + @Override | ||
142 | + public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException { | ||
143 | + generateCodeOfType(this, yangPlugin, false); | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * Creates a java file using the YANG enumeration info. | ||
148 | + * | ||
149 | + * @throws IOException IO operation fail | ||
150 | + */ | ||
151 | + @Override | ||
152 | + public void generateCodeExit() throws IOException { | ||
153 | + getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this); | ||
154 | + } | ||
155 | + | ||
156 | +} |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import org.onosproject.yangutils.datamodel.YangDataTypes; | 19 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
20 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; | 20 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
21 | +import org.onosproject.yangutils.datamodel.YangEnumeration; | ||
21 | import org.onosproject.yangutils.datamodel.YangNode; | 22 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.datamodel.YangType; | 23 | import org.onosproject.yangutils.datamodel.YangType; |
23 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 24 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
... | @@ -25,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangUnion; | ... | @@ -25,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangUnion; |
25 | import org.onosproject.yangutils.translator.exception.TranslatorException; | 26 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
26 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; | 27 | import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo; |
27 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 28 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
29 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; | ||
28 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; | 30 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; |
29 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion; | 31 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion; |
30 | 32 | ||
... | @@ -186,7 +188,8 @@ public final class AttributesJavaDataType { | ... | @@ -186,7 +188,8 @@ public final class AttributesJavaDataType { |
186 | case BOOLEAN: | 188 | case BOOLEAN: |
187 | return BOOLEAN_WRAPPER; | 189 | return BOOLEAN_WRAPPER; |
188 | case ENUMERATION: | 190 | case ENUMERATION: |
189 | - //TODO: ENUMERATION. | 191 | + return getCaptialCase( |
192 | + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); | ||
190 | case BITS: | 193 | case BITS: |
191 | //TODO:BITS | 194 | //TODO:BITS |
192 | case BINARY: | 195 | case BINARY: |
... | @@ -205,7 +208,7 @@ public final class AttributesJavaDataType { | ... | @@ -205,7 +208,7 @@ public final class AttributesJavaDataType { |
205 | case DERIVED: | 208 | case DERIVED: |
206 | return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); | 209 | return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null)); |
207 | default: | 210 | default: |
208 | - return null; | 211 | + throw new TranslatorException("given data type is not supported."); |
209 | } | 212 | } |
210 | } else { | 213 | } else { |
211 | switch (type) { | 214 | switch (type) { |
... | @@ -216,7 +219,8 @@ public final class AttributesJavaDataType { | ... | @@ -216,7 +219,8 @@ public final class AttributesJavaDataType { |
216 | case STRING: | 219 | case STRING: |
217 | return STRING_DATA_TYPE; | 220 | return STRING_DATA_TYPE; |
218 | case ENUMERATION: | 221 | case ENUMERATION: |
219 | - //TODO: ENUMERATION. | 222 | + return getCaptialCase( |
223 | + getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null)); | ||
220 | case BITS: | 224 | case BITS: |
221 | //TODO:BITS | 225 | //TODO:BITS |
222 | case BINARY: | 226 | case BINARY: |
... | @@ -269,7 +273,7 @@ public final class AttributesJavaDataType { | ... | @@ -269,7 +273,7 @@ public final class AttributesJavaDataType { |
269 | case DECIMAL64: | 273 | case DECIMAL64: |
270 | //TODO: DECIMAL64. | 274 | //TODO: DECIMAL64. |
271 | case ENUMERATION: | 275 | case ENUMERATION: |
272 | - //TODO: ENUMERATION. | 276 | + return getEnumsPackage(yangType); |
273 | case BITS: | 277 | case BITS: |
274 | //TODO:BITS | 278 | //TODO:BITS |
275 | case BINARY: | 279 | case BINARY: |
... | @@ -287,7 +291,7 @@ public final class AttributesJavaDataType { | ... | @@ -287,7 +291,7 @@ public final class AttributesJavaDataType { |
287 | case DERIVED: | 291 | case DERIVED: |
288 | return getTypDefsPackage(yangType); | 292 | return getTypDefsPackage(yangType); |
289 | default: | 293 | default: |
290 | - return null; | 294 | + throw new TranslatorException("given data type is not supported."); |
291 | } | 295 | } |
292 | } else { | 296 | } else { |
293 | switch (type) { | 297 | switch (type) { |
... | @@ -298,7 +302,7 @@ public final class AttributesJavaDataType { | ... | @@ -298,7 +302,7 @@ public final class AttributesJavaDataType { |
298 | case STRING: | 302 | case STRING: |
299 | return JAVA_LANG; | 303 | return JAVA_LANG; |
300 | case ENUMERATION: | 304 | case ENUMERATION: |
301 | - //TODO: ENUMERATION. | 305 | + return getEnumsPackage(yangType); |
302 | case BITS: | 306 | case BITS: |
303 | //TODO:BITS | 307 | //TODO:BITS |
304 | case BINARY: | 308 | case BINARY: |
... | @@ -364,6 +368,24 @@ public final class AttributesJavaDataType { | ... | @@ -364,6 +368,24 @@ public final class AttributesJavaDataType { |
364 | } | 368 | } |
365 | 369 | ||
366 | /** | 370 | /** |
371 | + * Returns YANG enumeration's java package. | ||
372 | + * | ||
373 | + * @param type YANG type | ||
374 | + * @return YANG enumeration's java package | ||
375 | + */ | ||
376 | + private static String getEnumsPackage(YangType<?> type) { | ||
377 | + | ||
378 | + if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) { | ||
379 | + throw new TranslatorException("type should have been enumeration."); | ||
380 | + } | ||
381 | + YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo(); | ||
382 | + if (enumeration.getJavaFileInfo().getPackage() == null) { | ||
383 | + return getPackageFromParent(enumeration.getParent()); | ||
384 | + } | ||
385 | + return enumeration.getJavaFileInfo().getPackage(); | ||
386 | + } | ||
387 | + | ||
388 | + /** | ||
367 | * Returns package from parent node. | 389 | * Returns package from parent node. |
368 | * | 390 | * |
369 | * @param parent parent YANG node | 391 | * @param parent parent YANG node | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; | ... | @@ -18,6 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils; |
18 | 18 | ||
19 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 19 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
20 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 20 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
21 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; | ||
21 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 22 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
22 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 23 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
23 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 24 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
... | @@ -27,6 +28,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato | ... | @@ -27,6 +28,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato |
27 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
28 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS; |
29 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
31 | +import static org.onosproject.yangutils.utils.UtilConstants.ENUM; | ||
30 | import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.EXTEND; |
31 | import static org.onosproject.yangutils.utils.UtilConstants.FINAL; | 33 | import static org.onosproject.yangutils.utils.UtilConstants.FINAL; |
32 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
... | @@ -76,11 +78,23 @@ public final class ClassDefinitionGenerator { | ... | @@ -76,11 +78,23 @@ public final class ClassDefinitionGenerator { |
76 | return getTypeClassDefinition(yangName); | 78 | return getTypeClassDefinition(yangName); |
77 | } else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) { | 79 | } else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) { |
78 | return getTypeClassDefinition(yangName); | 80 | return getTypeClassDefinition(yangName); |
81 | + } else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) { | ||
82 | + return getEnumClassDefinition(yangName); | ||
79 | } | 83 | } |
80 | return null; | 84 | return null; |
81 | } | 85 | } |
82 | 86 | ||
83 | /** | 87 | /** |
88 | + * Returns enum file class definition. | ||
89 | + * | ||
90 | + * @param yangName class name | ||
91 | + * @return enum file class definiton | ||
92 | + */ | ||
93 | + private static String getEnumClassDefinition(String yangName) { | ||
94 | + return PUBLIC + SPACE + ENUM + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
84 | * Returns interface file class definition. | 98 | * Returns interface file class definition. |
85 | * | 99 | * |
86 | * @param yangName file name | 100 | * @param yangName file name | ... | ... |
... | @@ -20,11 +20,13 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ... | @@ -20,11 +20,13 @@ 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.getEnumJavaAttribute; | ||
23 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | 24 | 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.ARRAY_LIST; |
25 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | 26 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
26 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 27 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
27 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
29 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
28 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | 30 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
29 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
30 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | 32 | import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
... | @@ -38,6 +40,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | ... | @@ -38,6 +40,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
39 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
43 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
44 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE; | ||
41 | 45 | ||
42 | /** | 46 | /** |
43 | * Represents utility class to generate the java snippet. | 47 | * Represents utility class to generate the java snippet. |
... | @@ -155,4 +159,17 @@ public final class JavaCodeSnippetGen { | ... | @@ -155,4 +159,17 @@ public final class JavaCodeSnippetGen { |
155 | public static String getJavaClassDefClose() { | 159 | public static String getJavaClassDefClose() { |
156 | return CLOSE_CURLY_BRACKET; | 160 | return CLOSE_CURLY_BRACKET; |
157 | } | 161 | } |
162 | + | ||
163 | + /** | ||
164 | + * Returns string for enum's attribute. | ||
165 | + * | ||
166 | + * @param name name of attribute | ||
167 | + * @param value value of the enum | ||
168 | + * @return string for enum's attribute | ||
169 | + */ | ||
170 | + public static String generateEnumAttributeString(String name, int value) { | ||
171 | + return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION + getEnumJavaAttribute(name) | ||
172 | + + OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE; | ||
173 | + } | ||
174 | + | ||
158 | } | 175 | } | ... | ... |
... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | ... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
27 | 27 | ||
28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 28 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
30 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; | ||
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
... | @@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -34,6 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
34 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | 35 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
35 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
38 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; | ||
37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; | 39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
... | @@ -45,15 +47,19 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -45,15 +47,19 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
45 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; | 47 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; |
46 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute; | 48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute; |
47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; | 49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle; |
50 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute; | ||
48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; | 51 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration; |
49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 52 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
53 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | ||
50 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; | 54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl; |
51 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; | 55 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl; |
52 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; | 56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart; |
57 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor; | ||
53 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; | 58 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose; |
54 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; | 59 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen; |
55 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; | 60 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose; |
56 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature; | 61 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature; |
62 | +import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter; | ||
57 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; | 63 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose; |
58 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; | 64 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen; |
59 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; | 65 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString; |
... | @@ -63,14 +69,21 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -63,14 +69,21 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
63 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; | 69 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended; |
64 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 70 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
65 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 71 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
72 | +import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | ||
66 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 73 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
67 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 74 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
68 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 75 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
76 | +import static org.onosproject.yangutils.utils.UtilConstants.INT; | ||
69 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 77 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
70 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 78 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
71 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | 79 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
80 | +import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | ||
81 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
82 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | ||
83 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; | ||
72 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 84 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
73 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; | 85 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString; |
86 | +import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | ||
74 | 87 | ||
75 | /** | 88 | /** |
76 | * Representation of java file generator. | 89 | * Representation of java file generator. |
... | @@ -384,7 +397,7 @@ public final class JavaFileGenerator { | ... | @@ -384,7 +397,7 @@ public final class JavaFileGenerator { |
384 | } | 397 | } |
385 | 398 | ||
386 | /** | 399 | /** |
387 | - * Generate class file for type def. | 400 | + * Generates class file for type def. |
388 | * | 401 | * |
389 | * @param file generated file | 402 | * @param file generated file |
390 | * @param curNode current YANG node | 403 | * @param curNode current YANG node |
... | @@ -469,7 +482,7 @@ public final class JavaFileGenerator { | ... | @@ -469,7 +482,7 @@ public final class JavaFileGenerator { |
469 | } | 482 | } |
470 | 483 | ||
471 | /** | 484 | /** |
472 | - * Generate class file for union type. | 485 | + * Generates class file for union type. |
473 | * | 486 | * |
474 | * @param file generated file | 487 | * @param file generated file |
475 | * @param curNode current YANG node | 488 | * @param curNode current YANG node |
... | @@ -559,4 +572,56 @@ public final class JavaFileGenerator { | ... | @@ -559,4 +572,56 @@ public final class JavaFileGenerator { |
559 | 572 | ||
560 | return file; | 573 | return file; |
561 | } | 574 | } |
575 | + | ||
576 | + /** | ||
577 | + * Generates class file for type enum. | ||
578 | + * | ||
579 | + * @param file generated file | ||
580 | + * @param curNode current YANG node | ||
581 | + * @return class file for type enum | ||
582 | + * @throws IOException when fails to generate class file | ||
583 | + */ | ||
584 | + public static File generateEnumClassFile(File file, YangNode curNode) throws IOException { | ||
585 | + | ||
586 | + JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo(); | ||
587 | + | ||
588 | + String className = getCaptialCase(javaFileInfo.getJavaName()); | ||
589 | + String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | ||
590 | + | ||
591 | + initiateJavaFileGeneration(file, className, GENERATE_ENUM_CLASS, null, path); | ||
592 | + /** | ||
593 | + * Add attribute strings. | ||
594 | + */ | ||
595 | + try { | ||
596 | + insertDataIntoJavaFile(file, | ||
597 | + trimAtLast(trimAtLast(getDataFromTempFileHandle(ENUM_IMPL_MASK, curNode), COMMA), NEW_LINE) | ||
598 | + + SEMI_COLAN + NEW_LINE); | ||
599 | + } catch (IOException e) { | ||
600 | + throw new IOException("No data found in temporary java code fragment files for " + className | ||
601 | + + " while enum class file generation"); | ||
602 | + } | ||
603 | + | ||
604 | + /** | ||
605 | + * Add an attribute to get the enum's values. | ||
606 | + */ | ||
607 | + insertDataIntoJavaFile(file, getEnumsValueAttribute(className)); | ||
608 | + | ||
609 | + /** | ||
610 | + * Add a constructor for enum. | ||
611 | + */ | ||
612 | + insertDataIntoJavaFile(file, | ||
613 | + getJavaDoc(TYPE_CONSTRUCTOR, getSmallCase(className), false) + getEnumsConstrcutor(className) | ||
614 | + + NEW_LINE); | ||
615 | + | ||
616 | + /** | ||
617 | + * Add a getter method for enum. | ||
618 | + */ | ||
619 | + insertDataIntoJavaFile(file, | ||
620 | + getJavaDoc(GETTER_METHOD, getSmallCase(className), false) + getGetter(INT, getSmallCase(className)) | ||
621 | + + NEW_LINE); | ||
622 | + | ||
623 | + insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE); | ||
624 | + | ||
625 | + return file; | ||
626 | + } | ||
562 | } | 627 | } | ... | ... |
... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; | ... | @@ -28,6 +28,7 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType; |
28 | 28 | ||
29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; | 29 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK; |
30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; | 30 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK; |
31 | +import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS; | ||
31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; | 34 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK; |
... | @@ -35,6 +36,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. | ... | @@ -35,6 +36,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType. |
35 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; | 36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK; |
36 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | 37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
37 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; | 38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK; |
39 | +import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK; | ||
38 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; | 40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK; |
39 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; | 41 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK; |
40 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; | 42 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK; |
... | @@ -46,17 +48,22 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -46,17 +48,22 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
46 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; | 48 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK; |
47 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; | 49 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart; |
48 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; | 50 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath; |
51 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase; | ||
52 | +import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | ||
53 | +import static org.onosproject.yangutils.utils.UtilConstants.INT; | ||
49 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 54 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
50 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; | 55 | import static org.onosproject.yangutils.utils.UtilConstants.ORG; |
51 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | 56 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; |
57 | +import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | ||
52 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 58 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
53 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
54 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
61 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
55 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; | 62 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS; |
56 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; | 63 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE; |
64 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS; | ||
57 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; | 65 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS; |
58 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; | 66 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE; |
59 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
60 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; | 67 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile; |
61 | 68 | ||
62 | /** | 69 | /** |
... | @@ -134,6 +141,9 @@ public final class JavaFileGeneratorUtils { | ... | @@ -134,6 +141,9 @@ public final class JavaFileGeneratorUtils { |
134 | } else if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { | 141 | } else if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) { |
135 | return tempJavaCodeFragmentFiles | 142 | return tempJavaCodeFragmentFiles |
136 | .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getUnionFromStringImplTempFileHandle()); | 143 | .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getUnionFromStringImplTempFileHandle()); |
144 | + } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) { | ||
145 | + return tempJavaCodeFragmentFiles | ||
146 | + .getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getEnumClassTempFileHandle()); | ||
137 | } | 147 | } |
138 | return null; | 148 | return null; |
139 | } | 149 | } |
... | @@ -190,6 +200,9 @@ public final class JavaFileGeneratorUtils { | ... | @@ -190,6 +200,9 @@ public final class JavaFileGeneratorUtils { |
190 | } else if ((type & GENERATE_UNION_CLASS) != 0) { | 200 | } else if ((type & GENERATE_UNION_CLASS) != 0) { |
191 | appendHeaderContents(file, pkgString, importsList); | 201 | appendHeaderContents(file, pkgString, importsList); |
192 | write(file, fileName, type, IMPL_CLASS); | 202 | write(file, fileName, type, IMPL_CLASS); |
203 | + } else if ((type & GENERATE_ENUM_CLASS) != 0) { | ||
204 | + appendHeaderContents(file, pkgString, importsList); | ||
205 | + write(file, fileName, type, ENUM_CLASS); | ||
193 | } | 206 | } |
194 | } | 207 | } |
195 | 208 | ||
... | @@ -259,4 +272,15 @@ public final class JavaFileGeneratorUtils { | ... | @@ -259,4 +272,15 @@ public final class JavaFileGeneratorUtils { |
259 | insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); | 272 | insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName)); |
260 | } | 273 | } |
261 | 274 | ||
275 | + /** | ||
276 | + * Returns integer attribute for enum's class to get the values. | ||
277 | + * | ||
278 | + * @param className enum's class name | ||
279 | + * @return enum's attribute | ||
280 | + */ | ||
281 | + public static String getEnumsValueAttribute(String className) { | ||
282 | + return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) + SEMI_COLAN | ||
283 | + + NEW_LINE; | ||
284 | + } | ||
285 | + | ||
262 | } | 286 | } | ... | ... |
... | @@ -381,6 +381,25 @@ public final class JavaIdentifierSyntax { | ... | @@ -381,6 +381,25 @@ public final class JavaIdentifierSyntax { |
381 | } | 381 | } |
382 | 382 | ||
383 | /** | 383 | /** |
384 | + * Returns enum's java name. | ||
385 | + * | ||
386 | + * @param name enum's name | ||
387 | + * @return enum's java name | ||
388 | + */ | ||
389 | + public static String getEnumJavaAttribute(String name) { | ||
390 | + | ||
391 | + String[] strArray = name.split(HYPHEN); | ||
392 | + String output = EMPTY_STRING; | ||
393 | + for (int i = 0; i < strArray.length; i++) { | ||
394 | + output = output + strArray[i]; | ||
395 | + if (i > 0 && i < strArray.length - 1) { | ||
396 | + output = output + UNDER_SCORE; | ||
397 | + } | ||
398 | + } | ||
399 | + return output; | ||
400 | + } | ||
401 | + | ||
402 | + /** | ||
384 | * Returns the directory path corresponding to java package. | 403 | * Returns the directory path corresponding to java package. |
385 | * | 404 | * |
386 | * @param packagePath package path | 405 | * @param packagePath package path | ... | ... |
... | @@ -87,6 +87,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TRY; | ... | @@ -87,6 +87,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TRY; |
87 | import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; | 87 | import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION; |
88 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; | 88 | import static org.onosproject.yangutils.utils.UtilConstants.VALUE; |
89 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; | 89 | import static org.onosproject.yangutils.utils.UtilConstants.VOID; |
90 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
90 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; | 91 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; |
91 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; | 92 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; |
92 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; | 93 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; |
... | @@ -95,7 +96,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_ | ... | @@ -95,7 +96,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_ |
95 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; | 96 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD; |
96 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; | 97 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
97 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.UNION_FROM_METHOD; | 98 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.UNION_FROM_METHOD; |
98 | -import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
99 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | 99 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
100 | 100 | ||
101 | /** | 101 | /** |
... | @@ -218,7 +218,7 @@ public final class MethodsGenerator { | ... | @@ -218,7 +218,7 @@ public final class MethodsGenerator { |
218 | * @param name attribute name | 218 | * @param name attribute name |
219 | * @return getter for attribute | 219 | * @return getter for attribute |
220 | */ | 220 | */ |
221 | - private static String getGetter(String type, String name) { | 221 | + public static String getGetter(String type, String name) { |
222 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name) | 222 | return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name) |
223 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | 223 | + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION |
224 | + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 224 | + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
... | @@ -803,4 +803,15 @@ public final class MethodsGenerator { | ... | @@ -803,4 +803,15 @@ public final class MethodsGenerator { |
803 | return method; | 803 | return method; |
804 | } | 804 | } |
805 | 805 | ||
806 | + /** | ||
807 | + * Returns enum's constructor. | ||
808 | + * | ||
809 | + * @param className enum's class name | ||
810 | + * @return enum's constructor | ||
811 | + */ | ||
812 | + public static String getEnumsConstrcutor(String className) { | ||
813 | + return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE | ||
814 | + + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL | ||
815 | + + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
816 | + } | ||
806 | } | 817 | } | ... | ... |
... | @@ -31,6 +31,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; | ... | @@ -31,6 +31,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO; |
31 | import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; | 31 | import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION; |
32 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | 32 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; |
33 | 33 | ||
34 | +import static java.util.Collections.sort; | ||
35 | + | ||
34 | /** | 36 | /** |
35 | * Represents utilities for temporary java code fragments. | 37 | * Represents utilities for temporary java code fragments. |
36 | */ | 38 | */ |
... | @@ -128,7 +130,7 @@ public final class TempJavaCodeFragmentFilesUtils { | ... | @@ -128,7 +130,7 @@ public final class TempJavaCodeFragmentFilesUtils { |
128 | } else { | 130 | } else { |
129 | imports.remove(curImport); | 131 | imports.remove(curImport); |
130 | } | 132 | } |
131 | - java.util.Collections.sort(imports); | 133 | + sort(imports); |
132 | return imports; | 134 | return imports; |
133 | } | 135 | } |
134 | 136 | ... | ... |
... | @@ -30,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangNotification; | ... | @@ -30,6 +30,7 @@ import org.onosproject.yangutils.datamodel.YangNotification; |
30 | import org.onosproject.yangutils.datamodel.YangOutput; | 30 | import org.onosproject.yangutils.datamodel.YangOutput; |
31 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; | 31 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles; |
32 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; | 32 | import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo; |
33 | +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration; | ||
33 | 34 | ||
34 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; | 35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase; |
35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; | 36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase; |
... | @@ -116,6 +117,9 @@ public final class YangJavaModelUtils { | ... | @@ -116,6 +117,9 @@ public final class YangJavaModelUtils { |
116 | } else if (javaCodeGeneratorInfo instanceof HasType) { | 117 | } else if (javaCodeGeneratorInfo instanceof HasType) { |
117 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | 118 | javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() |
118 | .addTypeInfoToTempFiles((HasType) javaCodeGeneratorInfo); | 119 | .addTypeInfoToTempFiles((HasType) javaCodeGeneratorInfo); |
120 | + } else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) { | ||
121 | + javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles() | ||
122 | + .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo); | ||
119 | } else { | 123 | } else { |
120 | //TODO throw exception | 124 | //TODO throw exception |
121 | } | 125 | } | ... | ... |
... | @@ -53,9 +53,24 @@ public final class UtilConstants { | ... | @@ -53,9 +53,24 @@ public final class UtilConstants { |
53 | public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for "; | 53 | public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for "; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | + * JavaDocs for enum class. | ||
57 | + */ | ||
58 | + public static final String ENUM_CLASS_JAVADOC = " * Represents ENUM data of "; | ||
59 | + | ||
60 | + /** | ||
61 | + * JavaDocs for enum attribute. | ||
62 | + */ | ||
63 | + public static final String ENUM_ATTRIBUTE_JAVADOC = " * Represents "; | ||
64 | + | ||
65 | + /** | ||
56 | * JavaDocs for package info class. | 66 | * JavaDocs for package info class. |
57 | */ | 67 | */ |
58 | - public static final String PACKAGE_INFO_JAVADOC = " * Implementation of YANG file "; | 68 | + public static final String PACKAGE_INFO_JAVADOC = " * Implementation of YANG node "; |
69 | + | ||
70 | + /** | ||
71 | + * JavaDocs for package info class. | ||
72 | + */ | ||
73 | + public static final String PACKAGE_INFO_JAVADOC_OF_CHILD = "'s children nodes"; | ||
59 | 74 | ||
60 | /** | 75 | /** |
61 | * JavaDocs's first line. | 76 | * JavaDocs's first line. |
... | @@ -283,6 +298,11 @@ public final class UtilConstants { | ... | @@ -283,6 +298,11 @@ public final class UtilConstants { |
283 | public static final String VALUE = "value"; | 298 | public static final String VALUE = "value"; |
284 | 299 | ||
285 | /** | 300 | /** |
301 | + * Static attribute for enumValue syntax. | ||
302 | + */ | ||
303 | + public static final String ENUM_VALUE = "enumValue"; | ||
304 | + | ||
305 | + /** | ||
286 | * Static attribute for suffix s. | 306 | * Static attribute for suffix s. |
287 | */ | 307 | */ |
288 | public static final String SUFFIX_S = "s"; | 308 | public static final String SUFFIX_S = "s"; | ... | ... |
... | @@ -23,6 +23,7 @@ import java.io.FileReader; | ... | @@ -23,6 +23,7 @@ import java.io.FileReader; |
23 | import java.io.IOException; | 23 | import java.io.IOException; |
24 | import java.io.InputStream; | 24 | import java.io.InputStream; |
25 | import java.io.OutputStream; | 25 | import java.io.OutputStream; |
26 | +import java.util.Calendar; | ||
26 | 27 | ||
27 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
28 | 29 | ||
... | @@ -33,6 +34,8 @@ public final class CopyrightHeader { | ... | @@ -33,6 +34,8 @@ public final class CopyrightHeader { |
33 | 34 | ||
34 | private static final int EOF = -1; | 35 | private static final int EOF = -1; |
35 | private static final String COPYRIGHT_HEADER_FILE = "CopyrightHeader.txt"; | 36 | private static final String COPYRIGHT_HEADER_FILE = "CopyrightHeader.txt"; |
37 | + private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR) | ||
38 | + + "-present Open Networking Laboratory\n"; | ||
36 | private static final String TEMP_FILE = "temp.txt"; | 39 | private static final String TEMP_FILE = "temp.txt"; |
37 | private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); | 40 | private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader(); |
38 | 41 | ||
... | @@ -82,6 +85,7 @@ public final class CopyrightHeader { | ... | @@ -82,6 +85,7 @@ public final class CopyrightHeader { |
82 | OutputStream out = new FileOutputStream(temp); | 85 | OutputStream out = new FileOutputStream(temp); |
83 | 86 | ||
84 | int index; | 87 | int index; |
88 | + out.write(COPYRIGHTS_FIRST_LINE.getBytes()); | ||
85 | while ((index = stream.read()) != EOF) { | 89 | while ((index = stream.read()) != EOF) { |
86 | out.write(index); | 90 | out.write(index); |
87 | } | 91 | } | ... | ... |
... | @@ -22,6 +22,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | ... | @@ -22,6 +22,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
22 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; | 22 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC; |
23 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; | 23 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC; |
24 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; | 24 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT; |
25 | +import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC; | ||
26 | +import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC; | ||
25 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 27 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
26 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; | 28 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; |
27 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; | 29 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; |
... | @@ -135,7 +137,17 @@ public final class JavaDocGen { | ... | @@ -135,7 +137,17 @@ public final class JavaDocGen { |
135 | /** | 137 | /** |
136 | * For build. | 138 | * For build. |
137 | */ | 139 | */ |
138 | - BUILD_METHOD | 140 | + BUILD_METHOD, |
141 | + | ||
142 | + /** | ||
143 | + * For enum. | ||
144 | + */ | ||
145 | + ENUM_CLASS, | ||
146 | + | ||
147 | + /** | ||
148 | + * For enum's attributes. | ||
149 | + */ | ||
150 | + ENUM_ATTRIBUTE | ||
139 | } | 151 | } |
140 | 152 | ||
141 | /** | 153 | /** |
... | @@ -176,6 +188,10 @@ public final class JavaDocGen { | ... | @@ -176,6 +188,10 @@ public final class JavaDocGen { |
176 | javaDoc = generateForTypeConstructor(name); | 188 | javaDoc = generateForTypeConstructor(name); |
177 | } else if (type.equals(JavaDocType.UNION_FROM_METHOD)) { | 189 | } else if (type.equals(JavaDocType.UNION_FROM_METHOD)) { |
178 | javaDoc = generateForUnionFrom(name); | 190 | javaDoc = generateForUnionFrom(name); |
191 | + } else if (type.equals(JavaDocType.ENUM_CLASS)) { | ||
192 | + javaDoc = generateForEnum(name); | ||
193 | + } else if (type.equals(JavaDocType.ENUM_ATTRIBUTE)) { | ||
194 | + javaDoc = generateForEnumAttr(name); | ||
179 | } else { | 195 | } else { |
180 | javaDoc = generateForConstructors(name); | 196 | javaDoc = generateForConstructors(name); |
181 | } | 197 | } |
... | @@ -183,7 +199,18 @@ public final class JavaDocGen { | ... | @@ -183,7 +199,18 @@ public final class JavaDocGen { |
183 | } | 199 | } |
184 | 200 | ||
185 | /** | 201 | /** |
186 | - * Generate javaDocs for getter method. | 202 | + * Generates javaDocs for enum's attributes. |
203 | + * | ||
204 | + * @param name attribute name | ||
205 | + * @return javaDocs | ||
206 | + */ | ||
207 | + private static String generateForEnumAttr(String name) { | ||
208 | + return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC | ||
209 | + + name + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE; | ||
210 | + } | ||
211 | + | ||
212 | + /** | ||
213 | + * Generates javaDocs for getter method. | ||
187 | * | 214 | * |
188 | * @param attribute attribute | 215 | * @param attribute attribute |
189 | * @param isList is list attribute | 216 | * @param isList is list attribute |
... | @@ -272,30 +299,28 @@ public final class JavaDocGen { | ... | @@ -272,30 +299,28 @@ public final class JavaDocGen { |
272 | } | 299 | } |
273 | 300 | ||
274 | /** | 301 | /** |
275 | - * Generates javaDocs for typedef constructor. | 302 | + * Generates javaDocs for the impl class. |
276 | * | 303 | * |
277 | - * @param attribute attribute | 304 | + * @param className class name |
278 | * @return javaDocs | 305 | * @return javaDocs |
279 | */ | 306 | */ |
280 | - private static String generateForTypeDefConstructor(String attribute) { | 307 | + private static String generateForImplClass(String className) { |
281 | - return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR | 308 | + return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; |
282 | - + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION | ||
283 | - + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE | ||
284 | - + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE); | ||
285 | } | 309 | } |
286 | 310 | ||
287 | /** | 311 | /** |
288 | - * Generate javaDocs for the impl class. | 312 | + * Generates javaDocs for enum. |
289 | * | 313 | * |
290 | - * @param className class name | 314 | + * @param className enum class name |
291 | * @return javaDocs | 315 | * @return javaDocs |
292 | */ | 316 | */ |
293 | - private static String generateForImplClass(String className) { | 317 | + private static String generateForEnum(String className) { |
294 | - return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE; | 318 | + return NEW_LINE + NEW_LINE + JAVA_DOC_FIRST_LINE + ENUM_CLASS_JAVADOC + className + PERIOD + NEW_LINE |
319 | + + JAVA_DOC_END_LINE; | ||
295 | } | 320 | } |
296 | 321 | ||
297 | /** | 322 | /** |
298 | - * Generate javaDocs for the builder class. | 323 | + * Generates javaDocs for the builder class. |
299 | * | 324 | * |
300 | * @param className class name | 325 | * @param className class name |
301 | * @return javaDocs | 326 | * @return javaDocs |
... | @@ -306,7 +331,7 @@ public final class JavaDocGen { | ... | @@ -306,7 +331,7 @@ public final class JavaDocGen { |
306 | } | 331 | } |
307 | 332 | ||
308 | /** | 333 | /** |
309 | - * Generate javaDoc for the interface. | 334 | + * Generates javaDoc for the interface. |
310 | * | 335 | * |
311 | * @param interfaceName interface name | 336 | * @param interfaceName interface name |
312 | * @return javaDocs | 337 | * @return javaDocs |
... | @@ -317,7 +342,7 @@ public final class JavaDocGen { | ... | @@ -317,7 +342,7 @@ public final class JavaDocGen { |
317 | } | 342 | } |
318 | 343 | ||
319 | /** | 344 | /** |
320 | - * Generate javaDoc for the builder interface. | 345 | + * Generates javaDoc for the builder interface. |
321 | * | 346 | * |
322 | * @param builderforName builder for name | 347 | * @param builderforName builder for name |
323 | * @return javaDocs | 348 | * @return javaDocs |
... | @@ -328,7 +353,7 @@ public final class JavaDocGen { | ... | @@ -328,7 +353,7 @@ public final class JavaDocGen { |
328 | } | 353 | } |
329 | 354 | ||
330 | /** | 355 | /** |
331 | - * Generate javaDocs for package-info. | 356 | + * Generates javaDocs for package-info. |
332 | * | 357 | * |
333 | * @param packageName package name | 358 | * @param packageName package name |
334 | * @return javaDocs | 359 | * @return javaDocs |
... | @@ -338,7 +363,7 @@ public final class JavaDocGen { | ... | @@ -338,7 +363,7 @@ public final class JavaDocGen { |
338 | } | 363 | } |
339 | 364 | ||
340 | /** | 365 | /** |
341 | - * Generate javaDocs for default constructor. | 366 | + * Generates javaDocs for default constructor. |
342 | * | 367 | * |
343 | * @param className class name | 368 | * @param className class name |
344 | * @return javaDocs | 369 | * @return javaDocs |
... | @@ -349,7 +374,7 @@ public final class JavaDocGen { | ... | @@ -349,7 +374,7 @@ public final class JavaDocGen { |
349 | } | 374 | } |
350 | 375 | ||
351 | /** | 376 | /** |
352 | - * Generate javaDocs for constructor with parameters. | 377 | + * Generates javaDocs for constructor with parameters. |
353 | * | 378 | * |
354 | * @param className class name | 379 | * @param className class name |
355 | * @return javaDocs | 380 | * @return javaDocs |
... | @@ -363,7 +388,7 @@ public final class JavaDocGen { | ... | @@ -363,7 +388,7 @@ public final class JavaDocGen { |
363 | } | 388 | } |
364 | 389 | ||
365 | /** | 390 | /** |
366 | - * Generate javaDocs for build. | 391 | + * Generates javaDocs for build. |
367 | * | 392 | * |
368 | * @param buildName builder name | 393 | * @param buildName builder name |
369 | * @return javaDocs | 394 | * @return javaDocs | ... | ... |
... | @@ -44,6 +44,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA | ... | @@ -44,6 +44,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA |
44 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES; | 44 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES; |
45 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents; | 45 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents; |
46 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; | 46 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle; |
47 | +import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | ||
47 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO; | 48 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO; |
48 | import static org.slf4j.LoggerFactory.getLogger; | 49 | import static org.slf4j.LoggerFactory.getLogger; |
49 | 50 | ||
... | @@ -96,7 +97,7 @@ public final class YangIoUtils { | ... | @@ -96,7 +97,7 @@ public final class YangIoUtils { |
96 | BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); | 97 | BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); |
97 | 98 | ||
98 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); | 99 | bufferedWriter.write(CopyrightHeader.getCopyrightHeader()); |
99 | - bufferedWriter.write(JavaDocGen.getJavaDoc(PACKAGE_INFO, classInfo, false)); | 100 | + bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, false)); |
100 | bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); | 101 | bufferedWriter.write(PACKAGE + SPACE + pack + SEMI_COLAN); |
101 | 102 | ||
102 | bufferedWriter.close(); | 103 | bufferedWriter.close(); | ... | ... |
1 | -/* | ||
2 | - * Copyright 2016-present Open Networking Laboratory | ||
3 | * | 1 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 2 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 3 | * you may not use this file except in compliance with the License. | ... | ... |
... | @@ -17,10 +17,13 @@ | ... | @@ -17,10 +17,13 @@ |
17 | package org.onosproject.yangutils.utils.io.impl; | 17 | package org.onosproject.yangutils.utils.io.impl; |
18 | 18 | ||
19 | import java.io.File; | 19 | import java.io.File; |
20 | +import java.io.FileInputStream; | ||
21 | +import java.io.FileOutputStream; | ||
20 | import java.io.FileWriter; | 22 | import java.io.FileWriter; |
21 | import java.io.IOException; | 23 | import java.io.IOException; |
22 | import java.lang.reflect.Constructor; | 24 | import java.lang.reflect.Constructor; |
23 | import java.lang.reflect.InvocationTargetException; | 25 | import java.lang.reflect.InvocationTargetException; |
26 | +import java.util.Calendar; | ||
24 | 27 | ||
25 | import org.junit.Rule; | 28 | import org.junit.Rule; |
26 | import org.junit.Test; | 29 | import org.junit.Test; |
... | @@ -40,7 +43,8 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -40,7 +43,8 @@ import static org.slf4j.LoggerFactory.getLogger; |
40 | public final class CopyrightHeaderTest { | 43 | public final class CopyrightHeaderTest { |
41 | 44 | ||
42 | private final Logger log = getLogger(getClass()); | 45 | private final Logger log = getLogger(getClass()); |
43 | - | 46 | + private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR) |
47 | + + "-present Open Networking Laboratory\n"; | ||
44 | @Rule | 48 | @Rule |
45 | public ExpectedException thrown = ExpectedException.none(); | 49 | public ExpectedException thrown = ExpectedException.none(); |
46 | 50 | ||
... | @@ -74,16 +78,30 @@ public final class CopyrightHeaderTest { | ... | @@ -74,16 +78,30 @@ public final class CopyrightHeaderTest { |
74 | @Test | 78 | @Test |
75 | public void testGetCopyrightHeader() throws IOException { | 79 | public void testGetCopyrightHeader() throws IOException { |
76 | 80 | ||
77 | - String baseDir = System.getProperty("basedir"); | 81 | + String path = "src/test/resources/CopyrightHeader.txt"; |
78 | - String path = "/src/test/resources/CopyrightHeader.txt"; | 82 | + |
83 | + File testRsc = new File(path); | ||
84 | + FileInputStream in = new FileInputStream(testRsc); | ||
85 | + | ||
86 | + File testFile = new File("target/TestHeader.txt"); | ||
87 | + FileOutputStream out = new FileOutputStream(testFile); | ||
88 | + | ||
89 | + out.write(COPYRIGHTS_FIRST_LINE.getBytes()); | ||
90 | + int c = 0; | ||
91 | + while ((c = in.read()) != -1) { | ||
92 | + out.write(c); | ||
93 | + } | ||
79 | 94 | ||
80 | String licenseHeader = getCopyrightHeader(); | 95 | String licenseHeader = getCopyrightHeader(); |
81 | File test = new File("target/TestCopyrightHeader.txt"); | 96 | File test = new File("target/TestCopyrightHeader.txt"); |
82 | 97 | ||
83 | - FileWriter out = new FileWriter(test); | 98 | + FileWriter writer = new FileWriter(test); |
84 | - out.write(licenseHeader); | 99 | + writer.write(licenseHeader); |
100 | + writer.close(); | ||
85 | out.close(); | 101 | out.close(); |
102 | + out.flush(); | ||
103 | + in.close(); | ||
86 | 104 | ||
87 | - assertThat(true, is(contentEquals(test, new File(baseDir + path)))); | 105 | + assertThat(true, is(contentEquals(test, testFile))); |
88 | } | 106 | } |
89 | } | 107 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -159,7 +159,7 @@ public final class JavaDocGenTest { | ... | @@ -159,7 +159,7 @@ public final class JavaDocGenTest { |
159 | @Test | 159 | @Test |
160 | public void packageInfoGenerationTest() { | 160 | public void packageInfoGenerationTest() { |
161 | String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false); | 161 | String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false); |
162 | - assertThat(true, is(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(END_STRING))); | 162 | + assertThat(true, is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING))); |
163 | } | 163 | } |
164 | 164 | ||
165 | /** | 165 | /** | ... | ... |
1 | -/* | ||
2 | - * Copyright 2016-present Open Networking Laboratory | ||
3 | * | 1 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 2 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 3 | * you may not use this file except in compliance with the License. | ... | ... |
-
Please register or login to post a comment