[ONOS-4829] Augmented data method generator implmentation.
Change-Id: I0cb68dd10a748e5b66eec0b832574f408a23ba5c
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
index 9d37d46..6d475cb 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAugment.java
@@ -15,8 +15,10 @@
*/
package org.onosproject.yangutils.datamodel;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
@@ -83,7 +85,7 @@
public class YangAugment
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentedInfo, Resolvable,
- YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
+ YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201602L;
@@ -128,9 +130,13 @@
private YangNode augmentedNode;
/**
- * Status of resolution. If completely resolved enum value is "RESOLVED",
- * if not enum value is "UNRESOLVED", in case reference of grouping/typedef
- * is added to uses/type but it's not resolved value of enum should be
+ * All resolved nodes in given xPath.
+ */
+ private Map<YangAtomicPath, YangNode> resolveNodeInPath;
+
+ /**
+ * Status of resolution. If completely resolved enum value is "RESOLVED", if not enum value is "UNRESOLVED", in case
+ * reference of grouping/typedef is added to uses/type but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
@@ -150,6 +156,7 @@
*/
public YangAugment() {
super(YangNodeType.AUGMENT_NODE);
+ resolveNodeInPath = new HashMap<>();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
@@ -411,6 +418,11 @@
}
@Override
+ public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
+ this.ifFeatureList = ifFeatureList;
+ }
+
+ @Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
@@ -419,11 +431,6 @@
}
@Override
- public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
- this.ifFeatureList = ifFeatureList;
- }
-
- @Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@@ -438,4 +445,22 @@
public void resolve() throws DataModelException {
// Resolving of target node is being done in XPathLinker.
}
+
+ /**
+ * Returns all resolved node in path.
+ *
+ * @return all resolved node in path
+ */
+ public Map<YangAtomicPath, YangNode> getResolveNodeInPath() {
+ return resolveNodeInPath;
+ }
+
+ /**
+ * Sets all resolved node in path.
+ *
+ * @param resolveNodeInPath all resolved node in path
+ */
+ public void setResolveNodeInPath(Map<YangAtomicPath, YangNode> resolveNodeInPath) {
+ this.resolveNodeInPath = resolveNodeInPath;
+ }
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
index 65261cc..bc3c72e 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
@@ -406,7 +406,7 @@
* Sets the config's value to all leaf if leaf's config statement is not
* specified.
*
- * @param leaves list of leaf attributes of container
+ * @param leaves list of leaf attributes of container
* @param leafLists list of leaf-list attributes of container
*/
private void setDefaultConfigValueToChild(List<YangLeaf> leaves, List<YangLeafList> leafLists) {
@@ -439,7 +439,7 @@
/**
* Validates config statement of container.
*
- * @param leaves list of leaf attributes of container
+ * @param leaves list of leaf attributes of container
* @param leafLists list of leaf-list attributes of container
* @throws DataModelException a violation of data model rules
*/
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
index 091a15f..25e11b6 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
@@ -144,7 +144,6 @@
listOfLeaf = leafsList;
}
-
@Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
index 7e14bc8..810a206 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
@@ -158,7 +158,6 @@
this.listOfLeafList = listOfLeafList;
}
-
@Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 1e15d1d..64f2c78 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -349,6 +349,7 @@
* type info needs to be updated to the cloned new type node.
*
* @param leavesHolder cloned leaves holder, for whom the leaves reference needs to be updated
+ * @throws DataModelException when fails to do data model operations
*/
public static void updateClonedLeavesUnionEnumRef(YangLeavesHolder leavesHolder) throws DataModelException {
List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
diff --git a/plugin/pom.xml b/plugin/pom.xml
index 155237b..41cabfa 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -14,7 +14,7 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -33,7 +33,7 @@
</properties>
<dependencies>
- <dependency>
+ <dependency>
<groupId>org.onosproject</groupId>
<artifactId>yangutils-datamodel</artifactId>
<version>1.7.0-SNAPSHOT</version>
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/PrefixResolverType.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/PrefixResolverType.java
new file mode 100644
index 0000000..1ea75e6
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/PrefixResolverType.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.linker.impl;
+
+/**
+ * Enum for prefix resolver type when augment has come in path.
+ */
+public enum PrefixResolverType {
+
+ /**
+ * When prefix changes from inter file to intra file.
+ */
+ INTER_TO_INTRA,
+
+ /**
+ * When prefix changes from intra file to inter file.
+ */
+ INTRA_TO_INTER,
+
+ /**
+ * When prefix changes from one inter file to other inter file.
+ */
+ INTER_TO_INTER,
+
+ /**
+ * When no prefix change occurres.
+ */
+ NO_PREFIX_CHANGE_FOR_INTRA,
+
+ /**
+ * When no prefix change occurres.
+ */
+ NO_PREFIX_CHANGE_FOR_INTER
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
index 38a8188..76098fb 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
@@ -21,6 +21,7 @@
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
+import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
@@ -36,8 +37,7 @@
}
/**
- * Detects collision between target nodes leaf/leaf-list or child node with
- * augmented leaf/leaf-list or child node.
+ * Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node.
*
* @param targetNode target node
* @param augment augment node
@@ -46,57 +46,66 @@
YangNode targetNodesChild = targetNode.getChild();
YangNode augmentsChild = augment.getChild();
YangLeavesHolder augmentsLeavesHolder = augment;
- YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
+ if (targetNode instanceof YangChoice) {
+ if (augmentsLeavesHolder.getListOfLeaf() != null
+ || augmentsLeavesHolder.getListOfLeafList() != null) {
+ throw new LinkerException("target node " + targetNode.getName()
+ + "is a instance of choice. it can " +
+ "only be augmented with leaf using a case node.");
+ }
+ } else {
+ YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
- YangNode parent = targetNode;
- if (targetNode instanceof YangAugment) {
- parent = targetNode.getParent();
- } else {
- while (parent.getParent() != null) {
- parent = parent.getParent();
- }
- }
- if (augmentsLeavesHolder.getListOfLeaf() != null && augmentsLeavesHolder.getListOfLeaf().size() != 0
- && targetNodesLeavesHolder.getListOfLeaf() != null) {
- for (YangLeaf leaf : augmentsLeavesHolder.getListOfLeaf()) {
- for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
- if (targetLeaf.getName().equals(leaf.getName())) {
- throw new LinkerException("target node " + targetNode.getName()
- + " contains augmented leaf " + leaf.getName() + " in module "
- + parent.getName());
- }
+ YangNode parent = targetNode;
+ if (targetNode instanceof YangAugment) {
+ parent = targetNode.getParent();
+ } else {
+ while (parent.getParent() != null) {
+ parent = parent.getParent();
}
}
- } else if (augmentsLeavesHolder.getListOfLeafList() != null
- && augmentsLeavesHolder.getListOfLeafList().size() != 0
- && targetNodesLeavesHolder.getListOfLeafList() != null) {
- for (YangLeafList leafList : augmentsLeavesHolder.getListOfLeafList()) {
- for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
- if (targetLeafList.getName().equals(leafList.getName())) {
- throw new LinkerException("target node " + targetNode.getName()
- + " contains augmented leaf-list" + leafList.getName() + " in module "
- + parent.getName());
+ if (augmentsLeavesHolder.getListOfLeaf() != null && augmentsLeavesHolder.getListOfLeaf().size() != 0
+ && targetNodesLeavesHolder.getListOfLeaf() != null) {
+ for (YangLeaf leaf : augmentsLeavesHolder.getListOfLeaf()) {
+ for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
+ if (targetLeaf.getName().equals(leaf.getName())) {
+ throw new LinkerException("target node " + targetNode.getName()
+ + " contains augmented leaf " + leaf.getName() + " in module "
+ + parent.getName());
+ }
}
}
- }
- } else {
- while (augmentsChild != null) {
- while (targetNodesChild != null) {
- if (targetNodesChild.getName().equals(augmentsChild.getName())) {
- throw new LinkerException("target node " + targetNode.getName()
- + " contains augmented child node" + augmentsChild.getName() + " in module "
- + parent.getName());
+ } else if (augmentsLeavesHolder.getListOfLeafList() != null
+ && augmentsLeavesHolder.getListOfLeafList().size() != 0
+ && targetNodesLeavesHolder.getListOfLeafList() != null) {
+ for (YangLeafList leafList : augmentsLeavesHolder.getListOfLeafList()) {
+ for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
+ if (targetLeafList.getName().equals(leafList.getName())) {
+ throw new LinkerException("target node " + targetNode.getName()
+ + " contains augmented leaf-list" + leafList.getName() + " in module "
+ + parent.getName());
+ }
}
- targetNodesChild = targetNodesChild.getNextSibling();
}
- augmentsChild = augmentsChild.getNextSibling();
+ } else {
+ while (augmentsChild != null) {
+ while (targetNodesChild != null) {
+ if (targetNodesChild.getName().equals(augmentsChild.getName())) {
+ throw new LinkerException("target node " + targetNode.getName()
+ + " contains augmented child node" + augmentsChild.getName() + " in module "
+ + parent.getName());
+ }
+ targetNodesChild = targetNodesChild.getNextSibling();
+ }
+ augmentsChild = augmentsChild.getNextSibling();
+ }
}
}
}
/**
- * Detects collision between target nodes and its all leaf/leaf-list or child node with
- * augmented leaf/leaf-list or child node.
+ * Detects collision between target nodes and its all leaf/leaf-list or child node with augmented leaf/leaf-list or
+ * child node.
*
* @param targetNode target node
* @param augment augment node
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index bcc5a5f..a502dd8 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -32,9 +32,9 @@
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangFeatureHolder;
import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangInput;
@@ -73,16 +73,16 @@
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
+import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
+import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
-import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
/**
* Represents implementation of resolution object which will be resolved by
@@ -128,7 +128,6 @@
*/
@SuppressWarnings("unused")
private YangResolutionInfoImpl() {
-
}
/**
@@ -153,7 +152,6 @@
throws DataModelException {
setCurReferenceResolver(dataModelRootNode);
-
/**
* Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or
* YANG leafref or YANG base or YANG identityref.
@@ -173,7 +171,6 @@
throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
"type/uses/if-feature/leafref/base/identityref");
}
-
// Push the initial entity to resolve in stack.
addInPartialResolvedStack(getEntityToResolveInfo());
@@ -191,7 +188,6 @@
throws DataModelException {
while (getPartialResolvedStack().size() != 0) {
-
/**
* Current node to resolve, it can be a YANG type or YANG uses or
* YANG if-feature or YANG leafref or YANG base or YANG identityref.
@@ -1479,6 +1475,7 @@
detectCollisionForAugmentedNode(targetNode, augment);
((YangAugmentableNode) targetNode).addAugmentation(augment);
augment.setAugmentedNode(targetNode);
+ augment.setResolveNodeInPath(xPathLinker.getResolvedNodes());
Resolvable resolvable = (Resolvable) entityToResolve;
resolvable.setResolvableStatus(RESOLVED);
} else {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
index 681a52c..e0d6c7b 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
@@ -34,9 +34,14 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTER;
+import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTRA;
+import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER;
+import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER;
+import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA;
+
/**
* Represents x-path linking.
*
@@ -44,40 +49,9 @@
*/
public class YangXpathLinker<T> {
- /**
- * Enum for prefix resolver type when augment has come in path.
- */
- private static enum PrefixResolverType {
-
- /**
- * When prefix changes from inter file to intra file.
- */
- INTER_TO_INTRA,
-
- /**
- * When prefix changes from intra file to inter file.
- */
- INTRA_TO_INTER,
-
- /**
- * When prefix changes from one inter file to other inter file.
- */
- INTER_TO_INTER,
-
- /**
- * When no prefix change occurres.
- */
- NO_PREFIX_CHANGE_FOR_INTRA,
-
- /**
- * When no prefix change occurres.
- */
- NO_PREFIX_CHANGE_FOR_INTER
- }
-
private List<YangAtomicPath> absPaths;
private YangNode rootNode;
- private PrefixResolverType type;
+ private Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes;
private String curPrefix;
private Map<YangAtomicPath, YangNode> resolvedNodes;
@@ -90,6 +64,34 @@
}
/**
+ * Returns prefix resolver list.
+ *
+ * @return prefix resolver list
+ */
+ public Map<YangAtomicPath, PrefixResolverType> getPrefixResolverTypes() {
+ return prefixResolverTypes;
+ }
+
+ /**
+ * Sets prefix resolver list.
+ *
+ * @param prefixResolverTypes prefix resolver list.
+ */
+ public void setPrefixResolverTypes(Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes) {
+ this.prefixResolverTypes = prefixResolverTypes;
+ }
+
+ /**
+ * Adds to the prefix resolver type map.
+ *
+ * @param type resolver type
+ * @param path absolute path
+ */
+ private void addToPrefixResolverList(PrefixResolverType type, YangAtomicPath path) {
+ getPrefixResolverTypes().put(path, type);
+ }
+
+ /**
* Returns list of target nodes paths.
*
* @return target nodes paths
@@ -144,24 +146,6 @@
}
/**
- * Returns prefix resolver type.
- *
- * @return prefix resolver type
- */
- private PrefixResolverType getPrefixResolverType() {
- return type;
- }
-
- /**
- * Sets prefix resolver type.
- *
- * @param type prefix resolver type
- */
- private void setPrefixResolverType(PrefixResolverType type) {
- this.type = type;
- }
-
- /**
* Returns resolved nodes.
*
* @return resolved nodes
@@ -211,13 +195,15 @@
* Process absolute node path for target leaf.
*
* @param absPaths absolute path node list
- * @param root root node
+ * @param root root node
* @return linked target node
*/
- public T processLeafRefXpathLinking(List<YangAtomicPath> absPaths, YangNode root) {
+ T processLeafRefXpathLinking(List<YangAtomicPath> absPaths, YangNode root) {
YangNode targetNode = null;
setRootNode(root);
+ setPrefixResolverTypes(new HashMap<>());
+ parsePrefixResolverList(absPaths);
YangAtomicPath leafRefPath = absPaths.get(absPaths.size() - 1);
// When leaf-ref path contains only one absolute path.
@@ -230,7 +216,7 @@
targetNode = parseData(root);
}
if (targetNode == null) {
- targetNode = parsePath(getIncludedNode(root));
+ targetNode = searchInSubModule(root);
}
if (targetNode != null) {
@@ -270,18 +256,20 @@
* Process absolute node path linking for augment.
*
* @param absPaths absolute path node list
- * @param root root node
+ * @param root root node
* @return linked target node
*/
public YangNode processAugmentXpathLinking(List<YangAtomicPath> absPaths, YangNode root) {
setAbsPaths(absPaths);
setRootNode(root);
+ setPrefixResolverTypes(new HashMap<>());
+ parsePrefixResolverList(absPaths);
YangNode targetNode = parseData(root);
if (targetNode == null) {
- targetNode = parsePath(getIncludedNode(root));
+ targetNode = searchInSubModule(root);
}
return targetNode;
@@ -291,7 +279,7 @@
* Searches for the referred leaf in target node.
*
* @param targetNode target node
- * @param leafName leaf name
+ * @param leafName leaf name
* @return target leaf
*/
private YangLeaf searchReferredLeaf(YangNode targetNode, String leafName) {
@@ -312,7 +300,7 @@
/**
* Searches for the referred leaf-list in target node.
*
- * @param targetNode target node
+ * @param targetNode target node
* @param leafListName leaf-list name
* @return target leaf-list
*/
@@ -363,20 +351,9 @@
YangAtomicPath tempPath = pathIterator.next();
setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
int index = 0;
- YangNode tempAugment = null;
+ YangNode tempAugment;
do {
- if (tempNode instanceof YangUses) {
- tempNode = handleUsesNode(tempNode, tempPath.getNodeIdentifier());
- if (pathIterator.hasNext()) {
- tempPath = pathIterator.next();
- index++;
- } else {
- addToResolvedNodes(tempPath, tempNode);
- return tempNode;
- }
- }
-
if (tempPath.getNodeIdentifier().getPrefix() == null) {
tempAugment = resolveIntraFileAugment(tempPath, root);
} else {
@@ -412,15 +389,24 @@
* Resolves intra file augment linking.
*
* @param tempPath temporary absolute path
- * @param root root node
+ * @param root root node
* @return linked target node
*/
private YangNode resolveIntraFileAugment(YangAtomicPath tempPath, YangNode root) {
- YangNode tempAugment = null;
- setPrefixResolverType(PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA);
+ YangNode tempAugment;
if (getCurPrefix() != tempPath.getNodeIdentifier().getPrefix()) {
- setPrefixResolverType(PrefixResolverType.INTRA_TO_INTER);
- root = getIncludedNode(getRootNode());
+ root = getIncludedNode(getRootNode(), tempPath.getNodeIdentifier().getName());
+ if (root == null) {
+ root = getIncludedNode(getRootNode(), getAugmentNodeIdentifier(tempPath.getNodeIdentifier(), absPaths,
+ getRootNode()));
+ if (root == null) {
+ root = getRootNode();
+ }
+ }
+ } else {
+ if (getCurPrefix() != null) {
+ root = getImportedNode(root, tempPath.getNodeIdentifier());
+ }
}
setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
@@ -435,24 +421,18 @@
* Resolves inter file augment linking.
*
* @param tempPath temporary absolute path
- * @param root root node
+ * @param root root node
* @return linked target node
*/
private YangNode resolveInterFileAugment(YangAtomicPath tempPath, YangNode root) {
- YangNode tempAugment = null;
- if (tempPath.getNodeIdentifier().getPrefix().equals(getCurPrefix())) {
- setPrefixResolverType(PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER);
- } else {
+ YangNode tempAugment;
+ if (!tempPath.getNodeIdentifier().getPrefix().equals(getCurPrefix())) {
setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
- setPrefixResolverType(PrefixResolverType.INTER_TO_INTER);
- if (getCurPrefix() == null) {
- setPrefixResolverType(PrefixResolverType.INTER_TO_INTRA);
- }
root = getImportedNode(getRootNode(), tempPath.getNodeIdentifier());
}
tempAugment = getAugment(tempPath.getNodeIdentifier(), root, getAbsPaths());
- if (tempAugment == null && getPrefixResolverType().equals(PrefixResolverType.INTER_TO_INTER)) {
+ if (tempAugment == null) {
return resolveInterToInterFileAugment(root);
}
return tempAugment;
@@ -494,8 +474,9 @@
/**
* Searches for the augment node in imported module when prefix has changed from
* inter file to inter file.
+ *
* @param nodeId node id
- * @param index index
+ * @param index index
* @return true if found
*/
private boolean searchForAugmentInImportedNode(YangNodeIdentifier nodeId, int index) {
@@ -507,11 +488,11 @@
* Returns augment node.
*
* @param tempNodeId temporary absolute path id
- * @param root root node
+ * @param root root node
* @return linked target node
*/
private YangNode getAugment(YangNodeIdentifier tempNodeId, YangNode root, List<YangAtomicPath> absPaths) {
- String augmentName = getAugmentNodeIdentifier(tempNodeId, absPaths);
+ String augmentName = getAugmentNodeIdentifier(tempNodeId, absPaths, root);
if (augmentName != null) {
return searchAugmentNode(root, augmentName);
}
@@ -521,13 +502,13 @@
/**
* Process linking using import list.
*
- * @param root root node
+ * @param root root node
* @param nodeId node identifier
* @return linked target node
*/
private YangNode getImportedNode(YangNode root, YangNodeIdentifier nodeId) {
- List<YangImport> importList = new ArrayList<>();
+ List<YangImport> importList;
if (root instanceof YangModule) {
importList = ((YangModule) root).getImportList();
@@ -545,14 +526,39 @@
}
/**
- * Process linking using include list.
+ * Searches in sub-module node.
*
* @param root root node
+ * @return target linked node
+ */
+ private YangNode searchInSubModule(YangNode root) {
+ List<YangInclude> includeList;
+ YangNode tempNode;
+ if (root instanceof YangModule) {
+ includeList = ((YangModule) root).getIncludeList();
+ } else {
+ includeList = ((YangSubModule) root).getIncludeList();
+ }
+
+ for (YangInclude included : includeList) {
+ tempNode = parseData(included.getIncludedNode());
+ if (tempNode != null) {
+ return tempNode;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Process linking using include list.
+ *
+ * @param root root node
+ * @param tempPathName temporary path node name
* @return linked target node
*/
- private YangNode getIncludedNode(YangNode root) {
+ private YangNode getIncludedNode(YangNode root, String tempPathName) {
- List<YangInclude> includeList = new ArrayList<>();
+ List<YangInclude> includeList;
if (root instanceof YangModule) {
includeList = ((YangModule) root).getIncludeList();
@@ -561,34 +567,84 @@
}
for (YangInclude included : includeList) {
- return included.getIncludedNode();
+ if (verifyChildNode(included.getIncludedNode(), tempPathName)) {
+ return included.getIncludedNode();
+ }
}
- return root;
+ return null;
}
/**
- * Returns augments node id.
+ * Verifies for child nodes in sub module.
*
- * @param nodeId node identifier
- * @return augment node id
+ * @param node submodule node
+ * @param name name of child node
+ * @return true if child node found
*/
- private String getAugmentNodeIdentifier(YangNodeIdentifier nodeId, List<YangAtomicPath> absPaths) {
+ private boolean verifyChildNode(YangNode node, String name) {
+ node = node.getChild();
+ while (node != null) {
+ if (node.getName().equals(name)) {
+ return true;
+ }
+ node = node.getNextSibling();
+ }
+ return false;
+ }
+
+
+ /**
+ * Returns augment's node id.
+ *
+ * @param nodeId node identifier
+ * @param absPaths absolute paths
+ * @param root root node
+ * @return augment's node id
+ */
+ private String getAugmentNodeIdentifier(YangNodeIdentifier nodeId, List<YangAtomicPath> absPaths, YangNode root) {
Iterator<YangAtomicPath> nodeIdIterator = absPaths.iterator();
- YangAtomicPath tempNodeId = null;
+ YangAtomicPath tempNodeId;
StringBuilder builder = new StringBuilder();
+ String id;
+ PrefixResolverType type;
while (nodeIdIterator.hasNext()) {
tempNodeId = nodeIdIterator.next();
if (!tempNodeId.getNodeIdentifier().equals(nodeId)) {
- if (tempNodeId.getNodeIdentifier().getPrefix() != null
- && (getPrefixResolverType().equals(PrefixResolverType.INTER_TO_INTER)
- || getPrefixResolverType().equals(PrefixResolverType.INTRA_TO_INTER))) {
- builder.append("/" + tempNodeId.getNodeIdentifier().getPrefix());
- builder.append(":" + tempNodeId.getNodeIdentifier().getName());
- } else {
- builder.append("/" + tempNodeId.getNodeIdentifier().getName());
+ type = getPrefixResolverTypes().get(tempNodeId);
+ switch (type) {
+ case INTER_TO_INTRA:
+ id = "/" + tempNodeId.getNodeIdentifier().getName();
+ break;
+ case INTRA_TO_INTER:
+ if (!getRootsPrefix(root).equals(tempNodeId.getNodeIdentifier().getPrefix())) {
+ id = "/" + tempNodeId.getNodeIdentifier().getPrefix() + ":" + tempNodeId.getNodeIdentifier()
+ .getName();
+ } else {
+ id = "/" + tempNodeId.getNodeIdentifier().getName();
+ }
+ break;
+ case INTER_TO_INTER:
+ id = "/" + tempNodeId.getNodeIdentifier().getPrefix() + ":" + tempNodeId.getNodeIdentifier()
+ .getName();
+ break;
+ case NO_PREFIX_CHANGE_FOR_INTRA:
+ id = "/" + tempNodeId.getNodeIdentifier().getName();
+ break;
+ case NO_PREFIX_CHANGE_FOR_INTER:
+ if (!getRootsPrefix(root).equals(tempNodeId.getNodeIdentifier().getPrefix())) {
+ id = "/" + tempNodeId.getNodeIdentifier().getPrefix() + ":" + tempNodeId.getNodeIdentifier()
+ .getName();
+ } else {
+ id = "/" + tempNodeId.getNodeIdentifier().getName();
+ }
+ break;
+ default:
+ id = "/" + tempNodeId.getNodeIdentifier().getName();
+ break;
}
+ builder.append(id);
} else {
return builder.toString();
}
@@ -599,15 +655,16 @@
/**
* Searches augment node in root node.
*
- * @param node root node
+ * @param node root node
* @param tempNodeId node identifier
* @return target augment node
*/
+
private YangNode searchAugmentNode(YangNode node, String tempNodeId) {
node = node.getChild();
while (node != null) {
if (node instanceof YangAugment) {
- if (((YangAugment) node).getName().equals(tempNodeId)) {
+ if (node.getName().equals(tempNodeId)) {
return node;
}
}
@@ -620,7 +677,7 @@
* Validates for target node if target node found or not.
*
* @param tempNode temporary node
- * @param index current index of list
+ * @param index current index of list
* @return false if target node found
*/
private boolean validate(YangNode tempNode, int index) {
@@ -628,11 +685,11 @@
int size = getAbsPaths().size();
if (tempNode != null && index != size) {
return true;
- } else if (tempNode != null && index == size) {
+ } else if (tempNode != null) {
return false;
// this is your target node.
- } else if (tempNode == null && index != size) {
- return false;
+ } else if (index != size) {
+ return true;
// this could be in submodule as well.
}
return false;
@@ -641,7 +698,7 @@
/**
* Searches target node in root node.
*
- * @param node root node
+ * @param node root node
* @param curNodeId YANG node identifier
* @return linked target node
*/
@@ -661,40 +718,6 @@
}
/**
- * Handles linking when uses node is present.
- *
- * @param node uses node
- * @param curNodeId current node id
- * @return linked node
- */
- private YangNode handleUsesNode(YangNode node, YangNodeIdentifier curNodeId) {
- YangNode tempNode = null;
- tempNode = searchInUsesNode((YangUses) node, curNodeId);
- if (tempNode != null) {
- return tempNode;
- }
- return null;
- }
-
- /**
- * Searches target node in uses resolved list.
- *
- * @param uses uses node
- * @param curNodeId current node id
- * @return linked target node
- */
- private YangNode searchInUsesNode(YangUses uses, YangNodeIdentifier curNodeId) {
-
- List<YangNode> resolvedNodes = uses.getUsesResolvedNodeList();
- for (YangNode node : resolvedNodes) {
- if (node.getName().equals(curNodeId.getName())) {
- return node;
- }
- }
- return null;
- }
-
- /**
* Returns root prefix.
*
* @param root root node
@@ -708,4 +731,39 @@
}
}
+ /**
+ * Resolves prefix and provides prefix resolver list.
+ *
+ * @param absolutePaths absolute paths
+ */
+ private void parsePrefixResolverList(List<YangAtomicPath> absolutePaths) {
+ Iterator<YangAtomicPath> pathIterator = absolutePaths.iterator();
+ YangAtomicPath absPath;
+ String prePrefix;
+ String curPrefix = null;
+ while (pathIterator.hasNext()) {
+ prePrefix = curPrefix;
+ absPath = pathIterator.next();
+ curPrefix = absPath.getNodeIdentifier().getPrefix();
+ if (curPrefix != null) {
+ if (!curPrefix.equals(prePrefix)) {
+ if (prePrefix != null) {
+ addToPrefixResolverList(INTER_TO_INTER, absPath);
+ } else {
+ addToPrefixResolverList(INTRA_TO_INTER, absPath);
+ }
+ } else {
+ addToPrefixResolverList(NO_PREFIX_CHANGE_FOR_INTER, absPath);
+ }
+ } else {
+ if (prePrefix != null) {
+ addToPrefixResolverList(INTER_TO_INTRA, absPath);
+ } else {
+ addToPrefixResolverList(NO_PREFIX_CHANGE_FOR_INTRA, absPath);
+ }
+ }
+ }
+
+ }
+
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index 3389659..e9eafbf 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -21,11 +21,14 @@
import java.util.TreeSet;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
+import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
@@ -33,6 +36,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
@@ -248,4 +252,31 @@
public String getEventListenerImport() {
return IMPORT + ONOS_EVENT_PKG + PERIOD + EVENT_LISTENER + SEMI_COLAN + NEW_LINE;
}
+
+ /**
+ * Returns import string for map class.
+ *
+ * @return import string for map class
+ */
+ public String getMapImport() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + MAP + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import string for hash map class.
+ *
+ * @return import string for hash map class
+ */
+ public String getHashMapImport() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + HASH_MAP + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import string for hash map class.
+ *
+ * @return import string for hash map class
+ */
+ public String getYangAugmentedInfoImport() {
+ return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index beb8de0..22d9539 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -189,8 +189,6 @@
if (fileType == GENERATE_ENUM_CLASS) {
getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
}
-
- freeTemporaryResources(false);
}
/**
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index bbc346d..d8bba5e 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -17,16 +17,18 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
@@ -40,6 +42,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
@@ -60,10 +63,12 @@
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedConstructor;
@@ -74,14 +79,11 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
@@ -100,9 +102,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
@@ -113,38 +115,12 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
/**
- * Represents implementation of java code fragments temporary implementations.
- * Manages the common temp file required for Java file(s) generated.
+ * Represents implementation of java code fragments temporary implementations. Manages the common temp file required for
+ * Java file(s) generated.
*/
public class TempJavaFragmentFiles {
/**
- * Information about the java files being generated.
- */
- private JavaFileInfo javaFileInfo;
-
- /**
- * Imported class info.
- */
- private JavaImportData javaImportData;
-
- /**
- * The variable which guides the types of temporary files generated using
- * the temporary generated file types mask.
- */
- private int generatedTempFiles;
-
- /**
- * Absolute path where the target java file needs to be generated.
- */
- private String absoluteDirPath;
-
- /**
- * Contains all the interface(s)/class name which will be extended by generated files.
- */
- private JavaExtendsListHolder javaExtendsListHolder;
-
- /**
* File type extension for java classes.
*/
private static final String JAVA_FILE_EXTENSION = ".java";
@@ -228,6 +204,32 @@
* File name for augment copy constructor method.
*/
private static final String AUGMENT_CONSTRUCTOR_FILE_NAME = "AugmentConstructor";
+
+ /**
+ * Information about the java files being generated.
+ */
+ private JavaFileInfo javaFileInfo;
+
+ /**
+ * Imported class info.
+ */
+ private JavaImportData javaImportData;
+
+ /**
+ * The variable which guides the types of temporary files generated using the temporary generated file types mask.
+ */
+ private int generatedTempFiles;
+
+ /**
+ * Absolute path where the target java file needs to be generated.
+ */
+ private String absoluteDirPath;
+
+ /**
+ * Contains all the interface(s)/class name which will be extended by generated files.
+ */
+ private JavaExtendsListHolder javaExtendsListHolder;
+
/**
* Java file handle for interface file.
*/
@@ -308,6 +310,245 @@
*/
private File augmentConstructorImplTempFileHandle;
+ TempJavaFragmentFiles() {
+ }
+
+ /**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated java file information
+ * @throws IOException when fails to create new file handle
+ */
+ TempJavaFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
+ setJavaImportData(new JavaImportData());
+ setJavaFileInfo(javaFileInfo);
+ setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
+ getJavaFileInfo().getPackageFilePath()));
+
+ /*
+ * Initialize getter when generation file type matches to interface
+ * mask.
+ */
+ if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
+ addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
+ }
+
+ /*
+ * Initialize getter and setter when generation file type matches to
+ * builder interface mask.
+ */
+ if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
+ addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
+ addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
+ }
+
+ /*
+ * Initialize getterImpl, setterImpl and attributes when generation file
+ * type matches to builder class mask.
+ */
+ if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
+ addGeneratedTempFile(ATTRIBUTES_MASK);
+ addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(AUGMENTE_CLASS_CONSTRUCTOR_MASK);
+ }
+
+ /*
+ * Initialize getterImpl, attributes, constructor, hash code, equals and
+ * to strings when generation file type matches to impl class mask.
+ */
+ if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
+ addGeneratedTempFile(ATTRIBUTES_MASK);
+ addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(HASH_CODE_IMPL_MASK);
+ addGeneratedTempFile(EQUALS_IMPL_MASK);
+ addGeneratedTempFile(TO_STRING_IMPL_MASK);
+ }
+
+ /*
+ * Initialize temp files to generate type class.
+ */
+ if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
+ addGeneratedTempFile(ATTRIBUTES_MASK);
+ addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(HASH_CODE_IMPL_MASK);
+ addGeneratedTempFile(EQUALS_IMPL_MASK);
+ addGeneratedTempFile(TO_STRING_IMPL_MASK);
+ addGeneratedTempFile(FROM_STRING_IMPL_MASK);
+ }
+
+ /*
+ * Initialize temp files to generate enum class.
+ */
+ if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
+ addGeneratedTempFile(FROM_STRING_IMPL_MASK);
+ }
+
+ /*
+ * Set temporary file handles.
+ */
+ if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
+ setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
+ setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
+ setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
+ setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
+ setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
+ }
+
+ if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
+ setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
+ }
+ if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
+ setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
+ }
+ if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
+ setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
+ }
+ if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
+ setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
+ }
+ if ((getGeneratedTempFiles() & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) {
+ setAugmentConstructorImplTempFileHandle(getTemporaryFileHandle(AUGMENT_CONSTRUCTOR_FILE_NAME));
+ }
+
+ }
+
+ /**
+ * Adds current node info as and attribute to the parent generated file.
+ *
+ * @param curNode current node which needs to be added as an attribute in the parent generated code
+ * @param isList is list construct
+ * @param pluginConfig plugin configurations
+ * @throws IOException IO operation exception
+ */
+ public static void addCurNodeInfoInParentTempFile(YangNode curNode,
+ boolean isList, YangPluginConfig pluginConfig)
+ throws IOException {
+ YangNode parent = getParentNodeInGenCode(curNode);
+ if (!(parent instanceof JavaCodeGenerator)) {
+ throw new TranslatorException("missing parent node to contain current node info in generated file");
+ }
+
+ if (parent instanceof YangJavaGrouping) {
+ /*
+ * In case of grouping, there is no need to add the information, it
+ * will be taken care in uses
+ */
+ return;
+ }
+ TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent)
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles();
+
+ JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
+ parent, isList, tempJavaBeanFragmentFiles);
+ if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("missing parent temp file handle");
+ }
+ getNodesInterfaceFragmentFiles(parent, javaAttributeInfo, pluginConfig);
+ }
+
+ /**
+ * Creates an attribute info object corresponding to a data model node and return it.
+ *
+ * @param curNode current data model node for which the java code generation is being handled
+ * @param targetNode target node in which the current node is an attribute
+ * @param isListNode is the current added attribute needs to be a list
+ * @param tempJavaFragmentFiles temp java fragment files
+ * @return AttributeInfo attribute details required to add in temporary files
+ */
+ public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
+ YangNode targetNode, boolean isListNode,
+ TempJavaFragmentFiles tempJavaFragmentFiles) {
+ String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
+ if (curNodeName == null) {
+ updateJavaFileInfo(curNode, null);
+ curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
+ }
+
+ /*
+ * Get the import info corresponding to the attribute for import in
+ * generated java files or qualified access
+ */
+ JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
+ getCapitalCase(curNodeName));
+ if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("Parent node does not have file info");
+ }
+ JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
+ JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
+
+ boolean isQualified;
+ if ((targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule)
+ && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)
+ || qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT)
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
+ || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
+ || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
+
+ isQualified = true;
+ } else {
+ String className;
+ if (targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule) {
+ className = getCapitalCase(fileInfo.getJavaName()) + "Service";
+ } else {
+ className = getCapitalCase(fileInfo.getJavaName());
+ }
+
+ isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
+ className, fileInfo.getPackage());
+ }
+
+ if (isListNode) {
+ parentImportData.setIfListImported(true);
+ }
+
+ return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
+ }
+
+ /**
+ * Adds java code snippet for corresponding files.
+ *
+ * @param node java node
+ * @param attr attribute info
+ * @param config plugin configurations
+ * @throws IOException when fails to do IO operations
+ */
+ public static void getNodesInterfaceFragmentFiles(YangNode node, JavaAttributeInfo attr,
+ YangPluginConfig config) throws IOException {
+ TempJavaFragmentFiles tempJavaFragmentFiles;
+ JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
+ if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
+ .getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
+ tempJavaFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
+ }
+ if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
+ tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
+ .getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles();
+ tempJavaFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
+ }
+
+ }
+
/**
* Retrieves the absolute path where the file needs to be generated.
*
@@ -320,23 +561,13 @@
/**
* Sets absolute path where the file needs to be generated.
*
- * @param absoluteDirPath absolute path where the file needs to be
- * generated.
+ * @param absoluteDirPath absolute path where the file needs to be generated.
*/
void setAbsoluteDirPath(String absoluteDirPath) {
this.absoluteDirPath = absoluteDirPath;
}
/**
- * Sets the generated java file information.
- *
- * @param javaFileInfo generated java file information
- */
- public void setJavaFileInfo(JavaFileInfo javaFileInfo) {
- this.javaFileInfo = javaFileInfo;
- }
-
- /**
* Retrieves the generated java file information.
*
* @return generated java file information
@@ -346,6 +577,15 @@
}
/**
+ * Sets the generated java file information.
+ *
+ * @param javaFileInfo generated java file information
+ */
+ public void setJavaFileInfo(JavaFileInfo javaFileInfo) {
+ this.javaFileInfo = javaFileInfo;
+ }
+
+ /**
* Retrieves the generated temp files.
*
* @return generated temp files
@@ -355,6 +595,15 @@
}
/**
+ * Sets generated file files.
+ *
+ * @param fileType generated file type
+ */
+ void setGeneratedTempFiles(int fileType) {
+ generatedTempFiles = fileType;
+ }
+
+ /**
* Clears the generated file mask.
*/
void clearGeneratedTempFileMask() {
@@ -372,15 +621,6 @@
}
/**
- * Sets generated file files.
- *
- * @param fileType generated file type
- */
- void setGeneratedTempFiles(int fileType) {
- generatedTempFiles = fileType;
- }
-
- /**
* Retrieves the generated Java files.
*
* @return generated Java files
@@ -500,138 +740,13 @@
/**
* Sets from string method's temporary file handle.
*
- * @param fromStringImplTempFileHandle from string method's temporary file
- * handle
+ * @param fromStringImplTempFileHandle from string method's temporary file handle
*/
private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
}
/**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated java file information
- * @throws IOException when fails to create new file handle
- */
- TempJavaFragmentFiles(JavaFileInfo javaFileInfo)
- throws IOException {
- setJavaExtendsListHolder(new JavaExtendsListHolder());
- setJavaImportData(new JavaImportData());
- setJavaFileInfo(javaFileInfo);
- setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
-
- /*
- * Initialize getter when generation file type matches to interface
- * mask.
- */
- if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
- addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
- }
-
- /*
- * Initialize getter and setter when generation file type matches to
- * builder interface mask.
- */
- if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
- addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
- addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
- }
-
- /*
- * Initialize getterImpl, setterImpl and attributes when generation file
- * type matches to builder class mask.
- */
- if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
- addGeneratedTempFile(ATTRIBUTES_MASK);
- addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(AUGMENTE_CLASS_CONSTRUCTOR_MASK);
- }
-
- /*
- * Initialize getterImpl, attributes, constructor, hash code, equals and
- * to strings when generation file type matches to impl class mask.
- */
- if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
- addGeneratedTempFile(ATTRIBUTES_MASK);
- addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(HASH_CODE_IMPL_MASK);
- addGeneratedTempFile(EQUALS_IMPL_MASK);
- addGeneratedTempFile(TO_STRING_IMPL_MASK);
- }
-
- /*
- * Initialize temp files to generate type class.
- */
- if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
- addGeneratedTempFile(ATTRIBUTES_MASK);
- addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(HASH_CODE_IMPL_MASK);
- addGeneratedTempFile(EQUALS_IMPL_MASK);
- addGeneratedTempFile(TO_STRING_IMPL_MASK);
- addGeneratedTempFile(FROM_STRING_IMPL_MASK);
- }
-
- /*
- * Initialize temp files to generate enum class.
- */
- if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
- addGeneratedTempFile(FROM_STRING_IMPL_MASK);
- }
- /*
- * Initialize getter and setter when generation file type matches to
- * builder interface mask.
- */
- if ((getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
- addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
- addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
- addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
- }
-
- /*
- * Set temporary file handles.
- */
- if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
- setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
- }
-
- if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
- setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
- }
-
- if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
- setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
- }
-
- if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
- setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
- }
-
- if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
- setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
- }
-
- if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
- setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
- }
- if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
- setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
- }
- if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
- setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
- }
- if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
- setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
- }
- if ((getGeneratedTempFiles() & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) {
- setAugmentConstructorImplTempFileHandle(getTemporaryFileHandle(AUGMENT_CONSTRUCTOR_FILE_NAME));
- }
-
- }
-
- /**
* Returns java file handle for interface file.
*
* @return java file handle for interface file
@@ -942,19 +1057,6 @@
}
/**
- * Adds default constructor for class.
- *
- * @param pluginCnfig plugin configurations
- * @return default constructor for class
- * @throws IOException when fails to append to file
- */
- public String addOfMethod(YangPluginConfig pluginCnfig)
- throws IOException {
- return getJavaDoc(OF_METHOD, getGeneratedJavaClassName(), false, pluginCnfig)
- + getOfMethod(getGeneratedJavaClassName(), null);
- }
-
- /**
* Adds hash code method for class.
*
* @param attr attribute info
@@ -1050,7 +1152,7 @@
/**
* Returns data from the temporary files.
*
- * @param file temporary file handle
+ * @param file temporary file handle
* @param absolutePath absolute path
* @return stored data from temporary files
* @throws IOException when failed to get data from the given file
@@ -1117,159 +1219,6 @@
}
/**
- * Adds current node info as and attribute to the parent generated file.
- *
- * @param curNode current node which needs to be added as an attribute in
- * the parent generated code
- * @param isList is list construct
- * @param pluginConfig plugin configurations
- * @throws IOException IO operation exception
- */
- public static void addCurNodeInfoInParentTempFile(YangNode curNode,
- boolean isList, YangPluginConfig pluginConfig)
- throws IOException {
- YangNode parent = getParentNodeInGenCode(curNode);
- if (!(parent instanceof JavaCodeGenerator)) {
- throw new TranslatorException("missing parent node to contain current node info in generated file");
- }
-
- if (parent instanceof YangJavaGrouping) {
- /*
- * In case of grouping, there is no need to add the information, it
- * will be taken care in uses
- */
- return;
- }
-
- JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
- parent, isList);
- if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException("missing parent temp file handle");
- }
- getNodesInterfaceFragmentFiles(parent)
- .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
- }
-
- /**
- * Adds current node info as and attribute to the parent generated file.
- *
- * @param curNode current node which needs to be added as an attribute in
- * the parent generated code
- * @param pluginConfig plugin configurations
- * @param targetNode target node to add the attribute
- * @throws IOException IO operation exception
- */
- public static void addCurNodeAsAttributeInTargetTempFile(YangNode curNode,
- YangPluginConfig pluginConfig, YangNode targetNode)
- throws IOException {
-
- if (!(targetNode instanceof JavaCodeGenerator)) {
- throw new TranslatorException("invalid target node to generated file");
- }
-
- if (targetNode instanceof YangJavaGrouping) {
- /*
- * In case of grouping, there is no need to add the information, it
- * will be taken care in uses
- */
- return;
- }
-
- boolean isList = curNode instanceof YangList;
-
- JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
- targetNode, isList);
- if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException("missing target node's temp file handle");
- }
- getNodesInterfaceFragmentFiles(targetNode)
- .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
- }
-
- /**
- * Creates an attribute info object corresponding to a data model node and
- * return it.
- *
- * @param curNode current data model node for which the java code generation
- * is being handled
- * @param targetNode target node in which the current node is an attribute
- * @param isListNode is the current added attribute needs to be a list
- * @return AttributeInfo attribute details required to add in temporary
- * files
- */
- public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
- YangNode targetNode, boolean isListNode) {
- String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
- if (curNodeName == null) {
- updateJavaFileInfo(curNode, null);
- curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
- }
-
- /*
- * Get the import info corresponding to the attribute for import in
- * generated java files or qualified access
- */
- JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
- getCapitalCase(curNodeName));
- if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException("Parent node does not have file info");
- }
- TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(targetNode);
- JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
- JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
-
- boolean isQualified;
- if ((targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule)
- && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)
- || qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT)
- || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
- || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
- || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
- || qualifiedTypeInfo.getClassInfo().contentEquals(REFERENCE))
- || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
- || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
-
- isQualified = true;
- } else {
- String className;
- if (targetNode instanceof YangJavaModule || targetNode instanceof YangJavaSubModule) {
- className = getCapitalCase(fileInfo.getJavaName()) + "Service";
- } else {
- className = getCapitalCase(fileInfo.getJavaName());
- }
-
- isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
- className, fileInfo.getPackage());
- }
-
- if (isListNode) {
- parentImportData.setIfListImported(true);
- }
-
- return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
- }
-
- /**
- * Returns interface fragment files for node.
- *
- * @param node YANG node
- * @return interface fragment files for node
- */
- public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) {
- TempJavaFragmentFiles tempJavaFragmentFiles;
- if (node instanceof RpcNotificationContainer) {
- tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
- .getTempJavaCodeFragmentFiles()
- .getServiceTempFiles();
- } else {
- tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles();
- }
- return tempJavaFragmentFiles;
- }
-
- /**
* Adds parent's info to current node import list.
*
* @param curNode current node for which import list needs to be updated
@@ -1378,8 +1327,7 @@
}
/**
- * Adds all the leaves in the current data model node as part of the
- * generated temporary file.
+ * Adds all the leaves in the current data model node as part of the generated temporary file.
*
* @param curNode java file info of the generated file
* @param yangPluginConfig plugin config
@@ -1399,8 +1347,7 @@
/**
* Adds the new attribute info to the target generated temporary files.
*
- * @param newAttrInfo the attribute info that needs to be added to temporary
- * files
+ * @param newAttrInfo the attribute info that needs to be added to temporary files
* @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
@@ -1489,8 +1436,12 @@
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
- List<String> imports = new ArrayList<>();
- imports = getJavaImportData().getImports();
+
+ if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
+ addResolvedAugmentedDataNodeImports(curNode);
+ }
+ List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
+ .getJavaImportData().getImports();
JavaFileInfo curInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
@@ -1543,7 +1494,10 @@
}
if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
if (isAttributePresent()) {
- addImportsToStringAndHasCodeMethods(curNode, imports);
+ addImportsToStringAndHasCodeMethods(imports);
+ }
+ if (curNode instanceof YangAugmentableNode) {
+ addImportsForAugmentableClass(imports);
}
sortImports(imports);
/*
@@ -1586,6 +1540,8 @@
throws IOException {
YangJavaAugment augment = (YangJavaAugment) curNode;
+ TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles();
YangNode augmentedNode = augment.getAugmentedNode();
if (augmentedNode instanceof YangLeavesHolder) {
YangLeavesHolder holder = (YangLeavesHolder) augmentedNode;
@@ -1610,7 +1566,10 @@
if (augmentedNode instanceof YangList) {
isList = true;
}
- addAugmentConstructor(getCurNodeAsAttributeInTarget(augmentedNode, augment, isList), pluginConfig);
+ if (!(augmentedNode instanceof YangUses)) {
+ addAugmentConstructor(getCurNodeAsAttributeInTarget(augmentedNode, augment, isList,
+ tempJavaBeanFragmentFiles), pluginConfig);
+ }
augmentedNode = augmentedNode.getNextSibling();
}
@@ -1619,14 +1578,23 @@
/**
* Adds imports for ToString and HashCodeMethod.
*
- * @param curNode current YANG node
* @param imports import list
- * @return import list
*/
- public List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) {
+ public void addImportsToStringAndHasCodeMethods(List<String> imports) {
imports.add(getJavaImportData().getImportForHashAndEquals());
imports.add(getJavaImportData().getImportForToString());
- return imports;
+ }
+
+
+ /**
+ * Adds import for map and hash map.
+ *
+ * @param imports import list
+ */
+ public void addImportsForAugmentableClass(List<String> imports) {
+ imports.add(getJavaImportData().getHashMapImport());
+ imports.add(getJavaImportData().getMapImport());
+ imports.add(getJavaImportData().getYangAugmentedInfoImport());
}
/**
@@ -1636,7 +1604,7 @@
* @return import for class
*/
private List<String> removeAugmentedImport(List<String> imports, JavaQualifiedTypeInfo augmentedInfo) {
- String augmentedNodeImport = null;
+ String augmentedNodeImport;
if (imports != null && augmentedInfo != null) {
augmentedNodeImport = IMPORT + augmentedInfo.getPkgInfo() + PERIOD + getCapitalCase(DEFAULT)
+ augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
@@ -1646,6 +1614,7 @@
+ augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
+ BUILDER + SEMI_COLAN + NEW_LINE;
imports.remove(augmentedNodeImport);
+ imports.remove(getJavaImportData().getYangAugmentedInfoImport());
}
return imports;
}
@@ -1668,9 +1637,8 @@
/**
* Removes all temporary file handles.
*
- * @param isErrorOccurred when translator fails to generate java files we
- * need to close all open file handles include temporary files
- * and java files.
+ * @param isErrorOccurred when translator fails to generate java files we need to close all open file handles
+ * include temporary files and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
@@ -1719,8 +1687,8 @@
}
/**
- * Returns if the attribute needs to be accessed in a qualified manner or
- * not, if it needs to be imported, then the same needs to be done.
+ * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the
+ * same needs to be done.
*
* @param importInfo import info for the current attribute being added
* @return status of the qualified access to the attribute
@@ -1732,16 +1700,4 @@
getJavaFileInfo().getPackage());
}
- /**
- * Checks if the import info is same as the package of the current generated
- * java file.
- *
- * @param importInfo import info for an attribute
- * @return true if the import info is same as the current nodes package
- * false otherwise
- */
- public boolean isImportPkgEqualCurNodePkg(JavaQualifiedTypeInfo importInfo) {
- return getJavaFileInfo().getPackage()
- .contentEquals(importInfo.getPkgInfo());
- }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
index 9cbe1fc..af2ed42 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
@@ -22,9 +22,9 @@
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
@@ -38,6 +38,8 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
+import static org.onosproject.yangutils.translator.tojava.utils.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.generateEventFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
@@ -45,17 +47,12 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
+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.getSmallCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
-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.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
@@ -66,22 +63,30 @@
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
- * Represents implementation of java service code fragments temporary implementations.
- * Maintains the temp files required specific for service and manager java snippet generation.
+ * Represents implementation of java service code fragments temporary implementations. Maintains the temp files required
+ * specific for service and manager java snippet generation.
*/
public class TempJavaServiceFragmentFiles
extends TempJavaFragmentFiles {
/**
+ * File name for generated class file for special type like union, typedef suffix.
+ */
+ public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
+ /**
* File name for rpc method.
*/
private static final String RPC_INTERFACE_FILE_NAME = "Rpc";
@@ -139,13 +144,6 @@
* suffix.
*/
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
-
- /**
- * File name for generated class file for special type like union, typedef
- * suffix.
- */
- public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
-
private static final String JAVA_FILE_EXTENSION = ".java";
/**
@@ -209,6 +207,65 @@
private File eventSubjectSetterTempFileHandle;
/**
+ * Creates an instance of temporary java code fragment.
+ *
+ * @param javaFileInfo generated file information
+ * @throws IOException when fails to create new file handle
+ */
+ public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo)
+ throws IOException {
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
+ setJavaImportData(new JavaImportData());
+ setJavaFileInfo(javaFileInfo);
+ setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
+ getJavaFileInfo().getPackageFilePath()));
+ addGeneratedTempFile(RPC_INTERFACE_MASK);
+ addGeneratedTempFile(RPC_IMPL_MASK);
+
+ addGeneratedTempFile(EVENT_ENUM_MASK);
+ addGeneratedTempFile(EVENT_METHOD_MASK);
+ addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK);
+ addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
+ addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
+
+ setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
+ setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
+
+ setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME));
+ setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME));
+ setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME));
+ setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME));
+ setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME));
+ }
+
+ /*Adds event method contents to event file.*/
+ private static String getEventFileContents(String eventClassname, String classname) {
+ return "\n" +
+ " /**\n" +
+ " * Creates " + classname + " event with type and subject.\n" +
+ " *\n" +
+ " * @param type event type\n" +
+ " * @param subject subject " + classname + "\n" +
+ " */\n" +
+ " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
+ " super(type, subject);\n" +
+ " }\n" +
+ "\n" +
+ " /**\n" +
+ " * Creates " + classname + " event with type, subject and time.\n" +
+ " *\n" +
+ " * @param type event type\n" +
+ " * @param subject subject " + classname + "\n" +
+ " * @param time time of event\n" +
+ " */\n" +
+ " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
+ + " subject, long time) {\n" +
+ " super(type, subject, time);\n" +
+ " }\n" +
+ "\n";
+ }
+
+ /**
* Returns rpc method's java file handle.
*
* @return java file handle
@@ -335,35 +392,6 @@
}
/**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated file information
- * @throws IOException when fails to create new file handle
- */
- public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo)
- throws IOException {
- super(javaFileInfo);
-
- addGeneratedTempFile(RPC_INTERFACE_MASK);
- addGeneratedTempFile(RPC_IMPL_MASK);
-
- addGeneratedTempFile(EVENT_ENUM_MASK);
- addGeneratedTempFile(EVENT_METHOD_MASK);
- addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK);
- addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
- addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
-
- setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
- setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
-
- setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME));
- setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME));
- setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME));
- setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME));
- setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME));
- }
-
- /**
* Constructs java code exit.
*
* @param fileType generated file type
@@ -373,7 +401,8 @@
@Override
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
- List<String> imports = getJavaImportData().getImports();
+ List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles()
+ .getJavaImportData().getImports();
createPackage(curNode);
@@ -395,7 +424,7 @@
* Creates rpc interface file.
*/
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
- generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
+ generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports);
if (isNotification) {
addListenersImport(curNode, imports, false, LISTENER_SERVICE);
@@ -406,7 +435,7 @@
* Create builder class file.
*/
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
- generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent());
+ generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode);
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
if (isNotification) {
@@ -436,8 +465,8 @@
* @throws IOException IO operation fail
*/
private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
- JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
- String rpcName)
+ JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
+ String rpcName)
throws IOException {
String rpcInput = EMPTY_STRING;
String rpcOutput = VOID;
@@ -468,8 +497,8 @@
* @throws IOException IO operation fail
*/
public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
- JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
- String rpcName)
+ JavaAttributeInfo javaAttributeInfoOfOutput,
+ YangPluginConfig pluginConfig, String rpcName)
throws IOException {
addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName);
}
@@ -477,7 +506,7 @@
/**
* Constructs java code exit.
*
- * @param curNode current YANG node
+ * @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventJavaFile(YangNode curNode)
@@ -534,7 +563,7 @@
/**
* Constructs java code exit.
*
- * @param curNode current YANG node
+ * @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventSubjectJavaFile(YangNode curNode)
@@ -558,9 +587,8 @@
/**
* Removes all temporary file handles.
*
- * @param isErrorOccurred when translator fails to generate java files we
- * need to close all open file handles include temporary files
- * and java files.
+ * @param isErrorOccurred when translator fails to generate java files we need to close all open file handles
+ * include temporary files and java files.
* @throws IOException when failed to delete the temporary files
*/
@Override
@@ -691,9 +719,9 @@
public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
throws IOException {
- String currentInfo = getCapitalCase(getCamelCase(((YangNotification) curNode).getName(),
+ String currentInfo = getCapitalCase(getCamelCase(curNode.getName(),
pluginConfig.getConflictResolver()));
- String notificationName = ((YangNotification) curNode).getName();
+ String notificationName = curNode.getName();
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(currentInfo));
@@ -722,33 +750,6 @@
appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className));
}
- /*Adds event method contents to event file.*/
- private static String getEventFileContents(String eventClassname, String classname) {
- return "\n" +
- " /**\n" +
- " * Creates " + classname + " event with type and subject.\n" +
- " *\n" +
- " * @param type event type\n" +
- " * @param subject subject " + classname + "\n" +
- " */\n" +
- " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
- " super(type, subject);\n" +
- " }\n" +
- "\n" +
- " /**\n" +
- " * Creates " + classname + " event with type, subject and time.\n" +
- " *\n" +
- " * @param type event type\n" +
- " * @param subject subject " + classname + "\n" +
- " * @param time time of event\n" +
- " */\n" +
- " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
- + " subject, long time) {\n" +
- " super(type, subject, time);\n" +
- " }\n" +
- "\n";
- }
-
/*Adds events to event subject file.*/
private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
index 69c9b1d..d693381 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
@@ -332,7 +332,7 @@
* Creates type def class file.
*/
if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
- addImportsToStringAndHasCodeMethods(curNode, imports);
+ addImportsToStringAndHasCodeMethods(imports);
setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
}
@@ -340,7 +340,7 @@
* Creates type class file.
*/
if ((fileType & GENERATE_UNION_CLASS) != 0) {
- addImportsToStringAndHasCodeMethods(curNode, imports);
+ addImportsToStringAndHasCodeMethods(imports);
setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports);
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModelUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
similarity index 86%
rename from plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModelUtils.java
rename to plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
index 582b9b5..19314e2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModelUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yangutils.translator.tojava.javamodel;
+package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
@@ -26,16 +26,17 @@
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
@@ -50,6 +51,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
@@ -75,7 +78,6 @@
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
-
if (javaCodeGeneratorInfo instanceof YangJavaAugment) {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(((YangJavaAugment) javaCodeGeneratorInfo).getAugmentClassName());
@@ -138,11 +140,11 @@
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
- if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
+ if (javaCodeGeneratorInfo instanceof YangJavaModule) {
if (!((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
}
- } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
+ } else if (javaCodeGeneratorInfo instanceof YangJavaSubModule) {
if (!((YangJavaSubModule) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
updateNotificaitonNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
}
@@ -186,6 +188,7 @@
* Process generate code entry of YANG node.
*
* @param javaCodeGeneratorInfo YANG java file info node
+ * @param yangPluginConfig plugin configurations
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
@@ -209,14 +212,14 @@
private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
- if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
+ if (javaCodeGeneratorInfo instanceof YangJavaModule) {
for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles()
.addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
}
}
- if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
+ if (javaCodeGeneratorInfo instanceof YangJavaSubModule) {
for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo)
.getNotificationNodes()) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
@@ -267,8 +270,9 @@
}
generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
-
+ TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles();
if (javaCodeGeneratorInfo instanceof YangJavaAugment) {
+
JavaQualifiedTypeInfo augmentedBuilderInfo = new JavaQualifiedTypeInfo();
JavaQualifiedTypeInfo augmentedBuilderClassInfo = new JavaQualifiedTypeInfo();
JavaQualifiedTypeInfo augmentedClassInfo = new JavaQualifiedTypeInfo();
@@ -283,8 +287,10 @@
} else {
name = getCapitalCase(getCamelCase(augmentedNode.getName(), yangPlugin.getConflictResolver()));
augmentedClassInfo.setClassInfo(name);
- augmentedClassInfo.setPkgInfo(getAugmentedNodesPackage(augmentedNode, yangPlugin));
+ augmentedClassInfo.setPkgInfo(getAugmentedNodesPackage(augmentedNode,
+ yangPlugin));
}
+
augmentedBuilderInfo.setClassInfo(name + PERIOD + name + BUILDER);
augmentedBuilderInfo.setPkgInfo(augmentedClassInfo.getPkgInfo());
augmentedBuilderClassInfo.setClassInfo(getCapitalCase(DEFAULT) + name + PERIOD + name + BUILDER);
@@ -296,13 +302,25 @@
((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedBuilderClassInfo);
((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedClassInfo);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(augmentedClassInfo, (YangNode) javaCodeGeneratorInfo);
+ .addToExtendsList(augmentedClassInfo, (YangNode) javaCodeGeneratorInfo,
+ tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(augmentedBuilderInfo, (YangNode) javaCodeGeneratorInfo);
+ .addToExtendsList(augmentedBuilderInfo, (YangNode) javaCodeGeneratorInfo,
+ tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(augmentedImplInfo, (YangNode) javaCodeGeneratorInfo);
+ .addToExtendsList(augmentedImplInfo, (YangNode) javaCodeGeneratorInfo,
+ tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(augmentedBuilderClassInfo, (YangNode) javaCodeGeneratorInfo);
+ .addToExtendsList(augmentedBuilderClassInfo, (YangNode) javaCodeGeneratorInfo,
+ tempJavaCodeFragmentFiles.getBeanTempFiles());
+
+ JavaQualifiedTypeInfo yangAugmentedInfo = new JavaQualifiedTypeInfo();
+ yangAugmentedInfo.setClassInfo(YANG_AUGMENTED_INFO);
+ yangAugmentedInfo.setPkgInfo(YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(yangAugmentedInfo, (YangNode) javaCodeGeneratorInfo,
+ tempJavaCodeFragmentFiles.getBeanTempFiles());
+
}
@@ -314,7 +332,8 @@
parentsInfo.setClassInfo(parentName);
parentsInfo.setPkgInfo(parentPkg);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
+ .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo,
+ tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
.addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
@@ -322,45 +341,6 @@
}
}
- private static String getAugmentedNodesPackage(YangNode node, YangPluginConfig yangPluginConfig) {
-
- List<String> clsInfo = new ArrayList<>();
- node = node.getParent();
- while (node != null) {
- if (!(node instanceof YangJavaModule)
- || !(node instanceof YangJavaSubModule)) {
- if (node instanceof YangJavaAugment) {
- clsInfo.add(((YangJavaAugment) node).getAugmentClassName());
- } else {
- clsInfo.add(getCamelCase(node.getName(), yangPluginConfig.getConflictResolver()));
- }
- }
- if (node instanceof YangJavaModule
- || node instanceof YangJavaSubModule) {
- break;
- }
- node = node.getParent();
- }
-
- StringBuilder pkg = new StringBuilder();
- if (node instanceof YangJavaModule) {
- YangJavaModule module = (YangJavaModule) node;
- pkg.append(getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
- .getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
- } else if (node instanceof YangJavaSubModule) {
- YangJavaSubModule submodule = (YangJavaSubModule) node;
- pkg.append(getRootPackage(submodule.getVersion(),
- submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
- submodule.getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
- }
- for (int i = 1; i <= clsInfo.size(); i++) {
- pkg.append("." + clsInfo.get(clsInfo.size() - i));
- }
-
- return pkg.toString().toLowerCase();
-
- }
-
/**
* Generates code for the current data model node.
*
@@ -398,18 +378,17 @@
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
- if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
+ if (javaCodeGeneratorInfo instanceof YangJavaModule) {
if (!((YangJavaModule) javaCodeGeneratorInfo)
.isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
}
- } else if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaSubModule) {
+ } else if (javaCodeGeneratorInfo instanceof YangJavaSubModule) {
if (!((YangJavaSubModule) javaCodeGeneratorInfo)
.isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
}
}
-
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
@@ -452,13 +431,26 @@
public static boolean isManagerCodeGenRequired(YangNode node) {
YangLeavesHolder holder = (YangLeavesHolder) node;
- if (holder.getListOfLeaf() != null && !holder.getListOfLeaf().isEmpty()) {
- return true;
- } else if (holder.getListOfLeafList() != null && !holder.getListOfLeafList().isEmpty()) {
- return true;
- }
+ boolean isCodeReq = true;
+
+ List<YangNode> childNodes = new ArrayList<>();
node = node.getChild();
- return node != null && !(node instanceof YangTypeDef) && !(node instanceof YangGrouping);
+ while (node != null) {
+ childNodes.add(node);
+ node = node.getNextSibling();
+ }
+
+ if (childNodes.size() == 0) {
+ if (holder.getListOfLeaf() != null && !holder.getListOfLeaf().isEmpty()) {
+ isCodeReq = true;
+ } else if (holder.getListOfLeafList() != null && !holder.getListOfLeafList().isEmpty()) {
+ isCodeReq = true;
+ }
+ return isCodeReq;
+ } else if (childNodes.size() == 1) {
+ return childNodes.get(0) instanceof YangTypeDef && childNodes.get(0) instanceof YangGrouping;
+ }
+ return isCodeReq;
}
/**
@@ -482,4 +474,49 @@
return true;
}
+ /**
+ * Returns augmented nodes package.
+ *
+ * @param node augmented node
+ * @param yangPluginConfig plugin config
+ * @return java package
+ */
+ public static String getAugmentedNodesPackage(YangNode node, YangPluginConfig yangPluginConfig) {
+
+ List<String> clsInfo = new ArrayList<>();
+ node = node.getParent();
+ while (node != null) {
+ if (!(node instanceof YangModule)
+ || !(node instanceof YangSubModule)) {
+ if (node instanceof YangJavaAugment) {
+ clsInfo.add(((YangJavaAugment) node).getAugmentClassName());
+ } else {
+ clsInfo.add(getCamelCase(node.getName(), yangPluginConfig.getConflictResolver()));
+ }
+ }
+ if (node instanceof YangJavaModule
+ || node instanceof YangJavaSubModule) {
+ break;
+ }
+ node = node.getParent();
+ }
+
+ StringBuilder pkg = new StringBuilder();
+ if (node instanceof YangJavaModule) {
+ YangJavaModule module = (YangJavaModule) node;
+ pkg.append(getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
+ .getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
+ } else if (node instanceof YangJavaSubModule) {
+ YangJavaSubModule submodule = (YangJavaSubModule) node;
+ pkg.append(getRootPackage(submodule.getVersion(),
+ submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
+ submodule.getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
+ }
+ for (int i = 1; i <= clsInfo.size(); i++) {
+ pkg.append("." + clsInfo.get(clsInfo.size() - i));
+ }
+
+ return pkg.toString().toLowerCase();
+
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
index 91849b2..d54fd7d 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -34,7 +34,7 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.utils.io.impl.YangToJavaNamingConflictUtil;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.getCurNodePackage;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
index ef185fa..a890ec2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
@@ -30,7 +30,8 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
@@ -154,10 +155,11 @@
*/
public String getAugmentClassName() {
YangNodeIdentifier nodeId = getTargetNode().get(getTargetNode().size() - 1).getNodeIdentifier();
+ String name = getCapitalCase(getCamelCase(nodeId.getName(), null));
if (nodeId.getPrefix() != null) {
- return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + getCapitalCase(nodeId.getName());
+ return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + name;
} else {
- return AUGMENTED + getCapitalCase(nodeId.getName());
+ return AUGMENTED + name;
}
}
@@ -173,7 +175,7 @@
/**
* Sets extended class info.
*
- * @param augmentedInfo extended class info
+ * @param augmentedInfo extended class info
*/
private void setExtendedClassInfo(List<JavaQualifiedTypeInfo> augmentedInfo) {
extendedClassInfo = augmentedInfo;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
index 4652fd4..4d4929d 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents case information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
index 1e29349..122bb40 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents choice information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
index eac6291..3578adc 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents container information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
index 2edd8d8..fe5e40f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
@@ -27,7 +27,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents YANG java enumeration information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentity.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentity.java
index a73a5b4..6ae672b 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentity.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentity.java
@@ -31,7 +31,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
index 7e6211a..f6bfbfc 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
@@ -27,7 +27,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents input information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
index e4a1997..d03c381 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeAndUpdateInParent;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents YANG list information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
index 10cf879..6837aa4 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
@@ -32,10 +32,11 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isManagerCodeGenRequired;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isGenerationOfCodeReq;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
@@ -71,7 +72,7 @@
super();
setJavaFileInfo(new JavaFileInfo());
setNotificationNodes(new ArrayList<>());
- int gentype = GENERATE_SERVICE_AND_MANAGER;
+ int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
@@ -158,7 +159,10 @@
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ getTempJavaCodeFragmentFiles()
+ .generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ getTempJavaCodeFragmentFiles()
+ .generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
index 61eebfb..a56fefa 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
@@ -28,12 +28,13 @@
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
@@ -143,22 +144,23 @@
/*Adds current notification info to the extends list so its parents service*/
private void addNotificationToExtendsList() {
YangNode parent = getParent();
- JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) parent)
+ TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parent)
.getTempJavaCodeFragmentFiles()
- .getServiceTempFiles().getJavaExtendsListHolder();
+ .getServiceTempFiles();
+ JavaExtendsListHolder holder = tempJavaServiceFragmentFiles.getJavaExtendsListHolder();
JavaQualifiedTypeInfo event = new JavaQualifiedTypeInfo();
String parentInfo = getCapitalCase(((JavaFileInfoContainer) parent)
.getJavaFileInfo().getJavaName());
event.setClassInfo(parentInfo + EVENT_STRING);
event.setPkgInfo(getJavaFileInfo().getPackage());
- holder.addToExtendsList(event, parent);
+ holder.addToExtendsList(event, parent, tempJavaServiceFragmentFiles);
JavaQualifiedTypeInfo eventListener = new JavaQualifiedTypeInfo();
eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING);
eventListener.setPkgInfo(getJavaFileInfo().getPackage());
- holder.addToExtendsList(eventListener, parent);
+ holder.addToExtendsList(eventListener, parent, tempJavaServiceFragmentFiles);
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
index ce9ed6e..4b18551 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
@@ -27,7 +27,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
/**
* Represents output information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
index fe72d18..315f7e3 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
@@ -39,7 +39,7 @@
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.updatePackageInfo;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
index 835d781..f7176e2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
@@ -34,10 +34,11 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isManagerCodeGenRequired;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isGenerationOfCodeReq;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
@@ -72,7 +73,7 @@
public YangJavaSubModule() {
super();
setJavaFileInfo(new JavaFileInfo());
- int gentype = GENERATE_SERVICE_AND_MANAGER;
+ int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
@@ -170,6 +171,8 @@
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
+
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
index 3d33f3d..e08ec19 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents type define information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
index cca3e4b..0dca9a7 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
@@ -26,7 +26,7 @@
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents union information extended to support java code generation.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index c439e0a..ff5f7ba 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -282,7 +282,7 @@
curNode = curNode.getChild();
while (curNode != null) {
if (curNode instanceof YangNotification) {
- return getRpcInterfaceDefinitionWhenItExtends(yangName, holder);
+ return getRpcInterfaceDefinitionWhenItExtends(yangName);
}
curNode = curNode.getNextSibling();
}
@@ -295,8 +295,7 @@
}
/* Provides class definition when RPC interface needs to extends any event.*/
- private static String getRpcInterfaceDefinitionWhenItExtends(String yangName,
- JavaExtendsListHolder holder) {
+ private static String getRpcInterfaceDefinitionWhenItExtends(String yangName) {
if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
String[] strArray = yangName.split(SERVICE);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index d29fb86..3f1a7d9 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -19,14 +19,14 @@
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
@@ -38,6 +38,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
@@ -45,18 +46,22 @@
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
@@ -221,11 +226,13 @@
public static void addListenersImport(YangNode curNode, List<String> imports, boolean operation,
String classInfo) {
String thisImport = "";
+ TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles();
if (classInfo.equals(LISTENER_SERVICE)) {
- thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerServiceImport();
+ thisImport = tempJavaServiceFragmentFiles.getJavaImportData().getListenerServiceImport();
performOperationOnImports(imports, thisImport, operation);
} else {
- thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerRegistryImport();
+ thisImport = tempJavaServiceFragmentFiles.getJavaImportData().getListenerRegistryImport();
performOperationOnImports(imports, thisImport, operation);
}
}
@@ -250,25 +257,6 @@
}
/**
- * Returns temp java fragment.
- *
- * @param curNode current YANG node
- * @return temp java fragments
- */
- public static TempJavaFragmentFiles getTempJavaFragment(YangNode curNode) {
- TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles();
- if (container.getBeanTempFiles() != null) {
- return container.getBeanTempFiles();
- }
- if (container.getServiceTempFiles() != null) {
- return container.getServiceTempFiles();
- }
-
- return null;
- }
-
- /**
* Returns integer attribute for enum's class to get the values.
*
* @param className enum's class name
@@ -285,7 +273,20 @@
* @return component string
*/
public static String addComponentString() {
- return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ return NEW_LINE + COMPONENT_ANNOTATION + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
}
+
+ /**
+ * Returns attribute for augmentation.
+ *
+ * @return attribute for augmentation
+ */
+ public static String addAugmentationAttribute() {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING
+ + DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO
+ + DIAMOND_CLOSE_BRACKET + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL + SPACE +
+ NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS
+ + CLOSE_PARENTHESIS + SEMI_COLAN;
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
index ca1f052..d686842 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
@@ -26,9 +26,9 @@
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getTempJavaFragment;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
@@ -36,6 +36,9 @@
*/
public class JavaExtendsListHolder {
+ private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore;
+ private List<JavaQualifiedTypeInfo> extendsList;
+
/**
* Creates an instance of JavaExtendsListHolder.
*/
@@ -44,9 +47,6 @@
setExtendsList(new ArrayList<>());
}
- private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore;
- private List<JavaQualifiedTypeInfo> extendsList;
-
/**
* Returns extends list.
*
@@ -68,13 +68,15 @@
/**
* Adds to the extends list.
*
- * @param info java file info
- * @param node YANG node
+ * @param info java file info
+ * @param node YANG node
+ * @param tempJavaFragmentFiles temp java fragment files
*/
- public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
+ public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node,
+ TempJavaFragmentFiles tempJavaFragmentFiles) {
JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
- JavaImportData importData = getTempJavaFragment(node).getJavaImportData();
+ JavaImportData importData = tempJavaFragmentFiles.getJavaImportData();
boolean qualified = importData.addImportInfo(info,
getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index 49315f3..46c9dd1 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -22,7 +22,9 @@
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
@@ -63,12 +65,19 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
+import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedNodesConstructorStart;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForManager;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod;
@@ -77,12 +86,16 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
@@ -317,15 +330,13 @@
/**
* Returns generated manager class file for current node.
*
- * @param file file
- * @param imports imports for the file
- * @param curNode current YANG node
- * @param isAttrPresent if any attribute is present or not
+ * @param file file
+ * @param imports imports for the file
+ * @param curNode current YANG node
* @return builder class file
* @throws IOException when fails to write in file
*/
- public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode,
- boolean isAttrPresent)
+ public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
@@ -341,25 +352,26 @@
methods.add(addActivateMethod());
methods.add(addDeActivateMethod());
- try {
- if (isAttrPresent) {
- /**
- * Getter methods.
- */
- methods.add(
- getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles(), path));
- /**
- * Setter methods.
- */
- methods.add(
- getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles(), path)
- + NEW_LINE);
+ TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles();
- }
+ JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false,
+ tempJavaServiceFragmentFiles);
+ try {
+ /**
+ * Getter methods.
+ */
+ methods.add(getOverRideString() +
+ getGetterForClass(rootAttribute, GENERATE_SERVICE_AND_MANAGER) + NEW_LINE);
+ /**
+ * Setter methods.
+ */
+ methods.add(getOverRideString() +
+ getSetterForClass(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER)
+ + NEW_LINE);
+
+ methods.add(getAugmentsDataMethodForManager(curNode) + NEW_LINE);
+
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
@@ -410,7 +422,9 @@
if (curNode instanceof YangAugment) {
isAugmentNode = true;
}
-
+ if (curNode instanceof YangAugmentableNode) {
+ insertDataIntoJavaFile(file, addAugmentationAttribute());
+ }
if (isAttrPresent) {
/**
* Add attribute strings.
@@ -483,6 +497,11 @@
+ " while impl class file generation");
}
+ if (curNode instanceof YangAugmentableNode) {
+ methods.add(getAddAugmentInfoMethodImpl());
+ methods.add(getAugmentInfoImpl());
+ }
+
/**
* Add methods in impl class.
*/
@@ -796,38 +815,38 @@
* @param file generated file
* @param curNode current YANG node
* @param imports imports for file
- * @param isAttributePresent is attribute present
* @return rpc class file
* @throws IOException when fails to generate class file
*/
- public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports,
- boolean isAttributePresent)
+ public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles();
String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
List<String> methods = new ArrayList<>();
+ JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false,
+ tempJavaServiceFragmentFiles);
try {
- if (isAttributePresent) {
+ /**
+ * Getter methods.
+ */
+ methods.add(getGetterString(rootAttribute, GENERATE_SERVICE_AND_MANAGER,
+ javaFileInfo.getPluginConfig()) + NEW_LINE);
+ /**
+ * Setter methods.
+ */
+ methods.add(getSetterString(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER,
+ javaFileInfo.getPluginConfig()) + NEW_LINE);
- /**
- * Getter methods.
- */
- methods.add(getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles(), path));
- /**
- * Setter methods.
- */
- methods.add(getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles(), path));
- }
+ methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE);
+
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
index c6fd897..6f4fa9b 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -18,14 +18,23 @@
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
@@ -67,6 +76,8 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getAugmentedNodesPackage;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
@@ -553,4 +564,191 @@
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
+ /**
+ * Returns resolved augments for manager classes.
+ *
+ * @param parent parent node
+ * @return resolved augments for manager classes
+ */
+ public static Map<YangAtomicPath, YangAugment> getResolvedAugmentsForManager(YangNode parent) {
+ Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = new HashMap<>();
+ YangNodeIdentifier nodeId;
+ List<YangAtomicPath> targets = new ArrayList<>();
+ for (YangAugment augment : getListOfAugments(parent)) {
+ nodeId = augment.getTargetNode().get(0).getNodeIdentifier();
+ if (validateNodeIdentifierInSet(nodeId, targets)) {
+ targets.add(augment.getTargetNode().get(0));
+ resolvedAugmentsForManager.put(augment.getTargetNode().get(0), augment);
+ }
+ }
+ return resolvedAugmentsForManager;
+ }
+
+ /**
+ * Returns set of node identifiers.
+ *
+ * @param parent parent node
+ * @return set of node identifiers
+ */
+ public static List<YangAtomicPath> getSetOfNodeIdentifiers(YangNode parent) {
+
+ List<YangAtomicPath> targets = new ArrayList<>();
+ YangNodeIdentifier nodeId;
+ List<YangAugment> augments = getListOfAugments(parent);
+ for (YangAugment augment : augments) {
+ nodeId = augment.getTargetNode().get(0).getNodeIdentifier();
+
+ if (validateNodeIdentifierInSet(nodeId, targets)) {
+ targets.add(augment.getTargetNode().get(0));
+ }
+ }
+ return targets;
+ }
+
+ /* Returns list of augments.*/
+ private static List<YangAugment> getListOfAugments(YangNode parent) {
+ List<YangAugment> augments = new ArrayList<>();
+ YangNode child = parent.getChild();
+ while (child != null) {
+ if (child instanceof YangAugment) {
+ augments.add((YangAugment) child);
+ }
+ child = child.getNextSibling();
+ }
+ return augments;
+ }
+
+ /*Validates the set for duplicate names of node identifiers.*/
+ private static boolean validateNodeIdentifierInSet(YangNodeIdentifier nodeId, List<YangAtomicPath> targets) {
+ boolean isPresent = true;
+ for (YangAtomicPath target : targets) {
+ if (target.getNodeIdentifier().getName().equals(nodeId.getName())) {
+ if (target.getNodeIdentifier().getPrefix() != null) {
+ isPresent = !target.getNodeIdentifier().getPrefix().equals(nodeId.getPrefix());
+ } else {
+ isPresent = nodeId.getPrefix() != null;
+ }
+ }
+ }
+ return isPresent;
+ }
+
+ /**
+ * Adds resolved augmented node imports to manager class.
+ *
+ * @param parent parent node
+ */
+ public static void addResolvedAugmentedDataNodeImports(YangNode parent) {
+ Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = getResolvedAugmentsForManager(parent);
+ List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
+ TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = ((JavaCodeGeneratorInfo) parent)
+ .getTempJavaCodeFragmentFiles();
+ YangNode augmentedNode;
+ JavaQualifiedTypeInfo javaQualifiedTypeInfo;
+ String curNodeName;
+ JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ for (YangAtomicPath nodeId : targets) {
+ augmentedNode = resolvedAugmentsForManager.get(nodeId).getResolveNodeInPath().get(nodeId);
+ if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
+ curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
+ } else {
+ curNodeName = getCapitalCase(getCamelCase(augmentedNode.getName(), parentInfo.getPluginConfig()
+ .getConflictResolver()));
+ }
+
+ javaQualifiedTypeInfo = getQualifiedTypeInfoOfAugmentedNode(augmentedNode, getCapitalCase(curNodeName),
+ parentInfo.getPluginConfig());
+ tempJavaCodeFragmentFiles.getServiceTempFiles().getJavaImportData().addImportInfo(javaQualifiedTypeInfo,
+ parentInfo.getJavaName(), parentInfo.getPackage());
+
+ }
+ }
+
+ /**
+ * Returns qualified type info of augmented node.
+ *
+ * @param augmentedNode augmented node
+ * @param curNodeName current node name
+ * @param pluginConfig plugin configurations
+ * @return qualified type info of augmented node
+ */
+ public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfAugmentedNode(YangNode augmentedNode, String curNodeName,
+ YangPluginConfig pluginConfig) {
+ JavaQualifiedTypeInfo javaQualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(augmentedNode,
+ getCapitalCase(curNodeName));
+ if (javaQualifiedTypeInfo.getPkgInfo() == null) {
+ javaQualifiedTypeInfo.setPkgInfo(getAugmentedNodesPackage(augmentedNode,
+ pluginConfig));
+ }
+ return javaQualifiedTypeInfo;
+ }
+
+ /**
+ * Validates if augmented node is imported in parent node.
+ *
+ * @param javaQualifiedTypeInfo qualified type info
+ * @param importData import data
+ * @return true if present in imports
+ */
+ private static boolean validateQualifiedInfoOfAugmentedNode(JavaQualifiedTypeInfo javaQualifiedTypeInfo,
+ JavaImportData importData) {
+ for (JavaQualifiedTypeInfo curImportInfo : importData.getImportSet()) {
+ if (curImportInfo.getClassInfo()
+ .contentEquals(javaQualifiedTypeInfo.getClassInfo())) {
+ return curImportInfo.getPkgInfo()
+ .contentEquals(javaQualifiedTypeInfo.getPkgInfo());
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Return augmented class name for data methods in manager and service.
+ *
+ * @param augmentedNode augmented node
+ * @param parent parent node
+ * @return augmented class name for data methods in manager and service
+ */
+ public static String getAugmentedClassNameForDataMethods(YangNode augmentedNode, YangNode parent) {
+ String curNodeName;
+ JavaQualifiedTypeInfo javaQualifiedTypeInfo;
+ JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ YangPluginConfig pluginConfig = parentInfo.getPluginConfig();
+ TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) parent)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles();
+ if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
+ curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
+ } else {
+ curNodeName = getCapitalCase(getCamelCase(augmentedNode.getName(), pluginConfig
+ .getConflictResolver()));
+ }
+
+ javaQualifiedTypeInfo = getQualifiedTypeInfoOfAugmentedNode(augmentedNode,
+ getCapitalCase(curNodeName),
+ parentInfo.getPluginConfig());
+ if (validateQualifiedInfoOfAugmentedNode(javaQualifiedTypeInfo,
+ tempJavaServiceFragmentFiles.getJavaImportData())) {
+ return javaQualifiedTypeInfo.getClassInfo();
+ } else {
+ return javaQualifiedTypeInfo.getPkgInfo() + PERIOD + javaQualifiedTypeInfo.getClassInfo();
+ }
+ }
+
+ /**
+ * Returns parent node name for data methods in manager and service.
+ *
+ * @param parent parent node
+ * @param pluginConfig plugin configurations
+ * @return parent node name for data methods in manager and service
+ */
+ public static String getParentNodeNameForDataMethods(YangNode parent, YangPluginConfig pluginConfig) {
+ JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ if (parentInfo.getJavaName() != null) {
+ return getCapitalCase(parentInfo.getJavaName());
+ }
+ return getCapitalCase(getCamelCase(parent.getName(), pluginConfig
+ .getConflictResolver()));
+
+ }
+
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index cde88ed..ffc0a46 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -19,19 +19,29 @@
import java.util.List;
import java.util.Map;
+import org.onosproject.yangutils.datamodel.YangAtomicPath;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getResolvedAugmentsForManager;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
@@ -43,6 +53,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.CASE;
import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
@@ -63,6 +75,7 @@
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.GET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_BYTES;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
@@ -75,6 +88,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
@@ -94,6 +108,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yangutils.utils.UtilConstants.PUT;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
@@ -117,6 +132,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
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.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
@@ -127,6 +143,8 @@
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForAddAugmentation;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForTypeConstructor;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
@@ -941,6 +959,38 @@
}
/**
+ * Returns implementation of add augmentation.
+ *
+ * @return implementation of add augmentation
+ */
+ public static String getAddAugmentInfoMethodImpl() {
+ return NEW_LINE + generateForAddAugmentation() + FOUR_SPACE_INDENTATION +
+ PUBLIC + SPACE + VOID + SPACE + ADD_STRING
+ + AUGMENTATION + OPEN_PARENTHESIS + YANG_AUGMENTED_INFO + SPACE + VALUE + COMMA + SPACE + CLASS_STRING +
+ SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT + OPEN_PARENTHESIS +
+ CLASS + OBJECT_STRING + COMMA + SPACE + VALUE +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns implementation of get augment info.
+ *
+ * @return implementation of get augment info
+ */
+ public static String getAugmentInfoImpl() {
+
+ return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
+ YANG_AUGMENTED_INFO + SPACE + GET_METHOD_PREFIX +
+ YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + GET + OPEN_PARENTHESIS + CLASS +
+ OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
* Returns enum's constructor.
*
* @param className enum's class name
@@ -1096,4 +1146,90 @@
+ VALUE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
+
+ /**
+ * Returns augmented data getter and setter methods for service class.
+ *
+ * @param parent parent node
+ * @return augmented data getter and setter methods for service class
+ */
+ public static String getAugmentsDataMethodForService(YangNode parent) {
+ Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = getResolvedAugmentsForManager(parent);
+ List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
+ YangNode augmentedNode;
+ String curNodeName;
+ String method;
+ StringBuilder methods = new StringBuilder();
+ String parentName;
+ String returnType;
+ YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
+ for (YangAtomicPath nodeId : targets) {
+ augmentedNode = resolvedAugmentsForManager.get(nodeId).getResolveNodeInPath().get(nodeId);
+ if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
+ curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
+ } else {
+ curNodeName = getCapitalCase(getCamelCase(augmentedNode.getName(), pluginConfig
+ .getConflictResolver()));
+ }
+ returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
+ parentName = getParentNodeNameForDataMethods(augmentedNode.getParent(), pluginConfig);
+ method = getJavaDoc(GETTER_METHOD, getSmallCase(AUGMENTED + parentName + curNodeName), false,
+ pluginConfig) + getGetterForInterface(AUGMENTED + parentName
+ + getCapitalCase(curNodeName),
+ returnType, false, GENERATE_SERVICE_AND_MANAGER)
+ + NEW_LINE;
+ methods.append(method);
+
+ method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
+ getCapitalCase(parentName) + curNodeName, false, pluginConfig) +
+ getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
+ getCapitalCase(curNodeName), returnType, parentName,
+ false,
+ GENERATE_SERVICE_AND_MANAGER) + NEW_LINE;
+ methods.append(method);
+ }
+ return methods.toString();
+ }
+
+ /**
+ * Returns augmented data getter and setter methods for manager class.
+ *
+ * @param parent parent node
+ * @return augmented data getter and setter methods for manager class
+ */
+ public static String getAugmentsDataMethodForManager(YangNode parent) {
+ Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = getResolvedAugmentsForManager(parent);
+ List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
+ YangNode augmentedNode;
+ String curNodeName;
+ String returnType;
+ String method;
+ StringBuilder methods = new StringBuilder();
+ String parentName;
+ YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
+ for (YangAtomicPath nodeId : targets) {
+ augmentedNode = resolvedAugmentsForManager.get(nodeId).getResolveNodeInPath().get(nodeId);
+ if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
+ curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
+ } else {
+ curNodeName = getCapitalCase(getCamelCase(augmentedNode.getName(), pluginConfig
+ .getConflictResolver()));
+ }
+ returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
+ parentName = getParentNodeNameForDataMethods(augmentedNode.getParent(), pluginConfig);
+ method = getOverRideString() + getGetter(returnType, AUGMENTED
+ + parentName + getCapitalCase(curNodeName),
+ GENERATE_SERVICE_AND_MANAGER) + NEW_LINE;
+ methods.append(method);
+
+ method = getOverRideString() + getSetter(parentName, getSmallCase(AUGMENTED) +
+ getCapitalCase(parentName) + getCapitalCase(curNodeName),
+ returnType,
+ GENERATE_SERVICE_AND_MANAGER)
+ + NEW_LINE;
+ methods.append(method);
+ }
+ return methods.toString();
+ }
+
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 8811dfa..44dddea 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -97,11 +97,6 @@
public static final String JAVA_DOC_RETURN = " * @return ";
/**
- * JavaDocs's throw annotation.
- */
- public static final String JAVA_DOC_THROWS = " * @throws ";
-
- /**
* JavaDocs's description for setter method.
*/
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
@@ -307,11 +302,6 @@
public static final String IDENTITYREF = "identityref";
/**
- * Static attribute for instance identifier string.
- */
- public static final String INSTANCE_IDENTIFIER = "instance-identifier";
-
- /**
* Static attribute for output variable of rpc.
*/
public static final String RPC_INPUT_VAR_NAME = "inputVar";
@@ -332,16 +322,6 @@
public static final String ADD = "+";
/**
- * Static attribute for asterisk.
- */
- public static final String ASTERISK = "*";
-
- /**
- * Static attribute for at.
- */
- public static final String AT = "@";
-
- /**
* Static attribute for quotes.
*/
public static final String QUOTES = "\"";
@@ -357,6 +337,21 @@
public static final String COMMA = ",";
/**
+ * Static attribute for class.
+ */
+ public static final String CLASS_STRING = "Class";
+
+ /**
+ * Static attribute for put.
+ */
+ public static final String PUT = "put";
+
+ /**
+ * Static attribute for get.
+ */
+ public static final String GET = "get";
+
+ /**
* Static attribute for slash character.
*/
public static final char CHAR_OF_SLASH = '/';
@@ -432,11 +427,6 @@
public static final String VALUE = "value";
/**
- * Static attribute for enumValue syntax.
- */
- public static final String ENUM_VALUE = "enumValue";
-
- /**
* Static attribute for suffix s.
*/
public static final String SUFFIX_S = "s";
@@ -447,16 +437,6 @@
public static final String IF = "if";
/**
- * Static attribute for for.
- */
- public static final String FOR = "for";
-
- /**
- * Static attribute for while.
- */
- public static final String WHILE = "while";
-
- /**
* Static attribute for of.
*/
public static final String OF = "of";
@@ -532,11 +512,6 @@
public static final String OPEN_PARENTHESIS = "(";
/**
- * Static attribute for clear syntax.
- */
- public static final String CLEAR = "clear";
-
- /**
* Static attribute for switch syntax.
*/
public static final String SWITCH = "switch";
@@ -592,11 +567,6 @@
public static final String FOUR_SPACE_INDENTATION = " ";
/**
- * Static attribute for not syntax.
- */
- public static final String NOT = "!";
-
- /**
* Static attribute for try syntax.
*/
public static final String TRY = "try";
@@ -667,11 +637,6 @@
public static final String ABSTRACT = "abstract";
/**
- * Static attribute for protected modifier.
- */
- public static final String PROTECTED = "protected";
-
- /**
* Void java type.
*/
public static final String VOID = "void";
@@ -732,11 +697,6 @@
public static final String LONG = "long";
/**
- * Float java built in type.
- */
- public static final String FLOAT = "float";
-
- /**
* Double java built in type.
*/
public static final String DOUBLE = "double";
@@ -767,14 +727,9 @@
public static final String LONG_WRAPPER = "Long";
/**
- * YangUint64 java built in wrapper type.
+ * Static varibale for question mark.
*/
- public static final String YANG_UINT64 = "YangUint64";
-
- /**
- * Double java built in wrapper type.
- */
- public static final String DOUBLE_WRAPPER = "Double";
+ public static final String QUESTION_MARK = "?";
/**
* List of keywords in java, this is used for checking if the input does not contain these keywords.
@@ -977,11 +932,22 @@
public static final String OVERRIDE = "@Override";
/**
- * Static attribute for new line.
+ * Static attribute for collections.
*/
public static final String COLLECTION_IMPORTS = "java.util";
/**
+ * Static attribute for map.
+ */
+ public static final String MAP = "Map";
+
+ /**
+ * Static attribute for hash map.
+ */
+ public static final String HASH_MAP = "HashMap";
+
+
+ /**
* Static attribute for more object import package.
*/
public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG = "com.google.common.base";
@@ -1007,25 +973,14 @@
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
/**
- * Static attribute for AugmentationHolder class import package.
- */
- public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG =
- "org.onosproject.yangutils.utils";
-
- /**
- * Static attribute for AugmentationHolder class import class.
- */
- public static final String AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS = "AugmentationHolder;\n";
-
- /**
* Static attribute for AugmentedInfo class import package.
*/
- public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.utils";
+ public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.datamodel";
/**
* Static attribute for AugmentedInfo class import class.
*/
- public static final String AUGMENTED_INFO_CLASS_IMPORT_CLASS = "AugmentedInfo;\n";
+ public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS = "YangAugmentedInfo;\n";
/**
* Static attribute for augmentation class.
@@ -1033,19 +988,14 @@
public static final String AUGMENTATION = "Augmentation";
/**
- * Static attribute for AugmentationHolder class.
- */
- public static final String AUGMENTATION_HOLDER = "AugmentationHolder";
-
- /**
* Static attribute for AugmentedInfo class.
*/
- public static final String AUGMENTED_INFO = "AugmentedInfo";
+ public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
/**
- * Static attribute for augmentable.
+ * Static attribute for augmented.
*/
- public static final String AUGMENTABLE = "Augmentable";
+ public static final String AUGMENTED = "Augmented";
/**
* Static attribute for list.
@@ -1053,11 +1003,6 @@
public static final String LIST = "List";
/**
- * Static attribute for array list.
- */
- public static final String ARRAY_LIST = "ArrayList";
-
- /**
* Comment to be added for autogenerated impl methods.
*/
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
@@ -1166,16 +1111,6 @@
public static final String EVENT_LISTENER = "EventListener";
/**
- * Static attribute for YANG types package.
- */
- public static final String YANG_TYPES_PKG = "org.onosproject.yangutils.datamodel.utils.builtindatatype";
-
- /**
- * Static attribute for MathContext class.
- */
- public static final String MATH_CONTEXT = "MathContext";
-
- /**
* Static attribute for YANG file error.
*/
public static final String YANG_FILE_ERROR = "YANG file error : ";
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index 1610536..336cc52 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -16,11 +16,13 @@
package org.onosproject.yangutils.utils.io.impl;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
@@ -47,9 +49,11 @@
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
+import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OF;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
@@ -60,6 +64,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
/**
* Represents javadoc for the generated classes.
@@ -73,127 +79,11 @@
}
/**
- * JavaDocs types.
- */
- public enum JavaDocType {
-
- /**
- * For class.
- */
- IMPL_CLASS,
-
- /**
- * For builder class.
- */
- BUILDER_CLASS,
-
- /**
- * For interface.
- */
- INTERFACE,
-
- /**
- * For builder interface.
- */
- BUILDER_INTERFACE,
-
- /**
- * For package-info.
- */
- PACKAGE_INFO,
-
- /**
- * For getters.
- */
- GETTER_METHOD,
-
- /**
- * For rpc service.
- */
- RPC_INTERFACE,
-
- /**
- * For rpc manager.
- */
- RPC_MANAGER,
-
- /**
- * For event.
- */
- EVENT,
-
- /**
- * For event listener.
- */
- EVENT_LISTENER,
-
- /**
- * For setters.
- */
- SETTER_METHOD,
-
- /**
- * For type def's setters.
- */
- TYPE_DEF_SETTER_METHOD,
-
- /**
- * For of method.
- */
- OF_METHOD,
-
- /**
- * For default constructor.
- */
- DEFAULT_CONSTRUCTOR,
-
- /**
- * For constructor.
- */
- CONSTRUCTOR,
-
- /**
- * For from method.
- */
- FROM_METHOD,
-
- /**
- * For type constructor.
- */
- TYPE_CONSTRUCTOR,
-
- /**
- * For build.
- */
- BUILD_METHOD,
-
- /**
- * For enum.
- */
- ENUM_CLASS,
-
- /**
- * For enum's attributes.
- */
- ENUM_ATTRIBUTE,
-
- /**
- * For manager setters.
- */
- MANAGER_SETTER_METHOD,
-
- /**
- * For event subject.
- */
- EVENT_SUBJECT_CLASS
- }
-
- /**
* Returns java docs.
*
- * @param type java doc type
- * @param name name of the YangNode
- * @param isList is list attribute
+ * @param type java doc type
+ * @param name name of the YangNode
+ * @param isList is list attribute
* @param pluginConfig plugin configurations
* @return javadocs.
*/
@@ -250,10 +140,10 @@
return generateForEnumAttr(name);
}
case RPC_INTERFACE: {
- return generateForRpcService(name);
+ return generateForRpcService(name);
}
case RPC_MANAGER: {
- return generateForClass(name);
+ return generateForClass(name);
}
case EVENT: {
return generateForEvent(name);
@@ -284,14 +174,14 @@
/**
* Generates javaDocs for rpc method.
*
- * @param rpcName name of the rpc
- * @param inputName name of input
- * @param outputName name of output
+ * @param rpcName name of the rpc
+ * @param inputName name of input
+ * @param outputName name of output
* @param pluginConfig plugin configurations
* @return javaDocs of rpc method
*/
public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName,
- YangPluginConfig pluginConfig) {
+ YangPluginConfig pluginConfig) {
rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
String javadoc =
@@ -310,7 +200,7 @@
* Returns output string of rpc.
*
* @param outputName name of output
- * @param rpcName name of rpc
+ * @param rpcName name of rpc
* @return javaDocs for output string of rpc
*/
private static String getOutputString(String outputName, String rpcName) {
@@ -321,7 +211,7 @@
* Returns input string of rpc.
*
* @param inputName name of input
- * @param rpcName name of rpc
+ * @param rpcName name of rpc
* @return javaDocs for input string of rpc
*/
private static String getInputString(String inputName, String rpcName) {
@@ -369,7 +259,7 @@
* Generates javaDocs for getter method.
*
* @param attribute attribute
- * @param isList is list attribute
+ * @param isList is list attribute
* @return javaDocs
*/
private static String generateForGetters(String attribute, boolean isList) {
@@ -392,7 +282,7 @@
* Generates javaDocs for setter method.
*
* @param attribute attribute
- * @param isList is list attribute
+ * @param isList is list attribute
* @return javaDocs
*/
private static String generateForSetters(String attribute, boolean isList) {
@@ -416,7 +306,7 @@
* Generates javaDocs for setter method.
*
* @param attribute attribute
- * @param isList is list attribute
+ * @param isList is list attribute
* @return javaDocs
*/
private static String generateForManagerSetters(String attribute, boolean isList) {
@@ -596,4 +486,143 @@
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
+
+ /**
+ * Generates javaDocs for add augmentation method.
+ *
+ * @return javaDocs
+ */
+ public static String generateForAddAugmentation() {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ + JAVA_DOC_SETTERS_COMMON + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + NEW_LINE +
+ FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE +
+ VALUE + SPACE + OF + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + NEW_LINE + FOUR_SPACE_INDENTATION
+ + JAVA_DOC_PARAM + CLASS + OBJECT_STRING + SPACE +
+ VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ }
+
+ public static String generateForGetAugmentation() {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ + JAVA_DOC_GETTERS + getSmallCase(YANG_AUGMENTED_INFO) + PERIOD + NEW_LINE +
+ FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + CLASS +
+ OBJECT_STRING + SPACE + VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE +
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + VALUE + SPACE +
+ OF + SPACE + YANG_AUGMENTED_INFO + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ }
+
+ /**
+ * JavaDocs types.
+ */
+ public enum JavaDocType {
+
+ /**
+ * For class.
+ */
+ IMPL_CLASS,
+
+ /**
+ * For builder class.
+ */
+ BUILDER_CLASS,
+
+ /**
+ * For interface.
+ */
+ INTERFACE,
+
+ /**
+ * For builder interface.
+ */
+ BUILDER_INTERFACE,
+
+ /**
+ * For package-info.
+ */
+ PACKAGE_INFO,
+
+ /**
+ * For getters.
+ */
+ GETTER_METHOD,
+
+ /**
+ * For rpc service.
+ */
+ RPC_INTERFACE,
+
+ /**
+ * For rpc manager.
+ */
+ RPC_MANAGER,
+
+ /**
+ * For event.
+ */
+ EVENT,
+
+ /**
+ * For event listener.
+ */
+ EVENT_LISTENER,
+
+ /**
+ * For setters.
+ */
+ SETTER_METHOD,
+
+ /**
+ * For type def's setters.
+ */
+ TYPE_DEF_SETTER_METHOD,
+
+ /**
+ * For of method.
+ */
+ OF_METHOD,
+
+ /**
+ * For default constructor.
+ */
+ DEFAULT_CONSTRUCTOR,
+
+ /**
+ * For constructor.
+ */
+ CONSTRUCTOR,
+
+ /**
+ * For from method.
+ */
+ FROM_METHOD,
+
+ /**
+ * For type constructor.
+ */
+ TYPE_CONSTRUCTOR,
+
+ /**
+ * For build.
+ */
+ BUILD_METHOD,
+
+ /**
+ * For enum.
+ */
+ ENUM_CLASS,
+
+ /**
+ * For enum's attributes.
+ */
+ ENUM_ATTRIBUTE,
+
+ /**
+ * For manager setters.
+ */
+ MANAGER_SETTER_METHOD,
+
+ /**
+ * For event subject.
+ */
+ EVENT_SUBJECT_CLASS
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index a32d927..566e9ce 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -103,7 +103,7 @@
* @throws IOException when fails to create package info file
*/
public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode,
- YangPluginConfig pluginConfig)
+ YangPluginConfig pluginConfig)
throws IOException {
pack = parsePkg(pack);
@@ -385,7 +385,7 @@
/* Updates the given line with the given size conditions. */
private static StringBuilder updateString(String[] strArray, StringBuilder stringBuilder, String string,
- int lineSize) {
+ int lineSize) {
StringBuilder tempBuilder = new StringBuilder();
for (String str : strArray) {
@@ -481,7 +481,7 @@
/**
* Adds prefix, if the string begins with digit or is a java key word.
*
- * @param camelCasePrefix string for adding prefix
+ * @param camelCasePrefix string for adding prefix
* @param conflictResolver object of YANG to java naming conflict util
* @return prefixed camel case string
*/
@@ -502,7 +502,7 @@
* Applies the rule that a string does not end with a capitalized letter and capitalizes
* the letter next to a number in an array.
*
- * @param stringArray containing strings for camel case separation
+ * @param stringArray containing strings for camel case separation
* @param conflictResolver object of YANG to java naming conflict util
* @return camel case rule checked string
*/
@@ -545,7 +545,7 @@
/**
* Resolves the conflict when input has upper case.
*
- * @param stringArray containing strings for upper case conflict resolver
+ * @param stringArray containing strings for upper case conflict resolver
* @param conflictResolver object of YANG to java naming conflict util
* @return camel cased string
*/
@@ -597,7 +597,7 @@
/**
* Returns the YANG identifier name as java identifier.
*
- * @param yangIdentifier identifier in YANG file
+ * @param yangIdentifier identifier in YANG file
* @param conflictResolver object of YANG to java naming conflict util
* @return corresponding java identifier
*/
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
index fcd2966..16962f2 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
@@ -206,7 +206,7 @@
File folder = new File(System.getProperty("user.dir") + SLASH + FLOW_CLASSIFIER_FOLDER);
File file = new File(System.getProperty("user.dir") + SLASH + FLOW_CLASSIFIER_MANAGER);
assertThat(true, is(folder.exists()));
- assertThat(false, is(file.exists()));
+ assertThat(true, is(file.exists()));
}
/**
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/NotificationTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/NotificationTranslatorTest.java
index 27b42e1..ac7e417 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/NotificationTranslatorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/NotificationTranslatorTest.java
@@ -50,6 +50,7 @@
generateJavaCode(node, yangPluginConfig);
deleteDirectory("target/NotificationTest/");
+ deleteDirectory("target/NotificationTest1/");
}
// TODO enhance the test cases, after having a framework of translator test.
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
index 5d1251a..7fcd7f1 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
@@ -26,7 +26,6 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.linker.impl.YangXpathLinker;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
@@ -44,11 +43,12 @@
private YangLinkerManager linkerManager = new YangLinkerManager();
private static final String INTRA_FILE_PATH = "src/test/resources/xPathLinker/IntraFile/";
private static final String INTER_FILE_PATH = "src/test/resources/xPathLinker/InterFile/";
+ private static final String CASE_FILE_PATH = "src/test/resources/xPathLinker/Case/";
/**
* Unit test case for intra file linking for single level container.
*
- * @throws IOException when fails to do IO operations
+ * @throws IOException when fails to do IO operations
* @throws MojoExecutionException
*/
@Test
@@ -230,7 +230,7 @@
*
* @throws IOException when fails to do IO operations
*/
- @Test(expected = LinkerException.class)
+ @Test
public void processIntraFileLinkingInUsesSingleLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
@@ -260,7 +260,7 @@
*
* @throws IOException when fails to do IO operations
*/
- @Test(expected = LinkerException.class)
+ @Test
public void processIntraFileLinkingInUsesMultiLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
@@ -449,6 +449,9 @@
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+ linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+ linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
@@ -459,7 +462,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = augment.getAugmentedNode();
}
}
@@ -481,7 +484,7 @@
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
-
+ linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
String targetNodeName = null;
@@ -491,7 +494,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = augment.getAugmentedNode();
}
}
@@ -523,7 +526,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = augment.getAugmentedNode();
}
}
@@ -538,11 +541,11 @@
@Test
public void processInterFileLinkingInUsesInAugment() throws IOException {
- /* FIXME: when uses cloning is done test it.
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
@@ -555,13 +558,13 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
- .getNodeIdentifier().getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node);
+ .getNodeIdentifier().getName();
+ targetNode = augment.getAugmentedNode();
}
}
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
- */
+
}
/**
@@ -569,7 +572,7 @@
*
* @throws IOException when fails to do IO operations
*/
- @Test(expected = LinkerException.class)
+ @Test
public void processInterFileLinkingInUsesMultiLevel() throws IOException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
@@ -596,4 +599,72 @@
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
}
+ /**
+ * Unit test case for inter file linking for multi level uses inside augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingInMultipleSubmodules() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "submodule/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+ linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ YangNode targetNode = null;
+ String targetNodeName = null;
+
+ for (YangNode node : utilManager.getYangNodeSet()) {
+ List<YangAugment> augments = linker.getListOfYangAugment(node);
+
+ for (YangAugment augment : augments) {
+ targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
+ .getNodeIdentifier().getName();
+ targetNode = augment.getAugmentedNode();
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+
+ }
+
+ /**
+ * Unit test case for inter file linking for multi level uses inside augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingInMultipleUses() throws IOException {
+
+ /** FIXME: once order of linking is done.
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "uses/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
+ linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
+
+ YangNode targetNode = null;
+ String targetNodeName = null;
+
+ for (YangNode node : utilManager.getYangNodeSet()) {
+ List<YangAugment> augments = linker.getListOfYangAugment(node);
+
+ for (YangAugment augment : augments) {
+ targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
+ .getNodeIdentifier().getName();
+ targetNode = augment.getAugmentedNode();
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ */
+ }
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
index bfde08d..bd598e4 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntaxTest.java
@@ -113,8 +113,6 @@
private static final String BASE_DIR_PKG = "target.UnitTestCase.";
private static final String DIR_PATH = "exist1.exist2.exist3";
private static final String PKG_INFO = "package-info.java";
- private static final String BASE_PKG = "target/UnitTestCase";
- private static final String TEST_DATA_1 = "This is to append a text to the file first1\n";
/**
* Unit test for private constructor.
@@ -319,5 +317,6 @@
assertThat(true, is(doesPackageExist(strPath)));
createDir.delete();
deleteDirectory(createDir);
+ deleteDirectory(new File(BASE_DIR_PKG.replace(PERIOD, SLASH)));
}
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java b/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
index 0198720..271036f 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtilTest.java
@@ -20,6 +20,8 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+
+import org.apache.commons.io.FileUtils;
import org.junit.Test;
import static org.apache.commons.io.FileUtils.deleteDirectory;
@@ -84,5 +86,6 @@
appendFileContents(createFile, createSourceFile);
updateFileHandle(createFile, null, true);
deleteDirectory(dir);
+ FileUtils.deleteDirectory(new File(BASE_PKG));
}
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java b/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
index e1b167d..6451e4d 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/YangIoUtilsTest.java
@@ -67,7 +67,7 @@
addPackageInfo(dirPath, CHECK1, CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
- FileUtils.deleteDirectory(dirPath);
+ FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
@@ -83,7 +83,7 @@
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, false, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
- FileUtils.deleteDirectory(dirPath);
+ FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
@@ -99,7 +99,7 @@
addPackageInfo(dirPath, CHECK1, PATH + CREATE_PATH, true, getStubPluginConfig());
File filePath = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath.isFile(), is(true));
- FileUtils.deleteDirectory(dirPath);
+ FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
@@ -117,6 +117,7 @@
File filePath1 = new File(dirPath + File.separator + PKG_INFO);
assertThat(filePath1.isFile(), is(false));
FileUtils.deleteDirectory(dirPath);
+ FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
@@ -180,7 +181,7 @@
File dirPath = createDirectories(CREATE_PATH);
assertThat(dirPath.isDirectory(), is(true));
- FileUtils.deleteDirectory(dirPath);
+ FileUtils.deleteDirectory(new File(BASE_DIR));
}
/**
diff --git a/plugin/src/test/resources/augmentTranslator/test4.yang b/plugin/src/test/resources/augmentTranslator/test4.yang
index daa0f88..bed22db 100644
--- a/plugin/src/test/resources/augmentTranslator/test4.yang
+++ b/plugin/src/test/resources/augmentTranslator/test4.yang
@@ -2,10 +2,7 @@
belongs-to "test" {
prefix "test";
- }
- import test1{
- prefix test1;
- }
+ }
organization "";
contact "";
diff --git a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
index 106b2aa..10b6c11 100644
--- a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
+++ b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
@@ -1723,9 +1723,9 @@
uses tet:te-link-state-derived;
}
- /*
+
augment "/te-link-event/te-link-attributes/underlay" {
description "Add state attributes to te-link underlay.";
uses te-link-state-underlay-attributes;
- } */
+ }
}
diff --git a/plugin/src/test/resources/xPathLinker/Case/submodule/test.yang b/plugin/src/test/resources/xPathLinker/Case/submodule/test.yang
new file mode 100644
index 0000000..dbff7e8
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/submodule/test.yang
@@ -0,0 +1,31 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ include test1;
+ include test2;
+ include test4;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /cont5/cont6 {
+ leaf a {
+ type int32;
+ }
+ }
+
+ augment /cont3/cont4/cont8 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/Case/submodule/test1.yang b/plugin/src/test/resources/xPathLinker/Case/submodule/test1.yang
new file mode 100644
index 0000000..23161d4
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/submodule/test1.yang
@@ -0,0 +1,47 @@
+submodule test1 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ include test4;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf2 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont1/cont2 {
+ container cont4 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont3/cont4 {
+ container cont8 {
+ leaf leaf8 {
+ type int32;
+ }
+ }
+ }
+
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/Case/submodule/test2.yang b/plugin/src/test/resources/xPathLinker/Case/submodule/test2.yang
new file mode 100644
index 0000000..26640ee
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/submodule/test2.yang
@@ -0,0 +1,36 @@
+submodule test2{
+ belongs-to test {
+ prefix test;
+ }
+
+ include test1;
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont5 {
+ leaf leaf5 {
+ type int32;
+ }
+ container cont6 {
+ leaf leaf6 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont1/cont2/cont4 {
+ container cont10 {
+ leaf leaf10 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/Case/submodule/test4.yang b/plugin/src/test/resources/xPathLinker/Case/submodule/test4.yang
new file mode 100644
index 0000000..fcbf522
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/submodule/test4.yang
@@ -0,0 +1,28 @@
+submodule test4 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont3 {
+ leaf leaf3 {
+ type int32;
+ }
+ container cont4 {
+ leaf leaf4 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/Case/uses/test.yang b/plugin/src/test/resources/xPathLinker/Case/uses/test.yang
new file mode 100644
index 0000000..e57a468
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/uses/test.yang
@@ -0,0 +1,31 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ include test1;
+ include test2;
+ include test4;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /cont5/cont6/cont3/cont4 {
+ leaf a {
+ type int32;
+ }
+ }
+
+ augment /group1/cont3/cont4/cont8 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/Case/uses/test1.yang b/plugin/src/test/resources/xPathLinker/Case/uses/test1.yang
new file mode 100644
index 0000000..2c5dc20
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/uses/test1.yang
@@ -0,0 +1,47 @@
+submodule test1 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ include test4;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf2 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont1/cont2 {
+ container cont4 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+
+ augment /group1/cont3/cont4 {
+ container cont8 {
+ leaf leaf8 {
+ type int32;
+ }
+ }
+ }
+
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/Case/uses/test2.yang b/plugin/src/test/resources/xPathLinker/Case/uses/test2.yang
new file mode 100644
index 0000000..fedb0aa
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/uses/test2.yang
@@ -0,0 +1,56 @@
+submodule test2{
+ belongs-to test {
+ prefix test;
+ }
+
+ include test1;
+ include test4;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ grouping group2 {
+ container cont11 {
+ }
+ }
+
+ container cont5 {
+ leaf leaf5 {
+ type int32;
+ }
+ container cont6 {
+ leaf leaf6 {
+ type int32;
+ }
+ uses group1;
+ }
+ }
+
+ container ethernet {
+ leaf leaf10 {
+ type string;
+ }
+ }
+
+
+ augment /ethernet {
+ uses group2;
+ }
+
+ augment /cont1/cont2/cont4 {
+ container cont10 {
+ leaf leaf10 {
+ type int32;
+ }
+
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/Case/uses/test4.yang b/plugin/src/test/resources/xPathLinker/Case/uses/test4.yang
new file mode 100644
index 0000000..589179d
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/Case/uses/test4.yang
@@ -0,0 +1,37 @@
+submodule test4 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ include test2;
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ grouping group1 {
+ container cont3 {
+ leaf leaf3 {
+ type int32;
+ }
+ container cont4 {
+ leaf leaf4 {
+ type int32;
+ }
+ }
+ }
+ }
+
+ augment /ethernet/cont11 {
+ leaf leaf11 {
+ type int32;
+ }
+ }
+
+}
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test.yang
index 139e2c5..adb4800 100644
--- a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test.yang
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test.yang
@@ -21,7 +21,7 @@
}
augment /test2:cont1/test2:cont2/test2:cont3/test1:cont2 {
- leaf a {
+ leaf leaf8 {
type int32;
}
}
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test1.yang
index ed3716f..0957e15 100644
--- a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test1.yang
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test1.yang
@@ -29,7 +29,7 @@
type int32;
}
container cont2 {
- leaf leaf1 {
+ leaf leaf3 {
type int32;
}
}
@@ -37,12 +37,12 @@
}
augment /test2:cont1/test2:cont2/test2:cont3 {
- leaf a {
+ leaf leaf2 {
type int32;
}
container cont2 {
- leaf leaf1 {
+ leaf leaf4 {
type int32;
}
}
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test2.yang
index f65bef0..0eeb46d 100644
--- a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test2.yang
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test2.yang
@@ -13,11 +13,11 @@
}
container cont1 {
- leaf leaf1 {
+ leaf leaf5 {
type int32;
}
container cont2 {
- leaf leaf1 {
+ leaf leaf6 {
type int32;
}
}
@@ -25,7 +25,7 @@
augment /cont1/cont2 {
container cont3 {
- leaf a {
+ leaf leaf7 {
type string;
}
}
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test.yang
index 80ee110..01aa34e 100644
--- a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test.yang
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test.yang
@@ -23,7 +23,7 @@
uses test2:group1;
}
- augment /cont2/group1/cont1/cont2 {
+ augment /cont2/cont1/cont2 {
leaf a {
type int32;
}
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test.yang
index 4b15645..15a6fab 100644
--- a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test.yang
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test.yang
@@ -19,14 +19,14 @@
}
augment /test2:cont1/test2:cont2/cont2 {
- leaf a {
+ leaf leaf {
type int32;
}
uses group1;
}
- augment /test2:cont1/test2:cont2/cont2/group1/cont1/cont2 {
- leaf a {
+ augment /test2:cont1/test2:cont2/cont2/cont1/cont2 {
+ leaf leaf1 {
type int32;
}
}
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test1.yang
index fbc3bcb..e7fbc31 100644
--- a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test1.yang
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test1.yang
@@ -21,7 +21,7 @@
grouping group1 {
container cont1 {
container cont2 {
- leaf a {
+ leaf leaf2 {
type string;
}
}
@@ -29,7 +29,7 @@
}
augment /test2:cont1/test2:cont2 {
- leaf a {
+ leaf leaf3 {
type int32;
}
container cont2 {
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test2.yang
index f20ac7d..2905f9a 100644
--- a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test2.yang
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test2.yang
@@ -13,11 +13,11 @@
}
container cont1 {
- leaf leaf1 {
+ leaf leaf4 {
type int32;
}
container cont2 {
- leaf leaf1 {
+ leaf leaf5 {
type int32;
}
}
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiUses/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiUses/test.yang
index 6cfb133..6d7473d 100644
--- a/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiUses/test.yang
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiUses/test.yang
@@ -29,7 +29,7 @@
uses group1;
}
- augment /cont2/group1/cont1/cont3 {
+ augment /cont2/cont1/cont3 {
leaf a {
type int32;
}
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleUses/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleUses/test.yang
index c60668a..3074db7 100644
--- a/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleUses/test.yang
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleUses/test.yang
@@ -24,7 +24,7 @@
uses group1;
}
- augment /cont2/group1/cont1 {
+ augment /cont2/cont1 {
leaf a {
type int32;
}