private function resolveCollection(\ArrayIterator $tokens, Type $classType, Context $context)
    {
        $isArray = ('array' === (string) $classType);

        // allow only "array" or class name before "<"
        if (!$isArray
            && (! $classType instanceof Object_ || $classType->getFqsen() === null)) {
            throw new \RuntimeException(
                $classType . ' is not a collection'
            );
        }

        $tokens->next();

        $valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
        $keyType = null;

        if ($tokens->current() !== null && trim($tokens->current()) === ',') {
            // if we have a comma, then we just parsed the key type, not the value type
            $keyType = $valueType;
            if ($isArray) {
                // check the key type for an "array" collection. We allow only
                // strings or integers.
                if (! $keyType instanceof String_ &&
                    ! $keyType instanceof Integer &&
                    ! $keyType instanceof Compound
                ) {
                    throw new \RuntimeException(
                        'An array can have only integers or strings as keys'
                    );
                }

                if ($keyType instanceof Compound) {
                    foreach ($keyType->getIterator() as $item) {
                        if (! $item instanceof String_ &&
                            ! $item instanceof Integer
                        ) {
                            throw new \RuntimeException(
                                'An array can have only integers or strings as keys'
                            );
                        }
                    }
                }
            }

            $tokens->next();
            // now let's parse the value type
            $valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
        }

        if ($tokens->current() !== '>') {
            if (empty($tokens->current())) {
                throw new \RuntimeException(
                    'Collection: ">" is missing'
                );
            }

            throw new \RuntimeException(
                'Unexpected character "' . $tokens->current() . '", ">" is missing'
            );
        }

        if ($isArray) {
            return new Array_($valueType, $keyType);
        }

        if ($classType instanceof Object_) {
            return $this->makeCollectionFromObject($classType, $valueType, $keyType);
        }
    }