Index: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart |
index 7e7e4823367cf371c83a62f6c71971203534cd3f..e52771da4ef8ca8f50ec6fca50baa1dc89706c34 100644 |
--- a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart |
+++ b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart |
@@ -11,7 +11,7 @@ import '../../compiler.dart' as diagnostics; |
import '../elements/elements.dart'; |
import '../resolution/resolution.dart' show ResolverTask, ResolverVisitor; |
import '../apiimpl.dart' as api; |
-import '../scanner/scannerlib.dart'; |
+import '../scanner/scannerlib.dart' hide SourceString; |
import '../ssa/ssa.dart'; |
import '../dart2jslib.dart'; |
import '../filenames.dart'; |
@@ -391,7 +391,7 @@ class Dart2JsCompilation implements Compilation { |
packageUri = libraryUri; |
} |
_compiler = new api.Compiler(provider, handler, |
- libraryUri, packageUri, <String>[]); |
+ libraryUri, packageUri, opts); |
var scriptUri = cwd.resolve(script.toString()); |
// TODO(johnniwinther): Detect file not found |
_compiler.run(scriptUri); |
@@ -408,7 +408,7 @@ class Dart2JsCompilation implements Compilation { |
packageUri = libraryUri; |
} |
_compiler = new LibraryCompiler(provider, handler, |
- libraryUri, packageUri, <String>[]); |
+ libraryUri, packageUri, opts); |
var librariesUri = <Uri>[]; |
for (Path library in libraries) { |
librariesUri.add(cwd.resolve(library.toString())); |
@@ -534,14 +534,24 @@ abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { |
int get hashCode => qualifiedName.hashCode; |
+ void _appendCommentTokens(Token commentToken) { |
+ while (commentToken != null && commentToken.kind == COMMENT_TOKEN) { |
+ _metadata.add(new Dart2JsCommentInstanceMirror( |
+ mirrors, commentToken.slowToString())); |
+ commentToken = commentToken.next; |
+ } |
+ } |
+ |
List<InstanceMirror> get metadata { |
if (_metadata == null) { |
_metadata = <InstanceMirror>[]; |
for (MetadataAnnotation metadata in _element.metadata) { |
+ _appendCommentTokens(mirrors.compiler.commentMap[metadata.beginToken]); |
ahe
2013/01/03 13:04:09
I think this has horrible performance.
|
metadata.ensureResolved(mirrors.compiler); |
_metadata.add( |
_convertConstantToInstanceMirror(mirrors, metadata.value)); |
} |
+ _appendCommentTokens(mirrors.compiler.commentMap[getBeginToken()]); |
ahe
2013/01/03 13:04:09
Ditto.
|
} |
// TODO(johnniwinther): Return an unmodifiable list instead. |
return new List<InstanceMirror>.from(_metadata); |
@@ -1776,4 +1786,85 @@ class Dart2JsConstructedConstantMirror extends Dart2JsConstantMirror { |
} |
return super.getField(fieldName); |
} |
+} |
+ |
+ |
+/** |
+ * Pulls the raw text out of a doc comment (i.e. removes the comment |
+ * characters). |
+ */ |
+String _stripComment(String comment) { |
Andrei Mouravski
2013/01/02 16:56:06
Why not make this public or even put it into a uti
|
+ if (comment.startsWith('///')) { |
+ var line = comment.substring(3); |
+ // Allow a leading space. |
ahe
2013/01/03 13:04:09
allow -> strip.
|
+ if (line.startsWith(' ')) line = line.substring(1); |
+ return line; |
+ } else { |
ahe
2013/01/03 13:04:09
I suggest you handle this case differently, per my
|
+ StringBuffer buf = new StringBuffer(); |
+ for (var line in comment.split('\n')) { |
+ line = line.trim(); |
ahe
2013/01/03 13:04:09
This deletes trailing whitespace, unlike how you h
|
+ if (line.startsWith('/**')) line = line.substring(3); |
ahe
2013/01/03 13:04:09
You don't need to trim the line to test for this.
|
+ if (line.endsWith('*/')) line = line.substring(0, line.length - 2); |
ahe
2013/01/03 13:04:09
You don't need to trim the line to test for this.
|
+ line = line.trim(); |
ahe
2013/01/03 13:04:09
I don't understand why you're trimming again.
|
+ if (line.startsWith('* ')) { |
ahe
2013/01/03 13:04:09
This has weird behavior for comments like this:
/
|
+ line = line.substring(2); |
+ } else if (line.startsWith('*')) { |
+ line = line.substring(1); |
+ } |
+ |
+ buf.add(line); |
+ buf.add('\n'); |
+ } |
+ return buf.toString(); |
+ } |
+} |
+ |
+class Dart2JsCommentInstanceMirror implements CommentInstanceMirror { |
+ final Dart2JsMirrorSystem mirrors; |
+ final String text; |
+ String _trimmedText; |
+ |
+ Dart2JsCommentInstanceMirror(this.mirrors, this.text); |
+ |
+ ClassMirror get type { |
+ var uri = new Uri.fromComponents(scheme: 'dart', path: 'mirrors'); |
+ LibraryElement libraryElement = |
+ mirrors.compiler.libraryLoader.loadLibrary(uri, null, uri); |
ahe
2013/01/03 13:04:09
This seems overly lazy. Can you initialize the obj
Johnni Winther
2013/01/04 16:40:53
The class element is now loaded in [Compiler.scanB
|
+ var element = libraryElement.find(const SourceString('Comment')); |
+ return new Dart2JsClassMirror(mirrors, element); |
+ } |
+ |
+ bool get isDocComment => text.startsWith('/**') || text.startsWith('///'); |
+ |
+ String get trimmedText { |
+ if (_trimmedText == null) { |
+ _trimmedText = _stripComment(text); |
+ } |
+ return _trimmedText; |
+ } |
+ |
+ bool get hasReflectee => false; |
+ |
+ get reflectee { |
+ // TODO(johnniwinther): Which exception/error should be thrown here? |
+ throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
+ } |
+ |
+ Future<InstanceMirror> getField(String fieldName) { |
+ if (fieldName == 'isDocComment') { |
+ return new Future.immediate( |
+ new Dart2JsBoolConstantMirror(mirrors, |
+ isDocComment ? new TrueConstant() : new FalseConstant())); |
+ } else if (fieldName == 'text') { |
+ return new Future.immediate( |
+ new Dart2JsStringConstantMirror(mirrors, |
+ new StringConstant(new DartString.literal(text), null))); |
+ } else if (fieldName == 'trimmedText') { |
+ return new Future.immediate( |
+ new Dart2JsStringConstantMirror(mirrors, |
+ new StringConstant(new DartString.literal(trimmedText), null))); |
ahe
2013/01/03 13:04:09
You might benefit from a new constructor on Dart2J
Johnni Winther
2013/01/04 16:40:53
Done.
|
+ } |
+ // TODO(johnniwinther): Which exception/error should be thrown here? |
+ throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
+ } |
} |