Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Davis2012-09-18 20:11:34 +0000
committerMatthew Davis2012-09-18 20:11:34 +0000
commit0a54d711ce054845d2a403038d29985b4c405e1a (patch)
tree3b1a6ff6fac6c4d17826c68118471d505ff8c597
parentd919cdec785892b73e0f3a3898afd2a93e2c5966 (diff)
downloadorg.eclipse.stem-0a54d711ce054845d2a403038d29985b4c405e1a.tar.gz
org.eclipse.stem-0a54d711ce054845d2a403038d29985b4c405e1a.tar.xz
org.eclipse.stem-0a54d711ce054845d2a403038d29985b4c405e1a.zip
Relocating method bodies from one static class to another
git-svn-id: http://dev.eclipse.org/svnroot/technology/org.eclipse.stem/trunk@3403 92a21009-5b66-0410-b83a-dc787c41c6e9
-rw-r--r--developer_tools/modelgen/org.eclipse.stem.model.codegen/src/org/eclipse/stem/model/codegen/GeneratorUtils.java124
-rw-r--r--developer_tools/modelgen/org.eclipse.stem.model.ui/src/org/eclipse/stem/model/ui/wizards/WizardHelper.java126
2 files changed, 144 insertions, 106 deletions
diff --git a/developer_tools/modelgen/org.eclipse.stem.model.codegen/src/org/eclipse/stem/model/codegen/GeneratorUtils.java b/developer_tools/modelgen/org.eclipse.stem.model.codegen/src/org/eclipse/stem/model/codegen/GeneratorUtils.java
index 16ad77331..7c63fccbf 100644
--- a/developer_tools/modelgen/org.eclipse.stem.model.codegen/src/org/eclipse/stem/model/codegen/GeneratorUtils.java
+++ b/developer_tools/modelgen/org.eclipse.stem.model.codegen/src/org/eclipse/stem/model/codegen/GeneratorUtils.java
@@ -365,4 +365,128 @@ public class GeneratorUtils {
}
return sb.toString();
}
+
+ /**
+ * Formats a string to camel case
+ * @param str
+ * @return
+ */
+ public static String formatToCamelCase(String str)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ if (str.length() > 0) {
+
+ boolean nextIsLC = true;
+ boolean nextIsUC = false;
+ for (int idx=0; idx<str.length(); idx++) {
+ int cp = str.codePointAt(idx);
+ if (Character.isJavaIdentifierPart(cp)) {
+ if (nextIsLC) {
+ sb.appendCodePoint(Character.toLowerCase(cp));
+ nextIsLC = false;
+ } else if (nextIsUC) {
+ sb.appendCodePoint(Character.toUpperCase(cp));
+ nextIsUC = false;
+ } else {
+ sb.appendCodePoint(cp);
+ }
+ } else {
+ if (!nextIsLC) {
+ nextIsUC = true;
+ }
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Formats a string to upper case words with no spaces.
+ * Example: This is a test => ThisIsATest
+ * @param str
+ * @return
+ */
+ public static String formatToUpperCaseWordsNoSpaces(String str)
+ {
+ str = formatToCamelCase(str);
+
+ StringBuilder sb = new StringBuilder();
+ if (str.length() > 0) {
+ sb.appendCodePoint(Character.toUpperCase(str.codePointAt(0)));
+ sb.append(str.substring(1));
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Formats a string to a valid Java package name
+ * @param str String to format
+ * @return A formatted, valid Java package name
+ */
+ public static String formatToJavaPackageName(String str)
+ {
+ boolean firstWhiteSpace = true;
+
+ str = str.trim();
+
+ StringBuilder sb = new StringBuilder();
+ if (str != null) {
+ for (int idx=0; idx<str.length(); idx++) {
+ int c = str.codePointAt(idx);
+ if (Character.isWhitespace(c)) {
+ if (firstWhiteSpace) {
+ sb.append('.');
+ firstWhiteSpace = false;
+ }
+ } else if (c == '.' || Character.isJavaIdentifierPart(c)) {
+ sb.appendCodePoint(c);
+ firstWhiteSpace = true;
+ }
+ }
+ }
+
+ return sb.toString().toLowerCase();
+ }
+
+ /**
+ * Checks whether the string is a valid Java package name / identifer
+ * @param str String to validate
+ * @return Whether the string is a valid Java package name
+ */
+ public static boolean isValidJavaPackageName(String str)
+ {
+ boolean valid = false;
+ for (String token : str.split("\\.")) {
+ if (isValidJavaName(token)) {
+ valid = true;
+ } else {
+ valid = false;
+ break;
+ }
+ }
+ return valid;
+ }
+
+ /**
+ * Checks whether the string is a valid Java identifier
+ * @param str String to validate
+ * @return Whether the string is a valid Java identifier
+ */
+ public static boolean isValidJavaName(String str)
+ {
+ boolean valid = false;
+ if (str.length() > 0) {
+ valid = Character.isJavaIdentifierStart(str.codePointAt(0));
+ for (int idx=1; valid && idx<str.length(); idx++) {
+ valid = Character.isJavaIdentifierPart(str.codePointAt(idx));
+ if (!valid) {
+ break;
+ }
+ }
+ }
+ return valid;
+ }
} \ No newline at end of file
diff --git a/developer_tools/modelgen/org.eclipse.stem.model.ui/src/org/eclipse/stem/model/ui/wizards/WizardHelper.java b/developer_tools/modelgen/org.eclipse.stem.model.ui/src/org/eclipse/stem/model/ui/wizards/WizardHelper.java
index c0bcfd254..3b59953df 100644
--- a/developer_tools/modelgen/org.eclipse.stem.model.ui/src/org/eclipse/stem/model/ui/wizards/WizardHelper.java
+++ b/developer_tools/modelgen/org.eclipse.stem.model.ui/src/org/eclipse/stem/model/ui/wizards/WizardHelper.java
@@ -41,6 +41,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.window.Window;
+import org.eclipse.stem.model.codegen.GeneratorUtils;
import org.eclipse.stem.model.codegen.ModelGeneratorDescriptors;
import org.eclipse.stem.model.codegen.descriptor.ModelGeneratorDescriptor;
import org.eclipse.stem.model.metamodel.Compartment;
@@ -583,134 +584,47 @@ public class WizardHelper {
return getAllCompartmentsForGroup(model.getCompartments());
}
- public static String formatToCapWords(String str) {
- StringBuilder sb = new StringBuilder();
- if (str.length() > 0) {
- sb.appendCodePoint(Character.toUpperCase(str.codePointAt(0)));
- for (int idx = 1; idx < str.length(); idx++) {
- int cp = str.codePointAt(idx);
-
- if (Character.isUpperCase(cp)
- && (Character.isLowerCase(str.codePointAt(idx - 1)) || (str
- .length() > idx + 1 && Character
- .isLowerCase(str.codePointAt(idx + 1))))) {
- sb.append(' ');
- }
-
- sb.appendCodePoint(cp);
+ public static String getFirstMatchingModelName(Package pkg)
+ {
+ List<String> modelNames = new ArrayList<String>();
+ for (Model m : pkg.getModels()) {
+ String name = m.getName();
+ if (modelNames.contains(name)) {
+ return name;
}
+ modelNames.add(name);
}
- return sb.toString();
+ return null;
+ }
+
+ public static String formatToCapWords(String str) {
+ return GeneratorUtils.formatToCapWords(str);
}
public static String formatToCamelCase(String str)
{
- StringBuilder sb = new StringBuilder();
-
- if (str.length() > 0) {
-
- boolean nextIsLC = true;
- boolean nextIsUC = false;
- for (int idx=0; idx<str.length(); idx++) {
- int cp = str.codePointAt(idx);
- if (Character.isJavaIdentifierPart(cp)) {
- if (nextIsLC) {
- sb.appendCodePoint(Character.toLowerCase(cp));
- nextIsLC = false;
- } else if (nextIsUC) {
- sb.appendCodePoint(Character.toUpperCase(cp));
- nextIsUC = false;
- } else {
- sb.appendCodePoint(cp);
- }
- } else {
- if (!nextIsLC) {
- nextIsUC = true;
- }
- }
- }
- }
-
- return sb.toString();
+ return GeneratorUtils.formatToCamelCase(str);
}
public static String formatToUpperCaseWordsNoSpaces(String str)
{
- str = formatToCamelCase(str);
-
- StringBuilder sb = new StringBuilder();
- if (str.length() > 0) {
- sb.appendCodePoint(Character.toUpperCase(str.codePointAt(0)));
- sb.append(str.substring(1));
- }
-
- return sb.toString();
+ return GeneratorUtils.formatToUpperCaseWordsNoSpaces(str);
}
public static String formatToJavaPackageName(String str)
{
- boolean firstWhiteSpace = true;
-
- str = str.trim();
-
- StringBuilder sb = new StringBuilder();
- if (str != null) {
- for (int idx=0; idx<str.length(); idx++) {
- int c = str.codePointAt(idx);
- if (Character.isWhitespace(c)) {
- if (firstWhiteSpace) {
- sb.append('.');
- firstWhiteSpace = false;
- }
- } else if (c == '.' || Character.isJavaIdentifierPart(c)) {
- sb.appendCodePoint(c);
- firstWhiteSpace = true;
- }
- }
- }
-
- return sb.toString().toLowerCase();
+ return GeneratorUtils.formatToJavaPackageName(str);
}
public static boolean isValidJavaPackageName(String str)
{
- boolean valid = false;
- for (String token : str.split("\\.")) {
- if (isValidJavaName(token)) {
- valid = true;
- } else {
- valid = false;
- break;
- }
- }
- return valid;
+ return GeneratorUtils.isValidJavaPackageName(str);
}
public static boolean isValidJavaName(String str)
{
- boolean valid = false;
- if (str.length() > 0) {
- valid = Character.isJavaIdentifierStart(str.codePointAt(0));
- for (int idx=1; valid && idx<str.length(); idx++) {
- valid = Character.isJavaIdentifierPart(str.codePointAt(idx));
- if (!valid) {
- break;
- }
- }
- }
- return valid;
+ return GeneratorUtils.isValidJavaName(str);
}
- public static String getFirstMatchingModelName(Package pkg)
- {
- List<String> modelNames = new ArrayList<String>();
- for (Model m : pkg.getModels()) {
- String name = m.getName();
- if (modelNames.contains(name)) {
- return name;
- }
- modelNames.add(name);
- }
- return null;
- }
+
}

Back to the top