Example usage for javax.lang.model.element ElementKind CONSTRUCTOR

List of usage examples for javax.lang.model.element ElementKind CONSTRUCTOR

Introduction

In this page you can find the example usage for javax.lang.model.element ElementKind CONSTRUCTOR.

Prototype

ElementKind CONSTRUCTOR

To view the source code for javax.lang.model.element ElementKind CONSTRUCTOR.

Click Source Link

Document

A constructor.

Usage

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;
        }//from   w  w w  .  j a  v  a2s  .c  o m
    }
    throw new RuntimeException("No constructor annotated with @BuilderConstructor found");
}

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

private boolean isValidPropertyElement(VariableElement element) {
    if (element.getEnclosingElement().getKind() == ElementKind.CONSTRUCTOR) {
        return true;
    } else {// w  w w  . ja va  2 s.co m
        return ((element.getAnnotation(Ignore.class) == null)
                && (!element.getModifiers().contains(Modifier.STATIC))
                && (!element.getModifiers().contains(Modifier.FINAL)));
    }
}

From source file:org.jsweet.transpiler.util.Util.java

/**
 * Finds the method in the given type that matches the given name and
 * signature./*from   w  w w .j  a  va  2s  . c  om*/
 */
public static MethodSymbol findMethodDeclarationInType(Types types, TypeSymbol typeSymbol, String methodName,
        MethodType methodType, boolean overrides) {
    if (typeSymbol == null) {
        return null;
    }
    if (typeSymbol.getEnclosedElements() != null) {
        for (Element element : typeSymbol.getEnclosedElements()) {
            if ((element instanceof MethodSymbol) && (methodName.equals(element.getSimpleName().toString())
                    || ((MethodSymbol) element).getKind() == ElementKind.CONSTRUCTOR
                            && "this".equals(methodName))) {
                MethodSymbol methodSymbol = (MethodSymbol) element;
                if (methodType == null) {
                    return methodSymbol;
                }
                if (overrides ? isInvocable(types, methodSymbol.type.asMethodType(), methodType)
                        : isInvocable(types, methodType, methodSymbol.type.asMethodType())) {
                    return methodSymbol;
                }
            }
        }
    }
    MethodSymbol result = null;
    if (typeSymbol instanceof ClassSymbol && ((ClassSymbol) typeSymbol).getSuperclass() != null) {
        result = findMethodDeclarationInType(types, ((ClassSymbol) typeSymbol).getSuperclass().tsym, methodName,
                methodType);
    }
    if (result == null) {
        if (typeSymbol instanceof ClassSymbol && ((ClassSymbol) typeSymbol).getInterfaces() != null) {
            for (Type t : ((ClassSymbol) typeSymbol).getInterfaces()) {
                result = findMethodDeclarationInType(types, t.tsym, methodName, methodType);
                if (result != null) {
                    break;
                }
            }
        }
    }
    return result;
}

From source file:therian.buildweaver.StandardOperatorsProcessor.java

private static ExecutableElement findDefaultConstructor(TypeElement t) {
    for (Element element : t.getEnclosedElements()) {
        if (element.getKind() == ElementKind.CONSTRUCTOR) {
            ExecutableElement cs = (ExecutableElement) element;
            if (cs.getParameters().size() == 0 && cs.getModifiers().contains(Modifier.PUBLIC)) {
                return cs;
            }/*from w  ww . j  ava  2  s  . co m*/
        }
    }
    return null;
}

From source file:uniol.apt.compiler.AbstractServiceProcessor.java

private boolean isValidClass(Element ele) {
    if (ele.getKind() != ElementKind.CLASS) {
        error(ele, "Non-Class %s annotated with %s.", ele.getSimpleName().toString(),
                this.annotationClass.getCanonicalName());
    }//from  ww  w.  j  av a  2  s .co  m

    TypeElement classEle = (TypeElement) ele;

    if (!classEle.getModifiers().contains(Modifier.PUBLIC)) {
        error(classEle, "Class %s is not public.", classEle.getQualifiedName().toString());
        return false;
    }

    if (classEle.getModifiers().contains(Modifier.ABSTRACT)) {
        error(classEle, "Class %s is abstract.", classEle.getQualifiedName().toString());
        return false;
    }

    TypeMirror expected = this.types.erasure(this.elements.getTypeElement(this.interfaceName).asType());
    boolean found = false;
    for (TypeMirror actual : classEle.getInterfaces()) {
        if (this.types.isAssignable(actual, expected)) {
            found = true;
            break;
        }
    }
    if (!found) {
        error(classEle, "Class %s doesn't implement interface %s.", classEle.getQualifiedName().toString(),
                this.interfaceName);
        return false;
    }

    if (!allowGenerics && !classEle.getTypeParameters().isEmpty()) {
        error(classEle, "Class %s is generic.", classEle.getQualifiedName().toString());
        return false;
    }

    for (Element enclosed : classEle.getEnclosedElements()) {
        if (enclosed.getKind() == ElementKind.CONSTRUCTOR) {
            ExecutableElement constructorEle = (ExecutableElement) enclosed;
            if (constructorEle.getParameters().size() == 0
                    && constructorEle.getModifiers().contains(Modifier.PUBLIC)) {
                return true;
            }
        }
    }

    error(classEle, String.format("Class %s needs an public no-arg constructor",
            classEle.getQualifiedName().toString()));
    return false;
}