Search in sources :

Example 1 with Function

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) ValueHolder(org.apache.drill.exec.expr.holders.ValueHolder) Function(org.apache.drill.shaded.guava.com.google.common.base.Function) Field(java.lang.reflect.Field) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.calcite.util.Pair) JVar(com.sun.codemodel.JVar)

Aggregations

JVar (com.sun.codemodel.JVar)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Pair (org.apache.calcite.util.Pair)1 ValueHolder (org.apache.drill.exec.expr.holders.ValueHolder)1 Function (org.apache.drill.shaded.guava.com.google.common.base.Function)1