use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class RoboGuiceHandler method onConfigurationChangedMethod.
private void onConfigurationChangedMethod(EActivityHolder holder, RoboGuiceHolder roboGuiceHolder, JFieldVar eventManager) {
JVar currentConfig = roboGuiceHolder.getCurrentConfig();
IJExpression newConfig = holder.getOnConfigurationChangedNewConfigParam();
JBlock onConfigurationChangedAfterSuperBlock = holder.getOnConfigurationChangedAfterSuperBlock();
fireEvent(eventManager, onConfigurationChangedAfterSuperBlock, getJClass(RoboGuiceClasses.ON_CONFIGURATION_CHANGED_EVENT), currentConfig, newConfig);
}
use of com.helger.jcodemodel.IJExpression in project androidannotations by androidannotations.
the class RestAnnotationHelper method getResponseClass.
public IJExpression getResponseClass(Element element, RestHolder holder) {
ExecutableElement executableElement = (ExecutableElement) element;
IJExpression responseClassExpr = nullCastedToNarrowedClass(holder);
TypeMirror returnType = executableElement.getReturnType();
if (returnType.getKind() != TypeKind.VOID) {
if (getElementUtils().getTypeElement(RestSpringClasses.PARAMETERIZED_TYPE_REFERENCE) != null) {
if (returnType.toString().startsWith(RestSpringClasses.RESPONSE_ENTITY)) {
List<? extends TypeMirror> typeArguments = ((DeclaredType) returnType).getTypeArguments();
if (!typeArguments.isEmpty()) {
returnType = typeArguments.get(0);
}
}
if (checkIfParameterizedTypeReferenceShouldBeUsed(returnType)) {
return createParameterizedTypeReferenceAnonymousSubclassInstance(returnType);
}
}
AbstractJClass responseClass = retrieveResponseClass(returnType, holder);
if (responseClass != null) {
responseClassExpr = responseClass.dotclass();
}
}
return responseClassExpr;
}
use of com.helger.jcodemodel.IJExpression 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();
}
use of com.helger.jcodemodel.IJExpression 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 ("void".equals(returnTypeName)) {
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.IJExpression in project androidannotations by androidannotations.
the class WakeLockHandler method process.
@Override
public void process(Element element, EComponentHolder holder) {
ExecutableElement executableElement = (ExecutableElement) element;
WakeLock annotation = executableElement.getAnnotation(WakeLock.class);
String tag = extractTag(executableElement);
Level level = annotation.level();
Flag[] flags = annotation.flags();
JMethod method = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousMethodBody = codeModelHelper.removeBody(method);
JBlock methodBody = method.body();
IJExpression levelAndFlags = getClasses().POWER_MANAGER.staticRef(level.name());
if (flags.length > 0) {
for (Flag flag : flags) {
levelAndFlags = levelAndFlags.bor(getClasses().POWER_MANAGER.staticRef(flag.name()));
}
}
JInvocation newWakeLock = holder.getPowerManagerRef().invoke("newWakeLock").arg(levelAndFlags).arg(JExpr.lit(tag));
JVar wakeLock = methodBody.decl(getClasses().WAKE_LOCK, "wakeLock", JExpr._null());
JTryBlock tryBlock = methodBody._try();
tryBlock.body().assign(wakeLock, newWakeLock);
tryBlock.body().add(wakeLock.invoke("acquire"));
tryBlock.body().add(previousMethodBody);
JBlock finallyBlock = tryBlock._finally();
JConditional ifStatement = finallyBlock._if(wakeLock.ne(JExpr._null()));
ifStatement._then().add(wakeLock.invoke("release"));
}
Aggregations