private void flagError(
      final String s,
      final String code,
      final boolean warning,
      final boolean info,
      final EObject source,
      final String... data)
      throws GamaRuntimeException {

    if (warning && !info && !GamaPreferences.WARNINGS_ENABLED.getValue()) {
      return;
    }
    if (info && !GamaPreferences.INFO_ENABLED.getValue()) {
      return;
    }

    IDescription desc = this;
    EObject e = source;
    if (e == null) {
      e = getUnderlyingElement(null);
    }
    while (e == null && desc != null) {
      desc = desc.getEnclosingDescription();
      if (desc != null) {
        e = desc.getUnderlyingElement(null);
      }
    }
    if (!warning && !info) {
      final String resource = e == null ? "(no file)" : e.eResource().getURI().lastSegment();
      // System.err.println("COMPILATION ERROR in " + this.toString() + ":
      // " + s + "; source: " + resource);
    }
    // throws a runtime exception if there is no way to signal the error in
    // the source
    // (i.e. we are probably in a runtime scenario)
    if (e == null
        || e.eResource().getURI().path().contains(IExpressionCompiler.SYNTHETIC_RESOURCES_PREFIX)) {
      throw warning ? GamaRuntimeException.warning(s) : GamaRuntimeException.error(s);
    }
    final ErrorCollector c = getErrorCollector();
    if (c == null) {
      System.out.println((warning ? "Warning" : "Error") + ": " + s);
      return;
    }
    c.add(new GamlCompilationError(s, code, e, warning, info, data));
  }