private T inject()

in cassandra/src/main/java/org/apache/ignite/activestore/commons/Injection.java [246:301]


    private <T> T inject(T result, boolean callPostConstruct) {
        Class<?> clazz = result.getClass();
        Deque<Method> postConstructs = new ArrayDeque<>();
        while (clazz != null) {
            for (Field field : clazz.getDeclaredFields()) {
                if (field.getAnnotation(Inject.class) != null) {
                    if (Modifier.isFinal(field.getModifiers())) {
                        throw new RuntimeException("Field " + field.getName() + " in " + clazz + " is final.");
                    }
                    field.setAccessible(true);
                    Qualifier qualifier = field.getAnnotation(Qualifier.class);
                    String name = qualifier == null ? null : qualifier.value();
                    try {
                        field.set(result, get(field.getType(), name));
                    }
                    catch (IllegalAccessException e) {
                        throw new RuntimeException("Cannot inject value into field " + field.getName() + " in class " + clazz, e);
                    }
                }
            }
            for (Method method : clazz.getDeclaredMethods()) {
                if (method.getAnnotation(Inject.class) != null) {
                    Class[] parameterTypes = method.getParameterTypes();
                    if (parameterTypes.length > 0) {
                        method.setAccessible(true);
                        try {
                            method.invoke(result, getInput(parameterTypes, method.getParameterAnnotations()));
                        }
                        catch (IllegalAccessException | InvocationTargetException e) {
                            throw new RuntimeException("Cannot inject value into method " + method.getName() + " in class " + clazz, e);
                        }
                    }
                }
                else if (callPostConstruct && method.getAnnotation(PostConstruct.class) != null) {
                    if (method.getParameterTypes().length == 0) {
                        method.setAccessible(true);
                        postConstructs.addFirst(method);
                    }
                }
            }
            clazz = clazz.getSuperclass();
        }
        injectIgnite(result, ignite);
        for (Method postConstruct : postConstructs) {
            try {
                postConstruct.invoke(result);
            }
            catch (IllegalAccessException | InvocationTargetException e) {
                throw new RuntimeException("Cannot execute PostConstruct method", e);
            }
        }
        if (callPostConstruct && result instanceof LifecycleAware) {
            ((LifecycleAware)result).start();
        }
        return result;
    }