本文整理了Java中java.lang.Character.isJavaIdentifierStart()
方法的一些代码示例,展示了Character.isJavaIdentifierStart()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.isJavaIdentifierStart()
方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:isJavaIdentifierStart
[英]Indicates whether the specified character is a valid first character for a Java identifier.
[中]指示指定的字符是否为Java标识符的有效第一个字符。
代码示例来源:origin: spring-projects/spring-framework
private boolean isVariableName(String name) {
char[] chars = name.toCharArray();
if (!Character.isJavaIdentifierStart(chars[0])) {
return false;
}
for (int i = 1; i < chars.length; i++) {
if (!Character.isJavaIdentifierPart(chars[i])) {
return false;
}
}
return true;
}
代码示例来源:origin: hibernate/hibernate-orm
private static boolean isJavaIdentifier(String token) {
return Character.isJavaIdentifierStart( token.charAt( 0 ) );
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
for (char ch = 0; ch < Character.MAX_VALUE; ch++) {
if (Character.isJavaIdentifierPart(ch) && !Character.isJavaIdentifierStart(ch)) {
System.out.printf("%04x <%s>%n", (int) ch, "" + ch);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private String maybeExtractVariableName(@Nullable String candidateToken) {
if (!StringUtils.hasLength(candidateToken)) {
return null;
}
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
Character.isLowerCase(candidateToken.charAt(0))) {
char[] tokenChars = candidateToken.toCharArray();
for (char tokenChar : tokenChars) {
if (!Character.isJavaIdentifierPart(tokenChar)) {
return null;
}
}
return candidateToken;
}
else {
return null;
}
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Returns true if s is a legal Java identifier.<p>
* <a href="http://www.exampledepot.com/egs/java.lang/IsJavaId.html">more info.</a>
*/
public static boolean isJavaIdentifier(String s) {
if (isEmpty(s) || !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;
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Returns true if s is a legal Java identifier.<p>
* <a href="http://www.exampledepot.com/egs/java.lang/IsJavaId.html">more info.</a>
*/
public static boolean isJavaIdentifier(String s) {
if (isEmpty(s) || !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;
}
代码示例来源:origin: stackoverflow.com
for (int i = Character.MIN_CODE_POINT; i <= Character.MAX_CODE_POINT; i++)
if (Character.isJavaIdentifierStart(i) && !Character.isAlphabetic(i))
System.out.print((char) i + " ");
}
代码示例来源:origin: pxb1988/dex2jar
private static boolean isJavaIdentifier(String str) {
if (str.length() < 1) {
return false;
}
if (!Character.isJavaIdentifierStart(str.charAt(0))) {
return false;
}
for (int i = 1; i < str.length(); i++) {
if (!Character.isJavaIdentifierPart(str.charAt(i))) {
return false;
}
}
return true;
}
代码示例来源:origin: org.easymock/easymock
public static boolean isJavaIdentifier(String mockName) {
if (mockName.length() == 0 || mockName.indexOf(' ') > -1
|| !Character.isJavaIdentifierStart(mockName.charAt(0))) {
return false;
}
for (char c : mockName.substring(1).toCharArray()) {
if (!isJavaIdentifierPart(c)) {
return false;
}
}
return true;
}
代码示例来源:origin: looly/hutool
private static boolean isFunctionName(String tok) {
char begin = tok.charAt(0);
boolean isIdentifier = (Character.isJavaIdentifierStart(begin)) || ('"' == begin);
return (isIdentifier) && (!LOGICAL.contains(tok)) && (!END_CLAUSES.contains(tok)) && (!QUANTIFIERS.contains(tok)) && (!DML.contains(tok)) && (!MISC.contains(tok));
}
代码示例来源:origin: baomidou/mybatis-plus
private static boolean isFunctionName(String tok) {
if (tok == null || tok.length() == 0) {
return false;
}
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);
}
代码示例来源:origin: looly/hutool
private static boolean isFunctionName(String tok) {
char begin = tok.charAt(0);
boolean isIdentifier = (Character.isJavaIdentifierStart(begin)) || ('"' == begin);
return (isIdentifier) && (!LOGICAL.contains(tok)) && (!END_CLAUSES.contains(tok)) && (!QUANTIFIERS.contains(tok)) && (!DML.contains(tok)) && (!MISC.contains(tok));
}
代码示例来源:origin: square/javapoet
public static String toJavaIdentifier(String suggestion) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < suggestion.length(); ) {
int codePoint = suggestion.codePointAt(i);
if (i == 0
&& !Character.isJavaIdentifierStart(codePoint)
&& Character.isJavaIdentifierPart(codePoint)) {
result.append("_");
}
int validCodePoint = Character.isJavaIdentifierPart(codePoint) ? codePoint : '_';
result.appendCodePoint(validCodePoint);
i += Character.charCount(codePoint);
}
return result.toString();
}
代码示例来源:origin: hibernate/hibernate-orm
private static boolean isFunctionName(String tok) {
if ( tok == null || tok.length() == 0 ) {
return false;
}
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 );
}
代码示例来源:origin: redisson/redisson
/**
* Checks if a Java identifier is valid.
*
* @param identifier The identifier to check for validity.
* @return {@code true} if the given identifier is valid.
*/
private static boolean isValidIdentifier(String identifier) {
if (KEYWORDS.contains(identifier) || identifier.length() == 0 || !Character.isJavaIdentifierStart(identifier.charAt(0))) {
return false;
} else if (identifier.equals(PackageDescription.PACKAGE_CLASS_NAME)) {
return true;
}
for (int index = 1; index < identifier.length(); index++) {
if (!Character.isJavaIdentifierPart(identifier.charAt(index))) {
return false;
}
}
return true;
}
}
代码示例来源:origin: square/javapoet
private static String extractMemberName(String part) {
checkArgument(Character.isJavaIdentifierStart(part.charAt(0)), "not an identifier: %s", part);
for (int i = 1; i <= part.length(); i++) {
if (!SourceVersion.isIdentifier(part.substring(0, i))) {
return part.substring(0, i - 1);
}
}
return part;
}
代码示例来源:origin: square/javapoet
private boolean emitStaticImportMember(String canonical, String part) throws IOException {
String partWithoutLeadingDot = part.substring(1);
if (partWithoutLeadingDot.isEmpty()) return false;
char first = partWithoutLeadingDot.charAt(0);
if (!Character.isJavaIdentifierStart(first)) return false;
String explicit = canonical + "." + extractMemberName(partWithoutLeadingDot);
String wildcard = canonical + ".*";
if (staticImports.contains(explicit) || staticImports.contains(wildcard)) {
emitAndIndent(partWithoutLeadingDot);
return true;
}
return false;
}
代码示例来源:origin: checkstyle/checkstyle
/**
* Checks if the given position is start one for HTML tag.
* @param javadocText text of javadoc comments.
* @param pos position to check.
* @return {@code true} some HTML tag starts from given position.
*/
private static boolean isTag(String[] javadocText, Point pos) {
final int column = pos.getColumnNo() + 1;
final String text = javadocText[pos.getLineNo()];
//Character.isJavaIdentifier... may not be a valid HTML
//identifier but is valid for generics
return column >= text.length()
|| Character.isJavaIdentifierStart(text.charAt(column))
|| text.charAt(column) == '/';
}
代码示例来源:origin: stanfordnlp/CoreNLP
protected String readJavaIdentifier() {
readWhiteSpace();
StringBuilder sb = new StringBuilder();
char ch = read();
if (Character.isJavaIdentifierStart(ch) && !isEOF) {
sb.append(ch);
ch = read();
while (Character.isJavaIdentifierPart(ch) && !isEOF) {
sb.append(ch);
ch = read();
}
}
unread();
// log.info("Read text: ["+sb+"]");
return sb.toString().intern();
}
代码示例来源:origin: alibaba/fastjson
String readName() {
skipWhitespace();
if (ch != '\\' && !Character.isJavaIdentifierStart(ch)) {
throw new JSONPathException("illeal jsonpath syntax. " + path);
}
StringBuilder buf = new StringBuilder();
while (!isEOF()) {
if (ch == '\\') {
next();
buf.append(ch);
if (isEOF()) {
return buf.toString();
}
next();
continue;
}
boolean identifierFlag = Character.isJavaIdentifierPart(ch);
if (!identifierFlag) {
break;
}
buf.append(ch);
next();
}
if (isEOF() && Character.isJavaIdentifierPart(ch)) {
buf.append(ch);
}
return buf.toString();
}
内容来源于网络,如有侵权,请联系作者删除!