use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class SharedPrefHandler method getLocalClassName.
private JMethod getLocalClassName(SharedPrefHolder holder) {
AbstractJClass stringClass = getClasses().STRING;
JMethod getLocalClassName = holder.getGeneratedClass().method(PRIVATE | STATIC, stringClass, "getLocalClassName");
AbstractJClass contextClass = getClasses().CONTEXT;
JVar contextParam = getLocalClassName.param(contextClass, "context");
JBlock body = getLocalClassName.body();
JVar packageName = body.decl(stringClass, "packageName", contextParam.invoke("getPackageName"));
JVar className = body.decl(stringClass, "className", contextParam.invoke("getClass").invoke("getName"));
JVar packageLen = body.decl(getCodeModel().INT, "packageLen", packageName.invoke("length"));
IJExpression condition = //
className.invoke("startsWith").arg(packageName).not().cor(//
className.invoke("length").lte(packageLen)).cor(className.invoke("charAt").arg(packageLen).ne(lit('.')));
body._if(condition)._then()._return(className);
body._return(className.invoke("substring").arg(packageLen.plus(lit(1))));
return getLocalClassName;
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class ItemLongClickHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
boolean hasItemParameter = parameters.size() == 1;
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");
if (hasItemParameter) {
VariableElement parameter = parameters.get(0);
TypeMirror parameterType = parameter.asType();
if (parameterType.getKind() == TypeKind.INT) {
call.arg(onItemClickPositionParam);
} else {
AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameterType);
call.arg(cast(parameterClass, invoke(onItemClickParentParam, "getAdapter").invoke("getItem").arg(onItemClickPositionParam)));
if (parameterClass.isParameterized()) {
codeModelHelper.addSuppressWarnings(listenerMethod, "unchecked");
}
}
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class LongClickHandler method processParameters.
@Override
protected void processParameters(EComponentWithViewSupportHolder holder, JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) {
boolean hasViewParameter = parameters.size() == 1;
JVar viewParam = listenerMethod.param(getClasses().VIEW, "view");
if (hasViewParameter) {
call.arg(castArgumentIfNecessary(holder, CanonicalNameConstants.VIEW, viewParam, parameters.get(0)));
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class OptionsMenuHandler method process.
@Override
public void process(Element element, HasOptionsMenu holder) {
JBlock body = holder.getOnCreateOptionsMenuMethodInflateBody();
JVar menuInflater = holder.getOnCreateOptionsMenuMenuInflaterVar();
JVar menuParam = holder.getOnCreateOptionsMenuMenuParam();
List<JFieldRef> fieldRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.MENU, false);
for (JFieldRef optionsMenuRefId : fieldRefs) {
body.invoke(menuInflater, "inflate").arg(optionsMenuRefId).arg(menuParam);
}
}
use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.
the class PageScrollStateChangedHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int stateParameterPosition = -1;
int viewPagerParameterPosition = -1;
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())) {
stateParameterPosition = i;
} else {
if (isViewPagerParameter(parameterType)) {
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.getPageScrollStateChangedBody();
IJExpression thisRef = holder.getGeneratedClass().staticRef("this");
JInvocation methodCall = methodBody.invoke(thisRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == stateParameterPosition) {
JVar stateParam = pageChangeHolder.getPageScrollStateChangedStateParam();
methodCall.arg(stateParam);
} else if (i == viewPagerParameterPosition) {
JVar viewParameter = pageChangeHolder.getViewPagerVariable();
methodCall.arg(viewParameter);
}
}
}
}
Aggregations