Committed by
Ray Milkey
[ONOS-4547, ONOS-4566, ONOS-4575, ONOS-4582, ONOS-4581, ONOS-4600,
ONOS-4598, ONOS-4607, ONOS-4610, ONOS-4611] Prefix addition from config and defect fixes. Change-Id: Ieaab5d3e0fe9a1bfa24a2527eeec5435cf0a1b85
Showing
33 changed files
with
396 additions
and
103 deletions
... | @@ -41,4 +41,6 @@ | ... | @@ -41,4 +41,6 @@ |
41 | <suppress checks="JavadocPackage" | 41 | <suppress checks="JavadocPackage" |
42 | files=".*/thirdparty/.*.java"/> | 42 | files=".*/thirdparty/.*.java"/> |
43 | 43 | ||
44 | + <!-- Suppressions for yangutils generated code --> | ||
45 | + <suppress files="org.onosproject.yang.gen.v1.*" checks="JavadocStyle" /> | ||
44 | </suppressions> | 46 | </suppressions> | ... | ... |
... | @@ -31,7 +31,7 @@ import org.onosproject.yangutils.utils.YangConstructType; | ... | @@ -31,7 +31,7 @@ import org.onosproject.yangutils.utils.YangConstructType; |
31 | /** | 31 | /** |
32 | * Represents the enumeration data type information. | 32 | * Represents the enumeration data type information. |
33 | */ | 33 | */ |
34 | -public class YangEnumeration extends YangNode implements Parsable { | 34 | +public class YangEnumeration extends YangNode implements Parsable, CollisionDetector { |
35 | 35 | ||
36 | // Enumeration info set. | 36 | // Enumeration info set. |
37 | private Set<YangEnum> enumSet; | 37 | private Set<YangEnum> enumSet; |
... | @@ -126,4 +126,18 @@ public class YangEnumeration extends YangNode implements Parsable { | ... | @@ -126,4 +126,18 @@ public class YangEnumeration extends YangNode implements Parsable { |
126 | public void validateDataOnExit() throws DataModelException { | 126 | public void validateDataOnExit() throws DataModelException { |
127 | // TODO auto-generated method stub, to be implemented by parser | 127 | // TODO auto-generated method stub, to be implemented by parser |
128 | } | 128 | } |
129 | + | ||
130 | + @Override | ||
131 | + public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException { | ||
132 | + /* | ||
133 | + Do nothing.The implementation for this is not required. | ||
134 | + */ | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public void detectSelfCollision(String identifierName, YangConstructType dataType) throws DataModelException { | ||
139 | + /* | ||
140 | + Do nothing.The implementation for this is not required. | ||
141 | + */ | ||
142 | + } | ||
129 | } | 143 | } | ... | ... |
... | @@ -444,8 +444,8 @@ public class YangList extends YangNode | ... | @@ -444,8 +444,8 @@ public class YangList extends YangNode |
444 | validateConfig(leaves, leafLists); | 444 | validateConfig(leaves, leafLists); |
445 | 445 | ||
446 | /* A list must have atleast one key leaf if config is true */ | 446 | /* A list must have atleast one key leaf if config is true */ |
447 | - if (isConfig | 447 | + if (isConfig && (keys == null || leaves == null && leafLists == null) && !isUsesPresentInList() |
448 | - && (keys == null || leaves == null && leafLists == null && !isUsesPresentInList())) { | 448 | + && !isListPresentInGrouping()) { |
449 | throw new DataModelException("A list must have atleast one key leaf if config is true;"); | 449 | throw new DataModelException("A list must have atleast one key leaf if config is true;"); |
450 | } else if (keys != null) { | 450 | } else if (keys != null) { |
451 | validateKey(leaves, leafLists, keys); | 451 | validateKey(leaves, leafLists, keys); |
... | @@ -565,7 +565,7 @@ public class YangList extends YangNode | ... | @@ -565,7 +565,7 @@ public class YangList extends YangNode |
565 | } | 565 | } |
566 | } | 566 | } |
567 | 567 | ||
568 | - if (!leafFound && !isUsesPresentInList()) { | 568 | + if (!leafFound && !isUsesPresentInList() && !isListPresentInGrouping()) { |
569 | throw new DataModelException("An identifier, in key, must refer to a child leaf of the list"); | 569 | throw new DataModelException("An identifier, in key, must refer to a child leaf of the list"); |
570 | } | 570 | } |
571 | leafFound = false; | 571 | leafFound = false; |
... | @@ -617,6 +617,18 @@ public class YangList extends YangNode | ... | @@ -617,6 +617,18 @@ public class YangList extends YangNode |
617 | node = node.getNextSibling(); | 617 | node = node.getNextSibling(); |
618 | } | 618 | } |
619 | return false; | 619 | return false; |
620 | + // TODO When grouping linking is done this method has to be modified. | ||
620 | } | 621 | } |
621 | 622 | ||
623 | + private boolean isListPresentInGrouping() { | ||
624 | + YangNode node = this.getParent(); | ||
625 | + while (node != null) { | ||
626 | + if (node instanceof YangGrouping) { | ||
627 | + return true; | ||
628 | + } | ||
629 | + node = node.getParent(); | ||
630 | + } | ||
631 | + return false; | ||
632 | + // TODO When grouping linking is done this method has to be modified. | ||
633 | + } | ||
622 | } | 634 | } | ... | ... |
... | @@ -122,6 +122,12 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -122,6 +122,12 @@ public class YangUtilManager extends AbstractMojo { |
122 | private String replacementForHyphen; | 122 | private String replacementForHyphen; |
123 | 123 | ||
124 | /** | 124 | /** |
125 | + * Prefix which is required for adding with the identifier. | ||
126 | + */ | ||
127 | + @Parameter(property = "prefixForIdentifier") | ||
128 | + private String prefixForIdentifier; | ||
129 | + | ||
130 | + /** | ||
125 | * Build context. | 131 | * Build context. |
126 | */ | 132 | */ |
127 | @Component | 133 | @Component |
... | @@ -146,6 +152,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -146,6 +152,7 @@ public class YangUtilManager extends AbstractMojo { |
146 | conflictResolver.setReplacementForPeriod(replacementForPeriod); | 152 | conflictResolver.setReplacementForPeriod(replacementForPeriod); |
147 | conflictResolver.setReplacementForHyphen(replacementForHyphen); | 153 | conflictResolver.setReplacementForHyphen(replacementForHyphen); |
148 | conflictResolver.setReplacementForUnderscore(replacementForUnderscore); | 154 | conflictResolver.setReplacementForUnderscore(replacementForUnderscore); |
155 | + conflictResolver.setPrefixForIdentifier(prefixForIdentifier); | ||
149 | YangPluginConfig yangPlugin = new YangPluginConfig(); | 156 | YangPluginConfig yangPlugin = new YangPluginConfig(); |
150 | yangPlugin.setCodeGenDir(codeGenDir); | 157 | yangPlugin.setCodeGenDir(codeGenDir); |
151 | yangPlugin.setConflictResolver(conflictResolver); | 158 | yangPlugin.setConflictResolver(conflictResolver); |
... | @@ -174,7 +181,7 @@ public class YangUtilManager extends AbstractMojo { | ... | @@ -174,7 +181,7 @@ public class YangUtilManager extends AbstractMojo { |
174 | addToSource(getDirectory(baseDir, genFilesDir), project, context); | 181 | addToSource(getDirectory(baseDir, genFilesDir), project, context); |
175 | 182 | ||
176 | copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project); | 183 | copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project); |
177 | - } catch (Exception e) { | 184 | + } catch (IOException | ParserException e) { |
178 | String fileName = ""; | 185 | String fileName = ""; |
179 | if (getCurYangFileInfo() != null) { | 186 | if (getCurYangFileInfo() != null) { |
180 | fileName = getCurYangFileInfo().getYangFileName(); | 187 | fileName = getCurYangFileInfo().getYangFileName(); | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
... | @@ -103,8 +103,7 @@ public class JavaQualifiedTypeInfo | ... | @@ -103,8 +103,7 @@ public class JavaQualifiedTypeInfo |
103 | * Current leaves holder is adding a leaf info as a attribute to the | 103 | * Current leaves holder is adding a leaf info as a attribute to the |
104 | * current class. | 104 | * current class. |
105 | */ | 105 | */ |
106 | - String className = | 106 | + String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(), |
107 | - AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(), | ||
108 | leaf.getConflictResolveConfig()); | 107 | leaf.getConflictResolveConfig()); |
109 | if (className != null) { | 108 | if (className != null) { |
110 | /* | 109 | /* |
... | @@ -113,7 +112,7 @@ public class JavaQualifiedTypeInfo | ... | @@ -113,7 +112,7 @@ public class JavaQualifiedTypeInfo |
113 | */ | 112 | */ |
114 | importInfo.setClassInfo(className); | 113 | importInfo.setClassInfo(className); |
115 | String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(), | 114 | String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(), |
116 | - leaf.isLeafList(), className); | 115 | + leaf.isLeafList(), className, leaf.getConflictResolveConfig()); |
117 | if (classPkg == null) { | 116 | if (classPkg == null) { |
118 | throw new TranslatorException("import package cannot be null when the class is used"); | 117 | throw new TranslatorException("import package cannot be null when the class is used"); |
119 | } | 118 | } |
... | @@ -166,11 +165,11 @@ public class JavaQualifiedTypeInfo | ... | @@ -166,11 +165,11 @@ public class JavaQualifiedTypeInfo |
166 | * Returns the java qualified type information for the wrapper classes. | 165 | * Returns the java qualified type information for the wrapper classes. |
167 | * | 166 | * |
168 | * @param referredTypesAttrInfo attribute of referred type | 167 | * @param referredTypesAttrInfo attribute of referred type |
169 | - * @param confilictResolver plugin configurations | 168 | + * @param conflictResolver plugin configurations |
170 | * @return return the import info for this attribute | 169 | * @return return the import info for this attribute |
171 | */ | 170 | */ |
172 | public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo, | 171 | public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo, |
173 | - YangToJavaNamingConflictUtil confilictResolver) { | 172 | + YangToJavaNamingConflictUtil conflictResolver) { |
174 | 173 | ||
175 | /* | 174 | /* |
176 | * Get the java qualified type information for the wrapper classes and | 175 | * Get the java qualified type information for the wrapper classes and |
... | @@ -179,9 +178,9 @@ public class JavaQualifiedTypeInfo | ... | @@ -179,9 +178,9 @@ public class JavaQualifiedTypeInfo |
179 | JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo(); | 178 | JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo(); |
180 | 179 | ||
181 | qualifiedInfoOfFromString.setClassInfo( | 180 | qualifiedInfoOfFromString.setClassInfo( |
182 | - getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, confilictResolver)); | 181 | + getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, conflictResolver)); |
183 | qualifiedInfoOfFromString.setPkgInfo( | 182 | qualifiedInfoOfFromString.setPkgInfo( |
184 | - getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null)); | 183 | + getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null, conflictResolver)); |
185 | return qualifiedInfoOfFromString; | 184 | return qualifiedInfoOfFromString; |
186 | } | 185 | } |
187 | 186 | ... | ... |
... | @@ -34,8 +34,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -34,8 +34,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
34 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; | 34 | import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; |
35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; | 35 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString; |
36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile; | 36 | import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile; |
37 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute; | ||
38 | +import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPrefixForIdentifier; | ||
37 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; | 39 | import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
41 | +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT; | ||
42 | +import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX; | ||
39 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; | 43 | import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage; |
40 | 44 | ||
41 | /** | 45 | /** |
... | @@ -173,7 +177,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -173,7 +177,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
173 | /** | 177 | /** |
174 | * Adds enum class attributes to temporary file. | 178 | * Adds enum class attributes to temporary file. |
175 | * | 179 | * |
176 | - * @param curEnumInfo current YANG enum | 180 | + * @param curEnumName current YANG enum |
177 | * @throws IOException when fails to do IO operations. | 181 | * @throws IOException when fails to do IO operations. |
178 | */ | 182 | */ |
179 | private void addAttributesForEnumClass(String curEnumName, YangPluginConfig pluginConfig) throws IOException { | 183 | private void addAttributesForEnumClass(String curEnumName, YangPluginConfig pluginConfig) throws IOException { |
... | @@ -194,6 +198,16 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -194,6 +198,16 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
194 | if (curNode instanceof YangEnumeration) { | 198 | if (curNode instanceof YangEnumeration) { |
195 | YangEnumeration enumeration = (YangEnumeration) curNode; | 199 | YangEnumeration enumeration = (YangEnumeration) curNode; |
196 | for (YangEnum curEnum : enumeration.getEnumSet()) { | 200 | for (YangEnum curEnum : enumeration.getEnumSet()) { |
201 | + String enumName = curEnum.getNamedValue(); | ||
202 | + String prefixForIdentifier = null; | ||
203 | + if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) { | ||
204 | + prefixForIdentifier = getPrefixForIdentifier(pluginConfig.getConflictResolver()); | ||
205 | + if (prefixForIdentifier != null) { | ||
206 | + curEnum.setNamedValue(prefixForIdentifier + enumName); | ||
207 | + } else { | ||
208 | + curEnum.setNamedValue(YANG_AUTO_PREFIX + enumName); | ||
209 | + } | ||
210 | + } | ||
197 | setEnumValue(curEnum.getValue()); | 211 | setEnumValue(curEnum.getValue()); |
198 | addToEnumStringList(curEnum.getNamedValue()); | 212 | addToEnumStringList(curEnum.getNamedValue()); |
199 | addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue()); | 213 | addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue()); |
... | @@ -228,7 +242,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -228,7 +242,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
228 | * @param curEnumName current enum name | 242 | * @param curEnumName current enum name |
229 | */ | 243 | */ |
230 | private void addToEnumSetJavaMap(String curEnumName, int value) { | 244 | private void addToEnumSetJavaMap(String curEnumName, int value) { |
231 | - getEnumSetJavaMap().put(curEnumName.toUpperCase(), value); | 245 | + getEnumSetJavaMap().put(getEnumJavaAttribute(curEnumName).toUpperCase(), value); |
232 | } | 246 | } |
233 | 247 | ||
234 | /** | 248 | /** |
... | @@ -240,7 +254,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -240,7 +254,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
240 | */ | 254 | */ |
241 | void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig) | 255 | void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig) |
242 | throws IOException { | 256 | throws IOException { |
243 | - addAttributesForEnumClass(curEnumName, pluginConfig); | 257 | + addAttributesForEnumClass(getEnumJavaAttribute(curEnumName), pluginConfig); |
244 | } | 258 | } |
245 | 259 | ||
246 | /** | 260 | /** |
... | @@ -279,7 +293,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { | ... | @@ -279,7 +293,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles { |
279 | * @param curEnumValue current enum value | 293 | * @param curEnumValue current enum value |
280 | */ | 294 | */ |
281 | private void addToEnumStringList(String curEnumValue) { | 295 | private void addToEnumStringList(String curEnumValue) { |
282 | - getEnumStringList().add(curEnumValue.toUpperCase()); | 296 | + getEnumStringList().add(getEnumJavaAttribute(curEnumValue).toUpperCase()); |
283 | } | 297 | } |
284 | 298 | ||
285 | /** | 299 | /** | ... | ... |
... | @@ -28,7 +28,6 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; | ... | @@ -28,7 +28,6 @@ import org.onosproject.yangutils.translator.exception.TranslatorException; |
28 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType; | 28 | import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType; |
29 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; | 29 | import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig; |
30 | 30 | ||
31 | -import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; | ||
32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; | 31 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS; |
33 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; | 32 | import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS; |
34 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; | 33 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK; |
... | @@ -212,10 +211,7 @@ public class TempJavaTypeFragmentFiles | ... | @@ -212,10 +211,7 @@ public class TempJavaTypeFragmentFiles |
212 | YangJavaType<?> javaType = (YangJavaType<?>) yangType; | 211 | YangJavaType<?> javaType = (YangJavaType<?>) yangType; |
213 | javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver()); | 212 | javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver()); |
214 | String typeName = javaType.getDataTypeName(); | 213 | String typeName = javaType.getDataTypeName(); |
215 | - | ||
216 | - if (javaType.getDataType().equals(DERIVED)) { | ||
217 | typeName = getCamelCase(typeName, pluginConfig.getConflictResolver()); | 214 | typeName = getCamelCase(typeName, pluginConfig.getConflictResolver()); |
218 | - } | ||
219 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( | 215 | JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData( |
220 | javaType.getJavaQualifiedInfo(), | 216 | javaType.getJavaQualifiedInfo(), |
221 | typeName, javaType, | 217 | typeName, javaType, | ... | ... |
... | @@ -126,7 +126,8 @@ public class YangJavaModule | ... | @@ -126,7 +126,8 @@ public class YangJavaModule |
126 | */ | 126 | */ |
127 | @Override | 127 | @Override |
128 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { | 128 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
129 | - String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate()); | 129 | + String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate(), |
130 | + yangPlugin.getConflictResolver()); | ||
130 | try { | 131 | try { |
131 | generateCodeOfRootNode(this, yangPlugin, modulePkg); | 132 | generateCodeOfRootNode(this, yangPlugin, modulePkg); |
132 | } catch (IOException e) { | 133 | } catch (IOException e) { | ... | ... |
... | @@ -139,7 +139,7 @@ public class YangJavaSubModule | ... | @@ -139,7 +139,7 @@ public class YangJavaSubModule |
139 | @Override | 139 | @Override |
140 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { | 140 | public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException { |
141 | String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()), | 141 | String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()), |
142 | - getRevision().getRevDate()); | 142 | + getRevision().getRevDate(), yangPlugin.getConflictResolver()); |
143 | try { | 143 | try { |
144 | generateCodeOfRootNode(this, yangPlugin, subModulePkg); | 144 | generateCodeOfRootNode(this, yangPlugin, subModulePkg); |
145 | } catch (IOException e) { | 145 | } catch (IOException e) { | ... | ... |
... | @@ -41,13 +41,13 @@ public class YangJavaType<T> | ... | @@ -41,13 +41,13 @@ public class YangJavaType<T> |
41 | } | 41 | } |
42 | 42 | ||
43 | @Override | 43 | @Override |
44 | - public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver) { | 44 | + public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil conflictResolver) { |
45 | JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo(); | 45 | JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo(); |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * Type is added as an attribute in the class. | 48 | * Type is added as an attribute in the class. |
49 | */ | 49 | */ |
50 | - String className = AttributesJavaDataType.getJavaImportClass(this, false, confilictResolver); | 50 | + String className = AttributesJavaDataType.getJavaImportClass(this, false, conflictResolver); |
51 | if (className != null) { | 51 | if (className != null) { |
52 | /* | 52 | /* |
53 | * Corresponding to the attribute type a class needs to be imported, | 53 | * Corresponding to the attribute type a class needs to be imported, |
... | @@ -55,7 +55,7 @@ public class YangJavaType<T> | ... | @@ -55,7 +55,7 @@ public class YangJavaType<T> |
55 | */ | 55 | */ |
56 | importInfo.setClassInfo(className); | 56 | importInfo.setClassInfo(className); |
57 | String classPkg = AttributesJavaDataType.getJavaImportPackage(this, | 57 | String classPkg = AttributesJavaDataType.getJavaImportPackage(this, |
58 | - false, className); | 58 | + false, className, conflictResolver); |
59 | if (classPkg == null) { | 59 | if (classPkg == null) { |
60 | throw new TranslatorException("import package cannot be null when the class is used"); | 60 | throw new TranslatorException("import package cannot be null when the class is used"); |
61 | } | 61 | } | ... | ... |
... | @@ -271,9 +271,11 @@ public final class AttributesJavaDataType { | ... | @@ -271,9 +271,11 @@ public final class AttributesJavaDataType { |
271 | * @param yangType YANG type | 271 | * @param yangType YANG type |
272 | * @param isListAttr if the attribute is of list type | 272 | * @param isListAttr if the attribute is of list type |
273 | * @param classInfo java import class info | 273 | * @param classInfo java import class info |
274 | + * @param conflictResolver object of YANG to java naming conflict util | ||
274 | * @return java import package | 275 | * @return java import package |
275 | */ | 276 | */ |
276 | - public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) { | 277 | + public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo, |
278 | + YangToJavaNamingConflictUtil conflictResolver) { | ||
277 | 279 | ||
278 | YangDataTypes type = yangType.getDataType(); | 280 | YangDataTypes type = yangType.getDataType(); |
279 | 281 | ||
... | @@ -293,7 +295,7 @@ public final class AttributesJavaDataType { | ... | @@ -293,7 +295,7 @@ public final class AttributesJavaDataType { |
293 | case UINT64: | 295 | case UINT64: |
294 | return JAVA_MATH; | 296 | return JAVA_MATH; |
295 | case ENUMERATION: | 297 | case ENUMERATION: |
296 | - return getEnumsPackage(yangType); | 298 | + return getEnumsPackage(yangType, conflictResolver); |
297 | case DECIMAL64: | 299 | case DECIMAL64: |
298 | case BITS: | 300 | case BITS: |
299 | case BINARY: | 301 | case BINARY: |
... | @@ -305,12 +307,12 @@ public final class AttributesJavaDataType { | ... | @@ -305,12 +307,12 @@ public final class AttributesJavaDataType { |
305 | //TODO:IDENTITYREF | 307 | //TODO:IDENTITYREF |
306 | break; | 308 | break; |
307 | case UNION: | 309 | case UNION: |
308 | - return getUnionPackage(yangType); | 310 | + return getUnionPackage(yangType, conflictResolver); |
309 | case INSTANCE_IDENTIFIER: | 311 | case INSTANCE_IDENTIFIER: |
310 | //TODO:INSTANCE_IDENTIFIER | 312 | //TODO:INSTANCE_IDENTIFIER |
311 | break; | 313 | break; |
312 | case DERIVED: | 314 | case DERIVED: |
313 | - return getTypDefsPackage(yangType); | 315 | + return getTypDefsPackage(yangType, conflictResolver); |
314 | default: | 316 | default: |
315 | throw new TranslatorException("given data type is not supported."); | 317 | throw new TranslatorException("given data type is not supported."); |
316 | } | 318 | } |
... | @@ -321,7 +323,7 @@ public final class AttributesJavaDataType { | ... | @@ -321,7 +323,7 @@ public final class AttributesJavaDataType { |
321 | case STRING: | 323 | case STRING: |
322 | return JAVA_LANG; | 324 | return JAVA_LANG; |
323 | case ENUMERATION: | 325 | case ENUMERATION: |
324 | - return getEnumsPackage(yangType); | 326 | + return getEnumsPackage(yangType, conflictResolver); |
325 | case DECIMAL64: | 327 | case DECIMAL64: |
326 | case BITS: | 328 | case BITS: |
327 | case BINARY: | 329 | case BINARY: |
... | @@ -335,12 +337,12 @@ public final class AttributesJavaDataType { | ... | @@ -335,12 +337,12 @@ public final class AttributesJavaDataType { |
335 | case EMPTY: | 337 | case EMPTY: |
336 | return JAVA_LANG; | 338 | return JAVA_LANG; |
337 | case UNION: | 339 | case UNION: |
338 | - return getUnionPackage(yangType); | 340 | + return getUnionPackage(yangType, conflictResolver); |
339 | case INSTANCE_IDENTIFIER: | 341 | case INSTANCE_IDENTIFIER: |
340 | //TODO:INSTANCE_IDENTIFIER | 342 | //TODO:INSTANCE_IDENTIFIER |
341 | break; | 343 | break; |
342 | case DERIVED: | 344 | case DERIVED: |
343 | - return getTypDefsPackage(yangType); | 345 | + return getTypDefsPackage(yangType, conflictResolver); |
344 | default: | 346 | default: |
345 | return null; | 347 | return null; |
346 | } | 348 | } |
... | @@ -352,9 +354,10 @@ public final class AttributesJavaDataType { | ... | @@ -352,9 +354,10 @@ public final class AttributesJavaDataType { |
352 | * Returns java package for typedef node. | 354 | * Returns java package for typedef node. |
353 | * | 355 | * |
354 | * @param type YANG type | 356 | * @param type YANG type |
357 | + * @param conflictResolver object of YANG to java naming conflict util | ||
355 | * @return java package for typedef node | 358 | * @return java package for typedef node |
356 | */ | 359 | */ |
357 | - private static String getTypDefsPackage(YangType<?> type) { | 360 | + private static String getTypDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) { |
358 | Object var = type.getDataTypeExtendedInfo(); | 361 | Object var = type.getDataTypeExtendedInfo(); |
359 | if (!(var instanceof YangDerivedInfo)) { | 362 | if (!(var instanceof YangDerivedInfo)) { |
360 | throw new TranslatorException("type should have been derived."); | 363 | throw new TranslatorException("type should have been derived."); |
... | @@ -366,7 +369,7 @@ public final class AttributesJavaDataType { | ... | @@ -366,7 +369,7 @@ public final class AttributesJavaDataType { |
366 | 369 | ||
367 | YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef(); | 370 | YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef(); |
368 | if (typedef.getJavaFileInfo().getPackage() == null) { | 371 | if (typedef.getJavaFileInfo().getPackage() == null) { |
369 | - return getPackageFromParent(typedef.getParent()); | 372 | + return getPackageFromParent(typedef.getParent(), conflictResolver); |
370 | } | 373 | } |
371 | return typedef.getJavaFileInfo().getPackage(); | 374 | return typedef.getJavaFileInfo().getPackage(); |
372 | } | 375 | } |
... | @@ -375,9 +378,10 @@ public final class AttributesJavaDataType { | ... | @@ -375,9 +378,10 @@ public final class AttributesJavaDataType { |
375 | * Returns java package for union node. | 378 | * Returns java package for union node. |
376 | * | 379 | * |
377 | * @param type YANG type | 380 | * @param type YANG type |
381 | + * @param conflictResolver object of YANG to java naming conflict util | ||
378 | * @return java package for union node | 382 | * @return java package for union node |
379 | */ | 383 | */ |
380 | - private static String getUnionPackage(YangType<?> type) { | 384 | + private static String getUnionPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) { |
381 | 385 | ||
382 | if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) { | 386 | if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) { |
383 | throw new TranslatorException("type should have been union."); | 387 | throw new TranslatorException("type should have been union."); |
... | @@ -385,7 +389,7 @@ public final class AttributesJavaDataType { | ... | @@ -385,7 +389,7 @@ public final class AttributesJavaDataType { |
385 | 389 | ||
386 | YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo(); | 390 | YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo(); |
387 | if (union.getJavaFileInfo().getPackage() == null) { | 391 | if (union.getJavaFileInfo().getPackage() == null) { |
388 | - return getPackageFromParent(union.getParent()); | 392 | + return getPackageFromParent(union.getParent(), conflictResolver); |
389 | } | 393 | } |
390 | return union.getJavaFileInfo().getPackage(); | 394 | return union.getJavaFileInfo().getPackage(); |
391 | } | 395 | } |
... | @@ -394,16 +398,17 @@ public final class AttributesJavaDataType { | ... | @@ -394,16 +398,17 @@ public final class AttributesJavaDataType { |
394 | * Returns YANG enumeration's java package. | 398 | * Returns YANG enumeration's java package. |
395 | * | 399 | * |
396 | * @param type YANG type | 400 | * @param type YANG type |
401 | + * @param conflictResolver object of YANG to java naming conflict util | ||
397 | * @return YANG enumeration's java package | 402 | * @return YANG enumeration's java package |
398 | */ | 403 | */ |
399 | - private static String getEnumsPackage(YangType<?> type) { | 404 | + private static String getEnumsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) { |
400 | 405 | ||
401 | if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) { | 406 | if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) { |
402 | throw new TranslatorException("type should have been enumeration."); | 407 | throw new TranslatorException("type should have been enumeration."); |
403 | } | 408 | } |
404 | YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo(); | 409 | YangJavaEnumeration enumeration = (YangJavaEnumeration) type.getDataTypeExtendedInfo(); |
405 | if (enumeration.getJavaFileInfo().getPackage() == null) { | 410 | if (enumeration.getJavaFileInfo().getPackage() == null) { |
406 | - return getPackageFromParent(enumeration.getParent()); | 411 | + return getPackageFromParent(enumeration.getParent(), conflictResolver); |
407 | } | 412 | } |
408 | return enumeration.getJavaFileInfo().getPackage(); | 413 | return enumeration.getJavaFileInfo().getPackage(); |
409 | } | 414 | } |
... | @@ -412,9 +417,10 @@ public final class AttributesJavaDataType { | ... | @@ -412,9 +417,10 @@ public final class AttributesJavaDataType { |
412 | * Returns package from parent node. | 417 | * Returns package from parent node. |
413 | * | 418 | * |
414 | * @param parent parent YANG node | 419 | * @param parent parent YANG node |
420 | + * @param conflictResolver object of YANG to java naming conflict util | ||
415 | * @return java package from parent node | 421 | * @return java package from parent node |
416 | */ | 422 | */ |
417 | - private static String getPackageFromParent(YangNode parent) { | 423 | + private static String getPackageFromParent(YangNode parent, YangToJavaNamingConflictUtil conflictResolver) { |
418 | if (!(parent instanceof JavaFileInfoContainer)) { | 424 | if (!(parent instanceof JavaFileInfoContainer)) { |
419 | throw new TranslatorException("invalid child node is being processed."); | 425 | throw new TranslatorException("invalid child node is being processed."); |
420 | } | 426 | } |
... | @@ -423,13 +429,13 @@ public final class AttributesJavaDataType { | ... | @@ -423,13 +429,13 @@ public final class AttributesJavaDataType { |
423 | if (parent instanceof YangJavaModule) { | 429 | if (parent instanceof YangJavaModule) { |
424 | YangJavaModule module = (YangJavaModule) parent; | 430 | YangJavaModule module = (YangJavaModule) parent; |
425 | String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module | 431 | String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module |
426 | - .getRevision().getRevDate()); | 432 | + .getRevision().getRevDate(), conflictResolver); |
427 | return modulePkg + PERIOD + getCamelCase(module.getName(), null).toLowerCase(); | 433 | return modulePkg + PERIOD + getCamelCase(module.getName(), null).toLowerCase(); |
428 | } else if (parent instanceof YangJavaSubModule) { | 434 | } else if (parent instanceof YangJavaSubModule) { |
429 | YangJavaSubModule submodule = (YangJavaSubModule) parent; | 435 | YangJavaSubModule submodule = (YangJavaSubModule) parent; |
430 | String subModulePkg = getRootPackage(submodule.getVersion(), | 436 | String subModulePkg = getRootPackage(submodule.getVersion(), |
431 | submodule.getNameSpaceFromModule(submodule.getBelongsTo()), | 437 | submodule.getNameSpaceFromModule(submodule.getBelongsTo()), |
432 | - submodule.getRevision().getRevDate()); | 438 | + submodule.getRevision().getRevDate(), conflictResolver); |
433 | return subModulePkg + PERIOD + getCamelCase(submodule.getName(), null).toLowerCase(); | 439 | return subModulePkg + PERIOD + getCamelCase(submodule.getName(), null).toLowerCase(); |
434 | } | 440 | } |
435 | } | 441 | } | ... | ... |
... | @@ -53,6 +53,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | ... | @@ -53,6 +53,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
53 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | 53 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
54 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 54 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
55 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | 55 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
56 | +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE; | ||
56 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; | 57 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; |
57 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 58 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
58 | import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT; |
... | @@ -241,24 +242,25 @@ public final class ClassDefinitionGenerator { | ... | @@ -241,24 +242,25 @@ public final class ClassDefinitionGenerator { |
241 | curNode = curNode.getNextSibling(); | 242 | curNode = curNode.getNextSibling(); |
242 | } | 243 | } |
243 | } | 244 | } |
244 | - if (yangName.contains(SERVICE)) { | 245 | + if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) { |
245 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 246 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
246 | } | 247 | } |
247 | - return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName | 248 | + return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + IMPLEMENTS + SPACE |
248 | - + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; | 249 | + + yangName.substring(0, yangName.length() - 7) + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE; |
249 | } | 250 | } |
250 | 251 | ||
251 | /* Provides class definition when RPC interface needs to extends any event.*/ | 252 | /* Provides class definition when RPC interface needs to extends any event.*/ |
252 | private static String getRpcInterfaceDefinitionWhenItExtends(String yangName, | 253 | private static String getRpcInterfaceDefinitionWhenItExtends(String yangName, |
253 | JavaExtendsListHolder holder) { | 254 | JavaExtendsListHolder holder) { |
254 | 255 | ||
255 | - if (yangName.contains(SERVICE)) { | 256 | + if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) { |
256 | String[] strArray = yangName.split(SERVICE); | 257 | String[] strArray = yangName.split(SERVICE); |
257 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION | 258 | return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION |
258 | + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA | 259 | + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA |
259 | + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE | 260 | + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE |
260 | + OPEN_CURLY_BRACKET + NEW_LINE; | 261 | + OPEN_CURLY_BRACKET + NEW_LINE; |
261 | } | 262 | } |
263 | + yangName = yangName.substring(0, yangName.length() - 7); | ||
262 | return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + NEW_LINE + EIGHT_SPACE_INDENTATION | 264 | return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + NEW_LINE + EIGHT_SPACE_INDENTATION |
263 | + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE | 265 | + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE |
264 | + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE | 266 | + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE | ... | ... |
... | @@ -97,6 +97,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATI | ... | @@ -97,6 +97,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATI |
97 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; | 97 | import static org.onosproject.yangutils.utils.UtilConstants.IMPL; |
98 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 98 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
99 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT; | 99 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT; |
100 | +import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; | ||
100 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 101 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
101 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 102 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
102 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; | 103 | import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC; |
... | @@ -306,7 +307,7 @@ public final class JavaFileGenerator { | ... | @@ -306,7 +307,7 @@ public final class JavaFileGenerator { |
306 | 307 | ||
307 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 308 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
308 | 309 | ||
309 | - String className = getCapitalCase(javaFileInfo.getJavaName()); | 310 | + String className = getCapitalCase(javaFileInfo.getJavaName()) + MANAGER; |
310 | 311 | ||
311 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); | 312 | initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className); |
312 | 313 | ... | ... |
... | @@ -72,14 +72,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; | ... | @@ -72,14 +72,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.EQUAL; |
72 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 72 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
73 | import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE; | 73 | import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE; |
74 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 74 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
75 | -import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; | ||
76 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; | 75 | import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE; |
77 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; | 76 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS; |
78 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; | 77 | import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE; |
79 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 78 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
80 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; | 79 | import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE; |
80 | +import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE; | ||
81 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; | 81 | import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN; |
82 | -import static org.onosproject.yangutils.utils.UtilConstants.SERVICE; | ||
83 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION; | 82 | import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION; |
84 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 83 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
85 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | 84 | import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
... | @@ -317,7 +316,7 @@ public final class JavaFileGeneratorUtils { | ... | @@ -317,7 +316,7 @@ public final class JavaFileGeneratorUtils { |
317 | if (type == GENERATE_EVENT_CLASS | 316 | if (type == GENERATE_EVENT_CLASS |
318 | || type == GENERATE_EVENT_LISTENER_INTERFACE | 317 | || type == GENERATE_EVENT_LISTENER_INTERFACE |
319 | || type == GENERATE_EVENT_SUBJECT_CLASS) { | 318 | || type == GENERATE_EVENT_SUBJECT_CLASS) { |
320 | - pkgString = parsePackageString(path + PERIOD + name, importsList); | 319 | + pkgString = parsePackageString((path + PERIOD + name).toLowerCase(), importsList); |
321 | } else { | 320 | } else { |
322 | pkgString = parsePackageString(path, importsList); | 321 | pkgString = parsePackageString(path, importsList); |
323 | } | 322 | } |
... | @@ -454,8 +453,8 @@ public final class JavaFileGeneratorUtils { | ... | @@ -454,8 +453,8 @@ public final class JavaFileGeneratorUtils { |
454 | 453 | ||
455 | YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig(); | 454 | YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig(); |
456 | if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { | 455 | if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) { |
457 | - if (!fileName.contains(SERVICE)) { | 456 | + if (!fileName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) { |
458 | - insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false, pluginConfig)); | 457 | + insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName, false, pluginConfig)); |
459 | insertDataIntoJavaFile(file, addComponentString()); | 458 | insertDataIntoJavaFile(file, addComponentString()); |
460 | } else { | 459 | } else { |
461 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); | 460 | insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig)); | ... | ... |
... | @@ -75,16 +75,18 @@ public final class JavaIdentifierSyntax { | ... | @@ -75,16 +75,18 @@ public final class JavaIdentifierSyntax { |
75 | * @param version YANG version | 75 | * @param version YANG version |
76 | * @param nameSpace name space of the module | 76 | * @param nameSpace name space of the module |
77 | * @param revision revision of the module defined | 77 | * @param revision revision of the module defined |
78 | - * @return returns the root package string | 78 | + * @param conflictResolver object of YANG to java naming conflict util |
79 | + * @return the root package string | ||
79 | */ | 80 | */ |
80 | - public static String getRootPackage(byte version, String nameSpace, String revision) { | 81 | + public static String getRootPackage(byte version, String nameSpace, String revision, |
82 | + YangToJavaNamingConflictUtil conflictResolver) { | ||
81 | 83 | ||
82 | String pkg; | 84 | String pkg; |
83 | pkg = DEFAULT_BASE_PKG; | 85 | pkg = DEFAULT_BASE_PKG; |
84 | pkg = pkg + PERIOD; | 86 | pkg = pkg + PERIOD; |
85 | pkg = pkg + getYangVersion(version); | 87 | pkg = pkg + getYangVersion(version); |
86 | pkg = pkg + PERIOD; | 88 | pkg = pkg + PERIOD; |
87 | - pkg = pkg + getPkgFromNameSpace(nameSpace); | 89 | + pkg = pkg + getPkgFromNameSpace(nameSpace, conflictResolver); |
88 | pkg = pkg + PERIOD; | 90 | pkg = pkg + PERIOD; |
89 | pkg = pkg + getYangRevisionStr(revision); | 91 | pkg = pkg + getYangRevisionStr(revision); |
90 | 92 | ||
... | @@ -144,9 +146,10 @@ public final class JavaIdentifierSyntax { | ... | @@ -144,9 +146,10 @@ public final class JavaIdentifierSyntax { |
144 | * Returns package name from name space. | 146 | * Returns package name from name space. |
145 | * | 147 | * |
146 | * @param nameSpace name space of YANG module | 148 | * @param nameSpace name space of YANG module |
149 | + * @param conflictResolver object of YANG to java naming conflict util | ||
147 | * @return java package name as per java rules | 150 | * @return java package name as per java rules |
148 | */ | 151 | */ |
149 | - private static String getPkgFromNameSpace(String nameSpace) { | 152 | + private static String getPkgFromNameSpace(String nameSpace, YangToJavaNamingConflictUtil conflictResolver) { |
150 | 153 | ||
151 | ArrayList<String> pkgArr = new ArrayList<String>(); | 154 | ArrayList<String> pkgArr = new ArrayList<String>(); |
152 | nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING); | 155 | nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING); |
... | @@ -156,7 +159,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -156,7 +159,7 @@ public final class JavaIdentifierSyntax { |
156 | for (String nameSpaceString : nameSpaceArr) { | 159 | for (String nameSpaceString : nameSpaceArr) { |
157 | pkgArr.add(nameSpaceString); | 160 | pkgArr.add(nameSpaceString); |
158 | } | 161 | } |
159 | - return getPkgFrmArr(pkgArr); | 162 | + return getPkgFrmArr(pkgArr, conflictResolver); |
160 | } | 163 | } |
161 | 164 | ||
162 | /** | 165 | /** |
... | @@ -194,17 +197,19 @@ public final class JavaIdentifierSyntax { | ... | @@ -194,17 +197,19 @@ public final class JavaIdentifierSyntax { |
194 | * Returns the package string. | 197 | * Returns the package string. |
195 | * | 198 | * |
196 | * @param pkgArr package array | 199 | * @param pkgArr package array |
200 | + * @param conflictResolver object of YANG to java naming conflict util | ||
197 | * @return package string | 201 | * @return package string |
198 | */ | 202 | */ |
199 | - private static String getPkgFrmArr(ArrayList<String> pkgArr) { | 203 | + private static String getPkgFrmArr(ArrayList<String> pkgArr, YangToJavaNamingConflictUtil conflictResolver) { |
200 | 204 | ||
201 | String pkg = EMPTY_STRING; | 205 | String pkg = EMPTY_STRING; |
202 | int size = pkgArr.size(); | 206 | int size = pkgArr.size(); |
203 | int i = 0; | 207 | int i = 0; |
204 | for (String member : pkgArr) { | 208 | for (String member : pkgArr) { |
205 | - boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member); | 209 | + boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member.toLowerCase()); |
206 | if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) { | 210 | if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) { |
207 | - member = YANG_AUTO_PREFIX + member; | 211 | + String prefix = getPrefixForIdentifier(conflictResolver); |
212 | + member = prefix + member; | ||
208 | } | 213 | } |
209 | pkg = pkg + member; | 214 | pkg = pkg + member; |
210 | if (i != size - 1) { | 215 | if (i != size - 1) { |
... | @@ -216,20 +221,40 @@ public final class JavaIdentifierSyntax { | ... | @@ -216,20 +221,40 @@ public final class JavaIdentifierSyntax { |
216 | } | 221 | } |
217 | 222 | ||
218 | /** | 223 | /** |
219 | - * Returns package sub name from YANG identifier name. | 224 | + * Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits. |
220 | * | 225 | * |
221 | - * @param name YANG identifier name | 226 | + * @param conflictResolver object of YANG to java naming conflict util |
222 | - * @return java package sub name as per java rules | 227 | + * @return prefix which needs to be added |
223 | */ | 228 | */ |
224 | - public static String getSubPkgFromName(String name) { | 229 | + public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) { |
225 | - | ||
226 | - ArrayList<String> pkgArr = new ArrayList<String>(); | ||
227 | - String[] nameArr = name.split(COLAN); | ||
228 | 230 | ||
229 | - for (String nameString : nameArr) { | 231 | + String prefixForIdentifier = null; |
230 | - pkgArr.add(nameString); | 232 | + if (conflictResolver != null) { |
233 | + prefixForIdentifier = conflictResolver.getPrefixForIdentifier(); | ||
234 | + } | ||
235 | + if (prefixForIdentifier != null) { | ||
236 | + prefixForIdentifier = prefixForIdentifier.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN); | ||
237 | + String[] strArray = prefixForIdentifier.split(COLAN); | ||
238 | + try { | ||
239 | + if (strArray[0].isEmpty()) { | ||
240 | + List<String> stringArrangement = new ArrayList<String>(); | ||
241 | + for (int i = 1; i < strArray.length; i++) { | ||
242 | + stringArrangement.add(strArray[i]); | ||
243 | + } | ||
244 | + strArray = stringArrangement.toArray(new String[stringArrangement.size()]); | ||
245 | + } | ||
246 | + prefixForIdentifier = strArray[0]; | ||
247 | + for (int j = 1; j < strArray.length; j++) { | ||
248 | + prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase() + | ||
249 | + strArray[j].substring(1); | ||
231 | } | 250 | } |
232 | - return getPkgFrmArr(pkgArr); | 251 | + } catch (ArrayIndexOutOfBoundsException outOfBoundsException) { |
252 | + throw new TranslatorException("The given prefix in pom.xml is invalid."); | ||
253 | + } | ||
254 | + } else { | ||
255 | + prefixForIdentifier = YANG_AUTO_PREFIX; | ||
256 | + } | ||
257 | + return prefixForIdentifier; | ||
233 | } | 258 | } |
234 | 259 | ||
235 | /** | 260 | /** |
... | @@ -267,16 +292,18 @@ public final class JavaIdentifierSyntax { | ... | @@ -267,16 +292,18 @@ public final class JavaIdentifierSyntax { |
267 | } | 292 | } |
268 | strArray = stringArrangement.toArray(new String[stringArrangement.size()]); | 293 | strArray = stringArrangement.toArray(new String[stringArrangement.size()]); |
269 | } | 294 | } |
270 | - return upperCaseConflictResolver(strArray); | 295 | + return upperCaseConflictResolver(strArray, conflictResolver); |
271 | } | 296 | } |
272 | 297 | ||
273 | /** | 298 | /** |
274 | - * Resolves the conflict when input has uppercase. | 299 | + * Resolves the conflict when input has upper case. |
275 | * | 300 | * |
276 | - * @param stringArray containing strings for uppercase conflict resolver | 301 | + * @param stringArray containing strings for upper case conflict resolver |
302 | + * @param conflictResolver object of YANG to java naming conflict util | ||
277 | * @return camel cased string | 303 | * @return camel cased string |
278 | */ | 304 | */ |
279 | - private static String upperCaseConflictResolver(String[] stringArray) { | 305 | + private static String upperCaseConflictResolver(String[] stringArray, |
306 | + YangToJavaNamingConflictUtil conflictResolver) { | ||
280 | 307 | ||
281 | for (int l = 0; l < stringArray.length; l++) { | 308 | for (int l = 0; l < stringArray.length; l++) { |
282 | String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE); | 309 | String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE); |
... | @@ -317,7 +344,7 @@ public final class JavaIdentifierSyntax { | ... | @@ -317,7 +344,7 @@ public final class JavaIdentifierSyntax { |
317 | } | 344 | } |
318 | } | 345 | } |
319 | stringArray = result.toArray(new String[result.size()]); | 346 | stringArray = result.toArray(new String[result.size()]); |
320 | - return applyCamelCaseRule(stringArray); | 347 | + return applyCamelCaseRule(stringArray, conflictResolver); |
321 | } | 348 | } |
322 | 349 | ||
323 | /** | 350 | /** |
... | @@ -325,9 +352,10 @@ public final class JavaIdentifierSyntax { | ... | @@ -325,9 +352,10 @@ public final class JavaIdentifierSyntax { |
325 | * the letter next to a number in an array. | 352 | * the letter next to a number in an array. |
326 | * | 353 | * |
327 | * @param stringArray containing strings for camel case separation | 354 | * @param stringArray containing strings for camel case separation |
355 | + * @param conflictResolver object of YANG to java naming conflict util | ||
328 | * @return camel case rule checked string | 356 | * @return camel case rule checked string |
329 | */ | 357 | */ |
330 | - private static String applyCamelCaseRule(String[] stringArray) { | 358 | + private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) { |
331 | 359 | ||
332 | String ruleChecker = stringArray[0].toLowerCase(); | 360 | String ruleChecker = stringArray[0].toLowerCase(); |
333 | int i; | 361 | int i; |
... | @@ -359,23 +387,25 @@ public final class JavaIdentifierSyntax { | ... | @@ -359,23 +387,25 @@ public final class JavaIdentifierSyntax { |
359 | ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1); | 387 | ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1); |
360 | } | 388 | } |
361 | } | 389 | } |
362 | - String ruleCheckerWithPrefix = addPrefix(ruleChecker); | 390 | + String ruleCheckerWithPrefix = addPrefix(ruleChecker, conflictResolver); |
363 | return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix); | 391 | return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix); |
364 | } | 392 | } |
365 | 393 | ||
366 | /** | 394 | /** |
367 | - * Adds prefix YANG auto prefix if the string begins with digit or is a java key word. | 395 | + * Adds prefix, if the string begins with digit or is a java key word. |
368 | * | 396 | * |
369 | * @param camelCasePrefix string for adding prefix | 397 | * @param camelCasePrefix string for adding prefix |
398 | + * @param conflictResolver object of YANG to java naming conflict util | ||
370 | * @return prefixed camel case string | 399 | * @return prefixed camel case string |
371 | */ | 400 | */ |
372 | - private static String addPrefix(String camelCasePrefix) { | 401 | + private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) { |
373 | 402 | ||
403 | + String prefix = getPrefixForIdentifier(conflictResolver); | ||
374 | if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) { | 404 | if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) { |
375 | - camelCasePrefix = YANG_AUTO_PREFIX + camelCasePrefix; | 405 | + camelCasePrefix = prefix + camelCasePrefix; |
376 | } | 406 | } |
377 | - if (JAVA_KEY_WORDS.contains(camelCasePrefix.toLowerCase())) { | 407 | + if (JAVA_KEY_WORDS.contains(camelCasePrefix)) { |
378 | - camelCasePrefix = YANG_AUTO_PREFIX + camelCasePrefix.substring(0, 1).toUpperCase() | 408 | + camelCasePrefix = prefix + camelCasePrefix.substring(0, 1).toUpperCase() |
379 | + camelCasePrefix.substring(1); | 409 | + camelCasePrefix.substring(1); |
380 | } | 410 | } |
381 | return camelCasePrefix; | 411 | return camelCasePrefix; |
... | @@ -444,13 +474,21 @@ public final class JavaIdentifierSyntax { | ... | @@ -444,13 +474,21 @@ public final class JavaIdentifierSyntax { |
444 | */ | 474 | */ |
445 | public static String getEnumJavaAttribute(String name) { | 475 | public static String getEnumJavaAttribute(String name) { |
446 | 476 | ||
447 | - String[] strArray = name.split(HYPHEN); | 477 | + name = name.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN); |
478 | + String[] strArray = name.split(COLAN); | ||
448 | String output = EMPTY_STRING; | 479 | String output = EMPTY_STRING; |
480 | + if (strArray[0].isEmpty()) { | ||
481 | + List<String> stringArrangement = new ArrayList<String>(); | ||
482 | + for (int i = 1; i < strArray.length; i++) { | ||
483 | + stringArrangement.add(strArray[i]); | ||
484 | + } | ||
485 | + strArray = stringArrangement.toArray(new String[stringArrangement.size()]); | ||
486 | + } | ||
449 | for (int i = 0; i < strArray.length; i++) { | 487 | for (int i = 0; i < strArray.length; i++) { |
450 | - output = output + strArray[i]; | 488 | + if (i > 0 && i < strArray.length) { |
451 | - if (i > 0 && i < strArray.length - 1) { | ||
452 | output = output + UNDER_SCORE; | 489 | output = output + UNDER_SCORE; |
453 | } | 490 | } |
491 | + output = output + strArray[i]; | ||
454 | } | 492 | } |
455 | return output; | 493 | return output; |
456 | } | 494 | } | ... | ... |
... | @@ -37,6 +37,11 @@ public final class YangToJavaNamingConflictUtil { | ... | @@ -37,6 +37,11 @@ public final class YangToJavaNamingConflictUtil { |
37 | private static String replacementForHyphenInIdentifier; | 37 | private static String replacementForHyphenInIdentifier; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | + * Contains the prefix value for adding with the identifier. | ||
41 | + */ | ||
42 | + private static String prefixForIdentifier; | ||
43 | + | ||
44 | + /** | ||
40 | * Creates an object for YANG to java naming conflict util. | 45 | * Creates an object for YANG to java naming conflict util. |
41 | */ | 46 | */ |
42 | public YangToJavaNamingConflictUtil() { | 47 | public YangToJavaNamingConflictUtil() { |
... | @@ -95,4 +100,22 @@ public final class YangToJavaNamingConflictUtil { | ... | @@ -95,4 +100,22 @@ public final class YangToJavaNamingConflictUtil { |
95 | public String getReplacementForUnderscore() { | 100 | public String getReplacementForUnderscore() { |
96 | return replacementForUnderscoreInIdentifier; | 101 | return replacementForUnderscoreInIdentifier; |
97 | } | 102 | } |
103 | + | ||
104 | + /** | ||
105 | + * Sets the prefix value for adding with the identifier. | ||
106 | + * | ||
107 | + * @param prefix prefix for identifier | ||
108 | + */ | ||
109 | + public void setPrefixForIdentifier(String prefix) { | ||
110 | + prefixForIdentifier = prefix; | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
114 | + * Returns the prefix for identifier. | ||
115 | + * | ||
116 | + * @return prefix for identifier | ||
117 | + */ | ||
118 | + public String getPrefixForIdentifier() { | ||
119 | + return prefixForIdentifier; | ||
120 | + } | ||
98 | } | 121 | } | ... | ... |
... | @@ -99,11 +99,11 @@ public final class RestrictionResolver { | ... | @@ -99,11 +99,11 @@ public final class RestrictionResolver { |
99 | } | 99 | } |
100 | 100 | ||
101 | if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { | 101 | if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { |
102 | - startInterval = rangeBoundary[0]; | 102 | + startInterval = rangeBoundary[0].trim(); |
103 | - endInterval = rangeBoundary[0]; | 103 | + endInterval = rangeBoundary[0].trim(); |
104 | } else { | 104 | } else { |
105 | - startInterval = rangeBoundary[0]; | 105 | + startInterval = rangeBoundary[0].trim(); |
106 | - endInterval = rangeBoundary[1]; | 106 | + endInterval = rangeBoundary[1].trim(); |
107 | } | 107 | } |
108 | 108 | ||
109 | try { | 109 | try { |
... | @@ -186,11 +186,11 @@ public final class RestrictionResolver { | ... | @@ -186,11 +186,11 @@ public final class RestrictionResolver { |
186 | } | 186 | } |
187 | 187 | ||
188 | if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { | 188 | if (rangeBoundary.length == MIN_RANGE_BOUNDARY) { |
189 | - startInterval = rangeBoundary[0]; | 189 | + startInterval = rangeBoundary[0].trim(); |
190 | - endInterval = rangeBoundary[0]; | 190 | + endInterval = rangeBoundary[0].trim(); |
191 | } else { | 191 | } else { |
192 | - startInterval = rangeBoundary[0]; | 192 | + startInterval = rangeBoundary[0].trim(); |
193 | - endInterval = rangeBoundary[1]; | 193 | + endInterval = rangeBoundary[1].trim(); |
194 | } | 194 | } |
195 | 195 | ||
196 | try { | 196 | try { | ... | ... |
... | @@ -767,6 +767,11 @@ public final class UtilConstants { | ... | @@ -767,6 +767,11 @@ public final class UtilConstants { |
767 | public static final String REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES = "[A-Z][0-9a-z]+"; | 767 | public static final String REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES = "[A-Z][0-9a-z]+"; |
768 | 768 | ||
769 | /** | 769 | /** |
770 | + * Static attribute for regex for any string ending with service. | ||
771 | + */ | ||
772 | + public static final String REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE = ".+Service"; | ||
773 | + | ||
774 | + /** | ||
770 | * Static attribute for class syntax. | 775 | * Static attribute for class syntax. |
771 | */ | 776 | */ |
772 | public static final String CLASS = "class"; | 777 | public static final String CLASS = "class"; | ... | ... |
... | @@ -25,8 +25,8 @@ import YangLexer; | ... | @@ -25,8 +25,8 @@ import YangLexer; |
25 | package org.onosproject.yangutils.parser.antlrgencode; | 25 | package org.onosproject.yangutils.parser.antlrgencode; |
26 | } | 26 | } |
27 | 27 | ||
28 | - yangfile : moduleStatement | 28 | + yangfile : moduleStatement EOF |
29 | - | subModuleStatement; | 29 | + | subModuleStatement EOF; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * module-stmt = optsep module-keyword sep identifier-arg-str | 32 | * module-stmt = optsep module-keyword sep identifier-arg-str | ... | ... |
... | @@ -52,4 +52,34 @@ public class TreeWalkListenerTest { | ... | @@ -52,4 +52,34 @@ public class TreeWalkListenerTest { |
52 | thrown.expectMessage("YANG file error : \"anyxml\" is not supported."); | 52 | thrown.expectMessage("YANG file error : \"anyxml\" is not supported."); |
53 | manager.getDataModel("src/test/resources/AnyxmlStatement.yang"); | 53 | manager.getDataModel("src/test/resources/AnyxmlStatement.yang"); |
54 | } | 54 | } |
55 | + | ||
56 | + /** | ||
57 | + * Checks whether exception is thrown when extra brace is added in the EOF. | ||
58 | + */ | ||
59 | + @Test | ||
60 | + public void processFileWithExtraBrace() throws IOException, ParserException { | ||
61 | + thrown.expect(ParserException.class); | ||
62 | + thrown.expectMessage("mismatched input '}' expecting <EOF>"); | ||
63 | + manager.getDataModel("src/test/resources/ProcessFileWithExtraBrace.yang"); | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * Checks whether exception is thrown when leaf is given after module ends. | ||
68 | + */ | ||
69 | + @Test | ||
70 | + public void processFileWithExtraLeaf() throws IOException, ParserException { | ||
71 | + thrown.expect(ParserException.class); | ||
72 | + thrown.expectMessage("mismatched input 'leaf' expecting <EOF>"); | ||
73 | + manager.getDataModel("src/test/resources/ProcessFileWithExtraLeaf.yang"); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Checks whether exception is thrown when extra brace is added in between the EOF. | ||
78 | + */ | ||
79 | + @Test | ||
80 | + public void processFileWithExtraBraceInBetween() throws IOException, ParserException { | ||
81 | + thrown.expect(ParserException.class); | ||
82 | + thrown.expectMessage("mismatched input 'container' expecting <EOF>"); | ||
83 | + manager.getDataModel("src/test/resources/ProcessFileWithExtraBraceInBetween.yang"); | ||
84 | + } | ||
55 | } | 85 | } | ... | ... |
... | @@ -267,4 +267,36 @@ public class LengthRestrictionListenerTest { | ... | @@ -267,4 +267,36 @@ public class LengthRestrictionListenerTest { |
267 | assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0))); | 267 | assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0))); |
268 | assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100))); | 268 | assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100))); |
269 | } | 269 | } |
270 | + | ||
271 | + /** | ||
272 | + * Checks whether space can be allowed when length statement is present. | ||
273 | + */ | ||
274 | + @Test | ||
275 | + public void processLengthStatementWithSpace() throws IOException, ParserException { | ||
276 | + | ||
277 | + YangNode node = manager.getDataModel("src/test/resources/LengthStatementWithSpace.yang"); | ||
278 | + | ||
279 | + assertThat((node instanceof YangModule), is(true)); | ||
280 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
281 | + YangModule yangNode = (YangModule) node; | ||
282 | + assertThat(yangNode.getName(), is("Test")); | ||
283 | + | ||
284 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
285 | + YangLeaf leafInfo = leafIterator.next(); | ||
286 | + | ||
287 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
288 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); | ||
289 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); | ||
290 | + YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo | ||
291 | + .getDataType().getDataTypeExtendedInfo(); | ||
292 | + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction(); | ||
293 | + | ||
294 | + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals() | ||
295 | + .listIterator(); | ||
296 | + | ||
297 | + YangRangeInterval rangeInterval = lengthListIterator.next(); | ||
298 | + | ||
299 | + assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0))); | ||
300 | + assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100))); | ||
301 | + } | ||
270 | } | 302 | } | ... | ... |
... | @@ -207,4 +207,33 @@ public class RangeRestrictionListenerTest { | ... | @@ -207,4 +207,33 @@ public class RangeRestrictionListenerTest { |
207 | assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); | 207 | assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); |
208 | assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); | 208 | assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); |
209 | } | 209 | } |
210 | + | ||
211 | + /** | ||
212 | + * Checks whether space can be allowed when range statement is present. | ||
213 | + */ | ||
214 | + @Test | ||
215 | + public void processRangeStatementWithSpace() throws IOException, ParserException { | ||
216 | + | ||
217 | + YangNode node = manager.getDataModel("src/test/resources/RangeStatementWithSpace.yang"); | ||
218 | + | ||
219 | + assertThat((node instanceof YangModule), is(true)); | ||
220 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
221 | + YangModule yangNode = (YangModule) node; | ||
222 | + assertThat(yangNode.getName(), is("Test")); | ||
223 | + | ||
224 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
225 | + YangLeaf leafInfo = leafIterator.next(); | ||
226 | + | ||
227 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
228 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("int32")); | ||
229 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32)); | ||
230 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) leafInfo | ||
231 | + .getDataType().getDataTypeExtendedInfo(); | ||
232 | + | ||
233 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
234 | + .listIterator(); | ||
235 | + YangRangeInterval rangeInterval = rangeListIterator.next(); | ||
236 | + assertThat(((YangInt32) rangeInterval.getStartValue()).getValue(), is(1)); | ||
237 | + assertThat(((YangInt32) rangeInterval.getEndValue()).getValue(), is(4)); | ||
238 | + } | ||
210 | } | 239 | } | ... | ... |
... | @@ -59,6 +59,7 @@ public class AttributesJavaDataTypeTest { | ... | @@ -59,6 +59,7 @@ public class AttributesJavaDataTypeTest { |
59 | 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"; | 60 | private static final String TYPE_DEF_PKG = "target.test"; |
61 | private static String test = ""; | 61 | private static String test = ""; |
62 | + private static YangToJavaNamingConflictUtil pluginConfig = null; | ||
62 | 63 | ||
63 | /** | 64 | /** |
64 | * Unit test for private constructor. | 65 | * Unit test for private constructor. |
... | @@ -88,7 +89,6 @@ public class AttributesJavaDataTypeTest { | ... | @@ -88,7 +89,6 @@ public class AttributesJavaDataTypeTest { |
88 | */ | 89 | */ |
89 | @Test | 90 | @Test |
90 | public void testgetJavaClassInfo() { | 91 | public void testgetJavaClassInfo() { |
91 | - YangToJavaNamingConflictUtil pluginConfig = null; | ||
92 | test = getJavaImportClass(getStubYangType(TYPE1), false, pluginConfig); | 92 | test = getJavaImportClass(getStubYangType(TYPE1), false, pluginConfig); |
93 | assertThat(true, is(test.equals(CLASS_INFO1))); | 93 | assertThat(true, is(test.equals(CLASS_INFO1))); |
94 | 94 | ||
... | @@ -125,16 +125,16 @@ public class AttributesJavaDataTypeTest { | ... | @@ -125,16 +125,16 @@ public class AttributesJavaDataTypeTest { |
125 | */ | 125 | */ |
126 | @Test | 126 | @Test |
127 | public void testgetJavaPkgInfo() { | 127 | public void testgetJavaPkgInfo() { |
128 | - test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1); | 128 | + test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1, pluginConfig); |
129 | assertThat(true, is(test.equals(JAVA_LANG))); | 129 | assertThat(true, is(test.equals(JAVA_LANG))); |
130 | 130 | ||
131 | - test = getJavaImportPackage(getStubYangType(TYPE2), true, CLASS_INFO5); | 131 | + test = getJavaImportPackage(getStubYangType(TYPE2), true, CLASS_INFO5, pluginConfig); |
132 | assertThat(true, is(test.equals(JAVA_LANG))); | 132 | assertThat(true, is(test.equals(JAVA_LANG))); |
133 | 133 | ||
134 | - test = getJavaImportPackage(getStubYangType(TYPE3), false, CLASS_INFO3); | 134 | + test = getJavaImportPackage(getStubYangType(TYPE3), false, CLASS_INFO3, pluginConfig); |
135 | assertThat(null, is(test)); | 135 | assertThat(null, is(test)); |
136 | 136 | ||
137 | - test = getJavaImportPackage(getStubYangType(TYPE4), false, CLASS_INFO4); | 137 | + test = getJavaImportPackage(getStubYangType(TYPE4), false, CLASS_INFO4, pluginConfig); |
138 | assertThat(null, is(test)); | 138 | assertThat(null, is(test)); |
139 | } | 139 | } |
140 | 140 | ||
... | @@ -145,7 +145,7 @@ public class AttributesJavaDataTypeTest { | ... | @@ -145,7 +145,7 @@ public class AttributesJavaDataTypeTest { |
145 | */ | 145 | */ |
146 | @Test | 146 | @Test |
147 | public void testForTypeDef() throws DataModelException { | 147 | public void testForTypeDef() throws DataModelException { |
148 | - test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, TYPE_DEF_PKG); | 148 | + test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, TYPE_DEF_PKG, pluginConfig); |
149 | assertThat(true, is(test.equals(TYPE_DEF_PKG))); | 149 | assertThat(true, is(test.equals(TYPE_DEF_PKG))); |
150 | } | 150 | } |
151 | 151 | ... | ... |
This diff is collapsed. Click to expand it.
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + import ietf-yang-types { | ||
6 | + prefix "P"; | ||
7 | + } | ||
8 | + grouping Percentage { | ||
9 | + leaf hello{ | ||
10 | + type string; | ||
11 | + } | ||
12 | + leaf invalid1{ | ||
13 | + type string; | ||
14 | + } | ||
15 | + } | ||
16 | + leaf invalid2{ | ||
17 | + type string; | ||
18 | + } | ||
19 | + } | ||
20 | + container ospf { | ||
21 | + list valid { | ||
22 | + key "invalid"; | ||
23 | + leaf invalid{ | ||
24 | + type string; | ||
25 | + } | ||
26 | + uses Ant:FirstClass; | ||
27 | + grouping FirstClass { | ||
28 | + uses P:PassingClass; | ||
29 | + } | ||
30 | + } | ||
31 | + grouping PassingClass { | ||
32 | + uses Ant:Percentage; | ||
33 | + } | ||
34 | + } | ||
35 | +} |
-
Please register or login to post a comment