[ONOS-5232] Update generated code
Change-Id: I9c25d9f2888fbee78fddf10d02a3fa94f7ce46e0
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
index 23e190c..507ebf3 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
@@ -16,20 +16,16 @@
package org.onosproject.yangutils.linker.impl;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
import org.onosproject.yangutils.datamodel.TraversalType;
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.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
+import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangLeaf;
@@ -48,18 +44,40 @@
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.CASE;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.FAILED_TO_ADD_CASE;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.TARGET_NODE;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.TARGET_NODE_LEAF_INFO;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
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.getYangConstructType;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
+import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.IS_INVALID;
+import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
/**
* Represent utilities for YANG linker.
@@ -82,20 +100,12 @@
private static void detectCollision(YangNode targetNode, YangAugment augment) {
YangNode targetNodesChild = targetNode.getChild();
YangNode augmentsChild = augment.getChild();
- YangNode parent = targetNode;
- if (targetNode instanceof YangAugment) {
- parent = targetNode.getParent();
- } else {
- while (parent.getParent() != null) {
- parent = parent.getParent();
- }
- }
if (targetNode instanceof YangChoice) {
addCaseNodeToChoiceTarget(augment);
} else {
detectCollisionInLeaveHolders(targetNode, augment);
while (augmentsChild != null) {
- detectCollisionInChildNodes(targetNodesChild, augmentsChild, targetNode.getName(), parent.getName());
+ detectCollisionInChildNodes(targetNodesChild, augmentsChild);
augmentsChild = augmentsChild.getNextSibling();
}
}
@@ -104,52 +114,52 @@
/*Detects collision between leaves/leaf-lists*/
private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
- YangNode parent = targetNode;
- if (targetNode instanceof YangAugment) {
- parent = targetNode.getParent();
- } else {
- while (parent.getParent() != null) {
- parent = parent.getParent();
- }
- }
- if (augment.getListOfLeaf() != null && augment.getListOfLeaf().size() != 0
- && targetNodesLeavesHolder.getListOfLeaf() != null) {
+ if (augment.getListOfLeaf() != null && augment.getListOfLeaf().isEmpty() &&
+ targetNodesLeavesHolder.getListOfLeaf() != null) {
for (YangLeaf leaf : augment.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() + " in " + targetNode.getLineNumber()
- + " at " + targetNode.getCharPosition() + " in " + targetNode.getFileName());
- }
+ detectCollision(targetLeaf.getName(), leaf.getName(),
+ leaf.getLineNumber(),
+ leaf.getCharPosition(),
+ leaf.getFileName(), TARGET_NODE_LEAF_INFO);
}
}
- } else if (augment.getListOfLeafList() != null
- && augment.getListOfLeafList().size() != 0
- && augment.getListOfLeafList() != null) {
+ }
+ if (augment.getListOfLeafList() != null &&
+ augment.getListOfLeafList().isEmpty() &&
+ targetNodesLeavesHolder.getListOfLeafList() != null) {
for (YangLeafList leafList : augment.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() + " in " + targetNode.getLineNumber()
- + " at " + targetNode.getCharPosition() + " in " + targetNode.getFileName());
- }
+ detectCollision(targetLeafList.getName(), leafList.getName(),
+ leafList.getLineNumber(),
+ leafList.getCharPosition(),
+ leafList.getFileName(), TARGET_NODE_LEAF_INFO);
}
}
}
}
+
+ private static void detectCollision(String first, String second,
+ int line, int position, String
+ fileName, String type) {
+ if (first.equals(second)) {
+ throw new LinkerException(getErrorMsgCollision(
+ COLLISION_DETECTION, second, line, position, type,
+ fileName));
+ }
+ }
+
/*Detects collision for child nodes.*/
- private static void detectCollisionInChildNodes(YangNode targetNodesChild, YangNode augmentsChild, String
- targetName, String parentName) {
+ private static void detectCollisionInChildNodes(YangNode targetNodesChild,
+ YangNode augmentsChild) {
while (augmentsChild != null) {
while (targetNodesChild != null) {
if (targetNodesChild.getName().equals(augmentsChild.getName())) {
- throw new LinkerException("target node " + targetName
- + " contains augmented child node " + augmentsChild.getName() + " in module "
- + parentName + " in " + targetNodesChild.getLineNumber()
- + " at " + targetNodesChild.getCharPosition() + " in " + targetNodesChild.getFileName());
+ detectCollision(targetNodesChild.getName(), augmentsChild.getName(),
+ augmentsChild.getLineNumber(),
+ augmentsChild.getCharPosition(),
+ augmentsChild.getFileName(), TARGET_NODE);
}
targetNodesChild = targetNodesChild.getNextSibling();
}
@@ -202,12 +212,51 @@
}
} catch (DataModelException e) {
- throw new TranslatorException("Failed to add child nodes to case node of augment " + augment.getName()
- + " in " + augment.getLineNumber() + " at "
- + augment.getCharPosition() + " in " + augment.getFileName());
+ throw new TranslatorException(
+ getErrorMsg(FAILED_TO_ADD_CASE, augment.getName(),
+ augment.getLineNumber(), augment.getCharPosition(),
+ augment.getFileName()));
}
}
+ /**
+ * Returns error messages.
+ *
+ * @param resolvable resolvable entity
+ * @return error message
+ */
+ static String getErrorInfoForLinker(Object resolvable) {
+ if (resolvable instanceof YangType) {
+ return TYPEDEF_LINKER_ERROR;
+ }
+ if (resolvable instanceof YangUses) {
+ return GROUPING_LINKER_ERROR;
+ }
+ if (resolvable instanceof YangIfFeature) {
+ return FEATURE_LINKER_ERROR;
+ }
+ if (resolvable instanceof YangBase) {
+ return BASE_LINKER_ERROR;
+ }
+ if (resolvable instanceof YangIdentityRef) {
+ return IDENTITYREF_LINKER_ERROR;
+ }
+ return LEAFREF_LINKER_ERROR;
+ }
+
+ /**
+ * Returns leafref's error message.
+ *
+ * @param leafref leaf ref
+ * @return error message
+ */
+ static String getLeafRefErrorInfo(YangLeafRef leafref) {
+ return getErrorMsg(
+ LEAFREF_ERROR + leafref.getPath() + COMMA + IS_INVALID, EMPTY_STRING,
+ leafref.getLineNumber(), leafref.getCharPosition(), leafref
+ .getFileName());
+ }
+
//Detect collision between augment and choice children.
private void detectCollisionForChoiceNode(YangNode choice, YangNode augment) {
YangNode choiceChild = choice.getChild();
@@ -225,9 +274,11 @@
for (YangNode cChild : choiceChildren) {
for (YangNode aChild : augmentChildren) {
if (cChild.getName().equals(aChild.getName())) {
- throw new LinkerException("case node " + aChild.getName() + "already present in choice " +
- choice.getName() + " in " + cChild.getLineNumber() + " at " + cChild.getCharPosition()
- + " in " + cChild.getFileName());
+ ;
+ throw new LinkerException(getErrorMsgCollision(
+ COLLISION_DETECTION, cChild.getName(),
+ cChild.getLineNumber(), cChild.getCharPosition(),
+ CASE, cChild.getFileName()));
}
}
}
@@ -260,10 +311,10 @@
static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) {
List<String> listOfPathName = new ArrayList<>();
for (YangAtomicPath atomicPath : augment.getTargetNode()) {
- if (atomicPath.getNodeIdentifier().getPrefix() != null && !atomicPath.getNodeIdentifier().getPrefix()
- .equals(EMPTY_STRING)) {
- listOfPathName.add(atomicPath.getNodeIdentifier().getPrefix() + ":" +
- atomicPath.getNodeIdentifier().getName());
+ if (atomicPath.getNodeIdentifier().getPrefix() != null &&
+ !atomicPath.getNodeIdentifier().getPrefix().equals(EMPTY_STRING)) {
+ listOfPathName.add(atomicPath.getNodeIdentifier().getPrefix()
+ + COLON + atomicPath.getNodeIdentifier().getName());
} else {
listOfPathName.add(atomicPath.getNodeIdentifier().getName());
}
@@ -286,9 +337,12 @@
throws LinkerException {
while (currentParent instanceof YangChoice || currentParent instanceof YangCase) {
if (currentParent.getParent() == null) {
- throw new LinkerException("YANG file error: The target node, in the leafref path " +
- leafref.getPath() + ", is invalid." + " in " + leafref.getLineNumber()
- + " at " + leafref.getCharPosition() + " in " + leafref.getFileName());
+ LinkerException ex = new LinkerException(
+ LEAFREF_ERROR + leafref.getPath() + IS_INVALID);
+ ex.setCharPosition(leafref.getCharPosition());
+ ex.setLine(leafref.getLineNumber());
+ ex.setFileName(leafref.getFileName());
+ throw ex;
}
currentParent = currentParent.getParent();
}
@@ -316,8 +370,8 @@
return nodeIdentifier;
} else {
throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + nodeIdentifierString +
- " is not valid.");
+ getYangConstructType(yangConstruct) + " name " + nodeIdentifierString +
+ " is not valid.");
}
}
@@ -332,16 +386,16 @@
if (identifier.length() > IDENTIFIER_LENGTH) {
throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifier + " is " +
- "greater than 64 characters.");
+ getYangConstructType(yangConstruct) + " name " + identifier + " is " +
+ "greater than 64 characters.");
} else if (!IDENTIFIER_PATTERN.matcher(identifier).matches()) {
throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifier + " is not " +
- "valid.");
+ getYangConstructType(yangConstruct) + " name " + identifier + " is not " +
+ "valid.");
} else if (identifier.toLowerCase().startsWith(XML)) {
throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " identifier " + identifier +
- " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
+ getYangConstructType(yangConstruct) + " identifier " + identifier +
+ " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
} else {
return identifier;
}
@@ -450,7 +504,7 @@
// Add resolution information to the list
YangResolutionInfoImpl resolutionInfo =
new YangResolutionInfoImpl<YangType>(type, curNode, type.getLineNumber(),
- type.getCharPosition());
+ type.getCharPosition());
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
@@ -460,7 +514,7 @@
" at position: " + e.getCharPositionInLine()
+ e.getLocalizedMessage();
throw new LinkerException("Failed to add type info in grouping to resolution "
- + errorInfo);
+ + errorInfo);
}
}
}
@@ -498,7 +552,7 @@
// Add resolution information to the list
YangResolutionInfoImpl resolutionInfo =
new YangResolutionInfoImpl<>(type, (YangNode) leavesHolder,
- type.getLineNumber(), type.getCharPosition());
+ type.getLineNumber(), type.getCharPosition());
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
@@ -512,7 +566,7 @@
// Add resolution information to the list
YangResolutionInfoImpl resolutionInfo =
new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
- identityRef.getLineNumber(), identityRef.getCharPosition());
+ identityRef.getLineNumber(), identityRef.getCharPosition());
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
@@ -532,7 +586,7 @@
// Add resolution information to the list
YangResolutionInfoImpl resolutionInfo =
new YangResolutionInfoImpl<YangType>(type, (YangNode) leavesHolder,
- type.getLineNumber(), type.getCharPosition());
+ type.getLineNumber(), type.getCharPosition());
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
@@ -545,7 +599,7 @@
// Add resolution information to the list
YangResolutionInfoImpl resolutionInfo =
new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
- identityRef.getLineNumber(), identityRef.getCharPosition());
+ identityRef.getLineNumber(), identityRef.getCharPosition());
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
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 1281bb8..84de876 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
@@ -16,15 +16,10 @@
package org.onosproject.yangutils.linker.impl;
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Stack;
-
import org.onosproject.yangutils.datamodel.DefaultLocationInfo;
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
@@ -32,7 +27,6 @@
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfoImpl;
import org.onosproject.yangutils.datamodel.YangFeature;
import org.onosproject.yangutils.datamodel.YangFeatureHolder;
@@ -47,31 +41,35 @@
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangPathArgType;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangRelativePath;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.YangSubModule;
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.YangConstructType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.linker.YangLinkingPhase;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Stack;
+
+import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_IDENTITYREF;
+import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_LEAFREF;
import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
+import static org.onosproject.yangutils.datamodel.YangPathArgType.ABSOLUTE_PATH;
+import static org.onosproject.yangutils.datamodel.YangPathArgType.RELATIVE_PATH;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
@@ -79,24 +77,27 @@
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNDEFINED;
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.datamodel.utils.YangConstructType.PATH_DATA;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
+import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getErrorInfoForLinker;
+import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getLeafRefErrorInfo;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getPathWithAugment;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getValidNodeIdentifier;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.skipInvalidDataNodes;
-import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-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.FAILED_TO_FIND_ANNOTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_FIND_LEAD_INFO_HOLDER;
+import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_LINK;
import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
-import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
+import static org.onosproject.yangutils.utils.UtilConstants.INVALID_ENTITY;
+import static org.onosproject.yangutils.utils.UtilConstants.INVALID_LINKER_STATE;
+import static org.onosproject.yangutils.utils.UtilConstants.INVALID_RESOLVED_ENTITY;
+import static org.onosproject.yangutils.utils.UtilConstants.INVALID_TARGET;
+import static org.onosproject.yangutils.utils.UtilConstants.INVALID_TREE;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
+import static org.onosproject.yangutils.utils.UtilConstants.LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.UNRESOLVABLE;
/**
* Represents implementation of resolution object which will be resolved by
@@ -118,7 +119,7 @@
* Current module/sub-module reference, will be used in inter-file/
* inter-jar scenario to get the import/include list.
*/
- private YangReferenceResolver curReferenceResolver;
+ private YangReferenceResolver curRefResolver;
/**
* Stack for type/uses is maintained for hierarchical references, this is
@@ -142,25 +143,26 @@
* @param lineNumber error line number
* @param charPositionInLine error character position in line
*/
- public YangResolutionInfoImpl(T dataNode, YangNode holderNode, int lineNumber, int charPositionInLine) {
- setEntityToResolveInfo(new YangEntityToResolveInfoImpl<>());
- getEntityToResolveInfo().setEntityToResolve(dataNode);
- getEntityToResolveInfo().setHolderOfEntityToResolve(holderNode);
- this.setLineNumber(lineNumber);
- this.setCharPosition(charPositionInLine);
- setPartialResolvedStack(new Stack<>());
+ public YangResolutionInfoImpl(T dataNode, YangNode holderNode, int lineNumber,
+ int charPositionInLine) {
+ entityToResolveInfo = new YangEntityToResolveInfoImpl<>();
+ entityToResolveInfo.setEntityToResolve(dataNode);
+ entityToResolveInfo.setHolderOfEntityToResolve(holderNode);
+ setLineNumber(lineNumber);
+ setCharPosition(charPositionInLine);
+ partialResolvedStack = new Stack<>();
}
@Override
public void resolveLinkingForResolutionInfo(YangReferenceResolver dataModelRootNode)
throws DataModelException {
- setCurReferenceResolver(dataModelRootNode);
- /*
+ curRefResolver = dataModelRootNode;
+ /*
* Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or
* YANG leafref or YANG base or YANG identityref.
*/
- T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
+ T entityToResolve = entityToResolveInfo.getEntityToResolve();
// Check if linking is already done
if (entityToResolve instanceof Resolvable) {
@@ -172,14 +174,11 @@
return;
}
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
- "type/uses/if-feature/leafref/base/identityref");
+ throw new DataModelException(LINKER_ERROR);
}
// Push the initial entity to resolve in stack.
- addInPartialResolvedStack(getEntityToResolveInfo());
-
+ addInPartialResolvedStack(entityToResolveInfo);
linkAndResolvePartialResolvedStack();
-
addDerivedRefTypeToRefTypeResolutionList();
}
@@ -191,87 +190,63 @@
private void linkAndResolvePartialResolvedStack()
throws DataModelException {
- while (getPartialResolvedStack().size() != 0) {
+ while (!partialResolvedStack.isEmpty()) {
/*
* Current node to resolve, it can be a YANG type or YANG uses or
* YANG if-feature or YANG leafref or YANG base or YANG identityref.
*/
- T entityToResolve = getCurrentEntityToResolveFromStack();
+ T entityToResolve = getCurEntityToResolveFromStack();
+ if (!(entityToResolve instanceof Resolvable)) {
+ throw new DataModelException(LINKER_ERROR);
+ }
// Check if linking is already done
- if (entityToResolve instanceof Resolvable) {
-
- Resolvable resolvable = (Resolvable) entityToResolve;
- switch (resolvable.getResolvableStatus()) {
- case RESOLVED: {
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ switch (resolvable.getResolvableStatus()) {
+ case RESOLVED:
/*
* If the entity is already resolved in the stack, then pop
* it and continue with the remaining stack elements to
* resolve
*/
- getPartialResolvedStack().pop();
- break;
- }
+ partialResolvedStack.pop();
+ break;
- case LINKED: {
+ case LINKED:
/*
* If the top of the stack is already linked then resolve
* the references and pop the entity and continue with
* remaining stack elements to resolve.
*/
- resolveTopOfStack(INTRA_FILE);
- getPartialResolvedStack().pop();
- break;
- }
+ resolveTopOfStack();
+ partialResolvedStack.pop();
+ break;
- case INTRA_FILE_RESOLVED: {
+ case INTRA_FILE_RESOLVED:
/*
* Pop the top of the stack.
*/
- getPartialResolvedStack().pop();
- break;
+ partialResolvedStack.pop();
+ break;
+
+ case UNRESOLVED:
+ linkTopOfStackReferenceUpdateStack();
+
+ if (resolvable.getResolvableStatus() == UNRESOLVED) {
+ // If current entity is still not resolved, then
+ // linking/resolution has failed.
+ DataModelException ex =
+ new DataModelException
+ (getErrorInfoForLinker(resolvable));
+ ex.setLine(getLineNumber());
+ ex.setCharPosition(getCharPosition());
+ throw ex;
}
+ break;
- case UNRESOLVED: {
- linkTopOfStackReferenceUpdateStack();
-
- if (resolvable.getResolvableStatus() == UNRESOLVED) {
- // If current entity is still not resolved, then
- // linking/resolution has failed.
- String errorInfo;
- if (resolvable instanceof YangType) {
- errorInfo = TYPEDEF_LINKER_ERROR;
- } else if (resolvable instanceof YangUses) {
- errorInfo = GROUPING_LINKER_ERROR;
- } else if (resolvable instanceof YangIfFeature) {
- errorInfo = FEATURE_LINKER_ERROR;
- } else if (resolvable instanceof YangBase) {
- errorInfo = BASE_LINKER_ERROR;
- } else if (resolvable instanceof YangIdentityRef) {
- errorInfo = IDENTITYREF_LINKER_ERROR;
- } else {
- errorInfo = LEAFREF_LINKER_ERROR;
- }
- DataModelException dataModelException =
- new DataModelException(errorInfo);
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- throw dataModelException;
- }
- break;
- }
- default: {
- throw new DataModelException("Data Model Exception: Unsupported, linker state");
- }
-
- }
-
- } else {
- throw new DataModelException(
- "Data Model Exception: Entity to resolved is other than type/uses/if-feature" +
- "/leafref/base/identityref");
+ default:
+ throw new DataModelException(INVALID_LINKER_STATE);
}
}
-
}
/**
@@ -281,39 +256,30 @@
private void addDerivedRefTypeToRefTypeResolutionList()
throws DataModelException {
- YangNode potentialAncestorWithReferredNode = getEntityToResolveInfo().getHolderOfEntityToResolve();
+ YangNode refNode = entityToResolveInfo.getHolderOfEntityToResolve();
+ YangType yangType = getValidateResolvableType();
- // If holder is typedef return.
- if (potentialAncestorWithReferredNode instanceof YangTypeDef) {
+ if (yangType == null) {
return;
}
- // If entity is not type return.
- if (!(getEntityToResolveInfo().getEntityToResolve() instanceof YangType)) {
- return;
- }
+ YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType
+ .getDataTypeExtendedInfo();
- YangType yangType = (YangType) getEntityToResolveInfo().getEntityToResolve();
-
- // If type is not resolved return.
- if (yangType.getResolvableStatus() != RESOLVED) {
- return;
- }
-
- YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType.getDataTypeExtendedInfo();
-
+ YangDataTypes dataType = derivedInfo.getEffectiveBuiltInType();
// If the derived types referred type is not leafref/identityref return
- if ((derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) &&
- (derivedInfo.getEffectiveBuiltInType() != YangDataTypes.IDENTITYREF)) {
+ if (dataType != YangDataTypes.LEAFREF &&
+ dataType != YangDataTypes.IDENTITYREF) {
return;
}
- T extendedInfo = (T) derivedInfo.getReferredTypeDef().getTypeDefBaseType().getDataTypeExtendedInfo();
+ T extendedInfo = (T) derivedInfo.getReferredTypeDef()
+ .getTypeDefBaseType().getDataTypeExtendedInfo();
while (extendedInfo instanceof YangDerivedInfo) {
YangDerivedInfo derivedInfoFromTypedef = (YangDerivedInfo) extendedInfo;
- extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef().getTypeDefBaseType()
- .getDataTypeExtendedInfo();
+ extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef()
+ .getTypeDefBaseType().getDataTypeExtendedInfo();
}
/*
@@ -322,61 +288,76 @@
* create a leafref/identityref resolution info using the current resolution info and
* add to leafref/identityref resolution list.
*/
- if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.LEAFREF) {
+ if (dataType == YangDataTypes.LEAFREF) {
YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo;
- yangType.resetYangType();
-
- yangType.setResolvableStatus(RESOLVED);
- yangType.setDataType(YangDataTypes.LEAFREF);
- yangType.setDataTypeName(LEAFREF);
- yangType.setDataTypeExtendedInfo(leafRefInTypeDef);
- leafRefInTypeDef.setResolvableStatus(UNRESOLVED);
- leafRefInTypeDef.setParentNodeOfLeafref(potentialAncestorWithReferredNode);
-
- // Add resolution information to the list.
- YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(leafRefInTypeDef,
- potentialAncestorWithReferredNode,
- getLineNumber(), getCharPosition());
- getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
- ResolvableType.YANG_LEAFREF);
- getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
-
- } else if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.IDENTITYREF) {
-
- YangIdentityRef identityRefInTypeDef = (YangIdentityRef) extendedInfo;
- yangType.resetYangType();
-
- yangType.setResolvableStatus(RESOLVED);
- yangType.setDataType(YangDataTypes.IDENTITYREF);
- yangType.setDataTypeName(IDENTITYREF);
- yangType.setDataTypeExtendedInfo(identityRefInTypeDef);
- identityRefInTypeDef.setResolvableStatus(UNRESOLVED);
-
- // Add resolution information to the list.
- YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(identityRefInTypeDef,
- potentialAncestorWithReferredNode, getLineNumber(), getCharPosition());
- getCurReferenceResolver().addToResolutionList(resolutionInfoImpl,
- ResolvableType.YANG_IDENTITYREF);
- getCurReferenceResolver().resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
+ addRefTypeInfo(YangDataTypes.LEAFREF, LEAFREF, extendedInfo,
+ yangType, refNode, YANG_LEAFREF);
+ leafRefInTypeDef.setParentNodeOfLeafref(refNode);
+ } else {
+ addRefTypeInfo(YangDataTypes.IDENTITYREF, IDENTITYREF, extendedInfo,
+ yangType, refNode, YANG_IDENTITYREF);
}
}
+ //Validates entity to resolve for YANG type and returns type
+ private YangType getValidateResolvableType() {
+ YangNode refNode = entityToResolveInfo.getHolderOfEntityToResolve();
+ T entity = entityToResolveInfo.getEntityToResolve();
+ // If holder is typedef return.
+ if (!(refNode instanceof YangTypeDef) && entity instanceof YangType) {
+ YangType yangType = (YangType) entity;
+
+ // If type is not resolved return.
+ if (yangType.getResolvableStatus() == RESOLVED) {
+ return (YangType) entity;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Adds referred type(leafref/identityref) info to resolution list.
+ *
+ * @param type data type
+ * @param typeName type name
+ * @param info extended info
+ * @param yangType YANG type
+ * @param refNode referred node
+ * @param resType resolution type
+ * @throws DataModelException when fails to do data model operations
+ */
+ private void addRefTypeInfo(YangDataTypes type, String typeName, T info,
+ YangType yangType, YangNode refNode,
+ ResolvableType resType) throws DataModelException {
+ yangType.resetYangType();
+ yangType.setResolvableStatus(RESOLVED);
+ yangType.setDataType(type);
+ yangType.setDataTypeName(typeName);
+ yangType.setDataTypeExtendedInfo(info);
+ ((Resolvable) info).setResolvableStatus(UNRESOLVED);
+ YangResolutionInfoImpl resolutionInfoImpl
+ = new YangResolutionInfoImpl<>(info, refNode,
+ getLineNumber(), getCharPosition());
+ curRefResolver.addToResolutionList(resolutionInfoImpl, resType);
+ curRefResolver.resolveSelfFileLinking(resType);
+ }
+
/**
* Resolves the current entity in the stack.
*/
- private void resolveTopOfStack(YangLinkingPhase linkingPhase)
+ private void resolveTopOfStack()
throws DataModelException {
- List<T> entityToResolve = (List<T>) ((Resolvable) getCurrentEntityToResolveFromStack()).resolve();
+ T entity = getCurEntityToResolveFromStack();
+ List<T> entityToResolve = (List<T>) ((Resolvable) entity).resolve();
if (entityToResolve != null && !entityToResolve.isEmpty()) {
- Iterator<T> entityToResolveIterator = entityToResolve.listIterator();
- while (entityToResolveIterator.hasNext()) {
- addUnresolvedEntitiesToResolutionList(entityToResolveIterator.next());
+ for (T anEntityToResolve : entityToResolve) {
+ addUnresolvedEntitiesToResolutionList(anEntityToResolve);
}
}
- if (((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != INTRA_FILE_RESOLVED
- && ((Resolvable) getCurrentEntityToResolveFromStack()).getResolvableStatus() != UNDEFINED) {
+ if (((Resolvable) entity).getResolvableStatus() != INTRA_FILE_RESOLVED &&
+ ((Resolvable) entity).getResolvableStatus() != UNDEFINED) {
// Sets the resolution status in inside the type/uses/if-feature/leafref.
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(RESOLVED);
+ ((Resolvable) entity).setResolvableStatus(RESOLVED);
}
}
@@ -389,10 +370,13 @@
private void addUnresolvedEntitiesToResolutionList(T entityToResolve)
throws DataModelException {
if (entityToResolve instanceof YangEntityToResolveInfoImpl) {
- YangEntityToResolveInfoImpl entityToResolveInfo = (YangEntityToResolveInfoImpl) entityToResolve;
+ YangEntityToResolveInfoImpl entityToResolveInfo
+ = (YangEntityToResolveInfoImpl) entityToResolve;
if (entityToResolveInfo.getEntityToResolve() instanceof YangLeafRef) {
- YangLeafRef leafref = (YangLeafRef) entityToResolveInfo.getEntityToResolve();
- YangNode parentNodeOfLeafref = entityToResolveInfo.getHolderOfEntityToResolve();
+ YangLeafRef leafref = (YangLeafRef) entityToResolveInfo
+ .getEntityToResolve();
+ YangNode parentNodeOfLeafref = entityToResolveInfo
+ .getHolderOfEntityToResolve();
leafref.setParentNodeOfLeafref(parentNodeOfLeafref);
if (leafref.getResolvableStatus() == UNRESOLVED) {
leafref.setResolvableStatus(INTRA_FILE_RESOLVED);
@@ -401,8 +385,10 @@
// Add resolution information to the list.
YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(
- entityToResolveInfo.getEntityToResolve(), entityToResolveInfo.getHolderOfEntityToResolve(),
- entityToResolveInfo.getLineNumber(), entityToResolveInfo.getCharPosition());
+ entityToResolveInfo.getEntityToResolve(),
+ entityToResolveInfo.getHolderOfEntityToResolve(),
+ entityToResolveInfo.getLineNumber(),
+ entityToResolveInfo.getCharPosition());
addResolutionInfo(resolutionInfoImpl);
}
}
@@ -414,9 +400,9 @@
*/
private void linkTopOfStackReferenceUpdateStack()
throws DataModelException {
-
- if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangLeafRef) {
+ ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
return;
}
/*
@@ -425,51 +411,45 @@
* sub-module from include list.
*/
if (!isCandidateForSelfFileReference()) {
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
return;
}
- /**
+ /*
* Try to resolve the top of the stack and update partial resolved stack
* if there is recursive references
*/
- YangNode potentialAncestorWithReferredNode = getPartialResolvedStack().peek()
+ YangNode ancestorRefNode = partialResolvedStack.peek()
.getHolderOfEntityToResolve();
- if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- resolveSelfFileLinkingForIfFeature(potentialAncestorWithReferredNode);
+ if (entity instanceof YangIfFeature) {
+ resolveSelfFileLinkingForIfFeature(ancestorRefNode);
return;
- } else if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
- (getCurrentEntityToResolveFromStack() instanceof YangBase)) {
+ }
+ if (entity instanceof YangIdentityRef || entity instanceof YangBase) {
resolveSelfFileLinkingForBaseAndIdentityref();
return;
- } else {
-
- YangType type = null;
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- type = (YangType) getCurrentEntityToResolveFromStack();
- }
-
- /**
+ }
+ YangType type = null;
+ if (entity instanceof YangType) {
+ type = (YangType) entity;
+ }
+ /*
* Traverse up in the ancestor tree to check if the referred node is
* defined
*/
- while (potentialAncestorWithReferredNode != null) {
-
- /**
+ while (ancestorRefNode != null) {
+ /*
* Check for the referred node defined in a ancestor scope
*/
- YangNode potentialReferredNode = potentialAncestorWithReferredNode.getChild();
- if (isReferredNodeInSiblingListProcessed(potentialReferredNode)) {
- return;
- }
-
- potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
-
- if (type != null && potentialAncestorWithReferredNode != null) {
- if (potentialAncestorWithReferredNode.getParent() == null) {
- type.setTypeNotResolvedTillRootNode(true);
- }
+ YangNode curRefNode = ancestorRefNode.getChild();
+ if (isReferredNodeInSiblingListProcessed(curRefNode)) {
+ return;
+ }
+ ancestorRefNode = ancestorRefNode.getParent();
+ if (type != null && ancestorRefNode != null) {
+ if (ancestorRefNode.getParent() == null) {
+ type.setTypeNotResolvedTillRootNode(true);
}
}
}
@@ -478,8 +458,9 @@
* In case prefix is not present or it's self prefix it's a candidate for inter-file
* resolution via include list.
*/
- if (getRefPrefix() == null || getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ if (getRefPrefix() == null ||
+ getRefPrefix().contentEquals(curRefResolver.getPrefix())) {
+ ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
}
}
@@ -491,28 +472,19 @@
private void resolveSelfFileLinkingForBaseAndIdentityref()
throws DataModelException {
- boolean referredIdentityFound = false;
+ boolean refIdentity = false;
String nodeName = null;
-
- if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- nodeName = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName();
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangIdentityRef) {
+ nodeName = ((YangIdentityRef) entity).getName();
+ } else if (entity instanceof YangBase) {
+ nodeName = ((YangBase) entity).getBaseIdentifier().getName();
}
-
- if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- nodeName = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName();
- }
-
- if (getCurReferenceResolver() instanceof YangModule) {
- YangModule rootNode = (YangModule) getCurReferenceResolver();
+ if (curRefResolver instanceof RpcNotificationContainer) {
// Sends list of nodes for finding the target identity.
- referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
- } else if (getCurReferenceResolver() instanceof YangSubModule) {
- YangSubModule rootNode = (YangSubModule) getCurReferenceResolver();
- // Sends list of nodes for finding the target identity.
- referredIdentityFound = isIdentityReferenceFound(nodeName, rootNode);
+ refIdentity = isIdentityReferenceFound(nodeName, (YangNode) curRefResolver);
}
-
- if (referredIdentityFound) {
+ if (refIdentity) {
return;
}
@@ -520,59 +492,34 @@
* In case prefix is not present or it's self prefix it's a candidate for inter-file
* resolution via include list.
*/
- if (getRefPrefix() == null || getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ if (getRefPrefix() == null || getRefPrefix()
+ .contentEquals(curRefResolver.getPrefix())) {
+ ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
}
}
/**
- * Returns the root parent with respect to the ancestor count from leafref.
- *
- * @param ancestorCount count of node where parent node can be reached
- * @param currentParent current parent node
- * @return root node
- * @throws DataModelException a violation of data model rules
- */
- private YangNode getRootNodeWithAncestorCount(int ancestorCount, YangNode currentParent)
- throws DataModelException {
-
- int currentParentCount = 1;
- while (currentParentCount < ancestorCount) {
- if (currentParent.getParent() == null) {
- throw new DataModelException("YANG file error: The target node of leafref is invalid."
- + currentParent.getName() + " in " +
- currentParent.getLineNumber() + " at " +
- currentParent.getCharPosition()
- + " in " + currentParent.getFileName() + "\"");
- }
- currentParent = currentParent.getParent();
- currentParentCount = currentParentCount + 1;
- }
- return currentParent;
- }
-
- /**
* Resolves self file linking for if-feature.
*
- * @param potentialAncestorWithReferredNode if-feature holder node
+ * @param ancestorRefNode if-feature holder node
* @throws DataModelException DataModelException a violation of data model
* rules
*/
- private void resolveSelfFileLinkingForIfFeature(YangNode potentialAncestorWithReferredNode)
+ private void resolveSelfFileLinkingForIfFeature(YangNode ancestorRefNode)
throws DataModelException {
- YangFeatureHolder featureHolder = getFeatureHolder(potentialAncestorWithReferredNode);
- YangNode potentialReferredNode = (YangNode) featureHolder;
- if (isReferredNode(potentialReferredNode)) {
+ YangFeatureHolder featureHolder = getFeatureHolder(ancestorRefNode);
+ YangNode curRefNode = (YangNode) featureHolder;
+ if (isReferredNode(curRefNode)) {
// Adds reference link of entity to the node under resolution.
- addReferredEntityLink(potentialReferredNode, LINKED);
+ addReferredEntityLink(curRefNode, LINKED);
- /**
+ /*
* resolve the reference and update the partial resolution stack
* with any further recursive references
*/
- addUnresolvedRecursiveReferenceToStack(potentialReferredNode);
+ addUnresolvedRecursiveReferenceToStack(curRefNode);
return;
}
@@ -580,37 +527,41 @@
* In case prefix is not present or it's self prefix it's a candidate for inter-file
* resolution via include list.
*/
- if (getRefPrefix() == null || getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
+ if (getRefPrefix() == null || getRefPrefix()
+ .contentEquals(curRefResolver.getPrefix())) {
+ ((Resolvable) getCurEntityToResolveFromStack())
+ .setResolvableStatus(INTRA_FILE_RESOLVED);
}
}
/**
* Returns the status of the referred identity found for base/identityref.
*
- * @param nodeName the name of the base nodeidentifier/identityref nodeidentifier
- * @param ancestorWithTheReferredNode the parent node of base/identityref
+ * @param nodeName the name of the base node
+ * identifier/identityref node identifier
+ * @param ancestorRefNode the parent node of base/identityref
* @return status of referred base/identityref
* @throws DataModelException a violation of data model rules
*/
- private boolean isIdentityReferenceFound(String nodeName, YangNode ancestorWithTheReferredNode)
+ private boolean isIdentityReferenceFound(String nodeName, YangNode ancestorRefNode)
throws DataModelException {
// When child is not present return.
- if (ancestorWithTheReferredNode.getChild() == null) {
+ if (ancestorRefNode.getChild() == null) {
return false;
}
- ancestorWithTheReferredNode = ancestorWithTheReferredNode.getChild();
+ ancestorRefNode = ancestorRefNode.getChild();
// Checks all the siblings under the node and returns the matched node.
- YangNode nodeFound = isReferredNodeInSiblingProcessedForIdentity(ancestorWithTheReferredNode, nodeName);
+ YangNode nodeFound = isReferredNodeInSiblingProcessedForIdentity(ancestorRefNode,
+ nodeName);
if (nodeFound != null) {
// Adds reference link of entity to the node under resolution.
addReferredEntityLink(nodeFound, LINKED);
- /**
+ /*
* resolve the reference and update the partial resolution stack with any further recursive references
*/
addUnresolvedRecursiveReferenceToStack(nodeFound);
@@ -623,55 +574,53 @@
/**
* Adds the unresolved constructs to stack which has to be resolved for leafref.
*
- * @param yangleafOrLeafList YANG leaf or leaf list which holds the type
- * @param ancestorWithTheReferredNode holder of the YANG leaf or leaf list
+ * @param leavesInfo YANG leaf or leaf list which holds the type
+ * @param ancestorRefNode holder of the YANG leaf or leaf list
*/
- private void addUnResolvedLeafRefTypeToStack(T yangleafOrLeafList, YangNode ancestorWithTheReferredNode) {
+ private void addUnResolvedLeafRefTypeToStack(T leavesInfo, YangNode ancestorRefNode) {
- YangType referredTypeInLeafOrLeafList;
- if (yangleafOrLeafList instanceof YangLeaf) {
- YangLeaf leaf = (YangLeaf) yangleafOrLeafList;
- referredTypeInLeafOrLeafList = leaf.getDataType();
- if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.LEAFREF) {
- YangEntityToResolveInfoImpl<YangLeafRef<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve((YangLeafRef<?>) leaf.getDataType().getDataTypeExtendedInfo());
- unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
- } else if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.DERIVED) {
- YangEntityToResolveInfoImpl<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve(referredTypeInLeafOrLeafList);
- unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
- }
+ YangType refType;
+ T extendedInfo;
+ if (leavesInfo instanceof YangLeaf) {
+ YangLeaf leaf = (YangLeaf) leavesInfo;
+ refType = leaf.getDataType();
} else {
- YangLeafList leafList = (YangLeafList) yangleafOrLeafList;
- referredTypeInLeafOrLeafList = leafList.getDataType();
- if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.LEAFREF) {
- YangEntityToResolveInfoImpl<YangLeafRef<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo
- .setEntityToResolve((YangLeafRef<?>) leafList.getDataType().getDataTypeExtendedInfo());
- unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
- } else if (referredTypeInLeafOrLeafList.getDataType() == YangDataTypes.DERIVED) {
- YangEntityToResolveInfoImpl<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve(referredTypeInLeafOrLeafList);
- unResolvedEntityInfo.setHolderOfEntityToResolve(ancestorWithTheReferredNode);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
- }
+ YangLeafList leafList = (YangLeafList) leavesInfo;
+ refType = leafList.getDataType();
+ }
+ extendedInfo = (T) refType.getDataTypeExtendedInfo();
+ addUnResolvedTypeDataToStack(refType, ancestorRefNode, extendedInfo);
+ }
+
+ //Adds unresolved type info to stack.
+ private void addUnResolvedTypeDataToStack(YangType refType, YangNode
+ ancestorRefNode, T extendedInfo) {
+ YangEntityToResolveInfoImpl<YangLeafRef<?>> unResolvedLeafRef =
+ new YangEntityToResolveInfoImpl<>();
+ YangEntityToResolveInfoImpl<YangType<?>> unResolvedTypeDef =
+ new YangEntityToResolveInfoImpl<>();
+ if (refType.getDataType() == YangDataTypes.LEAFREF) {
+ unResolvedLeafRef.setEntityToResolve((YangLeafRef<?>) extendedInfo);
+ unResolvedLeafRef.setHolderOfEntityToResolve(ancestorRefNode);
+ addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedLeafRef);
+ } else if (refType.getDataType() == YangDataTypes.DERIVED) {
+ unResolvedTypeDef.setEntityToResolve(refType);
+ unResolvedTypeDef.setHolderOfEntityToResolve(ancestorRefNode);
+ addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedTypeDef);
}
}
/**
* Returns feature holder(module/sub-module node) .
*
- * @param potentialAncestorWithReferredNode if-feature holder node
+ * @param ancestorRefNode if-feature holder node
*/
- private YangFeatureHolder getFeatureHolder(YangNode potentialAncestorWithReferredNode) {
- while (potentialAncestorWithReferredNode != null) {
- if (potentialAncestorWithReferredNode instanceof YangFeatureHolder) {
- return (YangFeatureHolder) potentialAncestorWithReferredNode;
+ private YangFeatureHolder getFeatureHolder(YangNode ancestorRefNode) {
+ while (ancestorRefNode != null) {
+ if (ancestorRefNode instanceof YangFeatureHolder) {
+ return (YangFeatureHolder) ancestorRefNode;
}
- potentialAncestorWithReferredNode = potentialAncestorWithReferredNode.getParent();
+ ancestorRefNode = ancestorRefNode.getParent();
}
return null;
}
@@ -685,146 +634,77 @@
private boolean isCandidateForSelfFileReference()
throws DataModelException {
String prefix = getRefPrefix();
- return prefix == null || prefix.contentEquals(getCurReferenceResolver().getPrefix());
- }
-
- /**
- * Checks for the referred parent node for the leafref path.
- *
- * @param potentialReferredNode potential referred node
- * @return the reffered parent node of leaf/leaf-list
- * @throws DataModelException data model errors
- */
- private YangNode isReferredNodeInSiblingProcessedForLeafref(YangNode potentialReferredNode, String referredNodeName)
- throws DataModelException {
-
- while (potentialReferredNode != null) {
- if (potentialReferredNode instanceof YangInput) {
- if (referredNodeName.equalsIgnoreCase(INPUT)) {
- return potentialReferredNode;
- }
- } else if (potentialReferredNode instanceof YangOutput) {
- if (referredNodeName.equalsIgnoreCase(OUTPUT)) {
- return potentialReferredNode;
- }
- }
- // Check if the potential referred node is the actual referred node
- if (isReferredNodeForLeafref(potentialReferredNode, referredNodeName)) {
- if (potentialReferredNode instanceof YangGrouping || potentialReferredNode instanceof YangTypeDef) {
- if (potentialReferredNode.getParent() instanceof YangRpc) {
- potentialReferredNode = potentialReferredNode.getNextSibling();
- } else {
- throw new DataModelException("YANG file error: The target node of leafref is invalid. "
- + potentialReferredNode.getName() + " in " +
- potentialReferredNode.getLineNumber() + " at " +
- potentialReferredNode.getCharPosition()
- + " in " + potentialReferredNode.getFileName() + "\"");
- }
- }
- return potentialReferredNode;
- }
- potentialReferredNode = potentialReferredNode.getNextSibling();
- }
- return null;
+ return prefix == null || prefix.contentEquals(curRefResolver.getPrefix());
}
/**
* Checks for the referred parent node for the base/identity.
*
- * @param potentialReferredNode potential referred node
- * @return the reffered parent node of base/identity.
+ * @param refNode potential referred node
+ * @return the referred parent node of base/identity.
* @throws DataModelException data model errors
*/
- private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode potentialReferredNode,
- String referredNodeName)
+ private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode refNode,
+ String refName)
throws DataModelException {
- while (potentialReferredNode != null) {
- if (potentialReferredNode instanceof YangIdentity) {
+ while (refNode != null) {
+ if (refNode instanceof YangIdentity) {
// Check if the potential referred node is the actual referred node
- if (isReferredNodeForIdentity(potentialReferredNode, referredNodeName)) {
- return potentialReferredNode;
+ if (isReferredNodeForIdentity(refNode, refName)) {
+ return refNode;
}
}
- potentialReferredNode = potentialReferredNode.getNextSibling();
+ refNode = refNode.getNextSibling();
}
return null;
}
/**
- * Checks if the current reference node name and the name in the path are equal.
- *
- * @param currentReferredNode the node where the reference is pointed
- * @param nameOfNodeinPath name of the node in the path
- * @return status of the match between the name
- * @throws DataModelException a violation of data model rules
- */
- private boolean isReferredNodeForLeafref(YangNode currentReferredNode, String nameOfNodeinPath)
- throws DataModelException {
-
- if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
- /*
- * Check if name of node name matches with the current reference
- * node.
- */
- return currentReferredNode.getName().contentEquals(nameOfNodeinPath);
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than leafref "
- + currentReferredNode.getName() + " in " +
- currentReferredNode.getLineNumber() + " at " +
- currentReferredNode.getCharPosition()
- + " in " + currentReferredNode.getFileName() + "\"");
- }
- }
-
- /**
* Checks if the current reference node name and the name in the base/identityref base are equal.
*
- * @param currentReferredNode the node where the reference is pointed
- * @param nameOfIdentityRefBase name of the base in the base/identityref base
+ * @param curRefNode the node where the reference is pointed
+ * @param name name of the base in the base/identityref base
* @return status of the match between the name
* @throws DataModelException a violation of data model rules
*/
- private boolean isReferredNodeForIdentity(YangNode currentReferredNode, String nameOfIdentityRefBase)
+ private boolean isReferredNodeForIdentity(YangNode curRefNode, String name)
throws DataModelException {
-
- if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
- (getCurrentEntityToResolveFromStack() instanceof YangBase)) {
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangIdentityRef || entity instanceof YangBase) {
//Check if name of node name matches with the current reference node.
- return currentReferredNode.getName().contentEquals(nameOfIdentityRefBase);
+ return curRefNode.getName().contentEquals(name);
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than identityref"
- + currentReferredNode.getName() + " in " +
- currentReferredNode.getLineNumber() + " at " +
- currentReferredNode.getCharPosition()
- + " in " + currentReferredNode.getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ INVALID_ENTITY, curRefNode.getName(), curRefNode.getLineNumber(),
+ curRefNode.getCharPosition(), curRefNode.getFileName()));
}
}
/**
* Checks for the referred node defined in a ancestor scope.
*
- * @param potentialReferredNode potential referred node
+ * @param refNode potential referred node
* @return status of resolution and updating the partial resolved stack with
* the any recursive references
* @throws DataModelException a violation of data model rules
*/
- private boolean isReferredNodeInSiblingListProcessed(YangNode potentialReferredNode)
+ private boolean isReferredNodeInSiblingListProcessed(YangNode refNode)
throws DataModelException {
- while (potentialReferredNode != null) {
+ while (refNode != null) {
// Check if the potential referred node is the actual referred node
- if (isReferredNode(potentialReferredNode)) {
+ if (isReferredNode(refNode)) {
// Adds reference link of entity to the node under resolution.
- addReferredEntityLink(potentialReferredNode, LINKED);
+ addReferredEntityLink(refNode, LINKED);
- /**
+ /*
* resolve the reference and update the partial resolution stack
* with any further recursive references
*/
- addUnresolvedRecursiveReferenceToStack(potentialReferredNode);
+ addUnresolvedRecursiveReferenceToStack(refNode);
/*
* return true, since the reference is linked and any recursive
@@ -833,7 +713,7 @@
return true;
}
- potentialReferredNode = potentialReferredNode.getNextSibling();
+ refNode = refNode.getNextSibling();
}
return false;
}
@@ -841,52 +721,33 @@
/**
* Checks if the potential referred node is the actual referred node.
*
- * @param potentialReferredNode typedef/grouping node
+ * @param refNode typedef/grouping node
* @return true if node is of resolve type otherwise false
* @throws DataModelException a violation of data model rules
*/
- private boolean isReferredNode(YangNode potentialReferredNode)
+ private boolean isReferredNode(YangNode refNode)
throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- if (potentialReferredNode instanceof YangTypeDef) {
- /*
- * Check if name of node name matches with the entity being
- * resolved
- */
- return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangType) {
+ if (refNode instanceof YangTypeDef) {
+ return isNodeNameSameAsResolutionInfoName(refNode);
}
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- if (potentialReferredNode instanceof YangGrouping) {
- /*
- * Check if name of node name matches with the entity being
- * resolved
- */
- return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
+ } else if (entity instanceof YangUses) {
+ if (refNode instanceof YangGrouping) {
+ return isNodeNameSameAsResolutionInfoName(refNode);
}
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- if (potentialReferredNode instanceof YangFeatureHolder) {
- /*
- * Check if name of node name matches with the entity being
- * resolved
- */
- return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
+ } else if (entity instanceof YangIfFeature) {
+ if (refNode instanceof YangFeatureHolder) {
+ return isNodeNameSameAsResolutionInfoName(refNode);
}
- } else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
- (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
- if (potentialReferredNode instanceof YangIdentity) {
- /*
- * Check if name of node name matches with the entity being
- * resolved
- */
- return isNodeNameSameAsResolutionInfoName(potentialReferredNode);
+ } else if (entity instanceof YangBase || entity instanceof YangIdentityRef) {
+ if (refNode instanceof YangIdentity) {
+ return isNodeNameSameAsResolutionInfoName(refNode);
}
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/" +
- "uses/base/identityref"
- + potentialReferredNode.getName() + " in " +
- potentialReferredNode.getLineNumber() + " at " +
- potentialReferredNode.getCharPosition()
- + " in " + potentialReferredNode.getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ LINKER_ERROR, refNode.getName(), refNode.getLineNumber(),
+ refNode.getCharPosition(), refNode.getFileName()));
}
return false;
}
@@ -903,50 +764,40 @@
private boolean isNodeNameSameAsResolutionInfoName(YangNode node)
throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- if (node.getName().contentEquals(
- ((YangType<?>) getCurrentEntityToResolveFromStack())
- .getDataTypeName())) {
- return true;
- }
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- if (node.getName().contentEquals(
- ((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
- return true;
- }
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- return isFeatureDefinedInNode(node);
- } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- if (node.getName().contentEquals(
- ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
- return true;
- }
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- if (node.getName().contentEquals(
- ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getName())) {
- return true;
- }
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses "
- + node.getName() + " in " +
- node.getLineNumber() + " at " +
- node.getCharPosition()
- + " in " + node.getFileName() + "\"");
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangType) {
+ return node.getName().contentEquals(((YangType<?>) entity)
+ .getDataTypeName());
}
- return false;
+ if (entity instanceof YangUses) {
+ return node.getName().contentEquals(((YangUses) entity).getName());
+ }
+ if (entity instanceof YangIfFeature) {
+ return isFeatureDefinedInNode(node);
+ }
+ if (entity instanceof YangBase) {
+ return node.getName().contentEquals(((
+ YangBase) entity).getBaseIdentifier().getName());
+ }
+ if (entity instanceof YangIdentityRef) {
+ return node.getName().contentEquals(((YangIdentityRef) entity).getName());
+ }
+ throw new DataModelException(getErrorMsg(
+ INVALID_RESOLVED_ENTITY, node.getName(), node.getLineNumber(),
+ node.getCharPosition(), node.getFileName()));
}
- private boolean isFeatureDefinedInNode(YangNode node)
- throws DataModelException {
- YangNodeIdentifier ifFeature = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getName();
+ private boolean isFeatureDefinedInNode(YangNode node) {
+ T entity = getCurEntityToResolveFromStack();
+ YangNodeIdentifier ifFeature = ((YangIfFeature) entity).getName();
List<YangFeature> featureList = ((YangFeatureHolder) node).getFeatureList();
if (featureList != null && !featureList.isEmpty()) {
Iterator<YangFeature> iterator = featureList.iterator();
while (iterator.hasNext()) {
YangFeature feature = iterator.next();
if (ifFeature.getName().equals(feature.getName())) {
- ((YangIfFeature) getCurrentEntityToResolveFromStack()).setReferredFeature(feature);
- ((YangIfFeature) getCurrentEntityToResolveFromStack()).setReferredFeatureHolder(node);
+ ((YangIfFeature) entity).setReferredFeature(feature);
+ ((YangIfFeature) entity).setReferredFeatureHolder(node);
return true;
}
}
@@ -957,38 +808,31 @@
/**
* Adds reference of grouping/typedef in uses/type.
*
- * @param referredNode grouping/typedef node being referred
+ * @param refNode grouping/typedef node being referred
* @param linkedStatus linked status if success.
* @throws DataModelException a violation of data model rules
*/
- private void addReferredEntityLink(YangNode referredNode, ResolvableStatus linkedStatus)
+ private void addReferredEntityLink(YangNode refNode, ResolvableStatus linkedStatus)
throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) ((YangType<?>) getCurrentEntityToResolveFromStack())
- .getDataTypeExtendedInfo();
- derivedInfo.setReferredTypeDef((YangTypeDef) referredNode);
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- ((YangUses) getCurrentEntityToResolveFromStack())
- .setRefGroup((YangGrouping) referredNode);
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- // do nothing , referred node is already set
- } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
- // do nothing , referred node is already set
- } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- ((YangBase) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- ((YangIdentityRef) getCurrentEntityToResolveFromStack()).setReferredIdentity((YangIdentity) referredNode);
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
- "/uses/base/identityref"
- + referredNode.getName() + " in " +
- referredNode.getLineNumber() + " at " +
- referredNode.getCharPosition()
- + " in " + referredNode.getFileName() + "\"");
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangType) {
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) ((
+ YangType<?>) entity).getDataTypeExtendedInfo();
+ derivedInfo.setReferredTypeDef((YangTypeDef) refNode);
+ } else if (entity instanceof YangUses) {
+ ((YangUses) entity).setRefGroup((YangGrouping) refNode);
+ } else if (entity instanceof YangBase) {
+ ((YangBase) entity).setReferredIdentity((YangIdentity) refNode);
+ } else if (entity instanceof YangIdentityRef) {
+ ((YangIdentityRef) entity).setReferredIdentity((YangIdentity) refNode);
+ } else if (!(entity instanceof YangIfFeature) &&
+ !(entity instanceof YangLeafRef)) {
+ throw new DataModelException(getErrorMsg(
+ LINKER_ERROR, refNode.getName(), refNode.getLineNumber(),
+ refNode.getCharPosition(), refNode.getFileName()));
}
-
// Sets the resolution status in inside the type/uses.
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(linkedStatus);
+ ((Resolvable) entity).setResolvableStatus(linkedStatus);
}
/**
@@ -996,49 +840,41 @@
* uses. Add it to the partial resolve stack and return the status of
* addition to stack.
*
- * @param referredNode grouping/typedef node
+ * @param refNode grouping/typedef node
* @throws DataModelException a violation of data model rules
*/
- private void addUnresolvedRecursiveReferenceToStack(YangNode referredNode)
+ private void addUnresolvedRecursiveReferenceToStack(YangNode refNode)
throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangType) {
//Checks if typedef type is derived
- if (((YangTypeDef) referredNode).getTypeDefBaseType().getDataType() == YangDataTypes.DERIVED) {
-
- YangEntityToResolveInfoImpl<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve(((YangTypeDef) referredNode)
- .getTypeDefBaseType());
- unResolvedEntityInfo.setHolderOfEntityToResolve(referredNode);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
+ if (((YangTypeDef) refNode).getTypeDefBaseType()
+ .getDataType() == YangDataTypes.DERIVED) {
+ addEntityToStack((T) ((YangTypeDef) refNode).getTypeDefBaseType(),
+ refNode);
}
-
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
+ } else if (entity instanceof YangUses) {
/*
* Search if the grouping has any un resolved uses child, if so
* return true, else return false.
*/
- addUnResolvedUsesToStack(referredNode);
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- addUnResolvedIfFeatureToStack(referredNode);
- } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
+ addUnResolvedUsesToStack(refNode);
+ } else if (entity instanceof YangIfFeature) {
+ addUnResolvedIfFeatureToStack(refNode);
+ } else if (entity instanceof YangLeafRef) {
// do nothing , referred node is already set
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses "
- + referredNode.getName() + " in " +
- referredNode.getLineNumber() + " at " +
- referredNode.getCharPosition()
- + " in " + referredNode.getFileName() + "\"");
- } else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
- (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
+ throw new DataModelException(getErrorMsg(
+ INVALID_RESOLVED_ENTITY, refNode.getName(), refNode.getLineNumber(),
+ refNode.getCharPosition(), refNode.getFileName()));
+ } else if (entity instanceof YangBase || entity instanceof YangIdentityRef) {
//Search if the identity has any un resolved base, if so return true, else return false.
- addUnResolvedBaseToStack(referredNode);
+ addUnResolvedBaseToStack(refNode);
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses/" +
- "base/identityref " + referredNode.getName() + " in " +
- referredNode.getLineNumber() + " at " +
- referredNode.getCharPosition()
- + " in " + referredNode.getFileName() + "\"");
+ throw new DataModelException(getErrorMsg(
+ LINKER_ERROR, refNode.getName(), refNode.getLineNumber(),
+ refNode.getCharPosition(), refNode.getFileName()));
}
}
@@ -1061,10 +897,7 @@
// if child nodes has uses, then add it to resolution stack
if (curNode instanceof YangUses) {
- YangEntityToResolveInfoImpl<YangUses> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve((YangUses) curNode);
- unResolvedEntityInfo.setHolderOfEntityToResolve(node);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
+ addEntityToStack((T) curNode, node);
}
// Traversing all the child nodes of grouping
@@ -1087,16 +920,13 @@
* @param node module/submodule node
*/
private void addUnResolvedIfFeatureToStack(YangNode node) {
- YangFeature refFeature = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeature();
+ YangFeature refFeature = ((YangIfFeature) getCurEntityToResolveFromStack())
+ .getReferredFeature();
List<YangIfFeature> ifFeatureList = refFeature.getIfFeatureList();
if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
while (ifFeatureIterator.hasNext()) {
- YangIfFeature ifFeature = ifFeatureIterator.next();
- YangEntityToResolveInfo<YangIfFeature> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve(ifFeature);
- unResolvedEntityInfo.setHolderOfEntityToResolve(node);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
+ addEntityToStack((T) ifFeatureIterator.next(), node);
}
}
}
@@ -1111,33 +941,17 @@
YangIdentity curNode = (YangIdentity) node;
if (curNode.getBaseNode() != null) {
if (curNode.getBaseNode().getResolvableStatus() != RESOLVED) {
- YangEntityToResolveInfoImpl<YangBase> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve(curNode.getBaseNode());
- unResolvedEntityInfo.setHolderOfEntityToResolve(node);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedEntityInfo);
-
+ addEntityToStack((T) curNode.getBaseNode(), node);
}
}
}
-
- /**
- * Returns stack of YANG type with partially resolved YANG construct
- * hierarchy.
- *
- * @return partial resolved YANG construct stack
- */
- private Stack<YangEntityToResolveInfoImpl<T>> getPartialResolvedStack() {
- return partialResolvedStack;
- }
-
- /**
- * Sets stack of YANG type with partially resolved YANG construct hierarchy.
- *
- * @param partialResolvedStack partial resolved YANG construct stack
- */
- private void setPartialResolvedStack(Stack<YangEntityToResolveInfoImpl<T>> partialResolvedStack) {
- this.partialResolvedStack = partialResolvedStack;
+ private void addEntityToStack(T entity, YangNode holder) {
+ YangEntityToResolveInfoImpl<T> unResolvedEntityInfo =
+ new YangEntityToResolveInfoImpl<>();
+ unResolvedEntityInfo.setEntityToResolve(entity);
+ unResolvedEntityInfo.setHolderOfEntityToResolve(holder);
+ addInPartialResolvedStack(unResolvedEntityInfo);
}
/**
@@ -1146,7 +960,7 @@
* @param partialResolvedInfo partial resolved YANG construct stack
*/
private void addInPartialResolvedStack(YangEntityToResolveInfoImpl<T> partialResolvedInfo) {
- getPartialResolvedStack().push(partialResolvedInfo);
+ partialResolvedStack.push(partialResolvedInfo);
}
/**
@@ -1155,8 +969,8 @@
*
* @return next entity in the stack that needs to be resolved
*/
- private T getCurrentEntityToResolveFromStack() {
- return getPartialResolvedStack().peek().getEntityToResolve();
+ private T getCurEntityToResolveFromStack() {
+ return partialResolvedStack.peek().getEntityToResolve();
}
@Override
@@ -1164,44 +978,14 @@
return entityToResolveInfo;
}
- /**
- * Sets information about the entity that needs to be resolved.
- *
- * @param entityToResolveInfo information about the entity that needs to be
- * resolved
- */
- private void setEntityToResolveInfo(YangEntityToResolveInfoImpl<T> entityToResolveInfo) {
- this.entityToResolveInfo = entityToResolveInfo;
- }
-
- /**
- * Returns current module/sub-module reference, will be used in inter-file/
- * inter-jar scenario to get the import/include list.
- *
- * @return current module/sub-module reference
- */
- private YangReferenceResolver getCurReferenceResolver() {
- return curReferenceResolver;
- }
-
- /**
- * Sets current module/sub-module reference, will be used in inter-file/
- * inter-jar scenario to get the import/include list.
- *
- * @param curReferenceResolver current module/sub-module reference
- */
- private void setCurReferenceResolver(YangReferenceResolver curReferenceResolver) {
- this.curReferenceResolver = curReferenceResolver;
- }
-
@Override
public void linkInterFile(YangReferenceResolver dataModelRootNode)
throws DataModelException {
- setCurReferenceResolver(dataModelRootNode);
+ curRefResolver = dataModelRootNode;
// Current node to resolve, it can be a YANG type or YANG uses.
- T entityToResolve = getEntityToResolveInfo().getEntityToResolve();
+ T entityToResolve = entityToResolveInfo.getEntityToResolve();
// Check if linking is already done
if (entityToResolve instanceof Resolvable) {
@@ -1210,21 +994,19 @@
return;
}
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is not Resolvable");
+ throw new DataModelException(UNRESOLVABLE);
}
- if (entityToResolve instanceof YangXPathResolver && !(entityToResolve instanceof YangLeafRef)) {
+ if (entityToResolve instanceof YangXPathResolver &&
+ !(entityToResolve instanceof YangLeafRef)) {
//Process x-path linking.
processXPathLinking(entityToResolve, dataModelRootNode);
} else {
-
// Push the initial entity to resolve in stack.
- addInPartialResolvedStack(getEntityToResolveInfo());
-
+ addInPartialResolvedStack(entityToResolveInfo);
// Inter file linking and resolution.
linkInterFileAndResolve();
-
addDerivedRefTypeToRefTypeResolutionList();
}
}
@@ -1241,10 +1023,10 @@
YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
if (entityToResolve instanceof YangAugment) {
- YangNode targetNode = null;
+ YangNode targetNode;
YangAugment augment = (YangAugment) entityToResolve;
- targetNode = xPathLinker.processAugmentXpathLinking(augment.getTargetNode(),
- (YangNode) root);
+ targetNode = xPathLinker
+ .processAugmentXpathLinking(augment.getTargetNode(), (YangNode) root);
if (targetNode != null) {
if (targetNode instanceof YangAugmentableNode) {
detectCollisionForAugmentedNode(targetNode, augment);
@@ -1253,25 +1035,26 @@
setAugmentedFlagInAncestors(targetNode);
Resolvable resolvable = (Resolvable) entityToResolve;
resolvable.setResolvableStatus(RESOLVED);
+ if (targetNode instanceof YangInput) {
+ xPathLinker.addInModuleIfInput(augment, (YangNode) root);
+ }
} else {
- throw new LinkerException("Invalid target node type " + targetNode.getNodeType() + " for "
- + augment.getName() + " for " + targetNode.getName() +
- " in " + targetNode.getLineNumber()
- + " at " + targetNode.getCharPosition() +
- " in " + targetNode.getFileName());
+ throw new LinkerException(getErrorMsg(
+ INVALID_TARGET + targetNode.getNodeType(),
+ augment.getName(), augment.getLineNumber(),
+ augment.getCharPosition(), augment.getFileName()));
}
} else {
- throw new LinkerException("Failed to link " + augment.getName() +
- " in " + augment.getLineNumber()
- + " at " + augment.getCharPosition() +
- " in " + augment.getFileName());
+ throw new LinkerException(getErrorMsg(
+ FAILED_TO_LINK, augment.getName(), augment
+ .getLineNumber(), augment.getCharPosition(),
+ augment.getFileName()));
}
} else if (entityToResolve instanceof YangCompilerAnnotation) {
YangNode targetNode;
YangCompilerAnnotation ca = (YangCompilerAnnotation) entityToResolve;
-
targetNode = xPathLinker.processAugmentXpathLinking(ca.getAtomicPathList(),
- (YangNode) root);
+ (YangNode) root);
if (targetNode != null) {
if (targetNode instanceof YangList) {
((YangList) targetNode).setCompilerAnnotation(
@@ -1279,19 +1062,19 @@
Resolvable resolvable = (Resolvable) entityToResolve;
resolvable.setResolvableStatus(RESOLVED);
} else {
- throw new LinkerException("Invalid target node type " + targetNode.getNodeType() + " for compiler" +
- " annotation " + ca.getPath() + " in " + ca.getLineNumber() + " at "
- + ca.getCharPosition() + " in " + ca.getFileName());
+ throw new LinkerException(getErrorMsg(
+ INVALID_TARGET + targetNode.getNodeType(), ca.getPath(),
+ ca.getLineNumber(), ca.getCharPosition(), ca.getFileName()));
}
} else {
- throw new LinkerException("Failed to link compiler annotation " + ca.getPath()
- + " in " + ca.getLineNumber() + " at "
- + ca.getCharPosition() + " in " + ca.getFileName());
+ throw new LinkerException(getErrorMsg(
+ FAILED_TO_FIND_ANNOTATION, ca.getPath(), ca.getLineNumber(),
+ ca.getCharPosition(), ca.getFileName()));
}
} else if (entityToResolve instanceof YangLeafRef) {
YangLeafRef leafRef = (YangLeafRef) entityToResolve;
- Object target = xPathLinker.processLeafRefXpathLinking(leafRef.getAtomicPath(),
- (YangNode) root, leafRef);
+ Object target = xPathLinker.processLeafRefXpathLinking(
+ leafRef.getAtomicPath(), (YangNode) root, leafRef);
if (target != null) {
YangLeaf leaf;
YangLeafList leafList;
@@ -1299,22 +1082,22 @@
if (target instanceof YangLeaf) {
leaf = (YangLeaf) target;
leafRef.setResolvableStatus(INTER_FILE_LINKED);
- addUnResolvedLeafRefTypeToStack((T) leaf, getEntityToResolveInfo().getHolderOfEntityToResolve());
+ addUnResolvedLeafRefTypeToStack((T) leaf, entityToResolveInfo
+ .getHolderOfEntityToResolve());
} else {
leafList = (YangLeafList) target;
leafRef.setResolvableStatus(INTER_FILE_LINKED);
- addUnResolvedLeafRefTypeToStack((T) leafList,
- getEntityToResolveInfo().getHolderOfEntityToResolve());
+ addUnResolvedLeafRefTypeToStack(
+ (T) leafList, entityToResolveInfo.getHolderOfEntityToResolve());
}
//TODO: add logic for leaf-ref for path predicates.
} else {
- LinkerException linkerException = new LinkerException("YANG file error: Unable to find base " +
- "leaf/leaf-list for given leafref path "
- + leafRef.getPath());
- linkerException.setCharPosition(leafRef.getCharPosition());
- linkerException.setLine(leafRef.getLineNumber());
- linkerException.setFileName(leafRef.getFileName());
- throw linkerException;
+ LinkerException ex = new LinkerException(
+ FAILED_TO_FIND_LEAD_INFO_HOLDER + leafRef.getPath());
+ ex.setCharPosition(leafRef.getCharPosition());
+ ex.setLine(leafRef.getLineNumber());
+ ex.setFileName(leafRef.getFileName());
+ throw ex;
}
}
}
@@ -1327,22 +1110,24 @@
*/
private String getRefPrefix()
throws DataModelException {
- String refPrefix;
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- refPrefix = ((YangType<?>) getCurrentEntityToResolveFromStack()).getPrefix();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- refPrefix = ((YangUses) getCurrentEntityToResolveFromStack()).getPrefix();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- refPrefix = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getPrefix();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- refPrefix = ((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getPrefix();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- refPrefix = ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getPrefix();
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than " +
- "type/uses/base/identityref");
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangType) {
+ return ((YangType<?>) entity).getPrefix();
}
- return refPrefix;
+ if (entity instanceof YangUses) {
+ return ((YangUses) entity).getPrefix();
+ }
+ if (entity instanceof YangIfFeature) {
+ return ((YangIfFeature) entity).getPrefix();
+ }
+ if (entity instanceof YangBase) {
+ return ((YangBase) entity).getBaseIdentifier()
+ .getPrefix();
+ }
+ if (entity instanceof YangIdentityRef) {
+ return ((YangIdentityRef) entity).getPrefix();
+ }
+ throw new DataModelException(LINKER_ERROR);
}
/**
@@ -1353,37 +1138,35 @@
private void linkInterFileAndResolve()
throws DataModelException {
- while (getPartialResolvedStack().size() != 0) {
+ while (!partialResolvedStack.isEmpty()) {
// Current node to resolve, it can be a YANG type or YANG uses.
- T entityToResolve = getCurrentEntityToResolveFromStack();
+ T entityToResolve = getCurEntityToResolveFromStack();
// Check if linking is already done
if (entityToResolve instanceof Resolvable) {
Resolvable resolvable = (Resolvable) entityToResolve;
switch (resolvable.getResolvableStatus()) {
- case RESOLVED: {
+ case RESOLVED:
/*
* If the entity is already resolved in the stack, then pop
* it and continue with the remaining stack elements to
* resolve
*/
- getPartialResolvedStack().pop();
+ partialResolvedStack.pop();
break;
- }
- case INTER_FILE_LINKED: {
+ case INTER_FILE_LINKED:
/*
* If the top of the stack is already linked then resolve
* the references and pop the entity and continue with
* remaining stack elements to resolve
*/
- resolveTopOfStack(INTER_FILE);
- getPartialResolvedStack().pop();
+ resolveTopOfStack();
+ partialResolvedStack.pop();
break;
- }
- case INTRA_FILE_RESOLVED: {
+ case INTRA_FILE_RESOLVED:
/*
* If the top of the stack is intra file resolved then check
* if top of stack is linked, if not link it using
@@ -1392,29 +1175,22 @@
*/
linkInterFileTopOfStackRefUpdateStack();
break;
- }
- case UNDEFINED: {
+ case UNDEFINED:
/*
* In case of if-feature resolution, if referred "feature" is not
* defined then the resolvable status will be undefined.
*/
- getPartialResolvedStack().pop();
+ partialResolvedStack.pop();
break;
- }
- default: {
- throw new DataModelException("Data Model Exception: Unsupported, linker state");
- }
-
+ default:
+ throw new DataModelException(INVALID_LINKER_STATE);
}
-
} else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
+ throw new DataModelException(INVALID_RESOLVED_ENTITY);
}
-
}
-
}
/**
@@ -1424,11 +1200,11 @@
*/
private void linkInterFileTopOfStackRefUpdateStack()
throws DataModelException {
-
- if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangLeafRef) {
// When leafref path comes with relative path, it will be converted to absolute path.
- setAbsolutePathFromRelativePathInLeafref(getCurrentEntityToResolveFromStack());
- processXPathLinking(getCurrentEntityToResolveFromStack(), getCurReferenceResolver());
+ setAbsolutePathFromRelativePathInLeafref(entity);
+ processXPathLinking(entity, curRefResolver);
return;
}
/*
@@ -1446,7 +1222,8 @@
* Check if prefix is null or not, to identify whether to search in
* import list or include list.
*/
- if (getRefPrefix() != null && !getRefPrefix().contentEquals(getCurReferenceResolver().getPrefix())) {
+ if (getRefPrefix() != null && !getRefPrefix()
+ .contentEquals(curRefResolver.getPrefix())) {
if (resolveWithImport()) {
return;
}
@@ -1456,32 +1233,20 @@
}
}
- if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- ((YangIfFeature) getCurrentEntityToResolveFromStack()).setResolvableStatus(UNDEFINED);
+ if (entity instanceof YangIfFeature) {
+ ((YangIfFeature) entity).setResolvableStatus(UNDEFINED);
return;
}
// If current entity is still not resolved, then
// linking/resolution has failed.
- String errorInfo;
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- errorInfo = TYPEDEF_LINKER_ERROR;
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- errorInfo = GROUPING_LINKER_ERROR;
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- errorInfo = FEATURE_LINKER_ERROR;
- } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- errorInfo = BASE_LINKER_ERROR;
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- errorInfo = IDENTITYREF_LINKER_ERROR;
- } else {
- errorInfo = LEAFREF_LINKER_ERROR;
- }
- DataModelException dataModelException = new DataModelException(errorInfo);
- dataModelException.setLine(getLineNumber());
- dataModelException.setCharPosition(getCharPosition());
- throw dataModelException;
+
+ DataModelException ex = new DataModelException(
+ getErrorInfoForLinker(entity));
+ ex.setLine(getLineNumber());
+ ex.setCharPosition(getCharPosition());
+ throw ex;
} else {
- ((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTER_FILE_LINKED);
+ ((Resolvable) entity).setResolvableStatus(INTER_FILE_LINKED);
addUnresolvedRecursiveReferenceToStack((YangNode) referredNode);
}
}
@@ -1492,42 +1257,51 @@
* @param resolutionInfo information about the YANG construct which has to be resolved
* @throws DataModelException a violation of data model rules
*/
- public void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo)
+ private void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo)
throws DataModelException {
if (resolutionInfo instanceof YangLeafRef) {
- YangNode parentOfLeafref = ((YangLeafRef) resolutionInfo).getParentNodeOfLeafref();
+ YangNode leafParent = ((YangLeafRef) resolutionInfo)
+ .getParentNodeOfLeafref();
YangLeafRef leafref = (YangLeafRef) resolutionInfo;
// Checks if the leafref has relative path in it.
- if (leafref.getPathType() == YangPathArgType.RELATIVE_PATH) {
+ if (leafref.getPathType() == RELATIVE_PATH) {
YangRelativePath relativePath = leafref.getRelativePath();
List<YangAtomicPath> absoluteInRelative = relativePath.getAtomicPathList();
- int numberOfAncestors = relativePath.getAncestorNodeCount();
+ int ancestorCount = relativePath.getAncestorNodeCount();
// Gets the root node from the ancestor count.
- T nodeOrAugmentList = getRootNodeWithAncestorCountForLeafref(numberOfAncestors, parentOfLeafref,
- leafref);
+ T nodeOrAugmentList =
+ getRootNodeWithAncestorCountForLeafref(ancestorCount, leafParent,
+ leafref);
if (nodeOrAugmentList instanceof YangNode) {
- String pathNameToBePrefixed = EMPTY_STRING;
+ StringBuilder name = new StringBuilder();
+ StringBuilder prefix = new StringBuilder();
YangNode rootNode = (YangNode) nodeOrAugmentList;
// Forms a new absolute path from the relative path
while (!(rootNode instanceof YangReferenceResolver)) {
- pathNameToBePrefixed = rootNode.getName() + SLASH_FOR_STRING + pathNameToBePrefixed;
+ name.append(rootNode.getName());
+ prefix.append(SLASH_FOR_STRING).append(name.reverse());
+ name.delete(0, name.length());
rootNode = rootNode.getParent();
if (rootNode == null) {
- throw new DataModelException("Internal datamodel error: Datamodel tree is not correct");
+ throw new DataModelException(INVALID_TREE);
}
}
- fillAbsolutePathValuesInLeafref(leafref, pathNameToBePrefixed, absoluteInRelative);
+ prefix.reverse();
+ fillAbsolutePathValuesInLeafref(leafref, prefix.toString(),
+ absoluteInRelative);
} else {
List<String> listOfAugment = (List<String>) nodeOrAugmentList;
Iterator<String> listOfAugmentIterator = listOfAugment.listIterator();
- String augment = EMPTY_STRING;
+ StringBuilder augment = new StringBuilder(EMPTY_STRING);
while (listOfAugmentIterator.hasNext()) {
- augment = augment + SLASH_FOR_STRING + listOfAugmentIterator.next();
+ augment.append(SLASH_FOR_STRING)
+ .append(listOfAugmentIterator.next());
}
- fillAbsolutePathValuesInLeafref(leafref, augment, absoluteInRelative);
+ fillAbsolutePathValuesInLeafref(leafref, augment.toString(),
+ absoluteInRelative);
}
}
}
@@ -1536,43 +1310,41 @@
/**
* Fills the absolute path values in the leafref from relative path.
*
- * @param leafref instance of YANG leafref
- * @param pathNameToBePrefixed path name which has to be prefixed to relative path
- * @param atomicPathsInRelative atomic paths in relative
+ * @param leafref instance of YANG leafref
+ * @param path path name which has to be prefixed to relative path
+ * @param relative atomic paths in relative
* @throws DataModelException a violation of data model rules
*/
- private void fillAbsolutePathValuesInLeafref(YangLeafRef leafref, String pathNameToBePrefixed,
- List<YangAtomicPath> atomicPathsInRelative)
+ private void fillAbsolutePathValuesInLeafref(YangLeafRef leafref, String path,
+ List<YangAtomicPath> relative)
throws DataModelException {
-
- leafref.setPathType(YangPathArgType.ABSOLUTE_PATH);
+ leafref.setPathType(ABSOLUTE_PATH);
String[] pathName = new String[0];
- if (pathNameToBePrefixed != EMPTY_STRING && pathNameToBePrefixed != null) {
- pathName = pathNameToBePrefixed.split(SLASH_FOR_STRING);
+ if (path != null && !path.equals(EMPTY_STRING)) {
+ pathName = path.split(SLASH_FOR_STRING);
}
List<YangAtomicPath> finalListForAbsolute = new LinkedList<>();
for (String value : pathName) {
- if (value != null && !value.isEmpty() && value != EMPTY_STRING) {
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(value, YangConstructType.PATH_DATA);
+ if (value != null && !value.isEmpty() && !value.equals(EMPTY_STRING)) {
+ YangNodeIdentifier nodeId = getValidNodeIdentifier(value, PATH_DATA);
YangAtomicPath atomicPath = new YangAtomicPath();
- atomicPath.setNodeIdentifier(nodeIdentifier);
+ atomicPath.setNodeIdentifier(nodeId);
finalListForAbsolute.add(atomicPath);
}
}
- if (atomicPathsInRelative != null && !atomicPathsInRelative.isEmpty()) {
- Iterator<YangAtomicPath> atomicPathIterator = atomicPathsInRelative.listIterator();
- while (atomicPathIterator.hasNext()) {
- YangAtomicPath yangAtomicPath = atomicPathIterator.next();
+ if (relative != null && !relative.isEmpty()) {
+ Iterator<YangAtomicPath> pathIt = relative.listIterator();
+ while (pathIt.hasNext()) {
+ YangAtomicPath yangAtomicPath = pathIt.next();
finalListForAbsolute.add(yangAtomicPath);
}
leafref.setAtomicPath(finalListForAbsolute);
} else {
- DataModelException dataModelException = new DataModelException("YANG file error: The target node, in the " +
- "leafref path " + leafref.getPath() + ", is invalid.");
- dataModelException.setCharPosition(leafref.getCharPosition());
- dataModelException.setLine(leafref.getLineNumber());
- dataModelException.setFileName(leafref.getFileName());
- throw dataModelException;
+ DataModelException ex = new DataModelException(getLeafRefErrorInfo(leafref));
+ ex.setCharPosition(leafref.getCharPosition());
+ ex.setLine(leafref.getLineNumber());
+ ex.setFileName(leafref.getFileName());
+ throw ex;
}
}
@@ -1580,46 +1352,44 @@
* Returns the root parent with respect to the ancestor count from leafref.
*
* @param ancestorCount count of node where parent node can be reached
- * @param currentParent current parent node
+ * @param curParent current parent node
* @param leafref instance of YANG leafref
* @return node where the ancestor count stops or augment path name list
* @throws DataModelException a violation of data model rules
*/
- private T getRootNodeWithAncestorCountForLeafref(int ancestorCount, YangNode currentParent, YangLeafRef leafref)
+ private T getRootNodeWithAncestorCountForLeafref(
+ int ancestorCount, YangNode curParent, YangLeafRef leafref)
throws DataModelException {
- int currentParentCount = 1;
- currentParent = skipInvalidDataNodes(currentParent, leafref);
- if (currentParent instanceof YangAugment) {
- YangAugment augment = (YangAugment) currentParent;
- List<String> valueInAugment = getPathWithAugment(augment, ancestorCount - currentParentCount);
+ int curParentCount = 1;
+ curParent = skipInvalidDataNodes(curParent, leafref);
+ if (curParent instanceof YangAugment) {
+ YangAugment augment = (YangAugment) curParent;
+ List<String> valueInAugment = getPathWithAugment(augment,
+ ancestorCount - curParentCount);
return (T) valueInAugment;
} else {
- while (currentParentCount < ancestorCount) {
- YangNode currentSkippedParent = skipInvalidDataNodes(currentParent, leafref);
- if (currentSkippedParent == currentParent) {
- if (currentParent.getParent() == null) {
- throw new DataModelException("YANG file error: The target node, in the leafref path "
- + leafref.getPath() + ", is invalid."
- + " in " +
- leafref.getLineNumber() + " at " +
- leafref.getCharPosition()
- + " in " + leafref.getFileName() + "\"");
+ while (curParentCount < ancestorCount) {
+ YangNode currentSkippedParent = skipInvalidDataNodes(curParent, leafref);
+ if (currentSkippedParent == curParent) {
+ if (curParent.getParent() == null) {
+ throw new DataModelException(getLeafRefErrorInfo(leafref));
}
- currentParent = currentParent.getParent();
+ curParent = curParent.getParent();
} else {
- currentParent = currentSkippedParent;
+ curParent = currentSkippedParent;
continue;
}
- currentParentCount = currentParentCount + 1;
- if (currentParent instanceof YangAugment) {
- YangAugment augment = (YangAugment) currentParent;
- List<String> valueInAugment = getPathWithAugment(augment, ancestorCount - currentParentCount);
+ curParentCount = curParentCount + 1;
+ if (curParent instanceof YangAugment) {
+ YangAugment augment = (YangAugment) curParent;
+ List<String> valueInAugment = getPathWithAugment(
+ augment, ancestorCount - curParentCount);
return (T) valueInAugment;
}
}
}
- return (T) currentParent;
+ return (T) curParent;
}
/**
@@ -1628,33 +1398,15 @@
* @return true if resolved, false otherwise
* @throws DataModelException a violation in data model rule
*/
- private boolean resolveWithInclude()
- throws DataModelException {
+ private boolean resolveWithInclude() throws DataModelException {
/*
* Run through all the nodes in include list and search for referred
* typedef/grouping at the root level.
*/
- for (YangInclude yangInclude : getCurReferenceResolver().getIncludeList()) {
- YangNode linkedNode = null;
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- linkedNode = findRefTypedef(yangInclude.getIncludedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- linkedNode = findRefGrouping(yangInclude.getIncludedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- linkedNode = findRefFeature(yangInclude.getIncludedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- linkedNode = findRefIdentity(yangInclude.getIncludedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- linkedNode = findRefIdentityRef(yangInclude.getIncludedNode());
- }
-
+ for (YangInclude yangInclude : curRefResolver.getIncludeList()) {
+ YangNode linkedNode = getLinkedNode(yangInclude.getIncludedNode());
if (linkedNode != null) {
- // Add the link to external entity.
- addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
-
- // Add the type/uses of referred typedef/grouping to the stack.
- addUnresolvedRecursiveReferenceToStack(linkedNode);
- return true;
+ return addUnResolvedRefToStack(linkedNode);
}
}
// If referred node can't be found return false.
@@ -1667,37 +1419,19 @@
* @return true if resolved, false otherwise
* @throws DataModelException a violation in data model rule
*/
- private boolean resolveWithImport()
- throws DataModelException {
+ private boolean resolveWithImport() throws DataModelException {
// Run through import list to find the referred typedef/grouping.
- for (YangImport yangImport : getCurReferenceResolver().getImportList()) {
+ for (YangImport yangImport : curRefResolver.getImportList()) {
/*
* Match the prefix attached to entity under resolution with the
* imported/included module/sub-module's prefix. If found, search
* for the referred typedef/grouping at the root level.
*/
if (yangImport.getPrefixId().contentEquals(getRefPrefix())) {
- YangNode linkedNode = null;
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- linkedNode = findRefTypedef(yangImport.getImportedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- linkedNode = findRefGrouping(yangImport.getImportedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- linkedNode = findRefFeature(yangImport.getImportedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- linkedNode = findRefIdentity(yangImport.getImportedNode());
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- linkedNode = findRefIdentityRef(yangImport.getImportedNode());
- }
+ YangNode linkedNode = getLinkedNode(yangImport.getImportedNode());
if (linkedNode != null) {
- // Add the link to external entity.
- addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
-
- // Add the type/uses of referred typedef/grouping to the
- // stack.
- addUnresolvedRecursiveReferenceToStack(linkedNode);
- return true;
+ return addUnResolvedRefToStack(linkedNode);
}
/*
* If referred node can't be found at root level break for loop,
@@ -1710,32 +1444,68 @@
return false;
}
+ //Add unresolved constructs to stack.
+ private boolean addUnResolvedRefToStack(YangNode linkedNode)
+ throws DataModelException {
+ // Add the link to external entity.
+ addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
+
+ // Add the type/uses of referred typedef/grouping to the stack.
+ addUnresolvedRecursiveReferenceToStack(linkedNode);
+ return true;
+ }
+
+ //Returns linked node from entity of stack.
+ private YangNode getLinkedNode(YangNode node) {
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangType) {
+ return findRefTypedef(node);
+ }
+ if (entity instanceof YangUses) {
+ return findRefGrouping(node);
+ }
+ if (entity instanceof YangIfFeature) {
+ return findRefFeature(node);
+ }
+ if (entity instanceof YangBase) {
+ return findRefIdentity(node);
+ }
+ if (entity instanceof YangIdentityRef) {
+ return findRefIdentityRef(node);
+ }
+ return null;
+ }
+
/**
* Returns referred typedef/grouping node.
*
* @return referred typedef/grouping node
* @throws DataModelException a violation in data model rule
*/
- private T getRefNode()
- throws DataModelException {
- if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) ((YangType<?>) getCurrentEntityToResolveFromStack())
- .getDataTypeExtendedInfo();
+ private T getRefNode() throws DataModelException {
+ T entity = getCurEntityToResolveFromStack();
+ if (entity instanceof YangType) {
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
+ ((YangType<?>) entity).getDataTypeExtendedInfo();
return (T) derivedInfo.getReferredTypeDef();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangUses) {
- return (T) ((YangUses) getCurrentEntityToResolveFromStack()).getRefGroup();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIfFeature) {
- return (T) ((YangIfFeature) getCurrentEntityToResolveFromStack()).getReferredFeatureHolder();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangLeafRef) {
- return (T) ((YangLeafRef) getCurrentEntityToResolveFromStack()).getReferredLeafOrLeafList();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangBase) {
- return (T) ((YangBase) getCurrentEntityToResolveFromStack()).getReferredIdentity();
- } else if (getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) {
- return (T) ((YangIdentityRef) getCurrentEntityToResolveFromStack()).getReferredIdentity();
- } else {
- throw new DataModelException("Data Model Exception: Entity to resolved is other than type" +
- "/uses/base/identityref");
}
+ if (entity instanceof YangUses) {
+ return (T) ((YangUses) entity).getRefGroup();
+ }
+ if (entity instanceof YangIfFeature) {
+ return (T) ((YangIfFeature) entity).getReferredFeatureHolder();
+ }
+ if (entity instanceof YangLeafRef) {
+ return (T) ((YangLeafRef) entity).getReferredLeafOrLeafList();
+ }
+ if (entity instanceof YangBase) {
+ return (T) ((YangBase) entity).getReferredIdentity();
+ }
+ if (entity instanceof YangIdentityRef) {
+ return (T) ((YangIdentityRef) entity).getReferredIdentity();
+ }
+ throw new DataModelException(LINKER_ERROR);
+
}
/**
@@ -1749,7 +1519,8 @@
while (tmpNode != null) {
if (tmpNode instanceof YangGrouping) {
if (tmpNode.getName()
- .equals(((YangUses) getCurrentEntityToResolveFromStack()).getName())) {
+ .equals(((YangUses) getCurEntityToResolveFromStack())
+ .getName())) {
return tmpNode;
}
}
@@ -1765,15 +1536,14 @@
* @return referred feature
*/
private YangNode findRefFeature(YangNode refNode) {
- YangNodeIdentifier ifFeature = ((YangIfFeature) getCurrentEntityToResolveFromStack()).getName();
- List<YangFeature> featureList = ((YangFeatureHolder) refNode).getFeatureList();
-
+ T entity = getCurEntityToResolveFromStack();
+ YangNodeIdentifier ifFeature = ((YangIfFeature) entity).getName();
+ List<YangFeature> featureList = ((YangFeatureHolder) refNode)
+ .getFeatureList();
if (featureList != null && !featureList.isEmpty()) {
- Iterator<YangFeature> iterator = featureList.iterator();
- while (iterator.hasNext()) {
- YangFeature feature = iterator.next();
+ for (YangFeature feature : featureList) {
if (ifFeature.getName().equals(feature.getName())) {
- ((YangIfFeature) getCurrentEntityToResolveFromStack()).setReferredFeature(feature);
+ ((YangIfFeature) entity).setReferredFeature(feature);
return refNode;
}
}
@@ -1792,7 +1562,8 @@
while (tmpNode != null) {
if (tmpNode instanceof YangTypeDef) {
if (tmpNode.getName()
- .equals(((YangType) getCurrentEntityToResolveFromStack()).getDataTypeName())) {
+ .equals(((YangType) getCurEntityToResolveFromStack())
+ .getDataTypeName())) {
return tmpNode;
}
}
@@ -1812,7 +1583,8 @@
while (tmpNode != null) {
if (tmpNode instanceof YangIdentity) {
if (tmpNode.getName()
- .equals(((YangBase) getCurrentEntityToResolveFromStack()).getBaseIdentifier().getName())) {
+ .equals(((YangBase) getCurEntityToResolveFromStack())
+ .getBaseIdentifier().getName())) {
return tmpNode;
}
}
@@ -1832,8 +1604,8 @@
while (tmpNode != null) {
if (tmpNode instanceof YangIdentity) {
if (tmpNode.getName()
- .equals(((YangIdentityRef) getCurrentEntityToResolveFromStack())
- .getBaseIdentity().getName())) {
+ .equals(((YangIdentityRef) getCurEntityToResolveFromStack())
+ .getBaseIdentity().getName())) {
return tmpNode;
}
}
@@ -1854,4 +1626,4 @@
targetNode = targetNode.getParent();
}
}
-}
+}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
index a53e727..5e1413f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
@@ -16,18 +16,10 @@
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.LeafRefInvalidHolder;
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangInput;
@@ -40,17 +32,29 @@
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
+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 static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTRA;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_FIND_LEAD_INFO_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
+import static org.onosproject.yangutils.utils.UtilConstants.IS_INVALID;
+import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.LEAF_HOLDER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
+import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
/**
* Represents x-path linking.
@@ -73,125 +77,6 @@
}
/**
- * Returns prefix resolver list.
- *
- * @return prefix resolver list
- */
- private Map<YangAtomicPath, PrefixResolverType> getPrefixResolverTypes() {
- return prefixResolverTypes;
- }
-
- /**
- * Sets prefix resolver list.
- *
- * @param prefixResolverTypes prefix resolver list.
- */
- private void setPrefixResolverTypes(Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes) {
- this.prefixResolverTypes = prefixResolverTypes;
- }
-
- /**
- * Adds to the prefix resolver type map.
- *
- * @param type resolver type
- * @param path absolute path
- */
- private void addToPrefixResolverList(PrefixResolverType type, YangAtomicPath path) {
- getPrefixResolverTypes().put(path, type);
- }
-
- /**
- * Returns list of target nodes paths.
- *
- * @return target nodes paths
- */
- private List<YangAtomicPath> getAbsPaths() {
- return absPaths;
- }
-
- /**
- * Sets target nodes paths.
- *
- * @param absPaths target nodes paths
- */
- private void setAbsPaths(List<YangAtomicPath> absPaths) {
- this.absPaths = absPaths;
- }
-
- /**
- * Adds target nodes paths.
- *
- * @param absPaths target nodes paths
- */
- private void addAbsPaths(YangAtomicPath absPaths) {
- getAbsPaths().add(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 unresolved construct's parent's prefix.
- *
- * @return unresolved construct's parent's prefix
- */
- private String getConstructsParentsPrefix() {
- return constructsParentsPrefix;
- }
-
- /**
- * Sets unresolved construct's parent's prefix.
- *
- * @param constructsParentsPrefix unresolved construct's parent's prefix
- */
- private void setConstructsParentsPrefix(String constructsParentsPrefix) {
- this.constructsParentsPrefix = constructsParentsPrefix;
- }
-
- /**
- * Adds node to resolved nodes.
- *
- * @param path absolute path
- * @param node resolved node
- */
- private void addToResolvedNodes(YangAtomicPath path, YangNode node) {
- path.setResolvedNode(node);
- }
-
- /**
* Returns list of augment nodes.
*
* @param node root node
@@ -217,21 +102,22 @@
* @param leafref instance of YANG leafref
* @return linked target node
*/
- T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) {
+ T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root,
+ YangLeafRef leafref) {
YangNode targetNode;
- setRootNode(root);
- setPrefixResolverTypes(new HashMap<>());
+ rootNode = root;
+ prefixResolverTypes = new HashMap<>();
parsePrefixResolverList(atomicPaths);
YangAtomicPath leafRefPath = atomicPaths.get(atomicPaths.size() - 1);
// When leaf-ref path contains only one absolute path.
if (atomicPaths.size() == 1) {
- targetNode = getTargetNodewhenSizeIsOne(atomicPaths);
+ targetNode = getTargetNodeWhenPathSizeIsOne(atomicPaths);
} else {
for (YangAtomicPath atomicPath : atomicPaths) {
if (atomicPath != leafRefPath) {
- addAbsPaths(atomicPath);
+ absPaths.add(atomicPath);
}
}
targetNode = parseData(root);
@@ -244,20 +130,20 @@
validateInvalidNodesInThePath(leafref);
if (targetNode != null) {
- YangLeaf targetLeaf = searchReferredLeaf(targetNode, leafRefPath.getNodeIdentifier().getName());
+ YangLeaf targetLeaf = searchReferredLeaf(targetNode, leafRefPath
+ .getNodeIdentifier().getName());
if (targetLeaf == null) {
- YangLeafList targetLeafList = searchReferredLeafList(targetNode,
- leafRefPath.getNodeIdentifier().getName());
+ YangLeafList targetLeafList = searchReferredLeafList(
+ targetNode, leafRefPath.getNodeIdentifier().getName());
if (targetLeafList != null) {
return (T) targetLeafList;
} else {
- LinkerException linkerException = new LinkerException("YANG file error: Unable to find base " +
- "leaf/leaf-list for given leafref path "
- + leafref.getPath());
- linkerException.setCharPosition(leafref.getCharPosition());
- linkerException.setLine(leafref.getLineNumber());
- linkerException.setFileName(leafref.getFileName());
- throw linkerException;
+ LinkerException ex = new LinkerException(
+ FAILED_TO_FIND_LEAD_INFO_HOLDER + leafref.getPath());
+ ex.setCharPosition(leafref.getCharPosition());
+ ex.setLine(leafref.getLineNumber());
+ ex.setFileName(leafref.getFileName());
+ throw ex;
}
}
return (T) targetLeaf;
@@ -271,18 +157,17 @@
* @param leafref instance of YANG leafref
*/
private void validateInvalidNodesInThePath(YangLeafRef leafref) {
- for (YangAtomicPath absolutePath : (Iterable<YangAtomicPath>) leafref.getAtomicPath()) {
+ for (YangAtomicPath absolutePath : (Iterable<YangAtomicPath>) leafref
+ .getAtomicPath()) {
YangNode nodeInPath = absolutePath.getResolvedNode();
- if (nodeInPath instanceof YangGrouping || nodeInPath instanceof YangUses
- || nodeInPath instanceof YangTypeDef || nodeInPath instanceof YangCase
- || nodeInPath instanceof YangChoice) {
- LinkerException linkerException = new LinkerException("YANG file error: The target node, in the " +
- "leafref path " + leafref.getPath() + ", is invalid.");
- linkerException.setCharPosition(leafref.getCharPosition());
- linkerException.setLine(leafref.getLineNumber());
- linkerException.setFileName(leafref.getFileName());
- throw linkerException;
+ if (nodeInPath instanceof LeafRefInvalidHolder) {
+ LinkerException ex = new LinkerException(
+ LEAFREF_ERROR + leafref.getPath() + IS_INVALID);
+ ex.setCharPosition(leafref.getCharPosition());
+ ex.setLine(leafref.getLineNumber());
+ ex.setFileName(leafref.getFileName());
+ throw ex;
}
}
}
@@ -290,39 +175,36 @@
/**
* Returns target node when leaf-ref has only one absolute path in list.
*
- * @param absPaths absolute paths
+ * @param paths 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());
+ private YangNode getTargetNodeWhenPathSizeIsOne(List<YangAtomicPath> paths) {
+ if (paths.get(0).getNodeIdentifier().getPrefix() != null
+ && !paths.get(0).getNodeIdentifier().getPrefix().equals
+ (getRootsPrefix(rootNode))) {
+ return getImportedNode(rootNode, paths.get(0).getNodeIdentifier());
}
- return getRootNode();
-
+ return rootNode;
}
/**
* Process absolute node path linking for augment.
*
- * @param absPaths absolute path node list
- * @param root root node
+ * @param paths absolute path node list
+ * @param root root node
* @return linked target node
*/
- public YangNode processAugmentXpathLinking(List<YangAtomicPath> absPaths, YangNode root) {
-
- setAbsPaths(absPaths);
- setRootNode(root);
- setPrefixResolverTypes(new HashMap<>());
- parsePrefixResolverList(absPaths);
-
+ public YangNode processAugmentXpathLinking(List<YangAtomicPath> paths,
+ YangNode root) {
+ absPaths = paths;
+ rootNode = root;
+ prefixResolverTypes = new HashMap<>();
+ parsePrefixResolverList(paths);
YangNode targetNode = parseData(root);
-
if (targetNode == null) {
targetNode = searchInSubModule(root);
}
return targetNode;
-
}
/**
@@ -334,9 +216,10 @@
*/
private YangLeaf searchReferredLeaf(YangNode targetNode, String leafName) {
if (!(targetNode instanceof YangLeavesHolder)) {
- throw new LinkerException("Referred node " + targetNode.getName() +
- "should be of type leaves holder in " + targetNode.getLineNumber() +
- " at " + targetNode.getCharPosition() + " in " + targetNode.getFileName());
+ throw new LinkerException(getErrorMsg(
+ LEAF_HOLDER_ERROR, targetNode.getName(), targetNode
+ .getLineNumber(), targetNode.getCharPosition(),
+ targetNode.getFileName()));
}
YangLeavesHolder holder = (YangLeavesHolder) targetNode;
List<YangLeaf> leaves = holder.getListOfLeaf();
@@ -354,20 +237,21 @@
* Searches for the referred leaf-list in target node.
*
* @param targetNode target node
- * @param leafListName leaf-list name
+ * @param name leaf-list name
* @return target leaf-list
*/
- private YangLeafList searchReferredLeafList(YangNode targetNode, String leafListName) {
+ private YangLeafList searchReferredLeafList(YangNode targetNode, String name) {
if (!(targetNode instanceof YangLeavesHolder)) {
- throw new LinkerException("Referred node " + targetNode.getName() +
- "should be of type leaves holder in " + targetNode.getLineNumber() +
- " at " + targetNode.getCharPosition() + " in " + targetNode.getFileName());
+ throw new LinkerException(getErrorMsg(
+ LEAF_HOLDER_ERROR, targetNode.getName(), targetNode
+ .getLineNumber(), targetNode.getCharPosition(),
+ targetNode.getFileName()));
}
YangLeavesHolder holder = (YangLeavesHolder) targetNode;
List<YangLeafList> leavesList = holder.getListOfLeafList();
if (leavesList != null && !leavesList.isEmpty()) {
for (YangLeafList leafList : leavesList) {
- if (leafList.getName().equals(leafListName)) {
+ if (leafList.getName().equals(name)) {
return leafList;
}
}
@@ -383,8 +267,8 @@
*/
private YangNode parseData(YangNode root) {
String rootPrefix = getRootsPrefix(root);
- setConstructsParentsPrefix(rootPrefix);
- Iterator<YangAtomicPath> pathIterator = getAbsPaths().iterator();
+ constructsParentsPrefix = rootPrefix;
+ Iterator<YangAtomicPath> pathIterator = absPaths.iterator();
YangAtomicPath path = pathIterator.next();
if (path.getNodeIdentifier().getPrefix() != null
&& !path.getNodeIdentifier().getPrefix().equals(rootPrefix)) {
@@ -404,10 +288,10 @@
YangNode tempNode = root;
Stack<YangNode> linkerStack = new Stack<>();
- Iterator<YangAtomicPath> pathIterator = getAbsPaths().iterator();
+ Iterator<YangAtomicPath> pathIterator = absPaths.iterator();
YangAtomicPath tempPath = pathIterator.next();
YangNodeIdentifier nodeId;
- setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
+ curPrefix = tempPath.getNodeIdentifier().getPrefix();
int index = 0;
YangNode tempAugment;
do {
@@ -424,17 +308,17 @@
tempNode = searchTargetNode(tempNode, nodeId);
- if (tempNode == null && linkerStack.size() != 0) {
+ if (tempNode == null && !linkerStack.isEmpty()) {
tempNode = linkerStack.peek();
linkerStack.pop();
tempNode = searchTargetNode(tempNode, nodeId);
}
if (tempNode != null) {
- addToResolvedNodes(tempPath, tempNode);
+ tempPath.setResolvedNode(tempNode);
}
- if (index == getAbsPaths().size() - 1) {
+ if (index == absPaths.size() - 1) {
break;
}
tempPath = pathIterator.next();
@@ -452,25 +336,26 @@
*/
private YangNode resolveIntraFileAugment(YangAtomicPath tempPath, YangNode root) {
YangNode tempAugment;
- if (getCurPrefix() != tempPath.getNodeIdentifier().getPrefix()) {
- root = getIncludedNode(getRootNode(), tempPath.getNodeIdentifier().getName());
+ if (curPrefix != tempPath.getNodeIdentifier().getPrefix()) {
+ root = getIncludedNode(rootNode, tempPath.getNodeIdentifier().getName());
if (root == null) {
- root = getIncludedNode(getRootNode(), getAugmentNodeIdentifier(tempPath.getNodeIdentifier(), absPaths,
- getRootNode()));
+ root = getIncludedNode(rootNode, getAugmentNodeIdentifier(
+ tempPath.getNodeIdentifier(), absPaths, rootNode));
if (root == null) {
- root = getRootNode();
+ root = rootNode;
}
}
} else {
- if (getCurPrefix() != null) {
+ if (curPrefix != null) {
root = getImportedNode(root, tempPath.getNodeIdentifier());
}
}
- setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
- tempAugment = getAugment(tempPath.getNodeIdentifier(), root, getAbsPaths());
+ curPrefix = tempPath.getNodeIdentifier().getPrefix();
+ tempAugment = getAugment(tempPath.getNodeIdentifier(), root, absPaths);
if (tempAugment == null) {
- tempAugment = getAugment(tempPath.getNodeIdentifier(), getRootNode(), getAbsPaths());
+ tempAugment = getAugment(tempPath.getNodeIdentifier(), rootNode,
+ absPaths);
}
return tempAugment;
}
@@ -485,11 +370,11 @@
private YangNode resolveInterFileAugment(YangAtomicPath tempPath, YangNode root) {
YangNode tempAugment;
- if (!tempPath.getNodeIdentifier().getPrefix().equals(getCurPrefix())) {
- setCurPrefix(tempPath.getNodeIdentifier().getPrefix());
- root = getImportedNode(getRootNode(), tempPath.getNodeIdentifier());
+ if (!tempPath.getNodeIdentifier().getPrefix().equals(curPrefix)) {
+ curPrefix = tempPath.getNodeIdentifier().getPrefix();
+ root = getImportedNode(rootNode, tempPath.getNodeIdentifier());
}
- tempAugment = getAugment(tempPath.getNodeIdentifier(), root, getAbsPaths());
+ tempAugment = getAugment(tempPath.getNodeIdentifier(), root, absPaths);
if (tempAugment == null) {
return resolveInterToInterFileAugment(root);
}
@@ -507,23 +392,23 @@
private YangNode resolveInterToInterFileAugment(YangNode root) {
List<YangAugment> augments = getListOfYangAugment(root);
int index;
- List<YangAtomicPath> absPaths = new ArrayList<>();
+ List<YangAtomicPath> paths = new ArrayList<>();
for (YangAugment augment : augments) {
index = 0;
for (YangAtomicPath path : augment.getTargetNode()) {
if (!searchForAugmentInImportedNode(path.getNodeIdentifier(), index)) {
- absPaths.clear();
+ paths.clear();
break;
}
- absPaths.add(path);
+ paths.add(path);
index++;
}
- if (!absPaths.isEmpty() && absPaths.size() == getAbsPaths().size() - 1) {
+ if (!paths.isEmpty() && paths.size() == absPaths.size() - 1) {
return augment;
} else {
- absPaths.clear();
+ paths.clear();
}
}
return null;
@@ -537,11 +422,12 @@
* @param index index
* @return true if found
*/
- private boolean searchForAugmentInImportedNode(YangNodeIdentifier nodeId, int index) {
- if (index == getAbsPaths().size()) {
+ private boolean searchForAugmentInImportedNode(YangNodeIdentifier nodeId,
+ int index) {
+ if (index == absPaths.size()) {
return false;
}
- YangNodeIdentifier tempNodeId = getAbsPaths().get(index).getNodeIdentifier();
+ YangNodeIdentifier tempNodeId = absPaths.get(index).getNodeIdentifier();
return nodeId.getName().equals(tempNodeId.getName());
}
@@ -552,7 +438,8 @@
* @param root root node
* @return linked target node
*/
- private YangNode getAugment(YangNodeIdentifier tempNodeId, YangNode root, List<YangAtomicPath> absPaths) {
+ private YangNode getAugment(YangNodeIdentifier tempNodeId, YangNode root,
+ List<YangAtomicPath> absPaths) {
String augmentName = getAugmentNodeIdentifier(tempNodeId, absPaths, root);
if (augmentName != null) {
return searchAugmentNode(root, augmentName);
@@ -583,8 +470,9 @@
}
}
- if (nodeId.getName() != null && nodeId.getPrefix().equals(getConstructsParentsPrefix())) {
- return getRootNode();
+ if (nodeId.getName() != null && nodeId.getPrefix()
+ .equals(constructsParentsPrefix)) {
+ return rootNode;
}
return root;
}
@@ -666,46 +554,47 @@
* @param root root node
* @return augment's node id
*/
- private String getAugmentNodeIdentifier(YangNodeIdentifier nodeId, List<YangAtomicPath> absPaths, YangNode root) {
-
+ private String getAugmentNodeIdentifier(
+ YangNodeIdentifier nodeId, List<YangAtomicPath> absPaths, YangNode root) {
Iterator<YangAtomicPath> nodeIdIterator = absPaths.iterator();
YangAtomicPath tempNodeId;
StringBuilder builder = new StringBuilder();
+ String name;
+ String prefix;
String id;
PrefixResolverType type;
while (nodeIdIterator.hasNext()) {
tempNodeId = nodeIdIterator.next();
+ name = tempNodeId.getNodeIdentifier().getName();
+ prefix = tempNodeId.getNodeIdentifier().getPrefix();
if (!tempNodeId.getNodeIdentifier().equals(nodeId)) {
- type = getPrefixResolverTypes().get(tempNodeId);
+ type = prefixResolverTypes.get(tempNodeId);
switch (type) {
case INTER_TO_INTRA:
- id = "/" + tempNodeId.getNodeIdentifier().getName();
+ id = SLASH_FOR_STRING + name;
break;
case INTRA_TO_INTER:
- if (!getRootsPrefix(root).equals(tempNodeId.getNodeIdentifier().getPrefix())) {
- id = "/" + tempNodeId.getNodeIdentifier().getPrefix() + ":" + tempNodeId.getNodeIdentifier()
- .getName();
+ if (!getRootsPrefix(root).equals(prefix)) {
+ id = SLASH_FOR_STRING + prefix + COLON + name;
} else {
- id = "/" + tempNodeId.getNodeIdentifier().getName();
+ id = SLASH_FOR_STRING + name;
}
break;
case INTER_TO_INTER:
- id = "/" + tempNodeId.getNodeIdentifier().getPrefix() + ":" + tempNodeId.getNodeIdentifier()
- .getName();
+ id = SLASH_FOR_STRING + prefix + COLON + name;
break;
case NO_PREFIX_CHANGE_FOR_INTRA:
- id = "/" + tempNodeId.getNodeIdentifier().getName();
+ id = SLASH_FOR_STRING + name;
break;
case NO_PREFIX_CHANGE_FOR_INTER:
- if (!getRootsPrefix(root).equals(tempNodeId.getNodeIdentifier().getPrefix())) {
- id = "/" + tempNodeId.getNodeIdentifier().getPrefix() + ":" + tempNodeId.getNodeIdentifier()
- .getName();
+ if (!getRootsPrefix(root).equals(prefix)) {
+ id = SLASH_FOR_STRING + prefix + COLON + name;
} else {
- id = "/" + tempNodeId.getNodeIdentifier().getName();
+ id = SLASH_FOR_STRING + name;
}
break;
default:
- id = "/" + tempNodeId.getNodeIdentifier().getName();
+ id = SLASH_FOR_STRING + name;
break;
}
builder.append(id);
@@ -746,7 +635,7 @@
*/
private boolean validate(YangNode tempNode, int index) {
- int size = getAbsPaths().size();
+ int size = absPaths.size();
if (tempNode != null && index != size) {
return true;
} else if (tempNode != null) {
@@ -771,7 +660,6 @@
if (node != null) {
node = node.getChild();
}
-
while (node != null) {
if (node instanceof YangInput) {
if (curNodeId.getName().equalsIgnoreCase(INPUT)) {
@@ -821,22 +709,33 @@
if (curPrefix != null) {
if (!curPrefix.equals(prePrefix)) {
if (prePrefix != null) {
- addToPrefixResolverList(INTER_TO_INTER, absPath);
+ prefixResolverTypes.put(absPath, INTER_TO_INTER);
} else {
- addToPrefixResolverList(INTRA_TO_INTER, absPath);
+ prefixResolverTypes.put(absPath, INTRA_TO_INTER);
}
} else {
- addToPrefixResolverList(NO_PREFIX_CHANGE_FOR_INTER, absPath);
+ prefixResolverTypes.put(absPath, NO_PREFIX_CHANGE_FOR_INTER);
}
} else {
if (prePrefix != null) {
- addToPrefixResolverList(INTER_TO_INTRA, absPath);
+ prefixResolverTypes.put(absPath, INTER_TO_INTRA);
} else {
- addToPrefixResolverList(NO_PREFIX_CHANGE_FOR_INTRA, absPath);
+ prefixResolverTypes.put(absPath, NO_PREFIX_CHANGE_FOR_INTRA);
}
}
}
}
-}
+ /**
+ * Adds augment to rpc augmented list of input.
+ *
+ * @param augment augment
+ * @param rootNode root node
+ */
+ void addInModuleIfInput(YangAugment augment,
+ YangNode rootNode) {
+ ((RpcNotificationContainer) rootNode).addToAugmentList(augment);
+ }
+
+}
\ No newline at end of file
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 7c82175..f2e7019 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
@@ -20,6 +20,9 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import static java.util.Collections.sort;
+import static java.util.Collections.unmodifiableSortedSet;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
@@ -29,22 +32,16 @@
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SET;
-import static java.util.Collections.sort;
/**
* Represents that generated Java file can contain imports.
@@ -70,23 +67,15 @@
* Sorted set of import info, to be used to maintain the set of classes to
* be imported in the generated class.
*/
- private SortedSet<JavaQualifiedTypeInfoTranslator> importSet;
+ private final SortedSet<JavaQualifiedTypeInfoTranslator> importSet;
/**
* Creates java import data object.
*/
public JavaImportData() {
- setImportSet(new TreeSet<>());
+ importSet = new TreeSet<>();
}
- /**
- * Returns if the list needs to be imported.
- *
- * @return true if any of the attribute needs to be maintained as a list
- */
- private boolean getIfListImported() {
- return isListToImport;
- }
/**
* Sets the status of importing list.
@@ -97,30 +86,13 @@
isListToImport = isList;
}
- /**
- * Is Queue to be imported due to compiler annotations.
- *
- * @return status of queue import
- */
- public boolean isQueueToImport() {
- return isQueueToImport;
- }
-
- /**
- * Is Set to be imported due to compiler annotations.
- *
- * @return status of set import
- */
- public boolean isSetToImport() {
- return isSetToImport;
- }
/**
* Sets the status of the queue to be imported due to compiler annotations.
*
* @param queueToImport status of queue to import
*/
- public void setQueueToImport(boolean queueToImport) {
+ void setQueueToImport(boolean queueToImport) {
isQueueToImport = queueToImport;
}
@@ -129,7 +101,7 @@
*
* @param setToImport status of set to import
*/
- public void setSetToImport(boolean setToImport) {
+ void setSetToImport(boolean setToImport) {
isSetToImport = setToImport;
}
@@ -139,16 +111,7 @@
* @return the set containing the imported class/interface info
*/
public SortedSet<JavaQualifiedTypeInfoTranslator> getImportSet() {
- return importSet;
- }
-
- /**
- * Assigns the set containing the imported class/interface info.
- *
- * @param importSet the set containing the imported class/interface info
- */
- private void setImportSet(SortedSet<JavaQualifiedTypeInfoTranslator> importSet) {
- this.importSet = importSet;
+ return unmodifiableSortedSet(importSet);
}
/**
@@ -178,7 +141,8 @@
return true;
} else if (newImportInfo.getPkgInfo() == null) {
/*
- * If the package info is null, then it is not a candidate for import / qualified access
+ * If the package info is null, then it is not a candidate for import
+ * / qualified access
*/
return false;
}
@@ -190,7 +154,8 @@
*/
if (newImportInfo.getPkgInfo().contentEquals(classPkg)) {
/*
- * Package of the referred attribute and the generated class is same, so no need import
+ * Package of the referred attribute and the generated class is same,
+ * so no need import
* or qualified access.
*/
return false;
@@ -207,7 +172,7 @@
/*
* Import is added, so it is a member for non qualified access
*/
- getImportSet().add(newImportInfo);
+ importSet.add(newImportInfo);
return false;
}
@@ -222,24 +187,21 @@
List<String> imports = new ArrayList<>();
for (JavaQualifiedTypeInfoTranslator importInfo : getImportSet()) {
- if (!importInfo.getPkgInfo().equals(EMPTY_STRING) && importInfo.getClassInfo() != null
- && !importInfo.getPkgInfo().equals(JAVA_LANG)) {
- importString = IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN
- + NEW_LINE;
-
+ if (!importInfo.getPkgInfo().equals(EMPTY_STRING) &&
+ importInfo.getClassInfo() != null &&
+ !importInfo.getPkgInfo().equals(JAVA_LANG)) {
+ importString = getImportString(importInfo.getPkgInfo(), importInfo
+ .getClassInfo());
imports.add(importString);
}
}
-
- if (getIfListImported()) {
+ if (isListToImport) {
imports.add(getImportForList());
}
-
- if (isQueueToImport()) {
+ if (isQueueToImport) {
imports.add(getImportForQueue());
}
-
- if (isSetToImport()) {
+ if (isSetToImport) {
imports.add(getImportForSet());
}
@@ -253,7 +215,8 @@
* @return import for hash and equals method
*/
String getImportForHashAndEquals() {
- return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_OBJECTS_IMPORT_CLASS;
+ return getImportString(JAVA_UTIL_OBJECTS_IMPORT_PKG,
+ JAVA_UTIL_OBJECTS_IMPORT_CLASS);
}
/**
@@ -262,7 +225,8 @@
* @return import for to string method
*/
String getImportForToString() {
- return IMPORT + GOOGLE_MORE_OBJECT_IMPORT_PKG + PERIOD + GOOGLE_MORE_OBJECT_IMPORT_CLASS;
+ return getImportString(GOOGLE_MORE_OBJECT_IMPORT_PKG,
+ GOOGLE_MORE_OBJECT_IMPORT_CLASS);
}
/**
@@ -271,7 +235,7 @@
* @return import for to bitset method
*/
String getImportForToBitSet() {
- return IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + BITSET + SEMI_COLAN + NEW_LINE;
+ return getImportString(JAVA_UTIL_OBJECTS_IMPORT_PKG, BITSET);
}
/**
@@ -280,7 +244,7 @@
* @return import for list attribute
*/
String getImportForList() {
- return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
+ return getImportString(COLLECTION_IMPORTS, LIST);
}
/**
@@ -288,8 +252,8 @@
*
* @return import for queue attribute
*/
- public String getImportForQueue() {
- return IMPORT + COLLECTION_IMPORTS + PERIOD + QUEUE + SEMI_COLAN + NEW_LINE;
+ private String getImportForQueue() {
+ return getImportString(COLLECTION_IMPORTS, QUEUE);
}
/**
@@ -297,8 +261,8 @@
*
* @return import for set attribute
*/
- public String getImportForSet() {
- return IMPORT + COLLECTION_IMPORTS + PERIOD + SET + SEMI_COLAN + NEW_LINE;
+ private String getImportForSet() {
+ return getImportString(COLLECTION_IMPORTS, SET);
}
/**
@@ -307,16 +271,7 @@
* @return import string for ListenerService class
*/
public String getListenerServiceImport() {
- return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
- }
-
- /**
- * Returns import string for ListenerRegistry class.
- *
- * @return import string for ListenerRegistry class
- */
- public String getListenerRegistryImport() {
- return IMPORT + ONOS_EVENT_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
+ return getImportString(ONOS_EVENT_PKG, LISTENER_SERVICE);
}
/**
@@ -325,7 +280,7 @@
* @return import string for AbstractEvent class
*/
String getAbstractEventsImport() {
- return IMPORT + ONOS_EVENT_PKG + PERIOD + ABSTRACT_EVENT + SEMI_COLAN + NEW_LINE;
+ return getImportString(ONOS_EVENT_PKG, ABSTRACT_EVENT);
}
/**
@@ -334,7 +289,7 @@
* @return import string for EventListener class
*/
String getEventListenerImport() {
- return IMPORT + ONOS_EVENT_PKG + PERIOD + EVENT_LISTENER + SEMI_COLAN + NEW_LINE;
+ return getImportString(ONOS_EVENT_PKG, EVENT_LISTENER);
}
/**
@@ -343,7 +298,7 @@
* @return import string for map class
*/
String getMapImport() {
- return IMPORT + COLLECTION_IMPORTS + PERIOD + MAP + SEMI_COLAN + NEW_LINE;
+ return getImportString(COLLECTION_IMPORTS, MAP);
}
/**
@@ -352,7 +307,7 @@
* @return import string for hash map class
*/
String getHashMapImport() {
- return IMPORT + COLLECTION_IMPORTS + PERIOD + HASH_MAP + SEMI_COLAN + NEW_LINE;
+ return getImportString(COLLECTION_IMPORTS, HASH_MAP);
}
/**
@@ -361,7 +316,7 @@
* @return import for big integer
*/
public String getBigIntegerImport() {
- return IMPORT + JAVA_MATH + PERIOD +
- BIG_INTEGER + SEMI_COLAN + NEW_LINE;
+ return getImportString(JAVA_MATH, BIG_INTEGER);
}
+
}
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 a12802f..7f15bc3 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
@@ -16,11 +16,11 @@
package org.onosproject.yangutils.translator.tojava;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+
import java.io.File;
import java.io.IOException;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
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.utils.io.impl.FileSystemUtil.closeFile;
@@ -40,7 +40,7 @@
/**
* Temporary file handle for constructor of class.
*/
- private File constructorImplTempFileHandle;
+ private final File constructorImplTempFileHandle;
/**
* Creates an instance of temporary java code fragment.
@@ -58,8 +58,7 @@
* to strings when generation file type matches to impl class mask.
*/
addGeneratedTempFile(CONSTRUCTOR_IMPL_MASK);
-
- setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME));
+ constructorImplTempFileHandle = getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME);
}
/**
@@ -72,44 +71,37 @@
}
/**
- * Sets to constructor's temporary file handle.
- *
- * @param constructor file handle for to constructor
- */
- private void setConstructorImplTempFileHandle(File constructor) {
- constructorImplTempFileHandle = constructor;
- }
-
- /**
* Adds constructor for class.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- private void addConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ private void addConstructor(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getConstructorImplTempFileHandle(), getConstructor(attr,
- getGeneratedJavaFiles(), pluginConfig));
+ appendToFile(constructorImplTempFileHandle,
+ getConstructor(attr, getGeneratedJavaFiles()));
}
/**
* Adds the new attribute info to the target generated temporary files.
*
* @param newAttrInfo the attribute info that needs to be added to temporary
- * files
+ * files
* @throws IOException IO operation fail
*/
@Override
- void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
+ void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
+ YangPluginConfig pluginConfig)
throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
- addConstructor(newAttrInfo, pluginConfig);
+ addConstructor(newAttrInfo);
}
/**
* Removes all temporary file handles.
*
- * @param isErrorOccurred flag to tell translator that error has occurred while code generation
+ * @param isErrorOccurred flag to tell translator that error has occurred
+ * while code generation
* @throws IOException when failed to delete the temporary files
*/
@Override
@@ -119,9 +111,7 @@
/*
* Close constructor temporary file handle and delete the file.
*/
- closeFile(getConstructorImplTempFileHandle(), true);
-
+ closeFile(constructorImplTempFileHandle, true);
super.freeTemporaryResources(isErrorOccurred);
}
-
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index d73fa63..9fdd9c8 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -16,12 +16,12 @@
package org.onosproject.yangutils.translator.tojava;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+
+import java.io.IOException;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
@@ -55,12 +55,12 @@
/**
* Has the temporary files required for enumeration generated classes.
*/
- private TempJavaEnumerationFragmentFiles enumerationTempFiles;
+ private TempJavaEnumerationFragmentFiles enumTempFiles;
/**
* Has the temporary files required for enumeration generated classes.
*/
- private TempJavaEventFragmentFiles tempJavaEventFragmentFiles;
+ private TempJavaEventFragmentFiles eventTempFiles;
/**
* Creates an instance of temporary java code fragment.
@@ -71,26 +71,26 @@
public TempJavaCodeFragmentFiles(JavaFileInfoTranslator javaFileInfo)
throws IOException {
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
- setBeanTempFiles(new TempJavaBeanFragmentFiles(javaFileInfo));
+ int genType = javaFileInfo.getGeneratedFileTypes();
+ if ((genType & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
+ beanTempFiles = new TempJavaBeanFragmentFiles(javaFileInfo);
}
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_TYPE_CLASS) != 0) {
- setTypeTempFiles(new TempJavaTypeFragmentFiles(javaFileInfo));
+ if ((genType & GENERATE_TYPE_CLASS) != 0) {
+ typeTempFiles = new TempJavaTypeFragmentFiles(javaFileInfo);
}
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ENUM_CLASS) != 0) {
- setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo));
+ if ((genType & GENERATE_ENUM_CLASS) != 0) {
+ enumTempFiles = new TempJavaEnumerationFragmentFiles(javaFileInfo);
}
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
- setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
+ if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
+ serviceTempFiles = new TempJavaServiceFragmentFiles(javaFileInfo);
}
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
- setEventFragmentFiles(new TempJavaEventFragmentFiles(javaFileInfo));
+ if ((genType & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
+ eventTempFiles = new TempJavaEventFragmentFiles(javaFileInfo);
}
-
}
/**
@@ -103,15 +103,6 @@
}
/**
- * Sets temp file handle for bean file generation.
- *
- * @param beanTempFiles temp file handle for bean file generation
- */
- private void setBeanTempFiles(TempJavaBeanFragmentFiles beanTempFiles) {
- this.beanTempFiles = beanTempFiles;
- }
-
- /**
* Retrieves the temp file handle for data type file generation.
*
* @return temp file handle for data type file generation
@@ -120,14 +111,6 @@
return typeTempFiles;
}
- /**
- * Sets temp file handle for data type file generation.
- *
- * @param typeTempFiles temp file handle for data type file generation
- */
- private void setTypeTempFiles(TempJavaTypeFragmentFiles typeTempFiles) {
- this.typeTempFiles = typeTempFiles;
- }
/**
* Retrieves the temp file handle for service file generation.
@@ -139,31 +122,12 @@
}
/**
- * Sets temp file handle for service file generation.
- *
- * @param serviceTempFiles temp file handle for service file generation
- */
- private void setServiceTempFiles(TempJavaServiceFragmentFiles serviceTempFiles) {
- this.serviceTempFiles = serviceTempFiles;
- }
-
- /**
* Retrieves the temp file handle for enumeration file generation.
*
* @return temp file handle for enumeration file generation
*/
- public TempJavaEnumerationFragmentFiles getEnumerationTempFiles() {
- return enumerationTempFiles;
- }
-
- /**
- * Sets temp file handle for enumeration file generation.
- *
- * @param enumerationTempFiles temp file handle for enumeration file generation
- */
- private void setEnumerationTempFiles(
- TempJavaEnumerationFragmentFiles enumerationTempFiles) {
- this.enumerationTempFiles = enumerationTempFiles;
+ public TempJavaEnumerationFragmentFiles getEnumTempFiles() {
+ return enumTempFiles;
}
/**
@@ -172,20 +136,10 @@
* @return temp file handle for enumeration file generation
*/
public TempJavaEventFragmentFiles getEventFragmentFiles() {
- return tempJavaEventFragmentFiles;
+ return eventTempFiles;
}
/**
- * Sets temp file handle for event file generation.
- *
- * @param tempJavaEventFragmentFiles temp file handle for event file generation
- */
- private void setEventFragmentFiles(TempJavaEventFragmentFiles tempJavaEventFragmentFiles) {
- this.tempJavaEventFragmentFiles = tempJavaEventFragmentFiles;
- }
-
-
- /**
* Constructs java code exit.
*
* @param fileType generated file type
@@ -196,35 +150,35 @@
throws IOException {
if ((fileType & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
- getBeanTempFiles().generateJavaFile(fileType, curNode);
+ beanTempFiles.generateJavaFile(fileType, curNode);
}
/*
* Creates user defined data type class file.
*/
if ((fileType & GENERATE_TYPE_CLASS) != 0) {
- getTypeTempFiles().generateJavaFile(fileType, curNode);
+ typeTempFiles.generateJavaFile(fileType, curNode);
}
/*
* Creates service and manager class file.
*/
if (fileType == GENERATE_SERVICE_AND_MANAGER) {
- getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
+ serviceTempFiles.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
}
/*
* Creates event, event listener and event subject files.
*/
if (fileType == GENERATE_ALL_EVENT_CLASS_MASK) {
- getEventFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, curNode);
+ eventTempFiles.generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, curNode);
}
/*
* Creates enumeration class file.
*/
if (fileType == GENERATE_ENUM_CLASS) {
- getEnumerationTempFiles().generateJavaFile(GENERATE_ENUM_CLASS, curNode);
+ enumTempFiles.generateJavaFile(GENERATE_ENUM_CLASS, curNode);
}
}
@@ -232,14 +186,13 @@
* Add all the type in the current data model node as part of the
* generated temporary file.
*
- * @param yangTypeHolder YANG java data model node which has type info, eg union / typedef
- * @param pluginConfig plugin configurations for naming convention
+ * @param typeHolder YANG java data model node which has type info, eg union / typedef
+ * @param config plugin configurations for naming convention
* @throws IOException IO operation fail
*/
- void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig pluginConfig)
+ void addTypeInfoToTempFiles(YangTypeHolder typeHolder, YangPluginConfig config)
throws IOException {
- getTypeTempFiles()
- .addTypeInfoToTempFiles(yangTypeHolder, pluginConfig);
+ typeTempFiles.addTypeInfoToTempFiles(typeHolder, config);
}
/**
@@ -251,8 +204,8 @@
*/
public String addBuildMethodForInterface(YangPluginConfig pluginConfig)
throws IOException {
- if (getBeanTempFiles() != null) {
- return getBeanTempFiles().addBuildMethodForInterface(pluginConfig);
+ if (beanTempFiles != null) {
+ return beanTempFiles.addBuildMethodForInterface();
}
throw new TranslatorException("build method only supported for bean class");
}
@@ -260,27 +213,24 @@
/**
* Adds default constructor for class.
*
- * @param modifier modifier for constructor.
- * @param toAppend string which need to be appended with the class name
- * @param pluginConfig plugin configurations
- * @param curNode YANG node
+ * @param modifier modifier for constructor.
+ * @param toAppend string which need to be appended with the class name
* @return default constructor for class
* @throws IOException when fails to append to file
*/
- public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig,
- YangNode curNode)
+ public String addDefaultConstructor(String modifier, String toAppend)
throws IOException {
boolean isSuffix = false;
if (toAppend.equals(BUILDER)) {
isSuffix = true;
}
- if (getTypeTempFiles() != null) {
- return getTypeTempFiles()
- .addDefaultConstructor(modifier, toAppend, pluginConfig, isSuffix);
+ if (typeTempFiles != null) {
+ return typeTempFiles.addDefaultConstructor(modifier, toAppend,
+ isSuffix);
}
-
- if (getBeanTempFiles() != null) {
- return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig, isSuffix);
+ if (beanTempFiles != null) {
+ return beanTempFiles.addDefaultConstructor(modifier, toAppend,
+ isSuffix);
}
throw new TranslatorException("default constructor should not be added");
@@ -289,49 +239,46 @@
/**
* Adds build method's implementation for class.
*
- * @param curNode YANG node
* @return build method implementation for class
* @throws IOException when fails to append to temporary file
*/
- public String addBuildMethodImpl(YangNode curNode)
+ public String addBuildMethodImpl()
throws IOException {
- if (getBeanTempFiles() != null) {
- return getBeanTempFiles().addBuildMethodImpl();
+ if (beanTempFiles != null) {
+ return beanTempFiles.addBuildMethodImpl();
}
-
throw new TranslatorException("build should not be added");
}
/**
* Removes all temporary file handles.
+ * when translator fails to generate java files we need to close
+ * all open file handles include temporary files and java files
*
- * @param isErrorOccurred when translator fails to generate java files we need to close
- * all open file handles include temporary files and java files.
+ * @param isErrorOccurred if error occurred
* @throws IOException when failed to delete the temporary files
*/
void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
- if (getBeanTempFiles() != null) {
- getBeanTempFiles().freeTemporaryResources(isErrorOccurred);
+ if (beanTempFiles != null) {
+ beanTempFiles.freeTemporaryResources(isErrorOccurred);
}
- if (getTypeTempFiles() != null) {
- getTypeTempFiles().freeTemporaryResources(isErrorOccurred);
+ if (typeTempFiles != null) {
+ typeTempFiles.freeTemporaryResources(isErrorOccurred);
}
- if (getEnumerationTempFiles() != null) {
- getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred);
+ if (enumTempFiles != null) {
+ enumTempFiles.freeTemporaryResources(isErrorOccurred);
}
- if (getServiceTempFiles() != null) {
- getServiceTempFiles().freeTemporaryResources(isErrorOccurred);
+ if (serviceTempFiles != null) {
+ serviceTempFiles.freeTemporaryResources(isErrorOccurred);
}
- if (getEventFragmentFiles() != null) {
- getEventFragmentFiles().freeTemporaryResources(isErrorOccurred);
+ if (eventTempFiles != null) {
+ eventTempFiles.freeTemporaryResources(isErrorOccurred);
}
-
}
-
}
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 12dc41c..1650395 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
@@ -15,9 +15,6 @@
*/
package org.onosproject.yangutils.translator.tojava;
-import java.io.File;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangNode;
@@ -25,11 +22,13 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.File;
+import java.io.IOException;
+
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen
- .generateEnumAttributeStringWithSchemaName;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeStringWithSchemaName;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
@@ -52,14 +51,9 @@
private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
/**
- * File name for enum class file name suffix.
- */
- private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
-
- /**
* Temporary file handle for enum class file.
*/
- private File enumClassTempFileHandle;
+ private final File enumClassTempFileHandle;
/**
* Java file handle for enum class.
@@ -80,25 +74,7 @@
* Initialize enum when generation file type matches to enum class mask.
*/
addGeneratedTempFile(ENUM_IMPL_MASK);
- setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME));
- }
-
- /**
- * Returns enum class java file handle.
- *
- * @return enum class java file handle
- */
- private File getEnumClassJavaFileHandle() {
- return enumClassJavaFileHandle;
- }
-
- /**
- * Sets enum class java file handle.
- *
- * @param enumClassJavaFileHandle enum class java file handle
- */
- private void setEnumClassJavaFileHandle(File enumClassJavaFileHandle) {
- this.enumClassJavaFileHandle = enumClassJavaFileHandle;
+ enumClassTempFileHandle = getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME);
}
/**
@@ -111,72 +87,66 @@
}
/**
- * Sets temporary file handle for enum class file.
- *
- * @param enumClassTempFileHandle temporary file handle for enum class file
- */
- private void setEnumClassTempFileHandle(File enumClassTempFileHandle) {
- this.enumClassTempFileHandle = enumClassTempFileHandle;
- }
-
- /**
* Adds enum class attributes to temporary file.
*
* @param yangEnum YANG enum
* @throws IOException when fails to do IO operations.
*/
- private void addAttributesForEnumClass(YangPluginConfig pluginConfig, YangEnum yangEnum)
+ private void addAttributesForEnumClass(YangEnum yangEnum)
throws IOException {
- appendToFile(getEnumClassTempFileHandle(),
+ appendToFile(enumClassTempFileHandle,
generateEnumAttributeStringWithSchemaName(yangEnum.getNamedValue(),
- yangEnum.getValue(), pluginConfig));
+ yangEnum.getValue()));
}
/**
* Adds enum attributes to temporary files.
*
- * @param curNode current YANG node
- * @param pluginConfig plugin configurations
+ * @param curNode current YANG node
+ * @param config plugin configurations
* @throws IOException when fails to do IO operations
*/
- void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig pluginConfig)
+ void addEnumAttributeToTempFiles(YangNode curNode, YangPluginConfig config)
throws IOException {
- super.addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(pluginConfig), pluginConfig);
+ addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(config),
+ config);
if (curNode instanceof YangEnumeration) {
YangEnumeration enumeration = (YangEnumeration) curNode;
for (YangEnum curEnum : enumeration.getEnumSet()) {
String enumName = curEnum.getNamedValue();
- String prefixForIdentifier;
+ String prefix;
if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) {
- prefixForIdentifier = getPrefixForIdentifier(pluginConfig.getConflictResolver());
- if (prefixForIdentifier != null) {
- curEnum.setNamedValue(prefixForIdentifier + enumName);
+ prefix = getPrefixForIdentifier(
+ config.getConflictResolver());
+ if (prefix != null) {
+ curEnum.setNamedValue(prefix + enumName);
} else {
curEnum.setNamedValue(YANG_AUTO_PREFIX + enumName);
}
}
- addJavaSnippetInfoToApplicableTempFiles(pluginConfig, curEnum);
+ addJavaSnippetInfoToApplicableTempFiles(curEnum);
}
} else {
- throw new TranslatorException("current node should be of enumeration type. " +
- curNode.getName() + " in " + curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ throw new TranslatorException(
+ "current node should be of enumeration type. " +
+ curNode.getName() + " in " + curNode.getLineNumber() +
+ " at " + curNode.getCharPosition() + " in " + curNode
+ .getFileName());
}
}
/**
* Returns java attribute for enum class.
*
- * @param pluginConfig plugin configurations
+ * @param config plugin configurations
* @return java attribute
*/
- private JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
+ private JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig config) {
YangJavaTypeTranslator javaType = new YangJavaTypeTranslator();
javaType.setDataType(INT32);
javaType.setDataTypeName(INT);
- javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
+ javaType.updateJavaQualifiedInfo(config.getConflictResolver());
return getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
javaType.getDataTypeName(), javaType,
@@ -187,11 +157,11 @@
/**
* Adds the new attribute info to the target generated temporary files.
*
- * @param yangEnum@throws IOException IO operation fail
+ * @param yangEnum @throws IOException IO operation fail
*/
- private void addJavaSnippetInfoToApplicableTempFiles(YangPluginConfig pluginConfig, YangEnum yangEnum)
+ private void addJavaSnippetInfoToApplicableTempFiles(YangEnum yangEnum)
throws IOException {
- addAttributesForEnumClass(pluginConfig, yangEnum);
+ addAttributesForEnumClass(yangEnum);
}
/**
@@ -205,8 +175,8 @@
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
createPackage(curNode);
- setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
- setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
+ enumClassJavaFileHandle = getJavaFileHandle(getJavaClassName(EMPTY_STRING));
+ generateEnumClassFile(enumClassJavaFileHandle, curNode);
freeTemporaryResources(false);
}
@@ -219,9 +189,8 @@
@Override
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
- closeFile(getEnumClassJavaFileHandle(), isErrorOccurred);
- closeFile(getEnumClassTempFileHandle(), true);
+ closeFile(enumClassJavaFileHandle, isErrorOccurred);
+ closeFile(enumClassTempFileHandle, true);
super.freeTemporaryResources(isErrorOccurred);
}
-
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
index 6235b52..4c5d69b 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
@@ -16,15 +16,15 @@
package org.onosproject.yangutils.translator.tojava;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
@@ -42,8 +42,8 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
@@ -54,7 +54,6 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
/**
* Represent temporary java fragments for event files.
@@ -79,27 +78,20 @@
/**
* File name for event subject attribute temp file.
*/
- private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME = "EventSubjectAttribute";
+ private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME
+ = "EventSubjectAttribute";
/**
* File name for event subject getter temp file.
*/
- private static final String EVENT_SUBJECT_GETTER_FILE_NAME = "EventSubjectGetter";
+ private static final String EVENT_SUBJECT_GETTER_FILE_NAME
+ = "EventSubjectGetter";
/**
* File name for event subject setter temp file.
*/
- private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter";
-
- /**
- * File name for generated class file for special type like union, typedef suffix.
- */
- private static final String EVENT_FILE_NAME_SUFFIX = "Event";
-
- /**
- * File name for generated class file for special type like union, typedef suffix.
- */
- private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "EventListener";
+ private static final String EVENT_SUBJECT_SETTER_FILE_NAME
+ = "EventSubjectSetter";
private static final String JAVA_FILE_EXTENSION = ".java";
@@ -121,27 +113,27 @@
/**
* Java file handle for event enum impl file.
*/
- private File eventEnumTempFileHandle;
+ private final File eventEnumTempFileHandle;
/**
* Java file handle for event method impl file.
*/
- private File eventMethodTempFileHandle;
+ private final File eventMethodTempFileHandle;
/**
* Java file handle for event subject attribute file.
*/
- private File eventSubjectAttributeTempFileHandle;
+ private final File eventSubjectAttributeTempFileHandle;
/**
* Java file handle for event subject getter impl file.
*/
- private File eventSubjectGetterTempFileHandle;
+ private final File eventSubjectGetterTempFileHandle;
/**
* Java file handle for event subject setter impl file.
*/
- private File eventSubjectSetterTempFileHandle;
+ private final File eventSubjectSetterTempFileHandle;
/**
* Creates an instance of temporary java code fragment.
@@ -154,8 +146,9 @@
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
- setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
+ setAbsoluteDirPath(getAbsolutePackagePath(
+ getJavaFileInfo().getBaseCodeGenPath(),
+ getJavaFileInfo().getPackageFilePath()));
addGeneratedTempFile(EVENT_ENUM_MASK);
addGeneratedTempFile(EVENT_METHOD_MASK);
@@ -163,11 +156,60 @@
addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
- setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME));
- setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME));
- setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME));
- setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME));
- setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME));
+ eventEnumTempFileHandle = getTemporaryFileHandle(EVENT_ENUM_FILE_NAME);
+ eventMethodTempFileHandle = getTemporaryFileHandle(
+ EVENT_METHOD_FILE_NAME);
+ eventSubjectAttributeTempFileHandle = getTemporaryFileHandle
+ (EVENT_SUBJECT_ATTRIBUTE_FILE_NAME);
+ eventSubjectGetterTempFileHandle = getTemporaryFileHandle(
+ EVENT_SUBJECT_GETTER_FILE_NAME);
+ eventSubjectSetterTempFileHandle = getTemporaryFileHandle(
+ EVENT_SUBJECT_SETTER_FILE_NAME);
+ }
+
+ /**
+ * Returns event enum temp file.
+ *
+ * @return event enum temp file
+ */
+ public File getEventEnumTempFileHandle() {
+ return eventEnumTempFileHandle;
+ }
+
+ /**
+ * Returns event method temp file.
+ *
+ * @return event method temp file
+ */
+ public File getEventMethodTempFileHandle() {
+ return eventMethodTempFileHandle;
+ }
+
+ /**
+ * Returns event subject attribute temp file.
+ *
+ * @return event subject attribute temp file
+ */
+ public File getEventSubjectAttributeTempFileHandle() {
+ return eventSubjectAttributeTempFileHandle;
+ }
+
+ /**
+ * Returns event subject getter temp file.
+ *
+ * @return event subject getter temp file
+ */
+ public File getEventSubjectGetterTempFileHandle() {
+ return eventSubjectGetterTempFileHandle;
+ }
+
+ /**
+ * Returns event subject setter temp file.
+ *
+ * @return event subject setter temp file
+ */
+ public File getEventSubjectSetterTempFileHandle() {
+ return eventSubjectSetterTempFileHandle;
}
/*Adds event method contents to event file.*/
@@ -179,7 +221,8 @@
" * @param type event type\n" +
" * @param subject subject " + classname + "\n" +
" */\n" +
- " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
+ " public " + eventClassname + "(Type type, " +
+ getCapitalCase(classname) + " subject) {\n" +
" super(type, subject);\n" +
" }\n" +
"\n" +
@@ -197,60 +240,6 @@
"\n";
}
- /**
- * Returns event's java file handle.
- *
- * @return java file handle
- */
- private File getEventJavaFileHandle() {
- return eventJavaFileHandle;
- }
-
- /**
- * Sets event's java file handle.
- *
- * @param eventJavaFileHandle file handle for event
- */
- private void setEventJavaFileHandle(File eventJavaFileHandle) {
- this.eventJavaFileHandle = eventJavaFileHandle;
- }
-
- /**
- * Returns event listeners's java file handle.
- *
- * @return java file handle
- */
- private File getEventListenerJavaFileHandle() {
- return eventListenerJavaFileHandle;
- }
-
- /**
- * Sets event's java file handle.
- *
- * @param eventListenerJavaFileHandle file handle for event
- */
- private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
- this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
- }
-
- /**
- * Returns event subject's java file handle.
- *
- * @return java file handle
- */
- private File getEventSubjectJavaFileHandle() {
- return eventSubjectJavaFileHandle;
- }
-
- /**
- * Sets event's subject java file handle.
- *
- * @param eventSubjectJavaFileHandle file handle for event's subject
- */
- private void setEventSubjectJavaFileHandle(File eventSubjectJavaFileHandle) {
- this.eventSubjectJavaFileHandle = eventSubjectJavaFileHandle;
- }
-
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
generateEventJavaFile(curNode);
@@ -273,15 +262,16 @@
List<String> imports = new ArrayList<>();
imports.add(getJavaImportData().getAbstractEventsImport());
- String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName());
+ String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo().getJavaName());
String nodeName = curNodeInfo + EVENT_STRING;
addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX);
//Creates event interface file.
- setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX));
- generateEventFile(getEventJavaFileHandle(), curNode, imports);
-
+ eventJavaFileHandle = getJavaFileHandle(curNode, curNodeInfo +
+ EVENT_STRING);
+ generateEventFile(eventJavaFileHandle, curNode, imports);
}
/**
@@ -300,10 +290,9 @@
.getJavaFileInfo().getJavaName());
// Creates event listener interface file.
- setEventListenerJavaFileHandle(
- getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
- generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports);
-
+ eventListenerJavaFileHandle =
+ getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER);
+ generateEventListenerFile(eventListenerJavaFileHandle, curNode, imports);
}
/**
@@ -319,100 +308,9 @@
.getJavaFileInfo().getJavaName());
//Creates event interface file.
- setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo +
- EVENT_SUBJECT_NAME_SUFFIX));
- generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode);
-
- }
-
- /**
- * Returns event enum temp file.
- *
- * @return event enum temp file
- */
- public File getEventEnumTempFileHandle() {
- return eventEnumTempFileHandle;
- }
-
- /**
- * Sets event enum temp file.
- *
- * @param eventEnumTempFileHandle event enum temp file
- */
- private void setEventEnumTempFileHandle(File eventEnumTempFileHandle) {
- this.eventEnumTempFileHandle = eventEnumTempFileHandle;
- }
-
- /**
- * Returns event method temp file.
- *
- * @return event method temp file
- */
- public File getEventMethodTempFileHandle() {
- return eventMethodTempFileHandle;
- }
-
- /**
- * Sets event method temp file.
- *
- * @param eventMethodTempFileHandle event method temp file
- */
- private void setEventMethodTempFileHandle(File eventMethodTempFileHandle) {
- this.eventMethodTempFileHandle = eventMethodTempFileHandle;
- }
-
- /**
- * Returns event subject attribute temp file.
- *
- * @return event subject attribute temp file
- */
- public File getEventSubjectAttributeTempFileHandle() {
- return eventSubjectAttributeTempFileHandle;
- }
-
- /**
- * Sets event subject attribute temp file.
- *
- * @param eventSubjectAttributeTempFileHandle event subject attribute temp file
- */
- private void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) {
- this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle;
- }
-
- /**
- * Returns event subject getter temp file.
- *
- * @return event subject getter temp file
- */
- public File getEventSubjectGetterTempFileHandle() {
- return eventSubjectGetterTempFileHandle;
- }
-
- /**
- * Sets event subject getter temp file.
- *
- * @param eventSubjectGetterTempFileHandle event subject getter temp file
- */
- private void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) {
- this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle;
- }
-
- /**
- * Returns event subject setter temp file.
- *
- * @return event subject setter temp file
- */
- public File getEventSubjectSetterTempFileHandle() {
- return eventSubjectSetterTempFileHandle;
- }
-
- /**
- * Sets event subject setter temp file.
- *
- * @param eventSubjectSetterTempFileHandle event subject setter temp file
- */
- private void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) {
- this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle;
+ eventSubjectJavaFileHandle = getJavaFileHandle(curNode, curNodeInfo +
+ EVENT_SUBJECT_NAME_SUFFIX);
+ generateEventSubjectFile(eventSubjectJavaFileHandle, curNode);
}
/**
@@ -425,67 +323,74 @@
void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
throws IOException {
- String currentInfo = getCapitalCase(getCamelCase(curNode.getName(),
- pluginConfig.getConflictResolver()));
+ String currentInfo = getCamelCase(curNode.getName(), pluginConfig
+ .getConflictResolver());
String notificationName = curNode.getName();
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
- getCapitalCase(currentInfo));
+ JavaQualifiedTypeInfoTranslator qualifiedTypeInfo
+ = getQualifiedTypeInfoOfCurNode(curNode, getCapitalCase(currentInfo));
- JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo),
- null, false, false);
+ JavaAttributeInfo javaAttributeInfo
+ = getAttributeInfoForTheData(qualifiedTypeInfo, currentInfo,
+ null, false, false);
/*Adds java info for event in respective temp files.*/
addEventEnum(notificationName);
- addEventSubjectAttribute(javaAttributeInfo, pluginConfig);
- addEventSubjectGetter(javaAttributeInfo, pluginConfig);
- addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo);
+ addEventSubjectAttribute(javaAttributeInfo);
+ addEventSubjectGetter(javaAttributeInfo);
+ addEventSubjectSetter(javaAttributeInfo, currentInfo);
}
/*Adds event to enum temp file.*/
private void addEventEnum(String notificationName)
throws IOException {
- appendToFile(getEventEnumTempFileHandle(),
- enumJavaDocForInnerClass(notificationName) + EIGHT_SPACE_INDENTATION
- + getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE);
+ appendToFile(getEventEnumTempFileHandle(), enumJavaDocForInnerClass(
+ notificationName) + EIGHT_SPACE_INDENTATION
+ + getEnumJavaAttribute(notificationName).toUpperCase() +
+ COMMA + NEW_LINE);
}
/*Adds event method in event class*/
private void addEnumMethod(String eventClassname, String className)
throws IOException {
- appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className));
+ appendToFile(getEventMethodTempFileHandle(),
+ getEventFileContents(eventClassname, className));
}
/*Adds events to event subject file.*/
- private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ private void addEventSubjectAttribute(JavaAttributeInfo attr)
throws IOException {
appendToFile(getEventSubjectAttributeTempFileHandle(),
- FOUR_SPACE_INDENTATION + parseAttribute(attr, pluginConfig));
+ parseAttribute(attr));
}
/*Adds getter method for event in event subject class.*/
- private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ private void addEventSubjectGetter(JavaAttributeInfo attr)
throws IOException {
String appDataStructure = null;
if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ appDataStructure = attr.getCompilerAnnotation()
+ .getYangAppDataStructure().getDataStructure().name();
}
- appendToFile(getEventSubjectGetterTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
- appDataStructure) + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
+ appendToFile(getEventSubjectGetterTempFileHandle(), getJavaDoc(
+ GETTER_METHOD, attr.getAttributeName(), false,
+ appDataStructure) + getGetterForClass(
+ attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
}
/*Adds setter method for event in event subject class.*/
- private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className)
+ private void addEventSubjectSetter(JavaAttributeInfo attr,
+ String className)
throws IOException {
String appDataStructure = null;
if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ appDataStructure = attr.getCompilerAnnotation()
+ .getYangAppDataStructure().getDataStructure().name();
}
- appendToFile(getEventSubjectSetterTempFileHandle(),
- getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
- appDataStructure) + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS)
- + NEW_LINE);
+ appendToFile(getEventSubjectSetterTempFileHandle(), getJavaDoc(
+ MANAGER_SETTER_METHOD, attr.getAttributeName(),
+ false, appDataStructure) + getSetterForClass(
+ attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
}
/**
@@ -493,12 +398,11 @@
*
* @param name file name
* @return temporary file handle
- * @throws IOException when fails to create new file handle
*/
- private File getJavaFileHandle(YangNode curNode, String name)
- throws IOException {
+ private File getJavaFileHandle(YangNode curNode, String name) {
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo();
return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
parentInfo);
}
@@ -509,7 +413,8 @@
* @return directory path
*/
private String getDirPath(JavaFileInfoTranslator parentInfo) {
- return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase();
+ return (parentInfo.getPackageFilePath() + SLASH +
+ parentInfo.getJavaName()).toLowerCase();
}
/**
@@ -522,17 +427,16 @@
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
- closeFile(getEventJavaFileHandle(), isErrorOccurred);
- closeFile(getEventListenerJavaFileHandle(), isErrorOccurred);
- closeFile(getEventSubjectJavaFileHandle(), isErrorOccurred);
+ closeFile(eventJavaFileHandle, isErrorOccurred);
+ closeFile(eventListenerJavaFileHandle, isErrorOccurred);
+ closeFile(eventSubjectJavaFileHandle, isErrorOccurred);
- closeFile(getEventEnumTempFileHandle(), true);
- closeFile(getEventSubjectAttributeTempFileHandle(), true);
- closeFile(getEventMethodTempFileHandle(), true);
- closeFile(getEventSubjectGetterTempFileHandle(), true);
- closeFile(getEventSubjectSetterTempFileHandle(), true);
+ closeFile(eventEnumTempFileHandle, true);
+ closeFile(eventSubjectAttributeTempFileHandle, true);
+ closeFile(eventMethodTempFileHandle, true);
+ closeFile(eventSubjectGetterTempFileHandle, true);
+ closeFile(eventSubjectSetterTempFileHandle, true);
super.freeTemporaryResources(isErrorOccurred);
-
}
}
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 aba6454..4cba71d 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
@@ -43,7 +43,6 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
@@ -68,7 +67,6 @@
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
@@ -85,11 +83,11 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForNode;
@@ -101,7 +99,9 @@
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
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.DEFAULT;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
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.INTERFACE;
@@ -385,7 +385,7 @@
/**
* Leaf count.
*/
- private int leafCount = 0;
+ private int leafCount;
/**
* If current node is root node.
@@ -406,17 +406,16 @@
/**
* Creates an instance of temporary java code fragment.
*
- * @param javaFileInfo generated java file information
+ * @param fileInfo generated java file information
* @throws IOException when fails to create new file handle
*/
- protected TempJavaFragmentFiles(JavaFileInfoTranslator javaFileInfo)
+ protected TempJavaFragmentFiles(JavaFileInfoTranslator fileInfo)
throws IOException {
javaExtendsListHolder = new JavaExtendsListHolder();
javaImportData = new JavaImportData();
- this.javaFileInfo = javaFileInfo;
- absoluteDirPath =
- getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(),
- javaFileInfo.getPackageFilePath());
+ javaFileInfo = fileInfo;
+ absoluteDirPath = getAbsolutePackagePath(fileInfo.getBaseCodeGenPath(),
+ fileInfo.getPackageFilePath());
/*
* Initialize getter when generation file type matches to interface
* mask.
@@ -605,8 +604,8 @@
((JavaFileInfoContainer) targetNode).getJavaFileInfo();
boolean qualified;
- if ((tempFiles instanceof TempJavaServiceFragmentFiles) &&
- (typeInfo.getClassInfo().contentEquals(SERVICE)) ||
+ if (tempFiles instanceof TempJavaServiceFragmentFiles &&
+ typeInfo.getClassInfo().contentEquals(SERVICE) ||
typeInfo.getClassInfo()
.contentEquals(getCapitalCase(fileInfo.getJavaName() +
SERVICE))) {
@@ -645,7 +644,7 @@
}
}
}
- if (listNode && !(collectionSet)) {
+ if (listNode && !collectionSet) {
parentImportData.setIfListImported(true);
}
if (curNode instanceof YangList) {
@@ -890,8 +889,8 @@
*
* @param holder java extends list holder
*/
- protected void setJavaExtendsListHolder(JavaExtendsListHolder
- holder) {
+ protected void setJavaExtendsListHolder(
+ JavaExtendsListHolder holder) {
javaExtendsListHolder = holder;
}
@@ -935,45 +934,38 @@
/**
* Adds attribute for class.
*
- * @param attr attribute info
- * @param config plugin configurations
+ * @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- private void addAttribute(JavaAttributeInfo attr,
- YangPluginConfig config)
+ private void addAttribute(JavaAttributeInfo attr)
throws IOException {
- appendToFile(attributesTempFileHandle, parseAttribute(attr, config) +
- FOUR_SPACE_INDENTATION);
+ appendToFile(attributesTempFileHandle, parseAttribute(attr));
}
/**
* Adds getter for interface.
*
- * @param attr attribute info
- * @param config plugin configurations
+ * @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- private void addGetterForInterface(JavaAttributeInfo attr,
- YangPluginConfig config)
+ private void addGetterForInterface(JavaAttributeInfo attr)
throws IOException {
appendToFile(getterInterfaceTempFileHandle,
- getGetterString(attr, getGeneratedJavaFiles(), config) +
+ getGetterString(attr, getGeneratedJavaFiles()) +
NEW_LINE);
}
/**
* Adds setter for interface.
*
- * @param attr attribute info
- * @param config plugin configurations
+ * @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- private void addSetterForInterface(JavaAttributeInfo attr,
- YangPluginConfig config)
+ private void addSetterForInterface(JavaAttributeInfo attr)
throws IOException {
appendToFile(setterInterfaceTempFileHandle,
getSetterString(attr, getGeneratedJavaClassName(),
- getGeneratedJavaFiles(), config) +
+ getGeneratedJavaFiles()) +
NEW_LINE);
}
@@ -983,16 +975,14 @@
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- private void addSetterImpl(JavaAttributeInfo attr,
- YangPluginConfig config)
+ private void addSetterImpl(JavaAttributeInfo attr)
throws IOException {
- String setter =
- getSetterForClass(attr, getGeneratedJavaClassName(),
- getGeneratedJavaFiles()) + NEW_LINE;
+ String setter = getSetterForClass(attr, getGeneratedJavaClassName(),
+ getGeneratedJavaFiles());
if (rootNode) {
appendToFile(setterImplTempFileHandle,
getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
- attr.isListAttr(), config, null) + setter);
+ attr.isListAttr(), null) + setter);
} else {
appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
}
@@ -1001,16 +991,13 @@
/**
* Adds getter method's impl for class.
*
- * @param attr attribute info
- * @param config plugin configurations
+ * @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- protected void addGetterImpl(JavaAttributeInfo attr,
- YangPluginConfig config)
+ protected void addGetterImpl(JavaAttributeInfo attr)
throws IOException {
- String getter =
- getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE;
- if (javaFlagSet(BUILDER_CLASS_MASK | GENERATE_SERVICE_AND_MANAGER)) {
+ String getter = getGetterForClass(attr, getGeneratedJavaFiles());
+ if (javaFlagSet(BUILDER_CLASS_MASK)) {
if (!rootNode) {
appendToFile(getterImplTempFileHandle, getOverRideString() +
getter);
@@ -1024,26 +1011,22 @@
.getYangAppDataStructure().getDataStructure().name();
}
appendToFile(getterImplTempFileHandle,
- getJavaDoc(GETTER_METHOD,
- getCapitalCase(attr.getAttributeName()),
- false, config, appDataStructure) + getter);
+ getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
+ false, appDataStructure) + getter);
}
}
/**
* Adds add to list interface method.
*
- * @param attr attribute
- * @param config plugin configurations
+ * @param attr attribute
* @throws IOException when fails to do IO operations
*/
- private void addAddToListInterface(JavaAttributeInfo attr,
- YangPluginConfig config)
+ private void addAddToListInterface(JavaAttributeInfo attr)
throws IOException {
appendToFile(addToListInterfaceTempFileHandle,
- getJavaDoc(ADD_TO_LIST,
- getCapitalCase(attr.getAttributeName()), false,
- config, null) + getAddToListMethodInterface(
+ getJavaDoc(ADD_TO_LIST, attr.getAttributeName(), false,
+ null) + getAddToListMethodInterface(
attr, getGeneratedJavaClassName()) + NEW_LINE);
}
@@ -1076,14 +1059,13 @@
/**
* Adds build method for interface.
*
- * @param config plugin configurations
* @return build method for interface
* @throws IOException when fails to append to temporary file
*/
- protected String addBuildMethodForInterface(YangPluginConfig config)
+ protected String addBuildMethodForInterface()
throws IOException {
- return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(),
- config);
+ return parseBuilderInterfaceBuildMethodString(
+ getGeneratedJavaClassName());
}
/**
@@ -1102,26 +1084,24 @@
*
* @param modifier modifier for constructor
* @param toAppend string which need to be appended with the class name
- * @param config plugin configurations
* @param suffix is value need to be appended as suffix
* @return default constructor for class
* @throws IOException when fails to append to file
*/
protected String addDefaultConstructor(String modifier, String toAppend,
- YangPluginConfig config,
boolean suffix)
throws IOException {
StringBuilder name = new StringBuilder();
name.append(getGeneratedJavaClassName());
- String constructor = NEW_LINE +
- getDefaultConstructorString(name.toString(), modifier, config);
if (rootNode && !toAppend.equals(BUILDER)) {
name.append(OP_PARAM);
- return constructor;
+ return getDefaultConstructorString(name.toString(), modifier
+ );
}
if (suffix) {
name.append(toAppend);
- return constructor;
+ return getDefaultConstructorString(name.toString(), modifier
+ );
}
StringBuilder appended = new StringBuilder();
if (toAppend.equals(DEFAULT)) {
@@ -1130,7 +1110,7 @@
appended.append(toAppend);
}
return NEW_LINE + getDefaultConstructorString(appended.append(
- name.toString()).toString(), modifier, config);
+ name).toString(), modifier);
// TODO getDefaultConstructorString to handle new line.
}
@@ -1264,20 +1244,16 @@
/**
* Parses attribute to get the attribute string.
*
- * @param attr attribute info
- * @param config plugin configurations
+ * @param attr attribute info
* @return attribute string
*/
- protected String parseAttribute(JavaAttributeInfo attr,
- YangPluginConfig config) {
+ protected String parseAttribute(JavaAttributeInfo attr) {
/*
* TODO: check if this utility needs to be called or move to the caller
*/
- String attrName = getCamelCase(attr.getAttributeName(),
- config.getConflictResolver());
+ String attrName = attr.getAttributeName();
String attrAccessType = PRIVATE;
- if ((javaFileInfo.getGeneratedFileTypes() &
- GENERATE_INTERFACE_WITH_BUILDER) != 0) {
+ if ((getGeneratedJavaFiles() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
attrAccessType = PROTECTED;
}
String pkg = null;
@@ -1429,16 +1405,16 @@
throws IOException {
isAttributePresent = true;
if (tempFlagSet(ATTRIBUTES_MASK)) {
- addAttribute(newAttrInfo, pluginConfig);
+ addAttribute(newAttrInfo);
}
if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
- addGetterForInterface(newAttrInfo, pluginConfig);
+ addGetterForInterface(newAttrInfo);
}
if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
- addSetterForInterface(newAttrInfo, pluginConfig);
+ addSetterForInterface(newAttrInfo);
}
if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
- addSetterImpl(newAttrInfo, pluginConfig);
+ addSetterImpl(newAttrInfo);
}
if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
addHashCodeMethod(newAttrInfo);
@@ -1457,12 +1433,12 @@
addAddToListImpl(newAttrInfo);
}
if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK) && listAttr) {
- addAddToListInterface(newAttrInfo, pluginConfig);
+ addAddToListInterface(newAttrInfo);
}
YangType attrType = newAttrInfo.getAttributeType();
if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
attrType == null && !newAttrInfo.getAttributeName()
- .equals(OPERATION_TYPE_ATTRIBUTE)) {
+ .contains(OPERATION_TYPE_ATTRIBUTE)) {
addSubtreeFilteringForChildNode(newAttrInfo);
}
if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
@@ -1481,7 +1457,7 @@
if (!newAttrInfo.isIntConflict() && !newAttrInfo.isLongConflict() &&
!newAttrInfo.isShortConflict()) {
if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
- addGetterImpl(newAttrInfo, pluginConfig);
+ addGetterImpl(newAttrInfo);
}
if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
JavaQualifiedTypeInfoTranslator typeInfo =
@@ -1519,10 +1495,9 @@
*/
private String getImplClassName(YangNode node) {
if (node instanceof RpcNotificationContainer) {
- return getCapitalCase(javaFileInfo.getJavaName()) + OP_PARAM;
+ return getGeneratedJavaClassName() + OP_PARAM;
}
- return getCapitalCase(DEFAULT) +
- getCapitalCase(javaFileInfo.getJavaName());
+ return DEFAULT_CAPS + getGeneratedJavaClassName();
}
/**
@@ -1551,8 +1526,8 @@
createPackage(curNode);
//Generate java code.
- if ((fileType & INTERFACE_MASK) != 0 || (fileType &
- BUILDER_INTERFACE_MASK) != 0) {
+ if ((fileType & INTERFACE_MASK) != 0 ||
+ (fileType & BUILDER_INTERFACE_MASK) != 0) {
//Create interface file.
interfaceJavaFileHandle =
@@ -1579,8 +1554,7 @@
interfaceJavaFileHandle);
}
}
- insertDataIntoJavaFile(interfaceJavaFileHandle,
- getJavaClassDefClose());
+ insertDataIntoJavaFile(interfaceJavaFileHandle, CLOSE_CURLY_BRACKET);
validateLineLength(interfaceJavaFileHandle);
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, false, true, curNode);
@@ -1632,8 +1606,7 @@
mergeJavaFiles(builderClassJavaFileHandle,
implClassJavaFileHandle);
}
- insertDataIntoJavaFile(implClassJavaFileHandle,
- getJavaClassDefClose());
+ insertDataIntoJavaFile(implClassJavaFileHandle, CLOSE_CURLY_BRACKET);
validateLineLength(implClassJavaFileHandle);
}
//Close all the file handles.
@@ -1781,8 +1754,8 @@
* @param importInfo import info
* @return status of the qualified access to the attribute
*/
- protected boolean getIsQualifiedAccessOrAddToImportList(JavaQualifiedTypeInfo
- importInfo) {
+ protected boolean getIsQualifiedAccessOrAddToImportList(
+ JavaQualifiedTypeInfo importInfo) {
return javaImportData
.addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
getGeneratedJavaClassName(),
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 8d08754..1751ab5 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
@@ -16,29 +16,33 @@
package org.onosproject.yangutils.translator.tojava;
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangOutput;
+import org.onosproject.yangutils.datamodel.YangRpc;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import java.io.File;
import java.io.IOException;
import java.util.List;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
+import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addListenersImport;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.Operation.ADD;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
@@ -58,29 +62,14 @@
private static final String RPC_INTERFACE_FILE_NAME = "Rpc";
/**
- * File name for rpc implementation method.
- */
- private static final String RPC_IMPL_FILE_NAME = "RpcImpl";
-
- /**
- * File name for generated class file for service suffix.
- */
- private static final String SERVICE_FILE_NAME_SUFFIX = "Service";
-
- /**
* Temporary file handle for rpc interface.
*/
- private File rpcInterfaceTempFileHandle;
-
- /**
- * Temporary file handle for rpc manager impl.
- */
- private File rpcImplTempFileHandle;
+ private final File rpcInterfaceTempFileHandle;
/**
* Java file handle for rpc interface file.
*/
- private File serviceInterfaceJavaFileHandle;
+ private File serviceJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
@@ -97,11 +86,7 @@
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
addGeneratedTempFile(RPC_INTERFACE_MASK);
- addGeneratedTempFile(RPC_IMPL_MASK);
-
- rpcInterfaceTempFileHandle =
- getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME);
- rpcImplTempFileHandle = getTemporaryFileHandle(RPC_IMPL_FILE_NAME);
+ rpcInterfaceTempFileHandle = getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME);
}
/**
@@ -114,15 +99,6 @@
}
/**
- * Retrieves the manager impl temp file.
- *
- * @return the manager impl temp file
- */
- public File getRpcImplTempFileHandle() {
- return rpcImplTempFileHandle;
- }
-
- /**
* Constructs java code exit.
*
* @param fileType generated file type
@@ -152,13 +128,11 @@
}
if (notification) {
- addListenersImport(curNode, imports, ADD, LISTENER_SERVICE);
+ addListenersImport(curNode, imports, ADD);
}
- serviceInterfaceJavaFileHandle =
- getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX));
- generateServiceInterfaceFile(serviceInterfaceJavaFileHandle, curNode,
- imports);
+ serviceJavaFileHandle = getJavaFileHandle(getJavaClassName(SERVICE));
+ generateServiceInterfaceFile(serviceJavaFileHandle, curNode, imports);
// Close all the file handles.
freeTemporaryResources(false);
@@ -167,53 +141,131 @@
/**
* Adds rpc string information to applicable temp file.
*
- * @param inputAttr RPCs input node attribute info
- * @param outputAttr RPCs output node attribute info
- * @param rpcName name of the rpc function
- * @param config plugin configurations
+ * @param inAttr RPCs input node attribute info
+ * @param outAttr RPCs output node attribute info
+ * @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
- private void addRpcString(JavaAttributeInfo inputAttr,
- JavaAttributeInfo outputAttr,
- YangPluginConfig config, String rpcName)
- throws IOException {
+ private void addRpcString(JavaAttributeInfo inAttr, JavaAttributeInfo outAttr,
+ String rpcName) throws IOException {
String rpcInput = EMPTY_STRING;
String rpcOutput = VOID;
- String rpcInputJavaDoc = EMPTY_STRING;
- if (inputAttr != null) {
- rpcInput = getCapitalCase(inputAttr.getAttributeName());
+ String rpcIn = EMPTY_STRING;
+ if (inAttr != null) {
+ rpcInput = getCapitalCase(inAttr.getAttributeName());
}
- if (outputAttr != null) {
- rpcOutput = getCapitalCase(outputAttr.getAttributeName());
+ if (outAttr != null) {
+ rpcOutput = getCapitalCase(outAttr.getAttributeName());
}
if (!rpcInput.equals(EMPTY_STRING)) {
- rpcInputJavaDoc = RPC_INPUT_VAR_NAME;
+ rpcIn = RPC_INPUT_VAR_NAME;
}
appendToFile(rpcInterfaceTempFileHandle,
- generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput,
- config) +
- getRpcServiceMethod(rpcName, rpcInput, rpcOutput,
- config) + NEW_LINE);
- appendToFile(rpcImplTempFileHandle,
- getRpcManagerMethod(rpcName, rpcInput, rpcOutput, config) +
- NEW_LINE);
+ generateJavaDocForRpc(rpcName, rpcIn, rpcOutput) +
+ getRpcServiceMethod(rpcName, rpcInput, rpcOutput));
}
/**
* Adds the JAVA rpc snippet information.
*
- * @param inputAttr RPCs input node attribute info
- * @param outputAttr RPCs output node attribute info
- * @param config plugin configurations
- * @param rpcName name of the rpc function
+ * @param inAttr RPCs input node attribute info
+ * @param outAttr RPCs output node attribute info
+ * @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
- public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo inputAttr,
- JavaAttributeInfo outputAttr,
- YangPluginConfig config,
+ public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo inAttr,
+ JavaAttributeInfo outAttr,
String rpcName)
throws IOException {
- addRpcString(inputAttr, outputAttr, config, rpcName);
+ addRpcString(inAttr, outAttr, rpcName);
+ }
+
+ /**
+ * Creates an attribute info object corresponding to a data model node and
+ * return it.
+ *
+ * @param childNode child data model node(input / output) for which the java code generation
+ * is being handled
+ * @param parentNode parent node (module / sub-module) in which the child node is an attribute
+ * @return AttributeInfo attribute details required to add in temporary
+ * files
+ */
+ public JavaAttributeInfo getChildNodeAsAttributeInParentService(
+ YangNode childNode, YangNode parentNode) {
+
+ String childNodeName = ((JavaFileInfoContainer) childNode)
+ .getJavaFileInfo().getJavaName();
+ /*
+ * Get the import info corresponding to the attribute for import in
+ * generated java files or qualified access
+ */
+ JavaQualifiedTypeInfoTranslator qualifiedTypeInfo =
+ getQualifiedTypeInfoOfCurNode(childNode,
+ getCapitalCase(childNodeName));
+ if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
+ throw new TranslatorException("Parent node does not have file info");
+ }
+
+ boolean isQualified = addImportToService(qualifiedTypeInfo, parentNode);
+ return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName,
+ null, isQualified, false);
+ }
+
+ /**
+ * Adds to service class import list.
+ *
+ * @param importInfo import info
+ * @return true or false
+ */
+ private boolean addImportToService(
+ JavaQualifiedTypeInfoTranslator importInfo, YangNode curNode) {
+ JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo();
+ String name = fileInfo.getJavaName();
+ String clsInfo = importInfo.getClassInfo();
+
+ StringBuilder className = new StringBuilder()
+ .append(getCapitalCase(name))
+ .append(SERVICE);
+ return clsInfo.contentEquals(SERVICE) || clsInfo.contentEquals(className) ||
+ getJavaImportData().addImportInfo(importInfo, className.toString(),
+ fileInfo.getPackage());
+ }
+
+ /**
+ * Adds augmented rpc methods to service temp file.
+ *
+ * @param module root node
+ * @throws IOException when fails to do IO operations
+ */
+ public void addAugmentedRpcMethod(RpcNotificationContainer module)
+ throws IOException {
+ JavaAttributeInfo in = null;
+ JavaAttributeInfo out = null;
+ YangNode rpcChild;
+ YangRpc rpc;
+ YangInput input;
+ for (YangAugment info : module.getAugmentList()) {
+ input = (YangInput) info.getAugmentedNode();
+
+ if (input != null) {
+ rpc = (YangRpc) input.getParent();
+ rpcChild = rpc.getChild();
+ while (rpcChild != null) {
+ if (rpcChild instanceof YangInput) {
+ in = getChildNodeAsAttributeInParentService(
+ rpcChild, (YangNode) module);
+ }
+ if (rpcChild instanceof YangOutput) {
+ out = getChildNodeAsAttributeInParentService(
+ rpcChild, (YangNode) module);
+ }
+ rpcChild = rpcChild.getChild();
+ }
+ addJavaSnippetInfoToApplicableTempFiles(in, out, rpc
+ .getJavaClassNameOrBuiltInType());
+ }
+ }
}
/**
@@ -225,9 +277,8 @@
@Override
public void freeTemporaryResources(boolean errorOccurred)
throws IOException {
- closeFile(serviceInterfaceJavaFileHandle, errorOccurred);
+ closeFile(serviceJavaFileHandle, errorOccurred);
closeFile(rpcInterfaceTempFileHandle);
- closeFile(rpcImplTempFileHandle);
closeFile(getGetterInterfaceTempFileHandle());
closeFile(getSetterInterfaceTempFileHandle());
closeFile(getSetterImplTempFileHandle());
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 32f6c17..022caf1 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
@@ -16,11 +16,6 @@
package org.onosproject.yangutils.translator.tojava;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
@@ -29,6 +24,11 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
@@ -275,13 +275,13 @@
for (YangType<?> yangType : typeList) {
if (!(yangType instanceof YangJavaTypeTranslator)) {
throw new TranslatorException("Type does not have Java info " +
- yangType.getDataTypeName() + " in " + yangType.getLineNumber() + " at " + yangType
+ yangType.getDataTypeName() + " in " + yangType.getLineNumber() + " at " + yangType
.getCharPosition()
- + " in " + yangType.getFileName());
+ + " in " + yangType.getFileName());
}
JavaAttributeInfo javaAttributeInfo = getAttributeForType(yangType, pluginConfig);
addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo,
- pluginConfig, typeList);
+ pluginConfig, typeList);
}
addTypeConstructor(pluginConfig);
addMethodsInConflictCase(pluginConfig);
@@ -384,15 +384,15 @@
if (attr.isIntConflict()) {
if (getIntIndex() < getUIntIndex()) {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getIntAttribute(),
- getGeneratedJavaClassName(), pluginConfig)
+ getGeneratedJavaClassName())
+ NEW_LINE);
- addGetterImpl(getIntAttribute(), pluginConfig);
+ addGetterImpl(getIntAttribute());
addFromStringMethod(getIntAttribute(), pluginConfig);
} else {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getUIntAttribute(),
- getGeneratedJavaClassName(), pluginConfig)
+ getGeneratedJavaClassName())
+ NEW_LINE);
- addGetterImpl(getUIntAttribute(), pluginConfig);
+ addGetterImpl(getUIntAttribute());
addFromStringMethod(getUIntAttribute(), pluginConfig);
}
}
@@ -405,15 +405,15 @@
if (attr.isLongConflict()) {
if (getLongIndex() < getULongIndex()) {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getLongAttribute(),
- getGeneratedJavaClassName(), pluginConfig)
+ getGeneratedJavaClassName())
+ NEW_LINE);
- addGetterImpl(getLongAttribute(), pluginConfig);
+ addGetterImpl(getLongAttribute());
addFromStringMethod(getLongAttribute(), pluginConfig);
} else {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getULongAttribute(),
- getGeneratedJavaClassName(), pluginConfig)
+ getGeneratedJavaClassName())
+ NEW_LINE);
- addGetterImpl(getULongAttribute(), pluginConfig);
+ addGetterImpl(getULongAttribute());
addFromStringMethod(getULongAttribute(), pluginConfig);
}
}
@@ -427,15 +427,15 @@
if (attr.isShortConflict()) {
if (getShortIndex() < getUInt8Index()) {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getShortAttribute(),
- getGeneratedJavaClassName(), pluginConfig)
+ getGeneratedJavaClassName())
+ NEW_LINE);
- addGetterImpl(getShortAttribute(), pluginConfig);
+ addGetterImpl(getShortAttribute());
addFromStringMethod(getShortAttribute(), pluginConfig);
} else {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getUInt8Attribute(),
- getGeneratedJavaClassName(), pluginConfig)
+ getGeneratedJavaClassName())
+ NEW_LINE);
- addGetterImpl(getUInt8Attribute(), pluginConfig);
+ addGetterImpl(getUInt8Attribute());
addFromStringMethod(getUInt8Attribute(), pluginConfig);
}
}
@@ -453,15 +453,15 @@
throws IOException {
JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
- pluginConfig.getConflictResolver());
+ pluginConfig.getConflictResolver());
/*
* Create a new java attribute info with qualified information of
* wrapper classes.
*/
JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
- newAttrInfo.getAttributeName(),
- newAttrInfo.getAttributeType(),
- getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
+ newAttrInfo.getAttributeName(),
+ newAttrInfo.getAttributeType(),
+ getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
}
@@ -476,7 +476,7 @@
private void addTypeConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
- getGeneratedJavaClassName(), pluginConfig) + NEW_LINE);
+ getGeneratedJavaClassName()) + NEW_LINE);
}
/**
@@ -495,7 +495,7 @@
if (attr.isIntConflict()) {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(
getIntAttribute(),
- getUIntAttribute(), getGeneratedJavaClassName(), pluginConfig, INT_TYPE_CONFLICT,
+ getUIntAttribute(), getGeneratedJavaClassName(), INT_TYPE_CONFLICT,
getIntIndex()
< getUIntIndex()) + NEW_LINE);
}
@@ -508,7 +508,7 @@
if (attr.isLongConflict()) {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(
getLongAttribute(),
- getULongAttribute(), getGeneratedJavaClassName(), pluginConfig, LONG_TYPE_CONFLICT,
+ getULongAttribute(), getGeneratedJavaClassName(), LONG_TYPE_CONFLICT,
getLongIndex()
< getULongIndex()) + NEW_LINE);
}
@@ -521,7 +521,7 @@
if (attr.isShortConflict()) {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(
getShortAttribute(),
- getUInt8Attribute(), getGeneratedJavaClassName(), pluginConfig, SHORT_TYPE_CONFLICT,
+ getUInt8Attribute(), getGeneratedJavaClassName(), SHORT_TYPE_CONFLICT,
getShortIndex()
< getUInt8Index()) + NEW_LINE);
}
@@ -538,7 +538,7 @@
private void addOfStringMethod(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
- getGeneratedJavaClassName(), pluginConfig)
+ getGeneratedJavaClassName())
+ NEW_LINE);
}
@@ -552,19 +552,16 @@
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
- if ((getGeneratedJavaFiles() & GENERATE_TYPEDEF_CLASS) != 0) {
- closeFile(getTypedefClassJavaFileHandle(), isErrorOccurred);
- }
-
- if ((getGeneratedJavaFiles() & GENERATE_UNION_CLASS) != 0) {
- closeFile(getTypeClassJavaFileHandle(), isErrorOccurred);
+ if ((getGeneratedJavaFiles() & GENERATE_TYPEDEF_CLASS) != 0 ||
+ (getGeneratedJavaFiles() & GENERATE_UNION_CLASS) != 0) {
+ closeFile(typeClassJavaFileHandle, isErrorOccurred);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
- closeFile(getConstructorForTypeTempFileHandle(), true);
+ closeFile(constructorForTypeTempFileHandle, true);
}
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
- closeFile(getOfStringImplTempFileHandle(), true);
+ closeFile(ofStringImplTempFileHandle, true);
}
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
closeFile(getFromStringImplTempFileHandle(), true);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
index ed37a36..3c41605 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
@@ -70,11 +70,9 @@
*
* @param info YANG java file info node
* @param config YANG plugin config
- * @throws IOException IO operations fails
*/
public static void updatePackageInfo(JavaCodeGeneratorInfo info,
- YangPluginConfig config)
- throws IOException {
+ YangPluginConfig config) {
JavaFileInfoTranslator translator = info.getJavaFileInfo();
@@ -95,11 +93,9 @@
*
* @param info YANG java file info node
* @param config YANG plugin config
- * @throws IOException IO operations fails
*/
private static void updatePackageForAugmentInfo(JavaCodeGeneratorInfo info,
- YangPluginConfig config)
- throws IOException {
+ YangPluginConfig config) {
JavaFileInfoTranslator translator = info.getJavaFileInfo();
@@ -236,11 +232,10 @@
/*
* Enumeration
*/
- translator.getEnumerationTempFiles()
+ translator.getEnumTempFiles()
.addEnumAttributeToTempFiles((YangNode) info, config);
- } else if (info instanceof YangChoice) {
- /*Do nothing, only the interface needs to be generated*/
- } else {
+ } else if (!(info instanceof YangChoice)) {
+ /*Do nothing, only the interface needs to be generated for choice*/
throw new TranslatorException(
getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
info));
@@ -494,8 +489,8 @@
* @param rootNodeGen flag indicating check type
* @return true if check pass, false otherwise
*/
- public static boolean isNodeCodeGenRequired(YangNode node,
- boolean rootNodeGen) {
+ private static boolean isNodeCodeGenRequired(YangNode node,
+ boolean rootNodeGen) {
YangLeavesHolder holder = (YangLeavesHolder) node;
if (!holder.getListOfLeaf().isEmpty()) {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumerationTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumerationTranslator.java
index da4531f..605df86 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumerationTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumerationTranslator.java
@@ -16,8 +16,6 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaEnumeration;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
@@ -26,8 +24,13 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
/**
* Represents YANG java enumeration information extended to support java code generation.
@@ -48,7 +51,6 @@
* Creates YANG java enumeration object.
*/
public YangJavaEnumerationTranslator() {
- super();
setJavaFileInfo(new JavaFileInfoTranslator());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_ENUM_CLASS);
}
@@ -63,10 +65,7 @@
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ getName());
}
return (JavaFileInfoTranslator) javaFileInfo;
}
@@ -113,12 +112,8 @@
try {
generateCodeOfNode(this, yangPlugin);
} catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for enumeration node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
+ e.getLocalizedMessage()));
}
}
@@ -132,11 +127,8 @@
try {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
} catch (IOException e) {
- throw new TranslatorException("Failed to generate code for enumeration node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
+ e.getLocalizedMessage()));
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
index 6a6ac26..16ff32c 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
@@ -15,10 +15,6 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaModule;
@@ -29,12 +25,20 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.removeEmptyDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
@@ -49,24 +53,24 @@
private static final long serialVersionUID = 806201625L;
/**
- * File handle to maintain temporary java code fragments as per the code snippet types.
+ * File handle to maintain temporary java code fragments as per the code
+ * snippet types.
*/
private transient TempJavaCodeFragmentFiles tempFileHandle;
/**
* List of notifications nodes.
*/
- private transient List<YangNode> notificationNodes;
+ private final transient List<YangNode> notificationNodes;
/**
* Creates a YANG node of module type.
*/
public YangJavaModuleTranslator() {
- super();
setJavaFileInfo(new JavaFileInfoTranslator());
- setNotificationNodes(new ArrayList<>());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER);
-
+ notificationNodes = new ArrayList<>();
+ getJavaFileInfo().setGeneratedFileTypes(
+ GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER);
}
/**
@@ -77,11 +81,8 @@
@Override
public JavaFileInfoTranslator getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ throw new TranslatorException(
+ "Missing java info in java datamodel node " + getName());
}
return (JavaFileInfoTranslator) javaFileInfo;
}
@@ -112,7 +113,8 @@
* @param fileHandle temporary file handle
*/
@Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
+ public void setTempJavaCodeFragmentFiles(
+ TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
@@ -125,22 +127,22 @@
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws TranslatorException {
- String modulePkg = getRootPackage(getVersion(), getNameSpace(), getRevision(),
+ String modulePkg = getRootPackage(getVersion(), getNameSpace(),
+ getRevision(),
yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
- getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
- | GENERATE_ALL_EVENT_CLASS_MASK);
+ getJavaFileInfo().setGeneratedFileTypes(
+ getJavaFileInfo().getGeneratedFileTypes()
+ | GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, modulePkg);
+ //Add augmented rpc name
+ tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(this);
} catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for module node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
+ e.getLocalizedMessage()));
}
}
@@ -160,16 +162,21 @@
* The manager class needs to extend the "ListenerRegistry".
*/
try {
- if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
+ if ((getJavaFileInfo().getGeneratedFileTypes() &
+ GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
+ getTempJavaCodeFragmentFiles().generateJavaFile(
+ GENERATE_ALL_EVENT_CLASS_MASK, this);
}
if (isRootNodesCodeGenRequired(this)) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
- if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForSbi() == null)
- || (!getJavaFileInfo().getPluginConfig().getCodeGenerateForSbi().equals(SBI))) {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ if (getJavaFileInfo().getPluginConfig()
+ .getCodeGenerateForSbi() == null ||
+ !getJavaFileInfo().getPluginConfig()
+ .getCodeGenerateForSbi().equals(SBI)) {
+ getTempJavaCodeFragmentFiles()
+ .generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
@@ -178,11 +185,8 @@
removeEmptyDirectory(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
- throw new TranslatorException("Failed to generate code for module node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
+ e.getLocalizedMessage()));
}
}
@@ -192,16 +196,7 @@
* @return notification nodes
*/
public List<YangNode> getNotificationNodes() {
- return notificationNodes;
- }
-
- /**
- * Sets notifications list.
- *
- * @param notificationNodes notification list
- */
- private void setNotificationNodes(List<YangNode> notificationNodes) {
- this.notificationNodes = notificationNodes;
+ return unmodifiableList(notificationNodes);
}
/**
@@ -210,7 +205,7 @@
* @param curNode notification node
*/
private void addToNotificationList(YangNode curNode) {
- getNotificationNodes().add(curNode);
+ notificationNodes.add(curNode);
}
/**
@@ -229,6 +224,6 @@
childNode = childNode.getNextSibling();
}
- return !getNotificationNodes().isEmpty();
+ return !notificationNodes.isEmpty();
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpcTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpcTranslator.java
index 6e6482b..f3b4416 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpcTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpcTranslator.java
@@ -16,8 +16,6 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
@@ -27,20 +25,20 @@
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
-import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_CHILD_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
/**
* Represents rpc information extended to support java code generation.
@@ -60,7 +58,6 @@
* Creates an instance of YANG java rpc.
*/
public YangJavaRpcTranslator() {
- super();
setJavaFileInfo(new JavaFileInfoTranslator());
}
@@ -74,10 +71,7 @@
if (javaFileInfo == null) {
throw new TranslatorException("missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ getName());
}
return (JavaFileInfoTranslator) javaFileInfo;
}
@@ -114,15 +108,7 @@
throws TranslatorException {
// Add package information for rpc and create corresponding folder.
- try {
- updatePackageInfo(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException("Failed to prepare generate code entry for RPC node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
+ updatePackageInfo(this, yangPlugin);
}
/**
@@ -138,18 +124,18 @@
// Parent should be holder of rpc or notification.
if (!(parent instanceof RpcNotificationContainer)) {
- throw new TranslatorException("parent node of rpc can only be module or sub-module " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
+ this));
}
/*
* Create attribute info for input and output of rpc and add it to the
* parent import list.
*/
-
+ TempJavaServiceFragmentFiles tempJavaFragmentFiles =
+ ((TempJavaCodeFragmentFilesContainer) getParent())
+ .getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
JavaAttributeInfo javaAttributeInfoOfInput = null;
JavaAttributeInfo javaAttributeInfoOfOutput = null;
@@ -158,106 +144,34 @@
YangNode yangNode = getChild();
while (yangNode != null) {
if (yangNode instanceof YangInput) {
- javaAttributeInfoOfInput = getChildNodeAsAttributeInParentService(yangNode, this);
-
+ javaAttributeInfoOfInput = tempJavaFragmentFiles
+ .getChildNodeAsAttributeInParentService(yangNode,
+ getParent());
} else if (yangNode instanceof YangOutput) {
- javaAttributeInfoOfOutput = getChildNodeAsAttributeInParentService(yangNode, this);
+ javaAttributeInfoOfOutput = tempJavaFragmentFiles
+ .getChildNodeAsAttributeInParentService(yangNode,
+ getParent());
} else {
- throw new TranslatorException("RPC should contain only input/output child nodes. " +
- yangNode.getName() + " in " +
- yangNode.getLineNumber() + " at " +
- yangNode.getCharPosition()
- + " in " + yangNode.getFileName());
-
+ throw new TranslatorException(getErrorMsg(INVALID_CHILD_NODE,
+ this));
}
yangNode = yangNode.getNextSibling();
}
- if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException("missing parent temp file handle " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
-
/*
* Add the rpc information to the parent's service temp file.
*/
try {
- ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
- .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
- ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig(), getName());
-
+ ((TempJavaCodeFragmentFilesContainer) parent)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles()
+ .addJavaSnippetInfoToApplicableTempFiles(
+ javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
+ getJavaClassNameOrBuiltInType());
} catch (IOException e) {
- throw new TranslatorException("Failed to generate code for RPC node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
+ e.getLocalizedMessage()));
}
// No file will be generated during RPC exit.
}
-
- /**
- * Creates an attribute info object corresponding to a data model node and
- * return it.
- *
- * @param childNode child data model node(input / output) for which the java code generation
- * is being handled
- * @param currentNode parent node (module / sub-module) in which the child node is an attribute
- * @return AttributeInfo attribute details required to add in temporary
- * files
- */
- private JavaAttributeInfo getChildNodeAsAttributeInParentService(
- YangNode childNode, YangNode currentNode) {
-
- YangNode parentNode = getParentNodeInGenCode(currentNode);
-
- String childNodeName = ((JavaFileInfoContainer) childNode).getJavaFileInfo().getJavaName();
- /*
- * Get the import info corresponding to the attribute for import in
- * generated java files or qualified access
- */
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(childNode,
- getCapitalCase(childNodeName));
- if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException("Parent node does not have file info");
- }
-
- TempJavaFragmentFiles tempJavaFragmentFiles;
- tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
- .getTempJavaCodeFragmentFiles()
- .getServiceTempFiles();
-
- if (tempJavaFragmentFiles == null) {
- throw new TranslatorException("Parent node does not have service file info");
- }
- boolean isQualified = addImportToService(qualifiedTypeInfo);
- return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false);
- }
-
- /**
- * Adds to service class import list.
- *
- * @param importInfo import info
- * @return true or false
- */
- private boolean addImportToService(JavaQualifiedTypeInfoTranslator importInfo) {
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) getParent()).getJavaFileInfo();
-
- if (importInfo.getClassInfo().contentEquals(SERVICE)
- || importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
- return true;
- }
-
- String className;
- className = getCapitalCase(fileInfo.getJavaName()) + "Service";
-
- return ((TempJavaCodeFragmentFilesContainer) getParent()).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles().getJavaImportData().addImportInfo(importInfo,
- className, fileInfo.getPackage());
- }
-
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
index 2604262..a530b2a 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
@@ -15,10 +15,6 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaSubModule;
@@ -29,12 +25,20 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.removeEmptyDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
@@ -56,15 +60,16 @@
/**
* List of notifications nodes.
*/
- private transient List<YangNode> notificationNodes = new ArrayList<>();
+ private final transient List<YangNode> notificationNodes;
/**
* Creates YANG java sub module object.
*/
public YangJavaSubModuleTranslator() {
- super();
setJavaFileInfo(new JavaFileInfoTranslator());
- int genType = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
+ notificationNodes = new ArrayList<>();
+ int genType =
+ GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
genType = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
}
@@ -80,10 +85,7 @@
public JavaFileInfoTranslator getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ getName());
}
return (JavaFileInfoTranslator) javaFileInfo;
}
@@ -124,11 +126,12 @@
* @return the name space string of the module.
*/
public String getNameSpaceFromModule() {
- return (getBelongsTo().getModuleNode()).getNameSpace();
+ return getBelongsTo().getModuleNode().getNameSpace();
}
/**
- * Prepares the information for java code generation corresponding to YANG submodule info.
+ * Prepares the information for java code generation corresponding to
+ * YANG submodule info.
*
* @param yangPlugin YANG plugin config
* @throws TranslatorException when fails to translate
@@ -136,24 +139,23 @@
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws TranslatorException {
- String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(),
- getRevision(), yangPlugin.getConflictResolver());
+ String subModulePkg = getRootPackage(
+ getVersion(), getNameSpaceFromModule(), getRevision(),
+ yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
- getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
- | GENERATE_ALL_EVENT_CLASS_MASK);
+ getJavaFileInfo().setGeneratedFileTypes(
+ getJavaFileInfo().getGeneratedFileTypes()
+ | GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, subModulePkg);
+ tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(
+ this);
} catch (IOException e) {
- throw new TranslatorException(
- "failed to prepare generate code entry for submodule node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
+ e.getLocalizedMessage()));
}
-
}
/**
@@ -162,7 +164,7 @@
@Override
public void generateCodeExit()
throws TranslatorException {
- /**
+ /*
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
@@ -172,15 +174,20 @@
* The manager class needs to extend the "ListenerRegistry".
*/
try {
- if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
+ if ((getJavaFileInfo().getGeneratedFileTypes() &
+ GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
+ getTempJavaCodeFragmentFiles().generateJavaFile(
+ GENERATE_ALL_EVENT_CLASS_MASK, this);
}
if (isRootNodesCodeGenRequired(this)) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
- if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForSbi() == null)
- || (!getJavaFileInfo().getPluginConfig().getCodeGenerateForSbi().equals(SBI))) {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ if (getJavaFileInfo().getPluginConfig()
+ .getCodeGenerateForSbi() == null ||
+ !getJavaFileInfo().getPluginConfig()
+ .getCodeGenerateForSbi().equals(SBI)) {
+ getTempJavaCodeFragmentFiles().generateJavaFile(
+ GENERATE_SERVICE_AND_MANAGER, this);
}
}
@@ -189,11 +196,8 @@
removeEmptyDirectory(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
- throw new TranslatorException("Failed to generate code for submodule node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
+ e.getLocalizedMessage()));
}
}
@@ -203,7 +207,7 @@
* @return notification nodes
*/
public List<YangNode> getNotificationNodes() {
- return notificationNodes;
+ return unmodifiableList(notificationNodes);
}
/**
@@ -212,7 +216,7 @@
* @param curNode notification node
*/
private void addToNotificationList(YangNode curNode) {
- getNotificationNodes().add(curNode);
+ notificationNodes.add(curNode);
}
/**
@@ -231,6 +235,6 @@
childNode = childNode.getNextSibling();
}
- return !getNotificationNodes().isEmpty();
+ return !notificationNodes.isEmpty();
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BracketType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BracketType.java
new file mode 100644
index 0000000..67fa9a5
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BracketType.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * Represents different bracket types.
+ */
+enum BracketType {
+
+ //Open close bracket '()'.
+ OPEN_CLOSE_BRACKET,
+
+ //Open close bracket with value '(value)).
+ OPEN_CLOSE_BRACKET_WITH_VALUE,
+
+ //Open close bracket with value '(String value)).
+ OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE,
+
+ //Open close bracket with value '(String value,.
+ OPEN_BRACKET_WITH_VALUE,
+
+ //Open close bracket with value ',String value)).
+ CLOSE_BRACKET_WITH_VALUE,
+
+ //Open close diamond bracket '<>'.
+ OPEN_CLOSE_DIAMOND,
+
+ //Open close diamond bracket with value '<String>'
+ OPEN_CLOSE_DIAMOND_WITH_VALUE
+}
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 d65907d..7f1cfce 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,12 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangIdentity;
-import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
@@ -41,24 +40,34 @@
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.INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_DIAMOND_WITH_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getBuilderImplStringClassDef;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinition;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithExtends;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithImpl;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultName;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getErrorMsg;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getEventExtendsString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getSpecificModifier;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getSuffixedName;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
+import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
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;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
+import static org.onosproject.yangutils.utils.UtilConstants.ERROR_MSG_JAVA_IDENTITY;
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_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
@@ -84,7 +93,8 @@
}
/**
- * Based on the file type and the YANG name of the file, generate the class / interface definition start.
+ * Based on the file type and the YANG name of the file, generate the class
+ * / interface definition start.
*
* @param genFileTypes generated file type
* @param yangName class name
@@ -108,15 +118,16 @@
}
/**
- * Based on the file type and the YANG name of the file, generate the class / interface definition start.
+ * Based on the file type and the YANG name of the file, generate the class
+ * / interface definition start.
*
* @param genFileTypes generated file type
* @param yangName class name
* @param curNode current YANG node
* @return class definition
*/
- static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) {
-
+ static String generateClassDefinition(int genFileTypes, String yangName,
+ YangNode curNode) {
/*
* Based on the file type and the YANG name of the file, generate the
* class / interface definition start.
@@ -153,7 +164,7 @@
* @return enum file class definition
*/
private static String getEnumClassDefinition(String yangName) {
- return PUBLIC + SPACE + ENUM + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinition(ENUM, yangName, PUBLIC);
}
/**
@@ -162,29 +173,36 @@
* @param yangName file name
* @return definition
*/
- private static String getInterfaceDefinition(String yangName, YangNode curNode) {
+ private static String getInterfaceDefinition(String yangName,
+ YangNode curNode) {
- String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, INTERFACE_MASK);
+ String clsDef = getClassDefinitionForWhenExtended(curNode, yangName,
+ INTERFACE_MASK);
if (clsDef != null) {
return clsDef;
}
- return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinition(INTERFACE, yangName, PUBLIC);
}
/**
* Returns builder interface file class definition.
*
- * @param yangName java class name, corresponding to which the builder class is being generated
+ * @param yangName java class name, corresponding to which the builder
+ * class is being generated
* @return definition
*/
- private static String getBuilderInterfaceDefinition(String yangName, YangNode curNode) {
- if (!(curNode instanceof YangCase) && !(curNode instanceof YangAugment)) {
- String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_INTERFACE_MASK);
+ private static String getBuilderInterfaceDefinition(String yangName,
+ YangNode curNode) {
+ if (!(curNode instanceof YangCase) &&
+ !(curNode instanceof YangAugment)) {
+ String 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;
+ return getDefaultDefinition(INTERFACE, getSuffixedName(yangName, BUILDER),
+ null);
}
/**
@@ -193,19 +211,22 @@
* @param yangName file name
* @return definition
*/
- private static String getBuilderClassDefinition(String yangName, YangNode curNode) {
+ private static String getBuilderClassDefinition(String yangName,
+ YangNode curNode) {
+ String mod = getSpecificModifier(PUBLIC, STATIC);
+ String bName = getSuffixedName(yangName, BUILDER);
if (!(curNode instanceof YangCase)) {
- String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_CLASS_MASK);
+ String clsDef = getClassDefinitionForWhenExtended(curNode, yangName,
+ BUILDER_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
}
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
- return PUBLIC + SPACE + STATIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE;
+ if (curNode instanceof RpcNotificationContainer) {
+ return getDefaultDefinition(CLASS, bName, mod);
}
- return PUBLIC + SPACE + STATIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE +
- yangName + PERIOD + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinitionWithImpl(CLASS, bName, mod,
+ getBuilderImplStringClassDef(yangName));
}
/**
@@ -214,19 +235,21 @@
* @param yangName file name
* @return definition
*/
- private static String getImplClassDefinition(String yangName, YangNode curNode) {
+ private static String getImplClassDefinition(String yangName,
+ YangNode curNode) {
if (!(curNode instanceof YangCase)) {
- String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, DEFAULT_CLASS_MASK);
+ String clsDef = getClassDefinitionForWhenExtended(
+ curNode, yangName, DEFAULT_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
}
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
- return PUBLIC + SPACE + CLASS + SPACE + yangName + OP_PARAM + SPACE + IMPLEMENTS + SPACE
- + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ if (curNode instanceof RpcNotificationContainer) {
+ return getDefaultDefinitionWithImpl(
+ CLASS, getSuffixedName(yangName, OP_PARAM), PUBLIC, yangName);
}
- return PUBLIC + SPACE + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + IMPLEMENTS + SPACE
- + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinitionWithImpl(CLASS, getDefaultName(yangName),
+ PUBLIC, yangName);
}
/**
@@ -236,7 +259,7 @@
* @return definition
*/
private static String getClassDefinition(String yangName) {
- return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinition(CLASS, yangName, PUBLIC);
}
/**
@@ -246,31 +269,27 @@
* @return identity class definition
*/
private static String getIdentityClassDefinition(String yangName, YangNode curNode) {
+ String error = getErrorMsg(ERROR_MSG_JAVA_IDENTITY, curNode.getName(),
+ curNode.getLineNumber(), curNode
+ .getCharPosition(), curNode
+ .getFileName());
if (!(curNode instanceof YangIdentity)) {
- throw new TranslatorException("Expected java identity instance node " +
- curNode.getName() + " in " +
- curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ throw new TranslatorException(error);
}
YangIdentity identity = (YangIdentity) curNode;
+ String mod = getSpecificModifier(PUBLIC, ABSTRACT);
if (identity.getBaseNode() != null) {
YangIdentity baseIdentity = identity.getBaseNode().getReferredIdentity();
if (baseIdentity == null) {
- throw new TranslatorException("Expected java identity instance node " +
- curNode.getName() + " in " +
- curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ throw new TranslatorException(error);
}
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) baseIdentity).getJavaFileInfo();
- return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + EXTEND + SPACE
- + getCapitalCase(fileInfo.getJavaName()) + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
+ JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) baseIdentity)
+ .getJavaFileInfo();
+ return getDefaultDefinitionWithExtends(
+ CLASS, yangName, mod, getCapitalCase(fileInfo.getJavaName()));
}
-
- return PUBLIC + SPACE + ABSTRACT + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinition(CLASS, yangName, mod);
}
/**
@@ -280,7 +299,8 @@
* @return definition
*/
private static String getTypeClassDefinition(String yangName) {
- return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinition(CLASS, yangName,
+ getSpecificModifier(PUBLIC, FINAL));
}
/**
@@ -292,7 +312,8 @@
*/
private static String getRpcInterfaceDefinition(String yangName, YangNode curNode) {
JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles().getJavaExtendsListHolder();
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles()
+ .getJavaExtendsListHolder();
if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
curNode = curNode.getChild();
while (curNode != null) {
@@ -303,29 +324,24 @@
}
}
if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
- return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinition(INTERFACE, yangName, PUBLIC);
}
- return PUBLIC + SPACE + CLASS + SPACE + yangName + SPACE + IMPLEMENTS + SPACE
- + yangName.substring(0, yangName.length() - 7) + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ String name = getSuffixedName(
+ yangName.substring(0, yangName.length() - 7), SERVICE);
+ return getDefaultDefinitionWithImpl(CLASS, yangName, PUBLIC, name);
}
/* Provides class definition when RPC interface needs to extends any event.*/
private static String getRpcInterfaceDefinitionWhenItExtends(String yangName) {
- if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
- StringBuilder newString = new StringBuilder(yangName);
- newString.replace(yangName.lastIndexOf("Service"), yangName.lastIndexOf("Service") + 7, "");
- return PUBLIC + SPACE + INTERFACE + SPACE + yangName + NEW_LINE + EIGHT_SPACE_INDENTATION
- + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + newString + EVENT_STRING + COMMA
- + SPACE + newString + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE;
- }
- yangName = yangName.substring(0, yangName.length() - 7);
- return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + NEW_LINE + EIGHT_SPACE_INDENTATION
- + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE
- + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE
- + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET
- + NEW_LINE;
+ StringBuilder newString = new StringBuilder(yangName);
+ newString.replace(yangName.lastIndexOf(SERVICE), yangName
+ .lastIndexOf(SERVICE) + 7, EMPTY_STRING);
+ return getDefaultDefinitionWithExtends(
+ INTERFACE, yangName, PUBLIC, getEventExtendsString(
+ getSuffixedName(newString.toString(), EVENT_STRING),
+ LISTENER_SERVICE, getSuffixedName(newString.toString(),
+ EVENT_LISTENER_STRING)));
}
/**
@@ -335,8 +351,11 @@
* @return definition
*/
private static String getEventDefinition(String javaName, String eventName) {
- return PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
- + javaName + ".Type, " + eventName + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return getDefaultDefinitionWithExtends(
+ CLASS, javaName, PUBLIC, getEventExtendsString(
+ getSuffixedName(javaName, EVENT_TYPE), ABSTRACT_EVENT,
+ eventName));
+
}
/**
@@ -346,15 +365,11 @@
* @return definition
*/
private static String getEventListenerDefinition(String javaName) {
- String interfaceDef = PUBLIC + SPACE + INTERFACE + SPACE + javaName + SPACE + "extends EventListener<"
- + javaName;
- if (interfaceDef.length() < 8) {
- throw new RuntimeException("Event listener interface name is error");
- }
- interfaceDef = interfaceDef.substring(0, interfaceDef.length() - 8);
- interfaceDef = interfaceDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
- return interfaceDef;
+ String name = javaName.substring(0, javaName.length() - 8);
+ return getDefaultDefinitionWithExtends(
+ INTERFACE, javaName, PUBLIC, EVENT_LISTENER_STRING +
+ brackets(OPEN_CLOSE_DIAMOND_WITH_VALUE, name, null));
}
/**
@@ -365,42 +380,60 @@
* @param genFileTypes gen file type
* @return class definition
*/
- private static String getClassDefinitionForWhenExtended(YangNode curNode, String yangName, int genFileTypes) {
+ private static String getClassDefinitionForWhenExtended(
+ YangNode curNode, String yangName, int genFileTypes) {
JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder();
-
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles()
+ .getJavaExtendsListHolder();
+ StringBuilder def = new StringBuilder();
if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
- String def = PUBLIC + SPACE;
+ def.append(PUBLIC).append(SPACE);
switch (genFileTypes) {
case INTERFACE_MASK:
- def = def + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
- def = getDefinitionString(def, holder);
- return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ def.append(INTERFACE).append(SPACE).append(yangName)
+ .append(SPACE).append(EXTEND).append(SPACE);
+ def = new StringBuilder(getDefinitionString(def.toString(),
+ holder));
+ break;
case BUILDER_INTERFACE_MASK:
- String builderDef = INTERFACE + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
- builderDef = getDefinitionString(builderDef, holder);
- return builderDef + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ def.append(INTERFACE)
+ .append(SPACE).append(yangName).append(BUILDER)
+ .append(SPACE).append(EXTEND).append(SPACE);
+ def = new StringBuilder(getDefinitionString(
+ def.toString(), holder));
+ break;
case BUILDER_CLASS_MASK:
- def = def + STATIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
- def = getDefinitionString(def, holder);
- if (curNode instanceof YangSubModule || curNode instanceof YangModule) {
- return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ def.append(STATIC).append(SPACE).append(CLASS)
+ .append(SPACE).append(yangName).append(BUILDER)
+ .append(SPACE).append(EXTEND).append(SPACE);
+ def = new StringBuilder(getDefinitionString(def.toString(),
+ holder));
+ if (!(curNode instanceof RpcNotificationContainer)) {
+ def.append(SPACE).append(IMPLEMENTS).append(SPACE)
+ .append(yangName).append(PERIOD)
+ .append(yangName).append(BUILDER);
}
- return def + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
- + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
-
+ break;
case DEFAULT_CLASS_MASK:
- if (curNode instanceof YangSubModule || curNode instanceof YangModule) {
- def = def + CLASS + SPACE + yangName + OP_PARAM + SPACE + EXTEND + SPACE;
+ if (curNode instanceof RpcNotificationContainer) {
+ def.append(CLASS).append(SPACE).append(yangName)
+ .append(OP_PARAM).append(SPACE).append(EXTEND)
+ .append(SPACE);
} else {
- def = def + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + EXTEND + SPACE;
+ def.append(CLASS).append(SPACE).append(DEFAULT_CAPS)
+ .append(yangName).append(SPACE).append(EXTEND)
+ .append(SPACE);
}
- def = getDefinitionString(def, holder);
- return def + SPACE + IMPLEMENTS + SPACE
- + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ def = new StringBuilder(getDefinitionString(def.toString(),
+ holder));
+ def.append(SPACE).append(IMPLEMENTS).append(SPACE)
+ .append(yangName);
+ break;
default:
return null;
}
+ return def.append(SPACE).append(OPEN_CURLY_BRACKET)
+ .append(NEW_LINE).toString();
}
return null;
}
@@ -412,15 +445,20 @@
* @param holder extend list holder
* @return updated class definition
*/
- private static String getDefinitionString(String def, JavaExtendsListHolder holder) {
+ private static String getDefinitionString(String def,
+ JavaExtendsListHolder holder) {
+ StringBuilder builder = new StringBuilder(def);
+ String str;
for (JavaQualifiedTypeInfoTranslator info : holder.getExtendsList()) {
if (!holder.getExtendedClassStore().get(info)) {
- def = def + info.getClassInfo() + COMMA + SPACE;
+ str = info.getClassInfo() + COMMA + SPACE;
} else {
- def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE;
+ str = info.getPkgInfo() + PERIOD + info.getClassInfo() +
+ COMMA + SPACE;
}
+ builder.append(str);
}
+ def = builder.toString();
return trimAtLast(def, COMMA);
}
-
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java
new file mode 100644
index 0000000..3b7b09c
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+/**
+ * Represents indentation type.
+ */
+enum IndentationType {
+
+ //Four space indentation.
+ FOUR_SPACE,
+
+ //Eight space indentation.
+ EIGHT_SPACE,
+
+ //Twelve space indentation.
+ TWELVE_SPACE,
+
+ //Sixteen space indentation.
+ SIXTEEN_SPACE,
+
+ //Twenty space indentation.
+ TWENTY_SPACE,
+
+ //Twenty four space indentation.
+ TWENTY_FOUR_SPACE,
+
+ //Twenty eight space indentation.
+ TWENTY_EIGHT_SPACE
+
+}
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 3910a78..5671dd7 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
@@ -23,38 +23,39 @@
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.utils.UtilConstants.Operation;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import java.util.List;
import static java.util.Collections.sort;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_DIAMOND;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinition;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
-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.PROTECTED;
@@ -63,7 +64,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SET;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE_ATTR;
@@ -76,11 +77,11 @@
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.enumJavaDocForInnerClass;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
* Represents utility class to generate the java snippet.
@@ -113,8 +114,8 @@
* list
*/
static String getImportText(JavaQualifiedTypeInfoTranslator importInfo) {
- return IMPORT + importInfo.getPkgInfo() + PERIOD +
- importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
+ return getImportString(importInfo.getPkgInfo(), importInfo
+ .getClassInfo());
}
/**
@@ -134,7 +135,7 @@
boolean isList,
String accessType,
YangCompilerAnnotation annotation) {
- StringBuilder attrDef = new StringBuilder();
+ StringBuilder attrDef = new StringBuilder(FOUR_SPACE_INDENTATION);
attrDef.append(accessType).append(SPACE);
if (!isList) {
@@ -143,7 +144,7 @@
}
attrDef.append(attrType).append(SPACE)
- .append(attrName).append(SEMI_COLAN)
+ .append(attrName).append(SEMI_COLON)
.append(NEW_LINE);
} else {
// Add starting definition.
@@ -204,28 +205,17 @@
if (annotation != null &&
annotation.getYangAppDataStructure() != null) {
attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE)
- .append(attrName).append(SEMI_COLAN)
+ .append(attrName).append(SEMI_COLON)
.append(NEW_LINE);
- // TODO refactor SEMI_COLAN, when refactoring in method generator.
} else {
attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE).append(attrName)
.append(SPACE).append(EQUAL).append(SPACE).append(NEW)
- .append(SPACE).append(ARRAY_LIST).append(SEMI_COLAN)
+ .append(SPACE).append(ARRAY_LIST).append(SEMI_COLON)
.append(NEW_LINE);
}
}
/**
- * Returns based on the file type and the YANG name of the file, generate
- * the class / interface definition close.
- *
- * @return corresponding textual java code information
- */
- public static String getJavaClassDefClose() {
- return CLOSE_CURLY_BRACKET;
- }
-
- /**
* Returns string for enum's attribute.
*
* @param name name of attribute
@@ -234,9 +224,10 @@
*/
public static String generateEnumAttributeString(String name, int value) {
String enumName = getEnumJavaAttribute(name);
- return NEW_LINE + enumJavaDocForInnerClass(name) +
- EIGHT_SPACE_INDENTATION + enumName.toUpperCase() +
- OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
+ return enumJavaDocForInnerClass(name) + EIGHT_SPACE_INDENTATION +
+ enumName.toUpperCase() + brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
+ value + EMPTY_STRING, null) +
+ COMMA + NEW_LINE;
}
/**
@@ -244,17 +235,15 @@
*
* @param name name of attribute
* @param value value of the enum
- * @param config plugin configurations
* @return string for enum's attribute
*/
- public static String generateEnumAttributeStringWithSchemaName(String name,
- int value,
- YangPluginConfig config) {
+ public static String generateEnumAttributeStringWithSchemaName(
+ String name, int value) {
String enumName = getEnumJavaAttribute(name);
- return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, config, null) +
- FOUR_SPACE_INDENTATION + enumName.toUpperCase() +
- OPEN_PARENTHESIS + value + COMMA + SPACE + QUOTES + name +
- QUOTES + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
+ String str = value + COMMA + SPACE + QUOTES + name + QUOTES;
+ return getJavaDoc(ENUM_ATTRIBUTE, name, false, null) +
+ FOUR_SPACE_INDENTATION + enumName.toUpperCase() + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, str, null) + COMMA + NEW_LINE;
}
/**
@@ -274,8 +263,8 @@
* @return event enum start
*/
static String getEventEnumTypeStart() {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return NEW_LINE + FOUR_SPACE_INDENTATION +
+ getDefaultDefinition(ENUM, TYPE, PUBLIC);
}
/**
@@ -284,25 +273,16 @@
* @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,
- Operation operation,
- String classInfo) {
+ Operation operation) {
String thisImport;
TempJavaServiceFragmentFiles tempFiles =
((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles();
- if (classInfo.equals(LISTENER_SERVICE)) {
- thisImport = tempFiles.getJavaImportData()
- .getListenerServiceImport();
- performOperationOnImports(imports, thisImport, operation);
- } else {
- thisImport = tempFiles.getJavaImportData()
- .getListenerRegistryImport();
- performOperationOnImports(imports, thisImport, operation);
- }
+ thisImport = tempFiles.getJavaImportData().getListenerServiceImport();
+ performOperationOnImports(imports, thisImport, operation);
}
/**
@@ -337,10 +317,10 @@
* @return enum's attribute
*/
static String getEnumsValueAttribute(String className) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT +
- SPACE + getSmallCase(className) + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + PRIVATE + SPACE + STRING_DATA_TYPE +
- SPACE + SCHEMA_NAME + SEMI_COLAN + NEW_LINE;
+ return getJavaAttributeDefinition(null, INT, className,
+ false, PRIVATE, null) +
+ getJavaAttributeDefinition(null, STRING_DATA_TYPE, SCHEMA_NAME,
+ false, PRIVATE, null);
}
/**
@@ -349,14 +329,24 @@
* @return attribute for augmentation
*/
static String addAugmentationAttribute() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + PROTECTED + SPACE + MAP +
- DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ String[] array = {NEW_LINE, SEMI_COLON};
+ return trimAtLast(getJavaAttributeDefinition(
+ null, getAugmentMapTypeString(),
+ YANG_AUGMENTED_INFO_LOWER_CASE + MAP, false, PROTECTED,
+ null), array) + SPACE + EQUAL + SPACE + NEW + SPACE +
+ HASH_MAP + brackets(OPEN_CLOSE_DIAMOND, null, null) + brackets(
+ OPEN_CLOSE_BRACKET, null, null) + signatureClose();
+ }
+
+ /**
+ * Returns augment map return type.
+ *
+ * @return augment map return type
+ */
+ static String getAugmentMapTypeString() {
+ return MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE +
- OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE +
- getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL +
- SPACE + NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET +
- DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- SEMI_COLAN;
+ OBJECT_STRING + DIAMOND_CLOSE_BRACKET;
}
/**
@@ -369,13 +359,13 @@
static String addStaticAttributeIntRange(String modifier,
boolean addFirst) {
if (addFirst) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
- INT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
- SPACE + INT_MAX_RANGE_ATTR;
+ return getTypeConflictAttributeStrings(modifier,
+ INT_MIN_RANGE_ATTR,
+ INT_MAX_RANGE_ATTR);
}
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
- UINT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
- SPACE + UINT_MAX_RANGE_ATTR;
+ return getTypeConflictAttributeStrings(modifier,
+ UINT_MIN_RANGE_ATTR,
+ UINT_MAX_RANGE_ATTR);
}
/**
@@ -388,13 +378,13 @@
static String addStaticAttributeLongRange(String modifier,
boolean addFirst) {
if (addFirst) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
- LONG_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
- modifier + SPACE + LONG_MAX_RANGE_ATTR;
+ return getTypeConflictAttributeStrings(modifier,
+ LONG_MIN_RANGE_ATTR,
+ LONG_MAX_RANGE_ATTR);
}
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
- ULONG_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
- SPACE + ULONG_MAX_RANGE_ATTR;
+ return getTypeConflictAttributeStrings(modifier,
+ ULONG_MIN_RANGE_ATTR,
+ ULONG_MAX_RANGE_ATTR);
}
/**
@@ -407,13 +397,29 @@
static String addStaticAttributeShortRange(String modifier,
boolean addFirst) {
if (addFirst) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
- SHORT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
- SPACE + SHORT_MAX_RANGE_ATTR;
+ return getTypeConflictAttributeStrings(modifier,
+ SHORT_MIN_RANGE_ATTR,
+ SHORT_MAX_RANGE_ATTR);
}
+ return getTypeConflictAttributeStrings(modifier,
+ UINT8_MIN_RANGE_ATTR,
+ UINT8_MAX_RANGE_ATTR);
+ }
+
+ /**
+ * Returns attribute for conflicting type in union.
+ *
+ * @param modifier modifier
+ * @param attr1 attribute one
+ * @param att2 attribute two
+ * @return attribute for conflicting type in union
+ */
+ private static String getTypeConflictAttributeStrings(String modifier,
+ String attr1,
+ String att2) {
return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
- UINT8_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
- SPACE + UINT8_MAX_RANGE_ATTR;
+ attr1 + FOUR_SPACE_INDENTATION + modifier +
+ SPACE + att2;
}
/**
@@ -422,10 +428,11 @@
* @return operation type enum
*/
static String getOperationTypeEnum() {
- return "\n" +
- " /**\n" +
- " * Specify the node specific operation in protocols like NETCONF.\n" +
- " * Applicable in protocol edit operation, not applicable in query operation\n" +
+ return " /**\n" +
+ " * Specify the node specific operation in protocols " +
+ "like NETCONF.\n" +
+ " * Applicable in protocol edit operation, not applicable" +
+ " in query operation\n" +
" */\n" +
" public enum OnosYangNodeOperationType {\n" +
" MERGE,\n" +
@@ -473,6 +480,7 @@
* @return augment info map
*/
static String getYangAugmentedMapObjectForConstruct() {
- return " this.yangAugmentedInfoMap = builderObject.yangAugmentedInfoMap();\n";
+ return " this.yangAugmentedInfoMap = builderObject" +
+ ".yangAugmentedInfoMap();\n";
}
}
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 6853ac9..eae26fd 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
@@ -16,15 +16,14 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
@@ -49,6 +48,8 @@
import static java.util.Collections.sort;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
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.DEFAULT_CLASS_MASK;
@@ -87,6 +88,9 @@
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getQualifierInfoForCasesParent;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGetSetOfRootNodeRequired;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
@@ -96,12 +100,14 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getYangAugmentedMapObjectForConstruct;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.ENUM_METHOD_INT_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.ENUM_METHOD_STRING_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.builderMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumValueOfSchemaNameMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfValueMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose;
@@ -110,14 +116,9 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGettersForValueAndSelectLeaf;
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.getInterfaceLeafIdEnumMethods;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumSignature;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationAttributesGetters;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
@@ -131,6 +132,16 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.processSubtreeFilteringInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getGettersForValueAndSelectLeaf;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getInterfaceLeafIdEnumMethods;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOmitNullValueString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOperationAttributesGetters;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getReturnString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodSignature;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getAugmentableSubTreeFiltering;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessChildNodeSubtreeFiltering;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafListSubtreeFiltering;
@@ -147,9 +158,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE;
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.DEFAULT_CAPS;
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.ENCODE_TO_STRING;
@@ -158,31 +169,25 @@
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.GET_ENCODER;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
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.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.UNION_CLASS;
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.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
@@ -218,7 +223,7 @@
((JavaFileInfoContainer) curNode).getJavaFileInfo();
String path;
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
+ if (curNode instanceof RpcNotificationContainer) {
path = fileInfo.getPluginConfig().getCodeGenDir() +
fileInfo.getPackageFilePath();
} else {
@@ -249,23 +254,19 @@
try {
//Leaf identifier enum.
if (leavesPresent) {
- insertDataIntoJavaFile(file, NEW_LINE +
- getInterfaceLeafIdEnumSignature(className) +
- NEW_LINE +
- trimAtLast(replaceLast(
- getDataFromTempFileHandle(
- LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK,
- getBeanFiles(curNode), path),
- COMMA, SEMI_COLAN), NEW_LINE) +
- NEW_LINE + NEW_LINE +
+ insertDataIntoJavaFile(file, getInterfaceLeafIdEnumSignature(
+ className) + trimAtLast(replaceLast(
+ getDataFromTempFileHandle(
+ LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK,
+ getBeanFiles(curNode), path),
+ COMMA, SEMI_COLON), NEW_LINE) +
getInterfaceLeafIdEnumMethods());
}
+ insertDataIntoJavaFile(file, NEW_LINE);
//Getter methods.
- insertDataIntoJavaFile(
- file, getDataFromTempFileHandle(
- GETTER_FOR_INTERFACE_MASK,
- getBeanFiles(curNode), path));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(
+ GETTER_FOR_INTERFACE_MASK, getBeanFiles(curNode), path));
} catch (IOException e) {
throw new IOException(getErrorMsg(className, INTERFACE));
}
@@ -274,7 +275,7 @@
if (curNode instanceof YangAugmentableNode &&
!(curNode instanceof YangChoice)) {
methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface(fileInfo.getPluginConfig()));
+ methods.add(getYangAugmentInfoMapInterface());
}
if (curNode instanceof YangCase) {
@@ -282,15 +283,15 @@
JavaQualifiedTypeInfo qualifiedTypeInfo =
getQualifierInfoForCasesParent(caseParent,
fileInfo.getPluginConfig());
- methods.add(NEW_LINE + processSubtreeFilteringInterface(
+ methods.add(processSubtreeFilteringInterface(
qualifiedTypeInfo.getClassInfo()));
} else {
- methods.add(NEW_LINE + processSubtreeFilteringInterface(className));
+ methods.add(processSubtreeFilteringInterface(className));
}
if (leavesPresent) {
- methods.add(NEW_LINE + isLeafValueSetInterface());
- methods.add(NEW_LINE + isSelectLeafSetInterface());
+ methods.add(isLeafValueSetInterface());
+ methods.add(isSelectLeafSetInterface());
}
for (String method : methods) {
insertDataIntoJavaFile(file, method);
@@ -326,7 +327,7 @@
String className = getCapitalCase(fileInfo.getJavaName());
String path;
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
+ if (curNode instanceof RpcNotificationContainer) {
path = fileInfo.getPluginConfig().getCodeGenDir() +
fileInfo.getPackageFilePath();
} else {
@@ -339,29 +340,21 @@
List<String> methods = new ArrayList<>();
if (attrPresent) {
try {
-
//Getter methods.
- methods.add(FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- GETTER_FOR_INTERFACE_MASK,
- getBeanFiles(curNode), path));
+ methods.add(getDataFromTempFileHandle(
+ GETTER_FOR_INTERFACE_MASK,
+ getBeanFiles(curNode), path));
//Setter methods.
- methods.add(NEW_LINE);
- methods.add(FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- SETTER_FOR_INTERFACE_MASK,
- getBeanFiles(curNode), path));
+ methods.add(getDataFromTempFileHandle(
+ SETTER_FOR_INTERFACE_MASK,
+ getBeanFiles(curNode), path));
//Add to list method.
- methods.add(NEW_LINE);
- insertDataIntoJavaFile(file,
- getDataFromTempFileHandle(
- ADD_TO_LIST_INTERFACE_MASK,
- getBeanFiles(curNode), path));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(
+ ADD_TO_LIST_INTERFACE_MASK, getBeanFiles(curNode), path));
} catch (IOException e) {
- throw new IOException(getErrorMsg(className,
- BUILDER_INTERFACE));
+ throw new IOException(getErrorMsg(className, BUILDER_INTERFACE));
}
}
@@ -369,11 +362,11 @@
!(curNode instanceof YangChoice)) {
methods.add(getAddAugmentInfoMethodInterface());
methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface(fileInfo.getPluginConfig()));
+ methods.add(getYangAugmentInfoMapInterface());
}
if (leavesPresent) {
- methods.add(NEW_LINE + setSelectLeafSetInterface(className));
+ methods.add(setSelectLeafSetInterface(className));
}
//Add build method to builder interface file.
methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
@@ -418,7 +411,7 @@
String className = getCapitalCase(fileInfo.getJavaName());
boolean isRootNode = false;
String path;
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
+ if (curNode instanceof RpcNotificationContainer) {
isRootNode = true;
path = fileInfo.getPluginConfig().getCodeGenDir() +
fileInfo.getPackageFilePath();
@@ -438,10 +431,8 @@
//Add attribute strings.
try {
- insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- ATTRIBUTES_MASK,
- getBeanFiles(curNode), path));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(
+ ATTRIBUTES_MASK, getBeanFiles(curNode), path));
} catch (IOException e) {
throw new IOException(getErrorMsg(className, BUILDER_CLASS));
}
@@ -465,7 +456,8 @@
//Add operation attribute methods.
if (leavesPresent) {
- methods.add(getOperationAttributesGetters() + NEW_LINE);
+ methods.add(getOperationAttributesGetters());
+ insertDataIntoJavaFile(file, NEW_LINE);
methods.add(getSetterForSelectLeaf(className, isRootNode));
}
} catch (IOException e) {
@@ -484,15 +476,14 @@
// Add default constructor and build method impl.
methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles()
- .addBuildMethodImpl(curNode));
- methods.add(addDefaultConstructor(curNode, PUBLIC, BUILDER,
- config, curNode));
+ .addBuildMethodImpl());
+ methods.add(addDefaultConstructor(curNode, PUBLIC, BUILDER
+ ));
//Add methods in builder class.
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
-
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
return file;
}
@@ -530,7 +521,7 @@
String className = getCapitalCase(fileInfo.getJavaName());
String opParamClassName = className;
String path;
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
+ if (curNode instanceof RpcNotificationContainer) {
opParamClassName = className + OP_PARAM;
rootNode = true;
path = fileInfo.getPluginConfig().getCodeGenDir() +
@@ -562,7 +553,7 @@
try {
//Constructor.
String constructor =
- getConstructorStart(className, config, rootNode);
+ getConstructorStart(className, rootNode);
constructor = constructor +
getDataFromTempFileHandle(
CONSTRUCTOR_IMPL_MASK, getBeanFiles(curNode), path);
@@ -571,18 +562,15 @@
constructor = constructor +
getOperationAttributeForConstructor();
}
+ String augmentableSubTreeFiltering = EMPTY_STRING;
if (curNode instanceof YangAugmentableNode) {
constructor = constructor +
getYangAugmentedMapObjectForConstruct();
- }
- methods.add(constructor + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE);
- // add is filter content match.
- String augmentableSubTreeFiltering = EMPTY_STRING;
- if (curNode instanceof YangAugmentableNode) {
+ // add is filter content match.
augmentableSubTreeFiltering = getAugmentableSubTreeFiltering();
}
+ methods.add(constructor + methodClose(FOUR_SPACE));
methods.add(getProcessSubtreeFilteringStart(curNode, config) +
getProcessSubtreeFunctionBody(curNode) +
@@ -595,29 +583,25 @@
methods.add(getProcessLeafSubtreeFiltering(curNode, config,
path));
}
- }
-
- if (curNode instanceof YangLeavesHolder) {
if (((YangLeavesHolder) curNode).getListOfLeafList() != null &&
!((YangLeavesHolder) curNode).getListOfLeafList().isEmpty()) {
- methods.add(getProcessLeafListSubtreeFiltering(curNode,
- config,
+ methods.add(getProcessLeafListSubtreeFiltering(curNode, config,
path));
}
}
if (curNode.getChild() != null) {
- methods.add(getProcessChildNodeSubtreeFiltering(curNode,
- config, path));
+ methods.add(getProcessChildNodeSubtreeFiltering(curNode, config,
+ path));
}
} catch (IOException e) {
throw new IOException(getErrorMsg(className, IMPL_CLASS));
}
- methods.add(addDefaultConstructor(curNode, PROTECTED, DEFAULT,
- config, curNode));
+ methods.add(addDefaultConstructor(curNode, PROTECTED, DEFAULT
+ ));
- methods.add(builderMethod(className) + NEW_LINE);
+ methods.add(builderMethod(className));
if (leavesPresent) {
methods.add(getOperationAttributesGetters());
methods.add(getGettersForValueAndSelectLeaf());
@@ -653,9 +637,8 @@
//Add attribute strings.
try {
- insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- ATTRIBUTES_MASK, getBeanFiles(curNode), path));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(
+ ATTRIBUTES_MASK, getBeanFiles(curNode), path));
} catch (IOException e) {
throw new IOException(getErrorMsg(className, IMPL_CLASS));
}
@@ -672,11 +655,9 @@
// Hash code method.
methods.add(getHashCodeMethodClose(
- getHashCodeMethodOpen() +
- getDataFromTempFileHandle(
- HASH_CODE_IMPL_MASK,
- getBeanFiles(curNode), path)
- .replace(NEW_LINE, EMPTY_STRING)));
+ getHashCodeMethodOpen() + getDataFromTempFileHandle(
+ HASH_CODE_IMPL_MASK, getBeanFiles(curNode), path)
+ .replace(NEW_LINE, EMPTY_STRING)));
//Equals method.
if (rootNode) {
@@ -687,17 +668,14 @@
getBeanFiles(curNode), path)));
} else {
methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(
- getCapitalCase(DEFAULT) + className) +
- getDataFromTempFileHandle(
- EQUALS_IMPL_MASK,
- getBeanFiles(curNode), path)));
+ getEqualsMethodOpen(DEFAULT_CAPS + className) +
+ getDataFromTempFileHandle(EQUALS_IMPL_MASK,
+ getBeanFiles(curNode),
+ path)));
}
// To string method.
- methods.add(getToStringMethodOpen() +
- getDataFromTempFileHandle(
- TO_STRING_IMPL_MASK,
- getBeanFiles(curNode), path) +
+ methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(
+ TO_STRING_IMPL_MASK, getBeanFiles(curNode), path) +
getToStringMethodClose());
} catch (IOException e) {
throw new IOException(getErrorMsg(className, IMPL_CLASS));
@@ -731,22 +709,21 @@
YangDataTypes yangDataTypes = type.getDataType();
initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS,
- imports, path, config);
+ imports, path);
List<String> methods = new ArrayList<>();
//Add attribute strings.
try {
- insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- ATTRIBUTES_MASK, getTypeFiles(curNode), path));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(
+ ATTRIBUTES_MASK, getTypeFiles(curNode), path));
} catch (IOException e) {
throw new IOException(getErrorMsg(className, TYPEDEF_CLASS));
}
//Default constructor.
- methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING,
- config, curNode));
+ methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING
+ ));
try {
@@ -780,19 +757,19 @@
JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
//From string method.
- if ((type.getDataType().equals(YangDataTypes.DERIVED)) &&
- (((YangDerivedInfo) type.getDataTypeExtendedInfo())
+ if (type.getDataType() == DERIVED &&
+ ((YangDerivedInfo) type.getDataTypeExtendedInfo())
.getEffectiveBuiltInType()
- .equals(YangDataTypes.IDENTITYREF))) {
- yangDataTypes = YangDataTypes.IDENTITYREF;
+ == IDENTITYREF) {
+ yangDataTypes = IDENTITYREF;
}
- if (type.getDataType().equals(YangDataTypes.IDENTITYREF)) {
- yangDataTypes = YangDataTypes.IDENTITYREF;
+ if (type.getDataType() == IDENTITYREF) {
+ yangDataTypes = IDENTITYREF;
}
- if (!yangDataTypes.equals(YangDataTypes.IDENTITYREF)) {
- methods.add(getFromStringMethodSignature(className, config) +
+ if (yangDataTypes != IDENTITYREF) {
+ methods.add(getFromStringMethodSignature(className) +
getDataFromTempFileHandle(
FROM_STRING_IMPL_MASK,
javaGenInfo.getTempJavaCodeFragmentFiles()
@@ -823,8 +800,14 @@
private static void addTypedefToString(YangNode curNode,
List<String> methods, String path,
YangType type) throws IOException {
+ String methodSig = methodSignature(TO + STRING_DATA_TYPE, EMPTY_STRING,
+ PUBLIC, null, STRING_DATA_TYPE, null,
+ CLASS_TYPE);
+ String methodClose = signatureClose() + methodClose(FOUR_SPACE);
+ String openClose = brackets(OPEN_CLOSE_BRACKET, null,
+ null);
//To string method.
- if (type.getDataType().equals(BINARY)) {
+ if (type.getDataType() == BINARY) {
JavaQualifiedTypeInfoTranslator typeInfo =
getQualifiedTypeInfoOfCurNode(curNode, getCapitalCase
(UtilConstants.BINARY));
@@ -834,22 +817,15 @@
UtilConstants.BINARY,
null, false, false);
String attributeName = attr.getAttributeName();
- String bitsToStringMethod =
- getOverRideString() + FOUR_SPACE_INDENTATION +
- PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO +
- STRING_DATA_TYPE + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + RETURN + SPACE +
- BASE64 + PERIOD + GET_ENCODER +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS +
- attributeName + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
+ String bitsToStringMethod = getOverRideString() + methodSig +
+ getReturnString(BASE64, EIGHT_SPACE_INDENTATION) +
+ PERIOD + GET_ENCODER + brackets(OPEN_CLOSE_BRACKET, null,
+ null) +
+ PERIOD + ENCODE_TO_STRING + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, attributeName, null) +
+ methodClose;
methods.add(bitsToStringMethod);
- } else if (type.getDataType().equals(BITS)) {
+ } else if (type.getDataType() == BITS) {
JavaQualifiedTypeInfoTranslator typeInfo =
getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(UtilConstants.BITS));
@@ -860,17 +836,10 @@
null, false, false);
String attributeName = attr.getAttributeName();
String bitsToStringMethod =
- getOverRideString() + FOUR_SPACE_INDENTATION +
- PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO +
- STRING_DATA_TYPE + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + RETURN + SPACE +
- attributeName + PERIOD + TO +
- STRING_DATA_TYPE + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
+ getOverRideString() + methodSig +
+ getReturnString(attributeName, EIGHT_SPACE_INDENTATION) +
+ PERIOD + TO + STRING_DATA_TYPE + openClose +
+ methodClose;
methods.add(bitsToStringMethod);
} else {
methods.add(getToStringMethodOpen() +
@@ -945,22 +914,21 @@
}
initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS,
- imports, path, config);
+ imports, path);
List<String> methods = new ArrayList<>();
// Add attribute strings.
try {
addUnionClassAttributeInfo(file, curNode, intConflict,
- longConflict, shortConflict, path,
- tempFiles);
+ longConflict, shortConflict, path, tempFiles);
} catch (IOException e) {
throw new IOException(getErrorMsg(className, UNION_CLASS));
}
//Default constructor.
- methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING,
- config, curNode));
+ methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING
+ ));
try {
@@ -985,7 +953,7 @@
//Equals method.
methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(className + EMPTY_STRING) +
+ getEqualsMethodOpen(className) +
getDataFromTempFileHandle(
EQUALS_IMPL_MASK, getTypeFiles(curNode),
path)));
@@ -998,7 +966,7 @@
getToStringMethodClose());
//From string method.
- methods.add(getFromStringMethodSignature(className, config) +
+ methods.add(getFromStringMethodSignature(className) +
getDataFromTempFileHandle(
FROM_STRING_IMPL_MASK,
getTypeFiles(curNode), path) +
@@ -1066,9 +1034,8 @@
tempFiles.getUInt8Index()));
}
- insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- ATTRIBUTES_MASK, getTypeFiles(curNode), path));
+ insertDataIntoJavaFile(file, getDataFromTempFileHandle(
+ ATTRIBUTES_MASK, getTypeFiles(curNode), path));
}
/**
@@ -1091,64 +1058,57 @@
fileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, getCapitalCase(className),
- GENERATE_ENUM_CLASS, null, path,
- config);
+ GENERATE_ENUM_CLASS, null, path
+ );
//Add attribute strings.
try {
JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
- insertDataIntoJavaFile(file,
- trimAtLast(trimAtLast(
- getDataFromTempFileHandle(
- ENUM_IMPL_MASK, javaGenInfo
- .getTempJavaCodeFragmentFiles()
- .getEnumerationTempFiles(),
- path), COMMA), NEW_LINE) +
- SEMI_COLAN + NEW_LINE);
+ String[] remove = {COMMA, NEW_LINE};
+ insertDataIntoJavaFile(file, trimAtLast(getDataFromTempFileHandle(
+ ENUM_IMPL_MASK, javaGenInfo.getTempJavaCodeFragmentFiles()
+ .getEnumTempFiles(), path), remove) +
+ signatureClose());
} catch (IOException e) {
throw new IOException(getErrorMsg(getCapitalCase(className),
ENUM_CLASS));
}
// Add an attribute to get the enum's values.
- insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className)));
+ insertDataIntoJavaFile(file, getEnumsValueAttribute(className));
// Add a constructor for enum.
- insertDataIntoJavaFile(file,
- getJavaDoc(TYPE_CONSTRUCTOR, className, false,
- config, null) +
- getEnumsConstructor(getCapitalCase(className)) +
- NEW_LINE);
+ //TODO: generate javadoc for method.
+ insertDataIntoJavaFile(file, getEnumsConstructor(getCapitalCase(className)) +
+ NEW_LINE);
insertDataIntoJavaFile(file,
getEnumsOfValueMethod(className,
(YangEnumeration) curNode,
- config) + NEW_LINE);
+ ENUM_METHOD_INT_VALUE));
insertDataIntoJavaFile(file,
- getEnumValueOfSchemaNameMethod(className,
- config,
- (YangEnumeration) curNode));
+ getEnumsOfValueMethod(className,
+ (YangEnumeration) curNode,
+ ENUM_METHOD_STRING_VALUE));
// Add a getter method for enum.
insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false,
- config, null) +
+ null) +
getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
- insertDataIntoJavaFile(file,
- getJavaDoc(GETTER_METHOD, SCHEMA_NAME, false,
- config, null) +
- getGetter(STRING_DATA_TYPE, SCHEMA_NAME,
- GENERATE_ENUM_CLASS) +
- NEW_LINE);
+ insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, SCHEMA_NAME, false,
+ null) +
+ getGetter(STRING_DATA_TYPE, SCHEMA_NAME, GENERATE_ENUM_CLASS) +
+ NEW_LINE);
try {
insertDataIntoJavaFile(file,
- getFromStringMethodSignature(getCapitalCase(className),
- config) +
+ getFromStringMethodSignature(
+ getCapitalCase(className)) +
getDataFromTempFileHandle(
FROM_STRING_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles()
- .getEnumerationTempFiles(),
+ .getEnumTempFiles(),
path) + getFromStringMethodClose());
} catch (IOException e) {
throw new IOException(getErrorMsg(getCapitalCase(className),
@@ -1196,17 +1156,17 @@
if (isGetSetOfRootNodeRequired(curNode)) {
//Getter methods.
methods.add(getGetterString(rootAttribute,
- GENERATE_SERVICE_AND_MANAGER,
- fileInfo.getPluginConfig()) +
+ GENERATE_SERVICE_AND_MANAGER
+ ) +
NEW_LINE);
// Setter methods.
methods.add(getSetterString(rootAttribute, className,
- GENERATE_SERVICE_AND_MANAGER,
- fileInfo.getPluginConfig()) +
+ GENERATE_SERVICE_AND_MANAGER
+ ) +
NEW_LINE);
}
- methods.add(getAugmentsDataMethodForService(curNode) + NEW_LINE);
+ methods.add(getAugmentsDataMethodForService(curNode));
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles() != null) {
@@ -1258,11 +1218,10 @@
initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode,
className);
try {
- insertDataIntoJavaFile(file, NEW_LINE + getEventEnumTypeStart() +
+ insertDataIntoJavaFile(file, getEventEnumTypeStart() +
trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK,
tempFiles, path),
- COMMA) + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE);
+ COMMA) + methodClose(FOUR_SPACE));
insertDataIntoJavaFile(file,
getDataFromTempFileHandle(EVENT_METHOD_MASK,
@@ -1325,17 +1284,17 @@
insertDataIntoJavaFile(file, NEW_LINE);
try {
- insertDataIntoJavaFile(file,
- getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK,
- tempFiles, path));
+ insertDataIntoJavaFile(
+ file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK,
+ tempFiles, path));
- insertDataIntoJavaFile(file,
- getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK,
- tempFiles, path));
+ insertDataIntoJavaFile(
+ file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK,
+ tempFiles, path));
- insertDataIntoJavaFile(file,
- getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK,
- tempFiles, path));
+ insertDataIntoJavaFile(
+ file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK,
+ tempFiles, path));
} catch (IOException e) {
throw new IOException(getErrorMsg(className, EVENT_CLASS));
}
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 09bb72b..2d9538f 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
@@ -16,18 +16,11 @@
package org.onosproject.yangutils.translator.tojava.utils;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangLeafRef;
-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.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -47,6 +40,11 @@
import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
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.DEFAULT_CLASS_MASK;
@@ -81,7 +79,6 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
@@ -90,12 +87,13 @@
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getNodesPackage;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.ERROR_MSG_FOR_GEN_CODE;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
@@ -134,187 +132,217 @@
* @param handler cached file handle
* @return file object
*/
- public static File getFileObject(String filePath, String fileName, String extension,
+ public static File getFileObject(String filePath, String fileName,
+ String extension,
JavaFileInfoTranslator handler) {
- return new File(handler.getBaseCodeGenPath() + filePath + SLASH + fileName + extension);
+ return new File(handler.getBaseCodeGenPath() + filePath + SLASH +
+ fileName + extension);
}
/**
* Returns data stored in temporary files.
*
- * @param generatedTempFiles temporary file types
- * @param tempJavaFragmentFiles temp java fragment files
- * @param absolutePath absolute path
+ * @param tempFiles temporary file types
+ * @param tempHandle temp java fragment files
+ * @param path absolute path
* @return data stored in temporary files
* @throws IOException when failed to get the data from temporary file handle
*/
- static String getDataFromTempFileHandle(int generatedTempFiles,
- TempJavaFragmentFiles tempJavaFragmentFiles, String absolutePath)
+ static String getDataFromTempFileHandle(
+ int tempFiles, TempJavaFragmentFiles tempHandle, String path)
throws IOException {
- TempJavaTypeFragmentFiles typeFragmentFiles = null;
-
- if (tempJavaFragmentFiles instanceof TempJavaTypeFragmentFiles) {
- typeFragmentFiles = (TempJavaTypeFragmentFiles) tempJavaFragmentFiles;
+ TempJavaTypeFragmentFiles typeHandle = null;
+ if (tempHandle instanceof TempJavaTypeFragmentFiles) {
+ typeHandle = (TempJavaTypeFragmentFiles) tempHandle;
}
- TempJavaBeanFragmentFiles beanFragmentFiles = null;
-
- if (tempJavaFragmentFiles instanceof TempJavaBeanFragmentFiles) {
- beanFragmentFiles = (TempJavaBeanFragmentFiles) tempJavaFragmentFiles;
+ TempJavaBeanFragmentFiles beanHandle = null;
+ if (tempHandle instanceof TempJavaBeanFragmentFiles) {
+ beanHandle = (TempJavaBeanFragmentFiles) tempHandle;
}
- TempJavaServiceFragmentFiles serviceFragmentFiles = null;
- if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
- serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
+ TempJavaServiceFragmentFiles serviceHandle = null;
+ if (tempHandle instanceof TempJavaServiceFragmentFiles) {
+ serviceHandle = (TempJavaServiceFragmentFiles) tempHandle;
}
- TempJavaEventFragmentFiles eventFragmentFiles = null;
- if (tempJavaFragmentFiles instanceof TempJavaEventFragmentFiles) {
- eventFragmentFiles = (TempJavaEventFragmentFiles) tempJavaFragmentFiles;
+ TempJavaEventFragmentFiles eventHandle = null;
+ if (tempHandle instanceof TempJavaEventFragmentFiles) {
+ eventHandle = (TempJavaEventFragmentFiles) tempHandle;
}
- if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterInterfaceTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & ADD_TO_LIST_INTERFACE_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAddToListInterfaceTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & ADD_TO_LIST_IMPL_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAddToListImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSubtreeFilteringForLeafTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetSubtreeFilteringForListTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles
- .getGetSubtreeFilteringForChildNodeTempFileHandle(), absolutePath);
- } else if ((generatedTempFiles & EDIT_CONTENT_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEditContentTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getLeafIdAttributeTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
- if (beanFragmentFiles == null) {
- throw new TranslatorException("Required constructor info is missing.");
+ if ((tempFiles & ATTRIBUTES_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getAttributesTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getGetterInterfaceTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getSetterInterfaceTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & GETTER_FOR_CLASS_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getGetterImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & SETTER_FOR_CLASS_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getSetterImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & ADD_TO_LIST_INTERFACE_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getAddToListInterfaceTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & ADD_TO_LIST_IMPL_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getAddToListImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getSubtreeFilteringForLeafTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getGetSubtreeFilteringForListTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getGetSubtreeFilteringForChildNodeTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & EDIT_CONTENT_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getEditContentTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getLeafIdAttributeTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
+ if (beanHandle == null) {
+ throw new TranslatorException("Required constructor info is" +
+ " missing.");
}
- return beanFragmentFiles
- .getTemporaryDataFromFileHandle(beanFragmentFiles.getConstructorImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getHashCodeImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEqualsImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
- if (typeFragmentFiles == null) {
- throw new TranslatorException("Required of string implementation info is missing.");
+ return beanHandle.getTemporaryDataFromFileHandle(
+ beanHandle.getConstructorImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & HASH_CODE_IMPL_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getHashCodeImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & EQUALS_IMPL_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getEqualsImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & TO_STRING_IMPL_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getToStringImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & OF_STRING_IMPL_MASK) != 0) {
+ if (typeHandle == null) {
+ throw new TranslatorException("Required of string implementation" +
+ " info is missing.");
}
- return typeFragmentFiles
- .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 typeHandle.getTemporaryDataFromFileHandle(
+ typeHandle.getOfStringImplTempFileHandle(), path);
+ }
+ if ((tempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
+ if (typeHandle == null) {
+ throw new TranslatorException("Required constructor implementation" +
+ " info is missing.");
}
- return typeFragmentFiles
- .getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
- return tempJavaFragmentFiles
- .getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
- if (!(tempJavaFragmentFiles instanceof TempJavaEnumerationFragmentFiles)) {
+ return typeHandle.getTemporaryDataFromFileHandle(
+ typeHandle.getConstructorForTypeTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & FROM_STRING_IMPL_MASK) != 0) {
+ return tempHandle.getTemporaryDataFromFileHandle(
+ tempHandle.getFromStringImplTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & ENUM_IMPL_MASK) != 0) {
+ if (!(tempHandle instanceof TempJavaEnumerationFragmentFiles)) {
throw new TranslatorException("Required enum info is missing.");
}
- TempJavaEnumerationFragmentFiles enumFragmentFiles =
- (TempJavaEnumerationFragmentFiles) tempJavaFragmentFiles;
- return enumFragmentFiles
- .getTemporaryDataFromFileHandle(enumFragmentFiles.getEnumClassTempFileHandle(), absolutePath);
- } else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) {
- if (serviceFragmentFiles == null) {
- throw new TranslatorException("Required rpc interface info is missing.");
+ TempJavaEnumerationFragmentFiles enumHandle =
+ (TempJavaEnumerationFragmentFiles) tempHandle;
+ return enumHandle.getTemporaryDataFromFileHandle(
+ enumHandle.getEnumClassTempFileHandle(), path);
+ }
+ if ((tempFiles & RPC_INTERFACE_MASK) != 0) {
+ if (serviceHandle == null) {
+ throw new TranslatorException("Required rpc interface info is" +
+ " missing.");
}
- return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcInterfaceTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
- if (serviceFragmentFiles == null) {
- throw new TranslatorException("Required rpc implementation info is missing.");
+ return serviceHandle.getTemporaryDataFromFileHandle(
+ serviceHandle.getRpcInterfaceTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & EVENT_ENUM_MASK) != 0) {
+ if (eventHandle == null) {
+ throw new TranslatorException(
+ "Required event enum implementation info is missing.");
}
- return serviceFragmentFiles
- .getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & EVENT_ENUM_MASK) != 0) {
- if (eventFragmentFiles == null) {
- throw new TranslatorException("Required event enum implementation info is missing.");
+ return eventHandle.getTemporaryDataFromFileHandle(
+ eventHandle.getEventEnumTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & EVENT_METHOD_MASK) != 0) {
+ if (eventHandle == null) {
+ throw new TranslatorException(
+ "Required event method implementation info is missing.");
}
- return eventFragmentFiles
- .getTemporaryDataFromFileHandle(eventFragmentFiles.getEventEnumTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & EVENT_METHOD_MASK) != 0) {
- if (eventFragmentFiles == null) {
- throw new TranslatorException("Required event method implementation info is missing.");
+ return eventHandle.getTemporaryDataFromFileHandle(
+ eventHandle.getEventMethodTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) {
+ if (eventHandle == null) {
+ throw new TranslatorException(
+ "Required event subject getter implementation info is" +
+ " missing.");
}
- return eventFragmentFiles
- .getTemporaryDataFromFileHandle(eventFragmentFiles.getEventMethodTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) {
- if (eventFragmentFiles == null) {
- throw new TranslatorException("Required event subject getter implementation info is missing.");
+ return eventHandle.getTemporaryDataFromFileHandle(
+ eventHandle.getEventSubjectGetterTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) {
+ if (eventHandle == null) {
+ throw new TranslatorException(
+ "Required event subject setter implementation info is" +
+ " missing.");
}
- return eventFragmentFiles
- .getTemporaryDataFromFileHandle(eventFragmentFiles.getEventSubjectGetterTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) {
- if (eventFragmentFiles == null) {
- throw new TranslatorException("Required event subject setter implementation info is missing.");
+ return eventHandle.getTemporaryDataFromFileHandle(
+ eventHandle.getEventSubjectSetterTempFileHandle(),
+ path);
+ }
+ if ((tempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) {
+ if (eventHandle == null) {
+ throw new TranslatorException(
+ "Required event subject attribute implementation info is" +
+ " missing.");
}
- return eventFragmentFiles
- .getTemporaryDataFromFileHandle(eventFragmentFiles.getEventSubjectSetterTempFileHandle(),
- absolutePath);
- } else if ((generatedTempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) {
- if (eventFragmentFiles == null) {
- throw new TranslatorException("Required event subject attribute implementation info is missing.");
- }
- return eventFragmentFiles
- .getTemporaryDataFromFileHandle(eventFragmentFiles.getEventSubjectAttributeTempFileHandle(),
- absolutePath);
+ return eventHandle.getTemporaryDataFromFileHandle(
+ eventHandle.getEventSubjectAttributeTempFileHandle(),
+ path);
}
return null;
}
@@ -322,64 +350,67 @@
/**
* Initiates generation of file based on generated file type.
*
- * @param file generated file
- * @param className generated file class name
- * @param genType generated file type
- * @param imports imports for the file
- * @param pkg generated file package
- * @param pluginConfig plugin configurations
+ * @param file generated file
+ * @param className generated file class name
+ * @param genType generated file type
+ * @param imports imports for the file
+ * @param pkg generated file package
* @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)
+ public static void initiateJavaFileGeneration(File file, String className,
+ int genType, List<String> imports,
+ String pkg)
throws IOException {
if (file.exists()) {
throw new IOException(" file " + file.getName() + " is already generated." +
- "please check whether multiple yang files has same module/submodule \"name\" and \"namespace\"" +
- "or You may have generated code of previous build present in your directory.");
+ ERROR_MSG_FOR_GEN_CODE);
}
boolean isFileCreated;
try {
isFileCreated = file.createNewFile();
if (!isFileCreated) {
- throw new IOException("Failed to create " + file.getName() + " class file.");
+ throw new IOException("Failed to create " + file.getName() +
+ " class file.");
}
- appendContents(file, className, genType, imports, pkg, pluginConfig);
+ appendContents(file, className, genType, imports, pkg);
} catch (IOException e) {
- throw new IOException("Failed to append contents in " + file.getName() + " class file.");
+ throw new IOException("Failed to append contents in " + file.getName() +
+ " class file.");
}
}
/**
* Initiates generation of file based on generated file type.
*
- * @param file generated file
- * @param genType generated file type
- * @param imports imports for the file
- * @param curNode current YANG node
- * @param className class name
+ * @param file generated file
+ * @param genType generated file type
+ * @param imports imports for the file
+ * @param curNode current YANG node
+ * @param name class name
* @throws IOException when fails to generate a file
*/
- public static void initiateJavaFileGeneration(File file, int genType, List<String> imports,
- YangNode curNode, String className)
+ public static void initiateJavaFileGeneration(File file, int genType,
+ List<String> imports,
+ YangNode curNode, String name)
throws IOException {
if (file.exists()) {
throw new IOException(" file " + file.getName() + " is already generated." +
- "please check whether multiple yang files has same module/submodule \"name\" and \"namespace\"" +
- "or You may have generated code of previous build present in your directory.");
+ ERROR_MSG_FOR_GEN_CODE);
}
boolean isFileCreated;
try {
isFileCreated = file.createNewFile();
if (!isFileCreated) {
- throw new IOException("Failed to create " + file.getName() + " class file.");
+ throw new IOException("Failed to create " + file.getName() +
+ " class file.");
}
- appendContents(file, genType, imports, curNode, className);
+ appendContents(file, genType, imports, curNode, name);
} catch (IOException e) {
- throw new IOException("Failed to append contents in " + file.getName() + " class file.");
+ throw new IOException("Failed to append contents in " + file.getName() +
+ " class file.");
}
}
@@ -393,20 +424,24 @@
* @param className class name
* @throws IOException when fails to do IO operations
*/
- private static void appendContents(File file, int genType, List<String> importsList, YangNode curNode,
+ private static void appendContents(File file, int genType,
+ List<String> importsList, YangNode curNode,
String className)
throws IOException {
- JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo();
String name = javaFileInfo.getJavaName();
- String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
+ String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo
+ .getPackageFilePath();
String pkgString;
- if (genType == GENERATE_EVENT_CLASS
- || genType == GENERATE_EVENT_LISTENER_INTERFACE
- || genType == GENERATE_EVENT_SUBJECT_CLASS) {
- pkgString = parsePackageString((path + PERIOD + name).toLowerCase(), importsList);
+ if (genType == GENERATE_EVENT_CLASS ||
+ genType == GENERATE_EVENT_LISTENER_INTERFACE ||
+ genType == GENERATE_EVENT_SUBJECT_CLASS) {
+ pkgString = parsePackageString((path + PERIOD + name)
+ .toLowerCase(), importsList);
} else {
pkgString = parsePackageString(path, importsList);
}
@@ -459,11 +494,10 @@
* @param genType generated file type
* @param importsList list of java imports
* @param pkg generated file package
- * @param pluginConfig plugin configurations
* @throws IOException when fails to append contents
*/
- private static void appendContents(File file, String fileName, int genType, List<String> importsList, String pkg,
- YangPluginConfig pluginConfig)
+ private static void appendContents(File file, String fileName, int genType,
+ List<String> importsList, String pkg)
throws IOException {
String pkgString = parsePackageString(pkg, importsList);
@@ -471,15 +505,15 @@
switch (genType) {
case GENERATE_TYPEDEF_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, IMPL_CLASS, pluginConfig);
+ write(file, fileName, genType, IMPL_CLASS);
break;
case GENERATE_UNION_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, IMPL_CLASS, pluginConfig);
+ write(file, fileName, genType, IMPL_CLASS);
break;
case GENERATE_ENUM_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, ENUM_CLASS, pluginConfig);
+ write(file, fileName, genType, ENUM_CLASS);
break;
default:
break;
@@ -493,30 +527,32 @@
* @param importsList list of imports
* @return package string
*/
- private static String parsePackageString(String javaPkg, List<String> importsList) {
+ private static String parsePackageString(String javaPkg,
+ List<String> importsList) {
javaPkg = parsePkg(getJavaPackageFromPackagePath(javaPkg));
if (importsList != null) {
if (!importsList.isEmpty()) {
- return PACKAGE + SPACE + javaPkg + SEMI_COLAN + NEW_LINE;
+ return PACKAGE + SPACE + javaPkg + SEMI_COLON + NEW_LINE;
} else {
- return PACKAGE + SPACE + javaPkg + SEMI_COLAN;
+ return PACKAGE + SPACE + javaPkg + SEMI_COLON;
}
} else {
- return PACKAGE + SPACE + javaPkg + SEMI_COLAN;
+ return PACKAGE + SPACE + javaPkg + SEMI_COLON;
}
}
/**
- * Appends other contents to interface, impl and typedef classes. for example : ONOS copyright, imports and
- * package.
+ * Appends other contents to interface, impl and typedef classes.
+ * for example : ONOS copyright, imports and package.
*
* @param file generated file
* @param pkg generated package
* @param importsList list of imports
* @throws IOException when fails to append contents
*/
- private static void appendHeaderContents(File file, String pkg, List<String> importsList)
+ private static void appendHeaderContents(File file, String pkg,
+ List<String> importsList)
throws IOException {
insertDataIntoJavaFile(file, CopyrightHeader.getCopyrightHeader());
@@ -545,28 +581,28 @@
* @param fileName file name
* @throws IOException when fails to write into a file
*/
- private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName)
+ private static void write(File file, int genType, JavaDocType javaDocType,
+ YangNode curNode, String fileName)
throws IOException {
-
- YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig();
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig, null));
- insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName,
+ false, null));
+ insertDataIntoJavaFile(file, generateClassDefinition(genType,
+ fileName, curNode));
}
/**
* Writes data to the specific generated file.
*
- * @param file generated file
- * @param fileName file name
- * @param genType generated file type
- * @param javaDocType java doc type
- * @param pluginConfig plugin configurations
+ * @param file generated file
+ * @param fileName file name
+ * @param genType generated file type
+ * @param javaDocType java doc type
* @throws IOException when fails to write into a file
*/
- private static void write(File file, String fileName, int genType, JavaDocType javaDocType,
- YangPluginConfig pluginConfig)
- throws IOException {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig, null));
+ private static void write(File file, String fileName, int genType,
+ JavaDocType javaDocType) throws IOException {
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false,
+ null));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
@@ -605,12 +641,14 @@
}
/*Validates the set for duplicate names of node identifiers.*/
- private static boolean validateNodeIdentifierInSet(YangNodeIdentifier nodeId, List<YangAtomicPath> targets) {
+ private static boolean validateNodeIdentifierInSet(
+ YangNodeIdentifier nodeId, List<YangAtomicPath> targets) {
boolean isPresent = true;
for (YangAtomicPath target : targets) {
if (target.getNodeIdentifier().getName().equals(nodeId.getName())) {
if (target.getNodeIdentifier().getPrefix() != null) {
- isPresent = !target.getNodeIdentifier().getPrefix().equals(nodeId.getPrefix());
+ isPresent = !target.getNodeIdentifier().getPrefix()
+ .equals(nodeId.getPrefix());
} else {
isPresent = nodeId.getPrefix() != null;
}
@@ -626,33 +664,37 @@
*/
public static void addResolvedAugmentedDataNodeImports(YangNode parent) {
List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
- TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = ((JavaCodeGeneratorInfo) parent)
+ TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = (
+ (JavaCodeGeneratorInfo) parent)
.getTempJavaCodeFragmentFiles();
YangNode augmentedNode;
- JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo;
+ JavaQualifiedTypeInfoTranslator typeInfo;
String curNodeName;
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent)
+ .getJavaFileInfo();
for (YangAtomicPath nodeId : targets) {
augmentedNode = nodeId.getResolvedNode().getParent();
- if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
- curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
- } else {
- curNodeName = getCapitalCase(getCamelCase(augmentedNode.getName(), parentInfo.getPluginConfig()
- .getConflictResolver()));
- }
+ curNodeName = getCurNodeName(augmentedNode, parentInfo
+ .getPluginConfig());
- javaQualifiedTypeInfo = getQualifiedTypeInfoOfAugmentedNode(augmentedNode, getCapitalCase(curNodeName),
- parentInfo.getPluginConfig());
- tempJavaCodeFragmentFiles.getServiceTempFiles().getJavaImportData().addImportInfo(javaQualifiedTypeInfo,
- parentInfo.getJavaName(), parentInfo.getPackage());
- if (augmentedNode instanceof YangModule || augmentedNode instanceof YangSubModule) {
- javaQualifiedTypeInfo = getQualifiedTypeInfoOfAugmentedNode(augmentedNode,
- getCapitalCase(curNodeName) + OP_PARAM,
- parentInfo.getPluginConfig());
- tempJavaCodeFragmentFiles.getServiceTempFiles().getJavaImportData().addImportInfo(javaQualifiedTypeInfo,
- parentInfo.getJavaName(), parentInfo.getPackage());
- }
+ typeInfo =
+ getQTypeInfoOfNode(
+ augmentedNode, curNodeName + OP_PARAM,
+ parentInfo.getPluginConfig());
+ tempJavaCodeFragmentFiles.getServiceTempFiles()
+ .getJavaImportData().addImportInfo(
+ typeInfo, parentInfo.getJavaName(),
+ parentInfo.getPackage());
+ typeInfo =
+ getQTypeInfoOfNode(
+ augmentedNode, curNodeName, parentInfo
+ .getPluginConfig());
+
+ tempJavaCodeFragmentFiles.getServiceTempFiles()
+ .getJavaImportData().addImportInfo(
+ typeInfo, parentInfo.getJavaName(),
+ parentInfo.getPackage());
}
}
@@ -664,13 +706,14 @@
* @param pluginConfig plugin configurations
* @return qualified type info of augmented node
*/
- private static JavaQualifiedTypeInfoTranslator getQualifiedTypeInfoOfAugmentedNode(YangNode augmentedNode,
- String curNodeName, YangPluginConfig pluginConfig) {
- JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(augmentedNode,
- getCapitalCase(curNodeName));
+ private static JavaQualifiedTypeInfoTranslator getQTypeInfoOfNode(
+ YangNode augmentedNode, String curNodeName, YangPluginConfig pluginConfig) {
+ JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo =
+ getQualifiedTypeInfoOfCurNode(augmentedNode,
+ curNodeName);
if (javaQualifiedTypeInfo.getPkgInfo() == null) {
javaQualifiedTypeInfo.setPkgInfo(getNodesPackage(augmentedNode,
- pluginConfig));
+ pluginConfig));
}
return javaQualifiedTypeInfo;
}
@@ -682,9 +725,11 @@
* @param importData import data
* @return true if present in imports
*/
- private static boolean validateQualifiedInfoOfAugmentedNode(JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo,
- JavaImportData importData) {
- for (JavaQualifiedTypeInfoTranslator curImportInfo : importData.getImportSet()) {
+ private static boolean validateQualifiedInfoOfAugmentedNode(
+ JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo,
+ JavaImportData importData) {
+ for (JavaQualifiedTypeInfoTranslator curImportInfo : importData
+ .getImportSet()) {
if (curImportInfo.getClassInfo()
.contentEquals(javaQualifiedTypeInfo.getClassInfo())) {
return curImportInfo.getPkgInfo()
@@ -701,46 +746,42 @@
* @param parent parent node
* @return augmented class name for data methods in manager and service
*/
- static String getAugmentedClassNameForDataMethods(YangNode augmentedNode, YangNode parent) {
+ static String getAugmentedClassNameForDataMethods(YangNode augmentedNode,
+ YangNode parent) {
String curNodeName;
JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo;
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent)
+ .getJavaFileInfo();
YangPluginConfig pluginConfig = parentInfo.getPluginConfig();
- TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) parent)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles();
- if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
- curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
- } else {
- curNodeName = getCapitalCase(getCamelCase(augmentedNode.getName(), pluginConfig
- .getConflictResolver()));
- }
+ TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = (
+ (JavaCodeGeneratorInfo) parent).getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
+ curNodeName = getCurNodeName(augmentedNode, pluginConfig);
- javaQualifiedTypeInfo = getQualifiedTypeInfoOfAugmentedNode(augmentedNode,
- getCapitalCase(curNodeName),
- parentInfo.getPluginConfig());
+ javaQualifiedTypeInfo = getQTypeInfoOfNode(augmentedNode,
+ getCapitalCase(curNodeName),
+ parentInfo.getPluginConfig());
if (validateQualifiedInfoOfAugmentedNode(javaQualifiedTypeInfo,
- tempJavaServiceFragmentFiles.getJavaImportData())) {
+ tempJavaServiceFragmentFiles
+ .getJavaImportData())) {
return javaQualifiedTypeInfo.getClassInfo();
} else {
- return javaQualifiedTypeInfo.getPkgInfo() + PERIOD + javaQualifiedTypeInfo.getClassInfo();
+ return javaQualifiedTypeInfo.getPkgInfo() + PERIOD +
+ javaQualifiedTypeInfo.getClassInfo();
}
}
- /**
- * Returns parent node name for data methods in manager and service.
- *
- * @param parent parent node
- * @param pluginConfig plugin configurations
- * @return parent node name for data methods in manager and service
- */
- static String getParentNodeNameForDataMethods(YangNode parent, YangPluginConfig pluginConfig) {
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- if (parentInfo.getJavaName() != null) {
- return getCapitalCase(parentInfo.getJavaName());
+ //Returns class name of current node
+ static String getCurNodeName(YangNode node, YangPluginConfig config) {
+ if (((JavaFileInfoContainer) node).getJavaFileInfo()
+ .getJavaName() != null) {
+ return getCapitalCase(((JavaFileInfoContainer) node)
+ .getJavaFileInfo()
+ .getJavaName());
+ } else {
+ return getCapitalCase(getCamelCase(node.getName(), config
+ .getConflictResolver()));
}
- return getCapitalCase(getCamelCase(parent.getName(), pluginConfig
- .getConflictResolver()));
-
}
/**
@@ -750,7 +791,8 @@
* @param attributeType effective type
* @return name of the effective type
*/
- public static String isTypeNameLeafref(String attributeName, YangType<?> attributeType) {
+ public static String isTypeNameLeafref(String attributeName,
+ YangType<?> attributeType) {
if (attributeName.equalsIgnoreCase(LEAFREF)) {
return attributeType.getDataTypeName();
}
@@ -765,10 +807,10 @@
*/
public static YangType isTypeLeafref(YangType<?> attributeType) {
if (attributeType.getDataType() == YangDataTypes.LEAFREF) {
- YangLeafRef leafRef = (YangLeafRef) attributeType.getDataTypeExtendedInfo();
+ YangLeafRef leafRef = (YangLeafRef) attributeType
+ .getDataTypeExtendedInfo();
return leafRef.getEffectiveDataType();
}
return attributeType;
}
-
-}
+}
\ No newline at end of file
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 b77a158..5bf97f3 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
@@ -16,6 +16,13 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangRevision;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
+import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
+
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -25,15 +32,8 @@
import java.util.Date;
import java.util.List;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangRevision;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
@@ -73,26 +73,26 @@
/**
* Returns the root package string.
*
- * @param version YANG version
- * @param nameSpace name space of the module
- * @param revision revision of the module defined
- * @param conflictResolver object of YANG to java naming conflict util
+ * @param version YANG version
+ * @param nameSpace name space of the module
+ * @param revision revision of the module defined
+ * @param resolver object of YANG to java naming conflict util
* @return the root package string
*/
- public static String getRootPackage(byte version, String nameSpace, YangRevision revision,
- YangToJavaNamingConflictUtil conflictResolver) {
+ public static String getRootPackage(byte version, String nameSpace,
+ YangRevision revision,
+ YangToJavaNamingConflictUtil resolver) {
- String pkg;
- pkg = DEFAULT_BASE_PKG;
- pkg = pkg + PERIOD;
- pkg = pkg + getYangVersion(version);
- pkg = pkg + PERIOD;
- pkg = pkg + getPkgFromNameSpace(nameSpace, conflictResolver);
+ StringBuilder pkg = new StringBuilder(DEFAULT_BASE_PKG)
+ .append(PERIOD)
+ .append(getYangVersion(version))
+ .append(PERIOD)
+ .append(getPkgFromNameSpace(nameSpace, resolver));
if (revision != null) {
- pkg = pkg + PERIOD;
- pkg = pkg + getYangRevisionStr(revision.getRevDate());
+ pkg.append(PERIOD)
+ .append(getYangRevisionStr(revision.getRevDate()));
}
- return pkg.toLowerCase();
+ return pkg.toString().toLowerCase();
}
@@ -109,19 +109,21 @@
/**
* Returns package name from name space.
*
- * @param nameSpace name space of YANG module
- * @param conflictResolver object of YANG to java naming conflict util
+ * @param nameSpace name space of YANG module
+ * @param resolver object of YANG to java naming conflict util
* @return java package name as per java rules
*/
- private static String getPkgFromNameSpace(String nameSpace, YangToJavaNamingConflictUtil conflictResolver) {
+ private static String getPkgFromNameSpace(String nameSpace,
+ YangToJavaNamingConflictUtil resolver) {
ArrayList<String> pkgArr = new ArrayList<>();
nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
- String properNameSpace = nameSpace.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
- String[] nameSpaceArr = properNameSpace.split(COLAN);
+ String properNameSpace = nameSpace.replaceAll
+ (REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
+ String[] nameSpaceArr = properNameSpace.split(COLON);
Collections.addAll(pkgArr, nameSpaceArr);
- return getPkgFrmArr(pkgArr, conflictResolver);
+ return getPkgFrmArr(pkgArr, resolver);
}
/**
@@ -135,17 +137,17 @@
String dateInString = sdf.format(date);
String[] revisionArr = dateInString.split(HYPHEN);
- String rev = REVISION_PREFIX;
- rev = rev + revisionArr[INDEX_ZERO];
+ StringBuilder rev = new StringBuilder(REVISION_PREFIX)
+ .append(revisionArr[INDEX_ZERO]);
for (int i = INDEX_ONE; i < revisionArr.length; i++) {
Integer val = Integer.parseInt(revisionArr[i]);
if (val < VALUE_CHECK) {
- rev = rev + ZERO;
+ rev.append(ZERO);
}
- rev = rev + val;
+ rev.append(val);
}
- return rev;
+ return rev.toString();
}
/**
@@ -157,7 +159,7 @@
*/
private static String getPkgFrmArr(ArrayList<String> pkgArr, YangToJavaNamingConflictUtil conflictResolver) {
- String pkg = EMPTY_STRING;
+ StringBuilder pkg = new StringBuilder();
int size = pkgArr.size();
int i = 0;
for (String member : pkgArr) {
@@ -166,13 +168,13 @@
String prefix = getPrefixForIdentifier(conflictResolver);
member = prefix + member;
}
- pkg = pkg + member;
+ pkg.append(member);
if (i != size - 1) {
- pkg = pkg + PERIOD;
+ pkg.append(PERIOD);
}
i++;
}
- return pkg;
+ return pkg.toString();
}
/**
@@ -183,9 +185,9 @@
*/
public static String getEnumJavaAttribute(String name) {
- name = name.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
- String[] strArray = name.split(COLAN);
- String output = EMPTY_STRING;
+ name = name.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
+ String[] strArray = name.split(COLON);
+ StringBuilder output = new StringBuilder();
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<>();
stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
@@ -193,11 +195,11 @@
}
for (int i = 0; i < strArray.length; i++) {
if (i > 0 && i < strArray.length) {
- output = output + UNDER_SCORE;
+ output.append(UNDER_SCORE);
}
- output = output + strArray[i];
+ output.append(strArray[i]);
}
- return output;
+ return output.toString();
}
/**
@@ -212,24 +214,28 @@
throw new TranslatorException("current node must have java file info " +
yangNode.getName() + " in " +
yangNode.getLineNumber() + " at " +
- yangNode.getCharPosition()
- + " in " + yangNode.getFileName());
+ yangNode.getCharPosition() +
+ " in " + yangNode.getFileName());
}
String pkgInfo;
- JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
- String pkg = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(), javaFileInfo.getPackageFilePath());
+ JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) yangNode)
+ .getJavaFileInfo();
+ String pkg = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(),
+ javaFileInfo.getPackageFilePath());
+ JavaFileInfoTranslator parentInfo;
if (!doesPackageExist(pkg)) {
try {
File pack = createDirectories(pkg);
YangNode parent = getParentNodeInGenCode(yangNode);
if (parent != null) {
- pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
- addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), true,
- ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig());
+ parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ pkgInfo = parentInfo.getJavaName();
+ addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg),
+ true);
} else {
- pkgInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getJavaName();
- addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg), false,
- ((JavaFileInfoContainer) yangNode).getJavaFileInfo().getPluginConfig());
+ pkgInfo = javaFileInfo.getJavaName();
+ addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg),
+ false);
}
} catch (IOException e) {
throw new IOException("failed to create package-info file");
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodBodyTypes.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodBodyTypes.java
new file mode 100644
index 0000000..8df3345
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodBodyTypes.java
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+/**
+ * Represents method body types.
+ */
+enum MethodBodyTypes {
+
+ //Getter method body.
+ GETTER,
+
+ //Setter method body.
+ SETTER,
+
+ //Build method body.
+ BUILD,
+
+ //Constructor method body.
+ CONSTRUCTOR,
+
+ //Default constructor method body.
+ DEFAULT_CONSTRUCTOR,
+
+ //Hash code method body.
+ HASH_CODE,
+
+ //To string method body.
+ TO_STRING,
+
+ //Equals method body.
+ EQUALS,
+
+ //add to list method body.
+ ADD_TO_LIST,
+
+ //Augment map getter for full map.
+ AUGMENTED_MAP_GETTER,
+
+ //Augment map getter for value.
+ AUGMENTED_MAP_GET_VALUE,
+
+ //Augment map add
+ AUGMENTED_MAP_ADD,
+
+ //Manager methods
+ MANAGER_METHODS,
+
+ //Of method.
+ OF_METHOD,
+
+ //Hash code method
+ HASH_CODE_METHOD,
+
+ //Equals method.
+ EQUALS_METHOD,
+
+ //To string method
+ TO_STRING_METHOD,
+
+ //Enum method int value.
+ ENUM_METHOD_INT_VALUE,
+
+ //Enum method string value.
+ ENUM_METHOD_STRING_VALUE
+
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodClassTypes.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodClassTypes.java
new file mode 100644
index 0000000..0e19388
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodClassTypes.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Represents java method types for classes.
+ */
+enum MethodClassTypes {
+
+ //Method for interface files.
+ INTERFACE_TYPE,
+
+ //Method for implementation classes.
+ CLASS_TYPE
+}
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 583bb0a..682cbdc 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
@@ -21,75 +21,82 @@
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
+import java.util.LinkedHashMap;
import java.util.List;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
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.BracketType.OPEN_CLOSE_BRACKET;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.EIGHT_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentMapTypeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getCurNodeName;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_TYPE_CONFLICT;
-import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.SHORT_TYPE_CONFLICT;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_ADD;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_GETTER;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_GET_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.GETTER;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.MANAGER_METHODS;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.SETTER;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.TO_STRING;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.INTERFACE_TYPE;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getCompareToString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getGreaterThanCondition;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIfConditionBegin;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getLesserThanCondition;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getNewInstance;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getReturnString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifAndAndCondition;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifConditionForIntInTypeDefConstructor;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifEqualEqualCondition;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodBody;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodSignature;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodSignatureClose;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
import static org.onosproject.yangutils.utils.UtilConstants.ADD;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
+import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
-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;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
-import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
-import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DECODE;
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.DOUBLE;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
-import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.FOR;
+import static org.onosproject.yangutils.utils.UtilConstants.FOR_TYPE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
@@ -103,15 +110,10 @@
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;
-import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF;
+import static org.onosproject.yangutils.utils.UtilConstants.LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
-import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
@@ -122,38 +124,27 @@
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OF;
-import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.ONE;
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.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.PUT;
-import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
-import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
-import static org.onosproject.yangutils.utils.UtilConstants.SET;
+import static org.onosproject.yangutils.utils.UtilConstants.SELECT_ALL_CHILD;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.SET_SELECT_LEAF;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
@@ -161,28 +152,21 @@
import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.STR_VAL;
import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
+import static org.onosproject.yangutils.utils.UtilConstants.TO_CAPS;
import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
-import static org.onosproject.yangutils.utils.UtilConstants.TRY;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
@@ -220,69 +204,66 @@
/**
* Returns the methods strings for builder interface.
*
- * @param name attribute name
- * @param pluginConfig plugin configurations
+ * @param name attribute name
* @return method string for builder interface
*/
- public static String parseBuilderInterfaceBuildMethodString(String name,
- YangPluginConfig pluginConfig) {
- return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) +
+ public static String parseBuilderInterfaceBuildMethodString(String name) {
+ return getJavaDoc(BUILD_METHOD, name, false, null) +
getBuildForInterface(name);
}
/**
* Returns getter string.
*
- * @param attr attribute info
- * @param generatedJavaFiles generated java files
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param genType generated java files
* @return getter string
*/
- public static String getGetterString(JavaAttributeInfo attr,
- int generatedJavaFiles,
- YangPluginConfig pluginConfig) {
+ public static String getGetterString(JavaAttributeInfo attr, int genType) {
String returnType = getReturnType(attr);
String attributeName = attr.getAttributeName();
String appDataStructure = null;
+ StringBuilder builder = new StringBuilder();
if (attr.getCompilerAnnotation() != null) {
appDataStructure =
attr.getCompilerAnnotation().getYangAppDataStructure()
.getDataStructure().name();
}
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return generateForGetMethodWithAttribute(returnType) +
- getGetterForInterface(attributeName, returnType,
- attr.isListAttr(),
- generatedJavaFiles,
- attr.getCompilerAnnotation());
+ if (genType == GENERATE_SERVICE_AND_MANAGER) {
+ builder.append(generateForGetMethodWithAttribute(returnType))
+ .append(getGetterForInterface(
+ attributeName, returnType, attr.isListAttr(),
+ genType, attr.getCompilerAnnotation()));
+
+ return builder.toString();
}
- return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(),
- pluginConfig, appDataStructure) +
- getGetterForInterface(attributeName, returnType,
- attr.isListAttr(), generatedJavaFiles,
- attr.getCompilerAnnotation());
+ builder.append(getJavaDoc(GETTER_METHOD, attributeName, attr
+ .isListAttr(), appDataStructure))
+ .append(getGetterForInterface(
+ attributeName, returnType, attr.isListAttr(),
+ genType, attr.getCompilerAnnotation()));
+
+ return builder.toString();
}
/**
* Returns setter string.
*
- * @param attr attribute info
- * @param className java class name
- * @param generatedJavaFiles generated java files
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param className java class name
+ * @param genType generated java files
* @return setter string
*/
public static String getSetterString(JavaAttributeInfo attr,
- String className,
- int generatedJavaFiles,
- YangPluginConfig pluginConfig) {
+ String className, int genType) {
String attrType = getReturnType(attr);
String attributeName = attr.getAttributeName();
JavaDocGen.JavaDocType type;
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
+ StringBuilder builder = new StringBuilder();
+ if (genType == GENERATE_SERVICE_AND_MANAGER) {
type = MANAGER_SETTER_METHOD;
} else {
type = SETTER_METHOD;
@@ -294,23 +275,22 @@
attr.getCompilerAnnotation().getYangAppDataStructure()
.getDataStructure().name();
}
- return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig,
- appDataStructure) +
- getSetterForInterface(attributeName, attrType, className,
- attr.isListAttr(), generatedJavaFiles,
- attr.getCompilerAnnotation());
+ builder.append(getJavaDoc(type, attributeName, attr.isListAttr(),
+ appDataStructure))
+ .append(getSetterForInterface(attributeName, attrType, className,
+ attr.isListAttr(), genType,
+ attr.getCompilerAnnotation()));
+ return builder.toString();
}
/**
* Returns constructor method string.
*
- * @param name class name
- * @param pluginConfig plugin configurations
+ * @param name class name
* @return constructor string
*/
- private static String getConstructorString(String name,
- YangPluginConfig pluginConfig) {
- return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null);
+ private static String getConstructorString(String name) {
+ return getJavaDoc(CONSTRUCTOR, name, false, null);
}
/**
@@ -318,29 +298,15 @@
*
* @param name class name
* @param modifierType modifier type
- * @param pluginConfig plugin configurations
* @return default constructor string
*/
public static String getDefaultConstructorString(String name,
- String modifierType,
- YangPluginConfig pluginConfig) {
- return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null)
+ String modifierType) {
+ return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, null)
+ getDefaultConstructor(name, modifierType) + NEW_LINE;
}
/**
- * Returns check not null string.
- *
- * @param name attribute name
- * @return check not null string
- */
- static String getCheckNotNull(String name) {
- return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING +
- OPEN_PARENTHESIS + name + COMMA + SPACE + name +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- }
-
- /**
* Returns build method string.
*
* @param name class name
@@ -372,52 +338,46 @@
return getGetter(attrQualifiedType, attributeName,
generatedJavaFiles);
}
- String attrParam = getListAttribute(attrQualifiedType,
- attr.getCompilerAnnotation());
+ String attrParam = StringGenerator.getListAttribute(attrQualifiedType,
+ attr.getCompilerAnnotation());
return getGetter(attrParam, attributeName, generatedJavaFiles);
}
/**
* Returns getter for attribute.
*
- * @param type return type
- * @param name attribute name
- * @param generatedJavaFiles generated java files
+ * @param type return type
+ * @param name attribute name
+ * @param genType generated java files
* @return getter for attribute
*/
- static String getGetter(String type, String name, int generatedJavaFiles) {
- String ret = parseTypeForReturnValue(type);
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE +
- GET_METHOD_PREFIX + getCapitalCase(name) +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
- } else {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE +
- name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + name + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ static String getGetter(String type, String name, int genType) {
+ StringBuilder builder = new StringBuilder();
+ if (genType == GENERATE_SERVICE_AND_MANAGER) {
+ //Append method signature.
+ builder.append(methodSignature(getCapitalCase(name), GET,
+ PUBLIC, null, type, null,
+ CLASS_TYPE))
+ //Append method body.
+ .append(methodBody(MANAGER_METHODS, null, null,
+ EIGHT_SPACE_INDENTATION, null,
+ type, false))
+ .append(signatureClose())
+ //Append method close.
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
}
- }
-
- /*Provides string to return for type.*/
- private static String parseTypeForReturnValue(String type) {
- switch (type) {
- case BYTE:
- case INT:
- case SHORT:
- case LONG:
- case DOUBLE:
- return "0";
- case BOOLEAN_DATA_TYPE:
- return FALSE;
- default:
- return null;
- }
+ builder.append(methodSignature(name, EMPTY_STRING,
+ PUBLIC, null, type, null,
+ CLASS_TYPE))
+ //Append method body.
+ .append(methodBody(GETTER, name, name,
+ EIGHT_SPACE_INDENTATION, null,
+ type, false))
+ .append(signatureClose())
+ //Append method close.
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
}
/**
@@ -441,8 +401,8 @@
return getSetter(className, attributeName, attrQualifiedType,
generatedJavaFiles, isTypeNull, false);
}
- String attrParam = getListAttribute(attrQualifiedType,
- attr.getCompilerAnnotation());
+ String attrParam = StringGenerator.getListAttribute(attrQualifiedType,
+ attr.getCompilerAnnotation());
return getSetter(className, attributeName, attrParam,
generatedJavaFiles, isTypeNull, true);
}
@@ -458,45 +418,48 @@
* @return setter for attribute
*/
private static String getSetter(String className, String name, String type,
- int generatedJavaFiles,
+ int genType,
boolean isTypeNull, boolean isList) {
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
- SET_METHOD_PREFIX + getCapitalCase(name) +
- OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
- } else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
- name + OPEN_PARENTHESIS + type + SPACE + name +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name +
- SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
- } else {
- String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- className + BUILDER + SPACE + name + OPEN_PARENTHESIS +
- type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET;
- if (!isTypeNull && !isList) {
- method = method + getValueLeafSetString(name);
- } else {
- method = method + EMPTY_STRING;
- }
- return method + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS +
- PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN +
- NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE +
- THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET;
+ StringBuilder builder = new StringBuilder();
+ if (genType == GENERATE_SERVICE_AND_MANAGER) {
+ //Append method signature.
+ builder.append(methodSignature(getCapitalCase(name),
+ SET_METHOD_PREFIX,
+ PUBLIC, name, VOID, type,
+ CLASS_TYPE))
+ //Append method body.
+ .append(methodBody(MANAGER_METHODS, null, null,
+ EIGHT_SPACE_INDENTATION, null, null,
+ false))
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
}
+ if (genType == GENERATE_EVENT_SUBJECT_CLASS) {
+ builder.append(methodSignature(name, EMPTY_STRING, PUBLIC, name, VOID,
+ type, CLASS_TYPE))
- }
-
- //Returns value leaf flag setter.
- private static String getValueLeafSetString(String name) {
- return "\n getValueLeafFlags().set(LeafIdentifier." +
- name.toUpperCase() + ".getLeafIndex());";
+ //Append method body.
+ .append(methodBody(SETTER, name, name,
+ EIGHT_SPACE_INDENTATION, null, null,
+ false))
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+ builder.append(methodSignature(name, EMPTY_STRING,
+ PUBLIC, name, getCapitalCase(className) +
+ BUILDER, type, CLASS_TYPE));
+ if (!isTypeNull && !isList) {
+ builder.append(StringGenerator.getValueLeafSetString(name));
+ } else {
+ builder.append(EMPTY_STRING);
+ }
+ //Append method body.
+ builder.append(methodBody(SETTER, name, name,
+ EIGHT_SPACE_INDENTATION, null, null,
+ true))
+ //Append method close.
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
}
/**
@@ -520,44 +483,32 @@
* @return setter for type def's attribute
*/
private static String getTypeDefSetter(String type, String name) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
- SET_METHOD_PREFIX + getCapitalCase(name) + OPEN_PARENTHESIS +
- type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE +
- SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET;
- }
-
- /**
- * Returns override string.
- *
- * @return override string
- */
- public static String getOverRideString() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
+ return methodSignature(getCapitalCase(name), SET_METHOD_PREFIX, PUBLIC,
+ name, VOID, type, CLASS_TYPE) +
+ methodBody(SETTER, name, name, EIGHT_SPACE_INDENTATION, null,
+ null, false) + methodClose(FOUR_SPACE);
}
/**
* Returns the getter method strings for interface file.
*
- * @param yangName name of the attribute
- * @param returnType return type of attribute
- * @param isList is list attribute
- * @param generatedJavaFiles generated java files
- * @param compilerAnnotation compiler annotation
+ * @param yangName name of the attribute
+ * @param returnType return type of attribute
+ * @param isList is list attribute
+ * @param genType generated java files
+ * @param annotation compiler annotation
* @return getter method for interface
*/
static String getGetterForInterface(String yangName, String returnType,
boolean isList,
- int generatedJavaFiles,
- YangCompilerAnnotation compilerAnnotation) {
+ int genType,
+ YangCompilerAnnotation annotation) {
if (!isList) {
return getGetterInterfaceString(returnType, yangName,
- generatedJavaFiles);
+ genType);
}
- String listAttr = getListAttribute(returnType, compilerAnnotation);
- return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
+ String listAttr = StringGenerator.getListAttribute(returnType, annotation);
+ return getGetterInterfaceString(listAttr, yangName, genType);
}
/**
@@ -569,72 +520,60 @@
*/
private static String getGetterInterfaceString(String returnType,
String yangName,
- int generatedJavaFiles) {
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return getGetMethodWithArgument(returnType, yangName);
- } else {
- return FOUR_SPACE_INDENTATION + returnType + SPACE +
- yangName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- SEMI_COLAN;
+ int genType) {
+ switch (genType) {
+ case GENERATE_SERVICE_AND_MANAGER:
+ return getGetMethodWithArgument(returnType, yangName);
+ default:
+ return methodSignature(yangName, EMPTY_STRING, null,
+ null, returnType, null, INTERFACE_TYPE);
}
}
/**
* Returns the setter method strings for interface file.
*
- * @param attrName name of the attribute
- * @param attrType return type of attribute
- * @param className name of the java class being generated
- * @param isList is list attribute
- * @param generatedJavaFiles generated java files
- * @param compilerAnnotation compiler annotations
+ * @param attrName name of the attribute
+ * @param attrType return type of attribute
+ * @param className name of the java class being generated
+ * @param isList is list attribute
+ * @param genType generated java files
+ * @param annotation compiler annotations
* @return setter method for interface
*/
static String getSetterForInterface(String attrName, String attrType,
String className,
- boolean isList, int generatedJavaFiles,
- YangCompilerAnnotation compilerAnnotation) {
+ boolean isList, int genType,
+ YangCompilerAnnotation annotation) {
if (!isList) {
return getSetterInterfaceString(className, attrName, attrType,
- generatedJavaFiles);
+ genType);
}
- String listAttr = getListAttribute(attrType, compilerAnnotation);
- return getSetterInterfaceString(className, attrName, listAttr,
- generatedJavaFiles);
+ String listAttr = StringGenerator.getListAttribute(attrType, annotation);
+ return getSetterInterfaceString(className, attrName, listAttr, genType);
}
/**
* Returns setter string for interface.
*
- * @param className class name
- * @param attrName attribute name
- * @param attrType attribute type
+ * @param name class name
+ * @param attrName attribute name
+ * @param attrType attribute type
* @return setter string
*/
- private static String getSetterInterfaceString(String className,
+ private static String getSetterInterfaceString(String name,
String attrName,
String attrType,
- int generatedJavaFiles) {
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX +
- getCapitalCase(attrName) + OPEN_PARENTHESIS + attrType +
- OP_PARAM + SPACE + attrName + CLOSE_PARENTHESIS +
- SEMI_COLAN;
- } else {
- return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE +
- attrName + OPEN_PARENTHESIS + attrType + SPACE + attrName +
- CLOSE_PARENTHESIS + SEMI_COLAN;
+ int genType) {
+ if (genType == GENERATE_SERVICE_AND_MANAGER) {
+ return methodSignature(getCapitalCase(attrName),
+ SET_METHOD_PREFIX,
+ null, attrName, VOID, attrType +
+ OP_PARAM, INTERFACE_TYPE);
}
- }
-
- /**
- * Returns list string.
- *
- * @return list string
- */
- private static String getListString() {
- return LIST + DIAMOND_OPEN_BRACKET;
+ return methodSignature(attrName, EMPTY_STRING, null,
+ attrName, name + BUILDER, attrType, INTERFACE_TYPE);
}
/**
@@ -644,13 +583,16 @@
* @return return type
*/
private static String getReturnType(JavaAttributeInfo attr) {
- String returnType = EMPTY_STRING;
+ String returnType;
+ StringBuilder builder = new StringBuilder();
if (attr.isQualifiedName() &&
attr.getImportInfo().getPkgInfo() != null) {
returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
+ builder.append(returnType);
}
- returnType = returnType + attr.getImportInfo().getClassInfo();
- return returnType;
+ returnType = attr.getImportInfo().getClassInfo();
+ builder.append(returnType);
+ return builder.toString();
}
/**
@@ -660,124 +602,72 @@
* @return build method for interface
*/
static String getBuildForInterface(String yangName) {
- return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return methodSignature(BUILD, EMPTY_STRING, null, null,
+ yangName, null, INTERFACE_TYPE);
}
/**
* Returns constructor string for impl class.
*
- * @param yangName class name
- * @param pluginConfig plugin configurations
- * @param isRootNode if root node
+ * @param yangName class name
+ * @param isRootNode if root node
* @return constructor string
*/
static String getConstructorStart(String yangName,
- YangPluginConfig pluginConfig,
boolean isRootNode) {
- String javadoc = getConstructorString(yangName, pluginConfig);
+ StringBuilder builder = new StringBuilder(
+ getConstructorString(yangName));
- String returnType = getCapitalCase(DEFAULT) + yangName;
+ String name = getCapitalCase(yangName);
+ String returnType = DEFAULT_CAPS + name;
if (isRootNode) {
- returnType = yangName + OP_PARAM;
+ returnType = name + OP_PARAM;
}
- String constructor =
- FOUR_SPACE_INDENTATION + PROTECTED + SPACE + returnType +
- OPEN_PARENTHESIS + yangName + BUILDER + SPACE +
- BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
- return javadoc + constructor;
+ builder.append(methodSignature(
+ returnType, EMPTY_STRING, PROTECTED, BUILDER_LOWER_CASE + OBJECT,
+ null, name + BUILDER, CLASS_TYPE));
+ return builder.toString();
}
/**
* Returns the constructor strings for class file.
*
- * @param attr attribute info
- * @param generatedJavaFiles generated java files
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param genType generated java files
* @return constructor for class
*/
- public static String getConstructor(JavaAttributeInfo attr,
- int generatedJavaFiles,
- YangPluginConfig pluginConfig) {
-
- String attributeName = attr.getAttributeName();
- String constructor;
-
- if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- 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;
+ public static String getConstructor(JavaAttributeInfo attr, int genType) {
+ String attrName = attr.getAttributeName();
+ String attrCaps = getCapitalCase(attrName);
+ switch (genType) {
+ case GENERATE_SERVICE_AND_MANAGER:
+ return methodBody(MethodBodyTypes.CONSTRUCTOR, attrName,
+ attrCaps, EIGHT_SPACE_INDENTATION, GET, null,
+ false);
+ default:
+ return methodBody(MethodBodyTypes.CONSTRUCTOR, attrName,
+ attrName, EIGHT_SPACE_INDENTATION, EMPTY_STRING,
+ null, false);
}
- return constructor;
}
/**
* Returns the rpc strings for service interface.
*
- * @param rpcName name of the rpc
- * @param inputName name of input
- * @param outputName name of output
- * @param pluginConfig plugin configurations
+ * @param rpcName name of the rpc
+ * @param input name of input
+ * @param output name of output
* @return rpc method string
*/
- public static String getRpcServiceMethod(String rpcName, String inputName,
- String outputName,
- YangPluginConfig pluginConfig) {
-
- rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
- if (!inputName.equals(EMPTY_STRING)) {
- inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
+ public static String getRpcServiceMethod(String rpcName, String input,
+ String output) {
+ String inputVal = EMPTY_STRING;
+ if (!input.equals(EMPTY_STRING)) {
+ inputVal = RPC_INPUT_VAR_NAME;
}
- return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName +
- OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SEMI_COLAN;
- }
-
- /**
- * Returns the rpc strings for manager impl.
- *
- * @param rpcName name of the rpc
- * @param inputName name of input
- * @param outputName name of output
- * @param pluginConfig plugin configurations
- * @return rpc method string
- */
- public static String getRpcManagerMethod(String rpcName, String inputName,
- String outputName,
- YangPluginConfig pluginConfig) {
-
- rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
- if (!inputName.equals(EMPTY_STRING)) {
- 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;
- if (!outputName.contentEquals(VOID)) {
- method += EIGHT_SPACE_INDENTATION + RETURN + SPACE +
- parseTypeForReturnValue(outputName) + SEMI_COLAN + NEW_LINE;
- }
- method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
-
- return method;
+ return methodSignature(rpcName, EMPTY_STRING, null,
+ inputVal, output, input, INTERFACE_TYPE) +
+ NEW_LINE;
}
/**
@@ -788,16 +678,17 @@
* @return build method string for class
*/
static String getBuild(String yangName, boolean isRootNode) {
- String type = getCapitalCase(DEFAULT) + yangName;
+ String type = DEFAULT_CAPS + yangName;
if (isRootNode) {
type = yangName + OP_PARAM;
}
- 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 + type + OPEN_PARENTHESIS + THIS +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return methodSignature(BUILD, EMPTY_STRING, PUBLIC, null,
+ yangName, null,
+ CLASS_TYPE) +
+ methodBody(MethodBodyTypes.BUILD, type, BUILD,
+ EIGHT_SPACE_INDENTATION, EMPTY_STRING,
+ null, false) +
+ methodClose(FOUR_SPACE);
}
/**
@@ -809,10 +700,9 @@
*/
private static String getDefaultConstructor(String name,
String modifierType) {
- return FOUR_SPACE_INDENTATION + modifierType + SPACE + name +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET;
+ return methodSignature(name, EMPTY_STRING, modifierType, null,
+ null, null, CLASS_TYPE) +
+ methodClose(FOUR_SPACE);
}
/**
@@ -821,66 +711,15 @@
* @return string method's open string
*/
static String getToStringMethodOpen() {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE;
- }
-
- /**
- * Returns whether the data type is of primitive data type.
- *
- * @param dataType data type to be checked
- * @return true, if data type can have primitive data type, false otherwise
- */
- static boolean isPrimitiveDataType(YangDataTypes dataType) {
- return dataType == INT8
- || dataType == INT16
- || dataType == INT32
- || dataType == INT64
- || dataType == UINT8
- || dataType == UINT16
- || dataType == UINT32
- || dataType == UINT64
- || dataType == DECIMAL64
- || dataType == BOOLEAN
- || dataType == EMPTY;
-
- }
-
-
- static String getIfConditionBegin(String indentation, String condition) {
- return indentation + IF + SPACE + OPEN_PARENTHESIS + condition +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
- }
-
- static String getElseIfConditionBegin(String indentation,
- String condition) {
- return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE +
- getIfConditionBegin("", condition);
- }
-
- static String getBlockEnd(String indentation) {
- return indentation + CLOSE_CURLY_BRACKET + NEW_LINE;
- }
-
- static String getCollectionIteratorForLoopBegin(String indentation,
- String loopVar,
- String collection) {
- return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE +
- COLAN + SPACE + collection + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
- }
-
- /*
- * Returns omit null value string.
- *
- * @return omit null value string
- */
- static String getOmitNullValueString() {
- return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING +
- NEW_LINE;
+ String line;
+ StringBuilder builder = new StringBuilder(getOverRideString());
+ builder.append(methodSignature(TO + STRING_DATA_TYPE, EMPTY_STRING,
+ PUBLIC, null, STRING_DATA_TYPE, null,
+ CLASS_TYPE));
+ line = getReturnString(GOOGLE_MORE_OBJECT_METHOD_STRING,
+ EIGHT_SPACE_INDENTATION) + NEW_LINE;
+ builder.append(line);
+ return builder.toString();
}
/**
@@ -890,8 +729,8 @@
*/
static String getToStringMethodClose() {
return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ brackets(OPEN_CLOSE_BRACKET, null, null) + signatureClose() +
+ methodClose(FOUR_SPACE);
}
/**
@@ -901,27 +740,23 @@
* @return to string method
*/
public static String getToStringMethod(JavaAttributeInfo attr) {
-
String attributeName = attr.getAttributeName();
- return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING +
- OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES + COMMA +
- SPACE + attributeName + CLOSE_PARENTHESIS;
+ return methodBody(TO_STRING, attributeName, null,
+ TWELVE_SPACE_INDENTATION, null, null, false);
}
/**
* Returns from string method's open string.
*
- * @param className name of the class
- * @param pluginConfig plugin configurations
+ * @param className name of the class
* @return from string method's open string
*/
- static String getFromStringMethodSignature(String className,
- YangPluginConfig pluginConfig) {
- return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) +
- FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
- className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS +
- STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ static String getFromStringMethodSignature(String className) {
+ return getJavaDoc(FROM_METHOD, className, false, null) +
+ methodSignature(FROM_STRING_METHOD_NAME, EMPTY_STRING, PUBLIC +
+ SPACE + STATIC, FROM_STRING_PARAM_NAME,
+ className, STRING_DATA_TYPE,
+ CLASS_TYPE);
}
/**
@@ -930,126 +765,134 @@
* @return from string method's close string
*/
static String getFromStringMethodClose() {
- return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN +
- NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
+ return getReturnString(NULL, EIGHT_SPACE_INDENTATION) +
+ signatureClose() + methodClose(FOUR_SPACE);
}
/**
* Return from string method's body string.
*
- * @param attr attribute info
- * @param fromStringAttributeInfo attribute info for the from string wrapper
- * type
+ * @param attr attribute info
+ * @param fromAttr attribute info for the from string wrapper
+ * type
* @return from string method's body string
*/
public static String getFromStringMethod(JavaAttributeInfo attr,
- JavaAttributeInfo fromStringAttributeInfo) {
+ JavaAttributeInfo fromAttr) {
- return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE +
- TWELVE_SPACE_INDENTATION +
- getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE +
- TWELVE_SPACE_INDENTATION +
- getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION +
- getCatchSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ return EIGHT_SPACE_INDENTATION + StringGenerator.getTrySubString() +
+ StringGenerator.getNewLineAndSpace(TWELVE_SPACE_INDENTATION) +
+ getParsedSubString(attr, fromAttr) +
+ StringGenerator.getNewLineAndSpace(TWELVE_SPACE_INDENTATION) +
+ StringGenerator.getReturnOfSubString() +
+ StringGenerator.getNewLineAndSpace(EIGHT_SPACE_INDENTATION) +
+ StringGenerator.getCatchSubString() +
+ StringGenerator.getNewLineAndSpace(EIGHT_SPACE_INDENTATION) +
CLOSE_CURLY_BRACKET;
}
/**
- * Returns sub string with try statement for union's from string method.
- *
- * @return sub string with try statement for union's from string method
- */
- private static String getTrySubString() {
- return TRY + SPACE + OPEN_CURLY_BRACKET;
- }
-
- /**
- * Returns sub string with return statement for union's from string method.
- *
- * @return sub string with return statement for union's from string method
- */
- private static String getReturnOfSubString() {
- return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL +
- CLOSE_PARENTHESIS + SEMI_COLAN;
- }
-
- /**
- * Returns sub string with catch statement for union's from string method.
- *
- * @return sub string with catch statement for union's from string method
- */
- private static String getCatchSubString() {
- return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS +
- EXCEPTION + SPACE + EXCEPTION_VAR + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET;
- }
-
- /**
* Returns sub string with parsed statement for union's from string method.
*
* @param attr attribute info
* @return sub string with parsed statement for union's from string method
*/
private static String getParsedSubString(JavaAttributeInfo attr,
- JavaAttributeInfo fromStringAttributeInfo) {
+ JavaAttributeInfo fromStringAttr) {
String targetDataType = getReturnType(attr);
- if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) {
- String lines =
- targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
- NEW + SPACE + targetDataType + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
- EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
- REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE +
- OPEN_CURLY_BRACKET + SINGLE_QUOTE + COMMA + SPACE +
- SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
- EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
- REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE +
- CLOSE_CURLY_BRACKET + SINGLE_QUOTE + COMMA + SPACE +
- SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
- EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
- TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE +
- SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR + SPACE +
- EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
- SPLIT_STRING + OPEN_PARENTHESIS + QUOTES + COMMA + QUOTES +
- COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN +
- NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS +
- STRING_DATA_TYPE + SPACE + BIT_TEMP_VAR + SPACE + COLON +
- SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
- lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL +
- SPACE + BIT_TEMP_VAR + PERIOD + TRIM_STRING +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE;
- lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD +
- SET_METHOD_PREFIX + OPEN_PARENTHESIS + INTEGER_WRAPPER +
- PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR +
- CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN +
- NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
- return lines;
- } else if (attr.getAttributeType().getDataType() == BINARY) {
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
- BASE64 + PERIOD + GET_DECODER + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS +
- FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
- } else {
- String parseFromStringMethod =
- getParseFromStringMethod(targetDataType,
- fromStringAttributeInfo
- .getAttributeType());
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
- parseFromStringMethod + OPEN_PARENTHESIS +
- FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
+ StringBuilder builder = new StringBuilder();
+ YangDataTypes types = fromStringAttr.getAttributeType()
+ .getDataType();
+ switch (types) {
+ case BITS:
+ String lines =
+ targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
+ NEW + SPACE + targetDataType + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
+ builder.append(lines);
+ /*
+ *" valInString = valInString.replace("{", " ");\n";
+ */
+ lines = TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE +
+ OPEN_CURLY_BRACKET + SINGLE_QUOTE + COMMA + SPACE +
+ SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS +
+ SEMI_COLON + NEW_LINE;
+ builder.append(lines);
+ /*
+ *" valInString = valInString.replace({, " ");\n";
+ */
+ lines = TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE +
+ CLOSE_CURLY_BRACKET + SINGLE_QUOTE + COMMA + SPACE +
+ SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS +
+ SEMI_COLON + NEW_LINE;
+ builder.append(lines);
+ /*
+ *" valInString = valInString.trim();\n"
+ */
+ lines = TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
+ SEMI_COLON + NEW_LINE;
+ builder.append(lines);
+ /*
+ *" String[] bitsTemp = valInString.split(",", 0);\n"
+ */
+ lines = TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE +
+ SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ SPLIT_STRING + OPEN_PARENTHESIS + QUOTES + COMMA + QUOTES +
+ COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLON +
+ NEW_LINE;
+ builder.append(lines);
+ /*
+ *" for (String bitTemp : bitsTemp) {\n"
+ */
+ lines = TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS +
+ STRING_DATA_TYPE + SPACE + BIT_TEMP_VAR + SPACE + COLON +
+ SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
+ builder.append(lines);
+ /*
+ *" bitTemp = bitTemp.trim();\n"
+ */
+ lines = SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL +
+ SPACE + BIT_TEMP_VAR + PERIOD + TRIM_STRING +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
+ SEMI_COLON + NEW_LINE;
+ builder.append(lines);
+ /*
+ *" tmpVal.set(Integer.parseInt(bitTemp));\n"
+ */
+ lines = SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD +
+ SET_METHOD_PREFIX + OPEN_PARENTHESIS + INTEGER_WRAPPER +
+ PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR +
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLON +
+ NEW_LINE;
+ builder.append(lines);
+ /*
+ *" }\n"
+ */
+ lines = TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ builder.append(lines);
+ return builder.toString();
+ case BINARY:
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
+ BASE64 + PERIOD + GET_DECODER + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS +
+ FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLON
+ + NEW_LINE;
+ default:
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL +
+ SPACE + StringGenerator.getParseFromStringMethod(
+ targetDataType, fromStringAttr.getAttributeType()) +
+ OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
}
}
@@ -1059,11 +902,14 @@
* @return hash code method open string
*/
static String getHashCodeMethodOpen() {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- INT + SPACE + HASH_CODE_STRING + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + OBJECT_STRING +
- SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS;
+ String line;
+ StringBuilder builder = new StringBuilder(getOverRideString());
+ builder.append(methodSignature(HASH_CODE_STRING, EMPTY_STRING, PUBLIC,
+ null, INT, null, CLASS_TYPE));
+ line = getReturnString(OBJECT_STRING + SUFFIX_S + PERIOD + HASH +
+ OPEN_PARENTHESIS, EIGHT_SPACE_INDENTATION);
+ builder.append(line);
+ return builder.toString();
}
/**
@@ -1073,10 +919,10 @@
* @return to hash code method close string
*/
static String getHashCodeMethodClose(String hashcodeString) {
- hashcodeString = trimAtLast(hashcodeString, COMMA);
- hashcodeString = trimAtLast(hashcodeString, SPACE);
- return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ String[] array = {SPACE, COMMA};
+ hashcodeString = trimAtLast(hashcodeString, array);
+ return hashcodeString + CLOSE_PARENTHESIS + signatureClose() +
+ methodClose(FOUR_SPACE);
}
/**
@@ -1096,10 +942,10 @@
* @return equals method open string
*/
static String getEqualsMethodOpen(String className) {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING + OPEN_PARENTHESIS +
- OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE +
+ return getOverRideString() +
+ methodSignature(EQUALS_STRING, EMPTY_STRING, PUBLIC, OBJ,
+ BOOLEAN_DATA_TYPE, OBJECT_STRING,
+ CLASS_TYPE) +
getEqualsMethodsCommonIfCondition() +
getEqualsMethodsSpecificIfCondition(className);
}
@@ -1110,12 +956,10 @@
* @return if condition string
*/
private static String getEqualsMethodsCommonIfCondition() {
- return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS +
- SPACE + EQUAL + EQUAL + SPACE + OBJ + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- TWELVE_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLAN +
- NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
+ return getIfConditionBegin(EIGHT_SPACE_INDENTATION, THIS + SPACE +
+ EQUAL + EQUAL + SPACE + OBJ) + getReturnString(
+ TRUE, TWELVE_SPACE_INDENTATION) + signatureClose()
+ + methodClose(EIGHT_SPACE);
}
/**
@@ -1130,7 +974,7 @@
OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION +
className + SPACE + OTHER + SPACE + EQUAL + SPACE +
OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE + OBJ +
- SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN +
+ SEMI_COLON + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN +
NEW_LINE;
}
@@ -1141,15 +985,12 @@
* @return equals method close string
*/
static String getEqualsMethodClose(String equalMethodString) {
- equalMethodString = trimAtLast(equalMethodString, AND);
- equalMethodString = trimAtLast(equalMethodString, AND);
- equalMethodString = trimAtLast(equalMethodString, SPACE);
- equalMethodString =
- trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE;
- return equalMethodString + EIGHT_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ String[] array = {NEW_LINE, AND, AND, SPACE};
+ equalMethodString = trimAtLast(equalMethodString, array) +
+ signatureClose();
+ return equalMethodString + methodClose(EIGHT_SPACE) +
+ getReturnString(FALSE, EIGHT_SPACE_INDENTATION) +
+ signatureClose() + methodClose(FOUR_SPACE);
}
/**
@@ -1159,115 +1000,89 @@
* @return equals method
*/
public static String getEqualsMethod(JavaAttributeInfo attr) {
-
String attributeName = attr.getAttributeName();
- return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S +
+ return SIXTEEN_SPACE_INDENTATION + OBJECT_STRING + SUFFIX_S +
PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + attributeName +
COMMA + SPACE + OTHER + PERIOD + attributeName +
CLOSE_PARENTHESIS + SPACE + AND + AND;
}
/**
- * Returns of method string for class.
- *
- * @param name class name
- * @param attr attribute info
- * @return of method string
- */
- static String getOfMethod(String name, JavaAttributeInfo attr) {
- String attrQualifiedType = getReturnType(attr);
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name +
- SPACE + OF + OPEN_PARENTHESIS + attrQualifiedType + SPACE +
- VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW +
- SPACE + name + OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
- }
-
- /**
* Returns of method's string and java doc for special type.
*
- * @param attr attribute info
- * @param generatedJavaClassName class name
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param className class name
* @return of method's string and java doc for special type
*/
public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr,
- String generatedJavaClassName,
- YangPluginConfig pluginConfig) {
-
+ String className) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " +
- attrName, false, pluginConfig, null) +
- getOfMethodString(attrType, generatedJavaClassName);
+ return getJavaDoc(OF_METHOD, className + FOR_TYPE_STRING + attrName,
+ false, null) + getOfMethodString(attrType, className);
}
/**
* Returns of method's string.
*
- * @param type data type
- * @param className class name
+ * @param type data type
+ * @param name class name
* @return of method's string
*/
- private static String getOfMethodString(String type, String className) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
- className + SPACE + OF + OPEN_PARENTHESIS + type + SPACE +
- VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW +
- SPACE + className + OPEN_PARENTHESIS + VALUE +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ private static String getOfMethodString(String type, String name) {
+ return methodSignature(OF, EMPTY_STRING, PUBLIC + SPACE + STATIC,
+ VALUE, name, type, CLASS_TYPE) +
+ methodBody(MethodBodyTypes.OF_METHOD, name, null,
+ EIGHT_SPACE_INDENTATION, EMPTY_STRING, null, false) +
+ methodClose(FOUR_SPACE);
}
/**
* Returns string and java doc for constructor of type class.
*
- * @param attr attribute info
- * @param generatedJavaClassName class name
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param className class name
* @return string and java doc for constructor of type class
*/
- public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
- String generatedJavaClassName,
- YangPluginConfig pluginConfig) {
-
+ public static String getTypeConstructorStringAndJavaDoc(
+ JavaAttributeInfo attr, String className) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName +
- " for type " + attrName, false, pluginConfig, null) +
- getTypeConstructorString(attrType, attrName,
- generatedJavaClassName);
+ return getJavaDoc(TYPE_CONSTRUCTOR, attrName, false, null) +
+ getTypeConstructorString(attrType, attrName, className);
}
/**
* Returns string and java doc for constructor of type class.
*
- * @param attr1 first attribute info
- * @param attr2 second attribute info
- * @param generatedJavaClassName class name
- * @param pluginConfig plugin config
- * @param type conflict validate type
- * @param addFirst whether int came first or uInt came first
+ * @param attr1 first attribute info
+ * @param attr2 second attribute info
+ * @param genType class name
+ * @param type conflict validate type
+ * @param addFirst whether int came first or uInt came first
* @return string and java doc for constructor of type class
*/
- public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1,
- JavaAttributeInfo attr2,
- String generatedJavaClassName,
- YangPluginConfig pluginConfig,
- ValidatorTypeForUnionTypes type,
- boolean addFirst) {
+ public static String getTypeConstructorStringAndJavaDoc(
+ JavaAttributeInfo attr1, JavaAttributeInfo attr2, String genType,
+ ValidatorTypeForUnionTypes type, boolean addFirst) {
String attrType = getReturnType(attr1);
String attrName1 = "";
String attrName2 = "";
if (attr1 != null) {
- attrName1 = attr1.getAttributeName();
+ if (addFirst) {
+ attrName1 = attr1.getAttributeName();
+ } else {
+ attrName2 = attr1.getAttributeName();
+ }
}
if (attr2 != null) {
- attrName2 = attr2.getAttributeName();
+ if (addFirst) {
+ attrName1 = attr2.getAttributeName();
+ } else {
+ attrName2 = attr2.getAttributeName();
+ }
}
String appDataStructure = null;
@@ -1276,13 +1091,16 @@
attr1.getCompilerAnnotation().getYangAppDataStructure()
.getDataStructure().name();
}
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName +
- " for type " + attrName1, false,
- pluginConfig, appDataStructure) +
+ String doc;
+ if (attrName1.isEmpty()) {
+ doc = attrName2;
+ } else {
+ doc = attrName1;
+ }
+ return getJavaDoc(TYPE_CONSTRUCTOR, doc, false, appDataStructure) +
getTypeConstructorString(attrType, attrName1,
- attrName2, generatedJavaClassName,
- type,
- addFirst);
+ attrName2, genType,
+ type, addFirst);
}
/**
@@ -1295,12 +1113,10 @@
*/
private static String getTypeConstructorString(String type, String name,
String className) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className +
- OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL +
- SPACE + VALUE + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return methodSignature(className, EMPTY_STRING, PUBLIC, name,
+ null, type, CLASS_TYPE) +
+ methodBody(SETTER, name, null, EIGHT_SPACE_INDENTATION,
+ EMPTY_STRING, null, false) + methodClose(FOUR_SPACE);
}
/**
@@ -1311,38 +1127,28 @@
* @param className class attr1
* @return type constructor string
*/
- private static String getTypeConstructorString(String type, String attr1,
- String attr2,
- String className,
- ValidatorTypeForUnionTypes validatorType,
- boolean addInt) {
+ private static String getTypeConstructorString(
+ String type, String attr1, String attr2, String className,
+ ValidatorTypeForUnionTypes validatorType, boolean addInt) {
- String constructor;
- constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className +
- OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ StringBuilder constructor = new StringBuilder(
+ methodSignature(className, EMPTY_STRING, null, type,
+ null, type, CLASS_TYPE))
+ .append(ifConditionForIntInTypeDefConstructor(validatorType,
+ addInt))
+ .append(methodBody(SETTER, attr1, null,
+ TWELVE_SPACE_INDENTATION, EMPTY_STRING,
+ null, false));
+ String str = EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE +
+ ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ constructor.append(str)
+ .append(methodBody(SETTER, attr2, null,
+ TWELVE_SPACE_INDENTATION, EMPTY_STRING,
+ null, false))
+ .append(methodClose(FOUR_SPACE))
+ .append(methodClose(EIGHT_SPACE));
- String name1;
- String name2;
- if (addInt) {
- name1 = attr1;
- name2 = attr2;
- } else {
- name1 = attr2;
- name2 = attr1;
- }
- constructor = constructor +
- ifConditionForIntInTypeDefConstructor(validatorType, addInt) +
- TWELVE_SPACE_INDENTATION + THIS + PERIOD + name1 + SPACE +
- EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE +
- EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + ELSE +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- TWELVE_SPACE_INDENTATION + THIS + PERIOD + name2 + SPACE +
- EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE +
- EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
-
- return constructor;
+ return constructor.toString();
}
/**
@@ -1351,12 +1157,14 @@
* @return interface of add augmentation
*/
static String getAddAugmentInfoMethodInterface() {
- return generateForAddAugmentation() + FOUR_SPACE_INDENTATION + VOID +
- SPACE +
- ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS +
- OBJECT_STRING + SPACE + VALUE + COMMA +
- SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ StringBuilder builder = new StringBuilder(generateForAddAugmentation());
+ LinkedHashMap<String, String> map = new LinkedHashMap<>();
+ map.put(OBJECT_STRING, VALUE);
+ map.put(CLASS_STRING, CLASS + OBJECT_STRING);
+ builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
+ EMPTY_STRING, EMPTY_STRING,
+ VOID, map, INTERFACE_TYPE));
+ return builder.toString();
}
/**
@@ -1365,19 +1173,18 @@
* @return implementation of add augmentation
*/
static String getAddAugmentInfoMethodImpl() {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- VOID + SPACE +
- ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS +
- OBJECT_STRING + SPACE + VALUE + COMMA +
- SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION +
- getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT +
- OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE +
- VALUE +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
+ StringBuilder builder = new StringBuilder(getOverRideString());
+ LinkedHashMap<String, String> map = new LinkedHashMap<>();
+ map.put(OBJECT_STRING, VALUE);
+ map.put(CLASS_STRING, CLASS + OBJECT_STRING);
+ builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
+ EMPTY_STRING, PUBLIC,
+ VOID, map, CLASS_TYPE))
+ .append(methodBody(AUGMENTED_MAP_ADD, null, null,
+ EIGHT_SPACE_INDENTATION, null, null, false))
+ .append(methodClose(FOUR_SPACE))
+ .append(NEW_LINE);
+ return builder.toString();
}
/**
@@ -1386,11 +1193,10 @@
* @return interface of get YANG augment info
*/
static String getYangAugmentInfoInterface() {
- return generateForGetAugmentation() + FOUR_SPACE_INDENTATION +
- OBJECT_STRING + SPACE +
- getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS +
- CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return generateForGetAugmentation() +
+ methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE, EMPTY_STRING,
+ null, CLASS + OBJECT_STRING,
+ OBJECT_STRING, CLASS_STRING, INTERFACE_TYPE);
}
/**
@@ -1399,17 +1205,13 @@
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoImpl() {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- OBJECT_STRING + SPACE +
- getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS +
- CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP +
- PERIOD + GET + OPEN_PARENTHESIS + CLASS +
- OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
+ return getOverRideString() +
+ methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE, EMPTY_STRING,
+ PUBLIC, CLASS + OBJECT_STRING, OBJECT_STRING,
+ CLASS_STRING, CLASS_TYPE) +
+ methodBody(AUGMENTED_MAP_GET_VALUE, null, null,
+ EIGHT_SPACE_INDENTATION, null, null, false) +
+ methodClose(FOUR_SPACE);
}
/**
@@ -1417,17 +1219,13 @@
*
* @return implementation of get YANG augment info
*/
- static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
- return getJavaDoc(GETTER_METHOD,
- getSmallCase(YANG_AUGMENTED_INFO) + MAP, false,
- pluginConfig, null) + FOUR_SPACE_INDENTATION + MAP +
- DIAMOND_OPEN_BRACKET +
- CLASS_STRING + DIAMOND_OPEN_BRACKET +
- QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE +
- OBJECT_STRING + DIAMOND_CLOSE_BRACKET +
- SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP +
- OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ static String getYangAugmentInfoMapInterface() {
+ return NEW_LINE +
+ getJavaDoc(GETTER_METHOD, YANG_AUGMENTED_INFO_LOWER_CASE + MAP,
+ false, null) +
+ methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE + MAP,
+ EMPTY_STRING, null, null,
+ getAugmentMapTypeString(), null, INTERFACE_TYPE);
}
/**
@@ -1436,17 +1234,12 @@
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoMapImpl() {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING +
- DIAMOND_OPEN_BRACKET + QUESTION_MARK +
- DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING +
- DIAMOND_CLOSE_BRACKET + SPACE +
- getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP +
- SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
+ return getOverRideString() + methodSignature(
+ YANG_AUGMENTED_INFO_LOWER_CASE + MAP, EMPTY_STRING, PUBLIC, null,
+ getAugmentMapTypeString(), null, CLASS_TYPE) +
+ methodBody(AUGMENTED_MAP_GETTER, null, null,
+ EIGHT_SPACE_INDENTATION, null, null, false) +
+ methodClose(FOUR_SPACE);
}
/**
@@ -1456,146 +1249,108 @@
* @return enum's constructor
*/
static String getEnumsConstructor(String className) {
- return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT +
- SPACE + VALUE + COMMA + SPACE + STRING_DATA_TYPE + SPACE +
- STR_VAL + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION +
- getSmallCase(className) + SPACE + EQUAL + SPACE + VALUE +
- SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + SCHEMA_NAME +
- SPACE + EQUAL + SPACE + STR_VAL + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ StringBuilder builder = new StringBuilder();
+ String clsName = getSmallCase(className);
+ LinkedHashMap<String, String> map = new LinkedHashMap<>();
+ map.put(INT, clsName);
+ map.put(STRING_DATA_TYPE, SCHEMA_NAME);
+ builder.append(multiAttrMethodSignature(className, EMPTY_STRING,
+ EMPTY_STRING, null,
+ map, CLASS_TYPE))
+ .append(methodBody(SETTER, clsName, EMPTY_STRING,
+ EIGHT_SPACE_INDENTATION, EMPTY_STRING,
+ EMPTY_STRING, false))
+ .append(methodBody(SETTER, SCHEMA_NAME, EMPTY_STRING,
+ EIGHT_SPACE_INDENTATION, EMPTY_STRING,
+ EMPTY_STRING, false))
+ .append(methodClose(FOUR_SPACE));
+
+ return builder.toString();
}
/**
* Returns of method for enum class.
*
- * @param className class name
- * @param pluginConfig plugin configurations
+ * @param className class name
+ * @param type method body type
* @return of method
*/
static String getEnumsOfValueMethod(String className,
YangEnumeration enumeration,
- YangPluginConfig pluginConfig) {
-
- String method =
- FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
- getCapitalCase(className) + SPACE + OF +
- OPEN_PARENTHESIS + INT + SPACE + VALUE +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION + SWITCH + SPACE +
- OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
- int value;
+ MethodBodyTypes type) {
+ String name = getCapitalCase(className);
+ StringBuilder builder = new StringBuilder(getJavaDoc(
+ OF_METHOD, name + SPACE + FOR,
+ false, null));
+ //Switch statement.
+ String sw = EIGHT_SPACE_INDENTATION + SWITCH + SPACE + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null) +
+ methodSignatureClose(CLASS_TYPE);
String str;
- for (YangEnum yangEnum : enumeration.getEnumSet()) {
- value = yangEnum.getValue();
- str = getEnumJavaAttribute(yangEnum.getNamedValue()).toUpperCase();
- method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value +
- COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN +
- SPACE + getCapitalCase(className) + PERIOD + str +
- SEMI_COLAN + NEW_LINE;
- }
- method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON +
- NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET;
-
- return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for value",
- false, pluginConfig, null) + method;
- }
-
- /**
- * Returns of method with string value for enum class.
- *
- * @param enumName enum class name
- * @return of method with string value for enum class
- */
- static String getEnumValueOfSchemaNameMethod(String enumName,
- YangPluginConfig pluginConfig,
- YangEnumeration enumeration) {
-
- String method =
- FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
- getCapitalCase(enumName) + SPACE + OF +
- OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE + VALUE +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION + SWITCH + SPACE +
- OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
- String value;
- for (YangEnum yangEnum : enumeration.getEnumSet()) {
-
- value = getEnumJavaAttribute(yangEnum.getNamedValue())
- .toUpperCase();
- method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + QUOTES +
- yangEnum.getNamedValue() + QUOTES + COLON + NEW_LINE +
- SIXTEEN_SPACE_INDENTATION + RETURN + SPACE +
- getCapitalCase(enumName) + PERIOD + value + SEMI_COLAN +
- NEW_LINE;
- }
- method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON +
- NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET;
-
- return getJavaDoc(OF_METHOD, getCapitalCase(enumName) + " for " +
- SCHEMA_NAME, false, pluginConfig, null) + method;
- }
-
- /**
- * Returns from string method parsed string.
- *
- * @param targetDataType target data type
- * @param yangType YANG type
- * @return parsed string
- */
- private static String getParseFromStringMethod(String targetDataType,
- YangType<?> yangType) {
- YangDataTypes type = yangType.getDataType();
-
switch (type) {
- case INT8:
- return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
- case INT16:
- return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
- case INT32:
- return INTEGER_WRAPPER + PERIOD + PARSE_INT;
- case INT64:
- return LONG_WRAPPER + PERIOD + PARSE_LONG;
- case UINT8:
- return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
- case UINT16:
- return INTEGER_WRAPPER + PERIOD + PARSE_INT;
- case UINT32:
- return LONG_WRAPPER + PERIOD + PARSE_LONG;
- case UINT64:
- return NEW + SPACE + BIG_INTEGER;
- case DECIMAL64:
- return NEW + SPACE + BIG_DECIMAL;
- case STRING:
- case IDENTITYREF:
- return EMPTY_STRING;
- case EMPTY:
- case BOOLEAN:
- return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
- case BITS:
- case UNION:
- case ENUMERATION:
- case DERIVED:
- return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
+ case ENUM_METHOD_INT_VALUE:
+ builder.append(getEnumValueMethodSignature(name, INT))
+ .append(sw);
+ for (YangEnum yangEnum : enumeration.getEnumSet()) {
+ str = getEnumJavaAttribute(yangEnum.getNamedValue())
+ .toUpperCase();
+ builder.append(getEnumValueMethodCases(
+ EMPTY_STRING + yangEnum.getValue(), str, name));
+ }
+ break;
+ case ENUM_METHOD_STRING_VALUE:
+ builder.append(getEnumValueMethodSignature(name,
+ STRING_DATA_TYPE))
+ .append(sw);
+ for (YangEnum yangEnum : enumeration.getEnumSet()) {
+ str = getEnumJavaAttribute(yangEnum.getNamedValue())
+ .toUpperCase();
+ builder.append(getEnumValueMethodCases(
+ QUOTES + yangEnum.getNamedValue() + QUOTES, str,
+ name));
+ }
+ break;
default:
- throw new TranslatorException("given data type is not " +
- "supported. " +
- yangType.getDataTypeName() +
- " in " +
- yangType.getLineNumber() +
- " at " +
- yangType.getCharPosition() +
- " in " +
- yangType.getFileName());
+ return null;
}
+
+ String method = TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON +
+ NEW_LINE;
+ builder.append(method)
+ .append(getReturnString(NULL, SIXTEEN_SPACE_INDENTATION))
+ .append(signatureClose())
+ .append(methodClose(EIGHT_SPACE))
+ .append(methodClose(FOUR_SPACE));
+
+ return builder.toString();
+ }
+
+ /**
+ * Returns enum value method signature.
+ *
+ * @param name method name
+ * @param type param type
+ * @return enum value method signature
+ */
+ private static String getEnumValueMethodSignature(String name, String type) {
+ return methodSignature(OF, EMPTY_STRING, PUBLIC + SPACE +
+ STATIC, VALUE, name, type, CLASS_TYPE);
+ }
+
+ /**
+ * Returns enum value method's cases.
+ *
+ * @param caseType case type
+ * @param value return value
+ * @param name name of class
+ * @return enum value method's cases
+ */
+ private static String getEnumValueMethodCases(String caseType, String value,
+ String name) {
+ return TWELVE_SPACE_INDENTATION + CASE + SPACE + caseType +
+ COLON + NEW_LINE + getReturnString(name,
+ SIXTEEN_SPACE_INDENTATION) +
+ PERIOD + value + signatureClose();
}
/**
@@ -1625,13 +1380,14 @@
((JavaFileInfoContainer) methodNode).getJavaFileInfo()
.getJavaName();
} else {
- curNodeName = getCapitalCase(getCamelCase(methodNode.getName(),
- pluginConfig.getConflictResolver()));
+ curNodeName = getCapitalCase(
+ getCamelCase(methodNode.getName(),
+ pluginConfig.getConflictResolver()));
}
returnType =
getAugmentedClassNameForDataMethods(augmentedNode, parent);
- parentName = getParentNodeNameForDataMethods(augmentedNode,
- pluginConfig);
+ parentName = getCurNodeName(augmentedNode,
+ pluginConfig);
method = generateForGetMethodWithAttribute(returnType) +
getGetMethodWithArgument(returnType, AUGMENTED +
parentName + getCapitalCase(curNodeName)) + NEW_LINE;
@@ -1640,7 +1396,7 @@
method = getJavaDoc(MANAGER_SETTER_METHOD,
AUGMENTED + getCapitalCase(parentName) +
getCapitalCase(curNodeName), false,
- pluginConfig, null) +
+ null) +
getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
getCapitalCase(curNodeName),
returnType, parentName, false,
@@ -1664,84 +1420,57 @@
} else {
newType = INT;
}
- String method = generateForValidatorMethod() + FOUR_SPACE_INDENTATION +
- PRIVATE + SPACE + BOOLEAN_DATA_TYPE + SPACE + VALIDATE_RANGE +
- OPEN_PARENTHESIS + type + SPACE + MIN_RANGE + COMMA + SPACE +
- type + SPACE + MAX_RANGE + COMMA + SPACE + newType + SPACE +
- VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE;
+ StringBuilder builder = new StringBuilder(generateForValidatorMethod());
+ String var = getSmallCase(BIG_INTEGER);
+ LinkedHashMap<String, String> map = new LinkedHashMap<>();
+ map.put(MIN_RANGE, type);
+ map.put(MAX_RANGE, type);
+ map.put(VALUE, newType);
+ builder.append(multiAttrMethodSignature(VALIDATE_RANGE, EMPTY_STRING,
+ PRIVATE, BOOLEAN_DATA_TYPE, map,
+ CLASS_TYPE));
if (type.contentEquals(BIG_INTEGER)) {
- method = method + EIGHT_SPACE_INDENTATION + BIG_INTEGER + SPACE +
- getSmallCase(BIG_INTEGER) + SPACE + EQUAL + SPACE + NEW +
- SPACE + BIG_INTEGER + OPEN_PARENTHESIS + QUOTES + SPACE +
- QUOTES + SPACE + ADD + SPACE + VALUE + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN +
- SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" +
- OPEN_PARENTHESIS + MIN_RANGE + CLOSE_PARENTHESIS + SPACE +
- EQUAL + EQUAL + " 1" + SPACE + AND +
- AND + SPACE + getSmallCase(BIG_INTEGER) + PERIOD +
- "compareTo" + OPEN_PARENTHESIS + MAX_RANGE +
- CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" +
- SEMI_COLAN + NEW_LINE;
+ //Create new instance of big integer.
+ builder.append(getNewInstance(BIG_INTEGER, var, EIGHT_SPACE_INDENTATION,
+ QUOTES + SPACE + QUOTES + SPACE +
+ ADD + SPACE + VALUE))
+ //Add return string.
+ .append(getReturnString(var, EIGHT_SPACE_INDENTATION))
+ //Add compareTo string
+ .append(getCompareToString())
+ //Add && condition.
+ .append(ifAndAndCondition(
+ //Add == condition
+ ifEqualEqualCondition(
+ brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
+ MIN_RANGE, null), ONE),
+ var))
+ //Add compareTo string.
+ .append(getCompareToString())
+ //Add == condition.
+ .append(ifEqualEqualCondition(
+ brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
+ MAX_RANGE, null), ONE))
+ .append(signatureClose());
} else {
- method = method + EIGHT_SPACE_INDENTATION + RETURN + SPACE + VALUE +
- SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE + MIN_RANGE +
- SPACE + AND + AND + SPACE + VALUE + SPACE +
- DIAMOND_OPEN_BRACKET + EQUAL + SPACE + MAX_RANGE +
- SEMI_COLAN + NEW_LINE;
+ builder.append(getReturnString(VALUE, EIGHT_SPACE_INDENTATION))
+ .append(getGreaterThanCondition())
+ .append(ifAndAndCondition(MIN_RANGE, VALUE))
+ .append(getLesserThanCondition())
+ .append(MAX_RANGE)
+ .append(signatureClose());
}
- return method + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
- }
-
- /**
- * Returns if condition string for typedef constructor.
- *
- * @param type type of conflict
- * @param addFirst true int/long need to be added first
- * @return if condition string for typedef constructor
- */
- private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type,
- boolean addFirst) {
- String condition =
- EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
- VALIDATE_RANGE + OPEN_PARENTHESIS;
-
- if (type == INT_TYPE_CONFLICT) {
- if (addFirst) {
- condition = condition + INT_MIN_RANGE + COMMA + SPACE +
- INT_MAX_RANGE + COMMA + SPACE + VALUE;
- } else {
- condition = condition + UINT_MIN_RANGE + COMMA + SPACE +
- UINT_MAX_RANGE + COMMA + SPACE + VALUE;
- }
- } else if (type == SHORT_TYPE_CONFLICT) {
- if (addFirst) {
- condition = condition + SHORT_MIN_RANGE + COMMA + SPACE +
- SHORT_MAX_RANGE + COMMA + SPACE + VALUE;
- } else {
- condition = condition + UINT8_MIN_RANGE + COMMA + SPACE +
- UINT8_MAX_RANGE + COMMA + SPACE + VALUE;
- }
- } else {
- if (addFirst) {
- condition = condition + LONG_MIN_RANGE + COMMA + SPACE +
- LONG_MAX_RANGE + COMMA + SPACE + VALUE;
- } else {
- condition = condition + ULONG_MIN_RANGE + COMMA + SPACE +
- ULONG_MAX_RANGE + COMMA + SPACE + VALUE;
- }
- }
- return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
+ builder.append(methodClose(FOUR_SPACE));
+ return builder.toString();
}
//Get method with arguments.
private static String getGetMethodWithArgument(String returnType,
String yangName) {
- return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX +
- getCapitalCase(yangName) + OPEN_PARENTHESIS + returnType +
- OP_PARAM + SPACE + getSmallCase(returnType) +
- CLOSE_PARENTHESIS + SEMI_COLAN;
+ return methodSignature(getCapitalCase(yangName), GET_METHOD_PREFIX,
+ null, getSmallCase(returnType),
+ returnType, returnType + OP_PARAM,
+ INTERFACE_TYPE);
}
/**
@@ -1753,39 +1482,54 @@
*/
public static String getAddToListMethodInterface(JavaAttributeInfo attr,
String className) {
- return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE +
- ADD_STRING + getCapitalCase(TO) +
- getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS +
- getReturnType(attr) + SPACE +
- VALUE + CLOSE_PARENTHESIS + SEMI_COLAN;
+
+ return methodSignature(ADD_STRING + TO_CAPS + getCapitalCase(
+ attr.getAttributeName()), EMPTY_STRING, EMPTY_STRING,
+ ADD_STRING + TO_CAPS,
+ className + BUILDER, getReturnType(attr),
+ INTERFACE_TYPE);
}
/**
* Returns add to list method impl.
*
- * @param attr java attribute
- * @param generatedJavaClassName class name
- * @param isRoot is root
+ * @param attr java attribute
+ * @param name class name
+ * @param isRoot is root
* @return add to list method impl
*/
public static String getAddToListMethodImpl(JavaAttributeInfo attr,
- String generatedJavaClassName,
+ String name,
boolean isRoot) {
+ String attrName = attr.getAttributeName();
String retString = "";
if (!isRoot) {
retString = getOverRideString();
}
- return retString + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- generatedJavaClassName + BUILDER + SPACE + ADD_STRING +
- getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) +
- OPEN_PARENTHESIS + getReturnType(attr) + SPACE + VALUE +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + attr.getAttributeName() +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING +
- OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN +
- NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS +
- SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET;
+ StringBuilder builder = new StringBuilder(retString);
+ builder.append(methodSignature(ADD_STRING + TO_CAPS +
+ getCapitalCase(attrName),
+ EMPTY_STRING, PUBLIC, ADD_STRING + TO_CAPS,
+ name + BUILDER, getReturnType(attr),
+ CLASS_TYPE))
+ .append(getIfConditionForAddToListMethod(attrName));
+ retString = EIGHT_SPACE_INDENTATION + attrName + PERIOD + ADD_STRING +
+ OPEN_PARENTHESIS + ADD_STRING + TO_CAPS + CLOSE_PARENTHESIS;
+ builder.append(retString)
+ .append(signatureClose())
+ .append(getReturnString(THIS, EIGHT_SPACE_INDENTATION))
+ .append(signatureClose())
+ .append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+
+ // Returns if condition for add to list method.
+ static String getIfConditionForAddToListMethod(String name) {
+ return getIfConditionBegin(EIGHT_SPACE_INDENTATION, name + SPACE + EQUAL +
+ EQUAL + SPACE + NULL) + TWELVE_SPACE_INDENTATION +
+ name + SPACE + EQUAL + SPACE +
+ NEW + SPACE + ARRAY_LIST + signatureClose() + methodClose(
+ EIGHT_SPACE);
}
/**
@@ -1795,15 +1539,14 @@
* @return builder method for class
*/
static String builderMethod(String name) {
- return NEW_LINE + generateForBuilderMethod(name) +
- FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
- name + BUILDER + SPACE + getSmallCase(BUILDER) +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + NEW + SPACE + name +
- BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN +
- NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET;
+ return generateForBuilderMethod(name) +
+ methodSignature(BUILDER_LOWER_CASE,
+ EMPTY_STRING, PUBLIC + SPACE +
+ STATIC, null, name + BUILDER, null, CLASS_TYPE) +
+ getReturnString(NEW + SPACE + name + BUILDER,
+ EIGHT_SPACE_INDENTATION) +
+ brackets(OPEN_CLOSE_BRACKET, null, null) + signatureClose() +
+ methodClose(FOUR_SPACE);
}
/**
@@ -1813,7 +1556,7 @@
* @return is filter content match interface
*/
static String processSubtreeFilteringInterface(String name) {
- String method = " /**\n" +
+ String method = " /**\n" +
" * Checks if the passed " + name +
" maps the content match query condition.\n" +
" *\n" +
@@ -1824,11 +1567,13 @@
" * @param isSelectAllSchemaChild is select all schema child\n" +
" * @return match result\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + name + SPACE +
- PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS +
- name + SPACE + getSmallCase(name) + COMMA + SPACE +
- BOOLEAN_DATA_TYPE + SPACE + "isSelectAllSchemaChild" +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ LinkedHashMap<String, String> map = new LinkedHashMap<>();
+ map.put(name, getSmallCase(name));
+ map.put(BOOLEAN_DATA_TYPE, SELECT_ALL_CHILD);
+
+ return method + multiAttrMethodSignature(PROCESS_SUBTREE_FILTERING,
+ EMPTY_STRING, EMPTY_STRING,
+ name, map, INTERFACE_TYPE);
}
/**
@@ -1836,16 +1581,16 @@
*
* @return is value set interface
*/
- static String isLeafValueSetInterface() {
- String method = " /**\n" +
+ static String isLeafValueSetInterface() {
+ String method = "\n /**\n" +
" * Checks if the leaf value is set.\n" +
" *\n" +
" * @param leaf leaf whose value status needs to checked\n" +
" * @return result of leaf value set in object\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
- VALUE_LEAF_SET + OPEN_PARENTHESIS + LEAF_IDENTIFIER + SPACE +
- "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return method + methodSignature(VALUE_LEAF_SET, EMPTY_STRING, null,
+ LEAF, BOOLEAN_DATA_TYPE,
+ LEAF_IDENTIFIER, INTERFACE_TYPE);
}
/**
@@ -1854,15 +1599,15 @@
* @return is select leaf set interface
*/
static String isSelectLeafSetInterface() {
- String method = " /**\n" +
+ String method = "\n /**\n" +
" * Checks if the leaf is set to be a selected leaf.\n" +
" *\n" +
" * @param leaf if leaf needs to be selected\n" +
" * @return result of leaf value set in object\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
- IS_SELECT_LEAF + OPEN_PARENTHESIS + LEAF_IDENTIFIER + SPACE +
- "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return method + methodSignature(IS_SELECT_LEAF, EMPTY_STRING, null,
+ LEAF, BOOLEAN_DATA_TYPE, LEAF_IDENTIFIER,
+ INTERFACE_TYPE);
}
/**
@@ -1878,9 +1623,10 @@
" * @param leaf leaf needs to be selected\n" +
" * @return builder object for select leaf\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE +
- SET_SELECT_LEAF + OPEN_PARENTHESIS + LEAF_IDENTIFIER + SPACE +
- "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return method + methodSignature(SET_SELECT_LEAF, EMPTY_STRING,
+ null, LEAF, name +
+ BUILDER, LEAF_IDENTIFIER,
+ INTERFACE_TYPE) + NEW_LINE;
}
/**
@@ -1890,7 +1636,7 @@
* @return leaf identifier interface enum signature
*/
static String getInterfaceLeafIdEnumSignature(String name) {
- String start = " /**\n" +
+ String start = "\n /**\n" +
" * Identify the leaf of " + name + PERIOD + NEW_LINE +
" */\n";
return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE +
@@ -1898,69 +1644,6 @@
}
/**
- * Returns interface leaf identifier enum method.
- *
- * @return interface leaf identifier enum method
- */
- static String getInterfaceLeafIdEnumMethods() {
- return " private int leafIndex;\n" +
- "\n" +
- " public int getLeafIndex() {\n" +
- " return leafIndex;\n" +
- " }\n" +
- "\n" +
- " LeafIdentifier(int value) {\n" +
- " this.leafIndex = value;\n" +
- " }\n" +
- " }\n";
- }
-
- /**
- * Returns getter methods for operation attributes.
- *
- * @return getter methods for operation attributes
- */
- static String getOperationAttributesGetters() {
- return "\n" +
- " /**\n" +
- " * Returns the valueLeafFlags.\n" +
- " *\n" +
- " * @return value of valueLeafFlags\n" +
- " */\n" +
- " public BitSet getValueLeafFlags() {\n" +
- " return valueLeafFlags;\n" +
- " }\n" +
- "\n" +
- " /**\n" +
- " * Returns the selectLeafFlags.\n" +
- " *\n" +
- " * @return value of selectLeafFlags\n" +
- " */\n" +
- " public BitSet getSelectLeafFlags() {\n" +
- " return selectLeafFlags;\n" +
- " }\n" +
- "\n";
- }
-
- /**
- * Returns getters for value and select leaf.
- *
- * @return getters for value and select leaf
- */
- static String getGettersForValueAndSelectLeaf() {
- return "\n" +
- " @Override\n" +
- " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
- " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
- " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
- " }\n";
- }
-
- /**
* Returns setter for select leaf.
*
* @param name name of node
@@ -1980,37 +1663,4 @@
" return this;\n" +
" }\n";
}
-
- private static String getListAttribute(String attrType,
- YangCompilerAnnotation compilerAnnotation) {
- String listAttr;
- if (compilerAnnotation != null &&
- compilerAnnotation.getYangAppDataStructure() != null) {
- switch (compilerAnnotation.getYangAppDataStructure()
- .getDataStructure()) {
- case QUEUE: {
- listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType +
- DIAMOND_CLOSE_BRACKET;
- break;
- }
- case SET: {
- listAttr = SET + DIAMOND_OPEN_BRACKET + attrType +
- DIAMOND_CLOSE_BRACKET;
- break;
- }
- case LIST: {
- listAttr = getListString() + attrType +
- DIAMOND_CLOSE_BRACKET;
- break;
- }
- default: {
- listAttr = getListString() + attrType +
- DIAMOND_CLOSE_BRACKET;
- }
- }
- } else {
- listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
- }
- return listAttr;
- }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
new file mode 100644
index 0000000..6d5a14c
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
@@ -0,0 +1,1057 @@
+/*
+ * 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 org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+
+import java.util.Map;
+
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
+import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIfConditionForAddToListMethod;
+import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.AND;
+import static org.onosproject.yangutils.utils.UtilConstants.AT;
+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.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
+import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
+import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+import static org.onosproject.yangutils.utils.UtilConstants.COMPARE_TO;
+import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
+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.DOUBLE;
+import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
+import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
+import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
+import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
+import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
+import static org.onosproject.yangutils.utils.UtilConstants.FOR;
+import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.GET;
+import static org.onosproject.yangutils.utils.UtilConstants.IF;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.IN;
+import static org.onosproject.yangutils.utils.UtilConstants.INT;
+import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.LONG;
+import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.MAP;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
+import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.OF;
+import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
+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.OVERRIDE;
+import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
+import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
+import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
+import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
+import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.PUT;
+import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
+import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
+import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.SET;
+import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
+import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
+import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+import static org.onosproject.yangutils.utils.UtilConstants.THIS;
+import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
+import static org.onosproject.yangutils.utils.UtilConstants.TRY;
+import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
+import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
+import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
+
+/**
+ * Represents string generator for translator.
+ */
+@SuppressWarnings("HardcodedFileSeparator")
+public final class StringGenerator {
+
+ private StringGenerator() {
+ }
+
+ /**
+ * Returns compare to string.
+ *
+ * @return compare to string
+ */
+ static String getCompareToString() {
+ return PERIOD + COMPARE_TO;
+ }
+
+ /**
+ * Returns lesser than and equals condition.
+ *
+ * @return lesser than and equals condition
+ */
+ static String getLesserThanCondition() {
+ return SPACE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE;
+ }
+
+ /**
+ * Returns greater than and equals condition.
+ *
+ * @return greater than and equals condition
+ */
+ static String getGreaterThanCondition() {
+ return SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE;
+ }
+
+ /**
+ * Returns && conditional string.
+ *
+ * @param cond1 condition one
+ * @param cond2 condition two
+ * @return && conditional string
+ */
+ static String ifAndAndCondition(String cond1, String cond2) {
+ return cond1 + SPACE + AND + AND + SPACE + cond2;
+ }
+
+ /**
+ * Returns equal equal conditional string.
+ *
+ * @param cond1 condition one
+ * @param cond2 condition two
+ * @return equal equal conditional string
+ */
+ static String ifEqualEqualCondition(String cond1, String cond2) {
+ return cond1 + SPACE + EQUAL + EQUAL + SPACE + cond2;
+ }
+
+ /**
+ * Returns new instance string.
+ *
+ * @param returnType return type
+ * @param varName variable name
+ * @param space spaces
+ * @param value value
+ * @return new instance string
+ */
+ static String getNewInstance(String returnType, String varName,
+ String space, String value) {
+ return space + returnType + SPACE + varName + SPACE + EQUAL + SPACE +
+ NEW + returnType + brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
+ value, null) + signatureClose();
+ }
+
+ /**
+ * Returns return string.
+ *
+ * @param value value to be returned
+ * @param space spaces
+ * @return return string
+ */
+ static String getReturnString(String value, String space) {
+ return space + RETURN + SPACE + value;
+ }
+
+ /**
+ * Returns new line string with spaces.
+ *
+ * @param space spaces
+ * @return new line string with spaces
+ */
+ static String getNewLineAndSpace(String space) {
+ return NEW_LINE + space;
+ }
+
+ /**
+ * Returns method close string.
+ *
+ * @param type indentation type
+ * @return method close string
+ */
+ static String methodClose(IndentationType type) {
+ switch (type) {
+ case EIGHT_SPACE:
+ return EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ case TWELVE_SPACE:
+ return TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ case SIXTEEN_SPACE:
+ return SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ case TWENTY_SPACE:
+ return TWENTY_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ case TWENTY_EIGHT_SPACE:
+ return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ case TWENTY_FOUR_SPACE:
+ return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ default:
+ return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ }
+ }
+
+ /**
+ * Returns body of the method.
+ *
+ * @param type type of method body
+ * @param paraName parameter name
+ * @param methodName method name
+ * @param space space to be given before body
+ * @param prefix prefix for internal method
+ * @param paramType parameter type
+ * @param isBuilderSetter is for builder setter
+ * @return body of the method
+ */
+ static String methodBody(MethodBodyTypes type, String paraName,
+ String methodName,
+ String space, String prefix,
+ String paramType, boolean isBuilderSetter) {
+ StringBuilder builder = new StringBuilder();
+ String body;
+ switch (type) {
+ case GETTER:
+ return getReturnString(paraName, space);
+ case SETTER:
+ body = space + THIS + PERIOD + paraName + SPACE + EQUAL + SPACE +
+ paraName + signatureClose();
+ builder.append(body);
+ if (isBuilderSetter) {
+ body = getReturnString(THIS + signatureClose(), space);
+ builder.append(body);
+ }
+ return builder.toString();
+ case BUILD:
+ return getReturnString(
+ NEW + SPACE + paraName + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, THIS, null) +
+ signatureClose(), space);
+ case CONSTRUCTOR:
+ return space + THIS + PERIOD + paraName + SPACE +
+ EQUAL + SPACE + BUILDER_LOWER_CASE + OBJECT + PERIOD +
+ prefix + methodName +
+ brackets(OPEN_CLOSE_BRACKET, null, null) +
+ signatureClose();
+ case DEFAULT_CONSTRUCTOR:
+ return EMPTY_STRING;
+ case ADD_TO_LIST:
+ return space + getIfConditionForAddToListMethod(paraName) +
+ space + paraName +
+ brackets(OPEN_CLOSE_BRACKET, null, null) + PERIOD +
+ ADD_STRING +
+ brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null) +
+ signatureClose() + getReturnString(
+ THIS + signatureClose(), space);
+ case AUGMENTED_MAP_ADD:
+ return space + YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
+ PERIOD + PUT + OPEN_PARENTHESIS + CLASS +
+ OBJECT_STRING + COMMA + SPACE + VALUE +
+ CLOSE_PARENTHESIS + signatureClose();
+ case AUGMENTED_MAP_GET_VALUE:
+ return getReturnString(
+ YANG_AUGMENTED_INFO_LOWER_CASE + MAP + PERIOD + GET +
+ brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, CLASS +
+ OBJECT_STRING, null) + signatureClose(),
+ space);
+ case AUGMENTED_MAP_GETTER:
+ return getReturnString(YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
+ signatureClose(), space);
+ case MANAGER_METHODS:
+ body = space + YANG_UTILS_TODO + NEW_LINE;
+ builder.append(body);
+ if (paramType != null) {
+ body = getReturnString(parseTypeForReturnValue(paramType),
+ space);
+ builder.append(body)
+ .append(signatureClose());
+ }
+ return builder.toString();
+ case OF_METHOD:
+ return getReturnString(
+ NEW + SPACE + paraName + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null)
+ + signatureClose(), space);
+ case TO_STRING:
+ return space + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES +
+ paraName + QUOTES + COMMA + SPACE + paraName +
+ CLOSE_PARENTHESIS;
+ case EQUALS_METHOD:
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Returns end of line.
+ *
+ * @return end of line
+ */
+ static String signatureClose() {
+ return SEMI_COLON + NEW_LINE;
+ }
+
+ /**
+ * Returns method signature close for method class type.
+ *
+ * @param type method class type
+ * @return method signature close for method class type
+ */
+ static String methodSignatureClose(MethodClassTypes type) {
+ switch (type) {
+ case INTERFACE_TYPE:
+ return signatureClose();
+ case CLASS_TYPE:
+ return SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Returns method param.
+ *
+ * @param type type of param
+ * @param name name of param
+ * @return method param
+ */
+ private static String methodParam(String type, String name) {
+ return type + SPACE + name;
+ }
+
+ /**
+ * Returns comma followed by a space.
+ *
+ * @return comma followed by a space
+ */
+ private static String commaWithSpace() {
+ return COMMA + SPACE;
+ }
+
+ /**
+ * Returns bracket string for the given type.
+ *
+ * @param type bracket type
+ * @param value value to be added in brackets
+ * @param returnType returns type to be added for value
+ * @return bracket for the given type.
+ */
+ static String brackets(BracketType type, String value,
+ String returnType) {
+ String ret = EMPTY_STRING;
+ switch (type) {
+ case OPEN_CLOSE_BRACKET:
+ return OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
+ case OPEN_CLOSE_BRACKET_WITH_VALUE:
+ return OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS;
+ case OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE:
+ if (returnType != null) {
+ ret = returnType + SPACE;
+ }
+ return OPEN_PARENTHESIS + ret + value +
+ CLOSE_PARENTHESIS;
+ case OPEN_BRACKET_WITH_VALUE:
+ ret = EMPTY_STRING;
+ if (returnType != null) {
+ ret = returnType + SPACE;
+ }
+ return OPEN_PARENTHESIS + ret + value +
+ COMMA;
+ case CLOSE_BRACKET_WITH_VALUE:
+ ret = EMPTY_STRING;
+ if (returnType != null) {
+ ret = returnType + SPACE;
+ }
+ return SPACE + ret + value +
+ CLOSE_PARENTHESIS;
+ case OPEN_CLOSE_DIAMOND:
+ return DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET;
+ case OPEN_CLOSE_DIAMOND_WITH_VALUE:
+ return DIAMOND_OPEN_BRACKET + value + DIAMOND_CLOSE_BRACKET;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Returns method signature for multi attribute methods.
+ *
+ * @param methodName method name
+ * @param prefix prefix for method
+ * @param modifier modifier for method
+ * @param methodReturnType method's return type
+ * @param params parameters
+ * @param type type of method
+ * @return method signature for multi attribute methods
+ */
+ static String multiAttrMethodSignature(String methodName, String
+ prefix, String modifier, String methodReturnType,
+ Map<String, String> params,
+ MethodClassTypes type) {
+ StringBuilder methodBuilder = new StringBuilder(FOUR_SPACE_INDENTATION);
+ String method = EMPTY_STRING;
+ if (modifier != null) {
+ method = modifier + SPACE;
+ }
+ methodBuilder.append(method);
+ if (methodReturnType != null) {
+ method = methodReturnType + SPACE + prefix + methodName;
+ } else {
+ method = prefix + methodName;
+ }
+ //Append method beginning.
+ methodBuilder.append(method)
+ .append(OPEN_PARENTHESIS);
+ for (Map.Entry<String, String> param : params.entrySet()) {
+ methodBuilder.append(methodParam(param.getKey(), param.getValue()));
+ methodBuilder.append(commaWithSpace());
+ }
+ String para = methodBuilder.toString();
+ String[] array = {SPACE, COMMA};
+ para = trimAtLast(para, array);
+ methodBuilder = new StringBuilder(para)
+ .append(CLOSE_PARENTHESIS)
+ .append(methodSignatureClose(type));
+
+ return methodBuilder.toString();
+ }
+
+ /**
+ * Returns method signature for interface and implementation classes.
+ *
+ * @param methodName name of the method
+ * @param prefix prefix which needs to be added for method
+ * @param modifier modifier which needs to be added for method
+ * @param paraVal value which needs to be added as parameter
+ * @param methodReturnType returns type to be added for method
+ * @param paraReturnType return type to be added for parameter
+ * @param type method class type
+ * @return method signature for interface and implementation classes
+ */
+ static String methodSignature(
+ String methodName, String prefix, String modifier, String paraVal,
+ String methodReturnType, String paraReturnType,
+ MethodClassTypes type) {
+ StringBuilder methodBuilder = new StringBuilder(FOUR_SPACE_INDENTATION);
+ String method = EMPTY_STRING;
+ if (modifier != null) {
+ method = modifier + SPACE;
+ }
+ methodBuilder.append(method);
+ if (methodReturnType != null) {
+ method = methodReturnType + SPACE + prefix + methodName;
+ } else {
+ method = prefix + methodName;
+ }
+ //Append method beginning.
+ methodBuilder.append(method);
+
+ if (paraVal != null) {
+ methodBuilder.append(brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE,
+ paraVal, paraReturnType));
+ } else {
+ methodBuilder.append(brackets(OPEN_CLOSE_BRACKET, null,
+ null));
+ }
+
+ methodBuilder.append(methodSignatureClose(type));
+
+ return methodBuilder.toString();
+ }
+
+ /**
+ * Returns list attribute.
+ *
+ * @param attrType attribute type
+ * @param compilerAnnotation compiler annotations
+ * @return list attribute
+ */
+
+ static String getListAttribute(String attrType,
+ YangCompilerAnnotation compilerAnnotation) {
+ String listAttr;
+ if (compilerAnnotation != null &&
+ compilerAnnotation.getYangAppDataStructure() != null) {
+ switch (compilerAnnotation.getYangAppDataStructure()
+ .getDataStructure()) {
+ case QUEUE: {
+ listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType +
+ DIAMOND_CLOSE_BRACKET;
+ break;
+ }
+ case SET: {
+ listAttr = SET + DIAMOND_OPEN_BRACKET + attrType +
+ DIAMOND_CLOSE_BRACKET;
+ break;
+ }
+ case LIST: {
+ listAttr = getListString() + attrType +
+ DIAMOND_CLOSE_BRACKET;
+ break;
+ }
+ default: {
+ listAttr = getListString() + attrType +
+ DIAMOND_CLOSE_BRACKET;
+ }
+ }
+ } else {
+ listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+ }
+ return listAttr;
+ }
+
+ /**
+ * Returns getters for value and select leaf.
+ *
+ * @return getters for value and select leaf
+ */
+ static String getGettersForValueAndSelectLeaf() {
+ return "\n" +
+ " @Override\n" +
+ " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
+ " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
+ " }\n" +
+ "\n" +
+ " @Override\n" +
+ " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
+ " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
+ " }\n";
+ }
+
+ /**
+ * Returns getter methods for operation attributes.
+ *
+ * @return getter methods for operation attributes
+ */
+ static String getOperationAttributesGetters() {
+ return "\n" +
+ " /**\n" +
+ " * Returns the valueLeafFlags.\n" +
+ " *\n" +
+ " * @return value of valueLeafFlags\n" +
+ " */\n" +
+ " public BitSet getValueLeafFlags() {\n" +
+ " return valueLeafFlags;\n" +
+ " }\n" +
+ "\n" +
+ " /**\n" +
+ " * Returns the selectLeafFlags.\n" +
+ " *\n" +
+ " * @return value of selectLeafFlags\n" +
+ " */\n" +
+ " public BitSet getSelectLeafFlags() {\n" +
+ " return selectLeafFlags;\n" +
+ " }\n" +
+ "\n";
+ }
+
+ /**
+ * Returns interface leaf identifier enum method.
+ *
+ * @return interface leaf identifier enum method
+ */
+ static String getInterfaceLeafIdEnumMethods() {
+ return "\n\n private int leafIndex;\n" +
+ "\n" +
+ " public int getLeafIndex() {\n" +
+ " return leafIndex;\n" +
+ " }\n" +
+ "\n" +
+ " LeafIdentifier(int value) {\n" +
+ " this.leafIndex = value;\n" +
+ " }\n" +
+ " }\n";
+ }
+
+ /**
+ * Returns if condition string for typedef constructor.
+ *
+ * @param type type of conflict
+ * @param addFirst true int/long need to be added first
+ * @return if condition string for typedef constructor
+ */
+ static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type,
+ boolean addFirst) {
+ String condition =
+ EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
+ VALIDATE_RANGE + OPEN_PARENTHESIS;
+
+ switch (type) {
+ case INT_TYPE_CONFLICT:
+ if (addFirst) {
+ condition = condition + INT_MIN_RANGE + COMMA + SPACE +
+ INT_MAX_RANGE + COMMA + SPACE + VALUE;
+ } else {
+ condition = condition + UINT_MIN_RANGE + COMMA + SPACE +
+ UINT_MAX_RANGE + COMMA + SPACE + VALUE;
+ }
+ break;
+ case LONG_TYPE_CONFLICT:
+ if (addFirst) {
+ condition = condition + LONG_MIN_RANGE + COMMA + SPACE +
+ LONG_MAX_RANGE + COMMA + SPACE + VALUE;
+ } else {
+ condition = condition + ULONG_MIN_RANGE + COMMA + SPACE +
+ ULONG_MAX_RANGE + COMMA + SPACE + VALUE;
+ }
+ break;
+ case SHORT_TYPE_CONFLICT:
+ if (addFirst) {
+ condition = condition + SHORT_MIN_RANGE + COMMA + SPACE +
+ SHORT_MAX_RANGE + COMMA + SPACE + VALUE;
+ } else {
+ condition = condition + UINT8_MIN_RANGE + COMMA + SPACE +
+ UINT8_MAX_RANGE + COMMA + SPACE + VALUE;
+ }
+ break;
+ default:
+ return null;
+ }
+
+ return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns from string method parsed string.
+ *
+ * @param targetDataType target data type
+ * @param yangType YANG type
+ * @return parsed string
+ */
+ static String getParseFromStringMethod(String targetDataType,
+ YangType<?> yangType) {
+ YangDataTypes type = yangType.getDataType();
+
+ switch (type) {
+ case INT8:
+ return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
+ case INT16:
+ return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
+ case INT32:
+ return INTEGER_WRAPPER + PERIOD + PARSE_INT;
+ case INT64:
+ return LONG_WRAPPER + PERIOD + PARSE_LONG;
+ case UINT8:
+ return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
+ case UINT16:
+ return INTEGER_WRAPPER + PERIOD + PARSE_INT;
+ case UINT32:
+ return LONG_WRAPPER + PERIOD + PARSE_LONG;
+ case UINT64:
+ return NEW + SPACE + BIG_INTEGER;
+ case DECIMAL64:
+ return NEW + SPACE + BIG_DECIMAL;
+ case STRING:
+ case IDENTITYREF:
+ return EMPTY_STRING;
+ case EMPTY:
+ case BOOLEAN:
+ return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
+ case BITS:
+ case UNION:
+ case ENUMERATION:
+ case DERIVED:
+ return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
+ default:
+ throw new TranslatorException("given data type is not " +
+ "supported. " +
+ yangType.getDataTypeName() +
+ " in " +
+ yangType.getLineNumber() +
+ " at " +
+ yangType.getCharPosition() +
+ " in " +
+ yangType.getFileName());
+ }
+ }
+
+ /**
+ * Returns sub string with catch statement for union's from string method.
+ *
+ * @return sub string with catch statement for union's from string method
+ */
+ static String getCatchSubString() {
+ return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE +
+ brackets(OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE, EXCEPTION_VAR,
+ EXCEPTION) + SPACE + OPEN_CURLY_BRACKET;
+ }
+
+ /**
+ * Returns sub string with return statement for union's from string method.
+ *
+ * @return sub string with return statement for union's from string method
+ */
+ static String getReturnOfSubString() {
+ return getReturnString(OF, EIGHT_SPACE_INDENTATION) +
+ brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, TMP_VAL, null) +
+ signatureClose();
+ }
+
+ /**
+ * Returns sub string with try statement for union's from string method.
+ *
+ * @return sub string with try statement for union's from string method
+ */
+ static String getTrySubString() {
+ return TRY + SPACE + OPEN_CURLY_BRACKET;
+ }
+
+ /*
+ * Returns omit null value string.
+ *
+ * @return omit null value string
+ */
+ static String getOmitNullValueString() {
+ return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING +
+ NEW_LINE;
+ }
+
+ /**
+ * Returns collection's iterator method.
+ *
+ * @param indentation indentation
+ * @param loopVar loop variable
+ * @param collection collection
+ * @return collection's iterator method
+ */
+ static String getCollectionIteratorForLoopBegin(String indentation,
+ String loopVar,
+ String collection) {
+ return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE +
+ COLON + SPACE + collection + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /**
+ * Returns if else condition's signature.
+ *
+ * @param indentation indentation
+ * @param condition conditions
+ * @return if else condition's signature
+ */
+ static String getElseIfConditionBegin(String indentation,
+ String condition) {
+ return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE +
+ getIfConditionBegin(EMPTY_STRING, condition);
+ }
+
+ /**
+ * Returns if condition's signature.
+ *
+ * @param indentation indentation
+ * @param condition conditions
+ * @return if condition's signature
+ */
+ static String getIfConditionBegin(String indentation, String condition) {
+ return indentation + IF + SPACE + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, condition, EMPTY_STRING) +
+ methodSignatureClose(CLASS_TYPE);
+ }
+
+ /**
+ * Returns whether the data type is of primitive data type.
+ *
+ * @param dataType data type to be checked
+ * @return true, if data type can have primitive data type, false otherwise
+ */
+ static boolean isPrimitiveDataType(YangDataTypes dataType) {
+ return dataType == INT8 ||
+ dataType == INT16 ||
+ dataType == INT32 ||
+ dataType == INT64 ||
+ dataType == UINT8 ||
+ dataType == UINT16 ||
+ dataType == UINT32 ||
+ dataType == UINT64 ||
+ dataType == DECIMAL64 ||
+ dataType == BOOLEAN ||
+ dataType == EMPTY;
+ }
+
+ /**
+ * Returns list string.
+ *
+ * @return list string
+ */
+ private static String getListString() {
+ return LIST + DIAMOND_OPEN_BRACKET;
+ }
+
+ /**
+ * Returns override string.
+ *
+ * @return override string
+ */
+ public static String getOverRideString() {
+ return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
+ }
+
+ /**
+ * Returns value leaf flag setter.
+ *
+ * @param name name of leaf
+ * @return value leaf flag setter
+ */
+ static String getValueLeafSetString(String name) {
+ return "\n valueLeafFlags.set(LeafIdentifier." +
+ name.toUpperCase() + ".getLeafIndex());\n";
+ }
+
+ /*Provides string to return for type.*/
+ private static String parseTypeForReturnValue(String type) {
+ switch (type) {
+ case BYTE:
+ case INT:
+ case SHORT:
+ case LONG:
+ case DOUBLE:
+ return ZERO;
+ case BOOLEAN_DATA_TYPE:
+ return FALSE;
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Returns check not null string.
+ *
+ * @param name attribute name
+ * @return check not null string
+ */
+ static String getCheckNotNull(String name) {
+ return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING +
+ OPEN_PARENTHESIS + name + COMMA + SPACE + name +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
+ }
+
+ /**
+ * Returns definition close string.
+ *
+ * @return definition close string
+ */
+ private static String defCloseString() {
+ return SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE;
+ }
+
+ /**
+ * Returns default class definition for java file when extends a
+ * interface.
+ *
+ * @param classType class type
+ * @param name name of class
+ * @param modifier modifier for class
+ * @param extend extends class name
+ * @return class definition
+ */
+ static String getDefaultDefinitionWithExtends(String classType,
+ String name, String
+ modifier,
+ String extend) {
+ String mod = EMPTY_STRING;
+ if (modifier != null) {
+ mod = modifier + SPACE;
+ }
+ return mod + classType + SPACE + name + SPACE + EXTEND + SPACE
+ + extend + defCloseString();
+ }
+
+ /**
+ * Returns default class definition for java file when implements a
+ * interface.
+ *
+ * @param classType class type
+ * @param name name of class
+ * @param modifier modifier for class
+ * @param impl implements class name
+ * @return class definition
+ */
+ static String getDefaultDefinitionWithImpl(String classType,
+ String name, String
+ modifier,
+ String impl) {
+ String mod = EMPTY_STRING;
+ if (modifier != null) {
+ mod = modifier + SPACE;
+ }
+ return mod + classType + SPACE + name + SPACE + IMPLEMENTS +
+ SPACE + impl + defCloseString();
+ }
+
+ /**
+ * Returns default class definition for java file.
+ *
+ * @param classType class type
+ * @param name name of class
+ * @param modifier modifier for class
+ * @return class definition
+ */
+ static String getDefaultDefinition(String classType,
+ String name, String modifier) {
+ String mod = EMPTY_STRING;
+ if (modifier != null) {
+ mod = modifier + SPACE;
+ }
+ return mod + classType + SPACE + name + defCloseString();
+ }
+
+ /**
+ * Returns string for service class.
+ *
+ * @param name1 name of even listener class
+ * @param name2 name of even class
+ * @return listener service string for service class
+ */
+ static String getEventExtendsString(String name1, String type,
+ String name2) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(type).append(DIAMOND_OPEN_BRACKET).append(name1)
+ .append(COMMA).append(SPACE).append(name2).append
+ (DIAMOND_CLOSE_BRACKET);
+ return builder.toString();
+ }
+
+ /**
+ * Returns import string.
+ *
+ * @param pkg package
+ * @param cls class
+ * @return import string
+ */
+ public static String getImportString(String pkg, String cls) {
+ StringBuilder builder = new StringBuilder()
+ .append(IMPORT).append(pkg).append(PERIOD).append(cls)
+ .append(signatureClose());
+ return builder.toString();
+ }
+
+ /**
+ * Returns static modifier string.
+ *
+ * @param modifier modifier
+ * @return static modifier string
+ */
+ static String getSpecificModifier(String modifier, String keyWord) {
+ return new StringBuilder(modifier).append(SPACE).append(keyWord)
+ .toString();
+ }
+
+ /**
+ * Returns builder string for class definition.
+ *
+ * @param yangName class name
+ * @return builder string for class definition
+ */
+ static String getBuilderImplStringClassDef(String yangName) {
+ return new StringBuilder(yangName).append(PERIOD).append(yangName)
+ .append(BUILDER).toString();
+ }
+
+ /**
+ * Returns default name string.
+ *
+ * @param yangName class name
+ * @return default name string
+ */
+ static String getDefaultName(String yangName) {
+ return new StringBuilder(DEFAULT_CAPS).append(yangName).toString();
+ }
+
+ /**
+ * Returns suffixed name string.
+ *
+ * @param yangName class name
+ * @param suffix suffix to append to name
+ * @return suffixed name string
+ */
+ static String getSuffixedName(String yangName, String suffix) {
+ return new StringBuilder(yangName).append(suffix).toString();
+ }
+
+ /**
+ * Returns error msg string.
+ *
+ * @param msg message
+ * @param name name of node
+ * @param line line number
+ * @param position char position
+ * @param fileName file name
+ * @return error message string
+ */
+ static String getErrorMsg(String msg, String name, int line, int position,
+ String fileName) {
+ return new StringBuilder().append(msg).append(name).append(IN)
+ .append(line).append(AT).append(position).append(IN)
+ .append(fileName).toString();
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
index 3bda74c..e7e83f4 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
@@ -16,8 +16,6 @@
package org.onosproject.yangutils.translator.tojava.utils;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
@@ -28,20 +26,22 @@
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava
- .TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype
- .YangDataTypes.LEAFREF;
-import static org.onosproject.yangutils.translator.tojava
- .GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
-import static org.onosproject.yangutils.translator.tojava
- .GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
-import static org.onosproject.yangutils.translator.tojava
- .GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils
- .JavaFileGeneratorUtils.getDataFromTempFileHandle;
+import java.io.IOException;
+
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
+import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.EIGHT_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.SIXTEEN_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWELVE_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_FOUR_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND_OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
@@ -52,48 +52,38 @@
import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
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;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.CONTINUE;
-import static org.onosproject.yangutils.utils.UtilConstants
- .EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
-import static org.onosproject.yangutils.utils.UtilConstants
- .EMPTY_PARAMETER_FUNCTION_CALL;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_PARAMETER_FUNCTION_CALL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.FOR;
-import static org.onosproject.yangutils.utils.UtilConstants
- .FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GET_LEAF_INDEX;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants
- .GET_SELECT_LEAF_FLAGS;
-import static org.onosproject.yangutils.utils.UtilConstants
- .GET_VALUE_LEAF_FLAGS;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_FLAGS;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_VALUE_LEAF_FLAGS;
import static org.onosproject.yangutils.utils.UtilConstants.IF;
-import static org.onosproject.yangutils.utils.UtilConstants
- .ILLEGAL_ACCESS_EXCEPTION;
+import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ACCESS_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE;
-import static org.onosproject.yangutils.utils.UtilConstants
- .INVOCATION_TARGET_EXCEPTION;
+import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.INVOKE;
-import static org.onosproject.yangutils.utils.UtilConstants
- .IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG;
+import static org.onosproject.yangutils.utils.UtilConstants.IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG;
import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
-import static org.onosproject.yangutils.utils.UtilConstants
- .IS_SELECT_ALL_SCHEMA_CHILD_FLAG;
+import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_ALL_SCHEMA_CHILD_FLAG;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
-import static org.onosproject.yangutils.utils.UtilConstants
- .NO_SUCH_METHOD_EXCEPTION;
+import static org.onosproject.yangutils.utils.UtilConstants.NO_SUCH_METHOD_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
@@ -102,44 +92,36 @@
import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yangutils.utils.UtilConstants
- .PROCESS_SUBTREE_FILTERING;
+import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
-import static org.onosproject.yangutils.utils.UtilConstants
- .SIXTEEN_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants
- .SUBTREE_FILTERING_RESULT_BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants
- .THIRTY_TWO_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.SUBTREE_FILTERING_RESULT_BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.THIRTY_TWO_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.TRY;
-import static org.onosproject.yangutils.utils.UtilConstants
- .TWELVE_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants
- .TWENTY_EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants
- .TWENTY_FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants
- .TWENTY_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants
- .YANG_AUGMENTED_OP_PARAM_INFO;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO;
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.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
/**
* Represents generator for subtree filtering methods of generated files
* based on the file type.
*/
+//TODO: improve class to use string generator.
public final class SubtreeFilteringMethodsGenerator {
/**
@@ -170,14 +152,14 @@
TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
attrQualifiedType + CLOSE_PARENTHESIS + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION +
- RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE +
+ RETURN + SPACE + FALSE + SEMI_COLON + NEW_LINE +
TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE +
ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
SIXTEEN_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + attributeName +
OPEN_PARENTHESIS + APP_INSTANCE + PERIOD + attributeName +
OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + ELSE +
SPACE + IF + SPACE + OPEN_PARENTHESIS +
@@ -189,11 +171,11 @@
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
TWELVE_SPACE_INDENTATION +
IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL +
- SPACE + TRUE + SEMI_COLAN + NEW_LINE +
+ SPACE + TRUE + SEMI_COLON + NEW_LINE +
TWELVE_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
PERIOD + attributeName + OPEN_PARENTHESIS + APP_INSTANCE +
PERIOD + attributeName + EMPTY_PARAMETER_FUNCTION_CALL +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
@@ -229,14 +211,14 @@
YangType dataType) {
String attrQualifiedType;
- if (MethodsGenerator.isPrimitiveDataType(dataType.getDataType())) {
+ if (StringGenerator.isPrimitiveDataType(dataType.getDataType())) {
attrQualifiedType =
getAttrTypeForFilterContentMatchWhenPrimitiveDataType(
attributeName);
} else if (dataType.getDataType() == LEAFREF) {
YangType type = ((YangLeafRef) dataType.getDataTypeExtendedInfo())
.getEffectiveDataType();
- if (MethodsGenerator.isPrimitiveDataType(type.getDataType())) {
+ if (StringGenerator.isPrimitiveDataType(type.getDataType())) {
attrQualifiedType =
getAttrTypeForFilterContentMatchWhenPrimitiveDataType(
attributeName);
@@ -322,7 +304,7 @@
caseName + SPACE + APP_INSTANCE + SPACE +
EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
}
processSubtreeFilteringMethod +=
@@ -332,7 +314,7 @@
.getBeanTempFiles(), path);
processSubtreeFilteringMethod +=
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLAN +
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
@@ -396,7 +378,7 @@
caseName + SPACE + APP_INSTANCE + SPACE +
EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
}
processSubtreeFilteringMethod += getDataFromTempFileHandle(
@@ -406,7 +388,7 @@
.getBeanTempFiles(), path);
processSubtreeFilteringMethod +=
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLAN +
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
@@ -469,7 +451,7 @@
caseName + SPACE + APP_INSTANCE + SPACE +
EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
}
processSubtreeFilteringMethod +=
@@ -479,7 +461,7 @@
.getBeanTempFiles(), path);
processSubtreeFilteringMethod +=
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLAN +
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
@@ -522,7 +504,7 @@
}
}
String processSubtreeFilteringMethod =
- MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION +
+ StringGenerator.getOverRideString() + FOUR_SPACE_INDENTATION +
PUBLIC + SPACE + name + SPACE +
PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + name +
SPACE + instance + COMMA + SPACE + BOOLEAN_DATA_TYPE +
@@ -532,10 +514,10 @@
builderNamePrefix + BUILDER + SPACE +
SUBTREE_FILTERING_RESULT_BUILDER + SPACE + EQUAL +
SPACE + NEW + SPACE + builderNamePrefix + BUILDER +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLON +
NEW_LINE + EIGHT_SPACE_INDENTATION + "Boolean" + SPACE +
IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE +
- EQUAL + SPACE + FALSE + SEMI_COLAN + NEW_LINE;
+ EQUAL + SPACE + FALSE + SEMI_COLON + NEW_LINE;
if (curNode instanceof YangCase) {
String caseName = getCapitalCase(javaFileInfo.getJavaName());
@@ -544,7 +526,7 @@
caseName + SPACE + APP_INSTANCE + SPACE +
EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
}
return processSubtreeFilteringMethod;
@@ -564,7 +546,7 @@
if (((YangLeavesHolder) curNode).getListOfLeaf() != null
&&
!((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
"processLeafSubtreeFiltering(appInstance, " +
"subTreeFilteringResultBuilder," + NEW_LINE +
@@ -573,9 +555,9 @@
"isSelectAllSchemaChild)");
method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
- method += MethodsGenerator.getBlockEnd(EIGHT_SPACE_INDENTATION);
+ method += methodClose(EIGHT_SPACE);
}
}
@@ -584,7 +566,7 @@
&&
!((YangLeavesHolder) curNode).getListOfLeafList()
.isEmpty()) {
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
"processLeafListSubTreeFiltering(appInstance," +
" subTreeFilteringResultBuilder," + NEW_LINE
@@ -593,15 +575,15 @@
"isSelectAllSchemaChild)");
method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
- method += MethodsGenerator.getBlockEnd(EIGHT_SPACE_INDENTATION);
+ method += methodClose(EIGHT_SPACE);
}
}
if (curNode.getChild() != null) {
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
"processChildNodesSubTreeFiltering(appInstance, " +
"subTreeFilteringResultBuilder," + NEW_LINE +
@@ -610,9 +592,9 @@
"isSelectAllSchemaChild)");
method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
- method += MethodsGenerator.getBlockEnd(EIGHT_SPACE_INDENTATION);
+ method += methodClose(EIGHT_SPACE);
}
return method;
@@ -639,7 +621,7 @@
* @return is filter content match close
*/
static String getProcessSubTreeFilteringEnd() {
- String method = MethodsGenerator
+ String method = StringGenerator
.getIfConditionBegin(EIGHT_SPACE_INDENTATION,
NOT + IS_SELECT_ALL_SCHEMA_CHILD_FLAG +
SPACE + AND_OPERATION + SPACE +
@@ -648,14 +630,14 @@
method += TWELVE_SPACE_INDENTATION + RETURN + SPACE +
PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + APP_INSTANCE +
- COMMA + SPACE + TRUE + CLOSE_PARENTHESIS + SEMI_COLAN +
+ COMMA + SPACE + TRUE + CLOSE_PARENTHESIS + SEMI_COLON +
NEW_LINE;
- method += MethodsGenerator.getBlockEnd(EIGHT_SPACE_INDENTATION);
+ method += methodClose(EIGHT_SPACE);
method += EIGHT_SPACE_INDENTATION + RETURN + SPACE +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + BUILD +
- EMPTY_PARAMETER_FUNCTION_CALL + SEMI_COLAN + NEW_LINE +
+ EMPTY_PARAMETER_FUNCTION_CALL + SEMI_COLON + NEW_LINE +
FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
return method;
@@ -677,13 +659,13 @@
type;
}
- String method = MethodsGenerator
+ String method = StringGenerator
.getIfConditionBegin(EIGHT_SPACE_INDENTATION, name + "() != " +
"null");
method += TWELVE_SPACE_INDENTATION +
IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL + SPACE +
- TRUE + SEMI_COLAN + NEW_LINE;
+ TRUE + SEMI_COLON + NEW_LINE;
method += TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
APP_INSTANCE + PERIOD + name + OPEN_PARENTHESIS +
@@ -694,7 +676,7 @@
method += SIXTEEN_SPACE_INDENTATION + type + SPACE + "result = " +
name + PERIOD + PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS +
APP_INSTANCE + PERIOD + name + EMPTY_PARAMETER_FUNCTION_CALL
- + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLAN +
+ + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
NEW_LINE;
method += SIXTEEN_SPACE_INDENTATION + "if (result != null) {" +
@@ -702,14 +684,14 @@
method += TWENTY_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
PERIOD + name + OPEN_PARENTHESIS + "result" +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
//if app instance is not null
- method += MethodsGenerator.getBlockEnd(TWELVE_SPACE_INDENTATION);
+ method += methodClose(TWELVE_SPACE);
//if query instance is not null
- method += MethodsGenerator.getBlockEnd(EIGHT_SPACE_INDENTATION);
+ method += methodClose(TWELVE_SPACE);
return method;
}
@@ -735,11 +717,11 @@
/*
* If select all schema child
*/
- String method = MethodsGenerator
+ String method = StringGenerator
.getIfConditionBegin(EIGHT_SPACE_INDENTATION,
IS_SELECT_ALL_SCHEMA_CHILD_FLAG);
- method = method + MethodsGenerator
+ method = method + StringGenerator
.getCollectionIteratorForLoopBegin(TWELVE_SPACE_INDENTATION,
type + SPACE + name,
APP_INSTANCE + PERIOD +
@@ -749,13 +731,12 @@
method = method + SIXTEEN_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
- name + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ name + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
- method += MethodsGenerator.getBlockEnd(
- TWELVE_SPACE_INDENTATION); // Close collection Iteration loop
+ method += methodClose(TWELVE_SPACE); // Close collection Iteration loop
//If need to explicitly participate in query
- method += MethodsGenerator
+ method += StringGenerator
.getElseIfConditionBegin(EIGHT_SPACE_INDENTATION,
name + EMPTY_PARAMETER_FUNCTION_CALL +
SPACE + NOT + EQUAL +
@@ -764,11 +745,11 @@
if (!isLeafList) {
method += TWELVE_SPACE_INDENTATION +
IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL +
- SPACE + TRUE + SEMI_COLAN + NEW_LINE;
+ SPACE + TRUE + SEMI_COLON + NEW_LINE;
}
//If there is any parameter in the query condition
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(TWELVE_SPACE_INDENTATION, NOT + name +
EMPTY_PARAMETER_FUNCTION_CALL + PERIOD + IS_EMPTY);
@@ -776,7 +757,7 @@
/*
* If there is no app instance to perform content match
*/
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
APP_INSTANCE + PERIOD + name +
EMPTY_PARAMETER_FUNCTION_CALL +
@@ -788,21 +769,21 @@
PERIOD + IS_EMPTY);
method += TWENTY_SPACE_INDENTATION + RETURN + SPACE + FALSE +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
- method += MethodsGenerator.getBlockEnd(SIXTEEN_SPACE_INDENTATION);
+ method += methodClose(SIXTEEN_SPACE);
// for instance iterator
- method += MethodsGenerator.getCollectionIteratorForLoopBegin(
+ method += StringGenerator.getCollectionIteratorForLoopBegin(
SIXTEEN_SPACE_INDENTATION, type + SPACE + name,
name + EMPTY_PARAMETER_FUNCTION_CALL);
method += TWENTY_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
- "flag" + SPACE + EQUAL + SPACE + FALSE + SEMI_COLAN +
+ "flag" + SPACE + EQUAL + SPACE + FALSE + SEMI_COLON +
NEW_LINE;
// for app instance iterator
- method += MethodsGenerator
+ method += StringGenerator
.getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
type + SPACE + name +
"2",
@@ -811,47 +792,43 @@
EMPTY_PARAMETER_FUNCTION_CALL);
//the content match leaf list attribute value matches
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(TWENTY_FOUR_SPACE_INDENTATION,
name + PERIOD + EQUALS_STRING
+ OPEN_PARENTHESIS + name +
"2" + CLOSE_PARENTHESIS);
method += TWENTY_EIGHT_SPACE_INDENTATION + "flag" + SPACE + EQUAL +
- SPACE + TRUE + SEMI_COLAN + NEW_LINE;
+ SPACE + TRUE + SEMI_COLON + NEW_LINE;
method += TWENTY_EIGHT_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
name + "2" + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
- BREAK + SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
+ BREAK + SEMI_COLON + NEW_LINE;
//the content match leaf list attribute value matches
- method +=
- MethodsGenerator.getBlockEnd(TWENTY_FOUR_SPACE_INDENTATION);
+ method += methodClose(TWENTY_FOUR_SPACE);
// for app instance iterator
- method += MethodsGenerator.getBlockEnd(TWENTY_SPACE_INDENTATION);
+ method += methodClose(TWENTY_SPACE);
//if the content match failed
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(TWENTY_SPACE_INDENTATION, "!flag");
method += TWENTY_FOUR_SPACE_INDENTATION + RETURN + SPACE + FALSE +
- SEMI_COLAN + NEW_LINE;
+ SEMI_COLON + NEW_LINE;
- method += MethodsGenerator
- .getBlockEnd(TWENTY_SPACE_INDENTATION); // if flag == false
+ method +=
+ methodClose(TWENTY_SPACE); // if flag == false
- method += MethodsGenerator.getBlockEnd(
- SIXTEEN_SPACE_INDENTATION); // for instance iterator
-
-
+ method += methodClose(SIXTEEN_SPACE); // for instance iterator
} else {
/*if there is any app instance entry*/
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
APP_INSTANCE + PERIOD + name +
EMPTY_PARAMETER_FUNCTION_CALL +
@@ -865,14 +842,14 @@
/*
* loop all the query condition instance(s)
*/
- method += MethodsGenerator
+ method += StringGenerator
.getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
type + SPACE + name,
name +
EMPTY_PARAMETER_FUNCTION_CALL);
//loop all the app instance(s)
- method += MethodsGenerator.getCollectionIteratorForLoopBegin(
+ method += StringGenerator.getCollectionIteratorForLoopBegin(
TWENTY_FOUR_SPACE_INDENTATION, type + SPACE + name + "2",
APP_INSTANCE + PERIOD + name +
EMPTY_PARAMETER_FUNCTION_CALL);
@@ -880,7 +857,7 @@
method += TWENTY_EIGHT_SPACE_INDENTATION + type + SPACE +
"result = " + name + PERIOD +
PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + name + "2" +
- COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLAN +
+ COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
NEW_LINE;
method += TWENTY_EIGHT_SPACE_INDENTATION + "if (result != null) {" +
@@ -890,18 +867,18 @@
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
"result" + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
+ SEMI_COLON + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE;
//loop all the app instance(s)
method +=
- MethodsGenerator.getBlockEnd(TWENTY_FOUR_SPACE_INDENTATION);
+ methodClose(TWENTY_FOUR_SPACE);
//loop all the query condition instance(s)
- method += MethodsGenerator.getBlockEnd(TWENTY_SPACE_INDENTATION);
+ method += methodClose(TWENTY_SPACE);
//if there is any app instance entry
- method += MethodsGenerator.getBlockEnd(SIXTEEN_SPACE_INDENTATION);
+ method += methodClose(SIXTEEN_SPACE);
}
method += TWELVE_SPACE_INDENTATION + "} else {" + NEW_LINE;
@@ -909,10 +886,10 @@
if (isLeafList) {
method += SIXTEEN_SPACE_INDENTATION +
IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE +
- EQUAL + SPACE + TRUE + SEMI_COLAN + NEW_LINE;
+ EQUAL + SPACE + TRUE + SEMI_COLON + NEW_LINE;
}
- method += MethodsGenerator
+ method += StringGenerator
.getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
APP_INSTANCE + PERIOD + name
+ EMPTY_PARAMETER_FUNCTION_CALL +
@@ -923,7 +900,7 @@
EMPTY_PARAMETER_FUNCTION_CALL +
PERIOD + IS_EMPTY);
- method = method + MethodsGenerator
+ method = method + StringGenerator
.getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
type + SPACE + name,
APP_INSTANCE + PERIOD +
@@ -933,57 +910,54 @@
method = method + TWENTY_FOUR_SPACE_INDENTATION +
SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING
+ getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
- name + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ name + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
- method += MethodsGenerator.getBlockEnd(
- TWENTY_SPACE_INDENTATION); // Close collection Iteration loop
+ method += methodClose(TWENTY_SPACE);// Close collection Iteration loop
- method += MethodsGenerator
- .getBlockEnd(SIXTEEN_SPACE_INDENTATION); // close if condition
+ method +=
+ methodClose(SIXTEEN_SPACE); // close if condition
- method += MethodsGenerator
- .getBlockEnd(TWELVE_SPACE_INDENTATION); // close else condition
+ method +=
+ methodClose(TWELVE_SPACE); // close else condition
- method += MethodsGenerator.getBlockEnd(
- EIGHT_SPACE_INDENTATION); // close else if condition
+ method += methodClose(EIGHT_SPACE); // close else if condition
return method;
-
}
//Returns method string for op params augmented syntax
static String getAugmentableSubTreeFiltering() {
return EIGHT_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS +
- OBJECT_STRING + SPACE + getSmallCase(YANG_AUGMENTED_INFO) +
- SPACE + COLAN + SPACE + THIS + PERIOD +
- getSmallCase(YANG_AUGMENTED_INFO) + MAP +
+ OBJECT_STRING + SPACE + YANG_AUGMENTED_INFO_LOWER_CASE +
+ SPACE + COLON + SPACE + THIS + PERIOD +
+ YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD
+ VALUE + "s" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
NEW_LINE + TWELVE_SPACE_INDENTATION + OBJECT_STRING + SPACE +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) + SPACE + EQUAL +
SPACE + APP_INSTANCE + PERIOD +
- getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS +
- getSmallCase(YANG_AUGMENTED_INFO) + PERIOD +
- GET_CLASS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ YANG_AUGMENTED_INFO_LOWER_CASE + OPEN_PARENTHESIS +
+ YANG_AUGMENTED_INFO_LOWER_CASE + PERIOD +
+ GET_CLASS + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
TWELVE_SPACE_INDENTATION + OBJECT + SPACE +
- PROCESS_SUBTREE_FILTERING + SEMI_COLAN
+ PROCESS_SUBTREE_FILTERING + SEMI_COLON
+ NEW_LINE + TWELVE_SPACE_INDENTATION + TRY + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE +
SIXTEEN_SPACE_INDENTATION +
- "Class<?>[] interfaces = " + getSmallCase(YANG_AUGMENTED_INFO) +
+ "Class<?>[] interfaces = " + YANG_AUGMENTED_INFO_LOWER_CASE +
".getClass().getInterfaces();" +
NEW_LINE + SIXTEEN_SPACE_INDENTATION +
PROCESS_SUBTREE_FILTERING + SPACE + EQUAL + SPACE +
- getSmallCase(YANG_AUGMENTED_INFO) + PERIOD + GET_CLASS +
+ YANG_AUGMENTED_INFO_LOWER_CASE + PERIOD + GET_CLASS +
NEW_LINE + TWENTY_SPACE_INDENTATION + PERIOD +
GET_METHOD + OPEN_PARENTHESIS + QUOTES +
PROCESS_SUBTREE_FILTERING + QUOTES + COMMA + SPACE +
"interfaces[0]" + CLOSE_PARENTHESIS + PERIOD + INVOKE +
- OPEN_PARENTHESIS + getSmallCase(YANG_AUGMENTED_INFO) +
+ OPEN_PARENTHESIS + YANG_AUGMENTED_INFO_LOWER_CASE +
COMMA + NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
SIXTEEN_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
PROCESS_SUBTREE_FILTERING + SPACE + NOT + EQUAL + SPACE +
NULL + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
@@ -992,7 +966,7 @@
YANG_AUGMENTED_INFO + OPEN_PARENTHESIS +
PROCESS_SUBTREE_FILTERING + COMMA + SPACE +
PROCESS_SUBTREE_FILTERING + PERIOD + GET_CLASS +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
SPACE + CATCH + SPACE + OPEN_PARENTHESIS +
@@ -1000,7 +974,7 @@
INVOCATION_TARGET_EXCEPTION + " | " + ILLEGAL_ACCESS_EXCEPTION +
SPACE + EXCEPTION_VAR + CLOSE_PARENTHESIS + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION +
- CONTINUE + SEMI_COLAN + NEW_LINE +
+ CONTINUE + SEMI_COLON + NEW_LINE +
TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java
index a2c80e6..2871f16 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java
@@ -43,6 +43,11 @@
INVALID_LEAF_HOLDER("Invalid holder of leaf"),
/**
+ * Represents the invalid child node.
+ */
+ INVALID_CHILD_NODE("Invalid child of node "),
+
+ /**
* Represents the invalid leaf list without JAVA information.
*/
INVALID_LEAF_LIST("Leaf-list does not have java information"),
@@ -61,16 +66,15 @@
/**
* Represents that code generation failed for a node at exit.
*/
- FAIL_AT_EXIT("Failed to generate code for notification node"),
+ FAIL_AT_EXIT("Failed to generate code for "),
/**
* Represents that code generation preparation failed for a node at entry.
*/
- FAIL_AT_ENTRY("Failed to prepare generate code entry for " +
- "notification node");
+ FAIL_AT_ENTRY("Failed to prepare generate code entry for ");
// Prefix of an error type.
- private String prefix;
+ private final String prefix;
/**
* Creates translator error type.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java
index 2116ab8..cc7781d 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java
@@ -23,18 +23,17 @@
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import java.io.IOException;
+import static org.onosproject.yangutils.utils.UtilConstants.AT;
+import static org.onosproject.yangutils.utils.UtilConstants.IN;
+
/**
* Represents common translator utilities.
*/
public final class TranslatorUtils {
- private static final String IN = " in ";
- private static final String AT = " at ";
-
// No instantiation
private TranslatorUtils() {
}
@@ -119,7 +118,7 @@
* @param curNode current YANG node
* @return type files
*/
- public static TempJavaTypeFragmentFiles getTypeFiles(YangNode curNode) {
+ static TempJavaTypeFragmentFiles getTypeFiles(YangNode curNode) {
return ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getTypeTempFiles();
}
@@ -130,19 +129,15 @@
* @param node YANG node
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
- * @param config plugin configurations
- * @param curNode YANG node
* @return default constructor for class
* @throws IOException when fails to append to file
*/
- public static String addDefaultConstructor(YangNode node, String modifier,
- String toAppend,
- YangPluginConfig config,
- YangNode curNode)
+ static String addDefaultConstructor(YangNode node, String modifier,
+ String toAppend)
throws IOException {
return ((TempJavaCodeFragmentFilesContainer) node)
.getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(modifier, toAppend, config, curNode);
+ .addDefaultConstructor(modifier, toAppend);
/*
* TODO update addDefaultConstructor, it doesn't need YANG node as an
* input.
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 b7ddc34..2dca607 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -153,7 +153,7 @@
* JavaDocs's description for getter method.
*/
public static final String JAVA_DOC_FOR_VALIDATOR_RETURN =
- " * @return true if value is in range";
+ " true if value is in range";
/**
* JavaDocs's description for constructor.
@@ -167,11 +167,6 @@
public static final String JAVA_DOC_BUILD = " * Builds object of ";
/**
- * JavaDocs's return statement for build method.
- */
- public static final String JAVA_DOC_BUILD_RETURN = "object of ";
-
- /**
* JavaDocs's statement for builder object.
*/
public static final String BUILDER_OBJECT = "builder object of ";
@@ -203,6 +198,11 @@
public static final String DEFAULT = "default";
/**
+ * Static attribute for default.
+ */
+ public static final String DEFAULT_CAPS = "Default";
+
+ /**
* Static attribute for java code generation for sbi.
*/
public static final String SBI = "sbi";
@@ -228,6 +228,11 @@
public static final String PERIOD = ".";
/**
+ * Static attribute for compare to.
+ */
+ public static final String COMPARE_TO = "compareTo";
+
+ /**
* Static attribute for period.
*/
public static final String INVOKE = "invoke";
@@ -288,11 +293,6 @@
public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()";
/**
- * Static attribute for colan.
- */
- public static final String COLAN = ":";
-
- /**
* Static attribute for underscore.
*/
public static final String UNDER_SCORE = "_";
@@ -300,7 +300,7 @@
/**
* Static attribute for semi-colan.
*/
- public static final String SEMI_COLAN = ";";
+ public static final String SEMI_COLON = ";";
/**
* Static attribute for hyphen.
@@ -313,16 +313,16 @@
public static final String SPACE = " ";
/**
+ * Static attribute for isSelectAllSchemaChild.
+ */
+ public static final String SELECT_ALL_CHILD = "isSelectAllSchemaChild";
+
+ /**
* Static attribute for schema name.
*/
public static final String SCHEMA_NAME = "schemaName";
/**
- * Static attribute for schema name value.
- */
- public static final String STR_VAL = "stringValue";
-
- /**
* Static attribute for validateRange.
*/
public static final String VALIDATE_RANGE = "validateRange";
@@ -484,11 +484,6 @@
public static final String SUBJECT = "Subject";
/**
- * Static attribute for ListenerRegistry.
- */
- public static final String LISTENER_REG = "ListenerRegistry";
-
- /**
* Static attribute for ListenerService.
*/
public static final String LISTENER_SERVICE = "ListenerService";
@@ -719,6 +714,11 @@
public static final String TO = "to";
/**
+ * Static attribute for to syntax.
+ */
+ public static final String TO_CAPS = "To";
+
+ /**
* Static attribute for true syntax.
*/
public static final String TRUE = "true";
@@ -736,7 +736,7 @@
/**
* Static attribute for temp.
*/
- public static final String TEMP = "temp";
+ public static final String TEMP = "Temp";
/**
* Static attribute for YANG file directory.
@@ -754,6 +754,11 @@
public static final String DIAMOND_CLOSE_BRACKET = ">";
/**
+ * Static attribute for event type.
+ */
+ public static final String EVENT_TYPE = ".Type";
+
+ /**
* Static attribute for exception syntax.
*/
public static final String EXCEPTION = "Exception";
@@ -913,6 +918,10 @@
* Static attribute for is LeafIdentifier enum prefix.
*/
public static final String LEAF_IDENTIFIER = "LeafIdentifier";
+ /**
+ * Static attribute for is leaf.
+ */
+ public static final String LEAF = "leaf";
/**
* Static attribute for four space indentation.
@@ -1123,6 +1132,11 @@
public static final String QUESTION_MARK = "?";
/**
+ * Static variable for forType string.
+ */
+ public static final String FOR_TYPE_STRING = " for type ";
+
+ /**
* List of keywords in java, this is used for checking if the input does not
* contain these keywords.
*/
@@ -1220,9 +1234,9 @@
public static final String BUILDER = "Builder";
/**
- * Static attribute for manager syntax.
+ * Static attribute for builder syntax.
*/
- public static final String MANAGER = "Manager";
+ public static final String BUILDER_LOWER_CASE = "builder";
/**
* Static attribute for service syntax.
@@ -1365,13 +1379,13 @@
* Static attribute for more object import class.
*/
public static final String GOOGLE_MORE_OBJECT_IMPORT_CLASS =
- "MoreObjects;\n";
+ "MoreObjects";
/**
* Static attribute for to string method.
*/
public static final String GOOGLE_MORE_OBJECT_METHOD_STRING =
- " MoreObjects.toStringHelper(getClass())";
+ "MoreObjects.toStringHelper(getClass())";
/**
* Static attribute for java utilities import package.
@@ -1386,7 +1400,7 @@
/**
* Static attribute for java utilities objects import class.
*/
- public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
+ public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects";
/**
* Static attribute for AugmentedInfo class.
@@ -1394,6 +1408,12 @@
public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
/**
+ * Static attribute for AugmentedInfo class.
+ */
+ public static final String YANG_AUGMENTED_INFO_LOWER_CASE =
+ "yangAugmentedInfo";
+
+ /**
* Static attribute for augmented.
*/
public static final String AUGMENTED = "Augmented";
@@ -1414,7 +1434,7 @@
public static final String SET = "Set";
/**
- * Comment to be added for autogenerated impl methods.
+ * Comment to be added for auto generated impl methods.
*/
public static final String YANG_UTILS_TODO =
"//TODO: YANG utils generated code";
@@ -1451,6 +1471,17 @@
" is not supported.";
/**
+ * Static attribute for "is invalid" information.
+ */
+ public static final String IS_INVALID = " is invalid.";
+
+ /**
+ * Static attribute for data model tree error information.
+ */
+ public static final String INVALID_TREE = "Internal datamodel error: " +
+ "Datamodel tree is not correct";
+
+ /**
* Static attribute for currently unsupported error information.
*/
public static final String CURRENTLY_UNSUPPORTED =
@@ -1458,6 +1489,70 @@
" for YANG utils road map.";
/**
+ * Static attribute for leaf ref target node error information.
+ */
+ public static final String LEAFREF_ERROR = "YANG file error: The target" +
+ " node, in the leafref path ";
+
+ /**
+ * Static attribute for leaf holder error information.
+ */
+ public static final String LEAF_HOLDER_ERROR = "Referred node should be of" +
+ " type leaves holder in ";
+
+ /**
+ * Static attribute for invalid resolve entity error information.
+ */
+ public static final String INVALID_RESOLVED_ENTITY = "Data Model " +
+ "Exception: Entity to resolved is other than type/uses";
+
+ /**
+ * Static attribute for invalid resolve entity error information.
+ */
+ public static final String INVALID_ENTITY = "Data Model Exception: Entity " +
+ "to resolved is other than identityref";
+
+ /**
+ * Static attribute for invalid state error information.
+ */
+ public static final String INVALID_LINKER_STATE = "Data Model Exception: " +
+ "Unsupported, linker state";
+
+ /**
+ * Static attribute for leaf ref resolve entity error information.
+ */
+ public static final String FAILED_TO_FIND_LEAD_INFO_HOLDER = "YANG file " +
+ "error: Unable to find base leaf/leaf-list for given leafref path ";
+
+ /**
+ * Static attribute for compiler annotation resolve entity error
+ * information.
+ */
+ public static final String FAILED_TO_FIND_ANNOTATION = "Failed to link " +
+ "compiler annotation ";
+
+ /**
+ * Static attribute for failed to link entity error information.
+ */
+ public static final String FAILED_TO_LINK = "Failed to link ";
+
+ /**
+ * Static attribute for un-resolve entity error information.
+ */
+ public static final String UNRESOLVABLE = "Data Model Exception: Entity " +
+ "to resolved is not Resolvable";
+
+ /**
+ * Static attribute for invalid resolve entity error information.
+ */
+ public static final String LINKER_ERROR = "Data Model Exception: Entity" +
+ " to resolved is other than type/uses/if-feature/leafref/base/identityref";
+
+ /**
+ * Static attribute for invalid resolve entity error information.
+ */
+ public static final String INVALID_TARGET = "Invalid target node type ";
+ /**
* Static attribute for typedef linker error information.
*/
public static final String TYPEDEF_LINKER_ERROR =
@@ -1564,7 +1659,7 @@
* Static attribute for YANG node operation type attribute.
*/
public static final String OPERATION_TYPE_ATTRIBUTE =
- "NodeOperationType";
+ "OpType";
/**
* Static attribute for event class.
@@ -1621,6 +1716,29 @@
*/
public static final String YANG = "yang";
+ /**
+ * Static attribute for error msg.
+ */
+ public static final String ERROR_MSG_FOR_GEN_CODE = "please check whether " +
+ "multiple yang" + " files has same module/submodule" +
+ " \"name\" and \"namespace\"" + "or You may have generated code of" +
+ " previous build present in your directory.";
+
+ /**
+ * Static attribute for error msg.
+ */
+ public static final String ERROR_MSG_JAVA_IDENTITY = "Expected java " +
+ "identity instance node ";
+ /**
+ * Static attribute for in.
+ */
+ public static final String IN = " in ";
+
+ /**
+ * Static attribute for at.
+ */
+ public static final String AT = " at ";
+
// No instantiation.
private UtilConstants() {
}
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 1f75ab8..cc721ed 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
@@ -52,7 +52,8 @@
*/
static void appendFileContents(File toAppend, File srcFile)
throws IOException {
- updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false);
+ updateFileHandle(srcFile, readAppendFile(toAppend.toString(),
+ FOUR_SPACE_INDENTATION), false);
}
/**
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 a5e86d1..d9933a9 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -16,12 +16,11 @@
package org.onosproject.yangutils.utils.io.impl;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
+import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
@@ -38,7 +37,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_ADD_TO_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
@@ -53,8 +51,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
@@ -71,11 +67,14 @@
import static org.onosproject.yangutils.utils.UtilConstants.SET;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
+import static org.onosproject.yangutils.utils.UtilConstants.TO_CAPS;
+import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
* Represents javadoc for the generated classes.
@@ -94,14 +93,13 @@
* @param type java doc type
* @param name name of the YangNode
* @param isList is list attribute
- * @param pluginConfig plugin configurations
* @param compilerAnnotation compiler annotations for user defined data type
* @return javaDocs.
*/
- public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig,
+ public static String getJavaDoc(JavaDocType type, String name, boolean isList,
String compilerAnnotation) {
- name = YangIoUtils.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver()));
+ name = YangIoUtils.getSmallCase(name);
switch (type) {
case IMPL_CLASS: {
return generateForClass(name);
@@ -188,8 +186,8 @@
* @return javaDocs
*/
private static String generateForEnumAttr(String name) {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
- + name + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(name, ENUM_ATTRIBUTE_JAVADOC,
+ FOUR_SPACE_INDENTATION);
}
/**
@@ -199,33 +197,31 @@
* @return javaDocs
*/
public static String enumJavaDocForInnerClass(String name) {
- return EIGHT_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + EIGHT_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
- + name + PERIOD + NEW_LINE + EIGHT_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(name, ENUM_ATTRIBUTE_JAVADOC,
+ EIGHT_SPACE_INDENTATION);
}
/**
* Generates javaDocs for rpc method.
*
- * @param rpcName name of the rpc
- * @param inputName name of input
- * @param outputName name of output
- * @param pluginConfig plugin configurations
+ * @param rpcName name of the rpc
+ * @param inputName name of input
+ * @param outputName name of output
* @return javaDocs of rpc method
*/
- public static String generateJavaDocForRpc(String rpcName, String inputName, String outputName,
- YangPluginConfig pluginConfig) {
- rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
+ public static String generateJavaDocForRpc(String rpcName, String inputName,
+ String outputName) {
- String javadoc =
- NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RPC
- + rpcName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK;
+ String javadoc = getJavaDocStartLine(rpcName, JAVA_DOC_RPC) +
+ getJavaDocEmptyAsteriskLine();
if (!inputName.equals(EMPTY_STRING)) {
javadoc = javadoc + getInputString(inputName, rpcName);
}
if (!outputName.equals(VOID)) {
- javadoc = javadoc + getOutputString(outputName, rpcName);
+ javadoc = javadoc + getOutputString(getSmallCase(outputName),
+ rpcName);
}
- return javadoc + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return javadoc + getJavaDocEndLine();
}
/**
@@ -236,7 +232,8 @@
* @return javaDocs for output string of rpc
*/
private static String getOutputString(String outputName, String rpcName) {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + outputName + SPACE + RPC_OUTPUT_STRING + rpcName + NEW_LINE;
+ return FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + outputName + SPACE +
+ RPC_OUTPUT_STRING + rpcName + NEW_LINE;
}
/**
@@ -247,10 +244,11 @@
* @return javaDocs for input string of rpc
*/
private static String getInputString(String inputName, String rpcName) {
- if (inputName.equals("")) {
+ if (inputName.isEmpty()) {
return null;
} else {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + inputName + SPACE + RPC_INPUT_STRING + rpcName + NEW_LINE;
+ return FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + inputName +
+ SPACE + RPC_INPUT_STRING + rpcName + NEW_LINE;
}
}
@@ -261,30 +259,27 @@
* @return javaDocs
*/
private static String generateForRpcService(String interfaceName) {
- return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE
- + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(interfaceName, INTERFACE_JAVA_DOC, EMPTY_STRING);
}
/**
* Generates javaDoc for the event.
*
- * @param eventClassName event class name
+ * @param name event class name
* @return javaDocs
*/
- private static String generateForEvent(String eventClassName) {
- return NEW_LINE + JAVA_DOC_FIRST_LINE + EVENT_JAVA_DOC + eventClassName + PERIOD + NEW_LINE
- + JAVA_DOC_END_LINE;
+ private static String generateForEvent(String name) {
+ return getJavaDocForClass(name, EVENT_JAVA_DOC, EMPTY_STRING);
}
/**
* Generates javaDoc for the event listener.
*
- * @param eventListenerInterfaceName event class name
+ * @param name event class name
* @return javaDocs
*/
- private static String generateForEventListener(String eventListenerInterfaceName) {
- return NEW_LINE + JAVA_DOC_FIRST_LINE + EVENT_LISTENER_JAVA_DOC + eventListenerInterfaceName
- + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
+ private static String generateForEventListener(String name) {
+ return getJavaDocForClass(name, EVENT_LISTENER_JAVA_DOC, EMPTY_STRING);
}
/**
@@ -298,38 +293,12 @@
private static String generateForGetters(String attribute, boolean isList,
String compilerAnnotation) {
- String getter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_GETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
- + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN;
- if (isList) {
- String attrParam;
- if (compilerAnnotation != null) {
- switch (compilerAnnotation) {
- case QUEUE: {
- attrParam = QUEUE.toLowerCase() + SPACE + OF + SPACE;
- break;
- }
- case SET: {
- attrParam = SET.toLowerCase() + SPACE + OF + SPACE;
- break;
- }
- case LIST: {
- attrParam = LIST.toLowerCase() + SPACE + OF + SPACE;
- break;
- }
- default: {
- attrParam = LIST.toLowerCase() + SPACE + OF + SPACE;
- }
- }
- } else {
- attrParam = LIST.toLowerCase() + SPACE + OF + SPACE;
- }
- getter = getter + attrParam;
- } else {
- getter = getter + VALUE + SPACE + OF + SPACE;
- }
+ String getter = getJavaDocStartLine(attribute, JAVA_DOC_GETTERS) +
+ getJavaDocEmptyAsteriskLine() +
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + attribute + SPACE;
- getter = getter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ getter = getParamForAnnotation(getter, compilerAnnotation, isList) +
+ attribute + NEW_LINE + getJavaDocEndLine();
return getter;
}
@@ -344,41 +313,12 @@
private static String generateForSetters(String attribute, boolean isList,
String compilerAnnotation) {
- String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
- + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
-
- String attributeParam;
- if (compilerAnnotation != null) {
- switch (compilerAnnotation) {
- case QUEUE: {
- attributeParam = QUEUE.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- break;
- }
- case SET: {
- attributeParam = SET.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- break;
- }
- case LIST: {
- attributeParam = LIST.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- break;
- }
- default: {
-
- }
- }
- } else if (isList) {
- attributeParam = LIST.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- } else {
- setter = setter + VALUE + SPACE + OF + SPACE;
- }
- setter = setter + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + BUILDER_OBJECT
- + attribute
- + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ String setter = getJavaDocStartLine(attribute, JAVA_DOC_SETTERS) +
+ getJavaDocEmptyAsteriskLine() +
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
+ setter = getParamForAnnotation(setter, compilerAnnotation, isList) +
+ attribute + NEW_LINE + getJavaDocReturnLine(attribute)
+ + getJavaDocEndLine();
return setter;
}
@@ -392,11 +332,16 @@
*/
private static String generateForManagerSetters(String attribute, boolean isList,
String compilerAnnotation) {
+ String setter = getJavaDocStartLine(attribute, JAVA_DOC_MANAGER_SETTERS) +
+ getJavaDocEmptyAsteriskLine() +
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
+ setter = getParamForAnnotation(setter, compilerAnnotation, isList) +
+ attribute + NEW_LINE + getJavaDocEndLine();
+ return setter;
+ }
- String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_MANAGER_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
- + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
-
+ private static String getParamForAnnotation(
+ String setter, String compilerAnnotation, boolean isList) {
String attributeParam;
if (compilerAnnotation != null) {
switch (compilerAnnotation) {
@@ -425,8 +370,6 @@
} else {
setter = setter + VALUE + SPACE + OF + SPACE;
}
- setter = setter + attribute
- + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return setter;
}
@@ -437,11 +380,11 @@
* @return javaDocs
*/
private static String generateForOf(String attribute) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
- + 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
- + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
- + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(attribute, JAVA_DOC_OF) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(attribute, VALUE) +
+ getJavaDocReturnLine(attribute) +
+ getJavaDocEndLine();
}
/**
@@ -451,13 +394,14 @@
* @return javaDocs
*/
private static String generateForFromString(String attribute) {
-
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
- + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD
- + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
- + FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + NEW_LINE
- + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
- + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(attribute, JAVA_DOC_OF
+ + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT +
+ SPACE + STRING_DATA_TYPE) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(INPUT + SPACE + STRING_DATA_TYPE,
+ FROM_STRING_PARAM_NAME) +
+ getJavaDocReturnLine(attribute) +
+ getJavaDocEndLine();
}
/**
@@ -467,10 +411,10 @@
* @return javaDocs
*/
private static String generateForTypeDefSetter(String attribute) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_SETTERS_COMMON + 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 + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(attribute, JAVA_DOC_SETTERS_COMMON) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(attribute, VALUE) +
+ getJavaDocEndLine();
}
/**
@@ -480,7 +424,7 @@
* @return javaDocs
*/
private static String generateForClass(String className) {
- return NEW_LINE + JAVA_DOC_FIRST_LINE + IMPL_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(className, IMPL_CLASS_JAVA_DOC, EMPTY_STRING);
}
/**
@@ -490,8 +434,7 @@
* @return javaDocs
*/
private static String generateForEnum(String className) {
- return NEW_LINE + NEW_LINE + JAVA_DOC_FIRST_LINE + ENUM_CLASS_JAVADOC + className + PERIOD + NEW_LINE
- + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(className, ENUM_CLASS_JAVADOC, EMPTY_STRING);
}
/**
@@ -501,8 +444,8 @@
* @return javaDocs
*/
private static String generateForBuilderClass(String className) {
- return NEW_LINE + JAVA_DOC_FIRST_LINE + BUILDER_CLASS_JAVA_DOC + className + PERIOD + NEW_LINE
- + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(className, BUILDER_CLASS_JAVA_DOC,
+ EMPTY_STRING);
}
/**
@@ -512,8 +455,8 @@
* @return javaDocs
*/
private static String generateForOpParamClass(String className) {
- return NEW_LINE + JAVA_DOC_FIRST_LINE + OP_PARAM_JAVA_DOC + className + PERIOD + NEW_LINE
- + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(className, OP_PARAM_JAVA_DOC,
+ EMPTY_STRING);
}
/**
@@ -523,8 +466,8 @@
* @return javaDocs
*/
private static String generateForInterface(String interfaceName) {
- return NEW_LINE + JAVA_DOC_FIRST_LINE + INTERFACE_JAVA_DOC + interfaceName + PERIOD + NEW_LINE
- + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(interfaceName, INTERFACE_JAVA_DOC,
+ EMPTY_STRING);
}
/**
@@ -534,8 +477,8 @@
* @return javaDocs
*/
private static String generateForBuilderInterface(String builderForName) {
- return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderForName + PERIOD + NEW_LINE
- + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(builderForName, BUILDER_INTERFACE_JAVA_DOC,
+ EMPTY_STRING);
}
/**
@@ -546,11 +489,12 @@
* @return javaDocs
*/
private static String generateForPackage(String packageName, boolean isChildNode) {
- String javaDoc = JAVA_DOC_FIRST_LINE + PACKAGE_INFO_JAVADOC + packageName;
if (isChildNode) {
- javaDoc = javaDoc + PACKAGE_INFO_JAVADOC_OF_CHILD;
+ return getJavaDocForClass(
+ packageName + PACKAGE_INFO_JAVADOC_OF_CHILD,
+ PACKAGE_INFO_JAVADOC, EMPTY_STRING);
}
- return javaDoc + PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
+ return getJavaDocForClass(packageName, PACKAGE_INFO_JAVADOC, EMPTY_STRING);
}
/**
@@ -560,8 +504,8 @@
* @return javaDocs
*/
private static String generateForDefaultConstructors(String className) {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className
- + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(className, JAVA_DOC_CONSTRUCTOR) +
+ getJavaDocEndLine();
}
/**
@@ -571,10 +515,11 @@
* @return javaDocs
*/
private static String generateForConstructors(String className) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
- + className + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
- + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT
- + className + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(className, JAVA_DOC_CONSTRUCTOR) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(BUILDER_OBJECT + className,
+ BUILDER_LOWER_CASE + OBJECT) +
+ getJavaDocEndLine();
}
/**
@@ -584,10 +529,10 @@
* @return javaDocs
*/
private static String generateForBuild(String buildName) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD
- + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
- + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(buildName, JAVA_DOC_BUILD) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocReturnLine(buildName) +
+ getJavaDocEndLine();
}
/**
@@ -597,10 +542,11 @@
* @return javaDocs for type constructor
*/
private static String generateForTypeConstructor(String attribute) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
- + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
- + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
- + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(attribute,
+ JAVA_DOC_CONSTRUCTOR) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(attribute, attribute) +
+ getJavaDocEndLine();
}
/**
@@ -609,12 +555,13 @@
* @return javaDocs
*/
public static String generateForAddAugmentation() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_SETTERS_COMMON + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + NEW_LINE +
- FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE +
- VALUE + SPACE + OF + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + NEW_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_PARAM + CLASS + OBJECT_STRING + SPACE +
- VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(YANG_AUGMENTED_INFO_LOWER_CASE,
+ JAVA_DOC_SETTERS_COMMON) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, VALUE) +
+ getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, CLASS +
+ OBJECT_STRING) +
+ getJavaDocEndLine();
}
/**
@@ -623,12 +570,13 @@
* @return javadoc for get augmentation method
*/
public static String generateForGetAugmentation() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_GETTERS + getSmallCase(YANG_AUGMENTED_INFO) + PERIOD + NEW_LINE +
- FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + CLASS +
- OBJECT_STRING + SPACE + VALUE + SPACE + OF + SPACE + AUGMENTED + CLASS + NEW_LINE +
- FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + VALUE + SPACE +
- OF + SPACE + YANG_AUGMENTED_INFO + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ return NEW_LINE + getJavaDocStartLine(YANG_AUGMENTED_INFO_LOWER_CASE,
+ JAVA_DOC_GETTERS) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, CLASS +
+ OBJECT_STRING) +
+ getJavaDocReturnLine(YANG_AUGMENTED_INFO) +
+ getJavaDocEndLine();
}
/**
@@ -637,15 +585,12 @@
* @return javadoc for validator method
*/
public static String generateForValidatorMethod() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION +
- JAVA_DOC_FOR_VALIDATOR + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK +
- FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + MIN_RANGE + SPACE + MIN_RANGE + SPACE + OF + SPACE +
- VALUE + NEW_LINE +
- FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + MAX_RANGE + SPACE + MAX_RANGE + SPACE + OF + SPACE + VALUE +
- NEW_LINE +
- FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + NEW_LINE +
- FOUR_SPACE_INDENTATION + JAVA_DOC_FOR_VALIDATOR_RETURN + NEW_LINE + FOUR_SPACE_INDENTATION +
- JAVA_DOC_END_LINE;
+ return getJavaDocStartLine(VALIDATE_RANGE, JAVA_DOC_FOR_VALIDATOR) +
+ getJavaDocEmptyAsteriskLine() +
+ trimAtLast(getJavaDocParamLine(MIN_RANGE, MIN_RANGE), NEW_LINE) +
+ getJavaDocParamLine(MIN_RANGE, MIN_RANGE) +
+ getJavaDocReturnLine(JAVA_DOC_FOR_VALIDATOR_RETURN) +
+ getJavaDocEndLine();
}
/**
@@ -655,11 +600,12 @@
* @return javaDocs for type constructor
*/
public static String generateForGetMethodWithAttribute(String attribute) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_GETTERS
- + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
- + JAVA_DOC_PARAM + getSmallCase(attribute) + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
- + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
- + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+ attribute = getSmallCase(attribute);
+ return getJavaDocStartLine(attribute, JAVA_DOC_GETTERS) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(attribute, attribute) +
+ getJavaDocReturnLine(attribute) +
+ getJavaDocEndLine();
}
/**
@@ -669,14 +615,11 @@
* @return javaDocs
*/
private static String generateForAddToList(String attribute) {
- String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_ADD_TO_LIST + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
- + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE;
- javadoc = javadoc + VALUE + SPACE + OF + SPACE;
- javadoc = javadoc + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + BUILDER_OBJECT
- + attribute
- + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
- return javadoc;
+ return getJavaDocStartLine(attribute, JAVA_DOC_ADD_TO_LIST) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocParamLine(attribute, ADD_STRING + TO_CAPS) +
+ getJavaDocReturnLine(BUILDER_OBJECT + attribute) +
+ getJavaDocEndLine();
}
/**
@@ -686,13 +629,78 @@
* @return javaDocs
*/
public static String generateForBuilderMethod(String attribute) {
+ return getJavaDocStartLine(attribute + BUILDER, JAVA_DOC_GETTERS) +
+ getJavaDocEmptyAsteriskLine() +
+ getJavaDocReturnLine(attribute + BUILDER) +
+ getJavaDocEndLine();
+ }
- String javadoc = FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
- + JAVA_DOC_GETTERS + attribute + BUILDER + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
- + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN;
- javadoc = javadoc + VALUE + SPACE + OF + SPACE;
- javadoc = javadoc + attribute + BUILDER + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
- return javadoc;
+ /**
+ * Returns class javadoc.
+ *
+ * @param name name of class
+ * @param type type of javadoc
+ * @param indent indentation
+ * @return class javadoc
+ */
+ private static String getJavaDocForClass(String name, String type,
+ String indent) {
+ return NEW_LINE + indent + JAVA_DOC_FIRST_LINE + indent + type +
+ getSmallCase(name) + PERIOD + NEW_LINE + indent + JAVA_DOC_END_LINE;
+ }
+
+ /**
+ * Returns javadoc start line.
+ *
+ * @param name name of attribute
+ * @param javaDoc type of javadoc
+ * @return javadoc start line
+ */
+ private static String getJavaDocStartLine(String name, String javaDoc) {
+ return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE +
+ FOUR_SPACE_INDENTATION + javaDoc + getSmallCase(name) +
+ PERIOD + NEW_LINE;
+ }
+
+ /**
+ * Returns asterisk line.
+ *
+ * @return asterisk line
+ */
+ private static String getJavaDocEmptyAsteriskLine() {
+ return FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK;
+ }
+
+ /**
+ * Returns javadoc param line.
+ *
+ * @param name name of attribute
+ * @return javadoc param line
+ */
+ private static String getJavaDocParamLine(String name, String paraName) {
+ return FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM +
+ getSmallCase(paraName) + SPACE + VALUE + SPACE + OF + SPACE +
+ getSmallCase(name) + NEW_LINE;
+ }
+
+ /**
+ * Returns javadoc return line.
+ *
+ * @param name name of attribute
+ * @return javadoc return line
+ */
+ private static String getJavaDocReturnLine(String name) {
+ return FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + getSmallCase(name)
+ + NEW_LINE;
+ }
+
+ /**
+ * Returns javadoc end line.
+ *
+ * @return javadoc end line
+ */
+ private static String getJavaDocEndLine() {
+ return FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
@@ -826,5 +834,4 @@
*/
ADD_TO_LIST,
}
-
}
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 2294b99..e1020a1 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
@@ -16,6 +16,10 @@
package org.onosproject.yangutils.utils.io.impl;
+import org.apache.commons.io.FileUtils;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
+import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -24,21 +28,16 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.LinkedList;
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 org.onosproject.yangutils.utils.io.YangPluginConfig;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
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.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -60,9 +59,10 @@
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_UPPERCASE;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
import static org.onosproject.yangutils.utils.UtilConstants.UNUSED;
@@ -80,7 +80,7 @@
private static final int LINE_SIZE = 118;
private static final int SUB_LINE_SIZE = 116;
- private static final int ZERO = 0;
+ private static final int SUB_SIZE = 60;
/**
* Creates an instance of YANG io utils.
@@ -110,26 +110,24 @@
/**
* Adds package info file for the created directory.
*
- * @param path directory path
- * @param classInfo class info for the package
- * @param pack package of the directory
- * @param isChildNode is it a child node
- * @param pluginConfig plugin configurations
+ * @param path directory path
+ * @param classInfo class info for the package
+ * @param pack package of the directory
+ * @param isChildNode is it a child node
* @throws IOException when fails to create package info file
*/
- public static void addPackageInfo(File path, String classInfo, String pack, boolean isChildNode,
- YangPluginConfig pluginConfig)
- throws IOException {
+ public static void addPackageInfo(File path, String classInfo, String pack,
+ boolean isChildNode) throws IOException {
pack = parsePkg(pack);
-
try {
File packageInfo = new File(path + SLASH + "package-info.java");
if (!packageInfo.exists()) {
boolean isGenerated = packageInfo.createNewFile();
if (!isGenerated) {
- throw new IOException("failed to generated package-info " + path);
+ throw new IOException("failed to generated package-info " +
+ path);
}
}
FileWriter fileWriter = new FileWriter(packageInfo);
@@ -137,16 +135,18 @@
bufferedWriter.write(getCopyrightHeader());
//TODO: get the compiler annotations and pass the info
- bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode, pluginConfig, null));
- String pkg = PACKAGE + SPACE + pack + SEMI_COLAN;
+ bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode,
+ null));
+ String pkg = PACKAGE + SPACE + pack + SEMI_COLON;
if (pkg.length() > LINE_SIZE) {
- pkg = whenDelimiterIsPresent(pkg, LINE_SIZE);
+ pkg = processModifications(pkg, LINE_SIZE);
}
bufferedWriter.write(pkg);
bufferedWriter.close();
fileWriter.close();
} catch (IOException e) {
- throw new IOException("Exception occurred while creating package info file.");
+ throw new IOException("Exception occurred while creating package info" +
+ " file.");
}
}
@@ -190,7 +190,8 @@
FileUtils.deleteDirectory(generatedDirectory);
} catch (IOException e) {
throw new IOException(
- "Failed to delete the generated files in " + generatedDirectory + " directory");
+ "Failed to delete the generated files in " +
+ generatedDirectory + " directory");
}
}
}
@@ -217,7 +218,7 @@
for (File current : fileList) {
if (current.isDirectory()) {
stack.push(current.toString());
- if (current.getName().endsWith("-Temp")) {
+ if (current.getName().endsWith(HYPHEN + TEMP)) {
store.add(current);
}
}
@@ -236,11 +237,17 @@
* @param removalString extra chars
* @return new string
*/
- public static String trimAtLast(String valueString, String removalString) {
+ public static String trimAtLast(String valueString, String...
+ removalString) {
StringBuilder stringBuilder = new StringBuilder(valueString);
- int index = valueString.lastIndexOf(removalString);
- if (index != -1) {
- stringBuilder.deleteCharAt(index);
+ String midString;
+ int index;
+ for (String remove : removalString) {
+ midString = stringBuilder.toString();
+ index = midString.lastIndexOf(remove);
+ if (index != -1) {
+ stringBuilder.deleteCharAt(index);
+ }
}
return stringBuilder.toString();
}
@@ -253,14 +260,16 @@
* @param replacingString string with which replacement is to be done
* @return new string
*/
- public static String replaceLast(String valueString, String removalString, String replacingString) {
+ public static String replaceLast(String valueString, String removalString,
+ String replacingString) {
StringBuilder stringBuilder = new StringBuilder(valueString);
int index = valueString.lastIndexOf(removalString);
if (index != -1) {
stringBuilder.replace(index, index + 1, replacingString);
} else {
- stringBuilder.append(NEW_LINE + EIGHT_SPACE_INDENTATION + UNUSED + OPEN_PARENTHESIS + ONE +
- CLOSE_PARENTHESIS + SEMI_COLAN);
+ stringBuilder.append(NEW_LINE + EIGHT_SPACE_INDENTATION + UNUSED +
+ OPEN_PARENTHESIS + ONE +
+ CLOSE_PARENTHESIS + SEMI_COLON);
}
return stringBuilder.toString();
@@ -297,7 +306,8 @@
* @param pathOfJavaPkg java package of the file being generated
* @return absolute path of the package in canonical form
*/
- public static String getAbsolutePackagePath(String baseCodeGenPath, String pathOfJavaPkg) {
+ public static String getAbsolutePackagePath(String baseCodeGenPath,
+ String pathOfJavaPkg) {
return baseCodeGenPath + pathOfJavaPkg;
}
@@ -313,7 +323,8 @@
try {
appendFileContents(appendFile, srcFile);
} catch (IOException e) {
- throw new IOException("Failed to merge " + appendFile + " in " + srcFile);
+ throw new IOException("Failed to merge " + appendFile + " in " +
+ srcFile);
}
}
@@ -345,23 +356,16 @@
throws IOException {
FileReader fileReader = new FileReader(dataFile);
BufferedReader bufferReader = new BufferedReader(fileReader);
- String append;
try {
StringBuilder stringBuilder = new StringBuilder();
String line = bufferReader.readLine();
while (line != null) {
if (line.length() > LINE_SIZE) {
- if (line.contains(PERIOD)) {
- line = whenDelimiterIsPresent(line, LINE_SIZE);
- } else if (line.contains(SPACE)) {
- line = whenSpaceIsPresent(line, LINE_SIZE);
- }
- stringBuilder.append(line);
- } else {
- append = line + NEW_LINE;
- stringBuilder.append(append);
+ line = processModifications(line, LINE_SIZE);
}
+ stringBuilder.append(line);
+ stringBuilder.append(NEW_LINE);
line = bufferReader.readLine();
}
FileWriter writer = new FileWriter(dataFile);
@@ -374,119 +378,220 @@
}
}
- /* When delimiters are present in the given line. */
- private static String whenDelimiterIsPresent(String line, int lineSize) {
- StringBuilder stringBuilder = new StringBuilder();
- String append;
- if (line.length() > lineSize) {
- String[] strArray = line.split(Pattern.quote(PERIOD));
- stringBuilder = updateString(strArray, stringBuilder, PERIOD, lineSize);
- } else {
- append = line + NEW_LINE;
- stringBuilder.append(append);
+ /**
+ * Resolves validation of line length by modifying the string.
+ *
+ * @param line current line string
+ * @param lineSize line size for change
+ * @return modified line string
+ */
+ private static String processModifications(String line, int lineSize) {
+ int period = getArrayLength(line, PERIOD);
+ int space = getArrayLength(line, SPACE);
+ if (period > space) {
+ return merge(getForPeriod(line), PERIOD, lineSize);
}
- String[] strArray = stringBuilder.toString().split(NEW_LINE);
- StringBuilder tempBuilder = new StringBuilder();
- for (String str : strArray) {
- if (str.length() > SUB_LINE_SIZE) {
- if (line.contains(PERIOD) && !line.contains(PERIOD + HASH + OPEN_PARENTHESIS)) {
- String[] strArr = str.split(Pattern.quote(PERIOD));
- tempBuilder = updateString(strArr, tempBuilder, PERIOD, SUB_LINE_SIZE);
- } else if (str.contains(SPACE)) {
- tempBuilder.append(whenSpaceIsPresent(str, SUB_LINE_SIZE));
- }
- } else {
- append = str + NEW_LINE;
- tempBuilder.append(append);
- }
- }
- return tempBuilder.toString();
-
+ return merge(getForSpace(line), SPACE, lineSize);
}
- /* When spaces are present in the given line. */
- private static String whenSpaceIsPresent(String line, int lineSize) {
- StringBuilder stringBuilder = new StringBuilder();
- String append;
- if (line.length() > lineSize) {
- String[] strArray = line.split(SPACE);
- stringBuilder = updateString(strArray, stringBuilder, SPACE, lineSize);
- } else {
- append = line + NEW_LINE;
- stringBuilder.append(append);
- }
-
- String[] strArray = stringBuilder.toString().split(NEW_LINE);
- StringBuilder tempBuilder = new StringBuilder();
- for (String str : strArray) {
- if (str.length() > LINE_SIZE) {
- if (str.contains(SPACE)) {
- String[] strArr = str.split(SPACE);
- tempBuilder = updateString(strArr, tempBuilder, SPACE, SUB_LINE_SIZE);
+ /**
+ * Returns count of pattern in line.
+ *
+ * @param line line string
+ * @param pattern pattern followed in line
+ * @return count of pattern in line
+ */
+ private static int getArrayLength(String line, String pattern) {
+ String[] array = line.split(Pattern.quote(pattern));
+ int len = array.length;
+ if (pattern.equals(SPACE)) {
+ for (String str : array) {
+ if (str.equals(EMPTY_STRING)) {
+ len--;
}
- } else {
- append = str + NEW_LINE;
- tempBuilder.append(append);
}
}
- return tempBuilder.toString();
+ return len - 1;
}
- /* Updates the given line with the given size conditions. */
- private static StringBuilder updateString(String[] strArray, StringBuilder stringBuilder, String string,
- int lineSize) {
+ /**
+ * Returns array list of string in case of period.
+ *
+ * @param line line string
+ * @return array list of string in case of period
+ */
+ private static ArrayList<String> getForPeriod(String line) {
+ String[] array = line.split(Pattern.quote(PERIOD));
+ return getSplitArray(array, PERIOD);
+ }
- StringBuilder tempBuilder = new StringBuilder();
+ /**
+ * Returns array list of string in case of space.
+ *
+ * @param line line string
+ * @return array list of string in case of space
+ */
+ private static ArrayList<String> getForSpace(String line) {
+ String[] array = line.split(SPACE);
+ return getSplitArray(array, SPACE);
+ }
+
+ /**
+ * Merges strings to form a new string.
+ *
+ * @param list list of strings
+ * @param pattern pattern
+ * @param lineSize line size
+ * @return merged string
+ */
+ private static String merge(ArrayList<String> list, String pattern, int lineSize) {
+ StringBuilder builder = new StringBuilder();
+ StringBuilder fine = new StringBuilder();
String append;
- for (String str : strArray) {
- if (strArray[strArray.length - 1].contains(OPEN_CURLY_BRACKET)) {
- if (str.equals(strArray[strArray.length - 2])
- && !str.equals(strArray[0])
- && tempBuilder.length() < SUB_LINE_SIZE) {
- String tempString = stringBuilder.toString();
- stringBuilder.delete(ZERO, stringBuilder.length());
- tempString = trimAtLast(tempString, string);
- stringBuilder.append(tempString);
- if (string.equals(PERIOD)) {
- append = NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string;
- } else {
- append = NEW_LINE + TWELVE_SPACE_INDENTATION + str + string;
- }
- stringBuilder.append(append);
- append = EMPTY_STRING;
- tempBuilder.delete(ZERO, tempBuilder.length());
- tempBuilder.append(TWELVE_SPACE_INDENTATION);
- } else {
- append = str + string;
- tempBuilder.append(append);
+ String pre;
+ String present = EMPTY_STRING;
+ //Add one blank string in list to handle border limit cases.
+ list.add(EMPTY_STRING);
+ Iterator<String> listIt = list.iterator();
+ ArrayList<String> arrayList = new ArrayList<>();
+ int length;
+ StringBuilder spaces = new StringBuilder();
+ while (listIt.hasNext()) {
+ pre = present;
+ present = listIt.next();
+ //check is present string is more than 80 char.
+ if (present.length() > SUB_SIZE) {
+ int period = getArrayLength(present, PERIOD);
+ int space = getArrayLength(present, SPACE);
+ if (period > space) {
+ // in such case present string should be resolved.
+ present = processModifications(present, SUB_SIZE);
+ builder.append(present);
}
- } else {
- append = str + string;
- tempBuilder.append(append);
}
- if (tempBuilder.length() > lineSize) {
- String tempString = stringBuilder.toString();
- stringBuilder.delete(ZERO, stringBuilder.length());
- tempString = trimAtLast(tempString, string);
- stringBuilder.append(tempString);
- if (string.equals(PERIOD)) {
- append = NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string;
- } else {
- append = NEW_LINE + TWELVE_SPACE_INDENTATION + str + string;
+ length = builder.length();
+ //If length of builder is less than the given length then append
+ // it to builder.
+ if (length <= lineSize) {
+ //fill the space builder to provide proper indentation.
+ if (present.equals(EMPTY_STRING)) {
+ spaces.append(SPACE);
}
- stringBuilder.append(append);
- tempBuilder.delete(ZERO, tempBuilder.length());
- tempBuilder.append(TWELVE_SPACE_INDENTATION);
+ //append to builder
+ builder.append(present);
+ builder.append(pattern);
+ fine.append(pre);
+ //do not append pattern in case of empty strings.
+ if (!pre.equals(EMPTY_STRING)) {
+ fine.append(pattern);
+ }
} else {
- stringBuilder.append(append);
+ // now the length is more than given size so trim the pattern
+ // for the string and add it to list,
+ fine = getReplacedString(fine, pattern);
+ arrayList.add(fine.toString());
+ // clear all.
+ builder.delete(0, length);
+ fine.delete(0, fine.length());
+ // append indentation
+ if (pattern.contains(PERIOD)) {
+ append = NEW_LINE + spaces +
+ TWELVE_SPACE_INDENTATION +
+ PERIOD;
+ } else {
+ append = NEW_LINE + spaces + TWELVE_SPACE_INDENTATION;
+ }
+ // builder needs to move one step forward to fine builder so
+ // append present and pre strings to builder with pattern.
+ builder.append(append);
+ builder.append(pre);
+ builder.append(pattern);
+ builder.append(present);
+ builder.append(pattern);
+ fine.append(append);
+ fine.append(pre);
+ if (!pre.equals(EMPTY_STRING)) {
+ fine.append(pattern);
+ }
}
}
- String tempString = stringBuilder.toString();
- tempString = trimAtLast(tempString, string);
- stringBuilder.delete(ZERO, stringBuilder.length());
- append = tempString + NEW_LINE;
- stringBuilder.append(append);
- return stringBuilder;
+
+ builder = getReplacedString(builder, pattern);
+
+ //need to remove extra string added from the builder.
+ if (builder.toString().lastIndexOf(pattern) == builder.length() - 1) {
+ builder = getReplacedString(builder, pattern);
+ }
+ arrayList.add(builder.toString());
+ fine.delete(0, fine.length());
+ for (String str : arrayList) {
+ fine.append(str);
+ }
+ //No need to append extra spaces.
+ if (pattern.equals(PERIOD)) {
+ return fine.toString();
+ }
+ return spaces + fine.toString();
+ }
+
+ /**
+ * Trims extra pattern strings for builder string.
+ *
+ * @param builder builder
+ * @param pattern pattern
+ * @return modified string
+ */
+ private static StringBuilder getReplacedString(StringBuilder builder, String
+ pattern) {
+ String temp = builder.toString();
+ temp = trimAtLast(temp, pattern);
+ int length = builder.length();
+ builder.delete(0, length);
+ builder.append(temp);
+ return builder;
+ }
+
+ /**
+ * Creates array list to process line string modification.
+ *
+ * @param array array of strings
+ * @param pattern pattern
+ * @return list to process line string modification
+ */
+ private static ArrayList<String> getSplitArray(String[] array, String pattern) {
+ ArrayList<String> newArray = new ArrayList<>();
+ int count = 0;
+ String temp;
+ for (String str : array) {
+ if (!str.contains(OPEN_CURLY_BRACKET)) {
+ if (str.length() > SUB_LINE_SIZE) {
+ count = getSplitString(str, newArray, count);
+ } else {
+ newArray.add(str);
+ count++;
+ }
+ } else {
+ if (newArray.isEmpty()) {
+ newArray.add(str);
+ } else {
+ temp = newArray.get(count - 1);
+ newArray.remove(count - 1);
+ newArray.add(count - 1, temp + pattern + str);
+ }
+ }
+ }
+
+ return newArray;
+ }
+
+ private static int getSplitString(String str,
+ ArrayList<String> newArray, int count) {
+ String[] array = str.split(SPACE);
+ for (String st : array) {
+ newArray.add(st + SPACE);
+ count++;
+ }
+ return count;
}
/**
@@ -697,8 +802,8 @@
HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
}
}
- yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
- String[] strArray = yangIdentifier.split(COLAN);
+ yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLON);
+ String[] strArray = yangIdentifier.split(COLON);
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<>();
stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
@@ -720,8 +825,9 @@
prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
}
if (prefixForIdentifier != null) {
- prefixForIdentifier = prefixForIdentifier.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
- String[] strArray = prefixForIdentifier.split(COLAN);
+ prefixForIdentifier = prefixForIdentifier.replaceAll
+ (REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
+ String[] strArray = prefixForIdentifier.split(COLON);
try {
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<>();
@@ -749,7 +855,7 @@
*/
public static void removeEmptyDirectory(String path) {
int index;
- while (path != null && !path.equals("")) {
+ while (path != null && !path.isEmpty()) {
if (!removeDirectory(path)) {
break;
} else {
@@ -767,7 +873,7 @@
if (files != null && files.length == 0) {
isDeleted = dir.delete();
} else if (files != null && files.length == 1) {
- if (files[0].getName().equals("package-info.java")
+ if ("package-info.java".equals(files[0].getName())
|| files[0].getName().endsWith("-temp")) {
isDeleted = dir.delete();
}
@@ -775,5 +881,4 @@
}
return isDeleted;
}
-
}