use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class InjectHelper method processParam.
private void processParam(Element element, T holder) {
ExecutableElement method = (ExecutableElement) element.getEnclosingElement();
List<? extends VariableElement> parameters = method.getParameters();
List<ParamHelper> parameterList = methodParameterMap.get(method);
JBlock targetBlock = methodBlockMap.get(method);
int paramCount = parameters.size();
if (parameterList == null) {
parameterList = new ArrayList<>();
methodParameterMap.put(method, parameterList);
}
if (targetBlock == null) {
targetBlock = createBlock(holder, true);
methodBlockMap.put(method, targetBlock);
}
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {
VariableElement param = parameters.get(paramIndex);
if (param.equals(element)) {
AbstractJClass type = codeModelHelper.typeMirrorToJClass(param.asType());
JVar fieldRef = targetBlock.decl(type, param.getSimpleName().toString(), getDefault(param.asType()));
handler.assignValue(targetBlock, fieldRef, holder, param, param);
parameterList.add(new ParamHelper(fieldRef, paramIndex, param));
}
}
if (parameterList.size() == paramCount) {
String methodName = method.getSimpleName().toString();
Collections.sort(parameterList);
JInvocation invocation = JExpr.invoke(methodName);
for (ParamHelper parameter : parameterList) {
invocation.arg(parameter.beanInstance);
}
targetBlock.add(invocation);
if (handler instanceof MethodInjectionHandler.AfterAllParametersInjectedHandler<?>) {
((MethodInjectionHandler.AfterAllParametersInjectedHandler<T>) handler).afterAllParametersInjected(holder, method, parameterList);
}
methodParameterMap.remove(method);
}
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method setOnViewChanged.
protected void setOnViewChanged() {
getGeneratedClass()._implements(OnViewChangedListener.class);
onViewChanged = getGeneratedClass().method(PUBLIC, getCodeModel().VOID, "onViewChanged");
onViewChanged.annotate(Override.class);
onViewChangedBody = onViewChanged.body();
onViewChangedBodyBeforeInjectionBlock = onViewChangedBody.blockVirtual();
onViewChangedBodyViewHolderBlock = onViewChangedBody.blockVirtual();
onViewChangedBodyInjectionBlock = onViewChangedBody.blockVirtual();
onViewChangedBodyAfterInjectionBlock = onViewChangedBody.blockVirtual();
onViewChangedHasViewsParam = onViewChanged.param(HasViews.class, "hasViews");
AbstractJClass notifierClass = getJClass(OnViewChangedNotifier.class);
getInitBodyInjectionBlock().staticInvoke(notifierClass, "registerOnViewChangedListener").arg(_this());
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method createOnSeekBarChangeListenerHolder.
private OnSeekBarChangeListenerHolder createOnSeekBarChangeListenerHolder(JFieldRef idRef) {
JDefinedClass onSeekbarChangeListenerClass = getCodeModel().anonymousClass(getClasses().ON_SEEKBAR_CHANGE_LISTENER);
AbstractJClass viewClass = getClasses().SEEKBAR;
FoundViewHolder foundViewHolder = getFoundViewHolder(idRef, viewClass);
foundViewHolder.getIfNotNullBlock().invoke(foundViewHolder.getRef(), "setOnSeekBarChangeListener").arg(_new(onSeekbarChangeListenerClass));
return new OnSeekBarChangeListenerHolder(this, onSeekbarChangeListenerClass);
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method createPageChangeHolder.
private PageChangeHolder createPageChangeHolder(JFieldRef idRef, TypeMirror viewParameterType, boolean hasAddOnPageChangeListenerMethod) {
JDefinedClass onPageChangeListenerClass = getCodeModel().anonymousClass(getClasses().PAGE_CHANGE_LISTENER);
AbstractJClass viewClass = getClasses().VIEW_PAGER;
if (viewParameterType != null) {
viewClass = getJClass(viewParameterType.toString());
}
JBlock onViewChangedBody = getOnViewChangedBodyInjectionBlock().blockSimple();
JVar viewVariable = onViewChangedBody.decl(FINAL, viewClass, "view", cast(viewClass, findViewById(idRef)));
JBlock block = onViewChangedBody._if(viewVariable.ne(JExpr._null()))._then();
if (hasAddOnPageChangeListenerMethod) {
block.invoke(viewVariable, "addOnPageChangeListener").arg(_new(onPageChangeListenerClass));
} else {
block.invoke(viewVariable, "setOnPageChangeListener").arg(_new(onPageChangeListenerClass));
}
return new PageChangeHolder(this, viewVariable, onPageChangeListenerClass);
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class EActivityHolder method setInit.
@Override
protected void setInit() {
init = generatedClass.method(PRIVATE, getCodeModel().VOID, "init" + generationSuffix());
AbstractJClass bundleClass = getClasses().BUNDLE;
initSavedInstanceParam = init.param(bundleClass, "savedInstanceState");
getOnCreate();
}
Aggregations