Search in sources :

Example 71 with Element

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

the class NonConfigurationInstanceHandler method rebindContextIfBean.

private void rebindContextIfBean(Element element, JBlock initIfNonConfigurationNotNullBlock, JFieldVar field) {
    boolean hasBeanAnnotation = element.getAnnotation(Bean.class) != null;
    if (hasBeanAnnotation) {
        TypeMirror elementType = annotationHelper.extractAnnotationClassParameter(element, Bean.class.getName());
        if (elementType == null) {
            elementType = element.asType();
        }
        String typeQualifiedName = elementType.toString();
        AbstractJClass fieldGeneratedBeanClass = getJClass(typeQualifiedName + classSuffix());
        // do not generate rebind call for singleton beans
        Element eBeanTypeElement = annotationHelper.getTypeUtils().asElement(elementType);
        EBean eBean = eBeanTypeElement.getAnnotation(EBean.class);
        if (eBean != null && eBean.scope() != EBean.Scope.Singleton) {
            initIfNonConfigurationNotNullBlock.invoke(cast(fieldGeneratedBeanClass, field), "rebind").arg(_this());
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Element(javax.lang.model.element.Element) AbstractJClass(com.helger.jcodemodel.AbstractJClass) EBean(org.androidannotations.annotations.EBean) EBean(org.androidannotations.annotations.EBean) Bean(org.androidannotations.annotations.Bean)

Example 72 with Element

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

the class ExtraHandler method afterAllParametersInjected.

@Override
public void afterAllParametersInjected(EActivityHolder holder, ExecutableElement method, List<InjectHelper.ParamHelper> parameterList) {
    List<IntentBuilder.IntentExtra> params = new ArrayList<>();
    for (InjectHelper.ParamHelper paramHelper : parameterList) {
        Element param = paramHelper.getParameterElement();
        String fieldName = param.getSimpleName().toString();
        String extraKey = extractExtraKey(param, fieldName);
        JFieldVar extraKeyStaticField = getOrCreateStaticExtraField(holder, extraKey, fieldName);
        params.add(new IntentBuilder.IntentExtra(param.asType(), fieldName, extraKeyStaticField));
    }
    holder.getIntentBuilder().getPutExtraMethod(method, params);
}
Also used : InjectHelper(org.androidannotations.helper.InjectHelper) JFieldVar(com.helger.jcodemodel.JFieldVar) IntentBuilder(org.androidannotations.internal.core.helper.IntentBuilder) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList)

Example 73 with Element

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

the class FragmentArgHandler method afterAllParametersInjected.

@Override
public void afterAllParametersInjected(EFragmentHolder holder, ExecutableElement method, List<InjectHelper.ParamHelper> parameterList) {
    List<ArgHelper> argHelpers = new ArrayList<>();
    for (InjectHelper.ParamHelper paramHelper : parameterList) {
        Element param = paramHelper.getParameterElement();
        String fieldName = param.getSimpleName().toString();
        String argKey = extractArgKey(param, fieldName);
        argHelpers.add(new ArgHelper(param, argKey));
    }
    createBuilderInjectMethod(holder, method, argHelpers);
}
Also used : InjectHelper(org.androidannotations.helper.InjectHelper) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList)

Example 74 with Element

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

the class AndroidAnnotationProcessor method handleException.

private void handleException(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv, ProcessingException e) {
    String errorMessage = errorHelper.getErrorMessage(processingEnv, e, coreVersion);
    /*
		 * Printing exception as an error on a random element. The exception is
		 * not related to this element, but otherwise it wouldn't show up in
		 * eclipse.
		 */
    Iterator<? extends TypeElement> iterator = annotations.iterator();
    if (iterator.hasNext()) {
        Element element = roundEnv.getElementsAnnotatedWith(iterator.next()).iterator().next();
        LOGGER.error("Something went wrong: {}", element, errorMessage);
    } else {
        LOGGER.error("Something went wrong: {}", errorMessage);
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element)

Example 75 with Element

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

the class AbstractResHandler method validate.

@Override
public final void validate(Element element, ElementValidation validation) {
    injectHelper.validate(androidRes.getAnnotationClass(), element, validation);
    if (!validation.isValid()) {
        return;
    }
    validatorHelper.allowedType(element, androidRes.getAllowedTypes(), validation);
    validatorHelper.resIdsExist(element, androidRes.getRInnerClass(), IdValidatorHelper.FallbackStrategy.USE_ELEMENT_NAME, validation);
    Element enclosingElement = element.getEnclosingElement();
    if (element instanceof VariableElement && enclosingElement instanceof ExecutableElement) {
        validatorHelper.isNotPrivate(enclosingElement, validation);
    } else {
        validatorHelper.isNotPrivate(element, validation);
    }
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement)

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