Gaurav Agrawal
Committed by Thomas Vachuska

[ONOS-4711] Removed cyclic dependencies

Change-Id: I9ffea9a1a1b72f6ed3a23c0edb04cfc37bd8e48e
Showing 69 changed files with 1150 additions and 1405 deletions
......@@ -31,11 +31,11 @@ import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
/**
* Represents utilities for data model tree.
*/
public final class DataModelUtils {
/**
* Creates a new data model tree utility.
*/
......
......@@ -17,7 +17,7 @@
package org.onosproject.yangutils.linker;
import java.util.Set;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.datamodel.YangNode;
/**
* Abstraction of entity which provides linking service of YANG files.
......@@ -28,7 +28,7 @@ public interface YangLinker {
* Resolve the import and include dependencies for a given resolution
* information.
*
* @param yangFileInfoSet set of all dependent YANG files
* @param yangNodeSet set of all dependent YANG nodes
*/
void resolveDependencies(Set<YangFileInfo> yangFileInfoSet);
void resolveDependencies(Set<YangNode> yangNodeSet);
}
......
......@@ -25,7 +25,6 @@ import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.YangLinker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
......@@ -53,53 +52,51 @@ public class YangLinkerManager
/**
* Creates YANG nodes set.
*
* @param yangFileInfoSet YANG file information set
* @param yangNodeSet YANG node information set
*/
public void createYangNodeSet(Set<YangFileInfo> yangFileInfoSet) {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
getYangNodeSet().add(yangFileInfo.getRootNode());
}
public void createYangNodeSet(Set<YangNode> yangNodeSet) {
getYangNodeSet().addAll(yangNodeSet);
}
@Override
public void resolveDependencies(Set<YangFileInfo> yangFileInfoSet) {
public void resolveDependencies(Set<YangNode> yangNodeSet) {
// Create YANG node set.
createYangNodeSet(yangFileInfoSet);
createYangNodeSet(yangNodeSet);
// Carry out linking of sub module with module.
linkSubModulesToParentModule(yangFileInfoSet);
linkSubModulesToParentModule(yangNodeSet);
// Add references to import list.
addRefToYangFilesImportList(yangFileInfoSet);
addRefToYangFilesImportList(yangNodeSet);
// Add reference to include list.
addRefToYangFilesIncludeList(yangFileInfoSet);
addRefToYangFilesIncludeList(yangNodeSet);
// TODO check for circular import/include.
// Carry out inter-file linking.
processInterFileLinking(yangFileInfoSet);
processInterFileLinking(yangNodeSet);
}
/**
* Resolves sub-module linking by linking sub module with parent module.
*
* @param yangFileInfoSet set of YANG files info
* @param yangNodeSet set of YANG files info
* @throws LinkerException fails to link sub-module to parent module
*/
public void linkSubModulesToParentModule(Set<YangFileInfo> yangFileInfoSet)
public void linkSubModulesToParentModule(Set<YangNode> yangNodeSet)
throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
YangNode yangNode = yangFileInfo.getRootNode();
for (YangNode yangNode : yangNodeSet) {
if (yangNode instanceof YangSubModule) {
try {
((YangSubModule) yangNode).linkWithModule(getYangNodeSet());
} catch (DataModelException e) {
String errorInfo = "YANG file error: " + yangFileInfo.getYangFileName() + " at line: "
String errorInfo = "YANG file error: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
+ e.getMessage();
throw new LinkerException(errorInfo);
// TODO add file path in exception message in util manager.
}
}
}
......@@ -108,20 +105,20 @@ public class YangLinkerManager
/**
* Adds imported node information to the import list.
*
* @param yangFileInfoSet set of YANG files info
* @param yangNodeSet set of YANG files info
* @throws LinkerException fails to find imported module
*/
public void addRefToYangFilesImportList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
YangNode yangNode = yangFileInfo.getRootNode();
public void addRefToYangFilesImportList(Set<YangNode> yangNodeSet) throws LinkerException {
for (YangNode yangNode : yangNodeSet) {
if (yangNode instanceof YangReferenceResolver) {
try {
((YangReferenceResolver) yangNode).addReferencesToImportList(getYangNodeSet());
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangFileInfo.getYangFileName() + " at line: "
String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
+ e.getMessage();
throw new LinkerException(errorInfo);
// TODO add file path in exception message in util manager.
}
}
}
......@@ -130,20 +127,20 @@ public class YangLinkerManager
/**
* Adds included node information to the include list.
*
* @param yangFileInfoSet set of YANG files info
* @param yangNodeSet set of YANG files info
* @throws LinkerException fails to find included sub-module
*/
public void addRefToYangFilesIncludeList(Set<YangFileInfo> yangFileInfoSet) throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
YangNode yangNode = yangFileInfo.getRootNode();
public void addRefToYangFilesIncludeList(Set<YangNode> yangNodeSet) throws LinkerException {
for (YangNode yangNode : yangNodeSet) {
if (yangNode instanceof YangReferenceResolver) {
try {
((YangReferenceResolver) yangNode).addReferencesToIncludeList(getYangNodeSet());
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangFileInfo.getYangFileName() + " at line: "
String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
+ e.getMessage();
throw new LinkerException(errorInfo);
// TODO add file path in exception message in util manager.
}
}
}
......@@ -152,20 +149,21 @@ public class YangLinkerManager
/**
* Processes inter file linking for type and uses.
*
* @param yangFileInfoSet set of YANG files info
* @param yangNodeSet set of YANG files info
* @throws LinkerException a violation in linker execution
*/
public void processInterFileLinking(Set<YangFileInfo> yangFileInfoSet)
public void processInterFileLinking(Set<YangNode> yangNodeSet)
throws LinkerException {
for (YangFileInfo yangFileInfo : yangFileInfoSet) {
for (YangNode yangNode : yangNodeSet) {
try {
((YangReferenceResolver) yangFileInfo.getRootNode()).resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangFileInfo.getRootNode())
((YangReferenceResolver) yangNode).resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangFileInfo.getYangFileName() + " at line: "
String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
throw new LinkerException(errorInfo);
// TODO add file path in exception message in util manager.
}
}
}
......
......@@ -17,7 +17,6 @@
package org.onosproject.yangutils.parser.impl;
import java.io.IOException;
import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
......
......@@ -31,7 +31,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.AUGMENT_DATA;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represents a utility which provides listener utilities augment node.
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.plugin.manager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAR;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Represents YANG plugin utilities.
*/
public final class YangPluginUtils {
private static final Logger log = getLogger(YangPluginUtils.class);
private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
private static final String SERIALIZED_FILE_EXTENSION = ".ser";
private YangPluginUtils() {
}
/**
* Adds generated source directory to the compilation root.
*
* @param source directory
* @param project current maven project
* @param context current build context
*/
public static void addToCompilationRoot(String source, MavenProject project, BuildContext context) {
project.addCompileSourceRoot(source);
context.refresh(project.getBasedir());
log.info("Source directory added to compilation root: " + source);
}
/**
* Copies YANG files to the current project's output directory.
*
* @param yangFileInfo list of YANG files
* @param outputDir project's output directory
* @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
throws IOException {
List<File> files = getListOfFile(yangFileInfo);
String path = outputDir + TARGET_RESOURCE_PATH;
File targetDir = new File(path);
targetDir.mkdirs();
for (File file : files) {
Files.copy(file.toPath(),
new File(path + file.getName()).toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
}
/**
* Provides a list of files from list of strings.
*
* @param yangFileInfo set of yang file information
* @return list of files
*/
private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
List<File> files = new ArrayList<>();
Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
while (yangFileIterator.hasNext()) {
YangFileInfo yangFile = yangFileIterator.next();
if (yangFile.isForTranslator()) {
files.add(new File(yangFile.getYangFileName()));
}
}
return files;
}
/**
* Serializes data-model.
*
* @param directory base directory for serialized files
* @param fileInfoSet YANG file info set
* @param project maven project
* @param operation true if need to add to resource
* @throws IOException when fails to do IO operations
*/
public static void serializeDataModel(String directory, Set<YangFileInfo> fileInfoSet,
MavenProject project, boolean operation) throws IOException {
String serFileDirPath = directory + TARGET_RESOURCE_PATH;
File dir = new File(serFileDirPath);
dir.mkdirs();
if (operation) {
addToProjectResource(directory + SLASH + TEMP + SLASH, project);
}
for (YangFileInfo fileInfo : fileInfoSet) {
String serFileName = serFileDirPath + getCamelCase(fileInfo.getRootNode().getName(), null)
+ SERIALIZED_FILE_EXTENSION;
fileInfo.setSerializedFile(serFileName);
FileOutputStream fileOutputStream = new FileOutputStream(serFileName);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(fileInfo.getRootNode());
objectOutputStream.close();
fileOutputStream.close();
}
}
/**
* Returns de-serializes YANG data-model nodes.
*
* @param serailizedfileInfoSet YANG file info set
* @return de-serializes YANG data-model nodes
* @throws IOException when fails do IO operations
*/
public static List<YangNode> deSerializeDataModel(List<String> serailizedfileInfoSet) throws IOException {
List<YangNode> nodes = new ArrayList<>();
for (String fileInfo : serailizedfileInfoSet) {
YangNode node = null;
try {
FileInputStream fileInputStream = new FileInputStream(fileInfo);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
node = (YangNode) objectInputStream.readObject();
nodes.add(node);
objectInputStream.close();
fileInputStream.close();
} catch (IOException | ClassNotFoundException e) {
throw new IOException(fileInfo + " not found.");
}
}
return nodes;
}
/**
* Returns list of jar path.
*
* @param project maven project
* @param localRepository local repository
* @param remoteRepos remote repository
* @return list of jar paths
*/
private static List<String> resolveDependecyJarPath(MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepos) {
StringBuilder path = new StringBuilder();
List<String> jarPaths = new ArrayList<>();
for (Dependency dependency : project.getDependencies()) {
path.append(localRepository.getBasedir());
path.append(SLASH);
path.append(getPackageDirPathFromJavaJPackage(dependency.getGroupId()));
path.append(SLASH);
path.append(dependency.getArtifactId());
path.append(SLASH);
path.append(dependency.getVersion());
path.append(SLASH);
path.append(dependency.getArtifactId() + HYPHEN + dependency.getVersion() + PERIOD + JAR);
File jarFile = new File(path.toString());
if (jarFile.exists()) {
jarPaths.add(path.toString());
}
path.delete(0, path.length());
}
for (ArtifactRepository repo : remoteRepos) {
// TODO: add resolver for remote repo.
}
return jarPaths;
}
/**
* Resolves inter jar dependencies.
*
* @param project current maven project
* @param localRepository local maven repository
* @param remoteRepos list of remote repository
* @param directory directory for serialized files
* @return list of resolved datamodel nodes
* @throws IOException when fails to do IO operations
*/
public static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepos, String directory)
throws IOException {
List<String> dependeciesJarPaths = resolveDependecyJarPath(project, localRepository, remoteRepos);
List<YangNode> resolvedDataModelNodes = new ArrayList<>();
for (String dependecy : dependeciesJarPaths) {
resolvedDataModelNodes.addAll(deSerializeDataModel(parseJarFile(dependecy, directory)));
}
return resolvedDataModelNodes;
}
/**
* Parses jar file and returns list of serialized file names.
*
* @param jarFile jar file to be parsed
* @param directory directory for keeping the searized files
* @return list of serialized files
* @throws IOException when fails to do IO operations
*/
public static List<String> parseJarFile(String jarFile, String directory)
throws IOException {
List<String> serailizedFiles = new ArrayList<>();
JarFile jar = new JarFile(jarFile);
Enumeration<?> enumEntries = jar.entries();
File serializedFileDir = new File(directory);
serializedFileDir.mkdirs();
while (enumEntries.hasMoreElements()) {
JarEntry file = (JarEntry) enumEntries.nextElement();
if (file.getName().endsWith(SERIALIZED_FILE_EXTENSION)) {
if (file.getName().contains(SLASH)) {
String[] strArray = file.getName().split(SLASH);
String tempPath = "";
for (int i = 0; i < strArray.length - 1; i++) {
tempPath = SLASH + tempPath + SLASH + strArray[i];
}
File dir = new File(directory + tempPath);
dir.mkdirs();
}
File serailizedFile = new File(directory + SLASH + file.getName());
if (file.isDirectory()) {
serailizedFile.mkdirs();
continue;
}
InputStream inputStream = jar.getInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(serailizedFile);
while (inputStream.available() > 0) {
fileOutputStream.write(inputStream.read());
}
fileOutputStream.close();
inputStream.close();
serailizedFiles.add(serailizedFile.toString());
}
}
jar.close();
return serailizedFiles;
}
/* Adds directory to resources of project */
private static void addToProjectResource(String dir, MavenProject project) {
Resource rsc = new Resource();
rsc.setDirectory(dir);
project.addResource(rsc);
}
}
......@@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
......@@ -37,25 +36,25 @@ 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.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.serializeDataModel;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToCompilationRoot;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.resolveInterJarDependencies;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.serializeDataModel;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
/**
* Represents ONOS YANG utility maven plugin.
......@@ -75,6 +74,8 @@ public class YangUtilManager
private YangLinker yangLinker = new YangLinkerManager();
private YangFileInfo curYangFileInfo = new YangFileInfo();
private Set<YangNode> yangNodeSet = new HashSet<>();
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
/**
......@@ -217,6 +218,15 @@ public class YangUtilManager
}
/**
* Returns the YANG node set.
*
* @return YANG node set
*/
public Set<YangNode> getYangNodeSet() {
return yangNodeSet;
}
/**
* Resolved inter-jar dependencies.
*
* @throws IOException when fails to do IO operations
......@@ -244,10 +254,11 @@ public class YangUtilManager
*/
public void resolveDependenciesUsingLinker()
throws MojoExecutionException {
createYangNodeSet();
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
setCurYangFileInfo(yangFileInfo);
try {
yangLinker.resolveDependencies(getYangFileInfoSet());
yangLinker.resolveDependencies(getYangNodeSet());
} catch (LinkerException e) {
throw new MojoExecutionException(e.getMessage());
}
......@@ -255,6 +266,15 @@ public class YangUtilManager
}
/**
* Creates YANG nodes set.
*/
public void createYangNodeSet() {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
getYangNodeSet().add(yangFileInfo.getRootNode());
}
}
/**
* Parses all the provided YANG files and generates YANG data model tree.
*
* @throws IOException a violation in IO
......
......@@ -17,7 +17,7 @@
package org.onosproject.yangutils.translator.tojava;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
/**
* Abstraction of an entity which provides Code generator functionalities.
......
......@@ -14,10 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
package org.onosproject.yangutils.translator.tojava;
/**
* Represents YANG java info containing interface for java code generator, java
......
......@@ -20,7 +20,7 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.TraversalType.CHILD;
import static org.onosproject.yangutils.translator.tojava.TraversalType.PARENT;
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.Serializable;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
/**
* Represents cached java file handle, which supports the addition of member attributes and
......
......@@ -22,13 +22,13 @@ import java.util.Objects;
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 org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import com.google.common.base.MoreObjects;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportClass;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportPackage;
/**
* Represents the information about individual imports in the generated file.
......
......@@ -19,7 +19,7 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
......
......@@ -21,7 +21,7 @@ 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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
......
......@@ -28,19 +28,19 @@ 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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPrefixForIdentifier;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
/**
* Represents implementation of java code fragments temporary implementations.
......
......@@ -33,7 +33,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
......@@ -55,7 +55,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.updateJavaFileInfo;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
......@@ -63,9 +63,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
......@@ -104,7 +104,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALIT
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
......
......@@ -25,7 +25,7 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
......@@ -46,10 +46,10 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
......@@ -67,7 +67,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
......
......@@ -26,7 +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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
......@@ -36,13 +36,13 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
/**
* Represents implementation of java data type code fragments temporary implementations.
......
......@@ -14,10 +14,9 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEnumeration;
......@@ -26,48 +25,35 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
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 org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
import static org.onosproject.yangutils.utils.UtilConstants.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;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
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;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
/**
* Represents java data types info corresponding to YANG type.
......@@ -121,51 +107,6 @@ public final class AttributesJavaDataType {
}
/**
* Returns from string method parsed string.
*
* @param targetDataType target data type
* @param yangType YANG type
* @return parsed string
*/
public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
YangDataTypes type = yangType.getDataType();
switch (type) {
case INT8:
return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
case INT16:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case INT32:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case INT64:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT8:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case UINT16:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case UINT32:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
case STRING:
return EMPTY_STRING;
case EMPTY:
case BOOLEAN:
return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
case DECIMAL64:
case BITS:
case BINARY:
case UNION:
case ENUMERATION:
case DERIVED:
return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
default:
throw new TranslatorException("given data type is not supported.");
}
}
/**
* Returns java import class.
*
* @param yangType YANG type
......
......@@ -17,7 +17,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
/**
* Represent java based identification of the YANG leaves.
......
......@@ -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;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
/**
* Represent java based identification of the YANG leaves.
......
......@@ -20,12 +20,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents augment information extended to support java code generation.
......
......@@ -20,12 +20,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents case information extended to support java code generation.
......
......@@ -20,12 +20,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents choice information extended to support java code generation.
......
......@@ -20,12 +20,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents container information extended to support java code generation.
......
......@@ -21,12 +21,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents YANG java enumeration information extended to support java code generation.
......
......@@ -20,11 +20,12 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
/**
* Represents grouping information extended to support java code generation.
......
......@@ -21,12 +21,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents input information extended to support java code generation.
......
......@@ -17,10 +17,10 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.updateLeavesJavaQualifiedInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
/**
* Represents java information corresponding to the YANG leaf.
......
......@@ -17,10 +17,10 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.updateLeavesJavaQualifiedInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
/**
* Represents java information corresponding to the YANG leaf-list.
......
......@@ -20,12 +20,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents YANG list information extended to support java code generation.
......
......@@ -14,24 +14,23 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
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 org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
......@@ -39,10 +38,10 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
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;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
/**
* Represents utility class for YANG java model.
......@@ -349,4 +348,26 @@ public final class YangJavaModelUtils {
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE);
}
/**
* Returns the node package string.
*
* @param curNode current java node whose package string needs to be set
* @return returns the root package string
*/
public static String getCurNodePackage(YangNode curNode) {
String pkg;
if (!(curNode instanceof JavaFileInfoContainer)
|| curNode.getParent() == null) {
throw new TranslatorException("missing parent node to get current node's package");
}
YangNode parentNode = DataModelUtils.getParentNodeInGenCode(curNode);
if (!(parentNode instanceof JavaFileInfoContainer)) {
throw new TranslatorException("missing parent java node to get current node's package");
}
JavaFileInfo parentJavaFileHandle = ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
return pkg.toLowerCase();
}
}
......
......@@ -24,16 +24,17 @@ 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.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.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;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......
......@@ -22,17 +22,18 @@ 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.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
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;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
......
......@@ -21,12 +21,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents output information extended to support java code generation.
......
......@@ -26,19 +26,20 @@ import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
......
......@@ -26,16 +26,17 @@ 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;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.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;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......
......@@ -18,8 +18,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
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;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
/**
* Represents java information corresponding to the YANG type.
......
......@@ -20,12 +20,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents type define information extended to support java code generation.
......
......@@ -20,12 +20,13 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents union information extended to support java code generation.
......
......@@ -25,13 +25,14 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeAsAttributeInTargetTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
/**
* Represents uses information extended to support java code generation.
......
......@@ -17,9 +17,9 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
......@@ -236,7 +236,7 @@ public final class ClassDefinitionGenerator {
if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
curNode = curNode.getChild();
while (curNode != null) {
if (curNode instanceof YangJavaNotification) {
if (curNode instanceof YangNotification) {
return getRpcInterfaceDefinitionWhenItExtends(yangName, holder);
}
curNode = curNode.getNextSibling();
......
......@@ -17,9 +17,10 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
......
......@@ -27,7 +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.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
/**
......
......@@ -28,7 +28,8 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
......@@ -65,7 +66,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetG
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
......
......@@ -31,6 +31,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
......@@ -64,8 +65,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
......
......@@ -16,16 +16,18 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.utils.io.impl.YangIoUtils;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
......@@ -33,23 +35,17 @@ import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_DIGITS_WITH_SINGLE_LETTER;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_IDENTIFIER_SPECIAL_CHAR;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_SINGLE_LETTER;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_UNDERSCORE;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_DIGITS;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_UPPERCASE;
import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
/**
* Represents an utility Class for translating the name from YANG to java convention.
......@@ -95,29 +91,6 @@ public final class JavaIdentifierSyntax {
}
/**
* Returns the node package string.
*
* @param curNode current java node whose package string needs to be set
* @return returns the root package string
*/
public static String getCurNodePackage(YangNode curNode) {
String pkg;
if (!(curNode instanceof JavaFileInfoContainer)
|| curNode.getParent() == null) {
throw new TranslatorException("missing parent node to get current node's package");
}
YangNode parentNode = DataModelUtils.getParentNodeInGenCode(curNode);
if (!(parentNode instanceof JavaFileInfoContainer)) {
throw new TranslatorException("missing parent java node to get current node's package");
}
JavaFileInfo parentJavaFileHandle = ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
return pkg.toLowerCase();
}
/**
* Returns version.
*
* @param ver YANG version
......@@ -193,7 +166,7 @@ public final class JavaIdentifierSyntax {
for (String member : pkgArr) {
boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member.toLowerCase());
if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
String prefix = getPrefixForIdentifier(conflictResolver);
String prefix = YangIoUtils.getPrefixForIdentifier(conflictResolver);
member = prefix + member;
}
pkg = pkg + member;
......@@ -206,252 +179,6 @@ public final class JavaIdentifierSyntax {
}
/**
* Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits.
*
* @param conflictResolver object of YANG to java naming conflict util
* @return prefix which needs to be added
*/
public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) {
String prefixForIdentifier = null;
if (conflictResolver != null) {
prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
}
if (prefixForIdentifier != null) {
prefixForIdentifier = prefixForIdentifier.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
String[] strArray = prefixForIdentifier.split(COLAN);
try {
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
prefixForIdentifier = strArray[0];
for (int j = 1; j < strArray.length; j++) {
prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase() +
strArray[j].substring(1);
}
} catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
throw new TranslatorException("The given prefix in pom.xml is invalid.");
}
} else {
prefixForIdentifier = YANG_AUTO_PREFIX;
}
return prefixForIdentifier;
}
/**
* Returns the YANG identifier name as java identifier.
*
* @param yangIdentifier identifier in YANG file
* @param conflictResolver object of YANG to java naming conflict util
* @return corresponding java identifier
*/
public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
if (conflictResolver != null) {
String replacementForHyphen = conflictResolver.getReplacementForHyphen();
String replacementForPeriod = conflictResolver.getReplacementForPeriod();
String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
if (replacementForPeriod != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
}
if (replacementForUnderscore != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
UNDER_SCORE + replacementForUnderscore.toLowerCase() + UNDER_SCORE);
}
if (replacementForHyphen != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
}
}
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
String[] strArray = yangIdentifier.split(COLAN);
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
return upperCaseConflictResolver(strArray, conflictResolver);
}
/**
* Resolves the conflict when input has upper case.
*
* @param stringArray containing strings for upper case conflict resolver
* @param conflictResolver object of YANG to java naming conflict util
* @return camel cased string
*/
private static String upperCaseConflictResolver(String[] stringArray,
YangToJavaNamingConflictUtil conflictResolver) {
for (int l = 0; l < stringArray.length; l++) {
String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
for (int m = 0; m < upperCaseSplitArray.length; m++) {
if (upperCaseSplitArray[m].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
int check = m;
while (check + 1 < upperCaseSplitArray.length) {
if (upperCaseSplitArray[check + 1].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
check = check + 1;
} else if (upperCaseSplitArray[check + 1]
.matches(REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES)) {
upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
break;
} else {
break;
}
}
}
}
StringBuilder strBuilder = new StringBuilder();
for (String element : upperCaseSplitArray) {
strBuilder.append(element);
}
stringArray[l] = strBuilder.toString();
}
List<String> result = new ArrayList<String>();
for (String element : stringArray) {
String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
for (String letter : capitalCaseSplitArray) {
String[] arrayForAddition = letter.split(REGEX_WITH_DIGITS);
List<String> list = Arrays.asList(arrayForAddition);
for (String str : list) {
if (str != null && !str.isEmpty()) {
result.add(str);
}
}
}
}
stringArray = result.toArray(new String[result.size()]);
return applyCamelCaseRule(stringArray, conflictResolver);
}
/**
* Applies the rule that a string does not end with a capitalized letter and capitalizes
* the letter next to a number in an array.
*
* @param stringArray containing strings for camel case separation
* @param conflictResolver object of YANG to java naming conflict util
* @return camel case rule checked string
*/
private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
String ruleChecker = stringArray[0].toLowerCase();
int i;
if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
i = 0;
ruleChecker = EMPTY_STRING;
} else {
i = 1;
}
for (; i < stringArray.length; i++) {
if (i + 1 == stringArray.length) {
if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
|| stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
ruleChecker = ruleChecker + stringArray[i].toLowerCase();
break;
}
}
if (stringArray[i].matches(REGEX_FOR_FIRST_DIGIT)) {
for (int j = 0; j < stringArray[i].length(); j++) {
char letterCheck = stringArray[i].charAt(j);
if (Character.isLetter(letterCheck)) {
stringArray[i] = stringArray[i].substring(0, j)
+ stringArray[i].substring(j, j + 1).toUpperCase() + stringArray[i].substring(j + 1);
break;
}
}
ruleChecker = ruleChecker + stringArray[i];
} else {
ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
}
}
String ruleCheckerWithPrefix = addPrefix(ruleChecker, conflictResolver);
return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
}
/**
* Adds prefix, if the string begins with digit or is a java key word.
*
* @param camelCasePrefix string for adding prefix
* @param conflictResolver object of YANG to java naming conflict util
* @return prefixed camel case string
*/
private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
String prefix = getPrefixForIdentifier(conflictResolver);
if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
camelCasePrefix = prefix + camelCasePrefix;
}
if (JAVA_KEY_WORDS.contains(camelCasePrefix)) {
camelCasePrefix = prefix + camelCasePrefix.substring(0, 1).toUpperCase()
+ camelCasePrefix.substring(1);
}
return camelCasePrefix;
}
/**
* Restricts consecutive capital cased string as a rule in camel case.
*
* @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
* @return string without consecutive capital case
*/
private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
if (k + 1 < consecCapitalCaseRemover.length()) {
if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) {
if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) {
consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1)
+ consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase()
+ consecCapitalCaseRemover.substring(k + 2);
}
}
}
}
return consecCapitalCaseRemover;
}
/**
* Returns the YANG identifier name as java identifier with first letter
* in capital.
*
* @param yangIdentifier identifier in YANG file
* @return corresponding java identifier
*/
public static String getCapitalCase(String yangIdentifier) {
yangIdentifier = yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
return restrictConsecutiveCapitalCase(yangIdentifier);
}
/**
* Returns the YANG identifier name as java identifier with first letter
* in small.
*
* @param yangIdentifier identifier in YANG file.
* @return corresponding java identifier
*/
public static String getSmallCase(String yangIdentifier) {
return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
}
/**
* Returns the java Package from package path.
*
* @param packagePath package path
* @return java package
*/
public static String getJavaPackageFromPackagePath(String packagePath) {
return packagePath.replace(SLASH, PERIOD);
}
/**
* Returns enum's java name.
*
* @param name enum's name
......@@ -479,12 +206,46 @@ public final class JavaIdentifierSyntax {
}
/**
* Returns the directory path corresponding to java package.
* Creates a package structure with package info java file if not present.
*
* @param yangNode YANG node for which code is being generated
* @throws IOException any IO exception
*/
public static void createPackage(YangNode yangNode) throws IOException {
if (!(yangNode instanceof JavaFileInfoContainer)) {
throw new TranslatorException("current node must have java file info");
}
String pkgInfo;
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
String pkg = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(), javaFileInfo.getPackageFilePath());
if (!doesPackageExist(pkg)) {
try {
File pack = createDirectories(pkg);
YangNode parent = getParentNodeInGenCode(yangNode);
if (parent != null) {
pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
} else {
pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
}
} catch (IOException e) {
throw new IOException("failed to create package-info file");
}
}
}
/**
* Checks if the package directory structure created.
*
* @param packagePath package path
* @return java package
* @param pkg Package to check if it is created
* @return existence status of package
*/
public static String getPackageDirPathFromJavaJPackage(String packagePath) {
return packagePath.replace(PERIOD, SLASH);
public static boolean doesPackageExist(String pkg) {
File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
return pkgDir.exists() && pkgWithFile.isFile();
}
}
......
......@@ -18,31 +18,28 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
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.AttributesJavaDataType.getParseFromStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
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;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.CASE;
import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
......@@ -74,8 +71,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.IF;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
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.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
......@@ -88,6 +87,11 @@ 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.OTHER;
import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
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;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
......@@ -96,6 +100,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STARTED_LOG_INFO;
......@@ -113,7 +118,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTA
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
......@@ -123,6 +127,10 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MAN
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
......@@ -904,7 +912,8 @@ public final class MethodsGenerator {
* @return string and java doc for constructor of type class
*/
public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
String generatedJavaClassName, YangPluginConfig pluginConfig) {
String generatedJavaClassName,
YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
......@@ -989,36 +998,6 @@ public final class MethodsGenerator {
}
/**
* Provides string to be added in augment node's constructor.
*
* @param curNode current YANG node
* @return constructors string
*/
public static String getAugmentsAddToAugmentedMethod(YangNode curNode) {
if (!(curNode instanceof YangJavaAugment)) {
throw new TranslatorException("current node should be of type augment node.");
}
YangJavaAugment augment = (YangJavaAugment) curNode;
List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
String name = targetNodes.get(targetNodes.size() - 1).getName();
String captialCase = getCapitalCase(name);
String smallCase = getSmallCase(captialCase);
return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE
+ NEW + SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE
+ captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION
+ OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
private static String getAugmentsAddToAugmentedMethodStart() {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING + AUGMENTABLE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
}
/**
* Returns of method for enum class.
*
* @param className class name
......@@ -1029,7 +1008,8 @@ public final class MethodsGenerator {
* @return of method
*/
public static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
Map<String, Integer> enumMap, List<String> enumList, YangPluginConfig pluginConfig) {
Map<String, Integer> enumMap, List<String> enumList,
YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
......@@ -1083,4 +1063,48 @@ public final class MethodsGenerator {
+ STOPPED_LOG_INFO + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns from string method parsed string.
*
* @param targetDataType target data type
* @param yangType YANG type
* @return parsed string
*/
public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
YangDataTypes type = yangType.getDataType();
switch (type) {
case INT8:
return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
case INT16:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case INT32:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case INT64:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT8:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case UINT16:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case UINT32:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
case STRING:
return EMPTY_STRING;
case EMPTY:
case BOOLEAN:
return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
case DECIMAL64:
case BITS:
case BINARY:
case UNION:
case ENUMERATION:
case DERIVED:
return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
default:
throw new TranslatorException("given data type is not supported.");
}
}
}
......
......@@ -19,51 +19,29 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
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;
import static java.util.Collections.sort;
/**
......@@ -121,84 +99,6 @@ public final class TempJavaCodeFragmentFilesUtils {
}
/**
* Updated imports with augmented nodes import.
*
* @param curNode current YANG node
* @param imports list of imports
* @param operation to add or to delete
*/
public static void addAugmentedNodesImport(YangNode curNode, List<String> imports, boolean operation) {
String nodesImport = "";
if (!(curNode instanceof YangJavaAugment)) {
throw new TranslatorException("current node should be of type augment node.");
}
YangJavaAugment augment = (YangJavaAugment) curNode;
List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
YangNode parent = curNode.getParent();
if (parent instanceof YangJavaModule) {
// Add impl class import.
nodesImport = getAugmendtedNodesImports(parent, targetNodes, true) + SEMI_COLAN + NEW_LINE;
performOperationOnImports(imports, nodesImport, operation);
// Add builder class import.
if (targetNodes.size() > 2) {
nodesImport = getAugmendtedNodesImports(parent, targetNodes, false) + SEMI_COLAN + NEW_LINE;
performOperationOnImports(imports, nodesImport, operation);
}
}
// TODO: add functionality for submodule and uses.
}
/**
* Returns imports for augmented node.
*
* @param parent parent YANG node
* @param targetNodes list of target nodes
* @param isImplClass if impl class's import required
* @return imports for augmented node
*/
private static String getAugmendtedNodesImports(YangNode parent, List<YangNodeIdentifier> targetNodes,
boolean isImplClass) {
String pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
for (int i = 0; i < targetNodes.size() - 1; i++) {
pkgInfo = pkgInfo + PERIOD + targetNodes.get(i).getName();
}
String classInfo = targetNodes.get(targetNodes.size() - 1).getName();
if (!isImplClass) {
return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER;
}
return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER + PERIOD
+ getCapitalCase(classInfo) + IMPL;
}
/**
* Provides string to be added in augment node's constructor.
*
* @param curNode current YANG node
* @return constructors string
*/
public static String getAugmentsAddToAugmentedClassString(YangNode curNode) {
if (!(curNode instanceof YangJavaAugment)) {
throw new TranslatorException("current node should be of type augment node.");
}
YangJavaAugment augment = (YangJavaAugment) curNode;
List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
String name = targetNodes.get(targetNodes.size() - 1).getName();
String captialCase = getCapitalCase(name);
String smallCase = getSmallCase(captialCase);
return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE + NEW
+ SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE
+ captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION + OPEN_PARENTHESIS
+ THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
* Adds import for array list.
*
* @param curNode current YANG node
......
......@@ -25,24 +25,12 @@ 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;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents utility to handle file system operations.
......@@ -56,50 +44,6 @@ public final class FileSystemUtil {
}
/**
* Checks if the package directory structure created.
*
* @param pkg Package to check if it is created
* @return existence status of package
*/
public static boolean doesPackageExist(String pkg) {
File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
return pkgDir.exists() && pkgWithFile.isFile();
}
/**
* Creates a package structure with package info java file if not present.
*
* @param yangNode YANG node for which code is being generated
* @throws IOException any IO exception
*/
public static void createPackage(YangNode yangNode) throws IOException {
if (!(yangNode instanceof JavaFileInfoContainer)) {
throw new TranslatorException("current node must have java file info");
}
String pkgInfo;
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
String pkg = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(), javaFileInfo.getPackageFilePath());
if (!doesPackageExist(pkg)) {
try {
File pack = createDirectories(pkg);
YangNode parent = getParentNodeInGenCode(yangNode);
if (parent != null) {
pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
} else {
pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
}
} catch (IOException e) {
throw new IOException("failed to create package-info file");
}
}
}
/**
* Reads the contents from source file and append its contents to append
* file.
*
......
......@@ -16,10 +16,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.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
......@@ -202,7 +199,7 @@ public final class JavaDocGen {
*/
public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) {
name = JavaIdentifierSyntax.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver()));
name = YangIoUtils.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver()));
switch (type) {
case IMPL_CLASS: {
return generateForClass(name);
......
......@@ -19,73 +19,60 @@ package org.onosproject.yangutils.utils.io.impl;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.ORG;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_DIGITS_WITH_SINGLE_LETTER;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_IDENTIFIER_SPECIAL_CHAR;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_SINGLE_LETTER;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_UNDERSCORE;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_DIGITS;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_UPPERCASE;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
/**
* Represents common utility functionalities for code generation.
*/
public final class YangIoUtils {
private static final Logger log = getLogger(YangIoUtils.class);
private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
private static final int LINE_SIZE = 118;
private static final int SUB_LINE_SIZE = 112;
private static final int ZERO = 0;
private static final String SERIALIZED_FILE_EXTENSION = ".ser";
/**
* Creates an instance of YANG io utils.
......@@ -223,19 +210,6 @@ public final class YangIoUtils {
}
/**
* Adds generated source directory to the compilation root.
*
* @param source directory
* @param project current maven project
* @param context current build context
*/
public static void addToCompilationRoot(String source, MavenProject project, BuildContext context) {
project.addCompileSourceRoot(source);
context.refresh(project.getBasedir());
log.info("Source directory added to compilation root: " + source);
}
/**
* Removes extra char from the string.
*
* @param valueString string to be trimmed
......@@ -303,49 +277,6 @@ public final class YangIoUtils {
}
/**
* Copies YANG files to the current project's output directory.
*
* @param yangFileInfo list of YANG files
* @param outputDir project's output directory
* @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
throws IOException {
List<File> files = getListOfFile(yangFileInfo);
String path = outputDir + TARGET_RESOURCE_PATH;
File targetDir = new File(path);
targetDir.mkdirs();
for (File file : files) {
Files.copy(file.toPath(),
new File(path + file.getName()).toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
}
/**
* Provides a list of files from list of strings.
*
* @param yangFileInfo set of yang file information
* @return list of files
*/
private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
List<File> files = new ArrayList<>();
Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
while (yangFileIterator.hasNext()) {
YangFileInfo yangFile = yangFileIterator.next();
if (yangFile.isForTranslator()) {
files.add(new File(yangFile.getYangFileName()));
}
}
return files;
}
/**
* Merges the temp java files to main java files.
*
* @param appendFile temp file
......@@ -501,173 +432,258 @@ public final class YangIoUtils {
}
/**
* Serializes data-model.
* Returns the java Package from package path.
*
* @param directory base directory for serialized files
* @param fileInfoSet YANG file info set
* @param project maven project
* @param operation true if need to add to resource
* @throws IOException when fails to do IO operations
* @param packagePath package path
* @return java package
*/
public static void serializeDataModel(String directory, Set<YangFileInfo> fileInfoSet,
MavenProject project, boolean operation) throws IOException {
public static String getJavaPackageFromPackagePath(String packagePath) {
return packagePath.replace(SLASH, PERIOD);
}
String serFileDirPath = directory + TARGET_RESOURCE_PATH;
File dir = new File(serFileDirPath);
dir.mkdirs();
/**
* Returns the directory path corresponding to java package.
*
* @param packagePath package path
* @return java package
*/
public static String getPackageDirPathFromJavaJPackage(String packagePath) {
return packagePath.replace(PERIOD, SLASH);
}
if (operation) {
addToProjectResource(directory + SLASH + TEMP + SLASH, project);
/**
* Returns the YANG identifier name as java identifier with first letter
* in small.
*
* @param yangIdentifier identifier in YANG file.
* @return corresponding java identifier
*/
public static String getSmallCase(String yangIdentifier) {
return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
}
/**
* Returns the YANG identifier name as java identifier with first letter
* in capital.
*
* @param yangIdentifier identifier in YANG file
* @return corresponding java identifier
*/
public static String getCapitalCase(String yangIdentifier) {
yangIdentifier = yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
return restrictConsecutiveCapitalCase(yangIdentifier);
}
for (YangFileInfo fileInfo : fileInfoSet) {
/**
* Restricts consecutive capital cased string as a rule in camel case.
*
* @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
* @return string without consecutive capital case
*/
public static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
String serFileName = serFileDirPath + getCamelCase(fileInfo.getRootNode().getName(), null)
+ SERIALIZED_FILE_EXTENSION;
fileInfo.setSerializedFile(serFileName);
FileOutputStream fileOutputStream = new FileOutputStream(serFileName);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(fileInfo.getRootNode());
objectOutputStream.close();
fileOutputStream.close();
for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
if (k + 1 < consecCapitalCaseRemover.length()) {
if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) {
if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) {
consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1)
+ consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase()
+ consecCapitalCaseRemover.substring(k + 2);
}
}
/* Adds directory to resources of project */
private static void addToProjectResource(String dir, MavenProject project) {
Resource rsc = new Resource();
rsc.setDirectory(dir);
project.addResource(rsc);
}
}
return consecCapitalCaseRemover;
}
/**
* Returns de-serializes YANG data-model nodes.
* Adds prefix, if the string begins with digit or is a java key word.
*
* @param serailizedfileInfoSet YANG file info set
* @return de-serializes YANG data-model nodes
* @throws IOException when fails do IO operations
* @param camelCasePrefix string for adding prefix
* @param conflictResolver object of YANG to java naming conflict util
* @return prefixed camel case string
*/
public static List<YangNode> deSerializeDataModel(List<String> serailizedfileInfoSet) throws IOException {
public static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
List<YangNode> nodes = new ArrayList<>();
for (String fileInfo : serailizedfileInfoSet) {
YangNode node = null;
try {
FileInputStream fileInputStream = new FileInputStream(fileInfo);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
node = (YangNode) objectInputStream.readObject();
nodes.add(node);
objectInputStream.close();
fileInputStream.close();
} catch (IOException | ClassNotFoundException e) {
throw new IOException(fileInfo + " not found.");
String prefix = getPrefixForIdentifier(conflictResolver);
if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
camelCasePrefix = prefix + camelCasePrefix;
}
if (JAVA_KEY_WORDS.contains(camelCasePrefix)) {
camelCasePrefix = prefix + camelCasePrefix.substring(0, 1).toUpperCase()
+ camelCasePrefix.substring(1);
}
return nodes;
return camelCasePrefix;
}
/**
* Resolves inter jar dependencies.
* Applies the rule that a string does not end with a capitalized letter and capitalizes
* the letter next to a number in an array.
*
* @param project current maven project
* @param localRepository local maven repository
* @param remoteRepos list of remote repository
* @param directory directory for serialized files
* @return list of resolved datamodel nodes
* @throws IOException when fails to do IO operations
* @param stringArray containing strings for camel case separation
* @param conflictResolver object of YANG to java naming conflict util
* @return camel case rule checked string
*/
public static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepos, String directory) throws IOException {
public static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
List<String> dependeciesJarPaths = resolveDependecyJarPath(project, localRepository, remoteRepos);
List<YangNode> resolvedDataModelNodes = new ArrayList<>();
for (String dependecy : dependeciesJarPaths) {
resolvedDataModelNodes.addAll(deSerializeDataModel(parseJarFile(dependecy, directory)));
String ruleChecker = stringArray[0].toLowerCase();
int i;
if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
i = 0;
ruleChecker = EMPTY_STRING;
} else {
i = 1;
}
for (; i < stringArray.length; i++) {
if (i + 1 == stringArray.length) {
if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
|| stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
ruleChecker = ruleChecker + stringArray[i].toLowerCase();
break;
}
}
if (stringArray[i].matches(REGEX_FOR_FIRST_DIGIT)) {
for (int j = 0; j < stringArray[i].length(); j++) {
char letterCheck = stringArray[i].charAt(j);
if (Character.isLetter(letterCheck)) {
stringArray[i] = stringArray[i].substring(0, j)
+ stringArray[i].substring(j, j + 1).toUpperCase() + stringArray[i].substring(j + 1);
break;
}
}
ruleChecker = ruleChecker + stringArray[i];
} else {
ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
}
return resolvedDataModelNodes;
}
String ruleCheckerWithPrefix = addPrefix(ruleChecker, conflictResolver);
return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
}
/**
* Returns list of jar path.
* Resolves the conflict when input has upper case.
*
* @return list of jar paths
* @param stringArray containing strings for upper case conflict resolver
* @param conflictResolver object of YANG to java naming conflict util
* @return camel cased string
*/
private static List<String> resolveDependecyJarPath(MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepos) {
public static String upperCaseConflictResolver(String[] stringArray,
YangToJavaNamingConflictUtil conflictResolver) {
for (int l = 0; l < stringArray.length; l++) {
String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
for (int m = 0; m < upperCaseSplitArray.length; m++) {
if (upperCaseSplitArray[m].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
int check = m;
while (check + 1 < upperCaseSplitArray.length) {
if (upperCaseSplitArray[check + 1].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
check = check + 1;
} else if (upperCaseSplitArray[check + 1]
.matches(REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES)) {
upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
break;
} else {
break;
}
}
}
}
StringBuilder strBuilder = new StringBuilder();
for (String element : upperCaseSplitArray) {
strBuilder.append(element);
}
stringArray[l] = strBuilder.toString();
}
List<String> result = new ArrayList<String>();
for (String element : stringArray) {
String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
for (String letter : capitalCaseSplitArray) {
String[] arrayForAddition = letter.split(REGEX_WITH_DIGITS);
List<String> list = Arrays.asList(arrayForAddition);
for (String str : list) {
if (str != null && !str.isEmpty()) {
result.add(str);
}
}
}
}
stringArray = result.toArray(new String[result.size()]);
return applyCamelCaseRule(stringArray, conflictResolver);
}
StringBuilder path = new StringBuilder();
List<String> jarPaths = new ArrayList<>();
for (Dependency dependency : project.getDependencies()) {
/**
* Returns the YANG identifier name as java identifier.
*
* @param yangIdentifier identifier in YANG file
* @param conflictResolver object of YANG to java naming conflict util
* @return corresponding java identifier
*/
public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
path.append(localRepository.getBasedir());
path.append(SLASH);
path.append(getPackageDirPathFromJavaJPackage(dependency.getGroupId()));
path.append(SLASH);
path.append(dependency.getArtifactId());
path.append(SLASH);
path.append(dependency.getVersion());
path.append(SLASH);
path.append(dependency.getArtifactId() + HYPHEN + dependency.getVersion() + PERIOD + JAR);
File jarFile = new File(path.toString());
if (jarFile.exists()) {
jarPaths.add(path.toString());
if (conflictResolver != null) {
String replacementForHyphen = conflictResolver.getReplacementForHyphen();
String replacementForPeriod = conflictResolver.getReplacementForPeriod();
String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
if (replacementForPeriod != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
}
path.delete(0, path.length());
if (replacementForUnderscore != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
UNDER_SCORE + replacementForUnderscore.toLowerCase() + UNDER_SCORE);
}
for (ArtifactRepository repo : remoteRepos) {
// TODO: add resolver for remote repo.
if (replacementForHyphen != null) {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
}
}
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
String[] strArray = yangIdentifier.split(COLAN);
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
return jarPaths;
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
return upperCaseConflictResolver(strArray, conflictResolver);
}
/**
* Parses jar file and returns list of serialized file names.
* Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits.
*
* @param jarFile jar file to be parsed
* @param directory directory for keeping the searized files
* @return list of serialized files
* @throws IOException when fails to do IO operations
* @param conflictResolver object of YANG to java naming conflict util
* @return prefix which needs to be added
*/
public static List<String> parseJarFile(String jarFile, String directory)
throws IOException {
public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) {
List<String> serailizedFiles = new ArrayList<>();
JarFile jar = new JarFile(jarFile);
Enumeration<?> enumEntries = jar.entries();
File serializedFileDir = new File(directory);
serializedFileDir.mkdirs();
while (enumEntries.hasMoreElements()) {
JarEntry file = (JarEntry) enumEntries.nextElement();
if (file.getName().endsWith(SERIALIZED_FILE_EXTENSION)) {
if (file.getName().contains(SLASH)) {
String[] strArray = file.getName().split(SLASH);
String tempPath = "";
for (int i = 0; i < strArray.length - 1; i++) {
tempPath = SLASH + tempPath + SLASH + strArray[i];
}
File dir = new File(directory + tempPath);
dir.mkdirs();
}
File serailizedFile = new File(directory + SLASH + file.getName());
if (file.isDirectory()) {
serailizedFile.mkdirs();
continue;
String prefixForIdentifier = null;
if (conflictResolver != null) {
prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
}
InputStream inputStream = jar.getInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(serailizedFile);
while (inputStream.available() > 0) {
fileOutputStream.write(inputStream.read());
if (prefixForIdentifier != null) {
prefixForIdentifier = prefixForIdentifier.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
String[] strArray = prefixForIdentifier.split(COLAN);
try {
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
fileOutputStream.close();
inputStream.close();
serailizedFiles.add(serailizedFile.toString());
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
prefixForIdentifier = strArray[0];
for (int j = 1; j < strArray.length; j++) {
prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase() +
strArray[j].substring(1);
}
jar.close();
return serailizedFiles;
} catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
throw new TranslatorException("The given prefix in pom.xml is invalid.");
}
} else {
prefixForIdentifier = YANG_AUTO_PREFIX;
}
return prefixForIdentifier;
}
}
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.utils.io.impl;
/**
* Representation of plugin configurations required for YANG utils.
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
package org.onosproject.yangutils.utils.io.impl;
/**
* Representation of YANG to java naming conflict resolver util.
......
......@@ -22,7 +22,7 @@ import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.plugin.manager.YangUtilManager;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import java.io.IOException;
......
......@@ -34,10 +34,9 @@ import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.plugin.manager.YangUtilManager;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
......@@ -67,29 +66,30 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/interfiletype";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
YangNode rootNode = yangNodeIterator.next();
if (yangFileInfo.getRootNode().getName().equals("module1")) {
selfNode = yangFileInfo.getRootNode();
refNode = yangFileInfoIterator.next().getRootNode();
if (rootNode.getName().equals("module1")) {
selfNode = rootNode;
refNode = yangNodeIterator.next();
} else {
refNode = yangFileInfo.getRootNode();
selfNode = yangFileInfoIterator.next().getRootNode();
refNode = rootNode;
selfNode = yangNodeIterator.next();
}
// Check whether the data model tree returned is of type module.
......@@ -136,29 +136,30 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/interfileuses";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
YangNode rootNode = yangNodeIterator.next();
if (yangFileInfo.getRootNode().getName().equals("module1")) {
selfNode = yangFileInfo.getRootNode();
refNode = yangFileInfoIterator.next().getRootNode();
if (rootNode.getName().equals("module1")) {
selfNode = rootNode;
refNode = yangNodeIterator.next();
} else {
refNode = yangFileInfo.getRootNode();
selfNode = yangFileInfoIterator.next().getRootNode();
refNode = rootNode;
selfNode = yangNodeIterator.next();
}
// Check whether the data model tree returned is of type module.
......@@ -193,14 +194,6 @@ public class InterFileLinkingTest {
// Check whether uses get resolved.
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
// leafIterator = yangNode.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under module.
// assertThat(leafInfo.getName(), is("hello"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
}
/**
......@@ -213,32 +206,33 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/interfiletypewithinclude";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Carry out linking of sub module with module.
yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangFileInfoSet());
yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
// Add reference to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
YangNode rootNode = yangNodeIterator.next();
if (yangFileInfo.getRootNode().getName().equals("module1")) {
selfNode = yangFileInfo.getRootNode();
refNode = yangFileInfoIterator.next().getRootNode();
if (rootNode.getName().equals("module1")) {
selfNode = rootNode;
refNode = yangNodeIterator.next();
} else {
refNode = yangFileInfo.getRootNode();
selfNode = yangFileInfoIterator.next().getRootNode();
refNode = rootNode;
selfNode = yangNodeIterator.next();
}
// Check whether the data model tree returned is of type module.
......@@ -285,32 +279,33 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/interfileuseswithinclude";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Carry out linking of sub module with module.
yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangFileInfoSet());
yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
// Add reference to include list.
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
YangNode rootNode = yangNodeIterator.next();
if (yangFileInfo.getRootNode().getName().equals("module1")) {
selfNode = yangFileInfo.getRootNode();
refNode = yangFileInfoIterator.next().getRootNode();
if (rootNode.getName().equals("module1")) {
selfNode = rootNode;
refNode = yangNodeIterator.next();
} else {
refNode = yangFileInfo.getRootNode();
selfNode = yangFileInfoIterator.next().getRootNode();
refNode = rootNode;
selfNode = yangNodeIterator.next();
}
// Check whether the data model tree returned is of type module.
......@@ -345,14 +340,6 @@ public class InterFileLinkingTest {
// Check whether uses get resolved.
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
// leafIterator = yangNode.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under module.
// assertThat(leafInfo.getName(), is("hello"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
}
/**
......@@ -365,29 +352,30 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/interfiletypewithrevision";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
YangNode rootNode = yangNodeIterator.next();
if (yangFileInfo.getRootNode().getName().equals("module1")) {
selfNode = yangFileInfo.getRootNode();
refNode = yangFileInfoIterator.next().getRootNode();
if (rootNode.getName().equals("module1")) {
selfNode = rootNode;
refNode = yangNodeIterator.next();
} else {
refNode = yangFileInfo.getRootNode();
selfNode = yangFileInfoIterator.next().getRootNode();
refNode = rootNode;
selfNode = yangNodeIterator.next();
}
// Check whether the data model tree returned is of type module.
......@@ -434,29 +422,30 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/interfiletypewithrevisioninname";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
YangNode rootNode = yangNodeIterator.next();
if (yangFileInfo.getRootNode().getName().equals("module1")) {
selfNode = yangFileInfo.getRootNode();
refNode = yangFileInfoIterator.next().getRootNode();
if (rootNode.getName().equals("module1")) {
selfNode = rootNode;
refNode = yangNodeIterator.next();
} else {
refNode = yangFileInfo.getRootNode();
selfNode = yangFileInfoIterator.next().getRootNode();
refNode = rootNode;
selfNode = yangNodeIterator.next();
}
// Check whether the data model tree returned is of type module.
......@@ -503,27 +492,28 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/hierarchicalinterfiletype";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode1 = null;
YangNode refNode2 = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangFileInfo yangFile : utilManager.getYangFileInfoSet()) {
if (yangFile.getRootNode().getName().equals("ietf-network-topology")) {
selfNode = yangFile.getRootNode();
} else if (yangFile.getRootNode().getName().equals("ietf-network")) {
refNode1 = yangFile.getRootNode();
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("ietf-network-topology")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("ietf-network")) {
refNode1 = rootNode;
} else {
refNode2 = yangFile.getRootNode();
refNode2 = rootNode;
}
}
......@@ -571,24 +561,25 @@ public class InterFileLinkingTest {
String searchDir = "src/test/resources/hierarchicalintrawithinterfiletype";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode1 = null;
YangNode selfNode = null;
// Create YANG node set
yangLinkerManager.createYangNodeSet(utilManager.getYangFileInfoSet());
yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet());
// Add references to import list.
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangFileInfoSet());
yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
// Carry out inter-file linking.
yangLinkerManager.processInterFileLinking(utilManager.getYangFileInfoSet());
yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet());
for (YangFileInfo yangFile : utilManager.getYangFileInfoSet()) {
if (yangFile.getRootNode().getName().equals("ietf-network")) {
selfNode = yangFile.getRootNode();
} else if (yangFile.getRootNode().getName().equals("ietf-inet-types")) {
refNode1 = yangFile.getRootNode();
for (YangNode rootNode : utilManager.getYangNodeSet()) {
if (rootNode.getName().equals("ietf-network")) {
selfNode = rootNode;
} else if (rootNode.getName().equals("ietf-inet-types")) {
refNode1 = rootNode;
}
}
......
/*
* 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.linker;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.plugin.manager.YangUtilManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deSerializeDataModel;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.parseJarFile;
/**
* Unit test case for inter-jar linker.
*/
public class InterJarLinkingTest {
private final YangUtilManager utilManager = new YangUtilManager();
private static final String TARGET = "target/interJarFileLinking";
private static final String SEARCH_DIR_FOR_YANG_FILES = "src/test/resources/interJarFileLinking/yangFiles";
private static final String SEARCH_DIR_FOR_SINGLE_JAR_FILES = "src/test/resources/interJarFileLinking/"
+ "jarFiles/single";
private static final String SEARCH_DIR_FOR_MULTI_JAR_FILES = "src/test/resources/interJarFileLinking/"
+ "jarFiles/multi";
/**
* Unit test case for a single jar dependency.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processSingleJarLinking()
throws IOException, MojoExecutionException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(SEARCH_DIR_FOR_YANG_FILES));
int size1 = utilManager.getYangFileInfoSet().size();
for (String file : getListOfTestJar(SEARCH_DIR_FOR_SINGLE_JAR_FILES)) {
addInterJarRootNodes(file);
}
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
int size2 = utilManager.getYangFileInfoSet().size();
assertThat(true, is(size1 != size2));
assertThat(true, is(yangFileInfo.getRootNode().getName().equals("port-pair")));
deleteDirectory(TARGET);
}
/**
* Unit test case for a multiple jar dependency.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processMultipleJarLinking()
throws IOException, MojoExecutionException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(SEARCH_DIR_FOR_YANG_FILES));
int size1 = utilManager.getYangFileInfoSet().size();
for (String file : getListOfTestJar(SEARCH_DIR_FOR_MULTI_JAR_FILES)) {
addInterJarRootNodes(file);
}
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
int size2 = utilManager.getYangFileInfoSet().size();
assertThat(true, is(size1 != size2));
assertThat(true, is(yangFileInfo.getRootNode().getName().equals("port-pair")));
yangFileInfo = yangFileInfoIterator.next();
assertThat(true, is(yangFileInfo.getRootNode().getName().equals("flow-classifier")));
/*
* grouping flow-classifier {
* container flow-classifier {
* leaf id {
* type flow-classifier-id;
* }
*
* leaf tenant-id {
* type port-pair:tenant-id;
* }
* .
* .
* .
*
*/
YangNode node = yangFileInfo.getRootNode();
node = node.getChild();
while (node != null) {
if (node instanceof YangGrouping) {
break;
}
node = node.getNextSibling();
}
node = node.getChild();
ListIterator<YangLeaf> leafIterator = ((YangContainer) node).getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("id"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("flow-classifier-id"));
assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("tenant-id"));
assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
assertThat(true, is(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef()
.getName().equals("tenant-id")));
assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
// Check for the effective built-in type.
assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
deleteDirectory(TARGET);
}
/**
* Returns list of test jar files.
*
* @param searchdir search directory
* @return list of test jar files
*/
private List<String> getListOfTestJar(String searchdir) {
List<String> jarFiles = new ArrayList<>();
File directory = new File(searchdir + "/");
File[] files = directory.listFiles();
for (File file : files) {
jarFiles.add(file.toString());
}
return jarFiles;
}
/**
* Adds data model nodes of jar to file info set.
*
* @param jarFile jar file name
* @throws IOException when fails to do IO operations
*/
private void addInterJarRootNodes(String jarFile) throws IOException {
try {
List<YangNode> interJarResolvedNodes = deSerializeDataModel(parseJarFile(jarFile, TARGET));
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
utilManager.getYangFileInfoSet().add(dependentFileInfo);
}
} catch (IOException e) {
throw new IOException("failed to resolve in interjar scenario.");
}
}
}
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.linker;
import java.io.IOException;
import java.util.List;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
......@@ -92,13 +93,15 @@ public class IntraFileUsesLinkingTest {
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
// leafIterator = yangNode.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under module.
// assertThat(leafInfo.getName(), is("hello"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
ListIterator<List<YangLeaf>> leafIterator1 = uses.getUsesResolvedLeavesList().listIterator();
List<YangLeaf> leafInfo1 = leafIterator1.next();
ListIterator<YangLeaf> leafIterator2 = leafInfo1.listIterator();
YangLeaf leafInfo2 = leafIterator2.next();
// Check whether the information in the leaf is correct under module.
assertThat(leafInfo2.getName(), is("hello"));
assertThat(leafInfo2.getDataType().getDataTypeName(), is("string"));
assertThat(leafInfo2.getDataType().getDataType(), is(YangDataTypes.STRING));
}
......@@ -161,28 +164,32 @@ public class IntraFileUsesLinkingTest {
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
// leafIterator = yangNode.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under module.
// assertThat(leafInfo.getName(), is("treat"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// // Check whether container is the child of module.
// assertThat((grouping.getNextSibling() instanceof YangContainer), is(true));
// container = (YangContainer) grouping.getNextSibling();
//
// // Check whether the container name is set correctly which is under module.
// assertThat(container.getName(), is("test"));
//
// leafIterator = container.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under container which is under module.
// assertThat(leafInfo.getName(), is("leaf2"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
ListIterator<List<YangLeaf>> leafIterator1 = uses.getUsesResolvedLeavesList().listIterator();
List<YangLeaf> leafInfo1 = leafIterator1.next();
ListIterator<YangLeaf> leafIterator2 = leafInfo1.listIterator();
YangLeaf leafInfo2 = leafIterator2.next();
// Check whether the information in the leaf is correct under module.
assertThat(leafInfo2.getName(), is("treat"));
assertThat(leafInfo2.getDataType().getDataTypeName(), is("string"));
assertThat(leafInfo2.getDataType().getDataType(), is(YangDataTypes.STRING));
ListIterator<YangNode> usesChildren = uses.getUsesResolvedNodeList().listIterator();
YangNode usesChild = usesChildren.next();
// Check whether container is the child of module.
assertThat((usesChild instanceof YangContainer), is(true));
container = (YangContainer) usesChild;
// Check whether the container name is set correctly which is under module.
assertThat(container.getName(), is("test"));
leafIterator = container.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under container which is under module.
assertThat(leafInfo.getName(), is("leaf2"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
}
/**
......@@ -241,52 +248,56 @@ public class IntraFileUsesLinkingTest {
assertThat(uses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
// // Check whether list is the sibling of uses which has been deep copied from grouping.
// assertThat((yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling() instanceof YangList),
// is(true));
// YangList yangList = (YangList) yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling();
//
// // Check whether the list name is set correctly.
// assertThat(yangList.getName(), is("valid"));
//
// leafIterator = yangList.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under list which is deep copied.
// assertThat(leafInfo.getName(), is("invalid-interval"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
// assertThat(leafInfo.getUnits(), is("\"seconds\""));
// assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
//
// // Check whether uses is output's child.
// assertThat((yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild() instanceof YangUses),
// is(true));
// YangUses usesInOuput = (YangUses) yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild();
//
// // Check whether uses get resolved.
// assertThat(usesInOuput.getResolvableStatus(),
// is(ResolvableStatus.RESOLVED));
//
// // Check whether list is the sibling of uses which has been deep copied from grouping.
// assertThat((yangNode.getChild().getChild().getNextSibling().getChild().getNextSibling() instanceof YangList),
// is(true));
//
// YangList yangListInOutput = (YangList) yangNode.getChild().getChild().getNextSibling().getNextSibling()
// .getChild().getNextSibling();
//
// // Check whether the list name is set correctly.
// assertThat(yangListInOutput.getName(), is("valid"));
//
// leafIterator = yangListInOutput.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under list which is deep copied.
// assertThat(leafInfo.getName(), is("invalid-interval"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
// assertThat(leafInfo.getUnits(), is("\"seconds\""));
// assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
ListIterator<YangNode> usesChildren = uses.getUsesResolvedNodeList().listIterator();
YangNode usesChild = usesChildren.next();
// Check whether list is the sibling of uses which has been deep copied from grouping.
assertThat((usesChild instanceof YangList), is(true));
YangList yangList = (YangList) usesChild;
// Check whether the list name is set correctly.
assertThat(yangList.getName(), is("valid"));
leafIterator = yangList.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under list which is deep copied.
assertThat(leafInfo.getName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
// Check whether uses is output's child.
assertThat((yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild() instanceof YangUses),
is(true));
YangUses usesInOuput = (YangUses) yangNode.getChild().getChild().getNextSibling().getNextSibling().getChild();
// Check whether uses get resolved.
assertThat(usesInOuput.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
ListIterator<YangNode> usesInOuputChildren = usesInOuput.getUsesResolvedNodeList().listIterator();
YangNode usesInOuputChild = usesInOuputChildren.next();
// Check whether list is the sibling of uses which has been deep copied from grouping.
assertThat((usesInOuputChild instanceof YangList), is(true));
YangList yangListInOutput = (YangList) usesInOuputChild;
// Check whether the list name is set correctly.
assertThat(yangListInOutput.getName(), is("valid"));
leafIterator = yangListInOutput.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under list which is deep copied.
assertThat(leafInfo.getName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
}
/**
......@@ -342,6 +353,24 @@ public class IntraFileUsesLinkingTest {
assertThat(firstUses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
ListIterator<YangNode> firstUsesChildren = firstUses.getUsesResolvedNodeList().listIterator();
YangNode firstUsesChild = firstUsesChildren.next();
// Check whether list is the sibling of uses.
assertThat((firstUsesChild instanceof YangList), is(true));
YangList yangList = (YangList) firstUsesChild;
assertThat(yangList.getName(), is("valid"));
leafIterator = yangList.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under list which has been deep copied from grouping.
assertThat(leafInfo.getName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
// Check whether container is the sibling of uses.
assertThat((firstUses.getNextSibling() instanceof YangContainer), is(true));
YangContainer yangContainer = (YangContainer) firstUses.getNextSibling();
......@@ -349,14 +378,6 @@ public class IntraFileUsesLinkingTest {
// Check whether the container name is set correctly.
assertThat(yangContainer.getName(), is("design"));
// leafIterator = yangContainer.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under design-container.
// assertThat(leafInfo.getName(), is("ink"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("int32"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32));
// Check whether uses is design-container's child.
assertThat((yangContainer.getChild() instanceof YangUses), is(true));
YangUses secondUses = (YangUses) yangContainer.getChild();
......@@ -365,6 +386,16 @@ public class IntraFileUsesLinkingTest {
assertThat(secondUses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
ListIterator<List<YangLeaf>> leafIterator1 = secondUses.getUsesResolvedLeavesList().listIterator();
List<YangLeaf> leafInfo1 = leafIterator1.next();
ListIterator<YangLeaf> leafIterator2 = leafInfo1.listIterator();
YangLeaf leafInfo2 = leafIterator2.next();
// Check whether the information in the leaf is correct under design-container.
assertThat(leafInfo2.getName(), is("ink"));
assertThat(leafInfo2.getDataType().getDataTypeName(), is("int32"));
assertThat(leafInfo2.getDataType().getDataType(), is(YangDataTypes.INT32));
// Check whether container is the sibling of uses.
assertThat((secondUses.getNextSibling() instanceof YangContainer), is(true));
YangContainer yangContainer2 = (YangContainer) secondUses.getNextSibling();
......@@ -386,85 +417,88 @@ public class IntraFileUsesLinkingTest {
assertThat(thirdUses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
// // Check whether container is the sibling of uses.
// assertThat((thirdUses.getNextSibling() instanceof YangContainer), is(true));
//
// YangContainer yangContainer3 = (YangContainer) thirdUses.getNextSibling();
// assertThat(yangContainer3.getName(), is("value"));
//
// leafIterator = yangContainer3.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under container
// // which has been deep copied from grouping.
// assertThat(leafInfo.getName(), is("zip-code"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
//
// // Check whether uses is the sibling of container-design.
// assertThat((yangContainer.getNextSibling() instanceof YangUses), is(true));
// YangUses fourthUses = (YangUses) yangContainer.getNextSibling();
//
// // Check whether uses get resolved.
// assertThat(fourthUses.getResolvableStatus(),
// is(ResolvableStatus.RESOLVED));
//
// // Check whether uses is the sibling of previous uses.
// assertThat((fourthUses.getNextSibling() instanceof YangUses), is(true));
// YangUses fifthUses = (YangUses) fourthUses.getNextSibling();
//
// // Check whether uses get resolved.
// assertThat(fifthUses.getResolvableStatus(),
// is(ResolvableStatus.RESOLVED));
//
// // Check whether list is the sibling of uses.
// assertThat((fifthUses.getNextSibling() instanceof YangList), is(true));
// YangList yangList = (YangList) fifthUses.getNextSibling();
// assertThat(yangList.getName(), is("valid"));
//
// leafIterator = yangList.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under list which has been deep copied from grouping.
// assertThat(leafInfo.getName(), is("invalid-interval"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
// assertThat(leafInfo.getUnits(), is("\"seconds\""));
// assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
//
// // Check whether typedef is the sibling of list.
// assertThat((yangList.getNextSibling() instanceof YangTypeDef), is(true));
// YangTypeDef yangTypeDef = (YangTypeDef) yangList.getNextSibling();
// assertThat(yangTypeDef.getName(), is("my-type"));
//
// leafIterator = grouping.getListOfLeaf().listIterator();
// leafInfo = leafIterator.next();
//
// // Check whether the information in the leaf is correct under grouping.
// assertThat(leafInfo.getName(), is("zip-code"));
// assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
// assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
//
// // Check whether uses is endpoint-grouping's sibling.
// assertThat((grouping.getNextSibling() instanceof YangUses), is(true));
// YangUses endpointUses = (YangUses) grouping.getNextSibling();
//
// // Check whether uses get resolved.
// assertThat(endpointUses.getResolvableStatus(),
// is(ResolvableStatus.RESOLVED));
//
// assertThat((endpointUses.getNextSibling().getNextSibling().getNextSibling().getNextSibling().getNextSibling()
// .getNextSibling() instanceof YangUses), is(true));
//
// YangUses yangUsesInEndpoint = (YangUses) endpointUses.getNextSibling().getNextSibling().getNextSibling()
// .getNextSibling().getNextSibling().getNextSibling();
// assertThat(yangUsesInEndpoint.getResolvableStatus(),
// is(ResolvableStatus.RESOLVED));
//
// assertThat((yangUsesInEndpoint.getNextSibling() instanceof YangContainer), is(true));
// YangContainer yangContainerInEndPoint = (YangContainer) yangUsesInEndpoint.getNextSibling();
//
// assertThat(yangContainerInEndPoint.getName(), is("design"));
ListIterator<YangNode> thirdUsesChildren = thirdUses.getUsesResolvedNodeList().listIterator();
YangNode thirdUsesChild = thirdUsesChildren.next();
// Check whether container is the child of uses.
assertThat((thirdUsesChild instanceof YangContainer), is(true));
YangContainer yangContainer3 = (YangContainer) thirdUsesChild;
assertThat(yangContainer3.getName(), is("value"));
leafIterator = yangContainer3.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under container
// which has been deep copied from grouping.
assertThat(leafInfo.getName(), is("zip-code"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// Check whether uses is the sibling of container-design.
assertThat((yangContainer.getNextSibling() instanceof YangUses), is(true));
YangUses fourthUses = (YangUses) yangContainer.getNextSibling();
assertThat(fourthUses.getName(), is("fourth"));
// Check whether uses get resolved.
assertThat(fourthUses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
ListIterator<List<YangLeaf>> fourthUsesChildren = fourthUses.getUsesResolvedLeavesList().listIterator();
List<YangLeaf> fourthUsesChild = fourthUsesChildren.next();
ListIterator<YangLeaf> fourthUsesChildren1 = fourthUsesChild.listIterator();
YangLeaf fourthUsesChild1 = fourthUsesChildren1.next();
// Check whether the information in the leaf is correct under correct-container.
assertThat(fourthUsesChild1.getName(), is("correct"));
assertThat(fourthUsesChild1.getDataType().getDataTypeName(), is("my-type"));
assertThat(fourthUsesChild1.getDataType().getDataType(), is(YangDataTypes.DERIVED));
// Check whether uses is the sibling of previous uses.
assertThat((fourthUses.getNextSibling() instanceof YangUses), is(true));
YangUses fifthUses = (YangUses) fourthUses.getNextSibling();
assertThat(fifthUses.getName(), is("fifth"));
// Check whether uses get resolved.
assertThat(fifthUses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
ListIterator<List<YangLeaf>> fifthUsesChildren = fifthUses.getUsesResolvedLeavesList().listIterator();
List<YangLeaf> fifthUsesChild = fifthUsesChildren.next();
ListIterator<YangLeaf> fifthUsesChildren1 = fifthUsesChild.listIterator();
YangLeaf fifthUsesChild1 = fifthUsesChildren1.next();
//Check whether the information in the leaf is correct under correct-container.
assertThat(fifthUsesChild1.getName(), is("abc"));
assertThat(fifthUsesChild1.getDataType().getDataTypeName(), is("string"));
assertThat(fifthUsesChild1.getDataType().getDataType(), is(YangDataTypes.STRING));
//Check whether uses is endpoint-grouping's sibling.
assertThat((grouping.getNextSibling() instanceof YangUses), is(true));
YangUses endpointUses = (YangUses) grouping.getNextSibling();
// Check whether uses get resolved.
assertThat(endpointUses.getResolvableStatus(),
is(ResolvableStatus.RESOLVED));
assertThat(endpointUses.getName(), is("endpoint"));
ListIterator<YangNode> endpointUsesUsesChildren = endpointUses.getUsesResolvedNodeList().listIterator();
YangNode endpointUsesUsesChild = endpointUsesUsesChildren.next();
// Check whether list is the sibling of uses.
assertThat((endpointUsesUsesChild instanceof YangList), is(true));
YangList yangList1 = (YangList) firstUsesChild;
assertThat(yangList1.getName(), is("valid"));
leafIterator = yangList1.getListOfLeaf().listIterator();
leafInfo = leafIterator.next();
// Check whether the information in the leaf is correct under list which has been deep copied from grouping.
assertThat(leafInfo.getName(), is("invalid-interval"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
assertThat(leafInfo.getUnits(), is("\"seconds\""));
assertThat(leafInfo.getReference(), is("\"RFC 6020\""));
}
/**
......
......@@ -26,8 +26,10 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
......@@ -37,9 +39,9 @@ import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaDataType;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaDataType;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportClass;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportPackage;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
/**
......
......@@ -22,6 +22,7 @@ import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......
......@@ -22,6 +22,7 @@ import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......
......@@ -23,16 +23,17 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......
......@@ -23,13 +23,14 @@ import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.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.utils.io.impl.YangIoUtils.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;
......
......@@ -22,6 +22,7 @@ import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......
......@@ -22,6 +22,7 @@ import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......
......@@ -22,6 +22,7 @@ import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......
......@@ -25,7 +25,6 @@ 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.apache.commons.io.FileUtils.deleteDirectory;
import static org.hamcrest.core.Is.is;
......@@ -34,8 +33,8 @@ import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.doesPackageExist;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.doesPackageExist;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
......
......@@ -22,7 +22,6 @@ 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;
......
......@@ -26,17 +26,15 @@ 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;
import static org.apache.commons.io.FileUtils.deleteDirectory;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToCompilationRoot;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
......