yang choice case translator + whitebox fix
Change-Id: I96f1855bc71a002335946150b51e911ae6ac2fb2
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/ResolutionType.java b/src/main/java/org/onosproject/yangutils/datamodel/ResolutionType.java
index aa0abbb..e69492a 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/ResolutionType.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/ResolutionType.java
@@ -28,5 +28,5 @@
/**
* Identifies that resolution is for grouping.
*/
- GROUPING_RESOLUTION;
+ GROUPING_RESOLUTION
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java b/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
index 48f5d17..e61d273 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
@@ -286,7 +286,7 @@
*/
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.CASE_DATA;
+ return CASE_DATA;
}
/**
@@ -311,7 +311,7 @@
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType) throws DataModelException {
- if (getParent() == null || !(getParent() instanceof YangChoice)) {
+ if (!(getParent() instanceof YangChoice)) {
throw new DataModelException("Internal Data Model Tree Error: Invalid/Missing holder in case " +
getName());
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java b/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
index 43a486f..f05a11c 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
@@ -277,11 +277,11 @@
/**
* Returns the type of the data.
*
- * @return returns CHOICE_DATA
+ * @return choice data
*/
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.CHOICE_DATA;
+ return CHOICE_DATA;
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java b/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
index 7e3d819..aa95899 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangEntityToResolveInfo.java
@@ -72,7 +72,7 @@
}
String prefix;
- T entityToResolve = (T) getEntityToResolve();
+ T entityToResolve = getEntityToResolve();
if (entityToResolve instanceof YangType) {
prefix = ((YangType<?>) entityToResolve).getPrefix();
} else if (entityToResolve instanceof YangUses) {
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangNodeIdentifier.java b/src/main/java/org/onosproject/yangutils/datamodel/YangNodeIdentifier.java
index 871b683..512b104 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangNodeIdentifier.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangNodeIdentifier.java
@@ -22,10 +22,10 @@
public class YangNodeIdentifier {
// Name of the node.
- String name;
+ private String name;
// Prefix of the node.
- String prefix;
+ private String prefix;
/**
* Creates an instance of YANG node identifier.
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java b/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
index 38b48bd..39c2cb5 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
@@ -118,7 +118,7 @@
if (getAscendingRangeIntervals() == null) {
throw new DataModelException("No range restriction info");
}
- if (getAscendingRangeIntervals().size() == 0) {
+ if (getAscendingRangeIntervals().isEmpty()) {
throw new DataModelException("No range interval info");
}
return getAscendingRangeIntervals().get(0).getStartValue();
@@ -134,7 +134,7 @@
if (getAscendingRangeIntervals() == null) {
throw new DataModelException("No range restriction info");
}
- if (getAscendingRangeIntervals().size() == 0) {
+ if (getAscendingRangeIntervals().isEmpty()) {
throw new DataModelException("No range interval info");
}
return getAscendingRangeIntervals()
@@ -184,7 +184,7 @@
public boolean isValidValueString(String valueInString) throws DataModelException {
if (getAscendingRangeIntervals() == null
- || getAscendingRangeIntervals().size() == 0) {
+ || getAscendingRangeIntervals().isEmpty()) {
// Throw exception, At least one default range needs to be set in constructor or in linker.
throw new DataModelException("Range interval missing in range restriction.");
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java b/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
index 9f54254..1d7fb9a 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangResolutionInfo.java
@@ -450,8 +450,6 @@
}
curNode = curNode.getNextSibling();
}
-
- return;
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
index 5b18fac..2a0c878 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -21,6 +21,7 @@
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
/*
* Reference:RFC 6020.
@@ -294,20 +295,18 @@
}
@Override
- public void resolve() {
+ public void resolve() throws DataModelException {
/*
Inherit the Restriction from the referred typedef definition.
*/
- if (getDataType() != YangDataTypes.DERIVED) {
- throw new RuntimeException("Resolve should only be called for derrived data types");
+ if (getDataType() != DERIVED) {
+ throw new DataModelException("Resolve should only be called for derived data types");
}
YangDerivedInfo<?> derrivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
YangType<?> baseType = derrivedInfo.getReferredTypeDef().getTypeDefBaseType();
- if (YangDataTypes.DERIVED == baseType.getDataType()) {
- if (baseType.getResolvableStatus() == INTRA_FILE_RESOLVED) {
+ if (DERIVED == baseType.getDataType() && baseType.getResolvableStatus() == INTRA_FILE_RESOLVED) {
setResolvableStatus(INTRA_FILE_RESOLVED);
- }
}
//TODO:
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
index 57eea99..68a1b36 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
@@ -224,6 +224,5 @@
*/
private static void validateForChildNodes() {
//TODO: implement with linker.
- return;
}
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
index 7b41b77..f08fe6f 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
@@ -80,8 +80,8 @@
checkStackIsNotEmpty(listener, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
// Data Model tree root node is set.
- if ((listener.getParsedDataStack().peek() instanceof YangModule)
- || (listener.getParsedDataStack().peek() instanceof YangSubModule)) {
+ if (listener.getParsedDataStack().peek() instanceof YangModule
+ || listener.getParsedDataStack().peek() instanceof YangSubModule) {
listener.setRootNode((YangNode) listener.getParsedDataStack().pop());
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, YANGBASE_DATA, "", EXIT));
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
index ddd08f3..16523c9 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
@@ -137,7 +137,7 @@
switch (tmpNode.getYangConstructType()) {
case BITS_DATA: {
YangBits yangBits = (YangBits) tmpNode;
- if ((ctx.bitBodyStatement() == null) || (ctx.bitBodyStatement().positionStatement() == null)) {
+ if (ctx.bitBodyStatement() == null || ctx.bitBodyStatement().positionStatement() == null) {
int maxPosition = 0;
boolean isPositionPresent = false;
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
index 103a7ee..ad2988d 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
@@ -131,7 +131,7 @@
switch (tmpNode.getYangConstructType()) {
case ENUMERATION_DATA: {
YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
- if ((ctx.enumStatementBody() == null) || (ctx.enumStatementBody().valueStatement() == null)) {
+ if (ctx.enumStatementBody() == null || ctx.enumStatementBody().valueStatement() == null) {
int maxValue = 0;
boolean isValuePresent = false;
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
index 51a29d5..e3cd47f 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
@@ -73,6 +73,8 @@
private static final String PIPE = "|";
private static final String LENGTH_INTERVAL = "..";
+ private static final int MAX_RANGE_BOUNDARY = 2;
+ private static final int MIN_RANGE_BOUNDARY = 1;
/**
* Creates a new length restriction listener.
@@ -114,7 +116,8 @@
GeneratedYangParser.LengthStatementContext ctx) {
YangStringRestriction stringRestriction;
- YangBuiltInDataTypeInfo<?> startValue, endValue;
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
YangRangeRestriction lengthRestriction = new YangRangeRestriction<>();
if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) {
@@ -148,11 +151,12 @@
String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
for (String rangePart : rangeArguments) {
- String startInterval, endInterval;
+ String startInterval;
+ String endInterval;
YangRangeInterval rangeInterval = new YangRangeInterval<>();
String[] rangeBoundary = rangePart.trim().split(Pattern.quote(LENGTH_INTERVAL));
- if (rangeBoundary.length > 2) {
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
" is not valid.");
@@ -161,7 +165,7 @@
throw parserException;
}
- if (rangeBoundary.length == 1) {
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
startInterval = rangeBoundary[0];
endInterval = rangeBoundary[0];
} else {
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
index 46bc67a..e4e5485 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
@@ -70,6 +70,8 @@
private static final String PIPE = "|";
private static final String RANGE_INTERVAL = "..";
+ private static final int MAX_RANGE_BOUNDARY = 2;
+ private static final int MIN_RANGE_BOUNDARY = 1;
/**
* Creates a new range restriction listener.
@@ -110,18 +112,20 @@
private static void setRangeRestriction(YangType type,
GeneratedYangParser.RangeStatementContext ctx) {
- YangBuiltInDataTypeInfo<?> startValue, endValue;
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
YangRangeRestriction rangeRestriction = new YangRangeRestriction();
String rangeArgument = removeQuotesAndHandleConcat(ctx.range().getText());
String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
for (String rangePart : rangeArguments) {
- String startInterval, endInterval;
+ String startInterval;
+ String endInterval;
YangRangeInterval rangeInterval = new YangRangeInterval();
String[] rangeBoundary = rangePart.trim().split(Pattern.quote(RANGE_INTERVAL));
- if (rangeBoundary.length > 2) {
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
" is not valid.");
@@ -130,7 +134,7 @@
throw parserException;
}
- if (rangeBoundary.length == 1) {
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
startInterval = rangeBoundary[0];
endInterval = rangeBoundary[0];
} else {
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
index a2b4531..e93001e 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
@@ -31,7 +31,6 @@
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
@@ -89,7 +88,7 @@
checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY);
// Validate node identifier.
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), YangConstructType.TYPE_DATA,
+ YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), TYPE_DATA,
ctx);
// Obtain the YANG data type.
@@ -107,7 +106,7 @@
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
YangLeaf leaf = (YangLeaf) tmpData;
- leaf.setDataType((YangType<?>) type);
+ leaf.setDataType(type);
/*
* If data type is derived, resolution information to be added
@@ -139,7 +138,7 @@
break;
case LEAF_LIST_DATA:
YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setDataType((YangType<?>) type);
+ leafList.setDataType(type);
/*
* If data type is derived, resolution information to be added
@@ -157,9 +156,6 @@
ctx.string().getText(), EXIT));
}
- // Get the prefix information
- String prefix = ((YangType<?>) type).getPrefix();
-
// Create empty derived info and attach it to type extended info.
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
@@ -174,7 +170,7 @@
case UNION_DATA:
YangUnion unionNode = (YangUnion) tmpData;
try {
- unionNode.addType((YangType<?>) type);
+ unionNode.addType(type);
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setLine(ctx.getStart().getLine());
@@ -188,16 +184,13 @@
*/
if (yangDataTypes == YangDataTypes.DERIVED) {
- // Get the prefix information
- String prefix = ((YangType<?>) type).getPrefix();
-
// Create empty derived info and attach it to type extended info.
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
// Add resolution information to the list
YangResolutionInfo resolutionInfo =
- new YangResolutionInfo<YangType>(type, (YangNode) unionNode, errorLine, errorPosition);
+ new YangResolutionInfo<YangType>(type, unionNode, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
@@ -205,24 +198,20 @@
case TYPEDEF_DATA:
/* Prepare the base type info and set in derived type */
YangTypeDef typeDef = (YangTypeDef) tmpData;
- typeDef.setDataType((YangType<?>) type);
+ typeDef.setDataType(type);
/*
* If data type is derived, resolution information to be added
* in resolution list.
*/
if (yangDataTypes == YangDataTypes.DERIVED) {
-
- // Get the prefix information
- String prefix = ((YangType<?>) type).getPrefix();
-
// Create empty derived info and attach it to type extended info.
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
// Add resolution information to the list
YangResolutionInfo resolutionInfo =
- new YangResolutionInfo<YangType>(type, (YangNode) typeDef, errorLine, errorPosition);
+ new YangResolutionInfo<YangType>(type, typeDef, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
break;
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnionListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnionListener.java
index 5a25762..1d2a698 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnionListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnionListener.java
@@ -51,7 +51,6 @@
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUnionNode;
@@ -214,7 +213,7 @@
curNode.addChild(unionNode);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- YangConstructType.UNION_DATA, "", ENTRY, e.getMessage()));
+ UNION_DATA, "", ENTRY, e.getMessage()));
}
}
}
diff --git a/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index 86203c6..5e7f587 100644
--- a/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -117,8 +117,6 @@
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
- private String searchDir;
- private String codeGenDir;
private YangNode rootNode;
@Override
@@ -132,12 +130,12 @@
clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
clean(getDirectory(baseDir, outputDirectory));
- searchDir = getDirectory(baseDir, yangFilesDir);
- codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
+ String searchDir = getDirectory(baseDir, yangFilesDir);
+ String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
conflictResolver.setReplacementForPeriod(replacementForPeriod);
conflictResolver.setReplacementForHyphen(replacementForHyphen);
- conflictResolver.setReplacementForUnderscore(replacementForHyphen);
+ conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
YangPluginConfig yangPlugin = new YangPluginConfig();
yangPlugin.setCodeGenDir(codeGenDir);
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index 7e010db..add5504 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -132,16 +132,14 @@
/**
* Free other YANG nodes of data-model tree when error occurs while file generation of current node.
- *
- * @throws DataModelException when fails to do datamodel operations
*/
- public static void freeRestResources() throws DataModelException {
+ public static void freeRestResources() {
YangNode curNode = getCurNode();
YangNode tempNode = curNode;
TraversalType curTraversal = ROOT;
- while (!(curNode == tempNode.getParent())) {
+ while (curNode != tempNode.getParent()) {
if (curTraversal != PARENT && curNode.getChild() != null) {
curTraversal = CHILD;
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index 7d8f4e0..723b937 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -162,6 +162,29 @@
}
/**
+ * Returns import for class.
+ *
+ * @return imports for class
+ */
+ public List<String> getImports() {
+ String importString;
+ List<String> imports = new ArrayList<>();
+
+ for (JavaQualifiedTypeInfo importInfo : getImportSet()) {
+ if (!importInfo.getPkgInfo().equals(EMPTY_STRING) && importInfo.getClassInfo() != null
+ && !importInfo.getPkgInfo().equals(JAVA_LANG)) {
+ importString = IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN
+ + NEW_LINE;
+
+ imports.add(importString);
+ }
+ }
+
+ sort(imports);
+ return imports;
+ }
+
+ /**
* Returns import for hash and equals method.
*
* @return import for hash and equals method
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
index 77170dc..9b0ccca 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
@@ -110,14 +110,14 @@
* Current leaves holder is adding a leaf info as a attribute to the
* current class.
*/
- String className = AttributesJavaDataType.getJavaImportClass(attrType, isListAttr);
+ String className = getJavaImportClass(attrType, isListAttr);
if (className != null) {
/*
* Corresponding to the attribute type a class needs to be imported,
* since it can be a derived type or a usage of wrapper classes.
*/
importInfo.setClassInfo(className);
- String classPkg = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr, className);
+ String classPkg = getJavaImportPackage(attrType, isListAttr, className);
if (classPkg == null) {
throw new TranslatorException("import package cannot be null when the class is used");
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index cc52daa..10d98c8 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -29,6 +29,7 @@
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
@@ -110,6 +111,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
@@ -393,6 +396,11 @@
private YangNode curYangNode;
/**
+ * Import info for case.
+ */
+ private JavaQualifiedTypeInfo caseImportInfo;
+
+ /**
* Current enum's value.
*/
private int enumValue;
@@ -1130,9 +1138,8 @@
* Adds build method for interface.
*
* @return build method for interface
- * @throws IOException when fails to append to temporary file
*/
- public String addBuildMethodForInterface() throws IOException {
+ public String addBuildMethodForInterface() {
return parseBuilderInterfaceBuildMethodString(generatedJavaClassName);
}
@@ -1140,9 +1147,8 @@
* Adds build method's implementation for class.
*
* @return build method implementation for class
- * @throws IOException when fails to append to temporary file
*/
- public String addBuildMethodImpl() throws IOException {
+ public String addBuildMethodImpl() {
return getBuildString(generatedJavaClassName) + NEW_LINE;
}
@@ -1162,9 +1168,8 @@
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
* @return default constructor for class
- * @throws IOException when fails to append to file
*/
- public String addDefaultConstructor(String modifier, String toAppend) throws IOException {
+ public String addDefaultConstructor(String modifier, String toAppend) {
return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier);
}
@@ -1172,9 +1177,8 @@
* Adds default constructor for class.
*
* @return default constructor for class
- * @throws IOException when fails to append to file
*/
- public String addOfMethod() throws IOException {
+ public String addOfMethod() {
return getJavaDoc(OF_METHOD, generatedJavaClassName, false)
+ getOfMethod(generatedJavaClassName, newAttrInfo);
}
@@ -1380,6 +1384,28 @@
}
/**
+ * Adds parent's info to current node import list.
+ *
+ * @param curNode current node for which import list needs to be updated
+ */
+ public void addParentInfoInCurNodeTempFile(YangNode curNode) {
+ caseImportInfo = new JavaQualifiedTypeInfo();
+ YangNode parent = getParentNodeInGenCode(curNode);
+ if (!(parent instanceof JavaCodeGenerator)) {
+ throw new TranslatorException("missing parent node to contain current node info in generated file");
+ }
+
+ if (!(curNode instanceof HasJavaFileInfo)) {
+ throw new TranslatorException("missing java file information to get the package details "
+ + "of attribute corresponding to child node");
+ }
+
+ caseImportInfo.setClassInfo(getCaptialCase(getCamelCase(parent.getName(), null)));
+ caseImportInfo.setPkgInfo(((HasJavaFileInfo) parent).getJavaFileInfo().getPackage());
+ ((HasJavaImportData) curNode).getJavaImportData().addImportInfo(curNode, caseImportInfo);
+ }
+
+ /**
* Adds leaf attributes in generated files.
*
* @param listOfLeaves list of YANG leaf
@@ -1415,7 +1441,7 @@
* Check if the attribute is of type list, then the java.lang.list
* needs to be imported.
*/
- if (listOfLeafList.size() != 0) {
+ if (!listOfLeafList.isEmpty()) {
if (!(curNode instanceof HasJavaImportData)) {
throw new TranslatorException("missing import info in current data model node");
@@ -1651,6 +1677,18 @@
if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) {
/**
+ * Adds import for case.
+ */
+ if (curNode instanceof YangCase) {
+ List<String> importData = ((HasJavaImportData) curNode).getJavaImportData().getImports();
+ for (String importInfo : importData) {
+ if (!imports.contains(importInfo)) {
+ imports.add(importInfo);
+ }
+ }
+ }
+
+ /**
* Adds import for HasAugmentation class.
*/
if (isHasAugmentationExtended(getExtendsList())) {
@@ -1689,6 +1727,10 @@
if (isAugmentedInfoExtended(getExtendsList())) {
addAugmentedInfoImport(curNode, imports, false);
}
+
+ if (curNode instanceof YangCase) {
+ removeCaseImport(imports);
+ }
}
if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) {
@@ -1763,6 +1805,21 @@
}
/**
+ * Removes case import info from import list.
+ *
+ * @param imports list of imports
+ * @return import for class
+ */
+ private List<String> removeCaseImport(List<String> imports) {
+ if (imports != null && caseImportInfo != null) {
+ String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() +
+ SEMI_COLAN + NEW_LINE;
+ imports.remove(caseImport);
+ }
+ return imports;
+ }
+
+ /**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we need to close
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
index 26727bd..8729f17 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
@@ -139,8 +139,7 @@
* Creates a java file using the YANG case info.
*/
@Override
- public void generateCodeExit() {
- // TODO Auto-generated method stub
-
+ public void generateCodeExit() throws IOException {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
index d5a00d5..0299e6c 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
@@ -24,7 +24,7 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
@@ -56,7 +56,7 @@
super();
setJavaFileInfo(new JavaFileInfo());
setJavaImportData(new JavaImportData());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
+ getJavaFileInfo().setGeneratedFileTypes(INTERFACE_MASK);
}
/**
@@ -133,15 +133,13 @@
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
generateCodeOfNode(this, yangPlugin, false);
- // TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
}
/**
* Creates a java file using the YANG choice info.
*/
@Override
- public void generateCodeExit() {
- // TODO Auto-generated method stub
-
+ public void generateCodeExit() throws IOException {
+ getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this);
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index ec58b26..9fa13d4 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -109,7 +109,7 @@
}
String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
for (String extend : getExtendsList()) {
- def = def + extend + COMMA;
+ def = def + extend + COMMA + SPACE;
}
def = trimAtLast(def, COMMA);
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 03be712..99ab915 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -373,7 +373,7 @@
private static String getReturnType(JavaAttributeInfo attr) {
String returnType = EMPTY_STRING;
- if (attr.isQualifiedName() && (attr.getImportInfo().getPkgInfo() != null)) {
+ if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
}
returnType = returnType + attr.getImportInfo().getClassInfo();
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
index ccb8370..a82d7d4 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
@@ -141,7 +141,7 @@
*/
public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) {
- if (!extendsList.isEmpty() && !extendsList.equals(null)) {
+ if (extendsList != null && !extendsList.isEmpty()) {
JavaFileGenerator.setExtendsList(extendsList);
JavaFileGenerator.setIsExtendsList(true);
} else {
@@ -157,10 +157,7 @@
* @return true or false
*/
public static boolean isHasAugmentationExtended(List<String> extendsList) {
- if (extendsList != null && extendsList.contains(HAS_AUGMENTATION)) {
- return true;
- }
- return false;
+ return (extendsList != null && extendsList.contains(HAS_AUGMENTATION));
}
/**
@@ -170,10 +167,7 @@
* @return true or false
*/
public static boolean isAugmentedInfoExtended(List<String> extendsList) {
- if (extendsList != null && extendsList.contains(AUGMENTED_INFO)) {
- return true;
- }
- return false;
+ return (extendsList != null && extendsList.contains(AUGMENTED_INFO));
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
index cd6a7cd..4f3cb45 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
@@ -39,6 +39,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
@@ -159,8 +160,10 @@
updatePackageInfo((HasJavaFileInfo) javaCodeGeneratorInfo, yangPlugin);
generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
+ if (!(javaCodeGeneratorInfo instanceof YangCase)) {
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
+ .addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
+ }
/**
* For augmentation of nodes.
@@ -176,6 +179,21 @@
} else if (javaCodeGeneratorInfo instanceof YangAugment) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO);
}
+
+ if (javaCodeGeneratorInfo instanceof YangCase) {
+ YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
+ String curNodeName = ((YangCase) javaCodeGeneratorInfo).getName();
+ if (!parent.getName().equals(curNodeName)) {
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(getCaptialCase(getCamelCase(
+ parent.getName(), null)));
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addParentInfoInCurNodeTempFile((YangNode)
+ javaCodeGeneratorInfo);
+ } else {
+ String parentPackage = ((HasJavaFileInfo) parent).getJavaFileInfo().getPackage();
+ String caseExtendInfo = parentPackage + PERIOD + parent.getName();
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(caseExtendInfo);
+ }
+ }
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java
index 49be81c..f827698 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangPluginConfig.java
@@ -22,12 +22,6 @@
public final class YangPluginConfig {
/**
- * Creates an object for YANG plugin config.
- */
- public YangPluginConfig() {
- }
-
- /**
* Contains the code generation directory.
*/
private String codeGenDir;
@@ -38,6 +32,12 @@
private YangToJavaNamingConflictUtil conflictResolver;
/**
+ * Creates an object for YANG plugin config.
+ */
+ public YangPluginConfig() {
+ }
+
+ /**
* Sets the path of the java code where it has to be generated.
*
* @param codeGenDir path of the directory
diff --git a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index def4cc9..eeee061 100644
--- a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -26,12 +26,6 @@
public final class UtilConstants {
/**
- * Creates an instance of util constants.
- */
- private UtilConstants() {
- }
-
- /**
* JavaDocs for impl class.
*/
public static final String IMPL_CLASS_JAVA_DOC = " * Represents the implementation of ";
@@ -841,4 +835,10 @@
* Static attribute for array list.
*/
public static final String ARRAY_LIST = "ArrayList";
+
+ /**
+ * Creates an instance of util constants.
+ */
+ private UtilConstants() {
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
index ffc36f7..c259a7f 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
@@ -55,10 +55,7 @@
public static boolean doesPackageExist(String pkg) {
File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
- if (pkgDir.exists() && pkgWithFile.isFile()) {
- return true;
- }
- return false;
+ return (pkgDir.exists() && pkgWithFile.isFile());
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index c793cd6..e2fe7fd 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -376,10 +376,10 @@
* @return javaDocs
*/
private static String generateForTypeDefSetter(String attribute) {
- return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute
- + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
+ + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
@@ -491,10 +491,9 @@
* @return javaDocs for type constructor
*/
private static String generateForTypeConstructor(String attribute) {
-
- return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
- + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
+ + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index baf6929..51ca81c 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -223,7 +223,7 @@
for (File file : files) {
Files.copy(file.toPath(),
- (new File(path + file.getName())).toPath(),
+ new File(path + file.getName()).toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
Resource rsc = new Resource();
diff --git a/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java b/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
index 52fb4ff..956867d 100644
--- a/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
+++ b/src/test/java/org/onosproject/yangutils/linker/IntraFileTypeLinkingTest.java
@@ -53,7 +53,7 @@
YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang");
// Check whether the data model tree returned is of type module.
- assertThat((node instanceof YangModule), is(true));
+ assertThat(node instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
@@ -72,7 +72,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -111,7 +111,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -151,7 +151,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild().getNextSibling()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -191,7 +191,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -228,21 +228,21 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -280,21 +280,21 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
}
@@ -331,21 +331,21 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangContainer.getChild().getNextSibling()));
- assertThat((typeDef1.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
@@ -383,7 +383,7 @@
assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) yangList.getChild()));
- assertThat((leafInfo.getDataType().getResolvableStatus()),
+ assertThat(leafInfo.getDataType().getResolvableStatus(),
is(ResolvableStatus.INTRA_FILE_RESOLVED));
YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
@@ -392,7 +392,7 @@
assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
is((YangTypeDef) node.getChild()));
- assertThat((typeDef2.getTypeDefBaseType().getResolvableStatus()),
+ assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
}
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java b/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
index e8cfa92..44d0c67 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/CustomExceptionMatcher.java
@@ -27,22 +27,22 @@
*/
public final class CustomExceptionMatcher extends TypeSafeMatcher<ParserException> {
+ private int actualLine;
+ private final int expectedLine;
+ private int actualCharPosition;
+ private final int expectedCharPosition;
+
/**
* Customized exception matcher to match error location.
*
* @param line error line
* @param charPosition error character position
- * @return
+ * @return customized exception matcher to match error location
*/
public static CustomExceptionMatcher errorLocation(int line, int charPosition) {
return new CustomExceptionMatcher(line, charPosition);
}
- private int actualLine;
- private final int expectedLine;
- private int actualCharPosition;
- private final int expectedCharPosition;
-
private CustomExceptionMatcher(int expectedLine, int expectedCharPosition) {
this.expectedLine = expectedLine;
this.expectedCharPosition = expectedCharPosition;
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
index 79c8488..bb59e65 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
@@ -54,9 +54,6 @@
assertThat(yangNode.getName(), is("Test"));
YangAugment yangAugment = (YangAugment) yangNode.getChild();
- if (yangAugment.getTargetNode().isEmpty()) {
- System.out.println("list is empty");
- }
ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator();
YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next();
assertThat(yangNodeIdentifier.getPrefix(), is("if"));
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
new file mode 100644
index 0000000..9f67ed0
--- /dev/null
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.translator.tojava.utils;
+
+import java.io.IOException;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+
+import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
+
+/**
+ * Unit tests for choice-case translator.
+ */
+public final class ChoiceCaseTranslatorTest {
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks choice-case translation should not result in any exception.
+ */
+ @Test
+ public void processChoiceCaseTranslator() throws IOException, ParserException {
+
+ String userDir = System.getProperty("user.dir");
+ YangNode node = manager.getDataModel("src/test/resources/ChoiceCaseTranslator.yang");
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
+
+ generateJavaCode(node, yangPluginConfig);
+
+ clean(userDir + "/target/ChoiceCaseTestGenFile/");
+ }
+ // TODO enhance the test cases, after having a framework of translator test.
+}
\ No newline at end of file
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
index 97302d8..8359ef3 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
@@ -28,21 +28,18 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.slf4j.Logger;
import static org.apache.commons.io.FileUtils.contentEquals;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Unit Tests for the CopyrightHeader contents.
*/
public final class CopyrightHeaderTest {
- private final Logger log = getLogger(getClass());
private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR)
+ "-present Open Networking Laboratory\n";
@Rule
diff --git a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
index 0057b56..d3137b3 100644
--- a/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
+++ b/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
@@ -26,14 +26,12 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.slf4j.Logger;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getJavaFiles;
import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles;
-import static org.slf4j.LoggerFactory.getLogger;
import static java.io.File.separator;
@@ -42,8 +40,6 @@
*/
public final class YangFileScannerTest {
- private final Logger log = getLogger(getClass());
-
@Rule
public ExpectedException thrown = ExpectedException.none();
diff --git a/src/test/resources/ChoiceCaseTranslator.yang b/src/test/resources/ChoiceCaseTranslator.yang
new file mode 100644
index 0000000..e8127ea
--- /dev/null
+++ b/src/test/resources/ChoiceCaseTranslator.yang
@@ -0,0 +1,22 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container food {
+ choice snack {
+ case sports-arena {
+ leaf pretzel {
+ type string;
+ }
+ leaf beer {
+ type string;
+ }
+ }
+ case late-night {
+ leaf chocolate {
+ type string;
+ }
+ }
+ }
+ }
+}