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

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

Introduction

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

Prototype

NestingKind getNestingKind();

Source Link

Document

Returns the nesting kind of this type element.

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.//  w  w  w.ja  v  a  2  s . com
 *
 * @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;
}