Search in sources :

Example 36 with ExecutableElement

use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.

the class ValidatorHelper method findTargetElement.

Element findTargetElement(Element element, ElementValidation valid) {
    if (element instanceof ExecutableElement) {
        ExecutableElement executableElement = (ExecutableElement) element;
        returnTypeIsVoid(executableElement, valid);
        if (!valid.isValid()) {
            return null;
        }
        List<? extends VariableElement> parameters = executableElement.getParameters();
        if (parameters.size() != 1) {
            valid.addError("The method can only have 1 parameter");
            return null;
        }
        return parameters.get(0);
    }
    return element;
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 37 with ExecutableElement

use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.

the class ValidatorHelper method allowedType.

public void allowedType(Element element, List<String> allowedTypes, ElementValidation valid) {
    String qualifiedName;
    Element enclosingElement = element.getEnclosingElement();
    if (element instanceof VariableElement && enclosingElement instanceof ExecutableElement) {
        qualifiedName = element.asType().toString();
    } else if (element instanceof ExecutableElement) {
        element = ((ExecutableElement) element).getParameters().get(0);
        qualifiedName = element.asType().toString();
    } else {
        qualifiedName = element.asType().toString();
    }
    if (!allowedTypes.contains(qualifiedName)) {
        valid.addError("%s can only be used on a field which is a " + allowedTypes.toString() + ", not " + qualifiedName);
    }
}
Also used : VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement)

Example 38 with ExecutableElement

use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.

the class EBeanHolder method setConstructor.

private void setConstructor() {
    constructor = generatedClass.constructor(PRIVATE);
    JVar constructorContextParam = constructor.param(getClasses().CONTEXT, "context");
    JBlock constructorBody = constructor.body();
    List<ExecutableElement> constructors = ElementFilter.constructorsIn(annotatedElement.getEnclosedElements());
    ExecutableElement superConstructor = constructors.get(0);
    if (superConstructor.getParameters().size() == 1) {
        constructorBody.invoke("super").arg(constructorContextParam);
    }
    constructorBody.assign(getContextField(), constructorContextParam);
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 39 with ExecutableElement

use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.

the class RestAnnotationHelper method getResponseClass.

public IJExpression getResponseClass(Element element, RestHolder holder) {
    ExecutableElement executableElement = (ExecutableElement) element;
    IJExpression responseClassExpr = nullCastedToNarrowedClass(holder);
    TypeMirror returnType = executableElement.getReturnType();
    if (returnType.getKind() != TypeKind.VOID) {
        if (getElementUtils().getTypeElement(RestSpringClasses.PARAMETERIZED_TYPE_REFERENCE) != null) {
            if (returnType.toString().startsWith(RestSpringClasses.RESPONSE_ENTITY)) {
                List<? extends TypeMirror> typeArguments = ((DeclaredType) returnType).getTypeArguments();
                if (!typeArguments.isEmpty()) {
                    returnType = typeArguments.get(0);
                }
            }
            if (checkIfParameterizedTypeReferenceShouldBeUsed(returnType)) {
                return createParameterizedTypeReferenceAnonymousSubclassInstance(returnType);
            }
        }
        AbstractJClass responseClass = retrieveResponseClass(returnType, holder);
        if (responseClass != null) {
            responseClassExpr = responseClass.dotclass();
        }
    }
    return responseClassExpr;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) DeclaredType(javax.lang.model.type.DeclaredType)

Example 40 with ExecutableElement

use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.

the class AbstractOttoHandler method process.

@Override
public void process(Element element, EComponentHolder holder) throws Exception {
    if (!annotationHelper.enclosingElementHasEnhancedComponentAnnotation(element)) {
        // do nothing when otto annotations are used in non-enhanced classes
        return;
    }
    ExecutableElement executableElement = (ExecutableElement) element;
    JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
    addOttoAnnotation(executableElement, method);
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) JMethod(com.helger.jcodemodel.JMethod)

Aggregations

ExecutableElement (javax.lang.model.element.ExecutableElement)345 TypeElement (javax.lang.model.element.TypeElement)158 TypeMirror (javax.lang.model.type.TypeMirror)97 VariableElement (javax.lang.model.element.VariableElement)85 Element (javax.lang.model.element.Element)72 Test (org.junit.Test)41 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)32 DeclaredType (javax.lang.model.type.DeclaredType)31 ArrayList (java.util.ArrayList)26 JBlock (com.helger.jcodemodel.JBlock)25 JInvocation (com.helger.jcodemodel.JInvocation)20 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)18 JVar (com.helger.jcodemodel.JVar)18 Map (java.util.Map)18 HashSet (java.util.HashSet)17 IJExpression (com.helger.jcodemodel.IJExpression)16 ElementValidation (org.androidannotations.ElementValidation)15 Block (com.google.devtools.j2objc.ast.Block)13 JMethod (com.helger.jcodemodel.JMethod)13 Elements (javax.lang.model.util.Elements)13