private QueryProfileType extendOrCreateQueryProfileType(String name, QueryProfileTypeRegistry registry) {
        QueryProfileType type = null;
        FieldDescription fieldDescription = getField(name);
        if (fieldDescription != null) {
            if ( ! (fieldDescription.getType() instanceof QueryProfileFieldType fieldType))
                throw new IllegalArgumentException("Cannot use name '" + name + "' as a prefix because it is " +
                                                   "already a " + fieldDescription.getType());
            type = fieldType.getQueryProfileType();
        }

        if (type == null) {
            type = registry.getComponent(name);
        }

        // found in registry but not already added in *this* type (getField also checks parents): extend it
        if (type != null && ! fields.containsKey(name)) {
            type = new QueryProfileType(registry.createAnonymousId(type.getIdString()),
                                        new LinkedHashMap<>(),
                                        List.of(type));
        }

        if (type == null) { // create it
            type = new QueryProfileType(registry.createAnonymousId(name));
        }

        if (fieldDescription == null) {
            fieldDescription = new FieldDescription(name, new QueryProfileFieldType(type));
        }
        else {
            fieldDescription = fieldDescription.withType(new QueryProfileFieldType(type));
        }

        registry.register(type);
        fields.put(name, fieldDescription);
        return type;
    }
Adds a field to this

@throws IllegalStateException if this is frozen
container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java