YANG translator error handler framework and UT fixes.
Change-Id: Icb4d65540ed7ea8d6ecbd8458d44d7d86df969fa
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
index 4e488bb..8ac2514 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/utils/YangDataModelFactory.java
@@ -43,6 +43,7 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
/**
* Factory to create data model objects based on the target file type.
@@ -68,7 +69,7 @@
return new YangJavaModule();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -86,7 +87,7 @@
return new YangJavaAugment();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -104,7 +105,7 @@
return new YangJavaCase();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -122,7 +123,7 @@
return new YangJavaChoice();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -140,7 +141,7 @@
return new YangJavaContainer();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -158,7 +159,7 @@
return new YangJavaGrouping();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -176,7 +177,7 @@
return new YangJavaList();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -194,7 +195,7 @@
return new YangJavaSubModule();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -212,7 +213,7 @@
return new YangJavaTypeDef();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -230,7 +231,7 @@
return new YangJavaUses();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -248,7 +249,7 @@
return new YangJavaNotification();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -266,7 +267,7 @@
return new YangJavaRpc();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -284,7 +285,7 @@
return new YangJavaInput();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
@@ -302,7 +303,7 @@
return new YangJavaOutput();
}
default: {
- throw new RuntimeException("Only YANG to Java is supported.");
+ throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index 27e5aa0..7000361 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.plugin.manager;
+import java.io.IOException;
import java.util.Iterator;
import java.util.List;
@@ -27,6 +28,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
@@ -36,6 +38,7 @@
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
+import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -94,16 +97,7 @@
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private String searchDir;
private String codeGenDir;
-
- /**
- * Set current project.
- *
- * @param curProject maven project
- */
- public void setCurrentProject(final MavenProject curProject) {
-
- project = curProject;
- }
+ private YangNode rootNode;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -125,6 +119,7 @@
String yangFile = yangFileIterator.next();
try {
YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
+ setRootNode(yangNode);
generateJavaCode(yangNode, codeGenDir);
} catch (ParserException e) {
String logInfo = "Error in file: " + e.getFileName();
@@ -143,8 +138,52 @@
addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project);
} catch (Exception e) {
- getLog().info(e);
+ try {
+ translatorErrorHandler(getRootNode());
+ clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
+ } catch (IOException | DataModelException ex) {
+ throw new MojoExecutionException("Error handler failed to delete files for data model node.");
+ }
throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage());
}
}
+
+ /**
+ * Set current project.
+ *
+ * @param curProject maven project
+ */
+ public void setCurrentProject(MavenProject curProject) {
+ project = curProject;
+
+ }
+
+ /**
+ * Returns current project.
+ *
+ * @return current project
+ */
+ public MavenProject getCurrentProject() {
+ return project;
+ }
+
+ /**
+ * Returns current root YANG node of data-model tree.
+ *
+ * @return current root YANG node of data-model tree
+ */
+ public YangNode getRootNode() {
+ return rootNode;
+ }
+
+ /**
+ * Sets current root YANG node of data-model tree.
+ *
+ * @param rootNode current root YANG node of data-model tree
+ */
+
+ public void setRootNode(YangNode rootNode) {
+ this.rootNode = rootNode;
+ }
+
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
index 24a0daa..092f77f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
@@ -18,6 +18,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList;
@@ -63,7 +64,7 @@
}
/**
- * Construct object of java attribute info.
+ * Creates object of java attribute info.
*
* @param attrType YANG type
* @param name attribute name
@@ -85,7 +86,7 @@
public YangType<?> getAttributeType() {
if (attrType == null) {
- throw new RuntimeException("Expected java attribute type is null");
+ throw new TranslatorException("Expected java attribute type is null");
}
return attrType;
}
@@ -96,7 +97,6 @@
* @param type the data type info of attribute
*/
public void setAttributeType(YangType<?> type) {
-
attrType = type;
}
@@ -108,7 +108,7 @@
public String getAttributeName() {
if (name == null) {
- throw new RuntimeException("Expected java attribute name is null");
+ throw new TranslatorException("Expected java attribute name is null");
}
return name;
}
@@ -119,7 +119,6 @@
* @param attrName name of the attribute
*/
public void setAttributeName(String attrName) {
-
name = attrName;
}
@@ -129,7 +128,6 @@
* @return the if the added attribute is a list of info
*/
public boolean isListAttr() {
-
return isListAttr;
}
@@ -139,7 +137,6 @@
* @param isList if the added attribute is a list of info
*/
public void setListAttr(boolean isList) {
-
isListAttr = isList;
}
@@ -151,7 +148,6 @@
* qualified manner.
*/
public boolean isQualifiedName() {
-
return isQualifiedName;
}
@@ -163,7 +159,6 @@
* qualified manner
*/
public void setIsQualifiedAccess(boolean isQualified) {
-
isQualifiedName = isQualified;
}
@@ -174,7 +169,6 @@
* @return import info
*/
public JavaQualifiedTypeInfo getImportInfo() {
-
return importInfo;
}
@@ -184,7 +178,6 @@
* @param importInfo import info for the attribute type
*/
public void setImportInfo(JavaQualifiedTypeInfo importInfo) {
-
this.importInfo = importInfo;
}
@@ -204,23 +197,14 @@
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
- JavaAttributeInfo newAttr = new JavaAttributeInfo();
-
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
attributeType, attributeName, isListAttribute);
- newAttr.setImportInfo(importInfo);
- newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(
- curNode, importInfo));
- newAttr.setAttributeName(getCamelCase(attributeName));
- newAttr.setListAttr(isListAttribute);
- newAttr.setImportInfo(importInfo);
- newAttr.setAttributeType(attributeType);
- return newAttr;
+ return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
}
/**
@@ -237,12 +221,6 @@
public static JavaAttributeInfo getCurNodeAsAttributeInParent(
YangNode curNode, YangNode parentNode, boolean isListNode) {
- JavaAttributeInfo newAttr = new JavaAttributeInfo();
-
- // if (curNode instanceof HasJavaFileInfo) {
- // throw new RuntimeException("translator data model node does not have java info");
- // }
-
String curNodeName = ((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName();
/*
@@ -251,16 +229,8 @@
*/
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(parentNode,
curNodeName, isListNode);
- newAttr.setImportInfo(qualifiedTypeInfo);
- newAttr.setIsQualifiedAccess(
- getIsQualifiedAccessOrAddToImportList(parentNode,
- qualifiedTypeInfo));
- newAttr.setAttributeName(getCamelCase(curNodeName));
- newAttr.setListAttr(isListNode);
- newAttr.setImportInfo(qualifiedTypeInfo);
- newAttr.setAttributeType(null);
- return newAttr;
+ return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, parentNode, isListNode);
}
/**
@@ -279,8 +249,6 @@
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
- JavaAttributeInfo newAttr = new JavaAttributeInfo();
-
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
@@ -288,9 +256,26 @@
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
attributeType, attributeName, isListAttribute);
AttributesJavaDataType.addImportInfo(importInfo);
+
+ return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
+ }
+
+ /**
+ * Returns java attribute info.
+ *
+ * @param importInfo java qualified type info
+ * @param attributeName attribute name
+ * @param attributeType attribute type
+ * @param curNode current YANG node
+ * @param isListAttribute is list attribute
+ * @return java attribute info.
+ */
+ private static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName,
+ YangType<?> attributeType, YangNode curNode, boolean isListAttribute) {
+
+ JavaAttributeInfo newAttr = new JavaAttributeInfo();
newAttr.setImportInfo(importInfo);
- newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(
- curNode, importInfo));
+ newAttr.setIsQualifiedAccess(getIsQualifiedAccessOrAddToImportList(curNode, importInfo));
newAttr.setAttributeName(getCamelCase(attributeName));
newAttr.setListAttr(isListAttribute);
newAttr.setImportInfo(importInfo);
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index 40fed6e..8402004 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -19,6 +19,13 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+
+import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
+import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
+import static org.onosproject.yangutils.translator.tojava.TraversalType.ROOT;
+import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING;
/**
* Implementation of Java code generator based on application schema.
@@ -26,12 +33,36 @@
public final class JavaCodeGeneratorUtil {
/**
+ * Current YANG node.
+ */
+ private static YangNode curNode;
+
+ /**
* Default constructor.
*/
private JavaCodeGeneratorUtil() {
}
/**
+ * Returns current YANG node.
+ *
+ * @return current YANG node
+ */
+ public static YangNode getCurNode() {
+ return curNode;
+ }
+
+ /**
+ * Sets current YANG node.
+ *
+ * @param node current YANG node
+ */
+
+ public static void setCurNode(YangNode node) {
+ curNode = node;
+ }
+
+ /**
* Generate Java code files corresponding to the YANG schema.
*
* @param rootNode root node of the data model tree
@@ -40,23 +71,25 @@
* node
*/
public static void generateJavaCode(YangNode rootNode, String codeGenDir) throws IOException {
+
YangNode curNode = rootNode;
- TraversalType curTraversal = TraversalType.ROOT;
+ TraversalType curTraversal = ROOT;
while (!(curNode == null)) {
- if (curTraversal != TraversalType.PARENT) {
+ if (curTraversal != PARENT) {
+ setCurNode(curNode);
generateCodeEntry(curNode, codeGenDir);
}
- if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) {
- curTraversal = TraversalType.CHILD;
+ if (curTraversal != PARENT && curNode.getChild() != null) {
+ curTraversal = CHILD;
curNode = curNode.getChild();
} else if (curNode.getNextSibling() != null) {
generateCodeExit(curNode);
- curTraversal = TraversalType.SIBILING;
+ curTraversal = SIBILING;
curNode = curNode.getNextSibling();
} else {
generateCodeExit(curNode);
- curTraversal = TraversalType.PARENT;
+ curTraversal = PARENT;
curNode = curNode.getParent();
}
}
@@ -76,8 +109,8 @@
if (curNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) curNode).generateCodeEntry(codeGenDir);
} else {
- throw new RuntimeException(
- "Gnenerated data model node cannot be translated to target language code");
+ throw new TranslatorException(
+ "Generated data model node cannot be translated to target language code");
}
}
@@ -93,8 +126,113 @@
if (curNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) curNode).generateCodeExit();
} else {
- throw new RuntimeException(
- "Gnenerated data model node cannot be translated to target language code");
+ throw new TranslatorException(
+ "Generated data model node cannot be translated to target language code");
+ }
+ }
+
+ /**
+ * 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 {
+
+ YangNode curNode = getCurNode();
+ YangNode tempNode = curNode;
+ TraversalType curTraversal = ROOT;
+
+ while (!(curNode == tempNode.getParent())) {
+
+ if (curTraversal != PARENT && curNode.getChild() != null) {
+ curTraversal = CHILD;
+ curNode = curNode.getChild();
+ } else if (curNode.getNextSibling() != null) {
+ curTraversal = SIBILING;
+ if (curNode != tempNode) {
+ free(curNode);
+ }
+ curNode = curNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ if (curNode != tempNode) {
+ free(curNode);
+ }
+ curNode = curNode.getParent();
+ }
+ }
+ }
+
+ /**
+ * Free the current node.
+ *
+ * @param node YANG node
+ * @throws DataModelException when fails to do datamodel operations
+ */
+ private static void free(YangNode node) throws DataModelException {
+
+ YangNode parent = node.getParent();
+ parent.setChild(null);
+ if (node.getNextSibling() != null) {
+ parent.setChild(node.getNextSibling());
+ } else if (node.getPreviousSibling() != null) {
+ parent.setChild(node.getPreviousSibling());
+ }
+ node = null;
+ }
+
+ /**
+ * Delete Java code files corresponding to the YANG schema.
+ *
+ * @param rootNode root node of data-model tree
+ * @throws IOException when fails to delete java code file the current node
+ * @throws DataModelException when fails to do datamodel operations
+ */
+ public static void translatorErrorHandler(YangNode rootNode) throws IOException, DataModelException {
+
+ /**
+ * Free other resources where translator has failed.
+ */
+ freeRestResources();
+
+ /**
+ * Start removing all open files.
+ */
+ YangNode curNode = rootNode;
+ setCurNode(curNode.getChild());
+ TraversalType curTraversal = ROOT;
+
+ while (!(curNode == null)) {
+
+ if (curTraversal != PARENT) {
+ close(curNode);
+ }
+ if (curTraversal != PARENT && curNode.getChild() != null) {
+ curTraversal = CHILD;
+ curNode = curNode.getChild();
+ } else if (curNode.getNextSibling() != null) {
+ curTraversal = SIBILING;
+ curNode = curNode.getNextSibling();
+ } else {
+ curTraversal = PARENT;
+ curNode = curNode.getParent();
+ }
+ }
+
+ freeRestResources();
+ curNode = null;
+ }
+
+ /**
+ * Closes all the current open file handles of node and delete all generated files.
+ *
+ * @param curNode current YANG node
+ * @throws IOException when fails to do IO operations
+ */
+ private static void close(YangNode curNode) throws IOException {
+
+ if (((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles() != null) {
+ ((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().close(true);
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
index 8b69fca..bbad23a 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfo.java
@@ -16,11 +16,14 @@
package org.onosproject.yangutils.translator.tojava;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+
/**
* Cached java file handle, which supports the addition of member attributes and
* methods.
*/
public class JavaFileInfo {
+
/**
* The type(s) of java source file(s) to be generated when the cached file
* handle is closed.
@@ -93,8 +96,9 @@
* @return the java package
*/
public String getPackage() {
+
if (pkg == null) {
- throw new RuntimeException("Referencing package of a generated java file which is not set");
+ throw new TranslatorException("Referencing package of a generated java file which is not set");
}
return pkg;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index 682a101..c4ff7e5 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -21,6 +21,7 @@
import java.util.TreeSet;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
@@ -64,7 +65,6 @@
* @return true if any of the attribute needs to be maintained as a list.
*/
public boolean getIfListImported() {
-
return isListToImport;
}
@@ -74,7 +74,6 @@
* @param isList status to mention list is bing imported.
*/
public void setIfListImported(boolean isList) {
-
isListToImport = isList;
}
@@ -84,7 +83,6 @@
* @return the set containing the imported class/interface info
*/
public SortedSet<JavaQualifiedTypeInfo> getImportSet() {
-
return importSet;
}
@@ -94,7 +92,6 @@
* @param importSet the set containing the imported class/interface info
*/
private void setImportSet(SortedSet<JavaQualifiedTypeInfo> importSet) {
-
this.importSet = importSet;
}
@@ -116,7 +113,7 @@
public boolean addImportInfo(YangNode curNode, JavaQualifiedTypeInfo newImportInfo) {
if (!(curNode instanceof HasJavaImportData)) {
- throw new RuntimeException("missing import info in data model node");
+ throw new TranslatorException("missing import info in data model node");
}
for (JavaQualifiedTypeInfo curImportInfo : ((HasJavaImportData) curNode).getJavaImportData().getImportSet()) {
if (curImportInfo.getClassInfo()
@@ -165,7 +162,6 @@
* @return import for hash and equals method
*/
public String getImportForHashAndEquals() {
-
return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS;
}
@@ -175,15 +171,13 @@
* @return import for to string method
*/
public String getImportForToString() {
-
return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS;
}
/**
- * Sets import for to list.
+ * Sets import for the list attribute.
*/
private static String setImportForList() {
-
return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
index ba4b99b..f703a2c 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfo.java
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import com.google.common.base.MoreObjects;
@@ -51,7 +52,6 @@
* @return the imported package info
*/
public String getPkgInfo() {
-
return pkgInfo;
}
@@ -61,7 +61,6 @@
* @param pkgInfo the imported package info
*/
public void setPkgInfo(String pkgInfo) {
-
this.pkgInfo = pkgInfo;
}
@@ -71,7 +70,6 @@
* @return the imported class/interface info
*/
public String getClassInfo() {
-
return classInfo;
}
@@ -81,7 +79,6 @@
* @param classInfo the imported class/interface info
*/
public void setClassInfo(String classInfo) {
-
this.classInfo = classInfo;
}
@@ -105,7 +102,7 @@
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
if (attrType == null) {
- throw new RuntimeException("missing data type of leaf " + attributeName);
+ throw new TranslatorException("missing data type of leaf " + attributeName);
}
/*
@@ -121,7 +118,7 @@
importInfo.setClassInfo(className);
String classPkg = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr, className);
if (classPkg == null) {
- throw new RuntimeException("import package cannot be null when the class is used");
+ throw new TranslatorException("import package cannot be null when the class is used");
}
importInfo.setPkgInfo(classPkg);
} else {
@@ -131,7 +128,7 @@
*/
String dataTypeName = AttributesJavaDataType.getJavaDataType(attrType);
if (dataTypeName == null) {
- throw new RuntimeException("not supported data type");
+ throw new TranslatorException("not supported data type");
}
importInfo.setClassInfo(dataTypeName);
}
@@ -155,7 +152,7 @@
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
if (!(curNode instanceof HasJavaFileInfo)) {
- throw new RuntimeException("missing java file information to get the package details "
+ throw new TranslatorException("missing java file information to get the package details "
+ "of attribute corresponding to child node");
}
/*
@@ -184,7 +181,7 @@
boolean isImportPkgEqualCurNodePkg;
if (!(curNode instanceof HasJavaFileInfo)) {
- throw new RuntimeException("missing java file info for getting the qualified access");
+ throw new TranslatorException("missing java file info for getting the qualified access");
}
if (importInfo.getClassInfo().contentEquals(
((HasJavaFileInfo) curNode).getJavaFileInfo().getJavaName())) {
@@ -211,7 +208,7 @@
* If the current data model node is not supposed to import
* data, then this is a usage issue and needs to be fixed.
*/
- throw new RuntimeException("Current node needs to support Imports");
+ throw new TranslatorException("Current node needs to support Imports");
}
boolean isImportAdded = ((HasJavaImportData) curNode).getJavaImportData()
@@ -241,7 +238,7 @@
YangNode curNode, JavaQualifiedTypeInfo importInfo) {
if (!(curNode instanceof HasJavaFileInfo)) {
- throw new RuntimeException("missing java file info for the data model node");
+ throw new TranslatorException("missing java file info for the data model node");
}
return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage()
.contentEquals(importInfo.getPkgInfo()
@@ -250,7 +247,6 @@
@Override
public int hashCode() {
-
return Objects.hash(pkgInfo, classInfo);
}
@@ -275,7 +271,6 @@
* @return if equal or not
*/
public boolean exactMatch(JavaQualifiedTypeInfo importInfo) {
-
return equals(importInfo)
&& Objects.equals(pkgInfo, importInfo.getPkgInfo())
&& Objects.equals(classInfo, importInfo.getClassInfo());
@@ -283,7 +278,6 @@
@Override
public String toString() {
-
return MoreObjects.toStringHelper(getClass())
.add("pkgInfo", pkgInfo)
.add("classInfo", classInfo).toString();
@@ -296,7 +290,6 @@
*/
@Override
public int compareTo(JavaQualifiedTypeInfo other) {
-
return getClassInfo().compareTo(other.getClassInfo());
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index 6396c9c..0c7666c 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -26,12 +26,7 @@
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen;
-import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
-import org.onosproject.yangutils.utils.UtilConstants;
-import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
-import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
-import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
@@ -52,13 +47,18 @@
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoOfTypeDef;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getCurNodeAsAttributeInParent;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
@@ -83,8 +83,11 @@
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
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.FileSystemUtil.updateFileHandle;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
@@ -389,7 +392,6 @@
if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
}
-
}
/**
@@ -398,7 +400,6 @@
* @return java file handle for interface file
*/
public File getInterfaceJavaFileHandle() {
-
return interfaceJavaFileHandle;
}
@@ -408,7 +409,6 @@
* @param interfaceJavaFileHandle java file handle
*/
public void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
-
this.interfaceJavaFileHandle = interfaceJavaFileHandle;
}
@@ -418,7 +418,6 @@
* @return java file handle for builder interface file
*/
public File getBuilderInterfaceJavaFileHandle() {
-
return builderInterfaceJavaFileHandle;
}
@@ -428,7 +427,6 @@
* @param builderInterfaceJavaFileHandle java file handle
*/
public void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
-
this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
}
@@ -438,7 +436,6 @@
* @return java file handle for builder class file
*/
public File getBuilderClassJavaFileHandle() {
-
return builderClassJavaFileHandle;
}
@@ -448,7 +445,6 @@
* @param builderClassJavaFileHandle java file handle
*/
public void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
-
this.builderClassJavaFileHandle = builderClassJavaFileHandle;
}
@@ -458,7 +454,6 @@
* @return java file handle for impl class file
*/
public File getImplClassJavaFileHandle() {
-
return implClassJavaFileHandle;
}
@@ -468,7 +463,6 @@
* @param implClassJavaFileHandle java file handle
*/
public void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
-
this.implClassJavaFileHandle = implClassJavaFileHandle;
}
@@ -478,7 +472,6 @@
* @return java file handle for typedef class file
*/
public File getTypedefClassJavaFileHandle() {
-
return typedefClassJavaFileHandle;
}
@@ -488,7 +481,6 @@
* @param typedefClassJavaFileHandle java file handle
*/
public void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
-
this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
}
@@ -498,7 +490,6 @@
* @return temporary file handle
*/
public File getAttributesTempFileHandle() {
-
return attributesTempFileHandle;
}
@@ -508,7 +499,6 @@
* @param attributeForClass file handle for attribute
*/
public void setAttributesTempFileHandle(File attributeForClass) {
-
attributesTempFileHandle = attributeForClass;
}
@@ -518,7 +508,6 @@
* @return temporary file handle
*/
public File getGetterInterfaceTempFileHandle() {
-
return getterInterfaceTempFileHandle;
}
@@ -528,7 +517,6 @@
* @param getterForInterface file handle for to getter method
*/
public void setGetterInterfaceTempFileHandle(File getterForInterface) {
-
getterInterfaceTempFileHandle = getterForInterface;
}
@@ -538,7 +526,6 @@
* @return temporary file handle
*/
public File getGetterImplTempFileHandle() {
-
return getterImplTempFileHandle;
}
@@ -548,7 +535,6 @@
* @param getterImpl file handle for to getter method's impl
*/
public void setGetterImplTempFileHandle(File getterImpl) {
-
getterImplTempFileHandle = getterImpl;
}
@@ -558,7 +544,6 @@
* @return temporary file handle
*/
public File getSetterInterfaceTempFileHandle() {
-
return setterInterfaceTempFileHandle;
}
@@ -568,7 +553,6 @@
* @param setterForInterface file handle for to setter method
*/
public void setSetterInterfaceTempFileHandle(File setterForInterface) {
-
setterInterfaceTempFileHandle = setterForInterface;
}
@@ -578,7 +562,6 @@
* @return temporary file handle
*/
public File getSetterImplTempFileHandle() {
-
return setterImplTempFileHandle;
}
@@ -588,7 +571,6 @@
* @param setterImpl file handle for to setter method's implementation class
*/
public void setSetterImplTempFileHandle(File setterImpl) {
-
setterImplTempFileHandle = setterImpl;
}
@@ -598,7 +580,6 @@
* @return temporary file handle
*/
public File getConstructorImplTempFileHandle() {
-
return constructorImplTempFileHandle;
}
@@ -608,7 +589,6 @@
* @param constructor file handle for to constructor
*/
public void setConstructorImplTempFileHandle(File constructor) {
-
constructorImplTempFileHandle = constructor;
}
@@ -618,7 +598,6 @@
* @return temporary file handle
*/
public File getHashCodeImplTempFileHandle() {
-
return hashCodeImplTempFileHandle;
}
@@ -628,7 +607,6 @@
* @param hashCodeMethod file handle for hash code method
*/
public void setHashCodeImplTempFileHandle(File hashCodeMethod) {
-
hashCodeImplTempFileHandle = hashCodeMethod;
}
@@ -638,7 +616,6 @@
* @return temporary file handle
*/
public File getEqualsImplTempFileHandle() {
-
return equalsImplTempFileHandle;
}
@@ -648,7 +625,6 @@
* @param equalsMethod file handle for to equals method
*/
public void setEqualsImplTempFileHandle(File equalsMethod) {
-
equalsImplTempFileHandle = equalsMethod;
}
@@ -658,7 +634,6 @@
* @return temporary file handle
*/
public File getToStringImplTempFileHandle() {
-
return toStringImplTempFileHandle;
}
@@ -668,7 +643,6 @@
* @param toStringMethod file handle for to string method
*/
public void setToStringImplTempFileHandle(File toStringMethod) {
-
toStringImplTempFileHandle = toStringMethod;
}
@@ -678,7 +652,6 @@
* @return java attribute info
*/
public JavaAttributeInfo getNewAttrInfo() {
-
return newAttrInfo;
}
@@ -701,7 +674,6 @@
* @return current YANG node
*/
public YangNode getCurYangNode() {
-
return curYangNode;
}
@@ -711,7 +683,6 @@
* @param curYangNode YANG node
*/
public void setCurYangNode(YangNode curYangNode) {
-
this.curYangNode = curYangNode;
}
@@ -722,7 +693,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addAttribute(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION);
}
@@ -733,7 +703,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addGetterForInterface(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE);
}
@@ -761,7 +730,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addSetterForInterface(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getSetterInterfaceTempFileHandle(),
getSetterString(attr, generatedJavaClassName) + NEW_LINE);
}
@@ -773,7 +741,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addSetterImpl(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getSetterImplTempFileHandle(),
getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE);
}
@@ -785,7 +752,6 @@
* @throws IOException when fails to append to temporary file
*/
public String addBuildMethodForInterface() throws IOException {
-
return parseBuilderInterfaceBuildMethodString(generatedJavaClassName);
}
@@ -796,7 +762,6 @@
* @throws IOException when fails to append to temporary file
*/
public String addBuildMethodImpl() throws IOException {
-
return getBuildString(generatedJavaClassName) + NEW_LINE;
}
@@ -807,7 +772,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addConstructor(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getConstructorImplTempFileHandle(), getConstructor(generatedJavaClassName, attr));
}
@@ -820,7 +784,6 @@
* @throws IOException when fails to append to file
*/
public String addDefaultConstructor(String modifier, String toAppend) throws IOException {
-
return NEW_LINE + getDefaultConstructorString(generatedJavaClassName + toAppend, modifier);
}
@@ -831,7 +794,6 @@
* @throws IOException when fails to append to file
*/
public String addTypeDefConstructor() throws IOException {
-
return NEW_LINE + getJavaDoc(TYPE_DEF_CONSTRUCTOR, generatedJavaClassName, false)
+ getTypeDefConstructor(newAttrInfo, generatedJavaClassName) + NEW_LINE;
}
@@ -843,7 +805,6 @@
* @throws IOException when fails to append to file
*/
public String addTypeDefsSetter() throws IOException {
-
return getJavaDoc(TYPE_DEF_SETTER_METHOD, generatedJavaClassName, false) + getSetterForTypeDefClass(newAttrInfo)
+ NEW_LINE;
}
@@ -855,8 +816,7 @@
* @throws IOException when fails to append to file
*/
public String addOfMethod() throws IOException {
-
- return JavaDocGen.getJavaDoc(JavaDocType.OF_METHOD, generatedJavaClassName, false)
+ return getJavaDoc(OF_METHOD, generatedJavaClassName, false)
+ getOfMethod(generatedJavaClassName, newAttrInfo);
}
@@ -867,7 +827,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addHashCodeMethod(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
}
@@ -878,7 +837,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addEqualsMethod(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
}
@@ -889,7 +847,6 @@
* @throws IOException when fails to append to temporary file
*/
public void addToStringMethod(JavaAttributeInfo attr) throws IOException {
-
appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
}
@@ -923,9 +880,7 @@
* @throws IOException when fails to create new file handle
*/
private File getJavaFileHandle(String fileName) throws IOException {
-
createPackage(absoluteDirPath, getJavaFileInfo().getJavaName());
-
return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
}
@@ -940,7 +895,7 @@
String path = getTempDirPath();
if (new File(path + file.getName()).exists()) {
- return FileSystemUtil.readAppendFile(path + file.getName(), EMPTY_STRING);
+ return readAppendFile(path + file.getName(), EMPTY_STRING);
} else {
throw new IOException("Unable to get data from the given "
+ file.getName() + " file for " + generatedJavaClassName + PERIOD);
@@ -953,9 +908,8 @@
* @return directory path
*/
private String getTempDirPath() {
-
- return absoluteDirPath.replace(PERIOD, UtilConstants.SLASH)
- + SLASH + generatedJavaClassName + TEMP_FOLDER_NAME_SUFIX + SLASH;
+ return getPackageDirPathFromJavaJPackage(absoluteDirPath) + SLASH + generatedJavaClassName
+ + TEMP_FOLDER_NAME_SUFIX + SLASH;
}
/**
@@ -969,8 +923,7 @@
/*
* TODO: check if this utility needs to be called or move to the caller
*/
- String attributeName = JavaIdentifierSyntax
- .getCamelCase(JavaIdentifierSyntax.getSmallCase(attr.getAttributeName()));
+ String attributeName = getCamelCase(getSmallCase(attr.getAttributeName()));
if (attr.isQualifiedName()) {
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(),
attributeName, attr.isListAttr());
@@ -1009,13 +962,13 @@
YangNode parent = getParentNodeInGenCode(curNode);
if (!(parent instanceof JavaCodeGenerator)) {
- throw new RuntimeException("missing parent node to contain current node info in generated file");
+ throw new TranslatorException("missing parent node to contain current node info in generated file");
}
JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInParent(curNode,
parent, isList);
if (!(parent instanceof HasTempJavaCodeFragmentFiles)) {
- throw new RuntimeException("missing parent temp file handle");
+ throw new TranslatorException("missing parent temp file handle");
}
((HasTempJavaCodeFragmentFiles) parent)
.getTempJavaCodeFragmentFiles()
@@ -1060,7 +1013,7 @@
*/
if (listOfLeafList.size() != 0) {
if (!(curNode instanceof HasJavaImportData)) {
- throw new RuntimeException("missing import info in current data model node");
+ throw new TranslatorException("missing import info in current data model node");
}
((HasJavaImportData) curNode).getJavaImportData()
@@ -1164,7 +1117,6 @@
* @return java file info
*/
private JavaFileInfo getJavaFileInfo() {
-
return ((HasJavaFileInfo) getCurYangNode()).getJavaFileInfo();
}
@@ -1175,8 +1127,7 @@
* @return java class name
*/
private String getJavaClassName(String suffix) {
-
- return JavaIdentifierSyntax.getCaptialCase(getJavaFileInfo().getJavaName()) + suffix;
+ return getCaptialCase(getJavaFileInfo().getJavaName()) + suffix;
}
/**
@@ -1185,7 +1136,6 @@
* @return directory path
*/
private String getDirPath() {
-
return getJavaFileInfo().getPackageFilePath();
}
@@ -1225,7 +1175,7 @@
* Append builder interface file to interface file and close it.
*/
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
- insertDataIntoJavaFile(getInterfaceJavaFileHandle(), JavaCodeSnippetGen.getJavaClassDefClose());
+ insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
}
@@ -1254,8 +1204,7 @@
* Append impl class to builder class and close it.
*/
mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
- insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), JavaCodeSnippetGen.getJavaClassDefClose());
-
+ insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
}
/**
@@ -1269,48 +1218,72 @@
/**
* Close all the file handles.
*/
- close();
+ close(false);
}
/**
* Removes all temporary file handles.
*
+ * @param isErrorOccurred when translator fails to generate java files we need to close
+ * all open file handles include temporary files and java files.
+ *
* @throws IOException when failed to delete the temporary files
*/
- private void close() throws IOException {
+ public void close(boolean isErrorOccurred) throws IOException {
+ boolean isError = isErrorOccurred;
+ /**
+ * Close all java file handles and when error occurs delete the files.
+ */
if ((generatedJavaFiles & INTERFACE_MASK) != 0) {
- closeFile(getInterfaceJavaFileHandle(), false);
+ closeFile(getInterfaceJavaFileHandle(), isError);
}
-
if ((generatedJavaFiles & BUILDER_CLASS_MASK) != 0) {
- closeFile(getBuilderClassJavaFileHandle(), false);
+ closeFile(getBuilderClassJavaFileHandle(), isError);
}
-
if ((generatedJavaFiles & BUILDER_INTERFACE_MASK) != 0) {
closeFile(getBuilderInterfaceJavaFileHandle(), true);
}
-
if ((generatedJavaFiles & IMPL_CLASS_MASK) != 0) {
closeFile(getImplClassJavaFileHandle(), true);
}
-
if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) {
- closeFile(getTypedefClassJavaFileHandle(), false);
+ closeFile(getTypedefClassJavaFileHandle(), isError);
}
/**
* Close all temporary file handles and delete the files.
*/
- closeFile(getGetterInterfaceTempFileHandle(), true);
- closeFile(getGetterImplTempFileHandle(), true);
- closeFile(getSetterInterfaceTempFileHandle(), true);
- closeFile(getSetterImplTempFileHandle(), true);
- closeFile(getConstructorImplTempFileHandle(), true);
- closeFile(getAttributesTempFileHandle(), true);
- closeFile(getHashCodeImplTempFileHandle(), true);
- closeFile(getToStringImplTempFileHandle(), true);
- closeFile(getEqualsImplTempFileHandle(), true);
+ if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
+ closeFile(getGetterInterfaceTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
+ closeFile(getGetterImplTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
+ closeFile(getSetterInterfaceTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
+ closeFile(getSetterImplTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
+ closeFile(getConstructorImplTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
+ closeFile(getAttributesTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
+ closeFile(getHashCodeImplTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
+ closeFile(getToStringImplTempFileHandle(), true);
+ }
+ if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
+ closeFile(getEqualsImplTempFileHandle(), true);
+ }
+
+ clean(getTempDirPath());
+ generatedTempFiles = 0;
}
/**
@@ -1321,12 +1294,11 @@
*/
private void closeFile(File file, boolean toBeDeleted) throws IOException {
- if (file.exists()) {
- FileSystemUtil.updateFileHandle(file, null, true);
+ if (file != null) {
+ updateFileHandle(file, null, true);
if (toBeDeleted) {
file.delete();
}
- clean(getTempDirPath());
}
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
index 329d934..5da421d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -76,7 +77,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -88,7 +89,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -99,7 +99,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -111,7 +110,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -122,11 +120,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -137,7 +130,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
index 739119e..cf104fc 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangCase;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -76,7 +77,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -88,7 +89,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -99,7 +99,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -111,7 +110,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -122,11 +120,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -137,7 +130,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
index 50c04ed..94a4315 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -76,7 +77,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -88,7 +89,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -99,7 +99,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -111,7 +110,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -122,11 +120,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -137,7 +130,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
index 3c2b773..5427543 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -76,7 +77,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -88,7 +89,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -99,7 +99,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -111,7 +110,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -122,11 +120,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("Missing temp file handle for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -137,7 +130,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
@@ -177,7 +169,6 @@
*/
@Override
public void generateCodeExit() throws IOException {
-
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
index 1b1b818..a93c83d 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGrouping.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangGrouping;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -76,7 +77,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -88,7 +89,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -99,7 +99,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -111,7 +110,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -122,11 +120,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -137,7 +130,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
index f3f3674..20aac19 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangInput;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -78,7 +79,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -90,7 +91,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -101,7 +101,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -113,7 +112,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -124,11 +122,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("Missing temporary file handle for" +
- "current node " + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -139,7 +132,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
@@ -179,7 +171,6 @@
*/
@Override
public void generateCodeExit() throws IOException {
-
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
index c504b8f..91a2866 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -77,7 +78,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -89,7 +90,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -100,7 +100,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -112,7 +111,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -123,11 +121,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -138,7 +131,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
@@ -180,7 +172,6 @@
*/
@Override
public void generateCodeExit() throws IOException {
-
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
index 9413c64..8d899a2 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -76,7 +77,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -88,7 +89,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -99,7 +99,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -111,7 +110,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -122,11 +120,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -137,7 +130,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
@@ -170,7 +162,6 @@
@Override
public void generateCodeExit() throws IOException {
-
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
return;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
index ac9a588..81a0915 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
@@ -76,7 +77,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -88,7 +89,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -99,7 +99,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -111,7 +110,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -122,11 +120,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("Missing temporary file handle for" +
- "current node " + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -137,7 +130,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
index 498510a..b062428 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -78,7 +79,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -90,7 +91,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -101,7 +101,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -113,7 +112,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -124,11 +122,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("Missing temporary file handle for" +
- "current node " + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -139,7 +132,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
@@ -179,7 +171,6 @@
*/
@Override
public void generateCodeExit() throws IOException {
-
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
index caa05bc..eaa0060 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
@@ -19,6 +19,7 @@
import org.onosproject.yangutils.datamodel.YangBelongsTo;
import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -77,7 +78,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -89,7 +90,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -100,7 +100,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -112,7 +111,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -123,11 +121,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -138,7 +131,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
@@ -150,7 +142,6 @@
* @return the name space string of the module.
*/
private String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
-
// TODO Auto-generated method stub
return "";
}
@@ -190,6 +181,5 @@
@Override
public void generateCodeExit() {
// TODO Auto-generated method stub
-
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
index a8cc75b..7440461 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
@@ -75,7 +76,7 @@
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -87,7 +88,6 @@
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
-
javaFileInfo = javaInfo;
}
@@ -98,7 +98,6 @@
*/
@Override
public JavaImportData getJavaImportData() {
-
return javaImportData;
}
@@ -110,7 +109,6 @@
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
-
this.javaImportData = javaImportData;
}
@@ -121,11 +119,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
-
- if (tempFileHandle == null) {
- throw new RuntimeException("missing temp file hand for current node "
- + getJavaFileInfo().getJavaName());
- }
return tempFileHandle;
}
@@ -136,7 +129,6 @@
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
-
tempFileHandle = fileHandle;
}
@@ -170,11 +162,11 @@
/**
* Create a java file using the YANG grouping info.
+ *
* @throws IOException IO operations fails
*/
@Override
public void generateCodeExit() throws IOException {
-
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
index cc29a74..b799d65 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUses.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
@@ -61,8 +62,9 @@
*/
@Override
public JavaFileInfo getJavaFileInfo() {
+
if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node");
+ throw new TranslatorException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
@@ -106,6 +108,7 @@
*/
@Override
public void generateCodeEntry(String codeGenDir) {
+
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
index 5ea5f1e..1f42d68 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
@@ -47,6 +47,8 @@
private static final int INDEX_ZERO = 0;
private static final int INDEX_ONE = 1;
private static final int INDEX_TWO = 2;
+ private static final int VALUE_CHECK = 10;
+ private static final String ZERO = "0";
/**
* Default constructor.
@@ -103,12 +105,12 @@
String pkg;
if (!(curNode instanceof HasJavaFileInfo)
|| curNode.getParent() == null) {
- throw new RuntimeException("missing parent node to get current node's package");
+ throw new TranslatorException("missing parent node to get current node's package");
}
YangNode parentNode = getParentNodeInGenCode(curNode);
if (!(parentNode instanceof HasJavaFileInfo)) {
- throw new RuntimeException("missing parent java node to get current node's package");
+ throw new TranslatorException("missing parent java node to get current node's package");
}
JavaFileInfo parentJavaFileHandle = ((HasJavaFileInfo) parentNode).getJavaFileInfo();
pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
@@ -122,7 +124,6 @@
* @return version
*/
private static String getYangVersion(byte ver) {
-
return VERSION_PREFIX + ver;
}
@@ -164,8 +165,8 @@
for (int i = INDEX_ONE; i < revisionArr.length; i++) {
Integer val = Integer.parseInt(revisionArr[i]);
- if (val < 10) {
- rev = rev + "0";
+ if (val < VALUE_CHECK) {
+ rev = rev + ZERO;
}
rev = rev + val;
}
@@ -242,7 +243,6 @@
* @return corresponding java identifier
*/
public static String getCaptialCase(String yangIdentifier) {
-
return yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
}
@@ -254,7 +254,6 @@
* @return corresponding java identifier
*/
public static String getSmallCase(String yangIdentifier) {
-
return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
}
@@ -265,7 +264,6 @@
* @return java package
*/
public static String getJavaPackageFromPackagePath(String packagePath) {
-
return packagePath.replace(SLASH, PERIOD);
}
@@ -276,7 +274,6 @@
* @return java package
*/
public static String getPackageDirPathFromJavaJPackage(String packagePath) {
-
return packagePath.replace(PERIOD, SLASH);
}
}
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 369b08a..a11b6d7 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -34,17 +34,18 @@
/**
* JavaDocs for impl class.
*/
- public static final String IMPL_CLASS_JAVA_DOC = " * Provides the implementation of ";
+ public static final String IMPL_CLASS_JAVA_DOC = " * Reperesents the implementation of ";
/**
* JavaDocs for builder class.
*/
- public static final String BUILDER_CLASS_JAVA_DOC = " * Provides the builder implementation of ";
+ public static final String BUILDER_CLASS_JAVA_DOC = " * Reperesents the builder implementation of ";
/**
* JavaDocs for interface class.
*/
- public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which provides functionalities of ";
+ public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which Reperesents the"
+ + " functionalities of ";
/**
* JavaDocs for builder interface class.
@@ -102,14 +103,9 @@
public static final String JAVA_DOC_GETTERS = " * Returns the attribute ";
/**
- * JavaDocs's description for default constructor.
- */
- public static final String JAVA_DOC_DEFAULT_CONSTRUCTOR = " * Default Constructor.\n";
-
- /**
* JavaDocs's description for constructor.
*/
- public static final String JAVA_DOC_CONSTRUCTOR = " * Construct the object of ";
+ public static final String JAVA_DOC_CONSTRUCTOR = " * Creates an instance of ";
/**
* JavaDocs's description for build method.
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index c3ff0a3..e2003d9 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -30,7 +30,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
@@ -164,7 +163,7 @@
} else if (type.equals(JavaDocType.OF_METHOD)) {
javaDoc = generateForOf(name);
} else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) {
- javaDoc = generateForDefaultConstructors();
+ javaDoc = generateForDefaultConstructors(name);
} else if (type.equals(JavaDocType.BUILD_METHOD)) {
javaDoc = generateForBuild(name);
} else {
@@ -226,7 +225,6 @@
* @return javaDocs
*/
private static String generateForOf(String attribute) {
-
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
+ 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
@@ -241,7 +239,6 @@
* @return javaDocs
*/
private static String generateForTypeDefSetter(String attribute) {
-
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
@@ -255,7 +252,6 @@
* @return javaDocs
*/
private static String generateForTypeDefConstructor(String attribute) {
-
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
@@ -269,7 +265,6 @@
* @return javaDocs
*/
private static String generateForImplClass(String className) {
-
return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
}
@@ -280,7 +275,6 @@
* @return javaDocs
*/
private static String generateForBuilderClass(String className) {
-
return NEW_LINE + JAVA_DOC_FIRST_LINE + BUILDER_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
@@ -292,7 +286,6 @@
* @return javaDocs
*/
private static String generateForInterface(String interfaceName) {
-
return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
@@ -304,7 +297,6 @@
* @return javaDocs
*/
private static String generateForBuilderInterface(String builderforName) {
-
return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
@@ -316,19 +308,18 @@
* @return javaDocs
*/
private static String generateForPackage(String packageName) {
-
return JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
}
/**
* Generate javaDocs for default constructor.
*
+ * @param className class name
* @return javaDocs
*/
- private static String generateForDefaultConstructors() {
-
- return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_DEFAULT_CONSTRUCTOR
- + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ private static String generateForDefaultConstructors(String className) {
+ return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className
+ + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
@@ -338,7 +329,6 @@
* @return javaDocs
*/
private static String generateForConstructors(String className) {
-
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE
+ FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
@@ -353,7 +343,6 @@
* @return javaDocs
*/
private static String generateForBuild(String buildName) {
-
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD
+ buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
index 4d62b73..1610c90 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/AttributesJavaDataTypeTest.java
@@ -24,7 +24,7 @@
import org.onosproject.yangutils.datamodel.YangType;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
@@ -69,7 +69,7 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -78,7 +78,6 @@
*/
@Test
public void testgetJavaClassInfo() {
-
test = getJavaImportClass(getStubYangType(TYPE1), false);
assertThat(true, is(test.equals(CLASS_INFO1)));
@@ -97,7 +96,6 @@
*/
@Test
public void testgetJavaDataType() {
-
test = getJavaDataType(getStubYangType(TYPE1));
assertThat(true, is(test.equals(CLASS_INFO1)));
@@ -116,7 +114,6 @@
*/
@Test
public void testgetJavaPkgInfo() {
-
test = getJavaImportPackage(getStubYangType(TYPE1), false, CLASS_INFO1);
assertThat(true, is(test.equals(JAVA_LANG)));
@@ -137,7 +134,6 @@
* @return YANG type
*/
private YangType<?> getStubYangType(YangDataTypes dataTypes) {
-
YangType<?> type = new YangType();
type.setDataType(dataTypes);
return type;
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
index c61a13b..d53ccd3 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
@@ -22,7 +22,7 @@
import org.junit.Test;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
@@ -62,7 +62,7 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -71,7 +71,6 @@
*/
@Test
public void generateBuilderClassDefinitionTest() {
-
String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME);
assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF)));
}
@@ -81,7 +80,6 @@
*/
@Test
public void generateBuilderInterfaceDefinitionTest() {
-
String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME);
assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF)));
}
@@ -91,7 +89,6 @@
*/
@Test
public void generateImplDefinitionTest() {
-
String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME);
assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF)));
}
@@ -101,7 +98,6 @@
*/
@Test
public void generateinterfaceDefinitionTest() {
-
String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME);
assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF)));
}
@@ -111,7 +107,6 @@
*/
@Test
public void generateTypeDefTest() {
-
String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME);
assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF)));
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
index 22daf1a..e12a230 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
@@ -24,7 +24,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.IsNot.not;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
@@ -75,7 +75,7 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -84,7 +84,6 @@
*/
@Test
public void testForImportText() {
-
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
importInfo.setPkgInfo(PKG_INFO);
importInfo.setClassInfo(CLASS_INFO);
@@ -99,11 +98,9 @@
*/
@Test
public void testForJavaClassDefStart() {
-
String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME);
assertThat(true, is(classDef
.equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
-
}
/**
@@ -111,7 +108,6 @@
*/
@Test
public void testForListAttribute() {
-
String listAttribute = getListAttribute(STRING_DATA_TYPE);
assertThat(true,
is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET)));
@@ -122,7 +118,6 @@
*/
@Test
public void testForJavaClassDefClose() {
-
String interfaceDef = getJavaClassDefClose();
assertThat(true, is(interfaceDef.equals(CLOSE_CURLY_BRACKET)));
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index d4a51d8..edcc013 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -22,7 +22,7 @@
import org.junit.Test;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
@@ -30,7 +30,6 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getYangRevisionStr;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
@@ -79,7 +78,7 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -88,7 +87,6 @@
*/
@Test
public void getRootPackageTest() {
-
String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
@@ -99,7 +97,6 @@
*/
@Test
public void getRootPackageWithSpecialCharactersTest() {
-
String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1);
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
+ PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
@@ -113,7 +110,6 @@
*/
@Test
public void getRootPackageWithRevTest() {
-
String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2);
assertThat(rootPkgWithRev.equals(
DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
@@ -125,7 +121,6 @@
*/
@Test
public void getCapitalCaseTest() {
-
String capitalCase = getCaptialCase(WITHOUT_CAPITAL);
assertThat(capitalCase.equals(WITH_CAPITAL), is(true));
}
@@ -135,7 +130,6 @@
*/
@Test
public void getCamelCaseTest() {
-
String camelCase = getCamelCase(WITHOUT_CAMEL_CASE);
assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
}
@@ -145,7 +139,6 @@
*/
@Test
public void getSmallCaseTest() {
-
String smallCase = getSmallCase(WITHOUT_CAPITAL);
assertThat(smallCase.equals(WITH_SMALL), is(true));
}
@@ -155,7 +148,6 @@
*/
@Test
public void getPackageFromPathTest() {
-
String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE);
assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true));
}
@@ -165,18 +157,7 @@
*/
@Test
public void getPathFromPackageTest() {
-
String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD);
assertThat(path.equals(PARENT_PACKAGE), is(true));
}
-
- /**
- * Unit test for getting the camel case for the received string.
- */
- @Test
- public void getYangRevTest() {
-
- String rev = getYangRevisionStr(DATE1);
- assertThat(rev.equals(DATE_WITH_REV1), is(true));
- }
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index cf1a110..370df8d 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -25,7 +25,7 @@
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
@@ -108,7 +108,7 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -117,7 +117,6 @@
*/
@Test
public void getTypeDefConstructorTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String test = getTypeDefConstructor(testAttr, CLASS_NAME);
assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
@@ -128,7 +127,6 @@
*/
@Test
public void getBuildTest() {
-
String method = getBuild(CLASS_NAME);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
@@ -142,7 +140,6 @@
*/
@Test
public void getBuildForInterfaceTest() {
-
String method = getBuildForInterface(CLASS_NAME);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + CLASS_NAME + SPACE + BUILD +
OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE)));
@@ -153,7 +150,6 @@
*/
@Test
public void getCheckNotNullTest() {
-
String method = getCheckNotNull(CLASS_NAME);
assertThat(true, is(method.equals(EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS
+ CLASS_NAME + COMMA + SPACE + CLASS_NAME + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE)));
@@ -164,7 +160,6 @@
*/
@Test
public void getConstructorTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String method = getConstructor(CLASS_NAME, testAttr);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
@@ -176,7 +171,6 @@
*/
@Test
public void getConstructorStartTest() {
-
String method = getConstructorStart(CLASS_NAME);
assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
@@ -188,7 +182,6 @@
*/
@Test
public void getEqualsMethodTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String method = getEqualsMethod(testAttr);
assertThat(true, is(method.contains(SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD
@@ -200,7 +193,6 @@
*/
@Test
public void getToStringMethodTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String method = getToStringMethod(testAttr);
assertThat(true, is(method.equals(
@@ -213,7 +205,6 @@
*/
@Test
public void getGetterForClassTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String method = getGetterForClass(testAttr);
assertThat(true, is(method.contains(PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
@@ -224,7 +215,6 @@
*/
@Test
public void getGetterForInterfaceTest() {
-
String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false);
assertThat(true, is(method.contains(STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
}
@@ -234,7 +224,6 @@
*/
@Test
public void getSetterForClassTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(testAttr, CLASS_NAME);
assertThat(true, is(
@@ -248,7 +237,6 @@
*/
@Test
public void getSetterForInterfaceTest() {
-
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false);
assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
}
@@ -258,7 +246,6 @@
*/
@Test
public void getOfMethodest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String method = getOfMethod(CLASS_NAME, testAttr);
assertThat(true, is(method.contains(PUBLIC + SPACE + STATIC + SPACE + CLASS_NAME + SPACE + OF + OPEN_PARENTHESIS
@@ -270,7 +257,6 @@
*/
@Test
public void getSetterForTypeDefClassTest() {
-
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForTypeDefClass(testAttr);
assertThat(true, is(method.contains(PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX)));
@@ -281,7 +267,6 @@
*/
@Test
public void getOverRideStringTest() {
-
String method = getOverRideString();
assertThat(true, is(method.contains(OVERRIDE)));
}
@@ -292,7 +277,6 @@
* @return java attribute
*/
private JavaAttributeInfo getTestAttribute() {
-
JavaAttributeInfo testAttr = new JavaAttributeInfo(getTestYangType(), ATTRIBUTE_NAME, false, false);
testAttr.setAttributeName(ATTRIBUTE_NAME);
testAttr.setAttributeType(getTestYangType());
@@ -306,7 +290,6 @@
* @return java qualified info
*/
private JavaQualifiedTypeInfo getTestJavaQualifiedTypeInfo() {
-
JavaQualifiedTypeInfo info = new JavaQualifiedTypeInfo();
info.setPkgInfo(JAVA_LANG);
info.setClassInfo(STRING_DATA_TYPE);
@@ -319,7 +302,6 @@
* @return test YANG type
*/
private YangType<?> getTestYangType() {
-
YangType<?> attrType = new YangType<>();
attrType.setDataTypeName(STRING_DATA_TYPE);
attrType.setDataType(STRING);
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/UtilConstantsTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/UtilConstantsTest.java
index 6a02ca1..49347fb 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/UtilConstantsTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/UtilConstantsTest.java
@@ -16,12 +16,15 @@
package org.onosproject.yangutils.utils;
-import org.junit.Test;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import static org.junit.Assert.assertNotNull;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
/**
* Test case for testing the util constants.
@@ -43,13 +46,13 @@
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
- InstantiationException, IllegalAccessException, InvocationTargetException {
+ InstantiationException, IllegalAccessException, InvocationTargetException {
- Class<?>[] classesToConstruct = {UtilConstants.class};
+ Class<?>[] classesToConstruct = {UtilConstants.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
index f37805f..3950d56 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeaderTest.java
@@ -16,27 +16,24 @@
package org.onosproject.yangutils.utils.io.impl;
-import org.junit.Test;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertNotNull;
-import org.slf4j.Logger;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+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.
*/
@@ -59,47 +56,34 @@
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
- InstantiationException, IllegalAccessException, InvocationTargetException {
+ InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {CopyrightHeader.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
/**
* This test case checks the received copyright header contents.
+ *
+ * @throws IOException when fails to do IO operations
*/
@Test
public void testGetCopyrightHeader() throws IOException {
- CopyrightHeader.parseCopyrightHeader();
- String licenseHeader = CopyrightHeader.getCopyrightHeader();
- ClassLoader classLoader = CopyrightHeaderTest.class.getClassLoader();
+ String baseDir = System.getProperty("basedir");
+ String path = "/src/test/resources/CopyrightHeader.txt";
+
+ String licenseHeader = getCopyrightHeader();
File test = new File("target/TestCopyrightHeader.txt");
FileWriter out = new FileWriter(test);
out.write(licenseHeader);
out.close();
- File temp = new File("target/temp.txt");
- InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt");
- OutputStream outStream = new FileOutputStream(temp);
- int i;
- while ((i = stream.read()) != -1) {
- outStream.write(i);
- }
- outStream.close();
- stream.close();
-
- BufferedReader br1 = new BufferedReader(new FileReader(test));
- BufferedReader br2 = new BufferedReader(new FileReader(temp));
- while (br1.readLine() != null && br2.readLine() != null) {
- assertThat(true, is((br1.readLine()).equals(br2.readLine())));
- }
- br1.close();
- br2.close();
+ assertThat(true, is(contentEquals(test, new File(baseDir + path))));
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
index cfa1cf1..c353b6d 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
@@ -22,10 +22,16 @@
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
-import org.onosproject.yangutils.utils.UtilConstants;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+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.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.doesPackageExist;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
* Tests the file handle utilities.
@@ -57,7 +63,7 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -69,17 +75,17 @@
@Test
public void updateFileHandleTest() throws IOException {
- File dir = new File(BASE_PKG + File.separator + "File1");
+ File dir = new File(BASE_PKG + SLASH + "File1");
dir.mkdirs();
File createFile = new File(dir + "testFile");
createFile.createNewFile();
File createSourceFile = new File(dir + "sourceTestFile");
createSourceFile.createNewFile();
- FileSystemUtil.updateFileHandle(createFile, TEST_DATA_1, false);
- FileSystemUtil.updateFileHandle(createFile, TEST_DATA_2, false);
- FileSystemUtil.updateFileHandle(createFile, TEST_DATA_3, false);
- FileSystemUtil.appendFileContents(createFile, createSourceFile);
- FileSystemUtil.updateFileHandle(createFile, null, true);
+ updateFileHandle(createFile, TEST_DATA_1, false);
+ updateFileHandle(createFile, TEST_DATA_2, false);
+ updateFileHandle(createFile, TEST_DATA_3, false);
+ appendFileContents(createFile, createSourceFile);
+ updateFileHandle(createFile, null, true);
}
/**
@@ -92,12 +98,12 @@
String dirPath = "exist1.exist2.exist3";
String strPath = BASE_DIR_PKG + dirPath;
- File createDir = new File(strPath.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
+ File createDir = new File(strPath.replace(PERIOD, SLASH));
createDir.mkdirs();
- File createFile = new File(createDir + File.separator + "package-info.java");
+ File createFile = new File(createDir + SLASH + "package-info.java");
createFile.createNewFile();
- assertTrue(FileSystemUtil.doesPackageExist(strPath));
- FileSystemUtil.createPackage(strPath, PKG_INFO_CONTENT);
+ assertThat(true, is(doesPackageExist(strPath)));
+ createPackage(strPath, PKG_INFO_CONTENT);
createDir.delete();
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
index 4a1d8de..d0d7704 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
@@ -16,22 +16,37 @@
package org.onosproject.yangutils.utils.io.impl;
-import org.junit.Test;
-import org.junit.Rule;
-import org.junit.rules.ExpectedException;
-import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
-
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+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.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_DEF_SETTER_METHOD;
/**
* Tests the java doc that is generated.
*/
public final class JavaDocGenTest {
+ private static final String TEST_NAME = "testName";
+ private static final String END_STRING = " */\n";
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -40,10 +55,9 @@
*/
@Test
public void builderClassGenerationTest() {
-
- String builderClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_CLASS, "testGeneration1", false);
- assertTrue(builderClassJavaDoc.contains("Provides the builder implementation of")
- && builderClassJavaDoc.contains(" */\n"));
+ String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false);
+ assertThat(true, is(builderClassJavaDoc.contains("Reperesents the builder implementation of")
+ && builderClassJavaDoc.contains(END_STRING)));
}
/**
@@ -51,9 +65,9 @@
*/
@Test
public void builderInterfaceGenerationTest() {
-
- String builderInterfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILDER_INTERFACE, "testGeneration1", false);
- assertTrue(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(" */\n"));
+ String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false);
+ assertThat(true,
+ is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING)));
}
/**
@@ -61,9 +75,8 @@
*/
@Test
public void buildGenerationTest() {
-
- String buildDoc = JavaDocGen.getJavaDoc(JavaDocType.BUILD_METHOD, "testGeneration1", false);
- assertTrue(buildDoc.contains("Builds object of") && buildDoc.contains(" */\n"));
+ String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false);
+ assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING)));
}
/**
@@ -78,13 +91,13 @@
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
- InstantiationException, IllegalAccessException, InvocationTargetException {
+ InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaDocGen.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -93,12 +106,10 @@
*/
@Test
public void constructorGenerationTest() {
-
- String constructorDoc = JavaDocGen.getJavaDoc(JavaDocType.CONSTRUCTOR, "testGeneration1", false);
- assertTrue(
- constructorDoc.contains("Construct the object of") && constructorDoc.contains("builder object of")
- && constructorDoc.contains("@param") && constructorDoc.contains("*/\n"));
- JavaDocType.valueOf(JavaDocType.CONSTRUCTOR.toString());
+ String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false);
+ assertThat(true,
+ is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of")
+ && constructorDoc.contains("@param") && constructorDoc.contains("*/\n")));
}
/**
@@ -106,9 +117,9 @@
*/
@Test
public void defaultConstructorGenerationTest() {
-
- String defaultConstructorDoc = JavaDocGen.getJavaDoc(JavaDocType.DEFAULT_CONSTRUCTOR, "testGeneration1", false);
- assertTrue(defaultConstructorDoc.contains("Default Constructor") && defaultConstructorDoc.contains(" */\n"));
+ String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false);
+ assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ")
+ && defaultConstructorDoc.contains(END_STRING)));
}
/**
@@ -116,9 +127,8 @@
*/
@Test
public void getterGenerationTest() {
-
- String getterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.GETTER_METHOD, "testGeneration1", false);
- assertTrue(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(" */\n"));
+ String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false);
+ assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
}
/**
@@ -126,8 +136,10 @@
*/
@Test
public void implClassGenerationTest() {
- String implClassJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.IMPL_CLASS, "testGeneration1", false);
- assertTrue(implClassJavaDoc.contains("Provides the implementation of") && implClassJavaDoc.contains(" */\n"));
+ String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false);
+ assertThat(true,
+ is(implClassJavaDoc.contains("Reperesents the implementation of")
+ && implClassJavaDoc.contains(END_STRING)));
}
/**
@@ -135,10 +147,10 @@
*/
@Test
public void interfaceGenerationTest() {
-
- String interfaceJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.INTERFACE, "testGeneration1", false);
- assertTrue(interfaceJavaDoc.contains("Abstraction of an entity which provides functionalities of")
- && interfaceJavaDoc.contains(" */\n"));
+ String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false);
+ assertThat(true,
+ is(interfaceJavaDoc.contains("Abstraction of an entity which Reperesents the functionalities of")
+ && interfaceJavaDoc.contains(END_STRING)));
}
/**
@@ -146,9 +158,8 @@
*/
@Test
public void packageInfoGenerationTest() {
-
- String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1", false);
- assertTrue(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(" */\n"));
+ String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false);
+ assertThat(true, is(packageInfo.contains("Implementation of YANG file") && packageInfo.contains(END_STRING)));
}
/**
@@ -156,9 +167,9 @@
*/
@Test
public void setterGenerationTest() {
-
- String setterJavaDoc = JavaDocGen.getJavaDoc(JavaDocType.SETTER_METHOD, "testGeneration1", false);
- assertTrue(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(" */\n"));
+ String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false);
+ assertThat(true,
+ is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING)));
}
/**
@@ -166,8 +177,7 @@
*/
@Test
public void typeDefSetterGenerationTest() {
-
- String typeDefSetter = JavaDocGen.getJavaDoc(JavaDocType.TYPE_DEF_SETTER_METHOD, "testGeneration1", false);
- assertTrue(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(" */\n"));
+ String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false);
+ assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING)));
}
}
\ No newline at end of file
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
index 9ee02a9..6d1bede 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangFileScannerTest.java
@@ -28,10 +28,15 @@
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+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;
+
/**
* Test the file scanner service.
*/
@@ -62,23 +67,25 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
/**
* This test case checks for a .java file inside the specified dir.
+ *
+ * @throws IOException when fails to do IO operations
*/
@Test
public void checkJavaFileInsideDirTest() throws IOException {
- String dir = baseDir + File.separator + "scanner2";
+ String dir = baseDir + separator + "scanner2";
File path = createDirectory(dir);
createFile(path, "testScanner.java");
- List<String> dirContents = YangFileScanner.getJavaFiles(path.toString());
+ List<String> dirContents = getJavaFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
- expectedContents.add(path.getCanonicalPath() + File.separator + "testScanner.java");
- assertEquals(dirContents, expectedContents);
+ expectedContents.add(path.getCanonicalPath() + separator + "testScanner.java");
+ assertThat(true, is(dirContents.equals(expectedContents)));
}
/**
@@ -87,7 +94,7 @@
* @param path where directories should be created
* @return the directory path that is created
*/
- public File createDirectory(String path) {
+ private File createDirectory(String path) {
File myDir = new File(path);
myDir.mkdirs();
@@ -100,67 +107,59 @@
* @param myDir the path where file has to be created inside
* @param fileName the name of the file to be created
*/
- public void createFile(File myDir, String fileName) throws IOException {
+ private void createFile(File myDir, String fileName) throws IOException {
File file = null;
- file = new File(myDir + File.separator + fileName);
+ file = new File(myDir + separator + fileName);
file.createNewFile();
}
/**
* This testcase checks for a java file inside an empty directory.
+ *
+ * @throws IOException when fails to do IO operations
*/
@Test
public void emptyDirJavaScannerTest() throws IOException {
- String emptyDir = baseDir + File.separator + "scanner1";
+ String emptyDir = baseDir + separator + "scanner1";
File path = createDirectory(emptyDir);
- List<String> emptyDirContents = YangFileScanner.getJavaFiles(path.toString());
+ List<String> emptyDirContents = getJavaFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
- assertEquals(emptyDirContents, expectedContents);
+ assertThat(true, is(emptyDirContents.equals(expectedContents)));
}
/**
* This testcase checks for a yang file inside an empty directory.
+ *
+ * @throws IOException when fails to do IO operations
*/
@Test
public void emptyDirYangScannerTest() throws IOException {
- String emptyYangDir = baseDir + File.separator + "scanner1";
+ String emptyYangDir = baseDir + separator + "scanner1";
File path = createDirectory(emptyYangDir);
- List<String> emptyDirContents = YangFileScanner.getYangFiles(path.toString());
+ List<String> emptyDirContents = getYangFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
- assertEquals(emptyDirContents, expectedContents);
+ assertThat(true, is(emptyDirContents.equals(expectedContents)));
}
/**
* This test case checks with the sub directories in the given path for java files.
+ *
+ * @throws IOException when fails to do IO operations
*/
@Test
public void emptySubDirScannerTest() throws IOException {
- String dir = baseDir + File.separator + "scanner3";
+ String dir = baseDir + separator + "scanner3";
File path = createDirectory(dir);
- String subDir = path.toString() + File.separator + "subDir1";
+ String subDir = path.toString() + separator + "subDir1";
createDirectory(subDir);
createFile(path, "invalidFile.txt");
- List<String> emptySubDirContents = YangFileScanner.getJavaFiles(path.toString());
+ List<String> emptySubDirContents = getJavaFiles(path.toString());
List<String> expectedContents = new LinkedList<>();
- assertEquals(emptySubDirContents, expectedContents);
+ assertThat(true, is(emptySubDirContents.equals(expectedContents)));
}
- /**
- * This test case checks with the sub directories in the given path for java files.
-
- @Test
- public void exceptionHandleTest() throws IOException {
-
- String dir = baseDir + File.separator + "scanner4";
- thrown.expect(IOException.class);
- List<String> invalidContents = YangFileScanner.getJavaFiles(dir);
- File path = createDirectory(dir);
- createFile(path, "except.java");
- List<String> dirWithFileName = YangFileScanner
- .getJavaFiles(path + File.separator + "except.java" + File.separator + "scanner5");
- }*/
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
index 200a448..0c5b9fd 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
@@ -1,4 +1,3 @@
-
/*
* Copyright 2016 Open Networking Laboratory
*
@@ -31,7 +30,7 @@
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
@@ -40,7 +39,7 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
- * Unit tests for YANG io utils.
+ * Unit tests for YANG IO utils.
*/
public final class YangIoUtilsTest {
@@ -119,7 +118,7 @@
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
- assertNotNull(constructor.newInstance());
+ assertThat(null, not(constructor.newInstance()));
}
}
@@ -183,4 +182,5 @@
String test = trimAtLast(CHECK_STRING, "six");
assertThat(test.contains(TRIM_STRING), is(true));
}
+
}