use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class ProcessHolder method refClass.
public AbstractJClass refClass(Class<?> clazz) {
AbstractJClass referencedClass = codeModel.ref(clazz);
loadedClasses.put(clazz.getCanonicalName(), referencedClass);
return referencedClass;
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class RInnerClass method extractIdStaticRef.
public static JFieldRef extractIdStaticRef(AndroidAnnotationsEnvironment environment, String layoutFieldQualifiedName) {
if (layoutFieldQualifiedName != null) {
int fieldSuffix = layoutFieldQualifiedName.lastIndexOf('.');
String fieldName = layoutFieldQualifiedName.substring(fieldSuffix + 1);
String rInnerClassName = layoutFieldQualifiedName.substring(0, fieldSuffix);
int innerClassSuffix = rInnerClassName.lastIndexOf('.');
String rClassQualifiedName = rInnerClassName.substring(0, innerClassSuffix);
String innerClassSimpleName = rInnerClassName.substring(innerClassSuffix + 1);
JDirectClass rClass = (JDirectClass) environment.getJClass(rClassQualifiedName);
AbstractJClass innerClass = null;
for (JDirectClass clazz : rClass.classes()) {
if (clazz.name().equals(innerClassSimpleName)) {
innerClass = clazz;
break;
}
}
if (innerClass == null) {
try {
innerClass = rClass._class(innerClassSimpleName);
} catch (JClassAlreadyExistsException e) {
// never happens, since we already checked the inner class does not exist
}
}
return innerClass.staticRef(fieldName);
} else {
return null;
}
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class TraceHandler method getExitMessage.
private IJExpression getExitMessage(ExecutableElement element, JMethod method, JVar result, JVar duration) throws ClassNotFoundException {
String methodName = getMethodName(element);
List<JVar> params = method.params();
StringBuilder paramStr = new StringBuilder();
for (int i = 0; i < params.size(); i++) {
if (i > 0) {
paramStr.append(", ");
}
JVar var = params.get(i);
paramStr.append(var.type().name());
}
methodName += "(" + paramStr.toString() + ")";
JInvocation format = getJClass(String.class).staticInvoke("format");
if (result == null) {
format.arg("Exiting [" + methodName + "], duration in ms: %d");
} else {
format.arg("Exiting [" + methodName + " returning: %s], duration in ms: %d");
if (method.type().isArray()) {
AbstractJClass arraysClass = getJClass(Arrays.class);
format.arg(arraysClass.staticInvoke("toString").arg(JExpr.cast(boxify(method.type()), result)));
} else {
format.arg(result);
}
}
return format.arg(duration);
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class TransactionalHandler method process.
@Override
public void process(Element element, EComponentHolder holder) {
ExecutableElement executableElement = (ExecutableElement) element;
String returnTypeName = executableElement.getReturnType().toString();
AbstractJClass returnType = getJClass(returnTypeName);
JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
codeModelHelper.removeBody(method);
JVar db = method.params().get(0);
JBlock body = method.body();
body.invoke(db, "beginTransaction");
JTryBlock tryBlock = body._try();
IJExpression activitySuper = holder.getGeneratedClass().staticRef("super");
JInvocation superCall = JExpr.invoke(activitySuper, method);
for (JVar param : method.params()) {
superCall.arg(param);
}
JBlock tryBody = tryBlock.body();
if (returnTypeName.equals("void")) {
tryBody.add(superCall);
tryBody.invoke(db, "setTransactionSuccessful");
tryBody._return();
} else {
JVar result = tryBody.decl(returnType, "result_", superCall);
tryBody.invoke(db, "setTransactionSuccessful");
tryBody._return(result);
}
JCatchBlock catchBlock = tryBlock._catch(getJClass(RuntimeException.class));
JVar exceptionParam = catchBlock.param("e");
JBlock catchBody = catchBlock.body();
JInvocation errorInvoke = catchBody.staticInvoke(getClasses().LOG, "e");
errorInvoke.arg(logTagForClassHolder(holder));
errorInvoke.arg("Error in transaction");
errorInvoke.arg(exceptionParam);
catchBody._throw(exceptionParam);
tryBlock._finally().invoke(db, "endTransaction");
}
use of com.helger.jcodemodel.AbstractJClass in project androidannotations by androidannotations.
the class UiThreadHandler method addUIThreadCheck.
/**
* Add the pre-check to see if we are already in the UI thread.
*
* @param delegatingMethod
* @param holder
* @throws JClassAlreadyExistsException
*/
private void addUIThreadCheck(JMethod delegatingMethod, JBlock previousBody, EComponentHolder holder) throws JClassAlreadyExistsException {
// Get the Thread and Looper class.
AbstractJClass tClass = getClasses().THREAD;
AbstractJClass lClass = getClasses().LOOPER;
// invoke the methods.
IJExpression lhs = tClass.staticInvoke(METHOD_CUR_THREAD);
IJExpression rhs = lClass.staticInvoke(METHOD_MAIN_LOOPER).invoke(METHOD_GET_THREAD);
// create the conditional and the block.
JConditional con = delegatingMethod.body()._if(JOp.eq(lhs, rhs));
JBlock thenBlock = con._then().add(previousBody);
thenBlock._return();
}
Aggregations