Bharat saraswal
Committed by Patrick Liu

[ONOS-4829] Augmented data method generator implmentation.

Change-Id: I0cb68dd10a748e5b66eec0b832574f408a23ba5c
Showing 66 changed files with 861 additions and 373 deletions
......@@ -15,8 +15,10 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
......@@ -128,9 +130,13 @@ public class YangAugment
private YangNode augmentedNode;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef
* is added to uses/type but it's not resolved value of enum should be
* All resolved nodes in given xPath.
*/
private Map<YangAtomicPath, YangNode> resolveNodeInPath;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED", if not enum value is "UNRESOLVED", in case
* reference of grouping/typedef is added to uses/type but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
......@@ -150,6 +156,7 @@ public class YangAugment
*/
public YangAugment() {
super(YangNodeType.AUGMENT_NODE);
resolveNodeInPath = new HashMap<>();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
......@@ -411,6 +418,11 @@ public class YangAugment
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
......@@ -419,11 +431,6 @@ public class YangAugment
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
......@@ -438,4 +445,22 @@ public class YangAugment
public void resolve() throws DataModelException {
// Resolving of target node is being done in XPathLinker.
}
/**
* Returns all resolved node in path.
*
* @return all resolved node in path
*/
public Map<YangAtomicPath, YangNode> getResolveNodeInPath() {
return resolveNodeInPath;
}
/**
* Sets all resolved node in path.
*
* @param resolveNodeInPath all resolved node in path
*/
public void setResolveNodeInPath(Map<YangAtomicPath, YangNode> resolveNodeInPath) {
this.resolveNodeInPath = resolveNodeInPath;
}
}
......
......@@ -144,7 +144,6 @@ public class YangInput
listOfLeaf = leafsList;
}
@Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
......
......@@ -158,7 +158,6 @@ public class YangOutput
this.listOfLeafList = listOfLeafList;
}
@Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
......
......@@ -349,6 +349,7 @@ public final class DataModelUtils {
* type info needs to be updated to the cloned new type node.
*
* @param leavesHolder cloned leaves holder, for whom the leaves reference needs to be updated
* @throws DataModelException when fails to do data model operations
*/
public static void updateClonedLeavesUnionEnumRef(YangLeavesHolder leavesHolder) throws DataModelException {
List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.linker.impl;
/**
* Enum for prefix resolver type when augment has come in path.
*/
public enum PrefixResolverType {
/**
* When prefix changes from inter file to intra file.
*/
INTER_TO_INTRA,
/**
* When prefix changes from intra file to inter file.
*/
INTRA_TO_INTER,
/**
* When prefix changes from one inter file to other inter file.
*/
INTER_TO_INTER,
/**
* When no prefix change occurres.
*/
NO_PREFIX_CHANGE_FOR_INTRA,
/**
* When no prefix change occurres.
*/
NO_PREFIX_CHANGE_FOR_INTER
}
......@@ -21,6 +21,7 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
......@@ -36,8 +37,7 @@ public final class YangLinkerUtils {
}
/**
* Detects collision between target nodes leaf/leaf-list or child node with
* augmented leaf/leaf-list or child node.
* Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node.
*
* @param targetNode target node
* @param augment augment node
......@@ -46,6 +46,14 @@ public final class YangLinkerUtils {
YangNode targetNodesChild = targetNode.getChild();
YangNode augmentsChild = augment.getChild();
YangLeavesHolder augmentsLeavesHolder = augment;
if (targetNode instanceof YangChoice) {
if (augmentsLeavesHolder.getListOfLeaf() != null
|| augmentsLeavesHolder.getListOfLeafList() != null) {
throw new LinkerException("target node " + targetNode.getName()
+ "is a instance of choice. it can " +
"only be augmented with leaf using a case node.");
}
} else {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
YangNode parent = targetNode;
......@@ -93,10 +101,11 @@ public final class YangLinkerUtils {
}
}
}
}
/**
* Detects collision between target nodes and its all leaf/leaf-list or child node with
* augmented leaf/leaf-list or child node.
* Detects collision between target nodes and its all leaf/leaf-list or child node with augmented leaf/leaf-list or
* child node.
*
* @param targetNode target node
* @param augment augment node
......
......@@ -32,9 +32,9 @@ import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangFeatureHolder;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangInput;
......@@ -73,16 +73,16 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOL
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
/**
* Represents implementation of resolution object which will be resolved by
......@@ -128,7 +128,6 @@ public class YangResolutionInfoImpl<T>
*/
@SuppressWarnings("unused")
private YangResolutionInfoImpl() {
}
/**
......@@ -153,7 +152,6 @@ public class YangResolutionInfoImpl<T>
throws DataModelException {
setCurReferenceResolver(dataModelRootNode);
/**
* Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or
* YANG leafref or YANG base or YANG identityref.
......@@ -173,7 +171,6 @@ public class YangResolutionInfoImpl<T>
throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
"type/uses/if-feature/leafref/base/identityref");
}
// Push the initial entity to resolve in stack.
addInPartialResolvedStack(getEntityToResolveInfo());
......@@ -191,7 +188,6 @@ public class YangResolutionInfoImpl<T>
throws DataModelException {
while (getPartialResolvedStack().size() != 0) {
/**
* Current node to resolve, it can be a YANG type or YANG uses or
* YANG if-feature or YANG leafref or YANG base or YANG identityref.
......@@ -1479,6 +1475,7 @@ public class YangResolutionInfoImpl<T>
detectCollisionForAugmentedNode(targetNode, augment);
((YangAugmentableNode) targetNode).addAugmentation(augment);
augment.setAugmentedNode(targetNode);
augment.setResolveNodeInPath(xPathLinker.getResolvedNodes());
Resolvable resolvable = (Resolvable) entityToResolve;
resolvable.setResolvableStatus(RESOLVED);
} else {
......
......@@ -21,11 +21,14 @@ import java.util.SortedSet;
import java.util.TreeSet;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
......@@ -33,6 +36,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IM
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
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.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......@@ -248,4 +252,31 @@ public class JavaImportData {
public String getEventListenerImport() {
return IMPORT + ONOS_EVENT_PKG + PERIOD + EVENT_LISTENER + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for map class.
*
* @return import string for map class
*/
public String getMapImport() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + MAP + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for hash map class.
*
* @return import string for hash map class
*/
public String getHashMapImport() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + HASH_MAP + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for hash map class.
*
* @return import string for hash map class
*/
public String getYangAugmentedInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
}
......
......@@ -189,8 +189,6 @@ public class TempJavaCodeFragmentFiles {
if (fileType == GENERATE_ENUM_CLASS) {
getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
}
freeTemporaryResources(false);
}
/**
......
......@@ -332,7 +332,7 @@ public class TempJavaTypeFragmentFiles
* Creates type def class file.
*/
if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(curNode, imports);
addImportsToStringAndHasCodeMethods(imports);
setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
}
......@@ -340,7 +340,7 @@ public class TempJavaTypeFragmentFiles
* Creates type class file.
*/
if ((fileType & GENERATE_UNION_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(curNode, imports);
addImportsToStringAndHasCodeMethods(imports);
setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports);
}
......
......@@ -34,7 +34,7 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
......
......@@ -30,7 +30,8 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
......@@ -154,10 +155,11 @@ public class YangJavaAugment
*/
public String getAugmentClassName() {
YangNodeIdentifier nodeId = getTargetNode().get(getTargetNode().size() - 1).getNodeIdentifier();
String name = getCapitalCase(getCamelCase(nodeId.getName(), null));
if (nodeId.getPrefix() != null) {
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + getCapitalCase(nodeId.getName());
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + name;
} else {
return AUGMENTED + getCapitalCase(nodeId.getName());
return AUGMENTED + name;
}
}
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents case information extended to support java code generation.
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents choice information extended to support java code generation.
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents container information extended to support java code generation.
......
......@@ -27,7 +27,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents YANG java enumeration information extended to support java code generation.
......
......@@ -31,7 +31,7 @@ import java.util.List;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
......
......@@ -27,7 +27,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents input information extended to support java code generation.
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents YANG list information extended to support java code generation.
......
......@@ -32,10 +32,11 @@ import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -71,7 +72,7 @@ public class YangJavaModule
super();
setJavaFileInfo(new JavaFileInfo());
setNotificationNodes(new ArrayList<>());
int gentype = GENERATE_SERVICE_AND_MANAGER;
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
......@@ -158,7 +159,10 @@ public class YangJavaModule
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
......
......@@ -28,12 +28,13 @@ 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.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
......@@ -143,22 +144,23 @@ public class YangJavaNotification
/*Adds current notification info to the extends list so its parents service*/
private void addNotificationToExtendsList() {
YangNode parent = getParent();
JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) parent)
TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parent)
.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().getJavaExtendsListHolder();
.getServiceTempFiles();
JavaExtendsListHolder holder = tempJavaServiceFragmentFiles.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);
holder.addToExtendsList(event, parent, tempJavaServiceFragmentFiles);
JavaQualifiedTypeInfo eventListener = new JavaQualifiedTypeInfo();
eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING);
eventListener.setPkgInfo(getJavaFileInfo().getPackage());
holder.addToExtendsList(eventListener, parent);
holder.addToExtendsList(eventListener, parent, tempJavaServiceFragmentFiles);
}
......
......@@ -27,7 +27,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents output information extended to support java code generation.
......
......@@ -39,7 +39,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParent
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
......
......@@ -34,10 +34,11 @@ import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -72,7 +73,7 @@ public class YangJavaSubModule
public YangJavaSubModule() {
super();
setJavaFileInfo(new JavaFileInfo());
int gentype = GENERATE_SERVICE_AND_MANAGER;
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
......@@ -170,6 +171,8 @@ public class YangJavaSubModule
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents type define information extended to support java code generation.
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents union information extended to support java code generation.
......
......@@ -282,7 +282,7 @@ public final class ClassDefinitionGenerator {
curNode = curNode.getChild();
while (curNode != null) {
if (curNode instanceof YangNotification) {
return getRpcInterfaceDefinitionWhenItExtends(yangName, holder);
return getRpcInterfaceDefinitionWhenItExtends(yangName);
}
curNode = curNode.getNextSibling();
}
......@@ -295,8 +295,7 @@ public final class ClassDefinitionGenerator {
}
/* Provides class definition when RPC interface needs to extends any event.*/
private static String getRpcInterfaceDefinitionWhenItExtends(String yangName,
JavaExtendsListHolder holder) {
private static String getRpcInterfaceDefinitionWhenItExtends(String yangName) {
if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
String[] strArray = yangName.split(SERVICE);
......
......@@ -19,14 +19,14 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
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.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
......@@ -38,6 +38,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
......@@ -45,18 +46,22 @@ import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
......@@ -221,11 +226,13 @@ public final class JavaCodeSnippetGen {
public static void addListenersImport(YangNode curNode, List<String> imports, boolean operation,
String classInfo) {
String thisImport = "";
TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
if (classInfo.equals(LISTENER_SERVICE)) {
thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerServiceImport();
thisImport = tempJavaServiceFragmentFiles.getJavaImportData().getListenerServiceImport();
performOperationOnImports(imports, thisImport, operation);
} else {
thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerRegistryImport();
thisImport = tempJavaServiceFragmentFiles.getJavaImportData().getListenerRegistryImport();
performOperationOnImports(imports, thisImport, operation);
}
}
......@@ -250,25 +257,6 @@ public final class JavaCodeSnippetGen {
}
/**
* Returns temp java fragment.
*
* @param curNode current YANG node
* @return temp java fragments
*/
public static TempJavaFragmentFiles getTempJavaFragment(YangNode curNode) {
TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles();
if (container.getBeanTempFiles() != null) {
return container.getBeanTempFiles();
}
if (container.getServiceTempFiles() != null) {
return container.getServiceTempFiles();
}
return null;
}
/**
* Returns integer attribute for enum's class to get the values.
*
* @param className enum's class name
......@@ -285,7 +273,20 @@ public final class JavaCodeSnippetGen {
* @return component string
*/
public static String addComponentString() {
return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE
return NEW_LINE + COMPONENT_ANNOTATION + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
}
/**
* Returns attribute for augmentation.
*
* @return attribute for augmentation
*/
public static String addAugmentationAttribute() {
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING
+ DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO
+ DIAMOND_CLOSE_BRACKET + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL + SPACE +
NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN;
}
}
......
......@@ -26,9 +26,9 @@ 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 org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getTempJavaFragment;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
......@@ -36,6 +36,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetG
*/
public class JavaExtendsListHolder {
private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore;
private List<JavaQualifiedTypeInfo> extendsList;
/**
* Creates an instance of JavaExtendsListHolder.
*/
......@@ -44,9 +47,6 @@ public class JavaExtendsListHolder {
setExtendsList(new ArrayList<>());
}
private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore;
private List<JavaQualifiedTypeInfo> extendsList;
/**
* Returns extends list.
*
......@@ -70,11 +70,13 @@ public class JavaExtendsListHolder {
*
* @param info java file info
* @param node YANG node
* @param tempJavaFragmentFiles temp java fragment files
*/
public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node,
TempJavaFragmentFiles tempJavaFragmentFiles) {
JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
JavaImportData importData = getTempJavaFragment(node).getJavaImportData();
JavaImportData importData = tempJavaFragmentFiles.getJavaImportData();
boolean qualified = importData.addImportInfo(info,
getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
......
......@@ -22,7 +22,9 @@ import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
......@@ -63,12 +65,19 @@ 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.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedNodesConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForManager;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod;
......@@ -77,12 +86,16 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
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.CLOSE_PARENTHESIS;
......@@ -320,12 +333,10 @@ public final class JavaFileGenerator {
* @param file file
* @param imports imports for the file
* @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @return builder class file
* @throws IOException when fails to write in file
*/
public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode,
boolean isAttrPresent)
public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
......@@ -341,25 +352,26 @@ public final class JavaFileGenerator {
methods.add(addActivateMethod());
methods.add(addDeActivateMethod());
TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false,
tempJavaServiceFragmentFiles);
try {
if (isAttrPresent) {
/**
* Getter methods.
*/
methods.add(
getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path));
methods.add(getOverRideString() +
getGetterForClass(rootAttribute, GENERATE_SERVICE_AND_MANAGER) + NEW_LINE);
/**
* Setter methods.
*/
methods.add(
getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path)
methods.add(getOverRideString() +
getSetterForClass(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER)
+ NEW_LINE);
}
methods.add(getAugmentsDataMethodForManager(curNode) + NEW_LINE);
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
......@@ -410,7 +422,9 @@ public final class JavaFileGenerator {
if (curNode instanceof YangAugment) {
isAugmentNode = true;
}
if (curNode instanceof YangAugmentableNode) {
insertDataIntoJavaFile(file, addAugmentationAttribute());
}
if (isAttrPresent) {
/**
* Add attribute strings.
......@@ -483,6 +497,11 @@ public final class JavaFileGenerator {
+ " while impl class file generation");
}
if (curNode instanceof YangAugmentableNode) {
methods.add(getAddAugmentInfoMethodImpl());
methods.add(getAugmentInfoImpl());
}
/**
* Add methods in impl class.
*/
......@@ -796,38 +815,38 @@ public final class JavaFileGenerator {
* @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @param isAttributePresent is attribute present
* @return rpc class file
* @throws IOException when fails to generate class file
*/
public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports,
boolean isAttributePresent)
public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
List<String> methods = new ArrayList<>();
JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false,
tempJavaServiceFragmentFiles);
try {
if (isAttributePresent) {
/**
* Getter methods.
*/
methods.add(getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles(), path));
methods.add(getGetterString(rootAttribute, GENERATE_SERVICE_AND_MANAGER,
javaFileInfo.getPluginConfig()) + NEW_LINE);
/**
* Setter methods.
*/
methods.add(getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles(), path));
}
methods.add(getSetterString(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER,
javaFileInfo.getPluginConfig()) + NEW_LINE);
methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE);
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
......
......@@ -97,11 +97,6 @@ public final class UtilConstants {
public static final String JAVA_DOC_RETURN = " * @return ";
/**
* JavaDocs's throw annotation.
*/
public static final String JAVA_DOC_THROWS = " * @throws ";
/**
* JavaDocs's description for setter method.
*/
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
......@@ -307,11 +302,6 @@ public final class UtilConstants {
public static final String IDENTITYREF = "identityref";
/**
* Static attribute for instance identifier string.
*/
public static final String INSTANCE_IDENTIFIER = "instance-identifier";
/**
* Static attribute for output variable of rpc.
*/
public static final String RPC_INPUT_VAR_NAME = "inputVar";
......@@ -332,16 +322,6 @@ public final class UtilConstants {
public static final String ADD = "+";
/**
* Static attribute for asterisk.
*/
public static final String ASTERISK = "*";
/**
* Static attribute for at.
*/
public static final String AT = "@";
/**
* Static attribute for quotes.
*/
public static final String QUOTES = "\"";
......@@ -357,6 +337,21 @@ public final class UtilConstants {
public static final String COMMA = ",";
/**
* Static attribute for class.
*/
public static final String CLASS_STRING = "Class";
/**
* Static attribute for put.
*/
public static final String PUT = "put";
/**
* Static attribute for get.
*/
public static final String GET = "get";
/**
* Static attribute for slash character.
*/
public static final char CHAR_OF_SLASH = '/';
......@@ -432,11 +427,6 @@ public final class UtilConstants {
public static final String VALUE = "value";
/**
* Static attribute for enumValue syntax.
*/
public static final String ENUM_VALUE = "enumValue";
/**
* Static attribute for suffix s.
*/
public static final String SUFFIX_S = "s";
......@@ -447,16 +437,6 @@ public final class UtilConstants {
public static final String IF = "if";
/**
* Static attribute for for.
*/
public static final String FOR = "for";
/**
* Static attribute for while.
*/
public static final String WHILE = "while";
/**
* Static attribute for of.
*/
public static final String OF = "of";
......@@ -532,11 +512,6 @@ public final class UtilConstants {
public static final String OPEN_PARENTHESIS = "(";
/**
* Static attribute for clear syntax.
*/
public static final String CLEAR = "clear";
/**
* Static attribute for switch syntax.
*/
public static final String SWITCH = "switch";
......@@ -592,11 +567,6 @@ public final class UtilConstants {
public static final String FOUR_SPACE_INDENTATION = " ";
/**
* Static attribute for not syntax.
*/
public static final String NOT = "!";
/**
* Static attribute for try syntax.
*/
public static final String TRY = "try";
......@@ -667,11 +637,6 @@ public final class UtilConstants {
public static final String ABSTRACT = "abstract";
/**
* Static attribute for protected modifier.
*/
public static final String PROTECTED = "protected";
/**
* Void java type.
*/
public static final String VOID = "void";
......@@ -732,11 +697,6 @@ public final class UtilConstants {
public static final String LONG = "long";
/**
* Float java built in type.
*/
public static final String FLOAT = "float";
/**
* Double java built in type.
*/
public static final String DOUBLE = "double";
......@@ -767,14 +727,9 @@ public final class UtilConstants {
public static final String LONG_WRAPPER = "Long";
/**
* YangUint64 java built in wrapper type.
*/
public static final String YANG_UINT64 = "YangUint64";
/**
* Double java built in wrapper type.
* Static varibale for question mark.
*/
public static final String DOUBLE_WRAPPER = "Double";
public static final String QUESTION_MARK = "?";
/**
* List of keywords in java, this is used for checking if the input does not contain these keywords.
......@@ -977,11 +932,22 @@ public final class UtilConstants {
public static final String OVERRIDE = "@Override";
/**
* Static attribute for new line.
* Static attribute for collections.
*/
public static final String COLLECTION_IMPORTS = "java.util";
/**
* Static attribute for map.
*/
public static final String MAP = "Map";
/**
* Static attribute for hash map.
*/
public static final String HASH_MAP = "HashMap";
/**
* Static attribute for more object import package.
*/
public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG = "com.google.common.base";
......@@ -1007,25 +973,14 @@ public final class UtilConstants {
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
/**
* Static attribute for AugmentationHolder class import package.
*/
public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG =
"org.onosproject.yangutils.utils";
/**
* Static attribute for AugmentationHolder class import class.
*/
public static final String AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS = "AugmentationHolder;\n";
/**
* Static attribute for AugmentedInfo class import package.
*/
public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.utils";
public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.datamodel";
/**
* Static attribute for AugmentedInfo class import class.
*/
public static final String AUGMENTED_INFO_CLASS_IMPORT_CLASS = "AugmentedInfo;\n";
public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS = "YangAugmentedInfo;\n";
/**
* Static attribute for augmentation class.
......@@ -1033,19 +988,14 @@ public final class UtilConstants {
public static final String AUGMENTATION = "Augmentation";
/**
* Static attribute for AugmentationHolder class.
*/
public static final String AUGMENTATION_HOLDER = "AugmentationHolder";
/**
* Static attribute for AugmentedInfo class.
*/
public static final String AUGMENTED_INFO = "AugmentedInfo";
public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
/**
* Static attribute for augmentable.
* Static attribute for augmented.
*/
public static final String AUGMENTABLE = "Augmentable";
public static final String AUGMENTED = "Augmented";
/**
* Static attribute for list.
......@@ -1053,11 +1003,6 @@ public final class UtilConstants {
public static final String LIST = "List";
/**
* Static attribute for array list.
*/
public static final String ARRAY_LIST = "ArrayList";
/**
* Comment to be added for autogenerated impl methods.
*/
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
......@@ -1166,16 +1111,6 @@ public final class UtilConstants {
public static final String EVENT_LISTENER = "EventListener";
/**
* Static attribute for YANG types package.
*/
public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.datamodel.utils.builtindatatype";
/**
* Static attribute for MathContext class.
*/
public static final String MATH_CONTEXT = "MathContext";
/**
* Static attribute for YANG file error.
*/
public static final String YANG_FILE_ERROR = "YANG file error : ";
......
......@@ -16,11 +16,13 @@
package org.onosproject.yangutils.utils.io.impl;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
......@@ -47,9 +49,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RPC;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OF;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
......@@ -60,6 +64,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
/**
* Represents javadoc for the generated classes.
......@@ -73,122 +79,6 @@ public final class JavaDocGen {
}
/**
* JavaDocs types.
*/
public enum JavaDocType {
/**
* For class.
*/
IMPL_CLASS,
/**
* For builder class.
*/
BUILDER_CLASS,
/**
* For interface.
*/
INTERFACE,
/**
* For builder interface.
*/
BUILDER_INTERFACE,
/**
* For package-info.
*/
PACKAGE_INFO,
/**
* For getters.
*/
GETTER_METHOD,
/**
* For rpc service.
*/
RPC_INTERFACE,
/**
* For rpc manager.
*/
RPC_MANAGER,
/**
* For event.
*/
EVENT,
/**
* For event listener.
*/
EVENT_LISTENER,
/**
* For setters.
*/
SETTER_METHOD,
/**
* For type def's setters.
*/
TYPE_DEF_SETTER_METHOD,
/**
* For of method.
*/
OF_METHOD,
/**
* For default constructor.
*/
DEFAULT_CONSTRUCTOR,
/**
* For constructor.
*/
CONSTRUCTOR,
/**
* For from method.
*/
FROM_METHOD,
/**
* For type constructor.
*/
TYPE_CONSTRUCTOR,
/**
* For build.
*/
BUILD_METHOD,
/**
* For enum.
*/
ENUM_CLASS,
/**
* For enum's attributes.
*/
ENUM_ATTRIBUTE,
/**
* For manager setters.
*/
MANAGER_SETTER_METHOD,
/**
* For event subject.
*/
EVENT_SUBJECT_CLASS
}
/**
* Returns java docs.
*
* @param type java doc type
......@@ -596,4 +486,143 @@ public final class JavaDocGen {
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
* Generates javaDocs for add augmentation method.
*
* @return javaDocs
*/
public static String generateForAddAugmentation() {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_SETTERS_COMMON + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + NEW_LINE +
FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE +
VALUE + SPACE + OF + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + NEW_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + CLASS + OBJECT_STRING + SPACE +
VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
public static String generateForGetAugmentation() {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_GETTERS + getSmallCase(YANG_AUGMENTED_INFO) + PERIOD + NEW_LINE +
FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + CLASS +
OBJECT_STRING + SPACE + VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE +
FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + VALUE + SPACE +
OF + SPACE + YANG_AUGMENTED_INFO + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
* JavaDocs types.
*/
public enum JavaDocType {
/**
* For class.
*/
IMPL_CLASS,
/**
* For builder class.
*/
BUILDER_CLASS,
/**
* For interface.
*/
INTERFACE,
/**
* For builder interface.
*/
BUILDER_INTERFACE,
/**
* For package-info.
*/
PACKAGE_INFO,
/**
* For getters.
*/
GETTER_METHOD,
/**
* For rpc service.
*/
RPC_INTERFACE,
/**
* For rpc manager.
*/
RPC_MANAGER,
/**
* For event.
*/
EVENT,
/**
* For event listener.
*/
EVENT_LISTENER,
/**
* For setters.
*/
SETTER_METHOD,
/**
* For type def's setters.
*/
TYPE_DEF_SETTER_METHOD,
/**
* For of method.
*/
OF_METHOD,
/**
* For default constructor.
*/
DEFAULT_CONSTRUCTOR,
/**
* For constructor.
*/
CONSTRUCTOR,
/**
* For from method.
*/
FROM_METHOD,
/**
* For type constructor.
*/
TYPE_CONSTRUCTOR,
/**
* For build.
*/
BUILD_METHOD,
/**
* For enum.
*/
ENUM_CLASS,
/**
* For enum's attributes.
*/
ENUM_ATTRIBUTE,
/**
* For manager setters.
*/
MANAGER_SETTER_METHOD,
/**
* For event subject.
*/
EVENT_SUBJECT_CLASS
}
}
......
......@@ -206,7 +206,7 @@ public class InterJarLinkerTest {
File folder = new File(System.getProperty("user.dir") + SLASH + FLOW_CLASSIFIER_FOLDER);
File file = new File(System.getProperty("user.dir") + SLASH + FLOW_CLASSIFIER_MANAGER);
assertThat(true, is(folder.exists()));
assertThat(false, is(file.exists()));
assertThat(true, is(file.exists()));
}
/**
......
......@@ -50,6 +50,7 @@ public final class NotificationTranslatorTest {
generateJavaCode(node, yangPluginConfig);
deleteDirectory("target/NotificationTest/");
deleteDirectory("target/NotificationTest1/");
}
// TODO enhance the test cases, after having a framework of translator test.
......
......@@ -26,7 +26,6 @@ import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.linker.impl.YangXpathLinker;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
......@@ -44,6 +43,7 @@ public class YangXpathLinkerTest {
private YangLinkerManager linkerManager = new YangLinkerManager();
private static final String INTRA_FILE_PATH = "src/test/resources/xPathLinker/IntraFile/";
private static final String INTER_FILE_PATH = "src/test/resources/xPathLinker/InterFile/";
private static final String CASE_FILE_PATH = "src/test/resources/xPathLinker/Case/";
/**
* Unit test case for intra file linking for single level container.
......@@ -230,7 +230,7 @@ public class YangXpathLinkerTest {
*
* @throws IOException when fails to do IO operations
*/
@Test(expected = LinkerException.class)
@Test
public void processIntraFileLinkingInUsesSingleLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
......@@ -260,7 +260,7 @@ public class YangXpathLinkerTest {
*
* @throws IOException when fails to do IO operations
*/
@Test(expected = LinkerException.class)
@Test
public void processIntraFileLinkingInUsesMultiLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
......@@ -449,6 +449,9 @@ public class YangXpathLinkerTest {
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
......@@ -459,7 +462,7 @@ public class YangXpathLinkerTest {
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
targetNode = augment.getAugmentedNode();
}
}
......@@ -481,7 +484,7 @@ public class YangXpathLinkerTest {
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
......@@ -491,7 +494,7 @@ public class YangXpathLinkerTest {
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
targetNode = augment.getAugmentedNode();
}
}
......@@ -523,7 +526,7 @@ public class YangXpathLinkerTest {
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
targetNode = augment.getAugmentedNode();
}
}
......@@ -538,11 +541,11 @@ public class YangXpathLinkerTest {
@Test
public void processInterFileLinkingInUsesInAugment() throws IOException {
/* FIXME: when uses cloning is done test it.
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
......@@ -556,12 +559,12 @@ public class YangXpathLinkerTest {
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
targetNode = linker.processXpathLinking(augment.getTargetNode(), node);
targetNode = augment.getAugmentedNode();
}
}
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
*/
}
/**
......@@ -569,7 +572,7 @@ public class YangXpathLinkerTest {
*
* @throws IOException when fails to do IO operations
*/
@Test(expected = LinkerException.class)
@Test
public void processInterFileLinkingInUsesMultiLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
......@@ -596,4 +599,72 @@ public class YangXpathLinkerTest {
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
}
/**
* Unit test case for inter file linking for multi level uses inside augment.
*
* @throws IOException when fails to do IO operations
*/
@Test
public void processInterFileLinkingInMultipleSubmodules() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "submodule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
for (YangNode node : utilManager.getYangNodeSet()) {
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
targetNode = augment.getAugmentedNode();
}
}
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
}
/**
* Unit test case for inter file linking for multi level uses inside augment.
*
* @throws IOException when fails to do IO operations
*/
@Test
public void processInterFileLinkingInMultipleUses() throws IOException {
/** FIXME: once order of linking is done.
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "uses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
for (YangNode node : utilManager.getYangNodeSet()) {
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
targetNode = augment.getAugmentedNode();
}
}
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
*/
}
}
......
......@@ -113,8 +113,6 @@ public final class JavaIdentifierSyntaxTest {
private static final String BASE_DIR_PKG = "target.UnitTestCase.";
private static final String DIR_PATH = "exist1.exist2.exist3";
private static final String PKG_INFO = "package-info.java";
private static final String BASE_PKG = "target/UnitTestCase";
private static final String TEST_DATA_1 = "This is to append a text to the file first1\n";
/**
* Unit test for private constructor.
......@@ -319,5 +317,6 @@ public final class JavaIdentifierSyntaxTest {
assertThat(true, is(doesPackageExist(strPath)));
createDir.delete();
deleteDirectory(createDir);
deleteDirectory(new File(BASE_DIR_PKG.replace(PERIOD, SLASH)));
}
}
......
......@@ -20,6 +20,8 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import static org.apache.commons.io.FileUtils.deleteDirectory;
......@@ -84,5 +86,6 @@ public final class FileSystemUtilTest {
appendFileContents(createFile, createSourceFile);
updateFileHandle(createFile, null, true);
deleteDirectory(dir);
FileUtils.deleteDirectory(new File(BASE_PKG));
}
}
......
......@@ -67,7 +67,7 @@ public final class YangIoUtilsTest {
addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
FileUtils.deleteDirectory(dirPath);
FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
......@@ -83,7 +83,7 @@ public final class YangIoUtilsTest {
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
FileUtils.deleteDirectory(dirPath);
FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
......@@ -99,7 +99,7 @@ public final class YangIoUtilsTest {
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
FileUtils.deleteDirectory(dirPath);
FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
......@@ -117,6 +117,7 @@ public final class YangIoUtilsTest {
File filePath1 = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath1.isFile(), is(false));
FileUtils.deleteDirectory(dirPath);
FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
......@@ -180,7 +181,7 @@ public final class YangIoUtilsTest {
File dirPath = createDirectories(CREATE_PATH);
assertThat(dirPath.isDirectory(), is(true));
FileUtils.deleteDirectory(dirPath);
FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
......
......@@ -3,9 +3,6 @@ submodule acme-types {
belongs-to "test" {
prefix "test";
}
import test1{
prefix test1;
}
organization "";
contact "";
......
......@@ -1723,9 +1723,9 @@
uses tet:te-link-state-derived;
}
/*
augment "/te-link-event/te-link-attributes/underlay" {
description "Add state attributes to te-link underlay.";
uses te-link-state-underlay-attributes;
} */
}
}
......
module test {
namespace "xpath:intra:single";
prefix test ;
include test1;
include test2;
include test4;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /cont5/cont6 {
leaf a {
type int32;
}
}
augment /cont3/cont4/cont8 {
leaf a {
type int32;
}
}
}
submodule test1 {
belongs-to test {
prefix test;
}
include test4;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf2 {
type int32;
}
}
}
augment /cont1/cont2 {
container cont4 {
leaf leaf1 {
type int32;
}
}
}
augment /cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
}
}
}
}
submodule test2{
belongs-to test {
prefix test;
}
include test1;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont5 {
leaf leaf5 {
type int32;
}
container cont6 {
leaf leaf6 {
type int32;
}
}
}
augment /cont1/cont2/cont4 {
container cont10 {
leaf leaf10 {
type int32;
}
}
}
}
submodule test4 {
belongs-to test {
prefix test;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont3 {
leaf leaf3 {
type int32;
}
container cont4 {
leaf leaf4 {
type int32;
}
}
}
}
module test {
namespace "xpath:intra:single";
prefix test ;
include test1;
include test2;
include test4;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /cont5/cont6/cont3/cont4 {
leaf a {
type int32;
}
}
augment /group1/cont3/cont4/cont8 {
leaf a {
type int32;
}
}
}
submodule test1 {
belongs-to test {
prefix test;
}
include test4;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf2 {
type int32;
}
}
}
augment /cont1/cont2 {
container cont4 {
leaf leaf1 {
type int32;
}
}
}
augment /group1/cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
}
}
}
}
submodule test2{
belongs-to test {
prefix test;
}
include test1;
include test4;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
grouping group2 {
container cont11 {
}
}
container cont5 {
leaf leaf5 {
type int32;
}
container cont6 {
leaf leaf6 {
type int32;
}
uses group1;
}
}
container ethernet {
leaf leaf10 {
type string;
}
}
augment /ethernet {
uses group2;
}
augment /cont1/cont2/cont4 {
container cont10 {
leaf leaf10 {
type int32;
}
}
}
}
submodule test4 {
belongs-to test {
prefix test;
}
include test2;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
grouping group1 {
container cont3 {
leaf leaf3 {
type int32;
}
container cont4 {
leaf leaf4 {
type int32;
}
}
}
}
augment /ethernet/cont11 {
leaf leaf11 {
type int32;
}
}
}
......@@ -21,7 +21,7 @@ module test {
}
augment /test2:cont1/test2:cont2/test2:cont3/test1:cont2 {
leaf a {
leaf leaf8 {
type int32;
}
}
......
......@@ -29,7 +29,7 @@ module test1 {
type int32;
}
container cont2 {
leaf leaf1 {
leaf leaf3 {
type int32;
}
}
......@@ -37,12 +37,12 @@ module test1 {
}
augment /test2:cont1/test2:cont2/test2:cont3 {
leaf a {
leaf leaf2 {
type int32;
}
container cont2 {
leaf leaf1 {
leaf leaf4 {
type int32;
}
}
......
......@@ -13,11 +13,11 @@ module test2 {
}
container cont1 {
leaf leaf1 {
leaf leaf5 {
type int32;
}
container cont2 {
leaf leaf1 {
leaf leaf6 {
type int32;
}
}
......@@ -25,7 +25,7 @@ module test2 {
augment /cont1/cont2 {
container cont3 {
leaf a {
leaf leaf7 {
type string;
}
}
......
......@@ -23,7 +23,7 @@ module test {
uses test2:group1;
}
augment /cont2/group1/cont1/cont2 {
augment /cont2/cont1/cont2 {
leaf a {
type int32;
}
......
......@@ -19,14 +19,14 @@ module test {
}
augment /test2:cont1/test2:cont2/cont2 {
leaf a {
leaf leaf {
type int32;
}
uses group1;
}
augment /test2:cont1/test2:cont2/cont2/group1/cont1/cont2 {
leaf a {
augment /test2:cont1/test2:cont2/cont2/cont1/cont2 {
leaf leaf1 {
type int32;
}
}
......
......@@ -21,7 +21,7 @@ submodule test1 {
grouping group1 {
container cont1 {
container cont2 {
leaf a {
leaf leaf2 {
type string;
}
}
......@@ -29,7 +29,7 @@ submodule test1 {
}
augment /test2:cont1/test2:cont2 {
leaf a {
leaf leaf3 {
type int32;
}
container cont2 {
......
......@@ -13,11 +13,11 @@ module test2 {
}
container cont1 {
leaf leaf1 {
leaf leaf4 {
type int32;
}
container cont2 {
leaf leaf1 {
leaf leaf5 {
type int32;
}
}
......
......@@ -29,7 +29,7 @@ module test {
uses group1;
}
augment /cont2/group1/cont1/cont3 {
augment /cont2/cont1/cont3 {
leaf a {
type int32;
}
......
......@@ -24,7 +24,7 @@ module test {
uses group1;
}
augment /cont2/group1/cont1 {
augment /cont2/cont1 {
leaf a {
type int32;
}
......