Bharat saraswal
Committed by bharat saraswal-huawei

[ONOS-5003][ONOS-5004][ONOS-5005]Generated Code modification for YangUtils+added…

… interface for augmentation method and other api changes.

Change-Id: I954b9c99e182f21d01fcc5cd76fbac7d61a6c3aa
Showing 82 changed files with 2040 additions and 2367 deletions
......@@ -83,7 +83,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
public class YangAugment
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentedInfo, Resolvable,
YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
YangXPathResolver, YangWhenHolder, YangIfFeatureHolder, YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201602L;
......@@ -254,7 +254,7 @@ public class YangAugment
@Override
public void addLeaf(YangLeaf leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
setListOfLeaf(new LinkedList<>());
}
getListOfLeaf().add(leaf);
......@@ -288,7 +288,7 @@ public class YangAugment
@Override
public void addLeafList(YangLeafList leafList) {
if (getListOfLeafList() == null) {
setListOfLeafList(new LinkedList<YangLeafList>());
setListOfLeafList(new LinkedList<>());
}
getListOfLeafList().add(leafList);
......
......@@ -96,7 +96,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D
public class YangCase
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentableNode,
YangWhenHolder, YangIfFeatureHolder {
YangWhenHolder, YangIfFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201603L;
......@@ -149,6 +149,8 @@ public class YangCase
*/
public YangCase() {
super(YangNodeType.CASE_NODE);
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
/**
......@@ -239,7 +241,7 @@ public class YangCase
@Override
public void addLeaf(YangLeaf leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
setListOfLeaf(new LinkedList<>());
}
getListOfLeaf().add(leaf);
......
......@@ -91,7 +91,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
public class YangContainer
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201605L;
......@@ -158,6 +158,8 @@ public class YangContainer
*/
public YangContainer() {
super(YangNodeType.CONTAINER_NODE);
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
/**
......
......@@ -71,7 +71,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangInput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode {
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201608L;
......@@ -97,8 +97,8 @@ public class YangInput
*/
public YangInput() {
super(YangNodeType.INPUT_NODE);
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
@Override
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.datamodel;
/**
* Represent the YANG nodes which can contain is filter content match.
*/
public interface YangIsFilterContentNodes {
}
......@@ -19,6 +19,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;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
......@@ -71,7 +72,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
public class YangList
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode {
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder, YangDataNode,
YangIsFilterContentNodes {
private static final long serialVersionUID = 806201609L;
......@@ -92,7 +94,7 @@ public class YangList
/**
* Reference RFC 6020.
*
* <p>
* The "key" statement, which MUST be present if the list represents
* configuration, and MAY be present otherwise, takes as an argument a
* string that specifies a space-separated list of leaf identifiers of this
......@@ -100,39 +102,39 @@ public class YangList
* such leaf identifier MUST refer to a child leaf of the list. The leafs
* can be defined directly in sub-statements to the list, or in groupings
* used in the list.
*
* <p>
* The combined values of all the leafs specified in the key are used to
* uniquely identify a list entry. All key leafs MUST be given values when a
* list entry is created. Thus, any default values in the key leafs or their
* types are ignored. It also implies that any mandatory statement in the
* key leafs are ignored.
*
* <p>
* A leaf that is part of the key can be of any built-in or derived type,
* except it MUST NOT be the built-in type "empty".
*
* <p>
* All key leafs in a list MUST have the same value for their "config" as
* the list itself.
*
* <p>
* List of key leaf names.
*/
private List<String> keyList;
/**
* Reference RFC 6020.
*
* <p>
* The "unique" statement is used to put constraints on valid list
* entries. It takes as an argument a string that contains a space-
* separated list of schema node identifiers, which MUST be given in the
* descendant form. Each such schema node identifier MUST refer to a leaf.
*
* <p>
* If one of the referenced leafs represents configuration data, then
* all of the referenced leafs MUST represent configuration data.
*
* <p>
* The "unique" constraint specifies that the combined values of all the
* leaf instances specified in the argument string, including leafs with
* default values, MUST be unique within all list entry instances in
* which all referenced leafs exist.
*
* <p>
* List of unique leaf/leaf-list names
*/
private List<String> uniqueList;
......@@ -151,32 +153,32 @@ public class YangList
/**
* Reference RFC 6020.
*
* <p>
* The "max-elements" statement, which is optional, takes as an argument a
* positive integer or the string "unbounded", which puts a constraint on
* valid list entries. A valid leaf-list or list always has at most
* max-elements entries.
*
* <p>
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private YangMaxElement maxElements;
/**
* Reference RFC 6020.
*
* <p>
* The "min-elements" statement, which is optional, takes as an argument a
* non-negative integer that puts a constraint on valid list entries. A
* valid leaf-list or list MUST have at least min-elements entries.
*
* <p>
* If no "min-elements" statement is present, it defaults to zero.
*
* <p>
* The behavior of the constraint depends on the type of the leaf-list's or
* list's closest ancestor node in the schema tree that is not a non-
* presence container:
*
* <p>
* o If this ancestor is a case node, the constraint is enforced if any
* other node from the case exists.
*
* <p>
* o Otherwise, it is enforced if the ancestor node exists.
*/
private YangMinElement minElements;
......@@ -211,6 +213,8 @@ public class YangList
*/
public YangList() {
super(YangNodeType.LIST_NODE);
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
/**
......
......@@ -74,7 +74,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
public class YangModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer, YangFeatureHolder {
RpcNotificationContainer, YangFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201610L;
......@@ -85,7 +85,7 @@ public class YangModule
/**
* Reference:RFC 6020.
*
* <p>
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
......@@ -96,7 +96,7 @@ public class YangModule
/**
* Reference:RFC 6020.
*
* <p>
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
......@@ -136,7 +136,7 @@ public class YangModule
/**
* Reference:RFC 6020.
*
* <p>
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
......@@ -211,9 +211,9 @@ public class YangModule
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* Leafref resolution list.
* LeafRef resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
private List<YangResolutionInfo> leafRefResolutionList;
/**
* Base resolution list.
......@@ -221,9 +221,9 @@ public class YangModule
private List<YangResolutionInfo> baseResolutionList;
/**
* Identityref resolution list.
* IdentityRef resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
private List<YangResolutionInfo> identityRefResolutionList;
/**
* Augment resolution list.
......@@ -250,15 +250,15 @@ public class YangModule
augmentResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
leafRefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
identityRefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
extensionList = new LinkedList<YangExtension>();
importList = new LinkedList<>();
includeList = new LinkedList<>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
extensionList = new LinkedList<>();
}
/**
......@@ -684,11 +684,11 @@ public class YangModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
return leafRefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
} else {
return identityrefResolutionList;
return identityRefResolutionList;
}
}
......@@ -702,13 +702,13 @@ public class YangModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
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);
identityRefResolutionList.add(resolutionInfo);
}
}
......@@ -722,13 +722,13 @@ public class YangModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
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;
identityRefResolutionList = resolutionList;
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
......@@ -185,7 +186,7 @@ public abstract class YangNode
*
* @param sibling YANG node
*/
private void setNextSibling(YangNode sibling) {
public void setNextSibling(YangNode sibling) {
nextSibling = sibling;
}
......@@ -203,7 +204,7 @@ public abstract class YangNode
*
* @param previousSibling points to predecessor sibling
*/
private void setPreviousSibling(YangNode previousSibling) {
public void setPreviousSibling(YangNode previousSibling) {
this.previousSibling = previousSibling;
}
......
......@@ -124,8 +124,8 @@ public class YangNotification
*/
public YangNotification() {
super(YangNodeType.NOTIFICATION_NODE);
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
@Override
......
......@@ -70,7 +70,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangOutput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode {
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201612L;
......@@ -96,8 +96,8 @@ public class YangOutput
*/
public YangOutput() {
super(YangNodeType.OUTPUT_NODE);
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
@Override
......
......@@ -82,7 +82,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.resolveLi
public class YangSubModule
extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CollisionDetector, YangReferenceResolver,
RpcNotificationContainer, YangFeatureHolder {
RpcNotificationContainer, YangFeatureHolder, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201614L;
......@@ -209,9 +209,9 @@ public class YangSubModule
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* Leafref resolution list.
* LeafRef resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
private List<YangResolutionInfo> leafRefResolutionList;
/**
* Base resolution list.
......@@ -219,9 +219,9 @@ public class YangSubModule
private List<YangResolutionInfo> baseResolutionList;
/**
* Identityref resolution list.
* IdentityRef resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
private List<YangResolutionInfo> identityRefResolutionList;
/**
* Compiler annotation list.
......@@ -247,15 +247,15 @@ public class YangSubModule
augmentResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
leafRefResolutionList = new LinkedList<>();
baseResolutionList = new LinkedList<>();
identityrefResolutionList = new LinkedList<>();
identityRefResolutionList = new LinkedList<>();
compilerAnnotationList = new LinkedList<>();
importList = new LinkedList<YangImport>();
includeList = new LinkedList<YangInclude>();
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
extensionList = new LinkedList<YangExtension>();
importList = new LinkedList<>();
includeList = new LinkedList<>();
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
extensionList = new LinkedList<>();
}
/**
......@@ -592,11 +592,11 @@ public class YangSubModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else if (type == ResolvableType.YANG_LEAFREF) {
return leafrefResolutionList;
return leafRefResolutionList;
} else if (type == ResolvableType.YANG_BASE) {
return baseResolutionList;
} else {
return identityrefResolutionList;
return identityRefResolutionList;
}
}
......@@ -610,13 +610,13 @@ public class YangSubModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList.add(resolutionInfo);
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);
identityRefResolutionList.add(resolutionInfo);
}
}
......@@ -630,13 +630,13 @@ public class YangSubModule
} else if (type == ResolvableType.YANG_IF_FEATURE) {
ifFeatureResolutionList.add((YangResolutionInfo) resolutionList);
} else if (type == ResolvableType.YANG_LEAFREF) {
leafrefResolutionList = resolutionList;
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;
identityRefResolutionList = resolutionList;
}
}
......
......@@ -276,7 +276,7 @@ public class YangType<T>
* @param value input data value
* @throws DataModelException a violation of data model rules
*/
public void isValidValue(String value) throws DataModelException {
void isValidValue(String value) throws DataModelException {
switch (getDataType()) {
case INT8:
case INT16:
......
......@@ -17,6 +17,7 @@ package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
......@@ -68,7 +69,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.updateClo
public class YangUses
extends YangNode
implements YangCommonInfo, Parsable, Resolvable, CollisionDetector, YangWhenHolder,
YangIfFeatureHolder {
YangIfFeatureHolder, YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201617L;
......
......@@ -27,14 +27,14 @@ public final class YangPluginConfig {
private String codeGenDir;
/**
* Contains the code generation directory.
* Contains information of naming conflicts that can be resolved.
*/
private String managerCodeGenDir;
private YangToJavaNamingConflictUtil conflictResolver;
/**
* Contains information of naming conflicts that can be resolved.
* Java code generation is for sbi.
*/
private YangToJavaNamingConflictUtil conflictResolver;
private String codeGenerateForsbi;
/**
* Creates an object for YANG plugin config.
......@@ -43,11 +43,6 @@ public final class YangPluginConfig {
}
/**
* Java code generation is for sbi.
*/
private String codeGenerateForsbi;
/**
* Returns the string for code generation.
*
* @return returns the string for code generation.
......@@ -101,21 +96,4 @@ public final class YangPluginConfig {
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,6 +16,22 @@
package org.onosproject.yangutils.datamodel.utils;
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.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
......@@ -41,22 +57,13 @@ import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Represents utilities for data model tree.
*/
public final class DataModelUtils {
public static final String TRUE = "true";
public static final String FALSE = "false";
private static final String SLASH = File.separator;
/**
* Creates a new data model tree utility.
......@@ -103,7 +110,7 @@ public final class DataModelUtils {
* @param node node instance of calling node
* @throws DataModelException a violation of data model rules
*/
public static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
private static void detectCollidingForUsesGrouping(String identifierName, YangConstructType dataType, YangNode node)
throws DataModelException {
node = node.getChild();
......@@ -297,27 +304,24 @@ public final class DataModelUtils {
/**
* Returns de-serializes YANG data-model nodes.
*
* @param serializableInfoSet YANG file info set
* @param serializedFileInfo serialized File Info
* @return de-serializes YANG data-model nodes
* @throws IOException when fails do IO operations
*/
public static List<YangNode> deSerializeDataModel(List<String> serializableInfoSet) throws IOException {
public static YangNode deSerializeDataModel(String serializedFileInfo) throws IOException {
List<YangNode> nodes = new ArrayList<>();
for (String fileInfo : serializableInfoSet) {
YangNode node = null;
YangNode node;
try {
FileInputStream fileInputStream = new FileInputStream(fileInfo);
FileInputStream fileInputStream = new FileInputStream(serializedFileInfo);
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.");
throw new IOException(serializedFileInfo + " not found.");
}
}
return nodes;
return node;
}
/**
......@@ -332,7 +336,7 @@ public final class DataModelUtils {
throws CloneNotSupportedException, DataModelException {
List<YangLeaf> currentListOfLeaves = leavesHolder.getListOfLeaf();
if (currentListOfLeaves != null) {
List<YangLeaf> clonedLeavesList = new LinkedList<YangLeaf>();
List<YangLeaf> clonedLeavesList = new LinkedList<>();
for (YangLeaf leaf : currentListOfLeaves) {
YangLeaf clonedLeaf = leaf.clone();
if (yangUses.getCurrentGroupingDepth() == 0) {
......@@ -350,7 +354,7 @@ public final class DataModelUtils {
List<YangLeafList> currentListOfLeafList = leavesHolder.getListOfLeafList();
if (currentListOfLeafList != null) {
List<YangLeafList> clonedListOfLeafList = new LinkedList<YangLeafList>();
List<YangLeafList> clonedListOfLeafList = new LinkedList<>();
for (YangLeafList leafList : currentListOfLeafList) {
YangLeafList clonedLeafList = leafList.clone();
if (yangUses.getCurrentGroupingDepth() == 0) {
......@@ -410,11 +414,9 @@ public final class DataModelUtils {
while (atomicPathIterator.hasNext()) {
YangAtomicPath atomicPath = atomicPathIterator.next();
Map<String, String> prefixesAndItsImportNameNode = leafrefForCloning.getPrefixAndItsImportedModule();
if (!prefixesAndItsImportNameNode.isEmpty() || prefixesAndItsImportNameNode != null) {
String prefixInPath = atomicPath.getNodeIdentifier().getPrefix();
String importedNodeName = prefixesAndItsImportNameNode.get(prefixInPath);
assignCurrentLeafrefWithNewPrefixes(importedNodeName, atomicPath, yangUses);
}
assignCurrentLeafedWithNewPrefixes(importedNodeName, atomicPath, yangUses);
}
}
}
......@@ -427,7 +429,7 @@ public final class DataModelUtils {
* @param node instance of YANG uses where cloning is done
* @throws DataModelException data model error
*/
private static void assignCurrentLeafrefWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath,
private static void assignCurrentLeafedWithNewPrefixes(String importedNodeName, YangAtomicPath atomicPath,
YangNode node) throws DataModelException {
while (!(node instanceof YangReferenceResolver)) {
node = node.getParent();
......@@ -534,7 +536,7 @@ public final class DataModelUtils {
dataTypeName = unionNode.getName();
}
if (potentialTypeNode.getName().contentEquals(dataTypeName)) {
dataType.setDataTypeExtendedInfo((Object) potentialTypeNode);
dataType.setDataTypeExtendedInfo(potentialTypeNode);
return;
}
potentialTypeNode = potentialTypeNode.getNextSibling();
......@@ -542,4 +544,52 @@ public final class DataModelUtils {
throw new DataModelException("Data model error: cloned leaves type is not found");
}
/**
* Parses jar file and returns list of serialized file names.
*
* @param jarFile jar file to be parsed
* @param directory directory where to search
* @return list of serialized files
* @throws IOException when fails to do IO operations
*/
public static List<YangNode> parseJarFile(String jarFile, String directory)
throws IOException {
List<YangNode> nodes = new ArrayList<>();
JarFile jar = new JarFile(jarFile);
Enumeration<?> enumEntries = jar.entries();
while (enumEntries.hasMoreElements()) {
JarEntry file = (JarEntry) enumEntries.nextElement();
if (file.getName().endsWith(".ser")) {
if (file.getName().contains(SLASH)) {
String[] strArray = file.getName().split(SLASH);
String tempPath = "";
for (int i = 0; i < strArray.length - 1; i++) {
tempPath = SLASH + tempPath + SLASH + strArray[i];
}
File dir = new File(directory + tempPath);
dir.mkdirs();
}
File serializedFile = new File(directory + SLASH + file.getName());
if (file.isDirectory()) {
serializedFile.mkdirs();
continue;
}
InputStream inputStream = jar.getInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(serializedFile);
while (inputStream.available() > 0) {
fileOutputStream.write(inputStream.read());
}
fileOutputStream.close();
inputStream.close();
nodes.add(deSerializeDataModel(serializedFile.toString()));
}
}
jar.close();
return nodes;
}
}
......
......@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
......@@ -41,7 +42,6 @@ import org.onosproject.yangutils.linker.exceptions.LinkerException;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
/**
* Represent utilities for YANG linker.
......@@ -73,7 +73,7 @@ public final class YangLinkerUtils {
}
}
if (targetNode instanceof YangChoice) {
// no need to check here.
//Do nothing
} else {
detectCollisionInLeaveHolders(targetNode, augment);
while (augmentsChild != null) {
......@@ -83,7 +83,7 @@ public final class YangLinkerUtils {
}
}
/*Detects collision between leaves/leaflists*/
/*Detects collision between leaves/leaf-lists*/
private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
YangNode parent = targetNode;
......@@ -160,17 +160,19 @@ public final class YangLinkerUtils {
* @param remainingAncestors ancestor count to move in augment path
* @return list of path names needed in leafref
*/
public static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) {
String augmentName = augment.getName();
static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) {
List<String> listOfPathName = new ArrayList<>();
if (augmentName.contains(SLASH_FOR_STRING)) {
String[] augmentNodeNames = augmentName.split(SLASH_FOR_STRING);
for (String valueInAugment : augmentNodeNames) {
if (valueInAugment != null && valueInAugment != EMPTY_STRING && !valueInAugment.isEmpty()) {
listOfPathName.add(valueInAugment);
}
for (YangAtomicPath atomicPath : augment.getTargetNode()) {
if (atomicPath.getNodeIdentifier().getPrefix() != null && !atomicPath.getNodeIdentifier().getPrefix()
.equals(EMPTY_STRING)) {
listOfPathName.add(atomicPath.getNodeIdentifier().getPrefix() + ":" +
atomicPath.getNodeIdentifier().getName());
} else {
listOfPathName.add(atomicPath.getNodeIdentifier().getName());
}
}
for (int countOfAncestor = 0; countOfAncestor < remainingAncestors; countOfAncestor++) {
listOfPathName.remove(listOfPathName.size() - 1);
}
......@@ -185,7 +187,7 @@ public final class YangLinkerUtils {
* @return parent node which can hold data
* @throws LinkerException a violation of linker rules
*/
public static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref) throws LinkerException {
static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref) throws LinkerException {
while (currentParent instanceof YangChoice || currentParent instanceof YangCase) {
if (currentParent.getParent() == null) {
throw new LinkerException("YANG file error: The target node, in the leafref path " +
......@@ -203,7 +205,7 @@ public final class YangLinkerUtils {
* @param yangConstruct yang construct for creating error message
* @return valid node identifier
*/
public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
YangConstructType yangConstruct) {
String[] tmpData = nodeIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
......@@ -264,7 +266,7 @@ public final class YangLinkerUtils {
*
* @param yangNode YANG node information
*/
public static void updateFilePriorityOfNode(YangNode yangNode) {
private static void updateFilePriorityOfNode(YangNode yangNode) {
int curNodePriority = yangNode.getPriority();
if (yangNode instanceof YangReferenceResolver) {
List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
......
......@@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.TraversalType;
......@@ -1221,7 +1222,7 @@ public class YangResolutionInfoImpl<T>
YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
if (entityToResolve instanceof YangAugment) {
YangNode targetNode = null;
YangNode targetNode;
YangAugment augment = (YangAugment) entityToResolve;
targetNode = xPathLinker.processAugmentXpathLinking(augment.getTargetNode(),
(YangNode) root);
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.parser.impl;
import java.io.IOException;
import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
......
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
/**
* Represents YANG file information.
*/
public class YangFileInfo {
class YangFileInfo {
/**
* YANG file name.
......@@ -79,7 +79,7 @@ public class YangFileInfo {
*
* @return yangFileName YANG file name
*/
public String getYangFileName() {
String getYangFileName() {
return yangFileName;
}
......@@ -88,7 +88,7 @@ public class YangFileInfo {
*
* @param yangFileName YANG file name
*/
public void setYangFileName(String yangFileName) {
void setYangFileName(String yangFileName) {
this.yangFileName = yangFileName;
}
......@@ -151,7 +151,7 @@ public class YangFileInfo {
*
* @return isForTranslator true if node need to be translated
*/
public boolean isForTranslator() {
boolean isForTranslator() {
return isForTranslator;
}
......@@ -160,7 +160,7 @@ public class YangFileInfo {
*
* @param isForTranslator true if node need to be translated
*/
public void setForTranslator(boolean isForTranslator) {
void setForTranslator(boolean isForTranslator) {
this.isForTranslator = isForTranslator;
}
......
......@@ -19,41 +19,36 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
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;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_RESOURCES;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Represents YANG plugin utilities.
*/
public final class YangPluginUtils {
final class YangPluginUtils {
private static final Logger log = getLogger(YangPluginUtils.class);
......@@ -71,7 +66,7 @@ public final class YangPluginUtils {
* @param project current maven project
* @param context current build context
*/
public static void addToCompilationRoot(String source, MavenProject project, BuildContext context) {
static void addToCompilationRoot(String source, MavenProject project, BuildContext context) {
project.addCompileSourceRoot(source);
context.refresh(project.getBasedir());
log.info("Source directory added to compilation root: " + source);
......@@ -85,7 +80,7 @@ public final class YangPluginUtils {
* @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
throws IOException {
List<File> files = getListOfFile(yangFileInfo);
......@@ -129,7 +124,7 @@ public final class YangPluginUtils {
* @param operation true if need to add to resource
* @throws IOException when fails to do IO operations
*/
public static void serializeDataModel(String directory, Set<YangFileInfo> fileInfoSet,
static void serializeDataModel(String directory, Set<YangFileInfo> fileInfoSet,
MavenProject project, boolean operation) throws IOException {
String serFileDirPath = directory + TARGET_RESOURCE_PATH;
......@@ -142,7 +137,7 @@ public final class YangPluginUtils {
for (YangFileInfo fileInfo : fileInfoSet) {
String serFileName = serFileDirPath + getCamelCase(fileInfo.getRootNode().getName(), null)
String serFileName = serFileDirPath + fileInfo.getRootNode().getName()
+ SERIALIZED_FILE_EXTENSION;
fileInfo.setSerializedFile(serFileName);
FileOutputStream fileOutputStream = new FileOutputStream(serFileName);
......@@ -201,67 +196,18 @@ public final class YangPluginUtils {
* @return list of resolved datamodel nodes
* @throws IOException when fails to do IO operations
*/
public static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepos, String directory)
throws IOException {
List<String> dependeciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
List<String> dependenciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
List<YangNode> resolvedDataModelNodes = new ArrayList<>();
for (String dependecy : dependeciesJarPaths) {
resolvedDataModelNodes.addAll(deSerializeDataModel(parseJarFile(dependecy, directory)));
for (String dependency : dependenciesJarPaths) {
resolvedDataModelNodes.addAll(DataModelUtils.parseJarFile(dependency, directory));
}
return resolvedDataModelNodes;
}
/**
* Parses jar file and returns list of serialized file names.
*
* @param jarFile jar file to be parsed
* @param directory directory for keeping the searized files
* @return list of serialized files
* @throws IOException when fails to do IO operations
*/
public static List<String> parseJarFile(String jarFile, String directory)
throws IOException {
List<String> serailizedFiles = new ArrayList<>();
JarFile jar = new JarFile(jarFile);
Enumeration<?> enumEntries = jar.entries();
File serializedFileDir = new File(directory);
serializedFileDir.mkdirs();
while (enumEntries.hasMoreElements()) {
JarEntry file = (JarEntry) enumEntries.nextElement();
if (file.getName().endsWith(SERIALIZED_FILE_EXTENSION)) {
if (file.getName().contains(SLASH)) {
String[] strArray = file.getName().split(SLASH);
String tempPath = "";
for (int i = 0; i < strArray.length - 1; i++) {
tempPath = SLASH + tempPath + SLASH + strArray[i];
}
File dir = new File(directory + tempPath);
dir.mkdirs();
}
File serailizedFile = new File(directory + SLASH + file.getName());
if (file.isDirectory()) {
serailizedFile.mkdirs();
continue;
}
InputStream inputStream = jar.getInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(serailizedFile);
while (inputStream.available() > 0) {
fileOutputStream.write(inputStream.read());
}
fileOutputStream.close();
inputStream.close();
serailizedFiles.add(serailizedFile.toString());
}
}
jar.close();
return serailizedFiles;
}
/* Adds directory to resources of project */
private static void addToProjectResource(String dir, MavenProject project) {
Resource rsc = new Resource();
......
......@@ -32,6 +32,8 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.linker.YangLinker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
......@@ -39,8 +41,6 @@ import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
......@@ -70,7 +70,7 @@ public class YangUtilManager
extends AbstractMojo {
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
YangPluginConfig yangPlugin = new YangPluginConfig();
private YangPluginConfig yangPlugin = new YangPluginConfig();
private YangNode rootNode;
// YANG file information set.
private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
......@@ -91,12 +91,6 @@ public class YangUtilManager
private String classFileDir;
/**
* Source directory for manager's generated files.
*/
@Parameter(property = "managerFileDir", defaultValue = "src/main/java")
private String managerFileDir;
/**
* Base directory for project.
*/
@Parameter(property = "basedir", defaultValue = "${basedir}")
......@@ -159,8 +153,8 @@ public class YangUtilManager
/**
* Code generation is for nbi or sbi.
*/
@Parameter(property = "generateJavaFileForsbi", defaultValue = "nbi")
private String generateJavaFileForsbi;
@Parameter(property = "generateJavaFileForSbi", defaultValue = "nbi")
private String generateJavaFileForSbi;
@Override
public void execute()
......@@ -171,12 +165,10 @@ public class YangUtilManager
/*
* For deleting the generated code in previous build.
*/
deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, outputDirectory));
String searchDir = getDirectory(baseDir, yangFilesDir);
String codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
String managerCodeGenDir = getDirectory(baseDir, managerFileDir) + SLASH;
// Creates conflict resolver and set values to it.
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
......@@ -185,10 +177,9 @@ public class YangUtilManager
conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
conflictResolver.setPrefixForIdentifier(prefixForIdentifier);
yangPlugin.setCodeGenDir(codeGenDir);
yangPlugin.setManagerCodeGenDir(managerCodeGenDir);
yangPlugin.setConflictResolver(conflictResolver);
yangPlugin.setCodeGenerateForsbi(generateJavaFileForsbi.toLowerCase());
yangPlugin.setCodeGenerateForsbi(generateJavaFileForSbi.toLowerCase());
/*
* Obtain the YANG files at a path mentioned in plugin and creates
* YANG file information set.
......@@ -216,7 +207,6 @@ public class YangUtilManager
serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
addToCompilationRoot(codeGenDir, project, context);
addToCompilationRoot(managerCodeGenDir, project, context);
copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
} catch (IOException | ParserException e) {
......@@ -232,7 +222,7 @@ public class YangUtilManager
"Error handler failed to delete files for data model node.");
}
throw new MojoExecutionException(
"Exception occured due to " + e.getLocalizedMessage() + " in " + fileName
"Exception occurred due to " + e.getLocalizedMessage() + " in " + fileName
+ " YANG file.");
}
}
......@@ -264,14 +254,14 @@ public class YangUtilManager
getYangFileInfoSet().add(dependentFileInfo);
}
} catch (IOException e) {
throw new IOException("failed to resolve in interjar scenario.");
throw new IOException("failed to resolve in inter-jar scenario.");
}
}
/**
* Links all the provided with the YANG file info set.
*
* @throws MojoExecutionException a violation in mojo excecution
* @throws MojoExecutionException a violation in mojo execution
*/
public void resolveDependenciesUsingLinker()
throws MojoExecutionException {
......@@ -378,7 +368,7 @@ public class YangUtilManager
*
* @return the YANG file info set
*/
public Set<YangFileInfo> getYangFileInfoSet() {
Set<YangFileInfo> getYangFileInfoSet() {
return yangFileInfoSet;
}
......
......@@ -39,7 +39,7 @@ public final class GeneratedJavaFileType {
/**
* Impl class file.
*/
public static final int IMPL_CLASS_MASK = 8;
public static final int DEFAULT_CLASS_MASK = 8;
/**
* Interface and class file.
......@@ -69,7 +69,7 @@ public final class GeneratedJavaFileType {
/**
* Java class corresponding to typedef.
*/
public static final int GENERATE_TYPE_CLASS = GENERATE_TYPEDEF_CLASS
static final int GENERATE_TYPE_CLASS = GENERATE_TYPEDEF_CLASS
| GENERATE_UNION_CLASS;
/**
......@@ -99,16 +99,6 @@ public final class GeneratedJavaFileType {
public static final int GENERATE_IDENTITY_CLASS = 2048;
/**
* Operation class file.
*/
public static final int OPERATION_CLASS_MASK = 4096;
/**
* Operation class builder file.
*/
public static final int OPERATION_BUILDER_CLASS_MASK = 8192;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
......
......@@ -122,6 +122,21 @@ public final class GeneratedTempFileType {
public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
/**
* Add to list method interface for class.
*/
public static final int ADD_TO_LIST_INTERFACE_MASK = 1048576;
/**
* Add to list method implementation for class.
*/
public static final int ADD_TO_LIST_IMPL_MASK = 2097152;
/**
* Leaf identifier enum attributes for class.
*/
public static final int LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK = 4194304;
/**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
......
......@@ -90,10 +90,6 @@ public final class JavaAttributeInfo {
* @return the data type info of attribute
*/
public YangType<?> getAttributeType() {
if (attrType == null) {
throw new TranslatorException("Expected java attribute type is null");
}
return attrType;
}
......
......@@ -17,11 +17,18 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
......@@ -31,6 +38,11 @@ import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getAugmentClassName;
import static org.onosproject.yangutils.utils.UtilConstants.CASE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......@@ -88,6 +100,11 @@ public final class JavaCodeGeneratorUtil {
TraversalType curTraversal = ROOT;
while (codeGenNode != null) {
if (codeGenNode instanceof YangAugment) {
if (((YangAugment) codeGenNode).getAugmentedNode() instanceof YangChoice) {
addCaseNodeToChoiceTarget((YangAugment) codeGenNode);
}
}
if (curTraversal != PARENT) {
if (!(codeGenNode instanceof JavaCodeGenerator)) {
throw new TranslatorException("Unsupported node to generate code");
......@@ -285,7 +302,7 @@ public final class JavaCodeGeneratorUtil {
searchAndDeleteTempDir(javaFileInfo.getBaseCodeGenPath() +
javaFileInfo.getPackageFilePath());
} else {
searchAndDeleteTempDir(yangPlugin.getManagerCodeGenDir());
searchAndDeleteTempDir(yangPlugin.getCodeGenDir());
}
}
}
......@@ -347,4 +364,43 @@ public final class JavaCodeGeneratorUtil {
}
return null;
}
/**
* Adds a case node in augment when augmenting a choice node.
*
* @param augment augment node
*/
private static void addCaseNodeToChoiceTarget(YangAugment augment) {
YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
YangPluginConfig pluginConfig = new YangPluginConfig();
javaCase.setName(getAugmentClassName(augment, pluginConfig) + getCapitalCase(CASE));
if (augment.getListOfLeaf() != null) {
augment.getListOfLeaf().forEach(javaCase::addLeaf);
augment.getListOfLeaf().clear();
}
if (augment.getListOfLeafList() != null) {
augment.getListOfLeafList().forEach(javaCase::addLeafList);
augment.getListOfLeafList().clear();
}
YangNode child = augment.getChild();
List<YangNode> childNodes = new ArrayList<>();
while (child != null) {
child.setParent(javaCase);
childNodes.add(child);
child = child.getNextSibling();
}
augment.setChild(null);
try {
augment.addChild(javaCase);
for (YangNode node : childNodes) {
node.setNextSibling(null);
node.setPreviousSibling(null);
javaCase.addChild(node);
}
} catch (DataModelException e) {
System.out.print("failed to add child node due to " + javaCase.getName() + " " + e.getLocalizedMessage());
}
}
}
......
......@@ -42,9 +42,6 @@ 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.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
import static java.util.Collections.sort;
/**
......@@ -226,7 +223,7 @@ public class JavaImportData {
*
* @return import for list attribute
*/
private String getImportForList() {
String getImportForList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
}
......@@ -285,25 +282,6 @@ public class JavaImportData {
}
/**
* Returns import string for hash map class.
*
* @return import string for hash map class
*/
String getYangAugmentedInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
/**
* Returns import string for YangAugmentedOpParamInfo class.
*
* @return import string for YangAugmentedOpParamInfo class
*/
String getYangAugmentedOpParamInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD +
YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
}
/**
* Returns import for big integer.
*
* @return import for big integer
......
......@@ -36,7 +36,6 @@ import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJa
*/
public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
implements Comparable<JavaQualifiedTypeInfoTranslator>, Serializable {
private static final long serialVersionUID = 806201634L;
/**
......@@ -98,7 +97,7 @@ public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
* Current leaves holder is adding a leaf info as a attribute to the
* current class.
*/
String className = AttributesJavaDataType.getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
String className = getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
leaf.getConflictResolveConfig());
if (className != null) {
/*
......@@ -106,7 +105,7 @@ public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
* since it can be a derived type or a usage of wrapper classes.
*/
importInfo.setClassInfo(className);
String classPkg = AttributesJavaDataType.getJavaImportPackage(leaf.getDataType(),
String classPkg = getJavaImportPackage(leaf.getDataType(),
leaf.isLeafList(), leaf.getConflictResolveConfig());
if (classPkg == null) {
throw new TranslatorException("import package cannot be null when the class is used");
......@@ -222,5 +221,4 @@ public class JavaQualifiedTypeInfoTranslator extends JavaQualifiedTypeInfo
public int compareTo(JavaQualifiedTypeInfoTranslator other) {
return getClassInfo().compareTo(other.getClassInfo());
}
}
......
......@@ -29,6 +29,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
/**
* Represents implementation of java code fragments temporary implementations.
......@@ -263,18 +264,24 @@ public class TempJavaCodeFragmentFiles {
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
* @param pluginConfig plugin configurations
* @param curNode YANG node
* @return default constructor for class
* @throws IOException when fails to append to file
*/
public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
public String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig,
YangNode curNode)
throws IOException {
boolean isSuffix = false;
if (toAppend.equals(BUILDER)) {
isSuffix = true;
}
if (getTypeTempFiles() != null) {
return getTypeTempFiles()
.addDefaultConstructor(modifier, toAppend, pluginConfig);
.addDefaultConstructor(modifier, toAppend, pluginConfig, isSuffix);
}
if (getBeanTempFiles() != null) {
return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig);
return getBeanTempFiles().addDefaultConstructor(modifier, toAppend, pluginConfig, isSuffix);
}
throw new TranslatorException("default constructor should not be added");
......@@ -283,10 +290,11 @@ public class TempJavaCodeFragmentFiles {
/**
* Adds build method's implementation for class.
*
* @param curNode YANG node
* @return build method implementation for class
* @throws IOException when fails to append to temporary file
*/
public String addBuildMethodImpl()
public String addBuildMethodImpl(YangNode curNode)
throws IOException {
if (getBeanTempFiles() != null) {
return getBeanTempFiles().addBuildMethodImpl();
......
......@@ -22,26 +22,27 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
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.INT;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
/**
* Represents implementation of java code fragments temporary implementations. Maintains the temp files required
......@@ -227,8 +228,8 @@ public class TempJavaEnumerationFragmentFiles extends TempJavaFragmentFiles {
*/
public JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig pluginConfig) {
YangJavaTypeTranslator<?> javaType = new YangJavaTypeTranslator<>();
javaType.setDataType(YangDataTypes.INT32);
javaType.setDataTypeName("int");
javaType.setDataType(INT32);
javaType.setDataTypeName(INT);
javaType.updateJavaQualifiedInfo(pluginConfig.getConflictResolver());
return getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
......
......@@ -20,6 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
......@@ -489,7 +490,7 @@ public class TempJavaEventFragmentFiles
JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
parentInfo.getPluginConfig().getCodeGenDir());
parentInfo);
}
/**
......
......@@ -19,7 +19,6 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangLeaf;
......@@ -38,19 +37,21 @@ import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_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;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.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;
......@@ -58,18 +59,18 @@ import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getA
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamBuilderClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
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;
......@@ -82,29 +83,25 @@ 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.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.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.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
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.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
......@@ -182,6 +179,21 @@ public class TempJavaFragmentFiles {
private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
/**
* File name for from add to list interface method.
*/
private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME = "addToList";
/**
* File name for from add to list impl method.
*/
private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME = "addToListImpl";
/**
* File name for from leaf identifier attributes.
*/
private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME = "leafIdentifierAtr";
/**
* File name for interface java file name suffix.
*/
private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
......@@ -237,21 +249,11 @@ public class TempJavaFragmentFiles {
private File builderClassJavaFileHandle;
/**
* Java file handle for builder op param class file.
*/
private File builderOpParamClassJavaFileHandle;
/**
* Java file handle for impl class file.
*/
private File implClassJavaFileHandle;
/**
* Java file handle for op param class file.
*/
private File opParamClassJavaFileHandle;
/**
* Temporary file handle for attribute.
*/
private File attributesTempFileHandle;
......@@ -297,19 +299,39 @@ public class TempJavaFragmentFiles {
private File fromStringImplTempFileHandle;
/**
* Temporary file handle for add to list interface method of class.
*/
private File addToListInterfaceTempFileHandle;
/**
* Temporary file handle for add to list impl method of class.
*/
private File addToListImplTempFileHandle;
/**
* Temporary file handle for leaf id attributes of enum.
*/
private File leafIdAttributeTempFileHandle;
/**
* Import info for case.
*/
private JavaQualifiedTypeInfoTranslator caseImportInfo;
/**
* Is attribute added.
* Leaf count.
*/
private boolean isAttributePresent;
private int leafCount = 0;
/**
* Base code gen path.
* If current node is root node.
*/
private String baseCodePath;
private boolean isRooNode;
/**
* Is attribute added.
*/
private boolean isAttributePresent;
TempJavaFragmentFiles() {
}
......@@ -325,21 +347,17 @@ public class TempJavaFragmentFiles {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
setBaseCodePath(getJavaFileInfo().getPluginConfig().getCodeGenDir());
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getPluginConfig().getCodeGenDir(),
getJavaFileInfo().getPackageFilePath()));
} else {
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/*
* Initialize getter when generation file type matches to interface
* mask.
*/
if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
addGeneratedTempFile(ADD_TO_LIST_INTERFACE_MASK);
addGeneratedTempFile(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
}
/*
......@@ -365,12 +383,13 @@ public class TempJavaFragmentFiles {
* Initialize getterImpl, attributes, constructor, hash code, equals and
* to strings when generation file type matches to impl class mask.
*/
if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
addGeneratedTempFile(ATTRIBUTES_MASK);
addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
addGeneratedTempFile(HASH_CODE_IMPL_MASK);
addGeneratedTempFile(EQUALS_IMPL_MASK);
addGeneratedTempFile(TO_STRING_IMPL_MASK);
addGeneratedTempFile(ADD_TO_LIST_IMPL_MASK);
}
/*
......@@ -398,23 +417,18 @@ public class TempJavaFragmentFiles {
if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
}
if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
}
if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
}
if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
}
......@@ -427,6 +441,15 @@ public class TempJavaFragmentFiles {
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
setAddToListInterfaceTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
setAddToListImplTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
setLeafIdAttributeTempFileHandle(getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME));
}
}
/**
......@@ -457,8 +480,7 @@ public class TempJavaFragmentFiles {
JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
parent, isList, tempJavaBeanFragmentFiles);
getNodesInterfaceFragmentFiles(parent, javaAttributeInfo, pluginConfig);
tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
}
/**
......@@ -493,20 +515,14 @@ public class TempJavaFragmentFiles {
boolean isQualified;
if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles)
&& (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(getCapitalCase(fileInfo.getJavaName() + SERVICE))
|| qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
&& (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE))
|| qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
isQualified = true;
} else {
String className;
if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
className = getCapitalCase(fileInfo.getJavaName()) + "Service";
className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
} else {
className = getCapitalCase(fileInfo.getJavaName());
}
......@@ -523,33 +539,6 @@ public class TempJavaFragmentFiles {
}
/**
* Adds java code snippet for corresponding files.
*
* @param node java node
* @param attr attribute info
* @param config plugin configurations
* @throws IOException when fails to do IO operations
*/
private static void getNodesInterfaceFragmentFiles(YangNode node, JavaAttributeInfo attr,
YangPluginConfig config) throws IOException {
TempJavaFragmentFiles tempJavaFragmentFiles;
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
.getTempJavaCodeFragmentFiles()
.getServiceTempFiles();
tempJavaFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
.getTempJavaCodeFragmentFiles()
.getBeanTempFiles();
tempJavaFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
}
}
/**
* Returns java attribute for leaf.
*
* @param tempJavaFragmentFiles temporary generated file
......@@ -593,42 +582,6 @@ public class TempJavaFragmentFiles {
true);
}
/**
* Retrieves the temporary file handle of op param builder class.
*
* @return op param builder temporary file handle
*/
private File getBuilderOpParamClassJavaFileHandle() {
return builderOpParamClassJavaFileHandle;
}
/**
* Sets the java file handle for op param builder class.
*
* @param builderOpParamClassJavaFileHandle java file handle
*/
private void setBuilderOpParamClassJavaFileHandle(File builderOpParamClassJavaFileHandle) {
this.builderOpParamClassJavaFileHandle = builderOpParamClassJavaFileHandle;
}
/**
* Returns base code path.
*
* @return base code path
*/
private String getBaseCodePath() {
return baseCodePath;
}
/**
* Sets base code path.
*
* @param baseCodePath base code path
*/
void setBaseCodePath(String baseCodePath) {
this.baseCodePath = baseCodePath;
}
/*
* Retrieves the absolute path where the file needs to be generated.
*
......@@ -1047,10 +1000,16 @@ public class TempJavaFragmentFiles {
*/
private void addSetterImpl(JavaAttributeInfo attr)
throws IOException {
if (isRooNode()) {
appendToFile(getSetterImplTempFileHandle(),
getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
+ NEW_LINE);
} else {
appendToFile(getSetterImplTempFileHandle(), getOverRideString() +
getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
+ NEW_LINE);
}
}
/**
* Adds getter method's impl for class.
......@@ -1063,9 +1022,14 @@ public class TempJavaFragmentFiles {
throws IOException {
if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
|| (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
if (!isRooNode()) {
appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
getGeneratedJavaFiles()) + NEW_LINE);
} else {
appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr,
getGeneratedJavaFiles()) + NEW_LINE);
}
} else {
appendToFile(getGetterImplTempFileHandle(),
getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
......@@ -1073,6 +1037,45 @@ public class TempJavaFragmentFiles {
}
/**
* Adds add to list interface method.
*
* @param attr attribute
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig) throws IOException {
appendToFile(getAddToListInterfaceTempFileHandle(),
getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getAddToListMethodInterface(attr) + NEW_LINE);
}
/**
* Adds add to list interface method.
*
* @param attr attribute
* @throws IOException when fails to do IO operations
*/
private void addAddToListImpl(JavaAttributeInfo attr) throws IOException {
appendToFile(getAddToListImplTempFileHandle(),
getAddToListMethodImpl(attr) + NEW_LINE);
}
/**
* Adds leaf identifier enum attributes.
*
* @param attr attribute
* @param value value
* @param yangPluginConfig plugin config
* @throws IOException when fails to do IO operations
*/
private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig)
throws IOException {
appendToFile(getLeafIdAttributeTempFileHandle(),
FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
value, yangPluginConfig));
}
/**
* Adds build method for interface.
*
* @param pluginConfig plugin configurations
......@@ -1092,7 +1095,7 @@ public class TempJavaFragmentFiles {
*/
String addBuildMethodImpl()
throws IOException {
return getBuildString(getGeneratedJavaClassName()) + NEW_LINE;
return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE;
}
/**
......@@ -1101,13 +1104,32 @@ public class TempJavaFragmentFiles {
* @param modifier modifier for constructor.
* @param toAppend string which need to be appended with the class name
* @param pluginConfig plugin configurations
* @param isSuffix is value need to be appended as suffix
* @return default constructor for class
* @throws IOException when fails to append to file
*/
String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig)
String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix)
throws IOException {
String name = getGeneratedJavaClassName();
if (isRooNode() && !toAppend.equals(BUILDER)) {
name = name + OP_PARAM;
return NEW_LINE
+ getDefaultConstructorString(getGeneratedJavaClassName() + toAppend, modifier, pluginConfig);
+ getDefaultConstructorString(name, modifier,
pluginConfig);
}
if (isSuffix) {
return NEW_LINE +
getDefaultConstructorString(name + toAppend, modifier, pluginConfig);
}
String appended;
if (toAppend.equals(DEFAULT)) {
appended = getCapitalCase(toAppend);
} else {
appended = toAppend;
}
return NEW_LINE
+ getDefaultConstructorString(appended + name, modifier,
pluginConfig);
}
/**
......@@ -1168,17 +1190,18 @@ public class TempJavaFragmentFiles {
throws IOException {
String path = getTempDirPath(getAbsoluteDirPath());
File dir = new File(path);
boolean isCreated;
if (!dir.exists()) {
boolean isCreated = dir.mkdirs();
isCreated = dir.mkdirs();
if (!isCreated) {
throw new IOException("failed to create temporary directory for " + fileName);
}
}
File file = new File(path + fileName + TEMP_FILE_EXTENSION);
if (!file.exists()) {
boolean isCreated = file.createNewFile();
isCreated = file.createNewFile();
if (!isCreated) {
throw new IOException("failed to create temporary files for " + fileName);
throw new IOException("failed to create temporary file for " + fileName);
}
} else {
throw new IOException(fileName + " is reused due to YANG naming");
......@@ -1195,7 +1218,7 @@ public class TempJavaFragmentFiles {
*/
File getJavaFileHandle(String fileName)
throws IOException {
return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getBaseCodePath());
return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
}
/**
......@@ -1246,11 +1269,11 @@ public class TempJavaFragmentFiles {
attributeAccessType = PROTECTED;
}
if (attr.isQualifiedName()) {
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
attr.getImportInfo().getClassInfo(),
attributeName, attr.isListAttr(), attributeAccessType);
} else {
return getJavaAttributeDefination(null, attr.getImportInfo().getClassInfo(), attributeName,
return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
attr.isListAttr(), attributeAccessType);
}
}
......@@ -1408,6 +1431,17 @@ public class TempJavaFragmentFiles {
if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
addToStringMethod(newAttrInfo);
}
if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) {
addAddToListImpl(newAttrInfo);
}
if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) {
addAddToListInterface(newAttrInfo, pluginConfig);
}
if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr()
&& newAttrInfo.getAttributeType() != null) {
leafCount++;
addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig);
}
if (!newAttrInfo.isIntConflict() &&
!newAttrInfo.isLongConflict()) {
......@@ -1445,28 +1479,14 @@ public class TempJavaFragmentFiles {
/**
* Returns java class name.
*
* @param node YANG node
* @return java class name
*/
private String getImplClassName() {
return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
private String getImplClassName(YangNode node) {
if (node instanceof YangModule || node instanceof YangSubModule) {
return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM;
}
/**
* Returns op param java class name.
*
* @return op param java class name
*/
private String getOpParamImplClassName() {
return getCapitalCase(getJavaFileInfo().getJavaName()) + OPERATION;
}
/**
* Returns op param builder java class name.
*
* @return op param builder java class name
*/
private String getOpParamBuilderImplClassName() {
return getCapitalCase(getJavaFileInfo().getJavaName()) + OPERATION + BUILDER;
return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
}
/**
......@@ -1487,15 +1507,11 @@ public class TempJavaFragmentFiles {
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
addResolvedAugmentedDataNodeImports(curNode);
}
TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
.getJavaImportData().getImports();
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, true, true);
}
createPackage(curNode);
/*
......@@ -1510,6 +1526,7 @@ public class TempJavaFragmentFiles {
setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
setInterfaceJavaFileHandle(
generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
/*
* Create builder interface file.
*/
......@@ -1525,30 +1542,32 @@ public class TempJavaFragmentFiles {
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
validateLineLength(getInterfaceJavaFileHandle());
}
}
insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
if (curNode instanceof YangCase) {
removeCaseImport(imports);
}
if (curNode instanceof YangAugment) {
removeAugmentedInfoImport(imports);
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, false, true);
}
}
if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(imports, true);
addArrayListImport(imports);
}
addBitsetImport(imports);
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, true);
addImportsForAugmentableClass(imports, true, false);
}
sortImports(imports);
/*
* Create impl class file.
*/
setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName()));
setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
setImplClassJavaFileHandle(
generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
/*
* Create builder class file.
......@@ -1565,53 +1584,7 @@ public class TempJavaFragmentFiles {
validateLineLength(getImplClassJavaFileHandle());
}
insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, false);
}
if (!(curNode instanceof YangModule)) {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(imports, false);
}
if (curNode instanceof YangAugmentableNode) {
addYangAugmentedOpParamInfoImport(imports);
}
JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = new JavaQualifiedTypeInfoTranslator();
qualifiedTypeInfo.setClassInfo(getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo()
.getJavaName()));
qualifiedTypeInfo.setPkgInfo(getJavaFileInfo().getPackage());
getJavaExtendsListHolder().addToExtendsList(qualifiedTypeInfo, curNode,
tempJavaBeanFragmentFiles);
addBitSetImport(imports, true);
if (curNode instanceof YangAugment) {
addYangAugmentedOpParamInfoImport(imports);
}
/*
* Create impl class file.
*/
setOpParamClassJavaFileHandle(getJavaFileHandle(getOpParamImplClassName()));
setOpParamClassJavaFileHandle(
generateOpParamImplClassFile(getOpParamClassJavaFileHandle(), curNode,
isAttributePresent(), imports));
/*
* Create builder class file.
*/
if ((fileType & BUILDER_CLASS_MASK) != 0) {
setBuilderOpParamClassJavaFileHandle(getJavaFileHandle(getOpParamBuilderImplClassName()));
setBuilderOpParamClassJavaFileHandle(
generateOpParamBuilderClassFile(getBuilderOpParamClassJavaFileHandle(), curNode,
isAttributePresent()));
/*
* Append impl class to builder class and close it.
*/
mergeJavaFiles(getBuilderOpParamClassJavaFileHandle(), getOpParamClassJavaFileHandle());
validateLineLength(getOpParamClassJavaFileHandle());
addBitSetImport(imports, false);
}
insertDataIntoJavaFile(getOpParamClassJavaFileHandle(), getJavaClassDefClose());
}
}
/*
* Close all the file handles.
......@@ -1619,9 +1592,16 @@ public class TempJavaFragmentFiles {
freeTemporaryResources(false);
}
/*Adds import for YANG augmented op param info.*/
private void addYangAugmentedOpParamInfoImport(List<String> imports) {
imports.add(getJavaImportData().getYangAugmentedOpParamInfoImport());
/*Adds import for array list.*/
private void addArrayListImport(List<String> imports) {
if (imports.contains(getJavaImportData().getImportForList())) {
imports.add(ARRAY_LIST_IMPORT);
}
}
/*Adds import for bitset list.*/
private void addBitsetImport(List<String> imports) {
imports.add(getJavaImportData().getImportForToBitSet());
}
/**
......@@ -1641,35 +1621,26 @@ public class TempJavaFragmentFiles {
}
/**
* Adds imports for bitSet method.
*
* @param imports import list
* @param operation add or remove
*/
private void addBitSetImport(List<String> imports, boolean operation) {
if (operation) {
imports.add(getJavaImportData().getImportForToBitSet());
} else {
imports.remove(getJavaImportData().getImportForToBitSet());
}
}
/**
* Adds import for map and hash map.
*
* @param imports import list
* @param operations true for adding and false for deletion
* @param isInterfaceFile if need to add in interface file
*/
private void addImportsForAugmentableClass(List<String> imports, boolean operations) {
private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile) {
if (operations) {
if (!isInterfaceFile) {
imports.add(getJavaImportData().getHashMapImport());
}
imports.add(getJavaImportData().getMapImport());
imports.add(getJavaImportData().getYangAugmentedInfoImport());
addInvocationExceptionImport(imports);
} else {
if (!isInterfaceFile) {
imports.remove(getJavaImportData().getHashMapImport());
}
imports.remove(getJavaImportData().getMapImport());
}
sortImports(imports);
}
/**
......@@ -1688,18 +1659,12 @@ public class TempJavaFragmentFiles {
}
/**
* Removes case import info from import list.
* Adds invocation exception import.
*
* @param imports list of imports
*/
private void removeAugmentedInfoImport(List<String> imports) {
imports.remove(getJavaImportData().getYangAugmentedInfoImport());
for (JavaQualifiedTypeInfoTranslator type : getJavaImportData().getImportSet()) {
if (type.getClassInfo().equals(YANG_AUGMENTED_INFO)) {
getJavaImportData().getImportSet().remove(type);
getJavaExtendsListHolder().getExtendsList().remove(type);
}
}
private void addInvocationExceptionImport(List<String> imports) {
imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
}
/**
......@@ -1719,13 +1684,10 @@ public class TempJavaFragmentFiles {
if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
closeFile(getBuilderClassJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & OPERATION_BUILDER_CLASS_MASK) != 0) {
closeFile(getBuilderOpParamClassJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
closeFile(getBuilderInterfaceJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
closeFile(getImplClassJavaFileHandle(), isErrorOccurred);
}
......@@ -1750,6 +1712,15 @@ public class TempJavaFragmentFiles {
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
closeFile(getFromStringImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
closeFile(getAddToListImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
closeFile(getAddToListInterfaceTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
closeFile(getLeafIdAttributeTempFileHandle(), true);
}
}
/**
......@@ -1767,20 +1738,74 @@ public class TempJavaFragmentFiles {
}
/**
* Returns java file handle for op param class file.
* Returns temp file handle for add to list interface.
*
* @return temp file handle for add to list interface
*/
public File getAddToListInterfaceTempFileHandle() {
return addToListInterfaceTempFileHandle;
}
/**
* Sets temp file handle for add to list interface.
*
* @param addToListInterfaceTempFileHandle temp file handle for add to list interface
*/
private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) {
this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle;
}
/**
* Returns temp file handle for add to list impl.
*
* @return temp file handle for add to list impl
*/
public File getAddToListImplTempFileHandle() {
return addToListImplTempFileHandle;
}
/**
* Sets temp file handle for add to list impl.
*
* @param addToListImplTempFileHandle temp file handle for add to list impl
*/
private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) {
this.addToListImplTempFileHandle = addToListImplTempFileHandle;
}
/**
* Returns temp file handle for leaf identifier attributes.
*
* @return temp file handle for leaf identifier attributes
*/
public File getLeafIdAttributeTempFileHandle() {
return leafIdAttributeTempFileHandle;
}
/**
* Sets temp file handle for leaf identifier attributes.
*
* @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes.
*/
private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) {
this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle;
}
/**
* Returns if root node is set.
*
* @return java file handle for op param class file
* @return true if root node
*/
private File getOpParamClassJavaFileHandle() {
return opParamClassJavaFileHandle;
private boolean isRooNode() {
return isRooNode;
}
/**
* Sets the java file handle for op param class file.
* Sets true if root node.
*
* @param opParamClassJavaFileHandle java file handle
* @param rooNode true if root node
*/
private void setOpParamClassJavaFileHandle(File opParamClassJavaFileHandle) {
this.opParamClassJavaFileHandle = opParamClassJavaFileHandle;
public void setRooNode(boolean rooNode) {
isRooNode = rooNode;
}
}
......
......@@ -22,23 +22,20 @@ import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAnnotationsImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addListenersImport;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
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.RPC_INPUT_VAR_NAME;
......@@ -47,7 +44,6 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
* Represents implementation of java service code fragments temporary implementations. Maintains the temp files required
......@@ -72,16 +68,6 @@ public class TempJavaServiceFragmentFiles
private static final String SERVICE_FILE_NAME_SUFFIX = "Service";
/**
* File name for generated class file for manager suffix.
*/
private static final String MANAGER_FILE_NAME_SUFFIX = "Manager";
/**
* Flag to set the manager files generation.
*/
private boolean isManagerNeedToBeGenerated = false;
/**
* Temporary file handle for rpc interface.
*/
private File rpcInterfaceTempFileHandle;
......@@ -97,16 +83,6 @@ public class TempJavaServiceFragmentFiles
private File serviceInterfaceJavaFileHandle;
/**
* Path for service file to be generated.
*/
private String serviceGenPath;
/**
* Java file handle for manager impl file.
*/
private File managerJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated file information
......@@ -117,8 +93,6 @@ public class TempJavaServiceFragmentFiles
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
setServiceGenPath(getJavaFileInfo().getPluginConfig().getCodeGenDir());
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
addGeneratedTempFile(RPC_INTERFACE_MASK);
......@@ -147,24 +121,6 @@ public class TempJavaServiceFragmentFiles
}
/**
* Returns managers java file handle.
*
* @return java file handle
*/
private File getManagerJavaFileHandle() {
return managerJavaFileHandle;
}
/**
* Sets manager java file handle.
*
* @param managerJavaFileHandle file handle for to manager
*/
private void setManagerJavaFileHandle(File managerJavaFileHandle) {
this.managerJavaFileHandle = managerJavaFileHandle;
}
/**
* Returns rpc method's temporary file handle.
*
* @return temporary file handle
......@@ -210,6 +166,8 @@ public class TempJavaServiceFragmentFiles
@Override
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
addResolvedAugmentedDataNodeImports(curNode);
List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles()
.getJavaImportData().getImports();
createPackage(curNode);
......@@ -228,28 +186,8 @@ public class TempJavaServiceFragmentFiles
addListenersImport(curNode, imports, true, LISTENER_SERVICE);
}
// Creates rpc interface file.
setBaseCodePath(getServiceGenPath());
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports);
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
if (isNotification) {
addListenersImport(curNode, imports, false, LISTENER_SERVICE);
addListenersImport(curNode, imports, true, LISTENER_REG);
}
addAnnotationsImports(imports, true);
// Create builder class file.
if (isManagerNeedToBeGenerated()) {
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode);
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
}
if (isNotification) {
addListenersImport(curNode, imports, false, LISTENER_REG);
}
addAnnotationsImports(imports, false);
// Close all the file handles.
freeTemporaryResources(false);
......@@ -314,7 +252,6 @@ public class TempJavaServiceFragmentFiles
throws IOException {
closeFile(getServiceInterfaceJavaFileHandle(), isErrorOccurred);
closeFile(getManagerJavaFileHandle(), isErrorOccurred);
closeFile(getRpcInterfaceTempFileHandle(), true);
closeFile(getRpcImplTempFileHandle(), true);
......@@ -325,41 +262,4 @@ public class TempJavaServiceFragmentFiles
super.freeTemporaryResources(isErrorOccurred);
}
/**
* Returns the path where service file should be generated.
*
* @return path where service file should be generated
*/
private String getServiceGenPath() {
return serviceGenPath;
}
/**
* Sets path where service file should be generated.
*
* @param serviceGenPath path where service file should be generated
*/
private void setServiceGenPath(String serviceGenPath) {
this.serviceGenPath = serviceGenPath;
}
/**
* Returns true if manager needs to be generated.
*
* @return true if manager needs to be generated
*/
private boolean isManagerNeedToBeGenerated() {
return isManagerNeedToBeGenerated;
}
/**
* Sets true if manager needs to be generated.
*
* @param managerNeedToBeGenerated true if manager needs to be generated
*/
public void setManagerNeedToBeGenerated(boolean managerNeedToBeGenerated) {
isManagerNeedToBeGenerated = managerNeedToBeGenerated;
}
}
......
......@@ -36,16 +36,9 @@ import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.utils.GeneratedLanguage;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugmentTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCaseTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoiceTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainerTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumerationTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentityTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInputTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafListTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaListTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotificationTranslator;
......@@ -56,6 +49,13 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTransla
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDefTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnionTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUsesTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugmentTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCaseTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentityTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInputTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafListTranslator;
/**
* Represents factory to create data model objects based on the target file type.
......
......@@ -16,18 +16,20 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.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.YangTranslatorOperatorNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
......@@ -44,13 +46,11 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
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.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG;
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.trimAtLast;
/**
* Represents utility class for YANG java model.
......@@ -74,19 +74,62 @@ public final class YangJavaModelUtils {
YangPluginConfig yangPluginConfig)
throws IOException {
if (javaCodeGeneratorInfo instanceof YangJavaAugmentTranslator) {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getAugmentClassName((YangJavaAugmentTranslator) javaCodeGeneratorInfo,
yangPluginConfig));
updatePackageForAugmentInfo(javaCodeGeneratorInfo, yangPluginConfig);
} else {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPluginConfig.getConflictResolver()));
}
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
}
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
}
/**
* Updates YANG java file package information.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPluginConfig YANG plugin config
* @throws IOException IO operations fails
*/
private static void updatePackageForAugmentInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getAugmentClassName((YangJavaAugmentTranslator) javaCodeGeneratorInfo,
yangPluginConfig));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(
getAugmentsNodePackage((YangNode) javaCodeGeneratorInfo, yangPluginConfig));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
}
/**
* Returns package for augment node.
*
* @param yangNode augment node
* @param yangPluginConfig plugin configurations
* @return package for augment node
*/
private static String getAugmentsNodePackage(YangNode yangNode, YangPluginConfig yangPluginConfig) {
YangAugment augment = (YangAugment) yangNode;
StringBuilder augmentPkg = new StringBuilder();
augmentPkg.append(getCurNodePackage(augment));
String pkg = PERIOD;
for (YangAtomicPath atomicPath : augment.getTargetNode()) {
pkg = pkg + getCamelCase(atomicPath.getNodeIdentifier().getName(), yangPluginConfig.getConflictResolver())
+ PERIOD;
}
pkg = trimAtLast(pkg, PERIOD);
augmentPkg.append(pkg.toLowerCase());
return augmentPkg.toString();
}
/**
......@@ -104,7 +147,7 @@ public final class YangJavaModelUtils {
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getManagerCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
}
......@@ -129,6 +172,12 @@ public final class YangJavaModelUtils {
private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
if (javaCodeGeneratorInfo instanceof YangModule
|| javaCodeGeneratorInfo instanceof YangSubModule) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().setRooNode(true);
}
if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
/*
* Module / sub module node code generation.
......@@ -268,20 +317,23 @@ public final class YangJavaModelUtils {
generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles();
if (javaCodeGeneratorInfo instanceof YangJavaAugmentTranslator) {
JavaQualifiedTypeInfoTranslator yangAugmentedInfo = new JavaQualifiedTypeInfoTranslator();
yangAugmentedInfo.setClassInfo(YANG_AUGMENTED_INFO);
yangAugmentedInfo.setPkgInfo(YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(yangAugmentedInfo, (YangNode) javaCodeGeneratorInfo,
tempJavaCodeFragmentFiles.getBeanTempFiles());
}
if (javaCodeGeneratorInfo instanceof YangCase) {
YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
if (parent instanceof YangAugment) {
parent = ((YangAugment) parent).getAugmentedNode();
}
JavaQualifiedTypeInfoTranslator parentsInfo = new JavaQualifiedTypeInfoTranslator();
String parentName = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
String parentName;
String parentPkg;
if (parentInfo.getPackage() != null) {
parentName = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
} else {
parentName = getCapitalCase(getCamelCase(parent.getName(), yangPlugin.getConflictResolver()));
parentPkg = getNodesPackage(parent, yangPlugin);
}
parentsInfo.setClassInfo(parentName);
parentsInfo.setPkgInfo(parentPkg);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
......@@ -363,17 +415,18 @@ public final class YangJavaModelUtils {
* @param node root YANG node
* @return true if root node contains any data node
*/
public static boolean isManagerCodeGenRequired(YangNode node) {
public static boolean isRootNodesCodeGenRequired(YangNode node) {
List<YangNode> childNodes = new ArrayList<>();
node = node.getChild();
while (node != null) {
childNodes.add(node);
node = node.getNextSibling();
YangNode tempNode = node.getChild();
while (tempNode != null) {
childNodes.add(tempNode);
tempNode = tempNode.getNextSibling();
}
if (childNodes.size() == 0) {
return false;
YangLeavesHolder leavesHolder = (YangLeavesHolder) node;
return !leavesHolder.getListOfLeaf().isEmpty() || !leavesHolder.getListOfLeafList().isEmpty();
} else if (childNodes.size() == 1) {
return !(childNodes.get(0) instanceof YangTranslatorOperatorNode);
}
......@@ -389,33 +442,13 @@ public final class YangJavaModelUtils {
}
/**
* Return false if files are already present.
* Returns nodes package.
*
* @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 != null && files.length >= 1) {
for (File file : files) {
if (file.getName().contentEquals(getCapitalCase(info.getJavaName() + MANAGER + ".java"))) {
return false;
}
}
}
return true;
}
/**
* Returns augmented nodes package.
*
* @param node augmented node
* @param node YANG node
* @param yangPluginConfig plugin config
* @return java package
*/
public static String getAugmentedNodesPackage(YangNode node, YangPluginConfig yangPluginConfig) {
public static String getNodesPackage(YangNode node, YangPluginConfig yangPluginConfig) {
List<String> clsInfo = new ArrayList<>();
while (node.getParent() != null) {
......@@ -424,7 +457,6 @@ public final class YangJavaModelUtils {
} else {
clsInfo.add(getCamelCase(node.getName(), yangPluginConfig.getConflictResolver()));
}
node = node.getParent();
}
......@@ -434,10 +466,10 @@ public final class YangJavaModelUtils {
pkg.append(getRootPackage(module.getVersion(), module.getNameSpace().getUri(), module
.getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
} else if (node instanceof YangJavaSubModuleTranslator) {
YangJavaSubModuleTranslator submodule = (YangJavaSubModuleTranslator) node;
pkg.append(getRootPackage(submodule.getVersion(),
submodule.getNameSpaceFromModule(submodule.getBelongsTo()),
submodule.getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
YangJavaSubModuleTranslator subModule = (YangJavaSubModuleTranslator) node;
pkg.append(getRootPackage(subModule.getVersion(),
subModule.getNameSpaceFromModule(subModule.getBelongsTo()),
subModule.getRevision().getRevDate(), yangPluginConfig.getConflictResolver()));
}
String concat = "";
for (int i = 1; i <= clsInfo.size(); i++) {
......@@ -456,12 +488,15 @@ public final class YangJavaModelUtils {
* @return augment class name
*/
public static String getAugmentClassName(YangAugment augment, YangPluginConfig yangPluginConfig) {
YangNodeIdentifier nodeId = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier();
String name = getCapitalCase(getCamelCase(nodeId.getName(), yangPluginConfig.getConflictResolver()));
if (nodeId.getPrefix() != null) {
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + name;
YangNodeIdentifier yangNodeIdentifier = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
.getNodeIdentifier();
String name = getCapitalCase(getCamelCase(yangNodeIdentifier.getName(), yangPluginConfig
.getConflictResolver()));
if (yangNodeIdentifier.getPrefix() != null) {
return AUGMENTED + getCapitalCase(yangNodeIdentifier.getPrefix()) + name;
} else {
return AUGMENTED + name;
}
}
}
......
......@@ -262,7 +262,7 @@ public final class AttributesJavaDataType {
case INSTANCE_IDENTIFIER:
return JAVA_LANG;
case DERIVED:
return getTypDefsPackage(yangType, conflictResolver);
return getTypeDefsPackage(yangType, conflictResolver);
default:
throw new TranslatorException("given data type is not supported.");
}
......@@ -288,7 +288,7 @@ public final class AttributesJavaDataType {
case INSTANCE_IDENTIFIER:
return JAVA_LANG;
case DERIVED:
return getTypDefsPackage(yangType, conflictResolver);
return getTypeDefsPackage(yangType, conflictResolver);
default:
return null;
}
......@@ -302,7 +302,7 @@ public final class AttributesJavaDataType {
* @param conflictResolver object of YANG to java naming conflict util
* @return java package for typedef node
*/
private static String getTypDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
private static String getTypeDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
Object var = type.getDataTypeExtendedInfo();
if (!(var instanceof YangDerivedInfo)) {
throw new TranslatorException("type should have been derived.");
......
......@@ -16,8 +16,8 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
/**
* Represent java based identification of the YANG leaves.
......@@ -25,21 +25,21 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflic
public interface JavaLeafInfoContainer
extends JavaQualifiedTypeInfoContainer {
/**
* Retreives the data type of the leaf.
* Retrieves the data type of the leaf.
*
* @return data type of the leaf
*/
YangType<?> getDataType();
/**
* Retreives the name of the leaf.
* Retrieves the name of the leaf.
*
* @return name of the leaf
*/
String getName();
/**
* Retreives the java name of the leaf.
* Retrieves the java name of the leaf.
*
* @param conflictResolveConfig user config to resolve conflicts
* @return name of the leaf
......
......@@ -21,7 +21,7 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContaine
/**
* Represent java based identification of the YANG leaves.
*/
public interface JavaQualifiedTypeResolver
interface JavaQualifiedTypeResolver
extends JavaQualifiedTypeInfoContainer {
/**
......
......@@ -17,6 +17,7 @@ package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaAugment;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
......@@ -118,10 +119,21 @@ public class YangJavaAugmentTranslator
@Override
public void generateCodeExit() throws TranslatorException {
try {
if (validateAugmentNode()) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
}
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for augmentable node " + getName());
}
}
/**
* Returns true if augment does not have choice as target node.
*
* @return true if augment does not have choice as target node
*/
private boolean validateAugmentNode() {
return !(getAugmentedNode() instanceof YangChoice);
}
}
......
......@@ -123,4 +123,5 @@ public class YangJavaCaseTranslator
throw new TranslatorException("Failed to generate code for case node " + getName());
}
}
}
......
......@@ -20,8 +20,8 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaGrouping;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
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.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
/**
......
......@@ -47,7 +47,7 @@ public class YangJavaIdentityTranslator extends YangJavaIdentity
//File type extension for java classes.
private static final String JAVA_FILE_EXTENSION = ".java";
//Contains the information of the importd.
//Contains the information of the imported.
private transient JavaImportData importData;
/**
......@@ -118,6 +118,7 @@ public class YangJavaIdentityTranslator extends YangJavaIdentity
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
try {
updatePackageInfo(this, yangPlugin);
JavaQualifiedTypeInfoTranslator basePkgInfo = new JavaQualifiedTypeInfoTranslator();
String className = getCapitalCase(getJavaFileInfo().getJavaName());
......@@ -142,7 +143,7 @@ public class YangJavaIdentityTranslator extends YangJavaIdentity
}
}
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo().getBaseCodeGenPath());
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
closeFile(file, false);
......
......@@ -33,8 +33,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -140,7 +139,7 @@ public class YangJavaModuleTranslator
*/
@Override
public void generateCodeExit() throws TranslatorException {
/**
/*
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
......@@ -153,17 +152,15 @@ public class YangJavaModuleTranslator
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
if (isRootNodesCodeGenRequired(this)) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
......@@ -197,22 +194,22 @@ public class YangJavaModuleTranslator
*
* @param curNode notification node
*/
private void addToNotificaitonList(YangNode curNode) {
private void addToNotificationList(YangNode curNode) {
getNotificationNodes().add(curNode);
}
/**
* Checks if there is any rpc defined in the module or sub-module.
* Checks if there is any notification node present.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
* @return status of notification's existence
*/
private boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangNotification) {
addToNotificaitonList(childNode);
addToNotificationList(childNode);
}
childNode = childNode.getNextSibling();
}
......
......@@ -116,7 +116,7 @@ public class YangJavaNotificationTranslator
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
/**
/*
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
......
......@@ -23,28 +23,22 @@ import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaRpc;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
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.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
......@@ -58,7 +52,7 @@ public class YangJavaRpcTranslator
private static final long serialVersionUID = 806201622L;
/**
* Temproary file for code generation.
* Temporary file for code generation.
*/
private transient TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles;
......@@ -191,7 +185,7 @@ public class YangJavaRpcTranslator
* @return AttributeInfo attribute details required to add in temporary
* files
*/
public JavaAttributeInfo getChildNodeAsAttributeInParentService(
private JavaAttributeInfo getChildNodeAsAttributeInParentService(
YangNode childNode, YangNode currentNode) {
YangNode parentNode = getParentNodeInGenCode(currentNode);
......@@ -229,13 +223,7 @@ public class YangJavaRpcTranslator
JavaFileInfo fileInfo = ((JavaFileInfoContainer) getParent()).getJavaFileInfo();
if (importInfo.getClassInfo().contentEquals(SERVICE)
|| importInfo.getClassInfo().contentEquals(COMPONENT)
|| importInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
|| importInfo.getClassInfo().contentEquals(getCapitalCase(DEACTIVATE))
|| importInfo.getClassInfo().contentEquals(REFERENCE_CARDINALITY)
|| importInfo.getClassInfo().contentEquals(REFERENCE)
|| importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))
|| importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + MANAGER))) {
|| importInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
return true;
}
......
......@@ -35,8 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -66,11 +65,11 @@ public class YangJavaSubModuleTranslator
public YangJavaSubModuleTranslator() {
super();
setJavaFileInfo(new JavaFileInfo());
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
int genType = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
genType = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
getJavaFileInfo().setGeneratedFileTypes(genType);
}
/**
......@@ -168,17 +167,14 @@ public class YangJavaSubModuleTranslator
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
if (isRootNodesCodeGenRequired(this)) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
......@@ -203,22 +199,22 @@ public class YangJavaSubModuleTranslator
*
* @param curNode notification node
*/
private void addToNotificaitonList(YangNode curNode) {
private void addToNotificationList(YangNode curNode) {
getNotificationNodes().add(curNode);
}
/**
* Checks if there is any rpc defined in the module or sub-module.
* Checks if there is any notification node present.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
* @return status of notification's existence
*/
private boolean isNotificationChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangNotification) {
addToNotificaitonList(childNode);
addToNotificationList(childNode);
}
childNode = childNode.getNextSibling();
}
......
......@@ -16,18 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaTypeDef;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
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.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
......@@ -109,12 +111,12 @@ public class YangJavaTypeDefTranslator
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
YangType typeInTypeDef = this.getTypeDefBaseType();
if (typeInTypeDef.getDataType() == YangDataTypes.DERIVED) {
if (typeInTypeDef.getDataType() == DERIVED) {
YangDerivedInfo derivedInfo = (YangDerivedInfo) typeInTypeDef.getDataTypeExtendedInfo();
if (derivedInfo.getEffectiveBuiltInType() == YangDataTypes.LEAFREF) {
if (derivedInfo.getEffectiveBuiltInType() == LEAFREF) {
throw new InvalidNodeForTranslatorException();
}
} else if (typeInTypeDef.getDataType() == YangDataTypes.LEAFREF) {
} else if (typeInTypeDef.getDataType() == LEAFREF) {
throw new InvalidNodeForTranslatorException();
}
try {
......
......@@ -16,10 +16,13 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaDataType;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportClass;
import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportPackage;
/**
* Represents java information corresponding to the YANG type.
......@@ -30,7 +33,7 @@ public class YangJavaTypeTranslator<T>
extends YangType<T>
implements JavaQualifiedTypeResolver {
private JavaQualifiedTypeInfo javaQualifiedAccess;
private JavaQualifiedTypeInfoTranslator javaQualifiedAccess;
/**
* Create a YANG leaf object with java qualified access details.
......@@ -47,14 +50,14 @@ public class YangJavaTypeTranslator<T>
/*
* Type is added as an attribute in the class.
*/
String className = AttributesJavaDataType.getJavaImportClass(this, false, conflictResolver);
String className = getJavaImportClass(this, false, conflictResolver);
if (className != null) {
/*
* Corresponding to the attribute type a class needs to be imported,
* since it can be a derived type or a usage of wrapper classes.
*/
importInfo.setClassInfo(className);
String classPkg = AttributesJavaDataType.getJavaImportPackage(this,
String classPkg = getJavaImportPackage(this,
false, conflictResolver);
if (classPkg == null) {
throw new TranslatorException("import package cannot be null when the class is used");
......@@ -65,7 +68,7 @@ public class YangJavaTypeTranslator<T>
* The attribute does not need a class to be imported, for example
* built in java types.
*/
String dataTypeName = AttributesJavaDataType.getJavaDataType(this);
String dataTypeName = getJavaDataType(this);
if (dataTypeName == null) {
throw new TranslatorException("not supported data type");
}
......@@ -76,7 +79,7 @@ public class YangJavaTypeTranslator<T>
@Override
public JavaQualifiedTypeInfoTranslator getJavaQualifiedInfo() {
return (JavaQualifiedTypeInfoTranslator) javaQualifiedAccess;
return javaQualifiedAccess;
}
@Override
......
......@@ -20,8 +20,8 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaUses;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
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.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
/**
......
......@@ -19,16 +19,19 @@ package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
......@@ -37,10 +40,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
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.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_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;
......@@ -61,21 +61,21 @@ import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
/**
* Represents generator for class definition of generated files.
*/
public final class ClassDefinitionGenerator {
final class ClassDefinitionGenerator {
/**
* Creates an instance of class definition generator.
......@@ -90,9 +90,9 @@ public final class ClassDefinitionGenerator {
* @param yangName class name
* @return class definition
*/
public static String generateClassDefinition(int genFileTypes, String yangName) {
static String generateClassDefinition(int genFileTypes, String yangName) {
/**
/*
* Based on the file type and the YANG name of the file, generate the
* class / interface definition start.
*/
......@@ -115,9 +115,9 @@ public final class ClassDefinitionGenerator {
* @param curNode current YANG node
* @return class definition
*/
public static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) {
static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) {
/**
/*
* Based on the file type and the YANG name of the file, generate the
* class / interface definition start.
*/
......@@ -126,12 +126,8 @@ public final class ClassDefinitionGenerator {
return getInterfaceDefinition(yangName, curNode);
case BUILDER_CLASS_MASK:
return getBuilderClassDefinition(yangName, curNode);
case OPERATION_BUILDER_CLASS_MASK:
return getOpParamBuilderClassDefinition(yangName, curNode);
case IMPL_CLASS_MASK:
case DEFAULT_CLASS_MASK:
return getImplClassDefinition(yangName, curNode);
case OPERATION_CLASS_MASK:
return getOpPramImplClassDefinition(yangName, curNode);
case BUILDER_INTERFACE_MASK:
return getBuilderInterfaceDefinition(yangName, curNode);
case GENERATE_SERVICE_AND_MANAGER:
......@@ -204,27 +200,12 @@ public final class ClassDefinitionGenerator {
return clsDef;
}
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
+ yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns operation param builder file class definition.
*
* @param yangName class name
* @param curNode YANG node
* @return definition returns operation param builder file class definition
*/
private static String getOpParamBuilderClassDefinition(String yangName, YangNode curNode) {
if (!(curNode instanceof YangCase)) {
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_BUILDER_CLASS_MASK);
if (clsDef != null) {
return clsDef + OPEN_CURLY_BRACKET + NEW_LINE;
}
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
return PUBLIC + SPACE + STATIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + BUILDER + SPACE + EXTEND +
SPACE + getCapitalCase(DEFAULT) + yangName + PERIOD + yangName + BUILDER + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE;
return PUBLIC + SPACE + STATIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE +
yangName + PERIOD + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
......@@ -235,39 +216,17 @@ public final class ClassDefinitionGenerator {
*/
private static String getImplClassDefinition(String yangName, YangNode curNode) {
if (!(curNode instanceof YangCase)) {
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, IMPL_CLASS_MASK);
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, DEFAULT_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
}
return PUBLIC + SPACE + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + IMPLEMENTS + SPACE
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
return PUBLIC + SPACE + CLASS + SPACE + yangName + OP_PARAM + SPACE + IMPLEMENTS + SPACE
+ yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns operation param file class definition.
*
* @param yangName class name
* @param curNode YANG node
* @return definition returns operation param file class definition
*/
private static String getOpPramImplClassDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (!(curNode instanceof YangCase)) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_CLASS_MASK);
}
if (clsDef.equals("")) {
clsDef = PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE + EXTEND + SPACE
+ getCapitalCase(DEFAULT) + yangName + SPACE;
}
if (curNode instanceof YangAugment) {
clsDef = clsDef + IMPLEMENTS + SPACE + YANG_AUGMENTED_OP_PARAM_INFO + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
} else {
clsDef = clsDef + OPEN_CURLY_BRACKET + NEW_LINE;
}
return clsDef;
return PUBLIC + SPACE + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + IMPLEMENTS + SPACE
+ yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
......@@ -293,7 +252,7 @@ public final class ClassDefinitionGenerator {
YangIdentity identity = (YangIdentity) curNode;
if (identity.getBaseNode() != null) {
YangIdentity baseIdentity = identity.getBaseNode().getReferredIdentity();
if (!(baseIdentity instanceof YangIdentity)) {
if (baseIdentity == null) {
throw new TranslatorException("Expected java identity instance node");
}
......@@ -367,10 +326,8 @@ public final class ClassDefinitionGenerator {
* @return definition
*/
private static String getEventDefinition(String javaName, String eventName) {
String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
return PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
+ javaName + ".Type, " + eventName + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return classDef;
}
/**
......@@ -380,15 +337,15 @@ public final class ClassDefinitionGenerator {
* @return definition
*/
private static String getEventListenerDefinition(String javaName) {
String intfDef = PUBLIC + SPACE + INTERFACE + SPACE + javaName + SPACE + "extends EventListener<"
String interfaceDef = PUBLIC + SPACE + INTERFACE + SPACE + javaName + SPACE + "extends EventListener<"
+ javaName;
if (intfDef.length() < 8) {
if (interfaceDef.length() < 8) {
throw new RuntimeException("Event listener interface name is error");
}
intfDef = intfDef.substring(0, intfDef.length() - 8);
intfDef = intfDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
interfaceDef = interfaceDef.substring(0, interfaceDef.length() - 8);
interfaceDef = interfaceDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return intfDef;
return interfaceDef;
}
/**
......@@ -415,21 +372,23 @@ public final class ClassDefinitionGenerator {
builderDef = getDefinitionString(builderDef, holder);
return builderDef + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
case BUILDER_CLASS_MASK:
def = def + CLASS + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
def = def + STATIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
def = getDefinitionString(def, holder);
if (curNode instanceof YangSubModule || curNode instanceof YangModule) {
return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
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;
case DEFAULT_CLASS_MASK:
if (curNode instanceof YangSubModule || curNode instanceof YangModule) {
def = def + CLASS + SPACE + yangName + OP_PARAM + SPACE + EXTEND + SPACE;
} else {
def = def + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + EXTEND + SPACE;
}
def = getDefinitionString(def, holder);
return def + SPACE + IMPLEMENTS + SPACE
+ yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
case OPERATION_CLASS_MASK:
def = def + CLASS + SPACE + yangName + OPERATION + SPACE + EXTEND + SPACE;
def = getDefinitionString(def, holder);
return def + SPACE;
default:
return null;
}
......
......@@ -19,40 +19,36 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.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.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......@@ -60,10 +56,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.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.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE_ATTR;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE_ATTR;
......@@ -93,7 +86,7 @@ public final class JavaCodeSnippetGen {
*/
public static String getFileHeaderComment() {
/**
/*
* TODO return the file header.
*/
return null;
......@@ -119,39 +112,29 @@ public final class JavaCodeSnippetGen {
* @param attributeAccessType attribute access type
* @return the textual java code for attribute definition in class
*/
public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
public static String getJavaAttributeDefinition(String javaAttributeTypePkg, String javaAttributeType,
String javaAttributeName, boolean isList,
String attributeAccessType) {
String attributeDefination = attributeAccessType + SPACE;
String attributeDefinition = attributeAccessType + SPACE;
if (!isList) {
if (javaAttributeTypePkg != null) {
attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD;
attributeDefinition = attributeDefinition + javaAttributeTypePkg + PERIOD;
}
attributeDefination = attributeDefination + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN
attributeDefinition = attributeDefinition + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN
+ NEW_LINE;
} else {
attributeDefination = attributeDefination + LIST + DIAMOND_OPEN_BRACKET;
attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
if (javaAttributeTypePkg != null) {
attributeDefination = attributeDefination + javaAttributeTypePkg + PERIOD;
attributeDefinition = attributeDefinition + javaAttributeTypePkg + PERIOD;
}
attributeDefination = attributeDefination + javaAttributeType + DIAMOND_CLOSE_BRACKET + SPACE
+ javaAttributeName + SEMI_COLAN + NEW_LINE;
attributeDefinition = attributeDefinition + javaAttributeType + DIAMOND_CLOSE_BRACKET + SPACE
+ javaAttributeName + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
}
return attributeDefination;
}
/**
* Returns list attribute string.
*
* @param type attribute type
* @return list attribute string
*/
public static String getListAttribute(String type) {
return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET;
return attributeDefinition;
}
/**
......@@ -172,37 +155,12 @@ public final class JavaCodeSnippetGen {
* @return string for enum's attribute
*/
public static String generateEnumAttributeString(String name, int value, YangPluginConfig pluginConfig) {
return getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig)
+ EIGHT_SPACE_INDENTATION + getEnumJavaAttribute(name).toUpperCase() + OPEN_PARENTHESIS
+ 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
......@@ -233,7 +191,7 @@ public final class JavaCodeSnippetGen {
*/
public static void addListenersImport(YangNode curNode, List<String> imports, boolean operation,
String classInfo) {
String thisImport = "";
String thisImport;
TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
if (classInfo.equals(LISTENER_SERVICE)) {
......@@ -276,23 +234,13 @@ public final class JavaCodeSnippetGen {
}
/**
* Returns component string.
*
* @return component string
*/
static String addComponentString() {
return NEW_LINE + COMPONENT_ANNOTATION + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
}
/**
* Returns attribute for augmentation.
*
* @return attribute for augmentation
*/
static String addAugmentationAttribute() {
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING
+ DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO
+ DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING
+ DIAMOND_CLOSE_BRACKET + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL + SPACE +
NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN;
......@@ -332,4 +280,76 @@ public final class JavaCodeSnippetGen {
FOUR_SPACE_INDENTATION + modifier + SPACE + ULONG_MAX_RANGE_ATTR;
}
}
/**
* Returns operation type enum.
*
* @return operation type enum
*/
static String getOperationTypeEnum() {
return "\n" +
" /**\n" +
" * Specify the node specific operation in protocols like NETCONF.\n" +
" * Applicable in protocol edit operation, not applicable in query operation\n" +
" */\n" +
" public enum OperationType {\n" +
" MERGE,\n" +
" REPLACE,\n" +
" CREATE,\n" +
" DELETE,\n" +
" REMOVE\n" +
" }\n";
}
/**
* Returns operation type enum, leaf value set attribute and select leaf attribute.
*
* @return operation type enum, leaf value set attribute and select leaf attribute.
*/
static String getOperationAttributes() {
return " /**\n" +
" * Identify the leafs whose value are explicitly set\n" +
" * Applicable in protocol edit and query operation\n" +
" */\n" +
" private BitSet _valueLeafFlags = new BitSet();\n" +
"\n" +
" /**\n" +
" * Identify the leafs to be selected, in a query operation\n" +
" */\n" +
" private BitSet _selectLeafFlags = new BitSet();\n";
}
/**
* Returns operation type enum, leaf value set attribute and select leaf attribute.
*
* @return operation type enum, leaf value set attribute and select leaf attribute.
*/
static String getOperationTypeAttr() {
return "\n /**\n" +
" * Specify the node specific operation in protocols like NETCONF.\n" +
" * Applicable in protocol edit operation, will be ignored in query operation\n" +
" */\n" +
" private OperationType _operationType;\n" +
"\n";
}
/**
* Returns operation type enum, leaf value set attribute and select leaf attribute for constructor.
*
* @return operation type enum, leaf value set attribute and select leaf attribute for constructor
*/
static String getOperationAttributeForConstructor() {
return " this._valueLeafFlags = builderObject.get_valueLeafFlags();\n" +
" this._selectLeafFlags = builderObject.get_selectLeafFlags();\n";
}
/**
* Returns operation type enum, leaf value set attribute and select leaf attribute for constructor.
*
* @return operation type enum, leaf value set attribute and select leaf attribute for constructor
*/
static String getOperationTypeForConstructor() {
return " this._operationType = builderObject.get_operationType();\n";
}
}
......
......@@ -52,7 +52,7 @@ public class JavaExtendsListHolder {
*
* @return extends list
*/
public Map<JavaQualifiedTypeInfoTranslator, Boolean> getExtendedClassStore() {
Map<JavaQualifiedTypeInfoTranslator, Boolean> getExtendedClassStore() {
return extendedClassStore;
}
......
......@@ -21,21 +21,20 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
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.YangSubModule;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
......@@ -43,11 +42,12 @@ import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFi
import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.YangJavaModelUtils;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
......@@ -55,10 +55,9 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
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.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
......@@ -73,8 +72,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
......@@ -82,19 +81,19 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributeForConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributes;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeAttr;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeEnum;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeForConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.builderMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoMapImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForManager;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBaseClassMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod;
......@@ -103,78 +102,62 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForOperationType;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGettersForValueAndSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumMethods;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIsFilterContentMatch;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOpParamConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypeSetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypegetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationAttributesGetters;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForLeafList;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForOperationType;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafListgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringLeafgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isFilterContentMatchInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isLeafValueSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.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.CREATE;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DELETE;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
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.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_IMPORT_BASE64_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.MERGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.REMOVE;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
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.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SUPER;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
......@@ -218,21 +201,63 @@ public final class JavaFileGenerator {
String className = getCapitalCase(javaFileInfo.getJavaName());
initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className);
boolean isLeavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
|| leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
} else {
isLeavesPresent = false;
}
initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
// Add getter methods to interface file.
try {
//Leaf identifier enum.
if (isLeavesPresent) {
insertDataIntoJavaFile(file, NEW_LINE + getInterfaceLeafIdEnumSignature(className) + NEW_LINE +
trimAtLast(trimAtLast(
getDataFromTempFileHandle(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK,
((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path), COMMA), NEW_LINE) + SEMI_COLAN
+ NEW_LINE + NEW_LINE + getInterfaceLeafIdEnumMethods());
}
//Getter methods.
insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path));
//Add to list method.
insertDataIntoJavaFile(file, getDataFromTempFileHandle(ADD_TO_LIST_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while interface file generation");
}
}
if (curNode instanceof YangAugmentableNode && !(curNode instanceof YangChoice)) {
methods.add(getAddAugmentInfoMethodInterface());
methods.add(getYangAugmentInfoInterface());
methods.add(getYangAugmentInfoMapInterface(javaFileInfo.getPluginConfig()));
}
if (!(curNode instanceof YangChoice)) {
methods.add(NEW_LINE + isFilterContentMatchInterface(className));
}
if (!(curNode instanceof YangChoice) && isLeavesPresent) {
methods.add(NEW_LINE + isLeafValueSetInterface());
methods.add(NEW_LINE + isSelectLeafSetInterface());
}
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
return validateLineLength(file);
}
/**
......@@ -250,6 +275,16 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
boolean isLeavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
|| leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
} else {
isLeavesPresent = false;
}
String className = getCapitalCase(javaFileInfo.getJavaName());
String path;
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
......@@ -279,6 +314,9 @@ public final class JavaFileGenerator {
}
}
if (isLeavesPresent) {
methods.add(NEW_LINE + setSelectLeafSetInterface(className));
}
//Add build method to builder interface file.
methods.add(
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
......@@ -303,16 +341,28 @@ public final class JavaFileGenerator {
* @return builder class file
* @throws IOException when fails to write in file
*/
public static File generateBuilderClassFile(File file, YangNode curNode,
boolean isAttrPresent) throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
boolean isLeavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
|| leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
} else {
isLeavesPresent = false;
}
String className = getCapitalCase(javaFileInfo.getJavaName());
boolean isRootNode = false;
String path;
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
isRootNode = true;
path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath();
} else {
path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
......@@ -334,6 +384,10 @@ public final class JavaFileGenerator {
+ " while builder class file generation");
}
insertDataIntoJavaFile(file, getOperationTypeAttr());
if (isLeavesPresent) {
insertDataIntoJavaFile(file, getOperationAttributes());
}
try {
//Getter methods.
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
......@@ -345,6 +399,14 @@ public final class JavaFileGenerator {
.getBeanTempFiles(), path));
insertDataIntoJavaFile(file, NEW_LINE);
methods.add(getGetterForOperationType());
methods.add(getSetterForOperationType(className));
//Add operation attribute methods.
if (isLeavesPresent) {
methods.add(getOperationAttributesGetters() + NEW_LINE);
methods.add(getSetterForSelectLeaf(className, isRootNode));
}
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while builder class file generation");
......@@ -355,191 +417,22 @@ public final class JavaFileGenerator {
// Add default constructor and build method impl.
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.addBuildMethodImpl());
.addBuildMethodImpl(curNode));
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.addDefaultConstructor(PUBLIC, BUILDER, pluginConfig));
.addDefaultConstructor(PUBLIC, BUILDER, pluginConfig, curNode));
//Add methods in builder class.
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
return validateLineLength(file);
}
/**
* Returns generated op param builder class file for current node.
*
* @param file file handle
* @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 generateOpParamBuilderClassFile(File file, YangNode curNode,
boolean isAttrPresent) throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
initiateJavaFileGeneration(file, OPERATION_BUILDER_CLASS_MASK, null, curNode, className);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
//Add attribute strings.
try {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
try {
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
}
}
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
try {
// Setter methods.
methods.add(getSetterForLeaf(className, curNode, pluginConfig));
methods.add(getSetterForLeafList(className, curNode, pluginConfig));
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
methods.add(getToStringLeafgetter());
methods.add(getToStringSelectLeafgetter());
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
methods.add(getToStringLeafListgetter());
methods.add(getToStringSelectLeafListgetter());
}
}
methods.add(getOperationTypegetter());
methods.add(getOperationTypeSetter());
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");
}
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
// Add methods in builder class.
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
* @return builder class file
* @throws IOException when fails to write in file
*/
public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode)
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);
List<String> methods = new ArrayList<>();
insertDataIntoJavaFile(file, LOGGER_STATEMENT);
methods.add(addActivateMethod());
methods.add(addDeActivateMethod());
TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
JavaAttributeInfo rootAttribute = getCurNodeAsAttributeInTarget(curNode, curNode, false,
tempJavaServiceFragmentFiles);
try {
//Getter methods.
methods.add(getOverRideString() +
getGetterForClass(rootAttribute, GENERATE_SERVICE_AND_MANAGER) + NEW_LINE);
// Setter methods.
methods.add(getOverRideString() +
getSetterForClass(rootAttribute, className, GENERATE_SERVICE_AND_MANAGER)
+ NEW_LINE);
methods.add(getAugmentsDataMethodForManager(curNode) + NEW_LINE);
if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles() != null) {
JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
//Rpc methods
methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK,
javaGenInfo.getTempJavaCodeFragmentFiles().getServiceTempFiles(), path));
}
insertDataIntoJavaFile(file, NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while manager class file generation");
}
// Add methods in builder class.
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
return validateLineLength(file);
}
/**
* Returns generated impl class file for current node.
* Returns generated default class file for current node.
*
* @param file file
* @param curNode current YANG node
......@@ -548,25 +441,41 @@ public final class JavaFileGenerator {
* @return impl class file
* @throws IOException when fails to write in file
*/
public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent, List<String> imports)
public static File generateDefaultClassFile(File file, YangNode curNode, boolean isAttrPresent,
List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
boolean isLeavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
|| leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
} else {
isLeavesPresent = false;
}
boolean isRootNode = false;
String className = getCapitalCase(javaFileInfo.getJavaName());
String opParamClassName = className;
String path;
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
opParamClassName = className + OP_PARAM;
isRootNode = true;
path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath();
} else {
path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
}
initiateJavaFileGeneration(file, IMPL_CLASS_MASK, imports, curNode, className);
initiateJavaFileGeneration(file, DEFAULT_CLASS_MASK, imports, curNode, className);
List<String> methods = new ArrayList<>();
if (curNode instanceof YangAugmentableNode) {
insertDataIntoJavaFile(file, addAugmentationAttribute());
insertDataIntoJavaFile(file, JavaCodeSnippetGen.addAugmentationAttribute());
}
if (isAttrPresent) {
......@@ -581,12 +490,23 @@ public final class JavaFileGenerator {
+ " while impl class file generation");
}
//Add operation attributes
insertDataIntoJavaFile(file, getOperationTypeEnum());
insertDataIntoJavaFile(file, getOperationTypeAttr());
if (isLeavesPresent) {
insertDataIntoJavaFile(file, getOperationAttributes());
}
try {
//Getter methods.
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path));
//Add to list impl method.
methods.add(getDataFromTempFileHandle(ADD_TO_LIST_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path));
// Hash code method.
methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
......@@ -595,11 +515,17 @@ public final class JavaFileGenerator {
.getBeanTempFiles(), path).replace(NEW_LINE, EMPTY_STRING)));
//Equals method.
if (isRootNode) {
methods.add(getEqualsMethodClose(getEqualsMethodOpen(opParamClassName)
+ getDataFromTempFileHandle(EQUALS_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path)));
} else {
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()
......@@ -613,186 +539,45 @@ public final class JavaFileGenerator {
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
try {
if (curNode instanceof YangAugmentableNode) {
methods.add(getAddAugmentInfoMethodImpl());
methods.add(getYangAugmentInfoImpl());
methods.add(getYangAugmentInfoMapImpl());
}
try {
//Constructor.
String constructor = getConstructorStart(className, pluginConfig);
String constructor = getConstructorStart(className, pluginConfig, isRootNode);
constructor = constructor + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path);
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
if (curNode instanceof YangAugmentableNode) {
methods.add(getAddAugmentInfoMethodImpl());
methods.add(getAugmentInfoImpl());
methods.add(getAugmentInfoMapImpl(javaFileInfo.getPluginConfig()));
}
// Add methods in impl class.
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
return validateLineLength(file);
}
/**
* Returns generated op param class file for current node.
*
* @param file file handle
* @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @param imports import list
* @return returns generated op param class file for current node
* @throws IOException when fails to write in file
*/
public static File generateOpParamImplClassFile(File file, YangNode curNode,
boolean isAttrPresent, List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
initiateJavaFileGeneration(file, OPERATION_CLASS_MASK, imports, curNode, className);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
// Add attribute strings.
try {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC +
SPACE + ENUM + SPACE + OPERATION_ENUM + SPACE + OPEN_CURLY_BRACKET +
NEW_LINE + EIGHT_SPACE_INDENTATION + MERGE +
NEW_LINE + EIGHT_SPACE_INDENTATION + REPLACE +
NEW_LINE + EIGHT_SPACE_INDENTATION + CREATE +
NEW_LINE + EIGHT_SPACE_INDENTATION + DELETE +
NEW_LINE + EIGHT_SPACE_INDENTATION + REMOVE +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
// Add attribute strings.
try {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
OPERATION_ENUM + SPACE + OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
try {
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
insertDataIntoJavaFile(file, FOUR_SPACE_INDENTATION + PRIVATE + SPACE +
BITSET + SPACE + SELECT_LEAF_LIST + SPACE + EQUAL + SPACE +
NEW + SPACE + BITSET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE);
constructor = constructor + getOperationTypeForConstructor();
}
if (isLeavesPresent) {
constructor = constructor + getOperationAttributeForConstructor();
}
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
}
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null && !leaves.isEmpty()) {
methods.add(getToStringLeafgetter());
methods.add(getToStringSelectLeafgetter());
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
methods.add(getToStringLeafListgetter());
methods.add(getToStringSelectLeafListgetter());
}
}
methods.add(getOperationTypegetter());
methods.add(getIsFilterContentMatch(className, curNode, pluginConfig));
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
String constructor = getOpParamConstructorStart(className, pluginConfig);
constructor = constructor + EIGHT_SPACE_INDENTATION + SUPER + OPEN_PARENTHESIS
+ BUILDER.toLowerCase() + OBJECT
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
String filterLeaf = "";
String filterLeafList = "";
if (leaves != null && !leaves.isEmpty()) {
filterLeaf = EIGHT_SPACE_INDENTATION + FILTER_LEAF + SPACE + EQUAL + SPACE
+ BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
filterLeafList = EIGHT_SPACE_INDENTATION + FILTER_LEAF_LIST + SPACE + EQUAL + SPACE
+ BUILDER.toLowerCase() + OBJECT + PERIOD + GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
constructor = constructor + filterLeaf + filterLeafList;
}
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.addDefaultConstructor(PUBLIC, DEFAULT, pluginConfig, curNode));
if (curNode instanceof YangAugment) {
String clsName = getCapitalCase(DEFAULT) +
getCapitalCase(YangJavaModelUtils.getAugmentClassName((YangAugment) curNode, pluginConfig));
methods.add(getBaseClassMethodImpl(clsName));
methods.add(builderMethod(className));
methods.add(getIsFilterContentMatch(curNode, pluginConfig));
if (isLeavesPresent) {
methods.add(getOperationAttributesGetters());
methods.add(getGettersForValueAndSelectLeaf());
}
// Add methods in impl class.
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
return validateLineLength(file);
}
......@@ -818,7 +603,7 @@ public final class JavaFileGenerator {
List<YangType<?>> types = typeDef.getTypeList();
YangType type = types.get(0);
YangDataTypes yangDataTypes = type.getDataType();
if (type.getDataType().equals(YangDataTypes.BINARY)) {
if (type.getDataType().equals(BINARY)) {
imports.add(IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_IMPORT_BASE64_CLASS);
}
......@@ -841,11 +626,10 @@ public final class JavaFileGenerator {
//Default constructor.
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
.addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig, curNode));
try {
//Type constructor.
methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
......@@ -879,27 +663,27 @@ public final class JavaFileGenerator {
//To string method.
if (type.getDataType().equals(YangDataTypes.BINARY)) {
if (type.getDataType().equals(BINARY)) {
JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase("binary"));
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "binary", null, false,
false);
String attributeName = attr.getAttributeName();
String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
String bitsToStringMethod = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
+ SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + BASE64 + PERIOD + GET_ENCODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS + attributeName + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
methods.add(bitsToStringMethod);
} else if (type.getDataType().equals(YangDataTypes.BITS)) {
} else if (type.getDataType().equals(BITS)) {
JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase("bits"));
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "bits", null, false, false);
String attributeName = attr.getAttributeName();
String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
String bitsToStringMethod = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
+ SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + attributeName + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS
......@@ -914,6 +698,7 @@ public final class JavaFileGenerator {
JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
//From string method.
if ((type.getDataType().equals(YangDataTypes.DERIVED))
&& (((YangDerivedInfo) type.getDataTypeExtendedInfo()).getEffectiveBuiltInType()
.equals(YangDataTypes.IDENTITYREF))) {
......@@ -925,12 +710,8 @@ public final class JavaFileGenerator {
}
if (!yangDataTypes.equals(YangDataTypes.IDENTITYREF)) {
//From string method.
methods.add(getFromStringMethodSignature(className, pluginConfig)
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGenInfo
.getTempJavaCodeFragmentFiles()
+ getDataFromTempFileHandle(FROM_STRING_IMPL_MASK, javaGenInfo.getTempJavaCodeFragmentFiles()
.getTypeTempFiles(), path)
+ getFromStringMethodClose());
}
......@@ -1022,7 +803,7 @@ public final class JavaFileGenerator {
//Default constructor.
methods.add(((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig));
.addDefaultConstructor(PRIVATE, EMPTY_STRING, pluginConfig, curNode));
try {
......@@ -1074,10 +855,10 @@ public final class JavaFileGenerator {
+ getFromStringMethodClose());
if (isIntConflict) {
methods.add(MethodsGenerator.getRangeValidatorMethodForUnion(INT));
methods.add(getRangeValidatorMethodForUnion(INT));
}
if (isLongConflict) {
methods.add(MethodsGenerator.getRangeValidatorMethodForUnion(BIG_INTEGER));
methods.add(getRangeValidatorMethodForUnion(BIG_INTEGER));
}
} catch (IOException e) {
......
......@@ -20,11 +20,14 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
......@@ -46,6 +49,7 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
......@@ -54,10 +58,9 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
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.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
......@@ -72,6 +75,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
......@@ -79,14 +83,14 @@ 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.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getAugmentedNodesPackage;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getNodesPackage;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
......@@ -98,9 +102,7 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVE
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OPERATION_CLASS;
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;
......@@ -125,12 +127,11 @@ public final class JavaFileGeneratorUtils {
* @param filePath file package path
* @param fileName file name
* @param extension file extension
* @param baseCodePath cached file handle
* @param handler cached file handle
* @return file object
*/
public static File getFileObject(String filePath, String fileName, String extension, String baseCodePath) {
return new File(baseCodePath + filePath + SLASH + fileName + extension);
public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handler) {
return new File(handler.getBaseCodeGenPath() + filePath + SLASH + fileName + extension);
}
/**
......@@ -188,6 +189,18 @@ public final class JavaFileGeneratorUtils {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & ADD_TO_LIST_INTERFACE_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAddToListInterfaceTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & ADD_TO_LIST_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAddToListImplTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getLeafIdAttributeTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
if (beanFragmentFiles == null) {
throw new TranslatorException("Required constructor info is missing.");
......@@ -370,20 +383,13 @@ public final class JavaFileGeneratorUtils {
appendHeaderContents(file, pkgString, importsList);
write(file, genType, INTERFACE, curNode, className);
break;
case IMPL_CLASS_MASK:
case DEFAULT_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
write(file, genType, IMPL_CLASS, curNode, className);
break;
case OPERATION_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
write(file, genType, OPERATION_CLASS, curNode, className);
break;
case BUILDER_CLASS_MASK:
write(file, genType, BUILDER_CLASS, curNode, className);
break;
case OPERATION_BUILDER_CLASS_MASK:
write(file, genType, BUILDER_CLASS, curNode, className);
break;
case BUILDER_INTERFACE_MASK:
write(file, genType, BUILDER_INTERFACE, curNode, className);
break;
......@@ -511,16 +517,7 @@ public final class JavaFileGeneratorUtils {
throws IOException {
YangPluginConfig pluginConfig = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPluginConfig();
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, JavaCodeSnippetGen.addComponentString());
} else {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
}
} else {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false, pluginConfig));
}
insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
}
......@@ -616,6 +613,13 @@ public final class JavaFileGeneratorUtils {
parentInfo.getPluginConfig());
tempJavaCodeFragmentFiles.getServiceTempFiles().getJavaImportData().addImportInfo(javaQualifiedTypeInfo,
parentInfo.getJavaName(), parentInfo.getPackage());
if (augmentedNode instanceof YangModule || augmentedNode instanceof YangSubModule) {
javaQualifiedTypeInfo = getQualifiedTypeInfoOfAugmentedNode(augmentedNode,
getCapitalCase(curNodeName) + OP_PARAM,
parentInfo.getPluginConfig());
tempJavaCodeFragmentFiles.getServiceTempFiles().getJavaImportData().addImportInfo(javaQualifiedTypeInfo,
parentInfo.getJavaName(), parentInfo.getPackage());
}
}
}
......@@ -634,7 +638,7 @@ public final class JavaFileGeneratorUtils {
JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(augmentedNode,
getCapitalCase(curNodeName));
if (javaQualifiedTypeInfo.getPkgInfo() == null) {
javaQualifiedTypeInfo.setPkgInfo(getAugmentedNodesPackage(augmentedNode,
javaQualifiedTypeInfo.setPkgInfo(getNodesPackage(augmentedNode,
pluginConfig));
}
return javaQualifiedTypeInfo;
......@@ -735,4 +739,5 @@ public final class JavaFileGeneratorUtils {
}
return attributeType;
}
}
......
......@@ -20,14 +20,16 @@ import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.utils.io.impl.YangIoUtils;
import org.onosproject.yangutils.datamodel.javadatamodel.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
......@@ -48,6 +50,7 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirector
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
/**
* Represents an utility Class for translating the name from YANG to java convention.
......@@ -109,14 +112,12 @@ public final class JavaIdentifierSyntax {
*/
private static String getPkgFromNameSpace(String nameSpace, YangToJavaNamingConflictUtil conflictResolver) {
ArrayList<String> pkgArr = new ArrayList<String>();
ArrayList<String> pkgArr = new ArrayList<>();
nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
String properNameSpace = nameSpace.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLAN);
String[] nameSpaceArr = properNameSpace.split(COLAN);
for (String nameSpaceString : nameSpaceArr) {
pkgArr.add(nameSpaceString);
}
Collections.addAll(pkgArr, nameSpaceArr);
return getPkgFrmArr(pkgArr, conflictResolver);
}
......@@ -159,7 +160,7 @@ public final class JavaIdentifierSyntax {
for (String member : pkgArr) {
boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member.toLowerCase());
if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
String prefix = YangIoUtils.getPrefixForIdentifier(conflictResolver);
String prefix = getPrefixForIdentifier(conflictResolver);
member = prefix + member;
}
pkg = pkg + member;
......@@ -183,10 +184,8 @@ public final class JavaIdentifierSyntax {
String[] strArray = name.split(COLAN);
String output = EMPTY_STRING;
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
List<String> stringArrangement = new ArrayList<>();
stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
for (int i = 0; i < strArray.length; i++) {
......@@ -236,7 +235,7 @@ public final class JavaIdentifierSyntax {
* @param pkg Package to check if it is created
* @return existence status of package
*/
public static boolean doesPackageExist(String pkg) {
static boolean doesPackageExist(String pkg) {
File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
return pkgDir.exists() && pkgWithFile.isFile();
......
......@@ -21,12 +21,16 @@ import java.util.Map;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangIsFilterContentNodes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
......@@ -34,7 +38,6 @@ import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
......@@ -58,21 +61,17 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_TYPE_CONFLICT;
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;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BASE_CLASS;
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.BITSET;
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.BREAK;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
......@@ -87,8 +86,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.DECODE;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
......@@ -97,37 +94,40 @@ import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FLAG;
import static org.onosproject.yangutils.utils.UtilConstants.FOR;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.GET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.GET_LEAF_INDEX;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.GET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.IF;
import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ARGUMENT_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ARGUMENT_EXCEPTION_MSG;
import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ACCESS_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.INVOKE;
import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
......@@ -139,6 +139,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
import static org.onosproject.yangutils.utils.UtilConstants.NO_SUCH_METHOD_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
import static org.onosproject.yangutils.utils.UtilConstants.OBJ;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
......@@ -147,9 +148,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.OF;
import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
......@@ -164,15 +163,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.PUT;
import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.RECEIVED_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.SET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SET_SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
......@@ -180,26 +176,27 @@ import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENT
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.STARTED_LOG_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
import static org.onosproject.yangutils.utils.UtilConstants.STOPPED_LOG_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.THROW;
import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.TRY;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO;
......@@ -215,7 +212,9 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_
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.generateForAddAugmentation;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForBuilderMethod;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetMethodWithAttribute;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForValidatorMethod;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
......@@ -260,6 +259,10 @@ public final class MethodsGenerator {
String returnType = getReturnType(attr);
String attributeName = attr.getAttributeName();
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
return generateForGetMethodWithAttribute(returnType)
+ getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
}
return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig)
+ getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
......@@ -297,7 +300,7 @@ public final class MethodsGenerator {
* @param pluginConfig plugin configurations
* @return constructor string
*/
public static String getConstructorString(String name, YangPluginConfig pluginConfig) {
private static String getConstructorString(String name, YangPluginConfig pluginConfig) {
return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig);
}
......@@ -322,7 +325,7 @@ public final class MethodsGenerator {
* @param name attribute name
* @return check not null string
*/
public static String getCheckNotNull(String name) {
static String getCheckNotNull(String name) {
return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING + OPEN_PARENTHESIS + name + COMMA + SPACE + name
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
......@@ -331,10 +334,14 @@ public final class MethodsGenerator {
* Returns build method string.
*
* @param name class name
* @param isRootNode if root node
* @return build string
*/
public static String getBuildString(String name) {
return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name);
public static String getBuildString(String name, boolean isRootNode) {
if (isRootNode) {
return NEW_LINE + getBuild(name, true);
}
return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name, false);
}
/**
......@@ -346,13 +353,13 @@ public final class MethodsGenerator {
*/
public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
String attrQuaifiedType = getReturnType(attr);
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
if (!attr.isListAttr()) {
return getGetter(attrQuaifiedType, attributeName, generatedJavaFiles);
return getGetter(attrQualifiedType, attributeName, generatedJavaFiles);
}
String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
String listAttr = getListString() + attrQualifiedType + DIAMOND_CLOSE_BRACKET;
return getGetter(listAttr, attributeName, generatedJavaFiles);
}
......@@ -364,7 +371,7 @@ public final class MethodsGenerator {
* @param generatedJavaFiles generated java files
* @return getter for attribute
*/
public static String getGetter(String type, String name, int generatedJavaFiles) {
static String getGetter(String type, String name, int generatedJavaFiles) {
String ret = parseTypeForReturnValue(type);
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
......@@ -406,13 +413,17 @@ public final class MethodsGenerator {
*/
public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
String attrQuaifiedType = getReturnType(attr);
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
boolean isTypeNull = false;
if (attr.getAttributeType() == null) {
isTypeNull = true;
}
if (!attr.isListAttr()) {
return getSetter(className, attributeName, attrQuaifiedType, generatedJavaFiles);
return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false);
}
String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
return getSetter(className, attributeName, listAttr, generatedJavaFiles);
String listAttr = getListString() + attrQualifiedType + DIAMOND_CLOSE_BRACKET;
return getSetter(className, attributeName, listAttr, generatedJavaFiles, isTypeNull, true);
}
/**
......@@ -421,9 +432,12 @@ public final class MethodsGenerator {
* @param className class name
* @param name attribute name
* @param type return type
* @param isTypeNull if attribute type is null
* @param isList true if leaf-list
* @return setter for attribute
*/
private static String getSetter(String className, String name, String type, int generatedJavaFiles) {
private static String getSetter(String className, String name, String type, int generatedJavaFiles,
boolean isTypeNull, boolean isList) {
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX
+ getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
......@@ -435,12 +449,25 @@ public final class MethodsGenerator {
+ THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE
+ OPEN_CURLY_BRACKET;
if (!isTypeNull && !isList) {
method = method + getValueLeafSetString(name);
} else {
method = method + EMPTY_STRING;
}
return method + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS +
PERIOD + name + SPACE
+ EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
+ THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
}
//Returns value leaf flag setter.
private static String getValueLeafSetString(String name) {
return "\n get_valueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());";
}
/**
......@@ -449,11 +476,11 @@ public final class MethodsGenerator {
* @param attr attribute info
* @return setter method for class
*/
public static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
String attrQuaifiedType = getReturnType(attr);
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
return getTypeDefSetter(attrQuaifiedType, attributeName);
return getTypeDefSetter(attrQualifiedType, attributeName);
}
/**
......@@ -466,8 +493,8 @@ public final class MethodsGenerator {
private static String getTypeDefSetter(String type, String name) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(name)
+ OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
......@@ -488,7 +515,7 @@ public final class MethodsGenerator {
* @param generatedJavaFiles generated java files
* @return getter method for interface
*/
public static String getGetterForInterface(String yangName, String returnType, boolean isList,
static String getGetterForInterface(String yangName, String returnType, boolean isList,
int generatedJavaFiles) {
if (!isList) {
......@@ -508,8 +535,7 @@ public final class MethodsGenerator {
private static String getGetterInterfaceString(String returnType, String yangName,
int generatedJavaFiles) {
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName)
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
return getGetMethodWithArgument(returnType, yangName);
} else {
return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
......@@ -526,7 +552,7 @@ public final class MethodsGenerator {
* @param generatedJavaFiles generated java files
* @return setter method for interface
*/
public static String getSetterForInterface(String attrName, String attrType, String className,
static String getSetterForInterface(String attrName, String attrType, String className,
boolean isList, int generatedJavaFiles) {
if (!isList) {
......@@ -547,7 +573,6 @@ public final class MethodsGenerator {
private static String getSetterInterfaceString(String className, String attrName, String attrType,
int generatedJavaFiles) {
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName)
+ OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
} else {
......@@ -587,7 +612,7 @@ public final class MethodsGenerator {
* @param yangName name of the interface
* @return build method for interface
*/
public static String getBuildForInterface(String yangName) {
static String getBuildForInterface(String yangName) {
return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ NEW_LINE;
}
......@@ -597,29 +622,19 @@ public final class MethodsGenerator {
*
* @param yangName class name
* @param pluginConfig plugin configurations
* @param isRootNode if root node
* @return constructor string
*/
public static String getConstructorStart(String yangName, YangPluginConfig pluginConfig) {
static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) {
String javadoc = getConstructorString(yangName, pluginConfig);
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 constructor string for op param class.
*
* @param yangName class name
* @param pluginConfig plugin configurations
* @return constructor string
*/
public static String getOpParamConstructorStart(String yangName, YangPluginConfig pluginConfig) {
String javadoc = getConstructorString(yangName, pluginConfig);
String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + OPERATION +
OPEN_PARENTHESIS + yangName + OPERATION + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
String returnType = getCapitalCase(DEFAULT) + yangName;
if (isRootNode) {
returnType = yangName + OP_PARAM;
}
String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + returnType +
OPEN_PARENTHESIS + yangName + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return javadoc + constructor;
}
......@@ -707,12 +722,18 @@ public final class MethodsGenerator {
* Returns the build method strings for class file.
*
* @param yangName class name
* @param isRootNode if root node
* @return build method string for class
*/
public static String getBuild(String yangName) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
static String getBuild(String yangName, boolean isRootNode) {
String type = getCapitalCase(DEFAULT) + yangName;
if (isRootNode) {
type = yangName + OP_PARAM;
}
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS +
CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE +
getCapitalCase(DEFAULT) + yangName + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN
type + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
......@@ -733,170 +754,13 @@ public final class MethodsGenerator {
*
* @return string method's open string
*/
public static String getToStringMethodOpen() {
static String getToStringMethodOpen() {
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO
+ STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + GOOGLE_MORE_OBJECT_METHOD_STRING + NEW_LINE;
}
/**
* Returns to string leaf for get method.
*
* @return string leaf for get method
*/
public static String getToStringLeafgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string select leaf for get method.
*
* @return select leaf string for get method
*/
public static String getToStringSelectLeafgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string leaf list for get method.
*
* @return string leaf list for get method
*/
public static String getToStringLeafListgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF_LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF_LIST + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string select leaf list for get.
*
* @return select leaf list list for get
*/
public static String getToStringSelectLeafListgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF_LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF_LIST + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string operation type for get method.
*
* @return operation type for get method
*/
public static String getOperationTypegetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + OPERATION_ENUM
+ SPACE + GET_OPERATION_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
+ OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns to string operation type for set.
*
* @return operation type set method
*/
public static String getOperationTypeSetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_OPERATION_TYPE
+ OPEN_PARENTHESIS + OPERATION_ENUM + SPACE + getSmallCase(OPERATION_ENUM) + CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ OP_PARAM_TYPE + SPACE + EQUAL + SPACE + getSmallCase(OPERATION_ENUM) + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns string for leaf set method.
*
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for leaf set method
*/
public static String getSetterForLeaf(String className, YangNode curnode, YangPluginConfig pluginConfig) {
int numleaf = 1;
String filterMethod = "";
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
if (curnode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
if (leaves != null && !leaves.isEmpty()) {
for (YangLeaf leaf : leaves) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeaf(tempFragmentFiles, leaf, pluginConfig);
String attrQuaifiedType = getReturnType(javaAttributeInfo);
String attributeName = javaAttributeInfo.getAttributeName();
filterMethod = filterMethod + NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE
+ attributeName + OPEN_PARENTHESIS + attrQuaifiedType
+ SPACE + RECEIVED_OBJECT + attributeName + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + EIGHT_SPACE_INDENTATION + attributeName + SPACE + EQUAL + SPACE
+ RECEIVED_OBJECT + attributeName + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
+ GET_FILTER_LEAF + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + SET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
numleaf++;
}
}
}
return filterMethod;
}
/**
* Returns string for leaf list set method.
*
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for leaf list set method
*/
public static String getSetterForLeafList(String className, YangNode curnode, YangPluginConfig pluginConfig) {
int numleaf = 1;
String filterMethod = "";
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
if (curnode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
for (YangLeafList leafList : listOfLeafList) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
String attrQuaifiedType = getReturnType(javaAttributeInfo);
if (javaAttributeInfo.isListAttr()) {
attrQuaifiedType = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
}
filterMethod = filterMethod + NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE
+ attributeName + OPEN_PARENTHESIS + attrQuaifiedType
+ SPACE + RECEIVED_OBJECT + attributeName + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + EIGHT_SPACE_INDENTATION + attributeName + SPACE + EQUAL + SPACE
+ RECEIVED_OBJECT + attributeName + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
+ GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + SET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numleaf) + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
numleaf++;
}
}
}
return filterMethod;
}
/**
* Returns whether the data type is of primitive data type.
*
* @param dataType data type to be checked
......@@ -923,7 +787,7 @@ public final class MethodsGenerator {
+ CLOSE_PARENTHESIS;
}
private static String getAttrTypeForFilterContentMatchWhenNonPremitiveDatatype(String attributeName) {
private static String getAttrTypeForFilterContentMatchWhenNonPrimitiveDataTypes(String attributeName) {
return APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + EQUAL + EQUAL + SPACE + NULL + SPACE + OR_OPERATION + SPACE
+ NOT + OPEN_PARENTHESIS + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
......@@ -933,7 +797,7 @@ public final class MethodsGenerator {
}
private static String getIfFilterContentMatchMethodImpl(String attributeName,
String filterMethod, int numleaf, YangType dataType) {
YangType dataType) {
String attrQualifiedType;
if (isPrimitiveDataType(dataType.getDataType())) {
......@@ -943,10 +807,10 @@ public final class MethodsGenerator {
if (isPrimitiveDataType(type.getDataType())) {
attrQualifiedType = getAttrTypeForFilterContentMatchWhenPrimitiveDataType(attributeName);
} else {
attrQualifiedType = getAttrTypeForFilterContentMatchWhenNonPremitiveDatatype(attributeName);
attrQualifiedType = getAttrTypeForFilterContentMatchWhenNonPrimitiveDataTypes(attributeName);
}
} else {
attrQualifiedType = getAttrTypeForFilterContentMatchWhenNonPremitiveDatatype(attributeName);
attrQualifiedType = getAttrTypeForFilterContentMatchWhenNonPrimitiveDataTypes(attributeName);
}
return attrQualifiedType;
......@@ -955,27 +819,21 @@ public final class MethodsGenerator {
/**
* Returns string for is filter content match method.
*
* @param className class name
* @param curNode current YANG node
* @param pluginConfig plugin configurations
* @return string for is filter content match method
*/
public static String getIsFilterContentMatch(String className, YangNode curNode, YangPluginConfig pluginConfig) {
static String getIsFilterContentMatch(YangNode curNode, YangPluginConfig pluginConfig) {
int numLeaf = 1;
String filterMethod = "";
String filterMethod = getOverRideString();
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
if (curNode instanceof YangLeavesHolder) {
filterMethod = NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE
+ SPACE + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS + getCapitalCase(OBJECT)
+ SPACE + OBJ +
CLOSE_PARENTHESIS + SPACE
filterMethod = filterMethod + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE
+ SPACE + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS + getCapitalCase(javaFileInfo.getJavaName())
+ SPACE + APP_INSTANCE + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + getCapitalCase(DEFAULT)
+ getCapitalCase(className) + SPACE + APP_INSTANCE + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS +
getCapitalCase(DEFAULT) + getCapitalCase(className) + CLOSE_PARENTHESIS + OBJ +
SEMI_COLAN + NEW_LINE;
if (curNode instanceof YangAugmentableNode) {
filterMethod = filterMethod + getAugmentableOpParamSyntax();
}
......@@ -990,39 +848,46 @@ public final class MethodsGenerator {
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
attrQualifiedType = getIfFilterContentMatchMethodImpl(attributeName,
filterMethod, numLeaf, leaf.getDataType());
leaf.getDataType());
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
+ GET_FILTER_LEAF + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numLeaf) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ OPEN_PARENTHESIS + LEAF_IDENTIFIER + PERIOD + attributeName.toUpperCase() + PERIOD +
GET_LEAF_INDEX
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE
+ OPEN_PARENTHESIS + attrQualifiedType + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE
+ SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
numLeaf++;
+ EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
}
}
if (listOfLeafList != null) {
numLeaf = 1;
for (YangLeafList leafList : listOfLeafList) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
attrQualifiedType = getIfFilterContentMatchMethodImpl(
attributeName, filterMethod, numLeaf, leafList.getDataType());
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
+ GET_FILTER_LEAF_LIST + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX
+ OPEN_PARENTHESIS + String.valueOf(numLeaf) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE
+ OPEN_PARENTHESIS + attrQualifiedType + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE
+ SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
numLeaf++;
filterMethod = filterMethod + getIsFileContentMatchForLists(getCapitalCase(attributeName), true,
javaAttributeInfo.getImportInfo().getClassInfo());
}
}
YangNode tempNode = curNode.getChild();
JavaFileInfo fileInfo;
String name;
while (tempNode != null) {
if (tempNode instanceof YangIsFilterContentNodes) {
fileInfo = ((JavaFileInfoContainer) tempNode).getJavaFileInfo();
name = getCapitalCase(fileInfo.getJavaName());
if (tempNode instanceof YangList) {
filterMethod = filterMethod +
getIsFileContentMatchForLists(name, false, null);
} else {
filterMethod = filterMethod + getIsFilerContentMatchForChildNode(name);
}
}
tempNode = tempNode.getNextSibling();
}
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLAN +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
......@@ -1031,57 +896,138 @@ public final class MethodsGenerator {
return filterMethod;
}
/*Returns method string for op parms augmented syntax*/
/**
* Returns filter content match for child nodes.
*
* @param name name of node
* @return filter content match for child nodes
*/
private static String getIsFilerContentMatchForChildNode(String name) {
name = getSmallCase(name);
String method = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + name + OPEN_PARENTHESIS +
CLOSE_PARENTHESIS + SPACE + NOT + EQUAL + SPACE + NULL + CLOSE_PARENTHESIS + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + APP_INSTANCE
+ PERIOD + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + EQUAL
+ EQUAL + SPACE + NULL + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE + NEW_LINE + TWELVE_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE;
return method + TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + name + OPEN_PARENTHESIS +
CLOSE_PARENTHESIS + PERIOD + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD + name +
OPEN_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE + SEMI_COLAN +
NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns filter content match for list types.
*
* @param name name of node
* @param isLeafList if for leaf list
* @param type type of the attribute
* @return filter content match for list types
*/
private static String getIsFileContentMatchForLists(String name, boolean isLeafList, String type) {
String method = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + getSmallCase(name) + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + NOT + EQUAL + SPACE + NULL + SPACE + AND + AND + SPACE + NOT +
getSmallCase(name) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + IS_EMPTY +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
method = method + TWELVE_SPACE_INDENTATION + IF + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD + getSmallCase(name)
+ OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + SPACE + NULL + SPACE + "||" + SPACE +
getSmallCase(name) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + IS_EMPTY + CLOSE_PARENTHESIS +
SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE +
TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
if (isLeafList) {
if (type.equals(getSmallCase(STRING_DATA_TYPE))) {
type = STRING_DATA_TYPE;
}
method = method + TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + type + SPACE +
getSmallCase(name)
+ SPACE + COLAN + SPACE + getSmallCase(name) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
FLAG + SPACE + EQUAL + SPACE + FALSE + SEMI_COLAN + NEW_LINE;
method = method + SIXTEEN_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + type + SPACE +
UNDER_SCORE + getSmallCase(name)
+ SPACE + COLAN + SPACE + APP_INSTANCE + PERIOD + getSmallCase(name) + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
method = method + TWENTY_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + getSmallCase(name) + PERIOD;
} else {
method = method + TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + name + SPACE +
getSmallCase(name)
+ SPACE + COLAN + SPACE + getSmallCase(name) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
FLAG + SPACE + EQUAL + SPACE + FALSE + SEMI_COLAN + NEW_LINE;
method = method + SIXTEEN_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + name + SPACE +
UNDER_SCORE + getSmallCase(name)
+ SPACE + COLAN + SPACE + APP_INSTANCE + PERIOD + getSmallCase(name) + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
method = method + TWENTY_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + getSmallCase(name) + PERIOD;
}
if (!isLeafList) {
method = method + FILTER_CONTENT_MATCH;
} else {
method = method + EQUALS_STRING;
}
method = method + OPEN_PARENTHESIS + UNDER_SCORE + getSmallCase(name) + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION + FLAG + SPACE + EQUAL + SPACE + TRUE +
SEMI_COLAN
+ NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION + BREAK + SEMI_COLAN + NEW_LINE + TWENTY_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
method = method + SIXTEEN_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + FLAG + SPACE + EQUAL + EQUAL
+ SPACE + FALSE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWENTY_SPACE_INDENTATION
+ RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
NEW_LINE;
return method + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
}
//Returns method string for op params augmented syntax
private static String getAugmentableOpParamSyntax() {
return EIGHT_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + YANG_AUGMENTED_INFO + SPACE +
return EIGHT_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + OBJECT_STRING + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + SPACE + COLAN + SPACE + THIS +
PERIOD + GET_METHOD_PREFIX + YANG_AUGMENTED_INFO + MAP + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD
PERIOD + getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD
+ VALUE + "s" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + NOT + OPEN_PARENTHESIS +
getSmallCase(YANG_AUGMENTED_INFO) + SPACE + INSTANCE_OF + SPACE + YANG_AUGMENTED_OP_PARAM_INFO +
CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
SIXTEEN_SPACE_INDENTATION + THROW + SPACE + NEW + SPACE + ILLEGAL_ARGUMENT_EXCEPTION +
OPEN_PARENTHESIS +
ILLEGAL_ARGUMENT_EXCEPTION_MSG + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE + TWELVE_SPACE_INDENTATION + YANG_AUGMENTED_INFO + SPACE +
NEW_LINE + TWELVE_SPACE_INDENTATION + OBJECT_STRING + SPACE +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) + SPACE + EQUAL + SPACE + APP_INSTANCE + PERIOD +
GET_METHOD_PREFIX + AUGMENTED_INFO + OPEN_PARENTHESIS + OPEN_PARENTHESIS + OPEN_PARENTHESIS +
YANG_AUGMENTED_OP_PARAM_INFO + CLOSE_PARENTHESIS + SPACE + getSmallCase(YANG_AUGMENTED_INFO) +
CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX + BASE_CLASS + CLOSE_PARENTHESIS + SEMI_COLAN +
NEW_LINE + TWELVE_SPACE_INDENTATION + IF + OPEN_PARENTHESIS + NOT +
OPEN_PARENTHESIS + OPEN_PARENTHESIS + YANG_AUGMENTED_OP_PARAM_INFO + CLOSE_PARENTHESIS + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + CLOSE_PARENTHESIS
+ PERIOD + "isFilterContentMatch" + OPEN_PARENTHESIS +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) + CLOSE_PARENTHESIS +
CLOSE_PARENTHESIS +
getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD + GET_CLASS +
CLOSE_PARENTHESIS + SEMI_COLAN +
NEW_LINE + TWELVE_SPACE_INDENTATION
+ BOOLEAN_DATA_TYPE + SPACE + FILTER_CONTENT_MATCH + SPACE + EQUAL + SPACE + FALSE + SEMI_COLAN
+ NEW_LINE + TWELVE_SPACE_INDENTATION + TRY + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
SIXTEEN_SPACE_INDENTATION +
FILTER_CONTENT_MATCH + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS
+ BOOLEAN_DATA_TYPE + CLOSE_PARENTHESIS + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + PERIOD +
GET_CLASS + NEW_LINE + TWENTY_SPACE_INDENTATION + PERIOD + GET_METHOD
+ OPEN_PARENTHESIS + QUOTES + FILTER_CONTENT_MATCH + QUOTES + COMMA + SPACE + OBJECT_STRING + PERIOD
+ CLASS + CLOSE_PARENTHESIS + PERIOD + INVOKE + OPEN_PARENTHESIS + getSmallCase(YANG_AUGMENTED_INFO) +
NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION + PERIOD + GET_CLASS + COMMA + SPACE +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO)
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + CATCH + OPEN_PARENTHESIS
+ NO_SUCH_METHOD_EXCEPTION + " | " + INVOCATION_TARGET_EXCEPTION + " | " + ILLEGAL_ACCESS_EXCEPTION +
SPACE + EXCEPTION_VAR + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION
+ IF + OPEN_PARENTHESIS + NOT + FILTER_CONTENT_MATCH + CLOSE_PARENTHESIS +
SPACE + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE +
SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns implementation of get base class method for op param files.
*
* @param baseClassName base class name
* @return implementation of get base class method for op param files
*/
public static String getBaseClassMethodImpl(String baseClassName) {
return NEW_LINE + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_STRING +
DIAMOND_OPEN_BRACKET +
QUESTION_MARK +
DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + BASE_CLASS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + RETURN + SPACE + baseClassName + PERIOD + CLASS + SEMI_COLAN + NEW_LINE +
FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET;
}
/*
* Retruns omit null value string.
* Returns omit null value string.
*
* @return omit null value string
*/
public static String getOmitNullValueString() {
static String getOmitNullValueString() {
return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE;
}
......@@ -1090,7 +1036,7 @@ public final class MethodsGenerator {
*
* @return to string method close string
*/
public static String getToStringMethodClose() {
static String getToStringMethodClose() {
return TWELVE_SPACE_INDENTATION + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
......@@ -1115,7 +1061,7 @@ public final class MethodsGenerator {
* @param pluginConfig plugin configurations
* @return from string method's open string
*/
public static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
return getJavaDoc(FROM_METHOD, className, false, pluginConfig) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
+ STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS
+ STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE
......@@ -1127,7 +1073,7 @@ public final class MethodsGenerator {
*
* @return from string method's close string
*/
public static String getFromStringMethodClose() {
static String getFromStringMethodClose() {
return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE;
}
......@@ -1153,7 +1099,7 @@ public final class MethodsGenerator {
*
* @return sub string with try statement for union's from string method
*/
public static String getTrySubString() {
private static String getTrySubString() {
return TRY + SPACE + OPEN_CURLY_BRACKET;
}
......@@ -1162,7 +1108,7 @@ public final class MethodsGenerator {
*
* @return sub string with return statement for union's from string method
*/
public static String getReturnOfSubString() {
private static String getReturnOfSubString() {
return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN;
}
......@@ -1171,7 +1117,7 @@ public final class MethodsGenerator {
*
* @return sub string with catch statement for union's from string method
*/
public static String getCatchSubString() {
private static String getCatchSubString() {
return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
}
......@@ -1227,10 +1173,11 @@ public final class MethodsGenerator {
*
* @return hash code method open string
*/
public static String getHashCodeMethodOpen() {
static String getHashCodeMethodOpen() {
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + INT + SPACE + HASH_CODE_STRING
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS;
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + HASH + OPEN_PARENTHESIS + SPACE;
}
/**
......@@ -1239,10 +1186,11 @@ public final class MethodsGenerator {
* @param hashcodeString hash code string
* @return to hash code method close string
*/
public static String getHashCodeMethodClose(String hashcodeString) {
static String getHashCodeMethodClose(String hashcodeString) {
hashcodeString = trimAtLast(hashcodeString, COMMA);
hashcodeString = trimAtLast(hashcodeString, SPACE);
return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET
+ NEW_LINE;
}
......@@ -1262,8 +1210,9 @@ public final class MethodsGenerator {
* @param className class name
* @return equals method open string
*/
public static String getEqualsMethodOpen(String className) {
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE + EQUALS_STRING
static String getEqualsMethodOpen(String className) {
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE +
EQUALS_STRING
+ OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className);
}
......@@ -1298,7 +1247,7 @@ public final class MethodsGenerator {
* @param equalMethodString equal method string
* @return equals method close string
*/
public static String getEqualsMethodClose(String equalMethodString) {
static String getEqualsMethodClose(String equalMethodString) {
equalMethodString = trimAtLast(equalMethodString, AND);
equalMethodString = trimAtLast(equalMethodString, AND);
equalMethodString = trimAtLast(equalMethodString, SPACE);
......@@ -1329,7 +1278,7 @@ public final class MethodsGenerator {
* @param attr attribute info
* @return of method string
*/
public static String getOfMethod(String name, JavaAttributeInfo attr) {
static String getOfMethod(String name, JavaAttributeInfo attr) {
String attrQualifiedType = getReturnType(attr);
......@@ -1399,7 +1348,7 @@ public final class MethodsGenerator {
* @param generatedJavaClassName class name
* @param pluginConfig plugin config
* @param type conflict validate type
* @param addFirst whether int came first or uint came first
* @param addFirst whether int came first or uInt came first
* @return string and java doc for constructor of type class
*/
public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1, JavaAttributeInfo
......@@ -1460,7 +1409,7 @@ public final class MethodsGenerator {
name1 = attr2;
name2 = attr1;
}
constructor = constructor + ifConditionForIntInTypeDefConstrcutor(validatorType, addInt) +
constructor = constructor + ifConditionForIntInTypeDefConstructor(validatorType, addInt) +
TWELVE_SPACE_INDENTATION + THIS + PERIOD
+ name1 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION
......@@ -1473,13 +1422,24 @@ public final class MethodsGenerator {
}
/**
* Returns interface of add augmentation.
*
* @return interface of add augmentation
*/
static String getAddAugmentInfoMethodInterface() {
return generateForAddAugmentation() + FOUR_SPACE_INDENTATION + VOID + SPACE +
ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
* Returns implementation of add augmentation.
*
* @return implementation of add augmentation
*/
static String getAddAugmentInfoMethodImpl() {
return NEW_LINE + generateForAddAugmentation() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
ADD_STRING + AUGMENTED_INFO + OPEN_PARENTHESIS + YANG_AUGMENTED_INFO + SPACE + VALUE + COMMA +
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT +
OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE + VALUE +
......@@ -1488,15 +1448,25 @@ public final class MethodsGenerator {
}
/**
* Returns implementation of get augment info.
* Returns interface of get YANG augment info.
*
* @return implementation of get augment info
* @return interface of get YANG augment info
*/
static String getAugmentInfoImpl() {
static String getYangAugmentInfoInterface() {
return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + OBJECT_STRING + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
YANG_AUGMENTED_INFO + SPACE + GET_METHOD_PREFIX +
AUGMENTED_INFO + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
/**
* Returns implementation of get YANG augment info.
*
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoImpl() {
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
OBJECT_STRING + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + GET + OPEN_PARENTHESIS + CLASS +
OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
......@@ -1504,17 +1474,29 @@ public final class MethodsGenerator {
}
/**
* Returns implementation of get augment info.
* Returns implementation of get YANG augment info.
*
* @return implementation of get augment info
* @return implementation of get YANG augment info
*/
static String getAugmentInfoMapImpl(YangPluginConfig pluginConfig) {
static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig)
+ FOUR_SPACE_INDENTATION + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET +
SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
* Returns implementation of get YANG augment info.
*
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoMapImpl() {
return getOverRideString()
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + QUESTION_MARK +
DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE +
GET_METHOD_PREFIX + YANG_AUGMENTED_INFO + MAP + OPEN_PARENTHESIS +
DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
......@@ -1526,7 +1508,7 @@ public final class MethodsGenerator {
* @param className enum's class name
* @return enum's constructor
*/
public static String getEnumsConstructor(String className) {
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;
......@@ -1542,7 +1524,7 @@ public final class MethodsGenerator {
* @param pluginConfig plugin configurations
* @return of method
*/
public static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
static String getEnumsOfMethod(String className, JavaAttributeInfo attr,
Map<String, Integer> enumMap, List<String> enumList,
YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
......@@ -1553,7 +1535,7 @@ public final class MethodsGenerator {
+ attrType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
int value = 0;
int value;
for (String str : enumList) {
value = enumMap.get(str);
......@@ -1570,42 +1552,13 @@ public final class MethodsGenerator {
}
/**
* Returns activate method string.
*
* @return activate method string
*/
public static String addActivateMethod() {
return FOUR_SPACE_INDENTATION + ACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION
+ PUBLIC + SPACE + VOID + SPACE + ACTIVATE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + EIGHT_SPACE_INDENTATION
+ YANG_UTILS_TODO
+ NEW_LINE + EIGHT_SPACE_INDENTATION
+ STARTED_LOG_INFO + FOUR_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns deactivate method string.
*
* @return deactivate method string
*/
public static String addDeActivateMethod() {
return NEW_LINE + FOUR_SPACE_INDENTATION + DEACTIVATE_ANNOTATION + FOUR_SPACE_INDENTATION
+ PUBLIC + SPACE + VOID + SPACE + DEACTIVATE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION
+ STOPPED_LOG_INFO + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns from string method parsed string.
*
* @param targetDataType target data type
* @param yangType YANG type
* @return parsed string
*/
public static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
YangDataTypes type = yangType.getDataType();
......@@ -1629,7 +1582,6 @@ public final class MethodsGenerator {
case DECIMAL64:
return NEW + SPACE + BIG_DECIMAL;
case STRING:
return EMPTY_STRING;
case IDENTITYREF:
return EMPTY_STRING;
case EMPTY:
......@@ -1646,22 +1598,6 @@ public final class MethodsGenerator {
}
/**
* 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;
}
/**
* Returns augmented data getter and setter methods for service class.
*
* @param parent parent node
......@@ -1688,11 +1624,9 @@ public final class MethodsGenerator {
}
returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
method = getJavaDoc(GETTER_METHOD, getSmallCase(AUGMENTED + parentName + curNodeName), false,
pluginConfig) + getGetterForInterface(AUGMENTED + parentName
+ getCapitalCase(curNodeName),
returnType, false, GENERATE_SERVICE_AND_MANAGER)
+ NEW_LINE;
method = generateForGetMethodWithAttribute(returnType)
+ getGetMethodWithArgument(returnType, AUGMENTED + parentName
+ getCapitalCase(curNodeName)) + NEW_LINE;
methods.append(method);
method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
......@@ -1707,54 +1641,12 @@ public final class MethodsGenerator {
}
/**
* Returns augmented data getter and setter methods for manager class.
*
* @param parent parent node
* @return augmented data getter and setter methods for manager class
*/
static String getAugmentsDataMethodForManager(YangNode parent) {
List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
YangNode augmentedNode;
String curNodeName;
String returnType;
String method;
StringBuilder methods = new StringBuilder();
String parentName;
YangNode methodNode;
YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
for (YangAtomicPath nodeId : targets) {
augmentedNode = nodeId.getResolvedNode().getParent();
methodNode = nodeId.getResolvedNode();
if (((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName() != null) {
curNodeName = ((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName();
} else {
curNodeName = getCapitalCase(getCamelCase(methodNode.getName(), pluginConfig
.getConflictResolver()));
}
returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
method = getOverRideString() + getGetter(returnType, AUGMENTED
+ parentName + getCapitalCase(curNodeName),
GENERATE_SERVICE_AND_MANAGER) + NEW_LINE;
methods.append(method);
method = getOverRideString() + getSetter(parentName, getSmallCase(AUGMENTED) +
getCapitalCase(parentName) + getCapitalCase(curNodeName),
returnType,
GENERATE_SERVICE_AND_MANAGER)
+ NEW_LINE;
methods.append(method);
}
return methods.toString();
}
/**
* Returns validator method for range in union class.
*
* @param type type
* @return validator method for range in union class
*/
public static String getRangeValidatorMethodForUnion(String type) {
static String getRangeValidatorMethodForUnion(String type) {
String newType;
if (type.contentEquals(BIG_INTEGER)) {
newType = LONG;
......@@ -1790,7 +1682,7 @@ public final class MethodsGenerator {
* @param addFirst true int/long need to be added first
* @return if condition string for typedef constructor
*/
private static String ifConditionForIntInTypeDefConstrcutor(ValidatorTypeForUnionTypes type, boolean addFirst) {
private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type, boolean addFirst) {
String condition = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + VALIDATE_RANGE + OPEN_PARENTHESIS;
if (type == INT_TYPE_CONFLICT) {
......@@ -1809,5 +1701,249 @@ public final class MethodsGenerator {
return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
//Get method with arguments.
private static String getGetMethodWithArgument(String returnType, String yangName) {
return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName)
+ OPEN_PARENTHESIS + returnType + OP_PARAM + SPACE + getSmallCase(returnType) + CLOSE_PARENTHESIS +
SEMI_COLAN;
}
/**
* Returns add to list method interface.
*
* @param attr java attribute
* @return add to list method interface
*/
public static String getAddToListMethodInterface(JavaAttributeInfo attr) {
return FOUR_SPACE_INDENTATION + VOID + SPACE + ADD_STRING + getCapitalCase(TO) +
getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS + getReturnType(attr) + SPACE +
VALUE + CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
* Returns add to list method impl.
*
* @param attr java attribute
* @return add to list method impl
*/
public static String getAddToListMethodImpl(JavaAttributeInfo attr) {
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING +
getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS +
getReturnType(attr) + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + EIGHT_SPACE_INDENTATION + attr.getAttributeName() + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
* Returns builder method for class.
*
* @param name name of class
* @return builder method for class
*/
static String builderMethod(String name) {
return NEW_LINE + generateForBuilderMethod(name) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE
+ name + BUILDER + SPACE + getSmallCase(BUILDER) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name +
BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET;
}
/**
* Returns is filter content match interface.
*
* @param name name of node
* @return is filter content match interface
*/
static String isFilterContentMatchInterface(String name) {
String method = " /**\n" +
" * Checks if the passed " + name + " maps the content match query condition.\n" +
" *\n" +
" * @param " + getSmallCase(name) + SPACE + getSmallCase(name) + SPACE + "being passed to check" +
" for" +
" content match\n" +
" * @return match result\n" +
" */\n";
return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS
+ name + SPACE + getSmallCase(name) + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
* Returns is value set interface.
*
* @return is value set interface
*/
static String isLeafValueSetInterface() {
String method = " /**\n" +
" * Checks if the leaf value is set.\n" +
" *\n" +
" * @param leaf leaf whose value status needs to checked\n" +
" * @return result of leaf value set in object\n" +
" */\n";
return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + VALUE_LEAF_SET + OPEN_PARENTHESIS
+ LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
* Returns is select leaf set interface.
*
* @return is select leaf set interface
*/
static String isSelectLeafSetInterface() {
String method = " /**\n" +
" * Checks if the leaf is set to be a selected leaf.\n" +
" *\n" +
" * @param leaf if leaf needs to be selected\n" +
" * @return result of leaf value set in object\n" +
" */\n";
return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + IS_SELECT_LEAF + OPEN_PARENTHESIS
+ LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
* Returns set select leaf set interface.
*
* @param name node name
* @return set select leaf set interface
*/
static String setSelectLeafSetInterface(String name) {
String method = " /**\n" +
" * Set a leaf to be selected.\n" +
" *\n" +
" * @param leaf leaf needs to be selected\n" +
" */\n";
return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE + SET_SELECT_LEAF + OPEN_PARENTHESIS
+ LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
* Returns leaf identifier interface enum signature.
*
* @param name name of node
* @return leaf identifier interface enum signature
*/
static String getInterfaceLeafIdEnumSignature(String name) {
String start = " /**\n" +
" * Identify the leaf of " + name + PERIOD + NEW_LINE +
" */\n";
return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + LEAF_IDENTIFIER + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns interface leaf identifier enum method.
*
* @return interface leaf identifier enum method
*/
static String getInterfaceLeafIdEnumMethods() {
return " private int leafIndex;\n" +
"\n" +
" public int getLeafIndex() {\n" +
" return leafIndex;\n" +
" }\n" +
"\n" +
" LeafIdentifier(int value) {\n" +
" this.leafIndex = value;\n" +
" }\n" +
" }\n";
}
/**
* Returns getter methods for operation attributes.
*
* @return getter methods for operation attributes
*/
static String getOperationAttributesGetters() {
return "\n" +
" /**\n" +
" * Returns the _valueLeafFlags.\n" +
" *\n" +
" * @return value of _valueLeafFlags\n" +
" */\n" +
" public BitSet get_valueLeafFlags() {\n" +
" return _valueLeafFlags;\n" +
" }\n" +
"\n" +
" /**\n" +
" * Returns the _selectLeafFlags.\n" +
" *\n" +
" * @return value of _selectLeafFlags\n" +
" */\n" +
" public BitSet get_selectLeafFlags() {\n" +
" return _selectLeafFlags;\n" +
" }\n" +
"\n";
}
/**
* Returns getter for operation type.
*
* @return getter for operation type
*/
static String getGetterForOperationType() {
return " /**\n" +
" * Returns the _operationType.\n" +
" *\n" +
" * @return value of _operationType\n" +
" */\n" +
" public OperationType get_operationType() {\n" +
" return _operationType;\n" +
" }\n";
}
/**
* Returns getters for value and select leaf.
*
* @return getters for value and select leaf
*/
static String getGettersForValueAndSelectLeaf() {
return "\n" +
" @Override\n" +
" public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
" return get_valueLeafFlags().get(leaf.getLeafIndex());\n" +
" }\n" +
"\n" +
" @Override\n" +
" public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
" return get_selectLeafFlags().get(leaf.getLeafIndex());\n" +
" }\n";
}
/**
* Returns setter for operation type.
*
* @param name name of node
* @return setter for operation type
*/
static String getSetterForOperationType(String name) {
return " /**\n" +
" * Set operation type.\n" +
" *\n" +
" * @param _operationType operation type\n" +
" */\n" +
" public " + name + BUILDER + " set_operationType(OperationType _operationType) {\n" +
" this._operationType = _operationType;\n" +
" return this;\n" +
" }\n";
}
/**
* Returns setter for select leaf.
*
* @param name name of node
* @param isRootNode if root node
* @return setter for select leaf
*/
static String getSetterForSelectLeaf(String name, boolean isRootNode) {
String append = OVERRIDE;
if (isRootNode) {
append = EMPTY_STRING;
}
return "\n" +
" " + append + "\n" +
" public " + name + BUILDER + " selectLeaf(LeafIdentifier leaf) {\n" +
" get_selectLeafFlags().set(leaf.getLeafIndex());\n" +
" return this;\n" +
" }\n";
}
}
......
......@@ -22,12 +22,12 @@ package org.onosproject.yangutils.translator.tojava.utils;
public enum ValidatorTypeForUnionTypes {
/**
* When conflict is there for int32 and uint16.
* When conflict is there for int32 and uInt16.
*/
INT_TYPE_CONFLICT,
/**
* When conflict is there for int64 and uint32.
* When conflict is there for int64 and uInt32.
*/
LONG_TYPE_CONFLICT
}
......
......@@ -107,6 +107,11 @@ public final class UtilConstants {
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
/**
* JavaDocs's description for add to list method.
*/
public static final String JAVA_DOC_ADD_TO_LIST = " * Adds to the list of ";
/**
* JavaDocs's description for setter method.
*/
public static final String JAVA_DOC_MANAGER_SETTERS = " * Sets the value to attribute ";
......@@ -187,11 +192,6 @@ public final class UtilConstants {
public static final String OPERATION = "OpParam";
/**
* Static attribute for operation type.
*/
public static final String OPERATION_ENUM = "OperationType";
/**
* Static attribute for java code generation for sbi.
*/
public static final String SBI = "sbi";
......@@ -217,14 +217,14 @@ public final class UtilConstants {
public static final String PERIOD = ".";
/**
* Static attribute for parse byte.
* Static attribute for period.
*/
public static final String PARSE_BYTE = "parseByte";
public static final String INVOKE = "invoke";
/**
* Static attribute for get bytes.
* Static attribute for parse byte.
*/
public static final String GET_BYTES = "getBytes";
public static final String PARSE_BYTE = "parseByte";
/**
* Static attribute for parse boolean.
......@@ -694,11 +694,6 @@ public final class UtilConstants {
public static final String OPEN_PARENTHESIS = "(";
/**
* Static attribute for received syntax.
*/
public static final String RECEIVED_OBJECT = "recv";
/**
* Static attribute for switch syntax.
*/
public static final String SWITCH = "switch";
......@@ -749,6 +744,16 @@ public final class UtilConstants {
public static final String GET_METHOD_PREFIX = "get";
/**
* Static attribute for getter method prefix.
*/
public static final String GET_METHOD = "getMethod";
/**
* Static attribute for getter method prefix.
*/
public static final String GET_CLASS = "getClass()";
/**
* Static attribute for setter method prefix.
*/
public static final String SET_METHOD_PREFIX = "set";
......@@ -756,62 +761,58 @@ public final class UtilConstants {
/**
* Static attribute for get filter leaf flags.
*/
public static final String GET_FILTER_LEAF = "getFilterLeafFlags";
public static final String GET_FILTER_LEAF = "get_valueLeafFlags";
/**
* Static attribute for get filter leaf list flags.
* Static attribute for getLeafIndex.
*/
public static final String GET_FILTER_LEAF_LIST = "getFilterLeafListFlags";
public static final String GET_LEAF_INDEX = "getLeafIndex()";
/**
* Static attribute for filter leaf flags.
* Static attribute for op param.
*/
public static final String FILTER_LEAF = "filterLeafFlags";
public static final String OP_PARAM = "OpParam";
/**
* Static attribute for filter leaf list flags.
*/
public static final String FILTER_LEAF_LIST = "filterLeafListFlags";
/**
* Static attribute for get select leaf flags.
* Static attribute for is filter content match method prefix.
*/
public static final String GET_SELECT_LEAF = "getSelectLeafFlags";
public static final String FILTER_CONTENT_MATCH = "isFilterContentMatch";
/**
* Static attribute for get select leaf list flags.
* Static attribute for flag prefix.
*/
public static final String GET_SELECT_LEAF_LIST = "getSelectLeafListFlags";
public static final String FLAG = "flag";
/**
* Static attribute for get operation type.
* Static attribute for break prefix.
*/
public static final String GET_OPERATION_TYPE = "getOpertionType";
public static final String BREAK = "break";
/**
* Static attribute for set operation type.
* Static attribute for break prefix.
*/
public static final String SET_OPERATION_TYPE = "setOpertionType";
public static final String IS_EMPTY = "isEmpty()";
/**
* Static attribute for select leaf flags.
* Static attribute for is isLeafValueSet method prefix.
*/
public static final String SELECT_LEAF = "selectLeafFlags";
public static final String VALUE_LEAF_SET = "isLeafValueSet";
/**
* Static attribute for select leaf list flags.
* Static attribute for is isSelectLeaf method prefix.
*/
public static final String SELECT_LEAF_LIST = "selectLeafListFlags";
public static final String IS_SELECT_LEAF = "isSelectLeaf";
/**
* Static attribute for op param type.
* Static attribute for is selectLeaf method prefix.
*/
public static final String OP_PARAM_TYPE = "opParamType";
public static final String SET_SELECT_LEAF = "selectLeaf";
/**
* Static attribute for is filter content match method prefix.
* Static attribute for is LeafIdentifier enum prefix.
*/
public static final String FILTER_CONTENT_MATCH = "isFilterContentMatch";
public static final String LEAF_IDENTIFIER = "LeafIdentifier";
/**
* Static attribute for four space indentation.
......@@ -834,36 +835,6 @@ public final class UtilConstants {
public static final String CATCH = "catch";
/**
* Static attribute for super syntax.
*/
public static final String SUPER = "super";
/**
* Static attribute for merge syntax.
*/
public static final String MERGE = "MERGE,";
/**
* Static attribute for replace syntax.
*/
public static final String REPLACE = "REPLACE,";
/**
* Static attribute for create syntax.
*/
public static final String CREATE = "CREATE,";
/**
* Static attribute for delete syntax.
*/
public static final String DELETE = "DELETE,";
/**
* Static attribute for remove syntax.
*/
public static final String REMOVE = "REMOVE";
/**
* Static attribute for eight space indentation.
*/
public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
......@@ -879,6 +850,16 @@ public final class UtilConstants {
public static final String SIXTEEN_SPACE_INDENTATION = EIGHT_SPACE_INDENTATION + EIGHT_SPACE_INDENTATION;
/**
* Static attribute for twenty space indentation.
*/
public static final String TWENTY_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + SIXTEEN_SPACE_INDENTATION;
/**
* Static attribute for twenty four space indentation.
*/
public static final String TWENTY_FOUR_SPACE_INDENTATION = EIGHT_SPACE_INDENTATION + SIXTEEN_SPACE_INDENTATION;
/**
* Static attribute for generated code path.
*/
public static final String YANG_GEN_DIR = "src/main/java/";
......@@ -899,7 +880,7 @@ public final class UtilConstants {
public static final String YANG_AUTO_PREFIX = "yangAutoPrefix";
/**
* Static attribute for YANG version perifx.
* Static attribute for YANG version prefix.
*/
public static final String VERSION_PREFIX = "v";
......@@ -1014,7 +995,7 @@ public final class UtilConstants {
public static final String LONG_WRAPPER = "Long";
/**
* Static varibale for question mark.
* Static variable for question mark.
*/
public static final String QUESTION_MARK = "?";
......@@ -1022,11 +1003,11 @@ public final class UtilConstants {
* List of keywords in java, this is used for checking if the input does not contain these keywords.
*/
public static final List<String> JAVA_KEY_WORDS = Arrays.asList(
"abstract", "continue", "for", "new", "switch", "assert", "default", "goto", "package", "synchronized",
"boolean", "do", "if", "private", "this", "break", "double", "implements", "protected", "throw", "byte",
"else", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient", "catch",
"extends", "int", "short", "try", "char", "final", "interface", "static", "void", "class", "finally",
"long", "strictfp", "volatile", "const", "float", "native", "super", "while");
"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
"default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "goto", "if",
"implements", "import", "instanceof", "enum", "int", "interface", "long", "native", "new", "null",
"package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch",
"synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
/**
* Static attribute for regex for all the special characters.
......@@ -1199,11 +1180,6 @@ public final class UtilConstants {
public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
/**
* Static attribute for impl syntax.
*/
public static final String IMPL = "Impl";
/**
* Static attribute for build method syntax.
*/
public static final String BUILD = "build";
......@@ -1275,21 +1251,6 @@ public final class UtilConstants {
public static final String JAVA_UTIL_IMPORT_BASE64_CLASS = "Base64;\n";
/**
* Static attribute for AugmentedInfo class import package.
*/
public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.datamodel";
/**
* Static attribute for AugmentedInfo class import class.
*/
public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS = "YangAugmentedInfo;\n";
/**
* Static attribute for augmentation class.
*/
public static final String AUGMENTED_INFO = "AugmentedInfo";
/**
* Static attribute for AugmentedInfo class.
*/
public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
......@@ -1305,104 +1266,11 @@ public final class UtilConstants {
public static final String LIST = "List";
/**
* Comment to be added for autogenerated impl methods.
* Comment to be added for auto generated impl methods.
*/
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
/**
* Static attribute for activate annotation.
*/
public static final String ACTIVATE_ANNOTATION = "@Activate\n";
/**
* Static attribute for activate.
*/
public static final String ACTIVATE = "activate";
/**
* Static attribute for activate annotation import.
*/
public static final String ACTIVATE_ANNOTATION_IMPORT = "import org.apache.felix.scr.annotations.Activate;\n";
/**
* Static attribute for deactivate annotation.
*/
public static final String DEACTIVATE_ANNOTATION = "@Deactivate\n";
/**
* Static attribute for deactivate.
*/
public static final String DEACTIVATE = "deactivate";
/**
* Static attribute for deactivate annotation import.
*/
public static final String DEACTIVATE_ANNOTATION_IMPORT =
"import org.apache.felix.scr.annotations.Deactivate;\n";
/**
* Static attribute for component annotation.
*/
public static final String COMPONENT_ANNOTATION = "@Component";
/**
* Static attribute for component.
*/
public static final String COMPONENT = "Component";
/**
* Static attribute for immediate.
*/
public static final String IMMEDIATE = "immediate";
/**
* Static attribute for component annotation import.
*/
public static final String COMPONENT_ANNOTATION_IMPORT =
"import org.apache.felix.scr.annotations.Component;\n";
/**
* Static attribute for service annotation.
*/
public static final String SERVICE_ANNOTATION = "@Service\n";
/**
* Static attribute for service annotation import.
*/
public static final String SERVICE_ANNOTATION_IMPORT =
"import org.apache.felix.scr.annotations.Service;\n";
/**
* Static attribute for logger factory import.
*/
public static final String LOGGER_FACTORY_IMPORT =
"import static org.slf4j.LoggerFactory.getLogger;\n";
/**
* Static attribute for logger import.
*/
public static final String LOGGER_IMPORT =
"import org.slf4j.Logger;\n";
/**
* Static attribute for logger statement.
*/
public static final String LOGGER_STATEMENT =
"\n private final Logger log = getLogger(getClass());\n";
/**
* Static attribute for logger statement for started.
*/
public static final String STARTED_LOG_INFO =
"log.info(\"Started\");\n";
/**
* Static attribute for logger statement for stopped.
*/
public static final String STOPPED_LOG_INFO =
"log.info(\"Stopped\");\n";
/**
* Static attribute for AbstractEvent.
*/
public static final String ABSTRACT_EVENT = "AbstractEvent";
......@@ -1470,16 +1338,6 @@ public final class UtilConstants {
+ "identity for given base";
/**
* Static attribute for reference.
*/
public static final String REFERENCE = "Reference";
/**
* Static attribute for ReferenceCardinality.
*/
public static final String REFERENCE_CARDINALITY = "ReferenceCardinality";
/**
* Static attribute for jar.
*/
public static final String JAR = "jar";
......@@ -1495,31 +1353,34 @@ public final class UtilConstants {
public static final String YANG_AUGMENTED_OP_PARAM_INFO = "YangAugmentedOpParamInfo";
/**
* Static attribute for YangAugmentedOpParamInfo.
* Static attribute for NoSuchMethodException.
*/
public static final String YANG_AUGMENTED_OP_PARAM_INFO_CLASS = "YangAugmentedOpParamInfo;\n";
public static final String NO_SUCH_METHOD_EXCEPTION = "NoSuchMethodException";
/**
* Static attribute for IllegalArgumentException.
* Static attribute for InvocationTargetException.
*/
public static final String ILLEGAL_ARGUMENT_EXCEPTION = "IllegalArgumentException";
public static final String INVOCATION_TARGET_EXCEPTION = "InvocationTargetException";
/**
* Static attribute for IllegalArgumentException.
* Static attribute for InvocationTargetException.
*/
public static final String ILLEGAL_ARGUMENT_EXCEPTION_MSG = "\"provided augmented info is invalid for content " +
"match.\"";
public static final String INVOCATION_TARGET_EXCEPTION_IMPORT = "import" +
" java.lang.reflect.InvocationTargetException;\n";
/**
* Static attribute for throw.
* Static attribute for IllegalAccessException.
*/
public static final String THROW = "throw";
public static final String ILLEGAL_ACCESS_EXCEPTION = "IllegalAccessException";
/**
* Static attribute for baseClass().
* Static attribute for arrayList.
*/
public static final String BASE_CLASS = "BaseClass()";
public static final String ARRAY_LIST = "ArrayList<>()";
/**
* Static attribute for arrayList import.
*/
public static final String ARRAY_LIST_IMPORT = IMPORT + COLLECTION_IMPORTS + ".ArrayList;\n";
/**
* Creates an instance of util constants.
......
......@@ -44,16 +44,13 @@ public final class FileSystemUtil {
}
/**
* Reads the contents from source file and append its contents to append
* file.
* Reads the contents from source file and append its contents to append file.
*
* @param toAppend destination file in which the contents of source file is
* appended
* @param srcFile source file from which data is read and added to to append
* file
* @param toAppend destination file in which the contents of source file is appended
* @param srcFile source file from which data is read and added to to append file
* @throws IOException any IO errors
*/
public static void appendFileContents(File toAppend, File srcFile)
static void appendFileContents(File toAppend, File srcFile)
throws IOException {
updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false);
}
......@@ -76,14 +73,21 @@ public final class FileSystemUtil {
String line = bufferReader.readLine();
while (line != null) {
if (line.equals(SPACE) || line.equals(EMPTY_STRING) || line.equals(EIGHT_SPACE_INDENTATION)
|| line.equals(MULTIPLE_NEW_LINE)) {
switch (line) {
case SPACE:
case EMPTY_STRING:
case EIGHT_SPACE_INDENTATION:
case MULTIPLE_NEW_LINE:
stringBuilder.append(NEW_LINE);
} else if (line.equals(FOUR_SPACE_INDENTATION)) {
break;
case FOUR_SPACE_INDENTATION:
stringBuilder.append(EMPTY_STRING);
} else {
stringBuilder.append(spaces + line);
break;
default:
String append = spaces + line;
stringBuilder.append(append);
stringBuilder.append(NEW_LINE);
break;
}
line = bufferReader.readLine();
}
......@@ -100,10 +104,10 @@ public final class FileSystemUtil {
* @param inputFile input file
* @param contentTobeAdded content to be appended to the file
* @param isClose when close of file is called.
* @throws IOException if the named file exists but is a directory rather than a regular file,
* does not exist but cannot be created, or cannot be opened for any other reason
* @throws IOException if the named file exists but is a directory rather than a regular file, does not exist but
* cannot be created, or cannot be opened for any other reason
*/
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
throws IOException {
List<FileWriter> fileWriterStore = new ArrayList<>();
......@@ -119,7 +123,6 @@ public final class FileSystemUtil {
for (FileWriter curWriter : fileWriterStore) {
curWriter.flush();
curWriter.close();
curWriter = null;
}
}
}
......@@ -137,7 +140,10 @@ public final class FileSystemUtil {
if (file != null) {
updateFileHandle(file, null, true);
if (toBeDeleted) {
file.delete();
boolean deleted = file.delete();
if (!deleted) {
throw new IOException("Failed to delete temporary file " + file.getName());
}
}
}
}
......
......@@ -19,17 +19,12 @@ package org.onosproject.yangutils.utils.io.impl;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
......@@ -38,15 +33,17 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_JAVA_
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_ADD_TO_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_MANAGER_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF;
......@@ -57,11 +54,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OF;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......@@ -71,6 +71,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
......@@ -92,7 +93,7 @@ public final class JavaDocGen {
* @param name name of the YangNode
* @param isList is list attribute
* @param pluginConfig plugin configurations
* @return javadocs.
* @return javaDocs.
*/
public static String getJavaDoc(JavaDocType type, String name, boolean isList, YangPluginConfig pluginConfig) {
......@@ -167,6 +168,9 @@ public final class JavaDocGen {
case EVENT_SUBJECT_CLASS: {
return generateForClass(name);
}
case ADD_TO_LIST: {
return generateForAddToList(name);
}
default: {
return generateForConstructors(name);
}
......@@ -180,8 +184,8 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForEnumAttr(String name) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
+ name + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return EIGHT_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + EIGHT_SPACE_INDENTATION + ENUM_ATTRIBUTE_JAVADOC
+ name + PERIOD + NEW_LINE + EIGHT_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
......@@ -438,11 +442,11 @@ public final class JavaDocGen {
/**
* Generates javaDoc for the builder interface.
*
* @param builderforName builder for name
* @param builderForName builder for name
* @return javaDocs
*/
private static String generateForBuilderInterface(String builderforName) {
return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderforName + PERIOD + NEW_LINE
private static String generateForBuilderInterface(String builderForName) {
return JAVA_DOC_FIRST_LINE + BUILDER_INTERFACE_JAVA_DOC + builderForName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
......@@ -480,7 +484,7 @@ public final class JavaDocGen {
*/
private static String generateForConstructors(String className) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ className + IMPL + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ className + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT
+ className + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
......@@ -504,7 +508,7 @@ public final class JavaDocGen {
* @param attribute attribute string
* @return javaDocs for type constructor
*/
public static String generateForTypeConstructor(String attribute) {
private static String generateForTypeConstructor(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
......@@ -557,6 +561,52 @@ public final class JavaDocGen {
}
/**
* Generates javaDocs for type constructor.
*
* @param attribute attribute string
* @return javaDocs for type constructor
*/
public static String generateForGetMethodWithAttribute(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_GETTERS
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + attribute + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
* Returns javaDocs for add to list method.
*
* @param attribute attribute
* @return javaDocs
*/
private static String generateForAddToList(String attribute) {
String javadoc = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_ADD_TO_LIST + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE;
javadoc = javadoc + VALUE + SPACE + OF + SPACE;
javadoc = javadoc + attribute + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return javadoc;
}
/**
* Generates for builder method.
*
* @param attribute attribute
* @return javaDocs
*/
public static String generateForBuilderMethod(String attribute) {
String javadoc = FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_GETTERS + attribute + BUILDER + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
+ NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN;
javadoc = javadoc + VALUE + SPACE + OF + SPACE;
javadoc = javadoc + attribute + BUILDER + NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return javadoc;
}
/**
* JavaDocs types.
*/
public enum JavaDocType {
......@@ -679,6 +729,12 @@ public final class JavaDocGen {
/**
* For operation builder.
*/
OPERATION_BUILDER_CLASS
OPERATION_BUILDER_CLASS,
/**
* For add to list.
*/
ADD_TO_LIST,
}
}
......
......@@ -27,8 +27,8 @@ import java.util.Stack;
*/
public final class YangFileScanner {
private static final String JAVA_FILE_EXTENTION = ".java";
private static final String YANG_FILE_EXTENTION = ".yang";
private static final String JAVA_FILE_EXTENSION = ".java";
private static final String YANG_FILE_EXTENSION = ".yang";
/**
* Creates an instance of YANG file scanner.
......@@ -45,9 +45,8 @@ public final class YangFileScanner {
* @throws IOException when files get deleted while performing the
* operations
*/
public static List<String> getJavaFiles(String root) throws IOException {
return getFiles(root, JAVA_FILE_EXTENTION);
static List<String> getJavaFiles(String root) throws IOException {
return getFiles(root, JAVA_FILE_EXTENSION);
}
/**
......@@ -60,8 +59,7 @@ public final class YangFileScanner {
* operations
*/
public static List<String> getYangFiles(String root) throws IOException {
return getFiles(root, YANG_FILE_EXTENTION);
return getFiles(root, YANG_FILE_EXTENSION);
}
/**
......@@ -73,22 +71,22 @@ public final class YangFileScanner {
* @throws NullPointerException when no file is there
* @throws IOException when files get deleted while performing the operations
*/
public static List<String> getFiles(String root, String extension) throws IOException {
private static List<String> getFiles(String root, String extension) throws IOException {
List<String> store = new LinkedList<>();
Stack<String> stack = new Stack<>();
stack.push(root);
File file;
File[] filelist;
File[] fileList;
try {
while (!stack.empty()) {
root = stack.pop();
file = new File(root);
filelist = file.listFiles();
if ((filelist == null) || (filelist.length == 0)) {
fileList = file.listFiles();
if ((fileList == null) || (fileList.length == 0)) {
continue;
}
for (File current : filelist) {
for (File current : fileList) {
if (current.isDirectory()) {
stack.push(current.toString());
} else {
......
......@@ -62,6 +62,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
......@@ -87,10 +88,16 @@ public final class YangIoUtils {
*
* @param path directory path
* @return directory structure
* @throws IOException when fails to do IO operations
*/
public static File createDirectories(String path) {
public static File createDirectories(String path) throws IOException {
File generatedDir = new File(path);
generatedDir.mkdirs();
if (!generatedDir.exists()) {
boolean isGenerated = generatedDir.mkdirs();
if (!isGenerated) {
throw new IOException("failed to generated directory " + path);
}
}
return generatedDir;
}
......@@ -113,22 +120,26 @@ public final class YangIoUtils {
try {
File packageInfo = new File(path + SLASH + "package-info.java");
packageInfo.createNewFile();
if (!packageInfo.exists()) {
boolean isGenerated = packageInfo.createNewFile();
if (!isGenerated) {
throw new IOException("failed to generated package-info " + path);
}
}
FileWriter fileWriter = new FileWriter(packageInfo);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
bufferedWriter.write(getCopyrightHeader());
bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode, pluginConfig));
String pkg = PACKAGE + SPACE + pack + SEMI_COLAN;
if (pkg.length() > LINE_SIZE) {
pkg = whenDelimiterIsPersent(pkg, LINE_SIZE);
pkg = whenDelimiterIsPresent(pkg, LINE_SIZE);
}
bufferedWriter.write(pkg);
bufferedWriter.close();
fileWriter.close();
} catch (IOException e) {
throw new IOException("Exception occured while creating package info file.");
throw new IOException("Exception occurred while creating package info file.");
}
}
......@@ -192,11 +203,11 @@ public final class YangIoUtils {
while (!stack.empty()) {
root = stack.pop();
File file = new File(root);
File[] filelist = file.listFiles();
if (filelist == null || filelist.length == 0) {
File[] fileList = file.listFiles();
if (fileList == null || fileList.length == 0) {
continue;
}
for (File current : filelist) {
for (File current : fileList) {
if (current.isDirectory()) {
stack.push(current.toString());
if (current.getName().endsWith("-Temp")) {
......@@ -215,12 +226,12 @@ public final class YangIoUtils {
* Removes extra char from the string.
*
* @param valueString string to be trimmed
* @param removalStirng extra chars
* @param removalString extra chars
* @return new string
*/
public static String trimAtLast(String valueString, String removalStirng) {
public static String trimAtLast(String valueString, String removalString) {
StringBuilder stringBuilder = new StringBuilder(valueString);
int index = valueString.lastIndexOf(removalStirng);
int index = valueString.lastIndexOf(removalString);
if (index != -1) {
stringBuilder.deleteCharAt(index);
}
......@@ -302,9 +313,9 @@ public final class YangIoUtils {
*/
public static File validateLineLength(File dataFile)
throws IOException {
File tempFile = dataFile;
FileReader fileReader = new FileReader(dataFile);
BufferedReader bufferReader = new BufferedReader(fileReader);
String append;
try {
StringBuilder stringBuilder = new StringBuilder();
String line = bufferReader.readLine();
......@@ -312,20 +323,21 @@ public final class YangIoUtils {
while (line != null) {
if (line.length() > LINE_SIZE) {
if (line.contains(PERIOD)) {
line = whenDelimiterIsPersent(line, LINE_SIZE);
line = whenDelimiterIsPresent(line, LINE_SIZE);
} else if (line.contains(SPACE)) {
line = whenSpaceIsPresent(line, LINE_SIZE);
}
stringBuilder.append(line);
} else {
stringBuilder.append(line + NEW_LINE);
append = line + NEW_LINE;
stringBuilder.append(append);
}
line = bufferReader.readLine();
}
FileWriter writer = new FileWriter(tempFile);
FileWriter writer = new FileWriter(dataFile);
writer.write(stringBuilder.toString());
writer.close();
return tempFile;
return dataFile;
} finally {
fileReader.close();
bufferReader.close();
......@@ -333,14 +345,15 @@ public final class YangIoUtils {
}
/* When delimiters are present in the given line. */
private static String whenDelimiterIsPersent(String line, int lineSize) {
private static String whenDelimiterIsPresent(String line, int lineSize) {
StringBuilder stringBuilder = new StringBuilder();
String append;
if (line.length() > lineSize) {
String[] strArray = line.split(Pattern.quote(PERIOD));
stringBuilder = updateString(strArray, stringBuilder, PERIOD, lineSize);
} else {
stringBuilder.append(line + NEW_LINE);
append = line + NEW_LINE;
stringBuilder.append(append);
}
String[] strArray = stringBuilder.toString().split(NEW_LINE);
StringBuilder tempBuilder = new StringBuilder();
......@@ -353,7 +366,8 @@ public final class YangIoUtils {
tempBuilder.append(whenSpaceIsPresent(str, SUB_LINE_SIZE));
}
} else {
tempBuilder.append(str + NEW_LINE);
append = str + NEW_LINE;
tempBuilder.append(append);
}
}
return tempBuilder.toString();
......@@ -363,11 +377,13 @@ public final class YangIoUtils {
/* When spaces are present in the given line. */
private static String whenSpaceIsPresent(String line, int lineSize) {
StringBuilder stringBuilder = new StringBuilder();
String append;
if (line.length() > lineSize) {
String[] strArray = line.split(SPACE);
stringBuilder = updateString(strArray, stringBuilder, SPACE, lineSize);
} else {
stringBuilder.append(line + NEW_LINE);
append = line + NEW_LINE;
stringBuilder.append(append);
}
String[] strArray = stringBuilder.toString().split(NEW_LINE);
......@@ -379,7 +395,8 @@ public final class YangIoUtils {
tempBuilder = updateString(strArr, tempBuilder, SPACE, SUB_LINE_SIZE);
}
} else {
tempBuilder.append(str + NEW_LINE);
append = str + NEW_LINE;
tempBuilder.append(append);
}
}
return tempBuilder.toString();
......@@ -390,28 +407,34 @@ public final class YangIoUtils {
int lineSize) {
StringBuilder tempBuilder = new StringBuilder();
String append;
for (String str : strArray) {
tempBuilder.append(str + string);
append = str + string;
tempBuilder.append(append);
if (tempBuilder.length() > lineSize) {
String tempString = stringBuilder.toString();
stringBuilder.delete(ZERO, stringBuilder.length());
tempString = trimAtLast(tempString, string);
stringBuilder.append(tempString);
if (string.equals(PERIOD)) {
stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string);
append = NEW_LINE + TWELVE_SPACE_INDENTATION + PERIOD + str + string;
stringBuilder.append(append);
} else {
stringBuilder.append(NEW_LINE + TWELVE_SPACE_INDENTATION + str + string);
append = NEW_LINE + TWELVE_SPACE_INDENTATION + str + string;
stringBuilder.append(append);
}
tempBuilder.delete(ZERO, tempBuilder.length());
tempBuilder.append(TWELVE_SPACE_INDENTATION);
} else {
stringBuilder.append(str + string);
append = str + string;
stringBuilder.append(append);
}
}
String tempString = stringBuilder.toString();
tempString = trimAtLast(tempString, string);
stringBuilder.delete(ZERO, stringBuilder.length());
stringBuilder.append(tempString + NEW_LINE);
append = tempString + NEW_LINE;
stringBuilder.append(append);
return stringBuilder;
}
......@@ -464,7 +487,7 @@ public final class YangIoUtils {
* @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
* @return string without consecutive capital case
*/
public static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
if (k + 1 < consecCapitalCaseRemover.length()) {
......@@ -487,7 +510,7 @@ public final class YangIoUtils {
* @param conflictResolver object of YANG to java naming conflict util
* @return prefixed camel case string
*/
public static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
String prefix = getPrefixForIdentifier(conflictResolver);
if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
......@@ -508,7 +531,7 @@ public final class YangIoUtils {
* @param conflictResolver object of YANG to java naming conflict util
* @return camel case rule checked string
*/
public static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
String ruleChecker = stringArray[0].toLowerCase();
int i;
......@@ -551,7 +574,7 @@ public final class YangIoUtils {
* @param conflictResolver object of YANG to java naming conflict util
* @return camel cased string
*/
public static String upperCaseConflictResolver(String[] stringArray,
private static String upperCaseConflictResolver(String[] stringArray,
YangToJavaNamingConflictUtil conflictResolver) {
for (int l = 0; l < stringArray.length; l++) {
......@@ -579,7 +602,7 @@ public final class YangIoUtils {
}
stringArray[l] = strBuilder.toString();
}
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
for (String element : stringArray) {
String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
for (String letter : capitalCaseSplitArray) {
......@@ -625,10 +648,8 @@ public final class YangIoUtils {
yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLAN);
String[] strArray = yangIdentifier.split(COLAN);
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
List<String> stringArrangement = new ArrayList<>();
stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
return upperCaseConflictResolver(strArray, conflictResolver);
......@@ -651,10 +672,8 @@ public final class YangIoUtils {
String[] strArray = prefixForIdentifier.split(COLAN);
try {
if (strArray[0].isEmpty()) {
List<String> stringArrangement = new ArrayList<String>();
for (int i = 1; i < strArray.length; i++) {
stringArrangement.add(strArray[i]);
}
List<String> stringArrangement = new ArrayList<>();
stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
}
prefixForIdentifier = strArray[0];
......
......@@ -54,7 +54,6 @@ 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(yangPluginConfig);
......
......@@ -20,9 +20,9 @@ import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......@@ -49,10 +49,8 @@ public class AugmentTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/augmentTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/augmentTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/augmentTranslator/");
deleteDirectory("target/augmentTranslator1/");
}
}
......
......@@ -44,7 +44,6 @@ public final class ChoiceCaseTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/ChoiceCaseTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/ChoiceCaseTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -45,7 +45,6 @@ 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;
......@@ -32,7 +33,6 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
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.utils.io.impl.YangFileScanner;
import static org.hamcrest.MatcherAssert.assertThat;
......@@ -52,7 +52,6 @@ public class InterFileLeafrefLinkingTest {
private final YangUtilManager utilManager = new YangUtilManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks inter file leafref linking.
......
......@@ -656,7 +656,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/");
yangPluginConfig.setManagerCodeGenDir("target/interfilewithusesreferringtype/");
utilManager.translateToJava(yangPluginConfig);
......@@ -678,7 +677,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
yangPluginConfig.setManagerCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
utilManager.translateToJava(yangPluginConfig);
......@@ -700,7 +698,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfileietf/");
yangPluginConfig.setManagerCodeGenDir("target/interfileietf/");
utilManager.translateToJava(yangPluginConfig);
......@@ -722,7 +719,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/usesInContainer/");
yangPluginConfig.setManagerCodeGenDir("target/usesInContainer/");
utilManager.translateToJava(yangPluginConfig);
......@@ -744,7 +740,6 @@ public class InterFileLinkingTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/");
yangPluginConfig.setManagerCodeGenDir("target/groupingNodeSameAsModule/");
utilManager.translateToJava(yangPluginConfig);
......
......@@ -41,11 +41,10 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
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.datamodel.utils.DataModelUtils.deSerializeDataModel;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.parseJarFile;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.parseJarFile;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.serializeDataModel;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
......@@ -189,7 +188,6 @@ public class InterJarLinkerTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(TARGET);
yangPluginConfig.setManagerCodeGenDir(TARGET);
utilManager.translateToJava(yangPluginConfig);
......@@ -206,7 +204,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()));
}
/**
......@@ -304,7 +302,7 @@ public class InterJarLinkerTest {
*/
private void addInterJarRootNodes(String jarFile) throws IOException {
try {
List<YangNode> interJarResolvedNodes = deSerializeDataModel(parseJarFile(jarFile, TARGET));
List<YangNode> interJarResolvedNodes = parseJarFile(jarFile, TARGET);
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
......@@ -326,7 +324,6 @@ public class InterJarLinkerTest {
File file = new File(TARGET + TARGET_RESOURCE_PATH);
File[] files = file.listFiles();
String[] source = new String[files.length];
for (int i = 0; i < files.length; i++) {
......
/*
* 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.datamodel.javadatamodel.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 when fails to do mojo operations
*/
@Test
public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/manager/singleChild";
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(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 when fails to do mojo operations
*/
@Test
public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/singleChild";
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(yangPluginConfig);
String file3 = "target/manager/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/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerforMultiChildTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/MultiChild";
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(yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
File manager1 = new File(file1);
assertThat(false, is(manager1.exists()));
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
File manager2 = new File(file2);
assertThat(false, is(manager2.exists()));
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(false, is(manager3.exists()));
String file4 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java";
File manager4 = new File(file4);
assertThat(true, is(manager4.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException when fails to do mojo operations
*/
@Test
public void processManagerforMultiChildWithDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/MultiChild";
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(yangPluginConfig);
String file1 = "target/manager1/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java";
File manager1 = new File(file1);
assertThat(true, is(manager1.exists()));
String file2 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Service.java";
File service2 = new File(file2);
assertThat(true, is(service2.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
}
......@@ -45,12 +45,10 @@ public final class NotificationTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/NotificationTest/");
yangPluginConfig.setManagerCodeGenDir("target/NotificationTest1/");
generateJavaCode(node, yangPluginConfig);
deleteDirectory("target/NotificationTest/");
deleteDirectory("target/NotificationTest1/");
}
// TODO enhance the test cases, after having a framework of translator test.
......
......@@ -45,7 +45,6 @@ public final class RpcTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/RpcTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/RpcTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -20,9 +20,9 @@ import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......@@ -49,7 +49,6 @@ public class TypeDefTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/typedefTranslator/");
......@@ -63,7 +62,6 @@ public class TypeDefTranslatorTest {
@Test
public void processTypeDefWithRestrictionsTranslator() throws IOException, ParserException, MojoExecutionException {
/*FIXME: After typedef with leafref is fixed.
String searchDir = "src/test/resources/typedefTranslator/with";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
......@@ -72,10 +70,10 @@ public class TypeDefTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/typedefTranslator/");
*/
}
}
......
......@@ -47,7 +47,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......@@ -71,7 +70,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -94,7 +92,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -117,7 +114,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -140,7 +136,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -163,7 +158,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -187,7 +181,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......@@ -211,7 +204,6 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/unionTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/unionTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/unionTranslator/");
......
......@@ -18,6 +18,7 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.ResolvableType;
......@@ -28,22 +29,24 @@ import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.linker.impl.YangXpathLinker;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* 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/";
private static final String CASE_FILE_PATH = "src/test/resources/xPathLinker/Case/";
private YangUtilManager utilManager = new YangUtilManager();
private YangXpathLinker linker = new YangXpathLinker();
private YangLinkerManager linkerManager = new YangLinkerManager();
/**
* Unit test case for intra file linking for single level container.
......@@ -622,6 +625,7 @@ public class YangXpathLinkerTest {
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -649,7 +653,6 @@ public class YangXpathLinkerTest {
@Test
public void processInterFileLinkingInMultipleUses() throws IOException {
/** FIXME: once order of linking is done.
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "uses/"));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
......@@ -657,6 +660,7 @@ public class YangXpathLinkerTest {
linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet());
linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet());
updateFilePriority(utilManager.getYangNodeSet());
linkerManager.processInterFileLinking(utilManager.getYangNodeSet());
YangNode targetNode = null;
......@@ -672,7 +676,11 @@ public class YangXpathLinkerTest {
}
}
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/xpath/");
utilManager.translateToJava(yangPluginConfig);
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
*/
deleteDirectory("target/xpath/");
}
}
......
......@@ -26,7 +26,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
......@@ -65,7 +65,7 @@ public class JavaCodeSnippetGenTest {
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class };
Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -102,26 +102,26 @@ public class JavaCodeSnippetGenTest {
@Test
public void testForJavaAttributeInfo() {
String attributeWithoutTypePkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
String attributeWithoutTypePkg = getJavaAttributeDefinition(null, STRING_DATA_TYPE, YANG_NAME,
false, PRIVATE);
assertThat(true, is(attributeWithoutTypePkg.equals(
PRIVATE + SPACE + STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithTypePkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
String attributeWithTypePkg = getJavaAttributeDefinition(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
false, PRIVATE);
assertThat(true, is(attributeWithTypePkg.equals(PRIVATE + SPACE + JAVA_LANG + PERIOD
+ STRING_DATA_TYPE + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
String attributeWithListPkg = getJavaAttributeDefination(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
String attributeWithListPkg = getJavaAttributeDefinition(JAVA_LANG, STRING_DATA_TYPE, YANG_NAME,
true, PRIVATE);
assertThat(true, is(attributeWithListPkg.equals(
assertThat(true, is(attributeWithListPkg.contains(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + JAVA_LANG + PERIOD + STRING_DATA_TYPE
+ DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME + SEMI_COLAN + NEW_LINE)));
+ DIAMOND_CLOSE_BRACKET + SPACE + YANG_NAME)));
String attributeWithListWithoutPkg = getJavaAttributeDefination(null, STRING_DATA_TYPE, YANG_NAME,
String attributeWithListWithoutPkg = getJavaAttributeDefinition(null, STRING_DATA_TYPE, YANG_NAME,
true, PRIVATE);
assertThat(true, is(attributeWithListWithoutPkg.equals(
assertThat(true, is(attributeWithListWithoutPkg.contains(
PRIVATE + SPACE + LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET + SPACE
+ YANG_NAME + SEMI_COLAN + NEW_LINE)));
+ YANG_NAME)));
}
}
......
......@@ -21,9 +21,9 @@ import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
......@@ -131,7 +131,7 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getBuildTest() {
String method = getBuild(CLASS_NAME);
String method = getBuild(CLASS_NAME, false);
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 + "Default" + CLASS_NAME + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
......@@ -177,7 +177,7 @@ public final class MethodsGeneratorTest {
@Test
public void getConstructorStartTest() {
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructorStart(CLASS_NAME, pluginConfig);
String method = getConstructorStart(CLASS_NAME, pluginConfig, false);
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)));
......
......@@ -47,7 +47,7 @@ public final class YangIoUtilsTest {
private static final String CHECK1 = "check1";
private static final String PKG_INFO = "package-info.java";
private static final String PATH = "src/main/yangmodel/";
private static final String MSG = "Exception occured while creating package info file.";
private static final String MSG = "Exception occurred while creating package info file.";
/**
* Expected exceptions.
......
......@@ -31,6 +31,19 @@ module test {
}
}
choice choice1 {
case case1 {
leaf case-leaf {
type int32;
}
container case-container3 {
leaf leafs {
type int64;
}
}
}
}
augment /cont3 {
leaf leaf1 {
......@@ -39,9 +52,27 @@ module test {
}
augment /cont1/cont2 {
leaf leaf2 {
leaf-list leaf2 {
type int32;
}
}
augment /choice1 {
leaf-list leaf2 {
type int32;
}
leaf leaf1 {
type int32;
}
container case-container {
leaf leafs {
type int64;
}
}
container case-container2 {
leaf leafs {
type int64;
}
}
}
augment /test1:cont1/test1:cont2 {
......@@ -57,10 +88,25 @@ module test {
}
augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s/test2:aa {
leaf a {
leaf name {
type string;
}
leaf surname {
type string;
}
leaf-list aleaflist {
type int32;
}
container aa {
container cont1 {
}
list alist {
key "name";
leaf name {
type string;
}
leaf-list surname {
type string;
}
}
}
......
......@@ -2,9 +2,7 @@ module test {
namespace "xpath:intra:single";
prefix test ;
include test1;
include test2;
include test4;
organization "";
contact "";
......@@ -21,11 +19,5 @@ module test {
type int32;
}
}
augment /group1/cont3/cont4/cont8 {
leaf a {
type int32;
}
}
}
......
......@@ -4,8 +4,6 @@ submodule test1 {
prefix test;
}
include test4;
organization "";
contact "";
......@@ -35,13 +33,5 @@ submodule test1 {
}
}
augment /group1/cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
}
}
}
}
......
......@@ -3,8 +3,8 @@ submodule test2{
prefix test;
}
include test3;
include test1;
include test4;
organization "";
contact "";
......@@ -52,5 +52,13 @@ submodule test2{
}
}
augment /group1/cont3/cont4 {
container cont8 {
leaf leaf8 {
type int32;
}
}
}
}
......
submodule test4 {
submodule test3 {
belongs-to test {
prefix test;
}
include test2;
organization "";
contact "";
......@@ -28,10 +27,4 @@ submodule test4 {
}
}
augment /ethernet/cont11 {
leaf leaf11 {
type int32;
}
}
}
......