[ONOS-5482][ONOS-5275] Yms Operation requirement Implementation in onos-yang-tools
Change-Id: I463ed105f85ca65a61ff251e5ca062903d465551
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/InvalidOpTypeHolder.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/InvalidOpTypeHolder.java
new file mode 100644
index 0000000..bdf714e
--- /dev/null
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/InvalidOpTypeHolder.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel;
+
+/**
+ * Represents non data nodes which will not have operation api's ex: operation
+ * type, value leaf flag, select leaf flag and process sub tree filter in
+ * their generated code.
+ */
+public interface InvalidOpTypeHolder {
+}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java
index 2c8fa80..83f3b89 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDecimal64.java
@@ -32,7 +32,8 @@
* Represents YANG decimal 64.
*/
public class YangDecimal64<T> extends DefaultLocationInfo
- implements YangBuiltInDataTypeInfo<YangDecimal64>, Parsable, Serializable, Comparable<YangDecimal64> {
+ implements YangBuiltInDataTypeInfo<YangDecimal64>, Parsable, Serializable,
+ Comparable<YangDecimal64> {
private static final long serialVersionUID = 8006201668L;
@@ -59,7 +60,8 @@
/**
* Valid minimum value of YANG's decimal64.
*/
- public static final BigDecimal MIN_VALUE = BigDecimal.valueOf(-922337203685477580.8);
+ private static final BigDecimal MIN_VALUE = BigDecimal.valueOf
+ (-922337203685477580.8);
/**
* Valid maximum value of YANG's decimal64.
@@ -97,7 +99,7 @@
*
* @param valueInString of decimal64 in string
*/
- public YangDecimal64(String valueInString) {
+ YangDecimal64(String valueInString) {
if (valueInString.matches(MIN_KEYWORD)) {
value = MIN_VALUE;
} else if (valueInString.matches(MAX_KEYWORD)) {
@@ -234,9 +236,13 @@
// Check whether value is within provided range value
ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
.listIterator();
+
boolean isMatched = false;
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
BigDecimal startValue = ((YangDecimal64) rangeInterval.getStartValue()).getValue();
BigDecimal endValue = ((YangDecimal64) rangeInterval.getEndValue()).getValue();
if ((this.value.doubleValue() >= startValue.doubleValue()) &&
@@ -248,19 +254,19 @@
// If range is not matched then throw error
if (!isMatched) {
throw new DataModelException("YANG file error : decimal64 validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
}
} else {
// Check value is in fraction-digits decimal64 value range
if (!FractionDigits.isValueInDecimal64Range(this.value, getFractionDigit())) {
throw new DataModelException("YANG file error : decimal64 validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
}
}
@@ -282,22 +288,25 @@
.listIterator();
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
if (!(FractionDigits.isValueInDecimal64Range(((YangDecimal64) rangeInterval.getStartValue()).getValue(),
- getFractionDigit()))) {
+ getFractionDigit()))) {
throw new DataModelException("YANG file error : range validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
}
if (!(FractionDigits.isValueInDecimal64Range(((YangDecimal64) rangeInterval.getEndValue()).getValue(),
- getFractionDigit()))) {
+ getFractionDigit()))) {
throw new DataModelException("YANG file error : range validation failed. " +
- " in " +
- getLineNumber() + " at " +
- getCharPosition() +
- " in " + getFileName() + "\"");
+ " in " +
+ getLineNumber() + " at " +
+ getCharPosition() +
+ " in " + getFileName() + "\"");
}
}
}
@@ -317,7 +326,10 @@
public YangRangeRestriction getDefaultRangeRestriction() throws DataModelException {
YangRangeRestriction refRangeRestriction = new YangRangeRestriction();
YangRangeInterval rangeInterval = new YangRangeInterval<>();
- FractionDigits.Range range = FractionDigits.getRange(this.fractionDigit);
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
+ FractionDigits.Range range = FractionDigits.getRange(fractionDigit);
rangeInterval.setStartValue(new YangDecimal64(new BigDecimal((range.getMin()))));
rangeInterval.setEndValue(new YangDecimal64(new BigDecimal((range.getMax()))));
refRangeRestriction.addRangeRestrictionInterval(rangeInterval);
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 f766271..9d9b686 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedInfo.java
@@ -16,13 +16,12 @@
package org.onosproject.yangutils.datamodel;
-import java.io.Serializable;
-
+import com.google.common.base.Strings;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import com.google.common.base.Strings;
+import java.io.Serializable;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
@@ -238,10 +237,10 @@
} else {
if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveRangeRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
/*
@@ -267,10 +266,10 @@
} else {
if (!(baseType.getDataTypeExtendedInfo() instanceof YangStringRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveStringRestriction((YangStringRestriction) baseType.getDataTypeExtendedInfo());
/*
@@ -292,10 +291,10 @@
} else {
if (!(baseType.getDataTypeExtendedInfo() instanceof YangRangeRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveBinaryRestriction((YangRangeRestriction) baseType.getDataTypeExtendedInfo());
/*
@@ -319,10 +318,10 @@
if (!(((YangDecimal64) baseType.getDataTypeExtendedInfo())
.getRangeRestrictedExtendedInfo() instanceof YangRangeRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is" +
- " of invalid type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ " of invalid type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveRangeRestriction((YangRangeRestriction) ((YangDecimal64) baseType
.getDataTypeExtendedInfo()).getRangeRestrictedExtendedInfo());
@@ -336,10 +335,10 @@
} else {
throw new DataModelException("Linker error: Unable to find type extended info for decimal64." +
- "" + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "" + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
}
}
@@ -355,19 +354,19 @@
return RESOLVED;
} else {
throw new DataModelException("YANG file error: Restrictions can't be applied to a given type "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
}
// Throw exception for unsupported types
throw new DataModelException("Linker error: Unable to process the derived type. "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
/**
@@ -384,10 +383,10 @@
//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."
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
/*
@@ -398,7 +397,7 @@
return INTRA_FILE_RESOLVED;
}
setEffectiveBuiltInType(((YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo())
- .getEffectiveBuiltInType());
+ .getEffectiveBuiltInType());
YangDerivedInfo refDerivedInfo = (YangDerivedInfo<?>) baseType.getDataTypeExtendedInfo();
/*
* Check whether the effective built-in type can have range
@@ -416,10 +415,10 @@
} else {
if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveRangeRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
/*
@@ -445,10 +444,10 @@
} else {
if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangStringRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveStringRestriction((YangStringRestriction) refDerivedInfo.getResolvedExtendedInfo());
/*
@@ -470,10 +469,10 @@
} else {
if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveBinaryRestriction((YangRangeRestriction) refDerivedInfo.getResolvedExtendedInfo());
/*
@@ -495,10 +494,10 @@
} else {
if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
- "type." + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ "type." + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
resolveRangeRestriction((YangRangeRestriction) refDerivedInfo
.getResolvedExtendedInfo());
@@ -532,7 +531,7 @@
*/
if (!Strings.isNullOrEmpty(getRangeRestrictionString())) {
DataModelException dataModelException = new DataModelException("YANG file error: Range restriction " +
- "should't be present for string data type.");
+ "should't be present for string data type.");
dataModelException.setLine(getLineNumber());
dataModelException.setCharPosition(getCharPosition());
dataModelException.setFileName(getFileName());
@@ -566,6 +565,9 @@
*/
if (lengthRestriction != null || patternRestriction != null) {
curStringRestriction = new YangStringRestriction();
+ curStringRestriction.setCharPosition(getCharPosition());
+ curStringRestriction.setFileName(getFileName());
+ curStringRestriction.setLineNumber(getLineNumber());
curStringRestriction.setLengthRestriction(lengthRestriction);
curStringRestriction.setPatternRestriction(patternRestriction);
}
@@ -584,7 +586,7 @@
if (rangeRestrictionString != null || patternRestriction != null) {
DataModelException dataModelException =
new DataModelException("YANG file error: for binary " +
- "range restriction or pattern restriction is not allowed.");
+ "range restriction or pattern restriction is not allowed.");
dataModelException.setLine(getLineNumber());
dataModelException.setCharPosition(getCharPosition());
dataModelException.setFileName(getFileName());
@@ -669,8 +671,10 @@
* carry out self resolution.
*/
if (refLengthRestriction == null) {
- YangRangeRestriction curLengthRestriction = processLengthRestriction(null, getLineNumber(),
- getCharPosition(), false, getLengthRestrictionString());
+ YangRangeRestriction curLengthRestriction =
+ processLengthRestriction(null, getLineNumber(),
+ getCharPosition(), false,
+ getLengthRestrictionString(), getFileName());
return curLengthRestriction;
}
@@ -678,8 +682,10 @@
* Carry out self resolution based with obtained effective built-in type
* and MIN/MAX values as per the referred typedef's values.
*/
- YangRangeRestriction curLengthRestriction = processLengthRestriction(refLengthRestriction, getLineNumber(),
- getCharPosition(), true, getLengthRestrictionString());
+ YangRangeRestriction curLengthRestriction =
+ processLengthRestriction(refLengthRestriction, getLineNumber(),
+ getCharPosition(), true,
+ getLengthRestrictionString(), getFileName());
// Resolve the range with referred typedef's restriction.
resolveLengthAndRangeRestriction(refLengthRestriction, curLengthRestriction);
@@ -700,10 +706,10 @@
for (Object curInterval : curRestriction.getAscendingRangeIntervals()) {
if (!(curInterval instanceof YangRangeInterval)) {
throw new DataModelException("Linker error: Current range intervals not processed correctly."
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
try {
refRestriction.isValidInterval((YangRangeInterval) curInterval);
@@ -732,7 +738,7 @@
*/
if (!Strings.isNullOrEmpty(getLengthRestrictionString()) || getPatternRestriction() != null) {
DataModelException dataModelException = new DataModelException("YANG file error: Length/Pattern " +
- "restriction should't be present for int/uint/decimal data type.");
+ "restriction should't be present for int/uint/decimal data type.");
dataModelException.setLine(getLineNumber());
dataModelException.setCharPosition(getCharPosition());
dataModelException.setFileName(getFileName());
@@ -761,8 +767,10 @@
* carry out self resolution.
*/
if (refRangeRestriction == null) {
- YangRangeRestriction curRangeRestriction = processRangeRestriction(null, getLineNumber(),
- getCharPosition(), false, getRangeRestrictionString(), getEffectiveBuiltInType());
+ YangRangeRestriction curRangeRestriction =
+ processRangeRestriction(null, getLineNumber(),
+ getCharPosition(), false, getRangeRestrictionString(),
+ getEffectiveBuiltInType(), getFileName());
setResolvedExtendedInfo((T) curRangeRestriction);
return;
}
@@ -771,8 +779,11 @@
* Carry out self resolution based with obtained effective built-in type
* and MIN/MAX values as per the referred typedef's values.
*/
- YangRangeRestriction curRangeRestriction = processRangeRestriction(refRangeRestriction, getLineNumber(),
- getCharPosition(), true, getRangeRestrictionString(), getEffectiveBuiltInType());
+ YangRangeRestriction curRangeRestriction =
+ processRangeRestriction(refRangeRestriction, getLineNumber(),
+ getCharPosition(), true,
+ getRangeRestrictionString(),
+ getEffectiveBuiltInType(), getFileName());
// Resolve the range with referred typedef's restriction.
resolveLengthAndRangeRestriction(refRangeRestriction, curRangeRestriction);
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
index d7ba0fe..642e8fd 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
@@ -80,7 +80,7 @@
public abstract class YangInput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector,
- YangAugmentableNode, YangIsFilterContentNodes {
+ YangAugmentableNode, YangIsFilterContentNodes, InvalidOpTypeHolder {
private static final long serialVersionUID = 806201608L;
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 87d126e..8c2a812 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafRef.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLeafRef.java
@@ -16,23 +16,27 @@
package org.onosproject.yangutils.datamodel;
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Collections.unmodifiableList;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LEAFREF_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.DATA_MISSING_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.ERROR_PATH_LEAFREF_LEAF;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.INSTANCE_REQUIRED_ERROR_APP_TAG;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
/*
* Reference:RFC 6020.
@@ -162,6 +166,9 @@
*/
public YangLeafRef() {
yangAppErrorInfo = new YangAppErrorInfo();
+ prefixAndItsImportedModule = new HashMap<>();
+ atomicPath = new ArrayList<>();
+ ifFeatureList = new ArrayList<>();
yangAppErrorInfo.setErrorTag(DATA_MISSING_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(INSTANCE_REQUIRED_ERROR_APP_TAG);
yangAppErrorInfo.setErrorAppPath(ERROR_PATH_LEAFREF_LEAF);
@@ -245,7 +252,7 @@
* @return list of atomic path
*/
public List<YangAtomicPath> getAtomicPath() {
- return atomicPath;
+ return unmodifiableList(atomicPath);
}
/**
@@ -295,15 +302,12 @@
@Override
public List<YangIfFeature> getIfFeatureList() {
- return ifFeatureList;
+ return unmodifiableList(ifFeatureList);
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
- if (getIfFeatureList() == null) {
- setIfFeatureList(new LinkedList<>());
- }
- getIfFeatureList().add(ifFeature);
+ ifFeatureList.add(ifFeature);
}
@Override
@@ -313,7 +317,7 @@
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.LEAFREF_DATA;
+ return LEAFREF_DATA;
}
@Override
@@ -382,7 +386,7 @@
YangLeaf yangLeaf = ((YangLeaf) getReferredLeafOrLeafList());
YangType baseType = yangLeaf.getDataType();
- if (baseType.getDataType() == YangDataTypes.LEAFREF) {
+ if (baseType.getDataType() == LEAFREF) {
YangLeafRef referredLeafRefInfo = (YangLeafRef) (yangLeaf.getDataType().getDataTypeExtendedInfo());
//Check whether the referred typedef is resolved.
@@ -450,7 +454,7 @@
YangLeafList yangLeafList = ((YangLeafList) getReferredLeafOrLeafList());
YangType baseType = yangLeafList.getDataType();
- if (baseType.getDataType() == YangDataTypes.LEAFREF) {
+ if (baseType.getDataType() == LEAFREF) {
YangLeafRef referredLeafRefInfo = (YangLeafRef) yangLeafList.getDataType().getDataTypeExtendedInfo();
//Check whether the referred typedef is resolved.
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
index 5df0f8f..ed75d01 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangLengthRestriction.java
@@ -16,13 +16,13 @@
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;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
+import java.io.Serializable;
+
/*-
* Reference RFC 6020.
*
@@ -98,7 +98,8 @@
* Creates a YANG length restriction object.
*/
public YangLengthRestriction() {
- setLengthRestriction(new YangRangeRestriction<YangUint64>());
+ setLengthRestriction(new YangRangeRestriction<>());
+ yangAppErrorInfo = new YangAppErrorInfo();
}
/**
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java
index c6ebdd7..9ffd3a6 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMaxElement.java
@@ -16,11 +16,11 @@
package org.onosproject.yangutils.datamodel;
+import java.io.Serializable;
+
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.TOO_MANY_ELEMENTS_ERROR_APP_TAG;
-import java.io.Serializable;
-
/**
* Represents max element data represented in YANG.
*/
@@ -36,12 +36,12 @@
/**
* Reference:RFC 6020.
- *
+ * <p>
* The "max-elements" statement, which is optional, takes as an argument a
* positive integer or the string "unbounded", which puts a constraint on
* valid list entries. A valid leaf-list or list always has at most
* max-elements entries.
- *
+ * <p>
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private int maxElement = Integer.MAX_VALUE;
@@ -50,7 +50,7 @@
* Creates a YANG maximum element.
*/
public YangMaxElement() {
- YangAppErrorInfo yangAppErrorInfo = new YangAppErrorInfo();
+ yangAppErrorInfo = new YangAppErrorInfo();
yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(TOO_MANY_ELEMENTS_ERROR_APP_TAG);
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java
index 8af5849..a2b73d3 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangMinElement.java
@@ -16,11 +16,11 @@
package org.onosproject.yangutils.datamodel;
+import java.io.Serializable;
+
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.OPERATION_FAILED_ERROR_TAG;
import static org.onosproject.yangutils.datamodel.utils.YangErrMsgConstants.TOO_FEW_ELEMENTS_ERROR_APP_TAG;
-import java.io.Serializable;
-
/**
* Represents minimum element data represented in YANG.
*/
@@ -36,20 +36,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>
* If this ancestor is a case node, the constraint is enforced if any
* other node from the case exists.
- *
+ * <p>
* Otherwise, it is enforced if the ancestor node exists.
*/
private int minElement = 0;
@@ -58,7 +58,7 @@
* Creates a YANG minimum element.
*/
public YangMinElement() {
- YangAppErrorInfo yangAppErrorInfo = new YangAppErrorInfo();
+ yangAppErrorInfo = new YangAppErrorInfo();
yangAppErrorInfo.setErrorTag(OPERATION_FAILED_ERROR_TAG);
yangAppErrorInfo.setErrorAppTag(TOO_FEW_ELEMENTS_ERROR_APP_TAG);
}
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 e57cc82..fc2bc6a 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNode.java
@@ -79,6 +79,11 @@
private boolean isToTranslate = true;
/**
+ * Flag if the node needs to generate operation type info for translation.
+ */
+ private boolean isOpTypeReq;
+
+ /**
* Map of YANG context information. It is to be consumed by YMS.
*/
private Map<YangSchemaNodeIdentifier, YangSchemaNodeContextInfo> ysnContextInfoMap;
@@ -877,4 +882,21 @@
public YangSchemaNode getReferredSchema() {
return referredSchemaNode;
}
+
+ /**
+ * Returns true if op type info required for node.
+ *
+ * @return true if op type info required for node
+ */
+ public boolean isOpTypeReq() {
+ if (this instanceof RpcNotificationContainer) {
+ isOpTypeReq = true;
+ return true;
+ }
+ if (this instanceof InvalidOpTypeHolder) {
+ isOpTypeReq = false;
+ return false;
+ }
+ return this.getParent().isOpTypeReq();
+ }
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
index b70190c..dbca232 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
@@ -16,16 +16,23 @@
package org.onosproject.yangutils.datamodel;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yangutils.datamodel.YangNodeType.NOTIFICATION_NODE;
+import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yangutils.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.NOTIFICATION;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.NOTIFICATION_DATA;
/*
* Reference RFC 6020.
@@ -79,7 +86,7 @@
public abstract class YangNotification
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
- YangAugmentableNode, YangIfFeatureHolder {
+ YangAugmentableNode, YangIfFeatureHolder, InvalidOpTypeHolder {
private static final long serialVersionUID = 806201611L;
@@ -106,30 +113,31 @@
/**
* Status of the node.
*/
- private YangStatusType status = YangStatusType.CURRENT;
+ private YangStatusType status = CURRENT;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
- private List<YangAugment> yangAugmentedInfo = new ArrayList<>();
+ private final List<YangAugment> yangAugmentedInfo;
/**
* Create a notification node.
*/
public YangNotification() {
- super(YangNodeType.NOTIFICATION_NODE, new HashMap<>());
+ super(NOTIFICATION_NODE, new HashMap<>());
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
ifFeatureList = new LinkedList<>();
+ yangAugmentedInfo = new LinkedList<>();
}
@Override
- public void addToChildSchemaMap(YangSchemaNodeIdentifier schemaNodeIdentifier,
- YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
throws DataModelException {
- getYsnContextInfoMap().put(schemaNodeIdentifier, yangSchemaNodeContextInfo);
+ getYsnContextInfoMap().put(id, context);
}
@Override
@@ -138,13 +146,14 @@
}
@Override
- public void addToDefaultChildMap(YangSchemaNodeIdentifier yangSchemaNodeIdentifier, YangSchemaNode yangSchemaNode) {
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
// TODO
}
@Override
public YangSchemaNodeType getYangSchemaNodeType() {
- return YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+ return YANG_SINGLE_INSTANCE_NODE;
}
@Override
@@ -158,17 +167,15 @@
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (getName().equals(identifierName)) {
- throw new DataModelException("YANG file error: Duplicate input identifier detected, same as notification \""
- + getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsgCollision(
+ COLLISION_DETECTION, getName(), getLineNumber(),
+ getCharPosition(), NOTIFICATION, getFileName()));
}
}
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.NOTIFICATION_DATA;
+ return NOTIFICATION_DATA;
}
@Override
@@ -195,7 +202,7 @@
@Override
public List<YangLeaf> getListOfLeaf() {
- return listOfLeaf;
+ return unmodifiableList(listOfLeaf);
}
@Override
@@ -205,12 +212,12 @@
@Override
public void addLeaf(YangLeaf leaf) {
- getListOfLeaf().add(leaf);
+ listOfLeaf.add(leaf);
}
@Override
public List<YangLeafList> getListOfLeafList() {
- return listOfLeafList;
+ return unmodifiableList(listOfLeafList);
}
@Override
@@ -220,7 +227,7 @@
@Override
public void addLeafList(YangLeafList leafList) {
- getListOfLeafList().add(leafList);
+ listOfLeafList.add(leafList);
}
@Override
@@ -245,15 +252,12 @@
@Override
public List<YangIfFeature> getIfFeatureList() {
- return ifFeatureList;
+ return unmodifiableList(ifFeatureList);
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
- if (getIfFeatureList() == null) {
- setIfFeatureList(new LinkedList<>());
- }
- getIfFeatureList().add(ifFeature);
+ ifFeatureList.add(ifFeature);
}
@Override
@@ -273,17 +277,17 @@
@Override
public List<YangAugment> getAugmentedInfoList() {
- return yangAugmentedInfo;
+ return unmodifiableList(yangAugmentedInfo);
}
@Override
public void setLeafNameSpaceAndAddToParentSchemaMap() {
// Add namespace for all leafs.
- for (YangLeaf yangLeaf : getListOfLeaf()) {
+ for (YangLeaf yangLeaf : listOfLeaf) {
yangLeaf.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
}
// Add namespace for all leaf list.
- for (YangLeafList yangLeafList : getListOfLeafList()) {
+ for (YangLeafList yangLeafList : listOfLeafList) {
yangLeafList.setLeafNameSpaceAndAddToParentSchemaMap(getNameSpace());
}
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
index 9bee1de..280da96 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
@@ -78,7 +78,7 @@
public abstract class YangOutput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector,
- YangAugmentableNode, YangIsFilterContentNodes {
+ YangAugmentableNode, YangIsFilterContentNodes, InvalidOpTypeHolder {
private static final long serialVersionUID = 806201612L;
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
index 048d8c4..c5376b0 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
@@ -71,7 +71,8 @@
* Creates a YANG pattern restriction object.
*/
public YangPatternRestriction() {
- setPatternList(new LinkedList<String>());
+ setPatternList(new LinkedList<>());
+ yangAppErrorInfo = new YangAppErrorInfo();
}
/**
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
index e664a64..346b794 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
@@ -16,18 +16,18 @@
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.YangConstructType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import static org.onosproject.yangutils.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.yangutils.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
/*-
* Reference RFC 6020.
@@ -89,6 +89,7 @@
* Creates YANG range restriction object.
*/
public YangRangeRestriction() {
+ yangAppErrorInfo = new YangAppErrorInfo();
}
/**
@@ -118,17 +119,17 @@
public T getMinRestrictedvalue() throws DataModelException {
if (getAscendingRangeIntervals() == null) {
throw new DataModelException("No range restriction info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
if (getAscendingRangeIntervals().isEmpty()) {
throw new DataModelException("No range interval info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
return getAscendingRangeIntervals().get(0).getStartValue();
}
@@ -142,17 +143,17 @@
public T getMaxRestrictedvalue() throws DataModelException {
if (getAscendingRangeIntervals() == null) {
throw new DataModelException("No range restriction info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
if (getAscendingRangeIntervals().isEmpty()) {
throw new DataModelException("No range interval info "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
return getAscendingRangeIntervals()
.get(getAscendingRangeIntervals().size() - 1).getEndValue();
@@ -209,10 +210,10 @@
// Throw exception, At least one default range needs to be set in
// constructor or in linker.
throw new DataModelException("Range interval missing in range restriction. "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
@@ -244,10 +245,10 @@
// Throw exception, At least one default range needs to be set in
// constructor or in linker.
throw new DataModelException("Range interval missing in range restriction. "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
for (YangRangeInterval<T> interval : getAscendingRangeIntervals()) {
@@ -259,10 +260,10 @@
}
}
throw new DataModelException("Range interval doesn't fall within the referred restriction ranges "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
/**
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
index 1ecfdab..9470cf2 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangRpc.java
@@ -16,15 +16,23 @@
package org.onosproject.yangutils.datamodel;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.util.Collections.unmodifiableList;
+import static org.onosproject.yangutils.datamodel.YangNodeType.RPC_NODE;
+import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yangutils.datamodel.YangStatusType.CURRENT;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.RPC;
+import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RPC_DATA;
/*
* Reference RFC 6020.
@@ -63,7 +71,7 @@
public abstract class YangRpc
extends YangNode
implements YangCommonInfo, Parsable,
- CollisionDetector, YangIfFeatureHolder {
+ CollisionDetector, YangIfFeatureHolder, InvalidOpTypeHolder {
private static final long serialVersionUID = 806201613L;
@@ -80,7 +88,7 @@
/**
* Status of the node.
*/
- private YangStatusType status = YangStatusType.CURRENT;
+ private YangStatusType status = CURRENT;
/**
* List of if-feature.
@@ -91,16 +99,15 @@
* Creates a rpc node.
*/
public YangRpc() {
- super(YangNodeType.RPC_NODE, new HashMap<>());
+ super(RPC_NODE, new HashMap<>());
ifFeatureList = new LinkedList<>();
}
@Override
- public void addToChildSchemaMap(
- YangSchemaNodeIdentifier schemaNodeIdentifier,
- YangSchemaNodeContextInfo yangSchemaNodeContextInfo)
+ public void addToChildSchemaMap(YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo context)
throws DataModelException {
- getYsnContextInfoMap().put(schemaNodeIdentifier, yangSchemaNodeContextInfo);
+ getYsnContextInfoMap().put(id, context);
}
@Override
@@ -114,9 +121,8 @@
}
@Override
- public void addToDefaultChildMap(
- YangSchemaNodeIdentifier yangSchemaNodeIdentifier,
- YangSchemaNode yangSchemaNode) {
+ public void addToDefaultChildMap(YangSchemaNodeIdentifier id,
+ YangSchemaNode yangSchemaNode) {
/*
* This will maintain all default child which are there inside input and
* output as input/output is non data node.
@@ -126,7 +132,7 @@
@Override
public YangSchemaNodeType getYangSchemaNodeType() {
- return YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+ return YANG_SINGLE_INSTANCE_NODE;
}
@Override
@@ -142,18 +148,15 @@
YangConstructType dataType)
throws DataModelException {
if (getName().equals(identifierName)) {
- throw new DataModelException("YANG file error: Duplicate input " +
- "identifier detected, same " +
- "as rpc \"" + getName() + " " +
- "in " + getLineNumber() +
- " at " + getCharPosition() +
- " in " + getFileName() + "\"");
+ throw new DataModelException(getErrorMsgCollision(
+ COLLISION_DETECTION, getName(), getLineNumber(),
+ getCharPosition(), RPC, getFileName()));
}
}
@Override
public YangConstructType getYangConstructType() {
- return YangConstructType.RPC_DATA;
+ return RPC_DATA;
}
@Override
@@ -200,15 +203,12 @@
@Override
public List<YangIfFeature> getIfFeatureList() {
- return ifFeatureList;
+ return unmodifiableList(ifFeatureList);
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
- if (getIfFeatureList() == null) {
- setIfFeatureList(new LinkedList<>());
- }
- getIfFeatureList().add(ifFeature);
+ ifFeatureList.add(ifFeature);
}
@Override
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java
index 13ac938..8067bda 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNodeIdentifier.java
@@ -91,13 +91,18 @@
final String name = namespace.getModuleName();
final String otherName = other.getNameSpace().getModuleName();
if (name != null && otherName != null) {
- return namespace.getModuleName()
- .equals(other.getNameSpace().getModuleName());
+ if (namespace.getModuleName()
+ .equals(other.getNameSpace().getModuleName())) {
+ return true;
+ }
+
}
final String nspace = namespace.getModuleNamespace();
final String otherNspace = other.getNameSpace().getModuleNamespace();
if (nspace != null && otherNspace != null) {
- return nspace.equals(otherNspace);
+ if (nspace.equals(otherNspace)) {
+ return true;
+ }
}
}
return false;
@@ -110,6 +115,6 @@
@Override
public int hashCode() {
- return Objects.hash(name, namespace);
+ return 0;
}
}
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
index cfa8088..b099f78 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
@@ -214,6 +214,9 @@
boolean isMatched = false;
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setCharPosition(getCharPosition());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setFileName(getFileName());
BigInteger startValue = ((YangUint64) rangeInterval.getStartValue()).getValue();
BigInteger endValue = ((YangUint64) rangeInterval.getEndValue()).getValue();
if ((valueInString.length() >= startValue.intValue()) &&
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
index 5fc6075..05063d3 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangType.java
@@ -16,11 +16,6 @@
package org.onosproject.yangutils.datamodel;
-import java.io.Serializable;
-import java.math.BigInteger;
-import java.util.Iterator;
-import java.util.ListIterator;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
import org.onosproject.yangutils.datamodel.utils.Parsable;
@@ -30,6 +25,11 @@
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.ListIterator;
+
import static org.onosproject.yangutils.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
@@ -263,19 +263,19 @@
*/
if (getDataType() != DERIVED) {
throw new DataModelException("Linker Error: Resolve should only be called for derived data types. "
- + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ + " in " +
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
// Check if the derived info is present.
YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) getDataTypeExtendedInfo();
if (derivedInfo == null) {
throw new DataModelException("Linker Error: Derived information is missing. " + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + "\"");
+ getLineNumber() + " at " +
+ getCharPosition()
+ + " in " + getFileName() + "\"");
}
@@ -311,7 +311,7 @@
} else {
if (!((YangRangeRestriction) getDataTypeExtendedInfo()).isValidValueString(value)) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- getDataType());
+ getDataType());
}
}
break;
@@ -321,7 +321,7 @@
YangDecimal64<YangRangeRestriction> decimal64 =
(YangDecimal64<YangRangeRestriction>) getDataTypeExtendedInfo();
validateDecimal64(value, decimal64.getFractionDigit(),
- decimal64.getRangeRestrictedExtendedInfo());
+ decimal64.getRangeRestrictedExtendedInfo());
break;
}
case STRING: {
@@ -331,14 +331,14 @@
&& ((YangStringRestriction) getDataTypeExtendedInfo())
.isValidStringOnPatternRestriction(value))) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- getDataType());
+ getDataType());
}
break;
}
case BOOLEAN:
if (!(value.equals(DataModelUtils.TRUE) || value.equals(DataModelUtils.FALSE))) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- getDataType());
+ getDataType());
}
break;
case ENUMERATION: {
@@ -354,7 +354,7 @@
if (!isValidated) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- getDataType());
+ getDataType());
}
break;
}
@@ -362,14 +362,14 @@
YangBits bits = (YangBits) getDataTypeExtendedInfo();
if (bits.fromString(value) == null) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- getDataType());
+ getDataType());
}
break;
}
case BINARY: {
if (!isValidBinary(value, (YangRangeRestriction) getDataTypeExtendedInfo())) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- getDataType());
+ getDataType());
}
break;
}
@@ -385,7 +385,7 @@
case EMPTY: {
if (value.length() > 0) {
throw new DataTypeException("YANG file error : Input value \"" + value
- + "\" is not allowed for a data type " + getDataType());
+ + "\" is not allowed for a data type " + getDataType());
}
break;
}
@@ -406,7 +406,7 @@
if (!isValidated) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- getDataType());
+ getDataType());
}
break;
}
@@ -419,13 +419,13 @@
if (isOfRangeRestrictedType(dataType)) {
if (((YangDerivedInfo) getDataTypeExtendedInfo()).getResolvedExtendedInfo() == null) {
getDataObjectFromString(value,
- ((YangDerivedInfo) getDataTypeExtendedInfo())
- .getEffectiveBuiltInType());
+ ((YangDerivedInfo) getDataTypeExtendedInfo())
+ .getEffectiveBuiltInType());
} else {
if (!((YangRangeRestriction) ((YangDerivedInfo) getDataTypeExtendedInfo())
.getResolvedExtendedInfo()).isValidValueString(value)) {
throw new DataTypeException("YANG file error : Input value \"" + value
- + "\" is not a valid " + dataType);
+ + "\" is not a valid " + dataType);
}
}
} else if (dataType == YangDataTypes.STRING) {
@@ -436,20 +436,20 @@
if (!(stringRestriction.isValidStringOnLengthRestriction(value) &&
stringRestriction.isValidStringOnPatternRestriction(value))) {
throw new DataTypeException("YANG file error : Input value \"" + value
- + "\" is not a valid " + dataType);
+ + "\" is not a valid " + dataType);
}
}
} else if (dataType == YangDataTypes.BITS) {
YangBits bits = (YangBits) getDataTypeExtendedInfo();
if (bits.fromString(value) == null) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- dataType);
+ dataType);
}
} else if (dataType == YangDataTypes.BINARY) {
if (!isValidBinary(value, (YangRangeRestriction) ((YangDerivedInfo)
getDataTypeExtendedInfo()).getResolvedExtendedInfo())) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
- dataType);
+ dataType);
}
} else if (dataType == YangDataTypes.DECIMAL64) {
YangDerivedInfo derivedInfo = (YangDerivedInfo) getDataTypeExtendedInfo();
@@ -459,13 +459,13 @@
YangDecimal64<YangRangeRestriction> decimal64 = decimal64Type.getDataTypeExtendedInfo();
// Fraction-Digits and range needs to get it from yang
validateDecimal64(value, decimal64.getFractionDigit(),
- decimal64.getRangeRestrictedExtendedInfo());
+ decimal64.getRangeRestrictedExtendedInfo());
}
break;
}
default: {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" received for " +
- "unsupported data type " + getDataType());
+ "unsupported data type " + getDataType());
}
}
}
@@ -509,6 +509,9 @@
boolean isMatched = false;
while (rangeListIterator.hasNext()) {
YangRangeInterval rangeInterval = rangeListIterator.next();
+ rangeInterval.setFileName(getFileName());
+ rangeInterval.setLineNumber(getLineNumber());
+ rangeInterval.setCharPosition(getCharPosition());
BigInteger startValue = ((YangUint64) rangeInterval.getStartValue()).getValue();
BigInteger endValue = ((YangUint64) rangeInterval.getEndValue()).getValue();
// convert (encode) back and check length
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/ErrorMessages.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/ErrorMessages.java
index 4a92990..49ce457 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/ErrorMessages.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/exceptions/ErrorMessages.java
@@ -28,6 +28,8 @@
private static final String AS = "as ";
public static final String QUOTES = "\"";
public static final String CASE = " case ";
+ public static final String NOTIFICATION = " notificaiton ";
+ public static final String RPC = " rpc ";
public static final String INPUT = " input ";
public static final String OUTPUT = " output ";
public static final String CHOICE = " choice ";
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
index e3d0d1a..17c455e 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
@@ -16,14 +16,14 @@
package org.onosproject.yangutils.datamodel.utils;
-import java.util.regex.Pattern;
-
import org.onosproject.yangutils.datamodel.YangRangeInterval;
import org.onosproject.yangutils.datamodel.YangRangeRestriction;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
+import java.util.regex.Pattern;
+
import static org.onosproject.yangutils.datamodel.BuiltInTypeObjectFactory.getDataObjectFromString;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LENGTH_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RANGE_DATA;
@@ -58,13 +58,14 @@
* @param hasReferredRestriction whether has referred restriction
* @param curRangeString caller type's range string
* @param effectiveType effective type, when called from linker
+ * @param fileName file name
* @return YANG range restriction
* @throws DataModelException a violation in data model rule
*/
public static YangRangeRestriction processRangeRestriction(YangRangeRestriction refRangeRestriction,
int lineNumber, int charPositionInLine,
boolean hasReferredRestriction,
- String curRangeString, YangDataTypes effectiveType)
+ String curRangeString, YangDataTypes effectiveType, String fileName)
throws DataModelException {
YangBuiltInDataTypeInfo<?> startValue;
YangBuiltInDataTypeInfo<?> endValue;
@@ -77,12 +78,15 @@
String startInterval;
String endInterval;
YangRangeInterval rangeInterval = new YangRangeInterval();
+ rangeInterval.setCharPosition(charPositionInLine);
+ rangeInterval.setLineNumber(lineNumber);
+ rangeInterval.setFileName(fileName);
String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
DataModelException dataModelException = new DataModelException("YANG file error : " +
- YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
- " is not valid.");
+ YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
+ " is not valid.");
dataModelException.setLine(lineNumber);
dataModelException.setCharPosition(charPositionInLine);
throw dataModelException;
@@ -144,13 +148,14 @@
* @param charPositionInLine error character position in line
* @param hasReferredRestriction whether has referred restriction
* @param curLengthString caller type's length string
+ * @param fileName file name
* @return YANG range restriction
* @throws DataModelException a violation in data model rule
*/
public static YangRangeRestriction processLengthRestriction(YangRangeRestriction refLengthRestriction,
int lineNumber, int charPositionInLine,
boolean hasReferredRestriction,
- String curLengthString) throws DataModelException {
+ String curLengthString, String fileName) throws DataModelException {
YangBuiltInDataTypeInfo<?> startValue;
YangBuiltInDataTypeInfo<?> endValue;
@@ -163,12 +168,15 @@
String startInterval;
String endInterval;
YangRangeInterval rangeInterval = new YangRangeInterval<>();
+ rangeInterval.setCharPosition(charPositionInLine);
+ rangeInterval.setLineNumber(lineNumber);
+ rangeInterval.setFileName(fileName);
String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
DataModelException dataModelException = new DataModelException("YANG file error : " +
- YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
- " is not valid.");
+ YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
+ " is not valid.");
dataModelException.setLine(lineNumber);
dataModelException.setCharPosition(charPositionInLine);
throw dataModelException;
diff --git a/generator/src/main/java/org/onosproject/yangutils/linker/impl/XpathLinkingTypes.java b/generator/src/main/java/org/onosproject/yangutils/linker/impl/XpathLinkingTypes.java
new file mode 100644
index 0000000..87e7fae
--- /dev/null
+++ b/generator/src/main/java/org/onosproject/yangutils/linker/impl/XpathLinkingTypes.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.linker.impl;
+
+/**
+ * Represents x path linking types.
+ */
+public enum XpathLinkingTypes {
+
+ // Augment path linking.
+ AUGMENT_LINKING,
+
+ // Leaf ref path linking.
+ LEAF_REF_LINKING,
+
+ // Compiler annotation linking.
+ COMPILER_ANNOTATION_LINKING
+}
diff --git a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index 84de876..480d8c6 100644
--- a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -78,6 +78,8 @@
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNDEFINED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATH_DATA;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.LEAF_REF_LINKING;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getErrorInfoForLinker;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getLeafRefErrorInfo;
@@ -1026,7 +1028,8 @@
YangNode targetNode;
YangAugment augment = (YangAugment) entityToResolve;
targetNode = xPathLinker
- .processAugmentXpathLinking(augment.getTargetNode(), (YangNode) root);
+ .processXpathLinking(augment.getTargetNode(), (YangNode)
+ root, AUGMENT_LINKING);
if (targetNode != null) {
if (targetNode instanceof YangAugmentableNode) {
detectCollisionForAugmentedNode(targetNode, augment);
@@ -1053,8 +1056,9 @@
} else if (entityToResolve instanceof YangCompilerAnnotation) {
YangNode targetNode;
YangCompilerAnnotation ca = (YangCompilerAnnotation) entityToResolve;
- targetNode = xPathLinker.processAugmentXpathLinking(ca.getAtomicPathList(),
- (YangNode) root);
+ targetNode = xPathLinker.processXpathLinking(ca.getAtomicPathList(),
+ (YangNode) root,
+ AUGMENT_LINKING);
if (targetNode != null) {
if (targetNode instanceof YangList) {
((YangList) targetNode).setCompilerAnnotation(
@@ -1074,7 +1078,7 @@
} else if (entityToResolve instanceof YangLeafRef) {
YangLeafRef leafRef = (YangLeafRef) entityToResolve;
Object target = xPathLinker.processLeafRefXpathLinking(
- leafRef.getAtomicPath(), (YangNode) root, leafRef);
+ leafRef.getAtomicPath(), (YangNode) root, leafRef, LEAF_REF_LINKING);
if (target != null) {
YangLeaf leaf;
YangLeafList leafList;
@@ -1210,13 +1214,13 @@
/*
* Obtain the referred node of top of stack entity under resolution
*/
- T referredNode = getRefNode();
+ T refNode = getRefNode();
/*
* Check for null for scenario when it's not linked and inter-file
* linking is required.
*/
- if (referredNode == null) {
+ if (refNode == null) {
/*
* Check if prefix is null or not, to identify whether to search in
@@ -1247,7 +1251,7 @@
throw ex;
} else {
((Resolvable) entity).setResolvableStatus(INTER_FILE_LINKED);
- addUnresolvedRecursiveReferenceToStack((YangNode) referredNode);
+ addUnresolvedRecursiveReferenceToStack((YangNode) refNode);
}
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
index 83f4a1a..f049dbd 100644
--- a/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
+++ b/generator/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
@@ -20,6 +20,7 @@
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangInput;
@@ -48,7 +49,9 @@
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.ERROR_MSG_FOR_AUGMENT_LINKING;
import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_FIND_LEAD_INFO_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.IS_INVALID;
@@ -69,6 +72,7 @@
private Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes;
private String curPrefix;
private String constructsParentsPrefix;
+ private XpathLinkingTypes linkingType;
/**
* Creates an instance of x-path linker.
@@ -101,14 +105,16 @@
* @param atomicPaths atomic path node list
* @param root root node
* @param leafref instance of YANG leafref
+ * @param curLinking x path linking type
* @return linked target node
*/
T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root,
- YangLeafRef leafref) {
+ YangLeafRef leafref, XpathLinkingTypes curLinking) {
YangNode targetNode;
rootNode = root;
prefixResolverTypes = new HashMap<>();
+ linkingType = curLinking;
parsePrefixResolverList(atomicPaths);
YangAtomicPath leafRefPath = atomicPaths.get(atomicPaths.size() - 1);
@@ -191,15 +197,17 @@
/**
* Process absolute node path linking for augment.
*
- * @param paths absolute path node list
- * @param root root node
+ * @param paths absolute path node list
+ * @param root root node
+ * @param curLinking x path linker type
* @return linked target node
*/
- public YangNode processAugmentXpathLinking(List<YangAtomicPath> paths,
- YangNode root) {
+ public YangNode processXpathLinking(List<YangAtomicPath> paths,
+ YangNode root, XpathLinkingTypes curLinking) {
absPaths = paths;
rootNode = root;
prefixResolverTypes = new HashMap<>();
+ linkingType = curLinking;
parsePrefixResolverList(paths);
YangNode targetNode = parseData(root);
if (targetNode == null) {
@@ -237,8 +245,8 @@
/**
* Searches for the referred leaf-list in target node.
*
- * @param targetNode target node
- * @param name leaf-list name
+ * @param targetNode target node
+ * @param name leaf-list name
* @return target leaf-list
*/
private YangLeafList searchReferredLeafList(YangNode targetNode, String name) {
@@ -317,6 +325,7 @@
if (tempNode != null) {
tempPath.setResolvedNode(tempNode);
+ validateTempPathNode(tempNode);
}
if (index == absPaths.size() - 1) {
@@ -329,6 +338,29 @@
}
/**
+ * Validates temp path nodes for augment linking.
+ *
+ * @param node temp path node
+ */
+ private void validateTempPathNode(YangNode node) {
+
+ if (linkingType != AUGMENT_LINKING) {
+ return;
+ }
+ if (node instanceof YangGrouping) {
+ LinkerException ex = new LinkerException(
+ ERROR_MSG_FOR_AUGMENT_LINKING +
+ getAugmentNodeIdentifier(
+ absPaths.get(absPaths.size() - 1).getNodeIdentifier(),
+ absPaths,
+ rootNode));
+ ex.setFileName(rootNode.getFileName());
+ throw ex;
+
+ }
+ }
+
+ /**
* Resolves intra file augment linking.
*
* @param tempPath temporary absolute path
@@ -739,5 +771,4 @@
YangNode rootNode) {
((RpcNotificationContainer) rootNode).addToAugmentList(augment);
}
-
}
\ No newline at end of file
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index a2e78f3..346fba2 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -24,6 +24,7 @@
import static java.util.Collections.unmodifiableSortedSet;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
+import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
@@ -245,6 +246,15 @@
*
* @return import for to bitset method
*/
+ public String getImportForToBase64() {
+ return getImportString(JAVA_UTIL_PKG, BASE64);
+ }
+
+ /**
+ * Returns import for to bitset method.
+ *
+ * @return import for to bitset method
+ */
public String getImportForPattern() {
return getImportString(JAVA_UTIL_REGEX_PKG, PATTERN);
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index ec97d8e..0e1c132 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -26,6 +26,7 @@
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -90,6 +91,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
@@ -101,6 +103,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENT_MAP_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
@@ -118,14 +121,16 @@
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
+import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.YANG;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
@@ -261,6 +266,11 @@
private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
/**
+ *
+ */
+ private boolean isBinary;
+
+ /**
* Information about the java files being generated.
*/
private JavaFileInfoTranslator javaFileInfo;
@@ -760,8 +770,10 @@
String containedInCls = getCapitalCase(tempFiles.getJavaFileInfo()
.getJavaName());
String containedInPkg = tempFiles.getJavaFileInfo().getPackage();
- JavaQualifiedTypeInfoTranslator info = new JavaQualifiedTypeInfoTranslator();
- if (container.getDataType().getDataType() == YangDataTypes.BITS) {
+ JavaQualifiedTypeInfoTranslator info;
+ if (container.getDataType().getDataType() == YangDataTypes.BINARY) {
+ tempFiles.setBinary(true);
+ } else if (container.getDataType().getDataType() == YangDataTypes.BITS) {
//Add bitset import for type and leaf value flags.
info = new JavaQualifiedTypeInfoTranslator();
info.setClassInfo(BIT_SET);
@@ -1051,13 +1063,7 @@
throws IOException {
String setter = getSetterForClass(attr, getGeneratedJavaClassName(),
getGeneratedJavaFiles());
- if (rootNode) {
- appendToFile(setterImplTempFileHandle,
- getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
- attr.isListAttr(), null) + setter);
- } else {
- appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
- }
+ appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
}
/**
@@ -1070,12 +1076,8 @@
throws IOException {
String getter = getGetterForClass(attr, getGeneratedJavaFiles());
if (javaFlagSet(BUILDER_CLASS_MASK)) {
- if (!rootNode) {
- appendToFile(getterImplTempFileHandle, getOverRideString() +
- getter);
- } else {
- appendToFile(getterImplTempFileHandle, getter);
- }
+ appendToFile(getterImplTempFileHandle, getOverRideString() +
+ getter);
} else {
String appDataStructure = null;
if (attr.getCompilerAnnotation() != null) {
@@ -1111,8 +1113,8 @@
private void addAddToListImpl(JavaAttributeInfo attr)
throws IOException {
appendToFile(addToListImplTempFileHandle,
- getAddToListMethodImpl(attr, getGeneratedJavaClassName(),
- rootNode) + NEW_LINE);
+ getAddToListMethodImpl(attr, getGeneratedJavaClassName()
+ ) + NEW_LINE);
}
/**
@@ -1276,7 +1278,7 @@
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
- protected File getJavaFileHandle(String fileName)
+ public File getJavaFileHandle(String fileName)
throws IOException {
return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION,
javaFileInfo);
@@ -1455,15 +1457,93 @@
JavaQualifiedTypeInfoTranslator typeInfo =
new JavaQualifiedTypeInfoTranslator();
typeInfo.setClassInfo(OPERATION_TYPE_CLASS);
- typeInfo.setPkgInfo(((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getPackage());
+ JavaFileInfo curInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ JavaFileInfo info;
+ if (curNode instanceof RpcNotificationContainer) {
+ info = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ } else {
+ info = ((JavaFileInfoContainer) getModuleNode(curNode))
+ .getJavaFileInfo();
+ }
+
+ typeInfo.setPkgInfo(info.getPackage().toLowerCase() + PERIOD +
+ getCapitalCase(info.getJavaName()));
+ String curNodeName = getCapitalCase(curInfo.getJavaName());
+ if (!(curNode instanceof RpcNotificationContainer)) {
+ javaImportData.addImportInfo(typeInfo, curNodeName, curInfo
+ .getPackage());
+ }
JavaAttributeInfo attributeInfo =
- getAttributeInfoForTheData(typeInfo, YANG + getCapitalCase(
- curNode.getJavaClassNameOrBuiltInType()) +
+ getAttributeInfoForTheData(typeInfo, YANG + curNodeName +
OPERATION_TYPE_ATTRIBUTE, null, false, false);
addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
}
+ private YangNode getModuleNode(YangNode curNode) {
+ YangNode tempNode = curNode.getParent();
+ while (!(tempNode instanceof RpcNotificationContainer)) {
+ tempNode = tempNode.getParent();
+ }
+ return tempNode;
+ }
+
+ /**
+ * Adds value leaf flag to temp files.
+ *
+ * @param config YANG plugin config
+ * @param node YANG node
+ * @throws IOException IO exception
+ */
+ protected void addValueLeafFlag(YangPluginConfig config, YangNode node)
+ throws IOException {
+ JavaFileInfo info = ((JavaFileInfoContainer) node).getJavaFileInfo();
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ new JavaQualifiedTypeInfoTranslator();
+ typeInfo.setClassInfo(BIT_SET);
+ typeInfo.setPkgInfo(JAVA_UTIL_PKG);
+ this.getJavaImportData().addImportInfo(typeInfo, info.getJavaName(),
+ info.getPackage());
+ JavaAttributeInfo attributeInfo =
+ getAttributeInfoForTheData(typeInfo, VALUE_LEAF, null, false, false);
+ addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
+ }
+
+ /**
+ * Adds value leaf flag to temp files.
+ *
+ * @param config YANG plugin config
+ * @throws IOException IO exception
+ */
+ protected void addSelectLeafFlag(YangPluginConfig config)
+ throws IOException {
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ new JavaQualifiedTypeInfoTranslator();
+ typeInfo.setClassInfo(BIT_SET);
+ typeInfo.setPkgInfo(JAVA_UTIL_PKG);
+ JavaAttributeInfo attributeInfo =
+ getAttributeInfoForTheData(typeInfo, SELECT_LEAF, null, false, false);
+ addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
+ }
+
+ /**
+ * Adds value leaf flag to temp files.
+ *
+ * @param config YANG plugin config
+ * @throws IOException IO exception
+ */
+ protected void addYangAugmentedMap(YangPluginConfig config)
+ throws IOException {
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ new JavaQualifiedTypeInfoTranslator();
+ typeInfo.setClassInfo(AUGMENT_MAP_TYPE);
+ //Fix for add yangAugmentedInfo in equals/hashcode/and to string method.
+ typeInfo.setPkgInfo(null);
+ JavaAttributeInfo attributeInfo =
+ getAttributeInfoForTheData(typeInfo, YANG_AUGMENTED_INFO_MAP,
+ null, false, false);
+ addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
+ }
+
/**
* Adds the new attribute info to the target generated temporary files.
*
@@ -1475,16 +1555,20 @@
YangPluginConfig pluginConfig)
throws IOException {
isAttributePresent = true;
+ String attrName = newAttrInfo.getAttributeName();
+ boolean required = !attrName.equals(VALUE_LEAF) &&
+ !attrName.equals(SELECT_LEAF) &&
+ !attrName.equals(YANG_AUGMENTED_INFO_MAP);
if (tempFlagSet(ATTRIBUTES_MASK)) {
addAttribute(newAttrInfo);
}
if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
addGetterForInterface(newAttrInfo);
}
- if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
+ if (tempFlagSet(SETTER_FOR_INTERFACE_MASK) && required) {
addSetterForInterface(newAttrInfo);
}
- if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
+ if (tempFlagSet(SETTER_FOR_CLASS_MASK) && required) {
addSetterImpl(newAttrInfo);
}
if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
@@ -1508,8 +1592,8 @@
}
YangType attrType = newAttrInfo.getAttributeType();
if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
- attrType == null && !newAttrInfo.getAttributeName()
- .contains(OPERATION_TYPE_ATTRIBUTE)) {
+ attrType == null && !attrName
+ .contains(OPERATION_TYPE_ATTRIBUTE) && required) {
addSubtreeFilteringForChildNode(newAttrInfo);
}
if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
@@ -1607,31 +1691,35 @@
interfaceJavaFileHandle =
generateInterfaceFile(interfaceJavaFileHandle, imports,
curNode, isAttributePresent);
- if (!(curNode instanceof RpcNotificationContainer)) {
- //Create builder interface file.
- if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
- builderInterfaceJavaFileHandle =
- getJavaFileHandle(getJavaClassName(
- BUILDER_INTERFACE_FILE_NAME_SUFFIX));
- builderInterfaceJavaFileHandle =
- generateBuilderInterfaceFile(
- builderInterfaceJavaFileHandle,
- curNode, isAttributePresent);
+ //Create builder interface file.
+ if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
+ builderInterfaceJavaFileHandle =
+ getJavaFileHandle(getJavaClassName(
+ BUILDER_INTERFACE_FILE_NAME_SUFFIX));
+ builderInterfaceJavaFileHandle =
+ generateBuilderInterfaceFile(
+ builderInterfaceJavaFileHandle,
+ curNode, isAttributePresent);
/*
* Append builder interface file to interface file and
* close it.
*/
- mergeJavaFiles(builderInterfaceJavaFileHandle,
- interfaceJavaFileHandle);
- }
+ mergeJavaFiles(builderInterfaceJavaFileHandle,
+ interfaceJavaFileHandle);
}
+
insertDataIntoJavaFile(interfaceJavaFileHandle, CLOSE_CURLY_BRACKET);
validateLineLength(interfaceJavaFileHandle);
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, false, true, curNode);
}
}
+
+ if (!curNode.isOpTypeReq() && curNode instanceof YangCase) {
+ removeCaseParentImport(curNode, imports);
+ }
+
if ((fileType & BUILDER_CLASS_MASK) != 0 ||
(fileType & DEFAULT_CLASS_MASK) != 0) {
if (isAttributePresent) {
@@ -1642,7 +1730,9 @@
addBitsAndBase64Imports(curNode, imports);
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, true, false, curNode);
- addInvocationExceptionImport(imports);
+ if (curNode.isOpTypeReq()) {
+ addInvocationExceptionImport(imports);
+ }
}
sortImports(imports);
@@ -1675,6 +1765,15 @@
freeTemporaryResources(false);
}
+ //Removes case's parent import.
+ private void removeCaseParentImport(YangNode node, List<String> imports) {
+ YangNode parent = node.getParent();
+ JavaFileInfo info = ((JavaFileInfoContainer) parent).getJavaFileInfo();
+ String impt = getImportString(info.getPackage(),
+ getCapitalCase(info.getJavaName()));
+ imports.remove(impt);
+ }
+
//Adds import for array list.
private void addArrayListImport(List<String> imports) {
if (imports.contains(javaImportData.getImportForList())) {
@@ -1686,7 +1785,7 @@
private void addBitsAndBase64Imports(YangNode curNode, List<String> imports) {
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder holder = (YangLeavesHolder) curNode;
- String impt = this.getJavaImportData()
+ String impt = getJavaImportData()
.getImportForToBitSet();
if (!holder.getListOfLeaf().isEmpty() &&
!imports.contains(impt)) {
@@ -1939,4 +2038,22 @@
return bitsHandler;
}
+ /**
+ * Sets true if binary type is there for leaf/leaf-list.
+ *
+ * @param binary true if binary type is there for leaf/leaf-list
+ */
+ public void setBinary(boolean binary) {
+ isBinary = binary;
+ }
+
+ /**
+ * Returns true if binary type is there for leaf/leaf-list.
+ *
+ * @return true if binary type is there for leaf/leaf-list
+ */
+ public boolean isBinary() {
+ return isBinary;
+ }
+
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
index 1751ab5..474594d 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
@@ -148,18 +148,11 @@
*/
private void addRpcString(JavaAttributeInfo inAttr, JavaAttributeInfo outAttr,
String rpcName) throws IOException {
- String rpcInput = EMPTY_STRING;
- String rpcOutput = VOID;
- String rpcIn = EMPTY_STRING;
- if (inAttr != null) {
- rpcInput = getCapitalCase(inAttr.getAttributeName());
- }
- if (outAttr != null) {
- rpcOutput = getCapitalCase(outAttr.getAttributeName());
- }
- if (!rpcInput.equals(EMPTY_STRING)) {
- rpcIn = RPC_INPUT_VAR_NAME;
- }
+ String rpcInput = inAttr == null ? null :
+ getCapitalCase(inAttr.getAttributeName());
+ String rpcOutput = outAttr == null ? VOID :
+ getCapitalCase(outAttr.getAttributeName());
+ String rpcIn = rpcInput == null ? EMPTY_STRING : RPC_INPUT_VAR_NAME;
appendToFile(rpcInterfaceTempFileHandle,
generateJavaDocForRpc(rpcName, rpcIn, rpcOutput) +
getRpcServiceMethod(rpcName, rpcInput, rpcOutput));
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
index a30ed4b..431cf19 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
@@ -51,7 +52,9 @@
import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_TYPE_CONFLICT;
import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.LONG_TYPE_CONFLICT;
import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.SHORT_TYPE_CONFLICT;
+import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
@@ -264,6 +267,15 @@
if (type.getDataType() == BITS) {
addBitsHandler(javaAttributeInfo, type, this);
}
+ if (type.getDataType() == BINARY) {
+ JavaQualifiedTypeInfoTranslator info = new
+ JavaQualifiedTypeInfoTranslator();
+ info.setClassInfo(BASE64);
+ info.setPkgInfo(JAVA_UTIL_PKG);
+ getJavaImportData().addImportInfo(
+ info, getGeneratedJavaClassName(), getJavaFileInfo()
+ .getPackage());
+ }
addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo,
config, types);
}
@@ -603,7 +615,7 @@
}
createPackage(curNode);
- addImportsToStringAndHasCodeMethods(imports, true);
+ imports.add(getJavaImportData().getImportForHashAndEquals());
/*
* Creates type def class file.
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
index 2c019f6..0a433ee 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
@@ -38,6 +38,7 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -45,7 +46,10 @@
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
+import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_TRANSLATION_NODE;
@@ -54,13 +58,17 @@
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsgForCodeGenerator;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT_KEYWORD;
import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT_KEYWORD;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
/**
* Represents utility class for YANG java model.
@@ -233,6 +241,11 @@
}
}
if (info instanceof YangLeavesHolder) {
+ YangLeavesHolder holder = (YangLeavesHolder) info;
+ boolean isLeafPresent = holder.getListOfLeaf() != null && !holder
+ .getListOfLeaf().isEmpty();
+ boolean isLeafListPresent = holder.getListOfLeafList() != null &&
+ !holder.getListOfLeafList().isEmpty();
/*
* Container
* Case
@@ -242,12 +255,23 @@
* Notification
* Output
*/
- getBeanFiles(info).addCurNodeLeavesInfoToTempFiles((YangNode) info,
+ if (isLeafPresent || isLeafListPresent) {
+ getBeanFiles(info).addCurNodeLeavesInfoToTempFiles((YangNode) info,
+ config);
+ }
+ //Add value leaf flag attribute to temp file.
+ if (isLeafPresent) {
+ getBeanFiles(info).addValueLeafFlag(config, (YangNode) info);
+ }
+ if (((YangNode) info).isOpTypeReq()) {
+ // Add operation type as an attribute.
+ getBeanFiles(info).addOperationTypeToTempFiles((YangNode) info,
config);
-
- // Add operation type as an attribute.
- getBeanFiles(info).addOperationTypeToTempFiles((YangNode) info,
- config);
+ if (isLeafPresent) {
+ //Add select leaf flag attribute to temp file.
+ getBeanFiles(info).addSelectLeafFlag(config);
+ }
+ }
} else if (info instanceof YangTypeHolder) {
/*
* Typedef
@@ -381,7 +405,7 @@
*/
private static YangSchemaNode getRefSchema(JavaCodeGeneratorInfo info) {
- YangSchemaNode node = ((YangSchemaNode) info);
+ YangSchemaNode node = (YangSchemaNode) info;
if (node.getReferredSchema() == null) {
return null;
}
@@ -416,7 +440,9 @@
generateCodeOfNode(info, config);
TempJavaCodeFragmentFiles tempFiles =
info.getTempJavaCodeFragmentFiles();
-
+ if (!(info instanceof YangChoice)) {
+ getBeanFiles(info).addYangAugmentedMap(config);
+ }
if (info instanceof YangCase) {
YangNode parent = ((YangCase) info).getParent();
JavaQualifiedTypeInfoTranslator typeInfo =
@@ -658,9 +684,9 @@
String name = getCapitalCase(getCamelCase(identifier.getName(),
config.getConflictResolver()));
if (identifier.getPrefix() != null) {
- return AUGMENTED + getCapitalCase(
- getCamelCase(identifier.getPrefix(),
- config.getConflictResolver())) + name;
+ return getCapitalCase(getCamelCase(AUGMENTED + HYPHEN + identifier
+ .getPrefix(),
+ config.getConflictResolver())) + name;
}
return AUGMENTED + name;
}
@@ -672,14 +698,41 @@
* @param node current YANG node
* @throws IOException when fails to generate java files
*/
- public static void generateJava(int type, YangNode node)
+ public static void generateJava(int type, YangNode node)
throws IOException {
/*
* Call for file generation if node is not under uses.
*/
- if(node.getReferredSchema() == null) {
+ if (node.getReferredSchema() == null) {
((TempJavaCodeFragmentFilesContainer) node)
- .getTempJavaCodeFragmentFiles().generateJavaFile(type, node);
+ .getTempJavaCodeFragmentFiles().generateJavaFile(type, node);
}
}
+
+ /**
+ * Generates interface file for those yang file which contains only any
+ * of these grouping, typedef and identity.
+ *
+ * @param rootNode root node
+ * @throws IOException when fails to do IO operations
+ */
+ public static void generateInterfaceFileForNonDataNodes(YangNode rootNode) throws
+ IOException {
+ JavaCodeGeneratorInfo info = (JavaCodeGeneratorInfo) rootNode;
+ TempJavaCodeFragmentFiles tempFile = info
+ .getTempJavaCodeFragmentFiles();
+ JavaFileInfoTranslator fileInfo = info.getJavaFileInfo();
+ File filePath = new File(fileInfo.getBaseCodeGenPath() + fileInfo
+ .getPackageFilePath());
+ String name = getCapitalCase(fileInfo.getJavaName());
+ //Add package info file for this.
+ addPackageInfo(filePath, name, fileInfo.getPackage(), false);
+ //Generate file handle for this.
+ File interFace = tempFile.getBeanTempFiles().getJavaFileHandle(
+ name);
+ //generate java code for interface file.
+ validateLineLength(generateInterfaceFile(interFace, null, rootNode,
+ false));
+ insertDataIntoJavaFile(interFace, methodClose(FOUR_SPACE));
+ }
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
index 2d70219..00d7a19 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
@@ -532,7 +532,7 @@
* @param isList true if list, false otherwise
* @return import class
*/
- private static String getLeafRefImpClass(
+ public static String getLeafRefImpClass(
YangType type, YangToJavaNamingConflictUtil cnfg, boolean isList) {
YangType<?> rt = getReferredTypeFromLeafref(type);
return rt == null ? OBJECT_STRING : getJavaImportClass(rt, isList,
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugmentTranslator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugmentTranslator.java
index 1607b9f..ca964f1 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugmentTranslator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugmentTranslator.java
@@ -15,8 +15,6 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaAugment;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -26,8 +24,10 @@
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents augment information extended to support java code generation.
@@ -109,7 +109,7 @@
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
- generateCodeOfAugmentableNode(this, yangPlugin);
+ generateCodeOfNode(this, yangPlugin);
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for augmentable node " +
getName() + " in " +
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
index e0b0dad..668b1e9 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
@@ -34,6 +34,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateInterfaceFileForNonDataNodes;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
@@ -168,7 +169,9 @@
GENERATE_ALL_EVENT_CLASS_MASK, this);
}
- if (isRootNodesCodeGenRequired(this)) {
+ if (!isRootNodesCodeGenRequired(this)) {
+ generateInterfaceFileForNonDataNodes(this);
+ } else {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (getJavaFileInfo().getPluginConfig()
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
index 20fa8d2..62f2962 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
@@ -35,6 +35,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
+import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateInterfaceFileForNonDataNodes;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
@@ -180,7 +181,9 @@
getTempJavaCodeFragmentFiles().generateJavaFile(
GENERATE_ALL_EVENT_CLASS_MASK, this);
}
- if (isRootNodesCodeGenRequired(this)) {
+ if (!isRootNodesCodeGenRequired(this)) {
+ generateInterfaceFileForNonDataNodes(this);
+ } else {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (getJavaFileInfo().getPluginConfig()
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index 4c711bf..9abd058 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -164,8 +164,7 @@
* @return enum file class definition
*/
private static String getEnumClassDefinition(String yangName) {
- return trimAtLast(getDefaultDefinition(ENUM, yangName, PUBLIC),
- NEW_LINE);
+ return getDefaultDefinition(ENUM, yangName, PUBLIC);
}
/**
@@ -223,9 +222,6 @@
return clsDef;
}
}
- if (curNode instanceof RpcNotificationContainer) {
- return getDefaultDefinition(CLASS, bName, mod);
- }
return getDefaultDefinitionWithImpl(CLASS, bName, mod,
getBuilderImplStringClassDef(yangName));
}
@@ -409,11 +405,9 @@
.append(SPACE).append(EXTEND).append(SPACE);
def = new StringBuilder(getDefinitionString(def.toString(),
holder));
- if (!(curNode instanceof RpcNotificationContainer)) {
- def.append(SPACE).append(IMPLEMENTS).append(SPACE)
- .append(yangName).append(PERIOD)
- .append(yangName).append(BUILDER);
- }
+ def.append(SPACE).append(IMPLEMENTS).append(SPACE)
+ .append(yangName).append(PERIOD)
+ .append(yangName).append(BUILDER);
break;
case DEFAULT_CLASS_MASK:
if (curNode instanceof RpcNotificationContainer) {
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java
index 3b7b09c..e49bc4b 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java
@@ -19,7 +19,7 @@
/**
* Represents indentation type.
*/
-enum IndentationType {
+public enum IndentationType {
//Four space indentation.
FOUR_SPACE,
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index 916dd42..96db5c3 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -27,9 +27,7 @@
import java.util.List;
import static java.util.Collections.sort;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_DIAMOND;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinition;
@@ -37,7 +35,6 @@
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
@@ -53,19 +50,17 @@
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_DIAMOND_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.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.SCHEMA_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SET;
import static org.onosproject.yangutils.utils.UtilConstants.SET_VALUE_PARA;
@@ -80,7 +75,8 @@
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.enumJavaDocForInnerClass;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
@@ -147,8 +143,20 @@
}
attrDef.append(attrType).append(SPACE)
- .append(attrName).append(SEMI_COLON)
- .append(NEW_LINE);
+ .append(attrName);
+ //Initialize select leaf/value leaf/ augment map attribute.
+ if (attrName.equals(SELECT_LEAF) || attrName.equals(VALUE_LEAF)) {
+ attrDef.append(SPACE).append(EQUAL).append(SPACE).append(NEW)
+ .append(SPACE).append(BIT_SET)
+ .append(OPEN_CLOSE_BRACKET_STRING);
+ } else if (attrName.equals(YANG_AUGMENTED_INFO_MAP)) {
+ attrDef.append(SPACE).append(EQUAL).append(SPACE).append(NEW)
+ .append(SPACE).append(HASH_MAP)
+ .append(OPEN_CLOSE_DIAMOND_STRING)
+ .append(OPEN_CLOSE_BRACKET_STRING);
+ }
+
+ attrDef.append(signatureClose());
} else {
// Add starting definition.
addAttrStartDef(annotation, attrDef);
@@ -208,13 +216,11 @@
if (annotation != null &&
annotation.getYangAppDataStructure() != null) {
attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE)
- .append(attrName).append(SEMI_COLON)
- .append(NEW_LINE);
+ .append(attrName).append(signatureClose());
} else {
attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE).append(attrName)
.append(SPACE).append(EQUAL).append(SPACE).append(NEW)
- .append(SPACE).append(ARRAY_LIST).append(SEMI_COLON)
- .append(NEW_LINE);
+ .append(SPACE).append(ARRAY_LIST).append(signatureClose());
}
}
@@ -327,32 +333,6 @@
}
/**
- * Returns attribute for augmentation.
- *
- * @return attribute for augmentation
- */
- static String addAugmentationAttribute() {
- String[] array = {NEW_LINE, SEMI_COLON};
- return trimAtLast(getJavaAttributeDefinition(
- null, getAugmentMapTypeString(),
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP, false, PROTECTED,
- null), array) + SPACE + EQUAL + SPACE + NEW + SPACE +
- HASH_MAP + brackets(OPEN_CLOSE_DIAMOND, null, null) + brackets(
- OPEN_CLOSE_BRACKET, null, null) + signatureClose();
- }
-
- /**
- * Returns augment map return type.
- *
- * @return augment map return type
- */
- static String getAugmentMapTypeString() {
- return MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
- QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE +
- OBJECT_STRING + DIAMOND_CLOSE_BRACKET;
- }
-
- /**
* Adds attribute for int ranges.
*
* @param modifier modifier for attribute
@@ -437,7 +417,7 @@
" * Applicable in protocol edit operation, not applicable" +
" in query operation\n" +
" */\n" +
- " public enum OnosYangNodeOperationType {\n" +
+ " public static enum OnosYangOpType {\n" +
" MERGE,\n" +
" REPLACE,\n" +
" CREATE,\n" +
@@ -448,36 +428,6 @@
}
/**
- * Returns operation type enum, leaf value set attribute and select leaf
- * attribute.
- *
- * @return operation attributes for value and select leaf flags
- */
- static String getOperationAttributes() {
- return " /**\n" +
- " * Identify the leafs whose value are explicitly set\n" +
- " * Applicable in protocol edit and query operation\n" +
- " */\n" +
- " private BitSet valueLeafFlags = new BitSet();\n" +
- "\n" +
- " /**\n" +
- " * Identify the leafs to be selected, in a query operation\n" +
- " */\n" +
- " private BitSet selectLeafFlags = new BitSet();\n";
- }
-
- /**
- * Returns operation type enum, leaf value set attribute and select leaf
- * attribute for constructor.
- *
- * @return operation attributes for constructor
- */
- static String getOperationAttributeForConstructor() {
- return " this.valueLeafFlags = builderObject.getValueLeafFlags();\n" +
- " this.selectLeafFlags = builderObject.getSelectLeafFlags();\n";
- }
-
- /**
* Returns attribute in constructor for yang augmented info map.
*
* @return augment info map
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index 979df3a..2033d2d 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -85,16 +85,12 @@
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getQualifierInfoForCasesParent;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGetSetOfRootNodeRequired;
+import static org.onosproject.yangutils.translator.tojava.utils.BitsJavaInfoHandler.generateBitsFile;
import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributeForConstructor;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributes;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeEnum;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getSetValueParaForUnionClass;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getYangAugmentedMapObjectForConstruct;
-import static org.onosproject.yangutils.translator.tojava.utils.BitsJavaInfoHandler.generateBitsFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.ENUM_METHOD_INT_VALUE;
@@ -120,20 +116,20 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringForEnumClass;
+import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringForType;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getUnionToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapImpl;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isLeafValueSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.processSubtreeFilteringInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getGettersForValueAndSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getInterfaceLeafIdEnumMethods;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOperationAttributesGetters;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIsSelectLeafSet;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIsValueLeafSet;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getAugmentableSubTreeFiltering;
@@ -169,14 +165,13 @@
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.UNION_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
+import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.replaceLast;
@@ -234,8 +229,9 @@
className);
// Generate ENUM interface
- insertDataIntoJavaFile(file, getOperationTypeEnum());
-
+ if (curNode instanceof RpcNotificationContainer) {
+ insertDataIntoJavaFile(file, getOperationTypeEnum());
+ }
List<String> methods = new ArrayList<>();
if (attrPresent) {
// Add getter methods to interface file.
@@ -263,23 +259,25 @@
if (curNode instanceof YangAugmentableNode &&
!(curNode instanceof YangChoice)) {
methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface());
}
-
- if (curNode instanceof YangCase) {
- YangNode caseParent = curNode.getParent();
- JavaQualifiedTypeInfo qualifiedTypeInfo =
- getQualifierInfoForCasesParent(caseParent,
- fileInfo.getPluginConfig());
- methods.add(processSubtreeFilteringInterface(
- qualifiedTypeInfo.getClassInfo()));
- } else {
- methods.add(processSubtreeFilteringInterface(className));
+ if (curNode.isOpTypeReq()) {
+ if (curNode instanceof YangCase) {
+ YangNode caseParent = curNode.getParent();
+ JavaQualifiedTypeInfo qualifiedTypeInfo =
+ getQualifierInfoForCasesParent(caseParent,
+ fileInfo.getPluginConfig());
+ methods.add(processSubtreeFilteringInterface(
+ qualifiedTypeInfo.getClassInfo()));
+ } else {
+ methods.add(processSubtreeFilteringInterface(className));
+ }
}
if (leavesPresent) {
methods.add(isLeafValueSetInterface());
- methods.add(isSelectLeafSetInterface());
+ if (curNode.isOpTypeReq()) {
+ methods.add(isSelectLeafSetInterface());
+ }
}
for (String method : methods) {
insertDataIntoJavaFile(file, method);
@@ -305,7 +303,8 @@
boolean leavesPresent;
YangLeavesHolder leavesHolder;
- if (curNode instanceof YangLeavesHolder) {
+ if (curNode instanceof YangLeavesHolder &&
+ curNode.isOpTypeReq()) {
leavesHolder = (YangLeavesHolder) curNode;
leavesPresent = leavesPresent(leavesHolder);
} else {
@@ -347,9 +346,8 @@
if (curNode instanceof YangAugmentableNode &&
!(curNode instanceof YangChoice)) {
- methods.add(getAddAugmentInfoMethodInterface());
+ methods.add(getAddAugmentInfoMethodInterface(className + BUILDER));
methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface());
}
if (leavesPresent) {
@@ -395,10 +393,8 @@
}
String className = getCapitalCase(fileInfo.getJavaName());
- boolean isRootNode = false;
String path;
if (curNode instanceof RpcNotificationContainer) {
- isRootNode = true;
path = fileInfo.getPluginConfig().getCodeGenDir() +
fileInfo.getPackageFilePath();
} else {
@@ -409,10 +405,6 @@
initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode,
className);
List<String> methods = new ArrayList<>();
-
- if (curNode instanceof YangAugmentableNode) {
- insertDataIntoJavaFile(file, addAugmentationAttribute());
- }
if (attrPresent) {
//Add attribute strings.
@@ -422,10 +414,6 @@
} catch (IOException e) {
throw new IOException(getErrorMsg(className, BUILDER_CLASS));
}
-
- if (leavesPresent) {
- insertDataIntoJavaFile(file, getOperationAttributes());
- }
try {
//Getter methods.
methods.add(getDataFromTempFileHandle(
@@ -441,10 +429,9 @@
insertDataIntoJavaFile(file, NEW_LINE);
//Add operation attribute methods.
- if (leavesPresent) {
- methods.add(getOperationAttributesGetters());
+ if (leavesPresent && curNode.isOpTypeReq()) {
insertDataIntoJavaFile(file, NEW_LINE);
- methods.add(getSetterForSelectLeaf(className, isRootNode));
+ methods.add(getSetterForSelectLeaf(className));
}
} catch (IOException e) {
throw new IOException(getErrorMsg(className, BUILDER_CLASS));
@@ -454,9 +441,8 @@
}
if (curNode instanceof YangAugmentableNode) {
- methods.add(getAddAugmentInfoMethodImpl());
+ methods.add(getAddAugmentInfoMethodImpl(className + BUILDER));
methods.add(getYangAugmentInfoImpl());
- methods.add(getYangAugmentInfoMapImpl());
}
// Add default constructor and build method impl.
@@ -520,64 +506,52 @@
className);
List<String> methods = new ArrayList<>();
- if (curNode instanceof YangAugmentableNode) {
- insertDataIntoJavaFile(file, addAugmentationAttribute());
- }
if (attrPresent) {
addDefaultClassAttributeInfo(file, curNode, className,
opParamClassName, path, methods,
- leavesPresent, rootNode);
+ rootNode);
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
if (curNode instanceof YangAugmentableNode) {
methods.add(getYangAugmentInfoImpl());
- methods.add(getYangAugmentInfoMapImpl());
}
try {
//Constructor.
- String constructor =
- getConstructorStart(className, rootNode);
- constructor = constructor +
+ String constructor = getConstructorStart(className, rootNode) +
getDataFromTempFileHandle(
- CONSTRUCTOR_IMPL_MASK, getBeanFiles(curNode), path);
-
- if (leavesPresent) {
- constructor = constructor +
- getOperationAttributeForConstructor();
- }
- String augmentableSubTreeFiltering = EMPTY_STRING;
- if (curNode instanceof YangAugmentableNode) {
- constructor = constructor +
- getYangAugmentedMapObjectForConstruct();
-
- // add is filter content match.
- augmentableSubTreeFiltering = getAugmentableSubTreeFiltering();
- }
- methods.add(constructor + methodClose(FOUR_SPACE));
-
- methods.add(getProcessSubtreeFilteringStart(curNode, config) +
- getProcessSubtreeFunctionBody(curNode) +
- augmentableSubTreeFiltering +
- getProcessSubTreeFilteringEnd());
-
- if (curNode instanceof YangLeavesHolder) {
- if (((YangLeavesHolder) curNode).getListOfLeaf() != null &&
- !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
- methods.add(getProcessLeafSubtreeFiltering(curNode, config,
- path));
+ CONSTRUCTOR_IMPL_MASK, getBeanFiles(curNode), path)
+ + methodClose(FOUR_SPACE);
+ methods.add(constructor);
+ if (curNode.isOpTypeReq()) {
+ String augmentableSubTreeFiltering = EMPTY_STRING;
+ if (curNode instanceof YangAugmentableNode) {
+ // add is filter content match.
+ augmentableSubTreeFiltering = getAugmentableSubTreeFiltering();
}
- if (((YangLeavesHolder) curNode).getListOfLeafList() != null &&
- !((YangLeavesHolder) curNode).getListOfLeafList().isEmpty()) {
- methods.add(getProcessLeafListSubtreeFiltering(curNode, config,
+ methods.add(getProcessSubtreeFilteringStart(curNode, config) +
+ getProcessSubtreeFunctionBody(curNode) +
+ augmentableSubTreeFiltering +
+ getProcessSubTreeFilteringEnd());
+
+ if (curNode instanceof YangLeavesHolder) {
+ if (((YangLeavesHolder) curNode).getListOfLeaf() != null &&
+ !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
+ methods.add(getProcessLeafSubtreeFiltering(curNode, config,
path));
+ }
+ if (((YangLeavesHolder) curNode).getListOfLeafList() != null &&
+ !((YangLeavesHolder) curNode).getListOfLeafList().isEmpty()) {
+ methods.add(getProcessLeafListSubtreeFiltering(curNode, config,
+ path));
+ }
}
- }
- if (curNode.getChild() != null) {
- methods.add(getProcessChildNodeSubtreeFiltering(curNode, config,
- path));
+ if (curNode.getChild() != null) {
+ methods.add(getProcessChildNodeSubtreeFiltering(curNode, config,
+ path));
+ }
}
} catch (IOException e) {
throw new IOException(getErrorMsg(className, IMPL_CLASS));
@@ -587,8 +561,10 @@
methods.add(builderMethod(className));
if (leavesPresent) {
- methods.add(getOperationAttributesGetters());
- methods.add(getGettersForValueAndSelectLeaf());
+ methods.add(getIsValueLeafSet());
+ if (curNode.isOpTypeReq()) {
+ methods.add(getIsSelectLeafSet());
+ }
}
// Add methods in impl class.
for (String method : methods) {
@@ -607,7 +583,6 @@
* @param opParamClassName op param class name
* @param path file path
* @param methods list of methods string
- * @param leavesPresent flag indicating presence of leaves
* @param rootNode flag indicating whether node is root node
* @throws IOException a violation in IO rule
*/
@@ -615,7 +590,6 @@
String className,
String opParamClassName,
String path, List<String> methods,
- boolean leavesPresent,
boolean rootNode)
throws IOException {
@@ -627,11 +601,6 @@
throw new IOException(getErrorMsg(className, IMPL_CLASS));
}
- //Add operation attributes
- if (leavesPresent) {
- insertDataIntoJavaFile(file, getOperationAttributes());
- }
-
try {
//Getter methods.
methods.add(getDataFromTempFileHandle(
@@ -786,10 +755,13 @@
List<String> methods, String path)
throws IOException {
//To string method.
- methods.add(getToStringMethodOpen() +
- getDataFromTempFileHandle(
- TO_STRING_IMPL_MASK, getTypeFiles(curNode), path) +
- getToStringMethodClose());
+
+ List<YangType<?>> types = ((YangTypeDef) curNode).getTypeList();
+ YangType type = types.get(0);
+ String className = ((JavaFileInfoContainer) curNode).getJavaFileInfo()
+ .getJavaName();
+ methods.add(getToStringForType(getCamelCase(type.getDataTypeName(),
+ null), type, getCapitalCase(className)));
for (BitsJavaInfoHandler handler : getTypeFiles(curNode)
.getBitsHandler()) {
generateBitsFile(handler.getAttr(), handler.getYangType(), curNode);
@@ -904,7 +876,7 @@
//To string method.
methods.add(getUnionToStringMethod(
- ((YangUnion) curNode).getTypeList()));
+ ((YangUnion) curNode).getTypeList(), getCapitalCase(className)));
for (BitsJavaInfoHandler handler : getTypeFiles(curNode)
.getBitsHandler()) {
@@ -1009,8 +981,6 @@
if (!enumFile.isEnumClass()) {
imports.add(data.getImportForToBitSet());
imports.add(data.getImportForPattern());
- imports.add(data.getImportForToString());
-
}
initiateJavaFileGeneration(file, getCapitalCase(className),
@@ -1052,16 +1022,13 @@
null) +
getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
- insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, SCHEMA_NAME, false,
- null) +
- getGetter(STRING_DATA_TYPE, SCHEMA_NAME, GENERATE_ENUM_CLASS) +
- NEW_LINE);
-
if (!enumFile.isEnumClass()) {
insertDataIntoJavaFile(file, getBitSetEnumClassFromString
(getCapitalCase(className)));
insertDataIntoJavaFile(file, getBitSetEnumClassToString(
getCapitalCase(className), (YangEnumeration) curNode));
+ } else {
+ insertDataIntoJavaFile(file, getToStringForEnumClass());
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
index e22465c..818351d 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -21,6 +21,7 @@
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
@@ -98,11 +99,11 @@
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
@@ -452,7 +453,7 @@
break;
case DEFAULT_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
- write(file, genType, IMPL_CLASS, curNode, className);
+ write(file, genType, DEFAULT_CLASS, curNode, className);
break;
case BUILDER_CLASS_MASK:
write(file, genType, BUILDER_CLASS, curNode, className);
@@ -505,11 +506,11 @@
switch (genType) {
case GENERATE_TYPEDEF_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, IMPL_CLASS);
+ write(file, fileName, genType, DEFAULT_CLASS);
break;
case GENERATE_UNION_CLASS:
appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, IMPL_CLASS);
+ write(file, fileName, genType, DEFAULT_CLASS);
break;
case GENERATE_ENUM_CLASS:
appendHeaderContents(file, pkgString, importsList);
@@ -664,6 +665,15 @@
*/
public static void addResolvedAugmentedDataNodeImports(YangNode parent) {
List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
+ if (targets.isEmpty()) {
+ return;
+ }
+
+ YangNode node = targets.get(0).getResolvedNode();
+ if (node instanceof YangNotification) {
+ return;
+ }
+
TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = (
(JavaCodeGeneratorInfo) parent)
.getTempJavaCodeFragmentFiles();
@@ -795,7 +805,7 @@
YangType<?> attributeType) {
if (attributeName.equalsIgnoreCase(LEAFREF)) {
YangLeafRef leafRef = (YangLeafRef) attributeType.getDataTypeExtendedInfo();
- if (!leafRef.isInGrouping()) {
+ if (leafRef != null && !leafRef.isInGrouping()) {
return attributeType.getDataTypeName();
}
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index a35ea24..77bf0f2 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -20,7 +20,9 @@
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
+import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
@@ -39,13 +41,11 @@
import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.EIGHT_SPACE;
import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWELVE_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentMapTypeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getCurNodeName;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_ADD;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_GETTER;
import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_GET_VALUE;
import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.GETTER;
import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.MANAGER_METHODS;
@@ -62,7 +62,6 @@
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIfConditionBegin;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getLesserThanCondition;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getListAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getMoreObjectAttr;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getNewInstance;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getNewLineAndSpace;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOmitNullValueString;
@@ -73,6 +72,8 @@
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getReturnOfSubString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getReturnString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getSetValueParaCondition;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getStringBuilderAttr;
+import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getToStringCall;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getTrySubString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getValueLeafSetString;
import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifAndAndCondition;
@@ -87,6 +88,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.ADD;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
+import static org.onosproject.yangutils.utils.UtilConstants.APPEND;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
@@ -110,6 +112,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
@@ -121,11 +124,11 @@
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.GET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER;
+import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.HELPER;
import static org.onosproject.yangutils.utils.UtilConstants.IF;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
@@ -133,7 +136,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
@@ -144,6 +146,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OF;
+import static org.onosproject.yangutils.utils.UtilConstants.OF_CAPS;
import static org.onosproject.yangutils.utils.UtilConstants.ONE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
@@ -156,6 +159,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
+import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
@@ -170,6 +174,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
+import static org.onosproject.yangutils.utils.UtilConstants.STRING_BUILDER_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
@@ -327,16 +332,13 @@
/**
* Returns build method string.
*
- * @param name class name
- * @param isRootNode if root node
+ * @param name class name
+ * @param isRoot true if root node
* @return build string
*/
- public static String getBuildString(String name, boolean isRootNode) {
- if (isRootNode) {
- return NEW_LINE + getBuild(name, true);
- }
+ public static String getBuildString(String name, boolean isRoot) {
return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE +
- getBuild(name, false);
+ getBuild(name, isRoot);
}
/**
@@ -679,10 +681,7 @@
*/
public static String getRpcServiceMethod(String rpcName, String input,
String output) {
- String inputVal = EMPTY_STRING;
- if (!input.equals(EMPTY_STRING)) {
- inputVal = RPC_INPUT_VAR_NAME;
- }
+ String inputVal = input == null ? null : RPC_INPUT_VAR_NAME;
return methodSignature(rpcName, EMPTY_STRING, null,
inputVal, output, input, INTERFACE_TYPE) +
NEW_LINE;
@@ -842,7 +841,7 @@
}
/**
- * Returns to string converter for binary type.
+ * Returns from string converter for binary type.
*
* @param var variable name
* @return to string method body
@@ -856,6 +855,21 @@
}
/**
+ * Returns to string converter for binary type.
+ *
+ * @param var variable name
+ * @return to string method body
+ */
+ private static String getToStringForBinary(String var) {
+ StringBuilder builder = new StringBuilder();
+ return builder.append(BASE64).append(PERIOD)
+ .append(GET_ENCODER).append(OPEN_CLOSE_BRACKET_STRING)
+ .append(PERIOD).append(ENCODE_TO_STRING)
+ .append(brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, var, null))
+ .toString();
+ }
+
+ /**
* Returns hash code method open strings.
*
* @return hash code method open string
@@ -1133,34 +1147,38 @@
/**
* Returns interface of add augmentation.
*
+ * @param className class name
* @return interface of add augmentation
*/
- static String getAddAugmentInfoMethodInterface() {
+ static String getAddAugmentInfoMethodInterface(String className) {
StringBuilder builder = new StringBuilder(generateForAddAugmentation());
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put(VALUE, OBJECT_STRING);
map.put(CLASS + OBJECT_STRING, CLASS_STRING);
builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
EMPTY_STRING, EMPTY_STRING,
- VOID, map, INTERFACE_TYPE));
+ className, map, INTERFACE_TYPE));
return builder.toString();
}
/**
* Returns implementation of add augmentation.
*
+ * @param className class name
* @return implementation of add augmentation
*/
- static String getAddAugmentInfoMethodImpl() {
+ static String getAddAugmentInfoMethodImpl(String className) {
StringBuilder builder = new StringBuilder(getOverRideString());
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put(VALUE, OBJECT_STRING);
map.put(CLASS + OBJECT_STRING, CLASS_STRING);
builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
EMPTY_STRING, PUBLIC,
- VOID, map, CLASS_TYPE))
+ className, map, CLASS_TYPE))
.append(methodBody(AUGMENTED_MAP_ADD, null, null,
EIGHT_SPACE_INDENTATION, null, null, false, null))
+ .append(getReturnString(THIS, EIGHT_SPACE_INDENTATION))
+ .append(signatureClose())
.append(methodClose(FOUR_SPACE))
.append(NEW_LINE);
return builder.toString();
@@ -1194,34 +1212,6 @@
}
/**
- * Returns implementation of get YANG augment info.
- *
- * @return implementation of get YANG augment info
- */
- static String getYangAugmentInfoMapInterface() {
- return NEW_LINE +
- getJavaDoc(GETTER_METHOD, YANG_AUGMENTED_INFO_LOWER_CASE + MAP,
- false, null) +
- methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE + MAP,
- EMPTY_STRING, null, null,
- getAugmentMapTypeString(), null, INTERFACE_TYPE);
- }
-
- /**
- * Returns implementation of get YANG augment info.
- *
- * @return implementation of get YANG augment info
- */
- static String getYangAugmentInfoMapImpl() {
- return getOverRideString() + methodSignature(
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP, EMPTY_STRING, PUBLIC, null,
- getAugmentMapTypeString(), null, CLASS_TYPE) +
- methodBody(AUGMENTED_MAP_GETTER, null, null,
- EIGHT_SPACE_INDENTATION, null, null, false, null) +
- methodClose(FOUR_SPACE);
- }
-
- /**
* Returns enum's constructor.
*
* @param className enum's class name
@@ -1340,6 +1330,15 @@
*/
static String getAugmentsDataMethodForService(YangNode parent) {
List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
+ if (targets.isEmpty()) {
+ return EMPTY_STRING;
+ }
+ YangNode first = targets.get(0).getResolvedNode();
+ //If target path is for notification then no need to generate get/set
+ // for that augment in service class.
+ if (first instanceof YangNotification) {
+ return EMPTY_STRING;
+ }
YangNode augmentedNode;
String curNodeName;
String method;
@@ -1472,19 +1471,14 @@
/**
* Returns add to list method impl.
*
- * @param attr java attribute
- * @param name class name
- * @param isRoot is root
+ * @param attr java attribute
+ * @param name class name
* @return add to list method impl
*/
public static String getAddToListMethodImpl(JavaAttributeInfo attr,
- String name,
- boolean isRoot) {
+ String name) {
String attrName = attr.getAttributeName();
- String retString = EMPTY_STRING;
- if (!isRoot) {
- retString = getOverRideString();
- }
+ String retString = getOverRideString();
StringBuilder builder = new StringBuilder(retString);
builder.append(methodSignature(ADD_STRING + TO_CAPS +
getCapitalCase(attrName),
@@ -1625,20 +1619,15 @@
/**
* Returns setter for select leaf.
*
- * @param name name of node
- * @param isRootNode if root node
+ * @param name name of node
* @return setter for select leaf
*/
- static String getSetterForSelectLeaf(String name, boolean isRootNode) {
- String append = OVERRIDE;
- if (isRootNode) {
- append = EMPTY_STRING;
- }
+ static String getSetterForSelectLeaf(String name) {
return "\n" +
- " " + append + "\n" +
+ " " + OVERRIDE + "\n" +
" public " + name + BUILDER +
" selectLeaf(LeafIdentifier leaf) {\n" +
- " getSelectLeafFlags().set(leaf.getLeafIndex());\n" +
+ " selectLeafFlags.set(leaf.getLeafIndex());\n" +
" return this;\n" +
" }\n";
}
@@ -1687,30 +1676,101 @@
return sBuild.toString();
}
+
+ /**
+ * Returns to string method for typedef.
+ *
+ * @param attr attribute name
+ * @param className class name
+ * @return to string method for typedef
+ */
+ static String getToStringForType(String attr, YangType type,
+ String className) {
+ StringBuilder builder = new StringBuilder(getOverRideString())
+ .append(methodSignature(TO_STRING_METHOD, null, PUBLIC, null,
+ STRING_DATA_TYPE, null, CLASS_TYPE));
+ builder.append(getReturnString(
+ getToStringForSpecialType(className, type, attr), EIGHT_SPACE_INDENTATION))
+ .append(signatureClose()).append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
+
+ /**
+ * Returns to string method body for type class.
+ *
+ * @param className class name
+ * @param type type of attribute
+ * @param name @return to string method body for typedef class
+ */
+ private static String getToStringForSpecialType(String className, YangType type,
+ String name) {
+ switch (type.getDataType()) {
+ case INT8:
+ case INT16:
+ case INT32:
+ case INT64:
+ case UINT8:
+ case UINT16:
+ case UINT32:
+ return STRING_DATA_TYPE + PERIOD + VALUE + OF_CAPS + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, name, null);
+
+ case BINARY:
+ return getToStringCall(getToStringForBinary(name));
+
+ case BITS:
+ return className + getCapitalCase(name) + PERIOD +
+ TO_STRING_METHOD + brackets(
+ OPEN_CLOSE_BRACKET_WITH_VALUE, name, null);
+
+ case BOOLEAN:
+ case EMPTY:
+ return name + SPACE + QUESTION_MARK + SPACE + getQuotedString(TRUE)
+ + SPACE + COLON + SPACE + getQuotedString(FALSE);
+
+ case LEAFREF:
+ YangLeafRef<?> lri = (YangLeafRef<?>) type.getDataTypeExtendedInfo();
+ YangType<?> rt = lri.isInGrouping() ? null : lri
+ .getEffectiveDataType();
+ return rt == null ? getToStringCall(name) :
+ getToStringForSpecialType(className, rt, name);
+
+ case ENUMERATION:
+ case INSTANCE_IDENTIFIER:
+ case UINT64:
+ case DECIMAL64:
+ case DERIVED:
+ case IDENTITYREF:
+ case UNION:
+ return getToStringCall(name);
+
+ default:
+ return name;
+ }
+ }
+
/**
* Returns union class's to string method.
*
* @param types list of types
+ * @param name class name
* @return union class's to string method
*/
- static String getUnionToStringMethod(List<YangType<?>> types) {
+ static String getUnionToStringMethod(List<YangType<?>> types, String name) {
StringBuilder builder = new StringBuilder(getOverRideString());
builder.append(methodSignature(TO_STRING_METHOD, null, PUBLIC, null,
- STRING_DATA_TYPE, null, CLASS_TYPE))
- .append(getMoreObjectAttr());
+ STRING_DATA_TYPE, null, CLASS_TYPE));
for (YangType type : types) {
builder.append(getIfConditionBegin(
EIGHT_SPACE_INDENTATION, getSetValueParaCondition(
- types.indexOf(type))))
- .append(TWELVE_SPACE_INDENTATION).append(HELPER).append(
- methodBody(TO_STRING, getCamelCase(type.getDataTypeName()
- , null), null, EMPTY_STRING, null, null, false, null))
+ types.indexOf(type)))).append(getReturnString(
+ getToStringForSpecialType(name, type,
+ getCamelCase(type.getDataTypeName(), null)),
+ TWELVE_SPACE_INDENTATION))
.append(signatureClose()).append(methodClose(EIGHT_SPACE));
}
- builder.append(getReturnString(HELPER, EIGHT_SPACE_INDENTATION))
- .append(PERIOD).append(TO_STRING_METHOD)
- .append(OPEN_CLOSE_BRACKET_STRING).append(signatureClose())
+ builder.append(getReturnString(NULL, EIGHT_SPACE_INDENTATION)).append(signatureClose())
.append(methodClose(FOUR_SPACE));
return builder.toString();
}
@@ -1726,13 +1786,21 @@
getFromStringForBits(className);
}
+ /**
+ * Returns to string method for bits type.
+ *
+ * @param className class name
+ * @param enumeration enumeration
+ * @return to string method
+ */
static String getBitSetEnumClassToString(String className,
YangEnumeration enumeration) {
StringBuilder builder = new StringBuilder();
- builder.append(methodSignature(TO_STRING_METHOD, null, PUBLIC, BITS,
+ builder.append(methodSignature(TO_STRING_METHOD, null,
+ PUBLIC + SPACE + STATIC, BITS,
STRING_DATA_TYPE, BIT_SET, CLASS_TYPE))
- .append(getMoreObjectAttr());
+ .append(getStringBuilderAttr(EMPTY_STRING, EIGHT_SPACE_INDENTATION));
String condition;
String name;
for (YangEnum yangEnum : enumeration.getEnumSet()) {
@@ -1745,16 +1813,34 @@
builder.append(getIfConditionBegin(
EIGHT_SPACE_INDENTATION, condition))
- .append(TWELVE_SPACE_INDENTATION).append(HELPER).append(
- PERIOD).append(ADD_STRING).append(OPEN_PARENTHESIS)
- .append(getQuotedString(name)).append(COMMA).append(SPACE)
+ .append(TWELVE_SPACE_INDENTATION).append(STRING_BUILDER_VAR).append(
+ PERIOD).append(APPEND).append(OPEN_PARENTHESIS)
.append(getQuotedString(name)).append(CLOSE_PARENTHESIS)
+ .append(signatureClose())
+ .append(TWELVE_SPACE_INDENTATION).append(STRING_BUILDER_VAR).append(
+ PERIOD).append(APPEND).append(OPEN_PARENTHESIS)
+ .append(getQuotedString(SPACE)).append(CLOSE_PARENTHESIS)
.append(signatureClose()).append(methodClose(EIGHT_SPACE));
}
- builder.append(getReturnString(HELPER, EIGHT_SPACE_INDENTATION))
+ builder.append(getReturnString(STRING_BUILDER_VAR, EIGHT_SPACE_INDENTATION))
.append(PERIOD).append(TO_STRING_METHOD)
.append(OPEN_CLOSE_BRACKET_STRING).append(signatureClose())
.append(methodClose(FOUR_SPACE));
return builder.toString();
}
+
+ /**
+ * Returns to string method for enum class.
+ *
+ * @return to string method for enum class
+ */
+ static String getToStringForEnumClass() {
+ StringBuilder builder = new StringBuilder(getOverRideString());
+ builder.append(methodSignature(TO_STRING_METHOD, EMPTY_STRING,
+ PUBLIC, null, STRING_DATA_TYPE, null,
+ CLASS_TYPE));
+ builder.append(getReturnString(SCHEMA_NAME, EIGHT_SPACE_INDENTATION))
+ .append(signatureClose()).append(methodClose(FOUR_SPACE));
+ return builder.toString();
+ }
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
index c0d05b0..9dfbf80 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
@@ -76,7 +76,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.GET;
-import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.IF;
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
@@ -90,7 +90,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.MORE_OBJ_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
@@ -127,6 +126,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.STRING_BUILDER_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
+import static org.onosproject.yangutils.utils.UtilConstants.TO_STRING_METHOD;
import static org.onosproject.yangutils.utils.UtilConstants.TRY;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
@@ -138,7 +138,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
@@ -243,7 +243,7 @@
* @param type indentation type
* @return method close string
*/
- static String methodClose(IndentationType type) {
+ public static String methodClose(IndentationType type) {
switch (type) {
case EIGHT_SPACE:
return EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
@@ -288,6 +288,7 @@
String paramType, boolean isBuilderSetter, String setterVal) {
StringBuilder builder = new StringBuilder();
String body;
+ String cond;
switch (type) {
case GETTER:
return getReturnString(paraName, space);
@@ -325,18 +326,18 @@
signatureClose() + getReturnString(
THIS + signatureClose(), space);
case AUGMENTED_MAP_ADD:
- return space + YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
+ return space + YANG_AUGMENTED_INFO_MAP +
PERIOD + PUT + OPEN_PARENTHESIS + CLASS +
OBJECT_STRING + COMMA + SPACE + VALUE +
CLOSE_PARENTHESIS + signatureClose();
case AUGMENTED_MAP_GET_VALUE:
return getReturnString(
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP + PERIOD + GET +
+ YANG_AUGMENTED_INFO_MAP + PERIOD + GET +
brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, CLASS +
OBJECT_STRING, null) + signatureClose(),
space);
case AUGMENTED_MAP_GETTER:
- return getReturnString(YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
+ return getReturnString(YANG_AUGMENTED_INFO_MAP +
signatureClose(), space);
case MANAGER_METHODS:
body = space + YANG_UTILS_TODO + NEW_LINE;
@@ -604,16 +605,24 @@
*
* @return getters for value and select leaf
*/
- static String getGettersForValueAndSelectLeaf() {
+ static String getIsValueLeafSet() {
return "\n" +
" @Override\n" +
" public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
- " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
+ " return valueLeafFlags.get(leaf.getLeafIndex());\n" +
" }\n" +
- "\n" +
- " @Override\n" +
+ "\n";
+ }
+
+ /**
+ * Returns is select leaf set.
+ *
+ * @return is select leaf set
+ */
+ static String getIsSelectLeafSet() {
+ return " @Override\n" +
" public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
- " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
+ " return selectLeafFlags.get(leaf.getLeafIndex());\n" +
" }\n";
}
@@ -622,7 +631,7 @@
*
* @return getter methods for operation attributes
*/
- static String getOperationAttributesGetters() {
+ static String getValueLeafGetters() {
return "\n" +
" /**\n" +
" * Returns the valueLeafFlags.\n" +
@@ -632,8 +641,16 @@
" public BitSet getValueLeafFlags() {\n" +
" return valueLeafFlags;\n" +
" }\n" +
- "\n" +
- " /**\n" +
+ "\n";
+ }
+
+ /**
+ * Returns getter methods for operation attributes.
+ *
+ * @return getter methods for operation attributes
+ */
+ static String getSelectLeafGetters() {
+ return " /**\n" +
" * Returns the selectLeafFlags.\n" +
" *\n" +
" * @return value of selectLeafFlags\n" +
@@ -894,7 +911,7 @@
* @return value leaf flag setter
*/
static String getValueLeafSetString(String name) {
- return "\n valueLeafFlags.set(LeafIdentifier." +
+ return " valueLeafFlags.set(LeafIdentifier." +
name.toUpperCase() + ".getLeafIndex());\n";
}
@@ -932,7 +949,7 @@
* @return definition close string
*/
private static String defCloseString() {
- return SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE;
+ return SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -1180,14 +1197,28 @@
/**
* Returns more object attr for union to string method.
*
+ * @param name name of generate class
* @return more object attr for union to string method
*/
- static String getMoreObjectAttr() {
+ static String getMoreObjectAttr(String name) {
+ String cls = name + PERIOD + CLASS;
StringBuilder attr = new StringBuilder(EIGHT_SPACE_INDENTATION);
String[] array = {NEW_LINE};
- attr.append(MORE_OBJ_ATTR).append(GOOGLE_MORE_OBJECT_METHOD_STRING)
+ attr.append(MORE_OBJ_ATTR).append(GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING)
+ .append(brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, cls, null))
.append(NEW_LINE).append(FOUR_SPACE_INDENTATION).append(trimAtLast(
getOmitNullValueString(), array)).append(signatureClose());
return attr.toString();
}
+
+ /**
+ * Returns to string call.
+ *
+ * @param name name of attribute
+ * @return to string call for attribute
+ */
+ static String getToStringCall(String name) {
+ return name + PERIOD +
+ TO_STRING_METHOD + OPEN_CLOSE_BRACKET_STRING;
+ }
}
diff --git a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
index f7229a2..952334c 100644
--- a/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
+++ b/generator/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
@@ -57,7 +57,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.CONTINUE;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
@@ -68,8 +67,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.GET_LEAF_INDEX;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_FLAGS;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_VALUE_LEAF_FLAGS;
import static org.onosproject.yangutils.utils.UtilConstants.IF;
import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ACCESS_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE;
@@ -79,7 +76,6 @@
import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_ALL_SCHEMA_CHILD_FLAG;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
@@ -87,6 +83,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
@@ -96,6 +93,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
+import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
@@ -110,8 +108,10 @@
import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
+import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
@@ -144,7 +144,7 @@
attrQualifiedType = getIfFilterContentMatchMethodImpl(attributeName,
type);
return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
- + GET_VALUE_LEAF_FLAGS + OPEN_CLOSE_BRACKET_STRING +
+ + VALUE_LEAF +
PERIOD + GET_METHOD_PREFIX + OPEN_PARENTHESIS +
LEAF_IDENTIFIER + PERIOD + attributeName.toUpperCase() +
PERIOD + GET_LEAF_INDEX + CLOSE_PARENTHESIS +
@@ -163,7 +163,7 @@
TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + ELSE +
SPACE + IF + SPACE + OPEN_PARENTHESIS +
- GET_SELECT_LEAF_FLAGS + OPEN_CLOSE_BRACKET_STRING +
+ SELECT_LEAF +
PERIOD + GET_METHOD_PREFIX + OPEN_PARENTHESIS +
LEAF_IDENTIFIER + PERIOD + attributeName.toUpperCase() +
PERIOD + GET_LEAF_INDEX + CLOSE_PARENTHESIS + SPACE +
@@ -941,7 +941,7 @@
return EIGHT_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS +
OBJECT_STRING + SPACE + YANG_AUGMENTED_INFO_LOWER_CASE +
SPACE + COLON + SPACE + THIS + PERIOD +
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
+ YANG_AUGMENTED_INFO_MAP +
OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD
+ VALUE + "s" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 6bfd9a8..d73a0d6 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -731,6 +731,10 @@
* Static attribute for of.
*/
public static final String OF = "of";
+ /**
+ * Static attribute for of.
+ */
+ public static final String OF_CAPS = "Of";
/**
* Static attribute for other.
@@ -848,6 +852,11 @@
public static final String OPEN_CLOSE_BRACKET_STRING = "()";
/**
+ * Static attribute for empty parameter function call.
+ */
+ public static final String OPEN_CLOSE_DIAMOND_STRING = "<>";
+
+ /**
* Static attribute for open curly bracket syntax.
*/
public static final String OPEN_CURLY_BRACKET = "{";
@@ -944,6 +953,16 @@
public static final String VALUE_LEAF_SET = "isLeafValueSet";
/**
+ * Static attribute for is valueLeafFlags method prefix.
+ */
+ public static final String VALUE_LEAF = "valueLeafFlags";
+
+ /**
+ * Static attribute for is selectLeafFlags method prefix.
+ */
+ public static final String SELECT_LEAF = "selectLeafFlags";
+
+ /**
* Static attribute for is isSelectLeaf method prefix.
*/
public static final String IS_SELECT_LEAF = "isSelectLeaf";
@@ -1120,6 +1139,11 @@
public static final String BIT_SET = "BitSet";
/**
+ * Augment map type.
+ */
+ public static final String AUGMENT_MAP_TYPE = "Map<Class<?>, Object>";
+
+ /**
* Byte java built in type.
*/
public static final String BYTE = "byte";
@@ -1452,6 +1476,12 @@
"MoreObjects.toStringHelper(getClass())";
/**
+ * Static attribute for to string method.
+ */
+ public static final String GOOGLE_MORE_OBJECT_METHOD_STATIC_STRING =
+ "MoreObjects.toStringHelper";
+
+ /**
* Static attribute for java utilities import package.
*/
public static final String JAVA_UTIL_PKG = "java.util";
@@ -1493,6 +1523,12 @@
"yangAugmentedInfo";
/**
+ * Static attribute for AugmentedInfo class.
+ */
+ public static final String YANG_AUGMENTED_INFO_MAP =
+ "yangAugmentedInfoMap";
+
+ /**
* Static attribute for augmented.
*/
public static final String AUGMENTED = "Augmented";
@@ -1732,7 +1768,7 @@
* Static attribute for YANG node operation type class.
*/
public static final String OPERATION_TYPE_CLASS =
- "OnosYangNodeOperationType";
+ "OnosYangOpType";
/**
* Static attribute for YANG node operation type attribute.
@@ -1823,6 +1859,14 @@
*/
public static final String ERROR_MSG_JAVA_IDENTITY = "Expected java " +
"identity instance node ";
+
+ /**
+ * Static attribute for error msg.
+ */
+ public static final String ERROR_MSG_FOR_AUGMENT_LINKING = "Augment " +
+ "linking does not support linking when path contains " +
+ "notification/grouping for path: ";
+
/**
* Static attribute for in.
*/
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index 7698d89..7d36c0f 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -101,7 +101,7 @@
name = YangIoUtils.getSmallCase(name);
switch (type) {
- case IMPL_CLASS: {
+ case DEFAULT_CLASS: {
return generateForClass(name);
}
case BUILDER_CLASS: {
@@ -424,7 +424,28 @@
* @return javaDocs
*/
private static String generateForClass(String className) {
- return getJavaDocForClass(className, IMPL_CLASS_JAVA_DOC, EMPTY_STRING);
+ return getJavaDocForDefaultClass(className, IMPL_CLASS_JAVA_DOC, EMPTY_STRING);
+ }
+
+ private static String addFlagJavaDoc() {
+ return " *\n" +
+ " * <p>\n" +
+ " * valueLeafFlags identify the leafs whose value are " +
+ "explicitly set\n" +
+ " * Applicable in protocol edit and query operation.\n" +
+ " * </p>\n" +
+ " *\n" +
+ " * <p>\n" +
+ " * selectLeafFlags identify the leafs to be selected, in" +
+ " a query operation.\n" +
+ " * </p>\n" +
+ " *\n" +
+ " * <p>\n" +
+ " * Operation type specify the node specific operation in" +
+ " protocols like NETCONF.\n" +
+ " * Applicable in protocol edit operation, not applicable" +
+ " in query operation.\n" +
+ " * </p>\n";
}
/**
@@ -650,6 +671,21 @@
}
/**
+ * Returns class javadoc.
+ *
+ * @param name name of class
+ * @param type type of javadoc
+ * @param indent indentation
+ * @return class javadoc
+ */
+ private static String getJavaDocForDefaultClass(String name, String type,
+ String indent) {
+ return NEW_LINE + indent + JAVA_DOC_FIRST_LINE + indent + type +
+ getSmallCase(name) + PERIOD + NEW_LINE + indent
+ + addFlagJavaDoc() + JAVA_DOC_END_LINE;
+ }
+
+ /**
* Returns javadoc start line.
*
* @param name name of attribute
@@ -712,7 +748,7 @@
/**
* For class.
*/
- IMPL_CLASS,
+ DEFAULT_CLASS,
/**
* For builder class.
diff --git a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index e1020a1..1e856bf 100644
--- a/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/generator/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -138,7 +138,7 @@
bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode,
null));
String pkg = PACKAGE + SPACE + pack + SEMI_COLON;
- if (pkg.length() > LINE_SIZE) {
+ if (pkg.length() >= LINE_SIZE) {
pkg = processModifications(pkg, LINE_SIZE);
}
bufferedWriter.write(pkg);
@@ -361,7 +361,7 @@
String line = bufferReader.readLine();
while (line != null) {
- if (line.length() > LINE_SIZE) {
+ if (line.length() >= LINE_SIZE) {
line = processModifications(line, LINE_SIZE);
}
stringBuilder.append(line);
@@ -564,7 +564,7 @@
String temp;
for (String str : array) {
if (!str.contains(OPEN_CURLY_BRACKET)) {
- if (str.length() > SUB_LINE_SIZE) {
+ if (str.length() >= SUB_LINE_SIZE) {
count = getSplitString(str, newArray, count);
} else {
newArray.add(str);
diff --git a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java
index 64f718b..c576118 100644
--- a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java
+++ b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java
@@ -63,7 +63,7 @@
* @param ctx context object of the grammar rule
*/
public static void processErrorAppTagMessageEntry(TreeWalkListener listener,
- GeneratedYangParser.ErrorAppTagStatementContext ctx) {
+ GeneratedYangParser.ErrorAppTagStatementContext ctx) {
// Check for stack to be non empty.
checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_APP_TAG_DATA, ctx.string().getText(), ENTRY);
@@ -73,13 +73,12 @@
if (tmpNode instanceof YangAppErrorHolder) {
YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
yangAppErrorInfo.setErrorAppTag(errorMessage);
-
yangAppErrorInfo.setLineNumber(ctx.getStart().getLine());
yangAppErrorInfo.setCharPosition(ctx.getStart().getCharPositionInLine());
yangAppErrorInfo.setFileName(listener.getFileName());
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_APP_TAG_DATA,
- ctx.string().getText(), ENTRY));
+ ctx.string().getText(), ENTRY));
}
}
}
diff --git a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
index 52b7143..2462d10 100644
--- a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
+++ b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
@@ -27,12 +27,12 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LENGTH_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.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;
@@ -93,7 +93,7 @@
setLengthRestriction(listener, type, ctx);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LENGTH_DATA,
- ctx.length().getText(), ENTRY));
+ ctx.length().getText(), ENTRY));
}
}
@@ -118,9 +118,13 @@
}
if (type.getDataType() != STRING && type.getDataType() != BINARY) {
- ParserException parserException = new ParserException("YANG file error : " +
- YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() +
- " can be used to restrict the built-in type string/binary or types derived from string/binary.");
+ ParserException parserException =
+ new ParserException(
+ "YANG file error : " +
+ YangConstructType.getYangConstructType(LENGTH_DATA) +
+ " name " + ctx.length().getText() +
+ " can be used to restrict the built-in type string/binary" +
+ " or types derived from string/binary.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -129,7 +133,8 @@
YangRangeRestriction lengthRestriction = null;
try {
lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(), false, ctx.length().getText());
+ ctx.getStart().getCharPositionInLine(), false, ctx.length
+ ().getText(), listener.getFileName());
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setCharPosition(e.getCharPositionInLine());
@@ -173,7 +178,7 @@
// TODO : need to handle in linker
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LENGTH_DATA,
- ctx.length().getText(), EXIT));
+ ctx.length().getText(), EXIT));
}
}
}
diff --git a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
index 6109518..90b8e52 100644
--- a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
+++ b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
@@ -17,10 +17,8 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
@@ -109,7 +107,7 @@
NOTIFICATION_DATA);
Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangModule || curData instanceof YangSubModule) {
+ if (curData instanceof RpcNotificationContainer) {
YangNotification notification = getYangNotificationNode(JAVA_GENERATION);
notification.setName(identifier);
diff --git a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
index 3b4ae43..0765470 100644
--- a/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
+++ b/parser/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
@@ -26,12 +26,12 @@
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RANGE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
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;
@@ -90,7 +90,7 @@
setRangeRestriction(listener, type, ctx);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, RANGE_DATA,
- ctx.range().getText(), ENTRY));
+ ctx.range().getText(), ENTRY));
}
}
@@ -116,7 +116,7 @@
if (!(isOfRangeRestrictedType(type.getDataType())) && (type.getDataType() != DECIMAL64)) {
ParserException parserException = new ParserException("YANG file error: Range restriction can't be " +
- "applied to a given type");
+ "applied to a given type");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
@@ -126,14 +126,20 @@
try {
if (type.getDataType() == DECIMAL64) {
YangDecimal64 yangDecimal64 = (YangDecimal64) type.getDataTypeExtendedInfo();
- rangeRestriction = processRangeRestriction(yangDecimal64.getDefaultRangeRestriction(),
- ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(),
- true, ctx.range().getText(), type.getDataType());
+ rangeRestriction =
+ processRangeRestriction(yangDecimal64.getDefaultRangeRestriction(),
+ ctx.getStart().getLine(),
+ ctx.getStart().getCharPositionInLine(),
+ true, ctx.range().getText(),
+ type.getDataType(), listener.getFileName());
} else {
- rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(),
- false, ctx.range().getText(), type.getDataType());
+ rangeRestriction =
+ processRangeRestriction(null, ctx.getStart().getLine(),
+ ctx.getStart().getCharPositionInLine(),
+ false, ctx.range()
+ .getText(), type
+ .getDataType(),
+ listener.getFileName());
}
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
@@ -174,7 +180,7 @@
// TODO : need to handle in linker
} else {
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, RANGE_DATA,
- ctx.range().getText(), EXIT));
+ ctx.range().getText(), EXIT));
}
}
}
diff --git a/plugin/buck/pom.xml b/plugin/buck/pom.xml
index fc1628b..09dde6d 100644
--- a/plugin/buck/pom.xml
+++ b/plugin/buck/pom.xml
@@ -13,7 +13,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
diff --git a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
index 28e77c5..00331b2 100644
--- a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
+++ b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangPluginUtils.java
@@ -16,10 +16,20 @@
package org.onosproject.yangutils.plugin.manager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Resource;
+import org.apache.maven.project.MavenProject;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.slf4j.Logger;
+import org.sonatype.plexus.build.incremental.BuildContext;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
@@ -28,15 +38,9 @@
import java.util.List;
import java.util.Set;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.Resource;
-import org.apache.maven.project.MavenProject;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.slf4j.Logger;
-import org.sonatype.plexus.build.incremental.BuildContext;
-
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.parseJarFile;
+import static org.onosproject.yangutils.utils.UtilConstants.COLON;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAR;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
@@ -56,7 +60,10 @@
private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
private static final String SERIALIZED_FILE_EXTENSION = ".ser";
+ private static final String TEXT_FILE_EXTENSION = ".txt";
private static final String YANG_META_DATA = "YangMetaData";
+ private static final String VERSION_META_DATA = "VersionMetaData";
+ private static final String PLUGIN_ARTIFACT = "onos-yang-maven-plugin";
private YangPluginUtils() {
}
@@ -93,8 +100,8 @@
for (File file : files) {
Files.copy(file.toPath(),
- new File(path + file.getName()).toPath(),
- StandardCopyOption.REPLACE_EXISTING);
+ new File(path + file.getName()).toPath(),
+ StandardCopyOption.REPLACE_EXISTING);
}
addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
}
@@ -148,6 +155,38 @@
objectOutputStream.writeObject(nodes);
objectOutputStream.close();
fileOutputStream.close();
+ if (operation) {
+ addVersionMetaDataFile(project, serFileDirPath);
+ }
+ }
+
+ /**
+ * Adds version meta data files for YSR to know version of YANG tools.
+ *
+ * @param project maven project
+ * @param dir directory
+ * @throws IOException when fails to do IO operations
+ */
+ private static void addVersionMetaDataFile(MavenProject project, String dir)
+ throws IOException {
+ List<Plugin> plugins = project.getBuildPlugins();
+ Iterator<Plugin> it = plugins.iterator();
+ Plugin plugin = it.next();
+ String data = EMPTY_STRING;
+ while (it.hasNext()) {
+ if (plugin.getArtifactId().equals(PLUGIN_ARTIFACT)) {
+ data = plugin.getGroupId() + COLON + plugin.getArtifactId()
+ + COLON + plugin.getVersion();
+ }
+ plugin = it.next();
+ }
+ if (data.equals(EMPTY_STRING)) {
+ throw new IOException("Invalid artifact for " + PLUGIN_ARTIFACT);
+ }
+ String verFileName = dir + VERSION_META_DATA + TEXT_FILE_EXTENSION;
+ PrintWriter out = new PrintWriter(verFileName);
+ out.print(data);
+ out.close();
}
/**
diff --git a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index e661c32..c965e95 100644
--- a/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/plugin/maven/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -39,12 +39,12 @@
import org.sonatype.plexus.build.incremental.BuildContext;
import java.io.IOException;
-import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import static java.util.Collections.sort;
import static org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
@@ -57,6 +57,8 @@
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.IN;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
@@ -71,11 +73,13 @@
* Execution phase is generate-sources.
* requiresDependencyResolution at compile time.
*/
-@Mojo(name = "yang2java", defaultPhase = PROCESS_SOURCES, requiresDependencyResolution = COMPILE)
+@Mojo(name = "yang2java", defaultPhase = PROCESS_SOURCES,
+ requiresDependencyResolution = COMPILE)
public class YangUtilManager
extends AbstractMojo {
- private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
+ private static final String DEFAULT_PKG =
+ getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private YangPluginConfig yangPlugin = new YangPluginConfig();
private YangNode rootNode;
// YANG file information set.
@@ -106,13 +110,15 @@
/**
* Output directory.
*/
- @Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes")
+ @Parameter(property = "project.build.outputDirectory", required = true,
+ defaultValue = "target/classes")
private String outputDirectory;
/**
* Current maven project.
*/
- @Parameter(property = "project", required = true, readonly = true, defaultValue = "${project}")
+ @Parameter(property = "project", required = true, readonly = true,
+ defaultValue = "${project}")
private MavenProject project;
/**
@@ -163,19 +169,22 @@
@Parameter(property = "generateJavaFileForSbi", defaultValue = "nbi")
private String generateJavaFileForSbi;
+ private String outputDir;
+ private String codeGenDir;
+
@Override
public void execute()
throws MojoExecutionException, MojoFailureException {
try {
-
/*
* For deleting the generated code in previous build.
*/
- deleteDirectory(getDirectory(baseDir, outputDirectory + SLASH + TEMP));
- deleteDirectory(getDirectory(baseDir, outputDirectory + SLASH + YANG_RESOURCES));
+ outputDir = getDirectory(baseDir, outputDirectory);
+ deleteDirectory(outputDir + SLASH + TEMP);
+ deleteDirectory(outputDir + SLASH + YANG_RESOURCES);
String searchDir = getDirectory(baseDir, yangFilesDir);
- String codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
+ codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
// Creates conflict resolver and set values to it.
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
@@ -194,7 +203,7 @@
createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
// Check if there are any file to translate, if not return.
- if (getYangFileInfoSet() == null || getYangFileInfoSet().isEmpty()) {
+ if (yangFileInfoSet == null || yangFileInfoSet.isEmpty()) {
// No files to translate
return;
}
@@ -211,19 +220,18 @@
translateToJava(yangPlugin);
// Serialize data model.
- serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
-
+ serializeDataModel(outputDir, yangFileInfoSet, project, true);
addToCompilationRoot(codeGenDir, project, context);
- copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
+ copyYangFilesToTarget(yangFileInfoSet, outputDir, project);
} catch (IOException | ParserException e) {
- String fileName = "";
- if (getCurYangFileInfo() != null) {
- fileName = getCurYangFileInfo().getYangFileName();
+ String fileName = EMPTY_STRING;
+ if (curYangFileInfo != null) {
+ fileName = curYangFileInfo.getYangFileName();
}
try {
- translatorErrorHandler(getRootNode(), yangPlugin);
- deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
+ translatorErrorHandler(rootNode, yangPlugin);
+ deleteDirectory(codeGenDir + DEFAULT_PKG);
} catch (IOException ex) {
e.printStackTrace();
throw new MojoExecutionException(
@@ -231,8 +239,8 @@
}
getLog().info(e);
throw new MojoExecutionException(
- "Exception occurred due to " + e.getLocalizedMessage() + " in " + fileName
- + " YANG file.");
+ "Exception occurred due to " + e.getLocalizedMessage() +
+ IN + fileName + " YANG file.");
}
}
@@ -253,15 +261,16 @@
private void resolveInterJarDependency()
throws IOException {
try {
- List<YangNode> interJarResolvedNodes = resolveInterJarDependencies(project, localRepository,
- remoteRepository, getDirectory(baseDir, outputDirectory));
+ List<YangNode> interJarResolvedNodes =
+ resolveInterJarDependencies(project, localRepository,
+ remoteRepository, outputDir);
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
node.setToTranslate(false);
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
- getYangFileInfoSet().add(dependentFileInfo);
+ yangFileInfoSet.add(dependentFileInfo);
}
} catch (IOException e) {
throw new IOException("failed to resolve in inter-jar scenario.");
@@ -277,19 +286,20 @@
throws MojoExecutionException {
createYangNodeSet();
try {
- yangLinker.resolveDependencies(getYangNodeSet());
+ yangLinker.resolveDependencies(yangNodeSet);
} catch (LinkerException e) {
+ printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
+ e.getMessage(), e.getLocalizedMessage());
throw new MojoExecutionException(e.getMessage());
}
-
}
/**
* Creates YANG nodes set.
*/
public void createYangNodeSet() {
- for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
- getYangNodeSet().add(yangFileInfo.getRootNode());
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ yangNodeSet.add(yangFileInfo.getRootNode());
}
}
@@ -300,31 +310,29 @@
*/
public void parseYangFileInfoSet()
throws IOException {
- for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
- setCurYangFileInfo(yangFileInfo);
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ curYangFileInfo = yangFileInfo;
if (yangFileInfo.isForTranslator()) {
try {
- YangNode yangNode = yangUtilsParser.getDataModel(yangFileInfo.getYangFileName());
+ YangNode yangNode = yangUtilsParser.getDataModel(
+ yangFileInfo.getYangFileName());
yangFileInfo.setRootNode(yangNode);
- setRootNode(yangNode);
+ rootNode = yangNode;
resolveGroupingInDefinationScope((YangReferenceResolver) yangNode);
try {
- ((YangReferenceResolver) yangNode).resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) yangNode).resolveSelfFileLinking(YANG_IDENTITYREF);
+ ((YangReferenceResolver) yangNode)
+ .resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
+ ((YangReferenceResolver) yangNode)
+ .resolveSelfFileLinking(YANG_IDENTITYREF);
} catch (DataModelException e) {
- //TODO: throw exception : throw e;
+ printLog(e.getFileName(), e.getLineNumber(), e
+ .getCharPositionInLine(), e.getMessage(), e
+ .getLocalizedMessage());
}
} catch (ParserException e) {
- String logInfo = "Error in file: " + e.getFileName();
- if (e.getLineNumber() != 0) {
- logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
- + e.getCharPositionInLine();
-
- }
- if (e.getMessage() != null) {
- logInfo = logInfo + NEW_LINE + e.getLocalizedMessage();
- }
- getLog().info(logInfo);
+ printLog(e.getFileName(), e.getLineNumber(), e
+ .getCharPositionInLine(), e.getMessage(), e
+ .getLocalizedMessage());
throw e;
}
}
@@ -332,24 +340,6 @@
}
/**
- * Returns current root YANG node of data-model tree.
- *
- * @return current root YANG node of data-model tree
- */
- private YangNode getRootNode() {
- return rootNode;
- }
-
- /**
- * Sets current root YANG node of data-model tree.
- *
- * @param rootNode current root YANG node of data-model tree
- */
- private void setRootNode(YangNode rootNode) {
- this.rootNode = rootNode;
- }
-
- /**
* Translates to java code corresponding to the YANG schema.
*
* @param yangPlugin YANG plugin config
@@ -358,8 +348,8 @@
public void translateToJava(YangPluginConfig yangPlugin)
throws IOException {
List<YangNode> yangNodeSortedList = new LinkedList<>();
- yangNodeSortedList.addAll(getYangNodeSet());
- Collections.sort(yangNodeSortedList);
+ yangNodeSortedList.addAll(yangNodeSet);
+ sort(yangNodeSortedList);
for (YangNode node : yangNodeSortedList) {
if (node.isToTranslate()) {
generateJavaCode(node, yangPlugin);
@@ -376,7 +366,7 @@
for (String yangFile : yangFileList) {
YangFileInfo yangFileInfo = new YangFileInfo();
yangFileInfo.setYangFileName(yangFile);
- getYangFileInfoSet().add(yangFileInfo);
+ yangFileInfoSet.add(yangFileInfo);
}
}
@@ -399,20 +389,25 @@
}
/**
- * Returns current YANG file's info.
+ * Adds log info for exception.
*
- * @return the yangFileInfo
+ * @param fileName file name
+ * @param line line number
+ * @param position character position
+ * @param msg error message
+ * @param localMsg local message
*/
- private YangFileInfo getCurYangFileInfo() {
- return curYangFileInfo;
- }
+ private void printLog(String fileName, int line, int position, String
+ msg, String localMsg) {
+ String logInfo = "Error in file: " + fileName;
+ if (line != 0) {
+ logInfo = logInfo + " at line: " + line + " at position: "
+ + position;
- /**
- * Sets current YANG file's info.
- *
- * @param yangFileInfo the yangFileInfo to set
- */
- private void setCurYangFileInfo(YangFileInfo yangFileInfo) {
- curYangFileInfo = yangFileInfo;
+ }
+ if (msg != null) {
+ logInfo = logInfo + NEW_LINE + localMsg;
+ }
+ getLog().info(logInfo);
}
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
index 9cd07b2..9ac1ad8 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/AugmentTranslatorTest.java
@@ -41,6 +41,7 @@
@Test
public void processAugmentTranslator() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/augmentTranslator/");
String searchDir = "src/test/resources/augmentTranslator";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
index 6ee1c71..7a1a8f6 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/ChoiceCaseTranslatorTest.java
@@ -16,14 +16,14 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.IOException;
-
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
@@ -40,6 +40,7 @@
@Test
public void processChoiceCaseTranslator() throws IOException, ParserException {
+ deleteDirectory("target/ChoiceCaseTestGenFile/");
YangNode node = manager.getDataModel("src/test/resources/ChoiceCaseTranslator.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
index fb0f805..89f7439 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/InterJarLinkerTest.java
@@ -79,17 +79,17 @@
public void processSingleJarLinking()
throws IOException, MojoExecutionException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
-
- int size1 = utilManager.getYangFileInfoSet().size();
+ Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
+ int size1 = info.size();
utilManager.parseYangFileInfoSet();
mockJarFileProvider.provideTestJarFile(utilManager);
- utilManager.setYangFileInfoSet(removeFileInfoFromSet(utilManager.getYangFileInfoSet()));
+ utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
utilManager.resolveDependenciesUsingLinker();
- int size2 = utilManager.getYangFileInfoSet().size();
+ int size2 = info.size();
assertThat(true, is(size1 != size2));
- assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
+ assertThat(true, is(parseFileInfoSet(info.iterator())));
deleteDirectory(TARGET);
mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
@@ -106,17 +106,18 @@
throws IOException, MojoExecutionException {
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
- int size1 = utilManager.getYangFileInfoSet().size();
+ Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
+ int size1 = info.size();
utilManager.parseYangFileInfoSet();
mockJarFileProvider.provideTestJarFile(utilManager);
- utilManager.setYangFileInfoSet(removeFileInfoFromSet(utilManager.getYangFileInfoSet()));
+ utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
utilManager.resolveDependenciesUsingLinker();
- int size2 = utilManager.getYangFileInfoSet().size();
+ int size2 = info.size();
assertThat(true, is(size1 != size2));
- assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
- assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
+ assertThat(true, is(parseFileInfoSet(info.iterator())));
+ assertThat(true, is(parseFileInfoSet(info.iterator())));
/*
* grouping flow-classifier {
@@ -134,7 +135,7 @@
*
*/
- Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+ Iterator<YangFileInfo> yangFileInfoIterator = info.iterator();
YangFileInfo yangFileInfo = yangFileInfoIterator.next();
@@ -268,12 +269,13 @@
*/
void provideTestJarFile(YangUtilManager utilManager) throws IOException {
+ Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
MavenProject project = new MavenProject();
- serializeDataModel(TARGET, utilManager.getYangFileInfoSet(), project, false);
+ serializeDataModel(TARGET, info, project, false);
createTestJar();
for (String file : getListOfTestJar(TARGET)) {
- addInterJarRootNodes(file, utilManager);
+ addInterJarRootNodes(file, info);
}
}
@@ -281,7 +283,8 @@
* Deletes serialized file.
*/
void deleteTestSerFile(String yangFileDir) {
- File ser = new File(System.getProperty("user.dir") + SLASH + yangFileDir + SLASH + SER_FILE_NAME);
+ File ser = new File(System.getProperty("user.dir") + SLASH + yangFileDir +
+ SLASH + SER_FILE_NAME);
ser.delete();
}
@@ -309,11 +312,11 @@
/**
* Adds data model nodes of jar to file info set.
*
- * @param jarFile jar file name
- * @param utilManager
+ * @param jarFile jar file name
+ * @param info file info
* @throws IOException when fails to do IO operations
*/
- private void addInterJarRootNodes(String jarFile, YangUtilManager utilManager) throws IOException {
+ private void addInterJarRootNodes(String jarFile, Set<YangFileInfo> info) throws IOException {
try {
List<YangNode> interJarResolvedNodes = parseJarFile(jarFile, TARGET);
@@ -323,7 +326,7 @@
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
- utilManager.getYangFileInfoSet().add(dependentFileInfo);
+ info.add(dependentFileInfo);
}
} catch (IOException e) {
throw new IOException("failed to resolve in interjar scenario.");
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java
index 472f083..80fd438 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/RootClassGeneratorTest.java
@@ -38,6 +38,7 @@
@Test
public void rootClassGenTest() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
@@ -49,36 +50,20 @@
utilManager.translateToJava(yangPluginConfig);
String path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5.java";
- assertThat(true, is(!(new File(path)).exists()));
+ "org/onosproject/yang/gen/v1/single/test5/test/rev20160704" +
+ "/Test5.java";
+ assertThat(true, is((new File(path)).exists()));
path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7.java";
+ "org/onosproject/yang/gen/v1/single/test5/test/rev20160704" +
+ "/Test7.java";
assertThat(true, is((new File(path)).exists()));
deleteDirectory("target/manager/");
}
@Test
- public void rootClassNoGenTest() throws IOException, ParserException, MojoExecutionException {
- String searchDir = "src/test/resources/manager/nogen";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
- utilManager.parseYangFileInfoSet();
- utilManager.createYangNodeSet();
- utilManager.resolveDependenciesUsingLinker();
-
- YangPluginConfig yangPluginConfig = new YangPluginConfig();
- yangPluginConfig.setCodeGenDir("target/manager/");
- utilManager.translateToJava(yangPluginConfig);
-
- String path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5.java";
-
- assertThat(true, is(!(new File(path)).exists()));
- deleteDirectory("target/manager/");
- }
-
- @Test
public void rootClassGenwithoutRevTest() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/genwithoutrev";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
@@ -98,6 +83,7 @@
@Test
public void rootClassMethodGenTest() throws IOException, ParserException, MojoExecutionException {
+ deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/MultiChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
@@ -109,15 +95,18 @@
utilManager.translateToJava(yangPluginConfig);
String path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5.java";
- assertThat(true, is(!(new File(path)).exists()));
+ "org/onosproject/yang/gen/v1/multi/test5/test/rev20160704" +
+ "/Test5.java";
+ assertThat(true, is((new File(path)).exists()));
path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7.java";
- assertThat(true, is(!(new File(path)).exists()));
+ "org/onosproject/yang/gen/v1/multi/test5/test/rev20160704" +
+ "/Test7.java";
+ assertThat(true, is((new File(path)).exists()));
path = System.getProperty("user.dir") + "/target/manager/" +
- "org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8.java";
+ "org/onosproject/yang/gen/v1/multi/test8/test/rev20160704" +
+ "/Test8.java";
assertThat(true, is((new File(path)).exists()));
deleteDirectory("target/manager/");
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java
index 4ef664c..40e567d 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/TypeDefTranslatorTest.java
@@ -16,14 +16,14 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.IOException;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
+import java.io.IOException;
+
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
@@ -76,4 +76,28 @@
}
+ /**
+ * Checks typedef translation should not result in any exception.
+ *
+ * @throws MojoExecutionException
+ */
+ @Test
+ public void processTypeDefWithUnionAndBitsTranslator() throws IOException,
+ ParserException, MojoExecutionException {
+
+ deleteDirectory("target/typedefTranslator/");
+ String searchDir = "src/test/resources/typedefTranslator/union";
+ utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ utilManager.parseYangFileInfoSet();
+ utilManager.createYangNodeSet();
+ utilManager.resolveDependenciesUsingLinker();
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
+ utilManager.translateToJava(yangPluginConfig);
+
+ //deleteDirectory("target/typedefTranslator/");
+
+ }
+
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
index 891a280..b6769ce 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangPluginUtilsTest.java
@@ -16,14 +16,17 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.File;
-import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
+import java.io.File;
+import java.io.IOException;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
/**
@@ -41,9 +44,12 @@
MavenProject project = new MavenProject();
BuildContext context = new DefaultBuildContext();
- File sourceDir = new File(BASE_DIR + File.separator + "yang");
+ String dir = BASE_DIR + File.separator + "yang";
+ String path = System.getProperty("user.dir") + File.separator + dir;
+ File sourceDir = new File(dir);
sourceDir.mkdirs();
addToCompilationRoot(sourceDir.toString(), project, context);
+ assertThat(true, is(project.getCompileSourceRoots().contains(path)));
FileUtils.deleteDirectory(sourceDir);
}
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
index cca5c3f..3d8ca0c 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/plugin/manager/YangXpathLinkerTest.java
@@ -16,9 +16,6 @@
package org.onosproject.yangutils.plugin.manager;
-import java.io.IOException;
-import java.util.List;
-
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.ResolvableType;
@@ -28,12 +25,16 @@
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.linker.impl.YangXpathLinker;
-import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+import java.util.List;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yangutils.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yangutils.utils.io.impl.YangFileScanner.getYangFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
@@ -57,7 +58,7 @@
@Test
public void processIntraFileLinkingSingleLevel() throws IOException, MojoExecutionException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingle/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingle/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -88,7 +89,7 @@
@Test
public void processIntraFileLinkingMultipleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMulti/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMulti/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -101,7 +102,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -115,7 +116,7 @@
*/
@Test
public void processIntraFileLinkingInAugmentSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -128,7 +129,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -142,7 +143,7 @@
*/
@Test
public void processIntraFileLinkingInAugmentMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMultiAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -159,7 +160,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -174,7 +175,7 @@
*/
@Test
public void processIntraFileLinkingInSubModuleSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingleSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -190,7 +191,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -205,7 +206,7 @@
@Test
public void processIntraFileLinkingInSubModuleMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMultiSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -221,7 +222,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -236,7 +237,7 @@
@Test
public void processIntraFileLinkingInUsesSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -252,7 +253,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -267,7 +268,7 @@
@Test
public void processIntraFileLinkingInUsesMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -283,7 +284,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -298,7 +299,7 @@
@Test
public void processInterFileLinkingSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingle/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingle/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -313,7 +314,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -328,7 +329,7 @@
@Test
public void processInterFileLinkingMultipleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMulti/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMulti/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -343,7 +344,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -358,7 +359,7 @@
@Test
public void processInterFileLinkingInAugmentSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingleAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -373,7 +374,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -388,7 +389,7 @@
@Test
public void processInterFileLinkingInAugmentMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -403,7 +404,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -418,7 +419,7 @@
@Test
public void processMultiInterFileLinkingInAugmentSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugment/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiFileAugment/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -433,7 +434,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -449,7 +450,7 @@
public void processMultiInterFileLinkingInAugmentMultiLevel() throws IOException {
utilManager
- .createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugmentMulti/"));
+ .createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiFileAugmentMulti/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -483,7 +484,7 @@
@Test
public void processInterFileLinkingInSubModuleSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingleSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -516,7 +517,7 @@
@Test
public void processInterFileLinkingInSubModuleMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiSubModule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiSubModule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -549,7 +550,7 @@
@Test
public void processInterFileLinkingInUsesInAugment() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterSingleUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -584,7 +585,7 @@
@Test
public void processInterFileLinkingInUsesMultiLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -602,7 +603,7 @@
for (YangAugment augment : augments) {
targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -617,7 +618,7 @@
@Test
public void processInterFileLinkingInMultipleSubmodules() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "submodule/"));
+ utilManager.createYangFileInfoSet(getYangFiles(CASE_FILE_PATH + "submodule/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -653,7 +654,7 @@
@Test
public void processInterFileLinkingInMultipleUses() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "uses/"));
+ utilManager.createYangFileInfoSet(getYangFiles(CASE_FILE_PATH + "uses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
index 6b20103..4de9402 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGeneratorTest.java
@@ -99,13 +99,10 @@
private static final String SET = "setValue.set(0);\n";
private static final String UNION = " @Override\n" +
" public String toString() {\n" +
- " MoreObjects.ToStringHelper helper =" +
- " MoreObjects.toStringHelper(getClass())\n" +
- " .omitNullValues();\n" +
" if (setValue.get(0)) {\n" +
- " helper.add(\"string\", string);\n" +
+ " return string;\n" +
" }\n" +
- " return helper.toString();\n" +
+ " return null;\n" +
" }";
/**
@@ -259,7 +256,7 @@
JavaAttributeInfo testAttr = getTestAttribute();
List<YangType<?>> types = new ArrayList<>();
types.add(testAttr.getAttributeType());
- String method = getUnionToStringMethod(types);
+ String method = getUnionToStringMethod(types, CLASS_NAME);
assertThat(true, is(method.contains(UNION)));
}
diff --git a/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java b/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
index dcb4a34..14c5134 100644
--- a/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
+++ b/plugin/maven/src/test/java/org/onosproject/yangutils/utils/io/impl/JavaDocGenTest.java
@@ -34,7 +34,7 @@
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
+import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
@@ -141,7 +141,7 @@
*/
@Test
public void implClassGenerationTest() {
- String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false, null);
+ String implClassJavaDoc = getJavaDoc(DEFAULT_CLASS, TEST_NAME, false, null);
assertThat(true,
is(implClassJavaDoc.contains("Represents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
diff --git a/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang b/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang
index e8127ea..35cbf19 100644
--- a/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang
+++ b/plugin/maven/src/test/resources/ChoiceCaseTranslator.yang
@@ -2,7 +2,7 @@
yang-version 1;
namespace http://huawei.com;
prefix Ant;
- container food {
+ notification food {
choice snack {
case sports-arena {
leaf pretzel {
diff --git a/plugin/maven/src/test/resources/manager/MultiChild/module.yang b/plugin/maven/src/test/resources/manager/MultiChild/module.yang
index 1c4637c..845380b 100644
--- a/plugin/maven/src/test/resources/manager/MultiChild/module.yang
+++ b/plugin/maven/src/test/resources/manager/MultiChild/module.yang
@@ -1,5 +1,5 @@
module test5 {
- namespace "test5:test";
+ namespace "multi:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/MultiChild/test.yang b/plugin/maven/src/test/resources/manager/MultiChild/test.yang
index 036d78a..2665267 100644
--- a/plugin/maven/src/test/resources/manager/MultiChild/test.yang
+++ b/plugin/maven/src/test/resources/manager/MultiChild/test.yang
@@ -1,5 +1,5 @@
module test7 {
- namespace "test5:test";
+ namespace "multi:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/MultiChild/test2.yang b/plugin/maven/src/test/resources/manager/MultiChild/test2.yang
index b252c23..c87022d 100644
--- a/plugin/maven/src/test/resources/manager/MultiChild/test2.yang
+++ b/plugin/maven/src/test/resources/manager/MultiChild/test2.yang
@@ -1,5 +1,5 @@
module test8 {
- namespace "test8:test";
+ namespace "multi:test8:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/singleChild/module.yang b/plugin/maven/src/test/resources/manager/singleChild/module.yang
index 5fb8a9b..67f4bc9 100644
--- a/plugin/maven/src/test/resources/manager/singleChild/module.yang
+++ b/plugin/maven/src/test/resources/manager/singleChild/module.yang
@@ -1,5 +1,5 @@
module test5 {
- namespace "test5:test";
+ namespace "single:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/manager/singleChild/test.yang b/plugin/maven/src/test/resources/manager/singleChild/test.yang
index 483e00e..2d13b4c 100644
--- a/plugin/maven/src/test/resources/manager/singleChild/test.yang
+++ b/plugin/maven/src/test/resources/manager/singleChild/test.yang
@@ -1,5 +1,5 @@
module test7 {
- namespace "test5:test";
+ namespace "single:test5:test";
prefix test ;
revision "2016-07-04" {
diff --git a/plugin/maven/src/test/resources/typedefTranslator/union/typedefs.yang b/plugin/maven/src/test/resources/typedefTranslator/union/typedefs.yang
new file mode 100644
index 0000000..4a3d150
--- /dev/null
+++ b/plugin/maven/src/test/resources/typedefTranslator/union/typedefs.yang
@@ -0,0 +1,52 @@
+module types {
+
+ namespace "yang:types";
+ prefix "types";
+ yang-version 1;
+
+ revision 2016-10-08;
+ typedef ip-address {
+ type union {
+ type ipv4-address;
+ type ipv6-address;
+ type leaf;
+ }
+ }
+
+ typedef ipv4-address {
+ type int32;
+ }
+
+ typedef ipv6-address {
+ type int32;
+ }
+
+ typedef port-number {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit Mb-only {
+ position 2;
+ }
+ }
+
+}
+
+
+ container con1 {
+ leaf abc {
+ type int32;
+ }
+ }
+
+ typedef leaf {
+ type leafref {
+ path "/con1/abc";
+ }
+ }
+
+}
diff --git a/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang b/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang
index e42101e..8e4dccf 100644
--- a/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang
+++ b/plugin/maven/src/test/resources/xPathLinker/Case/uses/test2.yang
@@ -53,7 +53,7 @@
}
}
- augment /group1/cont3/cont4 {
+ augment /cont5/cont6/cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
diff --git a/plugin/pom.xml b/plugin/pom.xml
index f35583d..882703f 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -13,7 +13,8 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>