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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/elements.dart

Issue 266913017: Convert property methods into getters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library elements; 5 library elements;
6 6
7 7
8 import '../tree/tree.dart'; 8 import '../tree/tree.dart';
9 import '../util/util.dart'; 9 import '../util/util.dart';
10 import '../resolution/resolution.dart'; 10 import '../resolution/resolution.dart';
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 /// Do not use [computeType] outside of the resolver; instead retrieve the 187 /// Do not use [computeType] outside of the resolver; instead retrieve the
188 /// type from the corresponding field: 188 /// type from the corresponding field:
189 /// - `type` for fields, variables, type variable, and function elements. 189 /// - `type` for fields, variables, type variable, and function elements.
190 /// - `thisType` or `rawType` for [TypeDeclarationElement]s (classes and 190 /// - `thisType` or `rawType` for [TypeDeclarationElement]s (classes and
191 /// typedefs), depending on the use case. 191 /// typedefs), depending on the use case.
192 /// Trying to access a type that has not been computed in resolution is an 192 /// Trying to access a type that has not been computed in resolution is an
193 /// error and calling [computeType] covers that error. 193 /// error and calling [computeType] covers that error.
194 /// This method will go away! 194 /// This method will go away!
195 @deprecated DartType computeType(Compiler compiler); 195 @deprecated DartType computeType(Compiler compiler);
196 196
197 bool isFunction(); 197 bool get isFunction;
198 bool isConstructor(); 198 bool get isConstructor;
199 bool isClosure(); 199 bool get isClosure;
200 bool isMember(); 200 bool get isMember;
201 bool isInstanceMember(); 201 bool get isInstanceMember;
202 202
203 bool isFactoryConstructor(); 203 bool get isFactoryConstructor;
204 bool isGenerativeConstructor(); 204 bool get isGenerativeConstructor;
205 bool isGenerativeConstructorBody(); 205 bool get isGenerativeConstructorBody;
206 bool isCompilationUnit(); 206 bool get isCompilationUnit;
207 bool isClass(); 207 bool get isClass;
208 bool isPrefix(); 208 bool get isPrefix;
209 bool isVariable(); 209 bool get isVariable;
210 bool isParameter(); 210 bool get isParameter;
211 bool isStatement(); 211 bool get isStatement;
212 bool isTypedef(); 212 bool get isTypedef;
213 bool isTypeVariable(); 213 bool get isTypeVariable;
214 bool isField(); 214 bool get isField;
215 bool isFieldParameter(); 215 bool get isFieldParameter;
216 bool isAbstractField(); 216 bool get isAbstractField;
217 bool isGetter(); 217 bool get isGetter;
218 bool isSetter(); 218 bool get isSetter;
219 bool isAccessor(); 219 bool get isAccessor;
220 bool isLibrary(); 220 bool get isLibrary;
221 bool isErroneous(); 221 bool get isErroneous;
222 bool isAmbiguous(); 222 bool get isAmbiguous;
223 bool isWarnOnUse(); 223 bool get isWarnOnUse;
224 224
225 /// Returns true if this [Element] is a top level element. 225 /// Returns true if this [Element] is a top level element.
226 /// That is, if it is not defined within the scope of a class. 226 /// That is, if it is not defined within the scope of a class.
227 /// 227 ///
228 /// This means whether the enclosing element is a compilation unit. 228 /// This means whether the enclosing element is a compilation unit.
229 /// With the exception of [ClosureClassElement] that is considered top level 229 /// With the exception of [ClosureClassElement] that is considered top level
230 /// as all other classes. 230 /// as all other classes.
231 bool isTopLevel(); 231 bool get isTopLevel;
232 bool isAssignable(); 232 bool get isAssignable;
233 bool isNative(); 233 bool get isNative;
234 bool isDeferredLoaderGetter(); 234 bool get isDeferredLoaderGetter;
235 235
236 bool impliesType(); 236 bool get impliesType;
237 237
238 Token position(); 238 Token get position;
239 239
240 CompilationUnitElement getCompilationUnit(); 240 CompilationUnitElement get compilationUnit;
241 LibraryElement getLibrary(); 241 LibraryElement get library;
242 LibraryElement getImplementationLibrary(); 242 LibraryElement get implementationLibrary;
243 ClassElement getEnclosingClass(); 243 ClassElement get enclosingClass;
244 Element getEnclosingClassOrCompilationUnit(); 244 Element get enclosingClassOrCompilationUnit;
245 Element getEnclosingMember(); 245 Element get enclosingMember;
246 Element getOutermostEnclosingMemberOrTopLevel(); 246 Element get outermostEnclosingMemberOrTopLevel;
247 247
248 FunctionElement asFunctionElement(); 248 FunctionElement asFunctionElement();
249 249
250 /// Is [:true:] if this element has a corresponding patch. 250 /// Is [:true:] if this element has a corresponding patch.
251 /// 251 ///
252 /// If [:true:] this element has a non-null [patch] field. 252 /// If [:true:] this element has a non-null [patch] field.
253 /// 253 ///
254 /// See [:patch_parser.dart:] for a description of the terminology. 254 /// See [:patch_parser.dart:] for a description of the terminology.
255 bool get isPatched; 255 bool get isPatched;
256 256
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 /// Returns the origin for this element if this element is a patch. 291 /// Returns the origin for this element if this element is a patch.
292 /// 292 ///
293 /// See [:patch_parser.dart:] for a description of the terminology. 293 /// See [:patch_parser.dart:] for a description of the terminology.
294 Element get origin; 294 Element get origin;
295 295
296 bool get isSynthesized; 296 bool get isSynthesized;
297 bool get isForwardingConstructor; 297 bool get isForwardingConstructor;
298 bool get isMixinApplication; 298 bool get isMixinApplication;
299 299
300 bool hasFixedBackendName(); 300 bool get hasFixedBackendName;
301 String fixedBackendName(); 301 String get fixedBackendName;
302 302
303 bool get isAbstract; 303 bool get isAbstract;
304 bool isForeign(Compiler compiler); 304 bool isForeign(Compiler compiler);
305 305
306 void addMetadata(MetadataAnnotation annotation); 306 void addMetadata(MetadataAnnotation annotation);
307 void setNative(String name); 307 void setNative(String name);
308 void setFixedBackendName(String name); 308 void setFixedBackendName(String name);
309 309
310 Scope buildScope(); 310 Scope buildScope();
311 311
312 /// If the element is a forwarding constructor, [targetConstructor] holds 312 /// If the element is a forwarding constructor, [targetConstructor] holds
313 /// the generative constructor that the forwarding constructor points to 313 /// the generative constructor that the forwarding constructor points to
314 /// (possibly via other forwarding constructors). 314 /// (possibly via other forwarding constructors).
315 FunctionElement get targetConstructor; 315 FunctionElement get targetConstructor;
316 316
317 void diagnose(Element context, DiagnosticListener listener); 317 void diagnose(Element context, DiagnosticListener listener);
318 318
319 TreeElements get treeElements; 319 TreeElements get treeElements;
320 320
321 accept(ElementVisitor visitor); 321 accept(ElementVisitor visitor);
322 } 322 }
323 323
324 class Elements { 324 class Elements {
325 static bool isUnresolved(Element e) { 325 static bool isUnresolved(Element e) {
326 return e == null || e.isErroneous(); 326 return e == null || e.isErroneous;
327 } 327 }
328 static bool isErroneousElement(Element e) => e != null && e.isErroneous(); 328 static bool isErroneousElement(Element e) => e != null && e.isErroneous;
329 329
330 /// Unwraps [element] reporting any warnings attached to it, if any. 330 /// Unwraps [element] reporting any warnings attached to it, if any.
331 static Element unwrap(Element element, 331 static Element unwrap(Element element,
332 DiagnosticListener listener, 332 DiagnosticListener listener,
333 Spannable spannable) { 333 Spannable spannable) {
334 if (element != null && element.isWarnOnUse()) { 334 if (element != null && element.isWarnOnUse) {
335 WarnOnUseElement wrappedElement = element; 335 WarnOnUseElement wrappedElement = element;
336 element = wrappedElement.unwrap(listener, spannable); 336 element = wrappedElement.unwrap(listener, spannable);
337 } 337 }
338 return element; 338 return element;
339 } 339 }
340 340
341 static bool isClass(Element e) => e != null && e.kind == ElementKind.CLASS; 341 static bool isClass(Element e) => e != null && e.kind == ElementKind.CLASS;
342 static bool isTypedef(Element e) { 342 static bool isTypedef(Element e) {
343 return e != null && e.kind == ElementKind.TYPEDEF; 343 return e != null && e.kind == ElementKind.TYPEDEF;
344 } 344 }
345 345
346 static bool isLocal(Element element) { 346 static bool isLocal(Element element) {
347 return !Elements.isUnresolved(element) 347 return !Elements.isUnresolved(element)
348 && !element.isInstanceMember() 348 && !element.isInstanceMember
349 && !isStaticOrTopLevelField(element) 349 && !isStaticOrTopLevelField(element)
350 && !isStaticOrTopLevelFunction(element) 350 && !isStaticOrTopLevelFunction(element)
351 && (identical(element.kind, ElementKind.VARIABLE) || 351 && (identical(element.kind, ElementKind.VARIABLE) ||
352 identical(element.kind, ElementKind.PARAMETER) || 352 identical(element.kind, ElementKind.PARAMETER) ||
353 identical(element.kind, ElementKind.FUNCTION)); 353 identical(element.kind, ElementKind.FUNCTION));
354 } 354 }
355 355
356 static bool isInstanceField(Element element) { 356 static bool isInstanceField(Element element) {
357 return !Elements.isUnresolved(element) 357 return !Elements.isUnresolved(element)
358 && element.isInstanceMember() 358 && element.isInstanceMember
359 && (identical(element.kind, ElementKind.FIELD) 359 && (identical(element.kind, ElementKind.FIELD)
360 || identical(element.kind, ElementKind.GETTER) 360 || identical(element.kind, ElementKind.GETTER)
361 || identical(element.kind, ElementKind.SETTER)); 361 || identical(element.kind, ElementKind.SETTER));
362 } 362 }
363 363
364 static bool isStaticOrTopLevel(Element element) { 364 static bool isStaticOrTopLevel(Element element) {
365 // TODO(ager): This should not be necessary when patch support has 365 // TODO(ager): This should not be necessary when patch support has
366 // been reworked. 366 // been reworked.
367 if (!Elements.isUnresolved(element) 367 if (!Elements.isUnresolved(element)
368 && element.modifiers.isStatic()) { 368 && element.modifiers.isStatic) {
369 return true; 369 return true;
370 } 370 }
371 return !Elements.isUnresolved(element) 371 return !Elements.isUnresolved(element)
372 && !element.isAmbiguous() 372 && !element.isAmbiguous
373 && !element.isInstanceMember() 373 && !element.isInstanceMember
374 && !element.isPrefix() 374 && !element.isPrefix
375 && element.enclosingElement != null 375 && element.enclosingElement != null
376 && (element.enclosingElement.kind == ElementKind.CLASS || 376 && (element.enclosingElement.kind == ElementKind.CLASS ||
377 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT || 377 element.enclosingElement.kind == ElementKind.COMPILATION_UNIT ||
378 element.enclosingElement.kind == ElementKind.LIBRARY || 378 element.enclosingElement.kind == ElementKind.LIBRARY ||
379 element.enclosingElement.kind == ElementKind.PREFIX); 379 element.enclosingElement.kind == ElementKind.PREFIX);
380 } 380 }
381 381
382 static bool isInStaticContext(Element element) { 382 static bool isInStaticContext(Element element) {
383 if (isUnresolved(element)) return true; 383 if (isUnresolved(element)) return true;
384 if (element.enclosingElement.isClosure()) { 384 if (element.enclosingElement.isClosure) {
385 var closureClass = element.enclosingElement; 385 var closureClass = element.enclosingElement;
386 element = closureClass.methodElement; 386 element = closureClass.methodElement;
387 } 387 }
388 Element outer = element.getOutermostEnclosingMemberOrTopLevel(); 388 Element outer = element.outermostEnclosingMemberOrTopLevel;
389 if (isUnresolved(outer)) return true; 389 if (isUnresolved(outer)) return true;
390 if (outer.isTopLevel()) return true; 390 if (outer.isTopLevel) return true;
391 if (outer.isGenerativeConstructor()) return false; 391 if (outer.isGenerativeConstructor) return false;
392 if (outer.isInstanceMember()) return false; 392 if (outer.isInstanceMember) return false;
393 return true; 393 return true;
394 } 394 }
395 395
396 static bool isStaticOrTopLevelField(Element element) { 396 static bool isStaticOrTopLevelField(Element element) {
397 return isStaticOrTopLevel(element) 397 return isStaticOrTopLevel(element)
398 && (identical(element.kind, ElementKind.FIELD) 398 && (identical(element.kind, ElementKind.FIELD)
399 || identical(element.kind, ElementKind.GETTER) 399 || identical(element.kind, ElementKind.GETTER)
400 || identical(element.kind, ElementKind.SETTER)); 400 || identical(element.kind, ElementKind.SETTER));
401 } 401 }
402 402
403 static bool isStaticOrTopLevelFunction(Element element) { 403 static bool isStaticOrTopLevelFunction(Element element) {
404 return isStaticOrTopLevel(element) 404 return isStaticOrTopLevel(element)
405 && (identical(element.kind, ElementKind.FUNCTION)); 405 && (identical(element.kind, ElementKind.FUNCTION));
406 } 406 }
407 407
408 static bool isInstanceMethod(Element element) { 408 static bool isInstanceMethod(Element element) {
409 return !Elements.isUnresolved(element) 409 return !Elements.isUnresolved(element)
410 && element.isInstanceMember() 410 && element.isInstanceMember
411 && (identical(element.kind, ElementKind.FUNCTION)); 411 && (identical(element.kind, ElementKind.FUNCTION));
412 } 412 }
413 413
414 static bool isNativeOrExtendsNative(ClassElement element) { 414 static bool isNativeOrExtendsNative(ClassElement element) {
415 if (element == null) return false; 415 if (element == null) return false;
416 if (element.isNative()) return true; 416 if (element.isNative) return true;
417 assert(element.resolutionState == STATE_DONE); 417 assert(element.resolutionState == STATE_DONE);
418 return isNativeOrExtendsNative(element.superclass); 418 return isNativeOrExtendsNative(element.superclass);
419 } 419 }
420 420
421 static bool isInstanceSend(Send send, TreeElements elements) { 421 static bool isInstanceSend(Send send, TreeElements elements) {
422 Element element = elements[send]; 422 Element element = elements[send];
423 if (element == null) return !isClosureSend(send, element); 423 if (element == null) return !isClosureSend(send, element);
424 return isInstanceMethod(element) || isInstanceField(element); 424 return isInstanceMethod(element) || isInstanceField(element);
425 } 425 }
426 426
427 static bool isClosureSend(Send send, Element element) { 427 static bool isClosureSend(Send send, Element element) {
428 if (send.isPropertyAccess) return false; 428 if (send.isPropertyAccess) return false;
429 if (send.receiver != null) return false; 429 if (send.receiver != null) return false;
430 Node selector = send.selector; 430 Node selector = send.selector;
431 // this(). 431 // this().
432 if (selector.isThis()) return true; 432 if (selector.isThis()) return true;
433 // (o)() or foo()(). 433 // (o)() or foo()().
434 if (element == null && selector.asIdentifier() == null) return true; 434 if (element == null && selector.asIdentifier() == null) return true;
435 if (element == null) return false; 435 if (element == null) return false;
436 // foo() with foo a local or a parameter. 436 // foo() with foo a local or a parameter.
437 return isLocal(element); 437 return isLocal(element);
438 } 438 }
439 439
440 static String reconstructConstructorNameSourceString(Element element) { 440 static String reconstructConstructorNameSourceString(Element element) {
441 if (element.name == '') { 441 if (element.name == '') {
442 return element.getEnclosingClass().name; 442 return element.enclosingClass.name;
443 } else { 443 } else {
444 return reconstructConstructorName(element); 444 return reconstructConstructorName(element);
445 } 445 }
446 } 446 }
447 447
448 // TODO(johnniwinther): Remove this method. 448 // TODO(johnniwinther): Remove this method.
449 static String reconstructConstructorName(Element element) { 449 static String reconstructConstructorName(Element element) {
450 String className = element.getEnclosingClass().name; 450 String className = element.enclosingClass.name;
451 if (element.name == '') { 451 if (element.name == '') {
452 return className; 452 return className;
453 } else { 453 } else {
454 return '$className\$${element.name}'; 454 return '$className\$${element.name}';
455 } 455 }
456 } 456 }
457 457
458 /** 458 /**
459 * Map an operator-name to a valid Dart identifier. 459 * Map an operator-name to a valid Dart identifier.
460 * 460 *
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 563
564 static bool isListSupertype(Element element, Compiler compiler) { 564 static bool isListSupertype(Element element, Compiler compiler) {
565 LibraryElement coreLibrary = compiler.coreLibrary; 565 LibraryElement coreLibrary = compiler.coreLibrary;
566 return element == coreLibrary.find('Iterable'); 566 return element == coreLibrary.find('Iterable');
567 } 567 }
568 568
569 /// A `compareTo` function that places [Element]s in a consistent order based 569 /// A `compareTo` function that places [Element]s in a consistent order based
570 /// on the source code order. 570 /// on the source code order.
571 static int compareByPosition(Element a, Element b) { 571 static int compareByPosition(Element a, Element b) {
572 if (identical(a, b)) return 0; 572 if (identical(a, b)) return 0;
573 int r = a.getLibrary().compareTo(b.getLibrary()); 573 int r = a.library.compareTo(b.library);
574 if (r != 0) return r; 574 if (r != 0) return r;
575 r = a.getCompilationUnit().compareTo(b.getCompilationUnit()); 575 r = a.compilationUnit.compareTo(b.compilationUnit);
576 if (r != 0) return r; 576 if (r != 0) return r;
577 Token positionA = a.position(); 577 Token positionA = a.position;
578 Token positionB = b.position(); 578 Token positionB = b.position;
579 int offsetA = positionA == null ? -1 : positionA.charOffset; 579 int offsetA = positionA == null ? -1 : positionA.charOffset;
580 int offsetB = positionB == null ? -1 : positionB.charOffset; 580 int offsetB = positionB == null ? -1 : positionB.charOffset;
581 r = offsetA.compareTo(offsetB); 581 r = offsetA.compareTo(offsetB);
582 if (r != 0) return r; 582 if (r != 0) return r;
583 r = a.name.compareTo(b.name); 583 r = a.name.compareTo(b.name);
584 if (r != 0) return r; 584 if (r != 0) return r;
585 // Same file, position and name. If this happens, we should find out why 585 // Same file, position and name. If this happens, we should find out why
586 // and make the order total and independent of hashCode. 586 // and make the order total and independent of hashCode.
587 return a.hashCode.compareTo(b.hashCode); 587 return a.hashCode.compareTo(b.hashCode);
588 } 588 }
(...skipping 25 matching lines...) Expand all
614 return element == compiler.filledListConstructor 614 return element == compiler.filledListConstructor
615 && node.isCall 615 && node.isCall
616 && !node.arguments.isEmpty 616 && !node.arguments.isEmpty
617 && !node.arguments.tail.isEmpty 617 && !node.arguments.tail.isEmpty
618 && node.arguments.tail.tail.isEmpty; 618 && node.arguments.tail.tail.isEmpty;
619 } 619 }
620 620
621 static bool isConstructorOfTypedArraySubclass(Element element, 621 static bool isConstructorOfTypedArraySubclass(Element element,
622 Compiler compiler) { 622 Compiler compiler) {
623 if (compiler.typedDataLibrary == null) return false; 623 if (compiler.typedDataLibrary == null) return false;
624 if (!element.isConstructor()) return false; 624 if (!element.isConstructor) return false;
625 FunctionElement constructor = element; 625 FunctionElement constructor = element;
626 constructor = constructor.redirectionTarget; 626 constructor = constructor.redirectionTarget;
627 ClassElement cls = constructor.getEnclosingClass(); 627 ClassElement cls = constructor.enclosingClass;
628 return cls.getLibrary() == compiler.typedDataLibrary 628 return cls.library == compiler.typedDataLibrary
629 && cls.isNative() 629 && cls.isNative
630 && compiler.world.isSubtype(compiler.typedDataClass, cls) 630 && compiler.world.isSubtype(compiler.typedDataClass, cls)
631 && compiler.world.isSubtype(compiler.listClass, cls) 631 && compiler.world.isSubtype(compiler.listClass, cls)
632 && constructor.name == ''; 632 && constructor.name == '';
633 } 633 }
634 634
635 static bool switchStatementHasContinue(SwitchStatement node, 635 static bool switchStatementHasContinue(SwitchStatement node,
636 TreeElements elements) { 636 TreeElements elements) {
637 for (SwitchCase switchCase in node.cases) { 637 for (SwitchCase switchCase in node.cases) {
638 for (Node labelOrCase in switchCase.labelsAndCases) { 638 for (Node labelOrCase in switchCase.labelsAndCases) {
639 Node label = labelOrCase.asLabel(); 639 Node label = labelOrCase.asLabel();
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 bool get isDeclaredByField; 1171 bool get isDeclaredByField;
1172 1172
1173 /// Returns `true` if this member is abstract. 1173 /// Returns `true` if this member is abstract.
1174 bool get isAbstract; 1174 bool get isAbstract;
1175 1175
1176 /// If abstract, [implementation] points to the overridden concrete member, 1176 /// If abstract, [implementation] points to the overridden concrete member,
1177 /// if any. Otherwise [implementation] points to the member itself. 1177 /// if any. Otherwise [implementation] points to the member itself.
1178 Member get implementation; 1178 Member get implementation;
1179 } 1179 }
1180 1180
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698