// Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library barback.transform_logger;

import 'package:source_maps/span.dart';

/// Object used to report warnings and errors encountered while running a
/// transformer.
class TransformLogger {

  bool _shouldPrint;

  TransformLogger(this._shouldPrint);

  /// Logs an informative message.
  ///
  /// If present, [span] indicates the location in the input asset that caused
  /// the message.
  void info(String message, [Span span]) {
    _printMessage('info', message, span);
  }

  /// Logs a warning message.
  ///
  /// If present, [span] indicates the location in the input asset that caused
  /// the warning.
  void warning(String message, [Span span]) {
    _printMessage('warning', message, span);
  }

  /// Logs an error message.
  ///
  /// If present, [span] indicates the location in the input asset that caused
  /// the error.
  // TODO(sigmund,nweiz): clarify when an error should be logged or thrown.
  void error(String message, [Span span]) {
    _printMessage('error', message, span);
  }

  // TODO(sigmund,rnystrom): do something better than printing.
  _printMessage(String prefix, String message, Span span) {
    if (!_shouldPrint) return;
    print(span == null ? '$prefix $message'
        : '$prefix ${span.getLocationMessage(message)}');
  }
}

// Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library barback.transform_logger;

import 'package:source_maps/span.dart';

/// Object used to report warnings and errors encountered while running a
/// transformer.
class TransformLogger {

  bool _shouldPrint;

  TransformLogger(this._shouldPrint);

  /// Logs an informative message.
  ///
  /// If present, [span] indicates the location in the input asset that caused
  /// the message.
  void info(String message, [Span span]) {
    _printMessage('info', message, span);
  }

  /// Logs a warning message.
  ///
  /// If present, [span] indicates the location in the input asset that caused
  /// the warning.
  void warning(String message, [Span span]) {
    _printMessage('warning', message, span);
  }

  /// Logs an error message.
  ///
  /// If present, [span] indicates the location in the input asset that caused
  /// the error.
  // TODO(sigmund,nweiz): clarify when an error should be logged or thrown.
  void error(String message, [Span span]) {
    _printMessage('error', message, span);
  }

  // TODO(sigmund,rnystrom): do something better than printing.
  _printMessage(String prefix, String message, Span span) {
    if (!_shouldPrint) return;
    print(span == null ? '$prefix: $message'
        : '$prefix ${span.getLocationMessage(message)}');
  }
}

Use our own DiagnosticHandler for dart2js.
Use our own DiagnosticHandler for dart2js.

Instead of implementing SourceFileProvider and using dart2js's
built in DiagnosticHandler, we just provide our own
CompilerInputProvider and DiagnosticHandler functions. This avoids
implementing stuff in SourceFileProvider and, more importantly,
lets us handle missing source files better.

The DiagnosticHandler in dart2js just barfs and trashes the original
error if it can't find a source file to associate with it. The windows
bots are currently failing on an error I can't see because it doesn't
have a source file.

BUG=
R=nweiz@google.com

Review URL: https://codereview.chromium.org//25540004

git-svn-id: c93d8a2297af3b929165606efe145742a534bc71@28246 260f80e4-7a28-3924-810f-c04153c831b5
