Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dce66fb
add InjectHelper
dodgex Sep 20, 2015
077e8d5
add compile time test for InjectHelper
dodgex Oct 11, 2015
9772deb
allow to inject @EBean's into an @Bean annotated method
dodgex Sep 20, 2015
3068d53
add test for method injected beans
dodgex Sep 20, 2015
5169a33
allow to inject system services into @SystemServices annotated methods
dodgex Dec 16, 2015
d22b612
add test for method injected system services
dodgex Sep 20, 2015
dc0a2ca
allow to inject resources into @*Res annotated method
dodgex Sep 24, 2015
fca69f6
add test for method injected resources
dodgex Sep 24, 2015
0dd6534
allow to inject shared preferences into @Pref annotated method
dodgex Sep 24, 2015
d91e71d
add test for method injected shared preferences
dodgex Sep 24, 2015
2137099
allow to inject application class into @App annotated method
dodgex Sep 25, 2015
81e5da4
add test for method injected application class
dodgex Sep 25, 2015
a97b8ad
allow to inject https client into @HttpsClient annotated method
dodgex Sep 25, 2015
73b994d
add test for method injected https clients
dodgex Sep 25, 2015
4801b0d
allow to inject extras into @Extra annotated method
dodgex Sep 26, 2015
4d9d2fc
add test for method injected extras
dodgex Sep 26, 2015
804bff7
allow to inject fragment arguments into @FragmentArg annotated method
dodgex Sep 26, 2015
bd8f4c1
add test for method injected fragment args
dodgex Sep 26, 2015
dc0c5f7
allow to inject context into @RootContext annotated method
dodgex Sep 26, 2015
dfec37e
add test for method injected context
dodgex Sep 26, 2015
6c2765d
allow to inject menu into @InjectMenu annotated method
dodgex Sep 26, 2015
a7affe7
add test for method injected menus
dodgex Sep 26, 2015
85197fd
allow to inject menu items into @OptionsMenuItem annotated method
dodgex Sep 26, 2015
8813c6b
add test for method injected menu items
dodgex Sep 26, 2015
63343c7
allow to inject fragments into @FragmentById or @FragmentByTag annota…
dodgex Sep 26, 2015
9d796cd
add test for method injected fragments
dodgex Sep 26, 2015
cade871
allow to inject views into @ViewById annotated methods
dodgex Oct 11, 2015
bbda8a1
add test for method injected views
dodgex Oct 11, 2015
161f128
allow to inject lists of views into @ViewsById annotated methods
dodgex Oct 11, 2015
4e1ba9d
add test for method injected lists of views
dodgex Oct 11, 2015
27ea853
allow to inject preferences into @PreferenceByKey annotated methods
dodgex Oct 11, 2015
9121bfc
add test for method injected preferences
dodgex Oct 11, 2015
7d0c59e
allow to inject ormlite daos into @OrmLiteDao annotated methods
dodgex Oct 11, 2015
a3256f4
add test for method injected ormlite daos
dodgex Dec 18, 2015
40b6f7d
allow to inject rest service into @RestService annotated methods
dodgex Oct 11, 2015
4396b44
add test for method injected rest services
dodgex Dec 18, 2015
c7d182d
update javadocs for method injection
dodgex Dec 14, 2015
a2f3bfd
generate only one method in Fragment-/IntentBuilder for methods with …
dodgex Dec 20, 2015
1c2575c
use the view field for FoundViewHolder
dodgex Dec 20, 2015
03bf6bb
use the preference field for FoundPreferenceHolder
dodgex Dec 20, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow to inject views into @ViewById annotated methods
  • Loading branch information
dodgex committed Dec 20, 2015
commit cade8710f918fe034755c6b26d090180003a9e74
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* @see AfterViews
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
public @interface ViewById {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,6 @@ public JInvocation findViewById(JFieldRef idRef) {
return findViewById;
}

public void processViewById(JFieldRef idRef, AbstractJClass viewClass, JFieldRef fieldRef) {
assignFindViewById(idRef, viewClass, fieldRef);
}

public void assignFindViewById(JFieldRef idRef, AbstractJClass viewClass, JFieldRef fieldRef) {
String idRefString = idRef.name();
FoundViewHolder foundViewHolder = (FoundViewHolder) foundHolders.get(idRefString);

JBlock block = getOnViewChangedBodyInjectionBlock();
IJExpression assignExpression;

if (foundViewHolder != null) {
assignExpression = foundViewHolder.getOrCastRef(viewClass);
} else {
assignExpression = findViewById(idRef);
if (viewClass != null && viewClass != getClasses().VIEW) {
assignExpression = cast(viewClass, assignExpression);

if (viewClass.isParameterized()) {
codeModelHelper.addSuppressWarnings(onViewChanged, "unchecked");
}
}
foundHolders.put(idRefString, new FoundViewHolder(this, viewClass, fieldRef, block));
}

block.assign(fieldRef, assignExpression);
}

public FoundViewHolder getFoundViewHolder(JFieldRef idRef, AbstractJClass viewClass) {
String idRefString = idRef.name();
FoundViewHolder foundViewHolder = (FoundViewHolder) foundHolders.get(idRefString);
Expand All @@ -166,16 +138,19 @@ public FoundViewHolder getFoundViewHolder(JFieldRef idRef, AbstractJClass viewCl

protected FoundViewHolder createFoundViewAndIfNotNullBlock(JFieldRef idRef, AbstractJClass viewClass) {
IJExpression findViewExpression = findViewById(idRef);
JBlock block = getOnViewChangedBodyInjectionBlock().blockSimple();
JBlock block = getOnViewChangedBodyBeforeInjectionBlock();

if (viewClass == null) {
viewClass = getClasses().VIEW;
} else if (viewClass != getClasses().VIEW) {
findViewExpression = cast(viewClass, findViewExpression);
}

JVar view = block.decl(viewClass, "view", findViewExpression);
return new FoundViewHolder(this, viewClass, view, block);
JVar view = block.decl(viewClass, "view_" + idRef.name(), findViewExpression);
if (viewClass.isParameterized()) {
codeModelHelper.addSuppressWarnings(view, "unchecked");
}
return new FoundViewHolder(this, viewClass, view, getOnViewChangedBodyInjectionBlock());
}

public JMethod getFindNativeFragmentById() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,7 @@ private JBlock getOnDestroyViewAfterSuperBlock() {
return onDestroyViewAfterSuperBlock;
}

@Override
public void processViewById(JFieldRef idRef, AbstractJClass viewClass, JFieldRef fieldRef) {
super.processViewById(idRef, viewClass, fieldRef);
clearInjectedView(fieldRef);
}

private void clearInjectedView(JFieldRef fieldRef) {
public void clearInjectedView(JFieldRef fieldRef) {
JBlock block = getOnDestroyViewAfterSuperBlock();
block.assign(fieldRef, _null());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,35 @@
import org.androidannotations.ElementValidation;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.handler.MethodInjectionHandler;
import org.androidannotations.helper.IdValidatorHelper;
import org.androidannotations.helper.InjectHelper;
import org.androidannotations.holder.EComponentWithViewSupportHolder;
import org.androidannotations.holder.EFragmentHolder;
import org.androidannotations.rclass.IRClass;

import com.helger.jcodemodel.AbstractJClass;
import com.helger.jcodemodel.IJAssignmentTarget;
import com.helger.jcodemodel.JBlock;
import com.helger.jcodemodel.JFieldRef;

public class ViewByIdHandler extends BaseAnnotationHandler<EComponentWithViewSupportHolder> {
public class ViewByIdHandler extends BaseAnnotationHandler<EComponentWithViewSupportHolder>implements MethodInjectionHandler<EComponentWithViewSupportHolder> {

private final InjectHelper<EComponentWithViewSupportHolder> injectHelper;

public ViewByIdHandler(AndroidAnnotationsEnvironment environment) {
super(ViewById.class, environment);
injectHelper = new InjectHelper<>(validatorHelper, this);
}

@Override
public void validate(Element element, ElementValidation validation) {
validatorHelper.enclosingElementHasEnhancedViewSupportAnnotation(element, validation);
injectHelper.validate(ViewById.class, element, validation);

validatorHelper.isDeclaredType(element, validation);
Element param = injectHelper.getParam(element);
validatorHelper.isDeclaredType(param, validation);

validatorHelper.extendsView(element, validation);
validatorHelper.extendsView(param, validation);

validatorHelper.resIdsExist(element, IRClass.Res.ID, IdValidatorHelper.FallbackStrategy.USE_ELEMENT_NAME, validation);

Expand All @@ -52,14 +61,30 @@ public void validate(Element element, ElementValidation validation) {

@Override
public void process(Element element, EComponentWithViewSupportHolder holder) {
String fieldName = element.getSimpleName().toString();
injectHelper.process(element, holder);
if (holder instanceof EFragmentHolder) {
String fieldName = element.getSimpleName().toString();
((EFragmentHolder) holder).clearInjectedView(ref(fieldName));
}
}

TypeMirror uiFieldTypeMirror = element.asType();
@Override
public JBlock getInvocationBlock(EComponentWithViewSupportHolder holder) {
return holder.getOnViewChangedBodyInjectionBlock();
}

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentWithViewSupportHolder holder, Element element, Element param) {
TypeMirror uiFieldTypeMirror = param.asType();

JFieldRef idRef = annotationHelper.extractOneAnnotationFieldRef(element, IRClass.Res.ID, true);
AbstractJClass viewClass = codeModelHelper.typeMirrorToJClass(uiFieldTypeMirror);
JFieldRef fieldRef = ref(fieldName);

holder.processViewById(idRef, viewClass, fieldRef);
targetBlock.add(fieldRef.assign(holder.getFoundViewHolder(idRef, viewClass).getOrCastRef(viewClass)));
}

@Override
public void validateEnclosingElement(Element element, ElementValidation valid) {
validatorHelper.enclosingElementHasEnhancedViewSupportAnnotation(element, valid);
}
}