public static void ensureMarshallerFieldCreated(final ClassStructureBuilder<?> classStructureBuilder, final MetaClass marshallerForType, final MetaClass type, final BlockBuilder<?> initMethod, final Statement marshallerCreationCallback) { final String fieldName = MarshallingGenUtil.getVarName(type); if (classStructureBuilder.getClassDefinition().getField(fieldName) == null) { final Statement marshallerLookup = createMarshallerLookup(marshallerForType, type, marshallerCreationCallback); if (initMethod == null) { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(marshallerLookup).finish(); } else { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(Stmt.load(null)).finish(); initMethod.append( If.isNull(Stmt.loadVariable(fieldName)).append( Stmt.loadVariable(fieldName).assignValue(marshallerLookup)).finish()); } } }
public static void ensureMarshallerFieldCreated(final ClassStructureBuilder<?> classStructureBuilder, final MetaClass marshallerForType, final MetaClass type, final BlockBuilder<?> initMethod, final Statement marshallerCreationCallback) { final String fieldName = MarshallingGenUtil.getVarName(type); if (classStructureBuilder.getClassDefinition().getField(fieldName) == null) { final Statement marshallerLookup = createMarshallerLookup(marshallerForType, type, marshallerCreationCallback); if (initMethod == null) { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(marshallerLookup).finish(); } else { classStructureBuilder.privateField(fieldName, parameterizedAs(Marshaller.class, typeParametersOf(type.getErased().asBoxed()))) .initializesWith(Stmt.load(null)).finish(); initMethod.append( If.isNull(Stmt.loadVariable(fieldName)).append( Stmt.loadVariable(fieldName).assignValue(marshallerLookup)).finish()); } } }