use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class RestHolder method implementSetBearerAuth.
private void implementSetBearerAuth(List<ExecutableElement> methods) {
JMethod setBearerMethod = codeModelHelper.implementMethod(this, methods, "setBearerAuth", TypeKind.VOID.toString(), true, STRING);
if (setBearerMethod != null) {
JVar tokenParamVar = setBearerMethod.params().get(0);
IJExpression tokenExpr = lit("Bearer ").plus(tokenParamVar);
AbstractJClass authClass = getJClass(HTTP_AUTHENTICATION);
JDefinedClass anonymousHttpAuthClass = getCodeModel().anonymousClass(authClass);
JMethod getHeaderValueMethod = anonymousHttpAuthClass.method(JMod.PUBLIC, String.class, "getHeaderValue");
getHeaderValueMethod.annotate(Override.class);
JBlock getHeaderValueMethodBody = getHeaderValueMethod.body();
getHeaderValueMethodBody._return(tokenExpr);
JBlock setBearerBody = setBearerMethod.body();
setBearerBody.assign(_this().ref(getAuthenticationField()), _new(anonymousHttpAuthClass));
}
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class BackgroundHandler method process.
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousMethodBody = codeModelHelper.removeBody(delegatingMethod);
JDefinedClass anonymousTaskClass = getCodeModel().anonymousClass(BackgroundExecutor.Task.class);
JMethod executeMethod = anonymousTaskClass.method(JMod.PUBLIC, getCodeModel().VOID, "execute");
executeMethod.annotate(Override.class);
// Catch exception in user code
JTryBlock tryBlock = executeMethod.body()._try();
tryBlock.body().add(previousMethodBody);
JCatchBlock catchBlock = tryBlock._catch(getClasses().THROWABLE);
JVar caughtException = catchBlock.param("e");
IJStatement uncaughtExceptionCall = //
getClasses().THREAD.staticInvoke(//
"getDefaultUncaughtExceptionHandler").invoke(//
"uncaughtException").arg(//
getClasses().THREAD.staticInvoke("currentThread")).arg(caughtException);
catchBlock.body().add(uncaughtExceptionCall);
Background annotation = element.getAnnotation(Background.class);
String id = annotation.id();
long delay = annotation.delay();
String serial = annotation.serial();
AbstractJClass backgroundExecutorClass = getJClass(BackgroundExecutor.class);
JInvocation newTask = _new(anonymousTaskClass).arg(lit(id)).arg(lit(delay)).arg(lit(serial));
JInvocation executeCall = backgroundExecutorClass.staticInvoke("execute").arg(newTask);
delegatingMethod.body().add(executeCall);
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class EActivityHolder method setInitNonConfigurationInstance.
private void setInitNonConfigurationInstance() throws JClassAlreadyExistsException {
JBlock initBody = getInitBodyInjectionBlock();
JDefinedClass ncHolderClass = getNonConfigurationHolder().getGeneratedClass();
initNonConfigurationInstance = initBody.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getGetLastNonConfigurationInstance())));
initIfNonConfigurationNotNullBlock = initBody._if(initNonConfigurationInstance.ne(_null()))._then();
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class EActivityHolder method setGetLastNonConfigurationInstance.
private void setGetLastNonConfigurationInstance() throws JClassAlreadyExistsException {
AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
TypeElement fragmentActivityTypeElement = getFragmentActivity(annotationHelper);
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
String getLastNonConfigurationInstanceName = "getLastNonConfigurationInstance";
if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
getLastNonConfigurationInstanceName = "getLastCustomNonConfigurationInstance";
}
NonConfigurationHolder ncHolder = getNonConfigurationHolder();
JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
JFieldVar superNonConfigurationInstanceField = ncHolder.getSuperNonConfigurationInstanceField();
getLastNonConfigurationInstance = generatedClass.method(PUBLIC, Object.class, getLastNonConfigurationInstanceName);
getLastNonConfigurationInstance.annotate(Override.class);
JBlock body = getLastNonConfigurationInstance.body();
JVar nonConfigurationInstance = body.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getLastNonConfigurationInstance)));
body._if(nonConfigurationInstance.eq(_null()))._then()._return(_null());
body._return(nonConfigurationInstance.ref(superNonConfigurationInstanceField));
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method createPageChangeHolder.
private PageChangeHolder createPageChangeHolder(JFieldRef idRef, TypeMirror viewParameterType, boolean hasAddOnPageChangeListenerMethod) {
AbstractJClass viewClass;
JDefinedClass onPageChangeListenerClass;
if (getProcessingEnvironment().getElementUtils().getTypeElement(CanonicalNameConstants.ANDROIDX_VIEW_PAGER) == null) {
viewClass = getClasses().VIEW_PAGER;
onPageChangeListenerClass = getCodeModel().anonymousClass(getClasses().PAGE_CHANGE_LISTENER);
} else {
viewClass = getClasses().ANDROIDX_VIEW_PAGER;
onPageChangeListenerClass = getCodeModel().anonymousClass(getClasses().ANDROIDX_PAGE_CHANGE_LISTENER);
}
if (viewParameterType != null) {
viewClass = getJClass(viewParameterType.toString());
}
JBlock onViewChangedBody = getOnViewChangedBodyInjectionBlock().blockSimple();
JVar viewVariable = onViewChangedBody.decl(FINAL, viewClass, "view", cast(viewClass, findViewById(idRef)));
JBlock block = onViewChangedBody._if(viewVariable.ne(JExpr._null()))._then();
if (hasAddOnPageChangeListenerMethod) {
block.invoke(viewVariable, "addOnPageChangeListener").arg(_new(onPageChangeListenerClass));
} else {
block.invoke(viewVariable, "setOnPageChangeListener").arg(_new(onPageChangeListenerClass));
}
return new PageChangeHolder(this, viewVariable, onPageChangeListenerClass);
}
Aggregations