|
From: <caw...@us...> - 2007-04-04 15:30:25
|
Revision: 2275
http://svn.sourceforge.net/rubyeclipse/?rev=2275&view=rev
Author: cawilliams
Date: 2007-04-04 08:30:23 -0700 (Wed, 04 Apr 2007)
Log Message:
-----------
when creating a new type convert the CamelCase constant for the type name to an under_score_file_name.rb
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java 2007-04-04 15:01:25 UTC (rev 2274)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java 2007-04-04 15:30:23 UTC (rev 2275)
@@ -518,17 +518,34 @@
/**
* Hook method that is called when evaluating the name of the compilation unit to create. By default, a file extension
- * <code>java</code> is added to the given type name, but implementors can override this behavior.
+ * <code>rb</code> is added to the given type name, but implementors can override this behavior.
*
* @param typeName the name of the type to create the compilation unit for.
* @return the name of the compilation unit to be created for the given name
*
- * @since 3.2
+ * @since 0.9.0
*/
protected String getRubyScriptName(String typeName) {
- return typeName + RubyModelUtil.DEFAULT_SCRIPT_SUFFIX;
+ return convertCamelCaseToUnderscore(typeName) + RubyModelUtil.DEFAULT_SCRIPT_SUFFIX;
}
+ private String convertCamelCaseToUnderscore(String name) {
+ StringBuffer newName = new StringBuffer();
+ boolean lastWasUpper = false;
+ for (int i = 0; i < name.length(); i++) {
+ char c = name.charAt(i);
+ newName.append(Character.toLowerCase(c));
+ if (lastWasUpper && Character.isLowerCase(c)) {
+ if (newName.length() > 2) newName.insert(newName.length() - 2, "_");
+ lastWasUpper = false;
+ }
+ if (Character.isUpperCase(c)) {
+ lastWasUpper = true;
+ }
+ }
+ return newName.toString();
+ }
+
/**
* Returns the package fragment corresponding to the current input.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|