List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:com.google.dart.engine.services.refactoring.NamingConventions.java
/** * Validate the given identifier, which should be upper camel case. */// w w w.ja v a2 s. com private static RefactoringStatus validateUpperCamelCase(String identifier, String elementName) { // null if (identifier == null) { String message = MessageFormat.format("{0} name must not be null.", elementName); return RefactoringStatus.createErrorStatus(message); } // is not identifier RefactoringStatus status = validateIdentifier(identifier, elementName); if (!status.isOK()) { return status; } // is private, OK if (identifier.charAt(0) == '_') { return new RefactoringStatus(); } // does not start with upper case if (!Character.isUpperCase(identifier.charAt(0))) { // By convention, class names usually start with an uppercase letter String message = MessageFormat.format("{0} name should start with an uppercase letter.", elementName); return RefactoringStatus.createWarningStatus(message); } // OK return new RefactoringStatus(); }
From source file:de.aschoerk.javaconv.RustDumpVisitor.java
private String toSnakeIfNecessary(String n) { if (namesMap.containsKey(n)) { n = namesMap.get(n);/* ww w . j av a 2s.c o m*/ } String name = n; if (Character.isLowerCase(name.charAt(0))) { StringBuilder sb = new StringBuilder(); for (Character c : name.toCharArray()) { if (Character.isUpperCase(c)) { sb.append("_").append(Character.toLowerCase(c)); } else { sb.append(c); } } return sb.toString(); } return n; }
From source file:com.webcohesion.enunciate.modules.ruby_json_client.RubyJSONClientModule.java
protected boolean usesUnmappableElements() { boolean usesUnmappableElements = false; if (this.jacksonModule != null && this.jacksonModule.getJacksonContext() != null) { for (TypeDefinition complexType : this.jacksonModule.getJacksonContext().getTypeDefinitions()) { if (!Character.isUpperCase(complexType.getClientSimpleName().charAt(0))) { warn("%s: Ruby requires your class name to be upper-case. Please rename the class or apply the @org.codehaus.enunciate.ClientName annotation to the class.", positionOf(complexType)); usesUnmappableElements = true; }/* w w w.j av a 2 s . c o m*/ } } if (this.jackson1Module != null && this.jackson1Module.getJacksonContext() != null) { for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition complexType : this.jackson1Module .getJacksonContext().getTypeDefinitions()) { if (!Character.isUpperCase(complexType.getClientSimpleName().charAt(0))) { warn("%s: Ruby requires your class name to be upper-case. Please rename the class or apply the @org.codehaus.enunciate.ClientName annotation to the class.", positionOf(complexType)); usesUnmappableElements = true; } } } return usesUnmappableElements; }
From source file:net.sourceforge.fenixedu.util.StringFormatter.java
/** * /* w w w . java 2 s . c o m*/ * @param string * @return */ public static String splitCamelCaseString(String string) { StringBuilder result = new StringBuilder(); boolean first = true; for (char c : string.toCharArray()) { if (first) { first = false; } else if (Character.isUpperCase(c)) { result.append(' '); } result.append(c); } return result.toString(); }
From source file:org.cafed00d.subtitle.WordProcessor.java
/** * Examines the first letter in words that are all lower case (except the * first letter). Looks for the patterns: * <ul>/*from w w w .j ava 2 s . c om*/ * <li>I<vowel> - converts to <i>L<vowel></i></li> * <li>l<consonant> - converts to <i>I<consonant></i></li> * </ul> * <p> * Note that this method must be called after {@link #fixMismatch()}. */ private void fixInitialLetter() { /* * Determine if this word is made up of all lower case characters except the * first character which is either an 'I' or an 'l'. */ char initialChar = line.charAt(first); if (getLength() > 1 && (initialChar == LOWER_l || initialChar == UPPER_I)) { boolean foundUpper = false; for (int inx = first + 1; inx < current; inx++) { char ch = line.charAt(inx); if (Character.isUpperCase(ch)) { log.trace("found upper " + ch + "@" + inx); foundUpper = true; break; } } if (!foundUpper) { /* * The word meets the general criteria, now examine the first two * letters to see if it matches the patterns and if so correct the first * letter. */ char secondChar = line.charAt(first + 1); log.trace("initialChar=" + initialChar); log.trace("secondChar=" + secondChar); if (initialChar == LOWER_l && isConsonant(secondChar)) { log.trace("fixing initial l"); convertToUpperI(first); } else if (initialChar == UPPER_I && isVowel(secondChar)) { log.trace("fixing initial I"); convertToLowerl(first); } } } }
From source file:org.codehaus.griffon.commons.GriffonClassUtils.java
/** * Returns the property name representation of the given name * * @param name The name to convert/*from w w w . java 2 s .co m*/ * @return The property name representation */ public static String getPropertyNameRepresentation(String name) { // Strip any package from the name. int pos = name.lastIndexOf('.'); if (pos != -1) { name = name.substring(pos + 1); } // Check whether the name begins with two upper case letters. if (name.length() > 1 && Character.isUpperCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) { return name; } else { String propertyName = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1); if (propertyName.indexOf(' ') > -1) { propertyName = propertyName.replaceAll("\\s", ""); } return propertyName; } }
From source file:net.sourceforge.pmd.lang.java.rule.codestyle.LinguisticNamingRule.java
private static boolean hasPrefix(String name, String prefix) { return name.startsWith(prefix) && name.length() > prefix.length() && Character.isUpperCase(name.charAt(prefix.length())); }
From source file:objenome.util.bytecode.SgUtils.java
/** * Inserts an underscore before every upper case character and returns an * all lower case string. If the first character is upper case an underscore * will not be inserted.//from ww w. j av a2 s. com * * @param str * String to convert. * * @return Lower case + underscored text. */ public static String uppercaseToUnderscore(String str) { if (str == null) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (Character.isUpperCase(ch)) { if (i > 0) { sb.append('_'); } sb.append(Character.toLowerCase(ch)); } else { sb.append(ch); } } return sb.toString(); }
From source file:com.netspective.sparx.util.xml.XmlSource.java
/** * Given a text string, return a string that would be suitable for that string to be used * as a Java identifier (as a variable or method name). Depending upon whether ucaseInitial * is set, the string starts out with a lowercase or uppercase letter. Then, the rule is * to convert all periods into underscores and title case any words separated by * underscores. This has the effect of removing all underscores and creating mixed case * words. For example, Person_Address becomes personAddress or PersonAddress depending upon * whether ucaseInitial is set to true or false. Person.Address would become Person_Address. *//*from ww w.ja va2s . c om*/ public static String xmlTextToJavaIdentifier(String xml, boolean ucaseInitial) { if (xml == null || xml.length() == 0) return xml; StringBuffer identifier = new StringBuffer(); char ch = xml.charAt(0); identifier.append(ucaseInitial ? Character.toUpperCase(ch) : Character.toLowerCase(ch)); boolean uCase = false; for (int i = 1; i < xml.length(); i++) { ch = xml.charAt(i); if (ch == '.') { identifier.append('_'); } else if (ch != '_' && Character.isJavaIdentifierPart(ch)) { identifier.append(Character.isUpperCase(ch) ? ch : (uCase ? Character.toUpperCase(ch) : Character.toLowerCase(ch))); uCase = false; } else uCase = true; } return identifier.toString(); }
From source file:org.apache.felix.webconsole.plugins.packageadmin.internal.WebConsolePlugin.java
static final Set/*<String>*/ getPackageNames(String findField) { StringTokenizer tok = new StringTokenizer(findField, " \t\n\f\r"); //$NON-NLS-1$ SortedSet/*<String>*/ result = new TreeSet/*<String>*/(); while (tok.hasMoreTokens()) { String part = tok.nextToken().trim(); if (part.length() > 0) { int idx = part.lastIndexOf('.'); if (idx == part.length() - 1) { part = part.substring(0, part.length() - 1); idx = part.lastIndexOf('.'); }/* w w w .java2 s. c o m*/ if (idx != -1) { char firstCharAfterLastDot = part.charAt(idx + 1); if (Character.isUpperCase(firstCharAfterLastDot)) { result.add(part.substring(0, idx)); } else { result.add(part); } } else { result.add(part); } } } return result; }