Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-4070] Translator of YANG union.

Change-Id: I5216687b6ea7cb6baeb3ef8e905719468370a1f4
Showing 25 changed files with 786 additions and 313 deletions
/*
* 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;
import java.util.List;
/**
* Represents the holder with type(s).
*/
public interface HasType {
/**
* Returns type list.
*
* @return type list
*/
List<YangType<?>> getTypeList();
}
......@@ -15,6 +15,8 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
......@@ -48,10 +50,11 @@ import org.onosproject.yangutils.utils.YangConstructType;
* | units | 7.3.3 | 0..1 |-string |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG typedef.
*/
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, HasType {
/**
* Default value in string, needs to be converted to the target object,
......@@ -90,10 +93,17 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
private String units;
/**
* List of YANG type, for typedef it will have single type.
* This is done to unify the code with union.
*/
private List<YangType<?>> typeList;
/**
* Creates a typedef node.
*/
public YangTypeDef() {
super(YangNodeType.TYPEDEF_NODE);
typeList = new LinkedList<>();
}
/**
......@@ -180,7 +190,10 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
* @return the data type
*/
public YangType<?> getTypeDefBaseType() {
return dataType;
if (!(getTypeList().isEmpty())) {
return getTypeList().get(0);
}
return null;
}
/**
......@@ -189,7 +202,7 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
* @param dataType the data type
*/
public void setDataType(YangType<?> dataType) {
this.dataType = dataType;
getTypeList().add(0, dataType);
}
/**
......@@ -259,4 +272,9 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
public void setName(String name) {
this.name = name;
}
@Override
public List<YangType<?>> getTypeList() {
return typeList;
}
}
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
......@@ -48,7 +47,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG union.
*/
public class YangUnion extends YangNode implements Parsable {
public class YangUnion extends YangNode implements Parsable, HasType {
// List of YANG type.
private List<YangType<?>> typeList;
......@@ -68,11 +67,7 @@ public class YangUnion extends YangNode implements Parsable {
childUnionNumber = 1;
}
/**
* Returns list of YANG type.
*
* @return the list of YANG type
*/
@Override
public List<YangType<?>> getTypeList() {
return typeList;
}
......@@ -105,11 +100,11 @@ public class YangUnion extends YangNode implements Parsable {
}
/**
* Add YANG type to type list.
* Adds YANG type to type list.
*
* @param yangType YANG type to be added to list
* @throws DataModelException union member type must not be one of the
* built-in types "empty" or "leafref"
* built-in types "empty" or "leafref"
*/
public void addType(YangType<?> yangType) throws DataModelException {
if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) {
......@@ -144,11 +139,21 @@ public class YangUnion extends YangNode implements Parsable {
return YangConstructType.UNION_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
//TODO: implement the method.
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
//TODO: implement the method.
......
......@@ -25,6 +25,7 @@ import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangRpc;
......@@ -40,6 +41,7 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaList;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
......@@ -53,7 +55,7 @@ import org.onosproject.yangutils.translator.exception.TranslatorException;
public final class YangDataModelFactory {
/**
* Utility class, hence private to prevent creating objects.
* Creates a YANG data model factory object.
*/
private YangDataModelFactory() {
}
......@@ -224,7 +226,25 @@ public final class YangDataModelFactory {
* Returns based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
* generated
* generated
* @return the corresponding inherited node based on the target language
*/
public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
switch (targetLanguage) {
case JAVA_GENERATION: {
return new YangJavaUnion();
}
default: {
throw new TranslatorException("Only YANG to Java is supported.");
}
}
}
/**
* Returns based on the target language generate the inherited data model node.
*
* @param targetLanguage target language in which YANG mapping needs to be
* generated
* @return the corresponding inherited node based on the target language
*/
public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
......
......@@ -146,7 +146,7 @@ public final class TypeListener {
* in resolution list.
*/
if (yangDataTypes == YangDataTypes.DERIVED) {
// Parent YANG node of leaf to be added in resolution information.
// Parent YANG node of leaf list to be added in resolution information.
Parsable leafListData = listener.getParsedDataStack().pop();
Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
listener.getParsedDataStack().push(leafListData);
......@@ -181,6 +181,26 @@ public final class TypeListener {
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
/*
* If data type is derived, resolution information to be added
* in resolution list.
*/
if (yangDataTypes == YangDataTypes.DERIVED) {
// Get the prefix information
String prefix = ((YangType<?>) type).getPrefix();
// Create empty derived info and attach it to type extended info.
YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
// Add resolution information to the list
YangResolutionInfo resolutionInfo =
new YangResolutionInfo<YangType>(type, (YangNode) unionNode, errorLine, errorPosition);
addToResolutionList(resolutionInfo, ctx);
}
break;
case TYPEDEF_DATA:
/* Prepare the base type info and set in derived type */
......@@ -244,7 +264,7 @@ public final class TypeListener {
* @param ctx context object of the grammar rule
*/
private static void addToResolutionList(YangResolutionInfo<YangType> resolutionInfo,
GeneratedYangParser.TypeStatementContext ctx) {
GeneratedYangParser.TypeStatementContext ctx) {
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
......
......@@ -53,6 +53,8 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangUnionNode;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
......@@ -96,7 +98,7 @@ public final class UnionListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, UNION_DATA, "", ENTRY);
if (listener.getParsedDataStack().peek() instanceof YangType) {
YangUnion unionNode = new YangUnion();
YangUnion unionNode = getYangUnionNode(JAVA_GENERATION);
Parsable typeData = listener.getParsedDataStack().pop();
// Check for stack to be non empty.
......
......@@ -22,12 +22,6 @@ package org.onosproject.yangutils.translator.tojava;
public final class GeneratedJavaFileType {
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
}
/**
* Interface file.
*/
public static final int INTERFACE_MASK = 1;
......@@ -56,4 +50,15 @@ public final class GeneratedJavaFileType {
* Java class corresponding to typedef.
*/
public static final int GENERATE_TYPEDEF_CLASS = 16;
/**
* Java class corresponding to union.
*/
public static final int GENERATE_UNION_CLASS = 32;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
}
}
......
......@@ -22,53 +22,68 @@ package org.onosproject.yangutils.translator.tojava;
public final class GeneratedTempFileType {
/**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
}
/**
* attributes definition temporary file.
* Attributes definition temporary file.
*/
public static final int ATTRIBUTES_MASK = 1;
/**
* getter methods for interface.
* Getter methods for interface.
*/
public static final int GETTER_FOR_INTERFACE_MASK = 2;
/**
* getter methods for class.
* Getter methods for class.
*/
public static final int GETTER_FOR_CLASS_MASK = 4;
/**
* setter methods for interface.
* Setter methods for interface.
*/
public static final int SETTER_FOR_INTERFACE_MASK = 8;
/**
* setter methods for class.
* Setter methods for class.
*/
public static final int SETTER_FOR_CLASS_MASK = 16;
/**
* constructor method of class.
* Constructor method of class.
*/
public static final int CONSTRUCTOR_IMPL_MASK = 32;
/**
* hash code implementation of class.
* Hash code implementation of class.
*/
public static final int HASH_CODE_IMPL_MASK = 64;
/**
* equals implementation of class.
* Equals implementation of class.
*/
public static final int EQUALS_IMPL_MASK = 128;
/**
* to string implementation of class.
* To string implementation of class.
*/
public static final int TO_STRING_IMPL_MASK = 256;
/**
* Of string implementation of class.
*/
public static final int OF_STRING_IMPL_MASK = 512;
/**
* Constructor for type class like typedef, union.
*/
public static final int CONSTRUCTOR_FOR_TYPE_MASK = 1024;
/**
* From string implementation of class.
*/
public static final int UNION_FROM_STRING_IMPL_MASK = 2048;
/**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
}
}
......
......@@ -21,8 +21,9 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfAttribute;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfLeafAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
/**
......@@ -65,9 +66,9 @@ public final class JavaAttributeInfo {
/**
* Creates object of java attribute info.
*
* @param attrType YANG type
* @param name attribute name
* @param isListAttr is list attribute
* @param attrType YANG type
* @param name attribute name
* @param isListAttr is list attribute
* @param isQualifiedName is qualified name
*/
public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) {
......@@ -78,6 +79,51 @@ public final class JavaAttributeInfo {
}
/**
* Creates an attribute info object corresponding to the passed type's attribute
* information and return it.
*
* @param curNode current data model node for which the java file is being generated
* @param referredTypesAttrInfo attribute of referred type
* @return JavaAttributeInfo attribute details required to add in temporary files
*/
public static JavaAttributeInfo getFromStringAttributeInfo(YangNode curNode,
JavaAttributeInfo referredTypesAttrInfo) {
JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(referredTypesAttrInfo);
/*
* Create a new java attribute info with qualified information of
* wrapper classes.
*/
return getAttributeInfoForTheData(qualifiedInfoOfFromString, referredTypesAttrInfo.getAttributeName(),
referredTypesAttrInfo.getAttributeType(), curNode, false);
}
/**
* Creates an attribute info object corresponding to the passed type attribute
* information and return it.
*
* @param curNode current data model node for which the java file is being
* generated
* @param attributeType leaf data type
* @param attributeName leaf name
* @param isListAttribute is the current added attribute needs to be a list
* @return AttributeInfo attribute details required to add in temporary
* files
*/
public static JavaAttributeInfo getAttributeInfoOfType(YangNode curNode,
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfAttribute(curNode,
attributeType, attributeName, isListAttribute);
return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
}
/**
* Returns the data type info of attribute.
*
* @return the data type info of attribute
......@@ -144,7 +190,7 @@ public final class JavaAttributeInfo {
* manner.
*
* @return the if the added attribute has to be accessed in a fully
* qualified manner.
* qualified manner.
*/
public boolean isQualifiedName() {
return isQualifiedName;
......@@ -155,7 +201,7 @@ public final class JavaAttributeInfo {
* manner.
*
* @param isQualified if the added attribute has to be accessed in a fully
* qualified manner
* qualified manner
*/
public void setIsQualifiedAccess(boolean isQualified) {
isQualifiedName = isQualified;
......@@ -184,23 +230,23 @@ public final class JavaAttributeInfo {
* Creates an attribute info object corresponding to the passed leaf
* information and return it.
*
* @param curNode current data model node for which the java file is being
* generated
* @param attributeType leaf data type
* @param attributeName leaf name
* @param curNode current data model node for which the java file is being
* generated
* @param attributeType leaf data type
* @param attributeName leaf name
* @param isListAttribute is the current added attribute needs to be a list
* @return AttributeInfo attribute details required to add in temporary
* files
* files
*/
public static JavaAttributeInfo getAttributeInfoOfLeaf(YangNode curNode,
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfAttribute(curNode,
attributeType, attributeName, isListAttribute);
return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
......@@ -210,12 +256,12 @@ public final class JavaAttributeInfo {
* Creates an attribute info object corresponding to a data model node and
* return it.
*
* @param curNode current data model node for which the java code generation
* is being handled
* @param curNode current data model node for which the java code generation
* is being handled
* @param parentNode parent node in which the current node is an attribute
* @param isListNode is the current added attribute needs to be a list
* @return AttributeInfo attribute details required to add in temporary
* files
* files
*/
public static JavaAttributeInfo getCurNodeAsAttributeInParent(
YangNode curNode, YangNode parentNode, boolean isListNode) {
......@@ -233,43 +279,18 @@ public final class JavaAttributeInfo {
}
/**
* Creates an attribute info object corresponding to the passed type def attribute
* information and return it.
*
* @param curNode current data model node for which the java file is being
* generated
* @param attributeType leaf data type
* @param attributeName leaf name
* @param isListAttribute is the current added attribute needs to be a list
* @return AttributeInfo attribute details required to add in temporary
* files
*/
public static JavaAttributeInfo getAttributeInfoOfTypeDef(YangNode curNode,
YangType<?> attributeType, String attributeName,
boolean isListAttribute) {
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
attributeType, attributeName, isListAttribute);
return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
}
/**
* Returns java attribute info.
*
* @param importInfo java qualified type info
* @param attributeName attribute name
* @param attributeType attribute type
* @param curNode current YANG node
* @param importInfo java qualified type info
* @param attributeName attribute name
* @param attributeType attribute type
* @param curNode current YANG node
* @param isListAttribute is list attribute
* @return java attribute info.
*/
private static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo, String attributeName,
YangType<?> attributeType, YangNode curNode, boolean isListAttribute) {
YangType<?> attributeType, YangNode curNode,
boolean isListAttribute) {
JavaAttributeInfo newAttr = new JavaAttributeInfo();
newAttr.setImportInfo(importInfo);
......
......@@ -17,14 +17,15 @@
package org.onosproject.yangutils.translator.tojava;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import com.google.common.base.MoreObjects;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportClass;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getJavaImportPackage;
/**
* Represents the information about individual imports in the generated file.
*/
......@@ -86,18 +87,18 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* Returns the import info for an attribute, which needs to be used for code
* generation for import or for qualified access.
*
* @param curNode current data model node for which the java file is being
* generated
* @param attrType type of attribute being added, it will be null, when the
* child class is added as an attribute
* @param curNode current data model node for which the java file is being
* generated
* @param attrType type of attribute being added, it will be null, when the
* child class is added as an attribute
* @param attributeName name of the attribute being added, it will used in
* import info for child class
* @param isListAttr is the added attribute going to be used as a list
* import info for child class
* @param isListAttr is the added attribute going to be used as a list
* @return return the import info for this attribute
*/
public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfLeafAttribute(YangNode curNode,
YangType<?> attrType, String attributeName,
boolean isListAttr) {
public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfAttribute(YangNode curNode,
YangType<?> attrType, String attributeName,
boolean isListAttr) {
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
......@@ -139,15 +140,15 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* Returns the import info for an attribute, which needs to be used for code
* generation for import or for qualified access.
*
* @param curNode current data model node for which the java file is being
* generated
* @param curNode current data model node for which the java file is being
* generated
* @param attributeName name of the attribute being added, it will used in
* import info for child class
* @param isListAttr is the added attribute going to be used as a list
* import info for child class
* @param isListAttr is the added attribute going to be used as a list
* @return return the import info for this attribute
*/
public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfCurNode(YangNode curNode,
String attributeName, boolean isListAttr) {
String attributeName, boolean isListAttr) {
JavaQualifiedTypeInfo importInfo = new JavaQualifiedTypeInfo();
......@@ -168,16 +169,35 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
}
/**
* Get the java qualified type information for the wrapper classes.
*
* @param referredTypesAttrInfo attribute of referred type
* @return return the import info for this attribute
*/
public static JavaQualifiedTypeInfo getQualifiedInfoOfFromString(JavaAttributeInfo referredTypesAttrInfo) {
/*
* Get the java qualified type information for the wrapper classes and
* set it in new java attribute information.
*/
JavaQualifiedTypeInfo qualifiedInfoOfFromString = new JavaQualifiedTypeInfo();
qualifiedInfoOfFromString.setClassInfo(
getJavaImportClass(referredTypesAttrInfo.getAttributeType(), true));
qualifiedInfoOfFromString.setPkgInfo(
getJavaImportPackage(referredTypesAttrInfo.getAttributeType(), true, null));
return qualifiedInfoOfFromString;
}
/**
* Returns if the attribute needs to be accessed in a qualified manner or not,
* if it needs to be imported, then the same needs to be done.
*
* @param curNode current cache of the data model node for which java file
* is bing generated
* @param curNode current cache of the data model node for which java file
* is bing generated
* @param importInfo import info for the current attribute being added
* @return status of the qualified access to the attribute
*/
public static boolean getIsQualifiedAccessOrAddToImportList(YangNode curNode,
JavaQualifiedTypeInfo importInfo) {
JavaQualifiedTypeInfo importInfo) {
boolean isImportPkgEqualCurNodePkg;
if (!(curNode instanceof HasJavaFileInfo)) {
......@@ -229,10 +249,10 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
* Checks if the import info is same as the package of the current generated
* java file.
*
* @param curNode Java identifier of the current data model node
* @param curNode Java identifier of the current data model node
* @param importInfo import info for an attribute
* @return true if the import info is same as the current nodes package
* false otherwise
* false otherwise
*/
public static boolean isImportPkgEqualCurNodePkg(
YangNode curNode, JavaQualifiedTypeInfo importInfo) {
......
......@@ -16,12 +16,8 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
......@@ -29,17 +25,12 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType;
/**
* Represents type define information extended to support java code generation.
*/
public class YangJavaTypeDef extends YangTypeDef
implements JavaCodeGenerator, HasJavaFileInfo, HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaTypeDef extends YangTypeDef implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -106,7 +97,7 @@ public class YangJavaTypeDef extends YangTypeDef
* Sets the data of java imports to be included in generated file.
*
* @param javaImportData data of java imports to be included in generated
* file
* file
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
......@@ -142,23 +133,7 @@ public class YangJavaTypeDef extends YangTypeDef
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName(), yangPlugin.getConflictResolver())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addTypeDefAttributeToTempFiles(this);
generateCodeOfType(this, yangPlugin, false);
}
/**
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfType;
/**
* Represents union information extended to support java code generation.
*/
public class YangJavaUnion extends YangUnion implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
*/
private JavaFileInfo javaFileInfo;
/**
* Contains information of the imports to be inserted in the java file
* generated.
*/
private JavaImportData javaImportData;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
*/
private TempJavaCodeFragmentFiles tempFileHandle;
/**
* Creates an instance of YANG java union.
*/
public YangJavaUnion() {
super();
setJavaFileInfo(new JavaFileInfo());
setJavaImportData(new JavaImportData());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_UNION_CLASS);
}
/**
* Returns the generated java file information.
*
* @return generated java file information
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new RuntimeException("Missing java info in java datamodel node");
}
return javaFileInfo;
}
/**
* Sets the java file info object.
*
* @param javaInfo java file info object
*/
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
javaFileInfo = javaInfo;
}
/**
* Returns the data of java imports to be included in generated file.
*
* @return data of java imports to be included in generated file
*/
@Override
public JavaImportData getJavaImportData() {
return javaImportData;
}
/**
* Sets the data of java imports to be included in generated file.
*
* @param javaImportData data of java imports to be included in generated
* file
*/
@Override
public void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
/**
* Returns the temporary file handle.
*
* @return temporary file handle
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
if (tempFileHandle == null) {
throw new RuntimeException("Missing temp file hand for current node "
+ getJavaFileInfo().getJavaName());
}
return tempFileHandle;
}
/**
* Sets temporary file handle.
*
* @param fileHandle temporary file handle
*/
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempFileHandle = fileHandle;
}
/**
* Prepare the information for java code generation corresponding to YANG
* union info.
*
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException {
generateCodeOfType(this, yangPlugin, false);
}
/**
* Creates a java file using the YANG union info.
*
* @throws IOException IO operations fails
*/
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this);
}
}
......@@ -21,10 +21,12 @@ import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnion;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
......@@ -33,15 +35,23 @@ 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.BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.OF;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
/**
......@@ -94,9 +104,56 @@ public final class AttributesJavaDataType {
}
/**
* 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) {
YangDataTypes type = yangType.getDataType();
switch (type) {
case INT8:
return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
case INT16:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case INT32:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case INT64:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT8:
return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
case UINT16:
return INTEGER_WRAPPER + PERIOD + PARSE_INT;
case UINT32:
return LONG_WRAPPER + PERIOD + PARSE_LONG;
case UINT64:
return NEW + SPACE + BIG_INTEGER;
case DECIMAL64:
//TODO: DECIMAL64.
case STRING:
return EMPTY_STRING;
case BOOLEAN:
return BOOLEAN_DATA_TYPE;
case ENUMERATION:
//TODO:ENUMERATION.
case BITS:
//TODO:BITS
case BINARY:
//TODO:BINARY
case DERIVED:
return targetDataType + PERIOD + OF;
default:
throw new TranslatorException("given data type is not supported.");
}
}
/**
* Returns java import class.
*
* @param yangType YANG type
* @param yangType YANG type
* @param isListAttr if the attribute need to be a list
* @return java import class
*/
......@@ -141,13 +198,14 @@ public final class AttributesJavaDataType {
case EMPTY:
return BOOLEAN_WRAPPER;
case UNION:
//TODO:UNION
return getCaptialCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
null));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
case DERIVED:
return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
default:
throw new TranslatorException("given data type is not supported.");
return null;
}
} else {
switch (type) {
......@@ -170,7 +228,8 @@ public final class AttributesJavaDataType {
case EMPTY:
//TODO:EMPTY
case UNION:
//TODO:UNION
return getCaptialCase(getCamelCase(((YangJavaUnion) yangType.getDataTypeExtendedInfo()).getName(),
null));
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
case DERIVED:
......@@ -184,9 +243,9 @@ public final class AttributesJavaDataType {
/**
* Returns java import package.
*
* @param yangType YANG type
* @param yangType YANG type
* @param isListAttr if the attribute is of list type
* @param classInfo java import class info
* @param classInfo java import class info
* @return java import package
*/
public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, String classInfo) {
......@@ -222,13 +281,13 @@ public final class AttributesJavaDataType {
case EMPTY:
//TODO:EMPTY
case UNION:
//TODO:UNION
return getUnionPackage(yangType);
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
case DERIVED:
return getTypDefsPackage(yangType);
default:
throw new TranslatorException("given data type is not supported.");
return null;
}
} else {
switch (type) {
......@@ -251,7 +310,7 @@ public final class AttributesJavaDataType {
case EMPTY:
//TODO:EMPTY
case UNION:
//TODO:UNION
return getUnionPackage(yangType);
case INSTANCE_IDENTIFIER:
//TODO:INSTANCE_IDENTIFIER
case DERIVED:
......@@ -286,6 +345,25 @@ public final class AttributesJavaDataType {
}
/**
* Returns java package for union node.
*
* @param type YANG type
* @return java package for union node
*/
private static String getUnionPackage(YangType<?> type) {
if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) {
throw new TranslatorException("type should have been union.");
}
YangJavaUnion union = (YangJavaUnion) type.getDataTypeExtendedInfo();
if (union.getJavaFileInfo().getPackage() == null) {
return getPackageFromParent(union.getParent());
}
return union.getJavaFileInfo().getPackage();
}
/**
* Returns package from parent node.
*
* @param parent parent YANG node
......@@ -293,7 +371,7 @@ public final class AttributesJavaDataType {
*/
private static String getPackageFromParent(YangNode parent) {
if (!(parent instanceof HasJavaFileInfo)) {
throw new TranslatorException("Invalid child node is being processed.");
throw new TranslatorException("invalid child node is being processed.");
}
JavaFileInfo parentInfo = ((HasJavaFileInfo) parent).getJavaFileInfo();
return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.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.utils.JavaFileGenerator.getExtendsList;
......@@ -54,7 +55,7 @@ public final class ClassDefinitionGenerator {
* / interface definition start.
*
* @param genFileTypes generated file type
* @param yangName class name
* @param yangName class name
* @return class definition
*/
public static String generateClassDefinition(int genFileTypes, String yangName) {
......@@ -64,20 +65,17 @@ public final class ClassDefinitionGenerator {
* class / interface definition start.
*/
if ((genFileTypes & INTERFACE_MASK) != 0) {
return getInterfaceDefinition(yangName);
} else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) {
return getBuilderClassDefinition(yangName);
} else if ((genFileTypes & IMPL_CLASS_MASK) != 0) {
return getImplClassDefinition(yangName);
} else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) {
return getBuilderInterfaceDefinition(yangName);
} else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) {
return getTypeDefClassDefinition(yangName);
return getTypeClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) {
return getTypeClassDefinition(yangName);
}
return null;
}
......@@ -105,7 +103,7 @@ public final class ClassDefinitionGenerator {
* Returns builder interface file class definition.
*
* @param yangName java class name, corresponding to which the builder class
* is being generated
* is being generated
* @return definition
*/
private static String getBuilderInterfaceDefinition(String yangName) {
......@@ -135,12 +133,12 @@ public final class ClassDefinitionGenerator {
}
/**
* Returns typeDef file class definition.
* Returns type file class definition.
*
* @param yangName file name
* @return definition
*/
private static String getTypeDefClassDefinition(String yangName) {
private static String getTypeClassDefinition(String yangName) {
return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
}
......
......@@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
......@@ -30,17 +29,21 @@ 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.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.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;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_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.OF_STRING_IMPL_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;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.UNION_FROM_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
......@@ -49,11 +52,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
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;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
......@@ -70,10 +73,10 @@ public final class JavaFileGeneratorUtils {
/**
* Returns a file object for generated file.
*
* @param fileName file name
* @param filePath file package path
* @param fileName file name
* @param filePath file package path
* @param extension file extension
* @param handle cached file handle
* @param handle cached file handle
* @return file object
*/
public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) {
......@@ -85,7 +88,7 @@ public final class JavaFileGeneratorUtils {
* Returns data stored in temporary files.
*
* @param generatedTempFiles temporary file types
* @param curNode current YANG node
* @param curNode current YANG node
* @return data stored in temporary files
* @throws IOException when failed to get the data from temporary file handle
*/
......@@ -121,6 +124,16 @@ public final class JavaFileGeneratorUtils {
} else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
return tempJavaCodeFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getToStringImplTempFileHandle());
} else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
return tempJavaCodeFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles
.getConstructorForTypeTempFileHandle());
} else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
return tempJavaCodeFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getOfStringImplTempFileHandle());
} else if ((generatedTempFiles & UNION_FROM_STRING_IMPL_MASK) != 0) {
return tempJavaCodeFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaCodeFragmentFiles.getUnionFromStringImplTempFileHandle());
}
return null;
}
......@@ -128,15 +141,15 @@ public final class JavaFileGeneratorUtils {
/**
* Initiates generation of file based on generated file type.
*
* @param file generated file
* @param file generated file
* @param className generated file class name
* @param type generated file type
* @param imports imports for the file
* @param pkg generated file package
* @param type generated file type
* @param imports imports for the file
* @param pkg generated file package
* @throws IOException when fails to generate a file
*/
public static void initiateJavaFileGeneration(File file, String className, int type, List<String> imports,
String pkg) throws IOException {
String pkg) throws IOException {
try {
file.createNewFile();
......@@ -149,42 +162,41 @@ public final class JavaFileGeneratorUtils {
/**
* Appends all the contents into a generated java file.
*
* @param file generated file
* @param fileName generated file name
* @param type generated file type
* @param pkg generated file package
* @param file generated file
* @param fileName generated file name
* @param type generated file type
* @param pkg generated file package
* @param importsList list of java imports.
* @throws IOException when fails to append contents
*/
private static void appendContents(File file, String fileName, int type, List<String> importsList,
String pkg) throws IOException {
String pkg) throws IOException {
String pkgString = parsePackageString(pkg, importsList);
if ((type & IMPL_CLASS_MASK) != 0) {
write(file, fileName, type, IMPL_CLASS);
} else if ((type & BUILDER_INTERFACE_MASK) != 0) {
write(file, fileName, type, BUILDER_INTERFACE);
} else if ((type & GENERATE_TYPEDEF_CLASS) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, IMPL_CLASS);
} else if ((type & INTERFACE_MASK) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, INTERFACE);
} else if ((type & BUILDER_CLASS_MASK) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, BUILDER_CLASS);
} else if ((type & GENERATE_UNION_CLASS) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, IMPL_CLASS);
}
}
/**
* Removes base directory path from package and generates package string for file.
*
* @param javaPkg generated java package
* @param javaPkg generated java package
* @param importsList list of imports
* @return package string
*/
......@@ -208,10 +220,11 @@ public final class JavaFileGeneratorUtils {
/**
* Appends other contents to interface, builder and typedef classes.
* for example : ONOS copyright, imports and package.
* @param file generated file
* @param pkg generated package
*
* @param file generated file
* @param pkg generated package
* @param importsList list of imports
* @throws IOException when fails to append contents.
* @throws IOException when fails to append contents
*/
private static void appendHeaderContents(File file, String pkg, List<String> importsList) throws IOException {
......@@ -234,15 +247,14 @@ public final class JavaFileGeneratorUtils {
/**
* Writes data to the specific generated file.
*
* @param file generated file
* @param fileName file name
* @param genType generated file type
* @param file generated file
* @param fileName file name
* @param genType generated file type
* @param javaDocType java doc type
* @throws IOException when fails to write into a file
*/
private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
throws IOException {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName));
}
......
......@@ -17,7 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.HasType;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
......@@ -54,7 +54,7 @@ public final class YangJavaModelUtils {
* Updates YANG java file package information.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
......@@ -72,11 +72,11 @@ public final class YangJavaModelUtils {
* Updates YANG java file package information for specified package.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPlugin YANG plugin config
* @throws IOException IO operations fails
*/
private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
String pkg)
String pkg)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCaptialCase(
......@@ -113,9 +113,11 @@ public final class YangJavaModelUtils {
if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof HasType) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addTypeInfoToTempFiles((HasType) javaCodeGeneratorInfo);
} else {
// TODO: either write a util for ENUM and UNION or, call the
// corresponding implementation in ENUM and UNION
//TODO throw exception
}
}
......@@ -123,7 +125,7 @@ public final class YangJavaModelUtils {
* Process generate code entry of YANG node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param codeGenDir code generation directory
* @param codeGenDir code generation directory
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir)
......@@ -140,12 +142,12 @@ public final class YangJavaModelUtils {
* Process generate code entry of YANG node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param isMultiInstance flag to indicate whether it's a list
* @param yangPlugin YANG plugin config
* @param isMultiInstance flag to indicate whether it's a list
* @throws IOException IO operations fails
*/
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
boolean isMultiInstance) throws IOException {
boolean isMultiInstance) throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
......@@ -172,15 +174,32 @@ public final class YangJavaModelUtils {
}
/**
* Process generate code entry of YANG type.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param isMultiInstance flag to indicate whether it's a list
* @throws IOException IO operations fails
*/
public static void generateCodeOfType(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
boolean isMultiInstance) throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
updatePackageInfo(javaCodeGeneratorInfo, yangPlugin);
generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
}
/**
* Process generate code entry of root node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param rootPkg package of the root node
* @param yangPlugin YANG plugin config
* @param rootPkg package of the root node
* @throws IOException IO operations fails
*/
public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
String rootPkg) throws IOException {
String rootPkg) throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
......
......@@ -34,18 +34,18 @@ public final class UtilConstants {
/**
* JavaDocs for impl class.
*/
public static final String IMPL_CLASS_JAVA_DOC = " * Reperesents the implementation of ";
public static final String IMPL_CLASS_JAVA_DOC = " * Represents the implementation of ";
/**
* JavaDocs for builder class.
*/
public static final String BUILDER_CLASS_JAVA_DOC = " * Reperesents the builder implementation of ";
public static final String BUILDER_CLASS_JAVA_DOC = " * Represents the builder implementation of ";
/**
* JavaDocs for interface class.
*/
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which Reperesents the"
+ " functionalities of ";
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the"
+ " functionality of ";
/**
* JavaDocs for builder interface class.
......@@ -148,6 +148,31 @@ public final class UtilConstants {
public static final String PERIOD = ".";
/**
* Static attribute for parse byte.
*/
public static final String PARSE_BYTE = "parseByte";
/**
* Static attribute for parse short.
*/
public static final String PARSE_SHORT = "parseShort";
/**
* Static attribute for parse int.
*/
public static final String PARSE_INT = "parseInt";
/**
* Static attribute for parse long.
*/
public static final String PARSE_LONG = "parseLong";
/**
* Static attribute for omit null value.
*/
public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()";
/**
* Static attribute for colan.
*/
public static final String COLAN = ":";
......@@ -173,9 +198,9 @@ public final class UtilConstants {
public static final String SPACE = " ";
/**
* Static attribute for tab.
* Static attribute for input string.
*/
public static final String TAB = "\t";
public static final String INPUT = "input";
/**
* Static attribute for new line.
......@@ -223,6 +248,11 @@ public final class UtilConstants {
public static final String ADD_STRING = "add";
/**
* Static attribute for from syntax.
*/
public static final String FROM_STRING_METHOD_NAME = "fromString";
/**
* Static attribute for check not null syntax.
*/
public static final String CHECK_NOT_NULL_STRING = "checkNotNull";
......@@ -333,14 +363,14 @@ public final class UtilConstants {
public static final String DIAMOND_CLOSE_BRACKET = ">";
/**
* Static attribute for square open bracket syntax.
* Static attribute for exception syntax.
*/
public static final String SQUARE_OPEN_BRACKET = "[";
public static final String EXCEPTION = "Exception";
/**
* Static attribute for square close bracket syntax.
* Static attribute for exception variable syntax.
*/
public static final String SQUARE_CLOSE_BRACKET = "]";
public static final String EXCEPTION_VAR = "e";
/**
* Static attribute for open parenthesis syntax.
......@@ -348,6 +378,21 @@ public final class UtilConstants {
public static final String OPEN_PARENTHESIS = "(";
/**
* Static attribute for clear syntax.
*/
public static final String CLEAR = "clear";
/**
* Static attribute for temp val syntax.
*/
public static final String TMP_VAL = "tmpVal";
/**
* From string parameter name.
*/
public static final String FROM_STRING_PARAM_NAME = "valInString";
/**
* Static attribute for close parenthesis syntax.
*/
public static final String CLOSE_PARENTHESIS = ")";
......@@ -378,6 +423,21 @@ public final class UtilConstants {
public static final String FOUR_SPACE_INDENTATION = " ";
/**
* Static attribute for not syntax.
*/
public static final String NOT = "!";
/**
* Static attribute for try syntax.
*/
public static final String TRY = "try";
/**
* Static attribute for catch syntax.
*/
public static final String CATCH = "catch";
/**
* Static attribute for eight space indentation.
*/
public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
......@@ -518,14 +578,9 @@ public final class UtilConstants {
public static final String LONG_WRAPPER = "Long";
/**
* Float java built in wrapper type.
*/
public static final String FLOAT_WRAPPER = "Float";
/**
* Double java built in wrapper type.
* YangUint64 java built in wrapper type.
*/
public static final String DOUBLE_WRAPPER = "Double";
public static final String YANG_UINT64 = "YangUint64";
/**
* List of keywords in java, this is used for checking if the input does not contain these keywords.
......@@ -733,92 +788,12 @@ public final class UtilConstants {
public static final String AUGMENTED_INFO = "AugmentedInfo";
/**
* Static attribute for abstract collection.
*/
public static final String ABSTRACT_COLLECTION = "AbstractCollection";
/**
* Static attribute for list.
*/
public static final String LIST = "List";
/**
* Static attribute for linked list.
*/
public static final String LINKED_LIST = "LinkedList";
/**
* Static attribute for array list.
*/
public static final String ARRAY_LIST = "ArrayList";
/**
* Static attribute for abstract list.
*/
public static final String ABSTRACT_LIST = "AbstractList";
/**
* Static attribute for abstract sequential list.
*/
public static final String ABSTRACT_SEQUENTAIL_LIST = "AbstractSequentialList";
/**
* Static attribute for set.
*/
public static final String SET = "Set";
/**
* Static attribute for hash set.
*/
public static final String HASH_SET = "HashSet";
/**
* Static attribute for abstract set.
*/
public static final String ABSTRACT_SET = "AbstractSet";
/**
* Static attribute for linked has set.
*/
public static final String LINKED_HASH_SET = "LinkedHashSet";
/**
* Static attribute for tree set.
*/
public static final String TREE_SET = "TreeSet";
/**
* Static attribute for map.
*/
public static final String MAP = "Map";
/**
* Static attribute for abstract map.
*/
public static final String ABSTRACT_MAP = "AbstractMap";
/**
* Static attribute for hash map.
*/
public static final String HASH_MAP = "HashMap";
/**
* Static attribute for tree map.
*/
public static final String TREE_MAP = "TreeMap";
/**
* Static attribute for concurrent map.
*/
public static final String CONCURRENT_MAP = "ConcurrentMap";
/**
* Static attribute for eventually consistent map.
*/
public static final String EVENTUALLY_CONSISTENT_MAP = "EventuallyConsitentMap";
/**
* Static attribute for stack syntax.
*/
public static final String STACK = "stack";
}
......
......@@ -23,8 +23,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_D
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.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_BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
......@@ -45,6 +48,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.OF;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
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;
/**
......@@ -104,11 +108,6 @@ public final class JavaDocGen {
TYPE_DEF_SETTER_METHOD,
/**
* For type def's constructor.
*/
TYPE_DEF_CONSTRUCTOR,
/**
* For of method.
*/
OF_METHOD,
......@@ -124,6 +123,16 @@ public final class JavaDocGen {
CONSTRUCTOR,
/**
* For union's from method.
*/
UNION_FROM_METHOD,
/**
* For type constructor.
*/
TYPE_CONSTRUCTOR,
/**
* For build.
*/
BUILD_METHOD
......@@ -132,8 +141,8 @@ public final class JavaDocGen {
/**
* Returns java docs.
*
* @param type java doc type
* @param name name of the YangNode
* @param type java doc type
* @param name name of the YangNode
* @param isList is list attribute
* @return javadocs.
*/
......@@ -155,8 +164,6 @@ public final class JavaDocGen {
javaDoc = generateForGetters(name, isList);
} else if (type.equals(JavaDocType.TYPE_DEF_SETTER_METHOD)) {
javaDoc = generateForTypeDefSetter(name);
} else if (type.equals(JavaDocType.TYPE_DEF_CONSTRUCTOR)) {
javaDoc = generateForTypeDefConstructor(name);
} else if (type.equals(JavaDocType.SETTER_METHOD)) {
javaDoc = generateForSetters(name, isList);
} else if (type.equals(JavaDocType.OF_METHOD)) {
......@@ -165,6 +172,10 @@ public final class JavaDocGen {
javaDoc = generateForDefaultConstructors(name);
} else if (type.equals(JavaDocType.BUILD_METHOD)) {
javaDoc = generateForBuild(name);
} else if (type.equals(JavaDocType.TYPE_CONSTRUCTOR)) {
javaDoc = generateForTypeConstructor(name);
} else if (type.equals(JavaDocType.UNION_FROM_METHOD)) {
javaDoc = generateForUnionFrom(name);
} else {
javaDoc = generateForConstructors(name);
}
......@@ -175,7 +186,7 @@ public final class JavaDocGen {
* Generate javaDocs for getter method.
*
* @param attribute attribute
* @param isList is list attribute
* @param isList is list attribute
* @return javaDocs
*/
private static String generateForGetters(String attribute, boolean isList) {
......@@ -198,7 +209,7 @@ public final class JavaDocGen {
* Generates javaDocs for setter method.
*
* @param attribute attribute
* @param isList is list attribute
* @param isList is list attribute
* @return javaDocs
*/
private static String generateForSetters(String attribute, boolean isList) {
......@@ -232,6 +243,22 @@ public final class JavaDocGen {
}
/**
* Generates javaDocs for from method.
*
* @param attribute attribute
* @return javaDocs
*/
private static String generateForUnionFrom(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
+ attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD
+ NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
+ FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
}
/**
* Generates javaDocs for typedef setter method.
*
* @param attribute attribute
......@@ -347,4 +374,18 @@ public final class JavaDocGen {
+ JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_END_LINE;
}
/**
* Generates javaDocs for type constructor.
*
* @param attribute attribute string
* @return javaDocs for type constructor
*/
private static String generateForTypeConstructor(String attribute) {
return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
}
}
......
......@@ -43,7 +43,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForTypeDefClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeDefConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
......@@ -113,12 +113,12 @@ public final class MethodsGeneratorTest {
}
/**
* Unit test case for checking the parse builder and typedef constructor.
* Unit test case for checking the parse builder and type constructor.
*/
@Test
public void getTypeDefConstructorTest() {
public void getTypeConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String test = getTypeDefConstructor(testAttr, CLASS_NAME);
String test = getTypeConstructorStringAndJavaDoc(testAttr, CLASS_NAME);
assertThat(true, is(test.contains(PUBLIC + SPACE + CLASS_NAME + OPEN_PARENTHESIS)));
}
......@@ -178,7 +178,7 @@ public final class MethodsGeneratorTest {
}
/**
* Test case for quals method.
* Test case for equals method.
*/
@Test
public void getEqualsMethodTest() {
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
/**
* Unit tests for union translator.
*/
public final class UnionTranslatorTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks union translation should not result in any exception.
*/
@Test
public void processUnionTranslator() throws IOException, ParserException {
clean("src/test/org/onosproject/yang");
YangNode node = manager.getDataModel("src/test/resources/UnionTranslator.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile");
generateJavaCode(node, yangPluginConfig);
clean("target/UnionTestGenFile");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......@@ -56,7 +56,7 @@ public final class JavaDocGenTest {
@Test
public void builderClassGenerationTest() {
String builderClassJavaDoc = getJavaDoc(BUILDER_CLASS, TEST_NAME, false);
assertThat(true, is(builderClassJavaDoc.contains("Reperesents the builder implementation of")
assertThat(true, is(builderClassJavaDoc.contains("Represents the builder implementation of")
&& builderClassJavaDoc.contains(END_STRING)));
}
......@@ -138,7 +138,7 @@ public final class JavaDocGenTest {
public void implClassGenerationTest() {
String implClassJavaDoc = getJavaDoc(IMPL_CLASS, TEST_NAME, false);
assertThat(true,
is(implClassJavaDoc.contains("Reperesents the implementation of")
is(implClassJavaDoc.contains("Represents the implementation of")
&& implClassJavaDoc.contains(END_STRING)));
}
......@@ -149,7 +149,7 @@ public final class JavaDocGenTest {
public void interfaceGenerationTest() {
String interfaceJavaDoc = getJavaDoc(INTERFACE, TEST_NAME, false);
assertThat(true,
is(interfaceJavaDoc.contains("Abstraction of an entity which Reperesents the functionalities of")
is(interfaceJavaDoc.contains("Abstraction of an entity which represents the functionality of")
&& interfaceJavaDoc.contains(END_STRING)));
}
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container valid {
leaf invalid-interval {
type union {
type int32;
type int8;
}
}
}
}
\ No newline at end of file