Search in sources :

Example 81 with JVar

use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.

the class TraceHandler method getEnterMessage.

private IJExpression getEnterMessage(JMethod method, ExecutableElement element) {
    String methodName = getMethodName(element);
    List<JVar> params = method.params();
    if (params.isEmpty()) {
        // early exit if the method has no parameters
        return JExpr.lit("Entering [" + methodName + "()]");
    }
    AbstractJClass arraysClass = getJClass(Arrays.class);
    StringBuilder paramStr = new StringBuilder();
    List<IJExpression> paramExpressions = new ArrayList<>();
    for (int i = 0; i < params.size(); i++) {
        if (i > 0) {
            paramStr.append(", ");
        }
        JVar var = params.get(i);
        paramStr.append(var.name()).append(" = %s");
        if (var.type().isArray()) {
            paramExpressions.add(arraysClass.staticInvoke("toString").arg(var));
        } else {
            paramExpressions.add(var);
        }
    }
    JInvocation format = getJClass(String.class).staticInvoke("format");
    format.arg(JExpr.lit("Entering [" + methodName + "(" + paramStr + ")]"));
    for (IJExpression expr : paramExpressions) {
        format.arg(expr);
    }
    return format;
}
Also used : IJExpression(com.helger.jcodemodel.IJExpression) ArrayList(java.util.ArrayList) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JVar(com.helger.jcodemodel.JVar)

Example 82 with JVar

use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.

the class IntentBuilder method createIntentMethod.

private void createIntentMethod() {
    JMethod method = holder.getGeneratedClass().method(STATIC | PUBLIC, holder.getIntentBuilderClass(), "intent");
    JVar contextParam = method.param(contextClass, "context");
    method.body()._return(_new(holder.getIntentBuilderClass()).arg(contextParam));
}
Also used : JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 83 with JVar

use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.

the class ViewNotifierHelper method wrapInitWithNotifier.

public void wrapInitWithNotifier() {
    JBlock initBlock = holder.getInit().body();
    JVar previousNotifier = replacePreviousNotifier(initBlock);
    ((EViewHolder) holder).setInitBody(holder.getInit().body().blockSimple());
    resetPreviousNotifier(initBlock.blockSimple(), previousNotifier);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar) EViewHolder(org.androidannotations.holder.EViewHolder)

Example 84 with JVar

use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.

the class PreferenceHeadersHandler method process.

@Override
public void process(Element element, HasPreferenceHeaders holder) throws Exception {
    JFieldRef headerId = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.XML, false).get(0);
    JBlock block = holder.getOnBuildHeadersBlock();
    JVar targetParam = holder.getOnBuildHeadersTargetParam();
    block.invoke("loadHeadersFromResource").arg(headerId).arg(targetParam);
    block.invoke(JExpr._super(), "onBuildHeaders").arg(targetParam);
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 85 with JVar

use of com.helger.jcodemodel.JVar in project androidannotations by androidannotations.

the class SharedPrefHandler method generateConstructor.

private void generateConstructor(Element element, SharedPrefHolder holder) {
    SharedPref sharedPrefAnnotation = element.getAnnotation(SharedPref.class);
    SharedPref.Scope scope = sharedPrefAnnotation.value();
    String name = sharedPrefAnnotation.name();
    int mode = sharedPrefAnnotation.mode();
    if (name.trim().isEmpty()) {
        name = element.getSimpleName().toString();
    }
    JBlock constructorSuperBlock = holder.getConstructorSuperBlock();
    JVar contextParam = holder.getConstructorContextParam();
    switch(scope) {
        case ACTIVITY_DEFAULT:
            {
                JMethod getLocalClassName = getLocalClassName(holder);
                // 
                constructorSuperBlock.invoke("super").arg(// 
                contextParam.invoke("getSharedPreferences").arg(// 
                invoke(getLocalClassName).arg(contextParam)).arg(lit(mode)));
                break;
            }
        case ACTIVITY:
            {
                JMethod getLocalClassName = getLocalClassName(holder);
                // 
                constructorSuperBlock.invoke("super").arg(// 
                contextParam.invoke("getSharedPreferences").arg(// 
                invoke(getLocalClassName).arg(contextParam).plus(// 
                lit("_" + name))).arg(lit(mode)));
                break;
            }
        case UNIQUE:
            {
                // 
                constructorSuperBlock.invoke("super").arg(// 
                contextParam.invoke("getSharedPreferences").arg(// 
                lit(name)).arg(lit(mode)));
                break;
            }
        case APPLICATION_DEFAULT:
            {
                AbstractJClass preferenceManagerClass = getJClass("android.preference.PreferenceManager");
                // 
                constructorSuperBlock.invoke("super").arg(// 
                preferenceManagerClass.staticInvoke("getDefaultSharedPreferences").arg(contextParam));
                break;
            }
    }
}
Also used : JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) DefaultString(org.androidannotations.annotations.sharedpreferences.DefaultString) JMethod(com.helger.jcodemodel.JMethod) SharedPref(org.androidannotations.annotations.sharedpreferences.SharedPref) 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