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

Side by Side Diff: pkg/fletchc/lib/src/model.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 months 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 unified diff | Download patch
« no previous file with comments | « pkg/fletchc/lib/src/messages.dart ('k') | pkg/fletchc/lib/src/please_report_crash.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file.
4
5 library fletchc.model;
6
7 import 'dart:mirrors' as mirrors;
8
9 /**
10 * Indirection from the class mirror. This allows us to adapt the interface
11 * here as needed.
12 */
13 class ClassMirror implements mirrors.ClassMirror {
14 mirrors.ClassMirror _raw;
15
16 Map<Symbol, mirrors.DeclarationMirror> get declarations => _raw.declarations;
17
18 mirrors.InstanceMirror getField(Symbol fieldName) => _raw.getField(fieldName);
19
20 bool get hasReflectedType => _raw.hasReflectedType;
21
22 Map<Symbol, mirrors.MethodMirror> get instanceMembers => _raw.instanceMembers;
23
24 bool get isAbstract => _raw.isAbstract;
25
26 bool isAssignableTo(mirrors.TypeMirror other) => _raw.isAssignableTo(other);
27
28 bool get isEnum => _raw.isEnum;
29
30 bool get isOriginalDeclaration => _raw.isOriginalDeclaration;
31
32 bool get isPrivate => _raw.isPrivate;
33
34 bool isSubclassOf(mirrors.ClassMirror other) => _raw.isSubclassOf(other);
35
36 bool isSubtypeOf(mirrors.TypeMirror other) => _raw.isSubtypeOf(other);
37
38 bool get isTopLevel => _raw.isTopLevel;
39
40 mirrors.SourceLocation get location => _raw.location;
41
42 mirrors.ClassMirror get mixin => _raw.mixin;
43
44 List<mirrors.InstanceMirror> get metadata => _raw.metadata;
45
46 mirrors.ClassMirror get superclass => _raw.superclass;
47
48 List<mirrors.ClassMirror> get superinterfaces => _raw.superinterfaces;
49
50 List<mirrors.TypeMirror> get typeArguments => _raw.typeArguments;
51
52 List<mirrors.TypeVariableMirror> get typeVariables => _raw.typeVariables;
53
54 mirrors.TypeMirror get originalDeclaration => _raw.originalDeclaration;
55
56 mirrors.DeclarationMirror get owner => _raw.owner;
57
58 Symbol get qualifiedName => _raw.qualifiedName;
59
60 Type get reflectedType => _raw.reflectedType;
61
62 Symbol get simpleName => _raw.simpleName;
63
64 Map<Symbol, mirrors.MethodMirror> get staticMembers => _raw.staticMembers;
65
66 mirrors.InstanceMirror newInstance(
67 Symbol constructorName,
68 List positionalArguments,
69 [Map<Symbol, dynamic> namedArguments]) {
70 throw ("Not implemented here.");
71 }
72
73 mirrors.InstanceMirror invoke(
74 Symbol memberName,
75 List positionalArguments,
76 [Map<Symbol, dynamic> namedArguments]) {
77 throw ("Not implemented here.");
78 }
79
80 mirrors.InstanceMirror setField(Symbol fieldName, Object value) {
81 throw ("Not implemented here.");
82 }
83
84 ClassBuilder get builder {
85 return new ClassBuilder(this);
86 }
87
88 }
89
90 /**
91 * [ClassBuilder] represents a set of changes to be previewed or applied
92 * to a class.
93 */
94 class ClassBuilder {
95 /**
96 * Should the entire class be deleted?
97 */
98 bool deleteClass = false;
99
100 /**
101 * The class mirror that this builder was derived from.
102 */
103 final ClassMirror original;
104
105 /**
106 * The definition of the change to the header of the class
107 * An empty string implies no change.
108 * for example: "class Foo extends Bar"
109 */
110 String classHeader = "";
111
112 /**
113 * A map of how the instance members of [original] should
114 * look after this builder has been applied.
115 */
116 final Map<String, MirrorBuilder> instanceMembers = {};
117
118 /**
119 * A map of how the static members of [original] should
120 * look after this builder has been applied.
121 */
122 final Map<String, MirrorBuilder> staticMembers = {};
123
124 /**
125 * A map of how the fields of [original] should
126 * look after this builder has been applied.
127 */
128 final Map<String, MirrorBuilder> fields = {};
129
130 ClassBuilder(this.original) {
131
132 // Setup with no changes by default.
133
134 original.staticMembers.forEach((symbol, methodMirror) {
135 String name = mirrors.MirrorSystem.getName(symbol);
136 staticMembers.putIfAbsent(
137 name, () => new MirrorBuilder.fromMirror(methodMirror));
138 });
139
140 original.instanceMembers.forEach((symbol, methodMirror) {
141 String name = mirrors.MirrorSystem.getName(symbol);
142 staticMembers.putIfAbsent(
143 name, () => new MirrorBuilder.fromMirror(methodMirror));
144 });
145
146 // TODO(lukechurch): Do the same thing for fields.
147 }
148
149 /**
150 * Construct a new class from [classHeader].
151 */
152 ClassBuilder.fromEmpty(this.classHeader) : original = null;
153 }
154
155 /**
156 * Used to assemble a change to a [ClassBuilder].
157 */
158 class MirrorBuilder {
159 final String newSource;
160 final mirrors.DeclarationMirror reuseFrom;
161
162 /**
163 * Represents a replacement of the implementation of a declaration with
164 * a new version from [newSource].
165 */
166 MirrorBuilder.fromSource(this.newSource)
167 : this.reuseFrom = null;
168
169 /**
170 * Represents reusing the implementation from [reuseFrom].
171 */
172 MirrorBuilder.fromMirror(this.reuseFrom)
173 : this.newSource = null;
174
175 bool get hasSource => newSource != null;
176 bool get isReusing => reuseFrom != null;
177 }
178
OLDNEW
« no previous file with comments | « pkg/fletchc/lib/src/messages.dart ('k') | pkg/fletchc/lib/src/please_report_crash.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698