summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostiantyn Sologubov <ksologubov@luxoft.com>2020-03-10 17:25:14 +0200
committerKostiantyn Sologubov <ksologubov@luxoft.com>2020-03-10 17:25:14 +0200
commitacf387b708b45fead6450f1327c94071ef6b658c (patch)
treecb8d68f88099a05c5588e8bef0bdcda52319c61f
parent60bc014eda6b91774f510c2d7917251ddacb88e1 (diff)
downloadsdl_android-acf387b708b45fead6450f1327c94071ef6b658c.tar.gz
readme changes for simplified enums and removed mappings
-rw-r--r--utils/generator/README.md215
1 files changed, 102 insertions, 113 deletions
diff --git a/utils/generator/README.md b/utils/generator/README.md
index 8ef29085a..dea372b6d 100644
--- a/utils/generator/README.md
+++ b/utils/generator/README.md
@@ -169,6 +169,8 @@ The set of `<element>` should be mapped to the set of Enum constants. Based on t
The following list are general rules for constant names and its fields:
1. The `"name"` attribute of `<element>` is the default name of the constant.
+ * if the name starts from digit, the leading `_` (underscore) symbol should be added.
+ * if the name starts with `_` (underscore) symbol and the next character is a letter of alphabet, the leading `_` (underscore) symbol should be removed.
1. Uses of the "sync" prefix shall be replaced with "sdl" (where it would not break functionality). E.g. `SyncMsgVersion -> SdlMsgVersion`. This applies to member variables and their accessors. The key used when creating the RPC message JSON should match that of the RPC Spec.
The constant definition could have the next JavaDoc comment:
@@ -187,7 +189,7 @@ Where:
The constant definition should have the `@Deprecated` decorator if the `"deprecated"` attribute exists and is "true".
-### Constants without fields:
+### Constants without field:
This type of enums doesn't require constructor and requires additional method `valueForString` to be defined. It should return the Enum constant based on its string name, or `null` if the constant is not found.
```java
@@ -278,7 +280,6 @@ package com.smartdevicelink.proxy.rpc.enums;
/**
* The different global properties.
*
- *
* @since SmartDeviceLink 1.0.0
*/
public enum GlobalProperty {
@@ -346,62 +347,56 @@ public enum GlobalProperty {
}
}
```
-### Constants with fields
-
-This type of enums is divided into 3 additional types:
-* field based on `"internal_name"` and `"name"` attributes of `<element>`
-* field based on `"value"` attribute of `<element>`
-#### Constants with field based on `"internal_name"` and `"name"` attributes
+### Constants with field based on `"value"` attribute
-In case if the `"internal_name"` attribute exists, this should be used for the constant name and the `"name"` attribute should be passed as a `String` field into Enum constant.
+This type of enums has field based on `"value"` attribute of `<element>`. In case if the `"value"` attribute exists, this attribute should be passed as the `int` or `String` constant field.
-The `"internal_name"` attribute should be normalized by following rules:
-* If it starts with the same prefix as `<enum>` name, this prefix should be removed.
-* After the prefix removal:
- * if the value starts from digit, the leading `_` (underscore) symbol should be added.
- * if the value starts with `_` (underscore) symbol and the next character is a letter of alphabet, the leading `_` (underscore) symbol should be removed.
+#### Constants with `int` value type
Constant definition:
```java
- [internal_name]("[name]")
+ [name]([value])
```
-Where `[internal_name]` is the normalized `"internal_name"` attribute of `<element>`, `[name]` is the `"name"` attribute.
+Where `[name]` is the `"name"` attribute of `<element>`, `[value]` is the `"value"` attribute.
Private field:
```java
- private final String VALUE;
+ private final int VALUE;
```
The private constructor should be defined to accept the value from the constant and and set the private field.
```java
- private [enum_name](String value) {
+ /**
+ * Private constructor
+ */
+ private [enum_name](int value) {
this.VALUE = value;
}
```
Where `[enum_name]` is the `"name"` attribute of `<enum>`.
-The `toString` method should be overridden to return the private field instead of the constant name.
+The `getValue` method should be defined to return the private field value.
```java
- @Override
- public String toString() {
+ /**
+ * Return value of element
+ *
+ * @return int
+ */
+ public int getValue(){
return VALUE;
}
```
-The additional `valueForString` should be defined. It should return the Enum constant based on the private field above, or `null` if the constant is not found.
+The additional `valueForInt` should be defined. It should return the Enum constant based on the private field above, or `null` if the constant is not found.
```java
/**
- * Convert String to [enum_name]
+ * Convert int to {{class_name}}
*
- * @param value String
- * @return [enum_name]
+ * @param value int
+ * @return {{class_name}}
*/
- public static [enum_name] valueForString(String value) {
- if (value == null) {
- return null;
- }
-
+ public static [enum_name] valueForInt(int value) {
for ([enum_name] anEnum : EnumSet.allOf([enum_name].class)) {
if (anEnum.toString().equals(value)) {
return anEnum;
@@ -412,7 +407,7 @@ The additional `valueForString` should be defined. It should return the Enum con
```
Where `[enum_name]` is the `"name"` attribute of `<enum>`.
-The `valueForString` method requires the import of `EnumSet` collection:
+The `valueForInt` method requires the import of `EnumSet` collection:
```java
import java.util.EnumSet;
```
@@ -421,16 +416,12 @@ Full example:
XML:
```xml
- <enum name="Dimension" since="2.0">
- <description>The supported dimensions of the GPS</description>
- <element name="NO_FIX" internal_name="Dimension_NO_FIX">
- <description>No GPS at all</description>
- </element>
- <element name="2D" internal_name="Dimension_2D">
- <description>Longitude and latitude</description>
+ <enum name="PredefinedWindows" since="6.0">
+ <element name="DEFAULT_WINDOW" value="0">
+ <description>The default window is a main window pre-created on behalf of the app.</description>
</element>
- <element name="3D" internal_name="Dimension_3D">
- <description>Longitude and latitude and altitude</description>
+ <element name="PRIMARY_WIDGET" value="1">
+ <description>The primary widget of the app.</description>
</element>
</enum>
```
@@ -473,47 +464,36 @@ package com.smartdevicelink.proxy.rpc.enums;
import java.util.EnumSet;
/**
- * The supported dimensions of the GPS
- *
- *
- * @since SmartDeviceLink 2.0.0
+ * @since SmartDeviceLink 6.0.0
*/
-public enum Dimension {
- /**
- * Longitude and latitude
- */
- _2D("2D"),
+public enum PredefinedWindows {
/**
- * Longitude and latitude and altitude
+ * The default window is a main window pre-created on behalf of the app.
*/
- _3D("3D"),
+ DEFAULT_WINDOW(0),
/**
- * No GPS at all
+ * The primary widget of the app.
*/
- NO_FIX("NO_FIX");
+ PRIMARY_WIDGET(1);
- private final String VALUE;
+ private final int VALUE;
/**
* Private constructor
*/
- private Dimension(String value) {
+ private PredefinedWindows (int value) {
this.VALUE = value;
}
/**
- * Convert String to Dimension
+ * Convert int to PredefinedWindows
*
- * @param value String
- * @return Dimension
+ * @param value int
+ * @return PredefinedWindows
*/
- public static Dimension valueForString(String value) {
- if (value == null) {
- return null;
- }
-
- for (Dimension anEnum : EnumSet.allOf(Dimension.class)) {
- if (anEnum.toString().equals(value)) {
+ public static PredefinedWindows valueForInt(int value) {
+ for (PredefinedWindows anEnum : EnumSet.allOf(PredefinedWindows.class)) {
+ if (anEnum.getValue() == value) {
return anEnum;
}
}
@@ -521,64 +501,58 @@ public enum Dimension {
}
/**
- * Return String value of element
+ * Return value of element
*
- * @return String
+ * @return int
*/
- @Override
- public String toString() {
+ public int getValue(){
return VALUE;
}
}
```
-#### Constants with field based on `"value"` attribute
-
-In case if the `"value"` attribute exists, this attribute should be passed as the `int` constant field.
+#### Constants with `String` value type
Constant definition:
```java
- [name]([value])
+ [name]("[value]")
```
Where `[name]` is the `"name"` attribute of `<element>`, `[value]` is the `"value"` attribute.
Private field:
```java
- private final int VALUE;
+ private final String VALUE;
```
The private constructor should be defined to accept the value from the constant and and set the private field.
```java
- /**
- * Private constructor
- */
- private [enum_name](int value) {
+ private [enum_name](String value) {
this.VALUE = value;
}
```
Where `[enum_name]` is the `"name"` attribute of `<enum>`.
-The `getValue` method should be defined to return the private field value.
+The `toString` method should be overridden to return the private field instead of the constant name.
```java
- /**
- * Return value of element
- *
- * @return int
- */
- public int getValue(){
+ @Override
+ public String toString() {
return VALUE;
}
```
-The additional `valueForInt` should be defined. It should return the Enum constant based on the private field above, or `null` if the constant is not found.
+The additional `valueForString` should be defined. It should return the Enum constant based on the private field above, or `null` if the constant is not found.
```java
/**
- * Convert int to {{class_name}}
+ * Convert String to [enum_name]
*
- * @param value int
- * @return {{class_name}}
+ * @param value String
+ * @return [enum_name]
*/
- public static [enum_name] valueForInt(int value) {
+ public static [enum_name] valueForString(String value) {
+ if (value == null) {
+ return null;
+ }
+
for ([enum_name] anEnum : EnumSet.allOf([enum_name].class)) {
if (anEnum.toString().equals(value)) {
return anEnum;
@@ -589,7 +563,7 @@ The additional `valueForInt` should be defined. It should return the Enum consta
```
Where `[enum_name]` is the `"name"` attribute of `<enum>`.
-The `valueForInt` method requires the import of `EnumSet` collection:
+The `valueForString` method requires the import of `EnumSet` collection:
```java
import java.util.EnumSet;
```
@@ -598,12 +572,16 @@ Full example:
XML:
```xml
- <enum name="PredefinedWindows" since="6.0">
- <element name="DEFAULT_WINDOW" value="0">
- <description>The default window is a main window pre-created on behalf of the app.</description>
+ <enum name="Dimension" since="2.0">
+ <description>The supported dimensions of the GPS</description>
+ <element name="NO_FIX" internal_name="Dimension_NO_FIX">
+ <description>No GPS at all</description>
</element>
- <element name="PRIMARY_WIDGET" value="1">
- <description>The primary widget of the app.</description>
+ <element name="2D" internal_name="Dimension_2D">
+ <description>Longitude and latitude</description>
+ </element>
+ <element name="3D" internal_name="Dimension_3D">
+ <description>Longitude and latitude and altitude</description>
</element>
</enum>
```
@@ -646,36 +624,46 @@ package com.smartdevicelink.proxy.rpc.enums;
import java.util.EnumSet;
/**
+ * The supported dimensions of the GPS
*
- * @since SmartDeviceLink 6.0.0
+ * @since SmartDeviceLink 2.0.0
*/
-public enum PredefinedWindows {
+public enum Dimension {
/**
- * The default window is a main window pre-created on behalf of the app.
+ * No GPS at all
*/
- DEFAULT_WINDOW(0),
+ NO_FIX("NO_FIX"),
/**
- * The primary widget of the app.
+ * Longitude and latitude
*/
- PRIMARY_WIDGET(1);
+ _2D("2D"),
+ /**
+ * Longitude and latitude and altitude
+ */
+ _3D("3D");
+
+ private final String VALUE;
- private final int VALUE;
/**
* Private constructor
*/
- private PredefinedWindows (int value) {
+ private Dimension(String value) {
this.VALUE = value;
}
/**
- * Convert int to PredefinedWindows
+ * Convert String to Dimension
*
- * @param value int
- * @return PredefinedWindows
+ * @param value String
+ * @return Dimension
*/
- public static PredefinedWindows valueForInt(int value) {
- for (PredefinedWindows anEnum : EnumSet.allOf(PredefinedWindows.class)) {
- if (anEnum.getValue() == value) {
+ public static Dimension valueForString(String value) {
+ if (value == null) {
+ return null;
+ }
+
+ for (Dimension anEnum : EnumSet.allOf(Dimension.class)) {
+ if (anEnum.toString().equals(value)) {
return anEnum;
}
}
@@ -683,11 +671,12 @@ public enum PredefinedWindows {
}
/**
- * Return value of element
+ * Return String value of element
*
- * @return int
+ * @return String
*/
- public int getValue(){
+ @Override
+ public String toString() {
return VALUE;
}
}