Bharat saraswal
Committed by Gerrit Code Review

[ONOS-4527,ONOS-4524,ONOS-4536,ONOS-4541,ONOS-4549,ONOS-4550,ONOS-4557

,ONOS-4558,ONOS-4545,ONOS-4543,ONOS-4546]
 Checkstyle error in generated code handled and defect fixed.

Change-Id: Ifef5a22f91d4ee21767f1e2c6d0dd5b5b0b8cfcc
Showing 53 changed files with 1235 additions and 652 deletions
......@@ -65,8 +65,8 @@ public final class DataModelUtils {
while (node != null) {
Parsable parsable = (Parsable) node;
if (node instanceof CollisionDetector
&& (parsable.getYangConstructType() != YangConstructType.USES_DATA)
&& (parsable.getYangConstructType() != YangConstructType.GROUPING_DATA)) {
&& parsable.getYangConstructType() != YangConstructType.USES_DATA
&& parsable.getYangConstructType() != YangConstructType.GROUPING_DATA) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
......@@ -90,7 +90,7 @@ public final class DataModelUtils {
while (node != null) {
Parsable parsable = (Parsable) node;
if (node instanceof CollisionDetector
&& (parsable.getYangConstructType() == dataType)) {
&& parsable.getYangConstructType() == dataType) {
((CollisionDetector) node).detectSelfCollision(identifierName, dataType);
}
node = node.getNextSibling();
......
......@@ -138,8 +138,8 @@ public final class EnumerationListener {
* integer number, this is done because under union there
* could be multiple child union types.
*/
enumerationNode.setName(yangUnion.getName() + yangUnion.getChildUnionNumber()
+ ENUMERATION_CLASS_SUFFIX);
enumerationNode.setName(yangUnion.getName() + ENUMERATION_CLASS_SUFFIX
+ yangUnion.getChildUnionNumber());
// Increment the running number.
yangUnion.setChildUnionNumber(yangUnion.getChildUnionNumber() + 1);
// Add union as a child to parent union.
......
......@@ -21,6 +21,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
......@@ -35,7 +36,6 @@ import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
......@@ -69,6 +69,7 @@ public class YangUtilManager extends AbstractMojo {
private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private YangLinker yangLinker = new YangLinkerManager();
private YangFileInfo curYangFileInfo = new YangFileInfo();
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
......@@ -161,7 +162,7 @@ public class YangUtilManager extends AbstractMojo {
return;
}
//Carry out the parsing for all the YANG files.
// Carry out the parsing for all the YANG files.
parseYangFileInfoSet();
// Resolve dependencies using linker.
......@@ -170,13 +171,13 @@ public class YangUtilManager extends AbstractMojo {
// Perform translation to JAVA.
translateToJava(getYangFileInfoSet(), yangPlugin);
addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
addToSource(getDirectory(baseDir, genFilesDir), project, context);
copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
} catch (Exception e) {
String fileName = "";
if (e instanceof TranslatorException) {
fileName = ((TranslatorException) e).getFileName();
if (getCurYangFileInfo() != null) {
fileName = getCurYangFileInfo().getYangFileName();
}
try {
translatorErrorHandler(getRootNode());
......@@ -198,6 +199,7 @@ public class YangUtilManager extends AbstractMojo {
*/
public void resolveDependenciesUsingLinker() throws MojoExecutionException {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
setCurYangFileInfo(yangFileInfo);
try {
yangLinker.resolveDependencies(getYangFileInfoSet());
} catch (LinkerException e) {
......@@ -213,6 +215,7 @@ public class YangUtilManager extends AbstractMojo {
*/
public void parseYangFileInfoSet() throws IOException {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
setCurYangFileInfo(yangFileInfo);
try {
YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
yangFileInfo.setRootNode(yangNode);
......@@ -264,7 +267,8 @@ public class YangUtilManager extends AbstractMojo {
Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator();
while (yangFileIterator.hasNext()) {
YangFileInfo yangFileInfo = yangFileIterator.next();
generateJavaCode(yangFileInfo.getRootNode(), yangPlugin, yangFileInfo.getYangFileName());
setCurYangFileInfo(yangFileInfo);
generateJavaCode(yangFileInfo.getRootNode(), yangPlugin);
}
}
......@@ -298,4 +302,22 @@ public class YangUtilManager extends AbstractMojo {
public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
this.yangFileInfoSet = yangFileInfoSet;
}
/**
* Returns current YANG file's info.
*
* @return the yangFileInfo
*/
public YangFileInfo getCurYangFileInfo() {
return curYangFileInfo;
}
/**
* Sets current YANG file's info.
*
* @param yangFileInfo the yangFileInfo to set
*/
public void setCurYangFileInfo(YangFileInfo yangFileInfo) {
this.curYangFileInfo = yangFileInfo;
}
}
......
......@@ -84,6 +84,11 @@ public final class GeneratedJavaFileType {
public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512;
/**
* Event listener class.
*/
public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
......
......@@ -97,6 +97,31 @@ public final class GeneratedTempFileType {
public static final int RPC_IMPL_MASK = 16384;
/**
* Event enum implementation of class.
*/
public static final int EVENT_ENUM_MASK = 32768;
/**
* Event method implementation of class.
*/
public static final int EVENT_METHOD_MASK = 65536;
/**
* Event subject attribute implementation of class.
*/
public static final int EVENT_SUBJECT_ATTRIBUTE_MASK = 131072;
/**
* Event subject getter implementation of class.
*/
public static final int EVENT_SUBJECT_GETTER_MASK = 262144;
/**
* Event subject setter implementation of class.
*/
public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
/**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
......
......@@ -66,11 +66,10 @@ public final class JavaCodeGeneratorUtil {
*
* @param rootNode root node of the data model tree
* @param yangPlugin YANG plugin config
* @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin, String fileName)
public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
throws TranslatorException {
YangNode codeGenNode = rootNode;
......@@ -80,7 +79,7 @@ public final class JavaCodeGeneratorUtil {
if (curTraversal != PARENT) {
if (codeGenNode instanceof JavaCodeGenerator) {
setCurNode(codeGenNode);
generateCodeEntry(codeGenNode, yangPlugin, fileName);
generateCodeEntry(codeGenNode, yangPlugin);
} else {
/*
* For grouping and uses, there is no code generation, skip the generation for the child.
......@@ -100,11 +99,11 @@ public final class JavaCodeGeneratorUtil {
curTraversal = CHILD;
codeGenNode = codeGenNode.getChild();
} else if (codeGenNode.getNextSibling() != null) {
generateCodeExit(codeGenNode, fileName);
generateCodeExit(codeGenNode);
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
generateCodeExit(codeGenNode, fileName);
generateCodeExit(codeGenNode);
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
......@@ -117,20 +116,17 @@ public final class JavaCodeGeneratorUtil {
* @param codeGenNode current data model node for which the code needs to be
* generated
* @param yangPlugin YANG plugin config
* @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin, String fileName)
private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
} else {
TranslatorException ex = new TranslatorException(
throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
ex.setFileName(fileName);
throw ex;
}
}
......@@ -139,19 +135,16 @@ public final class JavaCodeGeneratorUtil {
*
* @param codeGenNode current data model node for which the code needs to be
* generated
* @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
private static void generateCodeExit(YangNode codeGenNode, String fileName) throws TranslatorException {
private static void generateCodeExit(YangNode codeGenNode) throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeExit();
} else {
TranslatorException ex = new TranslatorException(
throw new TranslatorException(
"Generated data model node cannot be translated to target language code");
ex.setFileName(fileName);
throw ex;
}
}
......@@ -162,26 +155,28 @@ public final class JavaCodeGeneratorUtil {
private static void freeRestResources() {
YangNode freedNode = getCurNode();
YangNode tempNode = freedNode;
TraversalType curTraversal = ROOT;
while (freedNode != tempNode.getParent()) {
if (curTraversal != PARENT && freedNode.getChild() != null) {
curTraversal = CHILD;
freedNode = freedNode.getChild();
} else if (freedNode.getNextSibling() != null) {
curTraversal = SIBILING;
if (freedNode != tempNode) {
free(freedNode);
}
freedNode = freedNode.getNextSibling();
} else {
curTraversal = PARENT;
if (freedNode != tempNode) {
free(freedNode);
if (getCurNode() != null) {
YangNode tempNode = freedNode;
TraversalType curTraversal = ROOT;
while (freedNode != tempNode.getParent()) {
if (curTraversal != PARENT && freedNode.getChild() != null) {
curTraversal = CHILD;
freedNode = freedNode.getChild();
} else if (freedNode.getNextSibling() != null) {
curTraversal = SIBILING;
if (freedNode != tempNode) {
free(freedNode);
}
freedNode = freedNode.getNextSibling();
} else {
curTraversal = PARENT;
if (freedNode != tempNode) {
free(freedNode);
}
freedNode = freedNode.getParent();
}
freedNode = freedNode.getParent();
}
}
}
......@@ -213,36 +208,38 @@ public final class JavaCodeGeneratorUtil {
public static void translatorErrorHandler(YangNode rootNode)
throws IOException {
/**
* Free other resources where translator has failed.
*/
freeRestResources();
if (rootNode != null) {
/**
* Free other resources where translator has failed.
*/
freeRestResources();
/**
* Start removing all open files.
*/
YangNode tempNode = rootNode;
setCurNode(tempNode.getChild());
TraversalType curTraversal = ROOT;
/**
* Start removing all open files.
*/
YangNode tempNode = rootNode;
setCurNode(tempNode.getChild());
TraversalType curTraversal = ROOT;
while (tempNode != null) {
while (tempNode != null) {
if (curTraversal != PARENT) {
close(tempNode);
}
if (curTraversal != PARENT && tempNode.getChild() != null) {
curTraversal = CHILD;
tempNode = tempNode.getChild();
} else if (tempNode.getNextSibling() != null) {
curTraversal = SIBILING;
tempNode = tempNode.getNextSibling();
} else {
curTraversal = PARENT;
tempNode = tempNode.getParent();
if (curTraversal != PARENT) {
close(tempNode);
}
if (curTraversal != PARENT && tempNode.getChild() != null) {
curTraversal = CHILD;
tempNode = tempNode.getChild();
} else if (tempNode.getNextSibling() != null) {
curTraversal = SIBILING;
tempNode = tempNode.getNextSibling();
} else {
curTraversal = PARENT;
tempNode = tempNode.getParent();
}
}
}
freeRestResources();
freeRestResources();
}
}
/**
......
......@@ -16,6 +16,8 @@
package org.onosproject.yangutils.translator.tojava;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
* Represents cached java file handle, which supports the addition of member attributes and
* methods.
......@@ -49,6 +51,11 @@ public class JavaFileInfo {
private String codeGenDirFilePath;
/**
* Plugin configuration for naming convention.
*/
private YangPluginConfig pluginConfig;
/**
* Returns the types of files being generated corresponding to the YANG
* definition.
*
......@@ -152,4 +159,22 @@ public class JavaFileInfo {
public void setBaseCodeGenPath(String path) {
codeGenDirFilePath = path;
}
/**
* Returns plugin configurations.
*
* @return the pluginConfig
*/
public YangPluginConfig getPluginConfig() {
return pluginConfig;
}
/**
* Sets plugin configurations.
*
* @param pluginConfig the pluginConfig to set
*/
public void setPluginConfig(YangPluginConfig pluginConfig) {
this.pluginConfig = pluginConfig;
}
}
......
......@@ -22,12 +22,14 @@ import java.util.TreeSet;
import static java.util.Collections.sort;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
......@@ -35,10 +37,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
......@@ -218,7 +220,7 @@ public class JavaImportData {
* @return import string for ListenerService class
*/
public String getListenerServiceImport() {
return IMPORT + LISTENER_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
}
/**
......@@ -227,6 +229,24 @@ public class JavaImportData {
* @return import string for ListenerRegistry class
*/
public String getListenerRegistryImport() {
return IMPORT + LISTENER_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for AbstractEvent class.
*
* @return import string for AbstractEvent class
*/
public String getAbstractEventsImport() {
return IMPORT + ONOS_EVENT_PKG + PERIOD + ABSTRACT_EVENT + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for EventListener class.
*
* @return import string for EventListener class
*/
public String getEventListenerImport() {
return IMPORT + ONOS_EVENT_PKG + PERIOD + EVENT_LISTENER + SEMI_COLAN + NEW_LINE;
}
}
......
......@@ -22,6 +22,7 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import com.google.common.base.MoreObjects;
......@@ -88,7 +89,7 @@ public class JavaQualifiedTypeInfo
/**
* Updates the leaf's java information.
*
* @param leaf leaf whose jave information is being updated
* @param leaf leaf whose java information is being updated
*/
public static void updateLeavesJavaQualifiedInfo(JavaLeafInfoContainer leaf) {
......@@ -102,7 +103,9 @@ public class JavaQualifiedTypeInfo
* Current leaves holder is adding a leaf info as a attribute to the
* current class.
*/
String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList());
String className =
AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
leaf.getConflictResolveConfig());
if (className != null) {
/*
* Corresponding to the attribute type a class needs to be imported,
......@@ -163,17 +166,20 @@ public class JavaQualifiedTypeInfo
* Returns the java qualified type information for the wrapper classes.
*
* @param referredTypesAttrInfo attribute of referred type
* @param confilictResolver plugin configurations
* @return return the import info for this attribute
*/
public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) {
public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo,
YangToJavaNamingConflictUtil confilictResolver) {
/*
* Get the java qualified type information for the wrapper classes and
* set it in new java attribute information.
*/
JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo();
qualifiedInfoOfFromString.setClassInfo(
getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true));
getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true, confilictResolver));
qualifiedInfoOfFromString.setPkgInfo(
getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null));
return qualifiedInfoOfFromString;
......
......@@ -19,6 +19,8 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
......@@ -84,10 +86,10 @@ public class TempJavaBeanFragmentFiles
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addConstructor(JavaAttributeInfo attr)
private void addConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
getGeneratedJavaFiles()));
getGeneratedJavaFiles(), pluginConfig));
}
/**
......@@ -98,10 +100,10 @@ public class TempJavaBeanFragmentFiles
* @throws IOException IO operation fail
*/
@Override
void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
addConstructor(newAttrInfo);
super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
addConstructor(newAttrInfo, pluginConfig);
}
/**
......
......@@ -21,10 +21,9 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
......@@ -57,16 +56,6 @@ public class TempJavaCodeFragmentFiles {
private TempJavaEnumerationFragmentFiles enumerationTempFiles;
/**
* Has the temporary files required for generated event classes.
*/
private TempJavaEventFragmentFiles eventTempFiles;
/**
* Has the temporary files required for generated event listenerclasses.
*/
private TempJavaEventListenerFragmentFiles eventListenerTempFiles;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -79,16 +68,10 @@ public class TempJavaCodeFragmentFiles {
setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo));
}
/**
* Creates user defined data type class file.
*/
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) {
setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo));
}
/**
* Creates enumeration class file.
*/
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) {
setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo));
}
......@@ -97,13 +80,6 @@ public class TempJavaCodeFragmentFiles {
setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_CLASS) != 0) {
setEventTempFiles(new TempJavaEventFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
setEventListenerTempFiles(new TempJavaEventListenerFragmentFiles(javaFileInfo));
}
}
/**
......@@ -180,43 +156,6 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Retrieves the temp file handle for event file generation.
*
* @return temp file handle for event file generation
*/
public TempJavaEventFragmentFiles getEventTempFiles() {
return eventTempFiles;
}
/**
* Sets temp file handle for event file generation.
*
* @param eventTempFiles temp file handle for event file generation
*/
public void setEventTempFiles(TempJavaEventFragmentFiles eventTempFiles) {
this.eventTempFiles = eventTempFiles;
}
/**
* Retrieves the temp file handle for event listener file generation.
*
* @return temp file handle for event listener file generation
*/
public TempJavaEventListenerFragmentFiles getEventListenerTempFiles() {
return eventListenerTempFiles;
}
/**
* Sets temp file handle for event listener file generation.
*
* @param eventListenerTempFiles temp file handle for event listener file generation
*/
public void setEventListenerTempFiles(
TempJavaEventListenerFragmentFiles eventListenerTempFiles) {
this.eventListenerTempFiles = eventListenerTempFiles;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
......@@ -238,7 +177,7 @@ public class TempJavaCodeFragmentFiles {
}
/*
* Creats service and manager class file.
* Creates service and manager class file.
*/
if (fileType == GENERATE_SERVICE_AND_MANAGER) {
getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
......@@ -251,22 +190,6 @@ public class TempJavaCodeFragmentFiles {
getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
}
if ((fileType & GENERATE_EVENT_CLASS) != 0) {
/*
* Creates event class file.
*/
if (getEventTempFiles() != null) {
getEventTempFiles().generateJavaFile(fileType, curNode);
}
}
if ((fileType & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
/**
* Creates event listener class file.
*/
getEventListenerTempFiles().generateJavaFile(fileType, curNode);
}
freeTemporaryResources(false);
}
......@@ -275,14 +198,16 @@ public class TempJavaCodeFragmentFiles {
*
* @param newAttrInfo the attribute info that needs to be added to temporary
* files
* @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
YangPluginConfig pluginConfig)
throws IOException {
if (getBeanTempFiles() != null) {
getBeanTempFiles()
.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
}
/**
......@@ -290,7 +215,7 @@ public class TempJavaCodeFragmentFiles {
*/
if (getTypeTempFiles() != null) {
getTypeTempFiles()
.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
}
}
......@@ -299,24 +224,26 @@ public class TempJavaCodeFragmentFiles {
* generated temporary file.
*
* @param yangTypeHolder YANG java data model node which has type info, eg union / typedef
* @param pluginConfig plugin configurations for naming convention
* @throws IOException IO operation fail
*/
public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder)
public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig)
throws IOException {
getTypeTempFiles()
.addTypeInfoToTempFiles(yangTypeHolder);
.addTypeInfoToTempFiles(yangTypeHolder, pluginConfig);
}
/**
* Adds build method for interface.
*
* @param pluginConfig plugin configurations
* @return build method for interface
* @throws IOException when fails to append to temporary file
*/
public String addBuildMethodForInterface()
public String addBuildMethodForInterface(YangPluginConfig pluginConfig)
throws IOException {
if (getBeanTempFiles() != null) {
return getBeanTempFiles().addBuildMethodForInterface();
return getBeanTempFiles().addBuildMethodForInterface(pluginConfig);
}
throw new TranslatorException("build method only supported for bean class");
}
......@@ -326,18 +253,19 @@ public class TempJavaCodeFragmentFiles {
*
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
* @param pluginConfig plugin configurations
* @return default constructor for class
* @throws IOException when fails to append to file
*/
public String addDefaultConstructor(String modifier, String toAppend)
public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
throws IOException {
if (getTypeTempFiles() != null) {
return getTypeTempFiles()
.addDefaultConstructor(modifier, toAppend);
.addDefaultConstructor(modifier, toAppend, pluginConfig);
}
if (getBeanTempFiles() != null) {
return getBeanTempFiles().addDefaultConstructor(modifier, toAppend);
return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig);
}
throw new TranslatorException("default constructor should not be added");
......@@ -380,13 +308,10 @@ public class TempJavaCodeFragmentFiles {
getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEventTempFiles() != null) {
getEventTempFiles().freeTemporaryResources(isErrorOccurred);
if (getServiceTempFiles() != null) {
getServiceTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEventListenerTempFiles() != null) {
getEventListenerTempFiles().freeTemporaryResources(isErrorOccurred);
}
}
}
......
......@@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
......@@ -175,26 +176,28 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
* @param curEnumInfo current YANG enum
* @throws IOException when fails to do IO operations.
*/
private void addAttributesForEnumClass(String curEnumName) throws IOException {
appendToFile(getEnumClassTempFileHandle(), generateEnumAttributeString(curEnumName, getEnumValue()));
private void addAttributesForEnumClass(String curEnumName, YangPluginConfig pluginConfig) throws IOException {
appendToFile(getEnumClassTempFileHandle(),
generateEnumAttributeString(curEnumName, getEnumValue(), pluginConfig));
}
/**
* Adds enum attributes to temporary files.
*
* @param curNode current YANG node
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
public void addEnumAttributeToTempFiles(YangNode curNode) throws IOException {
public void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig) throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum());
super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig);
if (curNode instanceof YangEnumeration) {
YangEnumeration enumeration = (YangEnumeration) curNode;
for (YangEnum curEnum : enumeration.getEnumSet()) {
setEnumValue(curEnum.getValue());
addToEnumStringList(curEnum.getNamedValue());
addToEnumSetJavaMap(curEnum.getNamedValue(), curEnum.getValue());
addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue());
addJavaSnippetInfoToApplicableTempFiles(curEnum.getNamedValue(), pluginConfig);
}
} else {
throw new TranslatorException("current node should be of enumeration type.");
......@@ -204,13 +207,14 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
/**
* Returns java attribute for enum class.
*
* @param pluginConfig plugin configurations
* @return java attribute
*/
public JavaAttributeInfo getJavaAttributeForEnum() {
public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
YangJavaType<?> javaType = new YangJavaType<>();
javaType.setDataType(YangDataTypes.INT32);
javaType.setDataTypeName("int");
javaType.updateJavaQualifiedInfo();
javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
return getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
javaType.getDataTypeName(), javaType,
......@@ -234,8 +238,9 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
* files
* @throws IOException IO operation fail
*/
void addJavaSnippetInfoToApplicableTempFiles(String curEnumName) throws IOException {
addAttributesForEnumClass(curEnumName);
void addJavaSnippetInfoToApplicableTempFiles(String curEnumName, YangPluginConfig pluginConfig)
throws IOException {
addAttributesForEnumClass(curEnumName, pluginConfig);
}
/**
......
/*
* 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;
import java.io.File;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for event java snippet generation.
*/
public class TempJavaEventFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_FILE_NAME_SUFFIX = "Event";
/**
* Java file handle for event file.
*/
private File eventJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/**
* Returns event's java file handle.
*
* @return java file handle
*/
private File getEventJavaFileHandle() {
return eventJavaFileHandle;
}
/**
* Sets event's java file handle.
*
* @param eventJavaFileHandle file handle for event
*/
private void setEventJavaFileHandle(File eventJavaFileHandle) {
this.eventJavaFileHandle = eventJavaFileHandle;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
@Override
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
createPackage(curNode);
String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
.getJavaFileInfo().getJavaName());
/**
* Creates event interface file.
*/
setEventJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_FILE_NAME_SUFFIX));
generateEventFile(getEventJavaFileHandle(), curNode, null);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
@Override
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
/**
* Close all java file handles and when error occurs delete the files.
*/
closeFile(getEventJavaFileHandle(), isError);
super.freeTemporaryResources(isErrorOccurred);
}
}
/*
* 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;
import java.io.File;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for event listener java snippet generation.
*/
public class TempJavaEventListenerFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
/**
* Java file handle for event listener file.
*/
private File eventListenerJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/**
* Returns event listeners's java file handle.
*
* @return java file handle
*/
private File getEventListenerJavaFileHandle() {
return eventListenerJavaFileHandle;
}
/**
* Sets event's java file handle.
*
* @param eventListenerJavaFileHandle file handle for event
*/
private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
@Override
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
createPackage(curNode);
String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
.getJavaFileInfo().getJavaName());
/**
* Creates event listener interface file.
*/
setEventListenerJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
@Override
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
/**
* Close all java file handles and when error occurs delete the files.
*/
closeFile(getEventListenerJavaFileHandle(), isError);
super.freeTemporaryResources(isErrorOccurred);
}
}
......@@ -26,6 +26,7 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
......@@ -196,9 +197,10 @@ public class TempJavaTypeFragmentFiles
*
* @param yangTypeHolder YANG java data model node which has type info, eg union /
* typedef
* @param pluginConfig plugin configurations for naming conventions
* @throws IOException IO operation fail
*/
public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder)
public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig)
throws IOException {
List<YangType<?>> typeList = yangTypeHolder.getTypeList();
......@@ -208,18 +210,19 @@ public class TempJavaTypeFragmentFiles
throw new TranslatorException("Type does not have Java info");
}
YangJavaType<?> javaType = (YangJavaType<?>) yangType;
javaType.updateJavaQualifiedInfo();
javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
String typeName = javaType.getDataTypeName();
if (javaType.getDataType().equals(DERIVED)) {
typeName = getCamelCase(typeName, null);
typeName = getCamelCase(typeName, pluginConfig.getConflictResolver());
}
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
typeName, javaType,
getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
false);
addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo);
addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo,
pluginConfig);
}
}
}
......@@ -231,18 +234,20 @@ public class TempJavaTypeFragmentFiles
* @param hasType the node for which the type is being added as an attribute
* @param javaAttributeInfo the attribute info that needs to be added to
* temporary files
* @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo)
private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo,
YangPluginConfig pluginConfig)
throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
addOfStringMethod(javaAttributeInfo);
addOfStringMethod(javaAttributeInfo, pluginConfig);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
addTypeConstructor(javaAttributeInfo);
addTypeConstructor(javaAttributeInfo, pluginConfig);
}
}
......@@ -250,24 +255,26 @@ public class TempJavaTypeFragmentFiles
* Adds type constructor.
*
* @param attr attribute info
* @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
private void addTypeConstructor(JavaAttributeInfo attr)
private void addTypeConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
getGeneratedJavaClassName()) + NEW_LINE);
getGeneratedJavaClassName(), pluginConfig) + NEW_LINE);
}
/**
* Adds of string for type.
*
* @param attr attribute info
* @param pluginConfig plugin configurations
* @throws IOException when fails to append to temporary file
*/
private void addOfStringMethod(JavaAttributeInfo attr)
private void addOfStringMethod(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
getGeneratedJavaClassName())
getGeneratedJavaClassName(), pluginConfig)
+ NEW_LINE);
}
......
......@@ -57,4 +57,19 @@ public interface JavaLeafInfoContainer
* updates the qualified info.
*/
void updateJavaQualifiedInfo();
/**
* Returns java naming conflict resolver.
*
* @return java naming conflict resolver
*/
YangToJavaNamingConflictUtil getConflictResolveConfig();
/**
* Sets java naming conflict resolver.
*
* @param conflictResolveConfig java naming conflict resolver
*/
void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig);
}
......
......@@ -16,7 +16,7 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
/**
* Represent java based identification of the YANG leaves.
......@@ -26,6 +26,8 @@ public interface JavaQualifiedTypeResolver
/**
* updates the qualified access details of the type.
*
* @param confilictResolver plugin configurations
*/
void updateJavaQualifiedInfo();
void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver);
}
......
......@@ -30,6 +30,7 @@ public class YangJavaLeaf
implements JavaLeafInfoContainer {
private JavaQualifiedTypeInfo javaQualifiedAccess;
private YangToJavaNamingConflictUtil conflictResolveConfig;
/**
* Returns a new YANG leaf object with java qualified access details.
......@@ -50,6 +51,7 @@ public class YangJavaLeaf
}
@Override
public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) {
return getCamelCase(getName(), conflictResolveConfig);
}
......@@ -63,4 +65,23 @@ public class YangJavaLeaf
public void updateJavaQualifiedInfo() {
updateLeavesJavaQualifiedInfo(this);
}
/**
* Returns java naming conflict resolve configurations.
*
* @return java naming conflict resolve configurations
*/
public YangToJavaNamingConflictUtil getConflictResolveConfig() {
return conflictResolveConfig;
}
/**
* Sets java naming conflict resolve configurations.
*
* @param conflictResolveConfig java naming conflict resolve configurations
*/
public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
this.conflictResolveConfig = conflictResolveConfig;
}
}
......
......@@ -29,6 +29,7 @@ public class YangJavaLeafList
extends YangLeafList
implements JavaLeafInfoContainer {
private JavaQualifiedTypeInfo javaQualifiedAccess;
private YangToJavaNamingConflictUtil conflictResolveConfig;
/**
* Returns a new YANG leaf object with java qualified access details.
......@@ -62,4 +63,24 @@ public class YangJavaLeafList
public void setJavaQualifiedInfo(JavaQualifiedTypeInfo typeInfo) {
javaQualifiedAccess = typeInfo;
}
/**
* Returns java naming conflict resolve configurations.
*
* @return java naming conflict resolve configurations
*/
@Override
public YangToJavaNamingConflictUtil getConflictResolveConfig() {
return conflictResolveConfig;
}
/**
* Sets java naming conflict resolve configurations.
*
* @param conflictResolveConfig java naming conflict resolve configurations
*/
@Override
public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
this.conflictResolveConfig = conflictResolveConfig;
}
}
......
......@@ -16,14 +16,21 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
......@@ -48,12 +55,24 @@ public class YangJavaModule
private TempJavaCodeFragmentFiles tempFileHandle;
/**
* List of notifications nodes.
*/
private List<YangNode> notificationNodes;
/**
* Creates a YANG node of module type.
*/
public YangJavaModule() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
setNotificationNodes(new ArrayList<>());
int gentype = GENERATE_SERVICE_AND_MANAGER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
}
/**
......@@ -121,6 +140,15 @@ public class YangJavaModule
*/
@Override
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.
* 2) Event class extending "AbstractEvent" and defining event type enum.
* 3) Event listener interface extending "EventListener".
* 4) Event subject class.
*
* The manager class needs to extend the "ListenerRegistry".
*/
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
......@@ -129,4 +157,53 @@ public class YangJavaModule
throw new TranslatorException("Failed to generate code for module node " + this.getName());
}
}
/**
* Returns notifications node list.
*
* @return notification nodes
*/
public List<YangNode> getNotificationNodes() {
return notificationNodes;
}
/**
* Sets notifications list.
*
* @param notificationNodes notification list
*/
private void setNotificationNodes(List<YangNode> notificationNodes) {
this.notificationNodes = notificationNodes;
}
/**
* Adds to notification node list.
*
* @param curNode notification node
*/
private void addToNotificaitonList(YangNode curNode) {
getNotificationNodes().add(curNode);
}
/**
* Checks if there is any rpc defined in the module or sub-module.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
*/
public boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangNotification) {
addToNotificaitonList(childNode);
}
childNode = childNode.getNextSibling();
}
if (!getNotificationNodes().isEmpty()) {
return true;
}
return false;
}
}
......
......@@ -30,8 +30,6 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesCont
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
......@@ -62,8 +60,7 @@ public class YangJavaNotification
public YangJavaNotification() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
/**
......@@ -167,17 +164,8 @@ public class YangJavaNotification
*/
@Override
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.
* 2) Event class extending "AbstractEvent" and defining event type enum.
* 3) Event listener interface extending "EventListener".
*
* The manager class needs to extend the "ListenerRegistry".
*/
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for notification node " + this.getName());
}
......
......@@ -135,6 +135,7 @@ public class YangJavaRpc
try {
((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(),
((YangNode) this).getName());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for RPC node " + this.getName());
......
......@@ -16,8 +16,13 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
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.YangSubModule;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
......@@ -25,6 +30,9 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
......@@ -49,12 +57,22 @@ public class YangJavaSubModule
private TempJavaCodeFragmentFiles tempFileHandle;
/**
* List of notifications nodes.
*/
private List<YangNode> notificationNodes = new ArrayList<>();
/**
* Creates YANG java sub module object.
*/
public YangJavaSubModule() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
int gentype = GENERATE_SERVICE_AND_MANAGER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
}
/**
......@@ -136,6 +154,15 @@ public class YangJavaSubModule
*/
@Override
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.
* 2) Event class extending "AbstractEvent" and defining event type enum.
* 3) Event listener interface extending "EventListener".
* 4) Event subject class.
*
* The manager class needs to extend the "ListenerRegistry".
*/
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
......@@ -144,4 +171,44 @@ public class YangJavaSubModule
throw new TranslatorException("Failed to generate code for submodule node " + this.getName());
}
}
/**
* Returns notifications node list.
*
* @return notification nodes
*/
public List<YangNode> getNotificationNodes() {
return notificationNodes;
}
/**
* Adds to notification node list.
*
* @param curNode notification node
*/
private void addToNotificaitonList(YangNode curNode) {
getNotificationNodes().add(curNode);
}
/**
* Checks if there is any rpc defined in the module or sub-module.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
*/
public boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangNotification) {
addToNotificaitonList(childNode);
}
childNode = childNode.getNextSibling();
}
if (!getNotificationNodes().isEmpty()) {
return true;
}
return false;
}
}
......
......@@ -19,6 +19,7 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
/**
* Represents java information corresponding to the YANG type.
......@@ -40,13 +41,13 @@ public class YangJavaType<T>
}
@Override
public void updateJavaQualifiedInfo() {
public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil confilictResolver) {
JavaQualifiedTypeInfo importInfo = getJavaQualifiedInfo();
/*
* Type is added as an attribute in the class.
*/
String className = AttributesJavaDataType.getJavaImportClass(this, false);
String className = AttributesJavaDataType.getJavaImportClass(this, false, confilictResolver);
if (className != null) {
/*
* Corresponding to the attribute type a class needs to be imported,
......
......@@ -49,6 +49,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
......@@ -58,6 +59,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_BINARY_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_BITS_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_DECIMAL64_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_TYPES_PKG;
/**
* Represents java data types info corresponding to YANG type.
......@@ -97,8 +102,10 @@ public final class AttributesJavaDataType {
return LONG;
case UINT64:
return BIG_INTEGER;
case BINARY:
return YANG_BINARY_CLASS;
case DECIMAL64:
//TODO: DECIMAL64.
return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
......@@ -112,7 +119,7 @@ public final class AttributesJavaDataType {
* Returns from string method parsed string.
*
* @param targetDataType target data type
* @param yangType YANG type
* @param yangType YANG type
* @return parsed string
*/
public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
......@@ -136,18 +143,16 @@ public final class AttributesJavaDataType {
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
case DECIMAL64:
//TODO: DECIMAL64.
case STRING:
return EMPTY_STRING;
case EMPTY:
case BOOLEAN:
return BOOLEAN_DATA_TYPE;
case ENUMERATION:
//TODO:ENUMERATION.
return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
case DECIMAL64:
case BITS:
//TODO:BITS
case BINARY:
//TODO:BINARY
case UNION:
case ENUMERATION:
case DERIVED:
return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
default:
......@@ -158,11 +163,13 @@ public final class AttributesJavaDataType {
/**
* Returns java import class.
*
* @param yangType YANG type
* @param yangType YANG type
* @param isListAttr if the attribute need to be a list
* @param pluginConfig plugin configurations
* @return java import class
*/
public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) {
public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr,
YangToJavaNamingConflictUtil pluginConfig) {
YangDataTypes type = yangType.getDataType();
......@@ -185,21 +192,19 @@ public final class AttributesJavaDataType {
case UINT64:
return BIG_INTEGER;
case DECIMAL64:
//TODO: DECIMAL64.
break;
return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case BOOLEAN:
return BOOLEAN_WRAPPER;
case ENUMERATION:
return getCapitalCase(
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case BITS:
//TODO:BITS
break;
return YANG_BITS_CLASS;
case BINARY:
//TODO:BINARY
break;
return YANG_BINARY_CLASS;
case LEAFREF:
//TODO:LEAFREF
break;
......@@ -210,11 +215,13 @@ public final class AttributesJavaDataType {
return BOOLEAN_WRAPPER;
case UNION:
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
null));
pluginConfig));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
case DERIVED:
return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null));
return getCapitalCase(
getCamelCase(yangType.getDataTypeName(), pluginConfig));
default:
throw new TranslatorException("given data type is not supported.");
}
......@@ -223,19 +230,17 @@ public final class AttributesJavaDataType {
case UINT64:
return BIG_INTEGER;
case DECIMAL64:
//TODO: DECIMAL64.
break;
return YANG_DECIMAL64_CLASS;
case STRING:
return STRING_DATA_TYPE;
case ENUMERATION:
return getCapitalCase(
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(), null));
getCamelCase(((YangJavaEnumeration) yangType.getDataTypeExtendedInfo()).getName(),
pluginConfig));
case BITS:
//TODO:BITS
break;
return YANG_BITS_CLASS;
case BINARY:
//TODO:BINARY
break;
return YANG_BINARY_CLASS;
case LEAFREF:
//TODO:LEAFREF
break;
......@@ -243,16 +248,16 @@ public final class AttributesJavaDataType {
//TODO:IDENTITYREF
break;
case EMPTY:
//TODO:EMPTY
break;
return BOOLEAN_DATA_TYPE;
case UNION:
return getCapitalCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
null));
pluginConfig));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
break;
case DERIVED:
return getCapitalCase(getCamelCase(yangType.getDataTypeName(), null));
return getCapitalCase(
getCamelCase(yangType.getDataTypeName(), pluginConfig));
default:
return null;
}
......@@ -263,9 +268,9 @@ public final class AttributesJavaDataType {
/**
* Returns java import package.
*
* @param yangType YANG type
* @param yangType YANG type
* @param isListAttr if the attribute is of list type
* @param classInfo java import class info
* @param classInfo java import class info
* @return java import package
*/
public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
......@@ -283,29 +288,22 @@ public final class AttributesJavaDataType {
case UINT32:
case STRING:
case BOOLEAN:
case EMPTY:
return JAVA_LANG;
case UINT64:
return JAVA_MATH;
case DECIMAL64:
//TODO: DECIMAL64.
break;
case ENUMERATION:
return getEnumsPackage(yangType);
case DECIMAL64:
case BITS:
//TODO:BITS
break;
case BINARY:
//TODO:BINARY
break;
return YANG_TYPES_PKG;
case LEAFREF:
//TODO:LEAFREF
break;
case IDENTITYREF:
//TODO:IDENTITYREF
break;
case EMPTY:
//TODO:EMPTY
break;
case UNION:
return getUnionPackage(yangType);
case INSTANCE_IDENTIFIER:
......@@ -320,19 +318,14 @@ public final class AttributesJavaDataType {
switch (type) {
case UINT64:
return JAVA_MATH;
case DECIMAL64:
//TODO: DECIMAL64
break;
case STRING:
return JAVA_LANG;
case ENUMERATION:
return getEnumsPackage(yangType);
case DECIMAL64:
case BITS:
//TODO:BITS
break;
case BINARY:
//TODO:BINARY
break;
return YANG_TYPES_PKG;
case LEAFREF:
//TODO:LEAFREF
break;
......@@ -340,8 +333,7 @@ public final class AttributesJavaDataType {
//TODO:IDENTITYREF
break;
case EMPTY:
//TODO:EMPTY
break;
return JAVA_LANG;
case UNION:
return getUnionPackage(yangType);
case INSTANCE_IDENTIFIER:
......
......@@ -17,7 +17,6 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
......@@ -27,12 +26,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
......@@ -56,6 +55,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
......@@ -95,8 +95,6 @@ public final class ClassDefinitionGenerator {
return getTypeClassDefinition(yangName);
case GENERATE_ENUM_CLASS:
return getEnumClassDefinition(yangName);
case GENERATE_EVENT_LISTENER_INTERFACE:
return getEventListenerDefinition(yangName);
default:
return null;
}
......@@ -123,9 +121,12 @@ public final class ClassDefinitionGenerator {
case GENERATE_SERVICE_AND_MANAGER:
return getRpcInterfaceDefinition(yangName, curNode);
case GENERATE_EVENT_CLASS:
String eventName = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
String eventName = yangName + SUBJECT;
return getEventDefinition(yangName, eventName);
case GENERATE_EVENT_LISTENER_INTERFACE:
return getEventListenerDefinition(yangName);
case GENERATE_EVENT_SUBJECT_CLASS:
return getClassDefinition(yangName);
default:
return null;
}
......@@ -183,7 +184,6 @@ public final class ClassDefinitionGenerator {
* Returns builder file class definition.
*
* @param yangName file name
* @param genFileTypes
* @return definition
*/
private static String getBuilderClassDefinition(String yangName) {
......@@ -198,8 +198,18 @@ public final class ClassDefinitionGenerator {
* @return definition
*/
private static String getImplClassDefinition(String yangName) {
return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE
+ yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns impl file class definition.
*
* @param yangName file name
* @return definition
*/
private static String getClassDefinition(String yangName) {
return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
......@@ -244,14 +254,14 @@ public final class ClassDefinitionGenerator {
if (yangName.contains(SERVICE)) {
String[] strArray = yangName.split(SERVICE);
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION
+ EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA
+ SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + NEW_LINE + EIGHT_SPACE_INDENTATION
+ EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE
+ yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE + NEW_LINE
+ yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
}
......
......@@ -145,10 +145,11 @@ public final class JavaCodeSnippetGen {
*
* @param name name of attribute
* @param value value of the enum
* @param pluginConfig plugin configurations
* @return string for enum's attribute
*/
public static String generateEnumAttributeString(String name, int value) {
return getJavaDoc(ENUM_ATTRIBUTE, name, false) + FOUR_SPACE_INDENTATION
public static String generateEnumAttributeString(String name, int value, YangPluginConfig pluginConfig) {
return getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
+ value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
......
......@@ -27,18 +27,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
......@@ -87,6 +76,7 @@ public class JavaExtendsListHolder {
if (!fileInfo.getPackage().equals(info.getPkgInfo())) {
JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
importData.addImportInfo(info);
/*true means import should be added*/
getExtendedClassStore().put(info, true);
}
......@@ -95,33 +85,6 @@ public class JavaExtendsListHolder {
}
/**
* Returns extends string for class.
*
* @param genFileType generated file type
* @param className class name
* @param isNotificationPresent if notification node is present
* @return extends string
*/
public String getExtendsString(int genFileType, String className, boolean isNotificationPresent) {
String extend = EXTEND + SPACE;
if (genFileType == GENERATE_SERVICE_AND_MANAGER && isNotificationPresent) {
extend = extend + LISTENER_REG + DIAMOND_OPEN_BRACKET + className + EVENT_STRING + COMMA + SPACE
+ className + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE;
} else {
for (JavaQualifiedTypeInfo info : getExtendsList()) {
if (info.getClassInfo().equals(className)) {
if (!getExtendedClassStore().get(info)) {
return extend + info.getClassInfo();
} else {
return extend + info.getPkgInfo() + PERIOD + info.getClassInfo();
}
}
}
}
return null;
}
/**
* Returns extends list.
*
* @return the extendsList
......
......@@ -35,24 +35,35 @@ import static java.util.Collections.sort;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
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.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
......@@ -102,12 +113,6 @@ public final class TempJavaCodeFragmentFilesUtils {
if (container.getBeanTempFiles() != null) {
return container.getBeanTempFiles();
}
if (container.getEventTempFiles() != null) {
return container.getEventTempFiles();
}
if (container.getEventListenerTempFiles() != null) {
return container.getEventListenerTempFiles();
}
if (container.getServiceTempFiles() != null) {
return container.getServiceTempFiles();
}
......@@ -234,6 +239,31 @@ public final class TempJavaCodeFragmentFilesUtils {
}
/**
* Adds annotations imports.
*
* @param imports list if imports
* @param operation to add or to delete
*/
public static void addAnnotationsImports(List<String> imports, boolean operation) {
if (operation) {
imports.add(ACTIVATE_ANNOTATION_IMPORT);
imports.add(DEACTIVATE_ANNOTATION_IMPORT);
imports.add(COMPONENT_ANNOTATION_IMPORT);
imports.add(SERVICE_ANNOTATION_IMPORT);
imports.add(LOGGER_FACTORY_IMPORT);
imports.add(LOGGER_IMPORT);
} else {
imports.remove(ACTIVATE_ANNOTATION_IMPORT);
imports.remove(DEACTIVATE_ANNOTATION_IMPORT);
imports.remove(COMPONENT_ANNOTATION_IMPORT);
imports.remove(SERVICE_ANNOTATION_IMPORT);
imports.remove(LOGGER_FACTORY_IMPORT);
imports.remove(LOGGER_IMPORT);
}
sortImports(imports);
}
/**
* Performs given operations on import list.
*
* @param imports list of imports
......@@ -328,4 +358,13 @@ public final class TempJavaCodeFragmentFilesUtils {
return imports;
}
/**
* Returns event enum start.
*
* @return event enum start
*/
public static String getEventEnumTypeStart() {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
}
}
......
......@@ -32,8 +32,13 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
......@@ -49,7 +54,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATIO
public final class YangJavaModelUtils {
/**
* Creates YANG java model utility.
* Creates an instance of YANG java model utility.
*/
private YangJavaModelUtils() {
}
......@@ -64,6 +69,7 @@ public final class YangJavaModelUtils {
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPluginConfig.getConflictResolver()));
......@@ -71,6 +77,7 @@ public final class YangJavaModelUtils {
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
}
/**
......@@ -90,6 +97,7 @@ public final class YangJavaModelUtils {
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
}
/**
......@@ -120,6 +128,16 @@ public final class YangJavaModelUtils {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
}
} else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
if (!((YangJavaSubModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
}
}
} else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
/*
* Container
......@@ -139,13 +157,14 @@ public final class YangJavaModelUtils {
* Union
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo);
.addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
/*
* Enumeration
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
.addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo);
.addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangChoice) {
/*Do nothing, only the interface needs to be generated*/
} else {
......@@ -171,6 +190,32 @@ public final class YangJavaModelUtils {
}
/**
* Updates notification node info in service temporary file.
*
* @param javaCodeGeneratorInfo java code generator info
* @param yangPluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig) throws IOException {
if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles()
.addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
}
}
if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo)
.getNotificationNodes()) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles()
.addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
}
}
}
/**
* Generates code for the current ata model node and adds itself as an attribute in the parent.
*
* @param javaCodeGeneratorInfo YANG java file info node
......@@ -193,7 +238,7 @@ public final class YangJavaModelUtils {
/*
* Update the current nodes info in its parent nodes generated files.
*/
addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin);
}
/**
......@@ -242,7 +287,7 @@ public final class YangJavaModelUtils {
.addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
.addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo);
.addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
}
}
......@@ -284,7 +329,26 @@ public final class YangJavaModelUtils {
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
if (!((YangJavaModule) javaCodeGeneratorInfo)
.isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
}
} else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
if (!((YangJavaSubModule) javaCodeGeneratorInfo)
.isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
}
}
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
/*Updates java code generator info with events info.*/
private static void updateCodeGenInfoForEvent(JavaCodeGeneratorInfo javaCodeGeneratorInfo) {
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_SUBJECT_CLASS);
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_CLASS);
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE);
}
}
......
......@@ -197,6 +197,11 @@ public final class UtilConstants {
public static final String PARSE_BYTE = "parseByte";
/**
* Static attribute for parse boolean.
*/
public static final String PARSE_BOOLEAN = "parseBoolean";
/**
* Static attribute for parse short.
*/
public static final String PARSE_SHORT = "parseShort";
......@@ -242,6 +247,11 @@ public final class UtilConstants {
public static final String SPACE = " ";
/**
* Static attribute for subject.
*/
public static final String SUBJECT = "Subject";
/**
* Static attribute for ListenerRegistry.
*/
public static final String LISTENER_REG = "ListenerRegistry";
......@@ -254,7 +264,7 @@ public final class UtilConstants {
/**
* Static attribute for listener package.
*/
public static final String LISTENER_PKG = "org.onosproject.event";
public static final String ONOS_EVENT_PKG = "org.onosproject.event";
/**
* Static attribute for colon.
......@@ -787,6 +797,11 @@ public final class UtilConstants {
public static final String ENUM = "enum";
/**
* Static attribute for type syntax.
*/
public static final String TYPE = "Type";
/**
* Static attribute for static syntax.
*/
public static final String STATIC = "static";
......@@ -852,6 +867,11 @@ public final class UtilConstants {
public static final String EVENT_LISTENER_STRING = "Listener";
/**
* For event subject file generation.
*/
public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
/**
* Static attribute for impl syntax.
*/
public static final String IMPL = "Impl";
......@@ -957,6 +977,130 @@ public final class UtilConstants {
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
/**
* Static attribute for activate annotation.
*/
public static final String ACTIVATE_ANNOTATION = "@Activate\n";
/**
* Static attribute for activate.
*/
public static final String ACTIVATE = "activate";
/**
* Static attribute for activate annotation import.
*/
public static final String ACTIVATE_ANNOTATION_IMPORT = "import org.apache.felix.scr.annotations.Activate;\n";
/**
* Static attribute for deactivate annotation.
*/
public static final String DEACTIVATE_ANNOTATION = "@Deactivate\n";
/**
* Static attribute for deactivate.
*/
public static final String DEACTIVATE = "deactivate";
/**
* Static attribute for deactivate annotation import.
*/
public static final String DEACTIVATE_ANNOTATION_IMPORT =
"import org.apache.felix.scr.annotations.Deactivate;\n";
/**
* Static attribute for component annotation.
*/
public static final String COMPONENT_ANNOTATION = "@Component";
/**
* Static attribute for immediate.
*/
public static final String IMMEDIATE = "immediate";
/**
* Static attribute for component annotation import.
*/
public static final String COMPONENT_ANNOTATION_IMPORT =
"import org.apache.felix.scr.annotations.Component;\n";
/**
* Static attribute for service annotation.
*/
public static final String SERVICE_ANNOTATION = "@Service\n";
/**
* Static attribute for service annotation import.
*/
public static final String SERVICE_ANNOTATION_IMPORT =
"import org.apache.felix.scr.annotations.Service;\n";
/**
* Static attribute for logger factory import.
*/
public static final String LOGGER_FACTORY_IMPORT =
"import static org.slf4j.LoggerFactory.getLogger;\n";
/**
* Static attribute for logger import.
*/
public static final String LOGGER_IMPORT =
"import org.slf4j.Logger;\n";
/**
* Static attribute for logger statement.
*/
public static final String LOGGER_STATEMENT =
"\n private final Logger log = getLogger(getClass());\n";
/**
* Static attribute for logger statement for started.
*/
public static final String STARTED_LOG_INFO =
"log.info(\"Started\");\n";
/**
* Static attribute for logger statement for stopped.
*/
public static final String STOPPED_LOG_INFO =
"log.info(\"Stopped\");\n";
/**
* Static attribute for AbstractEvent.
*/
public static final String ABSTRACT_EVENT = "AbstractEvent";
/**
* Static attribute for EventListener.
*/
public static final String EVENT_LISTENER = "EventListener";
/**
* Static attribute for YangBinary class.
*/
public static final String YANG_BINARY_CLASS = "YangBinary";
/**
* Static attribute for YangBinary class.
*/
public static final String YANG_BITS_CLASS = "YangBits";
/**
* Static attribute for YANG types package.
*/
public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.utils.builtindatatype";
/**
* Static attribute for MathContext class.
*/
public static final String MATH_CONTEXT = "MathContext";
/**
* Static attribute for DECIMAL64 class.
*/
public static final String YANG_DECIMAL64_CLASS = "YangDecimal64";
/**
* Static attribute for YANG file error.
*/
public static final String YANG_FILE_ERROR = "YANG file error : ";
......
/*
* 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.utils.builtindatatype;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
* Represents binary data type.
*/
public final class YangBinary {
private byte[] byteArray;
/**
* Creates an instance of YANG binary.
*/
private YangBinary() {
}
/**
* Creates an instance of YANG binary.
*
* @param bytes byte array
*/
public YangBinary(byte[] bytes) {
this.byteArray = bytes;
}
/**
* Returns object of YANG binary.
*
* @param bytes byte array
* @return object of YANG binary
*/
public static YangBinary of(byte[] bytes) {
return new YangBinary(bytes);
}
/**
* Returns byte array.
*
* @return byte array
*/
public byte[] byteArray() {
return byteArray;
}
@Override
public int hashCode() {
return Objects.hash(byteArray);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof YangBinary) {
YangBinary other = (YangBinary) obj;
return Objects.equals(byteArray, other.byteArray);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("byteArray", byteArray)
.toString();
}
/**
* Returns the object of YANG binary fromString input String.
*
* @param valInString input String
* @return Object of YANG binary
*/
public static YangBinary fromString(String valInString) {
try {
byte[] tmpVal = valInString.getBytes();
return of(tmpVal);
} catch (Exception e) {
}
return null;
}
}
/*
* 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.utils.builtindatatype;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
* Represents bits data type.
*/
public class YangBits {
private byte[] byteArray;
/**
* Creates an instance of YANG bits.
*/
private YangBits() {
}
/**
* Creates an instance of YANG bits.
*
* @param bytes byte array
*/
public YangBits(byte[] bytes) {
this.byteArray = bytes;
}
/**
* Returns object of YANG bits.
*
* @param bytes byte array
* @return object of YANG bits
*/
public static YangBits of(byte[] bytes) {
return new YangBits(bytes);
}
/**
* Returns byte array.
*
* @return byte array
*/
public byte[] byteArray() {
return byteArray;
}
@Override
public int hashCode() {
return Objects.hash(byteArray);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof YangBits) {
YangBits other = (YangBits) obj;
return Objects.equals(byteArray, other.byteArray);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("byteArray", byteArray)
.toString();
}
/**
* Returns the object of YANG bits fromString input String.
*
* @param valInString input String
* @return Object of YANG bits
*/
public static YangBits fromString(String valInString) {
try {
byte[] tmpVal = valInString.getBytes();
return of(tmpVal);
} catch (Exception e) {
}
return null;
}
}
/*
* 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.utils.builtindatatype;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
* Represents YANG decimal 64.
*/
public class YangDecimal64 {
private int fractionDigit;
/**
* Creates an instance of YANG decimal64.
*/
public YangDecimal64() {
}
/**
* Creates an instance of of YANG decimal64.
*
* @param fractionDigit fraction digit
*/
public YangDecimal64(int fractionDigit) {
this.setFractionDigit(fractionDigit);
}
/**
* Returns fraction digit.
*
* @return the fractionDigit
*/
public int getFractionDigit() {
return fractionDigit;
}
/**
* Sets fraction digit.
*
* @param fractionDigit fraction digits.
*/
public void setFractionDigit(int fractionDigit) {
this.fractionDigit = fractionDigit;
}
/**
* Returns object of YANG decimal64.
*
* @param value fraction digit
* @return YANG decimal64
*/
public static YangDecimal64 of(int value) {
return new YangDecimal64(value);
}
@Override
public int hashCode() {
return Objects.hash(fractionDigit);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof YangDecimal64) {
YangDecimal64 other = (YangDecimal64) obj;
return Objects.equals(fractionDigit, other.fractionDigit);
}
return false;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.omitNullValues()
.add("fractionDigit", fractionDigit)
.toString();
}
/**
* Returns the object of YANG decimal64 fromString input String.
*
* @param valInString input String
* @return Object of YANG decimal64
*/
public static YangDecimal64 fromString(String valInString) {
try {
int tmpVal = Integer.parseInt(valInString);
return of(tmpVal);
} catch (Exception e) {
}
return null;
}
}
......@@ -22,6 +22,8 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
......@@ -84,10 +86,12 @@ public final class FileSystemUtil {
YangNode parent = getParentNodeInGenCode(yangNode);
if (parent != null) {
pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true);
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
} else {
pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false);
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
}
} catch (IOException e) {
throw new IOException("failed to create package-info file");
......@@ -120,6 +124,7 @@ public final class FileSystemUtil {
*/
public static String readAppendFile(String toAppend, String spaces)
throws IOException {
FileReader fileReader = new FileReader(toAppend);
BufferedReader bufferReader = new BufferedReader(fileReader);
try {
......@@ -156,15 +161,22 @@ public final class FileSystemUtil {
*/
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
throws IOException {
List<FileWriter> fileWriterStore = new ArrayList<>();
FileWriter fileWriter = new FileWriter(inputFile, true);
fileWriterStore.add(fileWriter);
PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
if (!isClose) {
outputPrintWriter.write(contentTobeAdded);
outputPrintWriter.flush();
outputPrintWriter.close();
} else {
fileWriter.flush();
fileWriter.close();
for (FileWriter curWriter : fileWriterStore) {
curWriter.flush();
curWriter.close();
curWriter = null;
}
}
}
}
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.utils.io.impl;
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
......@@ -181,7 +182,12 @@ public final class JavaDocGen {
/**
* For manager setters.
*/
MANAGER_SETTER_METHOD
MANAGER_SETTER_METHOD,
/**
* For event subject.
*/
EVENT_SUBJECT_CLASS
}
/**
......@@ -190,14 +196,15 @@ public final class JavaDocGen {
* @param type java doc type
* @param name name of the YangNode
* @param isList is list attribute
* @param pluginConfig plugin configurations
* @return javadocs.
*/
public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) {
name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, null));
name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver()));
switch (type) {
case IMPL_CLASS: {
return generateForImplClass(name);
return generateForClass(name);
}
case BUILDER_CLASS: {
return generateForBuilderClass(name);
......@@ -248,7 +255,7 @@ public final class JavaDocGen {
return generateForRpcService(name);
}
case RPC_MANAGER: {
return generateForImplClass(name);
return generateForClass(name);
}
case EVENT: {
return generateForEvent(name);
......@@ -256,6 +263,9 @@ public final class JavaDocGen {
case EVENT_LISTENER: {
return generateForEventListener(name);
}
case EVENT_SUBJECT_CLASS: {
return generateForClass(name);
}
default: {
return generateForConstructors(name);
}
......@@ -279,14 +289,17 @@ public final class JavaDocGen {
* @param rpcName name of the rpc
* @param inputName name of input
* @param outputName name of output
* @param pluginConfig plugin configurations
* @return javaDocs of rpc method
*/
public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName) {
rpcName = getCamelCase(rpcName, null);
String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
+ rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ getInputString(inputName, rpcName);
public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName,
YangPluginConfig pluginConfig) {
rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
String javadoc =
NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
+ rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ getInputString(inputName, rpcName);
if (!outputName.equals(VOID)) {
javadoc = javadoc + getOutputString(outputName, rpcName);
}
......@@ -470,7 +483,7 @@ public final class JavaDocGen {
* @param className class name
* @return javaDocs
*/
private static String generateForImplClass(String className) {
private static String generateForClass(String className) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
}
......
......@@ -60,8 +60,8 @@ public final class YangFileScanner {
* operations
*/
public static List<String> getYangFiles(String root) throws IOException {
List<String> yangFiles = getFiles(root, YANG_FILE_EXTENTION);
return yangFiles;
return getFiles(root, YANG_FILE_EXTENTION);
}
/**
......
......@@ -71,7 +71,8 @@ public class AttributesJavaDataTypeTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {AttributesJavaDataType.class };
......@@ -87,16 +88,17 @@ public class AttributesJavaDataTypeTest {
*/
@Test
public void testgetJavaClassInfo() {
test = getJavaImportClass(getStubYangType(TYPE1), false);
YangToJavaNamingConflictUtil pluginConfig = null;
test = getJavaImportClass(getStubYangType(TYPE1), false, pluginConfig);
assertThat(true, is(test.equals(CLASS_INFO1)));
test = getJavaImportClass(getStubYangType(TYPE2), true);
test = getJavaImportClass(getStubYangType(TYPE2), true, pluginConfig);
assertThat(true, is(test.equals(CLASS_INFO5)));
test = getJavaImportClass(getStubYangType(TYPE3), false);
test = getJavaImportClass(getStubYangType(TYPE3), false, pluginConfig);
assertThat(null, is(test));
test = getJavaImportClass(getStubYangType(TYPE4), false);
test = getJavaImportClass(getStubYangType(TYPE4), false, pluginConfig);
assertThat(null, is(test));
}
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
......@@ -44,7 +45,7 @@ public final class ChoiceCaseTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator");
generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
}
......
......@@ -46,7 +46,7 @@ public final class EnumTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
generateJavaCode(node, yangPluginConfig, "EnumTranslator");
generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/EnumTestGenFile/");
}
......
......@@ -29,6 +29,7 @@ import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
......@@ -105,7 +106,7 @@ public final class MethodsGeneratorTest {
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {MethodsGenerator.class};
Class<?>[] classesToConstruct = {MethodsGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -118,8 +119,10 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getTypeConstructorTest() {
YangPluginConfig pluginConfig = new YangPluginConfig();
JavaAttributeInfo testAttr = getTestAttribute();
String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME);
String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME, pluginConfig);
assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
}
......@@ -162,7 +165,8 @@ public final class MethodsGeneratorTest {
@Test
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER);
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
......@@ -172,7 +176,8 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getConstructorStartTest() {
String method = getConstructorStart(CLASS_NAME);
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructorStart(CLASS_NAME, pluginConfig);
assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE)));
......@@ -227,10 +232,10 @@ public final class MethodsGeneratorTest {
public void getSetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER);
// assertThat(true, is(
// method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX
// + getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
// + ATTRIBUTE_NAME)));
assertThat(true, is(
method.contains(PUBLIC + SPACE + VOID + SPACE +
SET_METHOD_PREFIX + getCapitalCase(CLASS_NAME) + OPEN_PARENTHESIS +
STRING_DATA_TYPE + SPACE + ATTRIBUTE_NAME)));
}
/**
......@@ -240,7 +245,8 @@ public final class MethodsGeneratorTest {
public void getSetterForInterfaceTest() {
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false,
GENERATE_SERVICE_AND_MANAGER);
// assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
assertThat(true, is(method.contains(VOID + SPACE +
SET_METHOD_PREFIX + "Testname")));
}
/**
......
......@@ -46,7 +46,7 @@ public final class NotificationTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
generateJavaCode(node, yangPluginConfig, "NotificationTest");
generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/NotificationTest/");
}
......
......@@ -46,7 +46,7 @@ public final class RpcTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
generateJavaCode(node, yangPluginConfig, "RpcTranslator");
generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/RpcTestGenFile/");
}
......
......@@ -46,7 +46,7 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig, "UnionTranslator");
generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/UnionTestGenFile/");
}
......
......@@ -25,6 +25,7 @@ import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
......@@ -125,7 +126,20 @@ public final class FileSystemUtilTest {
javafileInfo.setJavaName(TEST_DATA_1);
javafileInfo.setBaseCodeGenPath("");
javafileInfo.setPackageFilePath(BASE_PKG);
javafileInfo.setPluginConfig(getStubPluginConfig());
module.setJavaFileInfo(javafileInfo);
return module;
}
/**
* Returns stub pluginConfig.
*
* @return stub pluginConfig
*/
private YangPluginConfig getStubPluginConfig() {
YangPluginConfig pluginConfig = new YangPluginConfig();
pluginConfig.setConflictResolver(null);
return pluginConfig;
}
}
......
......@@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
......@@ -55,7 +56,7 @@ public final class JavaDocGenTest {
*/
@Test
public void builderClassGenerationTest() {
String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false);
String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of")
&& builderClassJavaDoc.contains(END_STRING)));
}
......@@ -65,9 +66,10 @@ public final class JavaDocGenTest {
*/
@Test
public void builderInterfaceGenerationTest() {
String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false);
String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(builderInterfaceJavaDoc.contains("Builder for") && builderInterfaceJavaDoc.contains(END_STRING)));
is(builderInterfaceJavaDoc.contains("Builder for")
&& builderInterfaceJavaDoc.contains(END_STRING)));
}
/**
......@@ -75,7 +77,7 @@ public final class JavaDocGenTest {
*/
@Test
public void buildGenerationTest() {
String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false);
String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING)));
}
......@@ -90,7 +92,8 @@ public final class JavaDocGenTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaDocGen.class };
......@@ -106,9 +109,10 @@ public final class JavaDocGenTest {
*/
@Test
public void constructorGenerationTest() {
String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false);
String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(constructorDoc.contains("Creates an instance of ") && constructorDoc.contains("builder object of")
is(constructorDoc.contains("Creates an instance of ")
&& constructorDoc.contains("builder object of")
&& constructorDoc.contains("@param") && constructorDoc.contains("*/\n")));
}
......@@ -117,7 +121,7 @@ public final class JavaDocGenTest {
*/
@Test
public void defaultConstructorGenerationTest() {
String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false);
String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ")
&& defaultConstructorDoc.contains(END_STRING)));
}
......@@ -127,8 +131,9 @@ public final class JavaDocGenTest {
*/
@Test
public void getterGenerationTest() {
String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false);
assertThat(true, is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
}
/**
......@@ -136,7 +141,7 @@ public final class JavaDocGenTest {
*/
@Test
public void implClassGenerationTest() {
String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false);
String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(implClassJavaDoc.contains("Represents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
......@@ -147,7 +152,7 @@ public final class JavaDocGenTest {
*/
@Test
public void interfaceGenerationTest() {
String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false);
String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of")
&& interfaceJavaDoc.contains(END_STRING)));
......@@ -158,8 +163,9 @@ public final class JavaDocGenTest {
*/
@Test
public void packageInfoGenerationTest() {
String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false);
assertThat(true, is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
}
/**
......@@ -167,7 +173,7 @@ public final class JavaDocGenTest {
*/
@Test
public void packageInfoGenerationForChildNodeTest() {
String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true);
String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true, getStubPluginConfig());
assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes")
&& packageInfo.contains(END_STRING)));
}
......@@ -177,7 +183,7 @@ public final class JavaDocGenTest {
*/
@Test
public void setterGenerationTest() {
String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false);
String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true,
is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING)));
}
......@@ -187,7 +193,18 @@ public final class JavaDocGenTest {
*/
@Test
public void typeDefSetterGenerationTest() {
String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false);
String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING)));
}
/**
* Returns stub pluginConfig.
*
* @return stub pluginConfig
*/
private YangPluginConfig getStubPluginConfig() {
YangPluginConfig pluginConfig = new YangPluginConfig();
pluginConfig.setConflictResolver(null);
return pluginConfig;
}
}
\ No newline at end of file
......
......@@ -25,6 +25,7 @@ import org.apache.maven.project.MavenProject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.UtilConstants;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
......@@ -68,7 +69,7 @@ public final class YangIoUtilsTest {
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
......@@ -83,7 +84,7 @@ public final class YangIoUtilsTest {
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false);
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
......@@ -98,7 +99,7 @@ public final class YangIoUtilsTest {
File dirPath = new File(CREATE_PATH);
dirPath.mkdirs();
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true);
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
}
......@@ -114,7 +115,7 @@ public final class YangIoUtilsTest {
File dirPath = new File("invalid/check");
thrown.expect(IOException.class);
thrown.expectMessage(MSG);
addPackageInfo(dirPath, CHECK1, CREATE_PATH, false);
addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath1 = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath1.isFile(), is(false));
}
......@@ -130,7 +131,8 @@ public final class YangIoUtilsTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {YangIoUtils.class };
......@@ -192,7 +194,7 @@ public final class YangIoUtilsTest {
addToSource(sourceDir.toString(), project, context);
}
/*
/**
* Unit test case for trim at last method.
*/
@Test
......@@ -202,4 +204,14 @@ public final class YangIoUtilsTest {
assertThat(test.contains(TRIM_STRING), is(true));
}
/**
* Returns stub pluginConfig.
*
* @return stub pluginConfig
*/
private YangPluginConfig getStubPluginConfig() {
YangPluginConfig pluginConfig = new YangPluginConfig();
pluginConfig.setConflictResolver(null);
return pluginConfig;
}
}
......