Search in sources :

Example 76 with Element

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

the class AppHandler method validate.

@Override
public void validate(Element element, ElementValidation validation) {
    injectHelper.validate(App.class, element, validation);
    if (!validation.isValid()) {
        return;
    }
    validatorHelper.isNotPrivate(element, validation);
    Element param = injectHelper.getParam(element);
    validatorHelper.typeHasAnnotation(EApplication.class, param, validation);
}
Also used : Element(javax.lang.model.element.Element)

Example 77 with Element

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

the class InjectMenuHandler method validate.

@Override
public void validate(Element element, ElementValidation valid) {
    injectHelper.validate(InjectMenu.class, element, valid);
    if (!valid.isValid()) {
        return;
    }
    Element param = injectHelper.getParam(element);
    validatorHelper.isDeclaredType(param, valid);
    validatorHelper.extendsMenu(param, valid);
    validatorHelper.isNotPrivate(element, valid);
}
Also used : Element(javax.lang.model.element.Element)

Example 78 with Element

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

the class RootContextHandler method validate.

@Override
public void validate(Element element, ElementValidation validation) {
    injectHelper.validate(RootContext.class, element, validation);
    if (!validation.isValid()) {
        return;
    }
    Element param = injectHelper.getParam(element);
    validatorHelper.extendsContext(param, validation);
    validatorHelper.isNotPrivate(element, validation);
}
Also used : Element(javax.lang.model.element.Element)

Example 79 with Element

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

the class CoreValidatorHelper method isSharedPreference.

public void isSharedPreference(Element element, ElementValidation valid) {
    TypeMirror type = element.asType();
    if (element instanceof ExecutableElement) {
        element = ((ExecutableElement) element).getParameters().get(0);
        type = element.asType();
    }
    /*
		 * The type is not available yet because it has just been generated
		 */
    if (type instanceof ErrorType || type.getKind() == TypeKind.ERROR) {
        String elementTypeName = type.toString();
        boolean sharedPrefValidatedInRound = false;
        if (elementTypeName.endsWith(classSuffix())) {
            String prefTypeName = elementTypeName.substring(0, elementTypeName.length() - classSuffix().length());
            prefTypeName = prefTypeName.replace(classSuffix() + ".", ".");
            Set<? extends Element> sharedPrefElements = validatedModel().getRootAnnotatedElements(SharedPref.class.getName());
            for (Element sharedPrefElement : sharedPrefElements) {
                TypeElement sharedPrefTypeElement = (TypeElement) sharedPrefElement;
                String sharedPrefQualifiedName = sharedPrefTypeElement.getQualifiedName().toString();
                if (sharedPrefQualifiedName.endsWith(prefTypeName)) {
                    sharedPrefValidatedInRound = true;
                    break;
                }
            }
        }
        if (!sharedPrefValidatedInRound) {
            valid.invalidate();
        }
    } else {
        extendsType(element, SharedPreferencesHelper.class.getName(), valid);
    }
}
Also used : ErrorType(javax.lang.model.type.ErrorType) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) DefaultString(org.androidannotations.annotations.sharedpreferences.DefaultString) SharedPref(org.androidannotations.annotations.sharedpreferences.SharedPref) SharedPreferencesHelper(org.androidannotations.api.sharedpreferences.SharedPreferencesHelper)

Example 80 with Element

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

the class ModelProcessor method generateElements.

@SuppressWarnings({ "unchecked", "rawtypes" })
private boolean generateElements(AnnotationElements validatedModel, ProcessHolder processHolder) throws Exception {
    boolean isElementRemaining = false;
    for (GeneratingAnnotationHandler generatingAnnotationHandler : environment.getGeneratingHandlers()) {
        if (!generatingAnnotationHandler.isEnabled()) {
            continue;
        }
        String annotationName = generatingAnnotationHandler.getTarget();
        Set<? extends Element> annotatedElements = validatedModel.getRootAnnotatedElements(annotationName);
        if (!annotatedElements.isEmpty()) {
            LOGGER.debug("Processing root elements {}: {}", generatingAnnotationHandler.getClass().getSimpleName(), annotatedElements);
        }
        for (Element annotatedElement : annotatedElements) {
            /*
				 * We do not generate code for abstract classes, because the
				 * generated classes are final anyway (we do not want anyone to
				 * extend them).
				 */
            if (!isAbstractClass(annotatedElement)) {
                if (processHolder.getGeneratedClassHolder(annotatedElement) == null) {
                    TypeElement typeElement = (TypeElement) annotatedElement;
                    Element enclosingElement = annotatedElement.getEnclosingElement();
                    if (typeElement.getNestingKind() == NestingKind.MEMBER && processHolder.getGeneratedClassHolder(enclosingElement) == null) {
                        isElementRemaining = true;
                    } else {
                        GeneratedClassHolder generatedClassHolder = generatingAnnotationHandler.createGeneratedClassHolder(environment, typeElement);
                        processHolder.put(annotatedElement, generatedClassHolder);
                        generatingAnnotationHandler.process(annotatedElement, generatedClassHolder);
                    }
                }
            } else {
                LOGGER.trace("Skip element {} because it's abstract", annotatedElement);
            }
        }
    /*
			 * We currently do not take into account class annotations from
			 * ancestors. We should careful design the priority rules first.
			 */
    }
    return isElementRemaining;
}
Also used : GeneratedClassHolder(org.androidannotations.holder.GeneratedClassHolder) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) GeneratingAnnotationHandler(org.androidannotations.handler.GeneratingAnnotationHandler)

Aggregations

Element (javax.lang.model.element.Element)286 TypeElement (javax.lang.model.element.TypeElement)227 ExecutableElement (javax.lang.model.element.ExecutableElement)148 VariableElement (javax.lang.model.element.VariableElement)96 TypeMirror (javax.lang.model.type.TypeMirror)68 PackageElement (javax.lang.model.element.PackageElement)48 ArrayList (java.util.ArrayList)39 DeclaredType (javax.lang.model.type.DeclaredType)30 IOException (java.io.IOException)29 Map (java.util.Map)26 HashSet (java.util.HashSet)23 LinkedHashSet (java.util.LinkedHashSet)22 List (java.util.List)22 Set (java.util.Set)22 Test (org.junit.Test)21 ElementKind (javax.lang.model.element.ElementKind)20 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Elements (javax.lang.model.util.Elements)18 HashMap (java.util.HashMap)16 LinkedHashMap (java.util.LinkedHashMap)15