List of usage examples for java.lang Character isJavaIdentifierPart
public static boolean isJavaIdentifierPart(int codePoint)
From source file:io.spring.initializr.metadata.InitializrConfiguration.java
private static boolean hasInvalidChar(String text) { if (!Character.isJavaIdentifierStart(text.charAt(0))) { return true; }//w w w . j av a 2s .c o m if (text.length() > 1) { for (int i = 1; i < text.length(); i++) { if (!Character.isJavaIdentifierPart(text.charAt(i))) { return true; } } } return false; }
From source file:com.aiblockchain.api.StringUtils.java
/** * Returns whether the given string is a valid Java class name. * * @param string the given string//from w w w .jav a 2s . c om * * @return whether the given string is a valid Java class name */ public static boolean isJavaClassName(final String string) { if (string == null || string.isEmpty() || !Character.isJavaIdentifierStart(string.charAt(0)) || string.contains("..")) { return false; } for (int i = 1; i < string.length(); i++) { final char ch = string.charAt(i); if (!Character.isJavaIdentifierPart(ch) && ch != '.') { return false; } } final String[] lastNameParts = string.split("\\."); final String lastNamePart = lastNameParts[lastNameParts.length - 1]; return Character.isUpperCase(lastNamePart.charAt(0)); }
From source file:org.apache.sling.scripting.sightly.impl.engine.compiled.SourceIdentifier.java
/** * Converts the given identifier to a legal Java identifier * * @param identifier the identifier to convert * @return legal Java identifier corresponding to the given identifier *///from w ww . j a v a 2s . c o m public static String makeJavaIdentifier(String identifier) { StringBuilder modifiedIdentifier = new StringBuilder(identifier.length()); if (!Character.isJavaIdentifierStart(identifier.charAt(0))) { modifiedIdentifier.append('_'); } for (int i = 0; i < identifier.length(); i++) { char ch = identifier.charAt(i); if (Character.isJavaIdentifierPart(ch) && ch != '_') { modifiedIdentifier.append(ch); } else if (ch == '.') { modifiedIdentifier.append('_'); } else { modifiedIdentifier.append(mangleChar(ch)); } } if (isJavaKeyword(modifiedIdentifier.toString())) { modifiedIdentifier.append('_'); } return modifiedIdentifier.toString(); }
From source file:org.apache.pluto.driver.util.PageState.java
/** * Returns a Pluto namespace string for the input portlet ID. * @param portletId//w ww .ja v a 2s . com * @return namespace string for the portlet ID */ public String getNameSpace(String portletId) { StringBuffer ns = new StringBuffer("Pluto_"); for (int ii = 0; ii < portletId.length(); ii++) { if (Character.isJavaIdentifierPart(portletId.charAt(ii))) { ns.append(portletId.charAt(ii)); } else { ns.append("_"); } } ns.append("_"); return ns.toString(); }
From source file:org.apache.cayenne.project.upgrade.v6.XMLDataChannelDescriptorLoader_V3_0_0_1.java
/** * Make sure the domain name is only made up of Java-identifier-safe * characters./*from ww w .ja v a 2s .c o m*/ */ protected String scrubDomainName(String name) { if (name == null || name.length() == 0) { return name; } StringBuilder buffer = new StringBuilder(name.length()); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (i == 0 && !Character.isJavaIdentifierStart(c)) { buffer.append('_'); } else if (i > 0 && !Character.isJavaIdentifierPart(c)) { buffer.append('_'); } else { buffer.append(c); } } return buffer.toString(); }
From source file:com.nextep.designer.sqlgen.mysql.strategies.SQLAutoIndentStrategy.java
/** * Retrieves the last word immediately before the specified * offset in the document. Any space will be ignored. * //w ww .ja v a 2 s . co m * @param document document to look into * @param offset offset to start the search from. * @return the last word. */ private String getLastWord(IDocument doc, int offset) { if (doc == null || offset > doc.getLength()) return ""; int length = 0; try { boolean wordStarted = false; while (--offset >= 0 && (!wordStarted || wordStarted && Character.isJavaIdentifierPart(doc.getChar(offset)))) { // We continue on spaces if (' ' == doc.getChar(offset)) { continue; } else if (!wordStarted) { wordStarted = true; } length++; } return doc.get(offset + 1, length); } catch (BadLocationException e) { log.debug("Error while retrieving completion prefix: BadLocation."); return ""; } }
From source file:org.ops4j.ramler.generator.Names.java
/** * Get enum field name from value/* www . j av a 2 s. c om*/ * * @param value * string to be checked * @return a {@link java.lang.String} object. */ public static boolean canBeEnumConstantName(final String value) { boolean res = !value.isEmpty(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (i == 0) { res &= Character.isJavaIdentifierStart(c); } else { res &= Character.isJavaIdentifierPart(c); } if (!res) { break; } } return res; }
From source file:JavaScriptCompressor.java
/** * Adds an identifier to output./*from w ww . j av a2s . c om*/ */ private void renderIdentifier() { if (!contentAppendedAfterLastIdentifier) append(SPACE); append(ch); nextChar(); while (Character.isJavaIdentifierPart(ch)) { append(ch); nextChar(); } contentAppendedAfterLastIdentifier = false; }
From source file:com.cloudera.sqoop.orm.ClassWriter.java
/** * Given some character that can't be in an identifier, * try to map it to a string that can.//from w w w. ja va 2 s . c o m * * @param c a character that can't be in a Java identifier * @return a string of characters that can, or null if there's * no good translation. */ static String getIdentifierStrForChar(char c) { if (Character.isJavaIdentifierPart(c)) { return "" + c; } else if (Character.isWhitespace(c)) { // Eliminate whitespace. return null; } else { // All other characters map to underscore. return "_"; } }
From source file:JavaFileGenerator.java
private String substitute(String text) throws IOException { int startPos; if ((startPos = text.indexOf("${")) == -1) { return text; }//www. j a va 2 s .c o m // Find matching "}". int braceDepth = 1; int endPos = startPos + 2; while (endPos < text.length() && braceDepth > 0) { if (text.charAt(endPos) == '{') braceDepth++; else if (text.charAt(endPos) == '}') braceDepth--; endPos++; } if (braceDepth != 0) throw new IOException("Mismatched \"{}\" in template string: " + text); final String variableExpression = text.substring(startPos + 2, endPos - 1); // Find the end of the variable name String value = null; for (int i = 0; i < variableExpression.length(); i++) { char ch = variableExpression.charAt(i); if (ch == ':' && i < variableExpression.length() - 1 && variableExpression.charAt(i + 1) == '-') { value = substituteWithDefault(variableExpression.substring(0, i), variableExpression.substring(i + 2)); break; } else if (ch == '?') { value = substituteWithConditional(variableExpression.substring(0, i), variableExpression.substring(i + 1)); break; } else if (ch != '_' && !Character.isJavaIdentifierPart(ch)) { throw new IOException("Invalid variable in " + text); } } if (value == null) { value = substituteWithDefault(variableExpression, ""); } return text.substring(0, startPos) + value + text.substring(endPos); }