Adding builder and operation type in generated interfaces
Change-Id: I0c3ed6f01a8f933ad91ce1a46aeebc62029ca47a
diff --git a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java
index 91df3f7..cb0be7b 100644
--- a/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java
+++ b/datamodel/src/main/java/org/onosproject/yangutils/datamodel/YangSchemaNode.java
@@ -16,15 +16,15 @@
package org.onosproject.yangutils.datamodel;
-import java.util.Map;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import java.util.Map;
+
/**
* Abstraction of YANG data node, used by YMS to abstractly refer the data
* nodes in YANG data tree.
*/
-public interface YangSchemaNode {
+public interface YangSchemaNode extends LocationInfo {
/**
* Returns type of YANG schema node.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
index 5451ea3..6f61e10 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
@@ -24,141 +24,139 @@
/**
* Attributes definition temporary file.
*/
- public static final int ATTRIBUTES_MASK = 1; //0x1
+ public static final int ATTRIBUTES_MASK = 1; // 1 << 0
/**
* Getter methods for interface.
*/
- public static final int GETTER_FOR_INTERFACE_MASK = 2; //0x2
+ public static final int GETTER_FOR_INTERFACE_MASK = 1 << 1;
/**
* Getter methods for class.
*/
- public static final int GETTER_FOR_CLASS_MASK = 4; //0x4
+ public static final int GETTER_FOR_CLASS_MASK = 1 << 2;
/**
* Setter methods for interface.
*/
- public static final int SETTER_FOR_INTERFACE_MASK = 8; //0x8
+ public static final int SETTER_FOR_INTERFACE_MASK = 1 << 3;
/**
* Setter methods for class.
*/
- public static final int SETTER_FOR_CLASS_MASK = 16; //0x10
+ public static final int SETTER_FOR_CLASS_MASK = 1 << 4;
/**
* Constructor method of class.
*/
- public static final int CONSTRUCTOR_IMPL_MASK = 32; //0x20
+ public static final int CONSTRUCTOR_IMPL_MASK = 1 << 5;
/**
* Hash code implementation of class.
*/
- public static final int HASH_CODE_IMPL_MASK = 64; //0X40
+ public static final int HASH_CODE_IMPL_MASK = 1 << 6;
/**
* Equals implementation of class.
*/
- public static final int EQUALS_IMPL_MASK = 128; //0x80
+ public static final int EQUALS_IMPL_MASK = 1 << 7;
/**
* To string implementation of class.
*/
- public static final int TO_STRING_IMPL_MASK = 256; //0x100
+ public static final int TO_STRING_IMPL_MASK = 1 << 8;
/**
* Of string implementation of class.
*/
- public static final int OF_STRING_IMPL_MASK = 512; //0x200
+ public static final int OF_STRING_IMPL_MASK = 1 << 9;
/**
* Constructor for type class like typedef, union.
*/
- public static final int CONSTRUCTOR_FOR_TYPE_MASK = 1024; //0x400
+ public static final int CONSTRUCTOR_FOR_TYPE_MASK = 1 << 10;
/**
* From string implementation of class.
*/
- public static final int FROM_STRING_IMPL_MASK = 2048; //0x800
+ public static final int FROM_STRING_IMPL_MASK = 1 << 11;
/**
* Enum implementation of class.
*/
- public static final int ENUM_IMPL_MASK = 4096; //0x1000
+ public static final int ENUM_IMPL_MASK = 1 << 12;
/**
* Rpc interface of module / sub module.
*/
- public static final int RPC_INTERFACE_MASK = 8192; //0x2000
+ public static final int RPC_INTERFACE_MASK = 1 << 13;
/**
* Rpc implementation of module / sub module.
*/
- public static final int RPC_IMPL_MASK = 16384; //0x4000
+ public static final int RPC_IMPL_MASK = 1 << 14;
/**
* Event enum implementation of class.
*/
- public static final int EVENT_ENUM_MASK = 32768; //0X8000
+ public static final int EVENT_ENUM_MASK = 1 << 15;
/**
* Event method implementation of class.
*/
- public static final int EVENT_METHOD_MASK = 65536; //0x10000
+ public static final int EVENT_METHOD_MASK = 1 << 16;
/**
* Event subject attribute implementation of class.
*/
- public static final int EVENT_SUBJECT_ATTRIBUTE_MASK = 131072; //0X20000
+ public static final int EVENT_SUBJECT_ATTRIBUTE_MASK = 1 << 17;
/**
* Event subject getter implementation of class.
*/
- public static final int EVENT_SUBJECT_GETTER_MASK = 262144; //0x40000
+ public static final int EVENT_SUBJECT_GETTER_MASK = 1 << 18;
/**
* Event subject setter implementation of class.
*/
- public static final int EVENT_SUBJECT_SETTER_MASK = 524288; //80000
+ public static final int EVENT_SUBJECT_SETTER_MASK = 1 << 19;
/**
* Add to list method interface for class.
*/
- public static final int ADD_TO_LIST_INTERFACE_MASK = 1048576; //0X100000
+ public static final int ADD_TO_LIST_INTERFACE_MASK = 1 << 20;
/**
* Add to list method implementation for class.
*/
- public static final int ADD_TO_LIST_IMPL_MASK = 2097152; //0X200000
+ public static final int ADD_TO_LIST_IMPL_MASK = 1 << 21;
/**
* Leaf identifier enum attributes for class.
*/
- public static final int LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK = 4194304; //0X400000
+ public static final int LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK = 1 << 22;
/**
* Is filter content match for leaves class.
*/
- public static final int FILTER_CONTENT_MATCH_FOR_LEAF_MASK = 8388608; //0X800000
+ public static final int FILTER_CONTENT_MATCH_FOR_LEAF_MASK = 1 << 23;
/**
* Is filter content match for leaf lists class.
*/
- public static final int FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK = 16777216; //0X1000000
+ public static final int FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK = 1 << 24;
/**
* Is filter content match for nodes class.
*/
- public static final int FILTER_CONTENT_MATCH_FOR_NODES_MASK = 33554432; //0X2000000
+ public static final int FILTER_CONTENT_MATCH_FOR_NODES_MASK = 1 << 25;
/**
* Edit config class content for class.
*/
- public static final int EDIT_CONTENT_MASK = 67108864; //0X4000000
+ public static final int EDIT_CONTENT_MASK = 1 << 26;
- /**
- * Creates an instance of generated temp file type.
- */
+ // No instantiation.
private GeneratedTempFileType() {
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index 756062d..aba6454 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -15,10 +15,7 @@
*/
package org.onosproject.yangutils.translator.tojava;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
+import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
@@ -27,9 +24,8 @@
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
@@ -37,6 +33,10 @@
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
@@ -90,12 +90,15 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getSubtreeFilteringForLeaf;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getSubtreeFilteringForLeafList;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getSubtreeFilteringForNode;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForNode;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_LEAF_HOLDER;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.MISSING_PARENT_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
@@ -104,12 +107,15 @@
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_ATTRIBUTE;
+import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
+import static org.onosproject.yangutils.utils.UtilConstants.YANG;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
@@ -125,8 +131,8 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
/**
- * Represents implementation of java code fragments temporary implementations. Manages the common temp file required for
- * Java file(s) generated.
+ * Represents implementation of java code fragments temporary implementations.
+ * Manages the common temp file required for Java file(s) generated.
*/
public class TempJavaFragmentFiles {
@@ -158,12 +164,14 @@
/**
* File name for getter method implementation.
*/
- private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
+ private static final String GETTER_METHOD_IMPL_FILE_NAME =
+ "GetterMethodImpl";
/**
* File name for setter method implementation.
*/
- private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
+ private static final String SETTER_METHOD_IMPL_FILE_NAME =
+ "SetterMethodImpl";
/**
* File name for attributes.
@@ -193,32 +201,38 @@
/**
* File name for from add to list interface method.
*/
- private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME = "addToList";
+ private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME =
+ "addToList";
/**
* File name for from add to list impl method.
*/
- private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME = "addToListImpl";
+ private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME =
+ "addToListImpl";
/**
* File name for from leaf identifier attributes.
*/
- private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME = "leafIdentifierAtr";
+ private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME =
+ "leafIdentifierAtr";
/**
* File name for is filter content leaf match.
*/
- private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME = "isFilterContentMatchLeafMask";
+ private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME =
+ "isFilterContentMatchLeafMask";
/**
* File name for is filter content leaf-list match.
*/
- private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME = "isFilterContentMatchLeafListMask";
+ private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME =
+ "isFilterContentMatchLeafListMask";
/**
* File name for is filter content node match.
*/
- private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME = "isFilterContentMatchNodeMask";
+ private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME =
+ "isFilterContentMatchNodeMask";
/**
* File name for edit content file.
@@ -233,7 +247,8 @@
/**
* File name for builder interface file name suffix.
*/
- private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX = BUILDER + INTERFACE;
+ private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX =
+ BUILDER + INTERFACE;
/**
* File name for builder class file name suffix.
@@ -251,9 +266,10 @@
private JavaImportData javaImportData;
/**
- * The variable which guides the types of temporary files generated using the temporary generated file types mask.
+ * The variable which guides the types of temporary files generated using
+ * the temporary generated file types mask.
*/
- private int generatedTempFiles;
+ private int tempFilesFlagSet;
/**
* Absolute path where the target java file needs to be generated.
@@ -261,7 +277,8 @@
private String absoluteDirPath;
/**
- * Contains all the interface(s)/class name which will be extended by generated files.
+ * Contains all the interface(s)/class name which will be extended by
+ * generated files.
*/
private JavaExtendsListHolder javaExtendsListHolder;
@@ -373,13 +390,16 @@
/**
* If current node is root node.
*/
- private boolean isRooNode;
+ private boolean rootNode;
/**
* Is attribute added.
*/
private boolean isAttributePresent;
+ /**
+ * Creates an instance of temp JAVA fragment files.
+ */
TempJavaFragmentFiles() {
}
@@ -389,228 +409,234 @@
* @param javaFileInfo generated java file information
* @throws IOException when fails to create new file handle
*/
- TempJavaFragmentFiles(JavaFileInfoTranslator javaFileInfo)
+ protected TempJavaFragmentFiles(JavaFileInfoTranslator javaFileInfo)
throws IOException {
- setJavaExtendsListHolder(new JavaExtendsListHolder());
- setJavaImportData(new JavaImportData());
- setJavaFileInfo(javaFileInfo);
- setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
-
+ javaExtendsListHolder = new JavaExtendsListHolder();
+ javaImportData = new JavaImportData();
+ this.javaFileInfo = javaFileInfo;
+ absoluteDirPath =
+ getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(),
+ javaFileInfo.getPackageFilePath());
/*
* Initialize getter when generation file type matches to interface
* mask.
*/
- if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
- addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
- addGeneratedTempFile(ADD_TO_LIST_INTERFACE_MASK);
- addGeneratedTempFile(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
+ if (javaFlagSet(INTERFACE_MASK)) {
+ addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
+ ADD_TO_LIST_INTERFACE_MASK |
+ LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
}
-
/*
* Initialize getter and setter when generation file type matches to
* builder interface mask.
*/
- if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
- addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
- addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
+ if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
+ addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
+ SETTER_FOR_INTERFACE_MASK);
}
-
/*
* Initialize getterImpl, setterImpl and attributes when generation file
* type matches to builder class mask.
*/
- if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
- addGeneratedTempFile(ATTRIBUTES_MASK);
- addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
+ if (javaFlagSet(BUILDER_CLASS_MASK)) {
+ addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
+ SETTER_FOR_CLASS_MASK);
}
-
/*
* Initialize getterImpl, attributes, constructor, hash code, equals and
* to strings when generation file type matches to impl class mask.
*/
- if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
- addGeneratedTempFile(ATTRIBUTES_MASK);
- addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(HASH_CODE_IMPL_MASK);
- addGeneratedTempFile(EQUALS_IMPL_MASK);
- addGeneratedTempFile(TO_STRING_IMPL_MASK);
- addGeneratedTempFile(ADD_TO_LIST_IMPL_MASK);
- addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK);
- addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_LEAF_MASK);
- addGeneratedTempFile(FILTER_CONTENT_MATCH_FOR_NODES_MASK);
+ if (javaFlagSet(DEFAULT_CLASS_MASK)) {
+ addGeneratedTempFile(
+ ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
+ HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
+ TO_STRING_IMPL_MASK | ADD_TO_LIST_IMPL_MASK |
+ FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK |
+ FILTER_CONTENT_MATCH_FOR_LEAF_MASK |
+ FILTER_CONTENT_MATCH_FOR_NODES_MASK);
}
-
/*
* Initialize temp files to generate type class.
*/
- if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
- addGeneratedTempFile(ATTRIBUTES_MASK);
- addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
- addGeneratedTempFile(HASH_CODE_IMPL_MASK);
- addGeneratedTempFile(EQUALS_IMPL_MASK);
- addGeneratedTempFile(TO_STRING_IMPL_MASK);
- addGeneratedTempFile(FROM_STRING_IMPL_MASK);
+ if (javaFlagSet(GENERATE_TYPE_CLASS)) {
+ addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
+ HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
+ TO_STRING_IMPL_MASK |
+ FROM_STRING_IMPL_MASK);
}
-
//Initialize temp files to generate enum class.
- if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
+ if (javaFlagSet(GENERATE_ENUM_CLASS)) {
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
}
-
//Set temporary file handles
- if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
- setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
+ if (tempFlagSet(ATTRIBUTES_MASK)) {
+ attributesTempFileHandle =
+ getTemporaryFileHandle(ATTRIBUTE_FILE_NAME);
}
- if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
- setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
+ if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
+ getterInterfaceTempFileHandle =
+ getTemporaryFileHandle(GETTER_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
- setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
+ if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
+ setterInterfaceTempFileHandle =
+ getTemporaryFileHandle(SETTER_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
- setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
+ if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
+ getterImplTempFileHandle =
+ getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME);
}
- if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
- setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
+ if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
+ setterImplTempFileHandle =
+ getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME);
}
- if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
- setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
+ if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
+ hashCodeImplTempFileHandle =
+ getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
- setEqualsImplTempFileHandle(getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME));
+ if (tempFlagSet(EQUALS_IMPL_MASK)) {
+ equalsImplTempFileHandle =
+ getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
- setToStringImplTempFileHandle(getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME));
+ if (tempFlagSet(TO_STRING_IMPL_MASK)) {
+ toStringImplTempFileHandle =
+ getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
- setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
+ if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
+ fromStringImplTempFileHandle =
+ getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
- setAddToListInterfaceTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME));
+ if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
+ addToListInterfaceTempFileHandle =
+ getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
- setAddToListImplTempFileHandle(getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME));
+ if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
+ addToListImplTempFileHandle =
+ getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME);
}
- if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
- setLeafIdAttributeTempFileHandle(getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME));
+ if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
+ leafIdAttributeTempFileHandle =
+ getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
- setSubtreeFilteringForLeafTempFileHandle(getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME));
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
+ subtreeFilteringForLeafTempFileHandle =
+ getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
- setGetSubtreeFilteringForListTempFileHandle(
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME));
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
+ getSubtreeFilteringForListTempFileHandle =
+ getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
- setGetSubtreeFilteringForChildNodeTempFileHandle(
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME));
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
+ getSubtreeFilteringForChildNodeTempFileHandle =
+ getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME);
}
- if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
- setEditContentTempFileHandle(getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME));
+ if (tempFlagSet(EDIT_CONTENT_MASK)) {
+ editContentTempFileHandle =
+ getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME);
}
}
/**
* Adds current node info as and attribute to the parent generated file.
*
- * @param curNode current node which needs to be added as an attribute in the parent generated code
- * @param isList is list construct
- * @param pluginConfig plugin configurations
+ * @param curNode current node
+ * @param isList is list construct
+ * @param config plugin configurations
* @throws IOException IO operation exception
*/
- static void addCurNodeInfoInParentTempFile(YangNode curNode,
- boolean isList, YangPluginConfig pluginConfig)
+ protected static void addCurNodeInfoInParentTempFile(YangNode curNode,
+ boolean isList,
+ YangPluginConfig config)
throws IOException {
YangNode parent = getParentNodeInGenCode(curNode);
if (!(parent instanceof JavaCodeGenerator)) {
- throw new TranslatorException("missing parent node to contain current node info in generated file "
- + parent.getName() + " in " + parent.getLineNumber() + " at " +
- parent.getCharPosition()
- + " in " + parent.getFileName());
+ throw new TranslatorException(getErrorMsg(MISSING_PARENT_NODE,
+ curNode));
}
-
if (parent instanceof YangJavaGroupingTranslator) {
/*
* In case of grouping, there is no need to add the information, it
- * will be taken care in uses
+ * will be taken care in uses.
*/
return;
}
+ TempJavaBeanFragmentFiles tempFiles =
+ getBeanFiles((JavaCodeGeneratorInfo) parent);
- TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) parent)
- .getTempJavaCodeFragmentFiles().getBeanTempFiles();
-
- JavaAttributeInfo javaAttributeInfo = getCurNodeAsAttributeInTarget(curNode,
- parent, isList, tempJavaBeanFragmentFiles);
- tempJavaBeanFragmentFiles.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo, pluginConfig);
+ JavaAttributeInfo attr =
+ getCurNodeAsAttributeInTarget(curNode, parent, isList,
+ tempFiles);
+ tempFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
}
/**
- * Creates an attribute info object corresponding to a data model node and return it.
+ * Creates an attribute info object corresponding to a data model node
+ * and return it.
*
- * @param curNode current data model node for which the java code generation is being handled
- * @param targetNode target node in which the current node is an attribute
- * @param isListNode is the current added attribute needs to be a list
- * @param tempJavaFragmentFiles temp java fragment files
- * @return AttributeInfo attribute details required to add in temporary files
+ * @param curNode current node
+ * @param targetNode target node
+ * @param listNode flag indicating if a node is a list node
+ * @param tempFiles temp java fragment files
+ * @return java attribute info
*/
- public static JavaAttributeInfo getCurNodeAsAttributeInTarget(YangNode curNode,
- YangNode targetNode, boolean isListNode,
- TempJavaFragmentFiles tempJavaFragmentFiles) {
- String curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
+ public static JavaAttributeInfo
+ getCurNodeAsAttributeInTarget(YangNode curNode, YangNode targetNode,
+ boolean listNode,
+ TempJavaFragmentFiles tempFiles) {
+ JavaFileInfoTranslator translator =
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ String curNodeName = translator.getJavaName();
if (curNodeName == null) {
updateJavaFileInfo(curNode, null);
- curNodeName = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName();
+ curNodeName = translator.getJavaName();
}
-
/*
* Get the import info corresponding to the attribute for import in
- * generated java files or qualified access
+ * generated java files or qualified access.
*/
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
- getCapitalCase(curNodeName));
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ getQualifiedTypeInfoOfCurNode(curNode,
+ getCapitalCase(curNodeName));
if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException("Parent node does not have file info "
- + targetNode.getName() + " in " + targetNode.getLineNumber() +
- " at " + targetNode.getCharPosition()
- + " in " + targetNode.getFileName());
+ throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
+ curNode));
}
- JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
+ JavaImportData parentImportData = tempFiles.getJavaImportData();
+ JavaFileInfoTranslator fileInfo =
+ ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
- boolean isQualified;
- if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles)
- && (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE))
- || qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(fileInfo.getJavaName() + SERVICE))) {
-
- isQualified = true;
+ boolean qualified;
+ if ((tempFiles instanceof TempJavaServiceFragmentFiles) &&
+ (typeInfo.getClassInfo().contentEquals(SERVICE)) ||
+ typeInfo.getClassInfo()
+ .contentEquals(getCapitalCase(fileInfo.getJavaName() +
+ SERVICE))) {
+ qualified = true;
} else {
String className;
- if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
+ if (tempFiles instanceof TempJavaServiceFragmentFiles) {
className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
} else {
className = getCapitalCase(fileInfo.getJavaName());
}
-
- isQualified = parentImportData.addImportInfo(qualifiedTypeInfo,
- className, fileInfo.getPackage());
+ qualified = parentImportData.addImportInfo(typeInfo, className,
+ fileInfo.getPackage());
}
- boolean collectionSetFlag = false;
+ boolean collectionSet = false;
if (curNode instanceof YangList) {
YangList yangList = (YangList) curNode;
- if (yangList.getCompilerAnnotation() != null && yangList.getCompilerAnnotation()
- .getYangAppDataStructure() != null) {
- switch (yangList.getCompilerAnnotation().getYangAppDataStructure().getDataStructure()) {
+ if (yangList.getCompilerAnnotation() != null &&
+ yangList.getCompilerAnnotation()
+ .getYangAppDataStructure() != null) {
+ switch (yangList.getCompilerAnnotation()
+ .getYangAppDataStructure().getDataStructure()) {
case QUEUE: {
parentImportData.setQueueToImport(true);
- collectionSetFlag = true;
+ collectionSet = true;
break;
}
case SET: {
parentImportData.setSetToImport(true);
- collectionSetFlag = true;
+ collectionSet = true;
break;
}
default: {
@@ -619,84 +645,81 @@
}
}
}
- if (isListNode && !(collectionSetFlag)) {
+ if (listNode && !(collectionSet)) {
parentImportData.setIfListImported(true);
}
if (curNode instanceof YangList) {
- return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode,
- ((YangList) curNode).getCompilerAnnotation());
+ return getAttributeInfoForTheData(typeInfo, curNodeName,
+ null, qualified, listNode,
+ ((YangList) curNode)
+ .getCompilerAnnotation());
}
- return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
+ return getAttributeInfoForTheData(typeInfo, curNodeName, null,
+ qualified, listNode);
}
/**
* Returns java attribute for leaf.
*
- * @param tempJavaFragmentFiles temporary generated file
- * @param leaf YANG leaf
- * @param yangPluginConfig plugin configurations
- * @return java attribute for leaf
+ * @param tempFiles temporary generated file
+ * @param container JAVA leaf info container
+ * @param config plugin configurations
+ * @param leafList flag indicating if it's leaf list
+ * @return java attribute info
*/
- private static JavaAttributeInfo getJavaAttributeOfLeaf(TempJavaFragmentFiles tempJavaFragmentFiles, YangLeaf leaf,
- YangPluginConfig yangPluginConfig) {
- JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leaf;
- javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
- javaLeaf.updateJavaQualifiedInfo();
- return getAttributeInfoForTheData(
- javaLeaf.getJavaQualifiedInfo(),
- javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
- javaLeaf.getDataType(),
- tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
- false);
+ private static JavaAttributeInfo
+ getJavaAttributeOfLeaf(TempJavaFragmentFiles tempFiles,
+ JavaLeafInfoContainer container,
+ YangPluginConfig config, boolean leafList) {
+ if (leafList) {
+ tempFiles.getJavaImportData().setIfListImported(true);
+ return getAttributeOfLeafInfoContainer(tempFiles, container, config,
+ true);
+ }
+ return getAttributeOfLeafInfoContainer(tempFiles, container, config,
+ false);
}
/**
- * Returns java attribute for leaf-list.
+ * Returns java attribute for leaf container.
*
- * @param tempJavaFragmentFiles temporary generated file
- * @param leafList YANG leaf-list
- * @param yangPluginConfig plugin configurations
- * @return java attribute for leaf-list
+ * @param tempFiles temporary generated file
+ * @param container JAVA leaf info container
+ * @param config plugin configurations
+ * @param listAttribute flag indicating if list attribute
+ * @return JAVA attribute information
*/
- private static JavaAttributeInfo getJavaAttributeOfLeafList(TempJavaFragmentFiles tempJavaFragmentFiles,
- YangLeafList leafList,
- YangPluginConfig yangPluginConfig) {
- JavaLeafInfoContainer javaLeaf = (JavaLeafInfoContainer) leafList;
- javaLeaf.setConflictResolveConfig(yangPluginConfig.getConflictResolver());
- javaLeaf.updateJavaQualifiedInfo();
- tempJavaFragmentFiles.getJavaImportData().setIfListImported(true);
+ private static JavaAttributeInfo
+ getAttributeOfLeafInfoContainer(TempJavaFragmentFiles tempFiles,
+ JavaLeafInfoContainer container,
+ YangPluginConfig config,
+ boolean listAttribute) {
+ container.setConflictResolveConfig(config.getConflictResolver());
+ container.updateJavaQualifiedInfo();
return getAttributeInfoForTheData(
- javaLeaf.getJavaQualifiedInfo(),
- javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
- javaLeaf.getDataType(),
- tempJavaFragmentFiles.getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
- true);
- }
-
- /*
- * Retrieves the absolute path where the file needs to be generated.
- *
- * @return absolute path where the file needs to be generated
- */
- private String getAbsoluteDirPath() {
- return absoluteDirPath;
+ container.getJavaQualifiedInfo(),
+ container.getJavaName(config.getConflictResolver()),
+ container.getDataType(),
+ tempFiles.getIsQualifiedAccessOrAddToImportList(
+ container.getJavaQualifiedInfo()), listAttribute);
}
/**
* Sets absolute path where the file needs to be generated.
*
- * @param absoluteDirPath absolute path where the file needs to be generated.
+ * @param absoluteDirPath absolute path where the file needs to be
+ * generated
*/
- void setAbsoluteDirPath(String absoluteDirPath) {
+ protected void setAbsoluteDirPath(String absoluteDirPath) {
this.absoluteDirPath = absoluteDirPath;
}
/**
- * Retrieves the generated java file information.
+ * Returns the generated java file information.
*
* @return generated java file information
*/
- public JavaFileInfoTranslator getJavaFileInfo() {
+ protected JavaFileInfoTranslator getJavaFileInfo() {
return javaFileInfo;
}
@@ -705,45 +728,35 @@
*
* @param javaFileInfo generated java file information
*/
- public void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
+ protected void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
this.javaFileInfo = javaFileInfo;
}
/**
- * Retrieves the generated temp files.
+ * Returns the flag-set for generated temp files.
*
- * @return generated temp files
+ * @return flag-set
*/
- int getGeneratedTempFiles() {
- return generatedTempFiles;
+ protected int getGeneratedTempFiles() {
+ return tempFilesFlagSet;
}
/**
- * Sets generated file files.
+ * Adds to the flag-set for generated temp files.
*
- * @param fileType generated file type
+ * @param flags generated temp files flag-set
*/
- private void setGeneratedTempFiles(int fileType) {
- generatedTempFiles = fileType;
+ protected void addGeneratedTempFile(int flags) {
+ tempFilesFlagSet |= flags;
}
/**
- * Adds to generated temporary files.
- *
- * @param generatedTempFile generated file
- */
- void addGeneratedTempFile(int generatedTempFile) {
- generatedTempFiles |= generatedTempFile;
- setGeneratedTempFiles(generatedTempFiles);
- }
-
- /**
- * Retrieves the generated Java files.
+ * Returns the generated Java files.
*
* @return generated Java files
*/
- int getGeneratedJavaFiles() {
- return getJavaFileInfo().getGeneratedFileTypes();
+ protected int getGeneratedJavaFiles() {
+ return javaFileInfo.getGeneratedFileTypes();
}
/**
@@ -751,8 +764,8 @@
*
* @return mapped Java class name
*/
- String getGeneratedJavaClassName() {
- return getCapitalCase(getJavaFileInfo().getJavaName());
+ protected String getGeneratedJavaClassName() {
+ return getCapitalCase(javaFileInfo.getJavaName());
}
/**
@@ -767,10 +780,10 @@
/**
* Sets import data for the generated Java file.
*
- * @param javaImportData import data for the generated Java file
+ * @param data import data for the generated Java file
*/
- void setJavaImportData(JavaImportData javaImportData) {
- this.javaImportData = javaImportData;
+ protected void setJavaImportData(JavaImportData data) {
+ javaImportData = data;
}
/**
@@ -778,20 +791,11 @@
*
* @return status of any attributes added
*/
- boolean isAttributePresent() {
+ protected boolean isAttributePresent() {
return isAttributePresent;
}
/**
- * Sets status of any attributes added.
- *
- * @param attributePresent status of any attributes added
- */
- private void setAttributePresent(boolean attributePresent) {
- isAttributePresent = attributePresent;
- }
-
- /**
* Returns getter methods's temporary file handle.
*
* @return temporary file handle
@@ -801,15 +805,6 @@
}
/**
- * Sets to getter method's temporary file handle.
- *
- * @param getterForInterface file handle for to getter method
- */
- private void setGetterInterfaceTempFileHandle(File getterForInterface) {
- getterInterfaceTempFileHandle = getterForInterface;
- }
-
- /**
* Returns setter method's temporary file handle.
*
* @return temporary file handle
@@ -819,15 +814,6 @@
}
/**
- * Sets to setter method's temporary file handle.
- *
- * @param setterForInterface file handle for to setter method
- */
- private void setSetterInterfaceTempFileHandle(File setterForInterface) {
- setterInterfaceTempFileHandle = setterForInterface;
- }
-
- /**
* Returns setter method's impl's temporary file handle.
*
* @return temporary file handle
@@ -837,15 +823,6 @@
}
/**
- * Sets to setter method's impl's temporary file handle.
- *
- * @param setterImpl file handle for to setter method's implementation class
- */
- private void setSetterImplTempFileHandle(File setterImpl) {
- setterImplTempFileHandle = setterImpl;
- }
-
- /**
* Returns from string method's temporary file handle.
*
* @return from string method's temporary file handle
@@ -855,87 +832,6 @@
}
/**
- * Sets from string method's temporary file handle.
- *
- * @param fromStringImplTempFileHandle from string method's temporary file handle
- */
- private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
- this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
- }
-
- /**
- * Returns java file handle for interface file.
- *
- * @return java file handle for interface file
- */
- private File getInterfaceJavaFileHandle() {
- return interfaceJavaFileHandle;
- }
-
- /**
- * Sets the java file handle for interface file.
- *
- * @param interfaceJavaFileHandle java file handle
- */
- private void setInterfaceJavaFileHandle(File interfaceJavaFileHandle) {
- this.interfaceJavaFileHandle = interfaceJavaFileHandle;
- }
-
- /**
- * Returns java file handle for builder interface file.
- *
- * @return java file handle for builder interface file
- */
- private File getBuilderInterfaceJavaFileHandle() {
- return builderInterfaceJavaFileHandle;
- }
-
- /**
- * Sets the java file handle for builder interface file.
- *
- * @param builderInterfaceJavaFileHandle java file handle
- */
- private void setBuilderInterfaceJavaFileHandle(File builderInterfaceJavaFileHandle) {
- this.builderInterfaceJavaFileHandle = builderInterfaceJavaFileHandle;
- }
-
- /**
- * Returns java file handle for builder class file.
- *
- * @return java file handle for builder class file
- */
- private File getBuilderClassJavaFileHandle() {
- return builderClassJavaFileHandle;
- }
-
- /**
- * Sets the java file handle for builder class file.
- *
- * @param builderClassJavaFileHandle java file handle
- */
- private void setBuilderClassJavaFileHandle(File builderClassJavaFileHandle) {
- this.builderClassJavaFileHandle = builderClassJavaFileHandle;
- }
-
- /**
- * Returns java file handle for impl class file.
- *
- * @return java file handle for impl class file
- */
- private File getImplClassJavaFileHandle() {
- return implClassJavaFileHandle;
- }
-
- /**
- * Sets the java file handle for impl class file.
- *
- * @param implClassJavaFileHandle java file handle
- */
- private void setImplClassJavaFileHandle(File implClassJavaFileHandle) {
- this.implClassJavaFileHandle = implClassJavaFileHandle;
- }
-
- /**
* Returns attribute's temporary file handle.
*
* @return temporary file handle
@@ -945,15 +841,6 @@
}
/**
- * Sets attribute's temporary file handle.
- *
- * @param attributeForClass file handle for attribute
- */
- private void setAttributesTempFileHandle(File attributeForClass) {
- attributesTempFileHandle = attributeForClass;
- }
-
- /**
* Returns getter method's impl's temporary file handle.
*
* @return temporary file handle
@@ -963,15 +850,6 @@
}
/**
- * Sets to getter method's impl's temporary file handle.
- *
- * @param getterImpl file handle for to getter method's impl
- */
- private void setGetterImplTempFileHandle(File getterImpl) {
- getterImplTempFileHandle = getterImpl;
- }
-
- /**
* Returns hash code method's temporary file handle.
*
* @return temporary file handle
@@ -981,15 +859,6 @@
}
/**
- * Sets hash code method's temporary file handle.
- *
- * @param hashCodeMethod file handle for hash code method
- */
- private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
- hashCodeImplTempFileHandle = hashCodeMethod;
- }
-
- /**
* Returns equals method's temporary file handle.
*
* @return temporary file handle
@@ -999,15 +868,6 @@
}
/**
- * Sets equals method's temporary file handle.
- *
- * @param equalsMethod file handle for to equals method
- */
- private void setEqualsImplTempFileHandle(File equalsMethod) {
- equalsImplTempFileHandle = equalsMethod;
- }
-
- /**
* Returns to string method's temporary file handle.
*
* @return temporary file handle
@@ -1017,15 +877,6 @@
}
/**
- * Sets to string method's temporary file handle.
- *
- * @param toStringMethod file handle for to string method
- */
- private void setToStringImplTempFileHandle(File toStringMethod) {
- toStringImplTempFileHandle = toStringMethod;
- }
-
- /**
* Returns java extends list holder.
*
* @return java extends list holder
@@ -1037,10 +888,11 @@
/**
* Sets java extends list holder.
*
- * @param javaExtendsListHolder java extends list holder
+ * @param holder java extends list holder
*/
- void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
- this.javaExtendsListHolder = javaExtendsListHolder;
+ protected void setJavaExtendsListHolder(JavaExtendsListHolder
+ holder) {
+ javaExtendsListHolder = holder;
}
/**
@@ -1051,8 +903,9 @@
*/
private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getSubtreeFilteringForLeafTempFileHandle(),
- getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) + NEW_LINE);
+ appendToFile(subtreeFilteringForLeafTempFileHandle,
+ getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) +
+ NEW_LINE);
}
/**
@@ -1063,7 +916,7 @@
*/
private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getGetSubtreeFilteringForListTempFileHandle(),
+ appendToFile(getSubtreeFilteringForListTempFileHandle,
getSubtreeFilteringForLeafList(attr) + NEW_LINE);
}
@@ -1075,48 +928,53 @@
*/
private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getGetSubtreeFilteringForChildNodeTempFileHandle(),
+ appendToFile(getSubtreeFilteringForChildNodeTempFileHandle,
getSubtreeFilteringForNode(attr) + NEW_LINE);
}
/**
* Adds attribute for class.
*
- * @param attr attribute info
- * @param yangPluginConfig plugin configurations
+ * @param attr attribute info
+ * @param config plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addAttribute(JavaAttributeInfo attr, YangPluginConfig yangPluginConfig)
+ private void addAttribute(JavaAttributeInfo attr,
+ YangPluginConfig config)
throws IOException {
- appendToFile(getAttributesTempFileHandle(), parseAttribute(attr, yangPluginConfig)
- + FOUR_SPACE_INDENTATION);
+ appendToFile(attributesTempFileHandle, parseAttribute(attr, config) +
+ FOUR_SPACE_INDENTATION);
}
/**
* Adds getter for interface.
*
- * @param attr attribute info
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param config plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addGetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ private void addGetterForInterface(JavaAttributeInfo attr,
+ YangPluginConfig config)
throws IOException {
- appendToFile(getGetterInterfaceTempFileHandle(),
- getGetterString(attr, getGeneratedJavaFiles(), pluginConfig) + NEW_LINE);
+ appendToFile(getterInterfaceTempFileHandle,
+ getGetterString(attr, getGeneratedJavaFiles(), config) +
+ NEW_LINE);
}
/**
* Adds setter for interface.
*
- * @param attr attribute info
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param config plugin configurations
* @throws IOException when fails to append to temporary file
*/
- private void addSetterForInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ private void addSetterForInterface(JavaAttributeInfo attr,
+ YangPluginConfig config)
throws IOException {
- appendToFile(getSetterInterfaceTempFileHandle(),
- getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), pluginConfig)
- + NEW_LINE);
+ appendToFile(setterInterfaceTempFileHandle,
+ getSetterString(attr, getGeneratedJavaClassName(),
+ getGeneratedJavaFiles(), config) +
+ NEW_LINE);
}
/**
@@ -1125,62 +983,68 @@
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
- private void addSetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ private void addSetterImpl(JavaAttributeInfo attr,
+ YangPluginConfig config)
throws IOException {
- if (isRooNode()) {
- appendToFile(getSetterImplTempFileHandle(), getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
- attr.isListAttr(), pluginConfig, null) +
- getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
- + NEW_LINE);
+ String setter =
+ getSetterForClass(attr, getGeneratedJavaClassName(),
+ getGeneratedJavaFiles()) + NEW_LINE;
+ if (rootNode) {
+ appendToFile(setterImplTempFileHandle,
+ getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
+ attr.isListAttr(), config, null) + setter);
} else {
- appendToFile(getSetterImplTempFileHandle(), getOverRideString() +
- getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles())
- + NEW_LINE);
+ appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
}
}
/**
* Adds getter method's impl for class.
*
- * @param attr attribute info
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param config plugin configurations
* @throws IOException when fails to append to temporary file
*/
- void addGetterImpl(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ protected void addGetterImpl(JavaAttributeInfo attr,
+ YangPluginConfig config)
throws IOException {
- if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
- || (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
- if (!isRooNode()) {
- appendToFile(getGetterImplTempFileHandle(), getOverRideString() +
- getGetterForClass(attr, getGeneratedJavaFiles()) +
- NEW_LINE);
+ String getter =
+ getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE;
+ if (javaFlagSet(BUILDER_CLASS_MASK | GENERATE_SERVICE_AND_MANAGER)) {
+ if (!rootNode) {
+ appendToFile(getterImplTempFileHandle, getOverRideString() +
+ getter);
} else {
- appendToFile(getGetterImplTempFileHandle(), getGetterForClass(attr,
- getGeneratedJavaFiles()) + NEW_LINE);
+ appendToFile(getterImplTempFileHandle, getter);
}
} else {
String appDataStructure = null;
if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ appDataStructure = attr.getCompilerAnnotation()
+ .getYangAppDataStructure().getDataStructure().name();
}
- appendToFile(getGetterImplTempFileHandle(),
- getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig,
- appDataStructure) + getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
+ appendToFile(getterImplTempFileHandle,
+ getJavaDoc(GETTER_METHOD,
+ getCapitalCase(attr.getAttributeName()),
+ false, config, appDataStructure) + getter);
}
}
/**
* Adds add to list interface method.
*
- * @param attr attribute
- * @param pluginConfig plugin configurations
+ * @param attr attribute
+ * @param config plugin configurations
* @throws IOException when fails to do IO operations
*/
- private void addAddToListInterface(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
+ private void addAddToListInterface(JavaAttributeInfo attr,
+ YangPluginConfig config)
throws IOException {
- appendToFile(getAddToListInterfaceTempFileHandle(),
- getJavaDoc(ADD_TO_LIST, getCapitalCase(attr.getAttributeName()), false, pluginConfig, null)
- + getAddToListMethodInterface(attr, getGeneratedJavaClassName()) + NEW_LINE);
+ appendToFile(addToListInterfaceTempFileHandle,
+ getJavaDoc(ADD_TO_LIST,
+ getCapitalCase(attr.getAttributeName()), false,
+ config, null) + getAddToListMethodInterface(
+ attr, getGeneratedJavaClassName()) + NEW_LINE);
}
/**
@@ -1191,35 +1055,35 @@
*/
private void addAddToListImpl(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getAddToListImplTempFileHandle(),
- getAddToListMethodImpl(attr, getGeneratedJavaClassName(), isRooNode()) + NEW_LINE);
+ appendToFile(addToListImplTempFileHandle,
+ getAddToListMethodImpl(attr, getGeneratedJavaClassName(),
+ rootNode) + NEW_LINE);
}
/**
* Adds leaf identifier enum attributes.
*
- * @param attr attribute
- * @param value value
- * @param yangPluginConfig plugin config
+ * @param attr attribute
+ * @param value value
* @throws IOException when fails to do IO operations
*/
- private void addLeafIdAttributes(JavaAttributeInfo attr, int value, YangPluginConfig yangPluginConfig)
+ private void addLeafIdAttributes(JavaAttributeInfo attr, int value)
throws IOException {
- appendToFile(getLeafIdAttributeTempFileHandle(),
- FOUR_SPACE_INDENTATION + generateEnumAttributeString(attr.getAttributeName(),
- value));
+ appendToFile(leafIdAttributeTempFileHandle, FOUR_SPACE_INDENTATION +
+ generateEnumAttributeString(attr.getAttributeName(), value));
}
/**
* Adds build method for interface.
*
- * @param pluginConfig plugin configurations
+ * @param config plugin configurations
* @return build method for interface
* @throws IOException when fails to append to temporary file
*/
- String addBuildMethodForInterface(YangPluginConfig pluginConfig)
+ protected String addBuildMethodForInterface(YangPluginConfig config)
throws IOException {
- return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(), pluginConfig);
+ return parseBuilderInterfaceBuildMethodString(getGeneratedJavaClassName(),
+ config);
}
/**
@@ -1228,43 +1092,46 @@
* @return build method implementation for class
* @throws IOException when fails to append to temporary file
*/
- String addBuildMethodImpl()
+ protected String addBuildMethodImpl()
throws IOException {
- return getBuildString(getGeneratedJavaClassName(), isRooNode()) + NEW_LINE;
+ return getBuildString(getGeneratedJavaClassName(), rootNode) + NEW_LINE;
}
/**
* Adds default constructor for class.
*
- * @param modifier modifier for constructor.
- * @param toAppend string which need to be appended with the class name
- * @param pluginConfig plugin configurations
- * @param isSuffix is value need to be appended as suffix
+ * @param modifier modifier for constructor
+ * @param toAppend string which need to be appended with the class name
+ * @param config plugin configurations
+ * @param suffix is value need to be appended as suffix
* @return default constructor for class
* @throws IOException when fails to append to file
*/
- String addDefaultConstructor(String modifier, String toAppend, YangPluginConfig pluginConfig, boolean isSuffix)
+ protected String addDefaultConstructor(String modifier, String toAppend,
+ YangPluginConfig config,
+ boolean suffix)
throws IOException {
- String name = getGeneratedJavaClassName();
- if (isRooNode() && !toAppend.equals(BUILDER)) {
- name = name + OP_PARAM;
- return NEW_LINE
- + getDefaultConstructorString(name, modifier,
- pluginConfig);
+ StringBuilder name = new StringBuilder();
+ name.append(getGeneratedJavaClassName());
+ String constructor = NEW_LINE +
+ getDefaultConstructorString(name.toString(), modifier, config);
+ if (rootNode && !toAppend.equals(BUILDER)) {
+ name.append(OP_PARAM);
+ return constructor;
}
- if (isSuffix) {
- return NEW_LINE +
- getDefaultConstructorString(name + toAppend, modifier, pluginConfig);
+ if (suffix) {
+ name.append(toAppend);
+ return constructor;
}
- String appended;
+ StringBuilder appended = new StringBuilder();
if (toAppend.equals(DEFAULT)) {
- appended = getCapitalCase(toAppend);
+ appended.append(getCapitalCase(toAppend));
} else {
- appended = toAppend;
+ appended.append(toAppend);
}
- return NEW_LINE
- + getDefaultConstructorString(appended + name, modifier,
- pluginConfig);
+ return NEW_LINE + getDefaultConstructorString(appended.append(
+ name.toString()).toString(), modifier, config);
+ // TODO getDefaultConstructorString to handle new line.
}
/**
@@ -1275,7 +1142,8 @@
*/
private void addHashCodeMethod(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getHashCodeImplTempFileHandle(), getHashCodeMethod(attr) + NEW_LINE);
+ appendToFile(hashCodeImplTempFileHandle,
+ getHashCodeMethod(attr) + NEW_LINE);
}
/**
@@ -1286,7 +1154,8 @@
*/
private void addEqualsMethod(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getEqualsImplTempFileHandle(), getEqualsMethod(attr) + NEW_LINE);
+ appendToFile(equalsImplTempFileHandle,
+ getEqualsMethod(attr) + NEW_LINE);
}
/**
@@ -1297,21 +1166,22 @@
*/
private void addToStringMethod(JavaAttributeInfo attr)
throws IOException {
- appendToFile(getToStringImplTempFileHandle(), getToStringMethod(attr) + NEW_LINE);
+ appendToFile(toStringImplTempFileHandle,
+ getToStringMethod(attr) + NEW_LINE);
}
/**
* Adds from string method for union class.
*
- * @param javaAttributeInfo type attribute info
- * @param fromStringAttributeInfo from string attribute info
+ * @param attr type attribute info
+ * @param fromStringAttr from string attribute info
* @throws IOException when fails to append to temporary file
*/
- void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
- JavaAttributeInfo fromStringAttributeInfo)
+ void addFromStringMethod(JavaAttributeInfo attr,
+ JavaAttributeInfo fromStringAttr)
throws IOException {
- appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
- fromStringAttributeInfo) + NEW_LINE);
+ appendToFile(fromStringImplTempFileHandle,
+ getFromStringMethod(attr, fromStringAttr) + NEW_LINE);
}
/**
@@ -1321,26 +1191,29 @@
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
- File getTemporaryFileHandle(String fileName)
+ protected File getTemporaryFileHandle(String fileName)
throws IOException {
- String path = getTempDirPath(getAbsoluteDirPath());
+ String path = getTempDirPath(absoluteDirPath);
File dir = new File(path);
boolean isCreated;
if (!dir.exists()) {
isCreated = dir.mkdirs();
if (!isCreated) {
- throw new IOException("failed to create temporary directory for " + fileName);
+ throw new IOException("failed to create temporary directory " +
+ "for " + fileName);
}
}
File file = new File(path + fileName + TEMP_FILE_EXTENSION);
if (!file.exists()) {
isCreated = file.createNewFile();
if (!isCreated) {
- throw new IOException("failed to create temporary file for " + fileName);
+ throw new IOException("failed to create temporary file for " +
+ fileName);
}
} else {
- throw new IOException(fileName + " is reused due to YANG naming. probably your previous build would have " +
- "failed");
+ throw new IOException(fileName + " is reused due to YANG naming. " +
+ "probably your previous build " +
+ "would have failed");
}
return file;
}
@@ -1352,9 +1225,10 @@
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
- File getJavaFileHandle(String fileName)
+ protected File getJavaFileHandle(String fileName)
throws IOException {
- return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
+ return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION,
+ javaFileInfo);
}
/**
@@ -1370,48 +1244,49 @@
String path = getTempDirPath(absolutePath);
if (new File(path + file.getName()).exists()) {
return readAppendFile(path + file.getName(), EMPTY_STRING);
- } else {
- throw new IOException("Unable to get data from the given "
- + file.getName() + " file for " + getGeneratedJavaClassName() + PERIOD);
}
+ throw new IOException("Unable to get data from the given " +
+ file.getName() + " file for " +
+ getGeneratedJavaClassName() + PERIOD);
}
/**
* Returns temporary directory path.
*
- * @param absolutePath absolute path
+ * @param path absolute path
* @return directory path
*/
- private String getTempDirPath(String absolutePath) {
- return getPackageDirPathFromJavaJPackage(absolutePath) + SLASH + getGeneratedJavaClassName()
- + TEMP_FOLDER_NAME_SUFFIX + SLASH;
+ private String getTempDirPath(String path) {
+ return getPackageDirPathFromJavaJPackage(path) + SLASH +
+ getGeneratedJavaClassName() + TEMP_FOLDER_NAME_SUFFIX + SLASH;
}
/**
* Parses attribute to get the attribute string.
*
- * @param attr attribute info
- * @param pluginConfig plugin configurations
+ * @param attr attribute info
+ * @param config plugin configurations
* @return attribute string
*/
- String parseAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig) {
+ protected String parseAttribute(JavaAttributeInfo attr,
+ YangPluginConfig config) {
/*
* TODO: check if this utility needs to be called or move to the caller
*/
- String attributeName = getCamelCase(attr.getAttributeName(), pluginConfig.getConflictResolver());
- String attributeAccessType = PRIVATE;
- if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
- attributeAccessType = PROTECTED;
+ String attrName = getCamelCase(attr.getAttributeName(),
+ config.getConflictResolver());
+ String attrAccessType = PRIVATE;
+ if ((javaFileInfo.getGeneratedFileTypes() &
+ GENERATE_INTERFACE_WITH_BUILDER) != 0) {
+ attrAccessType = PROTECTED;
}
+ String pkg = null;
if (attr.isQualifiedName()) {
- return getJavaAttributeDefinition(attr.getImportInfo().getPkgInfo(),
- attr.getImportInfo().getClassInfo(),
- attributeName, attr.isListAttr(), attributeAccessType,
- attr.getCompilerAnnotation());
- } else {
- return getJavaAttributeDefinition(null, attr.getImportInfo().getClassInfo(), attributeName,
- attr.isListAttr(), attributeAccessType, attr.getCompilerAnnotation());
+ pkg = attr.getImportInfo().getPkgInfo();
}
+ return getJavaAttributeDefinition(
+ pkg, attr.getImportInfo().getClassInfo(), attrName,
+ attr.isListAttr(), attrAccessType, attr.getCompilerAnnotation());
}
/**
@@ -1421,7 +1296,7 @@
* @param data data to be appended
* @throws IOException when fails to append to file
*/
- void appendToFile(File file, String data)
+ protected void appendToFile(File file, String data)
throws IOException {
try {
insertDataIntoJavaFile(file, data);
@@ -1433,228 +1308,221 @@
/**
* Adds parent's info to current node import list.
*
- * @param curNode current node for which import list needs to be updated
- * @param pluginConfig plugin configurations
+ * @param curNode current node
+ * @param config plugin configurations
*/
- void addParentInfoInCurNodeTempFile(YangNode curNode, YangPluginConfig pluginConfig) {
- JavaQualifiedTypeInfoTranslator caseImportInfo = new JavaQualifiedTypeInfoTranslator();
+ protected void addParentInfoInCurNodeTempFile(YangNode curNode,
+ YangPluginConfig config) {
+ JavaQualifiedTypeInfoTranslator caseImportInfo =
+ new JavaQualifiedTypeInfoTranslator();
YangNode parent = getParentNodeInGenCode(curNode);
if (curNode instanceof YangCase && parent instanceof YangAugment) {
return;
}
if (!(parent instanceof JavaCodeGenerator)) {
- throw new TranslatorException("missing parent node to contain current node info in generated file");
+ throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE, curNode));
}
if (!(curNode instanceof JavaFileInfoContainer)) {
- throw new TranslatorException("missing java file information to get the package details "
- + "of attribute corresponding to child node " +
- curNode.getName() + " in " + curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ throw new TranslatorException(getErrorMsg(INVALID_NODE, curNode));
}
- caseImportInfo.setClassInfo(getCapitalCase(getCamelCase(parent.getName(),
- pluginConfig.getConflictResolver())));
- caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage());
+ caseImportInfo.setClassInfo(
+ getCapitalCase(getCamelCase(parent.getName(),
+ config.getConflictResolver())));
+ caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo()
+ .getPackage());
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+ JavaFileInfoTranslator fileInfo =
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
- .getBeanTempFiles().getJavaImportData().addImportInfo(caseImportInfo,
- getCapitalCase(fileInfo.getJavaName()),
- fileInfo.getPackage());
+ getBeanFiles(curNode).getJavaImportData().addImportInfo(
+ caseImportInfo, getCapitalCase(fileInfo.getJavaName()),
+ fileInfo.getPackage());
}
/**
* Adds leaf attributes in generated files.
*
- * @param listOfLeaves list of YANG leaf
- * @param yangPluginConfig plugin config
- * @param curNode current node
+ * @param entry JAVA leaf info container
+ * @param config plugin config
+ * @param curNode current node
+ * @param leafList flag indicating whether leaf container is leafList
* @throws IOException IO operation fail
*/
- private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
- YangPluginConfig yangPluginConfig, YangNode curNode)
+ private void addLeafInfoToTempFiles(JavaLeafInfoContainer entry,
+ YangPluginConfig config,
+ YangNode curNode,
+ boolean leafList)
throws IOException {
- if (listOfLeaves != null) {
- for (YangLeaf leaf : listOfLeaves) {
- if (!(leaf instanceof JavaLeafInfoContainer)) {
- throw new TranslatorException("Leaf does not have java information " +
- leaf.getName() + " in " + leaf.getLineNumber() + " at " +
- leaf.getCharPosition()
- + " in " + leaf.getFileName());
- }
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
- TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
- .getTempJavaCodeFragmentFiles().getBeanTempFiles();
- addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(tempJavaBeanFragmentFiles, leaf,
- yangPluginConfig), yangPluginConfig);
- } else {
- addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeaf(this, leaf, yangPluginConfig),
- yangPluginConfig);
- }
+ if (entry != null) {
+ if (curNode instanceof RpcNotificationContainer) {
+ TempJavaBeanFragmentFiles tempFiles = getBeanFiles(curNode);
+ addJavaSnippetInfoToApplicableTempFiles(
+ getJavaAttributeOfLeaf(tempFiles, entry,
+ config, leafList), config);
+ } else {
+ addJavaSnippetInfoToApplicableTempFiles(
+ getJavaAttributeOfLeaf(this, entry,
+ config, leafList), config);
}
}
}
/**
- * Adds leaf list's attributes in generated files.
+ * Adds all the leaves in the current data model node as part of the
+ * generated temporary file.
*
- * @param listOfLeafList list of YANG leaves
- * @param yangPluginConfig plugin config
- * @param curNode current node
+ * @param curNode current node
+ * @param config plugin config
* @throws IOException IO operation fail
*/
- private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig,
- YangNode curNode)
- throws IOException {
- if (listOfLeafList != null) {
- for (YangLeafList leafList : listOfLeafList) {
- if (!(leafList instanceof JavaLeafInfoContainer)) {
- throw new TranslatorException("Leaf-list does not have java information " +
- curNode.getName() + " in " + curNode.getLineNumber() +
- " at " + curNode.getCharPosition()
- + " in " + curNode.getFileName());
- }
- if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
- TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
- .getTempJavaCodeFragmentFiles().getBeanTempFiles();
- addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(tempJavaBeanFragmentFiles,
- leafList, yangPluginConfig),
- yangPluginConfig);
- } else {
- addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeOfLeafList(this,
- leafList, yangPluginConfig),
- yangPluginConfig);
- }
- }
- }
- }
-
- /**
- * Adds all the leaves in the current data model node as part of the generated temporary file.
- *
- * @param curNode current node
- * @param yangPluginConfig plugin config
- * @throws IOException IO operation fail
- */
- void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
- YangPluginConfig yangPluginConfig)
+ protected void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
+ YangPluginConfig config)
throws IOException {
if (!(curNode instanceof YangLeavesHolder)) {
- throw new TranslatorException("Data model node does not have any leaves " +
- curNode.getName() + " in " + curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ throw new TranslatorException(getErrorMsg(INVALID_LEAF_HOLDER,
+ curNode));
}
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
- addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig, curNode);
- addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig, curNode);
+
+ for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
+ addLeafInfoToTempFiles((JavaLeafInfoContainer) leaf, config,
+ curNode, false);
+ }
+
+ for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
+ addLeafInfoToTempFiles((JavaLeafInfoContainer) leafList, config,
+ curNode, true);
+ }
+ }
+
+ /**
+ * Adds operation type to temp files.
+ *
+ * @param curNode current YANG node
+ * @param config YANG plugin config
+ * @throws IOException IO exception
+ */
+ protected void addOperationTypeToTempFiles(YangNode curNode,
+ YangPluginConfig config)
+ throws IOException {
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ new JavaQualifiedTypeInfoTranslator();
+ typeInfo.setClassInfo(OPERATION_TYPE_CLASS);
+ typeInfo.setPkgInfo(((JavaFileInfoContainer) curNode).getJavaFileInfo()
+ .getPackage());
+ JavaAttributeInfo attributeInfo =
+ getAttributeInfoForTheData(typeInfo, YANG + getCapitalCase(
+ curNode.getJavaClassNameOrBuiltInType()) +
+ OPERATION_TYPE_ATTRIBUTE, null, false, false);
+ addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
}
/**
* Adds the new attribute info to the target generated temporary files.
*
- * @param newAttrInfo the attribute info that needs to be added to temporary files
+ * @param newAttrInfo new attribute info
* @param pluginConfig plugin configurations
* @throws IOException IO operation fail
*/
- void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
+ void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
+ YangPluginConfig pluginConfig)
throws IOException {
- setAttributePresent(true);
- if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
+ isAttributePresent = true;
+ if (tempFlagSet(ATTRIBUTES_MASK)) {
addAttribute(newAttrInfo, pluginConfig);
}
- if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
+ if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
addGetterForInterface(newAttrInfo, pluginConfig);
}
- if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
+ if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
addSetterForInterface(newAttrInfo, pluginConfig);
}
- if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
+ if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
addSetterImpl(newAttrInfo, pluginConfig);
}
- if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
+ if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
addHashCodeMethod(newAttrInfo);
}
- if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
+ if (tempFlagSet(EQUALS_IMPL_MASK)) {
addEqualsMethod(newAttrInfo);
}
- if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
+ if (tempFlagSet(TO_STRING_IMPL_MASK)) {
addToStringMethod(newAttrInfo);
}
- if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
+ if (tempFlagSet(EDIT_CONTENT_MASK)) {
//TODO: add implementation for edit content match.
}
- if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0 && newAttrInfo.isListAttr()) {
+ boolean listAttr = newAttrInfo.isListAttr();
+ if (tempFlagSet(ADD_TO_LIST_IMPL_MASK) && listAttr) {
addAddToListImpl(newAttrInfo);
}
- if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0 && newAttrInfo.isListAttr()) {
+ if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK) && listAttr) {
addAddToListInterface(newAttrInfo, pluginConfig);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0
- && newAttrInfo.getAttributeType() == null) {
+ YangType attrType = newAttrInfo.getAttributeType();
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
+ attrType == null && !newAttrInfo.getAttributeName()
+ .equals(OPERATION_TYPE_ATTRIBUTE)) {
addSubtreeFilteringForChildNode(newAttrInfo);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0 && !newAttrInfo.isListAttr()
- && newAttrInfo.getAttributeType() != null) {
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
+ !listAttr && attrType != null) {
addSubTreeFilteringForLeaf(newAttrInfo);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0 && newAttrInfo.isListAttr()
- && newAttrInfo.getAttributeType() != null) {
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) &&
+ listAttr && attrType != null) {
addSubtreeFilteringForLeafList(newAttrInfo);
}
- if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0 && !newAttrInfo.isListAttr()
- && newAttrInfo.getAttributeType() != null) {
+ if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) &&
+ !listAttr && attrType != null) {
leafCount++;
- addLeafIdAttributes(newAttrInfo, leafCount, pluginConfig);
+ addLeafIdAttributes(newAttrInfo, leafCount);
}
- if (!newAttrInfo.isIntConflict() &&
- !newAttrInfo.isLongConflict() && !newAttrInfo.isShortConflict()) {
- if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
+ if (!newAttrInfo.isIntConflict() && !newAttrInfo.isLongConflict() &&
+ !newAttrInfo.isShortConflict()) {
+ if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
addGetterImpl(newAttrInfo, pluginConfig);
}
-
- if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
- JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString =
- getQualifiedInfoOfFromString(newAttrInfo, pluginConfig
- .getConflictResolver());
+ if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ getQualifiedInfoOfFromString(newAttrInfo,
+ pluginConfig.getConflictResolver());
/*
* Create a new java attribute info with qualified information of
* wrapper classes.
*/
JavaAttributeInfo fromStringAttributeInfo =
- getAttributeInfoForTheData(qualifiedInfoOfFromString, newAttrInfo.getAttributeName(),
- newAttrInfo.getAttributeType(),
- getIsQualifiedAccessOrAddToImportList(
- qualifiedInfoOfFromString),
- false);
-
+ getAttributeInfoForTheData(
+ typeInfo, newAttrInfo.getAttributeName(),
+ attrType, getIsQualifiedAccessOrAddToImportList(
+ typeInfo), false);
addFromStringMethod(newAttrInfo, fromStringAttributeInfo);
}
}
}
/**
- * Returns java class name.
+ * Returns JAVA class name for non implementation classes.
*
* @param suffix for the class name based on the file type
* @return java class name
*/
- String getJavaClassName(String suffix) {
- return getCapitalCase(getJavaFileInfo().getJavaName()) + suffix;
+ protected String getJavaClassName(String suffix) {
+ return getCapitalCase(javaFileInfo.getJavaName()) + suffix;
}
/**
- * Returns java class name.
+ * Returns class name for implementation classes.
*
* @param node YANG node
* @return java class name
*/
private String getImplClassName(YangNode node) {
- if (node instanceof YangModule || node instanceof YangSubModule) {
- return getCapitalCase(getJavaFileInfo().getJavaName()) + OP_PARAM;
+ if (node instanceof RpcNotificationContainer) {
+ return getCapitalCase(javaFileInfo.getJavaName()) + OP_PARAM;
}
- return getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo().getJavaName());
+ return getCapitalCase(DEFAULT) +
+ getCapitalCase(javaFileInfo.getJavaName());
}
/**
@@ -1663,7 +1531,7 @@
* @return directory path
*/
private String getDirPath() {
- return getJavaFileInfo().getPackageFilePath();
+ return javaFileInfo.getPackageFilePath();
}
/**
@@ -1675,8 +1543,8 @@
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
- List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
- .getJavaImportData().getImports();
+ List<String> imports =
+ getBeanFiles(curNode).getJavaImportData().getImports();
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, true, true, curNode);
}
@@ -1687,41 +1555,52 @@
BUILDER_INTERFACE_MASK) != 0) {
//Create interface file.
- setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
- setInterfaceJavaFileHandle(
- generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
- if (!(curNode instanceof YangModule) && !(curNode instanceof YangSubModule)) {
+ interfaceJavaFileHandle =
+ getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX));
+ interfaceJavaFileHandle =
+ generateInterfaceFile(interfaceJavaFileHandle, imports,
+ curNode, isAttributePresent);
+ if (!(curNode instanceof RpcNotificationContainer)) {
//Create builder interface file.
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());
+ builderInterfaceJavaFileHandle =
+ getJavaFileHandle(getJavaClassName(
+ BUILDER_INTERFACE_FILE_NAME_SUFFIX));
+ builderInterfaceJavaFileHandle =
+ generateBuilderInterfaceFile(
+ builderInterfaceJavaFileHandle,
+ curNode, isAttributePresent);
+ /*
+ * Append builder interface file to interface file and
+ * close it.
+ */
+ mergeJavaFiles(builderInterfaceJavaFileHandle,
+ interfaceJavaFileHandle);
}
}
- insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
- validateLineLength(getInterfaceJavaFileHandle());
+ insertDataIntoJavaFile(interfaceJavaFileHandle,
+ getJavaClassDefClose());
+ validateLineLength(interfaceJavaFileHandle);
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, false, true, curNode);
}
}
- if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & DEFAULT_CLASS_MASK) != 0) {
- if (isAttributePresent()) {
+ if ((fileType & BUILDER_CLASS_MASK) != 0 ||
+ (fileType & DEFAULT_CLASS_MASK) != 0) {
+ if (isAttributePresent) {
addImportsToStringAndHasCodeMethods(imports, true);
addArrayListImport(imports);
}
- boolean isLeavesPresent;
+ boolean leavesPresent;
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
- isLeavesPresent = leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()
- || leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty();
- if (isLeavesPresent) {
+ leavesPresent = leavesHolder.getListOfLeaf() != null &&
+ !leavesHolder.getListOfLeaf().isEmpty() ||
+ leavesHolder.getListOfLeafList() != null &&
+ !leavesHolder.getListOfLeafList().isEmpty();
+ if (leavesPresent) {
addBitsetImport(imports);
}
}
@@ -1732,22 +1611,30 @@
sortImports(imports);
//Create impl class file.
- setImplClassJavaFileHandle(getJavaFileHandle(getImplClassName(curNode)));
- setImplClassJavaFileHandle(
- generateDefaultClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent(), imports));
+ implClassJavaFileHandle =
+ getJavaFileHandle(getImplClassName(curNode));
+ implClassJavaFileHandle =
+ generateDefaultClassFile(implClassJavaFileHandle,
+ curNode, isAttributePresent,
+ imports);
//Create builder class file.
if ((fileType & BUILDER_CLASS_MASK) != 0) {
- setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
- setBuilderClassJavaFileHandle(
- generateBuilderClassFile(getBuilderClassJavaFileHandle(), curNode,
- isAttributePresent()));
+ builderClassJavaFileHandle =
+ getJavaFileHandle(getJavaClassName(
+ BUILDER_CLASS_FILE_NAME_SUFFIX));
+ builderClassJavaFileHandle =
+ generateBuilderClassFile(builderClassJavaFileHandle,
+ curNode,
+ isAttributePresent);
//Append impl class to builder class and close it.
- mergeJavaFiles(getBuilderClassJavaFileHandle(), getImplClassJavaFileHandle());
+ mergeJavaFiles(builderClassJavaFileHandle,
+ implClassJavaFileHandle);
}
- insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
- validateLineLength(getImplClassJavaFileHandle());
+ insertDataIntoJavaFile(implClassJavaFileHandle,
+ getJavaClassDefClose());
+ validateLineLength(implClassJavaFileHandle);
}
//Close all the file handles.
freeTemporaryResources(false);
@@ -1755,13 +1642,13 @@
//Adds import for array list.
private void addArrayListImport(List<String> imports) {
- if (imports.contains(getJavaImportData().getImportForList())) {
+ if (imports.contains(javaImportData.getImportForList())) {
imports.add(ARRAY_LIST_IMPORT);
}
}
private void addBitsetImport(List<String> imports) {
- imports.add(getJavaImportData().getImportForToBitSet());
+ imports.add(javaImportData.getImportForToBitSet());
}
/**
@@ -1770,14 +1657,16 @@
* @param imports import list
* @param operation add or remove
*/
- void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
+ protected void addImportsToStringAndHasCodeMethods(List<String> imports,
+ boolean operation) {
if (operation) {
- imports.add(getJavaImportData().getImportForHashAndEquals());
- imports.add(getJavaImportData().getImportForToString());
+ imports.add(javaImportData.getImportForHashAndEquals());
+ imports.add(javaImportData.getImportForToString());
} else {
- imports.remove(getJavaImportData().getImportForHashAndEquals());
- imports.remove(getJavaImportData().getImportForToString());
+ imports.remove(javaImportData.getImportForHashAndEquals());
+ imports.remove(javaImportData.getImportForToString());
}
+ // TODO change boolean to OPERATION, in all related places.
}
/**
@@ -1788,21 +1677,23 @@
* @param isInterfaceFile if need to add in interface file
* @param curNode current node
*/
- private void addImportsForAugmentableClass(List<String> imports, boolean operations, boolean isInterfaceFile,
+ private void addImportsForAugmentableClass(List<String> imports,
+ boolean operations,
+ boolean isInterfaceFile,
YangNode curNode) {
if (operations) {
if (!isInterfaceFile) {
- imports.add(getJavaImportData().getHashMapImport());
+ imports.add(javaImportData.getHashMapImport());
}
// Add import for hash map only if node is not a YANG choice.
if (!(curNode instanceof YangChoice)) {
- imports.add(getJavaImportData().getMapImport());
+ imports.add(javaImportData.getMapImport());
}
} else {
if (!isInterfaceFile) {
- imports.remove(getJavaImportData().getHashMapImport());
+ imports.remove(javaImportData.getHashMapImport());
}
- imports.remove(getJavaImportData().getMapImport());
+ imports.remove(javaImportData.getMapImport());
}
sortImports(imports);
}
@@ -1819,82 +1710,83 @@
/**
* Removes all temporary file handles.
*
- * @param isErrorOccurred flag to tell translator that error has occurred while file generation
+ * @param errorOccurred flag indicating if error occurred
* @throws IOException when failed to delete the temporary files
*/
- public void freeTemporaryResources(boolean isErrorOccurred)
+ public void freeTemporaryResources(boolean errorOccurred)
throws IOException {
/*
* Close all java file handles and when error occurs delete the files.
*/
- if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
- closeFile(getInterfaceJavaFileHandle(), isErrorOccurred);
+ if (javaFlagSet(INTERFACE_MASK)) {
+ closeFile(interfaceJavaFileHandle, errorOccurred);
}
- if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0) {
- closeFile(getBuilderClassJavaFileHandle(), true);
+ if (javaFlagSet(BUILDER_CLASS_MASK)) {
+ closeFile(builderClassJavaFileHandle);
}
- if ((getGeneratedJavaFiles() & BUILDER_INTERFACE_MASK) != 0) {
- closeFile(getBuilderInterfaceJavaFileHandle(), true);
+ if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
+ closeFile(builderInterfaceJavaFileHandle);
}
- if ((getGeneratedJavaFiles() & DEFAULT_CLASS_MASK) != 0) {
- closeFile(getImplClassJavaFileHandle(), isErrorOccurred);
+ if (javaFlagSet(DEFAULT_CLASS_MASK)) {
+ closeFile(implClassJavaFileHandle, errorOccurred);
}
/*
* Close all temporary file handles and delete the files.
*/
- if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
- closeFile(getGetterImplTempFileHandle(), true);
+ if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
+ closeFile(getterImplTempFileHandle);
}
- if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
- closeFile(getAttributesTempFileHandle(), true);
+ if (tempFlagSet(ATTRIBUTES_MASK)) {
+ closeFile(attributesTempFileHandle);
}
- if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
- closeFile(getHashCodeImplTempFileHandle(), true);
+ if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
+ closeFile(hashCodeImplTempFileHandle);
}
- if ((getGeneratedTempFiles() & TO_STRING_IMPL_MASK) != 0) {
- closeFile(getToStringImplTempFileHandle(), true);
+ if (tempFlagSet(TO_STRING_IMPL_MASK)) {
+ closeFile(toStringImplTempFileHandle);
}
- if ((getGeneratedTempFiles() & EQUALS_IMPL_MASK) != 0) {
- closeFile(getEqualsImplTempFileHandle(), true);
+ if (tempFlagSet(EQUALS_IMPL_MASK)) {
+ closeFile(equalsImplTempFileHandle);
}
- if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
- closeFile(getFromStringImplTempFileHandle(), true);
+ if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
+ closeFile(fromStringImplTempFileHandle);
}
- if ((getGeneratedTempFiles() & ADD_TO_LIST_IMPL_MASK) != 0) {
- closeFile(getAddToListImplTempFileHandle(), true);
+ if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
+ closeFile(addToListImplTempFileHandle);
}
- if ((getGeneratedTempFiles() & ADD_TO_LIST_INTERFACE_MASK) != 0) {
- closeFile(getAddToListInterfaceTempFileHandle(), true);
+ if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
+ closeFile(addToListInterfaceTempFileHandle);
}
- if ((getGeneratedTempFiles() & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
- closeFile(getLeafIdAttributeTempFileHandle(), true);
+ if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
+ closeFile(leafIdAttributeTempFileHandle);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
- closeFile(getSubtreeFilteringForLeafTempFileHandle(), true);
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
+ closeFile(subtreeFilteringForLeafTempFileHandle);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
- closeFile(getGetSubtreeFilteringForListTempFileHandle(), true);
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
+ closeFile(getSubtreeFilteringForListTempFileHandle);
}
- if ((getGeneratedTempFiles() & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
- closeFile(getGetSubtreeFilteringForChildNodeTempFileHandle(), true);
+ if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
+ closeFile(getSubtreeFilteringForChildNodeTempFileHandle);
}
- if ((getGeneratedTempFiles() & EDIT_CONTENT_MASK) != 0) {
- closeFile(getEditContentTempFileHandle(), true);
+ if (tempFlagSet(EDIT_CONTENT_MASK)) {
+ closeFile(editContentTempFileHandle);
}
}
/**
- * Returns if the attribute needs to be accessed in a qualified manner or not, if it needs to be imported, then the
- * same needs to be done.
+ * Returns if the attribute needs to be accessed in a qualified manner or
+ * not, if it needs to be imported, then the same needs to be done.
*
- * @param importInfo import info for the current attribute being added
+ * @param importInfo import info
* @return status of the qualified access to the attribute
*/
- boolean getIsQualifiedAccessOrAddToImportList(
- JavaQualifiedTypeInfo importInfo) {
- return getJavaImportData().addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
- getGeneratedJavaClassName(),
- getJavaFileInfo().getPackage());
+ protected boolean getIsQualifiedAccessOrAddToImportList(JavaQualifiedTypeInfo
+ importInfo) {
+ return javaImportData
+ .addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
+ getGeneratedJavaClassName(),
+ javaFileInfo.getPackage());
}
/**
@@ -1907,15 +1799,6 @@
}
/**
- * Sets temp file handle for add to list interface.
- *
- * @param addToListInterfaceTempFileHandle temp file handle for add to list interface
- */
- private void setAddToListInterfaceTempFileHandle(File addToListInterfaceTempFileHandle) {
- this.addToListInterfaceTempFileHandle = addToListInterfaceTempFileHandle;
- }
-
- /**
* Returns temp file handle for add to list impl.
*
* @return temp file handle for add to list impl
@@ -1925,15 +1808,6 @@
}
/**
- * Sets temp file handle for add to list impl.
- *
- * @param addToListImplTempFileHandle temp file handle for add to list impl
- */
- private void setAddToListImplTempFileHandle(File addToListImplTempFileHandle) {
- this.addToListImplTempFileHandle = addToListImplTempFileHandle;
- }
-
- /**
* Returns temp file handle for leaf identifier attributes.
*
* @return temp file handle for leaf identifier attributes
@@ -1943,30 +1817,12 @@
}
/**
- * Sets temp file handle for leaf identifier attributes.
- *
- * @param leafIdAttributeTempFileHandle temp file handle for leaf identifier attributes
- */
- private void setLeafIdAttributeTempFileHandle(File leafIdAttributeTempFileHandle) {
- this.leafIdAttributeTempFileHandle = leafIdAttributeTempFileHandle;
- }
-
- /**
- * Returns if root node is set.
- *
- * @return true if root node
- */
- private boolean isRooNode() {
- return isRooNode;
- }
-
- /**
* Sets true if root node.
*
- * @param rooNode true if root node
+ * @param rootNode true if root node
*/
- void setRooNode(boolean rooNode) {
- isRooNode = rooNode;
+ void setRootNode(boolean rootNode) {
+ this.rootNode = rootNode;
}
/**
@@ -1979,15 +1835,6 @@
}
/**
- * Sets temp file handle for is content match.
- *
- * @param subtreeFilteringForLeafTempFileHandle temp file handle for is content match
- */
- private void setSubtreeFilteringForLeafTempFileHandle(File subtreeFilteringForLeafTempFileHandle) {
- this.subtreeFilteringForLeafTempFileHandle = subtreeFilteringForLeafTempFileHandle;
- }
-
- /**
* Returns temp file for edit content file.
*
* @return temp file for edit content file
@@ -1997,15 +1844,6 @@
}
/**
- * Sets temp file for edit content file.
- *
- * @param editContentTempFileHandle temp file for edit content file
- */
- private void setEditContentTempFileHandle(File editContentTempFileHandle) {
- this.editContentTempFileHandle = editContentTempFileHandle;
- }
-
- /**
* Returns temp file for is content match.
*
* @return temp file for is content match
@@ -2015,15 +1853,6 @@
}
/**
- * Sets temp file handle for is content match.
- *
- * @param getSubtreeFilteringForListTempFileHandle temp file handle for is content match
- */
- private void setGetSubtreeFilteringForListTempFileHandle(File getSubtreeFilteringForListTempFileHandle) {
- this.getSubtreeFilteringForListTempFileHandle = getSubtreeFilteringForListTempFileHandle;
- }
-
- /**
* Returns temp file for is content match.
*
* @return temp file for is content match
@@ -2033,11 +1862,27 @@
}
/**
- * Sets temp file handle for is content match.
+ * Checks if a given flag is set in generated java files.
+ * Returns true if ANY flag is set in a bitwise-ORed argument, e.g.
+ * <pre>
+ * javaFlagSet(FOO | BAR)
+ * </pre>
+ * returns true if either FOO flag or BAR flag is set.
*
- * @param getSubtreeFilteringForChildNodeTempFileHandle temp file handle for is content match
+ * @param flag input flag mask value
+ * @return true if set, else false
*/
- private void setGetSubtreeFilteringForChildNodeTempFileHandle(File getSubtreeFilteringForChildNodeTempFileHandle) {
- this.getSubtreeFilteringForChildNodeTempFileHandle = getSubtreeFilteringForChildNodeTempFileHandle;
+ private boolean javaFlagSet(int flag) {
+ return (getGeneratedJavaFiles() & flag) != 0;
+ }
+
+ /**
+ * Checks if a given flag is set in temp files.
+ *
+ * @param flag input flag mask value
+ * @return true if set, else false
+ */
+ private boolean tempFlagSet(int flag) {
+ return (tempFilesFlagSet & flag) != 0;
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
index 97817d4..8d08754 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
@@ -16,15 +16,15 @@
package org.onosproject.yangutils.translator.tojava;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
@@ -37,6 +37,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.Operation.ADD;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
@@ -45,11 +46,11 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
- * Represents implementation of java service code fragments temporary implementations. Maintains the temp files required
- * specific for service and manager java snippet generation.
+ * Represents implementation of java service code fragments temporary
+ * implementations. Maintains the temp files required specific for service
+ * and manager java snippet generation.
*/
-public class TempJavaServiceFragmentFiles
- extends TempJavaFragmentFiles {
+public class TempJavaServiceFragmentFiles extends TempJavaFragmentFiles {
/**
* File name for rpc method.
@@ -92,31 +93,15 @@
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
- setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
+ setAbsoluteDirPath(getAbsolutePackagePath(
+ getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
addGeneratedTempFile(RPC_INTERFACE_MASK);
addGeneratedTempFile(RPC_IMPL_MASK);
- setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
- setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
- }
-
- /**
- * Returns rpc method's java file handle.
- *
- * @return java file handle
- */
- private File getServiceInterfaceJavaFileHandle() {
- return serviceInterfaceJavaFileHandle;
- }
-
- /**
- * Sets rpc method's java file handle.
- *
- * @param serviceInterfaceJavaFileHandle file handle for to rpc method
- */
- private void setServiceInterfaceJavaFileHandle(File serviceInterfaceJavaFileHandle) {
- this.serviceInterfaceJavaFileHandle = serviceInterfaceJavaFileHandle;
+ rpcInterfaceTempFileHandle =
+ getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME);
+ rpcImplTempFileHandle = getTemporaryFileHandle(RPC_IMPL_FILE_NAME);
}
/**
@@ -129,15 +114,6 @@
}
/**
- * Sets rpc method's temporary file handle.
- *
- * @param rpcInterfaceTempFileHandle file handle for to rpc method
- */
- private void setRpcInterfaceTempFileHandle(File rpcInterfaceTempFileHandle) {
- this.rpcInterfaceTempFileHandle = rpcInterfaceTempFileHandle;
- }
-
- /**
* Retrieves the manager impl temp file.
*
* @return the manager impl temp file
@@ -147,15 +123,6 @@
}
/**
- * Sets the manager impl temp file.
- *
- * @param rpcImplTempFileHandle the manager impl temp file
- */
- private void setRpcImplTempFileHandle(File rpcImplTempFileHandle) {
- this.rpcImplTempFileHandle = rpcImplTempFileHandle;
- }
-
- /**
* Constructs java code exit.
*
* @param fileType generated file type
@@ -167,26 +134,31 @@
throws IOException {
addResolvedAugmentedDataNodeImports(curNode);
- List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles()
+ List<String> imports = ((JavaCodeGeneratorInfo) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles()
.getJavaImportData().getImports();
createPackage(curNode);
- boolean isNotification = false;
+ boolean notification = false;
if (curNode instanceof YangJavaModuleTranslator) {
- if (!((YangJavaModuleTranslator) curNode).getNotificationNodes().isEmpty()) {
- isNotification = true;
+ if (!((YangJavaModuleTranslator) curNode).getNotificationNodes()
+ .isEmpty()) {
+ notification = true;
}
} else if (curNode instanceof YangJavaSubModuleTranslator) {
- if (!((YangJavaSubModuleTranslator) curNode).getNotificationNodes().isEmpty()) {
- isNotification = true;
+ if (!((YangJavaSubModuleTranslator) curNode).getNotificationNodes()
+ .isEmpty()) {
+ notification = true;
}
}
- if (isNotification) {
- addListenersImport(curNode, imports, true, LISTENER_SERVICE);
+ if (notification) {
+ addListenersImport(curNode, imports, ADD, LISTENER_SERVICE);
}
- setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
- generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports);
+ serviceInterfaceJavaFileHandle =
+ getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX));
+ generateServiceInterfaceFile(serviceInterfaceJavaFileHandle, curNode,
+ imports);
// Close all the file handles.
freeTemporaryResources(false);
@@ -195,70 +167,70 @@
/**
* Adds rpc string information to applicable temp file.
*
- * @param javaAttributeInfoOfInput RPCs input node attribute info
- * @param javaAttributeInfoOfOutput RPCs output node attribute info
- * @param rpcName name of the rpc function
- * @param pluginConfig plugin configurations
+ * @param inputAttr RPCs input node attribute info
+ * @param outputAttr RPCs output node attribute info
+ * @param rpcName name of the rpc function
+ * @param config plugin configurations
* @throws IOException IO operation fail
*/
- private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput,
- JavaAttributeInfo javaAttributeInfoOfOutput, YangPluginConfig pluginConfig,
- String rpcName)
+ private void addRpcString(JavaAttributeInfo inputAttr,
+ JavaAttributeInfo outputAttr,
+ YangPluginConfig config, String rpcName)
throws IOException {
String rpcInput = EMPTY_STRING;
String rpcOutput = VOID;
String rpcInputJavaDoc = EMPTY_STRING;
- if (javaAttributeInfoOfInput != null) {
- rpcInput = getCapitalCase(javaAttributeInfoOfInput.getAttributeName());
+ if (inputAttr != null) {
+ rpcInput = getCapitalCase(inputAttr.getAttributeName());
}
- if (javaAttributeInfoOfOutput != null) {
- rpcOutput = getCapitalCase(javaAttributeInfoOfOutput.getAttributeName());
+ if (outputAttr != null) {
+ rpcOutput = getCapitalCase(outputAttr.getAttributeName());
}
if (!rpcInput.equals(EMPTY_STRING)) {
rpcInputJavaDoc = RPC_INPUT_VAR_NAME;
}
- appendToFile(getRpcInterfaceTempFileHandle(),
- generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput, pluginConfig)
- + getRpcServiceMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
- appendToFile(getRpcImplTempFileHandle(),
- getRpcManagerMethod(rpcName, rpcInput, rpcOutput, pluginConfig) + NEW_LINE);
+ appendToFile(rpcInterfaceTempFileHandle,
+ generateJavaDocForRpc(rpcName, rpcInputJavaDoc, rpcOutput,
+ config) +
+ getRpcServiceMethod(rpcName, rpcInput, rpcOutput,
+ config) + NEW_LINE);
+ appendToFile(rpcImplTempFileHandle,
+ getRpcManagerMethod(rpcName, rpcInput, rpcOutput, config) +
+ NEW_LINE);
}
/**
* Adds the JAVA rpc snippet information.
*
- * @param javaAttributeInfoOfInput RPCs input node attribute info
- * @param javaAttributeInfoOfOutput RPCs output node attribute info
- * @param pluginConfig plugin configurations
- * @param rpcName name of the rpc function
+ * @param inputAttr RPCs input node attribute info
+ * @param outputAttr RPCs output node attribute info
+ * @param config plugin configurations
+ * @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
- public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
- JavaAttributeInfo javaAttributeInfoOfOutput,
- YangPluginConfig pluginConfig, String rpcName)
+ public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo inputAttr,
+ JavaAttributeInfo outputAttr,
+ YangPluginConfig config,
+ String rpcName)
throws IOException {
- addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, pluginConfig, rpcName);
+ addRpcString(inputAttr, outputAttr, config, rpcName);
}
/**
* Removes all temporary file handles.
*
- * @param isErrorOccurred flag to tell translator that error has occurred while file generation
+ * @param errorOccurred flag indicating error
* @throws IOException when failed to delete the temporary files
*/
@Override
- public void freeTemporaryResources(boolean isErrorOccurred)
+ public void freeTemporaryResources(boolean errorOccurred)
throws IOException {
-
- closeFile(getServiceInterfaceJavaFileHandle(), isErrorOccurred);
-
- closeFile(getRpcInterfaceTempFileHandle(), true);
- closeFile(getRpcImplTempFileHandle(), true);
- closeFile(getGetterInterfaceTempFileHandle(), true);
- closeFile(getSetterInterfaceTempFileHandle(), true);
- closeFile(getSetterImplTempFileHandle(), true);
-
- super.freeTemporaryResources(isErrorOccurred);
-
+ closeFile(serviceInterfaceJavaFileHandle, errorOccurred);
+ closeFile(rpcInterfaceTempFileHandle);
+ closeFile(rpcImplTempFileHandle);
+ closeFile(getGetterInterfaceTempFileHandle());
+ closeFile(getSetterInterfaceTempFileHandle());
+ closeFile(getSetterImplTempFileHandle());
+ super.freeTemporaryResources(errorOccurred);
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
index 7891b08..ed37a36 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
@@ -16,10 +16,6 @@
package org.onosproject.yangutils.translator.tojava;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
@@ -38,11 +34,22 @@
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_TRANSLATION_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsgForCodeGenerator;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
@@ -54,145 +61,156 @@
*/
public final class YangJavaModelUtils {
- /**
- * Creates an instance of YANG java model utility.
- */
+ // No instantiation.
private YangJavaModelUtils() {
}
/**
* Updates YANG java file package information.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPluginConfig YANG plugin config
+ * @param info YANG java file info node
+ * @param config YANG plugin config
* @throws IOException IO operations fails
*/
- public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ public static void updatePackageInfo(JavaCodeGeneratorInfo info,
+ YangPluginConfig config)
throws IOException {
- if (javaCodeGeneratorInfo instanceof YangJavaAugmentTranslator) {
- updatePackageForAugmentInfo(javaCodeGeneratorInfo, yangPluginConfig);
+
+ JavaFileInfoTranslator translator = info.getJavaFileInfo();
+
+ if (info instanceof YangJavaAugmentTranslator) {
+ updatePackageForAugmentInfo(info, config);
} else {
- javaCodeGeneratorInfo.getJavaFileInfo()
- .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
- yangPluginConfig.getConflictResolver()));
- javaCodeGeneratorInfo.getJavaFileInfo().setJavaAttributeName(javaCodeGeneratorInfo
- .getJavaFileInfo().getJavaName());
- javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
+ translator.setJavaName(getCamelCase(((YangNode) info).getName(),
+ config.getConflictResolver()));
+ translator.setJavaAttributeName(info.getJavaFileInfo()
+ .getJavaName());
+ translator.setPackage(getCurNodePackage((YangNode) info));
}
- javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
- getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
-
- javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
- javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
-
+ updateCommonPackageInfo(translator, info, config);
}
/**
* Updates YANG java file package information.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPluginConfig YANG plugin config
+ * @param info YANG java file info node
+ * @param config YANG plugin config
* @throws IOException IO operations fails
*/
- private static void updatePackageForAugmentInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ private static void updatePackageForAugmentInfo(JavaCodeGeneratorInfo info,
+ YangPluginConfig config)
throws IOException {
- javaCodeGeneratorInfo.getJavaFileInfo()
- .setJavaName(getAugmentClassName((YangJavaAugmentTranslator) javaCodeGeneratorInfo,
- yangPluginConfig));
- javaCodeGeneratorInfo.getJavaFileInfo().setPackage(
- getAugmentsNodePackage((YangNode) javaCodeGeneratorInfo, yangPluginConfig));
- javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
- getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
- javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
- javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPluginConfig);
+
+ JavaFileInfoTranslator translator = info.getJavaFileInfo();
+
+ translator.setJavaName(getAugmentClassName(
+ (YangJavaAugmentTranslator) info, config));
+ translator.setPackage(getAugmentsNodePackage((YangNode) info, config));
+ updateCommonPackageInfo(translator, info, config);
}
/**
* Returns package for augment node.
*
- * @param yangNode augment node
- * @param yangPluginConfig plugin configurations
+ * @param yangNode augment node
+ * @param config plugin configurations
* @return package for augment node
*/
- private static String getAugmentsNodePackage(YangNode yangNode, YangPluginConfig yangPluginConfig) {
+ private static String getAugmentsNodePackage(YangNode yangNode,
+ YangPluginConfig config) {
YangAugment augment = (YangAugment) yangNode;
StringBuilder augmentPkg = new StringBuilder();
augmentPkg.append(getCurNodePackage(augment));
- String pkg = PERIOD;
+ StringBuilder pkg = new StringBuilder();
+ pkg.append(PERIOD);
for (YangAtomicPath atomicPath : augment.getTargetNode()) {
- pkg = pkg + getCamelCase(atomicPath.getNodeIdentifier().getName(), yangPluginConfig.getConflictResolver())
- + PERIOD;
+ pkg.append(getCamelCase(atomicPath.getNodeIdentifier().getName(),
+ config.getConflictResolver()))
+ .append(PERIOD);
}
- pkg = trimAtLast(pkg, PERIOD);
- augmentPkg.append(pkg.toLowerCase());
+ augmentPkg.append(trimAtLast(pkg.toString(), PERIOD).toLowerCase());
return augmentPkg.toString();
}
/**
* Updates YANG java file package information for specified package.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPlugin YANG plugin config
- * @throws IOException IO operations fails
+ * @param info YANG java file info node
+ * @param config YANG plugin config
*/
- private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
- String pkg)
- throws IOException {
- javaCodeGeneratorInfo.getJavaFileInfo()
- .setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
- yangPlugin.getConflictResolver()));
- javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
- javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
- getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
- javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
- javaCodeGeneratorInfo.getJavaFileInfo().setPluginConfig(yangPlugin);
+ private static void updatePackageInfo(JavaCodeGeneratorInfo info,
+ YangPluginConfig config,
+ String pkg) {
+
+ JavaFileInfoTranslator translator = info.getJavaFileInfo();
+ translator.setJavaName(getCamelCase(((YangNode) info).getName(),
+ config.getConflictResolver()));
+ translator.setPackage(pkg);
+ updateCommonPackageInfo(translator, info, config);
+ }
+
+ /**
+ * Updates common package information.
+ *
+ * @param translator JAVA file info translator
+ * @param info YANG java file info node
+ * @param config YANG plugin config
+ */
+ private static void updateCommonPackageInfo(JavaFileInfoTranslator translator,
+ JavaCodeGeneratorInfo info,
+ YangPluginConfig config) {
+ translator.setPackageFilePath(getPackageDirPathFromJavaJPackage(
+ info.getJavaFileInfo().getPackage()));
+ translator.setBaseCodeGenPath(config.getCodeGenDir());
+ translator.setPluginConfig(config);
}
/**
* Updates temporary java code fragment files.
*
- * @param javaCodeGeneratorInfo YANG java file info node
+ * @param info YANG java file info node
* @throws IOException IO operations fails
*/
- private static void createTempFragmentFile(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
+ private static void createTempFragmentFile(JavaCodeGeneratorInfo info)
throws IOException {
- javaCodeGeneratorInfo.setTempJavaCodeFragmentFiles(
- new TempJavaCodeFragmentFiles(javaCodeGeneratorInfo.getJavaFileInfo()));
+ info.setTempJavaCodeFragmentFiles(
+ new TempJavaCodeFragmentFiles(info.getJavaFileInfo()));
}
/**
* Updates leaf information in temporary java code fragment files.
*
- * @param javaCodeGeneratorInfo YANG java file info node
+ * @param info YANG java file info node
* @throws IOException IO operations fails
*/
- private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ private static void updateTempFragmentFiles(JavaCodeGeneratorInfo info,
+ YangPluginConfig config)
throws IOException {
- if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().setRooNode(true);
+ TempJavaCodeFragmentFiles translator =
+ info.getTempJavaCodeFragmentFiles();
+
+ if (info instanceof RpcNotificationContainer) {
+ getBeanFiles(info).setRootNode(true);
/*
* Module / sub module node code generation.
*/
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
- (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
- if (javaCodeGeneratorInfo instanceof YangJavaModuleTranslator) {
- if (!((YangJavaModuleTranslator) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
- updateNotificationNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
+ translator.getServiceTempFiles()
+ .addCurNodeLeavesInfoToTempFiles((YangNode) info, config);
+ if (info instanceof YangJavaModuleTranslator) {
+ if (!((YangJavaModuleTranslator) info).getNotificationNodes()
+ .isEmpty()) {
+ updateNotificationNodeInfo(info, config);
}
- } else if (javaCodeGeneratorInfo instanceof YangJavaSubModuleTranslator) {
- if (!((YangJavaSubModuleTranslator) javaCodeGeneratorInfo).getNotificationNodes().isEmpty()) {
- updateNotificationNodeInfo(javaCodeGeneratorInfo, yangPluginConfig);
+ } else if (info instanceof YangJavaSubModuleTranslator) {
+ if (!((YangJavaSubModuleTranslator) info).getNotificationNodes()
+ .isEmpty()) {
+ updateNotificationNodeInfo(info, config);
}
}
-
}
- if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
+ if (info instanceof YangLeavesHolder) {
/*
* Container
* Case
@@ -202,155 +220,157 @@
* Notification
* Output
*/
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
- (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
- } else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
+ getBeanFiles(info).addCurNodeLeavesInfoToTempFiles((YangNode) info,
+ config);
+
+ // Add operation type as an attribute.
+ getBeanFiles(info).addOperationTypeToTempFiles((YangNode) info,
+ config);
+ } else if (info instanceof YangTypeHolder) {
/*
* Typedef
* Union
*/
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo, yangPluginConfig);
- } else if (javaCodeGeneratorInfo instanceof YangJavaEnumerationTranslator) {
+ translator.addTypeInfoToTempFiles((YangTypeHolder) info, config);
+ } else if (info instanceof YangJavaEnumerationTranslator) {
/*
* Enumeration
*/
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
- .addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo, yangPluginConfig);
-
- } else if (javaCodeGeneratorInfo instanceof YangChoice) {
+ translator.getEnumerationTempFiles()
+ .addEnumAttributeToTempFiles((YangNode) info, config);
+ } else if (info instanceof YangChoice) {
/*Do nothing, only the interface needs to be generated*/
} else {
- throw new TranslatorException("Unsupported Node Translation "
- + javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ throw new TranslatorException(
+ getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
+ info));
}
}
/**
* Process generate code entry of YANG node.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPluginConfig plugin configurations
+ * @param info YANG java file info node
+ * @param config plugin configurations
* @throws IOException IO operations fails
*/
- private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ private static void generateTempFiles(JavaCodeGeneratorInfo info,
+ YangPluginConfig config)
throws IOException {
- if (!(javaCodeGeneratorInfo instanceof YangNode)) {
- throw new TranslatorException("translation is not supported for the node "
- + javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ if (!(info instanceof YangNode)) {
+ throw new TranslatorException(
+ getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
+ info));
}
- createTempFragmentFile(javaCodeGeneratorInfo);
- updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig);
-
+ createTempFragmentFile(info);
+ updateTempFragmentFiles(info, config);
}
/**
* Updates notification node info in service temporary file.
*
- * @param javaCodeGeneratorInfo java code generator info
- * @param yangPluginConfig plugin configurations
+ * @param info java code generator info
+ * @param config plugin configurations
* @throws IOException when fails to do IO operations
*/
- private static void updateNotificationNodeInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ private static void updateNotificationNodeInfo(JavaCodeGeneratorInfo info,
+ YangPluginConfig config)
throws IOException {
- if (javaCodeGeneratorInfo instanceof YangJavaModuleTranslator) {
- for (YangNode notification : ((YangJavaModuleTranslator) javaCodeGeneratorInfo).getNotificationNodes()) {
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .getEventFragmentFiles()
- .addJavaSnippetOfEvent(notification, yangPluginConfig);
+ TempJavaCodeFragmentFiles translator =
+ info.getTempJavaCodeFragmentFiles();
+ if (info instanceof YangJavaModuleTranslator) {
+ for (YangNode notification : ((YangJavaModuleTranslator) info)
+ .getNotificationNodes()) {
+ translator.getEventFragmentFiles()
+ .addJavaSnippetOfEvent(notification, config);
}
}
- if (javaCodeGeneratorInfo instanceof YangJavaSubModuleTranslator) {
- for (YangNode notification : ((YangJavaSubModuleTranslator) javaCodeGeneratorInfo)
+ if (info instanceof YangJavaSubModuleTranslator) {
+ for (YangNode notification : ((YangJavaSubModuleTranslator) info)
.getNotificationNodes()) {
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
- .getEventFragmentFiles()
- .addJavaSnippetOfEvent(notification, yangPluginConfig);
+ translator.getEventFragmentFiles()
+ .addJavaSnippetOfEvent(notification, config);
}
}
}
/**
- * Generates code for the current ata model node and adds itself as an attribute in the parent.
+ * Generates code for the current ata model node and adds itself as an
+ * attribute in the parent.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPlugin YANG plugin config
- * @param isMultiInstance flag to indicate whether it's a list
+ * @param info YANG java file info node
+ * @param config YANG plugin config
+ * @param isMultiInstance flag to indicate whether it's a list
* @throws IOException IO operations fails
*/
- public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPlugin, boolean isMultiInstance)
+ public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo info,
+ YangPluginConfig config,
+ boolean isMultiInstance)
throws IOException {
- if (!(javaCodeGeneratorInfo instanceof YangNode)) {
- throw new TranslatorException("Invalid node for translation " +
- javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ if (!(info instanceof YangNode)) {
+ throw new TranslatorException(
+ getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
+ info));
}
/*
* Generate the Java files corresponding to the current node.
*/
- generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin);
+ generateCodeOfAugmentableNode(info, config);
/*
* Update the current nodes info in its parent nodes generated files.
*/
- addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance, yangPlugin);
+ addCurNodeInfoInParentTempFile((YangNode) info, isMultiInstance,
+ config);
}
/**
- * Generates code for the current data model node and adds support for it to be augmented.
+ * Generates code for the current data model node and adds support for it to
+ * be augmented.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPlugin YANG plugin config
+ * @param info YANG java file info node
+ * @param config YANG plugin config
* @throws IOException IO operations fails
*/
- public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPlugin)
+ public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo info,
+ YangPluginConfig config)
throws IOException {
- if (!(javaCodeGeneratorInfo instanceof YangNode)) {
- throw new TranslatorException("invalid node for translation " +
- javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ if (!(info instanceof YangNode)) {
+ throw new TranslatorException(
+ getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
+ info));
}
- generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
- TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles();
+ generateCodeOfNode(info, config);
+ TempJavaCodeFragmentFiles tempFiles =
+ info.getTempJavaCodeFragmentFiles();
- if (javaCodeGeneratorInfo instanceof YangCase) {
- YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
- JavaQualifiedTypeInfoTranslator parentsInfo = getQualifierInfoForCasesParent(parent, yangPlugin);
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
- .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo,
- tempJavaCodeFragmentFiles.getBeanTempFiles());
+ if (info instanceof YangCase) {
+ YangNode parent = ((YangCase) info).getParent();
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ getQualifierInfoForCasesParent(parent, config);
+ getBeanFiles(info).getJavaExtendsListHolder()
+ .addToExtendsList(typeInfo, (YangNode) info,
+ tempFiles.getBeanTempFiles());
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
- .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo, yangPlugin);
-
+ getBeanFiles(info).addParentInfoInCurNodeTempFile((YangNode) info,
+ config);
}
}
/**
* Returns cases parent's qualified info.
*
- * @param parent parent node
- * @param yangPluginConfig plugin configuration
+ * @param parent parent node
+ * @param config plugin configuration
* @return cases parent's qualified info
*/
- public static JavaQualifiedTypeInfoTranslator getQualifierInfoForCasesParent(YangNode parent,
- YangPluginConfig yangPluginConfig) {
+ public static JavaQualifiedTypeInfoTranslator
+ getQualifierInfoForCasesParent(YangNode parent,
+ YangPluginConfig config) {
String parentName;
String parentPkg;
- JavaQualifiedTypeInfoTranslator parentsInfo = new JavaQualifiedTypeInfoTranslator();
JavaFileInfoTranslator parentInfo;
if (parent instanceof YangChoice) {
parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
@@ -362,59 +382,60 @@
parentName = getCapitalCase(parentInfo.getJavaName());
parentPkg = parentInfo.getPackage();
} else {
- parentName = getCapitalCase(getCamelCase(parent.getName(), yangPluginConfig.getConflictResolver()));
- parentPkg = getNodesPackage(parent, yangPluginConfig);
+ parentName = getCapitalCase(getCamelCase(parent.getName(),
+ config.getConflictResolver()));
+ parentPkg = getNodesPackage(parent, config);
}
- parentsInfo.setClassInfo(parentName);
- parentsInfo.setPkgInfo(parentPkg);
- return parentsInfo;
-
+ JavaQualifiedTypeInfoTranslator qualifiedTypeInfo =
+ new JavaQualifiedTypeInfoTranslator();
+ qualifiedTypeInfo.setClassInfo(parentName);
+ qualifiedTypeInfo.setPkgInfo(parentPkg);
+ return qualifiedTypeInfo;
}
/**
* Generates code for the current data model node.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPluginConfig YANG plugin config
+ * @param info YANG java file info node
+ * @param config YANG plugin config
* @throws IOException IO operations fails
*/
- public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig)
+ public static void generateCodeOfNode(JavaCodeGeneratorInfo info,
+ YangPluginConfig config)
throws IOException {
- if (!(javaCodeGeneratorInfo instanceof YangNode)) {
- throw new TranslatorException("invalid node for translation "
- + javaCodeGeneratorInfo.getLineNumber() + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ if (!(info instanceof YangNode)) {
+ throw new TranslatorException(
+ getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
+ info));
}
- updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig);
- generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
+ updatePackageInfo(info, config);
+ generateTempFiles(info, config);
}
/**
* Generates code for the root module/sub-module node.
*
- * @param javaCodeGeneratorInfo YANG java file info node
- * @param yangPluginConfig YANG plugin config
- * @param rootPkg package of the root node
+ * @param info YANG java file info node
+ * @param config YANG plugin config
+ * @param rootPkg package of the root node
* @throws IOException IO operations fails
*/
- public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
- YangPluginConfig yangPluginConfig, String rootPkg)
+ public static void generateCodeOfRootNode(JavaCodeGeneratorInfo info,
+ YangPluginConfig config,
+ String rootPkg)
throws IOException {
- if (!(javaCodeGeneratorInfo instanceof YangNode)) {
- throw new TranslatorException("invalid node for translation " + javaCodeGeneratorInfo.getLineNumber()
- + " at " +
- javaCodeGeneratorInfo.getCharPosition()
- + " in " + javaCodeGeneratorInfo.getFileName());
+ if (!(info instanceof YangNode)) {
+ throw new TranslatorException(
+ getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
+ info));
}
- updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg);
+ updatePackageInfo(info, config, rootPkg);
- if (isRpcChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
- javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
+ if (isRpcChildNodePresent((YangNode) info)) {
+ info.getJavaFileInfo()
+ .addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
-
- generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
+ generateTempFiles(info, config);
}
/**
@@ -423,28 +444,23 @@
* @param curNode current java node whose package string needs to be set
* @return returns the root package string
*/
- public static String getCurNodePackage(YangNode curNode) {
+ public static String getCurNodePackage(YangNode curNode)
+ throws TranslatorException {
String pkg;
- if (!(curNode instanceof JavaFileInfoContainer)
- || curNode.getParent() == null) {
- throw new TranslatorException("missing parent node to get current node's package " +
- curNode.getName() + " in " +
- curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ if (!(curNode instanceof JavaFileInfoContainer) ||
+ curNode.getParent() == null) {
+ throw new TranslatorException(getErrorMsg(INVALID_NODE, curNode));
}
YangNode parentNode = DataModelUtils.getParentNodeInGenCode(curNode);
if (!(parentNode instanceof JavaFileInfoContainer)) {
- throw new TranslatorException("missing parent java node to get current node's package " +
- curNode.getName() + " in " +
- curNode.getLineNumber() + " at " +
- curNode.getCharPosition()
- + " in " + curNode.getFileName());
+ throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
+ curNode));
}
- JavaFileInfoTranslator parentJavaFileHandle = ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
- pkg = parentJavaFileHandle.getPackage() + PERIOD + parentJavaFileHandle.getJavaName();
+ JavaFileInfoTranslator handle =
+ ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
+ pkg = handle.getPackage() + PERIOD + handle.getJavaName();
return pkg.toLowerCase();
}
@@ -455,74 +471,80 @@
* @return true if root node contains any data node
*/
public static boolean isRootNodesCodeGenRequired(YangNode node) {
- YangLeavesHolder holder = (YangLeavesHolder) node;
-
- if (holder.getListOfLeaf().isEmpty()) {
- if (holder.getListOfLeafList().isEmpty()) {
- YangNode tempNode = node.getChild();
- if (tempNode == null) {
- return false;
- }
- while (tempNode != null) {
- if (!(tempNode instanceof YangTranslatorOperatorNode)) {
- return true;
- }
- tempNode = tempNode.getNextSibling();
- }
- return false;
- } else {
- return true;
- }
- } else {
- return true;
- }
+ return isNodeCodeGenRequired(node, true);
}
/**
* Returns true if get/set method of root node are required.
*
- * @param curNode root node
+ * @param node root node
* @return true if get/set method of root node are required
*/
- public static boolean isGetSetOfRootNodeRequired(YangNode curNode) {
- YangLeavesHolder holder = (YangLeavesHolder) curNode;
+ public static boolean isGetSetOfRootNodeRequired(YangNode node) {
+ return isNodeCodeGenRequired(node, false);
+ }
- if (holder.getListOfLeaf().isEmpty()) {
- if (holder.getListOfLeafList().isEmpty()) {
- curNode = curNode.getChild();
- if (curNode == null) {
- return false;
- }
- while (curNode != null) {
- if (!(curNode instanceof YangAugment)) {
- return true;
- }
- curNode = curNode.getNextSibling();
- }
- return false;
- } else {
- return true;
- }
- } else {
+ /**
+ * Returns true if either get/set method of root node are required or root
+ * node contains any data node. This check is done depending on the
+ * boolean parameter indicating whether check to be performed for root
+ * node code generation or get/set method generation.
+ *
+ * @param node root node
+ * @param rootNodeGen flag indicating check type
+ * @return true if check pass, false otherwise
+ */
+ public static boolean isNodeCodeGenRequired(YangNode node,
+ boolean rootNodeGen) {
+ YangLeavesHolder holder = (YangLeavesHolder) node;
+
+ if (!holder.getListOfLeaf().isEmpty()) {
return true;
}
+ if (!holder.getListOfLeafList().isEmpty()) {
+ return true;
+ }
+ node = node.getChild();
+ if (node == null) {
+ return false;
+ }
+
+ if (rootNodeGen) {
+ while (node != null) {
+ if (!(node instanceof YangTranslatorOperatorNode)) {
+ return true;
+ }
+ node = node.getNextSibling();
+ }
+ return false;
+ }
+ while (node != null) {
+ if (!(node instanceof YangAugment)) {
+ return true;
+ }
+ node = node.getNextSibling();
+ }
+ return false;
}
/**
* Returns nodes package.
*
- * @param node YANG node
- * @param yangPluginConfig plugin config
+ * @param node YANG node
+ * @param config plugin config
* @return java package
*/
- public static String getNodesPackage(YangNode node, YangPluginConfig yangPluginConfig) {
+ public static String getNodesPackage(YangNode node,
+ YangPluginConfig config) {
List<String> clsInfo = new ArrayList<>();
while (node.getParent() != null) {
if (node instanceof YangJavaAugmentTranslator) {
- clsInfo.add(getAugmentClassName((YangAugment) node, yangPluginConfig));
+ clsInfo.add(getAugmentClassName((YangAugment) node,
+ config));
} else {
- clsInfo.add(getCamelCase(node.getName(), yangPluginConfig.getConflictResolver()));
+ clsInfo.add(getCamelCase(node.getName(), config
+ .getConflictResolver()));
}
node = node.getParent();
}
@@ -530,41 +552,44 @@
StringBuilder pkg = new StringBuilder();
if (node instanceof YangJavaModuleTranslator) {
YangJavaModuleTranslator module = (YangJavaModuleTranslator) node;
- pkg.append(getRootPackage(module.getVersion(), module.getNameSpace(), module
- .getRevision(), yangPluginConfig.getConflictResolver()));
+ pkg.append(getRootPackage(module.getVersion(), module.getNameSpace(),
+ module.getRevision(),
+ config.getConflictResolver()));
} else if (node instanceof YangJavaSubModuleTranslator) {
- YangJavaSubModuleTranslator subModule = (YangJavaSubModuleTranslator) node;
+ YangJavaSubModuleTranslator subModule =
+ (YangJavaSubModuleTranslator) node;
pkg.append(getRootPackage(subModule.getVersion(),
subModule.getNameSpaceFromModule(),
- subModule.getRevision(), yangPluginConfig.getConflictResolver()));
+ subModule.getRevision(),
+ config.getConflictResolver()));
}
- String concat = "";
- for (int i = 1; i <= clsInfo.size(); i++) {
- concat = concat + "." + clsInfo.get(clsInfo.size() - i);
+ pkg.append(EMPTY_STRING);
+ int size = clsInfo.size();
+ for (int i = size - 1; i >= 0; i--) {
+ pkg.append(PERIOD).append(clsInfo.get(i));
}
- pkg.append(concat);
return pkg.toString().toLowerCase();
-
}
/**
* Returns augment class name.
*
- * @param augment YANG augment
- * @param yangPluginConfig plugin configurations
+ * @param augment YANG augment
+ * @param config plugin configurations
* @return augment class name
*/
- private static String getAugmentClassName(YangAugment augment, YangPluginConfig yangPluginConfig) {
- YangNodeIdentifier yangNodeIdentifier = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
- .getNodeIdentifier();
- String name = getCapitalCase(getCamelCase(yangNodeIdentifier.getName(), yangPluginConfig
- .getConflictResolver()));
- if (yangNodeIdentifier.getPrefix() != null) {
- return AUGMENTED + getCapitalCase(getCamelCase(yangNodeIdentifier.getPrefix(), yangPluginConfig
- .getConflictResolver())) + name;
- } else {
- return AUGMENTED + name;
+ private static String getAugmentClassName(YangAugment augment,
+ YangPluginConfig config) {
+ YangNodeIdentifier identifier =
+ augment.getTargetNode().get(augment.getTargetNode().size() - 1)
+ .getNodeIdentifier();
+ String name = getCapitalCase(getCamelCase(identifier.getName(),
+ config.getConflictResolver()));
+ if (identifier.getPrefix() != null) {
+ return AUGMENTED + getCapitalCase(
+ getCamelCase(identifier.getPrefix(),
+ config.getConflictResolver())) + name;
}
+ return AUGMENTED + name;
}
-
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
index 88a9070..daffc7a 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
@@ -16,8 +16,6 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
-import java.io.IOException;
-
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaNotification;
@@ -33,9 +31,15 @@
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.IOException;
+
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
@@ -59,7 +63,6 @@
* Creates an instance of java Notification.
*/
public YangJavaNotificationTranslator() {
- super();
setJavaFileInfo(new JavaFileInfoTranslator());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
@@ -73,11 +76,7 @@
public JavaFileInfoTranslator getJavaFileInfo() {
if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
+ throw new TranslatorException(getErrorMsg(INVALID_NODE, this));
}
return (JavaFileInfoTranslator) javaFileInfo;
}
@@ -124,9 +123,12 @@
throws TranslatorException {
/*
- * As part of the notification support the following files needs to be generated.
- * 1) Subject of the notification(event), this is simple interface with builder class.
- * 2) Event class extending "AbstractEvent" and defining event type enum.
+ * As part of the notification support the following files needs to be
+ * generated.
+ * 1) Subject of the notification(event), this is simple interface with
+ * builder class.
+ * 2) Event class extending "AbstractEvent" and defining event type
+ * enum.
* 3) Event listener interface extending "EventListener".
*
* The manager class needs to extend the ListenerRegistry.
@@ -138,36 +140,34 @@
generateCodeOfAugmentableNode(this, yangPlugin);
addNotificationToExtendsList();
} catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for notification node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
+ e.getLocalizedMessage()));
}
}
/*Adds current notification info to the extends list so its parents service*/
private void addNotificationToExtendsList() {
YangNode parent = getParent();
- TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parent)
- .getTempJavaCodeFragmentFiles()
- .getServiceTempFiles();
- JavaExtendsListHolder holder = tempJavaServiceFragmentFiles.getJavaExtendsListHolder();
- JavaQualifiedTypeInfoTranslator event = new JavaQualifiedTypeInfoTranslator();
+ TempJavaServiceFragmentFiles tempFiles =
+ ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
+ JavaExtendsListHolder holder = tempFiles.getJavaExtendsListHolder();
+ JavaQualifiedTypeInfoTranslator event =
+ new JavaQualifiedTypeInfoTranslator();
String parentInfo = getCapitalCase(((JavaFileInfoContainer) parent)
- .getJavaFileInfo().getJavaName());
+ .getJavaFileInfo()
+ .getJavaName());
event.setClassInfo(parentInfo + EVENT_STRING);
event.setPkgInfo(getJavaFileInfo().getPackage());
- holder.addToExtendsList(event, parent, tempJavaServiceFragmentFiles);
+ holder.addToExtendsList(event, parent, tempFiles);
- JavaQualifiedTypeInfoTranslator eventListener = new JavaQualifiedTypeInfoTranslator();
+ JavaQualifiedTypeInfoTranslator eventListener =
+ new JavaQualifiedTypeInfoTranslator();
eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING);
eventListener.setPkgInfo(getJavaFileInfo().getPackage());
- holder.addToExtendsList(eventListener, parent, tempJavaServiceFragmentFiles);
-
+ holder.addToExtendsList(eventListener, parent, tempFiles);
}
/**
@@ -177,36 +177,34 @@
public void generateCodeExit()
throws TranslatorException {
try {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ getTempJavaCodeFragmentFiles().generateJavaFile(
+ GENERATE_INTERFACE_WITH_BUILDER, this);
} catch (IOException e) {
- throw new TranslatorException("Failed to generate code for notification node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
+ throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
+ e.getLocalizedMessage()));
}
}
@Override
public void setNameSpaceAndAddToParentSchemaMap() {
// Get parent namespace.
- if (this.getParent() != null) {
- String nameSpace = this.getParent().getNameSpace();
+ if (getParent() != null) {
+ String nameSpace = getParent().getNameSpace();
// Set namespace for self node.
setNameSpace(nameSpace);
// Process addition of leaf to the child schema map of parent.
processAdditionOfSchemaNodeToParentMap(getName(), getNameSpace());
// Obtain the notification name as per enum in notification.
- String enumName = getEnumJavaAttribute(getJavaFileInfo().getJavaName()).toUpperCase();
+ String enumName = getEnumJavaAttribute(getName().toUpperCase());
- ((RpcNotificationContainer) this.getParent()).addToNotificationEnumMap(enumName, this);
+ ((RpcNotificationContainer) getParent())
+ .addToNotificationEnumMap(enumName, this);
}
/*
* Check if node contains leaf/leaf-list, if yes add namespace for leaf
* and leaf list.
*/
- this.setLeafNameSpaceAndAddToParentSchemaMap();
-
+ setLeafNameSpaceAndAddToParentSchemaMap();
}
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index b47cc9c..3910a78 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -16,15 +16,18 @@
package org.onosproject.yangutils.translator.tojava.utils;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
+import org.onosproject.yangutils.utils.UtilConstants.Operation;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.util.List;
+
+import static java.util.Collections.sort;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
@@ -79,16 +82,12 @@
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
-import static java.util.Collections.sort;
-
/**
* Represents utility class to generate the java snippet.
*/
public final class JavaCodeSnippetGen {
- /**
- * Creates an instance of java code snippet gen.
- */
+ // No instantiation.
private JavaCodeSnippetGen() {
}
@@ -106,84 +105,119 @@
}
/**
- * Returns the textual java code information corresponding to the import list.
+ * Returns the textual java code information corresponding to the import
+ * list.
*
* @param importInfo import info
- * @return the textual java code information corresponding to the import list
+ * @return the textual java code information corresponding to the import
+ * list
*/
static String getImportText(JavaQualifiedTypeInfoTranslator importInfo) {
- return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
+ return IMPORT + importInfo.getPkgInfo() + PERIOD +
+ importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
}
/**
* Returns the textual java code for attribute definition in class.
*
- * @param javaAttributeTypePkg Package of the attribute type
- * @param javaAttributeType java attribute type
- * @param javaAttributeName name of the attribute
- * @param isList is list attribute
- * @param attributeAccessType attribute access type
- * @param compilerAnnotation compiler annotation
+ * @param typePkg Package of the attribute type
+ * @param attrType java attribute type
+ * @param attrName name of the attribute
+ * @param isList is list attribute
+ * @param accessType attribute access type
+ * @param annotation compiler annotation
* @return the textual java code for attribute definition in class
*/
- public static String getJavaAttributeDefinition(String javaAttributeTypePkg, String javaAttributeType,
- String javaAttributeName, boolean isList,
- String attributeAccessType,
- YangCompilerAnnotation compilerAnnotation) {
-
- String attributeDefinition = attributeAccessType + SPACE;
+ public static String getJavaAttributeDefinition(String typePkg,
+ String attrType,
+ String attrName,
+ boolean isList,
+ String accessType,
+ YangCompilerAnnotation annotation) {
+ StringBuilder attrDef = new StringBuilder();
+ attrDef.append(accessType).append(SPACE);
if (!isList) {
- if (javaAttributeTypePkg != null) {
- attributeDefinition = attributeDefinition + javaAttributeTypePkg + PERIOD;
+ if (typePkg != null) {
+ attrDef.append(typePkg).append(PERIOD);
}
- attributeDefinition = attributeDefinition + javaAttributeType + SPACE + javaAttributeName + SEMI_COLAN
- + NEW_LINE;
+ attrDef.append(attrType).append(SPACE)
+ .append(attrName).append(SEMI_COLAN)
+ .append(NEW_LINE);
} else {
- if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
- switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
- case QUEUE: {
- attributeDefinition = attributeDefinition + QUEUE + DIAMOND_OPEN_BRACKET;
- break;
- }
- case SET: {
- attributeDefinition = attributeDefinition + SET + DIAMOND_OPEN_BRACKET;
- break;
- }
- default: {
- attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
- }
- }
- } else {
- attributeDefinition = attributeDefinition + LIST + DIAMOND_OPEN_BRACKET;
+ // Add starting definition.
+ addAttrStartDef(annotation, attrDef);
+
+ if (typePkg != null) {
+ attrDef.append(typePkg).append(PERIOD);
}
- if (javaAttributeTypePkg != null) {
- attributeDefinition = attributeDefinition + javaAttributeTypePkg + PERIOD;
- }
+ attrDef.append(attrType);
- attributeDefinition = attributeDefinition + javaAttributeType;
-
- if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
- switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
- default: {
- attributeDefinition = attributeDefinition + DIAMOND_CLOSE_BRACKET + SPACE
- + javaAttributeName + SEMI_COLAN + NEW_LINE;
- }
- }
- } else {
- attributeDefinition = attributeDefinition + DIAMOND_CLOSE_BRACKET + SPACE
- + javaAttributeName + SPACE + EQUAL + SPACE + NEW + SPACE
- + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
- }
-
+ // Add ending definition.
+ addAttrEndDef(annotation, attrDef, attrName);
}
- return attributeDefinition;
+ return attrDef.toString();
}
/**
- * Returns based on the file type and the YANG name of the file, generate the class / interface definition close.
+ * Adds starting attribute definition.
+ *
+ * @param annotation compiler annotation
+ * @param attrDef JAVA attribute definition
+ */
+ private static void addAttrStartDef(YangCompilerAnnotation annotation,
+ StringBuilder attrDef) {
+ if (annotation != null &&
+ annotation.getYangAppDataStructure() != null) {
+ switch (annotation.getYangAppDataStructure().getDataStructure()) {
+ case QUEUE: {
+ attrDef.append(QUEUE)
+ .append(DIAMOND_OPEN_BRACKET);
+ break;
+ }
+ case SET: {
+ attrDef.append(SET)
+ .append(DIAMOND_OPEN_BRACKET);
+ break;
+ }
+ default: {
+ attrDef.append(LIST)
+ .append(DIAMOND_OPEN_BRACKET);
+ }
+ }
+ } else {
+ attrDef.append(LIST).append(DIAMOND_OPEN_BRACKET);
+ }
+ }
+
+ /**
+ * Adds ending attribute definition.
+ *
+ * @param annotation compiler annotation
+ * @param attrDef JAVA attribute definition
+ * @param attrName name of attribute
+ */
+ private static void addAttrEndDef(YangCompilerAnnotation annotation,
+ StringBuilder attrDef, String attrName) {
+ if (annotation != null &&
+ annotation.getYangAppDataStructure() != null) {
+ attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE)
+ .append(attrName).append(SEMI_COLAN)
+ .append(NEW_LINE);
+ // TODO refactor SEMI_COLAN, when refactoring in method generator.
+ } else {
+ attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE).append(attrName)
+ .append(SPACE).append(EQUAL).append(SPACE).append(NEW)
+ .append(SPACE).append(ARRAY_LIST).append(SEMI_COLAN)
+ .append(NEW_LINE);
+ }
+ }
+
+ /**
+ * Returns based on the file type and the YANG name of the file, generate
+ * the class / interface definition close.
*
* @return corresponding textual java code information
*/
@@ -200,25 +234,27 @@
*/
public static String generateEnumAttributeString(String name, int value) {
String enumName = getEnumJavaAttribute(name);
- return NEW_LINE + enumJavaDocForInnerClass(name)
- + EIGHT_SPACE_INDENTATION + enumName.toUpperCase() + OPEN_PARENTHESIS
- + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
+ return NEW_LINE + enumJavaDocForInnerClass(name) +
+ EIGHT_SPACE_INDENTATION + enumName.toUpperCase() +
+ OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
/**
* Returns string for enum's attribute for enum class.
*
- * @param name name of attribute
- * @param value value of the enum
- * @param pluginConfig plugin configurations
+ * @param name name of attribute
+ * @param value value of the enum
+ * @param config plugin configurations
* @return string for enum's attribute
*/
- public static String generateEnumAttributeStringWithSchemaName(String name, int value, YangPluginConfig
- pluginConfig) {
+ public static String generateEnumAttributeStringWithSchemaName(String name,
+ int value,
+ YangPluginConfig config) {
String enumName = getEnumJavaAttribute(name);
- return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, pluginConfig, null)
- + FOUR_SPACE_INDENTATION + enumName.toUpperCase() + OPEN_PARENTHESIS
- + value + COMMA + SPACE + QUOTES + name + QUOTES + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
+ return NEW_LINE + getJavaDoc(ENUM_ATTRIBUTE, name, false, config, null) +
+ FOUR_SPACE_INDENTATION + enumName.toUpperCase() +
+ OPEN_PARENTHESIS + value + COMMA + SPACE + QUOTES + name +
+ QUOTES + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
/**
@@ -238,8 +274,8 @@
* @return event enum start
*/
static String getEventEnumTypeStart() {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
- + NEW_LINE;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE +
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -250,16 +286,21 @@
* @param operation add or remove
* @param classInfo class info to be added to import list
*/
- public static void addListenersImport(YangNode curNode, List<String> imports, boolean operation,
+ public static void addListenersImport(YangNode curNode,
+ List<String> imports,
+ Operation operation,
String classInfo) {
String thisImport;
- TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles();
+ TempJavaServiceFragmentFiles tempFiles =
+ ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles();
if (classInfo.equals(LISTENER_SERVICE)) {
- thisImport = tempJavaServiceFragmentFiles.getJavaImportData().getListenerServiceImport();
+ thisImport = tempFiles.getJavaImportData()
+ .getListenerServiceImport();
performOperationOnImports(imports, thisImport, operation);
} else {
- thisImport = tempJavaServiceFragmentFiles.getJavaImportData().getListenerRegistryImport();
+ thisImport = tempFiles.getJavaImportData()
+ .getListenerRegistryImport();
performOperationOnImports(imports, thisImport, operation);
}
}
@@ -269,15 +310,21 @@
*
* @param imports list of imports
* @param curImport current import
- * @param operation add or remove
+ * @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);
+ private static List<String> performOperationOnImports(List<String> imports,
+ String curImport,
+ Operation operation) {
+ switch (operation) {
+ case ADD:
+ imports.add(curImport);
+ break;
+ case REMOVE:
+ imports.remove(curImport);
+ break;
+ default:
+ throw new TranslatorException("Invalid operation type");
}
sortImports(imports);
return imports;
@@ -290,9 +337,10 @@
* @return enum's attribute
*/
static String getEnumsValueAttribute(String className) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
- + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + STRING_DATA_TYPE + SPACE +
- SCHEMA_NAME + SEMI_COLAN + NEW_LINE;
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT +
+ SPACE + getSmallCase(className) + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + PRIVATE + SPACE + STRING_DATA_TYPE +
+ SPACE + SCHEMA_NAME + SEMI_COLAN + NEW_LINE;
}
/**
@@ -301,11 +349,14 @@
* @return attribute for augmentation
*/
static String addAugmentationAttribute() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + PROTECTED + SPACE + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING
- + DIAMOND_OPEN_BRACKET + QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING
- + DIAMOND_CLOSE_BRACKET + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL + SPACE +
- NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS
- + CLOSE_PARENTHESIS + SEMI_COLAN;
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PROTECTED + SPACE + MAP +
+ DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE +
+ OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE +
+ getSmallCase(YANG_AUGMENTED_INFO) + MAP + SPACE + EQUAL +
+ SPACE + NEW + SPACE + HASH_MAP + DIAMOND_OPEN_BRACKET +
+ DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
+ SEMI_COLAN;
}
/**
@@ -315,15 +366,16 @@
* @param addFirst true if int need to be added fist.
* @return attribute for int ranges
*/
- static String addStaticAttributeIntRange(String modifier, boolean addFirst) {
+ static String addStaticAttributeIntRange(String modifier,
+ boolean addFirst) {
if (addFirst) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + INT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
- modifier +
+ return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
+ INT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
SPACE + INT_MAX_RANGE_ATTR;
- } else {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + UINT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
- modifier + SPACE + UINT_MAX_RANGE_ATTR;
}
+ return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
+ UINT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
+ SPACE + UINT_MAX_RANGE_ATTR;
}
/**
@@ -333,14 +385,16 @@
* @param addFirst if need to be added first
* @return attribute for long ranges
*/
- static String addStaticAttributeLongRange(String modifier, boolean addFirst) {
+ static String addStaticAttributeLongRange(String modifier,
+ boolean addFirst) {
if (addFirst) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + LONG_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
+ return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
+ LONG_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION +
modifier + SPACE + LONG_MAX_RANGE_ATTR;
- } else {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + ULONG_MIN_RANGE_ATTR +
- FOUR_SPACE_INDENTATION + modifier + SPACE + ULONG_MAX_RANGE_ATTR;
}
+ return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
+ ULONG_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
+ SPACE + ULONG_MAX_RANGE_ATTR;
}
/**
@@ -350,15 +404,16 @@
* @param addFirst if need to be added first
* @return attribute for long ranges
*/
- static String addStaticAttributeShortRange(String modifier, boolean addFirst) {
+ static String addStaticAttributeShortRange(String modifier,
+ boolean addFirst) {
if (addFirst) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + SHORT_MIN_RANGE_ATTR +
- FOUR_SPACE_INDENTATION +
- modifier + SPACE + SHORT_MAX_RANGE_ATTR;
- } else {
- return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE + UINT8_MIN_RANGE_ATTR +
- FOUR_SPACE_INDENTATION + modifier + SPACE + UINT8_MAX_RANGE_ATTR;
+ return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
+ SHORT_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
+ SPACE + SHORT_MAX_RANGE_ATTR;
}
+ return NEW_LINE + FOUR_SPACE_INDENTATION + modifier + SPACE +
+ UINT8_MIN_RANGE_ATTR + FOUR_SPACE_INDENTATION + modifier +
+ SPACE + UINT8_MAX_RANGE_ATTR;
}
/**
@@ -383,9 +438,10 @@
}
/**
- * Returns operation type enum, leaf value set attribute and select leaf attribute.
+ * Returns operation type enum, leaf value set attribute and select leaf
+ * attribute.
*
- * @return operation type enum, leaf value set attribute and select leaf attribute.
+ * @return operation attributes for value and select leaf flags
*/
static String getOperationAttributes() {
return " /**\n" +
@@ -401,23 +457,10 @@
}
/**
- * Returns operation type enum, leaf value set attribute and select leaf attribute.
+ * Returns operation type enum, leaf value set attribute and select leaf
+ * attribute for constructor.
*
- * @return operation type enum, leaf value set attribute and select leaf attribute.
- */
- static String getOperationTypeAttr() {
- return "\n /**\n" +
- " * Specify the node specific operation in protocols like NETCONF.\n" +
- " * Applicable in protocol edit operation, will be ignored in query operation\n" +
- " */\n" +
- " private OnosYangNodeOperationType onosYangNodeOperationType;\n" +
- "\n";
- }
-
- /**
- * Returns operation type enum, leaf value set attribute and select leaf attribute for constructor.
- *
- * @return operation type enum, leaf value set attribute and select leaf attribute for constructor
+ * @return operation attributes for constructor
*/
static String getOperationAttributeForConstructor() {
return " this.valueLeafFlags = builderObject.getValueLeafFlags();\n" +
@@ -425,18 +468,9 @@
}
/**
- * Returns operation type enum, leaf value set attribute and select leaf attribute for constructor.
- *
- * @return operation type enum, leaf value set attribute and select leaf attribute for constructor
- */
- static String getOperationTypeForConstructor() {
- return " this.onosYangNodeOperationType = builderObject.onosYangNodeOperationType();\n";
- }
-
- /**
* Returns attribute in constructor for yang augmented info map.
*
- * @return attribute in constructor for yang augmented info map
+ * @return augment info map
*/
static String getYangAugmentedMapObjectForConstruct() {
return " this.yangAugmentedInfoMap = builderObject.yangAugmentedInfoMap();\n";
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index d3df0dc..6853ac9 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -16,11 +16,6 @@
package org.onosproject.yangutils.translator.tojava.utils;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
@@ -43,8 +38,15 @@
import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
+import org.onosproject.yangutils.utils.UtilConstants;
import org.onosproject.yangutils.utils.io.YangPluginConfig;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.util.Collections.sort;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
@@ -90,11 +92,8 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributeForConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributes;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeAttr;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeEnum;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeForConstructor;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen
- .getYangAugmentedMapObjectForConstruct;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getYangAugmentedMapObjectForConstruct;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.builderMethod;
@@ -110,7 +109,6 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForOperationType;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGettersForValueAndSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
@@ -121,7 +119,6 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationAttributesGetters;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForOperationType;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
@@ -134,23 +131,21 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.processSubtreeFilteringInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getAugmentableSubTreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getProcessChildNodeSubtreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getProcessLeafListSubtreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getProcessLeafSubtreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getProcessSubTreeFilteringEnd;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getProcessSubtreeFilteringStart;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator
- .getProcessSubtreeFunctionBody;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getAugmentableSubTreeFiltering;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessChildNodeSubtreeFiltering;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafListSubtreeFiltering;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafSubtreeFiltering;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubTreeFilteringEnd;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFilteringStart;
+import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFunctionBody;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.addDefaultConstructor;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
+import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getTypeFiles;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
@@ -158,12 +153,16 @@
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
+import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
@@ -173,12 +172,15 @@
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
+import static org.onosproject.yangutils.utils.UtilConstants.RPC_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
+import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_CLASS;
+import static org.onosproject.yangutils.utils.UtilConstants.UNION_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
@@ -188,115 +190,105 @@
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
-import static java.util.Collections.sort;
-
/**
* Representation of java file generator.
*/
public final class JavaFileGenerator {
+ // No instantiation
private JavaFileGenerator() {
}
/**
* Returns generated interface file for current node.
*
- * @param file file
- * @param imports imports for the file
- * @param curNode current YANG node
- * @param isAttrPresent if any attribute is present or not
+ * @param file file
+ * @param imports imports for the file
+ * @param curNode current YANG node
+ * @param attrPresent if any attribute is present or not
* @return interface file
* @throws IOException when fails to write in file
*/
public static File generateInterfaceFile(File file, List<String> imports,
YangNode curNode,
- boolean isAttrPresent)
+ boolean attrPresent)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
String path;
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
- path = javaFileInfo.getPluginConfig().getCodeGenDir() +
- javaFileInfo.getPackageFilePath();
+ path = fileInfo.getPluginConfig().getCodeGenDir() +
+ fileInfo.getPackageFilePath();
} else {
- path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
}
- String className = getCapitalCase(javaFileInfo.getJavaName());
+ String className = getCapitalCase(fileInfo.getJavaName());
- boolean isLeavesPresent;
+ boolean leavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
- isLeavesPresent = leavesHolder.getListOfLeaf() != null &&
- !leavesHolder.getListOfLeaf().isEmpty()
- || leavesHolder.getListOfLeafList() != null &&
- !leavesHolder.getListOfLeafList().isEmpty();
+ leavesPresent = leavesPresent(leavesHolder);
} else {
- isLeavesPresent = false;
+ leavesPresent = false;
}
initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode,
className);
+
+ // Generate ENUM interface
+ insertDataIntoJavaFile(file, getOperationTypeEnum());
+
List<String> methods = new ArrayList<>();
- if (isAttrPresent) {
+ if (attrPresent) {
// Add getter methods to interface file.
try {
//Leaf identifier enum.
- if (isLeavesPresent) {
+ if (leavesPresent) {
insertDataIntoJavaFile(file, NEW_LINE +
getInterfaceLeafIdEnumSignature(className) +
NEW_LINE +
- trimAtLast(replaceLast(getDataFromTempFileHandle(
- LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK,
- ((TempJavaCodeFragmentFilesContainer)
- curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path),
- COMMA, SEMI_COLAN),
- NEW_LINE) +
+ trimAtLast(replaceLast(
+ getDataFromTempFileHandle(
+ LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK,
+ getBeanFiles(curNode), path),
+ COMMA, SEMI_COLAN), NEW_LINE) +
NEW_LINE + NEW_LINE +
getInterfaceLeafIdEnumMethods());
}
//Getter methods.
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- GETTER_FOR_INTERFACE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path));
+ insertDataIntoJavaFile(
+ file, getDataFromTempFileHandle(
+ GETTER_FOR_INTERFACE_MASK,
+ getBeanFiles(curNode), path));
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files " +
- "for " +
- className
- + " while interface file generation");
+ throw new IOException(getErrorMsg(className, INTERFACE));
}
}
if (curNode instanceof YangAugmentableNode &&
!(curNode instanceof YangChoice)) {
methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface(
- javaFileInfo.getPluginConfig()));
+ methods.add(getYangAugmentInfoMapInterface(fileInfo.getPluginConfig()));
}
if (curNode instanceof YangCase) {
YangNode caseParent = curNode.getParent();
JavaQualifiedTypeInfo qualifiedTypeInfo =
getQualifierInfoForCasesParent(caseParent,
- javaFileInfo
- .getPluginConfig());
- methods.add(NEW_LINE + processSubtreeFilteringInterface
- (qualifiedTypeInfo.getClassInfo()));
+ fileInfo.getPluginConfig());
+ methods.add(NEW_LINE + processSubtreeFilteringInterface(
+ qualifiedTypeInfo.getClassInfo()));
} else {
methods.add(NEW_LINE + processSubtreeFilteringInterface(className));
}
- if (isLeavesPresent) {
+ if (leavesPresent) {
methods.add(NEW_LINE + isLeafValueSetInterface());
methods.add(NEW_LINE + isSelectLeafSetInterface());
}
@@ -304,85 +296,72 @@
insertDataIntoJavaFile(file, method);
}
return file;
-
}
/**
* Returns generated builder interface file for current node.
*
- * @param file file
- * @param curNode current YANG node
- * @param isAttrPresent if any attribute is present or not
+ * @param file file
+ * @param curNode current YANG node
+ * @param attrPresent if any attribute is present or not
* @return builder interface file
* @throws IOException when fails to write in file
*/
public static File generateBuilderInterfaceFile(File file, YangNode curNode,
- boolean isAttrPresent)
+ boolean attrPresent)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
- YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
+ YangPluginConfig pluginConfig = fileInfo.getPluginConfig();
- boolean isLeavesPresent;
+ boolean leavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
- isLeavesPresent = leavesHolder.getListOfLeaf() != null &&
- !leavesHolder.getListOfLeaf().isEmpty()
- || leavesHolder.getListOfLeafList() != null &&
- !leavesHolder.getListOfLeafList().isEmpty();
+ leavesPresent = leavesPresent(leavesHolder);
} else {
- isLeavesPresent = false;
+ leavesPresent = false;
}
- String className = getCapitalCase(javaFileInfo.getJavaName());
+ String className = getCapitalCase(fileInfo.getJavaName());
String path;
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
- path = javaFileInfo.getPluginConfig().getCodeGenDir() +
- javaFileInfo.getPackageFilePath();
+ path = fileInfo.getPluginConfig().getCodeGenDir() +
+ fileInfo.getPackageFilePath();
} else {
- path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
}
initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode,
className);
List<String> methods = new ArrayList<>();
- if (isAttrPresent) {
+ if (attrPresent) {
try {
//Getter methods.
- methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(
- GETTER_FOR_INTERFACE_MASK,
- ((TempJavaCodeFragmentFilesContainer)
- curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path));
+ methods.add(FOUR_SPACE_INDENTATION +
+ getDataFromTempFileHandle(
+ GETTER_FOR_INTERFACE_MASK,
+ getBeanFiles(curNode), path));
//Setter methods.
methods.add(NEW_LINE);
- methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(
- SETTER_FOR_INTERFACE_MASK,
- ((TempJavaCodeFragmentFilesContainer)
- curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path));
+ methods.add(FOUR_SPACE_INDENTATION +
+ getDataFromTempFileHandle(
+ SETTER_FOR_INTERFACE_MASK,
+ getBeanFiles(curNode), path));
//Add to list method.
methods.add(NEW_LINE);
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- ADD_TO_LIST_INTERFACE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path));
-
+ insertDataIntoJavaFile(file,
+ getDataFromTempFileHandle(
+ ADD_TO_LIST_INTERFACE_MASK,
+ getBeanFiles(curNode), path));
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files " +
- "for " +
- className
- + " while builder interface file generation");
+ throw new IOException(getErrorMsg(className,
+ BUILDER_INTERFACE));
}
}
@@ -390,19 +369,16 @@
!(curNode instanceof YangChoice)) {
methods.add(getAddAugmentInfoMethodInterface());
methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface(
- javaFileInfo.getPluginConfig()));
+ methods.add(getYangAugmentInfoMapInterface(fileInfo.getPluginConfig()));
}
- if (isLeavesPresent) {
+ if (leavesPresent) {
methods.add(NEW_LINE + setSelectLeafSetInterface(className));
}
//Add build method to builder interface file.
- methods.add(
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .addBuildMethodForInterface(pluginConfig));
-
+ methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles()
+ .addBuildMethodForInterface(pluginConfig));
//Add getters and setters in builder interface.
for (String method : methods) {
@@ -416,43 +392,39 @@
/**
* Returns generated builder class file for current node.
*
- * @param file file
- * @param curNode current YANG node
- * @param isAttrPresent if any attribute is present or not
+ * @param file file
+ * @param curNode current YANG node
+ * @param attrPresent if any attribute is present or not
* @return builder class file
* @throws IOException when fails to write in file
*/
-
public static File generateBuilderClassFile(File file, YangNode curNode,
- boolean isAttrPresent)
+ boolean attrPresent)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
- YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
+ YangPluginConfig config = fileInfo.getPluginConfig();
- boolean isLeavesPresent;
+ boolean leavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
- isLeavesPresent = leavesHolder.getListOfLeaf() != null &&
- !leavesHolder.getListOfLeaf().isEmpty()
- || leavesHolder.getListOfLeafList() != null &&
- !leavesHolder.getListOfLeafList().isEmpty();
+ leavesPresent = leavesPresent(leavesHolder);
} else {
- isLeavesPresent = false;
+ leavesPresent = false;
}
- String className = getCapitalCase(javaFileInfo.getJavaName());
+ String className = getCapitalCase(fileInfo.getJavaName());
boolean isRootNode = false;
String path;
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
isRootNode = true;
- path = javaFileInfo.getPluginConfig().getCodeGenDir() +
- javaFileInfo.getPackageFilePath();
+ path = fileInfo.getPluginConfig().getCodeGenDir() +
+ fileInfo.getPackageFilePath();
} else {
- path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
}
initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode,
@@ -462,64 +434,42 @@
if (curNode instanceof YangAugmentableNode) {
insertDataIntoJavaFile(file, addAugmentationAttribute());
}
- if (isAttrPresent) {
+ if (attrPresent) {
//Add attribute strings.
try {
- insertDataIntoJavaFile(file,
- NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- ATTRIBUTES_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path));
+ insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
+ getDataFromTempFileHandle(
+ ATTRIBUTES_MASK,
+ getBeanFiles(curNode), path));
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files " +
- "for " + className +
- " while builder class file generation");
+ throw new IOException(getErrorMsg(className, BUILDER_CLASS));
}
- insertDataIntoJavaFile(file, getOperationTypeAttr());
- if (isLeavesPresent) {
+ if (leavesPresent) {
insertDataIntoJavaFile(file, getOperationAttributes());
}
try {
//Getter methods.
- methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path));
+ methods.add(getDataFromTempFileHandle(
+ GETTER_FOR_CLASS_MASK, getBeanFiles(curNode), path));
// Setter methods.
- methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path));
+ methods.add(getDataFromTempFileHandle(
+ SETTER_FOR_CLASS_MASK, getBeanFiles(curNode), path));
//Add to list impl method.
- methods.add(getDataFromTempFileHandle(ADD_TO_LIST_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path));
+ methods.add(getDataFromTempFileHandle(
+ ADD_TO_LIST_IMPL_MASK, getBeanFiles(curNode), path));
insertDataIntoJavaFile(file, NEW_LINE);
- methods.add(getGetterForOperationType());
- methods.add(getSetterForOperationType(className));
//Add operation attribute methods.
- if (isLeavesPresent) {
+ if (leavesPresent) {
methods.add(getOperationAttributesGetters() + NEW_LINE);
methods.add(getSetterForSelectLeaf(className, isRootNode));
}
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files " +
- "for " + className +
- " while builder class file generation");
+ throw new IOException(getErrorMsg(className, BUILDER_CLASS));
}
} else {
insertDataIntoJavaFile(file, NEW_LINE);
@@ -535,11 +485,8 @@
methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles()
.addBuildMethodImpl(curNode));
- methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(PUBLIC, BUILDER,
- pluginConfig, curNode));
-
+ methods.add(addDefaultConstructor(curNode, PUBLIC, BUILDER,
+ config, curNode));
//Add methods in builder class.
for (String method : methods) {
@@ -553,47 +500,44 @@
/**
* Returns generated default class file for current node.
*
- * @param file file
- * @param curNode current YANG node
- * @param isAttrPresent if any attribute is present or not
- * @param imports list of imports
+ * @param file file
+ * @param curNode current YANG node
+ * @param attrPresent if any attribute is present or not
+ * @param imports list of imports
* @return impl class file
* @throws IOException when fails to write in file
*/
public static File generateDefaultClassFile(File file, YangNode curNode,
- boolean isAttrPresent,
+ boolean attrPresent,
List<String> imports)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
- YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
+ YangPluginConfig config = fileInfo.getPluginConfig();
- boolean isLeavesPresent;
+ boolean leavesPresent;
YangLeavesHolder leavesHolder;
if (curNode instanceof YangLeavesHolder) {
leavesHolder = (YangLeavesHolder) curNode;
- isLeavesPresent = leavesHolder.getListOfLeaf() != null &&
- !leavesHolder.getListOfLeaf().isEmpty() ||
- leavesHolder.getListOfLeafList() != null &&
- !leavesHolder.getListOfLeafList().isEmpty();
+ leavesPresent = leavesPresent(leavesHolder);
} else {
- isLeavesPresent = false;
+ leavesPresent = false;
}
- boolean isRootNode = false;
+ boolean rootNode = false;
- String className = getCapitalCase(javaFileInfo.getJavaName());
+ String className = getCapitalCase(fileInfo.getJavaName());
String opParamClassName = className;
String path;
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
opParamClassName = className + OP_PARAM;
- isRootNode = true;
- path = javaFileInfo.getPluginConfig().getCodeGenDir() +
- javaFileInfo.getPackageFilePath();
+ rootNode = true;
+ path = fileInfo.getPluginConfig().getCodeGenDir() +
+ fileInfo.getPackageFilePath();
} else {
- path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
}
initiateJavaFileGeneration(file, DEFAULT_CLASS_MASK, imports, curNode,
@@ -603,89 +547,10 @@
if (curNode instanceof YangAugmentableNode) {
insertDataIntoJavaFile(file, addAugmentationAttribute());
}
- if (isAttrPresent) {
-
- //Add attribute strings.
- try {
- insertDataIntoJavaFile(file,
- NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- ATTRIBUTES_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path));
- } catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files " +
- "for " + className +
- " while impl class file generation");
- }
-
- //Add operation attributes
- insertDataIntoJavaFile(file, getOperationTypeEnum());
- insertDataIntoJavaFile(file, getOperationTypeAttr());
- if (isLeavesPresent) {
- insertDataIntoJavaFile(file, getOperationAttributes());
- }
-
- try {
- //Getter methods.
- methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path));
-
- methods.add(getGetterForOperationType());
-
- // Hash code method.
- methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
- getDataFromTempFileHandle(
- HASH_CODE_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path)
- .replace(
- NEW_LINE,
- EMPTY_STRING)));
-
- //Equals method.
- if (isRootNode) {
- methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(opParamClassName) +
- getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path)));
- } else {
- methods.add(getEqualsMethodClose(getEqualsMethodOpen(
- getCapitalCase(DEFAULT) + className) +
- getDataFromTempFileHandle(
- EQUALS_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path)));
- }
- // To string method.
- methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(
- TO_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer)
- curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path) +
- getToStringMethodClose());
-
-
- } catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files " +
- "for " + className +
- " while impl class file generation");
- }
+ if (attrPresent) {
+ addDefaultClassAttributeInfo(file, curNode, className,
+ opParamClassName, path, methods,
+ leavesPresent, rootNode);
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
@@ -697,80 +562,63 @@
try {
//Constructor.
String constructor =
- getConstructorStart(className, pluginConfig, isRootNode);
+ getConstructorStart(className, config, rootNode);
constructor = constructor +
- getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(),
- path);
+ getDataFromTempFileHandle(
+ CONSTRUCTOR_IMPL_MASK, getBeanFiles(curNode), path);
- if (isAttrPresent) {
- constructor = constructor + getOperationTypeForConstructor();
- }
- if (isLeavesPresent) {
- constructor =
- constructor + getOperationAttributeForConstructor();
+ if (leavesPresent) {
+ constructor = constructor +
+ getOperationAttributeForConstructor();
}
if (curNode instanceof YangAugmentableNode) {
- constructor = constructor + getYangAugmentedMapObjectForConstruct();
+ constructor = constructor +
+ getYangAugmentedMapObjectForConstruct();
}
- methods.add(
- constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE);
+ methods.add(constructor + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE);
// add is filter content match.
- String augmentableSubTreeFiltering = "";
+ String augmentableSubTreeFiltering = EMPTY_STRING;
if (curNode instanceof YangAugmentableNode) {
augmentableSubTreeFiltering = getAugmentableSubTreeFiltering();
}
- methods.add(getProcessSubtreeFilteringStart(curNode, pluginConfig)
- + getProcessSubtreeFunctionBody(curNode)
- + augmentableSubTreeFiltering
- + getProcessSubTreeFilteringEnd());
+ methods.add(getProcessSubtreeFilteringStart(curNode, config) +
+ getProcessSubtreeFunctionBody(curNode) +
+ augmentableSubTreeFiltering +
+ getProcessSubTreeFilteringEnd());
if (curNode instanceof YangLeavesHolder) {
- if (((YangLeavesHolder) curNode).getListOfLeaf() != null
- && !((YangLeavesHolder) curNode).getListOfLeaf()
- .isEmpty()) {
- methods.add(getProcessLeafSubtreeFiltering(curNode,
- pluginConfig,
+ if (((YangLeavesHolder) curNode).getListOfLeaf() != null &&
+ !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
+ methods.add(getProcessLeafSubtreeFiltering(curNode, config,
path));
}
}
-
if (curNode instanceof YangLeavesHolder) {
- if (((YangLeavesHolder) curNode).getListOfLeafList() != null
- && !((YangLeavesHolder) curNode).getListOfLeafList()
- .isEmpty()) {
+ if (((YangLeavesHolder) curNode).getListOfLeafList() != null &&
+ !((YangLeavesHolder) curNode).getListOfLeafList().isEmpty()) {
methods.add(getProcessLeafListSubtreeFiltering(curNode,
- pluginConfig,
+ config,
path));
}
}
if (curNode.getChild() != null) {
methods.add(getProcessChildNodeSubtreeFiltering(curNode,
- pluginConfig,
- path));
+ config, path));
}
-
-
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while impl class file generation");
+ throw new IOException(getErrorMsg(className, IMPL_CLASS));
}
- methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(PROTECTED, DEFAULT,
- pluginConfig, curNode));
+ methods.add(addDefaultConstructor(curNode, PROTECTED, DEFAULT,
+ config, curNode));
methods.add(builderMethod(className) + NEW_LINE);
- if (isLeavesPresent) {
+ if (leavesPresent) {
methods.add(getOperationAttributesGetters());
methods.add(getGettersForValueAndSelectLeaf());
}
@@ -783,6 +631,80 @@
}
/**
+ * Add methods related to attributes.
+ *
+ * @param file file
+ * @param curNode current YANG node
+ * @param className name of the class
+ * @param opParamClassName op param class name
+ * @param path file path
+ * @param methods list of methods string
+ * @param leavesPresent flag indicating presence of leaves
+ * @param rootNode flag indicating whether node is root node
+ * @throws IOException a violation in IO rule
+ */
+ private static void addDefaultClassAttributeInfo(File file, YangNode curNode,
+ String className,
+ String opParamClassName,
+ String path, List<String> methods,
+ boolean leavesPresent,
+ boolean rootNode)
+ throws IOException {
+
+ //Add attribute strings.
+ try {
+ insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
+ getDataFromTempFileHandle(
+ ATTRIBUTES_MASK, getBeanFiles(curNode), path));
+ } catch (IOException e) {
+ throw new IOException(getErrorMsg(className, IMPL_CLASS));
+ }
+
+ //Add operation attributes
+ if (leavesPresent) {
+ insertDataIntoJavaFile(file, getOperationAttributes());
+ }
+
+ try {
+ //Getter methods.
+ methods.add(getDataFromTempFileHandle(
+ GETTER_FOR_CLASS_MASK, getBeanFiles(curNode), path));
+
+ // Hash code method.
+ methods.add(getHashCodeMethodClose(
+ getHashCodeMethodOpen() +
+ getDataFromTempFileHandle(
+ HASH_CODE_IMPL_MASK,
+ getBeanFiles(curNode), path)
+ .replace(NEW_LINE, EMPTY_STRING)));
+
+ //Equals method.
+ if (rootNode) {
+ methods.add(getEqualsMethodClose(
+ getEqualsMethodOpen(opParamClassName) +
+ getDataFromTempFileHandle(
+ EQUALS_IMPL_MASK,
+ getBeanFiles(curNode), path)));
+ } else {
+ methods.add(getEqualsMethodClose(
+ getEqualsMethodOpen(
+ getCapitalCase(DEFAULT) + className) +
+ getDataFromTempFileHandle(
+ EQUALS_IMPL_MASK,
+ getBeanFiles(curNode), path)));
+ }
+ // To string method.
+ methods.add(getToStringMethodOpen() +
+ getDataFromTempFileHandle(
+ TO_STRING_IMPL_MASK,
+ getBeanFiles(curNode), path) +
+ getToStringMethodClose());
+ } catch (IOException e) {
+ throw new IOException(getErrorMsg(className, IMPL_CLASS));
+ }
+ }
+
+ /**
* Generates class file for type def.
*
* @param file generated file
@@ -795,159 +717,73 @@
List<String> imports)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
- YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
+ YangPluginConfig config = fileInfo.getPluginConfig();
// import
- String className = getCapitalCase(javaFileInfo.getJavaName());
- String path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ String className = getCapitalCase(fileInfo.getJavaName());
+ String path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
YangTypeDef typeDef = (YangTypeDef) curNode;
List<YangType<?>> types = typeDef.getTypeList();
YangType type = types.get(0);
YangDataTypes yangDataTypes = type.getDataType();
initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS,
- imports, path, pluginConfig);
+ imports, path, config);
List<String> methods = new ArrayList<>();
-
//Add attribute strings.
try {
insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(ATTRIBUTES_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
+ getDataFromTempFileHandle(
+ ATTRIBUTES_MASK, getTypeFiles(curNode), path));
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while type def class file " +
- "generation");
+ throw new IOException(getErrorMsg(className, TYPEDEF_CLASS));
}
-
//Default constructor.
- methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(PRIVATE, EMPTY_STRING,
- pluginConfig, curNode));
+ methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING,
+ config, curNode));
try {
//Type constructor.
- methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
-
+ methods.add(getDataFromTempFileHandle(
+ CONSTRUCTOR_FOR_TYPE_MASK, getTypeFiles(curNode), path));
//Of method.
- methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
+ methods.add(getDataFromTempFileHandle(
+ OF_STRING_IMPL_MASK, getTypeFiles(curNode), path));
//Getter methods.
- methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
+ methods.add(getDataFromTempFileHandle(
+ GETTER_FOR_CLASS_MASK, getTypeFiles(curNode), path));
// Hash code method.
- methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
- getDataFromTempFileHandle(
- HASH_CODE_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path)
- .replace(
- NEW_LINE,
- EMPTY_STRING)));
-
+ methods.add(getHashCodeMethodClose(
+ getHashCodeMethodOpen() + getDataFromTempFileHandle(
+ HASH_CODE_IMPL_MASK, getTypeFiles(curNode), path)
+ .replace(NEW_LINE, EMPTY_STRING)));
//Equals method.
methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(className + EMPTY_STRING)
- + getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path)));
+ getEqualsMethodOpen(className + EMPTY_STRING) +
+ getDataFromTempFileHandle(EQUALS_IMPL_MASK,
+ getTypeFiles(curNode), path)));
-
- //To string method.
- if (type.getDataType().equals(BINARY)) {
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo =
- getQualifiedTypeInfoOfCurNode(curNode, getCapitalCase(
- "binary"));
-
- JavaAttributeInfo attr =
- getAttributeInfoForTheData(qualifiedTypeInfo, "binary",
- null, false, false);
- String attributeName = attr.getAttributeName();
- String bitsToStringMethod =
- getOverRideString() + FOUR_SPACE_INDENTATION +
- PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO +
- STRING_DATA_TYPE + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + RETURN + SPACE +
- BASE64 + PERIOD + GET_ENCODER +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS +
- attributeName + CLOSE_PARENTHESIS +
- SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- methods.add(bitsToStringMethod);
- } else if (type.getDataType().equals(BITS)) {
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo =
- getQualifiedTypeInfoOfCurNode(curNode,
- getCapitalCase(
- "bits"));
-
- JavaAttributeInfo attr =
- getAttributeInfoForTheData(qualifiedTypeInfo, "bits",
- null, false, false);
- String attributeName = attr.getAttributeName();
- String bitsToStringMethod =
- getOverRideString() + FOUR_SPACE_INDENTATION +
- PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO +
- STRING_DATA_TYPE + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + RETURN + SPACE +
- attributeName + PERIOD + TO +
- STRING_DATA_TYPE + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
- methods.add(bitsToStringMethod);
- } else {
- methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(
- TO_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer)
- curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(), path) +
- getToStringMethodClose());
- }
+ // To string method.
+ addTypedefToString(curNode, methods, path, type);
JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
//From string method.
- if ((type.getDataType().equals(YangDataTypes.DERIVED))
- && (((YangDerivedInfo) type.getDataTypeExtendedInfo())
- .getEffectiveBuiltInType()
- .equals(YangDataTypes.IDENTITYREF))) {
+ if ((type.getDataType().equals(YangDataTypes.DERIVED)) &&
+ (((YangDerivedInfo) type.getDataTypeExtendedInfo())
+ .getEffectiveBuiltInType()
+ .equals(YangDataTypes.IDENTITYREF))) {
yangDataTypes = YangDataTypes.IDENTITYREF;
}
@@ -956,21 +792,15 @@
}
if (!yangDataTypes.equals(YangDataTypes.IDENTITYREF)) {
- methods.add(
- getFromStringMethodSignature(className, pluginConfig) +
- getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
- javaGenInfo
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path) +
- getFromStringMethodClose());
+ methods.add(getFromStringMethodSignature(className, config) +
+ getDataFromTempFileHandle(
+ FROM_STRING_IMPL_MASK,
+ javaGenInfo.getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles(), path) +
+ getFromStringMethodClose());
}
-
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while type def class file " +
- "generation");
+ throw new IOException(getErrorMsg(className, TYPEDEF_CLASS));
}
for (String method : methods) {
@@ -982,6 +812,79 @@
}
/**
+ * Adds typedef to string method.
+ *
+ * @param curNode current node
+ * @param methods list of methods string
+ * @param path file path
+ * @param type YANG type
+ * @throws IOException a violation in IO rule
+ */
+ private static void addTypedefToString(YangNode curNode,
+ List<String> methods, String path,
+ YangType type) throws IOException {
+ //To string method.
+ if (type.getDataType().equals(BINARY)) {
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ getQualifiedTypeInfoOfCurNode(curNode, getCapitalCase
+ (UtilConstants.BINARY));
+
+ JavaAttributeInfo attr =
+ getAttributeInfoForTheData(typeInfo,
+ UtilConstants.BINARY,
+ null, false, false);
+ String attributeName = attr.getAttributeName();
+ String bitsToStringMethod =
+ getOverRideString() + FOUR_SPACE_INDENTATION +
+ PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO +
+ STRING_DATA_TYPE + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE +
+ BASE64 + PERIOD + GET_ENCODER +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
+ PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS +
+ attributeName + CLOSE_PARENTHESIS +
+ SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
+ methods.add(bitsToStringMethod);
+ } else if (type.getDataType().equals(BITS)) {
+ JavaQualifiedTypeInfoTranslator typeInfo =
+ getQualifiedTypeInfoOfCurNode(curNode,
+ getCapitalCase(UtilConstants.BITS));
+
+ JavaAttributeInfo attr =
+ getAttributeInfoForTheData(typeInfo,
+ UtilConstants.BITS,
+ null, false, false);
+ String attributeName = attr.getAttributeName();
+ String bitsToStringMethod =
+ getOverRideString() + FOUR_SPACE_INDENTATION +
+ PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + TO +
+ STRING_DATA_TYPE + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE +
+ attributeName + PERIOD + TO +
+ STRING_DATA_TYPE + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE;
+ methods.add(bitsToStringMethod);
+ } else {
+ methods.add(getToStringMethodOpen() +
+ getDataFromTempFileHandle(
+ TO_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer)
+ curNode)
+ .getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles(), path) +
+ getToStringMethodClose());
+ }
+ }
+
+ /**
* Generates class file for union type.
*
* @param file generated file
@@ -994,189 +897,124 @@
List<String> imports)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
- YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
+ YangPluginConfig config = fileInfo.getPluginConfig();
- String className = getCapitalCase(javaFileInfo.getJavaName());
- String path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ String className = getCapitalCase(fileInfo.getJavaName());
+ String path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
- TempJavaTypeFragmentFiles tempJavaTypeFragmentFiles =
- ((JavaCodeGeneratorInfo) curNode)
- .getTempJavaCodeFragmentFiles().getTypeTempFiles();
+ TempJavaTypeFragmentFiles tempFiles =
+ ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
+ .getTypeTempFiles();
- boolean isIntConflict = false;
- boolean isLongConflict = false;
- boolean isShortConflict = false;
- JavaAttributeInfo intAttr = tempJavaTypeFragmentFiles.getIntAttribute();
+ boolean intConflict = false;
+ boolean longConflict = false;
+ boolean shortConflict = false;
+ JavaAttributeInfo intAttr = tempFiles.getIntAttribute();
if (intAttr == null) {
- intAttr = tempJavaTypeFragmentFiles.getUIntAttribute();
+ intAttr = tempFiles.getUIntAttribute();
}
JavaAttributeInfo longAttr =
- tempJavaTypeFragmentFiles.getLongAttribute();
+ tempFiles.getLongAttribute();
if (longAttr == null) {
- longAttr = tempJavaTypeFragmentFiles.getULongAttribute();
+ longAttr = tempFiles.getULongAttribute();
}
JavaAttributeInfo shortAttr =
- tempJavaTypeFragmentFiles.getShortAttribute();
+ tempFiles.getShortAttribute();
if (shortAttr == null) {
- shortAttr = tempJavaTypeFragmentFiles.getUInt8Attribute();
+ shortAttr = tempFiles.getUInt8Attribute();
}
if (intAttr != null) {
- isIntConflict = intAttr.isIntConflict();
+ intConflict = intAttr.isIntConflict();
}
if (longAttr != null) {
- isLongConflict = longAttr.isLongConflict();
+ longConflict = longAttr.isLongConflict();
}
if (shortAttr != null) {
- isShortConflict = shortAttr.isShortConflict();
+ shortConflict = shortAttr.isShortConflict();
}
- if (isLongConflict) {
- imports.add(tempJavaTypeFragmentFiles.getJavaImportData()
+ if (longConflict) {
+ imports.add(tempFiles.getJavaImportData()
.getBigIntegerImport());
sort(imports);
}
initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS,
- imports, path, pluginConfig);
+ imports, path, config);
List<String> methods = new ArrayList<>();
-
// Add attribute strings.
try {
- if (isIntConflict) {
- insertDataIntoJavaFile(file, JavaCodeSnippetGen
- .addStaticAttributeIntRange(PRIVATE,
- tempJavaTypeFragmentFiles
- .getIntIndex() <
- tempJavaTypeFragmentFiles
- .getUIntIndex()));
- }
-
- if (isLongConflict) {
- insertDataIntoJavaFile(file, JavaCodeSnippetGen
- .addStaticAttributeLongRange(PRIVATE,
- tempJavaTypeFragmentFiles
- .getLongIndex() <
- tempJavaTypeFragmentFiles
- .getULongIndex()));
- }
-
- if (isShortConflict) {
- insertDataIntoJavaFile(file, JavaCodeSnippetGen
- .addStaticAttributeShortRange(PRIVATE,
- tempJavaTypeFragmentFiles
- .getShortIndex() <
- tempJavaTypeFragmentFiles
- .getUInt8Index()));
- }
-
- insertDataIntoJavaFile(file,
- NEW_LINE + FOUR_SPACE_INDENTATION +
- getDataFromTempFileHandle(
- ATTRIBUTES_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
+ addUnionClassAttributeInfo(file, curNode, intConflict,
+ longConflict, shortConflict, path,
+ tempFiles);
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while union class file generation");
+ throw new IOException(getErrorMsg(className, UNION_CLASS));
}
-
//Default constructor.
- methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(PRIVATE, EMPTY_STRING,
- pluginConfig, curNode));
+ methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING,
+ config, curNode));
try {
-
//Type constructor.
- methods.add(getDataFromTempFileHandle(CONSTRUCTOR_FOR_TYPE_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
-
+ methods.add(getDataFromTempFileHandle(
+ CONSTRUCTOR_FOR_TYPE_MASK, getTypeFiles(curNode), path));
// Of string method.
- methods.add(getDataFromTempFileHandle(OF_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
+ methods.add(getDataFromTempFileHandle(
+ OF_STRING_IMPL_MASK, getTypeFiles(curNode), path));
//Getter methods.
- methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path));
-
+ methods.add(getDataFromTempFileHandle(
+ GETTER_FOR_CLASS_MASK, getTypeFiles(curNode), path));
//Hash code method.
- methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() +
- getDataFromTempFileHandle(
- HASH_CODE_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path).replace(
- NEW_LINE,
- EMPTY_STRING)));
+ methods.add(getHashCodeMethodClose(
+ getHashCodeMethodOpen() +
+ getDataFromTempFileHandle(
+ HASH_CODE_IMPL_MASK, getTypeFiles(curNode),
+ path).replace(NEW_LINE, EMPTY_STRING)));
//Equals method.
methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(className + EMPTY_STRING)
- + getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path)));
-
+ getEqualsMethodOpen(className + EMPTY_STRING) +
+ getDataFromTempFileHandle(
+ EQUALS_IMPL_MASK, getTypeFiles(curNode),
+ path)));
//To string method.
methods.add(getToStringMethodOpen() + getOmitNullValueString() +
- getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path) +
+ getDataFromTempFileHandle(
+ TO_STRING_IMPL_MASK,
+ getTypeFiles(curNode), path) +
getToStringMethodClose());
-
//From string method.
- methods.add(getFromStringMethodSignature(className, pluginConfig) +
- getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(),
- path) +
+ methods.add(getFromStringMethodSignature(className, config) +
+ getDataFromTempFileHandle(
+ FROM_STRING_IMPL_MASK,
+ getTypeFiles(curNode), path) +
getFromStringMethodClose());
- if (isIntConflict) {
+ if (intConflict) {
methods.add(getRangeValidatorMethodForUnion(INT));
}
- if (isLongConflict) {
+ if (longConflict) {
methods.add(getRangeValidatorMethodForUnion(BIG_INTEGER));
}
- if (isShortConflict && !isIntConflict) {
+ if (shortConflict && !intConflict) {
methods.add(getRangeValidatorMethodForUnion(INT));
}
-
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while union class file generation");
+ throw new IOException(getErrorMsg(className, UNION_CLASS));
}
for (String method : methods) {
@@ -1188,6 +1026,52 @@
}
/**
+ * Adds union class attribute information.
+ *
+ * @param file generated file
+ * @param curNode current YANG node
+ * @param intConflict flag to indicate if there is a conflict in int
+ * @param longConflict flag to indicate if there is a conflict in long
+ * @param shortConflict flag to indicate if there is a conflict in short
+ * @param path file path
+ * @param tempFiles temp java type fragment files
+ * @throws IOException a violation in IO rule
+ */
+ private static void addUnionClassAttributeInfo(File file,
+ YangNode curNode,
+ boolean intConflict,
+ boolean longConflict,
+ boolean shortConflict,
+ String path,
+ TempJavaTypeFragmentFiles tempFiles)
+ throws IOException {
+ if (intConflict) {
+ insertDataIntoJavaFile(file, JavaCodeSnippetGen
+ .addStaticAttributeIntRange(PRIVATE,
+ tempFiles.getIntIndex() <
+ tempFiles.getUIntIndex()));
+ }
+
+ if (longConflict) {
+ insertDataIntoJavaFile(file, JavaCodeSnippetGen
+ .addStaticAttributeLongRange(PRIVATE,
+ tempFiles.getLongIndex() <
+ tempFiles.getULongIndex()));
+ }
+
+ if (shortConflict) {
+ insertDataIntoJavaFile(file, JavaCodeSnippetGen
+ .addStaticAttributeShortRange(PRIVATE,
+ tempFiles.getShortIndex() <
+ tempFiles.getUInt8Index()));
+ }
+
+ insertDataIntoJavaFile(file, NEW_LINE + FOUR_SPACE_INDENTATION +
+ getDataFromTempFileHandle(
+ ATTRIBUTES_MASK, getTypeFiles(curNode), path));
+ }
+
+ /**
* Generates class file for type enum.
*
* @param file generated file
@@ -1198,17 +1082,17 @@
public static File generateEnumClassFile(File file, YangNode curNode)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
- YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
+ YangPluginConfig config = fileInfo.getPluginConfig();
- String className = javaFileInfo.getJavaName();
- String path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ String className = fileInfo.getJavaName();
+ String path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, getCapitalCase(className),
GENERATE_ENUM_CLASS, null, path,
- pluginConfig);
+ config);
//Add attribute strings.
try {
@@ -1219,55 +1103,56 @@
ENUM_IMPL_MASK, javaGenInfo
.getTempJavaCodeFragmentFiles()
.getEnumerationTempFiles(),
- path), COMMA),
- NEW_LINE) + SEMI_COLAN +
- NEW_LINE);
+ path), COMMA), NEW_LINE) +
+ SEMI_COLAN + NEW_LINE);
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- getCapitalCase(className) + " while enum class " +
- "file generation");
+ throw new IOException(getErrorMsg(getCapitalCase(className),
+ ENUM_CLASS));
}
-
// Add an attribute to get the enum's values.
- insertDataIntoJavaFile(file, getEnumsValueAttribute(
- getCapitalCase(className)));
+ insertDataIntoJavaFile(file, getEnumsValueAttribute(getCapitalCase(className)));
// Add a constructor for enum.
insertDataIntoJavaFile(file,
getJavaDoc(TYPE_CONSTRUCTOR, className, false,
- pluginConfig, null)
- + getEnumsConstructor(getCapitalCase(className)) + NEW_LINE);
+ config, null) +
+ getEnumsConstructor(getCapitalCase(className)) +
+ NEW_LINE);
insertDataIntoJavaFile(file,
- getEnumsOfValueMethod(className, (YangEnumeration) curNode, pluginConfig) + NEW_LINE);
+ getEnumsOfValueMethod(className,
+ (YangEnumeration) curNode,
+ config) + NEW_LINE);
insertDataIntoJavaFile(file,
- getEnumValueOfSchemaNameMethod(className, pluginConfig, (YangEnumeration) curNode));
+ getEnumValueOfSchemaNameMethod(className,
+ config,
+ (YangEnumeration) curNode));
// Add a getter method for enum.
insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false,
- pluginConfig, null) +
+ config, null) +
getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
- insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, SCHEMA_NAME, false,
- pluginConfig, null) +
- getGetter(STRING_DATA_TYPE, SCHEMA_NAME,
- GENERATE_ENUM_CLASS) + NEW_LINE);
+ insertDataIntoJavaFile(file,
+ getJavaDoc(GETTER_METHOD, SCHEMA_NAME, false,
+ config, null) +
+ getGetter(STRING_DATA_TYPE, SCHEMA_NAME,
+ GENERATE_ENUM_CLASS) +
+ NEW_LINE);
try {
- insertDataIntoJavaFile(file, getFromStringMethodSignature(
- getCapitalCase(className), pluginConfig) +
- getDataFromTempFileHandle(FROM_STRING_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getEnumerationTempFiles(),
- path) +
- getFromStringMethodClose());
+ insertDataIntoJavaFile(file,
+ getFromStringMethodSignature(getCapitalCase(className),
+ config) +
+ getDataFromTempFileHandle(
+ FROM_STRING_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles()
+ .getEnumerationTempFiles(),
+ path) + getFromStringMethodClose());
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- getCapitalCase(className) +
- " while enum class file generation");
+ throw new IOException(getErrorMsg(getCapitalCase(className),
+ ENUM_CLASS));
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
@@ -1288,23 +1173,23 @@
List<String> imports)
throws IOException {
- JavaFileInfoTranslator javaFileInfo =
+ JavaFileInfoTranslator fileInfo =
((JavaFileInfoContainer) curNode).getJavaFileInfo();
- TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles =
+ TempJavaServiceFragmentFiles tempFiles =
((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
- String className = getCapitalCase(javaFileInfo.getJavaName()) +
+ String className = getCapitalCase(fileInfo.getJavaName()) +
SERVICE_METHOD_STRING;
- String path = javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath();
+ String path = fileInfo.getBaseCodeGenPath() +
+ fileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports,
curNode, className);
List<String> methods = new ArrayList<>();
JavaAttributeInfo rootAttribute =
getCurNodeAsAttributeInTarget(curNode, curNode, false,
- tempJavaServiceFragmentFiles);
+ tempFiles);
try {
@@ -1312,12 +1197,12 @@
//Getter methods.
methods.add(getGetterString(rootAttribute,
GENERATE_SERVICE_AND_MANAGER,
- javaFileInfo.getPluginConfig()) +
+ fileInfo.getPluginConfig()) +
NEW_LINE);
// Setter methods.
methods.add(getSetterString(rootAttribute, className,
GENERATE_SERVICE_AND_MANAGER,
- javaFileInfo.getPluginConfig()) +
+ fileInfo.getPluginConfig()) +
NEW_LINE);
}
@@ -1329,16 +1214,13 @@
(JavaCodeGeneratorInfo) curNode;
// Rpc methods
- methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK,
- javaGenInfo
- .getTempJavaCodeFragmentFiles()
- .getServiceTempFiles(),
- path));
+ methods.add(getDataFromTempFileHandle(
+ RPC_INTERFACE_MASK,
+ javaGenInfo.getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles(), path));
}
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while rpc class file generation");
+ throw new IOException(getErrorMsg(className, RPC_CLASS));
}
for (String method : methods) {
@@ -1361,19 +1243,18 @@
List<String> imports)
throws IOException {
- String className = getCapitalCase(
- ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getJavaName())
- + EVENT_STRING;
+ String className =
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo()
+ .getJavaName()) + EVENT_STRING;
TempJavaEventFragmentFiles tempFiles =
((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getEventFragmentFiles();
String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getBaseCodeGenPath()
- + ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getPackageFilePath();
+ .getBaseCodeGenPath() +
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo()
+ .getPackageFilePath();
initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode,
className);
try {
@@ -1386,11 +1267,8 @@
insertDataIntoJavaFile(file,
getDataFromTempFileHandle(EVENT_METHOD_MASK,
tempFiles, path));
-
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while event class file generation");
+ throw new IOException(getErrorMsg(className, EVENT_CLASS));
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
@@ -1409,9 +1287,9 @@
List<String> imports)
throws IOException {
- String className = getCapitalCase(
- ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getJavaName()) + EVENT_LISTENER_STRING;
+ String className =
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo()
+ .getJavaName()) + EVENT_LISTENER_STRING;
initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE,
imports, curNode, className);
@@ -1429,17 +1307,17 @@
public static void generateEventSubjectFile(File file, YangNode curNode)
throws IOException {
- String className = getCapitalCase(
- ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getJavaName()) + EVENT_SUBJECT_NAME_SUFFIX;
+ String className =
+ getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo()
+ .getJavaName()) + EVENT_SUBJECT_NAME_SUFFIX;
initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null,
curNode, className);
String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getBaseCodeGenPath()
- + ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getPackageFilePath();
+ .getBaseCodeGenPath() +
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo()
+ .getPackageFilePath();
TempJavaEventFragmentFiles tempFiles =
((TempJavaCodeFragmentFilesContainer) curNode)
@@ -1447,22 +1325,47 @@
insertDataIntoJavaFile(file, NEW_LINE);
try {
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- EVENT_SUBJECT_ATTRIBUTE_MASK, tempFiles, path));
+ insertDataIntoJavaFile(file,
+ getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK,
+ tempFiles, path));
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- EVENT_SUBJECT_GETTER_MASK, tempFiles, path));
+ insertDataIntoJavaFile(file,
+ getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK,
+ tempFiles, path));
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- EVENT_SUBJECT_SETTER_MASK, tempFiles, path));
-
+ insertDataIntoJavaFile(file,
+ getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK,
+ tempFiles, path));
} catch (IOException e) {
- throw new IOException(
- "No data found in temporary java code fragment files for " +
- className + " while event class file generation");
+ throw new IOException(getErrorMsg(className, EVENT_CLASS));
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
validateLineLength(file);
}
+
+ /**
+ * Returns error message string.
+ *
+ * @param className name of the class
+ * @param fileType type of file
+ * @return error message string
+ */
+ private static String getErrorMsg(String className, String fileType) {
+ return "No data found in temporary java code fragment files for " +
+ className + " while " + fileType + " file generation.";
+ }
+
+ /**
+ * Checks whether leaf is present in YANG leaves holder.
+ *
+ * @param holder holder of YANG leaves
+ * @return true if leaves are present, false otherwise
+ */
+ private static boolean leavesPresent(YangLeavesHolder holder) {
+ return holder.getListOfLeaf() != null &&
+ !holder.getListOfLeaf().isEmpty() ||
+ holder.getListOfLeafList() != null &&
+ !holder.getListOfLeafList().isEmpty();
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 5b38096..583bb0a 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -16,8 +16,6 @@
package org.onosproject.yangutils.translator.tojava.utils;
-import java.util.List;
-
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
import org.onosproject.yangutils.datamodel.YangEnum;
@@ -31,6 +29,8 @@
import org.onosproject.yangutils.utils.io.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
+import java.util.List;
+
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
@@ -46,8 +46,7 @@
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils
- .getAugmentedClassNameForDataMethods;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
@@ -225,8 +224,10 @@
* @param pluginConfig plugin configurations
* @return method string for builder interface
*/
- public static String parseBuilderInterfaceBuildMethodString(String name, YangPluginConfig pluginConfig) {
- return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) + getBuildForInterface(name);
+ public static String parseBuilderInterfaceBuildMethodString(String name,
+ YangPluginConfig pluginConfig) {
+ return getJavaDoc(BUILD_METHOD, name, false, pluginConfig, null) +
+ getBuildForInterface(name);
}
/**
@@ -237,24 +238,31 @@
* @param pluginConfig plugin configurations
* @return getter string
*/
- public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles,
+ public static String getGetterString(JavaAttributeInfo attr,
+ int generatedJavaFiles,
YangPluginConfig pluginConfig) {
String returnType = getReturnType(attr);
String attributeName = attr.getAttributeName();
String appDataStructure = null;
if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ appDataStructure =
+ attr.getCompilerAnnotation().getYangAppDataStructure()
+ .getDataStructure().name();
}
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return generateForGetMethodWithAttribute(returnType)
- + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
- attr.getCompilerAnnotation());
+ return generateForGetMethodWithAttribute(returnType) +
+ getGetterForInterface(attributeName, returnType,
+ attr.isListAttr(),
+ generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
- return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
- + getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles,
- attr.getCompilerAnnotation());
+ return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr(),
+ pluginConfig, appDataStructure) +
+ getGetterForInterface(attributeName, returnType,
+ attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
/**
@@ -266,7 +274,9 @@
* @param pluginConfig plugin configurations
* @return setter string
*/
- public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles,
+ public static String getSetterString(JavaAttributeInfo attr,
+ String className,
+ int generatedJavaFiles,
YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
@@ -280,11 +290,15 @@
String appDataStructure = null;
if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ appDataStructure =
+ attr.getCompilerAnnotation().getYangAppDataStructure()
+ .getDataStructure().name();
}
- return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig, appDataStructure)
- + getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles,
- attr.getCompilerAnnotation());
+ return getJavaDoc(type, attributeName, attr.isListAttr(), pluginConfig,
+ appDataStructure) +
+ getSetterForInterface(attributeName, attrType, className,
+ attr.isListAttr(), generatedJavaFiles,
+ attr.getCompilerAnnotation());
}
/**
@@ -294,7 +308,8 @@
* @param pluginConfig plugin configurations
* @return constructor string
*/
- private static String getConstructorString(String name, YangPluginConfig pluginConfig) {
+ private static String getConstructorString(String name,
+ YangPluginConfig pluginConfig) {
return getJavaDoc(CONSTRUCTOR, name, false, pluginConfig, null);
}
@@ -306,7 +321,8 @@
* @param pluginConfig plugin configurations
* @return default constructor string
*/
- public static String getDefaultConstructorString(String name, String modifierType,
+ public static String getDefaultConstructorString(String name,
+ String modifierType,
YangPluginConfig pluginConfig) {
return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, pluginConfig, null)
+ getDefaultConstructor(name, modifierType) + NEW_LINE;
@@ -319,8 +335,9 @@
* @return check not null string
*/
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;
+ return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING +
+ OPEN_PARENTHESIS + name + COMMA + SPACE + name +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
@@ -334,7 +351,8 @@
if (isRootNode) {
return NEW_LINE + getBuild(name, true);
}
- return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE + getBuild(name, false);
+ return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE +
+ getBuild(name, false);
}
/**
@@ -344,15 +362,18 @@
* @param generatedJavaFiles for the type of java file being generated
* @return getter method for class
*/
- public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
+ public static String getGetterForClass(JavaAttributeInfo attr,
+ int generatedJavaFiles) {
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
if (!attr.isListAttr()) {
- return getGetter(attrQualifiedType, attributeName, generatedJavaFiles);
+ return getGetter(attrQualifiedType, attributeName,
+ generatedJavaFiles);
}
- String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
+ String attrParam = getListAttribute(attrQualifiedType,
+ attr.getCompilerAnnotation());
return getGetter(attrParam, attributeName, generatedJavaFiles);
}
@@ -367,15 +388,19 @@
static String getGetter(String type, String name, int generatedJavaFiles) {
String ret = parseTypeForReturnValue(type);
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE +
+ GET_METHOD_PREFIX + getCapitalCase(name) +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + 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;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE +
+ 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;
}
}
@@ -403,7 +428,9 @@
* @param generatedJavaFiles generated java files
* @return setter method for class
*/
- public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
+ public static String getSetterForClass(JavaAttributeInfo attr,
+ String className,
+ int generatedJavaFiles) {
String attrQualifiedType = getReturnType(attr);
String attributeName = attr.getAttributeName();
boolean isTypeNull = false;
@@ -411,10 +438,13 @@
isTypeNull = true;
}
if (!attr.isListAttr()) {
- return getSetter(className, attributeName, attrQualifiedType, generatedJavaFiles, isTypeNull, false);
+ return getSetter(className, attributeName, attrQualifiedType,
+ generatedJavaFiles, isTypeNull, false);
}
- String attrParam = getListAttribute(attrQualifiedType, attr.getCompilerAnnotation());
- return getSetter(className, attributeName, attrParam, generatedJavaFiles, isTypeNull, true);
+ String attrParam = getListAttribute(attrQualifiedType,
+ attr.getCompilerAnnotation());
+ return getSetter(className, attributeName, attrParam,
+ generatedJavaFiles, isTypeNull, true);
}
/**
@@ -427,38 +457,46 @@
* @param isList true if leaf-list
* @return setter for attribute
*/
- private static String getSetter(String className, String name, String type, int generatedJavaFiles,
+ private static String getSetter(String className, String name, String type,
+ int generatedJavaFiles,
boolean isTypeNull, boolean isList) {
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX
- + getCapitalCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO +
- NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
+ SET_METHOD_PREFIX + getCapitalCase(name) +
+ OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS +
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else if (generatedJavaFiles == GENERATE_EVENT_SUBJECT_CLASS) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + name + OPEN_PARENTHESIS + type + SPACE
- + name + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
- + THIS + PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE
- + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
+ name + OPEN_PARENTHESIS + type + SPACE + name +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
+ NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name +
+ SPACE + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
- String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
- name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET;
+ String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
+ className + BUILDER + SPACE + name + OPEN_PARENTHESIS +
+ type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET;
if (!isTypeNull && !isList) {
method = method + getValueLeafSetString(name);
} else {
method = method + EMPTY_STRING;
}
return method + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS +
- PERIOD + name + SPACE
- + EQUAL + SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
- + THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ PERIOD + name + SPACE + EQUAL + SPACE + name + SEMI_COLAN +
+ NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE +
+ THIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET;
}
}
//Returns value leaf flag setter.
private static String getValueLeafSetString(String name) {
- return "\n getValueLeafFlags().set(LeafIdentifier." + name.toUpperCase() + ".getLeafIndex());";
+ return "\n getValueLeafFlags().set(LeafIdentifier." +
+ name.toUpperCase() + ".getLeafIndex());";
}
/**
@@ -482,10 +520,13 @@
* @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 + getCapitalCase(name)
- + OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
- + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN +
- NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
+ SET_METHOD_PREFIX + getCapitalCase(name) + OPEN_PARENTHESIS +
+ type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ THIS + PERIOD + name + SPACE + EQUAL + SPACE + VALUE +
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET;
}
/**
@@ -507,10 +548,13 @@
* @param compilerAnnotation compiler annotation
* @return getter method for interface
*/
- static String getGetterForInterface(String yangName, String returnType, boolean isList,
- int generatedJavaFiles, YangCompilerAnnotation compilerAnnotation) {
+ static String getGetterForInterface(String yangName, String returnType,
+ boolean isList,
+ int generatedJavaFiles,
+ YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
- return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
+ return getGetterInterfaceString(returnType, yangName,
+ generatedJavaFiles);
}
String listAttr = getListAttribute(returnType, compilerAnnotation);
return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
@@ -523,13 +567,15 @@
* @param yangName attribute name
* @return getter for interface
*/
- private static String getGetterInterfaceString(String returnType, String yangName,
+ private static String getGetterInterfaceString(String returnType,
+ String yangName,
int generatedJavaFiles) {
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
return getGetMethodWithArgument(returnType, yangName);
} else {
- return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
+ return FOUR_SPACE_INDENTATION + returnType + SPACE +
+ yangName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
+ SEMI_COLAN;
}
}
@@ -544,15 +590,18 @@
* @param compilerAnnotation compiler annotations
* @return setter method for interface
*/
- static String getSetterForInterface(String attrName, String attrType, String className,
+ static String getSetterForInterface(String attrName, String attrType,
+ String className,
boolean isList, int generatedJavaFiles,
YangCompilerAnnotation compilerAnnotation) {
if (!isList) {
- return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
+ return getSetterInterfaceString(className, attrName, attrType,
+ generatedJavaFiles);
}
String listAttr = getListAttribute(attrType, compilerAnnotation);
- return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
+ return getSetterInterfaceString(className, attrName, listAttr,
+ generatedJavaFiles);
}
/**
@@ -563,14 +612,19 @@
* @param attrType attribute type
* @return setter string
*/
- private static String getSetterInterfaceString(String className, String attrName, String attrType,
+ private static String getSetterInterfaceString(String className,
+ String attrName,
+ String attrType,
int generatedJavaFiles) {
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCapitalCase(attrName)
- + OPEN_PARENTHESIS + attrType + OP_PARAM + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
+ return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX +
+ getCapitalCase(attrName) + OPEN_PARENTHESIS + attrType +
+ OP_PARAM + SPACE + attrName + CLOSE_PARENTHESIS +
+ SEMI_COLAN;
} else {
- return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName
- + OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
+ return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE +
+ attrName + OPEN_PARENTHESIS + attrType + SPACE + attrName +
+ CLOSE_PARENTHESIS + SEMI_COLAN;
}
}
@@ -591,7 +645,8 @@
*/
private static String getReturnType(JavaAttributeInfo attr) {
String returnType = EMPTY_STRING;
- if (attr.isQualifiedName() && attr.getImportInfo().getPkgInfo() != null) {
+ if (attr.isQualifiedName() &&
+ attr.getImportInfo().getPkgInfo() != null) {
returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
}
returnType = returnType + attr.getImportInfo().getClassInfo();
@@ -605,8 +660,8 @@
* @return build method for interface
*/
static String getBuildForInterface(String yangName) {
- return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
- + NEW_LINE;
+ return FOUR_SPACE_INDENTATION + yangName + SPACE + BUILD +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
@@ -617,16 +672,20 @@
* @param isRootNode if root node
* @return constructor string
*/
- static String getConstructorStart(String yangName, YangPluginConfig pluginConfig, boolean isRootNode) {
+ static String getConstructorStart(String yangName,
+ YangPluginConfig pluginConfig,
+ boolean isRootNode) {
String javadoc = getConstructorString(yangName, pluginConfig);
String returnType = getCapitalCase(DEFAULT) + yangName;
if (isRootNode) {
returnType = yangName + OP_PARAM;
}
- String constructor = FOUR_SPACE_INDENTATION + PROTECTED + SPACE + returnType +
- OPEN_PARENTHESIS + yangName + BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT
- + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ String constructor =
+ FOUR_SPACE_INDENTATION + PROTECTED + SPACE + returnType +
+ OPEN_PARENTHESIS + yangName + BUILDER + SPACE +
+ BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS +
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return javadoc + constructor;
}
@@ -638,24 +697,31 @@
* @param pluginConfig plugin configurations
* @return constructor for class
*/
- public static String getConstructor(JavaAttributeInfo attr, int generatedJavaFiles,
+ public static String getConstructor(JavaAttributeInfo attr,
+ int generatedJavaFiles,
YangPluginConfig pluginConfig) {
String attributeName = attr.getAttributeName();
String constructor;
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
- constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
- + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
- + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
- + getCapitalCase(getCamelCase(attributeName, pluginConfig.getConflictResolver()))
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD +
+ getCamelCase(attributeName,
+ pluginConfig.getConflictResolver()) + SPACE +
+ EQUAL + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD +
+ GET_METHOD_PREFIX +
+ getCapitalCase(getCamelCase(attributeName, pluginConfig
+ .getConflictResolver())) + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
} else {
- constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD
- + getCamelCase(attributeName, pluginConfig.getConflictResolver()) + SPACE + EQUAL
- + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD
- + getCamelCase(attributeName, pluginConfig.getConflictResolver()) +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD +
+ getCamelCase(attributeName,
+ pluginConfig.getConflictResolver()) + SPACE +
+ EQUAL + SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD +
+ getCamelCase(attributeName,
+ pluginConfig.getConflictResolver()) +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN +
+ NEW_LINE;
}
return constructor;
}
@@ -669,15 +735,16 @@
* @param pluginConfig plugin configurations
* @return rpc method string
*/
- public static String getRpcServiceMethod(String rpcName, String inputName, String outputName,
+ public static String getRpcServiceMethod(String rpcName, String inputName,
+ String outputName,
YangPluginConfig pluginConfig) {
rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
if (!inputName.equals(EMPTY_STRING)) {
inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
}
- return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName + OPEN_PARENTHESIS + inputName
- + CLOSE_PARENTHESIS + SEMI_COLAN;
+ return FOUR_SPACE_INDENTATION + outputName + SPACE + rpcName +
+ OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
@@ -689,7 +756,8 @@
* @param pluginConfig plugin configurations
* @return rpc method string
*/
- public static String getRpcManagerMethod(String rpcName, String inputName, String outputName,
+ public static String getRpcManagerMethod(String rpcName, String inputName,
+ String outputName,
YangPluginConfig pluginConfig) {
rpcName = getCamelCase(rpcName, pluginConfig.getConflictResolver());
@@ -697,12 +765,15 @@
inputName = inputName + SPACE + RPC_INPUT_VAR_NAME;
}
- String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
- + OPEN_PARENTHESIS + inputName + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
+ String method =
+ getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
+ outputName + SPACE + rpcName + OPEN_PARENTHESIS +
+ inputName + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
if (!outputName.contentEquals(VOID)) {
- method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + parseTypeForReturnValue(outputName) + SEMI_COLAN
- + NEW_LINE;
+ method += EIGHT_SPACE_INDENTATION + RETURN + SPACE +
+ parseTypeForReturnValue(outputName) + SEMI_COLAN + NEW_LINE;
}
method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
@@ -721,11 +792,12 @@
if (isRootNode) {
type = yangName + OP_PARAM;
}
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + SPACE + BUILD + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS
- + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE +
- type + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN
- + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ 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 + type + OPEN_PARENTHESIS + THIS +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
@@ -735,9 +807,12 @@
* @param modifierType modifier type for default constructor
* @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;
+ 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;
}
/**
@@ -746,9 +821,11 @@
* @return string method's open string
*/
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;
+ 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;
}
/**
@@ -774,21 +851,26 @@
static String getIfConditionBegin(String indentation, String condition) {
- return indentation + IF + SPACE + OPEN_PARENTHESIS + condition + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
- + NEW_LINE;
+ return indentation + IF + SPACE + OPEN_PARENTHESIS + condition +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
- static String getElseIfConditionBegin(String indentation, String condition) {
- return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + getIfConditionBegin("", condition);
+ static String getElseIfConditionBegin(String indentation,
+ String condition) {
+ return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE +
+ getIfConditionBegin("", condition);
}
static String getBlockEnd(String indentation) {
return indentation + CLOSE_CURLY_BRACKET + NEW_LINE;
}
- static String getCollectionIteratorForLoopBegin(String indentation, String loopVar, String collection) {
- return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE + COLAN + SPACE + collection
- + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ static String getCollectionIteratorForLoopBegin(String indentation,
+ String loopVar,
+ String collection) {
+ return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE +
+ COLAN + SPACE + collection + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
/*
@@ -797,7 +879,8 @@
* @return omit null value string
*/
static String getOmitNullValueString() {
- return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING + NEW_LINE;
+ return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING +
+ NEW_LINE;
}
/**
@@ -806,8 +889,9 @@
* @return to string method close string
*/
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;
+ 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;
}
/**
@@ -819,8 +903,9 @@
public static String getToStringMethod(JavaAttributeInfo attr) {
String attributeName = attr.getAttributeName();
- return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
- + COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
+ return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING +
+ OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES + COMMA +
+ SPACE + attributeName + CLOSE_PARENTHESIS;
}
/**
@@ -830,11 +915,13 @@
* @param pluginConfig plugin configurations
* @return from string method's open string
*/
- static String getFromStringMethodSignature(String className, YangPluginConfig pluginConfig) {
- return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE
- + STATIC + SPACE + className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS
- + STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE;
+ static String getFromStringMethodSignature(String className,
+ YangPluginConfig pluginConfig) {
+ return getJavaDoc(FROM_METHOD, className, false, pluginConfig, null) +
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
+ className + SPACE + FROM_STRING_METHOD_NAME + OPEN_PARENTHESIS +
+ STRING_DATA_TYPE + SPACE + FROM_STRING_PARAM_NAME +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -843,24 +930,29 @@
* @return from string method's close string
*/
static String getFromStringMethodClose() {
- return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
+ return EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN +
+ NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
+ NEW_LINE;
}
/**
* Return from string method's body string.
*
* @param attr attribute info
- * @param fromStringAttributeInfo attribute info for the from string wrapper type
+ * @param fromStringAttributeInfo attribute info for the from string wrapper
+ * type
* @return from string method's body string
*/
public static String getFromStringMethod(JavaAttributeInfo attr,
JavaAttributeInfo fromStringAttributeInfo) {
- return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE + TWELVE_SPACE_INDENTATION
- + getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE + TWELVE_SPACE_INDENTATION
- + getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION + getCatchSubString()
- + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return EIGHT_SPACE_INDENTATION + getTrySubString() + NEW_LINE +
+ TWELVE_SPACE_INDENTATION +
+ getParsedSubString(attr, fromStringAttributeInfo) + NEW_LINE +
+ TWELVE_SPACE_INDENTATION +
+ getReturnOfSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ getCatchSubString() + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET;
}
/**
@@ -878,7 +970,8 @@
* @return sub string with return statement for union's from string method
*/
private static String getReturnOfSubString() {
- return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL + CLOSE_PARENTHESIS + SEMI_COLAN;
+ return RETURN + SPACE + OF + OPEN_PARENTHESIS + TMP_VAL +
+ CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
@@ -887,8 +980,9 @@
* @return sub string with catch statement for union's from string method
*/
private static String getCatchSubString() {
- return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS + EXCEPTION + SPACE + EXCEPTION_VAR
- + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
+ return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE + OPEN_PARENTHESIS +
+ EXCEPTION + SPACE + EXCEPTION_VAR + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET;
}
/**
@@ -902,38 +996,60 @@
String targetDataType = getReturnType(attr);
if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) {
- String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
- + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + OPEN_CURLY_BRACKET + SINGLE_QUOTE
- + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
- + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + CLOSE_CURLY_BRACKET + SINGLE_QUOTE
- + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
- + PERIOD + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE + SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR
- + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD + SPLIT_STRING + OPEN_PARENTHESIS
- + QUOTES + COMMA + QUOTES + COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
- + BIT_TEMP_VAR + SPACE + COLON + SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE;
- lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL + SPACE + BIT_TEMP_VAR + PERIOD
- + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
- lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD + SET_METHOD_PREFIX + OPEN_PARENTHESIS
- + INTEGER_WRAPPER + PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR + CLOSE_PARENTHESIS
- + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ String lines =
+ targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
+ NEW + SPACE + targetDataType + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE +
+ OPEN_CURLY_BRACKET + SINGLE_QUOTE + COMMA + SPACE +
+ SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS +
+ SEMI_COLAN + NEW_LINE;
+ lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE +
+ CLOSE_CURLY_BRACKET + SINGLE_QUOTE + COMMA + SPACE +
+ SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS +
+ SEMI_COLAN + NEW_LINE;
+ lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
+ SEMI_COLAN + NEW_LINE;
+ lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE +
+ SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR + SPACE +
+ EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD +
+ SPLIT_STRING + OPEN_PARENTHESIS + QUOTES + COMMA + QUOTES +
+ COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN +
+ NEW_LINE;
+ lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS +
+ STRING_DATA_TYPE + SPACE + BIT_TEMP_VAR + SPACE + COLON +
+ SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
+ lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL +
+ SPACE + BIT_TEMP_VAR + PERIOD + TRIM_STRING +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
+ SEMI_COLAN + NEW_LINE;
+ lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD +
+ SET_METHOD_PREFIX + OPEN_PARENTHESIS + INTEGER_WRAPPER +
+ PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR +
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN +
+ NEW_LINE;
lines += TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return lines;
} else if (attr.getAttributeType().getDataType() == BINARY) {
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + BASE64 + PERIOD
- + GET_DECODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS
- + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
+ BASE64 + PERIOD + GET_DECODER + OPEN_PARENTHESIS +
+ CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS +
+ FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
} else {
- String parseFromStringMethod = getParseFromStringMethod(targetDataType,
- fromStringAttributeInfo.getAttributeType());
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
- + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
+ String parseFromStringMethod =
+ getParseFromStringMethod(targetDataType,
+ fromStringAttributeInfo
+ .getAttributeType());
+ return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE +
+ parseFromStringMethod + OPEN_PARENTHESIS +
+ FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
}
}
@@ -943,10 +1059,11 @@
* @return hash code method open string
*/
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;
+ 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;
}
/**
@@ -958,9 +1075,8 @@
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
- + NEW_LINE;
+ return hashcodeString + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -980,10 +1096,12 @@
* @return equals method open string
*/
static String getEqualsMethodOpen(String className) {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE + SPACE +
- EQUALS_STRING
- + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + OBJ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
- + NEW_LINE + getEqualsMethodsCommonIfCondition() + getEqualsMethodsSpecificIfCondition(className);
+ 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);
}
/**
@@ -992,9 +1110,12 @@
* @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;
+ 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;
}
/**
@@ -1004,10 +1125,13 @@
* @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
- + OBJ + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN + NEW_LINE;
+ 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 + OBJ +
+ SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN +
+ NEW_LINE;
}
/**
@@ -1020,10 +1144,12 @@
equalMethodString = trimAtLast(equalMethodString, AND);
equalMethodString = trimAtLast(equalMethodString, AND);
equalMethodString = trimAtLast(equalMethodString, SPACE);
- equalMethodString = trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE;
- return equalMethodString + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
- + RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
- + NEW_LINE;
+ equalMethodString =
+ trimAtLast(equalMethodString, NEW_LINE) + SEMI_COLAN + NEW_LINE;
+ return equalMethodString + EIGHT_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ RETURN + SPACE + FALSE + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -1035,9 +1161,10 @@
public static String getEqualsMethod(JavaAttributeInfo attr) {
String attributeName = 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;
+ 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;
}
/**
@@ -1049,10 +1176,13 @@
*/
static String getOfMethod(String name, JavaAttributeInfo attr) {
String attrQualifiedType = getReturnType(attr);
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name + SPACE + OF + OPEN_PARENTHESIS
- + attrQualifiedType + 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;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + name +
+ SPACE + OF + OPEN_PARENTHESIS + attrQualifiedType + 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;
}
/**
@@ -1063,14 +1193,16 @@
* @param pluginConfig plugin configurations
* @return of method's string and java doc for special type
*/
- public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr, String generatedJavaClassName,
+ public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr,
+ String generatedJavaClassName,
YangPluginConfig pluginConfig) {
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
- + getOfMethodString(attrType, generatedJavaClassName);
+ return getJavaDoc(OF_METHOD, generatedJavaClassName + " for type " +
+ attrName, false, pluginConfig, null) +
+ getOfMethodString(attrType, generatedJavaClassName);
}
/**
@@ -1081,10 +1213,13 @@
* @return of method's string
*/
private static String getOfMethodString(String type, String className) {
- return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + className + SPACE + OF + OPEN_PARENTHESIS
- + type + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
- + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + className + OPEN_PARENTHESIS + VALUE
- + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
+ className + SPACE + OF + OPEN_PARENTHESIS + type + SPACE +
+ VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
+ NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW +
+ SPACE + className + OPEN_PARENTHESIS + VALUE +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
@@ -1101,8 +1236,10 @@
String attrType = getReturnType(attr);
String attrName = attr.getAttributeName();
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName, false, pluginConfig, null)
- + getTypeConstructorString(attrType, attrName, generatedJavaClassName);
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName +
+ " for type " + attrName, false, pluginConfig, null) +
+ getTypeConstructorString(attrType, attrName,
+ generatedJavaClassName);
}
/**
@@ -1116,8 +1253,11 @@
* @param addFirst whether int came first or uInt came first
* @return string and java doc for constructor of type class
*/
- public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1, JavaAttributeInfo
- attr2, String generatedJavaClassName, YangPluginConfig pluginConfig, ValidatorTypeForUnionTypes type,
+ public static String getTypeConstructorStringAndJavaDoc(JavaAttributeInfo attr1,
+ JavaAttributeInfo attr2,
+ String generatedJavaClassName,
+ YangPluginConfig pluginConfig,
+ ValidatorTypeForUnionTypes type,
boolean addFirst) {
String attrType = getReturnType(attr1);
@@ -1132,12 +1272,17 @@
String appDataStructure = null;
if (attr1 != null && attr1.getCompilerAnnotation() != null) {
- appDataStructure = attr1.getCompilerAnnotation().getYangAppDataStructure().getDataStructure().name();
+ appDataStructure =
+ attr1.getCompilerAnnotation().getYangAppDataStructure()
+ .getDataStructure().name();
}
- return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName + " for type " + attrName1, false, pluginConfig,
- appDataStructure) + getTypeConstructorString(attrType, attrName1,
- attrName2, generatedJavaClassName, type,
- addFirst);
+ return getJavaDoc(TYPE_CONSTRUCTOR, generatedJavaClassName +
+ " for type " + attrName1, false,
+ pluginConfig, appDataStructure) +
+ getTypeConstructorString(attrType, attrName1,
+ attrName2, generatedJavaClassName,
+ type,
+ addFirst);
}
/**
@@ -1148,11 +1293,14 @@
* @param className class name
* @return type constructor string
*/
- private static String getTypeConstructorString(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
- + CLOSE_CURLY_BRACKET;
+ private static String getTypeConstructorString(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 + CLOSE_CURLY_BRACKET;
}
/**
@@ -1163,12 +1311,16 @@
* @param className class attr1
* @return type constructor string
*/
- private static String getTypeConstructorString(String type, String attr1, String attr2, String className,
- ValidatorTypeForUnionTypes validatorType, boolean addInt) {
+ private static String getTypeConstructorString(String type, String attr1,
+ String attr2,
+ String className,
+ ValidatorTypeForUnionTypes validatorType,
+ boolean addInt) {
String constructor;
- constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + OPEN_PARENTHESIS + type + SPACE + VALUE
- + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className +
+ OPEN_PARENTHESIS + type + SPACE + VALUE + CLOSE_PARENTHESIS +
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
String name1;
String name2;
@@ -1179,14 +1331,16 @@
name1 = attr2;
name2 = attr1;
}
- constructor = constructor + ifConditionForIntInTypeDefConstructor(validatorType, addInt) +
- TWELVE_SPACE_INDENTATION + THIS + PERIOD
- + name1 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
- + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION
- + THIS + PERIOD
- + name2 + SPACE + EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION
- + CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION
- + CLOSE_CURLY_BRACKET;
+ constructor = constructor +
+ ifConditionForIntInTypeDefConstructor(validatorType, addInt) +
+ TWELVE_SPACE_INDENTATION + THIS + PERIOD + name1 + SPACE +
+ EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + ELSE +
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ TWELVE_SPACE_INDENTATION + THIS + PERIOD + name2 + SPACE +
+ EQUAL + SPACE + VALUE + SEMI_COLAN + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return constructor;
}
@@ -1197,9 +1351,12 @@
* @return interface of add augmentation
*/
static String getAddAugmentInfoMethodInterface() {
- return generateForAddAugmentation() + FOUR_SPACE_INDENTATION + VOID + SPACE +
- ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
- SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return generateForAddAugmentation() + FOUR_SPACE_INDENTATION + VOID +
+ SPACE +
+ ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS +
+ OBJECT_STRING + SPACE + VALUE + COMMA +
+ SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
@@ -1208,12 +1365,18 @@
* @return implementation of add augmentation
*/
static String getAddAugmentInfoMethodImpl() {
- return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
- ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + OBJECT_STRING + SPACE + VALUE + COMMA +
- SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT +
- OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE + VALUE +
- CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
+ VOID + SPACE +
+ ADD_STRING + YANG_AUGMENTED_INFO + OPEN_PARENTHESIS +
+ OBJECT_STRING + SPACE + VALUE + COMMA +
+ SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
+ NEW_LINE + EIGHT_SPACE_INDENTATION +
+ getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT +
+ OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE +
+ VALUE +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE;
}
@@ -1223,8 +1386,10 @@
* @return interface of get YANG augment info
*/
static String getYangAugmentInfoInterface() {
- return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + OBJECT_STRING + SPACE +
- getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
+ return generateForGetAugmentation() + FOUR_SPACE_INDENTATION +
+ OBJECT_STRING + SPACE +
+ getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS +
+ CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
@@ -1236,10 +1401,14 @@
static String getYangAugmentInfoImpl() {
return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
OBJECT_STRING + SPACE +
- getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + GET + OPEN_PARENTHESIS + CLASS +
- OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ getSmallCase(YANG_AUGMENTED_INFO) + OPEN_PARENTHESIS +
+ CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION +
+ RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP +
+ PERIOD + GET + OPEN_PARENTHESIS + CLASS +
+ OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE;
}
@@ -1249,10 +1418,15 @@
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoMapInterface(YangPluginConfig pluginConfig) {
- return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig, null)
- + FOUR_SPACE_INDENTATION + MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
- QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET +
- SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
+ return getJavaDoc(GETTER_METHOD,
+ getSmallCase(YANG_AUGMENTED_INFO) + MAP, false,
+ pluginConfig, null) + FOUR_SPACE_INDENTATION + MAP +
+ DIAMOND_OPEN_BRACKET +
+ CLASS_STRING + DIAMOND_OPEN_BRACKET +
+ QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE +
+ OBJECT_STRING + DIAMOND_CLOSE_BRACKET +
+ SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP +
+ OPEN_PARENTHESIS +
CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
@@ -1262,14 +1436,17 @@
* @return implementation of get YANG augment info
*/
static String getYangAugmentInfoMapImpl() {
- return getOverRideString()
- + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
- MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + QUESTION_MARK +
- DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING + DIAMOND_CLOSE_BRACKET + SPACE +
+ return getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
+ MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING +
+ DIAMOND_OPEN_BRACKET + QUESTION_MARK +
+ DIAMOND_CLOSE_BRACKET + COMMA + SPACE + OBJECT_STRING +
+ DIAMOND_CLOSE_BRACKET + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + MAP + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SEMI_COLAN + NEW_LINE
- + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION +
+ RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP +
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -1279,12 +1456,14 @@
* @return enum's constructor
*/
static String getEnumsConstructor(String className) {
- return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT + SPACE + VALUE +
- COMMA + SPACE + STRING_DATA_TYPE + SPACE + STR_VAL + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(className) + SPACE + EQUAL
- + SPACE + VALUE + SEMI_COLAN + NEW_LINE
- + EIGHT_SPACE_INDENTATION + SCHEMA_NAME + SPACE + EQUAL
- + SPACE + STR_VAL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return FOUR_SPACE_INDENTATION + className + OPEN_PARENTHESIS + INT +
+ SPACE + VALUE + COMMA + SPACE + STRING_DATA_TYPE + SPACE +
+ STR_VAL + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
+ NEW_LINE + EIGHT_SPACE_INDENTATION +
+ getSmallCase(className) + SPACE + EQUAL + SPACE + VALUE +
+ SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + SCHEMA_NAME +
+ SPACE + EQUAL + SPACE + STR_VAL + SEMI_COLAN + NEW_LINE +
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
/**
@@ -1294,29 +1473,36 @@
* @param pluginConfig plugin configurations
* @return of method
*/
- static String getEnumsOfValueMethod(String className, YangEnumeration enumeration,
+ static String getEnumsOfValueMethod(String className,
+ YangEnumeration enumeration,
YangPluginConfig pluginConfig) {
- String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(className) + SPACE
- + OF + OPEN_PARENTHESIS
- + INT + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
- + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
- + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ String method =
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
+ getCapitalCase(className) + SPACE + OF +
+ OPEN_PARENTHESIS + INT + SPACE + VALUE +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
+ NEW_LINE + EIGHT_SPACE_INDENTATION + SWITCH + SPACE +
+ OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
int value;
String str;
for (YangEnum yangEnum : enumeration.getEnumSet()) {
value = yangEnum.getValue();
str = getEnumJavaAttribute(yangEnum.getNamedValue()).toUpperCase();
- method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE
- + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
- + str + SEMI_COLAN + NEW_LINE;
+ method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value +
+ COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN +
+ SPACE + getCapitalCase(className) + PERIOD + str +
+ SEMI_COLAN + NEW_LINE;
}
- method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION
- + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
- + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON +
+ NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + NULL +
+ SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET;
- return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for value", false, pluginConfig, null)
- + method;
+ return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for value",
+ false, pluginConfig, null) + method;
}
/**
@@ -1329,26 +1515,33 @@
YangPluginConfig pluginConfig,
YangEnumeration enumeration) {
- String method = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE + getCapitalCase(enumName) + SPACE
- + OF + OPEN_PARENTHESIS
- + STRING_DATA_TYPE + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
- + EIGHT_SPACE_INDENTATION + SWITCH + SPACE + OPEN_PARENTHESIS + VALUE
- + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ String method =
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
+ getCapitalCase(enumName) + SPACE + OF +
+ OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE + VALUE +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
+ NEW_LINE + EIGHT_SPACE_INDENTATION + SWITCH + SPACE +
+ OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
String value;
for (YangEnum yangEnum : enumeration.getEnumSet()) {
- value = getEnumJavaAttribute(yangEnum.getNamedValue()).toUpperCase();
+ value = getEnumJavaAttribute(yangEnum.getNamedValue())
+ .toUpperCase();
method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + QUOTES +
- yangEnum.getNamedValue() + QUOTES + COLON + NEW_LINE
- + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(enumName) + PERIOD
- + value + SEMI_COLAN + NEW_LINE;
+ yangEnum.getNamedValue() + QUOTES + COLON + NEW_LINE +
+ SIXTEEN_SPACE_INDENTATION + RETURN + SPACE +
+ getCapitalCase(enumName) + PERIOD + value + SEMI_COLAN +
+ NEW_LINE;
}
- method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION
- + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
- + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON +
+ NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + NULL +
+ SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET;
- return getJavaDoc(OF_METHOD, getCapitalCase(enumName) + " for " + SCHEMA_NAME, false, pluginConfig, null)
- + method;
+ return getJavaDoc(OF_METHOD, getCapitalCase(enumName) + " for " +
+ SCHEMA_NAME, false, pluginConfig, null) + method;
}
/**
@@ -1358,7 +1551,8 @@
* @param yangType YANG type
* @return parsed string
*/
- private static String getParseFromStringMethod(String targetDataType, YangType<?> yangType) {
+ private static String getParseFromStringMethod(String targetDataType,
+ YangType<?> yangType) {
YangDataTypes type = yangType.getDataType();
switch (type) {
@@ -1392,11 +1586,15 @@
case DERIVED:
return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
default:
- throw new TranslatorException("given data type is not supported. " +
- yangType.getDataTypeName() + " in " +
- yangType.getLineNumber() + " at " +
- yangType.getCharPosition()
- + " in " + yangType.getFileName());
+ throw new TranslatorException("given data type is not " +
+ "supported. " +
+ yangType.getDataTypeName() +
+ " in " +
+ yangType.getLineNumber() +
+ " at " +
+ yangType.getCharPosition() +
+ " in " +
+ yangType.getFileName());
}
}
@@ -1415,28 +1613,39 @@
String parentName;
String returnType;
YangNode methodNode;
- YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
+ YangPluginConfig pluginConfig =
+ ((JavaFileInfoContainer) parent).getJavaFileInfo()
+ .getPluginConfig();
for (YangAtomicPath nodeId : targets) {
augmentedNode = nodeId.getResolvedNode().getParent();
methodNode = nodeId.getResolvedNode();
- if (((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName() != null) {
- curNodeName = ((JavaFileInfoContainer) methodNode).getJavaFileInfo().getJavaName();
+ if (((JavaFileInfoContainer) methodNode).getJavaFileInfo()
+ .getJavaName() != null) {
+ curNodeName =
+ ((JavaFileInfoContainer) methodNode).getJavaFileInfo()
+ .getJavaName();
} else {
- curNodeName = getCapitalCase(getCamelCase(methodNode.getName(), pluginConfig
- .getConflictResolver()));
+ curNodeName = getCapitalCase(getCamelCase(methodNode.getName(),
+ pluginConfig.getConflictResolver()));
}
- returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
- parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
- method = generateForGetMethodWithAttribute(returnType)
- + getGetMethodWithArgument(returnType, AUGMENTED + parentName
- + getCapitalCase(curNodeName)) + NEW_LINE;
+ returnType =
+ getAugmentedClassNameForDataMethods(augmentedNode, parent);
+ parentName = getParentNodeNameForDataMethods(augmentedNode,
+ pluginConfig);
+ method = generateForGetMethodWithAttribute(returnType) +
+ getGetMethodWithArgument(returnType, AUGMENTED +
+ parentName + getCapitalCase(curNodeName)) + NEW_LINE;
methods.append(method);
- method = getJavaDoc(MANAGER_SETTER_METHOD, AUGMENTED +
- getCapitalCase(parentName) + getCapitalCase(curNodeName), false, pluginConfig, null) +
+ method = getJavaDoc(MANAGER_SETTER_METHOD,
+ AUGMENTED + getCapitalCase(parentName) +
+ getCapitalCase(curNodeName), false,
+ pluginConfig, null) +
getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
- getCapitalCase(curNodeName), returnType, parentName, false,
- GENERATE_SERVICE_AND_MANAGER, null) + NEW_LINE;
+ getCapitalCase(curNodeName),
+ returnType, parentName, false,
+ GENERATE_SERVICE_AND_MANAGER, null) +
+ NEW_LINE;
methods.append(method);
}
return methods.toString();
@@ -1455,25 +1664,31 @@
} else {
newType = INT;
}
- String method = generateForValidatorMethod() + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
- SPACE +
- VALIDATE_RANGE +
- OPEN_PARENTHESIS
- + type + SPACE + MIN_RANGE + COMMA + SPACE + type + SPACE + MAX_RANGE + COMMA + SPACE +
- newType + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ String method = generateForValidatorMethod() + FOUR_SPACE_INDENTATION +
+ PRIVATE + SPACE + BOOLEAN_DATA_TYPE + SPACE + VALIDATE_RANGE +
+ OPEN_PARENTHESIS + type + SPACE + MIN_RANGE + COMMA + SPACE +
+ type + SPACE + MAX_RANGE + COMMA + SPACE + newType + SPACE +
+ VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
+ NEW_LINE;
if (type.contentEquals(BIG_INTEGER)) {
- method = method + EIGHT_SPACE_INDENTATION + BIG_INTEGER + SPACE + getSmallCase(BIG_INTEGER)
- + SPACE + EQUAL + SPACE + NEW + SPACE + BIG_INTEGER + OPEN_PARENTHESIS + QUOTES + SPACE +
- QUOTES + SPACE + ADD + SPACE + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE +
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo"
- + OPEN_PARENTHESIS + MIN_RANGE + CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SPACE + AND +
- AND + SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" + OPEN_PARENTHESIS + MAX_RANGE +
- CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" + SEMI_COLAN + NEW_LINE;
+ method = method + EIGHT_SPACE_INDENTATION + BIG_INTEGER + SPACE +
+ getSmallCase(BIG_INTEGER) + SPACE + EQUAL + SPACE + NEW +
+ SPACE + BIG_INTEGER + OPEN_PARENTHESIS + QUOTES + SPACE +
+ QUOTES + SPACE + ADD + SPACE + VALUE + CLOSE_PARENTHESIS +
+ SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN +
+ SPACE + getSmallCase(BIG_INTEGER) + PERIOD + "compareTo" +
+ OPEN_PARENTHESIS + MIN_RANGE + CLOSE_PARENTHESIS + SPACE +
+ EQUAL + EQUAL + " 1" + SPACE + AND +
+ AND + SPACE + getSmallCase(BIG_INTEGER) + PERIOD +
+ "compareTo" + OPEN_PARENTHESIS + MAX_RANGE +
+ CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + " 1" +
+ SEMI_COLAN + NEW_LINE;
} else {
- method = method + EIGHT_SPACE_INDENTATION
- + RETURN + SPACE + VALUE + SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE + MIN_RANGE + SPACE + AND +
- AND + SPACE + VALUE + SPACE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE + MAX_RANGE + SEMI_COLAN +
- NEW_LINE;
+ method = method + EIGHT_SPACE_INDENTATION + RETURN + SPACE + VALUE +
+ SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE + MIN_RANGE +
+ SPACE + AND + AND + SPACE + VALUE + SPACE +
+ DIAMOND_OPEN_BRACKET + EQUAL + SPACE + MAX_RANGE +
+ SEMI_COLAN + NEW_LINE;
}
return method + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
@@ -1485,36 +1700,48 @@
* @param addFirst true int/long need to be added first
* @return if condition string for typedef constructor
*/
- private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type, boolean addFirst) {
- String condition = EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + VALIDATE_RANGE + OPEN_PARENTHESIS;
+ private static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type,
+ boolean addFirst) {
+ String condition =
+ EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
+ VALIDATE_RANGE + OPEN_PARENTHESIS;
if (type == INT_TYPE_CONFLICT) {
if (addFirst) {
- condition = condition + INT_MIN_RANGE + COMMA + SPACE + INT_MAX_RANGE + COMMA + SPACE + VALUE;
+ condition = condition + INT_MIN_RANGE + COMMA + SPACE +
+ INT_MAX_RANGE + COMMA + SPACE + VALUE;
} else {
- condition = condition + UINT_MIN_RANGE + COMMA + SPACE + UINT_MAX_RANGE + COMMA + SPACE + VALUE;
+ condition = condition + UINT_MIN_RANGE + COMMA + SPACE +
+ UINT_MAX_RANGE + COMMA + SPACE + VALUE;
}
} else if (type == SHORT_TYPE_CONFLICT) {
if (addFirst) {
- condition = condition + SHORT_MIN_RANGE + COMMA + SPACE + SHORT_MAX_RANGE + COMMA + SPACE + VALUE;
+ condition = condition + SHORT_MIN_RANGE + COMMA + SPACE +
+ SHORT_MAX_RANGE + COMMA + SPACE + VALUE;
} else {
- condition = condition + UINT8_MIN_RANGE + COMMA + SPACE + UINT8_MAX_RANGE + COMMA + SPACE + VALUE;
+ condition = condition + UINT8_MIN_RANGE + COMMA + SPACE +
+ UINT8_MAX_RANGE + COMMA + SPACE + VALUE;
}
} else {
if (addFirst) {
- condition = condition + LONG_MIN_RANGE + COMMA + SPACE + LONG_MAX_RANGE + COMMA + SPACE + VALUE;
+ condition = condition + LONG_MIN_RANGE + COMMA + SPACE +
+ LONG_MAX_RANGE + COMMA + SPACE + VALUE;
} else {
- condition = condition + ULONG_MIN_RANGE + COMMA + SPACE + ULONG_MAX_RANGE + COMMA + SPACE + VALUE;
+ condition = condition + ULONG_MIN_RANGE + COMMA + SPACE +
+ ULONG_MAX_RANGE + COMMA + SPACE + VALUE;
}
}
- return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
//Get method with arguments.
- private static String getGetMethodWithArgument(String returnType, String yangName) {
- return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCapitalCase(yangName)
- + OPEN_PARENTHESIS + returnType + OP_PARAM + SPACE + getSmallCase(returnType) + CLOSE_PARENTHESIS +
- SEMI_COLAN;
+ private static String getGetMethodWithArgument(String returnType,
+ String yangName) {
+ return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX +
+ getCapitalCase(yangName) + OPEN_PARENTHESIS + returnType +
+ OP_PARAM + SPACE + getSmallCase(returnType) +
+ CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
@@ -1524,9 +1751,12 @@
* @param className name of the class
* @return add to list method interface
*/
- public static String getAddToListMethodInterface(JavaAttributeInfo attr, String className) {
- return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + ADD_STRING + getCapitalCase(TO) +
- getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS + getReturnType(attr) + SPACE +
+ public static String getAddToListMethodInterface(JavaAttributeInfo attr,
+ String className) {
+ return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE +
+ ADD_STRING + getCapitalCase(TO) +
+ getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS +
+ getReturnType(attr) + SPACE +
VALUE + CLOSE_PARENTHESIS + SEMI_COLAN;
}
@@ -1538,19 +1768,24 @@
* @param isRoot is root
* @return add to list method impl
*/
- public static String getAddToListMethodImpl(JavaAttributeInfo attr, String generatedJavaClassName, boolean isRoot) {
+ public static String getAddToListMethodImpl(JavaAttributeInfo attr,
+ String generatedJavaClassName,
+ boolean isRoot) {
String retString = "";
if (!isRoot) {
retString = getOverRideString();
}
- return retString + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + generatedJavaClassName + BUILDER + SPACE +
- ADD_STRING +
- getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) + OPEN_PARENTHESIS +
- getReturnType(attr) + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
- + NEW_LINE + EIGHT_SPACE_INDENTATION + attr.getAttributeName() + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
- + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN +
- NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN +
- NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ return retString + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
+ generatedJavaClassName + BUILDER + SPACE + ADD_STRING +
+ getCapitalCase(TO) + getCapitalCase(attr.getAttributeName()) +
+ OPEN_PARENTHESIS + getReturnType(attr) + SPACE + VALUE +
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
+ EIGHT_SPACE_INDENTATION + attr.getAttributeName() +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING +
+ OPEN_PARENTHESIS + VALUE + CLOSE_PARENTHESIS + SEMI_COLAN +
+ NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS +
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ CLOSE_CURLY_BRACKET;
}
/**
@@ -1560,10 +1795,14 @@
* @return builder method for class
*/
static String builderMethod(String name) {
- return NEW_LINE + generateForBuilderMethod(name) + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE
- + name + BUILDER + SPACE + getSmallCase(BUILDER) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + NEW + SPACE + name +
- BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
+ return NEW_LINE + generateForBuilderMethod(name) +
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE + STATIC + SPACE +
+ name + BUILDER + SPACE + getSmallCase(BUILDER) +
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
+ RETURN + SPACE + NEW + SPACE + name +
+ BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN +
+ NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET;
}
@@ -1575,18 +1814,21 @@
*/
static String processSubtreeFilteringInterface(String name) {
String method = " /**\n" +
- " * Checks if the passed " + name + " maps the content match query condition.\n" +
+ " * Checks if the passed " + name +
+ " maps the content match query condition.\n" +
" *\n" +
- " * @param " + getSmallCase(name) + SPACE + getSmallCase(name) + SPACE + "being passed to check" +
+ " * @param " + getSmallCase(name) + SPACE +
+ getSmallCase(name) + SPACE + "being passed to check" +
" for" +
" content match\n" +
" * @param isSelectAllSchemaChild is select all schema child\n" +
" * @return match result\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + name + SPACE + PROCESS_SUBTREE_FILTERING +
- OPEN_PARENTHESIS
- + name + SPACE + getSmallCase(name) + COMMA + SPACE + BOOLEAN_DATA_TYPE + SPACE +
- "isSelectAllSchemaChild" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return method + FOUR_SPACE_INDENTATION + name + SPACE +
+ PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS +
+ name + SPACE + getSmallCase(name) + COMMA + SPACE +
+ BOOLEAN_DATA_TYPE + SPACE + "isSelectAllSchemaChild" +
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
@@ -1594,15 +1836,16 @@
*
* @return is value set interface
*/
- static String isLeafValueSetInterface() {
+ static String isLeafValueSetInterface() {
String method = " /**\n" +
" * Checks if the leaf value is set.\n" +
" *\n" +
" * @param leaf leaf whose value status needs to checked\n" +
" * @return result of leaf value set in object\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + VALUE_LEAF_SET + OPEN_PARENTHESIS
- + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
+ VALUE_LEAF_SET + OPEN_PARENTHESIS + LEAF_IDENTIFIER + SPACE +
+ "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
@@ -1617,8 +1860,9 @@
" * @param leaf if leaf needs to be selected\n" +
" * @return result of leaf value set in object\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE + IS_SELECT_LEAF + OPEN_PARENTHESIS
- + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return method + FOUR_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
+ IS_SELECT_LEAF + OPEN_PARENTHESIS + LEAF_IDENTIFIER + SPACE +
+ "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
@@ -1634,8 +1878,9 @@
" * @param leaf leaf needs to be selected\n" +
" * @return builder object for select leaf\n" +
" */\n";
- return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE + SET_SELECT_LEAF + OPEN_PARENTHESIS
- + LEAF_IDENTIFIER + SPACE + "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+ return method + FOUR_SPACE_INDENTATION + name + BUILDER + SPACE +
+ SET_SELECT_LEAF + OPEN_PARENTHESIS + LEAF_IDENTIFIER + SPACE +
+ "leaf" + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
/**
@@ -1648,8 +1893,8 @@
String start = " /**\n" +
" * Identify the leaf of " + name + PERIOD + NEW_LINE +
" */\n";
- return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + LEAF_IDENTIFIER + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
+ return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE +
+ LEAF_IDENTIFIER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -1698,22 +1943,6 @@
}
/**
- * Returns getter for operation type.
- *
- * @return getter for operation type
- */
- static String getGetterForOperationType() {
- return " /**\n" +
- " * Returns the onosYangNodeOperationType.\n" +
- " *\n" +
- " * @return value of onosYangNodeOperationType\n" +
- " */\n" +
- " public OnosYangNodeOperationType onosYangNodeOperationType() {\n" +
- " return onosYangNodeOperationType;\n" +
- " }\n\n";
- }
-
- /**
* Returns getters for value and select leaf.
*
* @return getters for value and select leaf
@@ -1732,26 +1961,6 @@
}
/**
- * Returns setter for operation type.
- *
- * @param name name of node
- * @return setter for operation type
- */
- static String getSetterForOperationType(String name) {
- return " /**\n" +
- " * Set node operation type.\n" +
- " *\n" +
- " * @param onosYangNodeOperationType node operation type\n" +
- " * @return builder object for node operation type\n" +
- " */\n" +
- " public " + name + BUILDER + " onosYangNodeOperationType(OnosYangNodeOperationType " +
- "onosYangNodeOperationType) {\n" +
- " this.onosYangNodeOperationType = onosYangNodeOperationType;\n" +
- " return this;\n" +
- " }\n\n";
- }
-
- /**
* Returns setter for select leaf.
*
* @param name name of node
@@ -1765,30 +1974,38 @@
}
return "\n" +
" " + append + "\n" +
- " public " + name + BUILDER + " selectLeaf(LeafIdentifier leaf) {\n" +
+ " public " + name + BUILDER +
+ " selectLeaf(LeafIdentifier leaf) {\n" +
" getSelectLeafFlags().set(leaf.getLeafIndex());\n" +
" return this;\n" +
" }\n";
}
- private static String getListAttribute(String attrType, YangCompilerAnnotation compilerAnnotation) {
+ private static String getListAttribute(String attrType,
+ YangCompilerAnnotation compilerAnnotation) {
String listAttr;
- if (compilerAnnotation != null && compilerAnnotation.getYangAppDataStructure() != null) {
- switch (compilerAnnotation.getYangAppDataStructure().getDataStructure()) {
+ if (compilerAnnotation != null &&
+ compilerAnnotation.getYangAppDataStructure() != null) {
+ switch (compilerAnnotation.getYangAppDataStructure()
+ .getDataStructure()) {
case QUEUE: {
- listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
+ listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType +
+ DIAMOND_CLOSE_BRACKET;
break;
}
case SET: {
- listAttr = SET + DIAMOND_OPEN_BRACKET + attrType + DIAMOND_CLOSE_BRACKET;
+ listAttr = SET + DIAMOND_OPEN_BRACKET + attrType +
+ DIAMOND_CLOSE_BRACKET;
break;
}
case LIST: {
- listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+ listAttr = getListString() + attrType +
+ DIAMOND_CLOSE_BRACKET;
break;
}
default: {
- listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
+ listAttr = getListString() + attrType +
+ DIAMOND_CLOSE_BRACKET;
}
}
} else {
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java
new file mode 100644
index 0000000..a2c80e6
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java
@@ -0,0 +1,92 @@
+/*
+ * 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;
+
+/**
+ * Represents translator error type.
+ */
+public enum TranslatorErrorType {
+ /**
+ * Represents the invalid node for translation.
+ */
+ INVALID_TRANSLATION_NODE("Invalid node for translation"),
+
+ /**
+ * Represents the missing parent node.
+ */
+ MISSING_PARENT_NODE("Missing parent node to get current node's java " +
+ "information"),
+
+ /**
+ * Represents the invalid parent node.
+ */
+ INVALID_PARENT_NODE("Invalid parent node to get current node's java " +
+ "information"),
+
+ /**
+ * Represents the invalid holder of leaf.
+ */
+ INVALID_LEAF_HOLDER("Invalid holder of leaf"),
+
+ /**
+ * Represents the invalid leaf list without JAVA information.
+ */
+ INVALID_LEAF_LIST("Leaf-list does not have java information"),
+
+ /**
+ * Represents the invalid leaf without JAVA information.
+ */
+ INVALID_LEAF("Leaf does not have java information"),
+
+ /**
+ * Represents the invalid node without JAVA information.
+ */
+ INVALID_NODE("Missing java file information to get the package details " +
+ "of attribute corresponding to child node"),
+
+ /**
+ * Represents that code generation failed for a node at exit.
+ */
+ FAIL_AT_EXIT("Failed to generate code for notification node"),
+
+ /**
+ * Represents that code generation preparation failed for a node at entry.
+ */
+ FAIL_AT_ENTRY("Failed to prepare generate code entry for " +
+ "notification node");
+
+ // Prefix of an error type.
+ private String prefix;
+
+ /**
+ * Creates translator error type.
+ *
+ * @param p prefix string
+ */
+ TranslatorErrorType(String p) {
+ prefix = p;
+ }
+
+ /**
+ * Returns prefix for a given enum type.
+ *
+ * @return prefix
+ */
+ public String prefix() {
+ return prefix;
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java
new file mode 100644
index 0000000..2116ab8
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java
@@ -0,0 +1,151 @@
+/*
+ * 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 org.onosproject.yangutils.datamodel.LocationInfo;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
+import org.onosproject.yangutils.utils.io.YangPluginConfig;
+
+import java.io.IOException;
+
+/**
+ * Represents common translator utilities.
+ */
+public final class TranslatorUtils {
+
+ private static final String IN = " in ";
+ private static final String AT = " at ";
+
+ // No instantiation
+ private TranslatorUtils() {
+ }
+
+ /**
+ * Returns translator error message string with location information for
+ * YANG schema node with localized message.
+ *
+ * @param errorType type of translator error
+ * @param node YANG schema node
+ * @param localizedMsg localized message
+ * @return translator error message
+ */
+ public static String getErrorMsg(TranslatorErrorType errorType,
+ YangSchemaNode node,
+ String localizedMsg) {
+ return getErrorMsg(errorType, node) + localizedMsg;
+ }
+
+ /**
+ * Returns translator error message string with location information for
+ * YANG schema node.
+ *
+ * @param errorType type of translator error
+ * @param node YANG schema node
+ * @return translator error message
+ */
+ public static String getErrorMsg(TranslatorErrorType errorType,
+ YangSchemaNode node) {
+ return errorType.prefix() + IN + node.getName() + getLocationMsg(node);
+ }
+
+ /**
+ * Returns translator error message string with location information for
+ * JAVA code generator info.
+ *
+ * @param errorType type of translator error
+ * @param location node with location info
+ * @return translator error message
+ */
+ public static String getErrorMsgForCodeGenerator(TranslatorErrorType errorType,
+ LocationInfo location) {
+ return errorType.prefix() + getLocationMsg(location);
+ }
+
+ /**
+ * Returns location message string.
+ *
+ * @param location location info node
+ * @return location message string
+ */
+ private static String getLocationMsg(LocationInfo location) {
+ return AT + location.getLineNumber() + AT +
+ location.getCharPosition() + IN + location.getFileName();
+ }
+
+ /**
+ * Returns bean temp files for YANG node.
+ *
+ * @param curNode current YANG node
+ * @return bean files
+ */
+ public static TempJavaBeanFragmentFiles getBeanFiles(YangNode curNode) {
+ return ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles();
+ }
+
+ /**
+ * Returns bean temp files for JAVA code generator info.
+ *
+ * @param info JAVA code generator info
+ * @return bean files
+ */
+ public static TempJavaBeanFragmentFiles getBeanFiles(JavaCodeGeneratorInfo
+ info) {
+ return info.getTempJavaCodeFragmentFiles().getBeanTempFiles();
+ }
+
+ /**
+ * Returns type temp files for YANG node.
+ *
+ * @param curNode current YANG node
+ * @return type files
+ */
+ public static TempJavaTypeFragmentFiles getTypeFiles(YangNode curNode) {
+ return ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getTypeTempFiles();
+ }
+
+ /**
+ * Adds default constructor to a given YANG node.
+ *
+ * @param node YANG node
+ * @param modifier modifier for constructor.
+ * @param toAppend string which need to be appended with the class name
+ * @param config plugin configurations
+ * @param curNode YANG node
+ * @return default constructor for class
+ * @throws IOException when fails to append to file
+ */
+ public static String addDefaultConstructor(YangNode node, String modifier,
+ String toAppend,
+ YangPluginConfig config,
+ YangNode curNode)
+ throws IOException {
+ return ((TempJavaCodeFragmentFilesContainer) node)
+ .getTempJavaCodeFragmentFiles()
+ .addDefaultConstructor(modifier, toAppend, config, curNode);
+ /*
+ * TODO update addDefaultConstructor, it doesn't need YANG node as an
+ * input.
+ */
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 5de5b1c..b7ddc34 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -28,33 +28,39 @@
/**
* JavaDocs for impl class.
*/
- public static final String IMPL_CLASS_JAVA_DOC = " * Represents the implementation of ";
+ public static final String IMPL_CLASS_JAVA_DOC =
+ " * Represents the implementation of ";
/**
* JavaDocs for builder class.
*/
- public static final String BUILDER_CLASS_JAVA_DOC = " * Represents the builder implementation of ";
+ public static final String BUILDER_CLASS_JAVA_DOC =
+ " * Represents the builder implementation of ";
/**
* JavaDocs for interface class.
*/
- public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the"
- + " functionality of ";
+ public static final String INTERFACE_JAVA_DOC =
+ " * Abstraction of an entity which represents the functionality " +
+ "of ";
/**
* JavaDocs for event.
*/
- public static final String EVENT_JAVA_DOC = " * Represents event implementation of ";
+ public static final String EVENT_JAVA_DOC =
+ " * Represents event implementation of ";
/**
* JavaDocs for op param class.
*/
- public static final String OP_PARAM_JAVA_DOC = " * Represents operation parameter implementation of ";
+ public static final String OP_PARAM_JAVA_DOC =
+ " * Represents operation parameter implementation of ";
/**
* JavaDocs for event listener.
*/
- public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of ";
+ public static final String EVENT_LISTENER_JAVA_DOC =
+ " * Abstraction for event listener of ";
/**
* JavaDocs for builder interface class.
@@ -64,7 +70,8 @@
/**
* JavaDocs for enum class.
*/
- public static final String ENUM_CLASS_JAVADOC = " * Represents ENUM data of ";
+ public static final String ENUM_CLASS_JAVADOC =
+ " * Represents ENUM data of ";
/**
* JavaDocs for enum attribute.
@@ -74,12 +81,14 @@
/**
* JavaDocs for package info class.
*/
- public static final String PACKAGE_INFO_JAVADOC = " * Implementation of YANG node ";
+ public static final String PACKAGE_INFO_JAVADOC =
+ " * Implementation of YANG node ";
/**
* JavaDocs for package info class.
*/
- public static final String PACKAGE_INFO_JAVADOC_OF_CHILD = "'s children nodes";
+ public static final String PACKAGE_INFO_JAVADOC_OF_CHILD =
+ "'s children nodes";
/**
* JavaDocs's first line.
@@ -104,7 +113,8 @@
/**
* JavaDocs's description for setter method.
*/
- public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
+ public static final String JAVA_DOC_SETTERS =
+ " * Returns the builder object of ";
/**
* JavaDocs's description for add to list method.
@@ -114,7 +124,8 @@
/**
* JavaDocs's description for setter method.
*/
- public static final String JAVA_DOC_MANAGER_SETTERS = " * Sets the value to attribute ";
+ public static final String JAVA_DOC_MANAGER_SETTERS =
+ " * Sets the value to attribute ";
/**
* JavaDocs's description for OF method.
@@ -124,7 +135,8 @@
/**
* JavaDocs's description for typedef' setter method.
*/
- public static final String JAVA_DOC_SETTERS_COMMON = " * Sets the value of ";
+ public static final String JAVA_DOC_SETTERS_COMMON =
+ " * Sets the value of ";
/**
* JavaDocs's description for getter method.
@@ -134,17 +146,20 @@
/**
* JavaDocs's description for getter method.
*/
- public static final String JAVA_DOC_FOR_VALIDATOR = " * Validates if value is in given range.";
+ public static final String JAVA_DOC_FOR_VALIDATOR =
+ " * Validates if value is in given range.";
/**
* JavaDocs's description for getter method.
*/
- public static final String JAVA_DOC_FOR_VALIDATOR_RETURN = " * @return true if value is in range";
+ public static final String JAVA_DOC_FOR_VALIDATOR_RETURN =
+ " * @return true if value is in range";
/**
* JavaDocs's description for constructor.
*/
- public static final String JAVA_DOC_CONSTRUCTOR = " * Creates an instance of ";
+ public static final String JAVA_DOC_CONSTRUCTOR =
+ " * Creates an instance of ";
/**
* JavaDocs's description for build method.
@@ -174,7 +189,8 @@
/**
* JavaDocs's statement for rpc's output string.
*/
- public static final String RPC_OUTPUT_STRING = "output of service interface ";
+ public static final String RPC_OUTPUT_STRING =
+ "output of service interface ";
/**
* Static attribute for new line.
@@ -187,11 +203,6 @@
public static final String DEFAULT = "default";
/**
- * Static attribute for op param class.
- */
- public static final String OPERATION = "OpParam";
-
- /**
* Static attribute for java code generation for sbi.
*/
public static final String SBI = "sbi";
@@ -312,11 +323,6 @@
public static final String STR_VAL = "stringValue";
/**
- * Static attribute for value of method.
- */
- public static final String VALUE_OF = "valueOf";
-
- /**
* Static attribute for validateRange.
*/
public static final String VALIDATE_RANGE = "validateRange";
@@ -334,7 +340,8 @@
/**
* Static attribute for minRange.
*/
- public static final String SHORT_MIN_RANGE_ATTR = "static final int INT16_MIN_RANGE = -32768;\n";
+ public static final String SHORT_MIN_RANGE_ATTR =
+ "static final int INT16_MIN_RANGE = -32768;\n";
/**
* Static attribute for minRange.
@@ -349,18 +356,21 @@
/**
* Static attribute for maxRange.
*/
- public static final String SHORT_MAX_RANGE_ATTR = "static final int INT16_MAX_RANGE = 32767;";
+ public static final String SHORT_MAX_RANGE_ATTR =
+ "static final int INT16_MAX_RANGE = 32767;";
/**
* Static attribute for minRange.
*/
- public static final String UINT8_MIN_RANGE_ATTR = "static final int UINT8_MIN_RANGE = 0;\n";
+ public static final String UINT8_MIN_RANGE_ATTR =
+ "static final int UINT8_MIN_RANGE = 0;\n";
/**
* Static attribute for maxRange.
*/
- public static final String UINT8_MAX_RANGE_ATTR = "static final int UINT8_MAX_RANGE = 32767;";
+ public static final String UINT8_MAX_RANGE_ATTR =
+ "static final int UINT8_MAX_RANGE = 32767;";
/**
@@ -376,7 +386,8 @@
/**
* Static attribute for minRange.
*/
- public static final String INT_MIN_RANGE_ATTR = "static final int INT32_MIN_RANGE = -2147483648;\n";
+ public static final String INT_MIN_RANGE_ATTR =
+ "static final int INT32_MIN_RANGE = -2147483648;\n";
/**
* Static attribute for minRange.
@@ -391,18 +402,21 @@
/**
* Static attribute for maxRange.
*/
- public static final String INT_MAX_RANGE_ATTR = "static final int INT32_MAX_RANGE = 2147483647;";
+ public static final String INT_MAX_RANGE_ATTR =
+ "static final int INT32_MAX_RANGE = 2147483647;";
/**
* Static attribute for minRange.
*/
- public static final String UINT_MIN_RANGE_ATTR = "static final int UINT16_MIN_RANGE = 0;\n";
+ public static final String UINT_MIN_RANGE_ATTR =
+ "static final int UINT16_MIN_RANGE = 0;\n";
/**
* Static attribute for maxRange.
*/
- public static final String UINT_MAX_RANGE_ATTR = "static final int UINT16_MAX_RANGE = 2147483647;";
+ public static final String UINT_MAX_RANGE_ATTR =
+ "static final int UINT16_MAX_RANGE = 2147483647;";
/**
@@ -418,14 +432,16 @@
/**
* Static attribute for minRange.
*/
- public static final String LONG_MIN_RANGE_ATTR = "static final BigInteger INT64_MIN_RANGE =" +
- " new BigInteger(\"-9223372036854775808\");\n";
+ public static final String LONG_MIN_RANGE_ATTR =
+ "static final BigInteger INT64_MIN_RANGE =" +
+ " new BigInteger(\"-9223372036854775808\");\n";
/**
* Static attribute for maxRange.
*/
- public static final String LONG_MAX_RANGE_ATTR = "static final BigInteger INT64_MAX_RANGE =" +
- " new BigInteger(\"9223372036854775807\");";
+ public static final String LONG_MAX_RANGE_ATTR =
+ "static final BigInteger INT64_MAX_RANGE =" +
+ " new BigInteger(\"9223372036854775807\");";
/**
* Static attribute for minRange.
@@ -440,14 +456,16 @@
/**
* Static attribute for minRange.
*/
- public static final String ULONG_MIN_RANGE_ATTR = "static final BigInteger UINT32_MIN_RANGE =" +
- " new BigInteger(\"0\");\n";
+ public static final String ULONG_MIN_RANGE_ATTR =
+ "static final BigInteger UINT32_MIN_RANGE =" +
+ " new BigInteger(\"0\");\n";
/**
* Static attribute for maxRange.
*/
- public static final String ULONG_MAX_RANGE_ATTR = "static final BigInteger UINT32_MAX_RANGE =" +
- " new BigInteger(\"9223372036854775807\");";
+ public static final String ULONG_MAX_RANGE_ATTR =
+ "static final BigInteger UINT32_MAX_RANGE =" +
+ " new BigInteger(\"9223372036854775807\");";
/**
@@ -845,27 +863,26 @@
/**
* Static attribute for is filter content match method prefix.
*/
- public static final String PROCESS_SUBTREE_FILTERING = "processSubtreeFiltering";
+ public static final String PROCESS_SUBTREE_FILTERING =
+ "processSubtreeFiltering";
/**
* variable name of the subtree filtering result builder.
*/
- public static final String SUBTREE_FILTERING_RESULT_BUILDER = "subTreeFilteringResultBuilder";
+ public static final String SUBTREE_FILTERING_RESULT_BUILDER =
+ "subTreeFilteringResultBuilder";
/**
* variable name of the subtree filtering result flag.
*/
- public static final String IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG = "isAnySelectOrContainmentNode";
+ public static final String IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG =
+ "isAnySelectOrContainmentNode";
/**
* variable name of the subtree filtering to select all child.
*/
- public static final String IS_SELECT_ALL_SCHEMA_CHILD_FLAG = "isSelectAllSchemaChild";
-
- /**
- * Static attribute for flag prefix.
- */
- public static final String FLAG = "flag";
+ public static final String IS_SELECT_ALL_SCHEMA_CHILD_FLAG =
+ "isSelectAllSchemaChild";
/**
* Static attribute for break prefix.
@@ -920,37 +937,44 @@
/**
* Static attribute for eight space indentation.
*/
- public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
+ public static final String EIGHT_SPACE_INDENTATION =
+ FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
/**
* Static attribute for twelve space indentation.
*/
- public static final String TWELVE_SPACE_INDENTATION = EIGHT_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
+ public static final String TWELVE_SPACE_INDENTATION =
+ EIGHT_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
/**
* Static attribute for sixteen space indentation.
*/
- public static final String SIXTEEN_SPACE_INDENTATION = TWELVE_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
+ public static final String SIXTEEN_SPACE_INDENTATION =
+ TWELVE_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
/**
* Static attribute for twenty space indentation.
*/
- public static final String TWENTY_SPACE_INDENTATION = SIXTEEN_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
+ public static final String TWENTY_SPACE_INDENTATION =
+ SIXTEEN_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
/**
* Static attribute for twenty four space indentation.
*/
- public static final String TWENTY_FOUR_SPACE_INDENTATION = TWENTY_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
+ public static final String TWENTY_FOUR_SPACE_INDENTATION =
+ TWENTY_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
/**
* Static attribute for twenty eight space indentation.
*/
- public static final String TWENTY_EIGHT_SPACE_INDENTATION = TWENTY_FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
+ public static final String TWENTY_EIGHT_SPACE_INDENTATION =
+ TWENTY_FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
/**
* Static attribute for thirty two space indentation.
*/
- public static final String THIRTY_TWO_SPACE_INDENTATION = TWENTY_EIGHT_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
+ public static final String THIRTY_TWO_SPACE_INDENTATION =
+ TWENTY_EIGHT_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
/**
* continue.
@@ -973,7 +997,8 @@
public static final String REVISION_PREFIX = "rev";
/**
- * Static attribute for YANG automatic prefix for identifiers with keywords and beginning with digits.
+ * Static attribute for YANG automatic prefix for identifiers with keywords
+ * and beginning with digits.
*/
public static final String YANG_AUTO_PREFIX = "yangAutoPrefix";
@@ -1098,14 +1123,20 @@
public static final String QUESTION_MARK = "?";
/**
- * List of keywords in java, this is used for checking if the input does not contain these keywords.
+ * List of keywords in java, this is used for checking if the input does not
+ * contain these keywords.
*/
- public static final List<String> JAVA_KEY_WORDS = Arrays.asList(
- "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
- "default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "goto", "if",
- "implements", "import", "instanceof", "enum", "int", "interface", "long", "native", "new", "null",
- "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch",
- "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
+ public static final List<String> JAVA_KEY_WORDS =
+ Arrays.asList("abstract", "assert", "boolean", "break", "byte",
+ "case", "catch", "char", "class", "const", "continue",
+ "default", "do", "double", "else", "extends", "false",
+ "final", "finally", "float", "for", "goto", "if",
+ "implements", "import", "instanceof", "enum", "int",
+ "interface", "long", "native", "new", "null",
+ "package", "private", "protected", "public", "return",
+ "short", "static", "strictfp", "super", "switch",
+ "synchronized", "this", "throw", "throws", "transient",
+ "true", "try", "void", "volatile", "while");
/**
* Static attribute for regex for all the special characters.
@@ -1113,7 +1144,8 @@
public static final String REGEX_WITH_ALL_SPECIAL_CHAR = "\\p{Punct}+";
/**
- * Static attribute for regex for three special characters used in identifier.
+ * Static attribute for regex for three special characters used in
+ * identifier.
*/
public static final String REGEX_FOR_IDENTIFIER_SPECIAL_CHAR = "[. _ -]+";
@@ -1150,7 +1182,8 @@
/**
* Static attribute for regex for digits with single letter.
*/
- public static final String REGEX_FOR_DIGITS_WITH_SINGLE_LETTER = "[0-9]+[a-zA-Z]";
+ public static final String REGEX_FOR_DIGITS_WITH_SINGLE_LETTER =
+ "[0-9]+[a-zA-Z]";
/**
* Static attribute for regex with uppercase.
@@ -1163,14 +1196,18 @@
public static final String REGEX_WITH_SINGLE_CAPITAL_CASE = "[A-Z]";
/**
- * Static attribute for regex for capital case letter with any number of digits and small case letters.
+ * Static attribute for regex for capital case letter with any number of
+ * digits and small case letters.
*/
- public static final String REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES = "[A-Z][0-9a-z]+";
+ public static final String
+ REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES =
+ "[A-Z][0-9a-z]+";
/**
* Static attribute for regex for any string ending with service.
*/
- public static final String REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE = ".+Service";
+ public static final String REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE =
+ ".+Service";
/**
* Static attribute for class syntax.
@@ -1321,17 +1358,20 @@
/**
* Static attribute for more object import package.
*/
- public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG = "com.google.common.base";
+ public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG =
+ "com.google.common.base";
/**
* Static attribute for more object import class.
*/
- public static final String GOOGLE_MORE_OBJECT_IMPORT_CLASS = "MoreObjects;\n";
+ public static final String GOOGLE_MORE_OBJECT_IMPORT_CLASS =
+ "MoreObjects;\n";
/**
* Static attribute for to string method.
*/
- public static final String GOOGLE_MORE_OBJECT_METHOD_STRING = " MoreObjects.toStringHelper(getClass())";
+ public static final String GOOGLE_MORE_OBJECT_METHOD_STRING =
+ " MoreObjects.toStringHelper(getClass())";
/**
* Static attribute for java utilities import package.
@@ -1349,11 +1389,6 @@
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
/**
- * Static attribute for java utilities import base64 class.
- */
- public static final String JAVA_UTIL_IMPORT_BASE64_CLASS = "Base64;\n";
-
- /**
* Static attribute for AugmentedInfo class.
*/
public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
@@ -1381,7 +1416,8 @@
/**
* Comment to be added for autogenerated impl methods.
*/
- public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
+ public static final String YANG_UTILS_TODO =
+ "//TODO: YANG utils generated code";
/**
* Static attribute for AbstractEvent.
@@ -1411,49 +1447,52 @@
/**
* Static attribute for unsupported error information.
*/
- public static final String UNSUPPORTED_YANG_CONSTRUCT = " is not supported.";
+ public static final String UNSUPPORTED_YANG_CONSTRUCT =
+ " is not supported.";
/**
* Static attribute for currently unsupported error information.
*/
- public static final String CURRENTLY_UNSUPPORTED = " is not supported in current version, please check wiki" +
- " for YANG utils road map.";
+ public static final String CURRENTLY_UNSUPPORTED =
+ " is not supported in current version, please check wiki" +
+ " for YANG utils road map.";
/**
* Static attribute for typedef linker error information.
*/
- public static final String TYPEDEF_LINKER_ERROR = "YANG file error: Unable to find base "
- + "typedef for given type";
+ public static final String TYPEDEF_LINKER_ERROR =
+ "YANG file error: Unable to find base typedef for given type";
/**
* Static attribute for grouping linker error information.
*/
- public static final String GROUPING_LINKER_ERROR = "YANG file error: Unable to find base "
- + "grouping for given uses";
+ public static final String GROUPING_LINKER_ERROR =
+ "YANG file error: Unable to find base grouping for given uses";
/**
* Static attribute for if-feature linker error information.
*/
- public static final String FEATURE_LINKER_ERROR = "YANG file error: Unable to find feature "
- + "for given if-feature";
+ public static final String FEATURE_LINKER_ERROR =
+ "YANG file error: Unable to find feature for given if-feature";
/**
* Static attribute for leafref linker error information.
*/
- public static final String LEAFREF_LINKER_ERROR = "YANG file error: Unable to find base "
- + "leaf/leaf-list for given leafref";
+ public static final String LEAFREF_LINKER_ERROR =
+ "YANG file error: Unable to find base leaf/leaf-list for given " +
+ "leafref";
/**
* Static attribute for base linker error information.
*/
- public static final String BASE_LINKER_ERROR = "YANG file error: Unable to find base "
- + "identity for given base";
+ public static final String BASE_LINKER_ERROR =
+ "YANG file error: Unable to find base identity for given base";
/**
* Static attribute for identityref linker error information.
*/
- public static final String IDENTITYREF_LINKER_ERROR = "YANG file error: Unable to find base "
- + "identity for given base";
+ public static final String IDENTITYREF_LINKER_ERROR =
+ "YANG file error: Unable to find base identity for given base";
/**
* Static attribute for jar.
@@ -1468,17 +1507,20 @@
/**
* Static attribute for YangAugmentedOpParamInfo.
*/
- public static final String YANG_AUGMENTED_OP_PARAM_INFO = "YangAugmentedOpParamInfo";
+ public static final String YANG_AUGMENTED_OP_PARAM_INFO =
+ "YangAugmentedOpParamInfo";
/**
* Static attribute for NoSuchMethodException.
*/
- public static final String NO_SUCH_METHOD_EXCEPTION = "NoSuchMethodException";
+ public static final String NO_SUCH_METHOD_EXCEPTION =
+ "NoSuchMethodException";
/**
* Static attribute for InvocationTargetException.
*/
- public static final String INVOCATION_TARGET_EXCEPTION = "InvocationTargetException";
+ public static final String INVOCATION_TARGET_EXCEPTION =
+ "InvocationTargetException";
/**
* Static attribute for InvocationTargetException.
@@ -1488,7 +1530,8 @@
/**
* Static attribute for IllegalAccessException.
*/
- public static final String ILLEGAL_ACCESS_EXCEPTION = "IllegalAccessException";
+ public static final String ILLEGAL_ACCESS_EXCEPTION =
+ "IllegalAccessException";
/**
* Static attribute for arrayList.
@@ -1498,12 +1541,8 @@
/**
* Static attribute for arrayList import.
*/
- public static final String ARRAY_LIST_IMPORT = IMPORT + COLLECTION_IMPORTS + ".ArrayList;\n";
-
- /**
- * Static attribute for temp keyword.
- */
- public static final String TMP_VAR = "tmp";
+ public static final String ARRAY_LIST_IMPORT =
+ IMPORT + COLLECTION_IMPORTS + ".ArrayList;\n";
/**
* Static attribute for unused keyword.
@@ -1516,8 +1555,88 @@
public static final String ONE = "1";
/**
- * Creates an instance of util constants.
+ * Static attribute for YANG node operation type class.
*/
+ public static final String OPERATION_TYPE_CLASS =
+ "OnosYangNodeOperationType";
+
+ /**
+ * Static attribute for YANG node operation type attribute.
+ */
+ public static final String OPERATION_TYPE_ATTRIBUTE =
+ "NodeOperationType";
+
+ /**
+ * Static attribute for event class.
+ */
+ public static final String EVENT_CLASS = "event class";
+
+ /**
+ * Static attribute for typedef class.
+ */
+ public static final String TYPEDEF_CLASS = "typedef class";
+
+ /**
+ * Static attribute for impl class.
+ */
+ public static final String IMPL_CLASS = "impl class";
+
+ /**
+ * Static attribute for union class.
+ */
+ public static final String UNION_CLASS = "union class";
+
+ /**
+ * Static attribute for enum class.
+ */
+ public static final String ENUM_CLASS = "enum class";
+
+ /**
+ * Static attribute for rpc class.
+ */
+ public static final String RPC_CLASS = "rpc class";
+
+ /**
+ * Static attribute for builder class.
+ */
+ public static final String BUILDER_CLASS = "builder class";
+
+ /**
+ * Static attribute for builder interface.
+ */
+ public static final String BUILDER_INTERFACE = "builder interface";
+
+ /**
+ * Static attribute for binary.
+ */
+ public static final String BINARY = "binary";
+
+ /**
+ * Static attribute for bits.
+ */
+ public static final String BITS = "bits";
+
+ /**
+ * Static attribute for YANG.
+ */
+ public static final String YANG = "yang";
+
+ // No instantiation.
private UtilConstants() {
}
+
+ /**
+ * Represents operation type.
+ */
+ public enum Operation {
+ /**
+ * Represents add operation.
+ */
+ ADD,
+
+ /**
+ * Represents remove operation.
+ */
+ REMOVE
+ }
}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
index 1b58c0f..1f75ab8 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
@@ -147,4 +147,23 @@
}
}
}
+
+ /**
+ * Closes the file handle for temporary file with file deletion.
+ *
+ * @param file file to be closed
+ * @throws IOException when failed to close the file handle
+ */
+ public static void closeFile(File file) throws IOException {
+
+ if (file != null) {
+ updateFileHandle(file, null, true);
+ boolean deleted = file.delete();
+ if (!deleted) {
+ throw new IOException("Failed to delete temporary file " +
+ file.getName());
+ }
+ }
+ }
+ // TODO follow coding guidelines in remaining of this file.
}