diff options
author | Sundong Ahn <sundongahn@google.com> | 2019-02-19 17:39:12 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-02-19 17:39:12 -0800 |
commit | 301e8b757c6b126371bb2199ca774108f0ee7570 (patch) | |
tree | 0ebc15e7089e0adabcce95a55bb08dc47e8d8ff4 | |
parent | 27a15c4693a1dc8589c95436216944b17b760b0c (diff) | |
parent | b18df6742b0b4f29ad90f7ede40de5d23aed89a3 (diff) | |
download | xsdc-301e8b757c6b126371bb2199ca774108f0ee7570.tar.gz |
Change naming rule am: a061e31ec9
am: b18df6742b
Change-Id: Ic42fd541ea99cf4cf2d3f4c30f9430bfac85e8b1
-rw-r--r-- | src/com/android/xsdc/cpp/Utils.java | 15 | ||||
-rw-r--r-- | src/com/android/xsdc/java/Utils.java | 15 | ||||
-rw-r--r-- | tests/main.cpp | 4 | ||||
-rw-r--r-- | tests/resources/simple_type/api/current.txt | 10 |
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; } |