List of usage examples for javax.lang.model.element ElementKind ENUM_CONSTANT
ElementKind ENUM_CONSTANT
To view the source code for javax.lang.model.element ElementKind ENUM_CONSTANT.
Click Source Link
From source file:cop.raml.utils.Utils.java
public static String toEnumStr(String doc, VariableElement var) { doc = StringUtils.isBlank(doc) || EMPTY_ENUM.matcher(doc).matches() ? null : doc; if (doc != null || var == null) return doc; try {/*from www. j ava 2s . c o m*/ TypeElement typeElement = ElementUtils.asElement(var.asType()); if (typeElement.getKind() != ElementKind.ENUM) return null; return toEnumStr(typeElement.getEnclosedElements().stream() .filter(element -> element.getKind() == ElementKind.ENUM_CONSTANT) .map(element -> element.getSimpleName().toString()).toArray(String[]::new)); } catch (Exception ignored) { return null; } }
From source file:cop.raml.mocks.MockUtils.java
private static TypeElementMock createEnumElement(@NotNull Class<?> cls) { TypeElementMock element = new TypeElementMock(cls.getName(), ElementKind.ENUM); element.setType(new TypeMirrorMock(element, TypeKind.DECLARED)); element.addEnclosedElement(new TypeElementMock("values()", ElementKind.METHOD)); for (Object obj : cls.getEnumConstants()) element.addEnclosedElement(new VariableElementMock(obj.toString(), ElementKind.ENUM_CONSTANT)); return setAnnotations(element, cls); }
From source file:cop.raml.utils.example.JsonExample.java
/** * Returns string representation of the given {@code element} when this is enum (i.e. {@link TypeElement#getKind()} == {@link ElementKind#ENUM}). * If enum contains at least one constant, then method returns {@link Object#toString()} for first enum constant. If enum doesn't contain any * constant, then method return name for enum itself. * * @param type not {@code null} enum element type * @return not {@code null} enum element string representation *//*from w ww. ja va 2s . c o m*/ @NotNull private static String getEnumExample(@NotNull TypeMirror type) { if (!ElementUtils.isEnum(type)) return null; try { Element element = ElementUtils.asElement(type); for (Element parent : element.getEnclosedElements()) if (parent.getKind() == ElementKind.ENUM_CONSTANT) return parent.getSimpleName().toString(); return element.getSimpleName().toString(); } catch (Exception ignored) { return null; } }