public Object getContext(String key) {
        for (State state : states) {
            if (state.context.containsKey(key)) {
                return state.context.get(key);
            } else if (state.sectionValue != null) {
                Method method = findContextMethod(state.sectionValue, key);
                if (method != null) {
                    try {
                        return method.invoke(state.sectionValue);
                    } catch (ReflectiveOperationException e) {
                        String message = String.format(
                                "Unable to get context '%s' from a matching method of the current CodeSection: %s %s",
                                key,
                                e.getCause() != null ? e.getCause().getMessage() : e.getMessage(),
                                getDebugInfo());
                        throw new RuntimeException(message, e);
                    }
                }
            }
        }
        return null;
    }
Gets a named contextual key-value pair from the current state or any parent states.

@param key Key to retrieve.
@return Returns the associated value or null if not present.
smithy-utils/src/main/java/software/amazon/smithy/utils/AbstractCodeWriter.java