use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class AnnotationArrayParamExtractor method visitType.
@Override
public Void visitType(TypeMirror t, JAnnotationArrayMember p) {
AbstractJClass annotationClass = helper.typeMirrorToJClass(t);
p.param(annotationClass);
return null;
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class ReceiverActionHandler method addActionInOnReceive.
private void addActionInOnReceive(EReceiverHolder holder, ExecutableElement executableElement, String methodName, JFieldVar actionsField, JFieldVar dataSchemesField) {
String actionsInvoke = getInvocationName(actionsField);
IJExpression filterCondition = actionsField.invoke(actionsInvoke).arg(holder.getOnReceiveIntentAction());
if (dataSchemesField != null) {
String dataSchemesInvoke = getInvocationName(dataSchemesField);
filterCondition = filterCondition.cand(dataSchemesField.invoke(dataSchemesInvoke).arg(holder.getOnReceiveIntentDataScheme()));
}
JBlock callActionBlock = holder.getOnReceiveBody()._if(filterCondition)._then();
IJExpression receiverRef = holder.getGeneratedClass().staticRef("this");
JInvocation callActionInvocation = receiverRef.invoke(methodName);
JVar intent = holder.getOnReceiveIntent();
JVar extras = null;
List<? extends VariableElement> methodParameters = executableElement.getParameters();
for (VariableElement param : methodParameters) {
AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType());
if (extraParamClass.equals(getClasses().CONTEXT)) {
callActionInvocation.arg(holder.getOnReceiveContext());
} else if (extraParamClass.equals(getClasses().INTENT) && param.getAnnotation(ReceiverAction.Extra.class) == null) {
callActionInvocation.arg(intent);
} else if (param.getAnnotation(ReceiverAction.Extra.class) != null) {
if (extras == null) {
extras = callActionBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(//
intent.invoke("getExtras").ne(_null()), intent.invoke("getExtras"), _new(getClasses().BUNDLE)));
}
callActionInvocation.arg(extraHandler.getExtraValue(param, extras, callActionBlock, holder));
}
}
callActionBlock.add(callActionInvocation);
callActionBlock._return();
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class ReceiverActionHandler method createStaticField.
private JFieldVar createStaticField(EReceiverHolder holder, String prefix, String methodName, String[] values) {
String staticFieldName = CaseHelper.camelCaseToUpperSnakeCase(prefix, methodName, null);
if (values == null || values.length == 0) {
return null;
} else if (values.length == 1) {
return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, getClasses().STRING, staticFieldName, lit(values[0]));
}
JInvocation asListInvoke = getClasses().ARRAYS.staticInvoke("asList");
for (String scheme : values) {
asListInvoke.arg(scheme);
}
AbstractJClass listOfStrings = getClasses().LIST.narrow(getClasses().STRING);
return holder.getGeneratedClass().field(PUBLIC | STATIC | FINAL, listOfStrings, staticFieldName, asListInvoke);
}
use of com.helger.jcodemodel.AbstractJClass 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.AbstractJClass in project androidannotations by androidannotations.
the class ProcessHolder method refClass.
public AbstractJClass refClass(String fullyQualifiedClassName) {
int arrayCounter = 0;
while (fullyQualifiedClassName.endsWith("[]")) {
arrayCounter++;
fullyQualifiedClassName = fullyQualifiedClassName.substring(0, fullyQualifiedClassName.length() - 2);
}
AbstractJClass refClass = loadedClasses.get(fullyQualifiedClassName);
if (refClass == null) {
refClass = codeModel.directClass(fullyQualifiedClassName);
loadedClasses.put(fullyQualifiedClassName, refClass);
}
for (int i = 0; i < arrayCounter; i++) {
refClass = refClass.array();
}
return refClass;
}
Aggregations