Bharat saraswal
Committed by Gerrit Code Review

[ONOS-4351][ONOS-4524] Augment linking and defect fixed.

Change-Id: I7c8e8c90579eea4631e014c4906a543a3c249427
Showing 56 changed files with 1294 additions and 589 deletions
/*
* 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.datamodel;
/**
* Represents YANG constructs which can be augmented.
*/
public interface YangAugmentationHolder {
}
......@@ -92,7 +92,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
* Represents data model node to maintain information defined in YANG case.
*/
public class YangCase extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Case name.
......
......@@ -59,7 +59,8 @@ import static org.onosproject.yangutils.utils.YangConstructType.CHOICE_DATA;
/**
* Represents data model node to maintain information defined in YANG choice.
*/
public class YangChoice extends YangNode implements YangCommonInfo, Parsable, CollisionDetector {
public class YangChoice extends YangNode
implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of choice.
......
......@@ -87,7 +87,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG container.
*/
public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
public class YangContainer extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the container.
......
......@@ -68,7 +68,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG input.
*/
public class YangInput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector {
public class YangInput extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the input.
......
......@@ -68,7 +68,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
* Represents list data represented in YANG.
*/
public class YangList extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the YANG list.
......
......@@ -74,8 +74,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG notification.
*/
public class YangNotification extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable,
CollisionDetector {
public class YangNotification extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the notification.
......
......@@ -67,7 +67,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG output.
*/
public class YangOutput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector {
public class YangOutput extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the output.
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.util.List;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
......@@ -33,9 +32,10 @@ import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangAugmentNode;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.generateNameForAugmentNode;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getParentsPrefix;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.parserException;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.validateNodeInTargetPath;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
......@@ -119,8 +119,11 @@ public final class AugmentListener {
if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) {
YangNode curNode = (YangNode) curData;
YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION);
validateTargetNodePath(targetNodes, curNode, ctx);
yangAugment.setTargetNode(targetNodes);
yangAugment.setName(detectCollisionForTargetNode(curData, targetNodes, line, charPositionInLine, listener));
yangAugment.setName(generateNameForAugmentNode(curData, targetNodes, listener));
try {
curNode.addChild(yangAugment);
......@@ -171,58 +174,34 @@ public final class AugmentListener {
}
/**
* Detects collision for java file generation of augment node when
* it is updating the same target node in same parent multiple times.
* Returns name for generated java file of augment node
* Validates whether the current target node path is correct or not.
*
* @param curData parsable data
* @param targetNodes list of target nodes
* @param line line in YANG file
* @param charPositionInLine char position in YANG file
* @param listener tree walk listener
* @return name for generated java file for augment node
* @param curNode current YANG node
*/
private static String detectCollisionForTargetNode(Parsable curData, List<YangNodeIdentifier> targetNodes, int line,
int charPositionInLine, TreeWalkListener listener) {
String curPrefix = null;
if (curData instanceof YangModule) {
curPrefix = ((YangModule) curData).getPrefix();
} else if (curData instanceof YangSubModule) {
curPrefix = ((YangSubModule) curData).getPrefix();
}
YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
boolean isPrefix = isPrefixPresent(nodeId, curPrefix);
String xpath = createValidNameForAugment(nodeId, isPrefix);
private static void validateTargetNodePath(List<YangNodeIdentifier> targetNodes, YangNode curNode,
GeneratedYangParser.AugmentStatementContext ctx) {
if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
try {
((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(xpath,
AUGMENT_DATA);
} catch (DataModelException e) {
return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix);
YangNodeIdentifier moduleId = targetNodes.get(0);
if (moduleId.getPrefix() == null) {
if (!moduleId.getName().equals(curNode.getName())) {
throw parserException(ctx);
} else {
validateNodeInTargetPath(curNode, targetNodes, ctx);
}
} else {
String parentPrefix = getParentsPrefix(curNode);
if (parentPrefix != null) {
if (!parentPrefix.equals(moduleId.getPrefix())) {
// TODO: handle in linker.
} else {
validateNodeInTargetPath(curNode, targetNodes, ctx);
}
clearOccurrenceCount();
return xpath;
} else {
// TODO: handle in linker.
}
/**
* Returns true if a prefix is present and it is not equals to parents prefix.
*
* @param nodeId YANG node identifier
* @param parentsPrefix parent's prefix
* @return true if a prefix is present and it is not equals to parents prefix
*/
private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) {
return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix;
}
/**
* Validates for the child nodes of augment node.
*/
private static void validateForChildNodes() {
//TODO: implement with linker.
}
}
......
......@@ -110,7 +110,7 @@ public final class EnumListener {
listener.getParsedDataStack().push(enumNode);
}
/* Removes quotes from the enum name if present.*/
/*Removes quotes from the enum name if present.*/
private static String getValidNamedValue(String name) {
if (name.contains(QUOTES)) {
name = name.replace(QUOTES, EMPTY_STRING);
......
......@@ -19,14 +19,24 @@ package org.onosproject.yangutils.parser.impl.parserutils;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA;
/**
* Represents a utility which provides valid name for generated java file for augment node.
* Represents a utility which provides listener utilities augment node.
*/
public final class AugmentJavaFileNameGenUtil {
public final class AugmentListenerUtil {
/**
* Prefix to be added to generated java file for augment node.
......@@ -39,7 +49,7 @@ public final class AugmentJavaFileNameGenUtil {
private static int occurrenceCount = 1;
/**
* List of names for generated augment java file.
* List of names for augment's generated java file.
*/
private static List<String> augmentJavaFileNameList = new ArrayList<>();
......@@ -50,7 +60,7 @@ public final class AugmentJavaFileNameGenUtil {
/**
* Creates an instance of augment java file name generator utility.
*/
private AugmentJavaFileNameGenUtil() {
private AugmentListenerUtil() {
}
/**
......@@ -90,6 +100,36 @@ public final class AugmentJavaFileNameGenUtil {
}
/**
* Generates name for augment node also detects collision for java file generation of augment node when
* augment is updating the same target node in same parent multiple times.
*
* @param curData parsable data
* @param targetNodes list of target nodes
* @param listener tree walk listener
* @return name for augment node
*/
public static String generateNameForAugmentNode(Parsable curData, List<YangNodeIdentifier> targetNodes,
TreeWalkListener listener) {
String curPrefix = getParentsPrefix((YangNode) curData);
YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
boolean isPrefix = isPrefixPresent(nodeId, curPrefix);
String generateName = createValidNameForAugment(nodeId, isPrefix);
if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
try {
((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(generateName,
AUGMENT_DATA);
} catch (DataModelException e) {
return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix);
}
}
clearOccurrenceCount();
return generateName;
}
/**
* Creates a name identifier for augment.
*
* @param nodeId node identifier
......@@ -119,7 +159,7 @@ public final class AugmentJavaFileNameGenUtil {
/**
* Updates occurrence count of augment.
*/
public static void updateOccurenceCount() {
private static void updateOccurenceCount() {
int count = getOccurrenceCount();
count++;
setOccurrenceCount(count);
......@@ -157,4 +197,113 @@ public final class AugmentJavaFileNameGenUtil {
setOccurrenceCount(ONE);
}
/**
* Returns true if a prefix is present and it is not equals to parents prefix.
*
* @param nodeId YANG node identifier
* @param parentsPrefix parent's prefix
* @return true if a prefix is present and it is not equals to parents prefix
*/
private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) {
return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix;
}
/**
* Validates whether current node in target path is valid or not.
*
* @param curNode current YANG node
* @param targetNodes list of target nodes
* @param ctx augment statement context
*/
public static void validateNodeInTargetPath(YangNode curNode, List<YangNodeIdentifier> targetNodes,
GeneratedYangParser.AugmentStatementContext ctx) {
curNode = curNode.getChild();
YangNode tempNode = validateCurrentTargetNode(targetNodes, curNode);
if (tempNode != null) {
switch (tempNode.getNodeType()) {
case CONTAINER_NODE:
break;
case LIST_NODE:
break;
case CHOICE_NODE:
break;
case CASE_NODE:
break;
case INPUT_NODE:
break;
case OUTPUT_NODE:
break;
case NOTIFICATION_NODE:
break;
default:
throw parserException(ctx);
}
} else {
throw parserException(ctx);
}
}
/**
* Validates whether nodes in target node list are valid or not.
*
* @param targetNodeName current target node
* @param curNode YANG node
* @return true or false
*/
private static YangNode validateCurrentTargetNode(List<YangNodeIdentifier> targetNodes, YangNode curNode) {
YangNode tempNode = null;
while (curNode != null) {
tempNode = curNode;
for (int i = 1; i < targetNodes.size(); i++) {
if (curNode.getName().equals(targetNodes.get(i).getName())) {
if (curNode.getChild() != null && targetNodes.size() - 1 != i) {
curNode = curNode.getChild();
} else if (curNode.getChild() != null && targetNodes.size() - 1 == i) {
return curNode;
} else if (curNode.getChild() == null && targetNodes.size() - 1 == i) {
return curNode;
} else {
break;
}
} else {
curNode = tempNode;
break;
}
}
curNode = curNode.getNextSibling();
}
return null;
}
/**
* Builds parser exception.
*
* @param ctx augment statement context
* @return parser exception
*/
public static ParserException parserException(GeneratedYangParser.AugmentStatementContext ctx) {
int line = ctx.getStart().getLine();
int charPositionInLine = ctx.getStart().getCharPositionInLine();
ParserException exception = new ParserException("invalid target node path.");
exception.setLine(line);
exception.setCharPosition(charPositionInLine);
return exception;
}
/**
* Returns parent nodes prefix.
*
* @param curNode current YANG node
* @return parent nodes prefix
*/
public static String getParentsPrefix(YangNode curNode) {
String curPrefix = null;
if (curNode instanceof YangModule) {
curPrefix = ((YangModule) curNode).getPrefix();
} else if (curNode instanceof YangSubModule) {
curPrefix = ((YangSubModule) curNode).getPrefix();
}
return curPrefix;
}
}
......
......@@ -28,10 +28,10 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
......@@ -114,7 +114,8 @@ public class YangUtilManager extends AbstractMojo {
@Component
private BuildContext context;
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private static final String DEFAULT_PKG = SLASH
+ getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private YangNode rootNode;
......@@ -124,7 +125,7 @@ public class YangUtilManager extends AbstractMojo {
try {
/**
/*
* For deleting the generated code in previous build.
*/
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
......@@ -146,7 +147,7 @@ public class YangUtilManager extends AbstractMojo {
try {
YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
setRootNode(yangNode);
generateJavaCode(yangNode, yangPlugin);
generateJavaCode(yangNode, yangPlugin, yangFile);
} catch (ParserException e) {
String logInfo = "Error in file: " + e.getFileName();
if (e.getLineNumber() != 0) {
......@@ -165,13 +166,20 @@ public class YangUtilManager extends AbstractMojo {
addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project);
} catch (Exception e) {
String fileName = "";
if (e instanceof TranslatorException) {
fileName = ((TranslatorException) e).getFileName();
}
try {
translatorErrorHandler(getRootNode());
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
} catch (IOException | DataModelException ex) {
throw new MojoExecutionException("Error handler failed to delete files for data model node.");
} catch (IOException ex) {
throw new MojoExecutionException(
"Error handler failed to delete files for data model node.");
}
throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage());
throw new MojoExecutionException(
"Exception occured due to " + e.getLocalizedMessage() + " in " + fileName
+ " YANG file.");
}
}
......
......@@ -21,7 +21,7 @@ import java.util.List;
/**
* Abstraction of an entity which represents augmentation of a YANG node.
*/
public interface HasAugmentation {
public interface AugmentationHolder {
/**
* Adds augment info to the augment info list.
......
......@@ -16,8 +16,7 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
......@@ -29,16 +28,16 @@ public interface JavaCodeGenerator {
* Traverse the schema of application and generate corresponding code.
*
* @param yangPlugin YANG plugin config
* @throws IOException when fails to translate the data model tree
* @throws TranslatorException when fails to translate the data model tree
*/
void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException;
throws TranslatorException;
/**
* Traverse the schema of application and generate corresponding code.
*
* @throws IOException when fails to generate java code
* @throws TranslatorException when fails to generate java code
*/
void generateCodeExit()
throws IOException;
throws TranslatorException;
}
......
......@@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
......@@ -67,11 +66,12 @@ public final class JavaCodeGeneratorUtil {
*
* @param rootNode root node of the data model tree
* @param yangPlugin YANG plugin config
* @throws IOException when fails to generate java code file the current
* @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
throws IOException {
public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin, String fileName)
throws TranslatorException {
YangNode codeGenNode = rootNode;
TraversalType curTraversal = ROOT;
......@@ -80,7 +80,7 @@ public final class JavaCodeGeneratorUtil {
if (curTraversal != PARENT) {
if (codeGenNode instanceof JavaCodeGenerator) {
setCurNode(codeGenNode);
generateCodeEntry(codeGenNode, yangPlugin);
generateCodeEntry(codeGenNode, yangPlugin, fileName);
} else {
/*
* For grouping and uses, there is no code generation, skip the generation for the child.
......@@ -100,11 +100,11 @@ public final class JavaCodeGeneratorUtil {
curTraversal = CHILD;
codeGenNode = codeGenNode.getChild();
} else if (codeGenNode.getNextSibling() != null) {
generateCodeExit(codeGenNode);
generateCodeExit(codeGenNode, fileName);
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
generateCodeExit(codeGenNode);
generateCodeExit(codeGenNode, fileName);
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
......@@ -117,16 +117,20 @@ public final class JavaCodeGeneratorUtil {
* @param codeGenNode current data model node for which the code needs to be
* generated
* @param yangPlugin YANG plugin config
* @throws IOException IO operation exception
* @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
throws IOException {
private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin, String fileName)
throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
} else {
throw new TranslatorException(
TranslatorException ex = new TranslatorException(
"Generated data model node cannot be translated to target language code");
ex.setFileName(fileName);
throw ex;
}
}
......@@ -135,27 +139,27 @@ public final class JavaCodeGeneratorUtil {
*
* @param codeGenNode current data model node for which the code needs to be
* generated
* @throws IOException IO operation exception
* @param fileName YANG file name
* @throws TranslatorException when fails to generate java code file the current
* node
*/
private static void generateCodeExit(YangNode codeGenNode)
throws IOException {
private static void generateCodeExit(YangNode codeGenNode, String fileName) throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeExit();
} else {
throw new TranslatorException(
TranslatorException ex = new TranslatorException(
"Generated data model node cannot be translated to target language code");
ex.setFileName(fileName);
throw ex;
}
}
/**
* Free other YANG nodes of data-model tree when error occurs while file
* generation of current node.
*
* @throws DataModelException when fails to do datamodel operations
*/
private static void freeRestResources()
throws DataModelException {
private static void freeRestResources() {
YangNode freedNode = getCurNode();
YangNode tempNode = freedNode;
......@@ -205,10 +209,9 @@ public final class JavaCodeGeneratorUtil {
*
* @param rootNode root node of data-model tree
* @throws IOException when fails to delete java code file the current node
* @throws DataModelException when fails to do datamodel operations
*/
public static void translatorErrorHandler(YangNode rootNode)
throws IOException, DataModelException {
throws IOException {
/**
* Free other resources where translator has failed.
......
......@@ -20,26 +20,29 @@ import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import static java.util.Collections.sort;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static java.util.Collections.sort;
/**
* Represents that generated Java file can contain imports.
*/
......@@ -178,7 +181,7 @@ public class JavaImportData {
*
* @return import for list attribute
*/
public static String getImportForList() {
public String getImportForList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
}
......@@ -187,17 +190,17 @@ public class JavaImportData {
*
* @return import for array list attribute
*/
public static String getImportForArrayList() {
public String getImportForArrayList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for HasAugmentation class.
* Returns import string for AugmentationHolder class.
*
* @return import string for HasAugmentation class
* @return import string for AugmentationHolder class
*/
public static String getHasAugmentationImport() {
return IMPORT + HAS_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + HAS_AUGMENTATION_CLASS_IMPORT_CLASS;
public String getAugmentationHolderImport() {
return IMPORT + PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
}
/**
......@@ -205,7 +208,25 @@ public class JavaImportData {
*
* @return import string for AugmentedInfo class
*/
public static String getAugmentedInfoImport() {
public String getAugmentedInfoImport() {
return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
/**
* Returns import string for ListenerService class.
*
* @return import string for ListenerService class
*/
public String getListenerServiceImport() {
return IMPORT + LISTENER_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for ListenerRegistry class.
*
* @return import string for ListenerRegistry class
*/
public String getListenerRegistryImport() {
return IMPORT + LISTENER_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
}
}
......
......@@ -28,7 +28,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
/**
* Represents implementation of java code fragments temporary implementations.
......@@ -309,15 +308,6 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Adds class to the extends list.
*
* @param extend class to be extended
*/
public void addToExtendsList(String extend) {
getExtendsList().add(extend);
}
/**
* Adds build method for interface.
*
* @return build method for interface
......
......@@ -18,11 +18,12 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
......@@ -53,7 +54,7 @@ public class TempJavaEventFragmentFiles
*/
public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setExtendsList(new ArrayList<>());
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
......@@ -92,11 +93,13 @@ public class TempJavaEventFragmentFiles
throws IOException {
createPackage(curNode);
String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
.getJavaFileInfo().getJavaName());
/**
* Creates event interface file.
*/
setEventJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_FILE_NAME_SUFFIX)));
setEventJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_FILE_NAME_SUFFIX));
generateEventFile(getEventJavaFileHandle(), curNode, null);
/**
......
......@@ -18,11 +18,12 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
......@@ -53,7 +54,7 @@ public class TempJavaEventListenerFragmentFiles
*/
public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setExtendsList(new ArrayList<>());
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
......@@ -90,11 +91,12 @@ public class TempJavaEventListenerFragmentFiles
throws IOException {
createPackage(curNode);
String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
.getJavaFileInfo().getJavaName());
/**
* Creates event listener interface file.
*/
setEventListenerJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_LISTENER_FILE_NAME_SUFFIX)));
setEventListenerJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null);
/**
......
......@@ -28,6 +28,7 @@ import org.onosproject.yangutils.datamodel.YangLeavesHolder;
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.JavaExtendsListHolder;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
......@@ -74,13 +75,12 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentationHoldersImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.detectCollisionBwParentAndChildForImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
......@@ -131,8 +131,7 @@ public class TempJavaFragmentFiles {
/**
* Contains all the interface(s)/class name which will be extended by generated files.
*/
private List<String> extendsList = new ArrayList<>();
private JavaExtendsListHolder javaExtendsListHolder;
/**
* File type extension for java classes.
*/
......@@ -499,9 +498,8 @@ public class TempJavaFragmentFiles {
* @param javaFileInfo generated java file information
* @throws IOException when fails to create new file handle
*/
TempJavaFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setExtendsList(new ArrayList<>());
TempJavaFragmentFiles(JavaFileInfo javaFileInfo) throws IOException {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
......@@ -776,30 +774,21 @@ public class TempJavaFragmentFiles {
}
/**
* Returns list of classes to be extended by generated files.
*
* @return list of classes to be extended by generated files
*/
List<String> getExtendsList() {
return extendsList;
}
/**
* Sets class to be extended by generated file.
* Returns java extends list holder.
*
* @param extendsList list of classes to be extended
* @return java extends list holder
*/
void setExtendsList(List<String> extendsList) {
this.extendsList = extendsList;
public JavaExtendsListHolder getJavaExtendsListHolder() {
return javaExtendsListHolder;
}
/**
* Adds class to the extends list.
* Sets java extends list holder.
*
* @param extend class to be extended
* @param javaExtendsListHolder java extends list holder
*/
public void addToExtendsList(String extend) {
getExtendsList().add(extend);
public void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
this.javaExtendsListHolder = javaExtendsListHolder;
}
/**
......@@ -1323,10 +1312,6 @@ public class TempJavaFragmentFiles {
if (isAttributePresent()) {
imports = getJavaImportData().getImports();
}
/*
* Prepares java file generator for extends list.
*/
prepareJavaFileGeneratorForExtendsList(getExtendsList());
createPackage(curNode);
/*
......@@ -1347,16 +1332,7 @@ public class TempJavaFragmentFiles {
}
}
}
/*
* Adds import for HasAugmentation class.
*/
if (isHasAugmentationExtended(getExtendsList())) {
addHasAugmentationImport(curNode, imports, true);
}
if (isAugmentedInfoExtended(getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
}
sortImports(imports);
/*
* Create interface file.
*/
......@@ -1378,10 +1354,10 @@ public class TempJavaFragmentFiles {
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
}
insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
if (isHasAugmentationExtended(getExtendsList())) {
addHasAugmentationImport(curNode, imports, false);
if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
addAugmentationHoldersImport(curNode, imports, false);
}
if (isAugmentedInfoExtended(getExtendsList())) {
if (isAugmentedInfoExtended(getJavaExtendsListHolder().getExtendsList())) {
addAugmentedInfoImport(curNode, imports, false);
}
if (curNode instanceof YangCase) {
......@@ -1392,7 +1368,7 @@ public class TempJavaFragmentFiles {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(curNode, imports);
}
if (isHasAugmentationExtended(getExtendsList())) {
if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
addArrayListImport(curNode, imports, true);
}
......@@ -1417,8 +1393,11 @@ public class TempJavaFragmentFiles {
mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
}
insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
addAugmentedInfoImport(curNode, imports, false);
addArrayListImport(curNode, imports, false);
}
}
/*
* Close all the file handles.
*/
......
......@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
......@@ -31,11 +32,11 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
......@@ -183,7 +184,7 @@ public class TempJavaServiceFragmentFiles
}
/**
* Generate java code.
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
......@@ -197,17 +198,29 @@ public class TempJavaServiceFragmentFiles
createPackage(curNode);
boolean isNotification = false;
YangNode tempNode = curNode.getChild();
while (tempNode != null) {
if (tempNode instanceof YangJavaNotification) {
isNotification = true;
break;
}
tempNode = tempNode.getNextSibling();
}
if (isNotification) {
addListnersImport(curNode, imports, true, LISTENER_SERVICE);
}
/**
* Creates rpc interface file.
*/
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
if (isHasAugmentationExtended(getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
addArrayListImport(curNode, imports, true);
if (isNotification) {
addListnersImport(curNode, imports, false, LISTENER_SERVICE);
addListnersImport(curNode, imports, true, LISTENER_REG);
}
/**
* Create builder class file.
*/
......@@ -215,7 +228,9 @@ public class TempJavaServiceFragmentFiles
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent());
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
if (isNotification) {
addListnersImport(curNode, imports, false, LISTENER_REG);
}
/**
* Close all the file handles.
*/
......
......@@ -21,13 +21,13 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangNode;
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 static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
......@@ -211,7 +211,7 @@ public class TempJavaTypeFragmentFiles
javaType.updateJavaQualifiedInfo();
String typeName = javaType.getDataTypeName();
if (javaType.getDataType().equals(YangDataTypes.DERIVED)) {
if (javaType.getDataType().equals(DERIVED)) {
typeName = getCamelCase(typeName, null);
}
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
......
......@@ -19,7 +19,6 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
/**
* Represent java based identification of the YANG leaves.
*/
......@@ -47,7 +46,6 @@ public interface JavaLeafInfoContainer
*/
String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig);
/**
* Identifies if object is a leaf-list.
*
......
......@@ -103,22 +103,28 @@ public class YangJavaAugment
* augment info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeOfAugmentableNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for augmentable node " + this.getName());
}
}
/**
* Create a java file using the YANG augment info.
*
* @throws IOException when failed to do IO operations
* @throws TranslatorException when failed to do translator operations
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for augmentable node " + this.getName());
}
}
}
......
......@@ -102,20 +102,27 @@ public class YangJavaCase
* case info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeOfAugmentableNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for case node " + this.getName());
}
}
/**
* Creates a java file using the YANG case info.
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for case node " + this.getName());
}
}
}
......
......@@ -22,10 +22,10 @@ import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents choice information extended to support java code generation.
......@@ -102,20 +102,27 @@ public class YangJavaChoice
* choice info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
YangJavaModelUtils.generateCodeAndUpdateInParent(this, yangPlugin, false);
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeAndUpdateInParent(this, yangPlugin, false);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for choice node " + this.getName());
}
}
/**
* Creates a java file using the YANG choice info.
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for choice node " + this.getName());
}
}
}
......
......@@ -102,23 +102,30 @@ public class YangJavaContainer
* container info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeAndUpdateInParent(this, yangPlugin, false);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for container node " + this.getName());
}
}
/**
* Create a java file using the YANG container info.
*
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for container node " + this.getName());
}
}
}
......
......@@ -104,23 +104,30 @@ public class YangJavaEnumeration
* enumeration info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
* @throws TranslatorException translator operations fails
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeOfNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for enumeration node " + this.getName());
}
}
/**
* Creates a java file using the YANG enumeration info.
*
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for enumeration node " + this.getName());
}
}
}
......
......@@ -103,22 +103,29 @@ public class YangJavaInput
* input info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeOfNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for input node " + this.getName());
}
}
/**
* Creates a java file using the YANG input info.
*
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for input node " + this.getName());
}
}
}
......
......@@ -102,22 +102,29 @@ public class YangJavaList
* list info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeAndUpdateInParent(this, yangPlugin, true);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for list node " + this.getName());
}
}
/**
* Creates a java file using the YANG list info.
*
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for list node " + this.getName());
}
}
}
......
......@@ -22,11 +22,11 @@ import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
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.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......@@ -103,23 +103,30 @@ public class YangJavaModule
* Generates java code for module.
*
* @param yangPlugin YANG plugin config
* @throws IOException when fails to generate the source files
* @throws TranslatorException when fails to generate the source files
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate());
YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, modulePkg);
try {
generateCodeOfRootNode(this, yangPlugin, modulePkg);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for module node " + this.getName());
}
}
/**
* Creates a java file using the YANG module info.
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for module node " + this.getName());
}
}
}
......
......@@ -18,17 +18,25 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.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 static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
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.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
/**
* Represents notification information extended to support java code generation.
......@@ -107,11 +115,10 @@ public class YangJavaNotification
* notification info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
/**
* As part of the notification support the following files needs to be generated.
......@@ -122,17 +129,44 @@ public class YangJavaNotification
* The manager class needs to extend the ListenerRegistry.
*/
// Generate subject of the notification(event), this is simple interface
// with builder class.
try {
generateCodeOfAugmentableNode(this, yangPlugin);
addNotificationToExtendsList();
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for notification node " + this.getName());
}
}
/*Adds current notification info to the extends list so its parents service*/
private void addNotificationToExtendsList() {
YangNode parent = this.getParent();
JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) parent)
.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().getJavaExtendsListHolder();
JavaQualifiedTypeInfo event = new JavaQualifiedTypeInfo();
String parentInfo = getCapitalCase(((JavaFileInfoContainer) parent)
.getJavaFileInfo().getJavaName());
event.setClassInfo(parentInfo + EVENT_STRING);
event.setPkgInfo(getJavaFileInfo().getPackage());
holder.addToExtendsList(event, parent);
JavaQualifiedTypeInfo eventListener = new JavaQualifiedTypeInfo();
eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING);
eventListener.setPkgInfo(getJavaFileInfo().getPackage());
holder.addToExtendsList(eventListener, parent);
// Generate subject of the notification(event), this is simple interface with builder class.
generateCodeOfNode(this, yangPlugin);
}
/**
* Creates a java file using the YANG notification info.
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
/**
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
......@@ -141,8 +175,12 @@ public class YangJavaNotification
*
* The manager class needs to extend the "ListenerRegistry".
*/
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for notification node " + this.getName());
}
}
}
......
......@@ -103,23 +103,31 @@ public class YangJavaOutput
* output info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeOfNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for output node " + this.getName());
}
}
/**
* Creates a java file using the YANG output info.
*
* @throws IOException IO operation fail
* @throws TranslatorException translator operation fail
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code exit for output node " + this.getName());
}
}
}
......
......@@ -71,31 +71,32 @@ public class YangJavaRpc
* RPC info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
* @throws TranslatorException translator operations fails
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
if (!(this instanceof JavaCodeGeneratorInfo)) {
// TODO:throw exception
}
// Add package information for rpc and create corresponding folder.
updatePackageInfo((JavaCodeGeneratorInfo) this, yangPlugin);
try {
updatePackageInfo(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException("Failed to prepare generate code entry for RPC node " + this.getName());
}
}
/**
* Creates a java file using the YANG RPC info.
*
* @throws IOException IO operations fails
* @throws TranslatorException translator operations fails
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
// Get the parent module/sub-module.
YangNode parent = getParentNodeInGenCode((YangNode) this);
YangNode parent = getParentNodeInGenCode(this);
// Parent should be holder of rpc or notification.
if (!(parent instanceof RpcNotificationContainer)) {
......@@ -110,7 +111,8 @@ public class YangJavaRpc
JavaAttributeInfo javaAttributeInfoOfInput = null;
JavaAttributeInfo javaAttributeInfoOfOutput = null;
// Get the child input and output node and obtain create java attribute info.
// Get the child input and output node and obtain create java attribute
// info.
YangNode yangNode = this.getChild();
while (yangNode != null) {
if (yangNode instanceof YangInput) {
......@@ -130,10 +132,13 @@ public class YangJavaRpc
/*
* Add the rpc information to the parent's service temp file.
*/
((TempJavaCodeFragmentFilesContainer) parent)
.getTempJavaCodeFragmentFiles().getServiceTempFiles()
try {
((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
((YangNode) this).getName());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for RPC node " + this.getName());
}
// No file will be generated during RPC exit.
}
......@@ -210,5 +215,5 @@ public class YangJavaRpc
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempJavaCodeFragmentFiles = fileHandle;
}
}
}
......
......@@ -23,11 +23,11 @@ import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
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.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......@@ -117,24 +117,32 @@ public class YangJavaSubModule
* submodule info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operation fail
* @throws TranslatorException when fails to translate
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
getRevision().getRevDate());
YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, subModulePkg);
try {
generateCodeOfRootNode(this, yangPlugin, subModulePkg);
} catch (IOException e) {
throw new TranslatorException(
"failed to prepare generate code entry for submodule node " + this.getName());
}
}
/**
* Creates a java file using the YANG submodule info.
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for submodule node " + this.getName());
}
}
}
......
......@@ -22,6 +22,8 @@ import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
/**
* Represents java information corresponding to the YANG type.
*
* @param <T> generic parameter for YANG java type
*/
public class YangJavaType<T>
extends YangType<T>
......
......@@ -103,23 +103,31 @@ public class YangJavaTypeDef
* typedef info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
* @throws TranslatorException when fails to translate
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeOfNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for typedef node " + this.getName());
}
}
/**
* Create a java file using the YANG typedef info.
*
* @throws IOException IO operations fails
* @throws TranslatorException when fails to translate
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for typedef node " + this.getName());
}
}
}
......
......@@ -18,13 +18,13 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
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.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
......@@ -84,10 +84,6 @@ public class YangJavaUnion
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("Missing temp file hand for current node "
+ getCapitalCase(getJavaFileInfo().getJavaName()));
}
return tempFileHandle;
}
......@@ -106,22 +102,30 @@ public class YangJavaUnion
* union info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
* @throws TranslatorException when fails to translate
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
generateCodeOfNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException(
"Failed to prepare generate code entry for union node " + this.getName());
}
}
/**
* Creates a java file using the YANG union info.
*
* @throws IOException IO operations fails
* @throws TranslatorException when fails to translate
*/
@Override
public void generateCodeExit()
throws IOException {
public void generateCodeExit() throws TranslatorException {
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for union node " + this.getName());
}
}
}
......
......@@ -16,6 +16,12 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
......@@ -26,17 +32,23 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.isExtendsList;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
......@@ -71,29 +83,53 @@ public final class ClassDefinitionGenerator {
* Based on the file type and the YANG name of the file, generate the
* class / interface definition start.
*/
if ((genFileTypes & INTERFACE_MASK) != 0) {
return getInterfaceDefinition(yangName);
} else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) {
switch (genFileTypes) {
case BUILDER_CLASS_MASK:
return getBuilderClassDefinition(yangName);
} else if ((genFileTypes & IMPL_CLASS_MASK) != 0) {
case IMPL_CLASS_MASK:
return getImplClassDefinition(yangName);
} else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) {
case BUILDER_INTERFACE_MASK:
return getBuilderInterfaceDefinition(yangName);
} else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) {
return getTypeClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) {
case GENERATE_TYPEDEF_CLASS:
case GENERATE_UNION_CLASS:
return getTypeClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) {
case GENERATE_ENUM_CLASS:
return getEnumClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) {
return getRpcInterfaceDefinition(yangName);
} else if ((genFileTypes & GENERATE_EVENT_CLASS) != 0) {
return getEventDefinition(yangName);
} else if ((genFileTypes & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
case GENERATE_EVENT_LISTENER_INTERFACE:
return getEventListenerDefinition(yangName);
default:
return null;
}
}
/**
* Based on the file type and the YANG name of the file, generate the class
* / interface definition start.
*
* @param genFileTypes generated file type
* @param yangName class name
* @param curNode current YANG node
* @return class definition
*/
public static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) {
/**
* Based on the file type and the YANG name of the file, generate the
* class / interface definition start.
*/
switch (genFileTypes) {
case INTERFACE_MASK:
return getInterfaceDefinition(yangName, curNode);
case GENERATE_SERVICE_AND_MANAGER:
return getRpcInterfaceDefinition(yangName, curNode);
case GENERATE_EVENT_CLASS:
String eventName = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
return getEventDefinition(yangName, eventName);
default:
return null;
}
}
/**
* Returns enum file class definition.
......@@ -111,18 +147,26 @@ public final class ClassDefinitionGenerator {
* @param yangName file name
* @return definition
*/
private static String getInterfaceDefinition(String yangName) {
if (!isExtendsList()) {
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
private static String getInterfaceDefinition(String yangName, YangNode curNode) {
JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder();
if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
for (String extend : getExtendsList()) {
def = def + extend + COMMA + SPACE;
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (!holder.getExtendedClassStore().get(info)) {
def = def + info.getClassInfo() + COMMA + SPACE;
} else {
def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE;
}
}
def = trimAtLast(def, COMMA);
return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns builder interface file class definition.
......@@ -169,17 +213,47 @@ public final class ClassDefinitionGenerator {
}
/**
* Returns rpc file interface definition.
* Returns RPC file interface definition.
*
* @param yangName file name
* @param curNode current YANG node
* @return definition
*/
private static String getRpcInterfaceDefinition(String yangName) {
private static String getRpcInterfaceDefinition(String yangName, YangNode curNode) {
JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles().getJavaExtendsListHolder();
if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
curNode = curNode.getChild();
while (curNode != null) {
if (curNode instanceof YangJavaNotification) {
return getRpcInterfaceDefinitionWhenItExtends(yangName, holder);
}
curNode = curNode.getNextSibling();
}
}
if (yangName.contains(SERVICE)) {
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName + SERVICE
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName
+ SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/* Provides class definition when RPC interface needs to extends any event.*/
private static String getRpcInterfaceDefinitionWhenItExtends(String yangName,
JavaExtendsListHolder holder) {
if (yangName.contains(SERVICE)) {
String[] strArray = yangName.split(SERVICE);
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
+ EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA
+ SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
+ EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE
+ yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE + NEW_LINE
+ EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
}
/**
......@@ -188,14 +262,9 @@ public final class ClassDefinitionGenerator {
* @param javaName file name
* @return definition
*/
private static String getEventDefinition(String javaName) {
private static String getEventDefinition(String javaName, String eventName) {
String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
+ javaName + ".Type, " + javaName;
if (classDef.length() < 5) {
throw new RuntimeException("Event class name is error");
}
classDef = classDef.substring(0, classDef.length() - 5);
classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ javaName + ".Type, " + eventName + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return classDef;
}
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
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.UtilConstants.ARRAY_LIST;
......@@ -78,18 +77,6 @@ public final class JavaCodeSnippetGen {
}
/**
* Returns based on the file type and the YANG name of the file, generate the class
* / interface definition start.
*
* @param genFileTypes type of file being generated
* @param yangName YANG name
* @return corresponding textual java code information
*/
public static String getJavaClassDefStart(int genFileTypes, String yangName) {
return generateClassDefinition(genFileTypes, yangName);
}
/**
* Returns the textual java code for attribute definition in class.
*
* @param javaAttributeTypePkg Package of the attribute type
......@@ -128,7 +115,7 @@ public final class JavaCodeSnippetGen {
* @param type attribute type
* @return list attribute string
*/
public static String getListAttribute(String type) {
private static String getListAttribute(String type) {
return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET;
}
......@@ -138,10 +125,9 @@ public final class JavaCodeSnippetGen {
* @return attribute of augmented info for generated impl file
*/
public static String getAugmentedInfoAttribute() {
return FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
+ getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST
+ DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ NEW_LINE;
+ DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
* to be extended by the generated java code.
*/
public class JavaExtendsListHolder {
/**
* Creates an instance of JavaExtendsListHolder.
*/
public JavaExtendsListHolder() {
setExtendedClassStore(new HashMap<>());
setExtendsList(new ArrayList<>());
}
private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore;
private List<JavaQualifiedTypeInfo> extendsList;
/**
* Returns extends list.
*
* @return extends list
*/
public Map<JavaQualifiedTypeInfo, Boolean> getExtendedClassStore() {
return extendedClassStore;
}
/**
* Sets extends list.
*
* @param extendsList list of classes need to be extended
*/
private void setExtendedClassStore(Map<JavaQualifiedTypeInfo, Boolean> extendedClass) {
this.extendedClassStore = extendedClass;
}
/**
* Adds to the extends list.
*
* @param info java file info
* @param node YANG node
*/
public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
if (!fileInfo.getPackage().equals(info.getPkgInfo())) {
JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
importData.addImportInfo(info);
/*true means import should be added*/
getExtendedClassStore().put(info, true);
}
getExtendedClassStore().put(info, false);
addToExtendsList(info);
}
/**
* Returns extends string for class.
*
* @param genFileType generated file type
* @param className class name
* @param isNotificationPresent if notification node is present
* @return extends string
*/
public String getExtendsString(int genFileType, String className, boolean isNotificationPresent) {
String extend = EXTEND + SPACE;
if (genFileType == GENERATE_SERVICE_AND_MANAGER && isNotificationPresent) {
extend = extend + LISTENER_REG + DIAMOND_OPEN_BRACKET + className + EVENT_STRING + COMMA + SPACE
+ className + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE;
} else {
for (JavaQualifiedTypeInfo info : getExtendsList()) {
if (info.getClassInfo().equals(className)) {
if (!getExtendedClassStore().get(info)) {
return extend + info.getClassInfo();
} else {
return extend + info.getPkgInfo() + PERIOD + info.getClassInfo();
}
}
}
}
return null;
}
/**
* Returns extends list.
*
* @return the extendsList
*/
public List<JavaQualifiedTypeInfo> getExtendsList() {
return extendsList;
}
/**
* Sets extends info list.
*
* @param classInfoList the extends List to set
*/
private void setExtendsList(List<JavaQualifiedTypeInfo> classInfoList) {
this.extendsList = classInfoList;
}
/**
* Adds extends info to list.
*
* @param classInfo class info
*/
private void addToExtendsList(JavaQualifiedTypeInfo classInfo) {
getExtendsList().add(classInfo);
}
}
......@@ -24,6 +24,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
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.javamodel.JavaCodeGeneratorInfo;
......@@ -74,8 +75,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
.isHasAugmentationExtended;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
......@@ -102,59 +102,10 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
*/
public final class JavaFileGenerator {
/**
* Flag to check whether generated interface file need to extends any class.
*/
private static boolean isExtendsList = false;
/**
* List of classes to be extended by generated interface file.
*/
private static List<String> extendsList = new ArrayList<>();
/**
* Creates an instance of java file generator.
*/
private JavaFileGenerator() {
}
/**
* Returns true if extends list is not empty.
*
* @return true or false
*/
public static boolean isExtendsList() {
return isExtendsList;
}
/**
* Sets the value of is extends list.
*
* @param isExtends true or false
*/
public static void setIsExtendsList(boolean isExtends) {
isExtendsList = isExtends;
}
/**
* Returns list of extended classes.
*
* @return list of extended classes
*/
public static List<String> getExtendsList() {
return extendsList;
}
/**
* Sets the list of extended classes.
*
* @param extendList list of extended classes
*/
public static void setExtendsList(List<String> extendList) {
extendsList = extendList;
}
/**
* Returns generated interface file for current node.
*
* @param file file
......@@ -171,9 +122,8 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path);
initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className);
if (isAttrPresent) {
/**
......@@ -343,9 +293,8 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
List<String> methods = new ArrayList<>();
......@@ -412,6 +361,17 @@ public final class JavaFileGenerator {
initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path);
List<String> methods = new ArrayList<>();
TempJavaCodeFragmentFiles javaCodeFragmentFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles();
boolean isAugmentationHolderExtended = isAugmentationHolderExtended(
javaCodeFragmentFiles.getBeanTempFiles().getJavaExtendsListHolder().getExtendsList());
/**
* Add attribute for augmented info's list.
*/
if (isAugmentationHolderExtended) {
insertDataIntoJavaFile(file, getAugmentedInfoAttribute());
}
if (isAttrPresent) {
/**
* Add attribute strings.
......@@ -426,12 +386,6 @@ public final class JavaFileGenerator {
+ " while impl class file generation");
}
/**
* Add attribute for augmented info's list.
*/
if (isHasAugmentationExtended(getExtendsList())) {
insertDataIntoJavaFile(file, getAugmentedInfoAttribute());
}
insertDataIntoJavaFile(file, NEW_LINE);
try {
/**
......@@ -471,12 +425,15 @@ public final class JavaFileGenerator {
insertDataIntoJavaFile(file, NEW_LINE);
}
try {
/**
* Constructor.
*/
methods.add(getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles())
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
String constructor = getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles());
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
......@@ -485,7 +442,7 @@ public final class JavaFileGenerator {
/**
* Add method for augment info's list.
*/
if (isHasAugmentationExtended(getExtendsList())) {
if (isAugmentationHolderExtended) {
methods.add(getAddAugmentInfoMethodImpl());
methods.add(getAugmentInfoListImpl());
methods.add(getRemoveAugmentationImpl());
......@@ -802,9 +759,7 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
List<String> methods = new ArrayList<>();
......@@ -853,16 +808,16 @@ public final class JavaFileGenerator {
* @param imports imports for file
* @throws IOException when fails to generate class file
*/
public static void generateEventFile(File file, YangNode curNode, List<String> imports)
throws IOException {
public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException {
YangNode parent = curNode.getParent();
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_EVENT_CLASS, imports, path);
String className =
getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName())
+ EVENT_STRING;
initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className);
insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName()));
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
}
......@@ -871,7 +826,7 @@ public final class JavaFileGenerator {
return "\n" +
" public enum Type {\n" +
" /**\n" +
" * " + eventClassname + "notification.\n" +
" * " + getCapitalCase(classname) + " notification.\n" +
" */\n" +
" " + classname.toUpperCase() + "_EVENT\n" +
" }\n" +
......@@ -880,9 +835,9 @@ public final class JavaFileGenerator {
" * Creates " + classname + " event with type and subject.\n" +
" *\n" +
" * @param type event type\n" +
" * @param subject subject interface\n" +
" * @param subject subject " + classname + "\n" +
" */\n" +
" public " + eventClassname + "(Type type, Interface subject) {\n" +
" public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
" super(type, subject);\n" +
" }\n" +
"\n" +
......@@ -890,10 +845,11 @@ public final class JavaFileGenerator {
" * Creates " + classname + " event with type, subject and time.\n" +
" *\n" +
" * @param type event type\n" +
" * @param subject subject interface\n" +
" * @param subject subject " + classname + "\n" +
" * @param time time of event\n" +
" */\n" +
" public " + eventClassname + "(Type type, Interface subject, long time) {\n" +
" public " + eventClassname + "(Type type, " + getCapitalCase(classname)
+ " subject, long time) {\n" +
" super(type, subject, time);\n" +
" }\n" +
"\n";
......@@ -909,10 +865,12 @@ public final class JavaFileGenerator {
*/
public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports)
throws IOException {
YangNode parent = curNode.getParent();
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_LISTENER_STRING;
String className =
getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName())
+ EVENT_LISTENER_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path);
......
......@@ -20,8 +20,10 @@ import java.io.File;
import java.io.IOException;
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 org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
......@@ -55,7 +57,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
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.JavaCodeSnippetGen.getJavaClassDefStart;
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.UtilConstants.FOUR_SPACE_INDENTATION;
......@@ -226,6 +228,27 @@ public final class JavaFileGeneratorUtils {
}
/**
* Initiates generation of file based on generated file type.
*
* @param file generated file
* @param type generated file type
* @param imports imports for the file
* @param curNode current YANG node
* @param className class name
* @throws IOException when fails to generate a file
*/
public static void initiateJavaFileGeneration(File file, int type, List<String> imports,
YangNode curNode, String className) throws IOException {
try {
file.createNewFile();
appendContents(file, type, imports, curNode, className);
} catch (IOException e) {
throw new IOException("Failed to create " + file.getName() + " class file.");
}
}
/**
* Appends all the contents into a generated java file.
*
* @param file generated file
......@@ -235,40 +258,76 @@ public final class JavaFileGeneratorUtils {
* @param importsList list of java imports.
* @throws IOException when fails to append contents
*/
private static void appendContents(File file, String fileName, int type, List<String> importsList,
String pkg)
private static void appendContents(File file, int type, List<String> importsList, YangNode curNode,
String className) throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
String pkgString = parsePackageString(path, importsList);
switch (type) {
case INTERFACE_MASK:
appendHeaderContents(file, pkgString, importsList);
write(file, type, INTERFACE, curNode, className);
break;
case GENERATE_SERVICE_AND_MANAGER:
appendHeaderContents(file, pkgString, importsList);
write(file, type, RPC_INTERFACE, curNode, className);
break;
case GENERATE_EVENT_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, type, EVENT, curNode, className);
break;
default:
break;
}
}
/**
* Appends all the contents into a generated java file.
*
* @param file generated file
* @param fileName generated file name
* @param type generated file type
* @param pkg generated file package
* @param importsList list of java imports.
* @throws IOException when fails to append contents
*/
private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg)
throws IOException {
String pkgString = parsePackageString(pkg, importsList);
if ((type & IMPL_CLASS_MASK) != 0) {
switch (type) {
case IMPL_CLASS_MASK:
write(file, fileName, type, IMPL_CLASS);
} else if ((type & BUILDER_INTERFACE_MASK) != 0) {
break;
case BUILDER_INTERFACE_MASK:
write(file, fileName, type, BUILDER_INTERFACE);
} else if ((type & GENERATE_TYPEDEF_CLASS) != 0) {
break;
case GENERATE_TYPEDEF_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, IMPL_CLASS);
} else if ((type & INTERFACE_MASK) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, INTERFACE);
} else if ((type & BUILDER_CLASS_MASK) != 0) {
break;
case BUILDER_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, BUILDER_CLASS);
} else if ((type & GENERATE_UNION_CLASS) != 0) {
break;
case GENERATE_UNION_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, IMPL_CLASS);
} else if ((type & GENERATE_ENUM_CLASS) != 0) {
break;
case GENERATE_ENUM_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, ENUM_CLASS);
} else if ((type & GENERATE_SERVICE_AND_MANAGER) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, RPC_INTERFACE);
} else if ((type & GENERATE_EVENT_CLASS) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, EVENT);
} else if ((type & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
break;
case GENERATE_EVENT_LISTENER_INTERFACE:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, EVENT_LISTENER);
break;
default:
break;
}
}
......@@ -333,8 +392,9 @@ public final class JavaFileGeneratorUtils {
* @param javaDocType java doc type
* @throws IOException when fails to write into a file
*/
private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName)
throws IOException {
if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
if (!fileName.contains(SERVICE)) {
insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false));
......@@ -344,7 +404,22 @@ public final class JavaFileGeneratorUtils {
} else {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
}
insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
}
/**
* Writes data to the specific generated file.
*
* @param file generated file
* @param fileName file name
* @param genType generated file type
* @param javaDocType java doc type
* @throws IOException when fails to write into a file
*/
private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
throws IOException {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
/**
......@@ -354,8 +429,8 @@ public final class JavaFileGeneratorUtils {
* @return enum's attribute
*/
public static String getEnumsValueAttribute(String className) {
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) + SEMI_COLAN
+ NEW_LINE;
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
+ SEMI_COLAN + NEW_LINE;
}
}
......
......@@ -19,7 +19,11 @@ 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.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 static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
......@@ -29,11 +33,13 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
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.BOOLEAN_DATA_TYPE;
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.CASE;
import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
......@@ -64,6 +70,7 @@ 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.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
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;
......@@ -83,6 +90,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
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.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
......@@ -241,11 +249,12 @@ public final class MethodsGenerator {
* @return getter for attribute
*/
public static String getGetter(String type, String name, int generatedJavaFiles) {
String ret = parseTypeForGetter(type);
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
......@@ -255,6 +264,21 @@ public final class MethodsGenerator {
}
/*Provides string to return for type.*/
private static String parseTypeForGetter(String type) {
switch (type) {
case BYTE:
case INT:
case SHORT:
case LONG:
return "0";
case BOOLEAN_DATA_TYPE:
return FALSE;
default:
return null;
}
}
/**
* Returns the setter method strings for class file.
*
......@@ -524,8 +548,7 @@ public final class MethodsGenerator {
outputName = getCapitalCase(outputName);
}
String method =
getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
+ OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
if (!outputName.contentEquals(VOID)) {
......@@ -805,22 +828,6 @@ public final class MethodsGenerator {
}
/**
* Returns implementation of add augmentation method of HasAugmentation class.
*
* @return implementation of add augmentation method of HasAugmentation class
*/
public static String getAddAugmentInfoMethodImpl() {
String method = FOUR_SPACE_INDENTATION;
method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING
+ AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return method;
}
/**
* Returns of method's string and java doc for special type.
*
* @param attr attribute info
......@@ -884,9 +891,25 @@ public final class MethodsGenerator {
}
/**
* Returns implementation of get augment info list method of HasAugmentation class.
* Returns implementation of add augmentation method of AugmentationHolder class.
*
* @return implementation of get augment info list method of HasAugmentation class
* @return implementation of add augmentation method of AugmentationHolder class
*/
public static String getAddAugmentInfoMethodImpl() {
String method = FOUR_SPACE_INDENTATION;
method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING
+ AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return method;
}
/**
* Returns implementation of get augment info list method of AugmentationHolder class.
*
* @return implementation of get augment info list method of AugmentationHolder class
*/
public static String getAugmentInfoListImpl() {
......@@ -900,9 +923,9 @@ public final class MethodsGenerator {
}
/**
* Returns implementation of remove augmentation method of HasAugmentation class.
* Returns implementation of remove augmentation method of AugmentationHolder class.
*
* @return implementation of remove augmentation method of HasAugmentation class
* @return implementation of remove augmentation method of AugmentationHolder class
*/
public static String getRemoveAugmentationImpl() {
String method = FOUR_SPACE_INDENTATION;
......@@ -927,6 +950,36 @@ 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
......
......@@ -21,18 +21,38 @@ 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.JavaImportDataContainer;
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 java.util.Collections.sort;
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport;
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport;
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForArrayList;
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForList;
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.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.HAS_AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
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.NEW;
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.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
......@@ -47,21 +67,16 @@ public final class TempJavaCodeFragmentFilesUtils {
}
/**
* Adds import for HasAugmentation class.
* Adds import for AugmentationHolders class.
*
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
* @return import for HasAugmentation class
*/
public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports,
boolean operation) {
if (curNode instanceof JavaImportDataContainer) {
String thisImport = getHasAugmentationImport();
public static void addAugmentationHoldersImport(YangNode curNode, List<String> imports, boolean operation) {
String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentationHolderImport();
performOperationOnImports(imports, thisImport, operation);
}
return imports;
}
/**
* Adds import for AugmentedInfo class.
......@@ -69,14 +84,113 @@ public final class TempJavaCodeFragmentFilesUtils {
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
* @return import for AugmentedInfo class
*/
public static List<String> addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
if (curNode instanceof JavaImportDataContainer) {
String thisImport = getAugmentedInfoImport();
public static void addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentedInfoImport();
performOperationOnImports(imports, thisImport, operation);
}
return imports;
/**
* Returns temp java fragment.
*
* @param curNode current YANG node
* @return temp java fragments
*/
public static TempJavaFragmentFiles getTempJavaFragement(YangNode curNode) {
TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles();
if (container.getBeanTempFiles() != null) {
return container.getBeanTempFiles();
}
if (container.getEventTempFiles() != null) {
return container.getEventTempFiles();
}
if (container.getEventListenerTempFiles() != null) {
return container.getEventListenerTempFiles();
}
if (container.getServiceTempFiles() != null) {
return container.getServiceTempFiles();
}
return null;
}
/**
* 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;
}
/**
......@@ -85,12 +199,10 @@ public final class TempJavaCodeFragmentFilesUtils {
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
* @return import for HasAugmentation class
*/
public static List<String> addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
if (curNode instanceof JavaImportDataContainer) {
String arrayListImport = getImportForArrayList();
String listImport = getImportForList();
public static void addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
String arrayListImport = getTempJavaFragement(curNode).getJavaImportData().getImportForArrayList();
String listImport = getTempJavaFragement(curNode).getJavaImportData().getImportForList();
performOperationOnImports(imports, arrayListImport, operation);
if (!imports.contains(listImport)) {
/**
......@@ -101,7 +213,24 @@ public final class TempJavaCodeFragmentFilesUtils {
}
}
return imports;
/**
* Adds listener's imports.
*
* @param curNode currentYangNode.
* @param imports import list
* @param operation add or remove
* @param classInfo class info to be added to import list
*/
public static void addListnersImport(YangNode curNode, List<String> imports, boolean operation,
String classInfo) {
String thisImport = "";
if (classInfo.equals(LISTENER_SERVICE)) {
thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerServiceImport();
performOperationOnImports(imports, thisImport, operation);
} else {
thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerRegistryImport();
performOperationOnImports(imports, thisImport, operation);
}
}
/**
......@@ -124,29 +253,16 @@ public final class TempJavaCodeFragmentFilesUtils {
}
/**
* Prepares java file generator for extends list.
*
* @param extendsList list of classes need to be extended
*/
public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) {
if (extendsList != null && !extendsList.isEmpty()) {
JavaFileGenerator.setExtendsList(extendsList);
JavaFileGenerator.setIsExtendsList(true);
} else {
JavaFileGenerator.getExtendsList().clear();
JavaFileGenerator.setIsExtendsList(false);
}
}
/**
* Returns true if HasAugmentation class needs to be extended.
* Returns true if AugmentationHolder class needs to be extended.
*
* @param extendsList list of classes need to be extended
* @return true or false
*/
public static boolean isHasAugmentationExtended(List<String> extendsList) {
return extendsList != null && extendsList.contains(HAS_AUGMENTATION);
public static boolean isAugmentationHolderExtended(List<JavaQualifiedTypeInfo> extendsList) {
for (JavaQualifiedTypeInfo info : extendsList) {
return info.getClassInfo().equals(AUGMENTATION_HOLDER);
}
return false;
}
/**
......@@ -155,8 +271,11 @@ public final class TempJavaCodeFragmentFilesUtils {
* @param extendsList list of classes need to be extended
* @return true or false
*/
public static boolean isAugmentedInfoExtended(List<String> extendsList) {
return extendsList != null && extendsList.contains(AUGMENTED_INFO);
public static boolean isAugmentedInfoExtended(List<JavaQualifiedTypeInfo> extendsList) {
for (JavaQualifiedTypeInfo info : extendsList) {
return info.getClassInfo().equals(AUGMENTED_INFO);
}
return false;
}
/**
......@@ -190,7 +309,7 @@ public final class TempJavaCodeFragmentFilesUtils {
JavaQualifiedTypeInfo qualifiedTypeInfo) {
YangNode parent = curNode.getParent();
String parentsClassInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
String childsClassInfo = qualifiedTypeInfo.getClassInfo();
if (childsClassInfo.equals(parentsClassInfo)) {
return true;
......
......@@ -20,18 +20,15 @@ import java.io.IOException;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentationHolder;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
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.javamodel.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
......@@ -40,12 +37,11 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChil
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.AUGMENTATION_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
/**
* Represents utility class for YANG java model.
......@@ -118,14 +114,14 @@ public final class YangJavaModelUtils {
YangPluginConfig yangPluginConfig)
throws IOException {
if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
/**
/*
* Module / sub module node code generation.
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
/**
/*
* Container
* Case
* Grouping
......@@ -138,14 +134,14 @@ public final class YangJavaModelUtils {
.getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
/**
/*
* Typedef
* Union
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
/**
/*
* Enumeration
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
......@@ -189,12 +185,12 @@ public final class YangJavaModelUtils {
throw new TranslatorException("Invalid node for translation");
}
/**
/*
* Generate the Java files corresponding to the current node.
*/
generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin);
/**
/*
* Update the current nodes info in its parent nodes generated files.
*/
addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
......@@ -216,34 +212,38 @@ public final class YangJavaModelUtils {
generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
/**
/*
* For augmentation of nodes.
*/
if (javaCodeGeneratorInfo instanceof YangContainer
|| javaCodeGeneratorInfo instanceof YangCase
|| javaCodeGeneratorInfo instanceof YangChoice
|| javaCodeGeneratorInfo instanceof YangInput
|| javaCodeGeneratorInfo instanceof YangList
|| javaCodeGeneratorInfo instanceof YangNotification
|| javaCodeGeneratorInfo instanceof YangOutput) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(HAS_AUGMENTATION);
if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) {
JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo();
augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER);
augmentationHoldersInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(augmentationHoldersInfo, (YangNode) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangAugment) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO);
JavaQualifiedTypeInfo augmentedInfo = new JavaQualifiedTypeInfo();
augmentedInfo.setClassInfo(AUGMENTED_INFO);
augmentedInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo);
}
if (javaCodeGeneratorInfo instanceof YangCase) {
YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
String curNodeName = ((YangCase) javaCodeGeneratorInfo).getName();
if (!parent.getName().equals(curNodeName)) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(getCapitalCase(getCamelCase(
parent.getName(), null)));
JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
String parentName = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
parentsInfo.setClassInfo(parentName);
parentsInfo.setPkgInfo(parentPkg);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
.addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo);
} else {
String parentPackage = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
String caseExtendInfo = parentPackage + PERIOD + parent.getName();
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(caseExtendInfo);
}
}
}
......
......@@ -242,6 +242,21 @@ public final class UtilConstants {
public static final String SPACE = " ";
/**
* Static attribute for ListenerRegistry.
*/
public static final String LISTENER_REG = "ListenerRegistry";
/**
* Static attribute for ListenerService.
*/
public static final String LISTENER_SERVICE = "ListenerService";
/**
* Static attribute for listener package.
*/
public static final String LISTENER_PKG = "org.onosproject.event";
/**
* Static attribute for input string.
*/
public static final String INPUT = "input";
......@@ -862,14 +877,15 @@ public final class UtilConstants {
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
/**
* Static attribute for HasAugmentation class import package.
* Static attribute for AugmentationHolder class import package.
*/
public static final String HAS_AUGMENTATION_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava";
public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG =
"org.onosproject.yangutils.translator.tojava";
/**
* Static attribute for HasAugmentation class import class.
* Static attribute for AugmentationHolder class import class.
*/
public static final String HAS_AUGMENTATION_CLASS_IMPORT_CLASS = "HasAugmentation;\n";
public static final String AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS = "AugmentationHolder;\n";
/**
* Static attribute for AugmentedInfo class import package.
......@@ -887,9 +903,9 @@ public final class UtilConstants {
public static final String AUGMENTATION = "Augmentation";
/**
* Static attribute for HasAugmentation class.
* Static attribute for AugmentationHolder class.
*/
public static final String HAS_AUGMENTATION = "HasAugmentation";
public static final String AUGMENTATION_HOLDER = "AugmentationHolder";
/**
* Static attribute for AugmentedInfo class.
......@@ -897,6 +913,10 @@ public final class UtilConstants {
public static final String AUGMENTED_INFO = "AugmentedInfo";
/**
* Static attribute for augmentable.
*/
public static final String AUGMENTABLE = "Augmentable";
/**
* Static attribute for list.
*/
public static final String LIST = "List";
......
......@@ -158,7 +158,7 @@ public final class YangIoUtils {
}
for (File dir : store) {
dir.delete();
FileUtils.deleteDirectory(dir);
}
}
......
......@@ -21,15 +21,15 @@ import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.getAugmentJavaFileNameList;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.clearOccurrenceCount;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.createValidNameForAugment;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getAugmentJavaFileNameList;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.updateNameWhenHasMultipleOuccrrence;
/**
* Unit test case for augment java file name generator utility.
* Unit test case for augment listener utility.
*/
public class AugmentJavaFileNameGenUtilTest {
public class AugmentListnerUtilTest {
private static final String TEST1 = "test1Node";
private static final String PARENT_PREFIX = "if";
......
......@@ -44,7 +44,7 @@ public final class ChoiceCaseTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
generateJavaCode(node, yangPluginConfig);
generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator");
deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
}
......
......@@ -28,7 +28,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
/**
......@@ -55,7 +54,8 @@ public final class ClassDefinitionGeneratorTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
......@@ -98,8 +98,7 @@ public final class ClassDefinitionGeneratorTest {
*/
@Test
public void generateinterfaceDefinitionTest() {
String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME);
assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF)));
// TODO: need to add this test case.
}
/**
......
......@@ -46,7 +46,7 @@ public final class EnumTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
generateJavaCode(node, yangPluginConfig);
generateJavaCode(node, yangPluginConfig, "EnumTranslator");
deleteDirectory(userDir + "/target/EnumTestGenFile/");
}
......
......@@ -25,24 +25,18 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getListAttribute;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
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.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
......@@ -54,7 +48,6 @@ public class JavaCodeSnippetGenTest {
private static final String PKG_INFO = "org.onosproject.unittest";
private static final String CLASS_INFO = "JavaCodeSnippetGenTest";
private static final int FILE_GEN_TYPE = INTERFACE_MASK;
private static final String YANG_NAME = "Test";
/**
......@@ -68,7 +61,8 @@ public class JavaCodeSnippetGenTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class };
......@@ -94,26 +88,6 @@ public class JavaCodeSnippetGenTest {
}
/**
* Unit test case for java class definition start.
*/
@Test
public void testForJavaClassDefStart() {
String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME);
assertThat(true, is(classDef
.equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
}
/**
* Unit test case for list attribute.
*/
@Test
public void testForListAttribute() {
String listAttribute = getListAttribute(STRING_DATA_TYPE);
assertThat(true,
is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET)));
}
/**
* Unit test case for java class interface definition close.
*/
@Test
......
......@@ -46,7 +46,7 @@ public final class NotificationTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
generateJavaCode(node, yangPluginConfig);
generateJavaCode(node, yangPluginConfig, "NotificationTest");
deleteDirectory(userDir + "/target/NotificationTest/");
}
......
......@@ -46,7 +46,7 @@ public final class RpcTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
generateJavaCode(node, yangPluginConfig);
generateJavaCode(node, yangPluginConfig, "RpcTranslator");
deleteDirectory(userDir + "/target/RpcTestGenFile/");
}
......
......@@ -46,7 +46,7 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig);
generateJavaCode(node, yangPluginConfig, "UnionTranslator");
deleteDirectory(userDir + "/target/UnionTestGenFile/");
}
......