use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class OnActivityResultHandler method process.
@Override
public void process(Element element, HasOnActivityResult holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int requestCode = executableElement.getAnnotation(OnActivityResult.class).value();
JBlock onResultBlock = holder.getOnActivityResultCaseBlock(requestCode).blockSimple();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation onResultInvocation = JExpr.invoke(activityRef, methodName);
JVar intent = holder.getOnActivityResultDataParam();
JVar extras = null;
for (VariableElement parameter : parameters) {
TypeMirror parameterType = parameter.asType();
if (parameter.getAnnotation(OnActivityResult.Extra.class) != null) {
if (extras == null) {
extras = onResultBlock.decl(getClasses().BUNDLE, "extras_", JOp.cond(intent.ne(_null()).cand(intent.invoke("getExtras").ne(_null())), intent.invoke("getExtras"), _new(getClasses().BUNDLE)));
}
IJExpression extraParameter = extraHandler.getExtraValue(parameter, extras, onResultBlock, holder);
onResultInvocation.arg(extraParameter);
} else if (CanonicalNameConstants.INTENT.equals(parameterType.toString())) {
onResultInvocation.arg(intent);
} else if (//
parameterType.getKind().equals(TypeKind.INT) || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
onResultInvocation.arg(holder.getOnActivityResultResultCodeParam());
}
}
onResultBlock.add(onResultInvocation);
}
use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class EditorActionHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> userParameters) {
JVar textView = listenerMethod.param(getClasses().TEXT_VIEW, "textView");
JVar actionId = listenerMethod.param(getCodeModel().INT, "actionId");
JVar event = listenerMethod.param(getClasses().KEY_EVENT, "event");
for (VariableElement param : userParameters) {
String paramClassQualifiedName = param.asType().toString();
if (isTypeOrSubclass(CanonicalNameConstants.TEXT_VIEW, param)) {
call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.TEXT_VIEW, textView, param));
} else if (paramClassQualifiedName.equals(CanonicalNameConstants.INTEGER) || paramClassQualifiedName.equals(getCodeModel().INT.fullName())) {
call.arg(actionId);
} else if (paramClassQualifiedName.equals(CanonicalNameConstants.KEY_EVENT)) {
call.arg(event);
}
}
}
use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class AbstractResHandler method validate.
@Override
public final void validate(Element element, ElementValidation validation) {
injectHelper.validate(androidRes.getAnnotationClass(), element, validation);
if (!validation.isValid()) {
return;
}
validatorHelper.allowedType(element, androidRes.getAllowedTypes(), validation);
validatorHelper.resIdsExist(element, androidRes.getRInnerClass(), IdValidatorHelper.FallbackStrategy.USE_ELEMENT_NAME, validation);
Element enclosingElement = element.getEnclosingElement();
if (element instanceof VariableElement && enclosingElement instanceof ExecutableElement) {
validatorHelper.isNotPrivate(enclosingElement, validation);
} else {
validatorHelper.isNotPrivate(element, validation);
}
}
use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class AfterTextChangeHandler 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 editableParameterPosition = -1;
int viewParameterPosition = -1;
TypeMirror viewParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.EDITABLE.equals(parameterType.toString())) {
editableParameterPosition = i;
} else {
TypeMirror textViewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.TEXT_VIEW).asType();
if (annotationHelper.isSubtype(parameterType, textViewType)) {
viewParameterPosition = i;
viewParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
TextWatcherHolder textWatcherHolder = holder.getTextWatcherHolder(idRef, viewParameterType);
JBlock methodBody = textWatcherHolder.getAfterTextChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == editableParameterPosition) {
JVar afterTextChangeEditableParam = textWatcherHolder.getAfterTextChangedEditableParam();
textChangeCall.arg(afterTextChangeEditableParam);
} else if (i == viewParameterPosition) {
JVar viewParameter = textWatcherHolder.getTextViewVariable();
textChangeCall.arg(viewParameter);
}
}
}
}
use of javax.lang.model.element.VariableElement in project androidannotations by androidannotations.
the class PageScrolledHandler 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 positionParameterPosition = -1;
int positionOffsetParameterPosition = -1;
int positionOffsetPixelsParameterPosition = -1;
int viewPagerParameterPosition = -1;
int numberOfIntParameters = 0;
TypeMirror viewPagerParameterType = null;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
if (numberOfIntParameters == 0 && positionOffsetParameterPosition == -1) {
positionParameterPosition = i;
} else {
positionOffsetPixelsParameterPosition = i;
}
numberOfIntParameters++;
} else if (parameterType.getKind() == TypeKind.FLOAT || CanonicalNameConstants.FLOAT.equals(parameterType.toString())) {
positionOffsetParameterPosition = i;
} else {
TypeMirror viewPagerType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW_PAGER).asType();
if (annotationHelper.isSubtype(parameterType, viewPagerType)) {
viewPagerParameterPosition = i;
viewPagerParameterType = parameterType;
}
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
JBlock methodBody = pageChangeHolder.getPageScrolledBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation pageScrollCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == positionParameterPosition) {
JVar positionParam = pageChangeHolder.getPageScrolledPositionParam();
pageScrollCall.arg(positionParam);
} else if (i == positionOffsetParameterPosition) {
JVar pageScrolledPositionOffsetParam = pageChangeHolder.getPageScrolledPositionOffsetParam();
pageScrollCall.arg(pageScrolledPositionOffsetParam);
} else if (i == positionOffsetPixelsParameterPosition) {
JVar pageScrolledPositionOffsetPixelsParam = pageChangeHolder.getPageScrolledPositionOffsetPixelsParam();
pageScrollCall.arg(pageScrolledPositionOffsetPixelsParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
pageScrollCall.arg(viewParameter);
}
}
}
}
Aggregations