Search in sources :

Example 86 with JVar

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;
}
Also used : JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 87 with JVar

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");
            }
        }
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) AbstractJClass(com.helger.jcodemodel.AbstractJClass) VariableElement(javax.lang.model.element.VariableElement) JVar(com.helger.jcodemodel.JVar)

Example 88 with JVar

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)));
    }
}
Also used : JVar(com.helger.jcodemodel.JVar)

Example 89 with JVar

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);
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 90 with JVar

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);
            }
        }
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) PageChangeHolder(org.androidannotations.holder.PageChangeHolder) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

JVar (com.helger.jcodemodel.JVar)126 JBlock (com.helger.jcodemodel.JBlock)86 JMethod (com.helger.jcodemodel.JMethod)61 AbstractJClass (com.helger.jcodemodel.AbstractJClass)53 JInvocation (com.helger.jcodemodel.JInvocation)39 IJExpression (com.helger.jcodemodel.IJExpression)33 VariableElement (javax.lang.model.element.VariableElement)25 ExecutableElement (javax.lang.model.element.ExecutableElement)19 JFieldRef (com.helger.jcodemodel.JFieldRef)16 TypeMirror (javax.lang.model.type.TypeMirror)16 JDefinedClass (com.helger.jcodemodel.JDefinedClass)15 JFieldVar (com.helger.jcodemodel.JFieldVar)15 JConditional (com.helger.jcodemodel.JConditional)9 JTryBlock (com.helger.jcodemodel.JTryBlock)7 JCatchBlock (com.helger.jcodemodel.JCatchBlock)5 AbstractJType (com.helger.jcodemodel.AbstractJType)4 ArrayList (java.util.ArrayList)4 BundleHelper (org.androidannotations.helper.BundleHelper)4 JTypeVar (com.helger.jcodemodel.JTypeVar)3 VariableDeclaration (com.github.sviperll.adt4j.model.config.VariableDeclaration)2