Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2741)

Unified Diff: pkg/analyzer/tool/summary/generate.dart

Issue 1420053011: Introduce code to generate summaries from an element model. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove more unnecessary TODOs. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/tool/summary/generate.dart
diff --git a/pkg/analyzer/tool/summary/generate.dart b/pkg/analyzer/tool/summary/generate.dart
index 5e4b2c2a9e37a2015fc173644b57c173b7ccfe29..88f7b349e63c49853ba7e2a7fb8e681c1faf1389 100644
--- a/pkg/analyzer/tool/summary/generate.dart
+++ b/pkg/analyzer/tool/summary/generate.dart
@@ -156,7 +156,15 @@ class _CodeGenerator {
_idl = new idlModel.Idl();
for (CompilationUnitMember decl in idlParsed.declarations) {
if (decl is ClassDeclaration) {
- idlModel.ClassDeclaration cls = new idlModel.ClassDeclaration();
+ bool isTopLevel = false;
+ for (Annotation annotation in decl.metadata) {
+ if (annotation.arguments == null &&
+ annotation.name.name == 'topLevel') {
+ isTopLevel = true;
+ }
+ }
+ idlModel.ClassDeclaration cls =
+ new idlModel.ClassDeclaration(isTopLevel);
_idl.classes[decl.name.name] = cls;
for (ClassMember classMember in decl.members) {
if (classMember is FieldDeclaration) {
@@ -236,6 +244,7 @@ class _CodeGenerator {
out();
out('library analyzer.src.summary.format;');
out();
+ out("import 'dart:convert';");
out("import 'builder.dart' as builder;");
out();
_idl.enums.forEach((String name, idlModel.EnumDeclaration enm) {
@@ -281,6 +290,10 @@ class _CodeGenerator {
}
});
out();
+ if (cls.isTopLevel) {
+ out('$name.fromBuffer(List<int> buffer) : this.fromJson(JSON.decode(UTF8.decode(buffer)));');
+ out();
+ }
cls.fields.forEach((String fieldName, idlModel.FieldType type) {
String def = defaultValue(type);
String defaultSuffix = def == null ? '' : ' ?? $def';

Powered by Google App Engine
This is Rietveld 408576698