Example usage for javax.lang.model.element TypeElement getEnclosedElements

List of usage examples for javax.lang.model.element TypeElement getEnclosedElements

Introduction

In this page you can find the example usage for javax.lang.model.element TypeElement getEnclosedElements.

Prototype

@Override
List<? extends Element> getEnclosedElements();

Source Link

Document

Returns the fields, methods, constructors, and member types that are directly declared in this class or interface.

Usage

From source file:org.mule.module.extension.internal.capability.xml.schema.AnnotationProcessorUtils.java

static Map<String, ExecutableElement> getMethodsAnnotatedWith(TypeElement typeElement,
        Class<? extends Annotation> annotation) {
    return collectAnnotatedElements(ElementFilter.methodsIn(typeElement.getEnclosedElements()), annotation);
}

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 {/* w  w  w. j  a  v a  2  s .  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:org.leandreck.endpoints.processor.model.TypeNodeFactory.java

private static List<String> definePublicGetter(final TypeElement typeElement, final TypeMirror typeMirror,
        final Types typeUtils) {

    final List<String> publicGetters = ElementFilter.methodsIn(typeElement.getEnclosedElements()).stream()
            .filter(g -> g.getSimpleName().toString().startsWith("get")
                    || g.getSimpleName().toString().startsWith("is"))
            .filter(g -> g.getModifiers().contains(Modifier.PUBLIC))
            .filter(g -> !g.getModifiers().contains(Modifier.ABSTRACT))//FIXME filter remaining modifiers
            .map(g -> g.getSimpleName().toString()).collect(toList());

    if (isLombokAnnotatedType(typeMirror, typeUtils)) {
        ElementFilter.fieldsIn(typeElement.getEnclosedElements()).stream()
                .filter(g -> !g.getModifiers().contains(Modifier.STATIC)).map(g -> g.getSimpleName().toString())
                .forEach(publicGetters::add);
    }//from  ww w  . j av a 2 s.  c  om

    return publicGetters;
}

From source file:cop.raml.utils.example.JsonExample.java

/**
 * Returns all ignored fields for given {@code typeElement}. This time support only {@link JsonIgnoreProperties} and {@link JsonIgnore}
 * annotations. But in the following article <a href="http://www.baeldung.com/jackson-ignore-properties-on-serialization">Jackson Ignore
 * Properties on Marshalling</a>, more ways to ignore properties can be found, but there're not supported this time.
 *
 * @param typeElement type element/*from w w  w  .j a  v a 2s .  c  om*/
 * @return not {@code null} list of ignored fields
 */
@NotNull
private static Set<String> getIgnoredFields(TypeElement typeElement) {
    if (typeElement == null)
        return Collections.emptySet();

    Set<String> res = new HashSet<>();
    JsonIgnoreProperties annotation = typeElement.getAnnotation(JsonIgnoreProperties.class);

    if (annotation != null && ArrayUtils.isNotEmpty(annotation.value()))
        Collections.addAll(res, annotation.value());

    JsonIgnore ann;

    for (Element element : typeElement.getEnclosedElements())
        if ((ann = element.getAnnotation(JsonIgnore.class)) != null && ann.value())
            res.add(element.toString());

    return res;
}

From source file:org.ez18n.apt.processor.LabelBundleProcessor.java

private void processLabels(TypeElement resourcesType, List<LabelTemplateMethod> methods) {
    for (Element element : resourcesType.getEnclosedElements()) {
        if (element.getKind() != ElementKind.METHOD) {
            continue;
        }//from ww w  .  jav  a  2  s  .c  o m
        final ExecutableElement method = (ExecutableElement) element;
        Message labelAnnotation = element.getAnnotation(Message.class);
        final TemplateParam returnType = new TemplateParam(method.getReturnType().toString());
        final boolean deprecated = method.getAnnotation(Deprecated.class) != null;
        final LabelTemplateMethod labelMethod;
        try {
            labelMethod = new LabelTemplateMethod(method.getSimpleName().toString(), deprecated, returnType,
                    labelAnnotation.value(), labelAnnotation.mobile());
        } catch (Throwable t) {
            processingEnv.getMessager().printMessage(Kind.WARNING, t.getMessage(), resourcesType);
            continue;
        }

        for (VariableElement variable : method.getParameters()) {
            final String paramName = variable.getSimpleName().toString();
            final String paramType = variable.asType().toString();

            List<TemplateAnnotation> annotations = new ArrayList<TemplateAnnotation>();
            for (AnnotationMirror annotationMirrors : variable.getAnnotationMirrors()) {
                annotations.add(new TemplateAnnotation(annotationMirrors.getAnnotationType().toString()));
            }

            labelMethod.getParams().add(new TemplateParam(paramType, paramName, annotations));
        }
        methods.add(labelMethod);
    }
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static ExecutableElement getLongestContructor(TypeElement typeElement) {
    List<ExecutableElement> constructors = ElementFilter.constructorsIn(typeElement.getEnclosedElements());
    int max = -1;
    ExecutableElement current = null;
    for (ExecutableElement constructor : constructors) {
        if (constructor.getParameters().size() > max) {
            max = constructor.getParameters().size();
            current = constructor;//from  w  ww.j  a  v  a 2  s .com
        }
    }
    return current;
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static List<VariableElement> getEnumVariableElements(Project project, String fqClassName)
        throws IOException {
    JavaSource javaSource = getJavaSource(project, fqClassName);
    if (javaSource == null) {
        throw new IOException();
    }//ww w .ja v a 2  s.  c o  m
    TypeElement typeElement = JavaSourceHelper.getTypeElement(javaSource);
    return ElementFilter.fieldsIn(typeElement.getEnclosedElements());
}

From source file:net.pkhsolutions.ceres.common.builder.processor.BuildableAP.java

private ExecutableElement getBuilderConstructor(TypeElement type) {
    for (Element e : type.getEnclosedElements()) {
        if (e.getKind().equals(ElementKind.CONSTRUCTOR) && e.getAnnotation(BuilderConstructor.class) != null) {
            return (ExecutableElement) e;
        }/*w w w . ja v a 2 s.com*/
    }
    throw new RuntimeException("No constructor annotated with @BuilderConstructor found");
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static TypeElement getXmlRepresentationClass(TypeElement typeElement, String defaultSuffix) {
    List<ExecutableElement> methods = ElementFilter.methodsIn(typeElement.getEnclosedElements());
    for (ExecutableElement method : methods) {
        List<? extends AnnotationMirror> anmirs = method.getAnnotationMirrors();

        AnnotationMirror mirrorHttpMethod = findAnnotation(anmirs, RestConstants.GET);
        if (mirrorHttpMethod != null) {
            TypeMirror tm = method.getReturnType();
            if (tm != null && tm.getKind() == TypeKind.DECLARED) {
                TypeElement returnType = (TypeElement) ((DeclaredType) tm).asElement();
                if (returnType.getSimpleName().toString().endsWith(defaultSuffix)) {
                    return returnType;
                }/*from   w w w.j av a 2 s . c o  m*/
            }
        }
    }
    return null;
}

From source file:net.pkhsolutions.ceres.common.builder.processor.BuildableAP.java

private Collection<VariableElement> getFields(TypeElement type) {
    final Set<Element> elements = new HashSet<Element>();
    elements.addAll(type.getEnclosedElements());
    TypeMirror supertype = type.getSuperclass();
    while (supertype.getKind() != TypeKind.NONE) {
        final TypeElement element = (TypeElement) processingEnv.getTypeUtils().asElement(supertype);
        elements.addAll(element.getEnclosedElements());
        supertype = element.getSuperclass();
    }/*from  ww w .java 2  s  .com*/
    return ElementFilter.fieldsIn(elements);
}