Android Open Source - PrettyBundle Extra Annotated Class






From Project

Back to project page PrettyBundle.

License

The source code is released under:

Apache License

If you think the Android project PrettyBundle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tale.prettybundle.internal;
//from w  w w . jav a 2  s .  c  o m
import com.tale.prettybundle.ExtraBinder;
import com.tale.prettybundle.ExtraBinderProvider;

import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;

/**
 * Created by tale on 2/1/15.
 */
public class ExtraAnnotatedClass {

    private final VariableElement annotatedVariableElement;
    private final String key;
    private final String qualifiedClassName;
    private String dataTypeQualifiedClassName;
    private final TypeMirror dataType;
    private ExtraBinder extraBinder;
    private SupportedType supportedType;

    public ExtraAnnotatedClass(VariableElement annotatedVariableElement, Elements elements, Types types) {
        this.annotatedVariableElement = annotatedVariableElement;
        key = annotatedVariableElement.getSimpleName().toString();
        // Get the full QualifiedTypeName
        final TypeElement parent = (TypeElement) annotatedVariableElement.getEnclosingElement();
        if (types.isSubtype(parent.asType(), elements.getTypeElement("android.app.Activity").asType())) {
            supportedType = SupportedType.ACTIVITY;
        } else if (types.isSubtype(parent.asType(), elements.getTypeElement("android.app.Service").asType())) {
            supportedType = SupportedType.SERVICE;
        } else if (types.isSubtype(parent.asType(), elements.getTypeElement("android.app.Fragment").asType())) {
            supportedType = SupportedType.FRAGMENT;
        } else {
            supportedType = SupportedType.NOP;
        }
        qualifiedClassName = parent.getQualifiedName().toString();
        // Get the full Qualified of DataType.
        dataType = annotatedVariableElement.asType();
        dataTypeQualifiedClassName = dataType.toString();
        extraBinder = ExtraBinderProvider.get(dataTypeQualifiedClassName);
        if (extraBinder != ExtraBinder.NOP) {
            return;
        }
        // Check if data type is kind of Parcelable.
        if (types.isSubtype(dataType, elements.getTypeElement("android.os.Parcelable").asType())) {
            extraBinder = ExtraBinderProvider.get("android.os.Parcelable");
            if (extraBinder != ExtraBinder.NOP) {
                return;
            }
        }

        try {
            // Check if data type is kind of Array.
            dataTypeQualifiedClassName = ((ArrayType) dataType).getComponentType().toString();
            final TypeMirror componentTypeMirror = elements.getTypeElement(dataTypeQualifiedClassName).asType();
            if (types.isSubtype(componentTypeMirror, elements.getTypeElement("android.os.Parcelable").asType())) {
                extraBinder = ExtraBinderProvider.get("android.os.Parcelable[]");
                if (extraBinder != ExtraBinder.NOP) {
                    return;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public SupportedType getSupportedType() {
        return supportedType;
    }

    public VariableElement getAnnotatedVariableElement() {
        return annotatedVariableElement;
    }

    public String getKey() {
        return key;
    }

    public ExtraBinder getExtraBinder() {
        return extraBinder;
    }

    public String getDataTypeQualifiedClassName() {
        return dataTypeQualifiedClassName;
    }

    public String getQualifiedClassName() {
        return qualifiedClassName;
    }

    public TypeMirror getDataType() {
        return dataType;
    }
}




Java Source Code List

com.tale.prettybundle.ExtraBinderProvider.java
com.tale.prettybundle.ExtraBinder.java
com.tale.prettybundle.Extra.java
com.tale.prettybundle.Injector.java
com.tale.prettybundle.PrettyBundle.java
com.tale.prettybundle.internal.ExtraAnnotatedClass.java
com.tale.prettybundle.internal.ExtraClassesGrouped.java
com.tale.prettybundle.internal.ExtraInjectorClassBuilder.java
com.tale.prettybundle.internal.ExtraUtilityClassBuilder.java
com.tale.prettybundle.internal.PrettyBundleProcessor.java
com.tale.prettybundle.internal.SupportedType.java
com.tale.prettybundle.sample.ActivitiesClassTest.java
com.tale.prettybundle.sample.ActivitiesTest.java
com.tale.prettybundle.sample.ApplicationTest.java
com.tale.prettybundle.sample.BaseActivityUnitTestCase.java
com.tale.prettybundle.sample.InjectArrayExtrasTest.java
com.tale.prettybundle.sample.InjectParcelableExtrasTest.java
com.tale.prettybundle.sample.InjectPrimaryTypeExtrasFragmentTest.java
com.tale.prettybundle.sample.InjectPrimaryTypeExtrasTest.java
com.tale.prettybundle.sample.InjectStringExtrasTest.java
com.tale.prettybundle.sample.MainActivity.java
com.tale.prettybundle.sample.MenuActivity.java
com.tale.prettybundle.sample.TestArrayExtrasActivity.java
com.tale.prettybundle.sample.TestExtraOnFragmentActivity.java
com.tale.prettybundle.sample.TestParcelableActivity.java
com.tale.prettybundle.sample.TestPrimaryTypeDisplayActivity.java
com.tale.prettybundle.sample.TestPrimaryTypeSetterActivity.java
com.tale.prettybundle.sample.TestStringExtra1Activity.java
com.tale.prettybundle.sample.TestStringExtra2Activity.java
com.tale.prettybundle.sample.data.Person.java
com.tale.prettybundle.sample.espresso.ExtViewActions.java
com.tale.prettybundle.sample.fragments.TestPrimaryExtraFragment.java
com.tale.prettybundle.sample.services.TestPrimaryTypeService.java