Java Code Examples for javax.lang.model.type.TypeKind#valueOf()

The following examples show how to use javax.lang.model.type.TypeKind#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeDesc.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static TypeDesc decodeString(String s) {
    s = s.trim();
    if (s.endsWith("[]")) {
        String componentPart = s.substring(0, s.length()-2);
        return new ArrayTypeDesc(decodeString(componentPart));
    }

    if (s.startsWith("#"))
        return new TypeVarTypeDesc(s.substring(1));

    if (s.matches("boolean|byte|char|double|float|int|long|short|void")) {
        TypeKind tk = TypeKind.valueOf(StringUtils.toUpperCase(s));
        return new PrimitiveTypeDesc(tk);
    }

    return new ReferenceTypeDesc(s);
}
 
Example 2
Source File: Util.java    From GoldenGate with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the {@link TypeMirror} for a given {@link Class}.
 *
 * Adapter from https://github.com/typetools/checker-framework/
 */
public static TypeMirror typeFromClass(Types types, Elements elements, Class<?> clazz) {
    if (clazz == void.class) {
        return types.getNoType(TypeKind.VOID);
    } else if (clazz.isPrimitive()) {
        String primitiveName = clazz.getName().toUpperCase();
        TypeKind primitiveKind = TypeKind.valueOf(primitiveName);
        return types.getPrimitiveType(primitiveKind);
    } else if (clazz.isArray()) {
        TypeMirror componentType = typeFromClass(types, elements, clazz.getComponentType());
        return types.getArrayType(componentType);
    } else {
        TypeElement element = elements.getTypeElement(clazz.getCanonicalName());
        if (element == null) {
            throw new IllegalArgumentException("Unrecognized class: " + clazz);
        }
        return element.asType();
    }
}