use of com.helger.jcodemodel.JDefinedClass in project adt4j by sviperll.
the class FinalValueClassModel method buildFactoryClass.
private JDefinedClass buildFactoryClass(Map<String, JMethod> constructorMethods) throws JClassAlreadyExistsException {
JDefinedClass factoryClass = environment.buildValueClassInnerClass(JMod.PRIVATE | JMod.STATIC, environment.valueClassName() + "Factory", EClassType.CLASS);
for (JTypeVar visitorTypeParameter : environment.getValueTypeParameters()) {
JTypeVar typeParameter = factoryClass.generify(visitorTypeParameter.name());
typeParameter.boundLike(visitorTypeParameter);
}
AbstractJClass usedValueClassType = environment.wrappedValueClassType(factoryClass.typeParams());
VisitorDefinition.VisitorUsage usedVisitor = environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException);
factoryClass._implements(usedVisitor.getVisitorType());
for (MethodUsage interfaceMethod : usedVisitor.methods()) {
JMethod factoryMethod = factoryClass.method(interfaceMethod.mods().getValue() & ~JMod.ABSTRACT, usedValueClassType, interfaceMethod.name());
for (JTypeVar visitorMethodTypeParameter : interfaceMethod.typeParams()) {
JTypeVar typeParameter = factoryMethod.generify(visitorMethodTypeParameter.name());
typeParameter.boundLike(visitorMethodTypeParameter);
}
MethodUsage usedInterfaceMethod = interfaceMethod.narrow(factoryMethod.typeParams());
Source.annotateNonnull(factoryMethod);
factoryMethod.annotate(Override.class);
List<AbstractJClass> typeArguments = new ArrayList<>();
typeArguments.addAll(factoryClass.typeParamList());
typeArguments.addAll(factoryMethod.typeParamList());
JMethod constructorMethod = constructorMethods.get(interfaceMethod.name());
JInvocation staticInvoke = environment.invokeValueClassStaticMethod(constructorMethod, typeArguments.toArray(new AbstractJClass[typeArguments.size()]));
for (VariableDeclaration param : usedInterfaceMethod.params()) {
JVar argument = factoryMethod.param(param.mods().getValue(), param.type().declarable(), param.name());
staticInvoke.arg(argument);
}
VariableDeclaration param = usedInterfaceMethod.varParam();
if (param != null) {
JVar argument = factoryMethod.varParam(param.mods().getValue(), param.type().elementType().declarable(), param.name());
staticInvoke.arg(argument);
}
factoryMethod.body()._return(staticInvoke);
}
return factoryClass;
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class EActivityHolder method setOnRetainNonConfigurationInstance.
private void setOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException {
AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
TypeElement fragmentActivityTypeElement = getFragmentActivity(annotationHelper);
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
String onRetainNonConfigurationInstanceName = "onRetainNonConfigurationInstance";
if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
onRetainNonConfigurationInstanceName = "onRetainCustomNonConfigurationInstance";
}
NonConfigurationHolder ncHolder = getNonConfigurationHolder();
JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
JMethod onRetainNonConfigurationInstanceMethod = generatedClass.method(PUBLIC, ncHolderClass, onRetainNonConfigurationInstanceName);
onRetainNonConfigurationInstanceMethod.annotate(Override.class);
JBlock methodBody = onRetainNonConfigurationInstanceMethod.body();
onRetainNonConfigurationInstance = methodBody.decl(ncHolderClass, "nonConfigurationInstanceState_", _new(ncHolderClass));
IJExpression superCall = _super().invoke(onRetainNonConfigurationInstanceMethod);
methodBody.assign(onRetainNonConfigurationInstance.ref(ncHolder.getSuperNonConfigurationInstanceField()), superCall);
onRetainNonConfigurationInstanceBindBlock = methodBody.blockSimple();
methodBody._return(onRetainNonConfigurationInstance);
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class APTCodeModelHelper method createDelegatingAnonymousRunnableClass.
public JDefinedClass createDelegatingAnonymousRunnableClass(JBlock previousBody) {
JCodeModel codeModel = environment.getCodeModel();
JDefinedClass anonymousRunnableClass = codeModel.anonymousClass(Runnable.class);
JMethod runMethod = anonymousRunnableClass.method(JMod.PUBLIC, codeModel.VOID, "run");
runMethod.annotate(Override.class);
runMethod.body().add(previousBody);
return anonymousRunnableClass;
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class EComponentWithViewSupportHolder method createTextWatcherHolder.
private TextWatcherHolder createTextWatcherHolder(JFieldRef idRef, TypeMirror viewParameterType) {
JDefinedClass onTextChangeListenerClass = getCodeModel().anonymousClass(getClasses().TEXT_WATCHER);
AbstractJClass viewClass = getClasses().TEXT_VIEW;
if (viewParameterType != null) {
viewClass = getJClass(viewParameterType.toString());
}
JBlock onViewChangedBody = getOnViewChangedBodyInjectionBlock().blockSimple();
JVar viewVariable = onViewChangedBody.decl(FINAL, viewClass, "view", cast(viewClass, findViewById(idRef)));
//
onViewChangedBody._if(viewVariable.ne(JExpr._null()))._then().invoke(viewVariable, "addTextChangedListener").arg(_new(onTextChangeListenerClass));
return new TextWatcherHolder(this, viewVariable, onTextChangeListenerClass);
}
use of com.helger.jcodemodel.JDefinedClass in project androidannotations by androidannotations.
the class UiThreadHandler method process.
@Override
public void process(Element element, EComponentHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
JMethod delegatingMethod = codeModelHelper.overrideAnnotatedMethod(executableElement, holder);
JBlock previousBody = codeModelHelper.removeBody(delegatingMethod);
JDefinedClass anonymousRunnableClass = codeModelHelper.createDelegatingAnonymousRunnableClass(previousBody);
UiThread annotation = element.getAnnotation(UiThread.class);
long delay = annotation.delay();
UiThread.Propagation propagation = annotation.propagation();
if (delay == 0 && propagation == UiThread.Propagation.REUSE) {
// Put in the check for the UI thread.
addUIThreadCheck(delegatingMethod, previousBody, holder);
}
delegatingMethod.body().add(//
getJClass(UiThreadExecutor.class).staticInvoke(METHOD_RUN_TASK).arg(//
annotation.id()).arg(//
_new(anonymousRunnableClass)).arg(lit(delay)));
}
Aggregations