Bharat saraswal
Committed by bharat saraswal-huawei

[ONOS-5003][ONOS-5004][ONOS-5005]Generated Code modification for YangUtils+added…

… interface for augmentation method and other api changes.

Change-Id: I954b9c99e182f21d01fcc5cd76fbac7d61a6c3aa
Showing 82 changed files with 628 additions and 796 deletions
......@@ -83,7 +83,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
public class YangAugment
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentedInfo, Resolvable,
YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
YangXPathResolver, YangWhenHolder, YangIfFeatureHolder, YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201602L;
......@@ -254,7 +254,7 @@ public class YangAugment
@Override
public void addLeaf(YangLeaf leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
setListOfLeaf(new LinkedList<>());
}
getListOfLeaf().add(leaf);
......@@ -288,7 +288,7 @@ public class YangAugment
@Override
public void addLeafList(YangLeafList leafList) {
if (getListOfLeafList() == null) {
setListOfLeafList(new LinkedList<YangLeafList>());
setListOfLeafList(new LinkedList<>());
}
getListOfLeafList().add(leafList);
......
......@@ -96,7 +96,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D
public class YangCase
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentableNode,
YangWhenHolder, YangIfFeatureHolder {
YangWhenHolder, YangIfFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201603L;
......@@ -149,6 +149,8 @@ public class YangCase
*/
public YangCase() {
super(YangNodeType.CASE_NODE);
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
/**
......@@ -239,7 +241,7 @@ public class YangCase
@Override
public void addLeaf(YangLeaf leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
setListOfLeaf(new LinkedList<>());
}
getListOfLeaf().add(leaf);
......
......@@ -91,7 +91,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
public class YangContainer
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201605L;
......@@ -158,6 +158,8 @@ public class YangContainer
*/
public YangContainer() {
super(YangNodeType.CONTAINER_NODE);
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
/**
......
......@@ -71,7 +71,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangInput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode {
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201608L;
......@@ -97,8 +97,8 @@ public class YangInput
*/
public YangInput() {
super(YangNodeType.INPUT_NODE);
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
@Override
......
/*
* 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;
/**
* Represent the YANG nodes which can contain is filter content match.
*/
public interface YangIsFilterContentNodes {
}
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
......@@ -71,7 +72,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
public class YangList
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode {
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode,
YangIsFilterContentNodes {
private static final long serialVersionUID = 806201609L;
......@@ -92,7 +94,7 @@ public class YangList
/**
* Reference RFC 6020.
*
* <p>
* The "key" statement, which MUST be present if the list represents
* configuration, and MAY be present otherwise, takes as an argument a
* string that specifies a space-separated list of leaf identifiers of this
......@@ -100,39 +102,39 @@ public class YangList
* such leaf identifier MUST refer to a child leaf of the list. The leafs
* can be defined directly in sub-statements to the list, or in groupings
* used in the list.
*
* <p>
* The combined values of all the leafs specified in the key are used to
* uniquely identify a list entry. All key leafs MUST be given values when a
* list entry is created. Thus, any default values in the key leafs or their
* types are ignored. It also implies that any mandatory statement in the
* key leafs are ignored.
*
* <p>
* A leaf that is part of the key can be of any built-in or derived type,
* except it MUST NOT be the built-in type "empty".
*
* <p>
* All key leafs in a list MUST have the same value for their "config" as
* the list itself.
*
* <p>
* List of key leaf names.
*/
private List<String> keyList;
/**
* Reference RFC 6020.
*
* <p>
* The "unique" statement is used to put constraints on valid list
* entries. It takes as an argument a string that contains a space-
* separated list of schema node identifiers, which MUST be given in the
* descendant form. Each such schema node identifier MUST refer to a leaf.
*
* <p>
* If one of the referenced leafs represents configuration data, then
* all of the referenced leafs MUST represent configuration data.
*
* <p>
* The "unique" constraint specifies that the combined values of all the
* leaf instances specified in the argument string, including leafs with
* default values, MUST be unique within all list entry instances in
* which all referenced leafs exist.
*
* <p>
* List of unique leaf/leaf-list names
*/
private List<String> uniqueList;
......@@ -151,32 +153,32 @@ public class YangList
/**
* Reference RFC 6020.
*
* <p>
* The "max-elements" statement, which is optional, takes as an argument a
* positive integer or the string "unbounded", which puts a constraint on
* valid list entries. A valid leaf-list or list always has at most
* max-elements entries.
*
* <p>
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private YangMaxElement maxElements;
/**
* Reference RFC 6020.
*
* <p>
* The "min-elements" statement, which is optional, takes as an argument a
* non-negative integer that puts a constraint on valid list entries. A
* valid leaf-list or list MUST have at least min-elements entries.
*
* <p>
* If no "min-elements" statement is present, it defaults to zero.
*
* <p>
* The behavior of the constraint depends on the type of the leaf-list's or
* list's closest ancestor node in the schema tree that is not a non-
* presence container:
*
* <p>
* o If this ancestor is a case node, the constraint is enforced if any
* other node from the case exists.
*
* <p>
* o Otherwise, it is enforced if the ancestor node exists.
*/
private YangMinElement minElements;
......@@ -211,6 +213,8 @@ public class YangList
*/
public YangList() {
super(YangNodeType.LIST_NODE);
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
/**
......
......@@ -74,7 +74,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
public class YangModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer, YangFeatureHolder {
RpcNotificationContainer, YangFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201610L;
......@@ -85,7 +85,7 @@ public class YangModule
/**
* Reference:RFC 6020.
*
* <p>
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
......@@ -96,7 +96,7 @@ public class YangModule
/**
* Reference:RFC 6020.
*
* <p>
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
......@@ -136,7 +136,7 @@ public class YangModule
/**
* Reference:RFC 6020.
*
* <p>
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
......@@ -211,9 +211,9 @@ public class YangModule
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* Leafref resolution list.
* LeafRef resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
private List<YangResolutionInfo> leafRefResolutionList;
/**
* Base resolution list.
......@@ -221,9 +221,9 @@ public class YangModule
private List<YangResolutionInfo> baseResolutionList;
/**
* Identityref resolution list.
* IdentityRef resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
private List<YangResolutionInfo> identityRefResolutionList;
/**
* Augment resolution list.
......@@ -250,15 +250,15 @@ public class YangModule
augmentResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
leafRefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
identityRefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
extensionList = new LinkedList<YangExtension>();
importList = new LinkedList<>();
includeList = new LinkedList<>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
extensionList = new LinkedList<>();
}
/**
......@@ -684,11 +684,11 @@ public class YangModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
return leafRefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
} else {
return identityrefResolutionList;
return identityRefResolutionList;
}
}
......@@ -702,13 +702,13 @@ public class YangModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
leafRefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
identityRefResolutionList.add(resolutionInfo);
}
}
......@@ -722,13 +722,13 @@ public class YangModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
leafRefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
identityRefResolutionList = resolutionList;
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
......@@ -185,7 +186,7 @@ public abstract class YangNode
*
* @param sibling YANG node
*/
private void setNextSibling(YangNode sibling) {
public void setNextSibling(YangNode sibling) {
nextSibling = sibling;
}
......@@ -203,7 +204,7 @@ public abstract class YangNode
*
* @param previousSibling points to predecessor sibling
*/
private void setPreviousSibling(YangNode previousSibling) {
public void setPreviousSibling(YangNode previousSibling) {
this.previousSibling = previousSibling;
}
......
......@@ -124,8 +124,8 @@ public class YangNotification
*/
public YangNotification() {
super(YangNodeType.NOTIFICATION_NODE);
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
@Override
......
......@@ -70,7 +70,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangOutput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode {
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201612L;
......@@ -96,8 +96,8 @@ public class YangOutput
*/
public YangOutput() {
super(YangNodeType.OUTPUT_NODE);
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
@Override
......
......@@ -82,7 +82,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
public class YangSubModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer, YangFeatureHolder {
RpcNotificationContainer, YangFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201614L;
......@@ -209,9 +209,9 @@ public class YangSubModule
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* Leafref resolution list.
* LeafRef resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
private List<YangResolutionInfo> leafRefResolutionList;
/**
* Base resolution list.
......@@ -219,9 +219,9 @@ public class YangSubModule
private List<YangResolutionInfo> baseResolutionList;
/**
* Identityref resolution list.
* IdentityRef resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
private List<YangResolutionInfo> identityRefResolutionList;
/**
* Compiler annotation list.
......@@ -247,15 +247,15 @@ public class YangSubModule
augmentResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
leafRefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
identityRefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
extensionList = new LinkedList<YangExtension>();
importList = new LinkedList<>();
includeList = new LinkedList<>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
extensionList = new LinkedList<>();
}
/**
......@@ -592,11 +592,11 @@ public class YangSubModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
return leafRefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
} else {
return identityrefResolutionList;
return identityRefResolutionList;
}
}
......@@ -610,13 +610,13 @@ public class YangSubModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
leafRefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
identityRefResolutionList.add(resolutionInfo);
}
}
......@@ -630,13 +630,13 @@ public class YangSubModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
leafRefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
identityRefResolutionList = resolutionList;
}
}
......
......@@ -276,7 +276,7 @@ public class YangType<T>
* @param value input data value
* @throws DataModelException a violation of data model rules
*/
public void isValidValue(String value) throws DataModelException {
void isValidValue(String value) throws DataModelException {
switch (getDataType()) {
case INT8:
case INT16:
......
......@@ -17,6 +17,7 @@ package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
......@@ -68,7 +69,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClo
public class YangUses
extends YangNode
implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
YangIfFeatureHolder {
YangIfFeatureHolder, YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201617L;
......
......@@ -27,14 +27,14 @@ public final class YangPluginConfig {
private String codeGenDir;
/**
* Contains the code generation directory.
* Contains information of naming conflicts that can be resolved.
*/
private String managerCodeGenDir;
private YangToJavaNamingConflictUtil conflictResolver;
/**
* Contains information of naming conflicts that can be resolved.
* Java code generation is for sbi.
*/
private YangToJavaNamingConflictUtil conflictResolver;
private String codeGenerateForsbi;
/**
* Creates an object for YANG plugin config.
......@@ -43,11 +43,6 @@ public final class YangPluginConfig {
}
/**
* Java code generation is for sbi.
*/
private String codeGenerateForsbi;
/**
* Returns the string for code generation.
*
* @return returns the string for code generation.
......@@ -101,21 +96,4 @@ public final class YangPluginConfig {
return conflictResolver;
}
/**
* Returns manager's code generation directory.
*
* @return manager's code generation directory
*/
public String getManagerCodeGenDir() {
return managerCodeGenDir;
}
/**
* Sets manager's code generation directory.
*
* @param moduleCodeGenDir manager's code generation directory
*/
public void setManagerCodeGenDir(String moduleCodeGenDir) {
this.managerCodeGenDir = moduleCodeGenDir;
}
}
......
......@@ -16,6 +16,22 @@
package org.onosproject.yangutils.datamodel.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
......@@ -41,22 +57,13 @@ import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Represents utilities for data model tree.
*/
public final class DataModelUtils {
public static final String TRUE = "true";
public static final String FALSE = "false";
private static final String SLASH = File.separator;
/**
* Creates a new data model tree utility.
......@@ -103,7 +110,7 @@ public final class DataModelUtils {
* @param node node instance of calling node
* @throws DataModelException a violation of data model rules
*/
public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
private static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
throws DataModelException {
node = node.getChild();
......@@ -297,27 +304,24 @@ public final class DataModelUtils {
/**
* Returns de-serializes YANG data-model nodes.
*
* @param serializableInfoSet YANG file info set
* @param serializedFileInfo serialized File Info
* @return de-serializes YANG data-model nodes
* @throws IOException when fails do IO operations
*/
public static List<YangNode> deSerializeDataModel(List<String> serializableInfoSet) throws IOException {
public static YangNode deSerializeDataModel(String serializedFileInfo) throws IOException {
List<YangNode> nodes = new ArrayList<>();
for (String fileInfo : serializableInfoSet) {
YangNode node = null;
YangNode node;
try {
FileInputStream fileInputStream = new FileInputStream(fileInfo);
FileInputStream fileInputStream = new FileInputStream(serializedFileInfo);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
node = (YangNode) objectInputStream.readObject();
nodes.add(node);
objectInputStream.close();
fileInputStream.close();
} catch (IOException | ClassNotFoundException e) {
throw new IOException(fileInfo + " not found.");
throw new IOException(serializedFileInfo + " not found.");
}
}
return nodes;
return node;
}
/**
......@@ -332,7 +336,7 @@ public final class DataModelUtils {
throws CloneNotSupportedException, DataModelException {
List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
if (currentListOfLeaves != null) {
List<YangLeaf> clonedLeavesList = new LinkedList<YangLeaf>();
List<YangLeaf> clonedLeavesList = new LinkedList<>();
for (YangLeaf leaf : currentListOfLeaves) {
YangLeaf clonedLeaf = leaf.clone();
if (yangUses.getCurrentGroupingDepth() == 0) {
......@@ -350,7 +354,7 @@ public final class DataModelUtils {
List<YangLeafList> currentListOfLeafList = leavesHolder.getListOfLeafList();
if (currentListOfLeafList != null) {
List<YangLeafList> clonedListOfLeafList = new LinkedList<YangLeafList>();
List<YangLeafList> clonedListOfLeafList = new LinkedList<>();
for (YangLeafList leafList : currentListOfLeafList) {
YangLeafList clonedLeafList = leafList.clone();
if (yangUses.getCurrentGroupingDepth() == 0) {
......@@ -410,11 +414,9 @@ public final class DataModelUtils {
while (atomicPathIterator.hasNext()) {
YangAtomicPath atomicPath = atomicPathIterator.next();
Map<String, String> prefixesAndItsImportNameNode = leafrefForCloning.getPrefixAndItsImportedModule();
if (!prefixesAndItsImportNameNode.isEmpty() || prefixesAndItsImportNameNode != null) {
String prefixInPath = atomicPath.getNodeIdentifier().getPrefix();
String importedNodeName = prefixesAndItsImportNameNode.get(prefixInPath);
assignCurrentLeafrefWithNewPrefixes(importedNodeName, atomicPath, yangUses);
}
assignCurrentLeafedWithNewPrefixes(importedNodeName, atomicPath, yangUses);
}
}
}
......@@ -427,7 +429,7 @@ public final class DataModelUtils {
* @param node instance of YANG uses where cloning is done
* @throws DataModelException data model error
*/
private static void assignCurrentLeafrefWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath,
private static void assignCurrentLeafedWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath,
YangNode node) throws DataModelException {
while (!(node instanceof YangReferenceResolver)) {
node = node.getParent();
......@@ -534,7 +536,7 @@ public final class DataModelUtils {
dataTypeName = unionNode.getName();
}
if (potentialTypeNode.getName().contentEquals(dataTypeName)) {
dataType.setDataTypeExtendedInfo((Object) potentialTypeNode);
dataType.setDataTypeExtendedInfo(potentialTypeNode);
return;
}
potentialTypeNode = potentialTypeNode.getNextSibling();
......@@ -542,4 +544,52 @@ public final class DataModelUtils {
throw new DataModelException("Data model error: cloned leaves type is not found");
}
/**
* Parses jar file and returns list of serialized file names.
*
* @param jarFile jar file to be parsed
* @param directory directory where to search
* @return list of serialized files
* @throws IOException when fails to do IO operations
*/
public static List<YangNode> parseJarFile(String jarFile, String directory)
throws IOException {
List<YangNode> nodes = new ArrayList<>();
JarFile jar = new JarFile(jarFile);
Enumeration<?> enumEntries = jar.entries();
while (enumEntries.hasMoreElements()) {
JarEntry file = (JarEntry) enumEntries.nextElement();
if (file.getName().endsWith(".ser")) {
if (file.getName().contains(SLASH)) {
String[] strArray = file.getName().split(SLASH);
String tempPath = "";
for (int i = 0; i < strArray.length - 1; i++) {
tempPath = SLASH + tempPath + SLASH + strArray[i];
}
File dir = new File(directory + tempPath);
dir.mkdirs();
}
File serializedFile = new File(directory + SLASH + file.getName());
if (file.isDirectory()) {
serializedFile.mkdirs();
continue;
}
InputStream inputStream = jar.getInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(serializedFile);
while (inputStream.available() > 0) {
fileOutputStream.write(inputStream.read());
}
fileOutputStream.close();
inputStream.close();
nodes.add(deSerializeDataModel(serializedFile.toString()));
}
}
jar.close();
return nodes;
}
}
......
......@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
......@@ -41,7 +42,6 @@ import org.onosproject.yangutils.linker.exceptions.LinkerException;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
/**
* Represent utilities for YANG linker.
......@@ -73,7 +73,7 @@ public final class YangLinkerUtils {
}
}
if (targetNode instanceof YangChoice) {
// no need to check here.
//Do nothing
} else {
detectCollisionInLeaveHolders(targetNode, augment);
while (augmentsChild != null) {
......@@ -83,7 +83,7 @@ public final class YangLinkerUtils {
}
}
/*Detects collision between leaves/leaflists*/
/*Detects collision between leaves/leaf-lists*/
private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
YangNode parent = targetNode;
......@@ -160,17 +160,19 @@ public final class YangLinkerUtils {
* @param remainingAncestors ancestor count to move in augment path
* @return list of path names needed in leafref
*/
public static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) {
String augmentName = augment.getName();
static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) {
List<String> listOfPathName = new ArrayList<>();
if (augmentName.contains(SLASH_FOR_STRING)) {
String[] augmentNodeNames = augmentName.split(SLASH_FOR_STRING);
for (String valueInAugment : augmentNodeNames) {
if (valueInAugment != null && valueInAugment != EMPTY_STRING && !valueInAugment.isEmpty()) {
listOfPathName.add(valueInAugment);
}
for (YangAtomicPath atomicPath : augment.getTargetNode()) {
if (atomicPath.getNodeIdentifier().getPrefix() != null && !atomicPath.getNodeIdentifier().getPrefix()
.equals(EMPTY_STRING)) {
listOfPathName.add(atomicPath.getNodeIdentifier().getPrefix() + ":" +
atomicPath.getNodeIdentifier().getName());
} else {
listOfPathName.add(atomicPath.getNodeIdentifier().getName());
}
}
for (int countOfAncestor = 0; countOfAncestor < remainingAncestors; countOfAncestor++) {
listOfPathName.remove(listOfPathName.size() - 1);
}
......@@ -185,7 +187,7 @@ public final class YangLinkerUtils {
* @return parent node which can hold data
* @throws LinkerException a violation of linker rules
*/
public static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref) throws LinkerException {
static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref) throws LinkerException {
while (currentParent instanceof YangChoice || currentParent instanceof YangCase) {
if (currentParent.getParent() == null) {
throw new LinkerException("YANG file error: The target node, in the leafref path " +
......@@ -203,7 +205,7 @@ public final class YangLinkerUtils {
* @param yangConstruct yang construct for creating error message
* @return valid node identifier
*/
public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
YangConstructType yangConstruct) {
String[] tmpData = nodeIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
......@@ -264,7 +266,7 @@ public final class YangLinkerUtils {
*
* @param yangNode YANG node information
*/
public static void updateFilePriorityOfNode(YangNode yangNode) {
private static void updateFilePriorityOfNode(YangNode yangNode) {
int curNodePriority = yangNode.getPriority();
if (yangNode instanceof YangReferenceResolver) {
List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
......
......@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.TraversalType;
......@@ -1221,7 +1222,7 @@ public class YangResolutionInfoImpl<T>
YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
if (entityToResolve instanceof YangAugment) {
YangNode targetNode = null;
YangNode targetNode;
YangAugment augment = (YangAugment) entityToResolve;
targetNode = xPathLinker.processAugmentXpathLinking(augment.getTargetNode(),
(YangNode) root);
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.parser.impl;
import java.io.IOException;
import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
......
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
/**
* Represents YANG file information.
*/
public class YangFileInfo {
class YangFileInfo {
/**
* YANG file name.
......@@ -79,7 +79,7 @@ public class YangFileInfo {
*
* @return yangFileName YANG file name
*/
public String getYangFileName() {
String getYangFileName() {
return yangFileName;
}
......@@ -88,7 +88,7 @@ public class YangFileInfo {
*
* @param yangFileName YANG file name
*/
public void setYangFileName(String yangFileName) {
void setYangFileName(String yangFileName) {
this.yangFileName = yangFileName;
}
......@@ -151,7 +151,7 @@ public class YangFileInfo {
*
* @return isForTranslator true if node need to be translated
*/
public boolean isForTranslator() {
boolean isForTranslator() {
return isForTranslator;
}
......@@ -160,7 +160,7 @@ public class YangFileInfo {
*
* @param isForTranslator true if node need to be translated
*/
public void setForTranslator(boolean isForTranslator) {
void setForTranslator(boolean isForTranslator) {
this.isForTranslator = isForTranslator;
}
......
......@@ -19,41 +19,36 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.deSerializeDataModel;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAR;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Represents YANG plugin utilities.
*/
public final class YangPluginUtils {
final class YangPluginUtils {
private static final Logger log = getLogger(YangPluginUtils.class);
......@@ -71,7 +66,7 @@ public final class YangPluginUtils {
* @param project current maven project
* @param context current build context
*/
public static void addToCompilationRoot(String source, MavenProject project, BuildContext context) {
static void addToCompilationRoot(String source, MavenProject project, BuildContext context) {
project.addCompileSourceRoot(source);
context.refresh(project.getBasedir());
log.info("Source directory added to compilation root: " + source);
......@@ -85,7 +80,7 @@ public final class YangPluginUtils {
* @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
throws IOException {
List<File> files = getListOfFile(yangFileInfo);
......@@ -129,7 +124,7 @@ public final class YangPluginUtils {
* @param operation true if need to add to resource
* @throws IOException when fails to do IO operations
*/
public static void serializeDataModel(String directory, Set<YangFileInfo> fileInfoSet,
static void serializeDataModel(String directory, Set<YangFileInfo> fileInfoSet,
MavenProject project, boolean operation) throws IOException {
String serFileDirPath = directory + TARGET_RESOURCE_PATH;
......@@ -142,7 +137,7 @@ public final class YangPluginUtils {
for (YangFileInfo fileInfo : fileInfoSet) {
String serFileName = serFileDirPath + getCamelCase(fileInfo.getRootNode().getName(), null)
String serFileName = serFileDirPath + fileInfo.getRootNode().getName()
+ SERIALIZED_FILE_EXTENSION;
fileInfo.setSerializedFile(serFileName);
FileOutputStream fileOutputStream = new FileOutputStream(serFileName);
......@@ -201,67 +196,18 @@ public final class YangPluginUtils {
* @return list of resolved datamodel nodes
* @throws IOException when fails to do IO operations
*/
public static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepos, String directory)
throws IOException {
List<String> dependeciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
List<String> dependenciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
List<YangNode> resolvedDataModelNodes = new ArrayList<>();
for (String dependecy : dependeciesJarPaths) {
resolvedDataModelNodes.addAll(deSerializeDataModel(parseJarFile(dependecy, directory)));
for (String dependency : dependenciesJarPaths) {
resolvedDataModelNodes.addAll(DataModelUtils.parseJarFile(dependency, directory));
}
return resolvedDataModelNodes;
}
/**
* Parses jar file and returns list of serialized file names.
*
* @param jarFile jar file to be parsed
* @param directory directory for keeping the searized files
* @return list of serialized files
* @throws IOException when fails to do IO operations
*/
public static List<String> parseJarFile(String jarFile, String directory)
throws IOException {
List<String> serailizedFiles = new ArrayList<>();
JarFile jar = new JarFile(jarFile);
Enumeration<?> enumEntries = jar.entries();
File serializedFileDir = new File(directory);
serializedFileDir.mkdirs();
while (enumEntries.hasMoreElements()) {
JarEntry file = (JarEntry) enumEntries.nextElement();
if (file.getName().endsWith(SERIALIZED_FILE_EXTENSION)) {
if (file.getName().contains(SLASH)) {
String[] strArray = file.getName().split(SLASH);
String tempPath = "";
for (int i = 0; i < strArray.length - 1; i++) {
tempPath = SLASH + tempPath + SLASH + strArray[i];
}
File dir = new File(directory + tempPath);
dir.mkdirs();
}
File serailizedFile = new File(directory + SLASH + file.getName());
if (file.isDirectory()) {
serailizedFile.mkdirs();
continue;
}
InputStream inputStream = jar.getInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(serailizedFile);
while (inputStream.available() > 0) {
fileOutputStream.write(inputStream.read());
}
fileOutputStream.close();
inputStream.close();
serailizedFiles.add(serailizedFile.toString());
}
}
jar.close();
return serailizedFiles;
}
/* Adds directory to resources of project */
private static void addToProjectResource(String dir, MavenProject project) {
Resource rsc = new Resource();
......
......@@ -32,6 +32,8 @@ 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.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.linker.YangLinker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
......@@ -39,8 +41,6 @@ import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
......@@ -70,7 +70,7 @@ public class YangUtilManager
extends AbstractMojo {
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
YangPluginConfig yangPlugin = new YangPluginConfig();
private YangPluginConfig yangPlugin = new YangPluginConfig();
private YangNode rootNode;
// YANG file information set.
private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
......@@ -91,12 +91,6 @@ public class YangUtilManager
private String classFileDir;
/**
* Source directory for manager's generated files.
*/
@Parameter(property = "managerFileDir", defaultValue = "src/main/java")
private String managerFileDir;
/**
* Base directory for project.
*/
@Parameter(property = "basedir", defaultValue = "${basedir}")
......@@ -159,8 +153,8 @@ public class YangUtilManager
/**
* Code generation is for nbi or sbi.
*/
@Parameter(property = "generateJavaFileForsbi", defaultValue = "nbi")
private String generateJavaFileForsbi;
@Parameter(property = "generateJavaFileForSbi", defaultValue = "nbi")
private String generateJavaFileForSbi;
@Override
public void execute()
......@@ -171,12 +165,10 @@ public class YangUtilManager
/*
* For deleting the generated code in previous build.
*/
deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, outputDirectory));
String searchDir = getDirectory(baseDir, yangFilesDir);
String codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
String managerCodeGenDir = getDirectory(baseDir, managerFileDir) + SLASH;
// Creates conflict resolver and set values to it.
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
......@@ -185,10 +177,9 @@ public class YangUtilManager
conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
conflictResolver.setPrefixForIdentifier(prefixForIdentifier);
yangPlugin.setCodeGenDir(codeGenDir);
yangPlugin.setManagerCodeGenDir(managerCodeGenDir);
yangPlugin.setConflictResolver(conflictResolver);
yangPlugin.setCodeGenerateForsbi(generateJavaFileForsbi.toLowerCase());
yangPlugin.setCodeGenerateForsbi(generateJavaFileForSbi.toLowerCase());
/*
* Obtain the YANG files at a path mentioned in plugin and creates
* YANG file information set.
......@@ -216,7 +207,6 @@ public class YangUtilManager
serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
addToCompilationRoot(codeGenDir, project, context);
addToCompilationRoot(managerCodeGenDir, project, context);
copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
} catch (IOException | ParserException e) {
......@@ -232,7 +222,7 @@ public class YangUtilManager
"Error handler failed to delete files for data model node.");
}
throw new MojoExecutionException(
"Exception occured due to " + e.getLocalizedMessage() + " in " + fileName
"Exception occurred due to " + e.getLocalizedMessage() + " in " + fileName
+ " YANG file.");
}
}
......@@ -264,14 +254,14 @@ public class YangUtilManager
getYangFileInfoSet().add(dependentFileInfo);
}
} catch (IOException e) {
throw new IOException("failed to resolve in interjar scenario.");
throw new IOException("failed to resolve in inter-jar scenario.");
}
}
/**
* Links all the provided with the YANG file info set.
*
* @throws MojoExecutionException a violation in mojo excecution
* @throws MojoExecutionException a violation in mojo execution
*/
public void resolveDependenciesUsingLinker()
throws MojoExecutionException {
......@@ -378,7 +368,7 @@ public class YangUtilManager
*
* @return the YANG file info set
*/
public Set<YangFileInfo> getYangFileInfoSet() {
Set<YangFileInfo> getYangFileInfoSet() {
return yangFileInfoSet;
}
......
......@@ -39,7 +39,7 @@ public final class GeneratedJavaFileType {
/**
* Impl class file.
*/
public static final int IMPL_CLASS_MASK = 8;
public static final int DEFAULT_CLASS_MASK = 8;
/**
* Interface and class file.
......@@ -69,7 +69,7 @@ public final class GeneratedJavaFileType {
/**
* Java class corresponding to typedef.
*/
public static final int GENERATE_TYPE_CLASS = GENERATE_TYPEDEF_CLASS
static final int GENERATE_TYPE_CLASS = GENERATE_TYPEDEF_CLASS
| GENERATE_UNION_CLASS;
/**
......@@ -99,16 +99,6 @@ public final class GeneratedJavaFileType {
public static final int GENERATE_IDENTITY_CLASS = 2048;
/**
* Operation class file.
*/
public static final int OPERATION_CLASS_MASK = 4096;
/**
* Operation class builder file.
*/
public static final int OPERATION_BUILDER_CLASS_MASK = 8192;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
......
......@@ -122,6 +122,21 @@ public final class GeneratedTempFileType {
public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
/**
* Add to list method interface for class.
*/
public static final int ADD_TO_LIST_INTERFACE_MASK = 1048576;
/**
* Add to list method implementation for class.
*/
public static final int ADD_TO_LIST_IMPL_MASK = 2097152;
/**
* Leaf identifier enum attributes for class.
*/
public static final int LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK = 4194304;
/**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
......
......@@ -90,10 +90,6 @@ public final class JavaAttributeInfo {
* @return the data type info of attribute
*/
public YangType<?> getAttributeType() {
if (attrType == null) {
throw new TranslatorException("Expected java attribute type is null");
}
return attrType;
}
......
......@@ -17,11 +17,18 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
......@@ -31,6 +38,11 @@ import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getAugmentClassName;
import static org.onosproject.yangutils.utils.UtilConstants.CASE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......@@ -88,6 +100,11 @@ public final class JavaCodeGeneratorUtil {
TraversalType curTraversal = ROOT;
while (codeGenNode != null) {
if (codeGenNode instanceof YangAugment) {
if (((YangAugment) codeGenNode).getAugmentedNode() instanceof YangChoice) {
addCaseNodeToChoiceTarget((YangAugment) codeGenNode);
}
}
if (curTraversal != PARENT) {
if (!(codeGenNode instanceof JavaCodeGenerator)) {
throw new TranslatorException("Unsupported node to generate code");
......@@ -285,7 +302,7 @@ public final class JavaCodeGeneratorUtil {
searchAndDeleteTempDir(javaFileInfo.getBaseCodeGenPath() +
javaFileInfo.getPackageFilePath());
} else {
searchAndDeleteTempDir(yangPlugin.getManagerCodeGenDir());
searchAndDeleteTempDir(yangPlugin.getCodeGenDir());
}
}
}
......@@ -347,4 +364,43 @@ public final class JavaCodeGeneratorUtil {
}
return null;
}
/**
* Adds a case node in augment when augmenting a choice node.
*
* @param augment augment node
*/
private static void addCaseNodeToChoiceTarget(YangAugment augment) {
YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
YangPluginConfig pluginConfig = new YangPluginConfig();
javaCase.setName(getAugmentClassName(augment, pluginConfig) + getCapitalCase(CASE));
if (augment.getListOfLeaf() != null) {
augment.getListOfLeaf().forEach(javaCase::addLeaf);
augment.getListOfLeaf().clear();
}
if (augment.getListOfLeafList() != null) {
augment.getListOfLeafList().forEach(javaCase::addLeafList);
augment.getListOfLeafList().clear();
}
YangNode child = augment.getChild();
List<YangNode> childNodes = new ArrayList<>();
while (child != null) {
child.setParent(javaCase);
childNodes.add(child);
child = child.getNextSibling();
}
augment.setChild(null);
try {
augment.addChild(javaCase);
for (YangNode node : childNodes) {
node.setNextSibling(null);
node.setPreviousSibling(null);
javaCase.addChild(node);
}
} catch (DataModelException e) {
System.out.print("failed to add child node due to " + javaCase.getName() + " " + e.getLocalizedMessage());
}
}
}
......
......@@ -42,9 +42,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
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.YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
import static java.util.Collections.sort;
/**
......@@ -226,7 +223,7 @@ public class JavaImportData {
*
* @return import for list attribute
*/
private String getImportForList() {
String getImportForList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
}
......@@ -285,25 +282,6 @@ public class JavaImportData {
}
/**
* Returns import string for hash map class.
*
* @return import string for hash map class
*/
String getYangAugmentedInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
/**
* Returns import string for YangAugmentedOpParamInfo class.
*
* @return import string for YangAugmentedOpParamInfo class
*/
String getYangAugmentedOpParamInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD +
YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
}
/**
* Returns import for big integer.
*
* @return import for big integer
......
......@@ -36,7 +36,6 @@ import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJa
*/
public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
implements Comparable<JavaQualifiedTypeInfoTranslator>, Serializable {
private static final long serialVersionUID = 806201634L;
/**
......@@ -98,7 +97,7 @@ public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
* Current leaves holder is adding a leaf info as a attribute to the
* current class.
*/
String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
String className = getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
leaf.getConflictResolveConfig());
if (className != null) {
/*
......@@ -106,7 +105,7 @@ public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
* since it can be a derived type or a usage of wrapper classes.
*/
importInfo.setClassInfo(className);
String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(),
String classPkg = getJavaImportPackage(leaf.getDataType(),
leaf.isLeafList(), leaf.getConflictResolveConfig());
if (classPkg == null) {
throw new TranslatorException("import package cannot be null when the class is used");
......@@ -222,5 +221,4 @@ public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
public int compareTo(JavaQualifiedTypeInfoTranslator other) {
return getClassInfo().compareTo(other.getClassInfo());
}
}
......
......@@ -29,6 +29,7 @@ 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.utils.UtilConstants.BUILDER;
/**
* Represents implementation of java code fragments temporary implementations.
......@@ -263,18 +264,24 @@ public class TempJavaCodeFragmentFiles {
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
* @param pluginConfig plugin configurations
* @param curNode YANG node
* @return default constructor for class
* @throws IOException when fails to append to file
*/
public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig,
YangNode curNode)
throws IOException {
boolean isSuffix = false;
if (toAppend.equals(BUILDER)) {
isSuffix = true;
}
if (getTypeTempFiles() != null) {
return getTypeTempFiles()
.addDefaultConstructor(modifier, toAppend, pluginConfig);
.addDefaultConstructor(modifier, toAppend, pluginConfig, isSuffix);
}
if (getBeanTempFiles() != null) {
return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig);
return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig, isSuffix);
}
throw new TranslatorException("default constructor should not be added");
......@@ -283,10 +290,11 @@ public class TempJavaCodeFragmentFiles {
/**
* Adds build method's implementation for class.
*
* @param curNode YANG node
* @return build method implementation for class
* @throws IOException when fails to append to temporary file
*/
public String addBuildMethodImpl()
public String addBuildMethodImpl(YangNode curNode)
throws IOException {
if (getBeanTempFiles() != null) {
return getBeanTempFiles().addBuildMethodImpl();
......
......@@ -22,26 +22,27 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
/**
* Represents implementation of java code fragments temporary implementations. Maintains the temp files required
......@@ -227,8 +228,8 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
*/
public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
YangJavaTypeTranslator<?> javaType = new YangJavaTypeTranslator<>();
javaType.setDataType(YangDataTypes.INT32);
javaType.setDataTypeName("int");
javaType.setDataType(INT32);
javaType.setDataTypeName(INT);
javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
return getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
......
......@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
......@@ -489,7 +490,7 @@ public class TempJavaEventFragmentFiles
JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
parentInfo.getPluginConfig().getCodeGenDir());
parentInfo);
}
/**
......
......@@ -22,23 +22,20 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAnnotationsImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addListenersImport;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
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.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;
......@@ -47,7 +44,6 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
* Represents implementation of java service code fragments temporary implementations. Maintains the temp files required
......@@ -72,16 +68,6 @@ public class TempJavaServiceFragmentFiles
private static final String SERVICE_FILE_NAME_SUFFIX = "Service";
/**
* File name for generated class file for manager suffix.
*/
private static final String MANAGER_FILE_NAME_SUFFIX = "Manager";
/**
* Flag to set the manager files generation.
*/
private boolean isManagerNeedToBeGenerated = false;
/**
* Temporary file handle for rpc interface.
*/
private File rpcInterfaceTempFileHandle;
......@@ -97,16 +83,6 @@ public class TempJavaServiceFragmentFiles
private File serviceInterfaceJavaFileHandle;
/**
* Path for service file to be generated.
*/
private String serviceGenPath;
/**
* Java file handle for manager impl file.
*/
private File managerJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated file information
......@@ -117,8 +93,6 @@ public class TempJavaServiceFragmentFiles
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
setServiceGenPath(getJavaFileInfo().getPluginConfig().getCodeGenDir());
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
addGeneratedTempFile(RPC_INTERFACE_MASK);
......@@ -147,24 +121,6 @@ public class TempJavaServiceFragmentFiles
}
/**
* Returns managers java file handle.
*
* @return java file handle
*/
private File getManagerJavaFileHandle() {
return managerJavaFileHandle;
}
/**
* Sets manager java file handle.
*
* @param managerJavaFileHandle file handle for to manager
*/
private void setManagerJavaFileHandle(File managerJavaFileHandle) {
this.managerJavaFileHandle = managerJavaFileHandle;
}
/**
* Returns rpc method's temporary file handle.
*
* @return temporary file handle
......@@ -210,6 +166,8 @@ public class TempJavaServiceFragmentFiles
@Override
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
addResolvedAugmentedDataNodeImports(curNode);
List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles()
.getJavaImportData().getImports();
createPackage(curNode);
......@@ -228,28 +186,8 @@ public class TempJavaServiceFragmentFiles
addListenersImport(curNode, imports, true, LISTENER_SERVICE);
}
// Creates rpc interface file.
setBaseCodePath(getServiceGenPath());
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports);
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
if (isNotification) {
addListenersImport(curNode, imports, false, LISTENER_SERVICE);
addListenersImport(curNode, imports, true, LISTENER_REG);
}
addAnnotationsImports(imports, true);
// Create builder class file.
if (isManagerNeedToBeGenerated()) {
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode);
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
}
if (isNotification) {
addListenersImport(curNode, imports, false, LISTENER_REG);
}
addAnnotationsImports(imports, false);
// Close all the file handles.
freeTemporaryResources(false);
......@@ -314,7 +252,6 @@ public class TempJavaServiceFragmentFiles
throws IOException {
closeFile(getServiceInterfaceJavaFileHandle(), isErrorOccurred);
closeFile(getManagerJavaFileHandle(), isErrorOccurred);
closeFile(getRpcInterfaceTempFileHandle(), true);
closeFile(getRpcImplTempFileHandle(), true);
......@@ -325,41 +262,4 @@ public class TempJavaServiceFragmentFiles
super.freeTemporaryResources(isErrorOccurred);
}
/**
* Returns the path where service file should be generated.
*
* @return path where service file should be generated
*/
private String getServiceGenPath() {
return serviceGenPath;
}
/**
* Sets path where service file should be generated.
*
* @param serviceGenPath path where service file should be generated
*/
private void setServiceGenPath(String serviceGenPath) {
this.serviceGenPath = serviceGenPath;
}
/**
* Returns true if manager needs to be generated.
*
* @return true if manager needs to be generated
*/
private boolean isManagerNeedToBeGenerated() {
return isManagerNeedToBeGenerated;
}
/**
* Sets true if manager needs to be generated.
*
* @param managerNeedToBeGenerated true if manager needs to be generated
*/
public void setManagerNeedToBeGenerated(boolean managerNeedToBeGenerated) {
isManagerNeedToBeGenerated = managerNeedToBeGenerated;
}
}
......
......@@ -36,16 +36,9 @@ import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.utils.GeneratedLanguage;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugmentTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCaseTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoiceTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainerTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumerationTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentityTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInputTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafListTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaListTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotificationTranslator;
......@@ -56,6 +49,13 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTransla
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDefTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnionTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUsesTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugmentTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCaseTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentityTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInputTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafListTranslator;
/**
* Represents factory to create data model objects based on the target file type.
......
......@@ -262,7 +262,7 @@ public final class AttributesJavaDataType {
case INSTANCE_IDENTIFIER:
return JAVA_LANG;
case DERIVED:
return getTypDefsPackage(yangType, conflictResolver);
return getTypeDefsPackage(yangType, conflictResolver);
default:
throw new TranslatorException("given data type is not supported.");
}
......@@ -288,7 +288,7 @@ public final class AttributesJavaDataType {
case INSTANCE_IDENTIFIER:
return JAVA_LANG;
case DERIVED:
return getTypDefsPackage(yangType, conflictResolver);
return getTypeDefsPackage(yangType, conflictResolver);
default:
return null;
}
......@@ -302,7 +302,7 @@ public final class AttributesJavaDataType {
* @param conflictResolver object of YANG to java naming conflict util
* @return java package for typedef node
*/
private static String getTypDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
private static String getTypeDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
Object var = type.getDataTypeExtendedInfo();
if (!(var instanceof YangDerivedInfo)) {
throw new TranslatorException("type should have been derived.");
......
......@@ -16,8 +16,8 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
/**
* Represent java based identification of the YANG leaves.
......@@ -25,21 +25,21 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflic
public interface JavaLeafInfoContainer
extends JavaQualifiedTypeInfoContainer {
/**
* Retreives the data type of the leaf.
* Retrieves the data type of the leaf.
*
* @return data type of the leaf
*/
YangType<?> getDataType();
/**
* Retreives the name of the leaf.
* Retrieves the name of the leaf.
*
* @return name of the leaf
*/
String getName();
/**
* Retreives the java name of the leaf.
* Retrieves the java name of the leaf.
*
* @param conflictResolveConfig user config to resolve conflicts
* @return name of the leaf
......
......@@ -21,7 +21,7 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContaine
/**
* Represent java based identification of the YANG leaves.
*/
public interface JavaQualifiedTypeResolver
interface JavaQualifiedTypeResolver
extends JavaQualifiedTypeInfoContainer {
/**
......
......@@ -17,6 +17,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaAugment;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
......@@ -118,10 +119,21 @@ public class YangJavaAugmentTranslator
@Override
public void generateCodeExit() throws TranslatorException {
try {
if (validateAugmentNode()) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for augmentable node " + getName());
}
}
/**
* Returns true if augment does not have choice as target node.
*
* @return true if augment does not have choice as target node
*/
private boolean validateAugmentNode() {
return !(getAugmentedNode() instanceof YangChoice);
}
}
......
......@@ -123,4 +123,5 @@ public class YangJavaCaseTranslator
throw new TranslatorException("Failed to generate code for case node " + getName());
}
}
}
......
......@@ -20,8 +20,8 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaGrouping;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
/**
......
......@@ -47,7 +47,7 @@ public class YangJavaIdentityTranslator extends YangJavaIdentity
//File type extension for java classes.
private static final String JAVA_FILE_EXTENSION = ".java";
//Contains the information of the importd.
//Contains the information of the imported.
private transient JavaImportData importData;
/**
......@@ -118,6 +118,7 @@ public class YangJavaIdentityTranslator extends YangJavaIdentity
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
updatePackageInfo(this, yangPlugin);
JavaQualifiedTypeInfoTranslator basePkgInfo = new JavaQualifiedTypeInfoTranslator();
String className = getCapitalCase(getJavaFileInfo().getJavaName());
......@@ -142,7 +143,7 @@ public class YangJavaIdentityTranslator extends YangJavaIdentity
}
}
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo().getBaseCodeGenPath());
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
closeFile(file, false);
......
......@@ -33,8 +33,7 @@ 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.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -140,7 +139,7 @@ public class YangJavaModuleTranslator
*/
@Override
public void generateCodeExit() throws TranslatorException {
/**
/*
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
......@@ -153,17 +152,15 @@ public class YangJavaModuleTranslator
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
if (isRootNodesCodeGenRequired(this)) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
......@@ -197,22 +194,22 @@ public class YangJavaModuleTranslator
*
* @param curNode notification node
*/
private void addToNotificaitonList(YangNode curNode) {
private void addToNotificationList(YangNode curNode) {
getNotificationNodes().add(curNode);
}
/**
* Checks if there is any rpc defined in the module or sub-module.
* Checks if there is any notification node present.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
* @return status of notification's existence
*/
private boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangNotification) {
addToNotificaitonList(childNode);
addToNotificationList(childNode);
}
childNode = childNode.getNextSibling();
}
......
......@@ -116,7 +116,7 @@ public class YangJavaNotificationTranslator
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
/**
/*
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
......
......@@ -23,28 +23,22 @@ import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaRpc;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
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;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
......@@ -58,7 +52,7 @@ public class YangJavaRpcTranslator
private static final long serialVersionUID = 806201622L;
/**
* Temproary file for code generation.
* Temporary file for code generation.
*/
private transient TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles;
......@@ -191,7 +185,7 @@ public class YangJavaRpcTranslator
* @return AttributeInfo attribute details required to add in temporary
* files
*/
public JavaAttributeInfo getChildNodeAsAttributeInParentService(
private JavaAttributeInfo getChildNodeAsAttributeInParentService(
YangNode childNode, YangNode currentNode) {
YangNode parentNode = getParentNodeInGenCode(currentNode);
......@@ -229,13 +223,7 @@ public class YangJavaRpcTranslator
JavaFileInfo fileInfo = ((JavaFileInfoContainer) getParent()).getJavaFileInfo();
if (importInfo.getClassInfo().contentEquals(SERVICE)
|| importInfo.getClassInfo().contentEquals(COMPONENT)
|| importInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
|| importInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
|| importInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
|| importInfo.getClassInfo().contentEquals(REFERENCE)
|| importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
|| importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
|| importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
return true;
}
......
......@@ -35,8 +35,7 @@ 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.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -66,11 +65,11 @@ public class YangJavaSubModuleTranslator
public YangJavaSubModuleTranslator() {
super();
setJavaFileInfo(new JavaFileInfo());
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
int genType = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
genType = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
getJavaFileInfo().setGeneratedFileTypes(genType);
}
/**
......@@ -168,17 +167,14 @@ public class YangJavaSubModuleTranslator
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
if (isRootNodesCodeGenRequired(this)) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
......@@ -203,22 +199,22 @@ public class YangJavaSubModuleTranslator
*
* @param curNode notification node
*/
private void addToNotificaitonList(YangNode curNode) {
private void addToNotificationList(YangNode curNode) {
getNotificationNodes().add(curNode);
}
/**
* Checks if there is any rpc defined in the module or sub-module.
* Checks if there is any notification node present.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
* @return status of notification's existence
*/
private boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangNotification) {
addToNotificaitonList(childNode);
addToNotificationList(childNode);
}
childNode = childNode.getNextSibling();
}
......
......@@ -16,18 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaTypeDef;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
......@@ -109,12 +111,12 @@ public class YangJavaTypeDefTranslator
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
YangType typeInTypeDef = this.getTypeDefBaseType();
if (typeInTypeDef.getDataType() == YangDataTypes.DERIVED) {
if (typeInTypeDef.getDataType() == DERIVED) {
YangDerivedInfo derivedInfo = (YangDerivedInfo) typeInTypeDef.getDataTypeExtendedInfo();
if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.LEAFREF) {
if (derivedInfo.getEffectiveBuiltInType() == LEAFREF) {
throw new InvalidNodeForTranslatorException();
}
} else if (typeInTypeDef.getDataType() == YangDataTypes.LEAFREF) {
} else if (typeInTypeDef.getDataType() == LEAFREF) {
throw new InvalidNodeForTranslatorException();
}
try {
......
......@@ -16,10 +16,13 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaDataType;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportClass;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportPackage;
/**
* Represents java information corresponding to the YANG type.
......@@ -30,7 +33,7 @@ public class YangJavaTypeTranslator<T>
extends YangType<T>
implements JavaQualifiedTypeResolver {
private JavaQualifiedTypeInfo javaQualifiedAccess;
private JavaQualifiedTypeInfoTranslator javaQualifiedAccess;
/**
* Create a YANG leaf object with java qualified access details.
......@@ -47,14 +50,14 @@ public class YangJavaTypeTranslator<T>
/*
* Type is added as an attribute in the class.
*/
String className = AttributesJavaDataType.getJavaImportClass(this, false, conflictResolver);
String className = getJavaImportClass(this, false, conflictResolver);
if (className != null) {
/*
* Corresponding to the attribute type a class needs to be imported,
* since it can be a derived type or a usage of wrapper classes.
*/
importInfo.setClassInfo(className);
String classPkg = AttributesJavaDataType.getJavaImportPackage(this,
String classPkg = getJavaImportPackage(this,
false, conflictResolver);
if (classPkg == null) {
throw new TranslatorException("import package cannot be null when the class is used");
......@@ -65,7 +68,7 @@ public class YangJavaTypeTranslator<T>
* The attribute does not need a class to be imported, for example
* built in java types.
*/
String dataTypeName = AttributesJavaDataType.getJavaDataType(this);
String dataTypeName = getJavaDataType(this);
if (dataTypeName == null) {
throw new TranslatorException("not supported data type");
}
......@@ -76,7 +79,7 @@ public class YangJavaTypeTranslator<T>
@Override
public JavaQualifiedTypeInfoTranslator getJavaQualifiedInfo() {
return (JavaQualifiedTypeInfoTranslator) javaQualifiedAccess;
return javaQualifiedAccess;
}
@Override
......
......@@ -20,8 +20,8 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaUses;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
/**
......
......@@ -52,7 +52,7 @@ public class JavaExtendsListHolder {
*
* @return extends list
*/
public Map<JavaQualifiedTypeInfoTranslator, Boolean> getExtendedClassStore() {
Map<JavaQualifiedTypeInfoTranslator, Boolean> getExtendedClassStore() {
return extendedClassStore;
}
......
......@@ -20,14 +20,16 @@ import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.utils.io.impl.YangIoUtils;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
......@@ -48,6 +50,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirector
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
/**
* Represents an utility Class for translating the name from YANG to java convention.
......@@ -109,14 +112,12 @@ public final class JavaIdentifierSyntax {
*/
private static String getPkgFromNameSpace(String nameSpace, YangToJavaNamingConflictUtil conflictResolver) {
ArrayList<String> pkgArr = new ArrayList<String>();
ArrayList<String> pkgArr = new ArrayList<>();
nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
String properNameSpace = nameSpace.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
String[] nameSpaceArr = properNameSpace.split(COLAN);
for (String nameSpaceString : nameSpaceArr) {
pkgArr.add(nameSpaceString);
}
Collections.addAll(pkgArr, nameSpaceArr);
return getPkgFrmArr(pkgArr, conflictResolver);
}
......@@ -159,7 +160,7 @@ public final class JavaIdentifierSyntax {
for (String member : pkgArr) {
boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member.toLowerCase());
if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
String prefix = YangIoUtils.getPrefixForIdentifier(conflictResolver);
String prefix = getPrefixForIdentifier(conflictResolver);
member = prefix + member;
}
pkg = pkg + member;
......@@ -183,10 +184,8 @@ public final class JavaIdentifierSyntax {
String[] strArray = name.split(COLAN);
String output = EMPTY_STRING;
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
List<String> stringArrangement = new ArrayList<>();
stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
for (int i = 0; i < strArray.length; i++) {
......@@ -236,7 +235,7 @@ public final class JavaIdentifierSyntax {
* @param pkg Package to check if it is created
* @return existence status of package
*/
public static boolean doesPackageExist(String pkg) {
static boolean doesPackageExist(String pkg) {
File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
return pkgDir.exists() && pkgWithFile.isFile();
......
......@@ -22,12 +22,12 @@ package org.onosproject.yangutils.translator.tojava.utils;
public enum ValidatorTypeForUnionTypes {
/**
* When conflict is there for int32 and uint16.
* When conflict is there for int32 and uInt16.
*/
INT_TYPE_CONFLICT,
/**
* When conflict is there for int64 and uint32.
* When conflict is there for int64 and uInt32.
*/
LONG_TYPE_CONFLICT
}
......
......@@ -44,16 +44,13 @@ public final class FileSystemUtil {
}
/**
* Reads the contents from source file and append its contents to append
* file.
* Reads the contents from source file and append its contents to append file.
*
* @param toAppend destination file in which the contents of source file is
* appended
* @param srcFile source file from which data is read and added to to append
* file
* @param toAppend destination file in which the contents of source file is appended
* @param srcFile source file from which data is read and added to to append file
* @throws IOException any IO errors
*/
public static void appendFileContents(File toAppend, File srcFile)
static void appendFileContents(File toAppend, File srcFile)
throws IOException {
updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false);
}
......@@ -76,14 +73,21 @@ public final class FileSystemUtil {
String line = bufferReader.readLine();
while (line != null) {
if (line.equals(SPACE) || line.equals(EMPTY_STRING) || line.equals(EIGHT_SPACE_INDENTATION)
|| line.equals(MULTIPLE_NEW_LINE)) {
switch (line) {
case SPACE:
case EMPTY_STRING:
case EIGHT_SPACE_INDENTATION:
case MULTIPLE_NEW_LINE:
stringBuilder.append(NEW_LINE);
} else if (line.equals(FOUR_SPACE_INDENTATION)) {
break;
case FOUR_SPACE_INDENTATION:
stringBuilder.append(EMPTY_STRING);
} else {
stringBuilder.append(spaces + line);
break;
default:
String append = spaces + line;
stringBuilder.append(append);
stringBuilder.append(NEW_LINE);
break;
}
line = bufferReader.readLine();
}
......@@ -100,10 +104,10 @@ public final class FileSystemUtil {
* @param inputFile input file
* @param contentTobeAdded content to be appended to the file
* @param isClose when close of file is called.
* @throws IOException if the named file exists but is a directory rather than a regular file,
* does not exist but cannot be created, or cannot be opened for any other reason
* @throws IOException if the named file exists but is a directory rather than a regular file, does not exist but
* cannot be created, or cannot be opened for any other reason
*/
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
throws IOException {
List<FileWriter> fileWriterStore = new ArrayList<>();
......@@ -119,7 +123,6 @@ public final class FileSystemUtil {
for (FileWriter curWriter : fileWriterStore) {
curWriter.flush();
curWriter.close();
curWriter = null;
}
}
}
......@@ -137,7 +140,10 @@ public final class FileSystemUtil {
if (file != null) {
updateFileHandle(file, null, true);
if (toBeDeleted) {
file.delete();
boolean deleted = file.delete();
if (!deleted) {
throw new IOException("Failed to delete temporary file " + file.getName());
}
}
}
}
......
......@@ -19,17 +19,12 @@ package org.onosproject.yangutils.utils.io.impl;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_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.EIGHT_SPACE_INDENTATION;
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;
......@@ -38,15 +33,17 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_JAVA_
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_ADD_TO_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_MANAGER_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF;
......@@ -57,11 +54,14 @@ 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.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
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.OP_PARAM_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......@@ -71,6 +71,7 @@ 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.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
......@@ -92,7 +93,7 @@ public final class JavaDocGen {
* @param name name of the YangNode
* @param isList is list attribute
* @param pluginConfig plugin configurations
* @return javadocs.
* @return javaDocs.
*/
public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) {
......@@ -167,6 +168,9 @@ public final class JavaDocGen {
case EVENT_SUBJECT_CLASS: {
return generateForClass(name);
}
case ADD_TO_LIST: {
return generateForAddToList(name);
}
default: {
return generateForConstructors(name);
}
......@@ -180,8 +184,8 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForEnumAttr(String name) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
+ name + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return EIGHT_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + EIGHT_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
+ name + PERIOD + NEW_LINE + EIGHT_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
......@@ -438,11 +442,11 @@ public final class JavaDocGen {
/**
* Generates javaDoc for the builder interface.
*
* @param builderforName builder for name
* @param builderForName builder for name
* @return javaDocs
*/
private static String generateForBuilderInterface(String builderforName) {
return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE
private static String generateForBuilderInterface(String builderForName) {
return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderForName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
......@@ -480,7 +484,7 @@ public final class JavaDocGen {
*/
private static String generateForConstructors(String className) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ className + IMPL + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ className + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT
+ className + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
......@@ -504,7 +508,7 @@ public final class JavaDocGen {
* @param attribute attribute string
* @return javaDocs for type constructor
*/
public static String generateForTypeConstructor(String attribute) {
private static String generateForTypeConstructor(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
......@@ -557,6 +561,52 @@ public final class JavaDocGen {
}
/**
* Generates javaDocs for type constructor.
*
* @param attribute attribute string
* @return javaDocs for type constructor
*/
public static String generateForGetMethodWithAttribute(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_GETTERS
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + attribute + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
* Returns javaDocs for add to list method.
*
* @param attribute attribute
* @return javaDocs
*/
private static String generateForAddToList(String attribute) {
String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_ADD_TO_LIST + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE;
javadoc = javadoc + VALUE + SPACE + OF + SPACE;
javadoc = javadoc + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return javadoc;
}
/**
* Generates for builder method.
*
* @param attribute attribute
* @return javaDocs
*/
public static String generateForBuilderMethod(String attribute) {
String javadoc = FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_GETTERS + attribute + BUILDER + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
+ NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN;
javadoc = javadoc + VALUE + SPACE + OF + SPACE;
javadoc = javadoc + attribute + BUILDER + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return javadoc;
}
/**
* JavaDocs types.
*/
public enum JavaDocType {
......@@ -679,6 +729,12 @@ public final class JavaDocGen {
/**
* For operation builder.
*/
OPERATION_BUILDER_CLASS
OPERATION_BUILDER_CLASS,
/**
* For add to list.
*/
ADD_TO_LIST,
}
}
......
......@@ -27,8 +27,8 @@ import java.util.Stack;
*/
public final class YangFileScanner {
private static final String JAVA_FILE_EXTENTION = ".java";
private static final String YANG_FILE_EXTENTION = ".yang";
private static final String JAVA_FILE_EXTENSION = ".java";
private static final String YANG_FILE_EXTENSION = ".yang";
/**
* Creates an instance of YANG file scanner.
......@@ -45,9 +45,8 @@ public final class YangFileScanner {
* @throws IOException when files get deleted while performing the
* operations
*/
public static List<String> getJavaFiles(String root) throws IOException {
return getFiles(root, JAVA_FILE_EXTENTION);
static List<String> getJavaFiles(String root) throws IOException {
return getFiles(root, JAVA_FILE_EXTENSION);
}
/**
......@@ -60,8 +59,7 @@ public final class YangFileScanner {
* operations
*/
public static List<String> getYangFiles(String root) throws IOException {
return getFiles(root, YANG_FILE_EXTENTION);
return getFiles(root, YANG_FILE_EXTENSION);
}
/**
......@@ -73,22 +71,22 @@ public final class YangFileScanner {
* @throws NullPointerException when no file is there
* @throws IOException when files get deleted while performing the operations
*/
public static List<String> getFiles(String root, String extension) throws IOException {
private static List<String> getFiles(String root, String extension) throws IOException {
List<String> store = new LinkedList<>();
Stack<String> stack = new Stack<>();
stack.push(root);
File file;
File[] filelist;
File[] fileList;
try {
while (!stack.empty()) {
root = stack.pop();
file = new File(root);
filelist = file.listFiles();
if ((filelist == null) || (filelist.length == 0)) {
fileList = file.listFiles();
if ((fileList == null) || (fileList.length == 0)) {
continue;
}
for (File current : filelist) {
for (File current : fileList) {
if (current.isDirectory()) {
stack.push(current.toString());
} else {
......
......@@ -54,7 +54,6 @@ public class IetfYangFileTest {
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/ietfyang/l3vpnservice/");
yangPluginConfig.setManagerCodeGenDir("target/ietfyang/l3vpnservice/");
utilManager.translateToJava(yangPluginConfig);
......
......@@ -20,9 +20,9 @@ import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......@@ -49,10 +49,8 @@ public class AugmentTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/augmentTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/augmentTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/augmentTranslator/");
deleteDirectory("target/augmentTranslator1/");
}
}
......
......@@ -44,7 +44,6 @@ public final class ChoiceCaseTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/ChoiceCaseTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/ChoiceCaseTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -45,7 +45,6 @@ public final class EnumTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/EnumTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/EnumTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Rule;
import org.junit.Test;
......@@ -32,7 +33,6 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import static org.hamcrest.MatcherAssert.assertThat;
......@@ -52,7 +52,6 @@ public class InterFileLeafrefLinkingTest {
private final YangUtilManager utilManager = new YangUtilManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks inter file leafref linking.
......
......@@ -656,7 +656,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/");
yangPluginConfig.setManagerCodeGenDir("target/interfilewithusesreferringtype/");
utilManager.translateToJava(yangPluginConfig);
......@@ -678,7 +677,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
yangPluginConfig.setManagerCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
utilManager.translateToJava(yangPluginConfig);
......@@ -700,7 +698,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfileietf/");
yangPluginConfig.setManagerCodeGenDir("target/interfileietf/");
utilManager.translateToJava(yangPluginConfig);
......@@ -722,7 +719,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/usesInContainer/");
yangPluginConfig.setManagerCodeGenDir("target/usesInContainer/");
utilManager.translateToJava(yangPluginConfig);
......@@ -744,7 +740,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/");
yangPluginConfig.setManagerCodeGenDir("target/groupingNodeSameAsModule/");
utilManager.translateToJava(yangPluginConfig);
......
......@@ -41,11 +41,10 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.deSerializeDataModel;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.parseJarFile;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.parseJarFile;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.serializeDataModel;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
......@@ -189,7 +188,6 @@ public class InterJarLinkerTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(TARGET);
yangPluginConfig.setManagerCodeGenDir(TARGET);
utilManager.translateToJava(yangPluginConfig);
......@@ -206,7 +204,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(true, is(file.exists()));
assertThat(false, is(file.exists()));
}
/**
......@@ -304,7 +302,7 @@ public class InterJarLinkerTest {
*/
private void addInterJarRootNodes(String jarFile) throws IOException {
try {
List<YangNode> interJarResolvedNodes = deSerializeDataModel(parseJarFile(jarFile, TARGET));
List<YangNode> interJarResolvedNodes = parseJarFile(jarFile, TARGET);
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
......@@ -326,7 +324,6 @@ public class InterJarLinkerTest {
File file = new File(TARGET + TARGET_RESOURCE_PATH);
File[] files = file.listFiles();
String[] source = new String[files.length];
for (int i = 0; i < files.length; i++) {
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.plugin.manager;
import java.io.File;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test case to test code generation for root nodes.
*/
public class ManagerCodeGeneratorTest {
private final YangUtilManager utilManager = new YangUtilManager();
/**
* Checks manager translation should not result in any exception.
*
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager = new File(file1);
assertThat(false, is(manager.exists()));
File manager2 = new File(file2);
assertThat(false, is(manager2.exists()));
File manager3 = new File(file3);
assertThat(true, is(manager3.exists()));
deleteDirectory("target/manager/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(yangPluginConfig);
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(true, is(manager3.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerforMultiChildTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/MultiChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
File manager1 = new File(file1);
assertThat(false, is(manager1.exists()));
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
File manager2 = new File(file2);
assertThat(false, is(manager2.exists()));
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(false, is(manager3.exists()));
String file4 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java";
File manager4 = new File(file4);
assertThat(true, is(manager4.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerforMultiChildWithDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/MultiChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager1/");
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager1/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java";
File manager1 = new File(file1);
assertThat(true, is(manager1.exists()));
String file2 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Service.java";
File service2 = new File(file2);
assertThat(true, is(service2.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
}
......@@ -45,12 +45,10 @@ public final class NotificationTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/NotificationTest/");
yangPluginConfig.setManagerCodeGenDir("target/NotificationTest1/");
generateJavaCode(node, yangPluginConfig);
deleteDirectory("target/NotificationTest/");
deleteDirectory("target/NotificationTest1/");
}
// TODO enhance the test cases, after having a framework of translator test.
......
......@@ -45,7 +45,6 @@ public final class RpcTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/RpcTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/RpcTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -20,9 +20,9 @@ import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......@@ -49,7 +49,6 @@ public class TypeDefTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/typedefTranslator/");
......@@ -63,7 +62,6 @@ public class TypeDefTranslatorTest {
@Test
public void processTypeDefWithRestrictionsTranslator() throws IOException, ParserException, MojoExecutionException {
/*FIXME: After typedef with leafref is fixed.
String searchDir = "src/test/resources/typedefTranslator/with";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
......@@ -72,10 +70,10 @@ public class TypeDefTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/typedefTranslator/");
*/
}
}
......
......@@ -47,7 +47,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......@@ -71,7 +70,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -94,7 +92,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -117,7 +114,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -140,7 +136,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -163,7 +158,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -187,7 +181,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -211,7 +204,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.ResolvableType;
......@@ -28,22 +29,24 @@ import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.linker.impl.YangXpathLinker;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test cases for x-path linker.
*/
public class YangXpathLinkerTest {
private YangUtilManager utilManager = new YangUtilManager();
private YangXpathLinker linker = new YangXpathLinker();
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/";
private YangUtilManager utilManager = new YangUtilManager();
private YangXpathLinker linker = new YangXpathLinker();
private YangLinkerManager linkerManager = new YangLinkerManager();
/**
* Unit test case for intra file linking for single level container.
......@@ -622,6 +625,7 @@ public class YangXpathLinkerTest {
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -649,7 +653,6 @@ public class YangXpathLinkerTest {
@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();
......@@ -657,6 +660,7 @@ public class YangXpathLinkerTest {
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -672,7 +676,11 @@ public class YangXpathLinkerTest {
}
}
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/xpath/");
utilManager.translateToJava(yangPluginConfig);
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
*/
deleteDirectory("target/xpath/");
}
}
......
......@@ -26,7 +26,7 @@ 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.utils.JavaCodeSnippetGen.getImportText;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
......@@ -65,7 +65,7 @@ public class JavaCodeSnippetGenTest {
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class };
Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -102,26 +102,26 @@ public class JavaCodeSnippetGenTest {
@Test
public void testForJavaAttributeInfo() {
String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
String attributeWithoutTypePkg = getJavaAttributeDefinition(null, STRING_DATA_TYPE, YANG_NAME,
false, PRIVATE);
assertThat(true, is(attributeWithoutTypePkg.equals(
PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
String attributeWithTypePkg = getJavaAttributeDefinition(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
false, PRIVATE);
assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD
+ STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
String attributeWithListPkg = getJavaAttributeDefinition(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
true, PRIVATE);
assertThat(true, is(attributeWithListPkg.equals(
assertThat(true, is(attributeWithListPkg.contains(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE
+ DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
+ DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME)));
String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
String attributeWithListWithoutPkg = getJavaAttributeDefinition(null, STRING_DATA_TYPE, YANG_NAME,
true, PRIVATE);
assertThat(true, is(attributeWithListWithoutPkg.equals(
assertThat(true, is(attributeWithListWithoutPkg.contains(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE
+ YANG_NAME + SEMI_COLAN + NEW_LINE)));
+ YANG_NAME)));
}
}
......
......@@ -21,9 +21,9 @@ import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
......@@ -131,7 +131,7 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getBuildTest() {
String method = getBuild(CLASS_NAME);
String method = getBuild(CLASS_NAME, false);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + NEW + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
......@@ -177,7 +177,7 @@ public final class MethodsGeneratorTest {
@Test
public void getConstructorStartTest() {
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructorStart(CLASS_NAME, pluginConfig);
String method = getConstructorStart(CLASS_NAME, pluginConfig, false);
assertThat(true, is(method.contains(PUBLIC + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE)));
......
......@@ -47,7 +47,7 @@ public final class YangIoUtilsTest {
private static final String CHECK1 = "check1";
private static final String PKG_INFO = "package-info.java";
private static final String PATH = "src/main/yangmodel/";
private static final String MSG = "Exception occured while creating package info file.";
private static final String MSG = "Exception occurred while creating package info file.";
/**
* Expected exceptions.
......
......@@ -31,6 +31,19 @@ module test {
}
}
choice choice1 {
case case1 {
leaf case-leaf {
type int32;
}
container case-container3 {
leaf leafs {
type int64;
}
}
}
}
augment /cont3 {
leaf leaf1 {
......@@ -39,9 +52,27 @@ module test {
}
augment /cont1/cont2 {
leaf leaf2 {
leaf-list leaf2 {
type int32;
}
}
augment /choice1 {
leaf-list leaf2 {
type int32;
}
leaf leaf1 {
type int32;
}
container case-container {
leaf leafs {
type int64;
}
}
container case-container2 {
leaf leafs {
type int64;
}
}
}
augment /test1:cont1/test1:cont2 {
......@@ -57,10 +88,25 @@ module test {
}
augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s/test2:aa {
leaf a {
leaf name {
type string;
}
leaf surname {
type string;
}
leaf-list aleaflist {
type int32;
}
container aa {
container cont1 {
}
list alist {
key "name";
leaf name {
type string;
}
leaf-list surname {
type string;
}
}
}
......
......@@ -2,9 +2,7 @@ module test {
namespace "xpath:intra:single";
prefix test ;
include test1;
include test2;
include test4;
organization "";
contact "";
......@@ -21,11 +19,5 @@ module test {
type int32;
}
}
augment /group1/cont3/cont4/cont8 {
leaf a {
type int32;
}
}
}
......
......@@ -4,8 +4,6 @@ submodule test1 {
prefix test;
}
include test4;
organization "";
contact "";
......@@ -35,13 +33,5 @@ submodule test1 {
}
}
augment /group1/cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
}
}
}
}
......
......@@ -3,8 +3,8 @@ submodule test2{
prefix test;
}
include test3;
include test1;
include test4;
organization "";
contact "";
......@@ -52,5 +52,13 @@ submodule test2{
}
}
augment /group1/cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
}
}
}
}
......
submodule test4 {
submodule test3 {
belongs-to test {
prefix test;
}
include test2;
organization "";
contact "";
......@@ -28,10 +27,4 @@ submodule test4 {
}
}
augment /ethernet/cont11 {
leaf leaf11 {
type int32;
}
}
}
......