List of usage examples for java.lang Character isJavaIdentifierPart
public static boolean isJavaIdentifierPart(int codePoint)
From source file:cc.recommenders.names.VmTypeName.java
/** * @see #get(String)//from ww w . j av a 2s . com */ protected VmTypeName(final String vmTypeName) { ensureIsNotNull(vmTypeName); ensureIsFalse(vmTypeName.length() == 0, "empty size for type name not permitted"); if (vmTypeName.length() == 1) { switch (vmTypeName.charAt(0)) { case 'B': case 'C': case 'D': case 'F': case 'I': case 'J': case 'S': case 'V': case 'Z': break; default: throwUnreachable("Invalid type name: " + vmTypeName); } } else { switch (vmTypeName.charAt(0)) { case '[': case 'L': break; default: throwUnreachable("Invalid type name: " + vmTypeName); } } int off = 0; while (off < vmTypeName.length()) { final char c = vmTypeName.charAt(off); if (c == '[' || c == '/' || c == '-'/* as in 'package-info.class' */ || c == '<' || c == '>' || Character.isJavaIdentifierPart(c)) { off++; continue; } throwIllegalArgumentException("Cannot parse '%s' as vm type name.", vmTypeName); break; } identifier = vmTypeName; }
From source file:cc.recommenders.names.CoReTypeName.java
/** * @see #get(String)/*from w w w . ja v a 2 s .co m*/ */ protected CoReTypeName(final String vmTypeName) { ensureIsNotNull(vmTypeName); ensureIsFalse(vmTypeName.length() == 0, "empty size for type name not permitted"); if (vmTypeName.length() == 1) { switch (vmTypeName.charAt(0)) { case 'B': case 'C': case 'D': case 'F': case 'I': case 'J': case 'S': case 'V': case 'Z': break; default: throwUnreachable("Invalid type name: " + vmTypeName); } } else { switch (vmTypeName.charAt(0)) { case '[': case 'L': break; default: throwUnreachable("Invalid type name: " + vmTypeName); } } int off = 0; while (off < vmTypeName.length()) { final char c = vmTypeName.charAt(off); if (c == '[' || c == '/' || c == '-'/* as in 'package-info.class' */ || c == '<' || c == '>' || Character.isJavaIdentifierPart(c)) { off++; continue; } throwIllegalArgumentException("Cannot parse '%s' as vm type name.", vmTypeName); break; } identifier = vmTypeName; }
From source file:org.eclipse.recommenders.utils.names.VmTypeName.java
/** * @see #get(String)/*from w w w . j a va2s.co m*/ */ @Testing("Outside of tests, VmTypeNames should be canonicalized through VmTypeName#get(String)") protected VmTypeName(final String vmTypeName) { ensureIsNotNull(vmTypeName); ensureIsFalse(vmTypeName.length() == 0, "empty size for type name not permitted"); if (vmTypeName.length() == 1) { switch (vmTypeName.charAt(0)) { case 'B': case 'C': case 'D': case 'F': case 'I': case 'J': case 'S': case 'V': case 'Z': break; default: throwUnreachable("Invalid type name: " + vmTypeName); } } else { switch (vmTypeName.charAt(0)) { case '[': case 'L': break; default: throwUnreachable("Invalid type name: " + vmTypeName); } } int off = 0; while (off < vmTypeName.length()) { final char c = vmTypeName.charAt(off); if (c == '[' || c == '/' || c == '-'/* as in 'package-info.class' */ || c == '<' || c == '>' || Character.isJavaIdentifierPart(c)) { off++; continue; } throwIllegalArgumentException("Cannot parse '%s' as vm type name.", vmTypeName); break; } identifier = vmTypeName; }
From source file:com.enonic.cms.core.portal.PrettyPathNameCreator.java
public static boolean isValidChar(char ch) { for (char unsafe : REMOVE_CHARS) { if (ch == unsafe) { return false; }/*w w w . j av a 2s . c om*/ } if (Character.isJavaIdentifierPart(ch)) { return true; } for (char other : ADDITIONAL_ALLOWED_CHARS) { if (ch == other) { return true; } } return false; }
From source file:com.wavemaker.common.util.StringUtils.java
public static String toJavaIdentifier(String s, char replacementChar) { if (ObjectUtils.isNullOrEmpty(s)) { throw new IllegalArgumentException("input cannot be null or empty"); }// w w w .ja v a 2 s . co m String unquoted = unquote(s); if (unquoted.length() > 0) { s = unquoted; } // although '$' is ok, it causes issues with type generation // because of inner class confusion s = s.replace("$", ""); if (s.length() == 0) { s = "" + replacementChar; } StringBuilder rtn = new StringBuilder(); if (JAVA_KEYWORDS.contains(s.toLowerCase()) || !Character.isJavaIdentifierStart(s.charAt(0))) { rtn.append(replacementChar); } if (s.length() == 1) { if (rtn.length() > 0) { return rtn.toString(); } else { return s; } } for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (!Character.isJavaIdentifierPart(c)) { c = replacementChar; } rtn.append(c); } return rtn.toString(); }
From source file:com.kstenschke.shifter.utils.UtilsTextual.java
/** * Get word at caret offset out of given text * * @param text The full text * @param cursorOffset Character offset of caret * @return The extracted word or null *//*from w w w. ja va2s . c o m*/ public static String getWordAtOffset(CharSequence text, int cursorOffset) { if (text.length() == 0 || cursorOffset >= text.length()) return null; if (cursorOffset > 0 && !Character.isJavaIdentifierPart(text.charAt(cursorOffset)) && Character.isJavaIdentifierPart(text.charAt(cursorOffset - 1))) { cursorOffset--; } if (Character.isJavaIdentifierPart(text.charAt(cursorOffset))) { int start = cursorOffset; int end = cursorOffset; while (start > 0 && Character.isJavaIdentifierPart(text.charAt(start - 1))) { start--; } while (end < text.length() && Character.isJavaIdentifierPart(text.charAt(end))) { end++; } return text.subSequence(start, end).toString(); } return null; }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.ejbql.EJBQLFieldsReader.java
/** * Takes a name and returns the same if it is a Java identifier; * else it substitutes the illegal characters so that it can be an identifier * * @param name//from w ww .j a va 2 s. c o m */ public static String getLiteral(String name) { if (isValidLiteral(name)) { return name; } StringBuffer buffer = new StringBuffer(name.length() + 5); char[] literalChars = new char[name.length()]; name.getChars(0, literalChars.length, literalChars, 0); for (int i = 0; i < literalChars.length; i++) { if (i == 0 && !Character.isJavaIdentifierStart(literalChars[i])) { buffer.append((int) literalChars[i]); } else if (i != 0 && !Character.isJavaIdentifierPart(literalChars[i])) { buffer.append((int) literalChars[i]); } else { buffer.append(literalChars[i]); } } return buffer.toString(); }
From source file:com.caocao.util.StringUtils.java
/** * Returns true if s is a legal Java identifier.<p> * <a href="http://www.exampledepot.com/egs/java.lang/IsJavaId.html">more info.</a> *//*from w w w . j a v a2 s . c o m*/ public static boolean isJavaIdentifier(String s) { if (s.length() == 0 || !Character.isJavaIdentifierStart(s.charAt(0))) { return false; } for (int i = 1; i < s.length(); i++) { if (!Character.isJavaIdentifierPart(s.charAt(i))) { return false; } } return true; }
From source file:PackageUtils.java
private static String removeIllegalIdentifierChars(String token) { StringBuffer newToken = new StringBuffer(); for (int i = 0; i < token.length(); i++) { char c = token.charAt(i); if (i == 0 && !Character.isJavaIdentifierStart(c)) { // prefix an '_' if the first char is illegal newToken.append("_" + c); } else if (!Character.isJavaIdentifierPart(c)) { // replace the char with an '_' if it is illegal newToken.append('_'); } else {//from w w w . ja v a2 s .c o m // add the legal char newToken.append(c); } } return newToken.toString(); }
From source file:com.salesforce.ide.ui.editors.internal.apex.completions.ApexCompletionUtils.java
public String getPrefix(ITextViewer viewer, int offset) throws BadLocationException { IDocument doc = viewer.getDocument(); if (doc == null || offset > doc.getLength()) return null; int length = 0; while (--offset >= 0) { char currentChar = doc.getChar(offset); if (Character.isJavaIdentifierPart(currentChar) || currentChar == FULLY_QUALIFIED_NAME_SEPARATOR_CHAR) { length++;//from w ww. ja v a 2 s.c o m } else { break; } } return doc.get(offset + 1, length); }