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

Side by Side Diff: pkg/compiler/lib/src/mirrors/dart2js_member_mirrors.dart

Issue 1799283002: Delete support for source mirrors (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: new attempt Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart 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 file.
4
5 part of dart2js.mirrors;
6
7 //------------------------------------------------------------------------------
8 // Member mirrors implementation.
9 //------------------------------------------------------------------------------
10
11 abstract class Dart2JsMemberMirror extends Dart2JsElementMirror {
12 Dart2JsMemberMirror(Dart2JsMirrorSystem system, AstElement element)
13 : super(system, element);
14
15 bool get isStatic => false;
16 }
17
18 class Dart2JsMethodKind {
19 static const Dart2JsMethodKind REGULAR = const Dart2JsMethodKind("regular");
20 static const Dart2JsMethodKind GENERATIVE =
21 const Dart2JsMethodKind("generative");
22 static const Dart2JsMethodKind REDIRECTING =
23 const Dart2JsMethodKind("redirecting");
24 static const Dart2JsMethodKind CONST = const Dart2JsMethodKind("const");
25 static const Dart2JsMethodKind FACTORY = const Dart2JsMethodKind("factory");
26 static const Dart2JsMethodKind GETTER = const Dart2JsMethodKind("getter");
27 static const Dart2JsMethodKind SETTER = const Dart2JsMethodKind("setter");
28 static const Dart2JsMethodKind OPERATOR = const Dart2JsMethodKind("operator");
29
30 final String text;
31
32 const Dart2JsMethodKind(this.text);
33
34 String toString() => text;
35 }
36
37 class Dart2JsMethodMirror extends Dart2JsMemberMirror implements MethodMirror {
38 final Dart2JsDeclarationMirror owner;
39 final String _simpleNameString;
40 final Dart2JsMethodKind _kind;
41
42 Dart2JsMethodMirror._internal(
43 Dart2JsDeclarationMirror owner,
44 FunctionElement function,
45 String this._simpleNameString,
46 Dart2JsMethodKind this._kind)
47 : this.owner = owner,
48 super(owner.mirrorSystem, function);
49
50 factory Dart2JsMethodMirror(
51 Dart2JsDeclarationMirror owner, FunctionElement function) {
52 String simpleName = function.name;
53 // TODO(ahe): This method should not be calling
54 // Elements.operatorNameToIdentifier.
55 Dart2JsMethodKind kind;
56 if (function.kind == ElementKind.GETTER) {
57 kind = Dart2JsMethodKind.GETTER;
58 } else if (function.kind == ElementKind.SETTER) {
59 kind = Dart2JsMethodKind.SETTER;
60 simpleName = '$simpleName=';
61 } else if (function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
62 // TODO(johnniwinther): Support detection of redirecting constructors.
63 if (function.isConst) {
64 kind = Dart2JsMethodKind.CONST;
65 } else {
66 kind = Dart2JsMethodKind.GENERATIVE;
67 }
68 } else if (function.isFactoryConstructor) {
69 // TODO(johnniwinther): Support detection of redirecting constructors.
70 kind = Dart2JsMethodKind.FACTORY;
71 } else if (function.isOperator) {
72 kind = Dart2JsMethodKind.OPERATOR;
73 } else {
74 kind = Dart2JsMethodKind.REGULAR;
75 }
76 return new Dart2JsMethodMirror._internal(owner, function, simpleName, kind);
77 }
78
79 FunctionElement get _function => _element;
80
81 bool get isTopLevel => owner is LibraryMirror;
82
83 // TODO(johnniwinther): This seems stale and broken.
84 Symbol get constructorName => isConstructor ? simpleName : const Symbol('');
85
86 bool get isConstructor =>
87 isGenerativeConstructor ||
88 isConstConstructor ||
89 isFactoryConstructor ||
90 isRedirectingConstructor;
91
92 bool get isSynthetic => false;
93
94 bool get isStatic => _function.isStatic;
95
96 List<ParameterMirror> get parameters {
97 return _parametersFromFunctionSignature(this, _function.functionSignature);
98 }
99
100 TypeMirror get returnType =>
101 owner._getTypeMirror(_function.functionSignature.type.returnType);
102
103 bool get isAbstract => _function.isAbstract;
104
105 bool get isRegularMethod => !(isGetter || isSetter || isConstructor);
106
107 bool get isConstConstructor => _kind == Dart2JsMethodKind.CONST;
108
109 bool get isGenerativeConstructor => _kind == Dart2JsMethodKind.GENERATIVE;
110
111 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING;
112
113 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY;
114
115 bool get isGetter => _kind == Dart2JsMethodKind.GETTER;
116
117 bool get isSetter => _kind == Dart2JsMethodKind.SETTER;
118
119 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR;
120
121 DeclarationMirror lookupInScope(String name) {
122 for (Dart2JsParameterMirror parameter in parameters) {
123 if (parameter._element.name == name) {
124 return parameter;
125 }
126 }
127 return super.lookupInScope(name);
128 }
129
130 // TODO(johnniwinther): Should this really be in the interface of
131 // [MethodMirror]?
132 String get source => location.sourceText;
133
134 String toString() => 'Mirror on method ${_element.name}';
135 }
136
137 class Dart2JsFieldMirror extends Dart2JsMemberMirror implements VariableMirror {
138 final Dart2JsDeclarationMirror owner;
139 VariableElement _variable;
140
141 Dart2JsFieldMirror(Dart2JsDeclarationMirror owner, VariableElement variable)
142 : this.owner = owner,
143 this._variable = variable,
144 super(owner.mirrorSystem, variable);
145
146 bool get isTopLevel => owner is LibraryMirror;
147
148 bool get isStatic => _variable.isStatic;
149
150 bool get isFinal => _variable.isFinal;
151
152 bool get isConst => _variable.isConst;
153
154 TypeMirror get type => owner._getTypeMirror(_variable.type);
155 }
156
157 class Dart2JsParameterMirror extends Dart2JsMemberMirror
158 implements ParameterMirror {
159 final Dart2JsDeclarationMirror owner;
160 final bool isOptional;
161 final bool isNamed;
162
163 factory Dart2JsParameterMirror(
164 Dart2JsDeclarationMirror owner, FormalElement element,
165 {bool isOptional: false, bool isNamed: false}) {
166 if (element is InitializingFormalElement) {
167 return new Dart2JsFieldParameterMirror(
168 owner, element, isOptional, isNamed);
169 } else {
170 return new Dart2JsParameterMirror._normal(
171 owner, element, isOptional, isNamed);
172 }
173 }
174
175 Dart2JsParameterMirror._normal(Dart2JsDeclarationMirror owner,
176 FormalElement element, this.isOptional, this.isNamed)
177 : this.owner = owner,
178 super(owner.mirrorSystem, element);
179
180 FormalElement get _element => super._element;
181
182 TypeMirror get type => owner._getTypeMirror(_element.type);
183
184 bool get isFinal => false;
185
186 bool get isConst => false;
187
188 InstanceMirror get defaultValue {
189 if (hasDefaultValue) {
190 // TODO(johnniwinther): Get the constant from the [TreeElements]
191 // associated with the enclosing method.
192 ParameterElement parameter = _element;
193 ConstantExpression constant = parameter.constant;
194 assert(invariant(parameter, constant != null,
195 message: "Missing constant for parameter "
196 "$parameter with default value."));
197 return _convertConstantToInstanceMirror(mirrorSystem, constant,
198 mirrorSystem.compiler.constants.getConstantValue(constant));
199 }
200 return null;
201 }
202
203 bool get hasDefaultValue {
204 if (_element is ParameterElement) {
205 ParameterElement parameter = _element;
206 return parameter.initializer != null;
207 }
208 return false;
209 }
210
211 bool get isInitializingFormal => false;
212
213 VariableMirror get initializedField => null;
214 }
215
216 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror {
217 Dart2JsFieldParameterMirror(Dart2JsDeclarationMirror method,
218 InitializingFormalElement element, bool isOptional, bool isNamed)
219 : super._normal(method, element, isOptional, isNamed);
220
221 InitializingFormalElement get _fieldParameterElement => _element;
222
223 bool get isInitializingFormal => true;
224
225 VariableMirror get initializedField =>
226 new Dart2JsFieldMirror(owner.owner, _fieldParameterElement.fieldElement);
227 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/mirrors/dart2js_library_mirror.dart ('k') | pkg/compiler/lib/src/mirrors/dart2js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698