[ONOS-5058][ONOS-4796][ONOS-4893]compiler annotation implementation + defect fix
Change-Id: Ie317409d9ab1d36e626433558b2d51f26daaac82
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
index 1be5cac..c97faa4 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/ResolvableType.java
@@ -54,5 +54,10 @@
/**
* Identifies the augment.
*/
- YANG_AUGMENT
+ YANG_AUGMENT,
+
+ /**
+ * Identifies the compiler annotations.
+ */
+ YANG_COMPILER_ANNOTATION
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
index 80ea6c6..d987ad4 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppDataStructure.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
+import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
@@ -25,7 +26,10 @@
/**
* Represents data model node to maintain information defined in YANG app-data-structure.
*/
-public class YangAppDataStructure implements Parsable {
+public class YangAppDataStructure
+ implements Parsable, Serializable {
+
+ private static final long serialVersionUID = 806201602L;
/**
* Data structure information.
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtendedName.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtended.java
similarity index 93%
rename from datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtendedName.java
rename to datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtended.java
index 2ab743e..5423361 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtendedName.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangAppExtended.java
@@ -16,6 +16,8 @@
package org.onosproject.yangutils.datamodel;
+import java.io.Serializable;
+
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
@@ -23,8 +25,10 @@
/**
* Represents data model node to maintain information defined in YANG extended name.
*/
-public class YangAppExtendedName implements Parsable {
+public class YangAppExtended
+ implements Parsable, Serializable {
+ private static final long serialVersionUID = 806201602L;
/**
* App extended name information.
*/
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCompilerAnnotation.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCompilerAnnotation.java
index 4d0c2ce..4099f47 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCompilerAnnotation.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangCompilerAnnotation.java
@@ -16,14 +16,21 @@
package org.onosproject.yangutils.datamodel;
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG compiler-annotation.
*/
-public class YangCompilerAnnotation implements Parsable {
+public class YangCompilerAnnotation
+ implements Parsable, YangXPathResolver, Resolvable, Serializable {
+
+ private static final long serialVersionUID = 806201602L;
/**
* App data structure information.
@@ -33,7 +40,7 @@
/**
* App extended name information.
*/
- private YangAppExtendedName yangAppExtendedName;
+ private YangAppExtended yangAppExtended;
/**
* Prefix of compiler-annotation.
@@ -46,6 +53,16 @@
private String path;
/**
+ * Path of compiler-annotation.
+ */
+ List<YangAtomicPath> atomicPathList = new LinkedList<>();
+
+ /**
+ * Resolution status.
+ */
+ private ResolvableStatus resolvableStatus;
+
+ /**
* Returns the YANG app data structure information.
*
* @return the YANG app data structure information
@@ -104,8 +121,8 @@
*
* @return the YANG app extended name information
*/
- public YangAppExtendedName getYangAppExtendedName() {
- return yangAppExtendedName;
+ public YangAppExtended getYangAppExtendedName() {
+ return yangAppExtended;
}
/**
@@ -113,8 +130,26 @@
*
* @param yangAppExtendedName the YANG app extended name to set
*/
- public void setYangAppExtendedName(YangAppExtendedName yangAppExtendedName) {
- this.yangAppExtendedName = yangAppExtendedName;
+ public void setYangAppExtendedName(YangAppExtended yangAppExtendedName) {
+ this.yangAppExtended = yangAppExtendedName;
+ }
+
+ /**
+ * Returns the list of atomic path.
+ *
+ * @return the list of atomic path
+ */
+ public List<YangAtomicPath> getAtomicPathList() {
+ return atomicPathList;
+ }
+
+ /**
+ * Sets the atomic path.
+ *
+ * @param atomicPathList the atomic path list to set
+ */
+ public void setAtomicPathList(List<YangAtomicPath> atomicPathList) {
+ this.atomicPathList = atomicPathList;
}
@Override
@@ -131,4 +166,20 @@
public void validateDataOnExit() throws DataModelException {
// TODO : to be implemented
}
+
+ @Override
+ public ResolvableStatus getResolvableStatus() {
+ return resolvableStatus;
+ }
+
+ @Override
+ public void setResolvableStatus(ResolvableStatus resolvableStatus) {
+ this.resolvableStatus = resolvableStatus;
+ }
+
+ @Override
+ public Object resolve()
+ throws DataModelException {
+ return null;
+ }
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
index 785d460..609f4ee 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDataStructure.java
@@ -21,7 +21,7 @@
*/
public enum YangDataStructure {
- MAP,
+ QUEUE,
LIST,
@@ -33,7 +33,7 @@
* @param name data structure name from YANG file.
* @return YANG data structure for corresponding data structure name.
*/
- public static YangDataStructure getType(String name) {
+ public static YangDataStructure getDataStructureType(String name) {
name = name.replace("\"", "");
for (YangDataStructure dataStructure : values()) {
if (dataStructure.name().toLowerCase().equals(name)) {
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
index dee1c98..863d03c 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -386,9 +386,8 @@
*/
public ResolvableStatus resolveTypeDerivedInfo(YangType<?> baseType)
throws DataModelException {
- /*
- * Check whether the referred typedef is resolved.
- */
+
+ //Check whether the referred typedef is resolved.
if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED && baseType.getResolvableStatus() != RESOLVED) {
throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafRef.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafRef.java
index 104d701..e29a84f 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafRef.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafRef.java
@@ -379,9 +379,8 @@
if (baseType.getDataType() == YangDataTypes.LEAFREF) {
YangLeafRef referredLeafRefInfo = (YangLeafRef) (yangLeaf.getDataType().getDataTypeExtendedInfo());
- /*
- * Check whether the referred typedef is resolved.
- */
+
+ //Check whether the referred typedef is resolved.
if (referredLeafRefInfo.getResolvableStatus() != INTRA_FILE_RESOLVED
&& referredLeafRefInfo.getResolvableStatus() != RESOLVED) {
throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
@@ -406,9 +405,8 @@
}
setEffectiveDataType(referredLeafRefInfo.getEffectiveDataType());
} else if (baseType.getDataType() == YangDataTypes.DERIVED) {
- /*
- * Check whether the referred typedef is resolved.
- */
+
+ // Check whether the referred typedef is resolved.
if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED
&& baseType.getResolvableStatus() != RESOLVED) {
throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
@@ -441,9 +439,8 @@
if (baseType.getDataType() == YangDataTypes.LEAFREF) {
YangLeafRef referredLeafRefInfo = (YangLeafRef) yangLeafList.getDataType().getDataTypeExtendedInfo();
- /*
- * Check whether the referred typedef is resolved.
- */
+
+ //Check whether the referred typedef is resolved.
if (referredLeafRefInfo.getResolvableStatus() != INTRA_FILE_RESOLVED
&& referredLeafRefInfo.getResolvableStatus() != RESOLVED) {
throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
@@ -468,9 +465,8 @@
}
setEffectiveDataType(referredLeafRefInfo.getEffectiveDataType());
} else if (baseType.getDataType() == YangDataTypes.DERIVED) {
- /*
- * Check whether the referred typedef is resolved.
- */
+
+ //Check whether the referred typedef is resolved.
if (baseType.getResolvableStatus() != INTRA_FILE_RESOLVED
&& baseType.getResolvableStatus() != RESOLVED) {
throw new DataModelException("Linker Error: Referred typedef is not resolved for type.");
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
index e2bd8b5..9571c90 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
@@ -165,20 +165,20 @@
/**
* Reference RFC 6020.
- * <p>
+ *
* The "min-elements" statement, which is optional, takes as an argument a
* non-negative integer that puts a constraint on valid list entries. A
* valid leaf-list or list MUST have at least min-elements entries.
- * <p>
+ *
* If no "min-elements" statement is present, it defaults to zero.
- * <p>
+ *
* The behavior of the constraint depends on the type of the leaf-list's or
* list's closest ancestor node in the schema tree that is not a non-
* presence container:
- * <p>
+ *
* o If this ancestor is a case node, the constraint is enforced if any
* other node from the case exists.
- * <p>
+ *
* o Otherwise, it is enforced if the ancestor node exists.
*/
private YangMinElement minElements;
@@ -209,6 +209,11 @@
private List<YangIfFeature> ifFeatureList;
/**
+ * Compiler Annotation.
+ */
+ private transient YangCompilerAnnotation compilerAnnotation;
+
+ /**
* Creates a YANG list object.
*/
public YangList() {
@@ -218,6 +223,24 @@
}
/**
+ * Returns the compiler annotation.
+ *
+ * @return the compiler annotation
+ */
+ public YangCompilerAnnotation getCompilerAnnotation() {
+ return compilerAnnotation;
+ }
+
+ /**
+ * Sets the compiler annotation.
+ *
+ * @param compilerAnnotation the compiler annotation to set
+ */
+ public void setCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
+ this.compilerAnnotation = compilerAnnotation;
+ }
+
+ /**
* Returns the when.
*
* @return the when
@@ -549,7 +572,7 @@
setDefaultConfigValueToChild(leaves, leafLists);
validateConfig(leaves, leafLists);
- /* A list must have atleast one key leaf if config is true */
+ //A list must have atleast one key leaf if config is true
if (isConfig && (keys == null || leaves == null) && !isUsesPresentInList()
&& !isListPresentInGrouping()) {
throw new DataModelException("A list must have atleast one key leaf if config is true;");
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index c2df52f..5d246a4 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -85,7 +85,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
@@ -96,7 +96,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
@@ -136,7 +136,7 @@
/**
* Reference:RFC 6020.
- * <p>
+ *
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
@@ -233,7 +233,7 @@
/**
* Compiler annotation list.
*/
- private List<YangCompilerAnnotation> compilerAnnotationList;
+ private List<YangResolutionInfo> compilerAnnotationList;
/**
* Extension list.
@@ -569,33 +569,6 @@
}
/**
- * Adds compiler annotation in compiler-annotation list.
- *
- * @param compilerAnnotation the compiler-annotation to be added
- */
- public void addCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
- getCompilerAnnotationList().add(compilerAnnotation);
- }
-
- /**
- * Returns the compiler annotation list.
- *
- * @return the compiler annotation list
- */
- public List<YangCompilerAnnotation> getCompilerAnnotationList() {
- return compilerAnnotationList;
- }
-
- /**
- * Sets the compiler-annotation list.
- *
- * @param compilerAnnotationList the list of compiler-annotation
- */
- public void setCompilerAnnotationList(List<YangCompilerAnnotation> compilerAnnotationList) {
- this.compilerAnnotationList = compilerAnnotationList;
- }
-
- /**
* Adds extension in extension list.
*
* @param extension the extension to be added
@@ -687,8 +660,10 @@
return leafRefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
- } else {
+ } else if (type == ResolvableType.YANG_IDENTITYREF) {
return identityRefResolutionList;
+ } else {
+ return compilerAnnotationList;
}
}
@@ -709,6 +684,8 @@
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityRefResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList.add(resolutionInfo);
}
}
@@ -729,6 +706,8 @@
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityRefResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList = resolutionList;
}
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
index d501b0b..ced0910 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -16,7 +16,6 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
@@ -248,15 +247,12 @@
YangNode curNode;
curNode = getChild();
- /*
- * Get the predecessor child of new child
- */
+ // Get the predecessor child of new child
while (curNode.getNextSibling() != null) {
-
curNode = curNode.getNextSibling();
}
- /* If the new node needs to be the last child */
+ // If the new node needs to be the last child
if (curNode.getNextSibling() == null) {
curNode.setNextSibling(newChild);
newChild.setPreviousSibling(curNode);
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
index a58eb7d..717ea1a 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSubModule.java
@@ -226,7 +226,7 @@
/**
* Compiler annotation list.
*/
- private List<YangCompilerAnnotation> compilerAnnotationList;
+ private List<YangResolutionInfo> compilerAnnotationList;
/**
* extension list.
@@ -256,6 +256,7 @@
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
extensionList = new LinkedList<>();
+ compilerAnnotationList = new LinkedList<>();
}
/**
@@ -595,8 +596,10 @@
return leafRefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
- } else {
+ } else if (type == ResolvableType.YANG_IDENTITYREF) {
return identityRefResolutionList;
+ } else {
+ return compilerAnnotationList;
}
}
@@ -617,6 +620,8 @@
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityRefResolutionList.add(resolutionInfo);
+ } else if (type == ResolvableType.YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList.add(resolutionInfo);
}
}
@@ -637,6 +642,8 @@
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityRefResolutionList = resolutionList;
+ } else if (type == ResolvableType.YANG_COMPILER_ANNOTATION) {
+ compilerAnnotationList = resolutionList;
}
}
@@ -698,34 +705,6 @@
}
/**
- * Adds compiler annotation in compiler annotation list.
- *
- * @param compilerAnnotation the compiler annotation to be added
- */
- public void addCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
- getCompilerAnnotationList().add(compilerAnnotation);
- }
-
- /**
- * Returns the compiler annotation list.
- *
- * @return the compiler annotation list
- */
- public List<YangCompilerAnnotation> getCompilerAnnotationList() {
- return compilerAnnotationList;
- }
-
- /**
- * Sets the compiler annotation list.
- *
- * @param compilerAnnotationList the list of compiler annotation
- */
- public void setCompilerAnnotationList(List<YangCompilerAnnotation> compilerAnnotationList) {
- this.compilerAnnotationList = compilerAnnotationList;
- }
-
-
- /**
* Adds extension in extension list.
*
* @param extension the extension to be added
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 1da8a1a..29896ef 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -37,6 +37,7 @@
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangBase;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfoImpl;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
@@ -210,6 +211,10 @@
resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_BASE);
} else if (resolutionInfo.getEntityToResolveInfo().getEntityToResolve() instanceof YangIdentityRef) {
resolutionNode.addToResolutionList(resolutionInfo, ResolvableType.YANG_IDENTITYREF);
+ } else if (resolutionInfo.getEntityToResolveInfo()
+ .getEntityToResolve() instanceof YangCompilerAnnotation) {
+ resolutionNode.addToResolutionList(resolutionInfo,
+ ResolvableType.YANG_COMPILER_ANNOTATION);
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 754801b..815f220 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -181,6 +181,8 @@
.resolveInterFileLinking(ResolvableType.YANG_IDENTITYREF);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
+ ((YangReferenceResolver) yangNode)
+ .resolveInterFileLinking(ResolvableType.YANG_COMPILER_ANNOTATION);
} catch (DataModelException e) {
String errorInfo = "Error in file: " + yangNode.getName() + " at line: "
+ e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE + e.getMessage();
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 0cd359b..7df0de2 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
@@ -21,7 +21,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
-
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.TraversalType;
@@ -29,6 +28,7 @@
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
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;
@@ -44,6 +44,7 @@
import org.onosproject.yangutils.datamodel.YangLeaf;
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;
@@ -308,9 +309,7 @@
YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType.getDataTypeExtendedInfo();
- /*
- * If the derived types referred type is not leafref/identityref return
- */
+ // If the derived types referred type is not leafref/identityref return
if ((derivedInfo.getEffectiveBuiltInType() != YangDataTypes.LEAFREF) &&
(derivedInfo.getEffectiveBuiltInType() != YangDataTypes.IDENTITYREF)) {
return;
@@ -511,9 +510,7 @@
return;
}
- /*
- * In case prefix is not present it's a candidate for inter-file resolution via include list.
- */
+ //In case prefix is not present it's a candidate for inter-file resolution via include list.
if (getRefPrefix() == null) {
((Resolvable) getCurrentEntityToResolveFromStack()).setResolvableStatus(INTRA_FILE_RESOLVED);
}
@@ -771,9 +768,8 @@
if ((getCurrentEntityToResolveFromStack() instanceof YangIdentityRef) ||
(getCurrentEntityToResolveFromStack() instanceof YangBase)) {
- /*
- * Check if name of node name matches with the current reference node.
- */
+
+ //Check if name of node name matches with the current reference node.
return currentReferredNode.getName().contentEquals(nameOfIdentityRefBase);
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than identityref");
@@ -967,9 +963,8 @@
private void addUnresolvedRecursiveReferenceToStack(YangNode referredNode)
throws DataModelException {
if (getCurrentEntityToResolveFromStack() instanceof YangType) {
- /*
- * Checks if typedef type is derived
- */
+
+ //Checks if typedef type is derived
if (((YangTypeDef) referredNode).getTypeDefBaseType().getDataType() == YangDataTypes.DERIVED) {
YangEntityToResolveInfoImpl<YangType<?>> unResolvedEntityInfo = new YangEntityToResolveInfoImpl<>();
@@ -992,9 +987,8 @@
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses");
} else if ((getCurrentEntityToResolveFromStack() instanceof YangBase) ||
(getCurrentEntityToResolveFromStack() instanceof YangIdentityRef)) {
- /*
- * Search if the identity has any un resolved base, if so return true, else return false.
- */
+
+ //Search if the identity has any un resolved base, if so return true, else return false.
addUnResolvedBaseToStack(referredNode);
} else {
throw new DataModelException("Data Model Exception: Entity to resolved is other than type/uses/" +
@@ -1009,9 +1003,7 @@
*/
private void addUnResolvedUsesToStack(YangNode node) {
- /**
- * Search the grouping node's children for presence of uses node.
- */
+ //Search the grouping node's children for presence of uses node.
TraversalType curTraversal = ROOT;
YangNode curNode = node.getChild();
while (curNode != null) {
@@ -1222,7 +1214,7 @@
YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
if (entityToResolve instanceof YangAugment) {
- YangNode targetNode;
+ YangNode targetNode = null;
YangAugment augment = (YangAugment) entityToResolve;
targetNode = xPathLinker.processAugmentXpathLinking(augment.getTargetNode(),
(YangNode) root);
@@ -1240,6 +1232,25 @@
} else {
throw new LinkerException("Failed to link " + augment.getName());
}
+ } else if (entityToResolve instanceof YangCompilerAnnotation) {
+ YangNode targetNode;
+ YangCompilerAnnotation ca = (YangCompilerAnnotation) entityToResolve;
+
+ targetNode = xPathLinker.processAugmentXpathLinking(ca.getAtomicPathList(),
+ (YangNode) root);
+ if (targetNode != null) {
+ if (targetNode instanceof YangList) {
+ ((YangList) targetNode).setCompilerAnnotation(
+ (YangCompilerAnnotation) entityToResolve);
+ Resolvable resolvable = (Resolvable) entityToResolve;
+ resolvable.setResolvableStatus(RESOLVED);
+ } else {
+ throw new LinkerException("Invalid target node type " + targetNode.getNodeType() + " for compiler" +
+ " annotation " + ca.getPath());
+ }
+ } else {
+ throw new LinkerException("Failed to link compiler annotation " + ca.getPath());
+ }
} else if (entityToResolve instanceof YangLeafRef) {
YangLeafRef leafRef = (YangLeafRef) entityToResolve;
Object target = xPathLinker.processLeafRefXpathLinking(leafRef.getAtomicPath(),
@@ -1613,9 +1624,8 @@
*/
private boolean resolveWithImport()
throws DataModelException {
- /*
- * Run through import list to find the referred typedef/grouping.
- */
+
+ // Run through import list to find the referred typedef/grouping.
for (YangImport yangImport : getCurReferenceResolver().getImportList()) {
/*
* Match the prefix attached to entity under resolution with the
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
index e6628b3..c541bda 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
@@ -24,7 +24,7 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import static org.onosproject.yangutils.datamodel.YangDataStructure.getType;
+import static org.onosproject.yangutils.datamodel.YangDataStructure.getDataStructureType;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.APP_DATA_STRUCTURE;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
@@ -75,7 +75,7 @@
checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", ENTRY);
String prefix = getValidPrefix(ctx.APP_DATA_STRUCTURE().getText(), APP_DATA_STRUCTURE, ctx);
- YangDataStructure dataStructure = getType(ctx.appDataStructure().getText());
+ YangDataStructure dataStructure = getDataStructureType(ctx.appDataStructure().getText());
YangAppDataStructure appDataStructure = new YangAppDataStructure();
appDataStructure.setPrefix(prefix);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
index 3ec31c7..b72b95c 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
@@ -16,7 +16,7 @@
package org.onosproject.yangutils.parser.impl.listeners;
-import org.onosproject.yangutils.datamodel.YangAppExtendedName;
+import org.onosproject.yangutils.datamodel.YangAppExtended;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -67,7 +67,7 @@
checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_EXTENDED_NAME_DATA, ctx.extendedName().getText(), ENTRY);
String prefix = getValidPrefix(ctx.APP_EXTENDED().getText(), APP_EXTENDED_NAME_DATA, ctx);
- YangAppExtendedName extendedName = new YangAppExtendedName();
+ YangAppExtended extendedName = new YangAppExtended();
extendedName.setPrefix(prefix);
extendedName.setYangAppExtendedName(removeQuotesAndHandleConcat(ctx.extendedName().getText()));
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
index c89e99a..8a5627f 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
@@ -16,21 +16,30 @@
package org.onosproject.yangutils.parser.impl.listeners;
+import java.util.List;
+import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.COMPILER_ANNOTATION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
@@ -81,20 +90,26 @@
compilerAnnotation.setPrefix(prefix);
compilerAnnotation.setPath(removeQuotesAndHandleConcat(ctx.string().getText()));
+ // Validate augment argument string
+ List<YangAtomicPath> targetNodes = getValidAbsoluteSchemaNodeId(ctx.string().getText(),
+ COMPILER_ANNOTATION_DATA, ctx);
+
+ compilerAnnotation.setAtomicPathList(targetNodes);
+
+ int line = ctx.getStart().getLine();
+ int charPositionInLine = ctx.getStart().getCharPositionInLine();
+
Parsable curData = listener.getParsedDataStack().peek();
- switch (curData.getYangConstructType()) {
- case MODULE_DATA:
- YangModule module = ((YangModule) curData);
- module.addCompilerAnnotation(compilerAnnotation);
- break;
- case SUB_MODULE_DATA:
- YangSubModule subModule = ((YangSubModule) curData);
- subModule.addCompilerAnnotation(compilerAnnotation);
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, COMPILER_ANNOTATION_DATA,
- ctx.string().getText(), ENTRY));
+ if (!(curData instanceof YangModule || curData instanceof YangSubModule)) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, COMPILER_ANNOTATION_DATA,
+ ctx.string().getText(), ENTRY));
}
+
+ // Add resolution information to the list
+ YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangCompilerAnnotation>(
+ compilerAnnotation, (YangNode) curData, line, charPositionInLine);
+ addToResolutionList(resolutionInfo, ctx);
+
listener.getParsedDataStack().push(compilerAnnotation);
}
@@ -115,4 +130,21 @@
}
listener.getParsedDataStack().pop();
}
+
+ /**
+ * Adds to resolution list.
+ *
+ * @param resolutionInfo resolution information.
+ * @param ctx context object of the grammar rule
+ */
+ private static void addToResolutionList(YangResolutionInfoImpl<YangCompilerAnnotation> resolutionInfo,
+ GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
+
+ try {
+ addResolutionInfo(resolutionInfo);
+ } catch (DataModelException e) {
+ throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
+ COMPILER_ANNOTATION_DATA, ctx.COMPILER_ANNOTATION().getText(), ENTRY, e.getMessage()));
+ }
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
index 1891595..270c9c1 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
@@ -177,8 +177,11 @@
yangList.validateDataOnExit();
validateUniqueInList(yangList, ctx);
} catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- LIST_DATA, ctx.identifier().getText(), EXIT, e.getMessage()));
+ ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
+ UNHANDLED_PARSED_DATA, LIST_DATA, ctx.identifier().getText(), EXIT, e.getMessage()));
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
}
listener.getParsedDataStack().pop();
} else {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
index 5b50ff9..972d1ef 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
@@ -32,7 +32,9 @@
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MODULE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
+ .constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CHILD;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
@@ -121,6 +123,14 @@
((YangModule) tmpNode).setRevision(currentRevision);
}
+ YangModule module = (YangModule) tmpNode;
+ if (module.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION) != null
+ && module.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION).size() != 0
+ && module.getChild() != null) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, MODULE_DATA,
+ ctx.identifier().getText(), EXIT));
+ }
+
try {
((YangReferenceResolver) listener.getParsedDataStack()
.peek()).resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
index d2c4f48..f9c4a27 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
@@ -29,10 +29,13 @@
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MODULE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.SUB_MODULE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
+ .constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CHILD;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
@@ -126,6 +129,14 @@
((YangSubModule) tmpNode).setRevision(currentRevision);
}
+ YangSubModule subModule = (YangSubModule) tmpNode;
+ if (subModule.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION) != null
+ && subModule.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION).size() != 0
+ && subModule.getChild() != null) {
+ throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, MODULE_DATA,
+ ctx.identifier().getText(), EXIT));
+ }
+
try {
((YangReferenceResolver) listener.getParsedDataStack().peek())
.resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
index 254ea4a..ffa7b21 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
@@ -16,6 +16,7 @@
package org.onosproject.yangutils.translator.tojava;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -54,6 +55,11 @@
private JavaQualifiedTypeInfoTranslator importInfo;
/**
+ * Compiler annotation attribute info.
+ */
+ private YangCompilerAnnotation compilerAnnotation;
+
+ /**
* If conflict occurs.
*/
private boolean isIntConflict;
@@ -184,7 +190,25 @@
}
/**
- * Returns true if conflict between int and uInt.
+ * Returns the compiler annotation.
+ *
+ * @return compiler annotation info
+ */
+ public YangCompilerAnnotation getCompilerAnnotation() {
+ return compilerAnnotation;
+ }
+
+ /**
+ * Sets the compiler annotation.
+ *
+ * @param compilerAnnotation the compiler annotation to set
+ */
+ public void setCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
+ this.compilerAnnotation = compilerAnnotation;
+ }
+
+ /**
+ * Returns true if conflict between int and uint.
*
* @return true if conflict between int and uInt
*/
@@ -247,4 +271,27 @@
return newAttr;
}
+
+ /**
+ * Returns java attribute info.
+ *
+ * @param importInfo java qualified type info
+ * @param attributeName attribute name
+ * @param attributeType attribute type
+ * @param isQualifiedAccess is the attribute a qualified access
+ * @param isListAttribute is list attribute
+ * @param compilerAnnotation compiler annotation
+ * @return java attribute info.
+ */
+ public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfoTranslator importInfo,
+ String attributeName, YangType<?> attributeType,
+ boolean isQualifiedAccess, boolean isListAttribute,
+ YangCompilerAnnotation compilerAnnotation) {
+ JavaAttributeInfo newAttr = getAttributeInfoForTheData(importInfo, attributeName, attributeType,
+ isQualifiedAccess, isListAttribute);
+
+ newAttr.setCompilerAnnotation(compilerAnnotation);
+
+ return newAttr;
+ }
}
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 aa8b53f..7c82175 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
@@ -41,7 +41,9 @@
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;
/**
@@ -55,6 +57,16 @@
private boolean isListToImport;
/**
+ * Flag to denote if any queue is imported due to compiler annotation.
+ */
+ private boolean isQueueToImport;
+
+ /**
+ * Flag to denote if any set is imported due to compiler annotation.
+ */
+ private boolean isSetToImport;
+
+ /**
* Sorted set of import info, to be used to maintain the set of classes to
* be imported in the generated class.
*/
@@ -86,6 +98,42 @@
}
/**
+ * 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) {
+ isQueueToImport = queueToImport;
+ }
+
+ /**
+ * Sets the status of the set to be imported due to compiler annotations.
+ *
+ * @param setToImport status of set to import
+ */
+ public void setSetToImport(boolean setToImport) {
+ isSetToImport = setToImport;
+ }
+
+ /**
* Returns the set containing the imported class/interface info.
*
* @return the set containing the imported class/interface info
@@ -124,7 +172,7 @@
if (newImportInfo.getClassInfo().contentEquals(className)) {
/*
- * if the current class name is same as the attribute class name,
+ * If the current class name is same as the attribute class name,
* then the attribute must be accessed in a qualified manner.
*/
return true;
@@ -157,7 +205,7 @@
}
/*
- * import is added, so it is a member for non qualified access
+ * Import is added, so it is a member for non qualified access
*/
getImportSet().add(newImportInfo);
return false;
@@ -187,6 +235,14 @@
imports.add(getImportForList());
}
+ if (isQueueToImport()) {
+ imports.add(getImportForQueue());
+ }
+
+ if (isSetToImport()) {
+ imports.add(getImportForSet());
+ }
+
sort(imports);
return imports;
}
@@ -228,6 +284,24 @@
}
/**
+ * Returns import for queue attribute.
+ *
+ * @return import for queue attribute
+ */
+ public String getImportForQueue() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + QUEUE + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import for set attribute.
+ *
+ * @return import for set attribute
+ */
+ public String getImportForSet() {
+ return IMPORT + COLLECTION_IMPORTS + PERIOD + SET + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
* Returns import string for ListenerService class.
*
* @return import string for ListenerService class
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 609a3d2..42c5e59 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
@@ -444,7 +444,7 @@
private void addEventEnum(String notificationName, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventEnumTempFileHandle(),
- getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig, null) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE);
}
@@ -464,17 +464,26 @@
/*Adds getter method for event in event subject class.*/
private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
appendToFile(getEventSubjectGetterTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
- + getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
+ 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)
throws IOException {
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
appendToFile(getEventSubjectSetterTempFileHandle(),
- getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
- + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
+ getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
+ appDataStructure) + getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS)
+ + NEW_LINE);
}
/**
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 58a0e28..a151f03 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
@@ -22,10 +22,11 @@
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
+import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
@@ -447,16 +448,12 @@
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
}
- /*
- * Initialize temp files to generate enum class.
- */
+ //Initialize temp files to generate enum class.
if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
}
- /*
- * Set temporary file handles.
- */
+ //Set temporary file handles
if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
}
@@ -586,10 +583,38 @@
className, fileInfo.getPackage());
}
- if (isListNode) {
+ boolean collectionSetFlag = false;
+ if (curNode instanceof YangList) {
+ YangList yangList = (YangList) curNode;
+ if (yangList.getCompilerAnnotation() != null && yangList.getCompilerAnnotation()
+ .getYangAppDataStructure() != null) {
+ switch (yangList.getCompilerAnnotation().getYangAppDataStructure().getDataStructure()) {
+ case QUEUE: {
+ parentImportData.setQueueToImport(true);
+ collectionSetFlag = true;
+ break;
+ }
+ case SET: {
+ parentImportData.setSetToImport(true);
+ collectionSetFlag = true;
+ break;
+ }
+ default: {
+ // TODO : to be implemented
+ }
+ }
+ }
+ }
+
+ if (isListNode && !(collectionSetFlag)) {
parentImportData.setIfListImported(true);
}
+ if (curNode instanceof YangList) {
+ return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
+ ((YangList) curNode).getCompilerAnnotation());
+ }
+
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
}
@@ -1121,9 +1146,13 @@
getGeneratedJavaFiles()) + NEW_LINE);
}
} else {
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
appendToFile(getGetterImplTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
- + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
+ getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
+ appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
}
}
@@ -1136,7 +1165,7 @@
*/
private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException {
appendToFile(getAddToListInterfaceTempFileHandle(),
- getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
+ getAddToListMethodInterface(attr) + NEW_LINE);
}
@@ -1322,7 +1351,6 @@
*/
public String getTemporaryDataFromFileHandle(File file, String absolutePath)
throws IOException {
-
String path = getTempDirPath(absolutePath);
if (new File(path + file.getName()).exists()) {
return readAppendFile(path + file.getName(), EMPTY_STRING);
@@ -1351,9 +1379,7 @@
* @return attribute string
*/
String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
- /*
- * TODO: check if this utility needs to be called or move to the caller
- */
+ //TODO: check if this utility needs to be called or move to the caller
String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
String attributeAccessType = PRIVATE;
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
@@ -1362,10 +1388,10 @@
if (attr.isQualifiedName()) {
return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
attr.getImportInfo().getClassInfo(),
- attributeName, attr.isListAttr(), attributeAccessType);
+ attributeName, attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
} else {
return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
- attr.isListAttr(), attributeAccessType);
+ attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
}
}
@@ -1392,7 +1418,6 @@
* @param pluginConfig plugin configurations
*/
void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
-
JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator();
YangNode parent = getParentNodeInGenCode(curNode);
if (curNode instanceof YangCase && parent instanceof YangAugment) {
@@ -1618,30 +1643,26 @@
addImportsForAugmentableClass(imports, true, true);
}
createPackage(curNode);
- /*
- * Generate java code.
- */
+
+ //Generate java code.
if ((fileType & INTERFACE_MASK) != 0 || (fileType &
BUILDER_INTERFACE_MASK) != 0) {
- /*
- * Create interface file.
- */
+
+ //Create interface file.
setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
setInterfaceJavaFileHandle(
generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
- /*
- * Create builder interface file.
- */
+
+ //Create builder interface file.
if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
setBuilderInterfaceJavaFileHandle(
getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
setBuilderInterfaceJavaFileHandle(
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
isAttributePresent()));
- /*
- * Append builder interface file to interface file and close it.
- */
+
+ //Append builder interface file to interface file and close it.
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
validateLineLength(getInterfaceJavaFileHandle());
}
@@ -1662,36 +1683,32 @@
addInvocationExceptionImport(imports);
}
sortImports(imports);
- /*
- * Create impl class file.
- */
+
+ //Create impl class file.
setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
setImplClassJavaFileHandle(
generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
- /*
- * Create builder class file.
- */
+
+ //Create builder class file.
if ((fileType & BUILDER_CLASS_MASK) != 0) {
setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
setBuilderClassJavaFileHandle(
generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
isAttributePresent()));
- /*
- * Append impl class to builder class and close it.
- */
+
+ //Append impl class to builder class and close it.
mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
validateLineLength(getImplClassJavaFileHandle());
}
insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
}
- /*
- * Close all the file handles.
- */
+
+ //Close all the file handles.
freeTemporaryResources(false);
}
- /*Adds import for array list.*/
+ //Adds import for array list.
private void addArrayListImport(List<String> imports) {
if (imports.contains(getJavaImportData().getImportForList())) {
imports.add(ARRAY_LIST_IMPORT);
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 29dc4ff..2250a62 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
@@ -18,6 +18,7 @@
import java.util.List;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
@@ -55,7 +56,9 @@
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
+import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SET;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE_ATTR;
@@ -110,11 +113,13 @@
* @param javaAttributeName name of the attribute
* @param isList is list attribute
* @param attributeAccessType attribute access type
+ * @param compilerAnnotation compiler annotation
* @return the textual java code for attribute definition in class
*/
public static String getJavaAttributeDefinition(String javaAttributeTypePkg, String javaAttributeType,
String javaAttributeName, boolean isList,
- String attributeAccessType) {
+ String attributeAccessType,
+ YangCompilerAnnotation compilerAnnotation) {
String attributeDefinition = attributeAccessType + SPACE;
@@ -126,13 +131,43 @@
attributeDefinition = attributeDefinition + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN
+ NEW_LINE;
} else {
- attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
+ if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
+ switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
+ case QUEUE: {
+ attributeDefinition = attributeDefinition + QUEUE + DIAMOND_OPEN_BRACKET;
+ break;
+ }
+ case SET: {
+ attributeDefinition = attributeDefinition + SET + DIAMOND_OPEN_BRACKET;
+ break;
+ }
+ default: {
+ attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
+ }
+ }
+ } else {
+ attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
+ }
+
if (javaAttributeTypePkg != null) {
attributeDefinition = attributeDefinition + javaAttributeTypePkg + PERIOD;
}
- attributeDefinition = attributeDefinition + javaAttributeType + DIAMOND_CLOSE_BRACKET + SPACE
- + javaAttributeName + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
+ attributeDefinition = attributeDefinition + javaAttributeType;
+
+ if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
+ switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
+ default: {
+ attributeDefinition = attributeDefinition + DIAMOND_CLOSE_BRACKET + SPACE
+ + javaAttributeName + SEMI_COLAN + NEW_LINE;
+ }
+ }
+ } else {
+ attributeDefinition = attributeDefinition + DIAMOND_CLOSE_BRACKET + SPACE
+ + javaAttributeName + SPACE + EQUAL + SPACE + NEW + SPACE
+ + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
+ }
+
}
return attributeDefinition;
}
@@ -155,7 +190,7 @@
* @return string for enum's attribute
*/
public static String generateEnumAttributeString(String name, int value, YangPluginConfig pluginConfig) {
- return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig)
+ return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig, null)
+ EIGHT_SPACE_INDENTATION + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
+ value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
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 033a7d7..9d0ca67 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
@@ -936,7 +936,7 @@
insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className)));
// Add a constructor for enum.
- insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig)
+ insertDataIntoJavaFile(file, getJavaDoc(TYPE_CONSTRUCTOR, className, false, pluginConfig, null)
+ getEnumsConstructor(getCapitalCase(className)) + NEW_LINE);
TempJavaEnumerationFragmentFiles enumFragFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
@@ -949,7 +949,7 @@
+ NEW_LINE);
// Add a getter method for enum.
- insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig)
+ insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false, pluginConfig, null)
+ getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
try {
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 cf753f0..a1000ca 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
@@ -538,7 +538,7 @@
throws IOException {
YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig();
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig, null));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
}
@@ -555,7 +555,7 @@
private static void write(File file, String fileName, int genType, JavaDocType javaDocType,
YangPluginConfig pluginConfig)
throws IOException {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig, null));
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
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 372897c..5f00ecc 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
@@ -18,10 +18,10 @@
import java.util.List;
import java.util.Map;
-
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangLeafRef;
@@ -157,11 +157,13 @@
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.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SET;
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;
@@ -238,7 +240,7 @@
* @return method string for builder interface
*/
public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
- return getJavaDoc(BUILD_METHOD, name, false, pluginConfig) + getBuildForInterface(name);
+ return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) + getBuildForInterface(name);
}
/**
@@ -251,16 +253,21 @@
*/
public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
YangPluginConfig pluginConfig) {
-
String returnType = getReturnType(attr);
String attributeName = attr.getAttributeName();
+ String appDataStructure = null;
+ 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);
+ + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
- return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig)
- + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
+ return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
+ + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
/**
@@ -274,7 +281,6 @@
*/
public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
YangPluginConfig pluginConfig) {
-
String attrType = getReturnType(attr);
String attributeName = attr.getAttributeName();
JavaDocGen.JavaDocType type;
@@ -284,8 +290,13 @@
type = SETTER_METHOD;
}
- return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig)
- + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles);
+ String appDataStructure = null;
+ if (attr.getCompilerAnnotation() != null) {
+ appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
+ return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
+ + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
/**
@@ -296,7 +307,7 @@
* @return constructor string
*/
private static String getConstructorString(String name, YangPluginConfig pluginConfig) {
- return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig);
+ return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null);
}
/**
@@ -309,9 +320,8 @@
*/
public static String getDefaultConstructorString(String name, String modifierType,
YangPluginConfig pluginConfig) {
- return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig)
- + getDefaultConstructor(name, modifierType)
- + NEW_LINE;
+ return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null)
+ + getDefaultConstructor(name, modifierType) + NEW_LINE;
}
/**
@@ -347,15 +357,14 @@
* @return getter method for class
*/
public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
-
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
if (!attr.isListAttr()) {
return getGetter(attrQualifiedType, attributeName, generatedJavaFiles);
}
- String listAttr = getListString() + attrQualifiedType + DIAMOND_CLOSE_BRACKET;
- return getGetter(listAttr, attributeName, generatedJavaFiles);
+ String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
+ return getGetter(attrParam, attributeName, generatedJavaFiles);
}
/**
@@ -379,7 +388,6 @@
EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET;
}
-
}
/*Provides string to return for type.*/
@@ -407,7 +415,6 @@
* @return setter method for class
*/
public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
-
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
boolean isTypeNull = false;
@@ -417,8 +424,8 @@
if (!attr.isListAttr()) {
return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false);
}
- String listAttr = getListString() + attrQualifiedType + DIAMOND_CLOSE_BRACKET;
- return getSetter(className, attributeName, listAttr, generatedJavaFiles, isTypeNull, true);
+ String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
+ return getSetter(className, attributeName, attrParam, generatedJavaFiles, isTypeNull, true);
}
/**
@@ -508,15 +515,15 @@
* @param returnType return type of attribute
* @param isList is list attribute
* @param generatedJavaFiles generated java files
+ * @param compilerAnnotation compiler annotation
* @return getter method for interface
*/
static String getGetterForInterface(String yangName, String returnType, boolean isList,
- int generatedJavaFiles) {
-
+ int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
}
- String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET;
+ String listAttr = getListAttribute(returnType, compilerAnnotation);
return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
}
@@ -545,15 +552,17 @@
* @param className name of the java class being generated
* @param isList is list attribute
* @param generatedJavaFiles generated java files
+ * @param compilerAnnotation compiler annotations
* @return setter method for interface
*/
static String getSetterForInterface(String attrName, String attrType, String className,
- boolean isList, int generatedJavaFiles) {
-
+ boolean isList, int generatedJavaFiles,
+ YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
}
- String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+
+ String listAttr = getListAttribute(attrType, compilerAnnotation);
return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
}
@@ -592,7 +601,6 @@
* @return return type
*/
private static String getReturnType(JavaAttributeInfo attr) {
-
String returnType = EMPTY_STRING;
if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
@@ -621,7 +629,6 @@
* @return constructor string
*/
static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) {
-
String javadoc = getConstructorString(yangName, pluginConfig);
String returnType = getCapitalCase(DEFAULT) + yangName;
@@ -644,7 +651,6 @@
*/
public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles,
YangPluginConfig pluginConfig) {
-
String attributeName = attr.getAttributeName();
String constructor;
@@ -675,7 +681,6 @@
*/
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;
@@ -695,7 +700,6 @@
*/
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;
@@ -709,7 +713,6 @@
+ NEW_LINE;
}
method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
-
return method;
}
@@ -1084,7 +1087,7 @@
* @return from string method's open string
*/
static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
- return getJavaDoc(FROM_METHOD, className, false, pluginConfig) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
+ 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;
@@ -1109,7 +1112,6 @@
*/
public static String getFromStringMethod(JavaAttributeInfo attr,
JavaAttributeInfo fromStringAttributeInfo) {
-
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()
@@ -1152,7 +1154,6 @@
*/
private static String getParsedSubString(JavaAttributeInfo attr,
JavaAttributeInfo fromStringAttributeInfo) {
-
String targetDataType = getReturnType(attr);
if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) {
String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType
@@ -1286,7 +1287,6 @@
* @return equals method
*/
public static String getEqualsMethod(JavaAttributeInfo attr) {
-
String attributeName = attr.getAttributeName();
return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
+ attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
@@ -1301,9 +1301,7 @@
* @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
@@ -1320,11 +1318,10 @@
*/
public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
YangPluginConfig pluginConfig) {
-
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
+ getOfMethodString(attrType, generatedJavaClassName);
}
@@ -1336,7 +1333,6 @@
* @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
@@ -1354,11 +1350,9 @@
public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr,
String generatedJavaClassName,
YangPluginConfig pluginConfig) {
-
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
-
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig)
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
+ getTypeConstructorString(attrType, attrName, generatedJavaClassName);
}
@@ -1376,7 +1370,6 @@
public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1, JavaAttributeInfo
attr2, String generatedJavaClassName, YangPluginConfig pluginConfig, ValidatorTypeForUnionTypes type,
boolean addFirst) {
-
String attrType = getReturnType(attr1);
String attrName1 = "";
String attrName2 = "";
@@ -1387,8 +1380,13 @@
attrName2 = attr2.getAttributeName();
}
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig)
- + getTypeConstructorString(attrType, attrName1, attrName2, generatedJavaClassName, type, addFirst);
+ String appDataStructure = null;
+ if (attr1.getCompilerAnnotation() != null) {
+ appDataStructure = attr1.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ }
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig,
+ appDataStructure) + getTypeConstructorString(attrType, attrName1,
+ attrName2, generatedJavaClassName, type, addFirst);
}
/**
@@ -1400,7 +1398,6 @@
* @return type constructor string
*/
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
@@ -1417,7 +1414,6 @@
*/
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;
@@ -1501,7 +1497,7 @@
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
- return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, 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 +
@@ -1559,7 +1555,6 @@
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
int value;
for (String str : enumList) {
-
value = enumMap.get(str);
method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE
+ SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
@@ -1569,7 +1564,7 @@
+ 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 type " + attrName, false, pluginConfig)
+ return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig, null)
+ method;
}
@@ -1581,7 +1576,6 @@
* @return parsed string
*/
private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
-
YangDataTypes type = yangType.getDataType();
switch (type) {
@@ -1652,11 +1646,10 @@
methods.append(method);
method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
- getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig) +
+ getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) +
getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
- getCapitalCase(curNodeName), returnType, parentName,
- false,
- GENERATE_SERVICE_AND_MANAGER) + NEW_LINE;
+ getCapitalCase(curNodeName), returnType, parentName, false,
+ GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
methods.append(method);
}
return methods.toString();
@@ -1968,4 +1961,30 @@
" 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/utils/UtilConstants.java b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 6c2f3dc..23dacfe 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -1271,7 +1271,17 @@
public static final String LIST = "List";
/**
- * Comment to be added for auto generated impl methods.
+ * Static attribute for queue.
+ */
+ public static final String QUEUE = "Queue";
+
+ /**
+ * Static attribute for set.
+ */
+ public static final String SET = "Set";
+
+ /**
+ * Comment to be added for autogenerated impl methods.
*/
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
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 d71d882..31e454f 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
@@ -65,8 +65,10 @@
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_OUTPUT_STRING;
+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.VALUE;
@@ -93,9 +95,11 @@
* @param name name of the YangNode
* @param isList is list attribute
* @param pluginConfig plugin configurations
- * @return javaDocs.
+ * @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, YangPluginConfig pluginConfig,
+ String compilerAnnotation) {
name = YangIoUtils.getSmallCase(getCamelCase(name, pluginConfig.getConflictResolver()));
switch (type) {
@@ -121,16 +125,16 @@
return generateForPackage(name, isList);
}
case GETTER_METHOD: {
- return generateForGetters(name, isList);
+ return generateForGetters(name, isList, compilerAnnotation);
}
case TYPE_DEF_SETTER_METHOD: {
return generateForTypeDefSetter(name);
}
case SETTER_METHOD: {
- return generateForSetters(name, isList);
+ return generateForSetters(name, isList, compilerAnnotation);
}
case MANAGER_SETTER_METHOD: {
- return generateForManagerSetters(name, isList);
+ return generateForManagerSetters(name, isList, compilerAnnotation);
}
case OF_METHOD: {
return generateForOf(name);
@@ -277,16 +281,39 @@
*
* @param attribute attribute
* @param isList is list attribute
+ * @param compilerAnnotation compiler annotation
* @return javaDocs
*/
- private static String generateForGetters(String attribute, boolean isList) {
+ 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 listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
- getter = getter + listAttribute;
+ 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;
}
@@ -300,16 +327,41 @@
*
* @param attribute attribute
* @param isList is list attribute
+ * @param compilerAnnotation compiler annotation
* @return javaDocs
*/
- private static String generateForSetters(String attribute, boolean isList) {
+ 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;
- if (isList) {
- String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + listAttribute;
+
+ 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;
}
@@ -324,16 +376,41 @@
*
* @param attribute attribute
* @param isList is list attribute
+ * @param compilerAnnotation compiler annotation
* @return javaDocs
*/
- private static String generateForManagerSetters(String attribute, boolean isList) {
+ private static String generateForManagerSetters(String attribute, boolean isList,
+ String compilerAnnotation) {
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;
- if (isList) {
- String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + listAttribute;
+
+ 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;
}
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 5901f25..1c1de71 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
@@ -130,7 +130,8 @@
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(getCopyrightHeader());
- bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode, pluginConfig));
+ //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;
if (pkg.length() > LINE_SIZE) {
pkg = whenDelimiterIsPresent(pkg, LINE_SIZE);
diff --git a/plugin/src/main/resources/YangLexer.g4 b/plugin/src/main/resources/YangLexer.g4
index 8abe32f..51a9231 100644
--- a/plugin/src/main/resources/YangLexer.g4
+++ b/plugin/src/main/resources/YangLexer.g4
@@ -133,7 +133,7 @@
PLUS : '+';
MINUS: '-';
- STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' )* ) | SUB_STRING );
+ STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '+' | '\'')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '+')* ) | SUB_STRING );
//Fragment rules
fragment SUB_STRING : ('"' (ESC | ~["])*'"') | ('\'' (ESC | ~['])*'\'') ;
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListenerTest.java
deleted file mode 100644
index cbc4009..0000000
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListenerTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import java.io.IOException;
-import org.junit.Test;
-import org.onosproject.yangutils.datamodel.YangAppDataStructure;
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangDataStructure;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeType;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-/**
- * Test cases for compiler annotation listener.
- */
-public class CompilerAnnotationListenerTest {
-
- private final YangUtilsParserManager manager = new YangUtilsParserManager();
-
- /**
- * Checks valid compiler annotation statements.
- */
- @Test
- public void processValidCompilerAnnotation() throws IOException, ParserException {
-
- YangNode node = manager.getDataModel("src/test/resources/ValidCompilerAnnotation.yang");
-
- // Check whether the data model tree returned is of type module.
- assertThat((node instanceof YangModule), is(true));
-
- // Check whether the node type is set properly to module.
- assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
-
- // Check whether the module name is set correctly.
- YangModule yangNode = (YangModule) node;
- assertThat(yangNode.getName(), is("event"));
-
- YangCompilerAnnotation compilerAnnotation = yangNode.getCompilerAnnotationList()
- .iterator().next();
- assertThat(compilerAnnotation.getPrefix(), is("ca"));
- assertThat(compilerAnnotation.getPath(), is("/candidate-servers/server"));
-
- YangAppDataStructure appDataStructure = compilerAnnotation.getYangAppDataStructure();
- assertThat(appDataStructure.getPrefix(), is("abc"));
- assertThat(appDataStructure.getDataStructure(), is(YangDataStructure.MAP));
-
- assertThat(appDataStructure.getKeyList().iterator().next(), is("name"));
- }
-}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
index b6b497a..60da95e 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
@@ -21,6 +21,8 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangContainer;
+import org.onosproject.yangutils.datamodel.YangLeafRef;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
@@ -147,4 +149,25 @@
assertThat(leafInfo.getDataType().getDataTypeName(), is("instance-identifier"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INSTANCE_IDENTIFIER));
}
+
+ /**
+ * Checks for leaf ref path concatenation.
+ */
+ @Test
+ public void processLeafRefPathConcatenation() throws IOException, ParserException {
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/leafRefPathConcatenation.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("test"));
+
+ YangTypeDef typeDef = (YangTypeDef) yangNode.getChild();
+ assertThat(typeDef.getName(), is("isis-instance-state-ref"));
+ assertThat(typeDef.getTypeDefBaseType().getDataType(), is(YangDataTypes.LEAFREF));
+ YangLeafRef leafRef = ((YangLeafRef) typeDef.getTypeDefBaseType().getDataTypeExtendedInfo());
+ assertThat(leafRef.getPath(), is("/isis-prefix-ipv4-std/default-metric"));
+ }
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
index e5021d3..9413e3c 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
@@ -103,23 +103,23 @@
public void testForJavaAttributeInfo() {
String attributeWithoutTypePkg = getJavaAttributeDefinition(null, STRING_DATA_TYPE, YANG_NAME,
- false, PRIVATE);
+ false, PRIVATE, null);
assertThat(true, is(attributeWithoutTypePkg.equals(
PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithTypePkg = getJavaAttributeDefinition(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
- false, PRIVATE);
+ false, PRIVATE, null);
assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD
+ STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithListPkg = getJavaAttributeDefinition(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
- true, PRIVATE);
+ true, PRIVATE, null);
assertThat(true, is(attributeWithListPkg.contains(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE
+ DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME)));
String attributeWithListWithoutPkg = getJavaAttributeDefinition(null, STRING_DATA_TYPE, YANG_NAME,
- true, PRIVATE);
+ true, PRIVATE, null);
assertThat(true, is(attributeWithListWithoutPkg.contains(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE
+ YANG_NAME)));
diff --git a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index cbac365..9579b7d 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -221,7 +221,7 @@
*/
@Test
public void getGetterForInterfaceTest() {
- String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false, GENERATE_SERVICE_AND_MANAGER);
+ String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false, GENERATE_SERVICE_AND_MANAGER, null);
assertThat(true, is(method.contains(STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
}
@@ -244,7 +244,7 @@
@Test
public void getSetterForInterfaceTest() {
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false,
- GENERATE_SERVICE_AND_MANAGER);
+ GENERATE_SERVICE_AND_MANAGER, null);
assertThat(true, is(method.contains(VOID + SPACE +
SET_METHOD_PREFIX + "Testname")));
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java b/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
index e229fed..eb2a674 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
@@ -56,7 +56,7 @@
*/
@Test
public void builderClassGenerationTest() {
- String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false, getStubPluginConfig());
+ String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of")
&& builderClassJavaDoc.contains(END_STRING)));
}
@@ -66,7 +66,7 @@
*/
@Test
public void builderInterfaceGenerationTest() {
- String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false, getStubPluginConfig());
+ String builderInterfaceJavaDoc = getJavaDoc(BUILDER_INTERFACE, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true,
is(builderInterfaceJavaDoc.contains("Builder for")
&& builderInterfaceJavaDoc.contains(END_STRING)));
@@ -77,7 +77,7 @@
*/
@Test
public void buildGenerationTest() {
- String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false, getStubPluginConfig());
+ String buildDoc = getJavaDoc(BUILD_METHOD, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true, is(buildDoc.contains("Builds object of") && buildDoc.contains(END_STRING)));
}
@@ -109,7 +109,7 @@
*/
@Test
public void constructorGenerationTest() {
- String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
+ String constructorDoc = getJavaDoc(CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true,
is(constructorDoc.contains("Creates an instance of ")
&& constructorDoc.contains("builder object of")
@@ -121,7 +121,7 @@
*/
@Test
public void defaultConstructorGenerationTest() {
- String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig());
+ String defaultConstructorDoc = getJavaDoc(DEFAULT_CONSTRUCTOR, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true, is(defaultConstructorDoc.contains("Creates an instance of ")
&& defaultConstructorDoc.contains(END_STRING)));
}
@@ -131,7 +131,7 @@
*/
@Test
public void getterGenerationTest() {
- String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
+ String getterJavaDoc = getJavaDoc(GETTER_METHOD, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true,
is(getterJavaDoc.contains("Returns the attribute") && getterJavaDoc.contains(END_STRING)));
}
@@ -141,7 +141,7 @@
*/
@Test
public void implClassGenerationTest() {
- String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, getStubPluginConfig());
+ String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true,
is(implClassJavaDoc.contains("Represents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
@@ -152,7 +152,7 @@
*/
@Test
public void interfaceGenerationTest() {
- String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false, getStubPluginConfig());
+ String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true,
is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of")
&& interfaceJavaDoc.contains(END_STRING)));
@@ -163,7 +163,7 @@
*/
@Test
public void packageInfoGenerationTest() {
- String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false, getStubPluginConfig());
+ String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true,
is(packageInfo.contains("Implementation of YANG node") && packageInfo.contains(END_STRING)));
}
@@ -173,7 +173,7 @@
*/
@Test
public void packageInfoGenerationForChildNodeTest() {
- String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true, getStubPluginConfig());
+ String packageInfo = getJavaDoc(PACKAGE_INFO, TEST_NAME, true, getStubPluginConfig(), null);
assertThat(true, is(packageInfo.contains("Implementation of YANG node testName's children nodes")
&& packageInfo.contains(END_STRING)));
}
@@ -183,7 +183,7 @@
*/
@Test
public void setterGenerationTest() {
- String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
+ String setterJavaDoc = getJavaDoc(SETTER_METHOD, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true,
is(setterJavaDoc.contains("Returns the builder object of") && setterJavaDoc.contains(END_STRING)));
}
@@ -193,7 +193,7 @@
*/
@Test
public void typeDefSetterGenerationTest() {
- String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false, getStubPluginConfig());
+ String typeDefSetter = getJavaDoc(TYPE_DEF_SETTER_METHOD, TEST_NAME, false, getStubPluginConfig(), null);
assertThat(true, is(typeDefSetter.contains("Sets the value of") && typeDefSetter.contains(END_STRING)));
}
diff --git a/plugin/src/test/resources/ValidCompilerAnnotation.yang b/plugin/src/test/resources/ValidCompilerAnnotation.yang
deleted file mode 100644
index 7913fab..0000000
--- a/plugin/src/test/resources/ValidCompilerAnnotation.yang
+++ /dev/null
@@ -1,13 +0,0 @@
-module event {
-
- namespace "http://example.com/event";
- prefix "ev";
-
- ca:compiler-annotation "/candidate-servers/server" {
- abc:app-data-structure "map" {
- ca:key "name";
- }
- xyz:app-extended-name "special-server";
- }
-}
-
diff --git a/plugin/src/test/resources/leafRefPathConcatenation.yang b/plugin/src/test/resources/leafRefPathConcatenation.yang
new file mode 100644
index 0000000..a9b688e
--- /dev/null
+++ b/plugin/src/test/resources/leafRefPathConcatenation.yang
@@ -0,0 +1,20 @@
+module test {
+ namespace "urn:ietf:params:xml:ns:yang:ietf-isis";
+ prefix isis;
+ typedef isis-instance-state-ref {
+ type leafref {
+ path "/isis-prefix-ipv4-std/"
+ +"default-metric";
+ }
+ }
+ container isis-route-content {
+ leaf metric {
+ type isis-instance-state-ref ;
+ }
+ }
+ container isis-prefix-ipv4-std {
+ leaf default-metric {
+ type string;
+ }
+ }
+}
\ No newline at end of file