Bharat saraswal
Committed by Gerrit Code Review

[ONOS-4583] Union defect fix.

Change-Id: Ic31866b9a1b7bd5d8209d5d22f4292ab9c79a118
Showing 36 changed files with 926 additions and 179 deletions
......@@ -75,7 +75,7 @@ public class YangXpathLinker<T> {
*
* @return prefix resolver list
*/
public Map<YangAtomicPath, PrefixResolverType> getPrefixResolverTypes() {
private Map<YangAtomicPath, PrefixResolverType> getPrefixResolverTypes() {
return prefixResolverTypes;
}
......@@ -84,7 +84,7 @@ public class YangXpathLinker<T> {
*
* @param prefixResolverTypes prefix resolver list.
*/
public void setPrefixResolverTypes(Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes) {
private void setPrefixResolverTypes(Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes) {
this.prefixResolverTypes = prefixResolverTypes;
}
......@@ -188,7 +188,7 @@ public class YangXpathLinker<T> {
* @param leafref instance of YANG leafref
* @return linked target node
*/
public T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) {
T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) {
YangNode targetNode;
setRootNode(root);
......
......@@ -17,9 +17,12 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
......@@ -42,7 +45,6 @@ import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies;
......@@ -68,6 +70,7 @@ public class YangUtilManager
extends AbstractMojo {
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
YangPluginConfig yangPlugin = new YangPluginConfig();
private YangNode rootNode;
// YANG file information set.
private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
......@@ -181,7 +184,6 @@ public class YangUtilManager
conflictResolver.setReplacementForHyphen(replacementForHyphen);
conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
conflictResolver.setPrefixForIdentifier(prefixForIdentifier);
YangPluginConfig yangPlugin = new YangPluginConfig();
yangPlugin.setCodeGenDir(codeGenDir);
yangPlugin.setManagerCodeGenDir(managerCodeGenDir);
yangPlugin.setConflictResolver(conflictResolver);
......@@ -223,7 +225,7 @@ public class YangUtilManager
fileName = getCurYangFileInfo().getYangFileName();
}
try {
translatorErrorHandler(getRootNode());
translatorErrorHandler(getRootNode(), yangPlugin);
deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
} catch (IOException ex) {
throw new MojoExecutionException(
......@@ -348,8 +350,10 @@ public class YangUtilManager
*/
public void translateToJava(YangPluginConfig yangPlugin)
throws IOException {
updateFilePriority(getYangNodeSet());
for (YangNode node : getYangNodeSet()) {
List<YangNode> yangNodeSortedList = new LinkedList<>();
yangNodeSortedList.addAll(getYangNodeSet());
Collections.sort(yangNodeSortedList);
for (YangNode node : yangNodeSortedList) {
if (node.isToTranslate()) {
generateJavaCode(node, yangPlugin);
}
......
......@@ -122,11 +122,6 @@ public final class GeneratedTempFileType {
public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
/**
* Event subject setter implementation of class.
*/
public static final int AUGMENTE_CLASS_CONSTRUCTOR_MASK = 1048576;
/**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
......
......@@ -51,6 +51,16 @@ public final class JavaAttributeInfo {
private JavaQualifiedTypeInfo importInfo;
/**
* If conflict occurs.
*/
private boolean isIntConflict;
/**
* If conflict occurs.
*/
private boolean isLongConflict;
/**
* Creates a java attribute info object.
*/
private JavaAttributeInfo() {
......@@ -175,6 +185,42 @@ public final class JavaAttributeInfo {
}
/**
* Returns true if conflict between int and uint.
*
* @return true if conflict between int and uint
*/
public boolean isIntConflict() {
return isIntConflict;
}
/**
* Sets true if conflict between int and uint.
*
* @param intConflict true if conflict between int and uint
*/
public void setIntConflict(boolean intConflict) {
isIntConflict = intConflict;
}
/**
* Returns true if conflict between long and ulong.
*
* @return true if conflict between long and ulong
*/
public boolean isLongConflict() {
return isLongConflict;
}
/**
* Sets true if conflict between long and ulong.
*
* @param longConflict true if conflict between long and ulong
*/
public void setLongConflict(boolean longConflict) {
isLongConflict = longConflict;
}
/**
* Returns java attribute info.
*
* @param importInfo java qualified type info
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
......@@ -27,6 +28,7 @@ import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
* Representation of java code generator based on application schema.
......@@ -39,6 +41,11 @@ public final class JavaCodeGeneratorUtil {
private static YangNode curNode;
/**
* Root node.
*/
private static YangNode rootNode;
/**
* Creates a java code generator utility object.
*/
private JavaCodeGeneratorUtil() {
......@@ -67,13 +74,14 @@ public final class JavaCodeGeneratorUtil {
*
* @param rootNode root node of the data model tree
* @param yangPlugin YANG plugin config
* @throws TranslatorException when fails to generate java code file the current
* node
* @throws TranslatorException when fails to generate java code file the current node
* @throws IOException when fails to do IO operations
*/
public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
throws TranslatorException {
throws TranslatorException, IOException {
YangNode codeGenNode = rootNode;
setRootNode(rootNode);
TraversalType curTraversal = ROOT;
while (codeGenNode != null) {
......@@ -94,6 +102,7 @@ public final class JavaCodeGeneratorUtil {
}
continue;
} catch (Exception e) {
close(codeGenNode, yangPlugin);
throw new TranslatorException(e.getMessage());
}
......@@ -103,16 +112,18 @@ public final class JavaCodeGeneratorUtil {
codeGenNode = codeGenNode.getChild();
} else if (codeGenNode.getNextSibling() != null) {
try {
generateCodeExit(codeGenNode);
generateCodeExit(codeGenNode, yangPlugin);
} catch (Exception e) {
close(codeGenNode, yangPlugin);
throw new TranslatorException(e.getMessage());
}
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
try {
generateCodeExit(codeGenNode);
generateCodeExit(codeGenNode, yangPlugin);
} catch (Exception e) {
close(codeGenNode, yangPlugin);
throw new TranslatorException(e.getMessage());
}
curTraversal = PARENT;
......@@ -124,18 +135,18 @@ public final class JavaCodeGeneratorUtil {
/**
* Generates the current nodes code snippet.
*
* @param codeGenNode current data model node for which the code needs to be
* generated
* @param codeGenNode current data model node for which the code needs to be generated
* @param yangPlugin YANG plugin config
* @throws TranslatorException when fails to generate java code file the current
* node
* @throws TranslatorException when fails to generate java code file the current node
* @throws IOException when fails to do IO operations
*/
private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
throws TranslatorException {
throws TranslatorException, IOException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
} else {
close(codeGenNode, yangPlugin);
throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
}
......@@ -144,25 +155,25 @@ public final class JavaCodeGeneratorUtil {
/**
* Generates the current nodes code target code from the snippet.
*
* @param codeGenNode current data model node for which the code needs to be
* generated
* @throws TranslatorException when fails to generate java code file the current
* node
* @param codeGenNode current data model node for which the code needs to be generated
* @param pluginConfig plugin configurations
* @throws TranslatorException when fails to generate java code file the current node
* @throws IOException when fails to do IO operations
*/
private static void generateCodeExit(YangNode codeGenNode)
throws TranslatorException {
private static void generateCodeExit(YangNode codeGenNode, YangPluginConfig pluginConfig)
throws TranslatorException, IOException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeExit();
} else {
close(codeGenNode, pluginConfig);
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.
* Free other YANG nodes of data-model tree when error occurs while file generation of current node.
*/
private static void freeRestResources() {
......@@ -214,21 +225,18 @@ public final class JavaCodeGeneratorUtil {
/**
* Delete Java code files corresponding to the YANG schema.
*
* @param rootNode root node of data-model tree
* @param rootNode root node of data-model tree
* @param yangPluginConfig plugin configurations
* @throws IOException when fails to delete java code file the current node
*/
public static void translatorErrorHandler(YangNode rootNode)
public static void translatorErrorHandler(YangNode rootNode, YangPluginConfig yangPluginConfig)
throws IOException {
if (rootNode != null) {
/**
* Free other resources where translator has failed.
*/
//Free other resources where translator has failed.
freeRestResources();
/**
* Start removing all open files.
*/
// Start removing all open files.
YangNode tempNode = rootNode;
setCurNode(tempNode.getChild());
TraversalType curTraversal = ROOT;
......@@ -236,7 +244,7 @@ public final class JavaCodeGeneratorUtil {
while (tempNode != null) {
if (curTraversal != PARENT) {
close(tempNode);
close(tempNode, yangPluginConfig);
}
if (curTraversal != PARENT && tempNode.getChild() != null) {
curTraversal = CHILD;
......@@ -255,17 +263,45 @@ public final class JavaCodeGeneratorUtil {
}
/**
* Closes all the current open file handles of node and delete all generated
* files.
* Closes all the current open file handles of node and delete all generated files.
*
* @param node current YANG node
* @param node current YANG node
* @param yangPlugin plugin configurations
* @throws IOException when fails to do IO operations
*/
private static void close(YangNode node)
private static void close(YangNode node, YangPluginConfig yangPlugin)
throws IOException {
if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node)
.getTempJavaCodeFragmentFiles() != null) {
((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
} else {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) getRootNode()).getJavaFileInfo();
if (javaFileInfo != null) {
searchAndDeleteTempDir(javaFileInfo.getBaseCodeGenPath() +
javaFileInfo.getPackageFilePath());
} else {
searchAndDeleteTempDir(yangPlugin.getManagerCodeGenDir());
}
}
}
/**
* Returns root node.
*
* @return root node
*/
private static YangNode getRootNode() {
return rootNode;
}
/**
* Sets root node.
*
* @param rootNode root node
*/
private static void setRootNode(YangNode rootNode) {
JavaCodeGeneratorUtil.rootNode = rootNode;
}
}
......
......@@ -21,6 +21,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
......@@ -31,6 +32,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_I
import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
......@@ -300,4 +302,14 @@ public class JavaImportData {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD +
YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
}
/**
* Returns import for big integer.
*
* @return import for big integer
*/
public String getBigIntegerImport() {
return IMPORT + JAVA_MATH + PERIOD +
BIG_INTEGER + SEMI_COLAN + NEW_LINE;
}
}
......
......@@ -48,7 +48,7 @@ public class TempJavaBeanFragmentFiles
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaBeanFragmentFiles(JavaFileInfo javaFileInfo)
TempJavaBeanFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
super(javaFileInfo);
......@@ -109,9 +109,7 @@ public class TempJavaBeanFragmentFiles
/**
* 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.
* @param isErrorOccurred flag to tell translator that error has occurred while code generation
* @throws IOException when failed to delete the temporary files
*/
@Override
......
......@@ -346,6 +346,10 @@ public class TempJavaCodeFragmentFiles {
getServiceTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEventFragmentFiles() != null) {
getEventFragmentFiles().freeTemporaryResources(isErrorOccurred);
}
}
}
......
......@@ -43,8 +43,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
/**
* Represents implementation of java code fragments temporary implementations.
* Maintains the temp files required specific for enumeration java snippet generation.
* Represents implementation of java code fragments temporary implementations. Maintains the temp files required
* specific for enumeration java snippet generation.
*/
public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
......@@ -89,7 +89,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo)
TempJavaEnumerationFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
super(javaFileInfo);
......@@ -107,7 +107,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
*
* @return enum class java file handle
*/
public File getEnumClassJavaFileHandle() {
private File getEnumClassJavaFileHandle() {
return enumClassJavaFileHandle;
}
......@@ -188,18 +188,18 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
/**
* Adds enum attributes to temporary files.
*
* @param curNode current YANG node
* @param curNode current YANG node
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
public void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig);
if (curNode instanceof YangEnumeration) {
YangEnumeration enumeration = (YangEnumeration) curNode;
for (YangEnum curEnum : enumeration.getEnumSet()) {
String enumName = curEnum.getNamedValue();
String prefixForIdentifier = null;
String prefixForIdentifier;
if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) {
prefixForIdentifier = getPrefixForIdentifier(pluginConfig.getConflictResolver());
if (prefixForIdentifier != null) {
......@@ -219,11 +219,11 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
}
/**
* Returns java attribute for enum class.
*
* @param pluginConfig plugin configurations
* @return java attribute
*/
* Returns java attribute for enum class.
*
* @param pluginConfig plugin configurations
* @return java attribute
*/
public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
YangJavaType<?> javaType = new YangJavaType<>();
javaType.setDataType(YangDataTypes.INT32);
......@@ -248,11 +248,10 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
/**
* Adds the new attribute info to the target generated temporary files.
*
* @param curEnumName the attribute name that needs to be added to temporary
* files
* @param curEnumName the attribute name that needs to be added to temporary files
* @throws IOException IO operation fail
*/
void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig)
private void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig)
throws IOException {
addAttributesForEnumClass(getEnumJavaAttribute(curEnumName), pluginConfig);
}
......@@ -261,7 +260,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
@Override
......@@ -275,9 +274,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
/**
* 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.
* @param isErrorOccurred flag to tell translator that error has occurred while file generation
* @throws IOException when failed to delete the temporary files
*/
@Override
......@@ -310,7 +307,7 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
*
* @param enumStringList the enumStringList to set
*/
public void setEnumStringList(List<String> enumStringList) {
private void setEnumStringList(List<String> enumStringList) {
this.enumStringList = enumStringList;
}
}
......
......@@ -46,6 +46,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
......@@ -63,12 +64,11 @@ public class TempJavaEventFragmentFiles
/**
* File name for generated class file for special type like union, typedef suffix.
*/
public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
private static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
/**
* File name for event enum temp file.
*/
private static final String EVENT_ENUM_FILE_NAME = "EventEnum";
/**
......@@ -149,7 +149,7 @@ public class TempJavaEventFragmentFiles
* @param javaFileInfo generated file information
* @throws IOException when fails to create new file handle
*/
public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
......@@ -255,6 +255,9 @@ public class TempJavaEventFragmentFiles
generateEventJavaFile(curNode);
generateEventListenerJavaFile(curNode);
generateEventSubjectJavaFile(curNode);
// Close all the file handles.
freeTemporaryResources(false);
}
/**
......@@ -263,7 +266,7 @@ public class TempJavaEventFragmentFiles
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventJavaFile(YangNode curNode)
private void generateEventJavaFile(YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
......@@ -274,25 +277,19 @@ public class TempJavaEventFragmentFiles
addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX);
/**
* Creates event interface file.
*/
//Creates event interface file.
setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX));
generateEventFile(getEventJavaFileHandle(), curNode, imports);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Constructs java code exit.
*
* @param curNode current YANG node
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventListenerJavaFile(YangNode curNode)
private void generateEventListenerJavaFile(YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
......@@ -300,17 +297,12 @@ public class TempJavaEventFragmentFiles
imports.add(getJavaImportData().getEventListenerImport());
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
/**
* Creates event listener interface file.
*/
// Creates event listener interface file.
setEventListenerJavaFileHandle(
getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
......@@ -319,22 +311,17 @@ public class TempJavaEventFragmentFiles
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventSubjectJavaFile(YangNode curNode)
private void generateEventSubjectJavaFile(YangNode curNode)
throws IOException {
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
/**
* Creates event interface file.
*/
//Creates event interface file.
setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo +
TempJavaEventFragmentFiles.EVENT_SUBJECT_NAME_SUFFIX));
generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
......@@ -351,7 +338,7 @@ public class TempJavaEventFragmentFiles
*
* @param eventEnumTempFileHandle event enum temp file
*/
public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) {
private void setEventEnumTempFileHandle(File eventEnumTempFileHandle) {
this.eventEnumTempFileHandle = eventEnumTempFileHandle;
}
......@@ -369,7 +356,7 @@ public class TempJavaEventFragmentFiles
*
* @param eventMethodTempFileHandle event method temp file
*/
public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) {
private void setEventMethodTempFileHandle(File eventMethodTempFileHandle) {
this.eventMethodTempFileHandle = eventMethodTempFileHandle;
}
......@@ -387,7 +374,7 @@ public class TempJavaEventFragmentFiles
*
* @param eventSubjectAttributeTempFileHandle event subject attribute temp file
*/
public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) {
private void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) {
this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle;
}
......@@ -405,7 +392,7 @@ public class TempJavaEventFragmentFiles
*
* @param eventSubjectGetterTempFileHandle event subject getter temp file
*/
public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) {
private void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) {
this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle;
}
......@@ -423,7 +410,7 @@ public class TempJavaEventFragmentFiles
*
* @param eventSubjectSetterTempFileHandle event subject setter temp file
*/
public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) {
private void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) {
this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle;
}
......@@ -434,7 +421,7 @@ public class TempJavaEventFragmentFiles
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
throws IOException {
String currentInfo = getCapitalCase(getCamelCase(curNode.getName(),
......@@ -521,4 +508,28 @@ public class TempJavaEventFragmentFiles
private String getDirPath(JavaFileInfo parentInfo) {
return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase();
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred flag to tell translator that error has occurred while file generation
* @throws IOException when failed to delete the temporary files
*/
@Override
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
closeFile(getEventJavaFileHandle(), isErrorOccurred);
closeFile(getEventListenerJavaFileHandle(), isErrorOccurred);
closeFile(getEventSubjectJavaFileHandle(), isErrorOccurred);
closeFile(getEventEnumTempFileHandle(), true);
closeFile(getEventSubjectAttributeTempFileHandle(), true);
closeFile(getEventMethodTempFileHandle(), true);
closeFile(getEventSubjectGetterTempFileHandle(), true);
closeFile(getEventSubjectSetterTempFileHandle(), true);
super.freeTemporaryResources(isErrorOccurred);
}
}
......
......@@ -78,7 +78,7 @@ public class TempJavaServiceFragmentFiles
/**
* Flag to set the manager files generation.
*/
boolean isManagerNeedToBeGenerated = false;
private boolean isManagerNeedToBeGenerated = false;
/**
* Temporary file handle for rpc interface.
......@@ -96,7 +96,7 @@ public class TempJavaServiceFragmentFiles
private File serviceInterfaceJavaFileHandle;
/**
* Path for serive file to be generated.
* Path for service file to be generated.
*/
private String serviceGenPath;
......@@ -111,7 +111,7 @@ public class TempJavaServiceFragmentFiles
* @param javaFileInfo generated file information
* @throws IOException when fails to create new file handle
*/
public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo)
TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
......@@ -150,7 +150,7 @@ public class TempJavaServiceFragmentFiles
*
* @return java file handle
*/
public File getManagerJavaFileHandle() {
private File getManagerJavaFileHandle() {
return managerJavaFileHandle;
}
......@@ -159,7 +159,7 @@ public class TempJavaServiceFragmentFiles
*
* @param managerJavaFileHandle file handle for to manager
*/
public void setManagerJavaFileHandle(File managerJavaFileHandle) {
private void setManagerJavaFileHandle(File managerJavaFileHandle) {
this.managerJavaFileHandle = managerJavaFileHandle;
}
......@@ -195,7 +195,7 @@ public class TempJavaServiceFragmentFiles
*
* @param rpcImplTempFileHandle the manager impl temp file
*/
public void setRpcImplTempFileHandle(File rpcImplTempFileHandle) {
private void setRpcImplTempFileHandle(File rpcImplTempFileHandle) {
this.rpcImplTempFileHandle = rpcImplTempFileHandle;
}
......@@ -226,9 +226,8 @@ public class TempJavaServiceFragmentFiles
if (isNotification) {
addListenersImport(curNode, imports, true, LISTENER_SERVICE);
}
/**
* Creates rpc interface file.
*/
// Creates rpc interface file.
setBaseCodePath(getServiceGenPath());
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports);
......@@ -238,9 +237,8 @@ public class TempJavaServiceFragmentFiles
addListenersImport(curNode, imports, true, LISTENER_REG);
}
addAnnotationsImports(imports, true);
/**
* Create builder class file.
*/
// Create builder class file.
if (isManagerNeedToBeGenerated()) {
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode);
......@@ -251,17 +249,16 @@ public class TempJavaServiceFragmentFiles
}
addAnnotationsImports(imports, false);
/**
* Close all the file handles.
*/
// Close all the file handles.
freeTemporaryResources(false);
}
/**
* Adds rpc string information to applicable temp file.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param javaAttributeInfoOfInput RPCs input node attribute info
* @param javaAttributeInfoOfOutput RPCs output node attribute info
* @param rpcName name of the rpc function
* @param pluginConfig plugin configurations
* @throws IOException IO operation fail
......@@ -292,8 +289,8 @@ public class TempJavaServiceFragmentFiles
/**
* Adds the JAVA rpc snippet information.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param javaAttributeInfoOfInput RPCs input node attribute info
* @param javaAttributeInfoOfOutput RPCs output node attribute info
* @param pluginConfig plugin configurations
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
......@@ -308,17 +305,15 @@ public class TempJavaServiceFragmentFiles
/**
* 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.
* @param isErrorOccurred flag to tell translator that error has occurred while file generation
* @throws IOException when failed to delete the temporary files
*/
@Override
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
closeFile(getServiceInterfaceJavaFileHandle(), isError);
closeFile(getManagerJavaFileHandle(), isError);
closeFile(getServiceInterfaceJavaFileHandle(), isErrorOccurred);
closeFile(getManagerJavaFileHandle(), isErrorOccurred);
closeFile(getRpcInterfaceTempFileHandle(), true);
closeFile(getRpcImplTempFileHandle(), true);
......@@ -335,7 +330,7 @@ public class TempJavaServiceFragmentFiles
*
* @return path where service file should be generated
*/
public String getServiceGenPath() {
private String getServiceGenPath() {
return serviceGenPath;
}
......@@ -344,7 +339,7 @@ public class TempJavaServiceFragmentFiles
*
* @param serviceGenPath path where service file should be generated
*/
public void setServiceGenPath(String serviceGenPath) {
private void setServiceGenPath(String serviceGenPath) {
this.serviceGenPath = serviceGenPath;
}
......@@ -353,7 +348,7 @@ public class TempJavaServiceFragmentFiles
*
* @return true if manager needs to be generated
*/
public boolean isManagerNeedToBeGenerated() {
private boolean isManagerNeedToBeGenerated() {
return isManagerNeedToBeGenerated;
}
......
......@@ -147,7 +147,8 @@ public final class YangJavaModelUtils {
}
}
} else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
}
if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
/*
* Container
* Case
......@@ -189,7 +190,7 @@ public final class YangJavaModelUtils {
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("translation is not supported for the node");
......@@ -456,7 +457,7 @@ public final class YangJavaModelUtils {
/**
* Returns augment class name.
*
* @param augment YANG augment
* @param augment YANG augment
* @param yangPluginConfig plugin configurations
* @return augment class name
*/
......
......@@ -36,8 +36,8 @@ import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.gen
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
* Represents module information extended to support java code generation.
......@@ -212,7 +212,7 @@ public class YangJavaModule
* @param rootNode root node of the data model
* @return status of rpc's existence
*/
public boolean isNotificationChildNodePresent(YangNode rootNode) {
private boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
......@@ -222,9 +222,6 @@ public class YangJavaModule
childNode = childNode.getNextSibling();
}
if (!getNotificationNodes().isEmpty()) {
return true;
}
return false;
return !getNotificationNodes().isEmpty();
}
}
......
......@@ -194,7 +194,6 @@ public class YangJavaSubModule
}
}
/**
* Returns notifications node list.
*
......@@ -219,7 +218,7 @@ public class YangJavaSubModule
* @param rootNode root node of the data model
* @return status of rpc's existence
*/
public boolean isNotificationChildNodePresent(YangNode rootNode) {
private boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
......@@ -229,9 +228,6 @@ public class YangJavaSubModule
childNode = childNode.getNextSibling();
}
if (!getNotificationNodes().isEmpty()) {
return true;
}
return false;
return !getNotificationNodes().isEmpty();
}
}
......
......@@ -182,7 +182,7 @@ public final class ClassDefinitionGenerator {
* @return definition
*/
private static String getBuilderInterfaceDefinition(String yangName, YangNode curNode) {
if (!(curNode instanceof YangCase)) {
if (!(curNode instanceof YangCase) && !(curNode instanceof YangAugment)) {
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_INTERFACE_MASK);
if (clsDef != null) {
return clsDef;
......
......@@ -42,10 +42,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
......@@ -61,6 +65,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_I
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
......@@ -97,22 +105,23 @@ public final class JavaCodeSnippetGen {
* @param importInfo import info
* @return the textual java code information corresponding to the import list
*/
public static String getImportText(JavaQualifiedTypeInfo importInfo) {
static String getImportText(JavaQualifiedTypeInfo importInfo) {
return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
}
/**
* Returns the textual java code for attribute definition in class.
*
* @param javaAttributeTypePkg Package of the attribute type
* @param javaAttributeType java attribute type
* @param javaAttributeName name of the attribute
* @param isList is list attribute
* @param attributeAccessType attribute access type
* @return the textual java code for attribute definition in class
* @param javaAttributeTypePkg Package of the attribute type
* @param javaAttributeType java attribute type
* @param javaAttributeName name of the attribute
* @param isList is list attribute
* @param attributeAccessType attribute access type
* @return the textual java code for attribute definition in class
*/
public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
String javaAttributeName, boolean isList, String attributeAccessType) {
String javaAttributeName, boolean isList,
String attributeAccessType) {
String attributeDefination = attributeAccessType + SPACE;
......@@ -209,7 +218,7 @@ public final class JavaCodeSnippetGen {
*
* @return event enum start
*/
public static String getEventEnumTypeStart() {
static String getEventEnumTypeStart() {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
}
......@@ -261,7 +270,7 @@ public final class JavaCodeSnippetGen {
* @param className enum's class name
* @return enum's attribute
*/
public static String getEnumsValueAttribute(String className) {
static String getEnumsValueAttribute(String className) {
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
+ SEMI_COLAN + NEW_LINE;
}
......@@ -271,7 +280,7 @@ public final class JavaCodeSnippetGen {
*
* @return component string
*/
public static String addComponentString() {
static String addComponentString() {
return NEW_LINE + COMPONENT_ANNOTATION + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
}
......@@ -281,11 +290,46 @@ public final class JavaCodeSnippetGen {
*
* @return attribute for augmentation
*/
public static String addAugmentationAttribute() {
static String addAugmentationAttribute() {
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING
+ DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO
+ DIAMOND_CLOSE_BRACKET + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL + SPACE +
NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
* Adds attribute for int ranges.
*
* @param modifier modifier for attribute
* @param addFirst true if int need to be added fist.
* @return attribute for int ranges
*/
static String addStaticAttributeIntRange(String modifier, boolean addFirst) {
if (addFirst) {
return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + INT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
modifier +
SPACE + INT_MAX_RANGE_ATTR;
} else {
return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + UINT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
modifier + SPACE + UINT_MAX_RANGE_ATTR;
}
}
/**
* Adds attribute for long ranges.
*
* @param modifier modifier for attribute
* @param addFirst if need to be added first
* @return attribute for long ranges
*/
static String addStaticAttributeLongRange(String modifier, boolean addFirst) {
if (addFirst) {
return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + LONG_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
modifier + SPACE + LONG_MAX_RANGE_ATTR;
} else {
return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + ULONG_MIN_RANGE_ATTR +
FOUR_SPACE_INDENTATION + modifier + SPACE + ULONG_MAX_RANGE_ATTR;
}
}
}
......
......@@ -57,7 +57,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
......@@ -120,10 +119,10 @@ public final class JavaFileGeneratorUtils {
/**
* Returns a file object for generated file.
*
* @param filePath file package path
* @param fileName file name
* @param extension file extension
* @param baseCodePath cached file handle
* @param filePath file package path
* @param fileName file name
* @param extension file extension
* @param baseCodePath cached file handle
* @return file object
*/
public static File getFileObject(String filePath, String fileName, String extension, String baseCodePath) {
......@@ -205,10 +204,6 @@ public final class JavaFileGeneratorUtils {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAugmentConstructorImplTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
if (typeFragmentFiles == null) {
throw new TranslatorException("Required of string implementation info is missing.");
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
/**
* Validator types for union when there is conflict between two types.
*/
public enum ValidatorTypeForUnionTypes {
/**
* When conflict is there for int32 and uint16.
*/
INT_TYPE_CONFLICT,
/**
* When conflict is there for int64 and uint32.
*/
LONG_TYPE_CONFLICT
}
......@@ -127,6 +127,16 @@ public final class UtilConstants {
public static final String JAVA_DOC_GETTERS = " * Returns the attribute ";
/**
* JavaDocs's description for getter method.
*/
public static final String JAVA_DOC_FOR_VALIDATOR = " * Validates if value is in given range.";
/**
* JavaDocs's description for getter method.
*/
public static final String JAVA_DOC_FOR_VALIDATOR_RETURN = " * @return true if value is in range";
/**
* JavaDocs's description for constructor.
*/
public static final String JAVA_DOC_CONSTRUCTOR = " * Creates an instance of ";
......@@ -292,6 +302,108 @@ public final class UtilConstants {
public static final String SPACE = " ";
/**
* Static attribute for validateRange.
*/
public static final String VALIDATE_RANGE = "validateRange";
/**
* Static attribute for minRange.
*/
public static final String MIN_RANGE = "minRange";
/**
* Static attribute for maxRange.
*/
public static final String MAX_RANGE = "maxRange";
/**
* Static attribute for minRange.
*/
public static final String INT_MIN_RANGE_ATTR = "static final int INT32_MIN_RANGE = -2147483648;\n";
/**
* Static attribute for minRange.
*/
public static final String INT_MIN_RANGE = "INT32_MIN_RANGE";
/**
* Static attribute for minRange.
*/
public static final String INT_MAX_RANGE = "INT32_MAX_RANGE";
/**
* Static attribute for maxRange.
*/
public static final String INT_MAX_RANGE_ATTR = "static final int INT32_MAX_RANGE = 2147483647;";
/**
* Static attribute for minRange.
*/
public static final String UINT_MIN_RANGE_ATTR = "static final int UINT16_MIN_RANGE = 0;\n";
/**
* Static attribute for maxRange.
*/
public static final String UINT_MAX_RANGE_ATTR = "static final int UINT16_MAX_RANGE = 2147483647;";
/**
* Static attribute for minRange.
*/
public static final String UINT_MIN_RANGE = "UINT16_MIN_RANGE";
/**
* Static attribute for maxRange.
*/
public static final String UINT_MAX_RANGE = "UINT16_MAX_RANGE";
/**
* Static attribute for minRange.
*/
public static final String LONG_MIN_RANGE_ATTR = "static final BigInteger INT64_MIN_RANGE =" +
" new BigInteger(\"-9223372036854775808\");\n";
/**
* Static attribute for maxRange.
*/
public static final String LONG_MAX_RANGE_ATTR = "static final BigInteger INT64_MAX_RANGE =" +
" new BigInteger(\"9223372036854775807\");";
/**
* Static attribute for minRange.
*/
public static final String LONG_MIN_RANGE = "INT64_MIN_RANGE";
/**
* Static attribute for maxRange.
*/
public static final String LONG_MAX_RANGE = "INT64_MAX_RANGE";
/**
* Static attribute for minRange.
*/
public static final String ULONG_MIN_RANGE_ATTR = "static final BigInteger UINT32_MIN_RANGE =" +
" new BigInteger(\"0\");\n";
/**
* Static attribute for maxRange.
*/
public static final String ULONG_MAX_RANGE_ATTR = "static final BigInteger UINT32_MAX_RANGE =" +
" new BigInteger(\"9223372036854775807\");";
/**
* Static attribute for minRange.
*/
public static final String ULONG_MIN_RANGE = "UINT32_MIN_RANGE";
/**
* Static attribute for maxRange.
*/
public static final String ULONG_MAX_RANGE = "UINT32_MAX_RANGE";
/**
* Static attribute for subject.
*/
public static final String SUBJECT = "Subject";
......@@ -347,16 +459,6 @@ public final class UtilConstants {
public static final String IDENTITYREF = "identityref";
/**
* Static attribute for binary string.
*/
public static final String BINARY_STRING = "binary";
/**
* Static attribute for bits string.
*/
public static final String BITS_STRING = "bits";
/**
* Static attribute for output variable of rpc.
*/
public static final String RPC_INPUT_VAR_NAME = "inputVar";
......@@ -612,6 +714,11 @@ public final class UtilConstants {
public static final String TMP_VAL = "tmpVal";
/**
* Static attribute for close curly bracket syntax.
*/
public static final String ELSE = "else";
/**
* From string parameter name.
*/
public static final String FROM_STRING_PARAM_NAME = "valInString";
......
......@@ -17,6 +17,10 @@
package org.onosproject.yangutils.utils.io.impl;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
......@@ -519,6 +523,11 @@ public final class JavaDocGen {
VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
* Returns javadoc for get augmentation method.
*
* @return javadoc for get augmentation method
*/
public static String generateForGetAugmentation() {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_GETTERS + getSmallCase(YANG_AUGMENTED_INFO) + PERIOD + NEW_LINE +
......@@ -529,6 +538,23 @@ public final class JavaDocGen {
}
/**
* Returns javadoc for validator method.
*
* @return javadoc for validator method
*/
public static String generateForValidatorMethod() {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION +
JAVA_DOC_FOR_VALIDATOR + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK +
FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + MIN_RANGE + SPACE + MIN_RANGE + SPACE + OF + SPACE +
VALUE + NEW_LINE +
FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + MAX_RANGE + SPACE + MAX_RANGE + SPACE + OF + SPACE + VALUE +
NEW_LINE +
FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + NEW_LINE +
FOUR_SPACE_INDENTATION + JAVA_DOC_FOR_VALIDATOR_RETURN + NEW_LINE + FOUR_SPACE_INDENTATION +
JAVA_DOC_END_LINE;
}
/**
* JavaDocs types.
*/
public enum JavaDocType {
......
......@@ -39,7 +39,7 @@ public class ManagerCodeGeneratorTest {
/**
* Checks manager translation should not result in any exception.
*
* @throws MojoExecutionException
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
......@@ -73,7 +73,7 @@ public class ManagerCodeGeneratorTest {
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
......@@ -102,7 +102,7 @@ public class ManagerCodeGeneratorTest {
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerforMultiChildTranslator() throws IOException, ParserException,
......@@ -140,6 +140,42 @@ public class ManagerCodeGeneratorTest {
assertThat(true, is(manager4.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerforMultiChildWithDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/MultiChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager1/");
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager1/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java";
File manager1 = new File(file1);
assertThat(true, is(manager1.exists()));
String file2 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Service.java";
File service2 = new File(file2);
assertThat(true, is(service2.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test case for typedef translator.
*/
public class TypeDefTranslatorTest {
private final YangUtilManager utilManager = new YangUtilManager();
/**
* Checks typedef translation should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
public void processTypeDefTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/typedefTranslator";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/typedefTranslator/");
}
}
......@@ -18,10 +18,12 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
......@@ -52,5 +54,168 @@ public final class UnionTranslatorTest {
deleteDirectory("target/UnionTestGenFile/");
}
/**
* Unit test case to test conflicting types.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processUnionIntUintConflictingTypes() throws IOException, MojoExecutionException {
String searchDir = "src/test/resources/unionTranslator/intuint";
YangUtilManager utilManager = new YangUtilManager();
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
}
/**
* Unit test case to test conflicting types.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processUnionUintIntConflictingTypes() throws IOException, MojoExecutionException {
String searchDir = "src/test/resources/unionTranslator/uintint";
YangUtilManager utilManager = new YangUtilManager();
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
}
/**
* Unit test case to test conflicting types.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processUnionLongUlongConflictingTypes() throws IOException, MojoExecutionException {
String searchDir = "src/test/resources/unionTranslator/longulong";
YangUtilManager utilManager = new YangUtilManager();
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
}
/**
* Unit test case to test conflicting types.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processUnionUlongLongConflictingTypes() throws IOException, MojoExecutionException {
String searchDir = "src/test/resources/unionTranslator/ulonglong";
YangUtilManager utilManager = new YangUtilManager();
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
}
/**
* Unit test case to test conflicting types.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processUnionIntUintUlongLongConflictingTypes() throws IOException, MojoExecutionException {
String searchDir = "src/test/resources/unionTranslator/intuintulonglong";
YangUtilManager utilManager = new YangUtilManager();
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
}
/**
* Unit test case to test conflicting types.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processUnionIntUintUlongLongStringConflictingTypes() throws IOException,
MojoExecutionException {
String searchDir = "src/test/resources/unionTranslator/intuintulonglongstring";
YangUtilManager utilManager = new YangUtilManager();
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
}
/**
* Unit test case to test conflicting types.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processUnionIntUintStringConflictingTypes() throws IOException,
MojoExecutionException {
String searchDir = "src/test/resources/unionTranslator/intuintstring";
YangUtilManager utilManager = new YangUtilManager();
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......
module test {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type int32;
type uint16;
}
}
}
module test {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type int32;
type string;
type uint16;
}
}
}
module test2 {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type int64;
type string;
type uint16;
}
}
}
module test {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type int32;
type uint16;
type uint32;
type int64;
}
}
}
module test {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type string;
type int32;
type uint16;
type uint32;
type int64;
}
}
}
module test {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type int64;
type uint32;
}
}
}
module test {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type uint16;
type int32;
}
}
}
module test {
namespace "test:test";
prefix test ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
leaf leaf1 {
type union {
type uint32;
type int64;
}
}
}