Skip to content

Commit

Permalink
Support colon in field names (#56)
Browse files Browse the repository at this point in the history
Support colon in field name
  • Loading branch information
frodrigo committed Dec 31, 2022
1 parent c662ef2 commit 614d9f3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/openmaptiles/Generate.java
Expand Up @@ -269,7 +269,7 @@ private static String generateCodeForLayer(String tag, LayerConfig layer) {
*/
""".stripTrailing().formatted(javadocDescription,
valuesForComment.stream().map(v -> "<li>" + v).collect(joining(LINE_SEPARATOR + " * "))),
name.toUpperCase(Locale.ROOT),
name.toUpperCase(Locale.ROOT).replace(":", "__"),
Format.quote(name)
).indent(4));

Expand All @@ -280,12 +280,14 @@ private static String generateCodeForLayer(String tag, LayerConfig layer) {
if (values.size() > 0) {
fieldValues.append(values.stream()
.map(v -> "public static final String %s = %s;"
.formatted(name.toUpperCase(Locale.ROOT) + "_" + v.toUpperCase(Locale.ROOT).replace('-', '_'),
.formatted(
name.toUpperCase(Locale.ROOT).replace(":", "__") + "_" +
v.toUpperCase(Locale.ROOT).replace('-', '_').replace(":", "__"),
Format.quote(v)))
.collect(joining(LINE_SEPARATOR)).indent(2).strip()
.indent(4));
fieldValues.append("public static final Set<String> %s = Set.of(%s);".formatted(
name.toUpperCase(Locale.ROOT) + "_VALUES",
name.toUpperCase(Locale.ROOT).replace(":", "__") + "_VALUES",
values.stream().map(Format::quote).collect(joining(", "))
).indent(4));
}
Expand Down Expand Up @@ -657,11 +659,11 @@ private static String generateJavaCode(MultiExpression<String> mapping) {
}

private static String lowerUnderscoreToLowerCamel(String name) {
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name.replace(":", "__"));
}

private static String lowerUnderscoreToUpperCamel(String name) {
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name);
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name.replace(":", "__"));
}

private static <T> List<T> iterToList(Iterator<T> iter) {
Expand Down

0 comments on commit 614d9f3

Please sign in to comment.