Example usage for javax.lang.model SourceVersion isIdentifier

List of usage examples for javax.lang.model SourceVersion isIdentifier

Introduction

In this page you can find the example usage for javax.lang.model SourceVersion isIdentifier.

Prototype

public static boolean isIdentifier(CharSequence name) 

Source Link

Document

Returns whether or not name is a syntactically valid identifier (simple name) or keyword in the latest source version.

Usage

From source file:com.mastfrog.parameters.processor.Processor.java

static boolean isJavaIdentifier(String id) {
    if (id == null) {
        return false;
    }/* w  ww  .  j a  v a  2s .c  o  m*/
    return SourceVersion.isIdentifier(id) && !SourceVersion.isKeyword(id);
}

From source file:org.bonitasoft.engine.bdm.CodeGenerator.java

private void validateFieldName(final String fieldName) {
    if (fieldName == null || fieldName.isEmpty()) {
        throw new IllegalArgumentException("Field name cannot be null or empty");
    }/*w w w . j av  a2s  .com*/
    if (SourceVersion.isKeyword(fieldName)) {
        throw new IllegalArgumentException("Field " + fieldName + " is a resered keyword");
    }
    if (!SourceVersion.isIdentifier(fieldName)) {
        throw new IllegalArgumentException("Field " + fieldName + " is not a valid Java identifier");
    }
}

From source file:org.eclipse.skalli.services.search.SearchQuery.java

Expression asExpression(String s) throws QueryParseException {
    int n = s.indexOf('(');
    if (n < 0) {
        if (!SourceVersion.isIdentifier(s)) {
            throw new QueryParseException("Invalid property name :" + s);
        }/*from   w  w w.java 2 s. c  om*/
        return new Expression(s);
    }
    if (!s.endsWith(")")) { //$NON-NLS-1$
        throw new QueryParseException("Invalid property expression: " + s);
    }
    String name = s.substring(0, n);
    if (name.length() == 0) {
        throw new QueryParseException("Property expression specifies no property name :" + s);
    }
    if (!SourceVersion.isIdentifier(name)) {
        throw new QueryParseException("Invalid property name :" + s);
    }
    String argsList = s.substring(n + 1, s.length() - 1);
    if (StringUtils.isBlank(argsList)) {
        return new Expression(name);
    }
    if ("''".equals(argsList) || "\"\"".equals(argsList)) { //$NON-NLS-1$ //$NON-NLS-2$
        return new Expression(name, ""); //$NON-NLS-1$
    }
    tokenizer.reset(argsList);
    return new Expression(name, tokenizer.getTokenArray());
}

From source file:org.guvnor.common.services.backend.validation.ValidationUtils.java

public static boolean isJavaIdentifier(final String value) {
    if (StringUtils.isBlank(value)) {
        return false;
    }/*from ww  w.  ja va  2 s  .c o m*/
    if (!SourceVersion.isIdentifier(value) || SourceVersion.isKeyword(value)) {
        return false;
    }
    for (int i = 0; i < value.length(); i++) {
        if (!CharUtils.isAsciiPrintable(value.charAt(i))) {
            return false;
        }
    }
    return true;
}