You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2014/10/13 09:50:13 UTC
svn commit: r1631307 - in /db/torque/torque4/trunk/torque-generator/src:
main/java/org/apache/torque/generator/processor/string/ConstantNameCreator.java
test/java/org/apache/torque/generator/processor/string/ConstantNameCreatorTest.java
Author: tfischer
Date: Mon Oct 13 07:50:12 2014
New Revision: 1631307
URL: http://svn.apache.org/r1631307
Log:
TORQUE-331 - consider some edge cases for constant name creation
Modified:
db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/ConstantNameCreator.java
db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/ConstantNameCreatorTest.java
Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/ConstantNameCreator.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/ConstantNameCreator.java?rev=1631307&r1=1631306&r2=1631307&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/ConstantNameCreator.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/processor/string/ConstantNameCreator.java Mon Oct 13 07:50:12 2014
@@ -24,6 +24,7 @@ package org.apache.torque.generator.proc
/**
* Creates the name of a constant from a string. All letters in the String are
* capitalized, and underscores (_) are used as separators per default.
+ * If the string is empty or starts with a number, an underscore(_) is prefixed to the constant name.
*/
public class ConstantNameCreator extends CharReplacer
{
@@ -66,7 +67,7 @@ public class ConstantNameCreator extends
* @param upperCaseSeparationPrefix the separator which is inserted
* between a lower case character and an upper case character.
*/
- public void setUpperCaseSeparationPrefix(String upperCaseSeparationPrefix)
+ public void setUpperCaseSeparationPrefix(final String upperCaseSeparationPrefix)
{
this.upperCaseSeparationPrefix = upperCaseSeparationPrefix;
}
@@ -77,7 +78,10 @@ public class ConstantNameCreator extends
* special characters are treated as one.
* Inserts <code>UPPER_CASE_SEPPARATION_PREFIX</code> if an upper case
* character follows a lower case character, and converts all charcters
- * to upper case. Finally, the new String is returned.
+ * to upper case.
+ * If the string starts is empty or start with a number, the character <code>toReplaceWith</code>
+ * is prefixed to the constant name.
+ * Finally, the new String is returned.
* <br/>
* Example: "prOceSS-*+ing~#._Test" is converted to "PR_OCE_SS_ING_TEST"
*
@@ -85,7 +89,8 @@ public class ConstantNameCreator extends
*
* @return the processed String, not null.
*/
- public String process(String toProcess)
+ @Override
+ public String process(final String toProcess)
{
StringBuilder result = new StringBuilder();
String toReplace = getToReplace();
@@ -128,6 +133,10 @@ public class ConstantNameCreator extends
}
lastCharWasSpecial = specialChar;
}
+ if (result.length() == 0 || (result.charAt(0) >= '0' && result.charAt(0) <= '9'))
+ {
+ result.insert(0, toReplaceWith);
+ }
return result.toString();
}
}
Modified: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/ConstantNameCreatorTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/ConstantNameCreatorTest.java?rev=1631307&r1=1631306&r2=1631307&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/ConstantNameCreatorTest.java (original)
+++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/processor/string/ConstantNameCreatorTest.java Mon Oct 13 07:50:12 2014
@@ -21,8 +21,6 @@ package org.apache.torque.generator.proc
import static org.junit.Assert.assertEquals;
-
-import org.apache.torque.generator.processor.string.ConstantNameCreator;
import org.junit.Before;
import org.junit.Test;
@@ -49,4 +47,18 @@ public class ConstantNameCreatorTest
String result = constantNameCreator.process("Process");
assertEquals("PROCESS", result);
}
+
+ @Test
+ public void testFirstCharacterNumber()
+ {
+ String result = constantNameCreator.process("1Process");
+ assertEquals("_1_PROCESS", result);
+ }
+
+ @Test
+ public void testEmpty()
+ {
+ String result = constantNameCreator.process("");
+ assertEquals("_", result);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org