You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/09/03 11:46:29 UTC
[camel] 08/10: CAMEL-15478: Nicer enum constant names
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9b76d2556661384ce69fa8b55320c18d483d5a73
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Sep 3 11:56:08 2020 +0200
CAMEL-15478: Nicer enum constant names
---
.../camel/maven/ApiComponentGeneratorMojo.java | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
index 51f732c..9e72ba5 100644
--- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
+++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java
@@ -19,8 +19,10 @@ package org.apache.camel.maven;
import java.io.File;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
import java.util.regex.Matcher;
+import org.apache.camel.util.StringHelper;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -269,19 +271,11 @@ public class ApiComponentGeneratorMojo extends AbstractApiMethodBaseMojo {
if (enumValue == null || enumValue.isEmpty()) {
return "DEFAULT";
}
- StringBuilder builder = new StringBuilder();
- if (!Character.isJavaIdentifierStart(enumValue.charAt(0))) {
- builder.append('_');
- }
- for (char c : enumValue.toCharArray()) {
- char upperCase = Character.toUpperCase(c);
- if (!Character.isJavaIdentifierPart(upperCase)) {
- builder.append('_');
- } else {
- builder.append(upperCase);
- }
- }
- return builder.toString();
+ String value = StringHelper.camelCaseToDash(enumValue);
+ // replace dash with underscore and upper case
+ value = value.replace('-', '_');
+ value = value.toUpperCase(Locale.ENGLISH);
+ return value;
}
public static String getNullableOptionValues(String[] nullableOptions) {