Search in sources :

Example 1 with Receiver

use of org.androidannotations.annotations.Receiver in project androidannotations by androidannotations.

the class ReceiverHandler method process.

@Override
public void process(Element element, HasReceiverRegistration holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    String receiverName = methodName + "Receiver" + generationSuffix();
    Receiver annotation = element.getAnnotation(Receiver.class);
    String[] actions = annotation.actions();
    String[] dataSchemes = annotation.dataSchemes();
    Receiver.RegisterAt registerAt = annotation.registerAt();
    boolean local = annotation.local();
    JFieldVar intentFilterField = holder.getIntentFilterField(new IntentFilterData(actions, dataSchemes, registerAt));
    JFieldVar receiverField = createReceiverField(holder, receiverName, methodName, (ExecutableElement) element);
    registerAndUnregisterReceiver(holder, registerAt, intentFilterField, receiverField, local);
}
Also used : IntentFilterData(org.androidannotations.holder.ReceiverRegistrationDelegate.IntentFilterData) JFieldVar(com.helger.jcodemodel.JFieldVar) Receiver(org.androidannotations.annotations.Receiver)

Example 2 with Receiver

use of org.androidannotations.annotations.Receiver in project androidannotations by androidannotations.

the class CoreValidatorHelper method hasRightRegisterAtValueDependingOnEnclosingElement.

public void hasRightRegisterAtValueDependingOnEnclosingElement(Element element, ElementValidation valid) {
    Element enclosingElement = element.getEnclosingElement();
    Receiver.RegisterAt registerAt = element.getAnnotation(Receiver.class).registerAt();
    Map<String, List<Receiver.RegisterAt>> validRegisterAts = new HashMap<>();
    validRegisterAts.put(CanonicalNameConstants.ACTIVITY, VALID_ACTIVITY_REGISTER_AT);
    validRegisterAts.put(CanonicalNameConstants.SERVICE, VALID_SERVICE_REGISTER_AT);
    validRegisterAts.put(CanonicalNameConstants.FRAGMENT, VALID_FRAGMENT_REGISTER_AT);
    validRegisterAts.put(CanonicalNameConstants.VIEW, VALID_VIEW_REGISTER_AT);
    for (Map.Entry<String, List<Receiver.RegisterAt>> validRegisterAt : validRegisterAts.entrySet()) {
        String enclosingType = validRegisterAt.getKey();
        Collection<Receiver.RegisterAt> validRegisterAtValues = validRegisterAt.getValue();
        if (extendsType(enclosingElement, enclosingType) && !validRegisterAtValues.contains(registerAt)) {
            valid.addError("The parameter registerAt of @Receiver in " + enclosingType + " can only be one of the following values : " + validRegisterAtValues);
        }
    }
}
Also used : HashMap(java.util.HashMap) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) Receiver(org.androidannotations.annotations.Receiver) List(java.util.List) DefaultString(org.androidannotations.annotations.sharedpreferences.DefaultString) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Receiver (org.androidannotations.annotations.Receiver)2 JFieldVar (com.helger.jcodemodel.JFieldVar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 DefaultString (org.androidannotations.annotations.sharedpreferences.DefaultString)1 IntentFilterData (org.androidannotations.holder.ReceiverRegistrationDelegate.IntentFilterData)1