1 package org.eclipse.emf.examples.jet.article2.model; 2 3 4 10 public class NameUtil 11 { 12 13 22 public static String uncapName(String name) 23 { 24 if (name.length() == 0) 25 { 26 return name; 27 } 28 return Character.toLowerCase(name.charAt(0)) + name.substring(1); 29 } 30 31 40 public static String capName(String name) 41 { 42 if (name.length() == 0) 43 { 44 return name; 45 } 46 return Character.toUpperCase(name.charAt(0)) + name.substring(1); 47 } 48 49 60 public static String constantToJavaClassName(String code) 61 { 62 StringBuffer result = new StringBuffer (); 63 64 boolean upperNext = true; 65 char[] chars = code.toCharArray(); 66 for (int i = 0; i < chars.length; i++) 67 { 68 char c = chars[i]; 69 70 boolean valid = (i == 0) ? Character.isJavaIdentifierStart(c) : Character.isJavaIdentifierPart(c); 71 72 if (!valid) 73 { 74 upperNext = true; 75 continue; 76 } 77 if (c == '_') 78 { 79 upperNext = true; 80 continue; 81 } 82 83 if (upperNext) 84 { 85 result.append(Character.toUpperCase(c)); 86 upperNext = false; 87 } 88 else 89 { 90 result.append(Character.toLowerCase(c)); 91 } 92 } 93 return result.toString(); 94 } 95 96 103 public static boolean isValidIdentifier(String name) 104 { 105 char[] chars = name.toCharArray(); 106 for (int i = 0; i < chars.length; i++) 107 { 108 char c = chars[i]; 109 110 boolean valid = (i == 0) ? Character.isJavaIdentifierStart(c) : Character.isJavaIdentifierPart(c); 111 112 if (!valid) 113 { 114 return false; 115 } 116 } 117 return true; 118 } 119 120 123 private NameUtil() 124 { 125 } 126 } | Popular Tags |