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;
}
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));
}
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);
}
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);
}
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;
}
}
}
Aggregations