class DefaultModelProblemCollector implements ModelProblemCollector {

    private final ModelBuilderResult result;

    private List<ModelProblem> problems;

    private String source;

    private Model sourceModel;

    private Model rootModel;

    private Set<ModelProblem.Severity> severities = EnumSet.noneOf(ModelProblem.Severity.class);

    DefaultModelProblemCollector(ModelBuilderResult result) {
        this.result = result;
        this.problems = result.getProblems();

        for (ModelProblem problem : this.problems) {
            severities.add(problem.getSeverity());
        }
    }

    public boolean hasFatalErrors() {
        return severities.contains(ModelProblem.Severity.FATAL);
    }

    public boolean hasErrors() {
        return severities.contains(ModelProblem.Severity.ERROR) || severities.contains(ModelProblem.Severity.FATAL);
    }

    @Override
    public List<ModelProblem> getProblems() {
        return problems;
    }

    public void setSource(String source) {
        this.source = source;
        this.sourceModel = null;
    }

    public void setSource(Model source) {
        this.sourceModel = source;
        this.source = null;

        if (rootModel == null) {
            rootModel = source;
        }
    }

    private String getSource() {
        if (source == null && sourceModel != null) {
            source = ModelProblemUtils.toPath(sourceModel);
        }
        return source;
    }

    private String getModelId() {
        return ModelProblemUtils.toId(sourceModel);
    }

    public void setRootModel(Model rootModel) {
        this.rootModel = rootModel;
    }

    public Model getRootModel() {
        return rootModel;
    }

    public String getRootModelId() {
        return ModelProblemUtils.toId(rootModel);
    }

    @Override
    public void add(ModelProblem problem) {
        problems.add(problem);

        severities.add(problem.getSeverity());
    }

    public void addAll(Collection<ModelProblem> problems) {
        this.problems.addAll(problems);

        for (ModelProblem problem : problems) {
            severities.add(problem.getSeverity());
        }
    }

    @Override
    public void add(BuilderProblem.Severity severity, ModelProblem.Version version, String message) {
        add(severity, version, message, null, null);
    }

    @Override
    public void add(
            BuilderProblem.Severity severity, ModelProblem.Version version, String message, InputLocation location) {
        add(severity, version, message, location, null);
    }

    @Override
    public void add(
            BuilderProblem.Severity severity, ModelProblem.Version version, String message, Exception exception) {
        add(severity, version, message, null, exception);
    }

    public void add(
            BuilderProblem.Severity severity,
            ModelProblem.Version version,
            String message,
            InputLocation location,
            Exception exception) {
        int line = -1;
        int column = -1;
        String source = null;
        String modelId = null;

        if (location != null) {
            line = location.getLineNumber();
            column = location.getColumnNumber();
            if (location.getSource() != null) {
                modelId = location.getSource().getModelId();
                source = location.getSource().getLocation();
            }
        }

        if (modelId == null) {
            modelId = getModelId();
            source = getSource();
        }

        if (line <= 0 && column <= 0 && exception instanceof ModelParserException e) {
            line = e.getLineNumber();
            column = e.getColumnNumber();
        }

        ModelProblem problem =
                new DefaultModelProblem(message, severity, version, source, line, column, modelId, exception);

        add(problem);
    }

    public ModelBuilderException newModelBuilderException() {<FILL_FUNCTION_BODY>}
}

        ModelBuilderResult result = this.result;
        if (result.getModelIds().isEmpty()) {
            DefaultModelBuilderResult tmp = new DefaultModelBuilderResult();
            tmp.setEffectiveModel(result.getEffectiveModel());
            tmp.setProblems(getProblems());
            tmp.setActiveExternalProfiles(result.getActiveExternalProfiles());
            String id = getRootModelId();
            tmp.addModelId(id);
            tmp.setRawModel(id, getRootModel());
            result = tmp;
        }
        return new ModelBuilderException(result);
    
<no_super_class>