use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class PreferenceChangeHandler method processParameters.
@Override
protected void processParameters(HasPreferences holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> userParameters) {
JVar preferenceParam = listenerMethod.param(holder.getBasePreferenceClass(), "preference");
JVar newValueParam = listenerMethod.param(getClasses().OBJECT, "newValue");
for (VariableElement variableElement : userParameters) {
String type = variableElement.asType().toString();
if (isTypeOrSubclass(CanonicalNameConstants.PREFERENCE, variableElement)) {
call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.PREFERENCE, preferenceParam, variableElement));
} else if (isTypeOrSubclass(CanonicalNameConstants.SUPPORT_V7_PREFERENCE, variableElement)) {
call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.SUPPORT_V7_PREFERENCE, preferenceParam, variableElement));
} else if (type.equals(CanonicalNameConstants.OBJECT)) {
call.arg(newValueParam);
} else if (//
type.equals(CanonicalNameConstants.INTEGER) || type.equals(int.class.getName()) || type.equals(CanonicalNameConstants.FLOAT) || //
type.equals(float.class.getName()) || type.equals(CanonicalNameConstants.LONG) || type.equals(long.class.getName())) {
AbstractJClass wrapperClass = getEnvironment().getCodeModel().parseType(type).boxify();
call.arg(wrapperClass.staticInvoke("valueOf").arg(JExpr.cast(getClasses().STRING, newValueParam)));
} else {
AbstractJClass userParamClass = codeModelHelper.typeMirrorToJClass(variableElement.asType());
call.arg(JExpr.cast(userParamClass, newValueParam));
if (type.equals(CanonicalNameConstants.STRING_SET)) {
codeModelHelper.addSuppressWarnings(listenerMethod, "unchecked");
}
}
}
}
use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class CheckedChangeHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
JVar btnParam = listenerMethod.param(getClasses().COMPOUND_BUTTON, "buttonView");
JVar isCheckedParam = listenerMethod.param(getCodeModel().BOOLEAN, "isChecked");
for (VariableElement parameter : parameters) {
String parameterType = parameter.asType().toString();
if (isTypeOrSubclass(CanonicalNameConstants.COMPOUND_BUTTON, parameter)) {
call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.COMPOUND_BUTTON, btnParam, parameter));
} else if (parameterType.equals(CanonicalNameConstants.BOOLEAN) || parameter.asType().getKind() == TypeKind.BOOLEAN) {
call.arg(isCheckedParam);
}
}
}
use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class ItemSelectHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation itemSelectedCall, List<? extends VariableElement> parameters) {
AbstractJClass narrowAdapterViewClass = getClasses().ADAPTER_VIEW.narrow(getCodeModel().wildcard());
JVar onItemClickParentParam = listenerMethod.param(narrowAdapterViewClass, "parent");
listenerMethod.param(getClasses().VIEW, "view");
JVar onItemClickPositionParam = listenerMethod.param(getCodeModel().INT, "position");
listenerMethod.param(getCodeModel().LONG, "id");
itemSelectedCall.arg(JExpr.TRUE);
boolean hasItemParameter = parameters.size() == 2;
boolean secondParameterIsInt = false;
String secondParameterQualifiedName = null;
if (hasItemParameter) {
VariableElement secondParameter = parameters.get(1);
TypeMirror secondParameterType = secondParameter.asType();
secondParameterQualifiedName = secondParameterType.toString();
secondParameterIsInt = secondParameterType.getKind() == TypeKind.INT;
}
if (hasItemParameter) {
if (secondParameterIsInt) {
itemSelectedCall.arg(onItemClickPositionParam);
} else {
itemSelectedCall.arg(JExpr.cast(getJClass(secondParameterQualifiedName), invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
}
}
onNothingSelectedMethod.param(narrowAdapterViewClass, "parent");
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation nothingSelectedCall = invoke(activityRef, getMethodName());
onNothingSelectedMethod.body().add(nothingSelectedCall);
nothingSelectedCall.arg(JExpr.FALSE);
if (hasItemParameter) {
if (secondParameterIsInt) {
nothingSelectedCall.arg(lit(-1));
} else {
nothingSelectedCall.arg(_null());
}
}
}
use of javax.lang.model.element.VariableElement 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 javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class SeekBarProgressChangeHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int seekBarViewParameterPosition = -1;
int progressParameterPosition = -1;
int fromUserParameterPosition = -1;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.SEEKBAR.equals(parameterType.toString())) {
seekBarViewParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
progressParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.BOOLEAN || CanonicalNameConstants.BOOLEAN.equals(parameterType.toString())) {
fromUserParameterPosition = i;
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
JBlock methodBody = onSeekBarChangeListenerHolder.getOnProgressChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == seekBarViewParameterPosition) {
JVar seekBarViewParameter = onSeekBarChangeListenerHolder.getOnProgressChangedSeekBarParam();
textChangeCall.arg(seekBarViewParameter);
} else if (i == progressParameterPosition) {
JVar progressParameter = onSeekBarChangeListenerHolder.getOnProgressChangedProgressParam();
textChangeCall.arg(progressParameter);
} else if (i == fromUserParameterPosition) {
JVar fromUserParameter = onSeekBarChangeListenerHolder.getOnProgressChangedFromUserParam();
textChangeCall.arg(fromUserParameter);
}
}
}
}
Aggregations