List of usage examples for java.lang Character isJavaIdentifierPart
public static boolean isJavaIdentifierPart(int codePoint)
From source file:com.google.jenkins.flakyTestHandler.junit.FlakyCaseResult.java
/** * Gets the version of {@link #getName()} that's URL-safe. *///w ww . j a v a 2s .co m public @Override synchronized String getSafeName() { if (safeName != null) { return safeName; } StringBuilder buf = new StringBuilder(testName); for (int i = 0; i < buf.length(); i++) { char ch = buf.charAt(i); if (!Character.isJavaIdentifierPart(ch)) buf.setCharAt(i, '_'); } Collection<FlakyCaseResult> siblings = (classResult == null ? Collections.<FlakyCaseResult>emptyList() : classResult.getChildren()); return safeName = uniquifyName(siblings, buf.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 ww. j a va 2s .c o m for (char c : modelName.toCharArray()) { if (!Character.isJavaIdentifierPart(c)) { sb.append("_"); } else { sb.append(c); } } modelName = sb.toString(); return modelName; }
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 constant (public static final XXX). The rule is to basically take every letter * or digit and return it in uppercase and every non-letter or non-digit as an underscore. * This trims all non-letter/digit characters from the beginning of the string. *//* w ww . j ava2s. co m*/ public static String xmlTextToJavaConstantTrimmed(String xml) { if (xml == null || xml.length() == 0) return xml; boolean stringStarted = false; StringBuffer constant = new StringBuffer(); for (int i = 0; i < xml.length(); i++) { char ch = xml.charAt(i); if (Character.isJavaIdentifierPart(ch)) { stringStarted = true; constant.append(Character.toUpperCase(ch)); } else if (stringStarted) constant.append('_'); } return constant.toString(); }
From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java
public static boolean isJavaIdentifierPart(String input) { for (int i = 0; i < input.length(); i++) { if (!Character.isJavaIdentifierPart(input.charAt(i))) return false; }//from w w w . j a va 2 s . com return true; }
From source file:org.apache.openjpa.lib.meta.ClassArgParser.java
/** * Returns the class named in the given .java file. *///from w w w .ja v a 2 s . c om private String getFromJavaFile(File file) throws IOException { BufferedReader in = null; try { // find the line with the package declaration in = new BufferedReader(new FileReader(file)); String line; StringBuilder pack = null; while ((line = in.readLine()) != null) { line = line.trim(); if (line.startsWith("package ")) { line = line.substring(8).trim(); // strip off anything beyond the package declaration pack = new StringBuilder(); for (int i = 0; i < line.length(); i++) { if (Character.isJavaIdentifierPart(line.charAt(i)) || line.charAt(i) == '.') pack.append(line.charAt(i)); else break; } break; } } // strip '.java' String clsName = file.getName(); clsName = clsName.substring(0, clsName.length() - 5); // prefix with package if (pack != null && pack.length() > 0) clsName = pack + "." + clsName; return clsName; } finally { if (in != null) try { in.close(); } catch (IOException ioe) { } } }
From source file:org.seasar.s2jsfplugin.validater.S2JSFHTMLValidator.java
/** JSFJX^^Oof?[V?s?B */ private void validateJSFTaglib(String jsfTagName, FuzzyXMLElement element) throws CoreException { String mayaPrefix = Util.getMayaPrefix(element); if (mayaPrefix == null) { return;//from w ww . j a v a 2s .c o m } // UIR|?[lgK?{??H // // K?{?`FbN // TLDInfo tld = project.getTLDInfo(S2JSFPlugin.HTML_URI); // TagInfo tag = tld.getTagInfo(jsfTagName); // if(tld!=null){ // AttributeInfo[] attrs = tag.getAttributeInfo(); // for(int i=0;i<attrs.length;i++){ // if(attrs[i].isRequired() && element.getAttributeNode(mayaPrefix + ":" + attrs[i].getAttributeName())==null){ // createMarker(file,element.getOffset(),element.getOffset()+element.getLength(), // widget.getLineAtOffset(element.getOffset()), // mayaPrefix + ":" + attrs[i].getAttributeName() + "?K?{?B"); // return; // } // } // } // ?l`FbN FuzzyXMLAttribute[] attrs = element.getAttributes(); for (int i = 0; i < attrs.length; i++) { String attrName = attrs[i].getName(); String attrValue = attrs[i].getValue(); if (attrName.indexOf(":") <= 0) { continue; } String[] attrDim = attrName.split(":"); if (!attrDim[0].equals(mayaPrefix)) { continue; } String type = JSFTagDefinition.getAttributeInfo(jsfTagName, attrDim[1]); if (type == null) { continue; } attrValue = processExpression(attrs[i], attrValue); if (attrValue == null) { continue; } if (type == JSFTagDefinition.VALUE) { type = JSFTagDefinition.PROPERTY; } // ELV^bNXG?[m String el = attrs[i].getValue(); el = el.replaceFirst("^#", "\\$"); try { ELParser parser = new ELParser(new StringReader(el)); parser.ExpressionString(); } catch (Exception ex) { createAttributeValueMarker(attrs[i], createMessage(ValidationMessages.INVALID_EL, attrValue)); continue; } // V^bNXG?[BeanL?q?? StringBuffer sb = new StringBuffer(); boolean errorFlag = true; for (int j = 0; j < attrValue.length(); j++) { char c = attrValue.charAt(j); if (Character.isJavaIdentifierPart(c) || c == '.') { sb.append(c); } else { errorFlag = validateBinding(element, attrs[i], sb.toString(), type); sb.setLength(0); if (errorFlag == false) { break; } if (c == '[') { errorFlag = false; break; } } } if (errorFlag == true && sb.length() > 0) { validateBinding(element, attrs[i], sb.toString(), type); } } }
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 w w . j a v a2 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:nl.strohalm.cyclos.utils.database.DatabaseHelper.java
/** * Generates a parameter name/*from w w w.ja v a2 s .c o m*/ */ private static String getParameterName(final Map<String, Object> namedParameters, final String propertyName) { int counter = 1; // Transform the property in a valid identifier final StringBuilder sb = new StringBuilder(propertyName.length()); for (int i = 0, len = propertyName.length(); i < len; i++) { final char c = propertyName.charAt(i); if (Character.isJavaIdentifierPart(c)) { sb.append(c); } else { sb.append('_'); } } final String field = sb.toString(); String parameterName = field.concat("_1"); while (namedParameters.containsKey(parameterName)) { parameterName = field.concat("_").concat(String.valueOf(++counter)); } return parameterName; }
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 . ja v a2s .c o m } 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: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; }//from ww w .ja va2 s. com return !(KEYWORDS.contains(s)); }