Bharat saraswal
Committed by Patrick Liu

[ONOS-4799],[ONOS-4351] Augment inter file linker and Generated Code refactored.

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