Search in sources :

Example 71 with JInvocation

use of com.helger.jcodemodel.JInvocation 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 : ArrayList(java.util.ArrayList) IJExpression(com.helger.jcodemodel.IJExpression) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JInvocation(com.helger.jcodemodel.JInvocation) JVar(com.helger.jcodemodel.JVar)

Aggregations

JInvocation (com.helger.jcodemodel.JInvocation)71 JVar (com.helger.jcodemodel.JVar)38 JBlock (com.helger.jcodemodel.JBlock)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)31 IJExpression (com.helger.jcodemodel.IJExpression)27 JMethod (com.helger.jcodemodel.JMethod)26 ExecutableElement (javax.lang.model.element.ExecutableElement)20 VariableElement (javax.lang.model.element.VariableElement)16 JFieldRef (com.helger.jcodemodel.JFieldRef)14 TypeMirror (javax.lang.model.type.TypeMirror)14 JConditional (com.helger.jcodemodel.JConditional)11 JDefinedClass (com.helger.jcodemodel.JDefinedClass)9 AbstractJType (com.helger.jcodemodel.AbstractJType)5 JFieldVar (com.helger.jcodemodel.JFieldVar)5 JTryBlock (com.helger.jcodemodel.JTryBlock)5 ArrayList (java.util.ArrayList)4 DeclaredType (javax.lang.model.type.DeclaredType)4 JCatchBlock (com.helger.jcodemodel.JCatchBlock)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3