aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-02-17 04:17:19 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-02-17 04:17:19 +0000
commita87ad8bdd93a5c0220edf6ca87c4bb7ad25137a2 (patch)
tree0ebc15e7089e0adabcce95a55bb08dc47e8d8ff4
parente5da3290351ac1024b7e067b76657c24268f5050 (diff)
parentcdc7449a32847f388778c5f2b672861a12d6cc3f (diff)
downloadxsdc-a87ad8bdd93a5c0220edf6ca87c4bb7ad25137a2.tar.gz
Snap for 5316819 from cdc7449a32847f388778c5f2b672861a12d6cc3f to qt-release
Change-Id: I7506c4e1a5f3c026fe4a60d3317764f308dfd2aa
-rw-r--r--src/com/android/xsdc/cpp/Utils.java15
-rw-r--r--src/com/android/xsdc/java/Utils.java15
-rw-r--r--tests/main.cpp4
-rw-r--r--tests/resources/simple_type/api/current.txt10
4 files changed, 29 insertions, 15 deletions
diff --git a/src/com/android/xsdc/cpp/Utils.java b/src/com/android/xsdc/cpp/Utils.java
index 8294f00..b76a835 100644
--- a/src/com/android/xsdc/cpp/Utils.java
+++ b/src/com/android/xsdc/cpp/Utils.java
@@ -36,6 +36,14 @@ class Utils {
};
private static final HashSet<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
+ private static String toCamelCase(String[] words) {
+ String res = words[0];
+ for (int idx = 1; idx < words.length; ++idx) {
+ res += capitalize(words[idx]);
+ }
+ return res;
+ }
+
static String capitalize(String input) {
return input.substring(0, 1).toUpperCase() + input.substring(1);
}
@@ -45,8 +53,7 @@ class Utils {
}
static String toVariableName(String name) throws CppCodeGeneratorException {
- // remove non-alphanumeric and non-underscore characters
- String trimmed = name.replaceAll("[^A-Za-z0-9_]", "");
+ String trimmed = toCamelCase(name.replaceAll("[^A-Za-z0-9_-]", "").split("-"));
if (trimmed.isEmpty()) {
throw new CppCodeGeneratorException(
String.format("cannot convert to a variable name : %s", name));
@@ -58,8 +65,8 @@ class Utils {
}
static String toClassName(String name) throws CppCodeGeneratorException {
- // remove non-alphanumeric characters
- String trimmed = name.replaceAll("[^A-Za-z0-9]", "");
+ String trimmed = toCamelCase(
+ name.replaceAll("[^A-Za-z0-9_-]", "").replaceAll("-","_").split("_"));
if (trimmed.isEmpty() || Character.isDigit(trimmed.charAt(0))) {
throw new CppCodeGeneratorException(
String.format("cannot convert to a class name : %s", name));
diff --git a/src/com/android/xsdc/java/Utils.java b/src/com/android/xsdc/java/Utils.java
index 7331d38..673f0a3 100644
--- a/src/com/android/xsdc/java/Utils.java
+++ b/src/com/android/xsdc/java/Utils.java
@@ -33,6 +33,14 @@ class Utils {
};
private static final HashSet<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
+ private static String toCamelCase(String[] words) {
+ String res = words[0];
+ for (int idx = 1; idx < words.length; ++idx) {
+ res += capitalize(words[idx]);
+ }
+ return res;
+ }
+
static String capitalize(String input) {
return input.substring(0, 1).toUpperCase() + input.substring(1);
}
@@ -42,8 +50,7 @@ class Utils {
}
static String toVariableName(String name) throws JavaCodeGeneratorException {
- // remove non-alphanumeric and non-underscore characters
- String trimmed = name.replaceAll("[^A-Za-z0-9_]", "");
+ String trimmed = toCamelCase(name.replaceAll("[^A-Za-z0-9_-]", "").split("-"));
if (trimmed.isEmpty()) {
throw new JavaCodeGeneratorException(
String.format("cannot convert to a variable name : %s", name));
@@ -55,8 +62,8 @@ class Utils {
}
static String toClassName(String name) throws JavaCodeGeneratorException {
- // remove non-alphanumeric characters
- String trimmed = name.replaceAll("[^A-Za-z0-9]", "");
+ String trimmed = toCamelCase(
+ name.replaceAll("[^A-Za-z0-9_-]", "").replaceAll("-","_").split("_"));
if (trimmed.isEmpty() || Character.isDigit(trimmed.charAt(0))) {
throw new JavaCodeGeneratorException(
String.format("cannot convert to a class name : %s", name));
diff --git a/tests/main.cpp b/tests/main.cpp
index cd07467..75e1d7a 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -38,12 +38,12 @@ public:
TEST_F(XmlTest, Simpletype) {
using namespace simple::type;
string file_name = "resources/simple_type.xml";
- Simpletypes simple = read(file_name.c_str())[0];
+ SimpleTypes simple = read(file_name.c_str())[0];
for (int i = 0; i < simple.getListInt().size(); ++i) {
EXPECT_EQ(simple.getListInt()[i], i + 1);
}
- EXPECT_EQ(simple.getUniontest()[0], "100");
+ EXPECT_EQ(simple.getUnionTest()[0], "100");
EXPECT_EQ(simple.getYesOrNo(), EnumType::YES);
}
diff --git a/tests/resources/simple_type/api/current.txt b/tests/resources/simple_type/api/current.txt
index ee89a7d..19c5e12 100644
--- a/tests/resources/simple_type/api/current.txt
+++ b/tests/resources/simple_type/api/current.txt
@@ -7,19 +7,19 @@ package simple.type {
enum_constant public static final simple.type.EnumType YES;
}
- public class Simpletypes {
- ctor public Simpletypes();
+ public class SimpleTypes {
+ ctor public SimpleTypes();
method public java.util.List<java.lang.Integer> getListInt();
- method public java.util.List<java.lang.String> getUniontest();
+ method public java.util.List<java.lang.String> getUnionTest();
method public simple.type.EnumType getYesOrNo();
method public void setListInt(java.util.List<java.lang.Integer>);
- method public void setUniontest(java.util.List<java.lang.String>);
+ method public void setUnionTest(java.util.List<java.lang.String>);
method public void setYesOrNo(simple.type.EnumType);
}
public class XmlParser {
ctor public XmlParser();
- method public static simple.type.Simpletypes read(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException;
+ method public static simple.type.SimpleTypes read(java.io.InputStream) throws javax.xml.datatype.DatatypeConfigurationException, java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public static String readText(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
method public static void skip(org.xmlpull.v1.XmlPullParser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
}