[ONOS-5178] Defect fix :No get/set for root node in generated service
Change-Id: I9d90068e4cdd3d35a9ee71fd1f00c4a635b191b7
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index 5598561..02389a1 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -16,12 +16,9 @@
package org.onosproject.yangutils.parser.impl.listeners;
-import java.util.Date;
-
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
@@ -39,7 +36,6 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
@@ -117,14 +113,7 @@
Parsable tmpNode = listener.getParsedDataStack().peek();
if (!(tmpNode instanceof YangModule)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
- ctx.identifier().getText(), EXIT));
- }
-
- if (((YangModule) tmpNode).getRevision() == null) {
- Date currentDate = getCurrentDateForRevision();
- YangRevision currentRevision = new YangRevision();
- currentRevision.setRevDate(currentDate);
- ((YangModule) tmpNode).setRevision(currentRevision);
+ ctx.identifier().getText(), EXIT));
}
YangModule module = (YangModule) tmpNode;
@@ -132,7 +121,7 @@
&& module.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION).size() != 0
&& module.getChild() != null) {
throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, MODULE_DATA,
- ctx.identifier().getText(), EXIT));
+ ctx.identifier().getText(), EXIT));
}
try {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index b429e6d..d2c7347 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -16,11 +16,8 @@
package org.onosproject.yangutils.parser.impl.listeners;
-import java.util.Date;
-
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
@@ -40,7 +37,6 @@
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getCurrentDateForRevision;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
@@ -89,7 +85,7 @@
// Check if stack is empty.
checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
- ENTRY);
+ ENTRY);
String identifier = getValidIdentifier(ctx.identifier().getText(), SUB_MODULE_DATA, ctx);
@@ -118,19 +114,12 @@
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
- EXIT);
+ EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
if (!(tmpNode instanceof YangSubModule)) {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
- ctx.identifier().getText(), EXIT));
- }
-
- if (((YangSubModule) tmpNode).getRevision() == null) {
- Date currentDate = getCurrentDateForRevision();
- YangRevision currentRevision = new YangRevision();
- currentRevision.setRevDate(currentDate);
- ((YangSubModule) tmpNode).setRevision(currentRevision);
+ ctx.identifier().getText(), EXIT));
}
YangSubModule subModule = (YangSubModule) tmpNode;
@@ -138,7 +127,7 @@
&& subModule.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION).size() != 0
&& subModule.getChild() != null) {
throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, MODULE_DATA,
- ctx.identifier().getText(), EXIT));
+ ctx.identifier().getText(), EXIT));
}
try {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index f580da9..df1dcad 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -16,16 +16,6 @@
package org.onosproject.yangutils.parser.impl.parserutils;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Pattern;
-
import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -46,6 +36,16 @@
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Pattern;
+
import static org.onosproject.yangutils.datamodel.YangPathArgType.ABSOLUTE_PATH;
import static org.onosproject.yangutils.datamodel.YangPathArgType.RELATIVE_PATH;
import static org.onosproject.yangutils.datamodel.YangPathOperator.EQUALTO;
@@ -123,16 +123,16 @@
if (identifierString.length() > IDENTIFIER_LENGTH) {
parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifierString + " is " +
- "greater than 64 characters.");
+ getYangConstructType(yangConstruct) + " name " + identifierString + " is " +
+ "greater than 64 characters.");
} else if (!IDENTIFIER_PATTERN.matcher(identifierString).matches()) {
parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifierString + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " name " + identifierString + " is not " +
+ "valid.");
} else if (identifierString.toLowerCase().startsWith(XML)) {
parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " identifier " + identifierString +
- " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
+ getYangConstructType(yangConstruct) + " identifier " + identifierString +
+ " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
} else {
return identifierString;
}
@@ -159,16 +159,16 @@
if (identifierString.length() > IDENTIFIER_LENGTH) {
parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " +
- getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is " +
- "greater than 64 characters.");
+ getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is " +
+ "greater than 64 characters.");
} else if (!IDENTIFIER_PATTERN.matcher(identifierString).matches()) {
parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " +
- getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is not " +
+ "valid.");
} else if (identifierString.toLowerCase().startsWith(XML)) {
parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " +
- getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
+ getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
+ " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
} else {
return identifierString;
}
@@ -235,8 +235,8 @@
String value = removeQuotesAndHandleConcat(integerValue);
if (!value.matches(NON_NEGATIVE_INTEGER_PATTERN)) {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " value " + value + " is not " +
+ "valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -247,8 +247,8 @@
valueInInteger = Integer.parseInt(value);
} catch (NumberFormatException e) {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " value " + value + " is not " +
+ "valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -270,8 +270,8 @@
String value = removeQuotesAndHandleConcat(integerValue);
if (!INTEGER_PATTERN.matcher(value).matches()) {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " value " + value + " is not " +
+ "valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -282,8 +282,8 @@
valueInInteger = Integer.parseInt(value);
} catch (NumberFormatException e) {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " value " + value + " is not " +
+ "valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -309,8 +309,8 @@
return false;
} else {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " value " + value + " is not " +
+ "valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -361,8 +361,8 @@
return nodeIdentifier;
} else {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + nodeIdentifierString +
- " is not valid.");
+ getYangConstructType(yangConstruct) + " name " + nodeIdentifierString +
+ " is not valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -395,8 +395,8 @@
return nodeIdentifier;
} else {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
- " is not valid.");
+ getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
+ " is not valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -419,7 +419,7 @@
if (completePathString.startsWith(SLASH)) {
yangLeafRef.setPathType(ABSOLUTE_PATH);
List<YangAtomicPath> yangAtomicPathListList = validateAbsolutePath(completePathString, yangConstruct, ctx,
- yangLeafRef);
+ yangLeafRef);
validatePrefixAndYangNode(yangAtomicPathListList, yangLeafRef);
yangLeafRef.setAtomicPath(yangAtomicPathListList);
} else if (completePathString.startsWith(ANCESTOR_ACCESSOR)) {
@@ -427,8 +427,8 @@
validateRelativePath(completePathString, yangConstruct, ctx, yangLeafRef);
} else {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
- " does not follow valid path syntax");
+ getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
+ " does not follow valid path syntax");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -522,7 +522,7 @@
atomicPath.add(yangAtomicPathPath);
if (nodeIdentifier.getPrefix() != null && nodeIdentifier.getPrefix() != prefixOfFile) {
ParserException parserException = new ParserException("YANG file error : A leaf reference, in unique," +
- " must refer to a leaf in the list");
+ " must refer to a leaf in the list");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -557,8 +557,8 @@
}
if (leaf == null) {
ParserException parserException = new ParserException("YANG file error : A leaf reference, in " +
- "unique," +
- " must refer to a leaf under the list");
+ "unique," +
+ " must refer to a leaf under the list");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -582,10 +582,10 @@
while (nodesInReference.hasNext()) {
YangAtomicPath nodeInUnique = nodesInReference.next();
YangNode referredNode = getReferredNodeFromTheUniqueNodes(nodeInUnique.getNodeIdentifier(),
- potentialReferredNode);
+ potentialReferredNode);
if (referredNode == null) {
ParserException parserException = new ParserException("YANG file error : The target node in unique " +
- "reference path is invalid");
+ "reference path is invalid");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -678,16 +678,16 @@
}
if (completePathString == null || completePathString.length() == 0) {
ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
- " does not follow valid path syntax");
+ + getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
+ " does not follow valid path syntax");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
relativePath.setAncestorNodeCount(numberOfAncestors);
List<YangAtomicPath> atomicPath = validateAbsolutePath(SLASH_FOR_STRING + completePathString,
- yangConstruct,
- ctx, yangLeafRef);
+ yangConstruct,
+ ctx, yangLeafRef);
validatePrefixAndYangNode(atomicPath, yangLeafRef);
relativePath.setAtomicPathList(atomicPath);
yangLeafRef.setRelativePath(relativePath);
@@ -714,8 +714,8 @@
String path = completePathString.replaceFirst(SLASH_FOR_STRING, EMPTY_STRING);
if (path == null || path.length() == 0) {
ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " does not follow valid path syntax");
+ + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
+ " does not follow valid path syntax");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -733,8 +733,8 @@
if (matchedPathPredicate == null || matchedPathPredicate.length() == 0) {
ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " does not follow valid path syntax");
+ + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
+ " does not follow valid path syntax");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -763,7 +763,7 @@
}
List<YangPathPredicate> pathPredicateList = validatePathPredicate(pathPredicate, yangConstruct, ctx,
- yangPathPredicate, yangLeafRef);
+ yangPathPredicate, yangLeafRef);
YangAtomicPath atomicPath = new YangAtomicPath();
yangNodeIdentifier = getValidNodeIdentifierForLeafref(nodeIdentifier, yangConstruct, ctx, yangLeafRef);
atomicPath.setNodeIdentifier(yangNodeIdentifier);
@@ -815,11 +815,11 @@
String pathPredicateForNode = pathPredicateString.next();
pathPredicateForNode = (pathPredicateForNode.substring(1)).trim();
pathPredicateForNode = pathPredicateForNode.substring(0,
- pathPredicateForNode.indexOf(CHAR_OF_CLOSE_SQUARE_BRACKET));
+ pathPredicateForNode.indexOf(CHAR_OF_CLOSE_SQUARE_BRACKET));
pathEqualityExpression.add(pathPredicateForNode);
}
List<YangPathPredicate> validatedPathPredicateList = validatePathEqualityExpression(pathEqualityExpression,
- yangConstruct, ctx, yangPathPredicate, yangLeafRef);
+ yangConstruct, ctx, yangPathPredicate, yangLeafRef);
return validatedPathPredicateList;
}
@@ -849,9 +849,9 @@
YangNodeIdentifier yangNodeIdentifierForPredicate;
YangRelativePath yangRelativePath;
yangNodeIdentifierForPredicate = getValidNodeIdentifierForLeafref(pathEqualityExpressionArray[0].trim(),
- yangConstruct, ctx, yangLeafRef);
+ yangConstruct, ctx, yangLeafRef);
yangRelativePath = validatePathKeyExpression(pathEqualityExpressionArray[1].trim(), yangConstruct, ctx,
- yangLeafRef);
+ yangLeafRef);
yangPathPredicate.setNodeIdentifier(yangNodeIdentifierForPredicate);
yangPathPredicate.setPathOperator(EQUALTO);
yangPathPredicate.setRightRelativePath(yangRelativePath);
@@ -885,7 +885,7 @@
}
}
List<YangAtomicPath> atomicPathInRelativePath = validateRelativePathKeyExpression(rightAbsolutePath,
- yangConstruct, ctx, yangLeafRef);
+ yangConstruct, ctx, yangLeafRef);
yangRelativePath.setAtomicPathList(atomicPathInRelativePath);
yangRelativePath.setAncestorNodeCount(accessAncestor);
return yangRelativePath;
@@ -915,8 +915,8 @@
if (!(currentFunction[0].trim().equals(CURRENT)) || !(currentFunction[1].trim().equals(CLOSE_PARENTHESIS))) {
ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " does not follow valid path syntax");
+ + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
+ " does not follow valid path syntax");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -967,8 +967,8 @@
// absolute-schema-nodeid = 1*("/" node-identifier)
if (!tmpSchemaNodeId.startsWith(SLASH)) {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstructType) + " name " + argumentString +
- "is not valid");
+ getYangConstructType(yangConstructType) + " name " + argumentString +
+ "is not valid");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -999,7 +999,7 @@
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
log.info(parserException.getMessage() + " at position " + parserException.getCharPositionInLine() +
- " in line " + parserException.getLineNumber() + " of yang file " + fileName);
+ " in line " + parserException.getLineNumber() + " of yang file " + fileName);
}
/**
@@ -1011,7 +1011,7 @@
*/
public static Date getValidDateFromString(String dateInString, ParserRuleContext ctx) {
String dateArgument = removeQuotesAndHandleConcat(dateInString);
- if (dateArgument == null || !dateArgument.matches(DATE_PATTERN)) {
+ if (!dateArgument.matches(DATE_PATTERN)) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
@@ -1023,8 +1023,7 @@
try {
//if not valid, it will throw ParseException
- Date date = sdf.parse(dateArgument);
- return date;
+ return sdf.parse(dateArgument);
} catch (ParseException e) {
ParserException parserException = new ParserException("YANG file error: Input date is not correct");
parserException.setLine(ctx.getStart().getLine());
@@ -1049,8 +1048,8 @@
return tmpData[0];
} else {
ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + inputString +
- " is not valid.");
+ getYangConstructType(yangConstruct) + " name " + inputString +
+ " is not valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index d89eee4..e661c32 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -254,7 +254,7 @@
throws IOException {
try {
List<YangNode> interJarResolvedNodes = resolveInterJarDependencies(project, localRepository,
- remoteRepository, getDirectory(baseDir, outputDirectory));
+ remoteRepository, getDirectory(baseDir, outputDirectory));
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
node.setToTranslate(false);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index e20d788..1d566d8 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -395,7 +395,7 @@
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
+ getJavaFileInfo().getPackageFilePath()));
/*
* Initialize getter when generation file type matches to interface
@@ -526,8 +526,9 @@
YangNode parent = getParentNodeInGenCode(curNode);
if (!(parent instanceof JavaCodeGenerator)) {
throw new TranslatorException("missing parent node to contain current node info in generated file "
- + parent.getName() + " in " + parent.getLineNumber() + " at " + parent.getCharPosition()
- + " in " + parent.getFileName());
+ + parent.getName() + " in " + parent.getLineNumber() + " at " +
+ parent.getCharPosition()
+ + " in " + parent.getFileName());
}
if (parent instanceof YangJavaGroupingTranslator) {
@@ -542,7 +543,7 @@
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
- parent, isList, tempJavaBeanFragmentFiles);
+ parent, isList, tempJavaBeanFragmentFiles);
tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
}
@@ -569,11 +570,12 @@
* generated java files or qualified access
*/
JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
- getCapitalCase(curNodeName));
+ getCapitalCase(curNodeName));
if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
throw new TranslatorException("Parent node does not have file info "
- + targetNode.getName() + " in " + targetNode.getLineNumber() + " at " + targetNode.getCharPosition()
- + " in " + targetNode.getFileName());
+ + targetNode.getName() + " in " + targetNode.getLineNumber() +
+ " at " + targetNode.getCharPosition()
+ + " in " + targetNode.getFileName());
}
JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
@@ -593,7 +595,7 @@
}
isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
- className, fileInfo.getPackage());
+ className, fileInfo.getPackage());
}
boolean collectionSetFlag = false;
if (curNode instanceof YangList) {
@@ -622,7 +624,7 @@
}
if (curNode instanceof YangList) {
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
- ((YangList) curNode).getCompilerAnnotation());
+ ((YangList) curNode).getCompilerAnnotation());
}
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
}
@@ -1050,7 +1052,7 @@
private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
throws IOException {
appendToFile(getSubtreeFilteringForLeafTempFileHandle(),
- getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) + NEW_LINE);
+ getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) + NEW_LINE);
}
/**
@@ -1062,7 +1064,7 @@
private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
throws IOException {
appendToFile(getGetSubtreeFilteringForListTempFileHandle(),
- getSubtreeFilteringForLeafList(attr) + NEW_LINE);
+ getSubtreeFilteringForLeafList(attr) + NEW_LINE);
}
/**
@@ -1074,7 +1076,7 @@
private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
throws IOException {
appendToFile(getGetSubtreeFilteringForChildNodeTempFileHandle(),
- getSubtreeFilteringForNode(attr) + NEW_LINE);
+ getSubtreeFilteringForNode(attr) + NEW_LINE);
}
/**
@@ -1100,7 +1102,7 @@
private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getGetterInterfaceTempFileHandle(),
- getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
+ getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
}
/**
@@ -1113,8 +1115,8 @@
private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getSetterInterfaceTempFileHandle(),
- getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
- + NEW_LINE);
+ getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
+ + NEW_LINE);
}
/**
@@ -1127,7 +1129,7 @@
throws IOException {
if (isRooNode()) {
appendToFile(getSetterImplTempFileHandle(), getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
- attr.isListAttr(), pluginConfig, null) +
+ attr.isListAttr(), pluginConfig, null) +
getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
+ NEW_LINE);
} else {
@@ -1150,10 +1152,11 @@
|| (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
if (!isRooNode()) {
appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
- getGeneratedJavaFiles()) + NEW_LINE);
+ getGeneratedJavaFiles()) +
+ NEW_LINE);
} else {
appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr,
- getGeneratedJavaFiles()) + NEW_LINE);
+ getGeneratedJavaFiles()) + NEW_LINE);
}
} else {
String appDataStructure = null;
@@ -1161,8 +1164,8 @@
appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
}
appendToFile(getGetterImplTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
- appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
+ appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
}
}
@@ -1176,8 +1179,8 @@
private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getAddToListInterfaceTempFileHandle(),
- getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
- + getAddToListMethodInterface(attr, getGeneratedJavaClassName()) + NEW_LINE);
+ getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
+ + getAddToListMethodInterface(attr, getGeneratedJavaClassName()) + NEW_LINE);
}
/**
@@ -1189,7 +1192,7 @@
private void addAddToListImpl(JavaAttributeInfo attr)
throws IOException {
appendToFile(getAddToListImplTempFileHandle(),
- getAddToListMethodImpl(attr, getGeneratedJavaClassName(), isRooNode()) + NEW_LINE);
+ getAddToListMethodImpl(attr, getGeneratedJavaClassName(), isRooNode()) + NEW_LINE);
}
/**
@@ -1203,8 +1206,8 @@
private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig)
throws IOException {
appendToFile(getLeafIdAttributeTempFileHandle(),
- FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
- value, yangPluginConfig));
+ FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
+ value, yangPluginConfig));
}
/**
@@ -1247,7 +1250,7 @@
name = name + OP_PARAM;
return NEW_LINE
+ getDefaultConstructorString(name, modifier,
- pluginConfig);
+ pluginConfig);
}
if (isSuffix) {
return NEW_LINE +
@@ -1261,7 +1264,7 @@
}
return NEW_LINE
+ getDefaultConstructorString(appended + name, modifier,
- pluginConfig);
+ pluginConfig);
}
/**
@@ -1308,7 +1311,7 @@
JavaAttributeInfo fromStringAttributeInfo)
throws IOException {
appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
- fromStringAttributeInfo) + NEW_LINE);
+ fromStringAttributeInfo) + NEW_LINE);
}
/**
@@ -1337,7 +1340,7 @@
}
} else {
throw new IOException(fileName + " is reused due to YANG naming. probably your previous build would have " +
- "failed");
+ "failed");
}
return file;
}
@@ -1369,7 +1372,7 @@
return readAppendFile(path + file.getName(), EMPTY_STRING);
} else {
throw new IOException("Unable to get data from the given "
- + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
+ + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
}
}
@@ -1402,11 +1405,12 @@
}
if (attr.isQualifiedName()) {
return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
- attr.getImportInfo().getClassInfo(),
- attributeName, attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
+ attr.getImportInfo().getClassInfo(),
+ attributeName, attr.isListAttr(), attributeAccessType,
+ attr.getCompilerAnnotation());
} else {
return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
- attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
+ attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
}
}
@@ -1443,19 +1447,21 @@
}
if (!(curNode instanceof JavaFileInfoContainer)) {
throw new TranslatorException("missing java file information to get the package details "
- + "of attribute corresponding to child node " +
- curNode.getName() + " in " + curNode.getLineNumber() + " at " + curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ + "of attribute corresponding to child node " +
+ curNode.getName() + " in " + curNode.getLineNumber() + " at " +
+ curNode.getCharPosition()
+ + " in " + curNode.getFileName());
}
caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
- pluginConfig.getConflictResolver())));
+ pluginConfig.getConflictResolver())));
caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
- getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
+ getCapitalCase(fileInfo.getJavaName()),
+ fileInfo.getPackage());
}
/**
@@ -1473,18 +1479,18 @@
for (YangLeaf leaf : listOfLeaves) {
if (!(leaf instanceof JavaLeafInfoContainer)) {
throw new TranslatorException("Leaf does not have java information " +
- leaf.getName() + " in " + leaf.getLineNumber() + " at " +
- leaf.getCharPosition()
- + " in " + leaf.getFileName());
+ leaf.getName() + " in " + leaf.getLineNumber() + " at " +
+ leaf.getCharPosition()
+ + " in " + leaf.getFileName());
}
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf,
- yangPluginConfig), yangPluginConfig);
+ yangPluginConfig), yangPluginConfig);
} else {
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
- yangPluginConfig);
+ yangPluginConfig);
}
}
}
@@ -1505,17 +1511,20 @@
for (YangLeafList leafList : listOfLeafList) {
if (!(leafList instanceof JavaLeafInfoContainer)) {
throw new TranslatorException("Leaf-list does not have java information " +
- curNode.getName() + " in " + curNode.getLineNumber() + " at " + curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ curNode.getName() + " in " + curNode.getLineNumber() +
+ " at " + curNode.getCharPosition()
+ + " in " + curNode.getFileName());
}
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles,
- leafList, yangPluginConfig), yangPluginConfig);
+ leafList, yangPluginConfig),
+ yangPluginConfig);
} else {
addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this,
- leafList, yangPluginConfig), yangPluginConfig);
+ leafList, yangPluginConfig),
+ yangPluginConfig);
}
}
}
@@ -1533,8 +1542,9 @@
throws IOException {
if (!(curNode instanceof YangLeavesHolder)) {
throw new TranslatorException("Data model node does not have any leaves " +
- curNode.getName() + " in " + curNode.getLineNumber() + " at " + curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ curNode.getName() + " in " + curNode.getLineNumber() + " at " +
+ curNode.getCharPosition()
+ + " in " + curNode.getFileName());
}
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode);
@@ -1606,15 +1616,18 @@
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
- pluginConfig.getConflictResolver());
+ pluginConfig
+ .getConflictResolver());
/*
* Create a new java attribute info with qualified information of
* wrapper classes.
*/
JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
- newAttrInfo.getAttributeName(),
- newAttrInfo.getAttributeType(),
- getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
+ newAttrInfo.getAttributeName(),
+ newAttrInfo.getAttributeType(),
+ getIsQualifiedAccessOrAddToImportList(
+ qualifiedInfoOfFromString),
+ false);
addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
}
@@ -1685,7 +1698,7 @@
getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
setBuilderInterfaceJavaFileHandle(
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
- isAttributePresent()));
+ isAttributePresent()));
//Append builder interface file to interface file and close it.
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
@@ -1728,7 +1741,7 @@
setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
setBuilderClassJavaFileHandle(
generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
- isAttributePresent()));
+ isAttributePresent()));
//Append impl class to builder class and close it.
mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
@@ -1880,8 +1893,8 @@
boolean getIsQualifiedAccessOrAddToImportList(
JavaQualifiedTypeInfo importInfo) {
return getJavaImportData().addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
- getGeneratedJavaClassName(),
- getJavaFileInfo().getPackage());
+ getGeneratedJavaClassName(),
+ getJavaFileInfo().getPackage());
}
/**
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
index 08a6d9b..7891b08 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
@@ -26,10 +26,8 @@
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangTranslatorOperatorNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
@@ -77,9 +75,9 @@
} else {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
- yangPluginConfig.getConflictResolver()));
+ yangPluginConfig.getConflictResolver()));
javaCodeGeneratorInfo.getJavaFileInfo().setJavaAttributeName(javaCodeGeneratorInfo
- .getJavaFileInfo().getJavaName());
+ .getJavaFileInfo().getJavaName());
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
}
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
@@ -102,7 +100,7 @@
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getAugmentClassName((YangJavaAugmentTranslator) javaCodeGeneratorInfo,
- yangPluginConfig));
+ yangPluginConfig));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(
getAugmentsNodePackage((YangNode) javaCodeGeneratorInfo, yangPluginConfig));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
@@ -141,10 +139,11 @@
* @throws IOException IO operations fails
*/
private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
- String pkg) throws IOException {
+ String pkg)
+ throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
- yangPlugin.getConflictResolver()));
+ yangPlugin.getConflictResolver()));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
@@ -174,12 +173,8 @@
YangPluginConfig yangPluginConfig)
throws IOException {
- if (javaCodeGeneratorInfo instanceof YangModule
- || javaCodeGeneratorInfo instanceof YangSubModule) {
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().setRooNode(true);
- }
-
if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().setRooNode(true);
/*
* Module / sub module node code generation.
*/
@@ -228,9 +223,9 @@
/*Do nothing, only the interface needs to be generated*/
} else {
throw new TranslatorException("Unsupported Node Translation "
- + javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ + javaCodeGeneratorInfo.getLineNumber() + " at " +
+ javaCodeGeneratorInfo.getCharPosition()
+ + " in " + javaCodeGeneratorInfo.getFileName());
}
}
@@ -246,9 +241,9 @@
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("translation is not supported for the node "
- + javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ + javaCodeGeneratorInfo.getLineNumber() + " at " +
+ javaCodeGeneratorInfo.getCharPosition()
+ + " in " + javaCodeGeneratorInfo.getFileName());
}
createTempFragmentFile(javaCodeGeneratorInfo);
updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig);
@@ -295,9 +290,9 @@
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("Invalid node for translation " +
- javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ javaCodeGeneratorInfo.getLineNumber() + " at " +
+ javaCodeGeneratorInfo.getCharPosition()
+ + " in " + javaCodeGeneratorInfo.getFileName());
}
/*
@@ -323,9 +318,9 @@
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("invalid node for translation " +
- javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ javaCodeGeneratorInfo.getLineNumber() + " at " +
+ javaCodeGeneratorInfo.getCharPosition()
+ + " in " + javaCodeGeneratorInfo.getFileName());
}
generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
@@ -336,7 +331,7 @@
JavaQualifiedTypeInfoTranslator parentsInfo = getQualifierInfoForCasesParent(parent, yangPlugin);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo,
- tempJavaCodeFragmentFiles.getBeanTempFiles());
+ tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
.addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
@@ -388,9 +383,9 @@
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("invalid node for translation "
- + javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ + javaCodeGeneratorInfo.getLineNumber() + " at " +
+ javaCodeGeneratorInfo.getCharPosition()
+ + " in " + javaCodeGeneratorInfo.getFileName());
}
updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig);
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
@@ -409,9 +404,9 @@
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("invalid node for translation " + javaCodeGeneratorInfo.getLineNumber()
- + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ + " at " +
+ javaCodeGeneratorInfo.getCharPosition()
+ + " in " + javaCodeGeneratorInfo.getFileName());
}
updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg);
@@ -434,19 +429,19 @@
if (!(curNode instanceof JavaFileInfoContainer)
|| curNode.getParent() == null) {
throw new TranslatorException("missing parent node to get current node's package " +
- curNode.getName() + " in " +
- curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ curNode.getName() + " in " +
+ curNode.getLineNumber() + " at " +
+ curNode.getCharPosition()
+ + " in " + curNode.getFileName());
}
YangNode parentNode = DataModelUtils.getParentNodeInGenCode(curNode);
if (!(parentNode instanceof JavaFileInfoContainer)) {
throw new TranslatorException("missing parent java node to get current node's package " +
- curNode.getName() + " in " +
- curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ curNode.getName() + " in " +
+ curNode.getLineNumber() + " at " +
+ curNode.getCharPosition()
+ + " in " + curNode.getFileName());
}
JavaFileInfoTranslator parentJavaFileHandle = ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
@@ -460,49 +455,57 @@
* @return true if root node contains any data node
*/
public static boolean isRootNodesCodeGenRequired(YangNode node) {
+ YangLeavesHolder holder = (YangLeavesHolder) node;
- List<YangNode> childNodes = new ArrayList<>();
- YangNode tempNode = node.getChild();
- while (tempNode != null) {
- childNodes.add(tempNode);
- tempNode = tempNode.getNextSibling();
- }
-
- if (childNodes.size() == 0) {
- YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
- return !leavesHolder.getListOfLeaf().isEmpty() || !leavesHolder.getListOfLeafList().isEmpty();
- } else if (childNodes.size() == 1) {
- return !(childNodes.get(0) instanceof YangTranslatorOperatorNode);
- }
- List<Boolean> booleanData = new ArrayList<>();
- for (YangNode child : childNodes) {
- if (child instanceof YangTranslatorOperatorNode) {
- booleanData.add(false);
+ if (holder.getListOfLeaf().isEmpty()) {
+ if (holder.getListOfLeafList().isEmpty()) {
+ YangNode tempNode = node.getChild();
+ if (tempNode == null) {
+ return false;
+ }
+ while (tempNode != null) {
+ if (!(tempNode instanceof YangTranslatorOperatorNode)) {
+ return true;
+ }
+ tempNode = tempNode.getNextSibling();
+ }
+ return false;
} else {
- booleanData.add(true);
+ return true;
}
+ } else {
+ return true;
}
- return booleanData.contains(true);
}
/**
- * Returns true if only augment nodes present in module.
+ * Returns true if get/set method of root node are required.
*
* @param curNode root node
- * @return true if only augment nodes present in module
+ * @return true if get/set method of root node are required
*/
- public static boolean isOnlyAugmentNodeInRoot(YangNode curNode) {
- List<Boolean> booleanData = new ArrayList<>();
- curNode = curNode.getChild();
- while (curNode != null) {
- if (curNode instanceof YangAugment) {
- booleanData.add(true);
+ public static boolean isGetSetOfRootNodeRequired(YangNode curNode) {
+ YangLeavesHolder holder = (YangLeavesHolder) curNode;
+
+ if (holder.getListOfLeaf().isEmpty()) {
+ if (holder.getListOfLeafList().isEmpty()) {
+ curNode = curNode.getChild();
+ if (curNode == null) {
+ return false;
+ }
+ while (curNode != null) {
+ if (!(curNode instanceof YangAugment)) {
+ return true;
+ }
+ curNode = curNode.getNextSibling();
+ }
+ return false;
} else {
- booleanData.add(false);
+ return true;
}
- curNode = curNode.getNextSibling();
+ } else {
+ return true;
}
- return !booleanData.contains(false);
}
/**
@@ -528,12 +531,12 @@
if (node instanceof YangJavaModuleTranslator) {
YangJavaModuleTranslator module = (YangJavaModuleTranslator) node;
pkg.append(getRootPackage(module.getVersion(), module.getNameSpace(), module
- .getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
+ .getRevision(), yangPluginConfig.getConflictResolver()));
} else if (node instanceof YangJavaSubModuleTranslator) {
YangJavaSubModuleTranslator subModule = (YangJavaSubModuleTranslator) node;
pkg.append(getRootPackage(subModule.getVersion(),
- subModule.getNameSpaceFromModule(subModule.getBelongsTo()),
- subModule.getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
+ subModule.getNameSpaceFromModule(),
+ subModule.getRevision(), yangPluginConfig.getConflictResolver()));
}
String concat = "";
for (int i = 1; i <= clsInfo.size(); i++) {
@@ -551,7 +554,7 @@
* @param yangPluginConfig plugin configurations
* @return augment class name
*/
- static String getAugmentClassName(YangAugment augment, YangPluginConfig yangPluginConfig) {
+ private static String getAugmentClassName(YangAugment augment, YangPluginConfig yangPluginConfig) {
YangNodeIdentifier yangNodeIdentifier = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
.getNodeIdentifier();
String name = getCapitalCase(getCamelCase(yangNodeIdentifier.getName(), yangPluginConfig
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
index 85c190b..d9517a8 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -112,10 +112,10 @@
return getJavaDataType(getReferredTypeFromLeafref(yangType));
default:
throw new TranslatorException("given data type is not supported. " +
- yangType.getDataTypeName() + " in " +
- yangType.getLineNumber() + " at " +
- yangType.getCharPosition()
- + " in " + yangType.getFileName());
+ yangType.getDataTypeName() + " in " +
+ yangType.getLineNumber() + " at " +
+ yangType.getCharPosition()
+ + " in " + yangType.getFileName());
}
}
@@ -159,7 +159,7 @@
case ENUMERATION:
return getCapitalCase(
getCamelCase(((YangJavaEnumerationTranslator) yangType.getDataTypeExtendedInfo()).getName(),
- pluginConfig));
+ pluginConfig));
case BITS:
return BIT_SET;
case BINARY:
@@ -184,10 +184,10 @@
getCamelCase(yangType.getDataTypeName(), pluginConfig));
default:
throw new TranslatorException("given data type is not supported ." +
- yangType.getDataTypeName() + " in " +
- yangType.getLineNumber() + " at " +
- yangType.getCharPosition()
- + " in " + yangType.getFileName());
+ yangType.getDataTypeName() + " in " +
+ yangType.getLineNumber() + " at " +
+ yangType.getCharPosition()
+ + " in " + yangType.getFileName());
}
} else {
switch (type) {
@@ -198,7 +198,7 @@
case ENUMERATION:
return getCapitalCase(
getCamelCase(((YangJavaEnumerationTranslator) yangType.getDataTypeExtendedInfo()).getName(),
- pluginConfig));
+ pluginConfig));
case BITS:
return BIT_SET;
case DECIMAL64:
@@ -273,10 +273,10 @@
return getTypeDefsPackage(yangType, conflictResolver);
default:
throw new TranslatorException("given data type is not supported. " +
- yangType.getDataTypeName() + " in " +
- yangType.getLineNumber() + " at " +
- yangType.getCharPosition()
- + " in " + yangType.getFileName());
+ yangType.getDataTypeName() + " in " +
+ yangType.getLineNumber() + " at " +
+ yangType.getCharPosition()
+ + " in " + yangType.getFileName());
}
} else {
switch (type) {
@@ -318,18 +318,18 @@
Object var = type.getDataTypeExtendedInfo();
if (!(var instanceof YangDerivedInfo)) {
throw new TranslatorException("type should have been derived. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
+ type.getDataTypeName() + " in " +
+ type.getLineNumber() + " at " +
+ type.getCharPosition()
+ + " in " + type.getFileName());
}
if (!(((YangDerivedInfo<?>) var).getReferredTypeDef() != null)) {
throw new TranslatorException("derived info is not an instance of typedef. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
+ type.getDataTypeName() + " in " +
+ type.getLineNumber() + " at " +
+ type.getCharPosition()
+ + " in " + type.getFileName());
}
YangJavaTypeDefTranslator typedef = (YangJavaTypeDefTranslator) ((YangDerivedInfo<?>) var).getReferredTypeDef();
@@ -350,10 +350,10 @@
if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) {
throw new TranslatorException("type should have been union. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
+ type.getDataTypeName() + " in " +
+ type.getLineNumber() + " at " +
+ type.getCharPosition()
+ + " in " + type.getFileName());
}
YangJavaUnionTranslator union = (YangJavaUnionTranslator) type.getDataTypeExtendedInfo();
@@ -374,10 +374,10 @@
if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) {
throw new TranslatorException("type should have been enumeration. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
+ type.getDataTypeName() + " in " +
+ type.getLineNumber() + " at " +
+ type.getCharPosition()
+ + " in " + type.getFileName());
}
YangJavaEnumerationTranslator enumeration = (YangJavaEnumerationTranslator) type.getDataTypeExtendedInfo();
if (enumeration.getJavaFileInfo().getPackage() == null) {
@@ -397,10 +397,10 @@
if (!(type.getDataTypeExtendedInfo() instanceof YangIdentityRef)) {
throw new TranslatorException("type should have been identityref. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
+ type.getDataTypeName() + " in " +
+ type.getLineNumber() + " at " +
+ type.getCharPosition()
+ + " in " + type.getFileName());
}
YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
YangJavaIdentityTranslator identity = (YangJavaIdentityTranslator) (identityRef.getReferredIdentity());
@@ -421,10 +421,10 @@
YangToJavaNamingConflictUtil conflictResolver) {
if (!(parent instanceof JavaFileInfoContainer)) {
throw new TranslatorException("invalid child node is being processed. " +
- parent.getName() + " in " +
- parent.getLineNumber() + " at " +
- parent.getCharPosition()
- + " in " + parent.getFileName());
+ parent.getName() + " in " +
+ parent.getLineNumber() + " at " +
+ parent.getCharPosition()
+ + " in " + parent.getFileName());
}
JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
if (parentInfo.getPackage() == null) {
@@ -464,18 +464,18 @@
if (yangNode instanceof YangJavaModuleTranslator) {
YangJavaModuleTranslator module = (YangJavaModuleTranslator) yangNode;
pkg = getRootPackage(module.getVersion(), module.getNameSpace(), module
- .getRevision().getRevDate(), conflictResolver);
+ .getRevision(), conflictResolver);
} else if (yangNode instanceof YangJavaSubModuleTranslator) {
YangJavaSubModuleTranslator submodule = (YangJavaSubModuleTranslator) yangNode;
pkg = getRootPackage(submodule.getVersion(),
- submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
- submodule.getRevision().getRevDate(), conflictResolver);
+ submodule.getNameSpaceFromModule(),
+ submodule.getRevision(), conflictResolver);
} else {
throw new TranslatorException("Invalid root node of data model tree " +
- yangNode.getName() + " in " +
- yangNode.getLineNumber() + " at " +
- yangNode.getCharPosition()
- + " in " + yangNode.getFileName());
+ yangNode.getName() + " in " +
+ yangNode.getLineNumber() + " at " +
+ yangNode.getCharPosition()
+ + " in " + yangNode.getFileName());
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
index cf1f455..6a6ac26 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
@@ -36,6 +36,7 @@
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.removeEmptyDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
@@ -77,10 +78,10 @@
public JavaFileInfoTranslator getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName());
}
return (JavaFileInfoTranslator) javaFileInfo;
}
@@ -122,13 +123,14 @@
* @throws TranslatorException when fails to generate the source files
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- String modulePkg = getRootPackage(getVersion(), getNameSpace(), getRevision().getRevDate(),
- yangPlugin.getConflictResolver());
+ public void generateCodeEntry(YangPluginConfig yangPlugin)
+ throws TranslatorException {
+ String modulePkg = getRootPackage(getVersion(), getNameSpace(), getRevision(),
+ yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
- | GENERATE_ALL_EVENT_CLASS_MASK);
+ | GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, modulePkg);
@@ -146,7 +148,8 @@
* Creates a java file using the YANG module info.
*/
@Override
- public void generateCodeExit() throws TranslatorException {
+ public void generateCodeExit()
+ throws TranslatorException {
/*
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
@@ -171,15 +174,15 @@
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
- searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
- getJavaFileInfo().getPackageFilePath());
+ getJavaFileInfo().getPackageFilePath());
+ removeEmptyDirectory(getJavaFileInfo().getBaseCodeGenPath() +
+ getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for module node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + " " + e.getLocalizedMessage());
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
index 4ab4be8..2604262 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
@@ -19,8 +19,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.onosproject.yangutils.datamodel.YangBelongsTo;
-import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaSubModule;
@@ -38,6 +36,7 @@
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.removeEmptyDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
@@ -81,10 +80,10 @@
public JavaFileInfoTranslator getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName());
}
return (JavaFileInfoTranslator) javaFileInfo;
}
@@ -122,11 +121,10 @@
/**
* Returns the name space of the module to which the sub module belongs to.
*
- * @param belongsToInfo Information of the module to which the sub module belongs
* @return the name space string of the module.
*/
- public String getNameSpaceFromModule(YangBelongsTo belongsToInfo) {
- return ((YangModule) belongsToInfo.getModuleNode()).getNameSpace();
+ public String getNameSpaceFromModule() {
+ return (getBelongsTo().getModuleNode()).getNameSpace();
}
/**
@@ -136,13 +134,14 @@
* @throws TranslatorException when fails to translate
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
- getRevision().getRevDate(), yangPlugin.getConflictResolver());
+ public void generateCodeEntry(YangPluginConfig yangPlugin)
+ throws TranslatorException {
+ String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(),
+ getRevision(), yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
- | GENERATE_ALL_EVENT_CLASS_MASK);
+ | GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, subModulePkg);
@@ -161,7 +160,8 @@
* Creates a java file using the YANG submodule info.
*/
@Override
- public void generateCodeExit() throws TranslatorException {
+ public void generateCodeExit()
+ throws TranslatorException {
/**
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
@@ -185,15 +185,15 @@
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
- searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
- getJavaFileInfo().getPackageFilePath());
+ getJavaFileInfo().getPackageFilePath());
+ removeEmptyDirectory(getJavaFileInfo().getBaseCodeGenPath() +
+ getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for submodule node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ getName() + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + " " + e.getLocalizedMessage());
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index ab37d7c..2a2d97a 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -126,6 +126,8 @@
.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils
.getQualifierInfoForCasesParent;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils
+ .isGetSetOfRootNodeRequired;
import static org.onosproject.yangutils.translator.tojava.utils
.JavaCodeSnippetGen.addAugmentationAttribute;
import static org.onosproject.yangutils.translator.tojava.utils
@@ -173,6 +175,8 @@
import static org.onosproject.yangutils.translator.tojava.utils
.MethodsGenerator.getGetterForOperationType;
import static org.onosproject.yangutils.translator.tojava.utils
+ .MethodsGenerator.getGetterString;
+import static org.onosproject.yangutils.translator.tojava.utils
.MethodsGenerator.getGettersForValueAndSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils
.MethodsGenerator.getHashCodeMethodClose;
@@ -195,6 +199,8 @@
import static org.onosproject.yangutils.translator.tojava.utils
.MethodsGenerator.getSetterForSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils
+ .MethodsGenerator.getSetterString;
+import static org.onosproject.yangutils.translator.tojava.utils
.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils
.MethodsGenerator.getToStringMethodOpen;
@@ -1413,6 +1419,19 @@
try {
+ if (isGetSetOfRootNodeRequired(curNode)) {
+ //Getter methods.
+ methods.add(getGetterString(rootAttribute,
+ GENERATE_SERVICE_AND_MANAGER,
+ javaFileInfo.getPluginConfig()) +
+ NEW_LINE);
+ // Setter methods.
+ methods.add(getSetterString(rootAttribute, className,
+ GENERATE_SERVICE_AND_MANAGER,
+ javaFileInfo.getPluginConfig()) +
+ NEW_LINE);
+ }
+
methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE);
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
index 8c14295..93e26c7 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
@@ -26,6 +26,7 @@
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
@@ -78,7 +79,7 @@
* @param conflictResolver object of YANG to java naming conflict util
* @return the root package string
*/
- public static String getRootPackage(byte version, String nameSpace, Date revision,
+ public static String getRootPackage(byte version, String nameSpace, YangRevision revision,
YangToJavaNamingConflictUtil conflictResolver) {
String pkg;
@@ -87,9 +88,10 @@
pkg = pkg + getYangVersion(version);
pkg = pkg + PERIOD;
pkg = pkg + getPkgFromNameSpace(nameSpace, conflictResolver);
- pkg = pkg + PERIOD;
- pkg = pkg + getYangRevisionStr(revision);
-
+ if (revision != null) {
+ pkg = pkg + PERIOD;
+ pkg = pkg + getYangRevisionStr(revision.getRevDate());
+ }
return pkg.toLowerCase();
}
@@ -203,13 +205,14 @@
* @param yangNode YANG node for which code is being generated
* @throws IOException any IO exception
*/
- public static void createPackage(YangNode yangNode) throws IOException {
+ public static void createPackage(YangNode yangNode)
+ throws IOException {
if (!(yangNode instanceof JavaFileInfoContainer)) {
throw new TranslatorException("current node must have java file info " +
- yangNode.getName() + " in " +
- yangNode.getLineNumber() + " at " +
- yangNode.getCharPosition()
- + " in " + yangNode.getFileName());
+ yangNode.getName() + " in " +
+ yangNode.getLineNumber() + " at " +
+ yangNode.getCharPosition()
+ + " in " + yangNode.getFileName());
}
String pkgInfo;
JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
@@ -221,11 +224,11 @@
if (parent != null) {
pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
- ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
+ ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
} else {
pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
- ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
+ ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
}
} catch (IOException e) {
throw new IOException("failed to create package-info file");
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index 6ac0581..2294b99 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -95,7 +95,8 @@
* @return directory structure
* @throws IOException when fails to do IO operations
*/
- public static File createDirectories(String path) throws IOException {
+ public static File createDirectories(String path)
+ throws IOException {
File generatedDir = new File(path);
if (!generatedDir.exists()) {
boolean isGenerated = generatedDir.mkdirs();
@@ -259,7 +260,7 @@
stringBuilder.replace(index, index + 1, replacingString);
} else {
stringBuilder.append(NEW_LINE + EIGHT_SPACE_INDENTATION + UNUSED + OPEN_PARENTHESIS + ONE +
- CLOSE_PARENTHESIS + SEMI_COLAN);
+ CLOSE_PARENTHESIS + SEMI_COLAN);
}
return stringBuilder.toString();
@@ -684,15 +685,16 @@
String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
if (replacementForPeriod != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
- PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
+ PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
}
if (replacementForUnderscore != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
- UNDER_SCORE + replacementForUnderscore.toLowerCase() + UNDER_SCORE);
+ UNDER_SCORE + replacementForUnderscore.toLowerCase() +
+ UNDER_SCORE);
}
if (replacementForHyphen != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
- HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
+ HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
}
}
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
@@ -739,4 +741,39 @@
}
return prefixForIdentifier;
}
+
+ /**
+ * Removes empty directory.
+ *
+ * @param path path to be checked
+ */
+ public static void removeEmptyDirectory(String path) {
+ int index;
+ while (path != null && !path.equals("")) {
+ if (!removeDirectory(path)) {
+ break;
+ } else {
+ index = path.lastIndexOf(SLASH);
+ path = path.substring(0, index);
+ }
+ }
+ }
+
+ private static boolean removeDirectory(String path) {
+ File dir = new File(path);
+ boolean isDeleted = false;
+ if (dir.isDirectory()) {
+ File[] files = dir.listFiles();
+ if (files != null && files.length == 0) {
+ isDeleted = dir.delete();
+ } else if (files != null && files.length == 1) {
+ if (files[0].getName().equals("package-info.java")
+ || files[0].getName().endsWith("-temp")) {
+ isDeleted = dir.delete();
+ }
+ }
+ }
+ return isDeleted;
+ }
+
}