mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-19 19:32:05 +02:00
[ONOS-4286],[ONOS-3911] YANG typedef and YANG augment
translator implementation. Change-Id: I3e21d1cb52bcb90b935b672eee42b836c21f448b
This commit is contained in:
parent
7445371c25
commit
cc1cdaba24
@ -17,11 +17,13 @@
|
||||
package org.onosproject.yangutils.parser.impl.listeners;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangAugment;
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.datamodel.YangModule;
|
||||
import org.onosproject.yangutils.datamodel.YangSubModule;
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
|
||||
import org.onosproject.yangutils.datamodel.YangSubModule;
|
||||
import org.onosproject.yangutils.datamodel.YangUses;
|
||||
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
|
||||
import org.onosproject.yangutils.parser.Parsable;
|
||||
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
|
||||
@ -35,21 +37,22 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
|
||||
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.DATA_DEF_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
|
||||
import static org.onosproject.yangutils.utils.YangConstructType.WHEN_DATA;
|
||||
|
||||
/*
|
||||
* Reference: RFC6020 and YANG ANTLR Grammar
|
||||
@ -73,11 +76,13 @@ import static org.onosproject.yangutils.utils.YangConstructType.CASE_DATA;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements listener based call back function corresponding to the "augment"
|
||||
* Represents listener based call back function corresponding to the "augment"
|
||||
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
|
||||
*/
|
||||
public final class AugmentListener {
|
||||
|
||||
private static final String AUGMENTED = "Augmented";
|
||||
|
||||
/**
|
||||
* Creates a new augment listener.
|
||||
*/
|
||||
@ -110,11 +115,12 @@ public final class AugmentListener {
|
||||
detectCollidingChildUtil(listener, line, charPositionInLine, "", AUGMENT_DATA);
|
||||
|
||||
Parsable curData = listener.getParsedDataStack().peek();
|
||||
if (curData instanceof YangModule || curData instanceof YangSubModule) {
|
||||
if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) {
|
||||
|
||||
YangNode curNode = (YangNode) curData;
|
||||
YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION);
|
||||
yangAugment.setTargetNode(targetNodes);
|
||||
yangAugment.setName(getValidNameForAugment(targetNodes));
|
||||
try {
|
||||
curNode.addChild(yangAugment);
|
||||
} catch (DataModelException e) {
|
||||
@ -163,4 +169,30 @@ public final class AugmentListener {
|
||||
validateMutuallyExclusiveChilds(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(),
|
||||
CASE_DATA, AUGMENT_DATA, ctx.augment().getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a name identifier for augment.
|
||||
*
|
||||
* @param targetNode list of target nodes
|
||||
* @return name identifier
|
||||
*/
|
||||
private static String getValidNameForAugment(List<YangNodeIdentifier> targetNodes) {
|
||||
String name = "";
|
||||
YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
|
||||
|
||||
if (nodeId.getPrefix() != null) {
|
||||
name = AUGMENTED + getCaptialCase(nodeId.getPrefix()) + getCaptialCase(nodeId.getName());
|
||||
} else {
|
||||
//TODO: name = name + ((HasAugmentation)getParentNode()).getAugmentPrefix(nodeId);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates for the child nodes of augment node.
|
||||
*/
|
||||
private static void validateForChildNodes() {
|
||||
//TODO: implement with linker.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Abstraction of an entity which represents augmented info.
|
||||
*/
|
||||
public interface AugmentedInfo {
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstraction of an entity which represents augmentation of a YANG node.
|
||||
*/
|
||||
public interface HasAugmentation {
|
||||
|
||||
/**
|
||||
* Adds augment info to the augment info list.
|
||||
*
|
||||
* @param augmentInfo augment info of node
|
||||
*/
|
||||
void addAugmentation(AugmentedInfo augmentInfo);
|
||||
|
||||
/**
|
||||
* Removes augment info from the node.
|
||||
*/
|
||||
void removeAugmentation();
|
||||
|
||||
/**
|
||||
* Returns list of augment info.
|
||||
*
|
||||
* @return list of augment info
|
||||
*/
|
||||
List<AugmentedInfo> getAugmentedInfoList();
|
||||
}
|
@ -19,7 +19,6 @@ package org.onosproject.yangutils.translator.tojava;
|
||||
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 static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getIsQualifiedAccessOrAddToImportList;
|
||||
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
|
||||
@ -163,7 +162,7 @@ public final class JavaAttributeInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the import info for the attribute type. It will be null, of the type
|
||||
* Returns the import info for the attribute type. It will be null, if the type
|
||||
* is basic built-in java type.
|
||||
*
|
||||
* @return import info
|
||||
@ -255,7 +254,6 @@ public final class JavaAttributeInfo {
|
||||
*/
|
||||
JavaQualifiedTypeInfo importInfo = getQualifiedTypeInfoOfLeafAttribute(curNode,
|
||||
attributeType, attributeName, isListAttribute);
|
||||
AttributesJavaDataType.addImportInfo(importInfo);
|
||||
|
||||
return getAttributeInfoForTheData(importInfo, attributeName, attributeType, curNode, isListAttribute);
|
||||
}
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava;
|
||||
|
||||
import org.onosproject.yangutils.translator.exception.TranslatorException;
|
||||
|
||||
/**
|
||||
* Represents cached java file handle, which supports the addition of member attributes and
|
||||
* methods.
|
||||
@ -36,7 +34,7 @@ public class JavaFileInfo {
|
||||
private String javaName;
|
||||
|
||||
/**
|
||||
* java Package of the mapped java class.
|
||||
* Java Package of the mapped java class.
|
||||
*/
|
||||
private String pkg;
|
||||
|
||||
@ -96,10 +94,6 @@ public class JavaFileInfo {
|
||||
* @return the java package
|
||||
*/
|
||||
public String getPackage() {
|
||||
|
||||
if (pkg == null) {
|
||||
throw new TranslatorException("Referencing package of a generated java file which is not set");
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,15 @@ import static java.util.Collections.sort;
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.translator.exception.TranslatorException;
|
||||
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_CLASS;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_PKG;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
|
||||
@ -88,7 +93,7 @@ public class JavaImportData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the set containing the imported class/interface info.
|
||||
* Assigns the set containing the imported class/interface info.
|
||||
*
|
||||
* @param importSet the set containing the imported class/interface info
|
||||
*/
|
||||
@ -97,7 +102,7 @@ public class JavaImportData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an imported class/interface info if it is not already part of the
|
||||
* Adds an imported class/interface info if it is not already part of the
|
||||
* collection.
|
||||
*
|
||||
* If already part of the collection, check if the packages are same, if so
|
||||
@ -177,10 +182,36 @@ public class JavaImportData {
|
||||
/**
|
||||
* Returns import for list attribute.
|
||||
*
|
||||
* @return import for for list attribute
|
||||
* @return import for list attribute
|
||||
*/
|
||||
|
||||
private static String getImportForList() {
|
||||
public static String getImportForList() {
|
||||
return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns import for array list attribute.
|
||||
*
|
||||
* @return import for array list attribute
|
||||
*/
|
||||
public static String getImportForArrayList() {
|
||||
return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns import string for HasAugmentation class.
|
||||
*
|
||||
* @return import string for HasAugmentation class
|
||||
*/
|
||||
public static String getHasAugmentationImport() {
|
||||
return IMPORT + HAS_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + HAS_AUGMENTATION_CLASS_IMPORT_CLASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns import string for AugmentedInfo class.
|
||||
*
|
||||
* @return import string for AugmentedInfo class
|
||||
*/
|
||||
public static String getAugmentedInfoImport() {
|
||||
return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS;
|
||||
}
|
||||
}
|
||||
|
@ -87,11 +87,11 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
|
||||
* generation for import or for qualified access.
|
||||
*
|
||||
* @param curNode current data model node for which the java file is being
|
||||
* generated.
|
||||
* 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.
|
||||
* 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
|
||||
*/
|
||||
@ -140,9 +140,9 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
|
||||
* generation for import or for qualified access.
|
||||
*
|
||||
* @param curNode current data model node for which the java file is being
|
||||
* generated.
|
||||
* generated
|
||||
* @param attributeName name of the attribute being added, it will used in
|
||||
* import info for child class.
|
||||
* 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
|
||||
*/
|
||||
@ -241,8 +241,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
|
||||
throw new TranslatorException("missing java file info for the data model node");
|
||||
}
|
||||
return ((HasJavaFileInfo) curNode).getJavaFileInfo().getPackage()
|
||||
.contentEquals(importInfo.getPkgInfo()
|
||||
+ "." + importInfo.getClassInfo());
|
||||
.contentEquals(importInfo.getPkgInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -265,7 +264,7 @@ public class JavaQualifiedTypeInfo implements Comparable<JavaQualifiedTypeInfo>
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the import info matches.
|
||||
* Checks if the import info matches.
|
||||
*
|
||||
* @param importInfo matched import
|
||||
* @return if equal or not
|
||||
|
@ -30,7 +30,6 @@ import org.onosproject.yangutils.translator.exception.TranslatorException;
|
||||
|
||||
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_INTERFACE_WITH_BUILDER;
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
|
||||
@ -74,6 +73,14 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
|
||||
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.parseBuilderInterfaceBuildMethodString;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addImportsToStringAndHasCodeMethods;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
|
||||
@ -84,7 +91,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
||||
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
|
||||
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
|
||||
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
|
||||
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
|
||||
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
|
||||
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
|
||||
@ -121,6 +127,11 @@ public class TempJavaCodeFragmentFiles {
|
||||
*/
|
||||
private String generatedJavaClassName;
|
||||
|
||||
/**
|
||||
* Contains all the class name which will be extended by generated files.
|
||||
*/
|
||||
private List<String> extendsList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* File type extension for java classes.
|
||||
*/
|
||||
@ -302,6 +313,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
public TempJavaCodeFragmentFiles(int genFileType, String genDir, String className)
|
||||
throws IOException {
|
||||
|
||||
setExtendsList(new ArrayList<>());
|
||||
generatedTempFiles = 0;
|
||||
absoluteDirPath = genDir;
|
||||
generatedJavaClassName = className;
|
||||
@ -399,7 +411,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @return java file handle for interface file
|
||||
*/
|
||||
public File getInterfaceJavaFileHandle() {
|
||||
private File getInterfaceJavaFileHandle() {
|
||||
return interfaceJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -408,7 +420,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param interfaceJavaFileHandle java file handle
|
||||
*/
|
||||
public void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
|
||||
private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
|
||||
this.interfaceJavaFileHandle = interfaceJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -417,7 +429,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @return java file handle for builder interface file
|
||||
*/
|
||||
public File getBuilderInterfaceJavaFileHandle() {
|
||||
private File getBuilderInterfaceJavaFileHandle() {
|
||||
return builderInterfaceJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -426,7 +438,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param builderInterfaceJavaFileHandle java file handle
|
||||
*/
|
||||
public void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
|
||||
private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
|
||||
this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -435,7 +447,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @return java file handle for builder class file
|
||||
*/
|
||||
public File getBuilderClassJavaFileHandle() {
|
||||
private File getBuilderClassJavaFileHandle() {
|
||||
return builderClassJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -444,7 +456,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param builderClassJavaFileHandle java file handle
|
||||
*/
|
||||
public void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
|
||||
private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
|
||||
this.builderClassJavaFileHandle = builderClassJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -453,7 +465,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @return java file handle for impl class file
|
||||
*/
|
||||
public File getImplClassJavaFileHandle() {
|
||||
private File getImplClassJavaFileHandle() {
|
||||
return implClassJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -462,7 +474,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param implClassJavaFileHandle java file handle
|
||||
*/
|
||||
public void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
|
||||
private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
|
||||
this.implClassJavaFileHandle = implClassJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -471,7 +483,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @return java file handle for typedef class file
|
||||
*/
|
||||
public File getTypedefClassJavaFileHandle() {
|
||||
private File getTypedefClassJavaFileHandle() {
|
||||
return typedefClassJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -480,7 +492,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param typedefClassJavaFileHandle java file handle
|
||||
*/
|
||||
public void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
|
||||
private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
|
||||
this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
|
||||
}
|
||||
|
||||
@ -498,7 +510,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param attributeForClass file handle for attribute
|
||||
*/
|
||||
public void setAttributesTempFileHandle(File attributeForClass) {
|
||||
private void setAttributesTempFileHandle(File attributeForClass) {
|
||||
attributesTempFileHandle = attributeForClass;
|
||||
}
|
||||
|
||||
@ -516,7 +528,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param getterForInterface file handle for to getter method
|
||||
*/
|
||||
public void setGetterInterfaceTempFileHandle(File getterForInterface) {
|
||||
private void setGetterInterfaceTempFileHandle(File getterForInterface) {
|
||||
getterInterfaceTempFileHandle = getterForInterface;
|
||||
}
|
||||
|
||||
@ -534,7 +546,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param getterImpl file handle for to getter method's impl
|
||||
*/
|
||||
public void setGetterImplTempFileHandle(File getterImpl) {
|
||||
private void setGetterImplTempFileHandle(File getterImpl) {
|
||||
getterImplTempFileHandle = getterImpl;
|
||||
}
|
||||
|
||||
@ -552,7 +564,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param setterForInterface file handle for to setter method
|
||||
*/
|
||||
public void setSetterInterfaceTempFileHandle(File setterForInterface) {
|
||||
private void setSetterInterfaceTempFileHandle(File setterForInterface) {
|
||||
setterInterfaceTempFileHandle = setterForInterface;
|
||||
}
|
||||
|
||||
@ -570,7 +582,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param setterImpl file handle for to setter method's implementation class
|
||||
*/
|
||||
public void setSetterImplTempFileHandle(File setterImpl) {
|
||||
private void setSetterImplTempFileHandle(File setterImpl) {
|
||||
setterImplTempFileHandle = setterImpl;
|
||||
}
|
||||
|
||||
@ -588,7 +600,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param constructor file handle for to constructor
|
||||
*/
|
||||
public void setConstructorImplTempFileHandle(File constructor) {
|
||||
private void setConstructorImplTempFileHandle(File constructor) {
|
||||
constructorImplTempFileHandle = constructor;
|
||||
}
|
||||
|
||||
@ -606,7 +618,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param hashCodeMethod file handle for hash code method
|
||||
*/
|
||||
public void setHashCodeImplTempFileHandle(File hashCodeMethod) {
|
||||
private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
|
||||
hashCodeImplTempFileHandle = hashCodeMethod;
|
||||
}
|
||||
|
||||
@ -624,7 +636,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param equalsMethod file handle for to equals method
|
||||
*/
|
||||
public void setEqualsImplTempFileHandle(File equalsMethod) {
|
||||
private void setEqualsImplTempFileHandle(File equalsMethod) {
|
||||
equalsImplTempFileHandle = equalsMethod;
|
||||
}
|
||||
|
||||
@ -642,7 +654,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param toStringMethod file handle for to string method
|
||||
*/
|
||||
public void setToStringImplTempFileHandle(File toStringMethod) {
|
||||
private void setToStringImplTempFileHandle(File toStringMethod) {
|
||||
toStringImplTempFileHandle = toStringMethod;
|
||||
}
|
||||
|
||||
@ -651,7 +663,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @return java attribute info
|
||||
*/
|
||||
public JavaAttributeInfo getNewAttrInfo() {
|
||||
private JavaAttributeInfo getNewAttrInfo() {
|
||||
return newAttrInfo;
|
||||
}
|
||||
|
||||
@ -660,7 +672,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param newAttrInfo java attribute info
|
||||
*/
|
||||
public void setNewAttrInfo(JavaAttributeInfo newAttrInfo) {
|
||||
private void setNewAttrInfo(JavaAttributeInfo newAttrInfo) {
|
||||
|
||||
if (newAttrInfo != null) {
|
||||
isAttributePresent = true;
|
||||
@ -673,7 +685,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @return current YANG node
|
||||
*/
|
||||
public YangNode getCurYangNode() {
|
||||
private YangNode getCurYangNode() {
|
||||
return curYangNode;
|
||||
}
|
||||
|
||||
@ -682,17 +694,45 @@ public class TempJavaCodeFragmentFiles {
|
||||
*
|
||||
* @param curYangNode YANG node
|
||||
*/
|
||||
public void setCurYangNode(YangNode curYangNode) {
|
||||
private void setCurYangNode(YangNode curYangNode) {
|
||||
this.curYangNode = curYangNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of classes to be extended by generated files.
|
||||
*
|
||||
* @return list of classes to be extended by generated files
|
||||
*/
|
||||
private List<String> getExtendsList() {
|
||||
return extendsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets class to be extended by generated file.
|
||||
*
|
||||
* @param extendsList list of classes to be extended
|
||||
*/
|
||||
|
||||
private void setExtendsList(List<String> extendsList) {
|
||||
this.extendsList = extendsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds class to the extends list.
|
||||
*
|
||||
* @param extend class to be extended
|
||||
*/
|
||||
public void addToExtendsList(String extend) {
|
||||
getExtendsList().add(extend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds attribute for class.
|
||||
*
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addAttribute(JavaAttributeInfo attr) throws IOException {
|
||||
private void addAttribute(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getAttributesTempFileHandle(), parseAttribute(attr) + FOUR_SPACE_INDENTATION);
|
||||
}
|
||||
|
||||
@ -702,7 +742,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addGetterForInterface(JavaAttributeInfo attr) throws IOException {
|
||||
private void addGetterForInterface(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE);
|
||||
}
|
||||
|
||||
@ -713,7 +753,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param genFiletype generated file type
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException {
|
||||
private void addGetterImpl(JavaAttributeInfo attr, int genFiletype) throws IOException {
|
||||
|
||||
if ((genFiletype & BUILDER_CLASS_MASK) != 0) {
|
||||
appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE);
|
||||
@ -729,7 +769,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addSetterForInterface(JavaAttributeInfo attr) throws IOException {
|
||||
private void addSetterForInterface(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getSetterInterfaceTempFileHandle(),
|
||||
getSetterString(attr, generatedJavaClassName) + NEW_LINE);
|
||||
}
|
||||
@ -740,7 +780,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addSetterImpl(JavaAttributeInfo attr) throws IOException {
|
||||
private void addSetterImpl(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getSetterImplTempFileHandle(),
|
||||
getOverRideString() + getSetterForClass(attr, generatedJavaClassName) + NEW_LINE);
|
||||
}
|
||||
@ -771,7 +811,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addConstructor(JavaAttributeInfo attr) throws IOException {
|
||||
private void addConstructor(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getConstructorImplTempFileHandle(), getConstructor(generatedJavaClassName, attr));
|
||||
}
|
||||
|
||||
@ -826,7 +866,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addHashCodeMethod(JavaAttributeInfo attr) throws IOException {
|
||||
private void addHashCodeMethod(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
|
||||
}
|
||||
|
||||
@ -836,7 +876,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addEqualsMethod(JavaAttributeInfo attr) throws IOException {
|
||||
private void addEqualsMethod(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
|
||||
}
|
||||
|
||||
@ -846,7 +886,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* @param attr attribute info
|
||||
* @throws IOException when fails to append to temporary file
|
||||
*/
|
||||
public void addToStringMethod(JavaAttributeInfo attr) throws IOException {
|
||||
private void addToStringMethod(JavaAttributeInfo attr) throws IOException {
|
||||
appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
|
||||
}
|
||||
|
||||
@ -1031,7 +1071,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the leaves in the current data model node as part of the
|
||||
* Adds all the leaves in the current data model node as part of the
|
||||
* generated temporary file.
|
||||
*
|
||||
* @param curNode java file info of the generated file
|
||||
@ -1139,7 +1179,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct java code exit.
|
||||
* Constructs java code exit.
|
||||
*
|
||||
* @param fileType generated file type
|
||||
* @param curNode current YANG node
|
||||
@ -1152,11 +1192,27 @@ public class TempJavaCodeFragmentFiles {
|
||||
if (curNode instanceof HasJavaImportData && isAttributePresent) {
|
||||
imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start generation of files.
|
||||
* Prepares java file generator for extends list.
|
||||
*/
|
||||
if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0
|
||||
| fileType == GENERATE_INTERFACE_WITH_BUILDER) {
|
||||
prepareJavaFileGeneratorForExtendsList(getExtendsList());
|
||||
|
||||
/**
|
||||
* Generate java code.
|
||||
*/
|
||||
if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) {
|
||||
|
||||
/**
|
||||
* Adds import for HasAugmentation class.
|
||||
*/
|
||||
if (isHasAugmentationExtended(getExtendsList())) {
|
||||
addHasAugmentationImport(curNode, imports, true);
|
||||
}
|
||||
|
||||
if (isAugmentedInfoExtended(getExtendsList())) {
|
||||
addAugmentedInfoImport(curNode, imports, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create interface file.
|
||||
@ -1167,25 +1223,36 @@ public class TempJavaCodeFragmentFiles {
|
||||
/**
|
||||
* Create builder interface file.
|
||||
*/
|
||||
setBuilderInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
|
||||
setBuilderInterfaceJavaFileHandle(
|
||||
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent));
|
||||
/**
|
||||
* Append builder interface file to interface file and close it.
|
||||
*/
|
||||
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
|
||||
if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
|
||||
|
||||
setBuilderInterfaceJavaFileHandle(
|
||||
getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
|
||||
setBuilderInterfaceJavaFileHandle(
|
||||
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent));
|
||||
/**
|
||||
* Append builder interface file to interface file and close it.
|
||||
*/
|
||||
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
|
||||
}
|
||||
insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
|
||||
|
||||
if (isHasAugmentationExtended(getExtendsList())) {
|
||||
addHasAugmentationImport(curNode, imports, false);
|
||||
}
|
||||
if (isAugmentedInfoExtended(getExtendsList())) {
|
||||
addAugmentedInfoImport(curNode, imports, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (curNode instanceof HasJavaImportData && isAttributePresent) {
|
||||
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals());
|
||||
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString());
|
||||
java.util.Collections.sort(imports);
|
||||
}
|
||||
if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) {
|
||||
|
||||
if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0
|
||||
| fileType == GENERATE_INTERFACE_WITH_BUILDER) {
|
||||
if (isAttributePresent) {
|
||||
addImportsToStringAndHasCodeMethods(curNode, imports);
|
||||
}
|
||||
if (isHasAugmentationExtended(getExtendsList())) {
|
||||
addAugmentedInfoImport(curNode, imports, true);
|
||||
addArrayListImport(curNode, imports, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create builder class file.
|
||||
@ -1196,13 +1263,15 @@ public class TempJavaCodeFragmentFiles {
|
||||
/**
|
||||
* Create impl class file.
|
||||
*/
|
||||
setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
|
||||
setImplClassJavaFileHandle(
|
||||
generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent));
|
||||
/**
|
||||
* Append impl class to builder class and close it.
|
||||
*/
|
||||
mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
|
||||
if ((fileType & IMPL_CLASS_MASK) != 0) {
|
||||
setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
|
||||
setImplClassJavaFileHandle(
|
||||
generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent));
|
||||
/**
|
||||
* Append impl class to builder class and close it.
|
||||
*/
|
||||
mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
|
||||
}
|
||||
insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
|
||||
}
|
||||
|
||||
@ -1210,6 +1279,7 @@ public class TempJavaCodeFragmentFiles {
|
||||
* Creates type def class file.
|
||||
*/
|
||||
if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
|
||||
addImportsToStringAndHasCodeMethods(curNode, imports);
|
||||
setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
|
||||
setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports));
|
||||
}
|
||||
@ -1285,19 +1355,4 @@ public class TempJavaCodeFragmentFiles {
|
||||
generatedTempFiles = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the file handle for temporary file.
|
||||
*
|
||||
* @param fileName temporary file's name
|
||||
* @throws IOException when failed to close the file handle
|
||||
*/
|
||||
private void closeFile(File file, boolean toBeDeleted) throws IOException {
|
||||
|
||||
if (file != null) {
|
||||
updateFileHandle(file, null, true);
|
||||
if (toBeDeleted) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
package org.onosproject.yangutils.translator.tojava.javamodel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangAugment;
|
||||
import org.onosproject.yangutils.translator.exception.TranslatorException;
|
||||
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
|
||||
@ -137,11 +138,12 @@ public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInf
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG grouping info.
|
||||
* Create a java file using the YANG augment info.
|
||||
*
|
||||
* @throws IOException when failed to do IO operations
|
||||
*/
|
||||
@Override
|
||||
public void generateCodeExit() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void generateCodeExit() throws IOException {
|
||||
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, Jav
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG grouping info.
|
||||
* Creates a java file using the YANG case info.
|
||||
*/
|
||||
@Override
|
||||
public void generateCodeExit() {
|
||||
|
@ -125,7 +125,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo,
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* case info.
|
||||
* choice info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operation fail
|
||||
@ -137,7 +137,7 @@ public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo,
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG grouping info.
|
||||
* Creates a java file using the YANG choice info.
|
||||
*/
|
||||
@Override
|
||||
public void generateCodeExit() {
|
||||
|
@ -125,7 +125,7 @@ public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorI
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* container info.
|
||||
* grouping info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operation fail
|
||||
|
@ -126,7 +126,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* container info.
|
||||
* input info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operation fail
|
||||
@ -137,7 +137,7 @@ public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, J
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG grouping info.
|
||||
* Creates a java file using the YANG input info.
|
||||
*
|
||||
* @throws IOException IO operation fail
|
||||
*/
|
||||
|
@ -125,7 +125,7 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* container info.
|
||||
* list info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operation fail
|
||||
@ -136,7 +136,7 @@ public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, Jav
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG grouping info.
|
||||
* Creates a java file using the YANG list info.
|
||||
*
|
||||
* @throws IOException IO operation fail
|
||||
*/
|
||||
|
@ -165,7 +165,7 @@ public class YangJavaNotification extends YangNotification
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a java file using the YANG notification info.
|
||||
* Creates a java file using the YANG notification info.
|
||||
*/
|
||||
@Override
|
||||
public void generateCodeExit() {
|
||||
|
@ -126,7 +126,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo,
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* container info.
|
||||
* output info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operation fail
|
||||
@ -137,7 +137,7 @@ public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo,
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG grouping info.
|
||||
* Creates a java file using the YANG output info.
|
||||
*
|
||||
* @throws IOException IO operation fail
|
||||
*/
|
||||
|
@ -34,7 +34,7 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator {
|
||||
|
||||
/**
|
||||
* Prepares the information for java code generation corresponding to YANG
|
||||
* rpc info.
|
||||
* RPC info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operation fail
|
||||
@ -45,7 +45,7 @@ public class YangJavaRpc extends YangRpc implements JavaCodeGenerator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG rpc info.
|
||||
* Creates a java file using the YANG RPC info.
|
||||
*
|
||||
* @throws IOException IO operation fail
|
||||
*/
|
||||
|
@ -139,7 +139,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* container info.
|
||||
* submodule info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operation fail
|
||||
@ -152,7 +152,7 @@ public class YangJavaSubModule extends YangSubModule implements JavaCodeGenerato
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a java file using the YANG grouping info.
|
||||
* Creates a java file using the YANG submodule info.
|
||||
*/
|
||||
@Override
|
||||
public void generateCodeExit() {
|
||||
|
@ -135,7 +135,7 @@ public class YangJavaTypeDef extends YangTypeDef
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* container info.
|
||||
* typedef info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
* @throws IOException IO operations fails
|
||||
@ -162,7 +162,7 @@ public class YangJavaTypeDef extends YangTypeDef
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a java file using the YANG grouping info.
|
||||
* Create a java file using the YANG typedef info.
|
||||
*
|
||||
* @throws IOException IO operations fails
|
||||
*/
|
||||
|
@ -103,7 +103,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava
|
||||
|
||||
/**
|
||||
* Prepare the information for java code generation corresponding to YANG
|
||||
* container info.
|
||||
* uses info.
|
||||
*
|
||||
* @param yangPlugin YANG plugin config
|
||||
*/
|
||||
@ -120,7 +120,7 @@ public class YangJavaUses extends YangUses implements JavaCodeGenerator, HasJava
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a java file using the YANG grouping info.
|
||||
* Create a java file using the YANG uses info.
|
||||
*/
|
||||
@Override
|
||||
public void generateCodeExit() {
|
||||
|
@ -16,35 +16,19 @@
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava.utils;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangDataTypes;
|
||||
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.datamodel.YangType;
|
||||
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
|
||||
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.JavaFileInfo;
|
||||
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
|
||||
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.BINARY;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.BITS;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.DECIMAL64;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.EMPTY;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.ENUMERATION;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.IDENTITYREF;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.INSTANCE_IDENTIFIER;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT16;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT64;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT8;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.LEAFREF;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT16;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT32;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT64;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.UNION;
|
||||
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.utils.UtilConstants.BIG_INTEGER;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
|
||||
@ -52,8 +36,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
|
||||
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.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.STRING_DATA_TYPE;
|
||||
@ -63,34 +49,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
|
||||
*/
|
||||
public final class AttributesJavaDataType {
|
||||
|
||||
private static Set<JavaQualifiedTypeInfo> importInfo = new TreeSet<>();
|
||||
|
||||
/**
|
||||
* Creates an instance of attribute java data type.
|
||||
*/
|
||||
private AttributesJavaDataType() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns import info.
|
||||
*
|
||||
* @return import info
|
||||
*/
|
||||
public static Set<JavaQualifiedTypeInfo> getImportInfo() {
|
||||
|
||||
return importInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds import info to the import info set.
|
||||
*
|
||||
* @param importData import info
|
||||
*/
|
||||
public static void addImportInfo(JavaQualifiedTypeInfo importData) {
|
||||
|
||||
getImportInfo().add(importData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns java type.
|
||||
*
|
||||
@ -101,48 +65,32 @@ public final class AttributesJavaDataType {
|
||||
|
||||
YangDataTypes type = yangType.getDataType();
|
||||
|
||||
if (type.equals(INT8)) {
|
||||
return BYTE;
|
||||
} else if (type.equals(INT16)) {
|
||||
return SHORT;
|
||||
} else if (type.equals(INT32)) {
|
||||
return INT;
|
||||
} else if (type.equals(INT64)) {
|
||||
return LONG;
|
||||
} else if (type.equals(UINT8)) {
|
||||
return SHORT;
|
||||
} else if (type.equals(UINT16)) {
|
||||
return INT;
|
||||
} else if (type.equals(UINT32)) {
|
||||
return LONG;
|
||||
} else if (type.equals(UINT64)) {
|
||||
//TODO: BIGINTEGER.
|
||||
} else if (type.equals(DECIMAL64)) {
|
||||
//TODO: DECIMAL64.
|
||||
} else if (type.equals(STRING)) {
|
||||
return STRING_DATA_TYPE;
|
||||
} else if (type.equals(BOOLEAN)) {
|
||||
return BOOLEAN_DATA_TYPE;
|
||||
} else if (type.equals(ENUMERATION)) {
|
||||
//TODO: ENUMERATION.
|
||||
} else if (type.equals(BITS)) {
|
||||
//TODO:BITS
|
||||
} else if (type.equals(BINARY)) {
|
||||
//TODO:BINARY
|
||||
} else if (type.equals(LEAFREF)) {
|
||||
//TODO:LEAFREF
|
||||
} else if (type.equals(IDENTITYREF)) {
|
||||
//TODO:IDENTITYREF
|
||||
} else if (type.equals(EMPTY)) {
|
||||
//TODO:EMPTY
|
||||
} else if (type.equals(UNION)) {
|
||||
//TODO:UNION
|
||||
} else if (type.equals(INSTANCE_IDENTIFIER)) {
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
} else if (type.equals(DERIVED)) {
|
||||
return yangType.getDataTypeName();
|
||||
switch (type) {
|
||||
case INT8:
|
||||
return BYTE;
|
||||
case INT16:
|
||||
return SHORT;
|
||||
case INT32:
|
||||
return INT;
|
||||
case INT64:
|
||||
return LONG;
|
||||
case UINT8:
|
||||
return SHORT;
|
||||
case UINT16:
|
||||
return INT;
|
||||
case UINT32:
|
||||
return LONG;
|
||||
case UINT64:
|
||||
return BIG_INTEGER;
|
||||
case DECIMAL64:
|
||||
//TODO: DECIMAL64.
|
||||
case STRING:
|
||||
return STRING_DATA_TYPE;
|
||||
case BOOLEAN:
|
||||
return BOOLEAN_DATA_TYPE;
|
||||
default:
|
||||
throw new TranslatorException("given data type is not supported.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,75 +105,80 @@ public final class AttributesJavaDataType {
|
||||
YangDataTypes type = yangType.getDataType();
|
||||
|
||||
if (isListAttr) {
|
||||
if (type.equals(INT8)) {
|
||||
return BYTE_WRAPPER;
|
||||
} else if (type.equals(INT16)) {
|
||||
return SHORT_WRAPPER;
|
||||
} else if (type.equals(INT32)) {
|
||||
return INTEGER_WRAPPER;
|
||||
} else if (type.equals(INT64)) {
|
||||
return LONG_WRAPPER;
|
||||
} else if (type.equals(UINT8)) {
|
||||
return SHORT_WRAPPER;
|
||||
} else if (type.equals(UINT16)) {
|
||||
return INTEGER_WRAPPER;
|
||||
} else if (type.equals(UINT32)) {
|
||||
return LONG_WRAPPER;
|
||||
} else if (type.equals(UINT64)) {
|
||||
//TODO: BIGINTEGER.
|
||||
} else if (type.equals(DECIMAL64)) {
|
||||
//TODO: DECIMAL64.
|
||||
} else if (type.equals(STRING)) {
|
||||
return STRING_DATA_TYPE;
|
||||
} else if (type.equals(BOOLEAN)) {
|
||||
return BOOLEAN_WRAPPER;
|
||||
} else if (type.equals(ENUMERATION)) {
|
||||
//TODO: ENUMERATION.
|
||||
} else if (type.equals(BITS)) {
|
||||
//TODO:BITS
|
||||
} else if (type.equals(BINARY)) {
|
||||
//TODO:BINARY
|
||||
} else if (type.equals(LEAFREF)) {
|
||||
//TODO:LEAFREF
|
||||
} else if (type.equals(IDENTITYREF)) {
|
||||
//TODO:IDENTITYREF
|
||||
} else if (type.equals(EMPTY)) {
|
||||
//TODO:EMPTY
|
||||
} else if (type.equals(UNION)) {
|
||||
//TODO:UNION
|
||||
} else if (type.equals(INSTANCE_IDENTIFIER)) {
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
} else if (type.equals(DERIVED)) {
|
||||
return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
|
||||
switch (type) {
|
||||
case INT8:
|
||||
return BYTE_WRAPPER;
|
||||
case INT16:
|
||||
return SHORT_WRAPPER;
|
||||
case INT32:
|
||||
return INTEGER_WRAPPER;
|
||||
case INT64:
|
||||
return LONG_WRAPPER;
|
||||
case UINT8:
|
||||
return SHORT_WRAPPER;
|
||||
case UINT16:
|
||||
return INTEGER_WRAPPER;
|
||||
case UINT32:
|
||||
return LONG_WRAPPER;
|
||||
case UINT64:
|
||||
return BIG_INTEGER;
|
||||
case DECIMAL64:
|
||||
//TODO: DECIMAL64.
|
||||
case STRING:
|
||||
return STRING_DATA_TYPE;
|
||||
case BOOLEAN:
|
||||
return BOOLEAN_WRAPPER;
|
||||
case ENUMERATION:
|
||||
//TODO: ENUMERATION.
|
||||
case BITS:
|
||||
//TODO:BITS
|
||||
case BINARY:
|
||||
//TODO:BINARY
|
||||
case LEAFREF:
|
||||
//TODO:LEAFREF
|
||||
case IDENTITYREF:
|
||||
//TODO:IDENTITYREF
|
||||
case EMPTY:
|
||||
return BOOLEAN_WRAPPER;
|
||||
case UNION:
|
||||
//TODO:UNION
|
||||
case INSTANCE_IDENTIFIER:
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
case DERIVED:
|
||||
return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
|
||||
default:
|
||||
throw new TranslatorException("given data type is not supported.");
|
||||
}
|
||||
} else {
|
||||
if (type.equals(UINT64)) {
|
||||
//TODO: BIGINTEGER.
|
||||
} else if (type.equals(DECIMAL64)) {
|
||||
//TODO: DECIMAL64.
|
||||
} else if (type.equals(STRING)) {
|
||||
return STRING_DATA_TYPE;
|
||||
} else if (type.equals(ENUMERATION)) {
|
||||
//TODO: ENUMERATION.
|
||||
} else if (type.equals(BITS)) {
|
||||
//TODO:BITS
|
||||
} else if (type.equals(BINARY)) {
|
||||
//TODO:BINARY
|
||||
} else if (type.equals(LEAFREF)) {
|
||||
//TODO:LEAFREF
|
||||
} else if (type.equals(IDENTITYREF)) {
|
||||
//TODO:IDENTITYREF
|
||||
} else if (type.equals(EMPTY)) {
|
||||
//TODO:EMPTY
|
||||
} else if (type.equals(UNION)) {
|
||||
//TODO:UNION
|
||||
} else if (type.equals(INSTANCE_IDENTIFIER)) {
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
} else if (type.equals(DERIVED)) {
|
||||
return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
|
||||
switch (type) {
|
||||
case UINT64:
|
||||
return BIG_INTEGER;
|
||||
case DECIMAL64:
|
||||
//TODO: DECIMAL64.
|
||||
case STRING:
|
||||
return STRING_DATA_TYPE;
|
||||
case ENUMERATION:
|
||||
//TODO: ENUMERATION.
|
||||
case BITS:
|
||||
//TODO:BITS
|
||||
case BINARY:
|
||||
//TODO:BINARY
|
||||
case LEAFREF:
|
||||
//TODO:LEAFREF
|
||||
case IDENTITYREF:
|
||||
//TODO:IDENTITYREF
|
||||
case EMPTY:
|
||||
//TODO:EMPTY
|
||||
case UNION:
|
||||
//TODO:UNION
|
||||
case INSTANCE_IDENTIFIER:
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
case DERIVED:
|
||||
return getCaptialCase(getCamelCase(yangType.getDataTypeName(), null));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,75 +194,108 @@ public final class AttributesJavaDataType {
|
||||
YangDataTypes type = yangType.getDataType();
|
||||
|
||||
if (isListAttr) {
|
||||
if (type.equals(INT8)
|
||||
|| type.equals(INT16)
|
||||
|| type.equals(INT32)
|
||||
|| type.equals(INT64)
|
||||
|| type.equals(UINT8)
|
||||
|| type.equals(UINT16)
|
||||
|| type.equals(UINT32)
|
||||
|| type.equals(STRING)
|
||||
|| type.equals(BOOLEAN)) {
|
||||
return JAVA_LANG;
|
||||
} else if (type.equals(UINT64)) {
|
||||
//TODO: BIGINTEGER.
|
||||
} else if (type.equals(DECIMAL64)) {
|
||||
//TODO: DECIMAL64.
|
||||
} else if (type.equals(ENUMERATION)) {
|
||||
//TODO: ENUMERATION.
|
||||
} else if (type.equals(BITS)) {
|
||||
//TODO:BITS
|
||||
} else if (type.equals(BINARY)) {
|
||||
//TODO:BINARY
|
||||
} else if (type.equals(LEAFREF)) {
|
||||
//TODO:LEAFREF
|
||||
} else if (type.equals(IDENTITYREF)) {
|
||||
//TODO:IDENTITYREF
|
||||
} else if (type.equals(EMPTY)) {
|
||||
//TODO:EMPTY
|
||||
} else if (type.equals(UNION)) {
|
||||
//TODO:UNION
|
||||
} else if (type.equals(INSTANCE_IDENTIFIER)) {
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
} else if (type.equals(DERIVED)) {
|
||||
for (JavaQualifiedTypeInfo imports : getImportInfo()) {
|
||||
if (imports.getClassInfo().equals(classInfo)) {
|
||||
return imports.getPkgInfo();
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case INT8:
|
||||
case INT16:
|
||||
case INT32:
|
||||
case INT64:
|
||||
case UINT8:
|
||||
case UINT16:
|
||||
case UINT32:
|
||||
case STRING:
|
||||
case BOOLEAN:
|
||||
return JAVA_LANG;
|
||||
case UINT64:
|
||||
return JAVA_MATH;
|
||||
case DECIMAL64:
|
||||
//TODO: DECIMAL64.
|
||||
case ENUMERATION:
|
||||
//TODO: ENUMERATION.
|
||||
case BITS:
|
||||
//TODO:BITS
|
||||
case BINARY:
|
||||
//TODO:BINARY
|
||||
case LEAFREF:
|
||||
//TODO:LEAFREF
|
||||
case IDENTITYREF:
|
||||
//TODO:IDENTITYREF
|
||||
case EMPTY:
|
||||
//TODO:EMPTY
|
||||
case UNION:
|
||||
//TODO:UNION
|
||||
case INSTANCE_IDENTIFIER:
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
case DERIVED:
|
||||
return getTypDefsPackage(yangType);
|
||||
default:
|
||||
throw new TranslatorException("given data type is not supported.");
|
||||
}
|
||||
} else {
|
||||
|
||||
if (type.equals(UINT64)) {
|
||||
//TODO: BIGINTEGER.
|
||||
} else if (type.equals(DECIMAL64)) {
|
||||
//TODO: DECIMAL64.
|
||||
} else if (type.equals(STRING)) {
|
||||
return JAVA_LANG;
|
||||
} else if (type.equals(ENUMERATION)) {
|
||||
//TODO: ENUMERATION.
|
||||
} else if (type.equals(BITS)) {
|
||||
//TODO:BITS
|
||||
} else if (type.equals(BINARY)) {
|
||||
//TODO:BINARY
|
||||
} else if (type.equals(LEAFREF)) {
|
||||
//TODO:LEAFREF
|
||||
} else if (type.equals(IDENTITYREF)) {
|
||||
//TODO:IDENTITYREF
|
||||
} else if (type.equals(EMPTY)) {
|
||||
//TODO:EMPTY
|
||||
} else if (type.equals(UNION)) {
|
||||
//TODO:UNION
|
||||
} else if (type.equals(INSTANCE_IDENTIFIER)) {
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
} else if (type.equals(DERIVED)) {
|
||||
for (JavaQualifiedTypeInfo imports : getImportInfo()) {
|
||||
if (imports.getClassInfo().equals(classInfo)) {
|
||||
return imports.getPkgInfo();
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case UINT64:
|
||||
//TODO: BIGINTEGER.
|
||||
case DECIMAL64:
|
||||
//TODO: DECIMAL64
|
||||
case STRING:
|
||||
return JAVA_LANG;
|
||||
case ENUMERATION:
|
||||
//TODO: ENUMERATION.
|
||||
case BITS:
|
||||
//TODO:BITS
|
||||
case BINARY:
|
||||
//TODO:BINARY
|
||||
case LEAFREF:
|
||||
//TODO:LEAFREF
|
||||
case IDENTITYREF:
|
||||
//TODO:IDENTITYREF
|
||||
case EMPTY:
|
||||
//TODO:EMPTY
|
||||
case UNION:
|
||||
//TODO:UNION
|
||||
case INSTANCE_IDENTIFIER:
|
||||
//TODO:INSTANCE_IDENTIFIER
|
||||
case DERIVED:
|
||||
return getTypDefsPackage(yangType);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns java package for typedef node.
|
||||
*
|
||||
* @param type YANG type
|
||||
* @return java package for typedef node
|
||||
*/
|
||||
private static String getTypDefsPackage(YangType<?> type) {
|
||||
Object var = type.getDataTypeExtendedInfo();
|
||||
if (!(var instanceof YangDerivedInfo)) {
|
||||
throw new TranslatorException("type should have been derived.");
|
||||
}
|
||||
|
||||
if (!(((YangDerivedInfo<?>) var).getReferredTypeDef() instanceof YangTypeDef)) {
|
||||
throw new TranslatorException("derived info is not an instance of typedef.");
|
||||
}
|
||||
|
||||
YangJavaTypeDef typedef = (YangJavaTypeDef) ((YangDerivedInfo<?>) var).getReferredTypeDef();
|
||||
if (typedef.getJavaFileInfo().getPackage() == null) {
|
||||
return getPackageFromParent(typedef.getParent());
|
||||
}
|
||||
return typedef.getJavaFileInfo().getPackage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns package from parent node.
|
||||
*
|
||||
* @param parent parent YANG node
|
||||
* @return java package from parent node
|
||||
*/
|
||||
private static String getPackageFromParent(YangNode parent) {
|
||||
if (!(parent instanceof HasJavaFileInfo)) {
|
||||
throw new TranslatorException("Invalid child node is being processed.");
|
||||
}
|
||||
JavaFileInfo parentInfo = ((HasJavaFileInfo) parent).getJavaFileInfo();
|
||||
return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,12 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.isExtendsList;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
|
||||
@ -32,6 +36,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
|
||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
|
||||
|
||||
/**
|
||||
* Represents generator for class definition of generated files.
|
||||
@ -84,8 +89,16 @@ public final class ClassDefinitionGenerator {
|
||||
* @return definition
|
||||
*/
|
||||
private static String getInterfaceDefinition(String yangName) {
|
||||
if (!isExtendsList()) {
|
||||
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
|
||||
}
|
||||
String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
|
||||
for (String extend : getExtendsList()) {
|
||||
def = def + extend + COMMA;
|
||||
}
|
||||
def = trimAtLast(def, COMMA);
|
||||
|
||||
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
|
||||
return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +109,6 @@ public final class ClassDefinitionGenerator {
|
||||
* @return definition
|
||||
*/
|
||||
private static String getBuilderInterfaceDefinition(String yangName) {
|
||||
|
||||
return INTERFACE + SPACE + yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE;
|
||||
}
|
||||
|
||||
@ -107,7 +119,6 @@ public final class ClassDefinitionGenerator {
|
||||
* @return definition
|
||||
*/
|
||||
private static String getBuilderClassDefinition(String yangName) {
|
||||
|
||||
return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
|
||||
+ yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
|
||||
}
|
||||
@ -119,7 +130,6 @@ public final class ClassDefinitionGenerator {
|
||||
* @return definition
|
||||
*/
|
||||
private static String getImplClassDefinition(String yangName) {
|
||||
|
||||
return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + IMPL + SPACE + IMPLEMENTS + SPACE + yangName
|
||||
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
|
||||
}
|
||||
@ -131,7 +141,6 @@ public final class ClassDefinitionGenerator {
|
||||
* @return definition
|
||||
*/
|
||||
private static String getTypeDefClassDefinition(String yangName) {
|
||||
|
||||
return PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,20 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
|
||||
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
|
||||
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.EQUAL;
|
||||
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.LIST;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
|
||||
@ -126,6 +134,18 @@ public final class JavaCodeSnippetGen {
|
||||
return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attribute of augmented info for generated impl file.
|
||||
*
|
||||
* @return attribute of augmented info for generated impl file
|
||||
*/
|
||||
public static String getAugmentedInfoAttribute() {
|
||||
return FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
|
||||
+ getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST
|
||||
+ DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
|
||||
+ NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns based on the file type and the YANG name of the file, generate the class
|
||||
* / interface definition close.
|
||||
|
@ -40,16 +40,21 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
|
||||
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentedInfoAttribute;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoListImpl;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen;
|
||||
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.getRemoveAugmentationImpl;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
|
||||
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.EMPTY_STRING;
|
||||
@ -67,11 +72,57 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.partString;
|
||||
public final class JavaFileGenerator {
|
||||
|
||||
/**
|
||||
* Creates an instance of java file generator.
|
||||
* Flag to check whether generated interface file need to extends any class.
|
||||
*/
|
||||
private static boolean isExtendsList = false;
|
||||
|
||||
/**
|
||||
* List of classes to be extended by generated interface file.
|
||||
*/
|
||||
private static List<String> extendsList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates an instance of java file generator.
|
||||
*/
|
||||
private JavaFileGenerator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if extends list is not empty.
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
public static boolean isExtendsList() {
|
||||
return isExtendsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of is extends list.
|
||||
*
|
||||
* @param isExtends true or false
|
||||
*/
|
||||
public static void setIsExtendsList(boolean isExtends) {
|
||||
isExtendsList = isExtends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of extended classes.
|
||||
*
|
||||
* @return list of extended classes
|
||||
*/
|
||||
public static List<String> getExtendsList() {
|
||||
return extendsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list of extended classes.
|
||||
*
|
||||
* @param extendList list of extended classes
|
||||
*/
|
||||
public static void setExtendsList(List<String> extendList) {
|
||||
extendsList = extendList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns generated interface file for current node.
|
||||
*
|
||||
@ -91,6 +142,7 @@ public final class JavaFileGenerator {
|
||||
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
|
||||
|
||||
initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path);
|
||||
|
||||
if (isAttrPresent) {
|
||||
/**
|
||||
* Add getter methods to interface file.
|
||||
@ -258,6 +310,12 @@ public final class JavaFileGenerator {
|
||||
+ " while impl class file generation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add attribute for augmented info's list.
|
||||
*/
|
||||
if (isHasAugmentationExtended(getExtendsList())) {
|
||||
insertDataIntoJavaFile(file, getAugmentedInfoAttribute());
|
||||
}
|
||||
insertDataIntoJavaFile(file, NEW_LINE);
|
||||
try {
|
||||
/**
|
||||
@ -298,6 +356,16 @@ public final class JavaFileGenerator {
|
||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||
+ " while impl class file generation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add method for augment info's list.
|
||||
*/
|
||||
if (isHasAugmentationExtended(getExtendsList())) {
|
||||
methods.add(getAddAugmentInfoMethodImpl());
|
||||
methods.add(getAugmentInfoListImpl());
|
||||
methods.add(getRemoveAugmentationImpl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add methods in impl class.
|
||||
*/
|
||||
@ -310,7 +378,7 @@ public final class JavaFileGenerator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate class file for type def.
|
||||
* Generates class file for type def.
|
||||
*
|
||||
* @param file generated file
|
||||
* @param curNode current YANG node
|
||||
@ -363,11 +431,6 @@ public final class JavaFileGenerator {
|
||||
*/
|
||||
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode));
|
||||
|
||||
/**
|
||||
* Setter method.
|
||||
*/
|
||||
methods.add(((HasTempJavaCodeFragmentFiles) curNode).getTempJavaCodeFragmentFiles().addTypeDefsSetter());
|
||||
|
||||
/**
|
||||
* Hash code method.
|
||||
*/
|
||||
@ -388,7 +451,7 @@ public final class JavaFileGenerator {
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||
+ " while tyoe def class file generation");
|
||||
+ " while type def class file generation");
|
||||
}
|
||||
|
||||
for (String method : methods) {
|
||||
|
@ -23,6 +23,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
|
||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.AND;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
|
||||
@ -100,7 +102,6 @@ public final class MethodsGenerator {
|
||||
* @return method string for builder interface
|
||||
*/
|
||||
public static String parseBuilderInterfaceBuildMethodString(String name) {
|
||||
|
||||
return getJavaDoc(BUILD_METHOD, name, false) + getBuildForInterface(name);
|
||||
}
|
||||
|
||||
@ -142,7 +143,6 @@ public final class MethodsGenerator {
|
||||
* @return constructor string
|
||||
*/
|
||||
public static String getConstructorString(String name) {
|
||||
|
||||
return getJavaDoc(CONSTRUCTOR, name, false);
|
||||
}
|
||||
|
||||
@ -154,7 +154,6 @@ public final class MethodsGenerator {
|
||||
* @return default constructor string
|
||||
*/
|
||||
public static String getDefaultConstructorString(String name, String modifierType) {
|
||||
|
||||
return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false) + getDefaultConstructor(name, modifierType);
|
||||
}
|
||||
|
||||
@ -186,7 +185,6 @@ public final class MethodsGenerator {
|
||||
* @return setter for type def's attribute
|
||||
*/
|
||||
private static String getTypeDefConstructorString(String type, String name, String className) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
|
||||
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
|
||||
+ name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
|
||||
@ -200,7 +198,6 @@ public final class MethodsGenerator {
|
||||
* @return check not null string
|
||||
*/
|
||||
public 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;
|
||||
}
|
||||
@ -212,7 +209,6 @@ public final class MethodsGenerator {
|
||||
* @return build string
|
||||
*/
|
||||
public static String getBuildString(String name) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name);
|
||||
}
|
||||
|
||||
@ -242,7 +238,6 @@ public final class MethodsGenerator {
|
||||
* @return getter for attribute
|
||||
*/
|
||||
private static String getGetter(String type, String name) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name)
|
||||
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
|
||||
+ RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
|
||||
@ -275,7 +270,6 @@ public final class MethodsGenerator {
|
||||
* @return setter for attribute
|
||||
*/
|
||||
private static String getSetter(String className, String name, String type) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + SET_METHOD_PREFIX
|
||||
+ getCaptialCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
|
||||
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE
|
||||
@ -304,7 +298,6 @@ public final class MethodsGenerator {
|
||||
* @return setter for type def's attribute
|
||||
*/
|
||||
private static String getTypeDefSetter(String type, String name) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX + getCaptialCase(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
|
||||
@ -317,7 +310,6 @@ public final class MethodsGenerator {
|
||||
* @return override string
|
||||
*/
|
||||
public static String getOverRideString() {
|
||||
|
||||
return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
|
||||
}
|
||||
|
||||
@ -346,7 +338,6 @@ public final class MethodsGenerator {
|
||||
* @return getter for interface
|
||||
*/
|
||||
private static String getGetterInterfaceString(String returnType, String yangName) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCaptialCase(yangName)
|
||||
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
|
||||
}
|
||||
@ -378,7 +369,6 @@ public final class MethodsGenerator {
|
||||
* @return setter string
|
||||
*/
|
||||
private static String getSetterInterfaceString(String className, String attrName, String attrType) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName)
|
||||
+ OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
|
||||
}
|
||||
@ -389,7 +379,6 @@ public final class MethodsGenerator {
|
||||
* @return list string
|
||||
*/
|
||||
private static String getListString() {
|
||||
|
||||
return LIST + DIAMOND_OPEN_BRACKET;
|
||||
}
|
||||
|
||||
@ -416,7 +405,6 @@ public final class MethodsGenerator {
|
||||
* @return build method for interface
|
||||
*/
|
||||
public static String getBuildForInterface(String yangName) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
|
||||
+ NEW_LINE;
|
||||
}
|
||||
@ -462,7 +450,6 @@ public final class MethodsGenerator {
|
||||
* @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
|
||||
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE
|
||||
+ yangName + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
|
||||
@ -477,7 +464,6 @@ public final class MethodsGenerator {
|
||||
* @return Default constructor for class
|
||||
*/
|
||||
private static String getDefaultConstructor(String name, String modifierType) {
|
||||
|
||||
return FOUR_SPACE_INDENTATION + modifierType + SPACE + name + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
|
||||
+ OPEN_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
|
||||
}
|
||||
@ -488,7 +474,6 @@ public final class MethodsGenerator {
|
||||
* @return to string method open string
|
||||
*/
|
||||
public 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;
|
||||
@ -500,7 +485,6 @@ public final class MethodsGenerator {
|
||||
* @return to string method close string
|
||||
*/
|
||||
public 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;
|
||||
}
|
||||
@ -514,10 +498,8 @@ public final class MethodsGenerator {
|
||||
public static String getToStringMethod(JavaAttributeInfo attr) {
|
||||
|
||||
String attributeName = getSmallCase(attr.getAttributeName());
|
||||
|
||||
return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
|
||||
+ COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -526,7 +508,6 @@ public final class MethodsGenerator {
|
||||
* @return hash code method open string
|
||||
*/
|
||||
public 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;
|
||||
@ -539,7 +520,6 @@ public final class MethodsGenerator {
|
||||
* @return to hash code method close string
|
||||
*/
|
||||
public 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
|
||||
@ -553,7 +533,6 @@ public final class MethodsGenerator {
|
||||
* @return hash code method
|
||||
*/
|
||||
public static String getHashCodeMethod(JavaAttributeInfo attr) {
|
||||
|
||||
return getSmallCase(attr.getAttributeName()) + COMMA + SPACE;
|
||||
}
|
||||
|
||||
@ -564,7 +543,6 @@ public final class MethodsGenerator {
|
||||
* @return equals method open string
|
||||
*/
|
||||
public 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);
|
||||
@ -576,7 +554,6 @@ public final class MethodsGenerator {
|
||||
* @return if condition string
|
||||
*/
|
||||
private static String getEqualsMethodsCommonIfCondition() {
|
||||
|
||||
return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + THIS + SPACE + EQUAL + EQUAL + SPACE + OBJ
|
||||
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + SPACE
|
||||
+ TRUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
|
||||
@ -589,7 +566,6 @@ public final class MethodsGenerator {
|
||||
* @return if condition string
|
||||
*/
|
||||
private static String getEqualsMethodsSpecificIfCondition(String className) {
|
||||
|
||||
return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ + INSTANCE_OF + className
|
||||
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION + className
|
||||
+ SPACE + OTHER + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE
|
||||
@ -603,7 +579,6 @@ public final class MethodsGenerator {
|
||||
* @return equals method close string
|
||||
*/
|
||||
public static String getEqualsMethodClose(String equalMethodString) {
|
||||
|
||||
equalMethodString = trimAtLast(equalMethodString, AND);
|
||||
equalMethodString = trimAtLast(equalMethodString, AND);
|
||||
equalMethodString = trimAtLast(equalMethodString, SPACE);
|
||||
@ -622,11 +597,9 @@ public final class MethodsGenerator {
|
||||
public static String getEqualsMethod(JavaAttributeInfo attr) {
|
||||
|
||||
String attributeName = getSmallCase(attr.getAttributeName());
|
||||
|
||||
return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
|
||||
+ attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
|
||||
+ AND;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -639,11 +612,57 @@ public final class MethodsGenerator {
|
||||
public static String getOfMethod(String name, JavaAttributeInfo attr) {
|
||||
|
||||
String attrQuaifiedType = getReturnType(attr);
|
||||
|
||||
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS
|
||||
+ attrQuaifiedType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
|
||||
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name + OPEN_PARENTHESIS + VALUE
|
||||
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns implementation of add augmentation method of HasAugmentation class.
|
||||
*
|
||||
* @return implementation of add augmentation method of HasAugmentation class
|
||||
*/
|
||||
public static String getAddAugmentInfoMethodImpl() {
|
||||
String method = FOUR_SPACE_INDENTATION;
|
||||
method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING
|
||||
+ AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
|
||||
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
|
||||
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE
|
||||
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns implementation of get augment info list method of HasAugmentation class.
|
||||
*
|
||||
* @return implementation of get augment info list method of HasAugmentation class
|
||||
*/
|
||||
public static String getAugmentInfoListImpl() {
|
||||
|
||||
String method = FOUR_SPACE_INDENTATION;
|
||||
method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + LIST + DIAMOND_OPEN_BRACKET
|
||||
+ AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
|
||||
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
|
||||
+ RETURN + SPACE + getSmallCase(AUGMENTED_INFO) + LIST + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
|
||||
+ CLOSE_CURLY_BRACKET;
|
||||
return method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns implementation of remove augmentation method of HasAugmentation class.
|
||||
*
|
||||
* @return implementation of remove augmentation method of HasAugmentation class
|
||||
*/
|
||||
public static String getRemoveAugmentationImpl() {
|
||||
String method = FOUR_SPACE_INDENTATION;
|
||||
method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + "remove"
|
||||
+ AUGMENTATION + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
|
||||
+ EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST + OPEN_PARENTHESIS
|
||||
+ CLOSE_PARENTHESIS + PERIOD + "clear" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
|
||||
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
|
||||
return method;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright 2016-present Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
|
||||
|
||||
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport;
|
||||
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport;
|
||||
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForArrayList;
|
||||
import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForList;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
|
||||
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
|
||||
|
||||
/**
|
||||
* Represents utilities for temporary java code fragments.
|
||||
*/
|
||||
public final class TempJavaCodeFragmentFilesUtils {
|
||||
|
||||
/**
|
||||
* Creates a private instance of temporary java code fragment utils.
|
||||
*/
|
||||
private TempJavaCodeFragmentFilesUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds imports for ToString and HashCodeMethod.
|
||||
*
|
||||
* @param curNode current YANG node
|
||||
* @param imports import list
|
||||
* @return import list
|
||||
*/
|
||||
public static List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) {
|
||||
if (curNode instanceof HasJavaImportData) {
|
||||
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals());
|
||||
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString());
|
||||
}
|
||||
return imports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds import for HasAugmentation class.
|
||||
*
|
||||
* @param curNode current YANG node
|
||||
* @param imports list of imports
|
||||
* @param operation add or delete import
|
||||
* @return import for HasAugmentation class
|
||||
*/
|
||||
public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports, boolean operation) {
|
||||
if (curNode instanceof HasJavaImportData) {
|
||||
String thisImport = getHasAugmentationImport();
|
||||
performOperationOnImports(imports, thisImport, operation);
|
||||
}
|
||||
return imports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds import for AugmentedInfo class.
|
||||
*
|
||||
* @param curNode current YANG node
|
||||
* @param imports list of imports
|
||||
* @param operation add or delete import
|
||||
* @return import for AugmentedInfo class
|
||||
*/
|
||||
public static List<String> addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
|
||||
if (curNode instanceof HasJavaImportData) {
|
||||
String thisImport = getAugmentedInfoImport();
|
||||
performOperationOnImports(imports, thisImport, operation);
|
||||
}
|
||||
return imports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds import for array list.
|
||||
*
|
||||
* @param curNode current YANG node
|
||||
* @param imports list of imports
|
||||
* @param operation add or delete import
|
||||
* @return import for HasAugmentation class
|
||||
*/
|
||||
public static List<String> addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
|
||||
if (curNode instanceof HasJavaImportData) {
|
||||
String arrayListImport = getImportForArrayList();
|
||||
String listImport = getImportForList();
|
||||
performOperationOnImports(imports, arrayListImport, operation);
|
||||
if (!imports.contains(listImport)) {
|
||||
/**
|
||||
* List can be there because of attribute also , so no need to remove it and operation will
|
||||
* always be add(true).
|
||||
*/
|
||||
performOperationOnImports(imports, listImport, true);
|
||||
}
|
||||
}
|
||||
|
||||
return imports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs given operations on import list.
|
||||
*
|
||||
* @param imports list of imports
|
||||
* @param curImport current import
|
||||
* @param operation add or remove
|
||||
* @return import list
|
||||
*/
|
||||
private static List<String> performOperationOnImports(List<String> imports, String curImport, boolean operation) {
|
||||
if (operation) {
|
||||
imports.add(curImport);
|
||||
} else {
|
||||
imports.remove(curImport);
|
||||
}
|
||||
java.util.Collections.sort(imports);
|
||||
return imports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares java file generator for extends list.
|
||||
*
|
||||
* @param extendsList list of classes need to be extended
|
||||
*/
|
||||
public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) {
|
||||
|
||||
if (!extendsList.isEmpty() && !extendsList.equals(null)) {
|
||||
JavaFileGenerator.setExtendsList(extendsList);
|
||||
JavaFileGenerator.setIsExtendsList(true);
|
||||
} else {
|
||||
JavaFileGenerator.getExtendsList().clear();
|
||||
JavaFileGenerator.setIsExtendsList(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if HasAugmentation class needs to be extended.
|
||||
*
|
||||
* @param extendsList list of classes need to be extended
|
||||
* @return true or false
|
||||
*/
|
||||
public static boolean isHasAugmentationExtended(List<String> extendsList) {
|
||||
if (extendsList != null && extendsList.contains(HAS_AUGMENTATION)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if AugmentedInfo class needs to be extended.
|
||||
*
|
||||
* @param extendsList list of classes need to be extended
|
||||
* @return true or false
|
||||
*/
|
||||
public static boolean isAugmentedInfoExtended(List<String> extendsList) {
|
||||
if (extendsList != null && extendsList.contains(AUGMENTED_INFO)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the file handle for temporary file.
|
||||
*
|
||||
* @param file file to be closed
|
||||
* @param toBeDeleted flag to indicate if file needs to be deleted
|
||||
* @throws IOException when failed to close the file handle
|
||||
*/
|
||||
public static void closeFile(File file, boolean toBeDeleted) throws IOException {
|
||||
|
||||
if (file != null) {
|
||||
updateFileHandle(file, null, true);
|
||||
if (toBeDeleted) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,8 +17,17 @@
|
||||
package org.onosproject.yangutils.translator.tojava.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangAugment;
|
||||
import org.onosproject.yangutils.datamodel.YangCase;
|
||||
import org.onosproject.yangutils.datamodel.YangChoice;
|
||||
import org.onosproject.yangutils.datamodel.YangContainer;
|
||||
import org.onosproject.yangutils.datamodel.YangInput;
|
||||
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
|
||||
import org.onosproject.yangutils.datamodel.YangList;
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.datamodel.YangNotification;
|
||||
import org.onosproject.yangutils.datamodel.YangOutput;
|
||||
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
|
||||
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
|
||||
|
||||
@ -26,6 +35,8 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
|
||||
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.UtilConstants.AUGMENTED_INFO;
|
||||
import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
|
||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
|
||||
|
||||
/**
|
||||
@ -143,6 +154,21 @@ public final class YangJavaModelUtils {
|
||||
|
||||
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
|
||||
.addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
|
||||
|
||||
/**
|
||||
* For augmentation of nodes.
|
||||
*/
|
||||
if (javaCodeGeneratorInfo instanceof YangContainer
|
||||
|| javaCodeGeneratorInfo instanceof YangCase
|
||||
|| javaCodeGeneratorInfo instanceof YangChoice
|
||||
|| javaCodeGeneratorInfo instanceof YangInput
|
||||
|| javaCodeGeneratorInfo instanceof YangList
|
||||
|| javaCodeGeneratorInfo instanceof YangNotification
|
||||
|| javaCodeGeneratorInfo instanceof YangOutput) {
|
||||
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(HAS_AUGMENTATION);
|
||||
} else if (javaCodeGeneratorInfo instanceof YangAugment) {
|
||||
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -441,58 +441,69 @@ public final class UtilConstants {
|
||||
* String built in java type.
|
||||
*/
|
||||
public static final String STRING_DATA_TYPE = "String";
|
||||
|
||||
/**
|
||||
* java.lang.* packages.
|
||||
* Java.lang.* packages.
|
||||
*/
|
||||
public static final String JAVA_LANG = "java.lang";
|
||||
|
||||
/**
|
||||
* boolean built in java type.
|
||||
* Java.math.* packages.
|
||||
*/
|
||||
public static final String JAVA_MATH = "java.math";
|
||||
|
||||
/**
|
||||
* Boolean built in java type.
|
||||
*/
|
||||
public static final String BOOLEAN_DATA_TYPE = "boolean";
|
||||
|
||||
/**
|
||||
* byte java built in type.
|
||||
* BigInteger built in java type.
|
||||
*/
|
||||
public static final String BIG_INTEGER = "BigInteger";
|
||||
|
||||
/**
|
||||
* Byte java built in type.
|
||||
*/
|
||||
public static final String BYTE = "byte";
|
||||
|
||||
/**
|
||||
* short java built in type.
|
||||
* Short java built in type.
|
||||
*/
|
||||
public static final String SHORT = "short";
|
||||
|
||||
/**
|
||||
* int java built in type.
|
||||
* Int java built in type.
|
||||
*/
|
||||
public static final String INT = "int";
|
||||
|
||||
/**
|
||||
* long java built in type.
|
||||
* Long java built in type.
|
||||
*/
|
||||
public static final String LONG = "long";
|
||||
|
||||
/**
|
||||
* float java built in type.
|
||||
* Float java built in type.
|
||||
*/
|
||||
public static final String FLOAT = "float";
|
||||
|
||||
/**
|
||||
* double java built in type.
|
||||
* Double java built in type.
|
||||
*/
|
||||
public static final String DOUBLE = "double";
|
||||
|
||||
/**
|
||||
* boolean built in java wrapper type.
|
||||
* Boolean built in java wrapper type.
|
||||
*/
|
||||
public static final String BOOLEAN_WRAPPER = "Boolean";
|
||||
|
||||
/**
|
||||
* byte java built in wrapper type.
|
||||
* Byte java built in wrapper type.
|
||||
*/
|
||||
public static final String BYTE_WRAPPER = "Byte";
|
||||
|
||||
/**
|
||||
* short java built in wrapper type.
|
||||
* Short java built in wrapper type.
|
||||
*/
|
||||
public static final String SHORT_WRAPPER = "Short";
|
||||
|
||||
@ -502,17 +513,17 @@ public final class UtilConstants {
|
||||
public static final String INTEGER_WRAPPER = "Integer";
|
||||
|
||||
/**
|
||||
* long java built in wrapper type.
|
||||
* Long java built in wrapper type.
|
||||
*/
|
||||
public static final String LONG_WRAPPER = "Long";
|
||||
|
||||
/**
|
||||
* float java built in wrapper type.
|
||||
* Float java built in wrapper type.
|
||||
*/
|
||||
public static final String FLOAT_WRAPPER = "Float";
|
||||
|
||||
/**
|
||||
* double java built in wrapper type.
|
||||
* Double java built in wrapper type.
|
||||
*/
|
||||
public static final String DOUBLE_WRAPPER = "Double";
|
||||
|
||||
@ -686,6 +697,41 @@ public final class UtilConstants {
|
||||
*/
|
||||
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
|
||||
|
||||
/**
|
||||
* Static attribute for HasAugmentation class import package.
|
||||
*/
|
||||
public static final String HAS_AUGMENTATION_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava";
|
||||
|
||||
/**
|
||||
* Static attribute for HasAugmentation class import class.
|
||||
*/
|
||||
public static final String HAS_AUGMENTATION_CLASS_IMPORT_CLASS = "HasAugmentation;\n";
|
||||
|
||||
/**
|
||||
* Static attribute for AugmentedInfo class import package.
|
||||
*/
|
||||
public static final String AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava";
|
||||
|
||||
/**
|
||||
* Static attribute for AugmentedInfo class import class.
|
||||
*/
|
||||
public static final String AUGMENTED_INFO_CLASS_IMPORT_CLASS = "AugmentedInfo;\n";
|
||||
|
||||
/**
|
||||
* Static attribute for augmentation class.
|
||||
*/
|
||||
public static final String AUGMENTATION = "Augmentation";
|
||||
|
||||
/**
|
||||
* Static attribute for HasAugmentation class.
|
||||
*/
|
||||
public static final String HAS_AUGMENTATION = "HasAugmentation";
|
||||
|
||||
/**
|
||||
* Static attribute for AugmentedInfo class.
|
||||
*/
|
||||
public static final String AUGMENTED_INFO = "AugmentedInfo";
|
||||
|
||||
/**
|
||||
* Static attribute for abstract collection.
|
||||
*/
|
||||
|
@ -21,12 +21,19 @@ import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.onosproject.yangutils.datamodel.YangDataTypes;
|
||||
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.datamodel.YangType;
|
||||
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
|
||||
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
|
||||
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
|
||||
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.BOOLEAN;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
|
||||
import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8;
|
||||
@ -44,11 +51,13 @@ public class AttributesJavaDataTypeTest {
|
||||
private static final YangDataTypes TYPE2 = INT32;
|
||||
private static final YangDataTypes TYPE3 = BOOLEAN;
|
||||
private static final YangDataTypes TYPE4 = UINT8;
|
||||
private static final YangDataTypes TYPE_DEF = DERIVED;
|
||||
private static final String CLASS_INFO1 = "String";
|
||||
private static final String CLASS_INFO2 = "int";
|
||||
private static final String CLASS_INFO3 = "boolean";
|
||||
private static final String CLASS_INFO4 = "short";
|
||||
private static final String CLASS_INFO5 = "Integer";
|
||||
private static final String TYPE_DEF_PKG = "target.test";
|
||||
private static String test = "";
|
||||
|
||||
/**
|
||||
@ -127,6 +136,17 @@ public class AttributesJavaDataTypeTest {
|
||||
assertThat(null, is(test));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit test case for typedef.
|
||||
*
|
||||
* @throws DataModelException when fails to do data model operations
|
||||
*/
|
||||
@Test
|
||||
public void testForTypeDef() throws DataModelException {
|
||||
test = getJavaImportPackage(getStubExtendedInfo(getStubYangType(TYPE_DEF)), false, TYPE_DEF_PKG);
|
||||
assertThat(true, is(test.equals(TYPE_DEF_PKG)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns stub YANG type for test.
|
||||
*
|
||||
@ -134,8 +154,48 @@ public class AttributesJavaDataTypeTest {
|
||||
* @return YANG type
|
||||
*/
|
||||
private YangType<?> getStubYangType(YangDataTypes dataTypes) {
|
||||
YangType<?> type = new YangType();
|
||||
YangType<?> type = new YangType<>();
|
||||
type.setDataType(dataTypes);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns YANG type with extended info.
|
||||
*
|
||||
* @param type YANG type
|
||||
* @return YANG type with extended info
|
||||
* @throws DataModelException when fails to do data model operations
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private YangType<?> getStubExtendedInfo(YangType<?> type) throws DataModelException {
|
||||
YangJavaTypeDef typedef = new YangJavaTypeDef();
|
||||
getStubParent().addChild(typedef);
|
||||
YangDerivedInfo<?> derInfo = new YangDerivedInfo<>();
|
||||
derInfo.setReferredTypeDef(typedef);
|
||||
((YangType<YangDerivedInfo<?>>) type).setDataTypeExtendedInfo(derInfo);
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns java file info.
|
||||
*
|
||||
* @return java file info
|
||||
*/
|
||||
private JavaFileInfo addStubJavaFileInfo() {
|
||||
JavaFileInfo fileInfo = new JavaFileInfo();
|
||||
fileInfo.setJavaName("test");
|
||||
fileInfo.setPackage("target");
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds stub parent module for typedef.
|
||||
*
|
||||
* @return stub parent module
|
||||
*/
|
||||
private YangNode getStubParent() {
|
||||
YangJavaModule parent = new YangJavaModule();
|
||||
parent.setJavaFileInfo(addStubJavaFileInfo());
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user