Example usage for javax.lang.model.element NestingKind MEMBER

List of usage examples for javax.lang.model.element NestingKind MEMBER

Introduction

In this page you can find the example usage for javax.lang.model.element NestingKind MEMBER.

Prototype

NestingKind MEMBER

To view the source code for javax.lang.model.element NestingKind MEMBER.

Click Source Link

Document

A type that is a named member of another type.

Usage

From source file:therian.buildweaver.StandardOperatorsProcessor.java

/**
 * Must be a public static concrete class with a default constructor, public static zero-arg method, or public
 * static final field./*  www.j  a v a 2  s  .c  o  m*/
 *
 * @param e
 * @return boolean
 */
private static boolean isValidStandardOperator(final Element e) {
    if (e.getKind() == ElementKind.FIELD) {
        return e.getModifiers().containsAll(EnumSet.of(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL));
    }
    if (e.getKind() == ElementKind.METHOD) {
        return e.getModifiers().containsAll(EnumSet.of(Modifier.PUBLIC, Modifier.STATIC))
                && ((ExecutableElement) e).getParameters().isEmpty();
    }
    if (e.getKind() == ElementKind.CLASS) {
        if (e.getModifiers().contains(Modifier.ABSTRACT) || findDefaultConstructor((TypeElement) e) == null) {
            return false;
        }
        Element current = e;
        while (current.getKind() == ElementKind.CLASS) {
            final TypeElement t = (TypeElement) current;
            if (t.getNestingKind() == NestingKind.TOP_LEVEL) {
                return true;
            }
            if (t.getNestingKind() == NestingKind.MEMBER && t.getModifiers().contains(Modifier.STATIC)) {
                current = t.getEnclosingElement();
                continue;
            }
            break;
        }
    }
    return false;
}