use of com.helger.jcodemodel.JFieldVar in project RoboBinding by RoboBinding.
the class PresentationModelObjectClassGen method defineFields.
/**
* Note: not private in order to improve performance.
*
* final PresentationModelType presentationModel;
*/
@Override
public void defineFields() {
JFieldVar var = definedClass.field(JMod.FINAL, presentationModelClass, "presentationModel");
presentationModelField = JExpr.refthis(var.name());
presentationModelFieldWithoutThis = JExpr.ref(var.name());
}
use of com.helger.jcodemodel.JFieldVar in project androidannotations by androidannotations.
the class EActivityHolder method setGetLastNonConfigurationInstance.
private void setGetLastNonConfigurationInstance() throws JClassAlreadyExistsException {
AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment());
TypeElement fragmentActivityTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY);
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.JFieldVar in project androidannotations by androidannotations.
the class RoboGuiceHandler method process.
@Override
public void process(Element element, EActivityHolder holder) {
RoboGuiceHolder roboGuiceHolder = holder.getPluginHolder(new RoboGuiceHolder(holder));
holder.getGeneratedClass()._implements(getJClass(RoboGuiceClasses.ROBO_CONTEXT));
JFieldVar scope = roboGuiceHolder.getScopeField();
JFieldVar scopedObjects = roboGuiceHolder.getScopedObjectsField();
JFieldVar eventManager = roboGuiceHolder.getEventManagerField();
roboGuiceHolder.getContentViewListenerField();
listenerFields(element, holder);
beforeCreateMethod(holder, scope, scopedObjects, eventManager);
onRestartMethod(holder, eventManager);
onStartMethod(holder, eventManager);
onResumeMethod(holder, eventManager);
onPauseMethod(holder, eventManager);
onNewIntentMethod(holder, eventManager);
onStopMethod(holder, eventManager);
onDestroyMethod(holder, eventManager);
onConfigurationChangedMethod(holder, roboGuiceHolder, eventManager);
onContentChangedMethod(roboGuiceHolder, scope, eventManager);
onActivityResultMethod(holder, eventManager);
getScopedObjectMap(holder, scopedObjects);
}
use of com.helger.jcodemodel.JFieldVar in project adt4j by sviperll.
the class FinalValueClassModel method buildCaseClass.
private JDefinedClass buildCaseClass(String interfaceMethodName, Serialization serialization) throws JClassAlreadyExistsException {
JDefinedClass caseClass = environment.buildValueClassInnerClass(JMod.PRIVATE | JMod.STATIC, Source.capitalize(interfaceMethodName) + "Case" + environment.acceptingInterfaceName(), EClassType.CLASS);
for (JTypeVar visitorTypeParameter : environment.getValueTypeParameters()) {
JTypeVar typeParameter = caseClass.generify(visitorTypeParameter.name());
typeParameter.boundLike(visitorTypeParameter);
}
AbstractJClass usedAcceptingInterfaceType = environment.acceptingInterfaceType(caseClass.typeParams());
AbstractJClass usedValueClassType = environment.wrappedValueClassType(caseClass.typeParams());
VisitorDefinition.VisitorUsage usedVisitor = environment.visitor(usedValueClassType, usedValueClassType, types._RuntimeException);
MethodUsage interfaceMethod = usedVisitor.findMethod(interfaceMethodName);
if (interfaceMethod == null)
throw new IllegalStateException("Method with given name not found: " + interfaceMethodName);
JTypeVar[] methodArguments = new JTypeVar[interfaceMethod.typeParams().length];
for (int i = 0; i < methodArguments.length; i++) {
JTypeVar visitorMethodTypeParameter = interfaceMethod.typeParams()[i];
JTypeVar typeParameter = caseClass.generify(visitorMethodTypeParameter.name());
typeParameter.boundLike(visitorMethodTypeParameter);
methodArguments[i] = typeParameter;
}
MethodUsage usedInterfaceMethod = interfaceMethod.narrow(methodArguments);
caseClass._implements(usedAcceptingInterfaceType);
if (serialization.isSerializable()) {
caseClass._implements(types._Serializable);
caseClass.field(JMod.PRIVATE | JMod.FINAL | JMod.STATIC, types._long, "serialVersionUID", JExpr.lit(serialization.serialVersionUIDForGeneratedCode()));
}
JMethod constructor = caseClass.constructor(JMod.NONE);
for (VariableDeclaration param : usedInterfaceMethod.params()) {
AbstractJType paramType = param.type().declarable();
JFieldVar field = caseClass.field(JMod.PRIVATE | JMod.FINAL, paramType, param.name());
JVar argument = constructor.param(paramType, param.name());
constructor.body().assign(JExpr._this().ref(field), argument);
}
VariableDeclaration param = usedInterfaceMethod.varParam();
if (param != null) {
AbstractJType paramType = param.type().elementType().declarable();
JFieldVar field = caseClass.field(JMod.PRIVATE | JMod.FINAL, paramType.array(), param.name());
JVar argument = constructor.varParam(paramType, param.name());
constructor.body().assign(JExpr._this().ref(field), argument);
}
JMethod acceptMethod = declareAcceptMethod(caseClass, usedValueClassType);
JInvocation invocation = JExpr.invoke(acceptMethod.params().get(0), usedInterfaceMethod.name());
for (AbstractJClass argument : methodArguments) {
invocation.narrow(argument);
}
for (VariableDeclaration param1 : usedInterfaceMethod.params()) {
invocation.arg(JExpr._this().ref(param1.name()));
}
VariableDeclaration param1 = usedInterfaceMethod.varParam();
if (param1 != null) {
invocation.arg(JExpr._this().ref(param1.name()));
}
acceptMethod.body()._return(invocation);
return caseClass;
}
use of com.helger.jcodemodel.JFieldVar in project adt4j by sviperll.
the class FinalValueClassModel method createMethodBuilder.
MethodBuilder createMethodBuilder(Serialization serialization) {
if (isError)
return new MethodBuilder(null, null);
else {
JFieldVar acceptorField = buildAcceptorField();
Map<String, JDefinedClass> caseClasses;
try {
caseClasses = buildCaseClasses(serialization);
} catch (JClassAlreadyExistsException ex) {
throw new RuntimeException("Unexpected exception :)", ex);
}
Caching hashCode = environment.hashCodeCaching();
if (!hashCode.enabled())
return new MethodBuilder(caseClasses, acceptorField);
else {
JFieldVar hashCodeField = buildHashCodeCachedValueField(serialization);
return new MethodBuilder(caseClasses, acceptorField, hashCodeField);
}
}
}
Aggregations