Chromium Code Reviews| Index: pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart |
| diff --git a/pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart b/pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart |
| index f033e40d80543a6a45fbc1fdba7ac342371f4c14..c6ae211a64dea333b6f94654cada22954bdd22d2 100644 |
| --- a/pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart |
| +++ b/pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart |
| @@ -21,6 +21,7 @@ import '../../../../../lib/compiler/implementation/tree/tree.dart'; |
| import '../../../../../lib/compiler/implementation/util/util.dart'; |
| import '../../../../../lib/compiler/implementation/util/uri_extras.dart'; |
| import '../../../../../lib/compiler/implementation/dart2js.dart'; |
| +import '../../../../../lib/compiler/implementation/util/characters.dart'; |
| // TODO(rnystrom): Use "package:" URL (#4968). |
| import '../../mirrors.dart'; |
| @@ -428,7 +429,7 @@ abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { |
| String get displayName => simpleName; |
| - SourceLocation get location => new Dart2JsLocation( |
| + SourceLocation get location => new Dart2JsSourceLocation( |
| _element.getCompilationUnit().script, |
| mirrors.compiler.spanFromElement(_element)); |
| @@ -617,35 +618,64 @@ class Dart2JsLibraryMirror extends Dart2JsContainerMirror |
| SourceLocation get location { |
| var script = _library.getCompilationUnit().script; |
| - return new Dart2JsLocation( |
| + return new Dart2JsSourceLocation( |
| script, |
| new SourceSpan(script.uri, 0, script.text.length)); |
| } |
| } |
| -class Dart2JsLocation implements SourceLocation { |
| - Script _script; |
| - SourceSpan _span; |
| +class Dart2JsSourceLocation implements SourceLocation { |
| + final Script _script; |
| + final SourceSpan _span; |
| - Dart2JsLocation(this._script, this._span); |
| + Dart2JsSourceLocation(this._script, this._span); |
| - int get start => _span.begin; |
| + int get line { |
| + var sourceFile = _script.file is SourceFile; |
|
kasperl
2012/11/01 10:13:29
I'd factor out the computation part into a compute
Johnni Winther
2012/11/01 12:01:58
Done.
|
| + if (sourceFile != null) { |
| + return sourceFile.getLine(offset); |
| + } |
| + var index = 0; |
| + var lineNumber = 0; |
| + while (index < sourceText.length) { |
| + lineNumber++; |
| + index = sourceText.indexOf('\n', index) + 1; |
|
kasperl
2012/11/01 10:13:29
I don't think this works on all platforms. I'd rec
Johnni Winther
2012/11/01 12:01:58
Done.
|
| + if (index <= 0) break; |
| + } |
| + return lineNumber; |
| + } |
| - int get end => _span.end; |
| + int get column { |
|
kasperl
2012/11/01 10:13:29
I'd factor out the computation part into a compute
Johnni Winther
2012/11/01 12:01:58
Done.
|
| + if (length == 0) return 0; |
| - Source get source => new Dart2JsSource(_script); |
| + var sourceFile = _script.file is SourceFile; |
| + if (sourceFile != null) { |
| + return sourceFile.getColumn(sourceFile.getLine(offset), offset); |
| + } |
| - String get text => _script.text.substring(start, end); |
| -} |
| + int index = offset-1; |
|
kasperl
2012/11/01 10:13:29
offset - 1 (spacing)
Johnni Winther
2012/11/01 12:01:58
Done.
|
| + var columnNumber = 0; |
| + while (0 <= index && index < sourceText.length) { |
| + var charCode = sourceText.charCodeAt(index); |
| + if (charCode == $CR || charCode == $LF) { |
| + break; |
| + } |
| + index--; |
| + columnNumber++; |
| + } |
| + return column; |
|
kasperl
2012/11/01 10:13:29
Hmm. This looks broken. Isn't this self-recursive?
Johnni Winther
2012/11/01 12:01:58
Yes. Fixed.
|
| + |
| + } |
| + |
| + int get offset => _span.begin; |
| -class Dart2JsSource implements Source { |
| - Script _script; |
| + int get length => _span.end - _span.end; |
| - Dart2JsSource(this._script); |
| + String get text => _script.text.substring(_span.begin, _span.end); |
| - Uri get uri => _script.uri; |
| + Uri get sourceUri => _script.uri; |
| - String get text => _script.text; |
| + String get sourceText => _script.text; |
| } |
| class Dart2JsParameterMirror extends Dart2JsMemberMirror |
| @@ -764,7 +794,7 @@ class Dart2JsClassMirror extends Dart2JsContainerMirror |
| if (node !== null) { |
| var script = _class.getCompilationUnit().script; |
| var span = mirrors.compiler.spanFromNode(node, script.uri); |
| - return new Dart2JsLocation(script, span); |
| + return new Dart2JsSourceLocation(script, span); |
| } |
| } |
| return super.location; |
| @@ -899,7 +929,7 @@ class Dart2JsTypedefMirror extends Dart2JsTypeElementMirror |
| if (node !== null) { |
| var script = _typedef.element.getCompilationUnit().script; |
| var span = mirrors.compiler.spanFromNode(node, script.uri); |
| - return new Dart2JsLocation(script, span); |
| + return new Dart2JsSourceLocation(script, span); |
| } |
| return super.location; |
| } |
| @@ -1023,7 +1053,7 @@ abstract class Dart2JsTypeElementMirror extends Dart2JsProxyMirror |
| SourceLocation get location { |
| var script = _type.element.getCompilationUnit().script; |
| - return new Dart2JsLocation(script, |
| + return new Dart2JsSourceLocation(script, |
| mirrors.compiler.spanFromElement(_type.element)); |
|
kasperl
2012/11/01 10:13:29
Indentation is off now.
Johnni Winther
2012/11/01 12:01:58
Done.
|
| } |
| @@ -1434,7 +1464,7 @@ class Dart2JsMethodMirror extends Dart2JsMemberMirror |
| if (node !== null) { |
| var script = _function.getCompilationUnit().script; |
| var span = mirrors.compiler.spanFromNode(node, script.uri); |
| - return new Dart2JsLocation(script, span); |
| + return new Dart2JsSourceLocation(script, span); |
| } |
| return super.location; |
| } |
| @@ -1475,10 +1505,10 @@ class Dart2JsFieldMirror extends Dart2JsMemberMirror implements VariableMirror { |
| var node = _variable.variables.parseNode(_diagnosticListener); |
| if (node !== null) { |
| var span = mirrors.compiler.spanFromNode(node, script.uri); |
| - return new Dart2JsLocation(script, span); |
| + return new Dart2JsSourceLocation(script, span); |
| } else { |
| var span = mirrors.compiler.spanFromElement(_variable); |
| - return new Dart2JsLocation(script, span); |
| + return new Dart2JsSourceLocation(script, span); |
| } |
| } |
| } |