List of usage examples for java.lang Character isJavaIdentifierStart
public static boolean isJavaIdentifierStart(int codePoint)
From source file:name.ikysil.beanpathdsl.codegen.CodeGen.java
private String getNavigationMethodName(PropertyDescriptor pd) { String name = pd.getName();/* w ww . ja va2 s .co m*/ if (!Character.isJavaIdentifierStart(name.charAt(0)) || isJavaKeyword(name)) { name = KEYWORD_PREFIX + name; } return name; }
From source file:com.cisco.step.jenkins.plugins.jenkow.WfUtil.java
/** * Produces a valid workflow ID out of a given string. * Replaces each invalid character with an underscore. *//*from w w w . j a v a 2s. c o m*/ static String mkWorkflowId(String s) { if (s == null || s.length() < 1) return s; // TODO 5: figure out what's the actual definition for valid workflow IDs StringBuffer sb = new StringBuffer(); char c = s.charAt(0); sb.append(Character.isJavaIdentifierStart(c) ? c : '_'); for (int i = 1, n = s.length(); i < n; i++) { c = s.charAt(i); sb.append(Character.isJavaIdentifierPart(c) ? c : '_'); } return sb.toString(); }
From source file:org.drools.guvnor.server.contenthandler.drools.ScorecardsContentHandler.java
private String convertToJavaIdentifier(String modelName) { StringBuilder sb = new StringBuilder(); if (!Character.isJavaIdentifierStart(modelName.charAt(0))) { sb.append("_"); }//from w w w. j a v a 2 s . c om for (char c : modelName.toCharArray()) { if (!Character.isJavaIdentifierPart(c)) { sb.append("_"); } else { sb.append(c); } } modelName = sb.toString(); return modelName; }
From source file:org.nsesa.editor.app.xsd.FileClassOverlayGenerator.java
/** * Generates overlay factories that implement {@link org.nsesa.editor.gwt.core.client.ui.overlay.document.OverlayFactory}. * Used during the overlay mechanism when creating a higher abstraction based on the DOM. * * @param elementClasses the map with overlay classes for each namespace. * @param packageNameGenerator the package name generator * @param directoryNameGenerator the directory name generator *//*from ww w . j a v a 2 s.com*/ private void generateFactories(Map<String, List<OverlayClass>> elementClasses, PackageNameGenerator packageNameGenerator, PackageNameGenerator directoryNameGenerator) { // create the factory for each namespace for (final Map.Entry<String, List<OverlayClass>> entry : elementClasses.entrySet()) { String factoryName = directoryNameGenerator.getPackageName(entry.getKey()).replace("_", ""); if (!Character.isJavaIdentifierStart(factoryName.charAt(0))) { factoryName = "_" + factoryName; } final String className = StringUtils.capitalize(factoryName) + "OverlayFactory"; final File file = new File(generatedSourcesDirectory, className + ".java"); final Map<String, Object> context = new HashMap<String, Object>(); final OverlayClass factoryClass = new OverlayClass(className, null, OverlayType.Unknown); factoryClass.setClassName(className); factoryClass.setNamespaceURI(entry.getKey()); factoryClass.setPackageName( basePackageName.endsWith(".") ? basePackageName.substring(0, basePackageName.length() - 1) : basePackageName); context.put("overlayClass", factoryClass); context.put("overlayClasses", entry.getValue()); context.put("packageNameGenerator", packageNameGenerator); writeToFile(file, context, OVERLAY_FACTORY_TEMPLATE_NAME); } }
From source file:org.executequery.sql.SQLFormatter.java
private boolean isFunctionName(String tok) { if (StringUtils.isBlank(tok)) { return false; }/*w w w . j av a2 s . c o m*/ final char begin = tok.charAt(0); final boolean isIdentifier = Character.isJavaIdentifierStart(begin) || '"' == begin; return isIdentifier && !LOGICAL.contains(tok) && !END_CLAUSES.contains(tok) && !QUANTIFIERS.contains(tok) && !DML.contains(tok) && !MISC.contains(tok); }
From source file:com.curecomp.primefaces.migrator.PrimefacesMigration.java
private static void findWidgetVarUsages(Path sourceFile, WidgetVarLocation widgetVarLocation, BlockingQueue<WidgetVarLocation> foundUsages, BlockingQueue<WidgetVarLocation> skippedUsages, BlockingQueue<WidgetVarLocation> unusedOrAmbiguous) throws IOException { try (BufferedReader br = Files.newBufferedReader(sourceFile, StandardCharsets.UTF_8)) { int lineNr = 0; String line;//from w ww. java 2 s .c o m while ((line = br.readLine()) != null) { lineNr++; int startIndex = 0; int endIndex = -1; while ((startIndex = line.indexOf(widgetVarLocation.widgetVar, endIndex + 1)) > -1) { endIndex = startIndex + widgetVarLocation.widgetVar.length(); if (sourceFile.equals(widgetVarLocation.location) && lineNr == widgetVarLocation.lineNr && startIndex == widgetVarLocation.columnNr) { continue; } WidgetVarLocation usage = new WidgetVarLocation(widgetVarLocation.widgetVar, sourceFile, lineNr, startIndex, line); // Only look at lines that use the word as a whole and not just as a part if ((startIndex == 0 || !Character.isJavaIdentifierStart(line.charAt(startIndex - 1))) && (line.length() == endIndex || !Character.isJavaIdentifierPart(line.charAt(endIndex)))) { // We skip usages that occur as the last word of a line or usages that don't call methods directly if (endIndex == line.length() || endIndex < line.length() && line.charAt(endIndex) != '.') { skippedUsages.add(usage); } else { foundUsages.add(usage); } } else { skippedUsages.add(usage); } unusedOrAmbiguous.remove(widgetVarLocation); } } } }
From source file:com.weibo.api.motan.core.extension.ExtensionLoader.java
private void parseLine(Class<T> type, URL url, String line, int lineNumber, List<String> names) throws IOException, ServiceConfigurationError { int ci = line.indexOf('#'); if (ci >= 0) { line = line.substring(0, ci);/* w w w .j av a2 s. c om*/ } line = line.trim(); if (line.length() <= 0) { return; } if ((line.indexOf(' ') >= 0) || (line.indexOf('\t') >= 0)) { failThrows(type, url, lineNumber, "Illegal spi configuration-file syntax"); } int cp = line.codePointAt(0); if (!Character.isJavaIdentifierStart(cp)) { failThrows(type, url, lineNumber, "Illegal spi provider-class name: " + line); } for (int i = Character.charCount(cp); i < line.length(); i += Character.charCount(cp)) { cp = line.codePointAt(i); if (!Character.isJavaIdentifierPart(cp) && (cp != '.')) { failThrows(type, url, lineNumber, "Illegal spi provider-class name: " + line); } } if (!names.contains(line)) { names.add(line); } }
From source file:ca.sfu.federation.model.Expression.java
/** * A statement has the form of a reference if it is comprised of only * alphanumeric, ('.','_','[',']') characters, and the first character is a * char or the @ symbol. No guarantee is given that the reference can be * resolved./*w w w . jav a2 s. c o m*/ * @param Statement User specified statement. * @return True if the statement is a reference, false otherwise. */ private static boolean isReference(String Statement) { // init boolean result = true; // check if the statement is a proper reference char c = Statement.charAt(0); if (!Character.isJavaIdentifierStart(c)) { result = false; } if (Statement.substring(0, 1).equals("@")) { result = true; } // if the statement contains any operators, then it is not a reference int i = 0; while (result && i < Expression.OPERATORS.length) { if (Statement.contains(Expression.OPERATORS[i])) { result = false; } i++; } // if the statement contains punctuation other than ('@','.','_','[',']'), then it is not a reference if (Statement.length() > 1) { for (i = 1; i < Statement.length(); i++) { char ch = Statement.charAt(i); if (!Character.isJavaIdentifierPart(ch)) { result = false; } } } // return result return result; }
From source file:org.openlaszlo.sc.ScriptCompiler.java
/** Returns true iff the string is a valid JavaScript identifier. */ public static boolean isIdentifier(String s) { int length = s.length(); if (length == 0) return false; if (!Character.isJavaIdentifierStart(s.charAt(0))) return false; for (int i = 1; i < length; i++) { if (!Character.isJavaIdentifierPart(s.charAt(i))) return false; }// w w w . j av a 2s.c o m return !(KEYWORDS.contains(s)); }
From source file:me.oriley.crate.CrateGenerator.java
@NonNull private static String sanitiseFieldName(@NonNull String fileName) { // JavaPoet doesn't like the dollar signs so we remove them too char[] charArray = fileName.toCharArray(); for (int i = 0; i < charArray.length; i++) { if (!Character.isJavaIdentifierPart(charArray[i]) || charArray[i] == '$') { charArray[i] = '_'; }/* w w w .j a va 2s.co m*/ } if (!Character.isJavaIdentifierStart(charArray[0]) || charArray[0] == '$') { return "_" + new String(charArray); } else { return new String(charArray); } }