use of org.apache.drill.shaded.guava.com.google.common.base.Function in project drill by apache.
the class CodeGenMemberInjector method injectMembers.
/**
* Generated code for a class may have several class members, they
* are initialized by invoking this method when the instance created.
*
* @param cg the class generator
* @param instance the class instance created by the compiler
* @param context the fragment context
*/
public static void injectMembers(ClassGenerator<?> cg, Object instance, FragmentContext context) {
Map<Integer, Object> cachedInstances = new HashMap<>();
for (Map.Entry<Pair<Integer, JVar>, Function<DrillBuf, ? extends ValueHolder>> setter : cg.getConstantVars().entrySet()) {
try {
JVar var = setter.getKey().getValue();
Integer depth = setter.getKey().getKey();
Object varInstance = getFieldInstance(instance, depth, cachedInstances);
Field field = varInstance.getClass().getDeclaredField(var.name());
field.setAccessible(true);
field.set(varInstance, setter.getValue().apply(context.getManagedBuffer()));
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
}