[ONOS-4799],[ONOS-4351] Augment inter file linker and Generated Code refactored.
Change-Id: Id1f3ac9c90a632373f51cc75d499c3110216be17
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 3847d3d..f63d8df 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -161,6 +161,8 @@
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
+ .resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
+ ((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
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
new file mode 100644
index 0000000..38a8188
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
@@ -0,0 +1,113 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangAugmentableNode;
+import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+
+/**
+ * Represent utilities for YANG linker.
+ */
+public final class YangLinkerUtils {
+
+ private YangLinkerUtils() {
+ }
+
+ /**
+ * 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
+ */
+ private static void detectCollision(YangNode targetNode, YangAugment augment) {
+ YangNode targetNodesChild = targetNode.getChild();
+ YangNode augmentsChild = augment.getChild();
+ YangLeavesHolder augmentsLeavesHolder = augment;
+ 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());
+ }
+ }
+ }
+ } 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());
+ }
+ }
+ }
+ } 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.
+ *
+ * @param targetNode target node
+ * @param augment augment node
+ */
+ public static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
+ // Detect collision for target node and augment node.
+ detectCollision(targetNode, augment);
+ List<YangAugmentedInfo> yangAugmentedInfo = ((YangAugmentableNode) targetNode).getAugmentedInfoList();
+ // Detect collision for target augment node and current augment node.
+ for (YangAugmentedInfo info : yangAugmentedInfo) {
+ detectCollision((YangAugment) info, augment);
+ }
+ }
+}
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 eb42233..bcc5a5f 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
@@ -24,6 +24,8 @@
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
@@ -55,10 +57,12 @@
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.datamodel.YangXPathResolver;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.YangLinkingPhase;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
@@ -68,6 +72,7 @@
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
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.FEATURE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
@@ -1438,14 +1443,73 @@
throw new DataModelException("Data Model Exception: Entity to resolved is not Resolvable");
}
- // Push the initial entity to resolve in stack.
- addInPartialResolvedStack(getEntityToResolveInfo());
+ if (entityToResolve instanceof YangXPathResolver) {
+ //Process x-path linking.
+ processXPathLinking(getEntityToResolveInfo(), dataModelRootNode);
- // Inter file linking and resolution.
- linkInterFileAndResolve();
+ } else {
- // Resolve the derived types having leafref.
- addDerivedRefTypeToRefTypeResolutionList();
+ // Push the initial entity to resolve in stack.
+ addInPartialResolvedStack(getEntityToResolveInfo());
+
+ // Inter file linking and resolution.
+ linkInterFileAndResolve();
+
+ addDerivedRefTypeToRefTypeResolutionList();
+ }
+ }
+
+ /**
+ * Process x-path linking for augment and leaf-ref.
+ *
+ * @param entityToResolveInfo entity to resolve
+ * @param root root node
+ */
+ private void processXPathLinking(YangEntityToResolveInfoImpl<T> entityToResolveInfo,
+ YangReferenceResolver root) {
+ YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
+ T entityToResolve = entityToResolveInfo.getEntityToResolve();
+ if (entityToResolve instanceof YangAugment) {
+ YangNode targetNode = null;
+ YangAugment augment = (YangAugment) entityToResolve;
+ targetNode = xPathLinker.processAugmentXpathLinking(augment.getTargetNode(),
+ (YangNode) root);
+ if (targetNode != null) {
+ if (targetNode instanceof YangAugmentableNode) {
+ detectCollisionForAugmentedNode(targetNode, augment);
+ ((YangAugmentableNode) targetNode).addAugmentation(augment);
+ augment.setAugmentedNode(targetNode);
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ resolvable.setResolvableStatus(RESOLVED);
+ } else {
+ throw new LinkerException("Invalid target node type " + targetNode.getNodeType() + " for "
+ + augment.getName());
+ }
+ } else {
+ throw new LinkerException("Failed to link " + augment.getName());
+ }
+ } else if (entityToResolve instanceof YangLeafRef) {
+ YangLeafRef leafRef = (YangLeafRef) entityToResolve;
+ Object target = xPathLinker.processLeafRefXpathLinking(leafRef.getAtomicPath(),
+ (YangNode) root);
+ if (target != null) {
+ YangLeaf leaf = null;
+ YangLeafList leafList = null;
+ leafRef.setReferredLeafOrLeafList(target);
+ if (target instanceof YangLeaf) {
+ leaf = (YangLeaf) target;
+ leafRef.setEffectiveDataType(leaf.getDataType());
+ } else {
+ leafList = (YangLeafList) target;
+ leafRef.setEffectiveDataType(leafList.getDataType());
+ }
+ leafRef.setResolvableStatus(RESOLVED);
+ //TODO: add logic for leaf-ref for path predicates.
+ } else {
+ throw new LinkerException("YANG file error: Unable to find base leaf/leaf-list for given leafref "
+ + leafRef.getPath());
+ }
+ }
}
/**
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
new file mode 100644
index 0000000..681a52c
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
@@ -0,0 +1,711 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import org.onosproject.yangutils.datamodel.YangAtomicPath;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangImport;
+import org.onosproject.yangutils.datamodel.YangInclude;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangLeavesHolder;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.YangUses;
+import org.onosproject.yangutils.linker.exceptions.LinkerException;
+
+/**
+ * Represents x-path linking.
+ *
+ * @param <T> x-path linking can be done for target node or for target leaf/leaf-list
+ */
+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 String curPrefix;
+ private Map<YangAtomicPath, YangNode> resolvedNodes;
+
+ /**
+ * Creates an instance of x-path linker.
+ */
+ public YangXpathLinker() {
+ absPaths = new ArrayList<>();
+ setResolvedNodes(new HashMap<>());
+ }
+
+ /**
+ * Returns list of target nodes paths.
+ *
+ * @return target nodes paths
+ */
+ private List<YangAtomicPath> getAbsPaths() {
+ return absPaths;
+ }
+
+ /**
+ * Sets target nodes paths.
+ *
+ * @param absPaths target nodes paths
+ */
+ private void setAbsPaths(List<YangAtomicPath> absPaths) {
+ this.absPaths = absPaths;
+ }
+
+ /**
+ * Returns current prefix.
+ *
+ * @return current prefix
+ */
+ private String getCurPrefix() {
+ return curPrefix;
+ }
+
+ /**
+ * Sets current prefix.
+ *
+ * @param curPrefix current prefix
+ */
+ private void setCurPrefix(String curPrefix) {
+ this.curPrefix = curPrefix;
+ }
+
+ /**
+ * Return root node.
+ *
+ * @return root Node
+ */
+ private YangNode getRootNode() {
+ return rootNode;
+ }
+
+ /**
+ * Sets root node.
+ *
+ * @param rootNode root node
+ */
+ private void setRootNode(YangNode rootNode) {
+ this.rootNode = rootNode;
+ }
+
+ /**
+ * 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
+ */
+ public Map<YangAtomicPath, YangNode> getResolvedNodes() {
+ return resolvedNodes;
+ }
+
+ /**
+ * Sets resolved nodes.
+ *
+ * @param resolvedNodes resolved nodes
+ */
+ private void setResolvedNodes(Map<YangAtomicPath, YangNode> resolvedNodes) {
+ this.resolvedNodes = resolvedNodes;
+ }
+
+ /**
+ * Adds node to resolved nodes.
+ *
+ * @param path absolute path
+ * @param node resolved node
+ */
+ private void addToResolvedNodes(YangAtomicPath path, YangNode node) {
+ getResolvedNodes().put(path, node);
+ }
+
+ /**
+ * Returns list of augment nodes.
+ *
+ * @param node root node
+ * @return list of augment nodes
+ */
+ public List<YangAugment> getListOfYangAugment(YangNode node) {
+ node = node.getChild();
+ List<YangAugment> augments = new ArrayList<>();
+ while (node != null) {
+ if (node instanceof YangAugment) {
+ augments.add((YangAugment) node);
+ }
+ node = node.getNextSibling();
+ }
+ return augments;
+ }
+
+ /**
+ * Process absolute node path for target leaf.
+ *
+ * @param absPaths absolute path node list
+ * @param root root node
+ * @return linked target node
+ */
+ public T processLeafRefXpathLinking(List<YangAtomicPath> absPaths, YangNode root) {
+
+ YangNode targetNode = null;
+ setRootNode(root);
+ YangAtomicPath leafRefPath = absPaths.get(absPaths.size() - 1);
+
+ // When leaf-ref path contains only one absolute path.
+ if (absPaths.size() == 1) {
+ targetNode = getTargetNodewhenSizeIsOne(absPaths);
+ } else {
+ absPaths.remove(absPaths.size() - 1);
+
+ setAbsPaths(absPaths);
+ targetNode = parseData(root);
+ }
+ if (targetNode == null) {
+ targetNode = parsePath(getIncludedNode(root));
+ }
+
+ if (targetNode != null) {
+ YangLeaf targetLeaf = searchReferredLeaf(targetNode, leafRefPath.getNodeIdentifier().getName());
+ if (targetLeaf == null) {
+ YangLeafList targetLeafList = searchReferredLeafList(targetNode,
+ leafRefPath.getNodeIdentifier().getName());
+ if (targetLeafList != null) {
+ return (T) targetLeafList;
+ } else {
+ throw new LinkerException(
+ "YANG file error: Unable to find base leaf/leaf-list for given leafref "
+ + leafRefPath.getNodeIdentifier().getName());
+ }
+ }
+ return (T) targetLeaf;
+ }
+ return null;
+ }
+
+ /**
+ * Returns target node when leaf-ref has only one absolute path in list.
+ *
+ * @param absPaths absolute paths
+ * @return target node
+ */
+ private YangNode getTargetNodewhenSizeIsOne(List<YangAtomicPath> absPaths) {
+ if (absPaths.get(0).getNodeIdentifier().getPrefix() != null
+ && !absPaths.get(0).getNodeIdentifier().getPrefix().equals(getRootsPrefix(getRootNode()))) {
+ return getImportedNode(getRootNode(), absPaths.get(0).getNodeIdentifier());
+ }
+ return getRootNode();
+
+ }
+
+ /**
+ * Process absolute node path linking for augment.
+ *
+ * @param absPaths absolute path node list
+ * @param root root node
+ * @return linked target node
+ */
+ public YangNode processAugmentXpathLinking(List<YangAtomicPath> absPaths, YangNode root) {
+
+ setAbsPaths(absPaths);
+ setRootNode(root);
+
+ YangNode targetNode = parseData(root);
+
+ if (targetNode == null) {
+ targetNode = parsePath(getIncludedNode(root));
+ }
+ return targetNode;
+
+ }
+
+ /**
+ * Searches for the referred leaf in target node.
+ *
+ * @param targetNode target node
+ * @param leafName leaf name
+ * @return target leaf
+ */
+ private YangLeaf searchReferredLeaf(YangNode targetNode, String leafName) {
+ if (!(targetNode instanceof YangLeavesHolder)) {
+ throw new LinkerException("Refered node " + targetNode.getName() +
+ "should be of type leaves holder ");
+ }
+ YangLeavesHolder holder = (YangLeavesHolder) targetNode;
+ List<YangLeaf> leaves = holder.getListOfLeaf();
+ for (YangLeaf leaf : leaves) {
+ if (leaf.getName().equals(leafName)) {
+ return leaf;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Searches for the referred leaf-list in target node.
+ *
+ * @param targetNode target node
+ * @param leafListName leaf-list name
+ * @return target leaf-list
+ */
+ private YangLeafList searchReferredLeafList(YangNode targetNode, String leafListName) {
+ if (!(targetNode instanceof YangLeavesHolder)) {
+ throw new LinkerException("Refered node " + targetNode.getName() +
+ "should be of type leaves holder ");
+ }
+ YangLeavesHolder holder = (YangLeavesHolder) targetNode;
+ List<YangLeafList> leavesList = holder.getListOfLeafList();
+ for (YangLeafList leafList : leavesList) {
+ if (leafList.getName().equals(leafListName)) {
+ return leafList;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Process linking using for node identifier for inter/intra file.
+ *
+ * @param root root node
+ * @return linked target node
+ */
+ private YangNode parseData(YangNode root) {
+ String rootPrefix = getRootsPrefix(root);
+ Iterator<YangAtomicPath> pathIterator = getAbsPaths().iterator();
+ YangAtomicPath path = pathIterator.next();
+ if (path.getNodeIdentifier().getPrefix() != null
+ && !path.getNodeIdentifier().getPrefix().equals(rootPrefix)) {
+ return parsePath(getImportedNode(root, path.getNodeIdentifier()));
+ } else {
+ return parsePath(root);
+ }
+ }
+
+ /**
+ * Process linking of target node in root node.
+ *
+ * @param root root node
+ * @return linked target node
+ */
+ private YangNode parsePath(YangNode root) {
+
+ YangNode tempNode = root;
+ Stack<YangNode> linkerStack = new Stack<>();
+ Iterator<YangAtomicPath> pathIterator = getAbsPaths().iterator();
+ YangAtomicPath tempPath = pathIterator.next();
+ setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
+ int index = 0;
+ YangNode tempAugment = null;
+ 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 {
+ tempAugment = resolveInterFileAugment(tempPath, root);
+ }
+
+ if (tempAugment != null) {
+ linkerStack.push(tempNode);
+ tempNode = tempAugment;
+ }
+
+ tempNode = searchTargetNode(tempNode, tempPath.getNodeIdentifier());
+ if (tempNode == null && linkerStack.size() != 0) {
+ tempNode = linkerStack.peek();
+ linkerStack.pop();
+ tempNode = searchTargetNode(tempNode, tempPath.getNodeIdentifier());
+ }
+
+ if (tempNode != null) {
+ addToResolvedNodes(tempPath, tempNode);
+ }
+
+ if (index == getAbsPaths().size() - 1) {
+ break;
+ }
+ tempPath = pathIterator.next();
+ index++;
+ } while (validate(tempNode, index));
+ return tempNode;
+ }
+
+ /**
+ * Resolves intra file augment linking.
+ *
+ * @param tempPath temporary absolute path
+ * @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);
+ if (getCurPrefix() != tempPath.getNodeIdentifier().getPrefix()) {
+ setPrefixResolverType(PrefixResolverType.INTRA_TO_INTER);
+ root = getIncludedNode(getRootNode());
+ }
+
+ setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
+ tempAugment = getAugment(tempPath.getNodeIdentifier(), root, getAbsPaths());
+ if (tempAugment == null) {
+ tempAugment = getAugment(tempPath.getNodeIdentifier(), getRootNode(), getAbsPaths());
+ }
+ return tempAugment;
+ }
+
+ /**
+ * Resolves inter file augment linking.
+ *
+ * @param tempPath temporary absolute path
+ * @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 {
+ 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)) {
+ return resolveInterToInterFileAugment(root);
+ }
+ return tempAugment;
+ }
+
+ /**
+ * Resolves augment when prefix changed from inter file to inter file.
+ * it may be possible that the prefix used in imported module is different the
+ * given list of node identifiers.
+ *
+ * @param root root node
+ * @return target node
+ */
+ private YangNode resolveInterToInterFileAugment(YangNode root) {
+ List<YangAugment> augments = getListOfYangAugment(root);
+ int index;
+ List<YangAtomicPath> absPaths = new ArrayList<>();
+ for (YangAugment augment : augments) {
+ index = 0;
+
+ for (YangAtomicPath path : augment.getTargetNode()) {
+
+ if (!searchForAugmentInImportedNode(path.getNodeIdentifier(), index)) {
+ absPaths.clear();
+ break;
+ }
+ absPaths.add(path);
+ index++;
+ }
+ if (!absPaths.isEmpty() && absPaths.size() == getAbsPaths().size() - 1) {
+ return augment;
+ } else {
+ absPaths.clear();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 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
+ * @return true if found
+ */
+ private boolean searchForAugmentInImportedNode(YangNodeIdentifier nodeId, int index) {
+ YangNodeIdentifier tempNodeId = getAbsPaths().get(index).getNodeIdentifier();
+ return nodeId.getName().equals(tempNodeId.getName());
+ }
+
+ /**
+ * Returns augment node.
+ *
+ * @param tempNodeId temporary absolute path id
+ * @param root root node
+ * @return linked target node
+ */
+ private YangNode getAugment(YangNodeIdentifier tempNodeId, YangNode root, List<YangAtomicPath> absPaths) {
+ String augmentName = getAugmentNodeIdentifier(tempNodeId, absPaths);
+ if (augmentName != null) {
+ return searchAugmentNode(root, augmentName);
+ }
+ return null;
+ }
+
+ /**
+ * Process linking using import list.
+ *
+ * @param root root node
+ * @param nodeId node identifier
+ * @return linked target node
+ */
+ private YangNode getImportedNode(YangNode root, YangNodeIdentifier nodeId) {
+
+ List<YangImport> importList = new ArrayList<>();
+
+ if (root instanceof YangModule) {
+ importList = ((YangModule) root).getImportList();
+ } else {
+ importList = ((YangSubModule) root).getImportList();
+ }
+
+ for (YangImport imported : importList) {
+ if (imported.getPrefixId().equals(nodeId.getPrefix())) {
+ return imported.getImportedNode();
+ }
+ }
+
+ return root;
+ }
+
+ /**
+ * Process linking using include list.
+ *
+ * @param root root node
+ * @return linked target node
+ */
+ private YangNode getIncludedNode(YangNode root) {
+
+ List<YangInclude> includeList = new ArrayList<>();
+
+ if (root instanceof YangModule) {
+ includeList = ((YangModule) root).getIncludeList();
+ } else {
+ includeList = ((YangSubModule) root).getIncludeList();
+ }
+
+ for (YangInclude included : includeList) {
+ return included.getIncludedNode();
+ }
+
+ return root;
+ }
+
+ /**
+ * Returns augments node id.
+ *
+ * @param nodeId node identifier
+ * @return augment node id
+ */
+ private String getAugmentNodeIdentifier(YangNodeIdentifier nodeId, List<YangAtomicPath> absPaths) {
+
+ Iterator<YangAtomicPath> nodeIdIterator = absPaths.iterator();
+ YangAtomicPath tempNodeId = null;
+ StringBuilder builder = new StringBuilder();
+ 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());
+ }
+ } else {
+ return builder.toString();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Searches augment node in 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)) {
+ return node;
+ }
+ }
+ node = node.getNextSibling();
+ }
+ return null;
+ }
+
+ /**
+ * Validates for target node if target node found or not.
+ *
+ * @param tempNode temporary node
+ * @param index current index of list
+ * @return false if target node found
+ */
+ private boolean validate(YangNode tempNode, int index) {
+
+ int size = getAbsPaths().size();
+ if (tempNode != null && index != size) {
+ return true;
+ } else if (tempNode != null && index == size) {
+ return false;
+ // this is your target node.
+ } else if (tempNode == null && index != size) {
+ return false;
+ // this could be in submodule as well.
+ }
+ return false;
+ }
+
+ /**
+ * Searches target node in root node.
+ *
+ * @param node root node
+ * @param curNodeId YANG node identifier
+ * @return linked target node
+ */
+ private YangNode searchTargetNode(YangNode node, YangNodeIdentifier curNodeId) {
+
+ if (node != null) {
+ node = node.getChild();
+ }
+
+ while (node != null) {
+ if (node.getName().equals(curNodeId.getName())) {
+ return node;
+ }
+ node = node.getNextSibling();
+ }
+ return null;
+ }
+
+ /**
+ * 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
+ * @return root prefix
+ */
+ private String getRootsPrefix(YangNode root) {
+ if (root instanceof YangModule) {
+ return ((YangModule) root).getPrefix();
+ } else {
+ return ((YangSubModule) root).getPrefix();
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
index b6172ed..f049be0 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
@@ -18,18 +18,20 @@
import java.util.List;
+import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.AUGMENT_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA;
@@ -38,22 +40,17 @@
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.generateNameForAugmentNode;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getParentsPrefix;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.parserException;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.validateNodeInTargetPath;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
- .constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
- .constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
@@ -106,7 +103,7 @@
checkStackIsNotEmpty(listener, MISSING_HOLDER, AUGMENT_DATA, ctx.augment().getText(), ENTRY);
// Validate augment argument string
- List<YangNodeIdentifier> targetNodes = getValidAbsoluteSchemaNodeId(ctx.augment().getText(),
+ List<YangAtomicPath> targetNodes = getValidAbsoluteSchemaNodeId(ctx.augment().getText(),
AUGMENT_DATA, ctx);
// Validate sub statement cardinality.
@@ -126,7 +123,7 @@
// TODO: handle in linker.
yangAugment.setTargetNode(targetNodes);
- yangAugment.setName(generateNameForAugmentNode(curData, targetNodes, listener));
+ yangAugment.setName(removeQuotesAndHandleConcat(ctx.augment().getText()));
try {
curNode.addChild(yangAugment);
@@ -135,6 +132,13 @@
AUGMENT_DATA, ctx.augment().getText(), ENTRY, e.getMessage()));
}
listener.getParsedDataStack().push(yangAugment);
+
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangAugment>(yangAugment,
+ curNode, line,
+ charPositionInLine);
+ addToResolutionList(resolutionInfo, ctx);
+
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, AUGMENT_DATA,
ctx.augment().getText(), ENTRY));
@@ -177,35 +181,19 @@
}
/**
- * Validates whether the current target node path is correct or not.
+ * Add to resolution list.
*
- * @param targetNodes list of target nodes
- * @param curNode current Node
- * @param ctx augment context
- * @param curNode current YANG node
+ * @param resolutionInfo resolution information.
+ * @param ctx context object of the grammar rule
*/
- private static void validateTargetNodePath(List<YangNodeIdentifier> targetNodes, YangNode curNode,
- GeneratedYangParser.AugmentStatementContext ctx) {
+ private static void addToResolutionList(YangResolutionInfoImpl<YangAugment> resolutionInfo,
+ GeneratedYangParser.AugmentStatementContext ctx) {
- YangNodeIdentifier moduleId = targetNodes.get(0);
- if (moduleId.getPrefix() == null) {
- if (!moduleId.getName().equals(curNode.getName())) {
- throw parserException(ctx);
- } else {
- //validateNodeInTargetPath(curNode, targetNodes, ctx);
- // TODO: handle in linker.
- }
- } else {
- String parentPrefix = getParentsPrefix(curNode);
- if (parentPrefix != null) {
- if (!parentPrefix.equals(moduleId.getPrefix())) {
- // TODO: handle in linker.
- } else {
- validateNodeInTargetPath(curNode, targetNodes, ctx);
- }
- } else {
- // TODO: handle in linker.
- }
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ AUGMENT_DATA, ctx.augment().getText(), EXIT, e.getMessage()));
}
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index 48ac0de..5ad6133 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -709,10 +709,10 @@
* @param ctx yang construct's context to get the line number and character position
* @return target nodes list of absolute schema node id
*/
- public static List<YangNodeIdentifier> getValidAbsoluteSchemaNodeId(String argumentString,
+ public static List<YangAtomicPath> getValidAbsoluteSchemaNodeId(String argumentString,
YangConstructType yangConstructType, ParserRuleContext ctx) {
- List<YangNodeIdentifier> targetNodes = new LinkedList<>();
+ List<YangAtomicPath> targetNodes = new ArrayList<>();
YangNodeIdentifier yangNodeIdentifier;
String tmpSchemaNodeId = removeQuotesAndHandleConcat(argumentString);
@@ -728,7 +728,9 @@
String[] tmpData = tmpSchemaNodeId.replaceFirst(CARET + SLASH, EMPTY_STRING).split(SLASH);
for (String nodeIdentifiers : tmpData) {
yangNodeIdentifier = getValidNodeIdentifier(nodeIdentifiers, yangConstructType, ctx);
- targetNodes.add(yangNodeIdentifier);
+ YangAtomicPath yangAbsPath = new YangAtomicPath();
+ yangAbsPath.setNodeIdentifier(yangNodeIdentifier);
+ targetNodes.add(yangAbsPath);
}
return targetNodes;
}
@@ -780,4 +782,4 @@
throw parserException;
}
}
-}
\ No newline at end of file
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
index ccb43e3..148dd0e 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
@@ -17,11 +17,9 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
@@ -41,6 +39,7 @@
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.deSerializeDataModel;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAR;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
@@ -155,32 +154,6 @@
}
/**
- * Returns de-serializes YANG data-model nodes.
- *
- * @param serailizedfileInfoSet YANG file info set
- * @return de-serializes YANG data-model nodes
- * @throws IOException when fails do IO operations
- */
- public static List<YangNode> deSerializeDataModel(List<String> serailizedfileInfoSet) throws IOException {
-
- List<YangNode> nodes = new ArrayList<>();
- for (String fileInfo : serailizedfileInfoSet) {
- YangNode node = null;
- try {
- FileInputStream fileInputStream = new FileInputStream(fileInfo);
- ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
- node = (YangNode) objectInputStream.readObject();
- nodes.add(node);
- objectInputStream.close();
- fileInputStream.close();
- } catch (IOException | ClassNotFoundException e) {
- throw new IOException(fileInfo + " not found.");
- }
- }
- return nodes;
- }
-
- /**
* Returns list of jar path.
*
* @param project maven project
@@ -188,8 +161,8 @@
* @param remoteRepos remote repository
* @return list of jar paths
*/
- private static List<String> resolveDependecyJarPath(MavenProject project, ArtifactRepository localRepository,
- List<ArtifactRepository> remoteRepos) {
+ private static List<String> resolveDependencyJarPath(MavenProject project, ArtifactRepository localRepository,
+ List<ArtifactRepository> remoteRepos) {
StringBuilder path = new StringBuilder();
List<String> jarPaths = new ArrayList<>();
@@ -232,7 +205,7 @@
List<ArtifactRepository> remoteRepos, String directory)
throws IOException {
- List<String> dependeciesJarPaths = resolveDependecyJarPath(project, localRepository, remoteRepos);
+ List<String> dependeciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
List<YangNode> resolvedDataModelNodes = new ArrayList<>();
for (String dependecy : dependeciesJarPaths) {
resolvedDataModelNodes.addAll(deSerializeDataModel(parseJarFile(dependecy, directory)));
diff --git a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index 7240725..7a894e6 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -87,8 +87,14 @@
/**
* Source directory for generated files.
*/
- @Parameter(property = "genFilesDir", defaultValue = "src/main/java")
- private String genFilesDir;
+ @Parameter(property = "classFileDir", defaultValue = "target/generated-sources")
+ private String classFileDir;
+
+ /**
+ * Source directory for manager's generated files.
+ */
+ @Parameter(property = "managerFileDir", defaultValue = "src/main/java")
+ private String managerFileDir;
/**
* Base directory for project.
@@ -153,11 +159,12 @@
/*
* For deleting the generated code in previous build.
*/
- deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
+ deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, outputDirectory));
String searchDir = getDirectory(baseDir, yangFilesDir);
- String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
+ String codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
+ String managerCodeGenDir = getDirectory(baseDir, managerFileDir) + SLASH;
// Creates conflict resolver and set values to it.
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
@@ -167,6 +174,7 @@
conflictResolver.setPrefixForIdentifier(prefixForIdentifier);
YangPluginConfig yangPlugin = new YangPluginConfig();
yangPlugin.setCodeGenDir(codeGenDir);
+ yangPlugin.setManagerCodeGenDir(managerCodeGenDir);
yangPlugin.setConflictResolver(conflictResolver);
/*
@@ -195,18 +203,18 @@
// Serialize data model.
serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
- addToCompilationRoot(getDirectory(baseDir, genFilesDir), project, context);
+ addToCompilationRoot(codeGenDir, project, context);
+ addToCompilationRoot(managerCodeGenDir, project, context);
copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
} catch (IOException | ParserException e) {
- getLog().info(e);
String fileName = "";
if (getCurYangFileInfo() != null) {
fileName = getCurYangFileInfo().getYangFileName();
}
try {
translatorErrorHandler(getRootNode());
- deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
+ deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
} catch (IOException ex) {
throw new MojoExecutionException(
"Error handler failed to delete files for data model node.");
@@ -255,14 +263,12 @@
public void resolveDependenciesUsingLinker()
throws MojoExecutionException {
createYangNodeSet();
- for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
- setCurYangFileInfo(yangFileInfo);
- try {
- yangLinker.resolveDependencies(getYangNodeSet());
- } catch (LinkerException e) {
- throw new MojoExecutionException(e.getMessage());
- }
+ try {
+ yangLinker.resolveDependencies(getYangNodeSet());
+ } catch (LinkerException e) {
+ throw new MojoExecutionException(e.getMessage());
}
+
}
/**
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
index 2ffd282..87e4679 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
@@ -122,6 +122,11 @@
public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
/**
+ * Event subject setter implementation of class.
+ */
+ public static final int AUGMENTE_CLASS_CONSTRUCTOR_MASK = 1048576;
+
+ /**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
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 b1c36ec..3389659 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,10 +21,6 @@
import java.util.TreeSet;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
-import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
@@ -40,9 +36,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
-
import static java.util.Collections.sort;
/**
@@ -220,33 +214,6 @@
}
/**
- * Returns import for array list attribute.
- *
- * @return import for array list attribute
- */
- public String getImportForArrayList() {
- return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
- }
-
- /**
- * Returns import string for AugmentationHolder class.
- *
- * @return import string for AugmentationHolder class
- */
- public String getAugmentationHolderImport() {
- return IMPORT + PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
- }
-
- /**
- * Returns import string for AugmentedInfo class.
- *
- * @return import string for AugmentedInfo class
- */
- public String getAugmentedInfoImport() {
- return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS;
- }
-
- /**
* Returns import string for ListenerService class.
*
* @return import string for ListenerService class
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
index 9ae2986..39ce34f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
@@ -23,7 +23,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
/**
* Represents implementation of java bean code fragments temporary implementations.
@@ -88,7 +88,7 @@
*/
private void addConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
- appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
+ appendToFile(getConstructorImplTempFileHandle(), getConstructor(attr,
getGeneratedJavaFiles(), pluginConfig));
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
index d383a43..09471cd 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
@@ -36,7 +36,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
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 03ace2a..bbc346d 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
@@ -29,6 +29,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
@@ -44,6 +45,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
@@ -63,10 +65,8 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
@@ -80,17 +80,13 @@
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.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentationHoldersImport;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports;
+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;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
@@ -104,12 +100,14 @@
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.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
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;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
@@ -227,6 +225,10 @@
private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
/**
+ * File name for augment copy constructor method.
+ */
+ private static final String AUGMENT_CONSTRUCTOR_FILE_NAME = "AugmentConstructor";
+ /**
* Java file handle for interface file.
*/
private File interfaceJavaFileHandle;
@@ -302,6 +304,11 @@
private boolean isAttributePresent;
/**
+ * Temporary file handle for augments copy constructor method of class.
+ */
+ private File augmentConstructorImplTempFileHandle;
+
+ /**
* Retrieves the absolute path where the file needs to be generated.
*
* @return absolute path where the file needs to be generated
@@ -539,6 +546,7 @@
addGeneratedTempFile(ATTRIBUTES_MASK);
addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
+ addGeneratedTempFile(AUGMENTE_CLASS_CONSTRUCTOR_MASK);
}
/*
@@ -617,6 +625,9 @@
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));
+ }
}
@@ -801,6 +812,24 @@
}
/**
+ * Returns augments copy constructor method impl class file.
+ *
+ * @return augments copy constructor method impl class file
+ */
+ public File getAugmentConstructorImplTempFileHandle() {
+ return augmentConstructorImplTempFileHandle;
+ }
+
+ /**
+ * Sets augments copy constructor method impl class.
+ *
+ * @param augmentConstructorImplTempFileHandle augments copy constructor method impl class file
+ */
+ public void setAugmentConstructorImplTempFileHandle(File augmentConstructorImplTempFileHandle) {
+ this.augmentConstructorImplTempFileHandle = augmentConstructorImplTempFileHandle;
+ }
+
+ /**
* Adds attribute for class.
*
* @param attr attribute info
@@ -966,13 +995,24 @@
* @throws IOException when fails to append to temporary file
*/
private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
- JavaAttributeInfo fromStringAttributeInfo)
+ JavaAttributeInfo fromStringAttributeInfo)
throws IOException {
appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
fromStringAttributeInfo) + NEW_LINE);
}
/**
+ * Adds constructor for augment class.
+ *
+ * @param attr attribute info
+ * @throws IOException when fails to append to temporary file
+ */
+ private void addAugmentConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ throws IOException {
+ appendToFile(getAugmentConstructorImplTempFileHandle(), getAugmentedConstructor(attr, pluginConfig));
+ }
+
+ /**
* Returns a temporary file handle for the specific file type.
*
* @param fileName file name
@@ -981,7 +1021,7 @@
*/
File getTemporaryFileHandle(String fileName)
throws IOException {
- String path = getTempDirPath();
+ String path = getTempDirPath(getAbsoluteDirPath());
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
@@ -1011,13 +1051,14 @@
* Returns data from the temporary files.
*
* @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
*/
- public String getTemporaryDataFromFileHandle(File file)
+ public String getTemporaryDataFromFileHandle(File file, String absolutePath)
throws IOException {
- String path = getTempDirPath();
+ String path = getTempDirPath(absolutePath);
if (new File(path + file.getName()).exists()) {
return readAppendFile(path + file.getName(), EMPTY_STRING);
} else {
@@ -1029,10 +1070,11 @@
/**
* Returns temporary directory path.
*
+ * @param absolutePath absolute path
* @return directory path
*/
- String getTempDirPath() {
- return getPackageDirPathFromJavaJPackage(getAbsoluteDirPath()) + SLASH + getGeneratedJavaClassName()
+ String getTempDirPath(String absolutePath) {
+ return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName()
+ TEMP_FOLDER_NAME_SUFIX + SLASH;
}
@@ -1084,7 +1126,7 @@
* @throws IOException IO operation exception
*/
public static void addCurNodeInfoInParentTempFile(YangNode curNode,
- boolean isList, YangPluginConfig pluginConfig)
+ boolean isList, YangPluginConfig pluginConfig)
throws IOException {
YangNode parent = getParentNodeInGenCode(curNode);
if (!(parent instanceof JavaCodeGenerator)) {
@@ -1118,7 +1160,7 @@
* @throws IOException IO operation exception
*/
public static void addCurNodeAsAttributeInTargetTempFile(YangNode curNode,
- YangPluginConfig pluginConfig, YangNode targetNode)
+ YangPluginConfig pluginConfig, YangNode targetNode)
throws IOException {
if (!(targetNode instanceof JavaCodeGenerator)) {
@@ -1156,7 +1198,7 @@
* files
*/
public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
- YangNode targetNode, boolean isListNode) {
+ YangNode targetNode, boolean isListNode) {
String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
if (curNodeName == null) {
updateJavaFileInfo(curNode, null);
@@ -1179,11 +1221,11 @@
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(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))) {
@@ -1208,63 +1250,6 @@
}
/**
- * Resolves groupings java qualified info.
- *
- * @param curNode grouping node
- * @param pluginConfig plugin configurations
- * @return groupings java qualified info
- */
- public static JavaQualifiedTypeInfo resolveGroupingsQuailifiedInfo(YangNode curNode,
- YangPluginConfig pluginConfig) {
-
- JavaFileInfo groupingFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo();
- if (groupingFileInfo.getPackage() == null) {
- List<String> parentNames = new ArrayList<>();
-
- YangNode tempNode = curNode.getParent();
- YangNode groupingSuperParent = null;
- while (tempNode != null) {
- parentNames.add(tempNode.getName());
- groupingSuperParent = tempNode;
- tempNode = tempNode.getParent();
- }
-
- String pkg = null;
- JavaFileInfo parentInfo = ((JavaFileInfoContainer) groupingSuperParent).getJavaFileInfo();
- if (parentInfo.getPackage() == null) {
- if (groupingSuperParent instanceof YangJavaModule) {
- YangJavaModule module = (YangJavaModule) groupingSuperParent;
- String modulePkg = getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
- .getRevision().getRevDate(), pluginConfig.getConflictResolver());
- pkg = modulePkg;
- } else if (groupingSuperParent instanceof YangJavaSubModule) {
- YangJavaSubModule submodule = (YangJavaSubModule) groupingSuperParent;
- String subModulePkg = getRootPackage(submodule.getVersion(),
- submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
- submodule.getRevision().getRevDate(), pluginConfig.getConflictResolver());
- pkg = subModulePkg;
- }
- } else {
- pkg = parentInfo.getPackage();
- }
- for (String name : parentNames) {
- pkg = pkg + PERIOD + getCamelCase(name, pluginConfig.getConflictResolver());
- }
-
- qualifiedTypeInfo.setPkgInfo(pkg.toLowerCase());
- qualifiedTypeInfo.setClassInfo(
- getCapitalCase(getCamelCase(curNode.getName(), pluginConfig.getConflictResolver())));
- return qualifiedTypeInfo;
-
- } else {
- qualifiedTypeInfo.setPkgInfo(groupingFileInfo.getPackage().toLowerCase());
- qualifiedTypeInfo.setClassInfo(getCapitalCase(groupingFileInfo.getJavaName()));
- return qualifiedTypeInfo;
- }
- }
-
- /**
* Returns interface fragment files for node.
*
* @param node YANG node
@@ -1308,7 +1293,7 @@
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
- getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
+ getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
}
/**
@@ -1319,28 +1304,40 @@
* @throws IOException IO operation fail
*/
public void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
- YangPluginConfig yangPluginConfig)
+ YangPluginConfig yangPluginConfig)
throws IOException {
if (listOfLeaves != null) {
for (YangLeaf leaf : listOfLeaves) {
if (!(leaf instanceof JavaLeafInfoContainer)) {
throw new TranslatorException("Leaf does not have java information");
}
- JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
- javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
- javaLeaf.updateJavaQualifiedInfo();
- JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
- javaLeaf.getJavaQualifiedInfo(),
- javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
- javaLeaf.getDataType(),
- getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
- false);
- addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
+ addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(leaf, yangPluginConfig),
+ yangPluginConfig);
}
}
}
/**
+ * Returns java attribute for leaf.
+ *
+ * @param leaf YANG leaf
+ * @param yangPluginConfig plugin configurations
+ * @return java attribute for leaf
+ */
+ private JavaAttributeInfo getJavaAttributeOfLeaf(YangLeaf leaf,
+ YangPluginConfig yangPluginConfig) {
+ JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
+ javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
+ javaLeaf.updateJavaQualifiedInfo();
+ return getAttributeInfoForTheData(
+ javaLeaf.getJavaQualifiedInfo(),
+ javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
+ javaLeaf.getDataType(),
+ getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
+ false);
+ }
+
+ /**
* Adds leaf list's attributes in generated files.
*
* @param listOfLeafList list of YANG leaves
@@ -1354,22 +1351,33 @@
if (!(leafList instanceof JavaLeafInfoContainer)) {
throw new TranslatorException("Leaf-list does not have java information");
}
- JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
- javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
- javaLeaf.updateJavaQualifiedInfo();
- getJavaImportData().setIfListImported(true);
- JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
- javaLeaf.getJavaQualifiedInfo(),
- javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
- javaLeaf.getDataType(),
- getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
- true);
- addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, yangPluginConfig);
+ addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(leafList, yangPluginConfig),
+ yangPluginConfig);
}
}
}
/**
+ * Returns java attribute for leaf-list.
+ *
+ * @param leafList YANG leaf-list
+ * @param yangPluginConfig plugin configurations
+ * @return java attribute for leaf-list
+ */
+ private JavaAttributeInfo getJavaAttributeOfLeafList(YangLeafList leafList, YangPluginConfig yangPluginConfig) {
+ JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
+ javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
+ javaLeaf.updateJavaQualifiedInfo();
+ getJavaImportData().setIfListImported(true);
+ return getAttributeInfoForTheData(
+ javaLeaf.getJavaQualifiedInfo(),
+ javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
+ javaLeaf.getDataType(),
+ getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
+ true);
+ }
+
+ /**
* Adds all the leaves in the current data model node as part of the
* generated temporary file.
*
@@ -1378,7 +1386,7 @@
* @throws IOException IO operation fail
*/
public void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
- YangPluginConfig yangPluginConfig)
+ YangPluginConfig yangPluginConfig)
throws IOException {
if (!(curNode instanceof YangLeavesHolder)) {
throw new TranslatorException("Data model node does not have any leaves");
@@ -1455,6 +1463,15 @@
}
/**
+ * Returns java class name.
+ *
+ * @return java class name
+ */
+ String getImplClassName() {
+ return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
+ }
+
+ /**
* Returns the directory path.
*
* @return directory path
@@ -1475,6 +1492,8 @@
List<String> imports = new ArrayList<>();
imports = getJavaImportData().getImports();
+ JavaFileInfo curInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
createPackage(curNode);
/*
@@ -1505,50 +1524,50 @@
validateLineLength(getInterfaceJavaFileHandle());
}
insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
- if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
- addAugmentationHoldersImport(curNode, imports, false);
- }
- if (isAugmentedInfoExtended(getJavaExtendsListHolder().getExtendsList())) {
- addAugmentedInfoImport(curNode, imports, false);
- }
+
if (curNode instanceof YangCase) {
removeCaseImport(imports);
}
+ if (curNode instanceof YangJavaAugment) {
+ updateAugmentConstructorTempFile(curNode, curInfo.getPluginConfig());
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+ List<JavaQualifiedTypeInfo> infoList = augment.getExtendedClassInfo();
+ for (JavaQualifiedTypeInfo info : infoList) {
+ if (info.getClassInfo()
+ .equals(getCapitalCase(getCamelCase(augment.getAugmentedNode().getName(), null)))) {
+ removeAugmentedImport(imports, info);
+ }
+
+ }
+ }
}
if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(curNode, imports);
}
- if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
- addAugmentedInfoImport(curNode, imports, true);
- addArrayListImport(curNode, imports, true);
- }
sortImports(imports);
/*
- * Create builder class file.
- */
- setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
- setBuilderClassJavaFileHandle(
- generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode,
- isAttributePresent()));
- /*
* Create impl class file.
*/
- if ((fileType & IMPL_CLASS_MASK) != 0) {
- setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
- setImplClassJavaFileHandle(
- generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent()));
+ setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName()));
+ setImplClassJavaFileHandle(
+ generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
+
+ /*
+ * Create builder class file.
+ */
+ if ((fileType & BUILDER_CLASS_MASK) != 0) {
+ setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
+ setBuilderClassJavaFileHandle(
+ generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
+ isAttributePresent()));
/*
* Append impl class to builder class and close it.
*/
- mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
- validateLineLength(getBuilderClassJavaFileHandle());
+ mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
+ validateLineLength(getImplClassJavaFileHandle());
}
- insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
- if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
- addAugmentedInfoImport(curNode, imports, false);
- addArrayListImport(curNode, imports, false);
- }
+ insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
}
/*
* Close all the file handles.
@@ -1557,6 +1576,47 @@
}
/**
+ * Updates augment constructor temp file.
+ *
+ * @param curNode current augment node
+ * @param pluginConfig plugin configurations
+ * @throws IOException when fails to do IO operations
+ */
+ private void updateAugmentConstructorTempFile(YangNode curNode, YangPluginConfig pluginConfig)
+ throws IOException {
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+
+ YangNode augmentedNode = augment.getAugmentedNode();
+ if (augmentedNode instanceof YangLeavesHolder) {
+ YangLeavesHolder holder = (YangLeavesHolder) augmentedNode;
+ if (holder.getListOfLeaf() != null) {
+ for (YangLeaf leaf : holder.getListOfLeaf()) {
+ addAugmentConstructor(getJavaAttributeOfLeaf(leaf,
+ pluginConfig), pluginConfig);
+ }
+
+ }
+ if (holder.getListOfLeafList() != null) {
+ for (YangLeafList leafList : holder.getListOfLeafList()) {
+ addAugmentConstructor(getJavaAttributeOfLeafList(leafList,
+ pluginConfig), pluginConfig);
+ }
+
+ }
+ }
+ augmentedNode = augmentedNode.getChild();
+ boolean isList = false;
+ while (augmentedNode != null) {
+ if (augmentedNode instanceof YangList) {
+ isList = true;
+ }
+ addAugmentConstructor(getCurNodeAsAttributeInTarget(augmentedNode, augment, isList), pluginConfig);
+ augmentedNode = augmentedNode.getNextSibling();
+ }
+
+ }
+
+ /**
* Adds imports for ToString and HashCodeMethod.
*
* @param curNode current YANG node
@@ -1570,6 +1630,27 @@
}
/**
+ * Removes augmented node import info from import list.
+ *
+ * @param imports list of imports
+ * @return import for class
+ */
+ private List<String> removeAugmentedImport(List<String> imports, JavaQualifiedTypeInfo augmentedInfo) {
+ String augmentedNodeImport = null;
+ if (imports != null && augmentedInfo != null) {
+ augmentedNodeImport = IMPORT + augmentedInfo.getPkgInfo() + PERIOD + getCapitalCase(DEFAULT)
+ + augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
+ + BUILDER + SEMI_COLAN + NEW_LINE;
+ imports.remove(augmentedNodeImport);
+ augmentedNodeImport = IMPORT + augmentedInfo.getPkgInfo() + PERIOD
+ + augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
+ + BUILDER + SEMI_COLAN + NEW_LINE;
+ imports.remove(augmentedNodeImport);
+ }
+ return imports;
+ }
+
+ /**
* Removes case import info from import list.
*
* @param imports list of imports
@@ -1602,13 +1683,13 @@
closeFile(getInterfaceJavaFileHandle(), isError);
}
if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
- closeFile(getBuilderClassJavaFileHandle(), isError);
+ closeFile(getBuilderClassJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
closeFile(getBuilderInterfaceJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
- closeFile(getImplClassJavaFileHandle(), true);
+ closeFile(getImplClassJavaFileHandle(), isError);
}
/*
@@ -1632,6 +1713,9 @@
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
closeFile(getFromStringImplTempFileHandle(), true);
}
+ if ((getGeneratedTempFiles() & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) {
+ closeFile(getAugmentConstructorImplTempFileHandle(), true);
+ }
}
/**
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 e5a7308..9cbe1fc 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
@@ -27,7 +27,6 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
@@ -54,9 +53,9 @@
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.TempJavaCodeFragmentFilesUtils.addAnnotationsImports;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.translator.tojava.utils.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;
@@ -390,7 +389,7 @@
}
if (isNotification) {
- addListnersImport(curNode, imports, true, LISTENER_SERVICE);
+ addListenersImport(curNode, imports, true, LISTENER_SERVICE);
}
/**
* Creates rpc interface file.
@@ -399,8 +398,8 @@
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
if (isNotification) {
- addListnersImport(curNode, imports, false, LISTENER_SERVICE);
- addListnersImport(curNode, imports, true, LISTENER_REG);
+ addListenersImport(curNode, imports, false, LISTENER_SERVICE);
+ addListenersImport(curNode, imports, true, LISTENER_REG);
}
addAnnotationsImports(imports, true);
/**
@@ -411,14 +410,14 @@
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
if (isNotification) {
- addListnersImport(curNode, imports, false, LISTENER_REG);
+ addListenersImport(curNode, imports, false, LISTENER_REG);
}
addAnnotationsImports(imports, false);
if (isNotification) {
- generateEventJavaFile(GENERATE_EVENT_CLASS, curNode);
+ generateEventJavaFile(curNode);
generateEventListenerJavaFile(GENERATE_EVENT_LISTENER_INTERFACE, curNode);
- generateEventSubjectJavaFile(GENERATE_EVENT_SUBJECT_CLASS, curNode);
+ generateEventSubjectJavaFile(curNode);
}
/**
@@ -478,11 +477,10 @@
/**
* Constructs java code exit.
*
- * @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
- public void generateEventJavaFile(int fileType, YangNode curNode)
+ public void generateEventJavaFile(YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
@@ -536,11 +534,10 @@
/**
* Constructs java code exit.
*
- * @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
- public void generateEventSubjectJavaFile(int fileType, YangNode curNode)
+ public void generateEventSubjectJavaFile(YangNode curNode)
throws IOException {
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
@@ -778,7 +775,7 @@
/**
* Returns a temporary file handle for the event's file type.
*
- * @param fileName file name
+ * @param name file name
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
@@ -786,9 +783,10 @@
throws IOException {
JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ JavaFileInfo childInfo = ((JavaFileInfoContainer) curNode.getChild()).getJavaFileInfo();
return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
- parentInfo);
+ childInfo);
}
/**
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 989ac0c..69c9b1d 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
@@ -39,7 +39,7 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
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 cc54b24..ef185fa 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
@@ -16,17 +16,22 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represents augment information extended to support java code generation.
@@ -38,11 +43,21 @@
private static final long serialVersionUID = 806201632L;
/**
+ * Prefix to be added to generated java file for augment node.
+ */
+ private static final String AUGMENTED = "Augmented";
+
+ /**
* Contains the information of the java file being generated.
*/
private JavaFileInfo javaFileInfo;
/**
+ * TargetNodes java qualified info.
+ */
+ private List<JavaQualifiedTypeInfo> extendedClassInfo;
+
+ /**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
*/
@@ -54,6 +69,7 @@
public YangJavaAugment() {
super();
setJavaFileInfo(new JavaFileInfo());
+ setExtendedClassInfo(new ArrayList<>());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
@@ -130,4 +146,46 @@
throw new TranslatorException("Failed to generate code for augmentable node " + getName());
}
}
+
+ /**
+ * Returns augment class name.
+ *
+ * @return augment class name
+ */
+ public String getAugmentClassName() {
+ YangNodeIdentifier nodeId = getTargetNode().get(getTargetNode().size() - 1).getNodeIdentifier();
+ if (nodeId.getPrefix() != null) {
+ return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + getCapitalCase(nodeId.getName());
+ } else {
+ return AUGMENTED + getCapitalCase(nodeId.getName());
+ }
+ }
+
+ /**
+ * Returns extended class info.
+ *
+ * @return extended class info
+ */
+ public List<JavaQualifiedTypeInfo> getExtendedClassInfo() {
+ return extendedClassInfo;
+ }
+
+ /**
+ * Sets extended class info.
+ *
+ * @param augmentedInfo extended class info
+ */
+ private void setExtendedClassInfo(List<JavaQualifiedTypeInfo> augmentedInfo) {
+ extendedClassInfo = augmentedInfo;
+ }
+
+ /**
+ * Adds to extended class info list.
+ *
+ * @param augmentedInfo extended class info
+ */
+ public void addToExtendedClassInfo(JavaQualifiedTypeInfo augmentedInfo) {
+ getExtendedClassInfo().add(augmentedInfo);
+ }
+
}
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 ec0e637..a73a5b4 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
@@ -35,7 +35,7 @@
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;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
+import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
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/javamodel/YangJavaModelUtils.java
index 8687115..582b9b5 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModelUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModelUtils.java
@@ -16,12 +16,18 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
+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.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
+import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
+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;
@@ -38,7 +44,12 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
+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.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
@@ -62,12 +73,17 @@
* @throws IOException IO operations fails
*/
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ YangPluginConfig yangPluginConfig)
throws IOException {
- javaCodeGeneratorInfo.getJavaFileInfo()
- .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
- yangPluginConfig.getConflictResolver()));
+ if (javaCodeGeneratorInfo instanceof YangJavaAugment) {
+ javaCodeGeneratorInfo.getJavaFileInfo()
+ .setJavaName(((YangJavaAugment) javaCodeGeneratorInfo).getAugmentClassName());
+ } else {
+ javaCodeGeneratorInfo.getJavaFileInfo()
+ .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
+ yangPluginConfig.getConflictResolver()));
+ }
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
@@ -83,15 +99,14 @@
* @throws IOException IO operations fails
*/
private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
- String pkg)
- throws IOException {
+ String pkg) throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPlugin.getConflictResolver()));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
- javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
+ javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getManagerCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
}
@@ -114,7 +129,7 @@
* @throws IOException IO operations fails
*/
private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ YangPluginConfig yangPluginConfig)
throws IOException {
if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
/*
@@ -174,7 +189,7 @@
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("translation is not supported for the node");
@@ -192,7 +207,7 @@
* @throws IOException when fails to do IO operations
*/
private static void updateNotificaitonNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ YangPluginConfig yangPluginConfig)
throws IOException {
if ((YangNode) javaCodeGeneratorInfo instanceof YangJavaModule) {
for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
@@ -220,7 +235,7 @@
* @throws IOException IO operations fails
*/
public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPlugin, boolean isMultiInstance)
+ YangPluginConfig yangPlugin, boolean isMultiInstance)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("Invalid node for translation");
@@ -245,7 +260,7 @@
* @throws IOException IO operations fails
*/
public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPlugin)
+ YangPluginConfig yangPlugin)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("invalid node for translation");
@@ -253,26 +268,44 @@
generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
- /*
- TODO: Need to use this, when augmentation is added in YMS
- * For augmentation of nodes.
-
- if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) {
- JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo();
- augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER);
- augmentationHoldersInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
+ if (javaCodeGeneratorInfo instanceof YangJavaAugment) {
+ JavaQualifiedTypeInfo augmentedBuilderInfo = new JavaQualifiedTypeInfo();
+ JavaQualifiedTypeInfo augmentedBuilderClassInfo = new JavaQualifiedTypeInfo();
+ JavaQualifiedTypeInfo augmentedClassInfo = new JavaQualifiedTypeInfo();
+ JavaQualifiedTypeInfo augmentedImplInfo = new JavaQualifiedTypeInfo();
+ YangNode augmentedNode = ((YangJavaAugment) javaCodeGeneratorInfo).getAugmentedNode();
+ String name = null;
+ JavaFileInfo augmentedfileInfo = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo();
+ if (augmentedfileInfo.getJavaName() != null) {
+ name = getCapitalCase(augmentedfileInfo.getJavaName());
+ augmentedClassInfo.setClassInfo(name);
+ augmentedClassInfo.setPkgInfo(augmentedfileInfo.getPackage());
+ } else {
+ name = getCapitalCase(getCamelCase(augmentedNode.getName(), yangPlugin.getConflictResolver()));
+ augmentedClassInfo.setClassInfo(name);
+ augmentedClassInfo.setPkgInfo(getAugmentedNodesPackage(augmentedNode, yangPlugin));
+ }
+ augmentedBuilderInfo.setClassInfo(name + PERIOD + name + BUILDER);
+ augmentedBuilderInfo.setPkgInfo(augmentedClassInfo.getPkgInfo());
+ augmentedBuilderClassInfo.setClassInfo(getCapitalCase(DEFAULT) + name + PERIOD + name + BUILDER);
+ augmentedBuilderClassInfo.setPkgInfo(augmentedClassInfo.getPkgInfo());
+ augmentedImplInfo.setClassInfo(getCapitalCase(DEFAULT) + name);
+ augmentedImplInfo.setPkgInfo(augmentedBuilderInfo.getPkgInfo());
+ ((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedBuilderInfo);
+ ((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedImplInfo);
+ ((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedBuilderClassInfo);
+ ((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedClassInfo);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(augmentationHoldersInfo, (YangNode) javaCodeGeneratorInfo);
-
- } else if (javaCodeGeneratorInfo instanceof YangAugment) {
- JavaQualifiedTypeInfo augmentedInfo = new JavaQualifiedTypeInfo();
- augmentedInfo.setClassInfo(AUGMENTED_INFO);
- augmentedInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
+ .addToExtendsList(augmentedClassInfo, (YangNode) javaCodeGeneratorInfo);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo);
+ .addToExtendsList(augmentedBuilderInfo, (YangNode) javaCodeGeneratorInfo);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(augmentedImplInfo, (YangNode) javaCodeGeneratorInfo);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(augmentedBuilderClassInfo, (YangNode) javaCodeGeneratorInfo);
}
- */
+
if (javaCodeGeneratorInfo instanceof YangCase) {
YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
@@ -289,6 +322,45 @@
}
}
+ 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.
*
@@ -297,7 +369,7 @@
* @throws IOException IO operations fails
*/
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("invalid node for translation");
@@ -370,4 +442,44 @@
pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
return pkg.toLowerCase();
}
+
+ /**
+ * Returns true if root node contains any data node.
+ *
+ * @param node root YANG node
+ * @return true if root node contains any data node
+ */
+ 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;
+ }
+ node = node.getChild();
+ return node != null && !(node instanceof YangTypeDef) && !(node instanceof YangGrouping);
+ }
+
+ /**
+ * Return false if files are already present.
+ *
+ * @param info java file info
+ * @return false if files already present
+ */
+ public static boolean isGenerationOfCodeReq(JavaFileInfo info) {
+ File codeGenDir = new File(info.getBaseCodeGenPath()
+ + info.getPackageFilePath());
+ File[] files = codeGenDir.listFiles();
+ if (files.length >= 1) {
+ for (File file : files) {
+ if (file.getName().contentEquals(getCapitalCase(info.getJavaName() + MANAGER + ".java"))
+ || file.getName().contentEquals(getCapitalCase(info.getJavaName() + SERVICE + ".java"))) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
}
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 b53ec92..10cf879 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
@@ -33,8 +33,10 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.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.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
@@ -60,7 +62,7 @@
/**
* List of notifications nodes.
*/
- private List<YangNode> notificationNodes;
+ private transient List<YangNode> notificationNodes;
/**
* Creates a YANG node of module type.
@@ -153,10 +155,15 @@
*
* The manager class needs to extend the "ListenerRegistry".
*/
+
try {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ }
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
+ searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
+ getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for module node " + getName());
}
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 31abd5c..835d781 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
@@ -35,8 +35,10 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.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.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
@@ -62,7 +64,7 @@
/**
* List of notifications nodes.
*/
- private List<YangNode> notificationNodes = new ArrayList<>();
+ private transient List<YangNode> notificationNodes = new ArrayList<>();
/**
* Creates YANG java sub module object.
@@ -167,9 +169,13 @@
* The manager class needs to extend the "ListenerRegistry".
*/
try {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ }
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
+ searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
+ getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for submodule node " + getName());
}
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 ab8134f..c439e0a 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
@@ -16,13 +16,15 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentity;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
@@ -36,9 +38,11 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
+import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
@@ -47,7 +51,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
@@ -61,7 +64,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
-import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
@@ -91,12 +93,6 @@
* class / interface definition start.
*/
switch (genFileTypes) {
- case BUILDER_CLASS_MASK:
- return getBuilderClassDefinition(yangName);
- case IMPL_CLASS_MASK:
- return getImplClassDefinition(yangName);
- case BUILDER_INTERFACE_MASK:
- return getBuilderInterfaceDefinition(yangName);
case GENERATE_TYPEDEF_CLASS:
case GENERATE_UNION_CLASS:
return getTypeClassDefinition(yangName);
@@ -125,6 +121,12 @@
switch (genFileTypes) {
case INTERFACE_MASK:
return getInterfaceDefinition(yangName, curNode);
+ case BUILDER_CLASS_MASK:
+ return getBuilderClassDefinition(yangName, curNode);
+ case IMPL_CLASS_MASK:
+ return getImplClassDefinition(yangName, curNode);
+ case BUILDER_INTERFACE_MASK:
+ return getBuilderInterfaceDefinition(yangName, curNode);
case GENERATE_SERVICE_AND_MANAGER:
return getRpcInterfaceDefinition(yangName, curNode);
case GENERATE_EVENT_CLASS:
@@ -158,22 +160,10 @@
* @return definition
*/
private static String getInterfaceDefinition(String yangName, YangNode curNode) {
- JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder();
- if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
- String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
- for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
- if (!holder.getExtendedClassStore().get(info)) {
- def = def + info.getClassInfo() + COMMA + SPACE;
- } else {
- def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE;
- }
- }
-
- def = trimAtLast(def, COMMA);
-
- return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, INTERFACE_MASK);
+ if (clsDef != null) {
+ return clsDef;
}
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
@@ -185,7 +175,14 @@
* is being generated
* @return definition
*/
- private static String getBuilderInterfaceDefinition(String yangName) {
+ private static String getBuilderInterfaceDefinition(String yangName, YangNode curNode) {
+ String clsDef = "";
+ if (curNode instanceof YangAugment) {
+ clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_INTERFACE_MASK);
+ if (clsDef != null) {
+ return clsDef;
+ }
+ }
return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE;
}
@@ -195,7 +192,14 @@
* @param yangName file name
* @return definition
*/
- private static String getBuilderClassDefinition(String yangName) {
+ private static String getBuilderClassDefinition(String yangName, YangNode curNode) {
+ String clsDef = "";
+ if (curNode instanceof YangAugment) {
+ clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_CLASS_MASK);
+ if (clsDef != null) {
+ return clsDef;
+ }
+ }
return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
+ yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
@@ -206,8 +210,15 @@
* @param yangName file name
* @return definition
*/
- private static String getImplClassDefinition(String yangName) {
- return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE
+ private static String getImplClassDefinition(String yangName, YangNode curNode) {
+ String clsDef = "";
+ if (curNode instanceof YangAugment) {
+ clsDef = getClassDefinitionForWhenExtended(curNode, yangName, IMPL_CLASS_MASK);
+ if (clsDef != null) {
+ return clsDef;
+ }
+ }
+ return PUBLIC + SPACE + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + IMPLEMENTS + SPACE
+ yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
@@ -228,19 +239,19 @@
* @return identity class definition
*/
private static String getIdentityClassDefinition(String yangName, YangNode curNode) {
- if (!(curNode instanceof YangJavaIdentity)) {
+ if (!(curNode instanceof YangIdentity)) {
throw new TranslatorException("Expected java identity instance node");
}
- YangJavaIdentity identity = (YangJavaIdentity) curNode;
+ YangIdentity identity = (YangIdentity) curNode;
if (identity.getBaseNode() != null) {
YangIdentity baseIdentity = identity.getBaseNode().getReferredIdentity();
- if (!(baseIdentity instanceof YangJavaIdentity)) {
+ if (!(baseIdentity instanceof YangIdentity)) {
throw new TranslatorException("Expected java identity instance node");
}
- YangJavaIdentity baseJavaIdentity = (YangJavaIdentity) baseIdentity;
+ JavaFileInfo fileInfo = ((JavaFileInfoContainer) baseIdentity).getJavaFileInfo();
return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + EXTEND + SPACE
- + getCapitalCase(baseJavaIdentity.getJavaFileInfo().getJavaName()) + SPACE +
+ + getCapitalCase(fileInfo.getJavaName()) + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE;
}
@@ -332,4 +343,99 @@
return intfDef;
}
+
+ /**
+ * Returns class definition when class is extending another class.
+ *
+ * @param curNode current node
+ * @param yangName name
+ * @param genFileTypes gen file type
+ * @return class definition
+ */
+ private static String getClassDefinitionForWhenExtended(YangNode curNode, String yangName, int genFileTypes) {
+ JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder();
+
+ if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
+ String def = PUBLIC + SPACE;
+ switch (genFileTypes) {
+ case INTERFACE_MASK:
+ def = def + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
+ for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
+ if (curNode instanceof YangAugment) {
+ if (!info.getClassInfo().contains(BUILDER) && !info.getClassInfo().contains(
+ getCapitalCase(DEFAULT))) {
+ def = getDefinitionString(def, info, holder);
+ }
+ } else {
+ def = getDefinitionString(def, info, holder);
+ }
+ }
+ def = trimAtLast(def, COMMA);
+
+ return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ case BUILDER_INTERFACE_MASK:
+ String builderDef = INTERFACE + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
+ for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
+ if (info.getClassInfo().contains(BUILDER) && !info.getClassInfo().contains(
+ getCapitalCase(DEFAULT))) {
+ builderDef = getDefinitionString(builderDef, info, holder);
+ }
+ }
+
+ builderDef = trimAtLast(builderDef, COMMA);
+
+ return builderDef + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ case BUILDER_CLASS_MASK:
+ def = def + CLASS + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
+ for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
+ if (info.getClassInfo().contains(BUILDER)
+ && info.getClassInfo().contains(getCapitalCase(DEFAULT))) {
+ def = getDefinitionString(def, info, holder);
+ }
+ }
+
+ def = trimAtLast(def, COMMA);
+
+ return def + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
+ + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+
+ case IMPL_CLASS_MASK:
+ def = def + SPACE + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + EXTEND + SPACE;
+ for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
+ if (!info.getClassInfo().contains(BUILDER)
+ && info.getClassInfo().contains(getCapitalCase(DEFAULT))) {
+ def = getDefinitionString(def, info, holder);
+ }
+ }
+
+ def = trimAtLast(def, COMMA);
+
+ return def + SPACE + IMPLEMENTS + SPACE
+ + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+
+ default:
+ return null;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns updated class definition.
+ *
+ * @param def current definition
+ * @param info java qualified info
+ * @param holder extend list holder
+ * @return updated class definition
+ */
+ private static String getDefinitionString(String def, JavaQualifiedTypeInfo info, JavaExtendsListHolder holder) {
+ if (!holder.getExtendedClassStore().get(info)) {
+ def = def + info.getClassInfo() + COMMA + SPACE;
+ } else {
+ def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE;
+ }
+ return def;
+ }
+
}
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 3e523b0..d29fb86 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
@@ -16,31 +16,51 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.YangNode;
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.utils.io.impl.YangPluginConfig;
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.utils.UtilConstants.ARRAY_LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
+import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
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;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW;
+import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_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.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.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
+import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
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;
+import static java.util.Collections.sort;
/**
* Represents utility class to generate the java snippet.
@@ -71,7 +91,7 @@
*
* @param importInfo import info
* @return the textual java code information corresponding to the import
- * list
+ * list
*/
public static String getImportText(JavaQualifiedTypeInfo importInfo) {
return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
@@ -81,13 +101,13 @@
* Returns the textual java code for attribute definition in class.
*
* @param javaAttributeTypePkg Package of the attribute type
- * @param javaAttributeType java attribute type
- * @param javaAttributeName name of the attribute
- * @param isList is list attribute
+ * @param javaAttributeType java attribute type
+ * @param javaAttributeName name of the attribute
+ * @param isList is list attribute
* @return the textual java code for attribute definition in class
*/
public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
- String javaAttributeName, boolean isList) {
+ String javaAttributeName, boolean isList) {
String attributeDefination = PRIVATE + SPACE;
@@ -121,17 +141,6 @@
}
/**
- * Returns attribute of augmented info for generated impl file.
- *
- * @return attribute of augmented info for generated impl file
- */
- public static String getAugmentedInfoAttribute() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
- + getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST
- + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
- }
-
- /**
* Returns based on the file type and the YANG name of the file, generate the class
* / interface definition close.
*
@@ -144,8 +153,8 @@
/**
* Returns string for enum's attribute.
*
- * @param name name of attribute
- * @param value value of the enum
+ * @param name name of attribute
+ * @param value value of the enum
* @param pluginConfig plugin configurations
* @return string for enum's attribute
*/
@@ -155,4 +164,128 @@
+ value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
+ /**
+ * Adds annotations imports.
+ *
+ * @param imports list if imports
+ * @param operation to add or to delete
+ */
+ public static void addAnnotationsImports(List<String> imports, boolean operation) {
+ if (operation) {
+ imports.add(ACTIVATE_ANNOTATION_IMPORT);
+ imports.add(DEACTIVATE_ANNOTATION_IMPORT);
+ imports.add(COMPONENT_ANNOTATION_IMPORT);
+ imports.add(SERVICE_ANNOTATION_IMPORT);
+ imports.add(LOGGER_FACTORY_IMPORT);
+ imports.add(LOGGER_IMPORT);
+ } else {
+ imports.remove(ACTIVATE_ANNOTATION_IMPORT);
+ imports.remove(DEACTIVATE_ANNOTATION_IMPORT);
+ imports.remove(COMPONENT_ANNOTATION_IMPORT);
+ imports.remove(SERVICE_ANNOTATION_IMPORT);
+ imports.remove(LOGGER_FACTORY_IMPORT);
+ imports.remove(LOGGER_IMPORT);
+ }
+ sortImports(imports);
+ }
+
+ /**
+ * Returns sorted import list.
+ *
+ * @param imports import list
+ * @return sorted import list
+ */
+ public static List<String> sortImports(List<String> imports) {
+ sort(imports);
+ return imports;
+ }
+
+ /**
+ * Returns event enum start.
+ *
+ * @return event enum start
+ */
+ public static String getEventEnumTypeStart() {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
+ + NEW_LINE;
+ }
+
+ /**
+ * Adds listener's imports.
+ *
+ * @param curNode currentYangNode.
+ * @param imports import list
+ * @param operation add or remove
+ * @param classInfo class info to be added to import list
+ */
+ public static void addListenersImport(YangNode curNode, List<String> imports, boolean operation,
+ String classInfo) {
+ String thisImport = "";
+ if (classInfo.equals(LISTENER_SERVICE)) {
+ thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerServiceImport();
+ performOperationOnImports(imports, thisImport, operation);
+ } else {
+ thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerRegistryImport();
+ performOperationOnImports(imports, thisImport, operation);
+ }
+ }
+
+ /**
+ * Performs given operations on import list.
+ *
+ * @param imports list of imports
+ * @param curImport current import
+ * @param operation add or remove
+ * @return import list
+ */
+ private static List<String> performOperationOnImports(List<String> imports, String curImport,
+ boolean operation) {
+ if (operation) {
+ imports.add(curImport);
+ } else {
+ imports.remove(curImport);
+ }
+ sortImports(imports);
+ return imports;
+ }
+
+ /**
+ * 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
+ * @return enum's attribute
+ */
+ public static String getEnumsValueAttribute(String className) {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
+ + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns component string.
+ *
+ * @return component string
+ */
+ public static String addComponentString() {
+ return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
+ }
}
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 efe3833..ca1f052 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
@@ -28,7 +28,7 @@
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
+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
@@ -62,7 +62,7 @@
* @param extendedClass map of classes need to be extended
*/
private void setExtendedClassStore(Map<JavaQualifiedTypeInfo, Boolean> extendedClass) {
- this.extendedClassStore = extendedClass;
+ extendedClassStore = extendedClass;
}
/**
@@ -74,7 +74,7 @@
public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
- JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
+ JavaImportData importData = getTempJavaFragment(node).getJavaImportData();
boolean qualified = importData.addImportInfo(info,
getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
@@ -99,7 +99,7 @@
* @param classInfoList the extends List to set
*/
private void setExtendsList(List<JavaQualifiedTypeInfo> classInfoList) {
- this.extendsList = classInfoList;
+ extendsList = classInfoList;
}
/**
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 25b9c85..49315f3 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
@@ -21,14 +21,14 @@
import java.util.ArrayList;
import java.util.List;
+import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNode;
+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.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
@@ -43,6 +43,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
@@ -62,17 +63,14 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getEnumsValueAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedNodesConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstrcutor;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen;
@@ -82,31 +80,36 @@
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.getRemoveAugmentationImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getEventEnumTypeStart;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
+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;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
+import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
+import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.UtilConstants.SUPER;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
@@ -122,18 +125,19 @@
/**
* Returns generated interface file for current node.
*
- * @param file file
- * @param imports imports for the file
- * @param curNode current YANG node
+ * @param file file
+ * @param imports imports for the file
+ * @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @return interface file
* @throws IOException when fails to write in file
*/
public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode,
- boolean isAttrPresent)
+ boolean isAttrPresent)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
String className = getCapitalCase(javaFileInfo.getJavaName());
@@ -149,7 +153,7 @@
*/
insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()));
+ .getBeanTempFiles(), path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while interface file generation");
@@ -161,8 +165,8 @@
/**
* Returns generated builder interface file for current node.
*
- * @param file file
- * @param curNode current YANG node
+ * @param file file
+ * @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @return builder interface file
* @throws IOException when fails to write in file
@@ -176,7 +180,7 @@
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path, pluginConfig);
+ initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode, className);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
try {
@@ -185,14 +189,14 @@
*/
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()));
+ .getBeanTempFiles(), path));
/**
* Setter methods.
*/
methods.add(NEW_LINE);
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()));
+ .getBeanTempFiles(), path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while builder interface file generation");
@@ -219,16 +223,14 @@
/**
* Returns generated builder class file for current node.
*
- * @param file file
- * @param imports imports for the file
- * @param curNode current YANG node
+ * @param file file
+ * @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @return builder class file
* @throws IOException when fails to write in file
*/
- public static File generateBuilderClassFile(File file, List<String> imports, YangNode curNode,
- boolean isAttrPresent)
- throws IOException {
+ public static File generateBuilderClassFile(File file, YangNode curNode,
+ boolean isAttrPresent) throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
@@ -236,9 +238,12 @@
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, BUILDER_CLASS_MASK, imports, path, pluginConfig);
-
+ initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode, className);
List<String> methods = new ArrayList<>();
+ boolean isAugmentNode = false;
+ if (curNode instanceof YangAugment) {
+ isAugmentNode = true;
+ }
if (isAttrPresent) {
/**
@@ -248,7 +253,7 @@
insertDataIntoJavaFile(file,
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()));
+ .getBeanTempFiles(), path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while builder class file generation");
@@ -260,14 +265,30 @@
*/
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()));
+ .getBeanTempFiles(), path));
/**
* Setter methods.
*/
methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()) +
- NEW_LINE);
+ .getBeanTempFiles(), path));
+
+ if (isAugmentNode) {
+ YangAugment augment = (YangAugment) curNode;
+ String augmentNode = getCapitalCase(
+ getCamelCase(augment.getAugmentedNode().getName(), pluginConfig.getConflictResolver()));
+ /**
+ * Constructor.
+ */
+ String constructor = getAugmentedNodesConstructorStart(className, augmentNode)
+ + getDataFromTempFileHandle(AUGMENTE_CLASS_CONSTRUCTOR_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles(), path);
+
+ methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE + NEW_LINE);
+ }
+ insertDataIntoJavaFile(file, NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while builder class file generation");
@@ -289,26 +310,28 @@
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
+ insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
return validateLineLength(file);
}
/**
* Returns generated manager class file for current node.
*
- * @param file file
- * @param imports imports for the file
- * @param curNode current YANG node
+ * @param file file
+ * @param imports imports for the file
+ * @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @return builder class file
* @throws IOException when fails to write in file
*/
public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode,
- boolean isAttrPresent)
+ boolean isAttrPresent)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName()) + MANAGER;
+ String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
@@ -326,14 +349,14 @@
methods.add(
getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles()));
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles(), path));
/**
* Setter methods.
*/
methods.add(
getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles())
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles(), path)
+ NEW_LINE);
}
@@ -343,7 +366,7 @@
* Rpc methods
*/
methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK,
- javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles()));
+ javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path));
}
insertDataIntoJavaFile(file, NEW_LINE);
@@ -364,13 +387,14 @@
/**
* Returns generated impl class file for current node.
*
- * @param file file
- * @param curNode current YANG node
+ * @param file file
+ * @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
+ * @param imports list of imports
* @return impl class file
* @throws IOException when fails to write in file
*/
- public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent)
+ public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent, List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
@@ -379,20 +403,14 @@
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path, pluginConfig);
+ initiateJavaFileGeneration(file, IMPL_CLASS_MASK, imports, curNode, className);
List<String> methods = new ArrayList<>();
-
- TempJavaCodeFragmentFiles javaCodeFragmentFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles();
- boolean isAugmentationHolderExtended = isAugmentationHolderExtended(
- javaCodeFragmentFiles.getBeanTempFiles().getJavaExtendsListHolder().getExtendsList());
- /**
- * Add attribute for augmented info's list.
- */
- if (isAugmentationHolderExtended) {
- insertDataIntoJavaFile(file, getAugmentedInfoAttribute());
+ boolean isAugmentNode = false;
+ if (curNode instanceof YangAugment) {
+ isAugmentNode = true;
}
+
if (isAttrPresent) {
/**
* Add attribute strings.
@@ -401,20 +419,19 @@
insertDataIntoJavaFile(file,
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()));
+ .getBeanTempFiles(), path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
- insertDataIntoJavaFile(file, NEW_LINE);
try {
/**
* Getter methods.
*/
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()));
+ .getBeanTempFiles(), path));
/**
* Hash code method.
@@ -422,20 +439,20 @@
methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles()).replace(NEW_LINE, EMPTY_STRING)));
+ .getBeanTempFiles(), path).replace(NEW_LINE, EMPTY_STRING)));
/**
* Equals method.
*/
- methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(className + IMPL) + getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles())));
+ methods.add(getEqualsMethodClose(getEqualsMethodOpen(getCapitalCase(DEFAULT) + className)
+ + getDataFromTempFileHandle(EQUALS_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles(), path)));
/**
* To string method.
*/
methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles())
+ .getBeanTempFiles(), path)
+ getToStringMethodClose());
} catch (IOException e) {
@@ -450,10 +467,15 @@
/**
* Constructor.
*/
- String constructor =
- getConstructorStart(className, pluginConfig) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles());
+ String constructor = getConstructorStart(className, pluginConfig);
+ if (isAugmentNode) {
+ constructor = constructor + EIGHT_SPACE_INDENTATION + SUPER + OPEN_PARENTHESIS
+ + BUILDER.toLowerCase() + OBJECT
+ + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ }
+ constructor = constructor + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles(), path);
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
} catch (IOException e) {
@@ -462,21 +484,11 @@
}
/**
- * Add method for augment info's list.
- */
- if (isAugmentationHolderExtended) {
- methods.add(getAddAugmentInfoMethodImpl());
- methods.add(getAugmentInfoListImpl());
- methods.add(getRemoveAugmentationImpl());
- }
-
- /**
* Add methods in impl class.
*/
for (String method : methods) {
- insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + method + NEW_LINE);
+ insertDataIntoJavaFile(file, method);
}
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
return validateLineLength(file);
}
@@ -484,7 +496,7 @@
/**
* Generates class file for type def.
*
- * @param file generated file
+ * @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @return type def class file
@@ -510,7 +522,7 @@
insertDataIntoJavaFile(file,
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getTypeTempFiles()));
+ .getTypeTempFiles(), path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while type def class file generation");
@@ -528,19 +540,22 @@
* Type constructor.
*/
methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
+ path));
/**
* Of method.
*/
methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
+ path));
/**
* Getter method.
*/
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
+ path));
/**
* Hash code method.
@@ -548,22 +563,23 @@
methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getTypeTempFiles())
- .replace(NEW_LINE, EMPTY_STRING)));
+ .getTypeTempFiles(), path)
+ .replace(NEW_LINE, EMPTY_STRING)));
/**
* Equals method.
*/
methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING)
+ getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles(), path)));
/**
* To string method.
*/
methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())
- + getToStringMethodClose());
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
+ path) + getToStringMethodClose());
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
@@ -571,7 +587,8 @@
*/
methods.add(getFromStringMethodSignature(className, pluginConfig)
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles()
- .getTypeTempFiles()) + getFromStringMethodClose());
+ .getTypeTempFiles(), path)
+ + getFromStringMethodClose());
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
@@ -589,7 +606,7 @@
/**
* Generates class file for union type.
*
- * @param file generated file
+ * @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @return type def class file
@@ -615,7 +632,7 @@
insertDataIntoJavaFile(file,
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getTypeTempFiles()));
+ .getTypeTempFiles(), path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while union class file generation");
@@ -633,19 +650,22 @@
* Type constructor.
*/
methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
+ path));
/**
* Of string method.
*/
methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
+ path));
/**
* Getter method.
*/
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles()));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
+ path));
/**
* Hash code method.
@@ -653,15 +673,16 @@
methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getTypeTempFiles())
- .replace(NEW_LINE, EMPTY_STRING)));
+ .getTypeTempFiles(), path)
+ .replace(NEW_LINE, EMPTY_STRING)));
/**
* Equals method.
*/
methods.add(getEqualsMethodClose(getEqualsMethodOpen(className + EMPTY_STRING)
+ getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())));
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles(), path)));
/**
* To string method.
@@ -669,14 +690,16 @@
methods.add(getToStringMethodOpen() + getOmitNullValueString() +
getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getTypeTempFiles()) + getToStringMethodClose());
+ .getTypeTempFiles(), path)
+ + getToStringMethodClose());
/**
* From string method.
*/
methods.add(getFromStringMethodSignature(className, pluginConfig)
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles())
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles(), path)
+ getFromStringMethodClose());
} catch (IOException e) {
@@ -695,7 +718,7 @@
/**
* Generates class file for type enum.
*
- * @param file generated file
+ * @param file generated file
* @param curNode current YANG node
* @return class file for type enum
* @throws IOException when fails to generate class file
@@ -717,7 +740,7 @@
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
insertDataIntoJavaFile(file,
trimAtLast(trimAtLast(getDataFromTempFileHandle(ENUM_IMPL_MASK, javaGeninfo
- .getTempJavaCodeFragmentFiles().getEnumerationTempFiles()), COMMA), NEW_LINE)
+ .getTempJavaCodeFragmentFiles().getEnumerationTempFiles(), path), COMMA), NEW_LINE)
+ SEMI_COLAN + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + getCapitalCase(className)
@@ -734,11 +757,11 @@
* Add a constructor for enum.
*/
insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig)
- + getEnumsConstrcutor(getCapitalCase(className)) + NEW_LINE);
+ + getEnumsConstructor(getCapitalCase(className)) + NEW_LINE);
- TempJavaEnumerationFragmentFiles enumFragFiles =
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getEnumerationTempFiles();
+ TempJavaEnumerationFragmentFiles enumFragFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles()
+ .getEnumerationTempFiles();
insertDataIntoJavaFile(file, getEnumsOfMethod(className,
enumFragFiles.getJavaAttributeForEnum(pluginConfig),
enumFragFiles.getEnumSetJavaMap(),
@@ -754,8 +777,8 @@
try {
insertDataIntoJavaFile(file, getFromStringMethodSignature(getCapitalCase(className), pluginConfig)
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getEnumerationTempFiles())
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getEnumerationTempFiles(), path)
+ getFromStringMethodClose());
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " +
@@ -770,20 +793,21 @@
/**
* Generates interface file for rpc.
*
- * @param file generated file
- * @param curNode current YANG node
- * @param imports imports for file
+ * @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)
+ boolean isAttributePresent)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
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<>();
@@ -796,13 +820,13 @@
*/
methods.add(getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles()));
+ .getServiceTempFiles(), path));
/**
* Setter methods.
*/
methods.add(getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles()));
+ .getServiceTempFiles(), path));
}
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
@@ -810,7 +834,7 @@
* Rpc methods
*/
methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK,
- javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles()));
+ javaGeninfo.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path));
}
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
@@ -828,27 +852,28 @@
/**
* Generates event file.
*
- * @param file generated file
+ * @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @throws IOException when fails to generate class file
*/
public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException {
- String className =
- getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
- + EVENT_STRING;
+ String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ + EVENT_STRING;
TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
+ String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath()
+ + ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath();
initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className);
try {
insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() +
- trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, tempFiles), COMMA)
+ trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK, tempFiles, path), COMMA)
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE);
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_METHOD_MASK, tempFiles));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_METHOD_MASK, tempFiles, path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
@@ -862,7 +887,7 @@
/**
* Generates event listener file.
*
- * @param file generated file
+ * @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @throws IOException when fails to generate class file
@@ -870,9 +895,8 @@
public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports)
throws IOException {
- String className =
- getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
- + EVENT_LISTENER_STRING;
+ String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ + EVENT_LISTENER_STRING;
initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE, imports, curNode, className);
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
@@ -882,7 +906,7 @@
/**
* Generates event subject's file.
*
- * @param file file handle
+ * @param file file handle
* @param curNode current YANG node
* @throws IOException when fails to do IO exceptions
*/
@@ -894,16 +918,18 @@
initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null, curNode, className);
+ String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath()
+ + ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath();
TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
insertDataIntoJavaFile(file, NEW_LINE);
try {
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles, path));
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK, tempFiles));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK, tempFiles, path));
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK, tempFiles));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK, tempFiles, path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
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 4a2b6f5..c6fd897 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
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.util.List;
+import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
@@ -39,13 +40,14 @@
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_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
@@ -66,26 +68,16 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
-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.IMMEDIATE;
-import static org.onosproject.yangutils.utils.UtilConstants.INT;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
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.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
@@ -97,6 +89,9 @@
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.parsePkg;
@@ -130,11 +125,12 @@
*
* @param generatedTempFiles temporary file types
* @param tempJavaFragmentFiles temp java fragment files
+ * @param absolutePath absolute path
* @return data stored in temporary files
* @throws IOException when failed to get the data from temporary file handle
*/
public static String getDataFromTempFileHandle(int generatedTempFiles,
- TempJavaFragmentFiles tempJavaFragmentFiles)
+ TempJavaFragmentFiles tempJavaFragmentFiles, String absolutePath)
throws IOException {
TempJavaTypeFragmentFiles typeFragmentFiles = null;
@@ -156,49 +152,64 @@
if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterInterfaceTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterInterfaceTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
if (beanFragmentFiles == null) {
throw new TranslatorException("Required constructor info is missing.");
}
return beanFragmentFiles
- .getTemporaryDataFromFileHandle(beanFragmentFiles.getConstructorImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(beanFragmentFiles.getConstructorImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getHashCodeImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getHashCodeImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEqualsImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEqualsImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle(),
+ absolutePath);
+ } else if ((generatedTempFiles & AUGMENTE_CLASS_CONSTRUCTOR_MASK) != 0) {
+ return tempJavaFragmentFiles
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAugmentConstructorImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
if (typeFragmentFiles == null) {
throw new TranslatorException("Required of string implementation info is missing.");
}
return typeFragmentFiles
- .getTemporaryDataFromFileHandle(typeFragmentFiles.getOfStringImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(typeFragmentFiles.getOfStringImplTempFileHandle(), absolutePath);
} else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
if (typeFragmentFiles == null) {
throw new TranslatorException("Required constructor implementation info is missing.");
}
return typeFragmentFiles
- .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle());
+ .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
if (!(tempJavaFragmentFiles instanceof TempJavaEnumerationFragmentFiles)) {
throw new TranslatorException("Required enum info is missing.");
@@ -206,49 +217,56 @@
TempJavaEnumerationFragmentFiles enumFragmentFiles =
(TempJavaEnumerationFragmentFiles) tempJavaFragmentFiles;
return enumFragmentFiles
- .getTemporaryDataFromFileHandle(enumFragmentFiles.getEnumClassTempFileHandle());
+ .getTemporaryDataFromFileHandle(enumFragmentFiles.getEnumClassTempFileHandle(), absolutePath);
} else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc interface info is missing.");
}
return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcInterfaceTempFileHandle());
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcInterfaceTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle());
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & EVENT_ENUM_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventEnumTempFileHandle());
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventEnumTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & EVENT_METHOD_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventMethodTempFileHandle());
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventMethodTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectGetterTempFileHandle());
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectGetterTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectSetterTempFileHandle());
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectSetterTempFileHandle(),
+ absolutePath);
} else if ((generatedTempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectAttributeTempFileHandle());
+ .getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectAttributeTempFileHandle(),
+ absolutePath);
}
return null;
}
@@ -265,7 +283,7 @@
* @throws IOException when fails to generate a file
*/
public static void initiateJavaFileGeneration(File file, String className, int genType, List<String> imports,
- String pkg, YangPluginConfig pluginConfig)
+ String pkg, YangPluginConfig pluginConfig)
throws IOException {
try {
@@ -287,16 +305,11 @@
* @throws IOException when fails to generate a file
*/
public static void initiateJavaFileGeneration(File file, int genType, List<String> imports,
- YangNode curNode, String className)
+ YangNode curNode, String className)
throws IOException {
try {
- if (file.exists()) {
- throw new IOException(file.getName() + " is reused due to YANG naming");
- }
-
file.createNewFile();
-
appendContents(file, genType, imports, curNode, className);
} catch (IOException e) {
throw new IOException("Failed to create " + file.getName() + " class file.");
@@ -314,7 +327,7 @@
* @throws IOException
*/
private static void appendContents(File file, int genType, List<String> importsList, YangNode curNode,
- String className)
+ String className)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
@@ -322,6 +335,10 @@
String name = javaFileInfo.getJavaName();
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
+ YangNode augmentedNode = null;
+ if (curNode instanceof YangAugment) {
+ augmentedNode = ((YangAugment) curNode).getAugmentedNode();
+ }
String pkgString = null;
if (genType == GENERATE_EVENT_CLASS
|| genType == GENERATE_EVENT_LISTENER_INTERFACE
@@ -332,9 +349,23 @@
}
switch (genType) {
case INTERFACE_MASK:
- appendHeaderContents(file, pkgString, importsList);
+ if (augmentedNode != null) {
+ appendHeaderContents(file, pkgString, importsList, augmentedNode);
+ } else {
+ appendHeaderContents(file, pkgString, importsList);
+ }
write(file, genType, INTERFACE, curNode, className);
break;
+ case IMPL_CLASS_MASK:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, genType, IMPL_CLASS, curNode, className);
+ break;
+ case BUILDER_CLASS_MASK:
+ write(file, genType, BUILDER_CLASS, curNode, className);
+ break;
+ case BUILDER_INTERFACE_MASK:
+ write(file, genType, BUILDER_INTERFACE, curNode, className);
+ break;
case GENERATE_SERVICE_AND_MANAGER:
appendHeaderContents(file, pkgString, importsList);
write(file, genType, RPC_INTERFACE, curNode, className);
@@ -373,26 +404,16 @@
* @throws IOException when fails to append contents
*/
private static void appendContents(File file, String fileName, int genType, List<String> importsList, String pkg,
- YangPluginConfig pluginConfig)
+ YangPluginConfig pluginConfig)
throws IOException {
String pkgString = parsePackageString(pkg, importsList);
switch (genType) {
- case IMPL_CLASS_MASK:
- write(file, fileName, genType, IMPL_CLASS, pluginConfig);
- break;
- case BUILDER_INTERFACE_MASK:
- write(file, fileName, genType, BUILDER_INTERFACE, pluginConfig);
- break;
case GENERATE_TYPEDEF_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, genType, IMPL_CLASS, pluginConfig);
break;
- case BUILDER_CLASS_MASK:
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, BUILDER_CLASS, pluginConfig);
- break;
case GENERATE_UNION_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, genType, IMPL_CLASS, pluginConfig);
@@ -428,7 +449,7 @@
}
/**
- * Appends other contents to interface, builder and typedef classes.
+ * Appends other contents to interface, impl and typedef classes.
* for example : ONOS copyright, imports and package.
*
* @param file generated file
@@ -456,6 +477,39 @@
}
/**
+ * Appends other contents to interface and impl classes when augmented node is not null.
+ * for example : ONOS copyright, imports and package.
+ *
+ * @param file generated file
+ * @param pkg generated package
+ * @param augmentedNode augmented node
+ * @param importsList list of imports
+ * @throws IOException when fails to append contents
+ */
+ private static void appendHeaderContents(File file, String pkg, List<String> importsList, YangNode augmentedNode)
+ throws IOException {
+
+ insertDataIntoJavaFile(file, CopyrightHeader.getCopyrightHeader());
+ insertDataIntoJavaFile(file, pkg);
+
+ /*
+ * TODO: add the file header using
+ * JavaCodeSnippetGen.getFileHeaderComment
+ */
+
+ if (importsList != null) {
+ insertDataIntoJavaFile(file, NEW_LINE);
+ for (String imports : importsList) {
+ if (!imports.contains(getCapitalCase(DEFAULT) + getCapitalCase(getCamelCase(augmentedNode.getName(),
+ null)))
+ && !imports.contains(getCapitalCase(getCamelCase(augmentedNode.getName(), null)) + BUILDER)) {
+ insertDataIntoJavaFile(file, imports);
+ }
+ }
+ }
+ }
+
+ /**
* Writes data to the specific generated file.
*
* @param file generated file
@@ -472,7 +526,7 @@
if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
if (!fileName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName, false, pluginConfig));
- insertDataIntoJavaFile(file, addComponentString());
+ insertDataIntoJavaFile(file, JavaCodeSnippetGen.addComponentString());
} else {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
}
@@ -493,30 +547,10 @@
* @throws IOException when fails to write into a file
*/
private static void write(File file, String fileName, int genType, JavaDocType javaDocType,
- YangPluginConfig pluginConfig)
+ YangPluginConfig pluginConfig)
throws IOException {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
- /**
- * Returns integer attribute for enum's class to get the values.
- *
- * @param className enum's class name
- * @return enum's attribute
- */
- public static String getEnumsValueAttribute(String className) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
- + SEMI_COLAN + NEW_LINE;
- }
-
- /**
- * Returns component string.
- *
- * @return component string
- */
- public static String addComponentString() {
- return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE
- + EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
- }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
index 8c938ed..9743c92 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
@@ -54,11 +54,8 @@
*/
public final class JavaIdentifierSyntax {
- private static final int MAX_MONTHS = 12;
- private static final int MAX_DAYS = 31;
private static final int INDEX_ZERO = 0;
private static final int INDEX_ONE = 1;
- private static final int INDEX_TWO = 2;
private static final int VALUE_CHECK = 10;
private static final String ZERO = "0";
private static final String DATE_FORMAT = "yyyy-MM-dd";
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 a5fc104..cde88ed 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
@@ -32,10 +32,8 @@
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_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
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;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
@@ -45,7 +43,6 @@
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.CLEAR;
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;
@@ -72,7 +69,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.IF;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
@@ -122,7 +118,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
@@ -132,6 +127,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.generateForTypeConstructor;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
@@ -515,43 +512,38 @@
public static String getConstructorStart(String yangName, YangPluginConfig pluginConfig) {
String javadoc = getConstructorString(yangName, pluginConfig);
- String constructor =
- FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + IMPL + OPEN_PARENTHESIS + yangName
- + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET
- + NEW_LINE;
+ String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + getCapitalCase(DEFAULT) + yangName +
+ OPEN_PARENTHESIS + yangName + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return javadoc + constructor;
}
/**
* Returns the constructor strings for class file.
*
- * @param yangName name of the class
* @param attr attribute info
* @param generatedJavaFiles generated java files
* @param pluginConfig plugin configurations
* @return constructor for class
*/
- public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles,
+ public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles,
YangPluginConfig pluginConfig) {
String attributeName = attr.getAttributeName();
String constructor;
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
- constructor =
- EIGHT_SPACE_INDENTATION + THIS + PERIOD
- + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
- + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
- + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver()))
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
+ + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
+ + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver()))
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
} else {
- constructor =
- EIGHT_SPACE_INDENTATION + THIS + PERIOD
- + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
- + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
- + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
+ + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
+ + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
return constructor;
}
@@ -593,10 +585,9 @@
inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
}
- String method =
- getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
- + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
+ String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
+ + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
if (!outputName.contentEquals(VOID)) {
method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN
+ NEW_LINE;
@@ -614,9 +605,9 @@
*/
public static String getBuild(String yangName) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
- + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE
- + yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
- + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE +
+ getCapitalCase(DEFAULT) + yangName + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
@@ -950,59 +941,12 @@
}
/**
- * Returns implementation of add augmentation method of AugmentationHolder class.
- *
- * @return implementation of add augmentation method of AugmentationHolder class
- */
- public static String getAddAugmentInfoMethodImpl() {
- String method = FOUR_SPACE_INDENTATION;
- method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING
- + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE
- + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
-
- return method;
- }
-
- /**
- * Returns implementation of get augment info list method of AugmentationHolder class.
- *
- * @return implementation of get augment info list method of AugmentationHolder class
- */
- public static String getAugmentInfoListImpl() {
-
- String method = FOUR_SPACE_INDENTATION;
- method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + LIST + DIAMOND_OPEN_BRACKET
- + AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
- + RETURN + SPACE + getSmallCase(AUGMENTED_INFO) + LIST + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
- + CLOSE_CURLY_BRACKET;
- return method;
- }
-
- /**
- * Returns implementation of remove augmentation method of AugmentationHolder class.
- *
- * @return implementation of remove augmentation method of AugmentationHolder class
- */
- public static String getRemoveAugmentationImpl() {
- String method = FOUR_SPACE_INDENTATION;
- method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove"
- + AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
- + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS
- + CLOSE_PARENTHESIS + PERIOD + CLEAR + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
- + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
- return method;
- }
-
- /**
* Returns enum's constructor.
*
* @param className enum's class name
* @return enum's constructor
*/
- public static String getEnumsConstrcutor(String className) {
+ public static String getEnumsConstructor(String className) {
return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL
+ SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
@@ -1118,4 +1062,38 @@
throw new TranslatorException("given data type is not supported.");
}
}
+
+ /**
+ * Returns copy constructor for augmented class.
+ *
+ * @param yangName augmente class name
+ * @param augmentName augmented class name
+ * @return copy constructor for augmented class
+ */
+ public static String getAugmentedNodesConstructorStart(String yangName,
+ String augmentName) {
+
+ String javadoc = generateForTypeConstructor(yangName);
+ String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + BUILDER + OPEN_PARENTHESIS
+ + augmentName + PERIOD + augmentName + BUILDER + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE;
+ return javadoc + constructor;
+
+ }
+
+ /**
+ * Returns the constructor strings for class file.
+ *
+ * @param attr attribute info
+ * @param pluginConfig plugin configurations
+ * @return constructor for class
+ */
+ public static String getAugmentedConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
+
+ String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
+
+ return EIGHT_SPACE_INDENTATION + THIS + PERIOD + attributeName + OPEN_PARENTHESIS
+ + VALUE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
deleted file mode 100644
index 39620f9..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import org.onosproject.yangutils.datamodel.YangNode;
-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 static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-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.TYPE;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
-import static java.util.Collections.sort;
-
-/**
- * Represents utilities for temporary java code fragments.
- */
-public final class TempJavaCodeFragmentFilesUtils {
-
- /**
- * Creates a private instance of temporary java code fragment utils.
- */
- private TempJavaCodeFragmentFilesUtils() {
- }
-
- /**
- * Adds import for AugmentationHolders class.
- *
- * @param curNode current YANG node
- * @param imports list of imports
- * @param operation add or delete import
- */
- public static void addAugmentationHoldersImport(YangNode curNode, List<String> imports, boolean operation) {
- String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentationHolderImport();
- performOperationOnImports(imports, thisImport, operation);
- }
-
- /**
- * Adds import for AugmentedInfo class.
- *
- * @param curNode current YANG node
- * @param imports list of imports
- * @param operation add or delete import
- */
- public static void addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
- String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentedInfoImport();
- performOperationOnImports(imports, thisImport, operation);
- }
-
- /**
- * Returns temp java fragment.
- *
- * @param curNode current YANG node
- * @return temp java fragments
- */
- public static TempJavaFragmentFiles getTempJavaFragement(YangNode curNode) {
- TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles();
- if (container.getBeanTempFiles() != null) {
- return container.getBeanTempFiles();
- }
- if (container.getServiceTempFiles() != null) {
- return container.getServiceTempFiles();
- }
-
- return null;
- }
-
- /**
- * Adds import for array list.
- *
- * @param curNode current YANG node
- * @param imports list of imports
- * @param operation add or delete import
- */
- public static void addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
- String arrayListImport = getTempJavaFragement(curNode).getJavaImportData().getImportForArrayList();
- String listImport = getTempJavaFragement(curNode).getJavaImportData().getImportForList();
- performOperationOnImports(imports, arrayListImport, operation);
- if (!imports.contains(listImport)) {
- /**
- * List can be there because of attribute also , so no need to remove it and operation will
- * always be add(true).
- */
- performOperationOnImports(imports, listImport, true);
- }
- }
-
- /**
- * Adds listener's imports.
- *
- * @param curNode currentYangNode.
- * @param imports import list
- * @param operation add or remove
- * @param classInfo class info to be added to import list
- */
- public static void addListnersImport(YangNode curNode, List<String> imports, boolean operation,
- String classInfo) {
- String thisImport = "";
- if (classInfo.equals(LISTENER_SERVICE)) {
- thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerServiceImport();
- performOperationOnImports(imports, thisImport, operation);
- } else {
- thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerRegistryImport();
- performOperationOnImports(imports, thisImport, operation);
- }
- }
-
- /**
- * Adds annotations imports.
- *
- * @param imports list if imports
- * @param operation to add or to delete
- */
- public static void addAnnotationsImports(List<String> imports, boolean operation) {
- if (operation) {
- imports.add(ACTIVATE_ANNOTATION_IMPORT);
- imports.add(DEACTIVATE_ANNOTATION_IMPORT);
- imports.add(COMPONENT_ANNOTATION_IMPORT);
- imports.add(SERVICE_ANNOTATION_IMPORT);
- imports.add(LOGGER_FACTORY_IMPORT);
- imports.add(LOGGER_IMPORT);
- } else {
- imports.remove(ACTIVATE_ANNOTATION_IMPORT);
- imports.remove(DEACTIVATE_ANNOTATION_IMPORT);
- imports.remove(COMPONENT_ANNOTATION_IMPORT);
- imports.remove(SERVICE_ANNOTATION_IMPORT);
- imports.remove(LOGGER_FACTORY_IMPORT);
- imports.remove(LOGGER_IMPORT);
- }
- sortImports(imports);
- }
-
- /**
- * Performs given operations on import list.
- *
- * @param imports list of imports
- * @param curImport current import
- * @param operation add or remove
- * @return import list
- */
- private static List<String> performOperationOnImports(List<String> imports, String curImport,
- boolean operation) {
- if (operation) {
- imports.add(curImport);
- } else {
- imports.remove(curImport);
- }
- sortImports(imports);
- return imports;
- }
-
- /**
- * Returns true if AugmentationHolder class needs to be extended.
- *
- * @param extendsList list of classes need to be extended
- * @return true or false
- */
- public static boolean isAugmentationHolderExtended(List<JavaQualifiedTypeInfo> extendsList) {
- for (JavaQualifiedTypeInfo info : extendsList) {
- return info.getClassInfo().equals(AUGMENTATION_HOLDER);
- }
- return false;
- }
-
- /**
- * Returns true if AugmentedInfo class needs to be extended.
- *
- * @param extendsList list of classes need to be extended
- * @return true or false
- */
- public static boolean isAugmentedInfoExtended(List<JavaQualifiedTypeInfo> extendsList) {
- for (JavaQualifiedTypeInfo info : extendsList) {
- return info.getClassInfo().equals(AUGMENTED_INFO);
- }
- return false;
- }
-
- /**
- * Closes the file handle for temporary file.
- *
- * @param file file to be closed
- * @param toBeDeleted flag to indicate if file needs to be deleted
- * @throws IOException when failed to close the file handle
- */
- public static void closeFile(File file, boolean toBeDeleted)
- throws IOException {
-
- if (file != null) {
- updateFileHandle(file, null, true);
- if (toBeDeleted) {
- file.delete();
- }
- }
- }
-
- /**
- * Returns sorted import list.
- *
- * @param imports import list
- * @return sorted import list
- */
- public static List<String> sortImports(List<String> imports) {
- sort(imports);
- return imports;
- }
-
- /**
- * Returns event enum start.
- *
- * @return event enum start
- */
- public static String getEventEnumTypeStart() {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
- + NEW_LINE;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/AugmentationHolder.java b/plugin/src/main/java/org/onosproject/yangutils/utils/AugmentationHolder.java
deleted file mode 100644
index b306fe2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/AugmentationHolder.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.utils;
-
-import java.util.List;
-
-/**
- * Abstraction of an entity which represents augmentation of a YANG node.
- */
-public interface AugmentationHolder {
-
- /**
- * Adds augment info to the augment info list.
- *
- * @param augmentInfo augment info of node
- */
- void addAugmentation(AugmentedInfo augmentInfo);
-
- /**
- * Removes augment info from the node.
- */
- void removeAugmentation();
-
- /**
- * Returns list of augment info.
- *
- * @return list of augment info
- */
- List<AugmentedInfo> getAugmentedInfoList();
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/AugmentedInfo.java b/plugin/src/main/java/org/onosproject/yangutils/utils/AugmentedInfo.java
deleted file mode 100644
index 566caf0..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/AugmentedInfo.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.utils;
-
-/**
- * Abstraction of an entity which represents augmented info.
- */
-public interface AugmentedInfo {
-}
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 fec23d3..8811dfa 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -607,6 +607,11 @@
public static final String CATCH = "catch";
/**
+ * Static attribute for super syntax.
+ */
+ public static final String SUPER = "super";
+
+ /**
* Static attribute for eight space indentation.
*/
public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
index d3e7b09..fae08ed 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
@@ -123,4 +123,22 @@
}
}
}
+
+ /**
+ * Closes the file handle for temporary file.
+ *
+ * @param file file to be closed
+ * @param toBeDeleted flag to indicate if file needs to be deleted
+ * @throws IOException when failed to close the file handle
+ */
+ public static void closeFile(File file, boolean toBeDeleted)
+ throws IOException {
+
+ if (file != null) {
+ updateFileHandle(file, null, true);
+ if (toBeDeleted) {
+ file.delete();
+ }
+ }
+ }
}
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 19660b1..1610536 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
@@ -590,7 +590,7 @@
* @param attribute attribute string
* @return javaDocs for type constructor
*/
- private static String generateForTypeConstructor(String attribute) {
+ public static String generateForTypeConstructor(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
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 baea6ea..a32d927 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
@@ -28,11 +28,11 @@
import java.util.List;
import java.util.Stack;
import java.util.regex.Pattern;
+
import org.apache.commons.io.FileUtils;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
@@ -212,35 +212,17 @@
/**
* Removes extra char from the string.
*
- * @param valueString string to be trimmed
- * @param removealStirng extra chars
+ * @param valueString string to be trimmed
+ * @param removalStirng extra chars
* @return new string
*/
- public static String trimAtLast(String valueString, String removealStirng) {
+ public static String trimAtLast(String valueString, String removalStirng) {
StringBuilder stringBuilder = new StringBuilder(valueString);
- int index = valueString.lastIndexOf(removealStirng);
- stringBuilder.deleteCharAt(index);
- return stringBuilder.toString();
- }
-
- /**
- * Returns new parted string.
- *
- * @param partString string to be parted
- * @return parted string
- */
- public static String partString(String partString) {
- String[] strArray = partString.split(COMMA);
- String newString = EMPTY_STRING;
- for (int i = 0; i < strArray.length; i++) {
- if (i % 4 != 0 || i == 0) {
- newString = newString + strArray[i] + COMMA;
- } else {
- newString = newString + NEW_LINE + TWELVE_SPACE_INDENTATION
- + strArray[i] + COMMA;
- }
+ int index = valueString.lastIndexOf(removalStirng);
+ if (index != -1) {
+ stringBuilder.deleteCharAt(index);
}
- return trimAtLast(newString, COMMA);
+ return stringBuilder.toString();
}
/**
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangPluginConfig.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangPluginConfig.java
index 21314ef..d7ef5a2 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangPluginConfig.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangPluginConfig.java
@@ -27,6 +27,11 @@
private String codeGenDir;
/**
+ * Contains the code generation directory.
+ */
+ private String managerCodeGenDir;
+
+ /**
* Contains information of naming conflicts that can be resolved.
*/
private YangToJavaNamingConflictUtil conflictResolver;
@@ -72,4 +77,22 @@
public YangToJavaNamingConflictUtil getConflictResolver() {
return conflictResolver;
}
+
+ /**
+ * Returns manager's code generation directory.
+ *
+ * @return manager's code generation directory
+ */
+ public String getManagerCodeGenDir() {
+ return managerCodeGenDir;
+ }
+
+ /**
+ * Sets manager's code generation directory.
+ *
+ * @param moduleCodeGenDir manager's code generation directory
+ */
+ public void setManagerCodeGenDir(String moduleCodeGenDir) {
+ this.managerCodeGenDir = moduleCodeGenDir;
+ }
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/ietfyang/IetfYangFileTest.java b/plugin/src/test/java/org/onosproject/yangutils/ietfyang/IetfYangFileTest.java
index 49c5d60..7176760 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/ietfyang/IetfYangFileTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/ietfyang/IetfYangFileTest.java
@@ -16,16 +16,16 @@
package org.onosproject.yangutils.ietfyang;
+import java.io.IOException;
+
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.plugin.manager.YangUtilManager;
-import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
-
-import java.io.IOException;
+import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
@@ -54,6 +54,7 @@
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/ietfyang/l3vpnservice/");
+ yangPluginConfig.setManagerCodeGenDir("target/ietfyang/l3vpnservice/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
index 6c0930a..146f410 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListenerTest.java
@@ -20,12 +20,12 @@
import java.util.ListIterator;
import org.junit.Test;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
@@ -48,16 +48,16 @@
YangNode node = manager.getDataModel("src/test/resources/ValidAugmentStatement.yang");
- assertThat((node instanceof YangModule), is(true));
+ assertThat(node instanceof YangModule, is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
YangAugment yangAugment = (YangAugment) yangNode.getChild();
- ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator();
- YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next();
- assertThat(yangNodeIdentifier.getPrefix(), is("if"));
- assertThat(yangNodeIdentifier.getName(), is("interfaces"));
+ ListIterator<YangAtomicPath> absPathIterator = yangAugment.getTargetNode().listIterator();
+ YangAtomicPath absPathIdentifier = absPathIterator.next();
+ assertThat(absPathIdentifier.getNodeIdentifier().getPrefix(), is("if"));
+ assertThat(absPathIdentifier.getNodeIdentifier().getName(), is("interfaces"));
ListIterator<YangLeaf> leafIterator = yangAugment.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
new file mode 100644
index 0000000..821a435
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.plugin.manager;
+
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
+
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Unit test case for augment translator.
+ */
+public class AugmentTranslatorTest {
+
+ private final YangUtilManager utilManager = new YangUtilManager();
+
+ /**
+ * Checks augment translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processAugmentTranslator() throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/augmentTranslator";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir("target/augmentTranslator/");
+ yangPluginConfig.setManagerCodeGenDir("target/augmentTranslator/");
+ utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
+
+ deleteDirectory("target/augmentTranslator/");
+ }
+
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
index a9516eb..789bf94 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
@@ -44,6 +44,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/ChoiceCaseTestGenFile/");
+ yangPluginConfig.setManagerCodeGenDir("target/ChoiceCaseTestGenFile/");
generateJavaCode(node, yangPluginConfig);
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/EnumTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/EnumTranslatorTest.java
index c8784c8..3fbf50f 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/EnumTranslatorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/EnumTranslatorTest.java
@@ -45,6 +45,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/EnumTestGenFile/");
+ yangPluginConfig.setManagerCodeGenDir("target/EnumTestGenFile/");
generateJavaCode(node, yangPluginConfig);
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java
index 1554c5f..b5fd40b 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/InterFileLinkingTest.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
+
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Rule;
import org.junit.Test;
@@ -171,7 +172,7 @@
}
// Check whether the data model tree returned is of type module.
- assertThat((selfNode instanceof YangModule), is(true));
+ assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
@@ -184,7 +185,7 @@
YangLeaf leafInfo;
// Check whether grouping is the sibling of module's child.
- assertThat((refNode.getChild() instanceof YangGrouping), is(true));
+ assertThat(refNode.getChild() instanceof YangGrouping, is(true));
YangGrouping grouping = (YangGrouping) refNode.getChild();
leafIterator = grouping.getListOfLeaf().listIterator();
@@ -196,7 +197,7 @@
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// Check whether uses is module's child.
- assertThat((yangNode.getChild() instanceof YangUses), is(true));
+ assertThat(yangNode.getChild() instanceof YangUses, is(true));
YangUses uses = (YangUses) yangNode.getChild();
// Check whether uses get resolved.
@@ -317,7 +318,7 @@
}
// Check whether the data model tree returned is of type module.
- assertThat((selfNode instanceof YangModule), is(true));
+ assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
@@ -330,7 +331,7 @@
YangLeaf leafInfo;
// Check whether grouping is the sibling of module's child.
- assertThat((refNode.getChild() instanceof YangGrouping), is(true));
+ assertThat(refNode.getChild() instanceof YangGrouping, is(true));
YangGrouping grouping = (YangGrouping) refNode.getChild();
leafIterator = grouping.getListOfLeaf().listIterator();
@@ -342,7 +343,7 @@
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// Check whether uses is module's child.
- assertThat((yangNode.getChild() instanceof YangUses), is(true));
+ assertThat(yangNode.getChild() instanceof YangUses, is(true));
YangUses uses = (YangUses) yangNode.getChild();
// Check whether uses get resolved.
@@ -637,13 +638,13 @@
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
- String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/");
+ yangPluginConfig.setManagerCodeGenDir("target/interfilewithusesreferringtype/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
- deleteDirectory(userDir + "/target/interfilewithusesreferringtype/");
+ deleteDirectory("target/interfilewithusesreferringtype/");
}
@@ -659,17 +660,16 @@
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
- String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
+ yangPluginConfig.setManagerCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
- deleteDirectory(userDir + "/target/file1UsesFile2TypeDefFile3Type/");
+ deleteDirectory("target/file1UsesFile2TypeDefFile3Type/");
}
-
/**
* Checks hierarchical intra with inter file type linking.
*/
@@ -682,17 +682,16 @@
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
- String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfileietf/");
+ yangPluginConfig.setManagerCodeGenDir("target/interfileietf/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
- deleteDirectory(userDir + "/target/interfileietf/");
+ deleteDirectory("target/interfileietf/");
}
-
/**
* Checks hierarchical intra with inter file type linking.
*/
@@ -705,17 +704,16 @@
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
- String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/usesInContainer/");
+ yangPluginConfig.setManagerCodeGenDir("target/usesInContainer/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
- deleteDirectory(userDir + "/target/usesInContainer/");
+ deleteDirectory("target/usesInContainer/");
}
-
/**
* Checks hierarchical intra with inter file type linking.
*/
@@ -728,13 +726,13 @@
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
- String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/");
+ yangPluginConfig.setManagerCodeGenDir("target/groupingNodeSameAsModule/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
- deleteDirectory(userDir + "/target/groupingNodeSameAsModule/");
+ deleteDirectory("target/groupingNodeSameAsModule/");
}
@@ -846,7 +844,7 @@
thrown.expect(LinkerException.class);
thrown.expectMessage(
- "YANG file error: Unable to find base leaf/leaf-list for given leafref");
+ "YANG file error: Unable to find base leaf/leaf-list for given leafref networks");
String searchDir = "src/test/resources/interfileleafrefwithinvaliddestinationnode";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
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 cb9eff9..fcd2966 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
@@ -44,7 +44,7 @@
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
-import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.deSerializeDataModel;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.deSerializeDataModel;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.parseJarFile;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.serializeDataModel;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
@@ -189,6 +189,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(TARGET);
+ yangPluginConfig.setManagerCodeGenDir(TARGET);
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
@@ -205,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(true, is(file.exists()));
+ assertThat(false, is(file.exists()));
}
/**
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileLeafrefLinkingTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileLeafrefLinkingTest.java
index 368d5f9..81a4e70 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileLeafrefLinkingTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/IntraFileLeafrefLinkingTest.java
@@ -16,11 +16,17 @@
package org.onosproject.yangutils.plugin.manager;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
@@ -34,16 +40,10 @@
import org.onosproject.yangutils.datamodel.YangPathPredicate;
import org.onosproject.yangutils.datamodel.YangRelativePath;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/ManagerCodeGeneratorTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/ManagerCodeGeneratorTest.java
new file mode 100644
index 0000000..817fb4e
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/ManagerCodeGeneratorTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.plugin.manager;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
+
+/**
+ * Unit test case to test code generation for root nodes.
+ */
+public class ManagerCodeGeneratorTest {
+
+ private final YangUtilManager utilManager = new YangUtilManager();
+
+ /**
+ * Checks manager translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
+
+ String searchDir = "src/test/resources/manager";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir("target/manager/");
+ yangPluginConfig.setManagerCodeGenDir("target/manager/");
+
+ utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
+ String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
+ String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
+ String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
+ File manager = new File(file1);
+ assertThat(false, is(manager.exists()));
+
+ File manager2 = new File(file2);
+ assertThat(false, is(manager2.exists()));
+
+ File manager3 = new File(file3);
+ assertThat(true, is(manager3.exists()));
+
+ deleteDirectory("target/manager/");
+ }
+
+ /**
+ * Checks manager translation in different package should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
+ MojoExecutionException {
+
+ String searchDir = "src/test/resources/manager";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir("target/manager/");
+ yangPluginConfig.setManagerCodeGenDir("target/manager1/");
+
+ utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
+ String file3 = "target/manager1/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
+
+ File manager3 = new File(file3);
+ assertThat(true, is(manager3.exists()));
+
+ deleteDirectory("target/manager/");
+ deleteDirectory("target/manager1/");
+ }
+}
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 ab98c76..27b42e1 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
@@ -38,13 +38,14 @@
* Checks union translation should not result in any exception.
*/
@Test
- public void processUnionTranslator()
+ public void processNotificationTranslator()
throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/NotificationTest.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/NotificationTest/");
+ yangPluginConfig.setManagerCodeGenDir("target/NotificationTest1/");
generateJavaCode(node, yangPluginConfig);
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/RpcTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/RpcTranslatorTest.java
index e34613d..078ea50 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/RpcTranslatorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/RpcTranslatorTest.java
@@ -45,6 +45,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/RpcTestGenFile/");
+ yangPluginConfig.setManagerCodeGenDir("target/RpcTestGenFile/");
generateJavaCode(node, yangPluginConfig);
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/UnionTranslatorTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/UnionTranslatorTest.java
index b892edd..46d4f67 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/UnionTranslatorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/UnionTranslatorTest.java
@@ -45,6 +45,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
+ yangPluginConfig.setManagerCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig);
diff --git a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
index a6e2e08..891a280 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.onosproject.yangutils.plugin.manager;
import java.io.File;
@@ -11,7 +27,7 @@
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
/**
- * Created by root1 on 16/6/16.
+ * Unit test case for YANG plugin utils.
*/
public class YangPluginUtilsTest {
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
new file mode 100644
index 0000000..946bac1
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
@@ -0,0 +1,598 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.onosproject.yangutils.plugin.manager;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.ResolvableType;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.YangResolutionInfo;
+import org.onosproject.yangutils.linker.impl.YangLinkerManager;
+import org.onosproject.yangutils.linker.impl.YangXpathLinker;
+import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * Unit test cases for x-path linker.
+ */
+public class YangXpathLinkerTest {
+
+ private YangUtilManager utilManager = new YangUtilManager();
+ private YangXpathLinker linker = new YangXpathLinker();
+ private YangLinkerManager linkerManager = new YangLinkerManager();
+ private static final String INTRA_FILE_PATH = "src/test/resources/xPathLinker/IntraFile/";
+ private static final String INTER_FILE_PATH = "src/test/resources/xPathLinker/InterFile/";
+
+ /**
+ * Unit test case for intra file linking for single level container.
+ *
+ * @throws IOException when fails to do IO operations
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processIntraFileLinkingSingleLevel() throws IOException, MojoExecutionException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingle/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangNode targetNode = null;
+ String targetNodeName = null;
+
+ for (YangNode node : utilManager.getYangNodeSet()) {
+ YangReferenceResolver ref = (YangReferenceResolver) node;
+ List<YangResolutionInfo> infos = ref.getUnresolvedResolutionList(ResolvableType.YANG_AUGMENT);
+ YangResolutionInfo info = infos.get(0);
+
+ YangAugment augment = (YangAugment) info.getEntityToResolveInfo().getEntityToResolve();
+ targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ .getName();
+ targetNode = augment.getAugmentedNode();
+
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for intra file linking for multiple level container.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processIntraFileLinkingMultipleLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMulti/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ 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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for intra file linking for single level augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processIntraFileLinkingInAugmentSingleLevel() throws IOException {
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+
+ 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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for intra file linking for multiple level augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processIntraFileLinkingInAugmentMultiLevel() throws IOException {
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiAugment/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+
+ }
+
+ /**
+ * Unit test case for intra file linking for multiple level submodule.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processIntraFileLinkingInSubModuleSingleLevel() throws IOException {
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleSubModule/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesIncludeList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for intra file linking for multiple level submodule.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processIntraFileLinkingInSubModuleMultiLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiSubModule/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesIncludeList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for intra file linking for single level uses.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processIntraFileLinkingInUsesSingleLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for intra file linking for multi level uses.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processIntraFileLinkingInUsesMultiLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for inter file linking for single level container.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingSingleLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingle/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for inter file linking for multi level container.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingMultipleLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMulti/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for inter file linking for single level augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingInAugmentSingleLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleAugment/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for inter file linking for multi level augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingInAugmentMultiLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiAugment/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for multipler inter file linking for single level augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processMultiInterFileLinkingInAugmentSingleLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugment/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for multiple inter file linking for multi level augment.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processMultiInterFileLinkingInAugmentMultiLevel() throws IOException {
+
+ utilManager
+ .createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugmentMulti/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for inter file linking for single level submodule.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingInSubModuleSingleLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleSubModule/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
+ linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
+ linkerManager.addRefToYangFilesIncludeList(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+ /**
+ * Unit test case for inter file linking for multi level submodule.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingInSubModuleMultiLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiSubModule/"));
+ 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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ 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 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.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 = linker.processXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ */
+ }
+
+ /**
+ * Unit test case for inter file linking for multi level uses.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ @Test
+ public void processInterFileLinkingInUsesMultiLevel() throws IOException {
+
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ linkerManager.createYangNodeSet(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 = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ }
+ }
+
+ assertThat(true, is(targetNode.getName().equals(targetNodeName)));
+ }
+
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
deleted file mode 100644
index 39d5205..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-import org.junit.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
-
-/**
- * Unit tests for class definition generator for generated files.
- */
-public final class ClassDefinitionGeneratorTest {
-
- private static final String CLASS_NAME = "TestClass";
- private static final String INTERFACE_CLASS_DEF = "public interface TestClass {\n";
- private static final String BULDER_INTERFACE_CLASS_DEF = "interface TestClassBuilder {\n\n";
- private static final String BUILDER_CLASS_DEF = "public class TestClassBuilder implements "
- + "TestClass.TestClassBuilder {\n";
- private static final String IMPL_CLASS_DEF = "public final class TestClassImpl implements TestClass {\n";
- private static final String TYPE_DEF_CLASS_DEF = "public final class TestClass {\n";
-
- /**
- * Unit test for private constructor.
- *
- * @throws SecurityException if any security violation is observed
- * @throws NoSuchMethodException if when the method is not found
- * @throws IllegalArgumentException if there is illegal argument found
- * @throws InstantiationException if instantiation is provoked for the private constructor
- * @throws IllegalAccessException if instance is provoked or a method is provoked
- * @throws InvocationTargetException when an exception occurs by the method or constructor
- */
- @Test
- public void callPrivateConstructors()
- throws SecurityException, NoSuchMethodException, IllegalArgumentException,
- InstantiationException, IllegalAccessException, InvocationTargetException {
-
- Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
- for (Class<?> clazz : classesToConstruct) {
- Constructor<?> constructor = clazz.getDeclaredConstructor();
- constructor.setAccessible(true);
- assertThat(null, not(constructor.newInstance()));
- }
- }
-
- /**
- * Unit test for builder class definition.
- */
- @Test
- public void generateBuilderClassDefinitionTest() {
- String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME);
- assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF)));
- }
-
- /**
- * Unit test for builder interface definition.
- */
- @Test
- public void generateBuilderInterfaceDefinitionTest() {
- String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME);
- assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF)));
- }
-
- /**
- * Unit test for impl class definition.
- */
- @Test
- public void generateImplDefinitionTest() {
- String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME);
- assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF)));
- }
-
- /**
- * Unit test for interface definition.
- */
- @Test
- public void generateinterfaceDefinitionTest() {
- // TODO: need to add this test case.
- }
-
- /**
- * Unit test for typedef generated type.
- */
- @Test
- public void generateTypeDefTest() {
- String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME);
- assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF)));
- }
-}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index d441c03..5a8f822 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -30,7 +30,6 @@
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
@@ -58,7 +57,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -83,6 +81,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.io.impl.YangIoUtils.getCapitalCase;
/**
* Unit tests for generated methods from the file type.
@@ -107,7 +106,7 @@
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
- Class<?>[] classesToConstruct = {MethodsGenerator.class };
+ Class<?>[] classesToConstruct = {MethodsGenerator.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
@@ -135,7 +134,7 @@
String method = getBuild(CLASS_NAME);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
- + RETURN + SPACE + NEW + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
+ + RETURN + SPACE + NEW + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET)));
}
@@ -167,7 +166,7 @@
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
YangPluginConfig pluginConfig = new YangPluginConfig();
- String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
+ String method = getConstructor(testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
@@ -179,7 +178,7 @@
public void getConstructorStartTest() {
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructorStart(CLASS_NAME, pluginConfig);
- assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
+ assertThat(true, is(method.contains(PUBLIC + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE)));
}
diff --git a/plugin/src/test/resources/augmentTranslator/test.yang b/plugin/src/test/resources/augmentTranslator/test.yang
new file mode 100644
index 0000000..76ea6c9
--- /dev/null
+++ b/plugin/src/test/resources/augmentTranslator/test.yang
@@ -0,0 +1,68 @@
+module test {
+ namespace "test:test";
+ prefix test ;
+
+
+ import test1{
+ prefix test1;
+ }
+
+ import test2{
+ prefix test2;
+ }
+
+ include acme-types;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ container cont2 {
+ leaf leaf {
+ type int32;
+ }
+ }
+ }
+
+
+ augment /cont3 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont1/cont2 {
+ leaf leaf2 {
+ type int32;
+ }
+ }
+
+ augment /test1:cont1/test1:cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+
+ augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s {
+ leaf a {
+ type int32;
+ }
+ }
+
+ augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s/test2:aa {
+ leaf a {
+ type int32;
+ }
+ container aa {
+ }
+ }
+
+}
+
diff --git a/plugin/src/test/resources/augmentTranslator/test2.yang b/plugin/src/test/resources/augmentTranslator/test2.yang
new file mode 100644
index 0000000..3b5de76
--- /dev/null
+++ b/plugin/src/test/resources/augmentTranslator/test2.yang
@@ -0,0 +1,30 @@
+module test1 {
+ namespace "test1:test1";
+ prefix test1 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ container cont2 {
+ }
+ }
+
+ augment /cont1/cont2 {
+ leaf leaf4 {
+ type int32;
+ }
+ container cont1s {
+ container cont1s {
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/augmentTranslator/test3.yang b/plugin/src/test/resources/augmentTranslator/test3.yang
new file mode 100644
index 0000000..dca558c
--- /dev/null
+++ b/plugin/src/test/resources/augmentTranslator/test3.yang
@@ -0,0 +1,26 @@
+module test2 {
+ namespace "test2:test2";
+ prefix test2 ;
+
+ import test1{
+ prefix test1;
+ }
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+
+ augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s {
+ leaf leaf5 {
+ type int32;
+ }
+ container aa {
+ }
+ }
+}
diff --git a/plugin/src/test/resources/augmentTranslator/test4.yang b/plugin/src/test/resources/augmentTranslator/test4.yang
new file mode 100644
index 0000000..daa0f88
--- /dev/null
+++ b/plugin/src/test/resources/augmentTranslator/test4.yang
@@ -0,0 +1,21 @@
+submodule acme-types {
+
+ belongs-to "test" {
+ prefix "test";
+ }
+ import test1{
+ prefix test1;
+ }
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont3 {
+ }
+}
diff --git a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
index 5b65dff..106b2aa 100644
--- a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
+++ b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
@@ -1723,8 +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/manager/module.yang b/plugin/src/test/resources/manager/module.yang
new file mode 100644
index 0000000..212b171
--- /dev/null
+++ b/plugin/src/test/resources/manager/module.yang
@@ -0,0 +1,12 @@
+module test5 {
+ namespace "test5:test";
+ prefix test ;
+
+ revision "2016-07-04" {
+ description "Initial revision.";
+ }
+ typedef abc {
+ type int32;
+ }
+
+}
diff --git a/plugin/src/test/resources/manager/submodule.yang b/plugin/src/test/resources/manager/submodule.yang
new file mode 100644
index 0000000..961147c
--- /dev/null
+++ b/plugin/src/test/resources/manager/submodule.yang
@@ -0,0 +1,15 @@
+submodule test6 {
+
+ belongs-to "test5" {
+ prefix "test";
+ }
+
+ revision "2016-07-04" {
+ description "Initial revision.";
+ }
+ grouping abc {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/manager/test.yang b/plugin/src/test/resources/manager/test.yang
new file mode 100644
index 0000000..7b2861c
--- /dev/null
+++ b/plugin/src/test/resources/manager/test.yang
@@ -0,0 +1,13 @@
+module test7 {
+ namespace "test5:test";
+ prefix test ;
+
+ revision "2016-07-04" {
+ description "Initial revision.";
+ }
+
+ leaf abc {
+ type int32;
+ }
+
+}
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMulti/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMulti/test.yang
new file mode 100644
index 0000000..772f792
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMulti/test.yang
@@ -0,0 +1,25 @@
+module test {
+ namespace "xpath:inter:single";
+ prefix test ;
+
+ import test1{
+ prefix test1;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test1:cont1/test1:cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMulti/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMulti/test1.yang
new file mode 100644
index 0000000..9c1cdb0
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMulti/test1.yang
@@ -0,0 +1,26 @@
+module test1 {
+ namespace "xpath:inter:single";
+ prefix test1 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiAugment/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiAugment/test.yang
new file mode 100644
index 0000000..640a15a
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiAugment/test.yang
@@ -0,0 +1,25 @@
+module test {
+ namespace "xpath:inter:single";
+ prefix test ;
+
+ import test1{
+ prefix test1;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test1:cont1/test1:cont2/test1:cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiAugment/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiAugment/test1.yang
new file mode 100644
index 0000000..c9fbeab
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiAugment/test1.yang
@@ -0,0 +1,34 @@
+module test1 {
+ namespace "xpath:inter:single";
+ prefix test1 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont1 {
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test.yang
new file mode 100644
index 0000000..53ed780
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test.yang
@@ -0,0 +1,29 @@
+module test {
+ namespace "xpath:inter:single";
+ prefix test ;
+
+ import test1{
+ prefix test1;
+ }
+
+ import test2{
+ prefix test2;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test2:cont1/test2:cont2/test1:cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test1.yang
new file mode 100644
index 0000000..9ae5e24
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test1.yang
@@ -0,0 +1,51 @@
+module test1 {
+ namespace "xpath:inter:single";
+ prefix test1 ;
+
+ import test2{
+ prefix test2;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont1 {
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+ }
+
+ augment /test2:cont1/test2:cont2 {
+ leaf a {
+ type int32;
+ }
+
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test2.yang
new file mode 100644
index 0000000..f20ac7d
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugment/test2.yang
@@ -0,0 +1,26 @@
+module test2 {
+ namespace "xpath:inter:multi";
+ prefix test2 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test.yang
new file mode 100644
index 0000000..139e2c5
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test.yang
@@ -0,0 +1,29 @@
+module test {
+ namespace "xpath:inter:single";
+ prefix test ;
+
+ import test1{
+ prefix test1;
+ }
+
+ import test2{
+ prefix test2;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test2:cont1/test2:cont2/test2:cont3/test1:cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test1.yang
new file mode 100644
index 0000000..ed3716f
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test1.yang
@@ -0,0 +1,51 @@
+module test1 {
+ namespace "xpath:inter:single";
+ prefix test1 ;
+
+ import test2{
+ prefix test2;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont1 {
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+ }
+
+ augment /test2:cont1/test2:cont2/test2:cont3 {
+ leaf a {
+ type int32;
+ }
+
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test2.yang
new file mode 100644
index 0000000..f65bef0
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiFileAugmentMulti/test2.yang
@@ -0,0 +1,34 @@
+module test2 {
+ namespace "xpath:inter:multi";
+ prefix test2 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont1/cont2 {
+ container cont3 {
+ leaf a {
+ type string;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test.yang
new file mode 100644
index 0000000..40b2386
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test.yang
@@ -0,0 +1,33 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ import test2 {
+ prefix test2;
+ }
+
+ include test1;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test2:cont1/test2:cont2/cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+
+ augment /cont2/cont3/cont4 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test1.yang
new file mode 100644
index 0000000..a19ba35
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test1.yang
@@ -0,0 +1,50 @@
+submodule test1 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ import test2 {
+ prefix test2;
+ }
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont3 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont2/cont3 {
+ container cont4 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+
+ augment /test2:cont1/test2:cont2 {
+ leaf a {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test2.yang
new file mode 100644
index 0000000..f20ac7d
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiSubModule/test2.yang
@@ -0,0 +1,26 @@
+module test2 {
+ namespace "xpath:inter:multi";
+ prefix test2 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test.yang
new file mode 100644
index 0000000..80ee110
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test.yang
@@ -0,0 +1,32 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ import test2 {
+ prefix test2;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont2 {
+ leaf a {
+ type int32;
+ }
+ uses test2:group1;
+ }
+
+ augment /cont2/group1/cont1/cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test2.yang
new file mode 100644
index 0000000..298d443
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterMultiUses/test2.yang
@@ -0,0 +1,28 @@
+module test2 {
+ namespace "xpath:inter:multi";
+ prefix test2 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ grouping group1 {
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingle/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingle/test.yang
new file mode 100644
index 0000000..102ec39
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingle/test.yang
@@ -0,0 +1,25 @@
+module test {
+ namespace "xpath:inter:single";
+ prefix test ;
+
+ import test1{
+ prefix test1;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test1:cont1 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingle/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingle/test1.yang
new file mode 100644
index 0000000..243ddfe
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingle/test1.yang
@@ -0,0 +1,21 @@
+module test1 {
+ namespace "xpath:inter:single";
+ prefix test1 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleAugment/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleAugment/test.yang
new file mode 100644
index 0000000..772f792
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleAugment/test.yang
@@ -0,0 +1,25 @@
+module test {
+ namespace "xpath:inter:single";
+ prefix test ;
+
+ import test1{
+ prefix test1;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test1:cont1/test1:cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleAugment/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleAugment/test1.yang
new file mode 100644
index 0000000..b9c5e32
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleAugment/test1.yang
@@ -0,0 +1,29 @@
+module test1 {
+ namespace "xpath:inter:single";
+ prefix test1 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont1 {
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test.yang
new file mode 100644
index 0000000..a8340ab
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test.yang
@@ -0,0 +1,27 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ import test2 {
+ prefix test2;
+ }
+
+ include test1;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test2:cont1/test2:cont2/cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test1.yang
new file mode 100644
index 0000000..ebc8750
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test1.yang
@@ -0,0 +1,31 @@
+submodule test1 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ import test2 {
+ prefix test2;
+ }
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test2:cont1/test2:cont2 {
+ leaf a {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test2.yang
new file mode 100644
index 0000000..f20ac7d
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleSubModule/test2.yang
@@ -0,0 +1,26 @@
+module test2 {
+ namespace "xpath:inter:multi";
+ prefix test2 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test.yang
new file mode 100644
index 0000000..4b15645
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test.yang
@@ -0,0 +1,34 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ import test2 {
+ prefix test2;
+ }
+
+ include test1;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ augment /test2:cont1/test2:cont2/cont2 {
+ leaf a {
+ type int32;
+ }
+ uses group1;
+ }
+
+ augment /test2:cont1/test2:cont2/cont2/group1/cont1/cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test1.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test1.yang
new file mode 100644
index 0000000..fbc3bcb
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test1.yang
@@ -0,0 +1,42 @@
+submodule test1 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ import test2 {
+ prefix test2;
+ }
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+
+ grouping group1 {
+ container cont1 {
+ container cont2 {
+ leaf a {
+ type string;
+ }
+ }
+ }
+ }
+
+ augment /test2:cont1/test2:cont2 {
+ leaf a {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test2.yang b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test2.yang
new file mode 100644
index 0000000..f20ac7d
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/InterFile/InterSingleUses/test2.yang
@@ -0,0 +1,26 @@
+module test2 {
+ namespace "xpath:inter:multi";
+ prefix test2 ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraMulti/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMulti/test.yang
new file mode 100644
index 0000000..77d61b9
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMulti/test.yang
@@ -0,0 +1,37 @@
+module test {
+ namespace "xpath:intra:multi";
+ prefix test ;
+
+ 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;
+ }
+ container cont3 {
+ leaf leaf3 {
+ type int32;
+ }
+ }
+ }
+ }
+
+ augment /cont1/cont2/cont3 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiAugment/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiAugment/test.yang
new file mode 100644
index 0000000..b53012c
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiAugment/test.yang
@@ -0,0 +1,54 @@
+module test {
+ namespace "xpath:intra:multi";
+ prefix test ;
+
+ 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;
+ }
+ container cont3 {
+ leaf leaf3 {
+ type int32;
+ }
+ }
+ }
+ }
+
+ augment /cont1/cont2/cont3 {
+ leaf a {
+ type int32;
+ }
+ container cont4 {
+ leaf leaf2 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont1/cont2/cont3/cont4 {
+ leaf a {
+ type int32;
+ }
+
+ container cont5 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiSubModule/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiSubModule/test.yang
new file mode 100644
index 0000000..b5d1c8d
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiSubModule/test.yang
@@ -0,0 +1,28 @@
+module test {
+ namespace "xpath:intra:multi";
+ prefix test ;
+
+ include test1;
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont2/cont3 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiSubModule/test1.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiSubModule/test1.yang
new file mode 100644
index 0000000..faf672e
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiSubModule/test1.yang
@@ -0,0 +1,28 @@
+submodule test1 {
+
+ belongs-to "test" {
+ prefix "test";
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont3 {
+ leaf leaf3 {
+ type int32;
+ }
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiUses/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiUses/test.yang
new file mode 100644
index 0000000..6cfb133
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraMultiUses/test.yang
@@ -0,0 +1,38 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ grouping group1 {
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ container cont3 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+ }
+
+ container cont2 {
+ uses group1;
+ }
+
+ augment /cont2/group1/cont1/cont3 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingle/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingle/test.yang
new file mode 100644
index 0000000..95d9c2b
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingle/test.yang
@@ -0,0 +1,27 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont1 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleAugment/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleAugment/test.yang
new file mode 100644
index 0000000..2925dcf
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleAugment/test.yang
@@ -0,0 +1,39 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont1 {
+ leaf a {
+ type int32;
+ }
+
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+
+ augment /cont1/cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleSubModule/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleSubModule/test.yang
new file mode 100644
index 0000000..77401da
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleSubModule/test.yang
@@ -0,0 +1,28 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ include test1;
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+
+ augment /cont2 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleSubModule/test1.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleSubModule/test1.yang
new file mode 100644
index 0000000..47d4c5c
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleSubModule/test1.yang
@@ -0,0 +1,23 @@
+submodule test1 {
+
+ belongs-to test {
+ prefix test;
+ }
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ container cont2 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+}
+
diff --git a/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleUses/test.yang b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleUses/test.yang
new file mode 100644
index 0000000..c60668a
--- /dev/null
+++ b/plugin/src/test/resources/xPathLinker/IntraFile/IntraSingleUses/test.yang
@@ -0,0 +1,33 @@
+module test {
+ namespace "xpath:intra:single";
+ prefix test ;
+
+ organization "";
+ contact "";
+
+ description
+ "Defines basic service types for L3VPN service.";
+
+ revision "2015-12-16" {
+ reference "";
+ }
+
+ grouping group1 {
+ container cont1 {
+ leaf leaf1 {
+ type int32;
+ }
+ }
+ }
+
+ container cont2 {
+ uses group1;
+ }
+
+ augment /cont2/group1/cont1 {
+ leaf a {
+ type int32;
+ }
+ }
+}
+