private static ArtifactSourcedType mergePluginType()

in log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/internal/TypeLookup.java [118:148]


    private static ArtifactSourcedType mergePluginType(
            final ArtifactSourcedType oldSourcedType, final ArtifactSourcedType newSourcedType) {

        // If the entry already exists, but is of `AbstractType`, promote it to `PluginType`.
        //
        // The most prominent example to this is `LoggerConfig`, which is a plugin.
        // Assume `AsyncLoggerConfig` (extending from `LoggerConfig`) is encountered first.
        // This results in `LoggerConfig` getting registered as an `AbstractType`.
        // When the actual `LoggerConfig` definition is encountered, the type needs to be promoted to `PluginType`.
        // Otherwise, `LoggerConfig` plugin definition will get skipped.
        if (oldSourcedType.type instanceof AbstractType && !(oldSourcedType.type instanceof PluginType)) {
            final PluginType newType = (PluginType) newSourcedType.type;
            // Preserve old implementations
            final AbstractType oldType = (AbstractType) oldSourcedType.type;
            oldType.getImplementations().forEach(newType::addImplementation);
            return newSourcedType;
        }

        // If the entry already exists and is of expected type, extend it
        else if (oldSourcedType.type instanceof PluginType) {
            final PluginType oldType = (PluginType) oldSourcedType.type;
            final PluginType newType = (PluginType) newSourcedType.type;
            newType.getImplementations().forEach(oldType::addImplementation);
            return oldSourcedType;
        }

        // If the entry already exists, but with an unexpected type, fail
        else {
            throw conflictingTypeFailure(oldSourcedType.type, newSourcedType.type);
        }
    }