use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class FragmentArgHandler method createBuilderInjectMethod.
public void createBuilderInjectMethod(EFragmentHolder holder, Element element, List<ArgHelper> argHelpers) {
JDefinedClass builderClass = holder.getBuilderClass();
JFieldRef builderArgsField = holder.getBuilderArgsField();
JMethod builderMethod = builderClass.method(PUBLIC, holder.narrow(builderClass), element.getSimpleName().toString());
String docComment = getProcessingEnvironment().getElementUtils().getDocComment(element);
codeModelHelper.addTrimmedDocComment(builderMethod, docComment);
for (ArgHelper argHelper : argHelpers) {
String fieldName = argHelper.param.getSimpleName().toString();
TypeMirror actualType = codeModelHelper.getActualTypeOfEnclosingElementOfInjectedElement(holder, argHelper.param);
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), actualType);
JFieldVar argKeyStaticField = getOrCreateStaticArgField(holder, argHelper.argKey, fieldName);
AbstractJClass paramClass = codeModelHelper.typeMirrorToJClass(actualType);
JVar arg = builderMethod.param(paramClass, fieldName);
builderMethod.body().add(bundleHelper.getExpressionToSaveFromField(builderArgsField, argKeyStaticField, arg));
builderMethod.javadoc().addParam(fieldName).append("value for this Fragment argument");
}
builderMethod.javadoc().addReturn().append("the FragmentBuilder to chain calls");
builderMethod.body()._return(_this());
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ReceiverActionHandler method process.
@Override
public void process(Element element, EReceiverHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
String methodName = element.getSimpleName().toString();
ReceiverAction annotation = element.getAnnotation(ReceiverAction.class);
String[] dataSchemes = annotation.dataSchemes();
String[] actions = annotation.actions();
JFieldVar actionKeyField = createStaticField(holder, "actions", methodName, actions);
JFieldVar dataSchemesField = createStaticField(holder, "dataSchemes", methodName, dataSchemes);
addActionInOnReceive(holder, executableElement, methodName, actionKeyField, dataSchemesField);
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ServiceActionHandler method addActionInOnHandleIntent.
private void addActionInOnHandleIntent(EIntentServiceHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionKeyField) {
JMethod onHandleIntentMethod = holder.getOnHandleIntentMethod();
// If action match, call the method
JInvocation actionCondition = actionKeyField.invoke("equals").arg(holder.getOnHandleIntentIntentAction());
JBlock callActionBlock = holder.getOnHandleIntentBody()._if(actionCondition)._then();
JInvocation callActionInvocation = JExpr._super().invoke(methodName);
// For each method params, we get back value from extras and put it
// in super calls
List<? extends VariableElement> methodParameters = executableElement.getParameters();
if (methodParameters.size() > 0) {
// Extras
JVar intent = holder.getOnHandleIntentIntent();
JVar extras = callActionBlock.decl(getClasses().BUNDLE, "extras");
extras.init(intent.invoke("getExtras"));
callActionBlock = callActionBlock._if(extras.ne(_null()))._then();
// Extras params
for (VariableElement param : methodParameters) {
String paramName = param.getSimpleName().toString();
String extraParamName = paramName + "Extra";
JFieldVar paramVar = getStaticExtraField(holder, paramName);
AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
BundleHelper bundleHelper = new BundleHelper(getEnvironment(), param.asType());
IJExpression getExtraExpression = bundleHelper.getExpressionToRestoreFromBundle(extraParamClass, extras, paramVar, onHandleIntentMethod);
JVar extraField = callActionBlock.decl(extraParamClass, extraParamName, getExtraExpression);
callActionInvocation.arg(extraField);
}
}
callActionBlock.add(callActionInvocation);
callActionBlock._return();
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ServiceActionHandler method process.
@Override
public void process(Element element, EIntentServiceHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
String methodName = element.getSimpleName().toString();
ServiceAction annotation = element.getAnnotation(ServiceAction.class);
String extraKey = annotation.value();
if (extraKey.isEmpty()) {
extraKey = methodName;
}
JFieldVar actionKeyField = createStaticActionField(holder, extraKey, methodName);
addActionInOnHandleIntent(holder, executableElement, methodName, actionKeyField);
addActionToIntentBuilder(holder, executableElement, methodName, actionKeyField);
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class ActivityIntentBuilder method addFragmentConstructor.
private JFieldVar addFragmentConstructor(AbstractJClass fragmentClass, String fieldName) {
JFieldVar fragmentField = holder.getIntentBuilderClass().field(PRIVATE, fragmentClass, fieldName);
IJExpression generatedClass = holder.getGeneratedClass().dotclass();
JMethod constructor = holder.getIntentBuilderClass().constructor(JMod.PUBLIC);
JVar constructorFragmentParam = constructor.param(fragmentClass, "fragment");
JBlock constructorBody = constructor.body();
constructorBody.invoke("super").arg(constructorFragmentParam.invoke("getActivity")).arg(generatedClass);
constructorBody.assign(fragmentField, constructorFragmentParam);
return fragmentField;
}
Aggregations