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

Side by Side Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 738673002: Use shorter DartElementLocation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element; 8 library engine.element;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
11 11
12 import 'ast.dart'; 12 import 'ast.dart';
13 import 'constant.dart' show EvaluationResultImpl; 13 import 'constant.dart' show EvaluationResultImpl;
14 import 'engine.dart' show AnalysisContext, AnalysisEngine, AnalysisException; 14 import 'engine.dart' show AnalysisContext, AnalysisEngine, AnalysisException;
15 import 'html.dart' show XmlAttributeNode, XmlTagNode; 15 import 'html.dart' show XmlAttributeNode, XmlTagNode;
16 import 'java_core.dart'; 16 import 'java_core.dart';
17 import 'java_engine.dart'; 17 import 'java_engine.dart';
18 import 'resolver.dart'; 18 import 'resolver.dart';
19 import 'scanner.dart' show Keyword; 19 import 'scanner.dart' show Keyword;
20 import 'sdk.dart' show DartSdk; 20 import 'sdk.dart' show DartSdk;
21 import 'source.dart'; 21 import 'source.dart';
22 import 'utilities_collection.dart'; 22 import 'utilities_collection.dart';
23 import 'utilities_dart.dart'; 23 import 'utilities_dart.dart';
24 import 'element.dart';
24 25
25 /** 26 /**
26 * Information about Angular application. 27 * Information about Angular application.
27 */ 28 */
28 class AngularApplication { 29 class AngularApplication {
29 final Source entryPoint; 30 final Source entryPoint;
30 31
31 final Set<Source> _librarySources; 32 final Set<Source> _librarySources;
32 33
33 final List<AngularElement> elements; 34 final List<AngularElement> elements;
(...skipping 2358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 return type; 2393 return type;
2393 } 2394 }
2394 } 2395 }
2395 return null; 2396 return null;
2396 } 2397 }
2397 2398
2398 @override 2399 @override
2399 void visitChildren(ElementVisitor visitor) { 2400 void visitChildren(ElementVisitor visitor) {
2400 super.visitChildren(visitor); 2401 super.visitChildren(visitor);
2401 safelyVisitChildren(_accessors, visitor); 2402 safelyVisitChildren(_accessors, visitor);
2403 safelyVisitChildren(_enums, visitor);
2402 safelyVisitChildren(_functions, visitor); 2404 safelyVisitChildren(_functions, visitor);
2403 safelyVisitChildren(_typeAliases, visitor); 2405 safelyVisitChildren(_typeAliases, visitor);
2404 safelyVisitChildren(_types, visitor); 2406 safelyVisitChildren(_types, visitor);
2405 safelyVisitChildren(_variables, visitor); 2407 safelyVisitChildren(_variables, visitor);
2406 safelyVisitChildren(_angularViews, visitor); 2408 safelyVisitChildren(_angularViews, visitor);
2407 } 2409 }
2408 2410
2409 /** 2411 /**
2410 * Returns the associated toolkit objects. 2412 * Returns the associated toolkit objects.
2411 * 2413 *
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 * of this class should be accessed through the method [getInstance]. 2967 * of this class should be accessed through the method [getInstance].
2966 */ 2968 */
2967 DynamicElementImpl() : super(Keyword.DYNAMIC.syntax, -1) { 2969 DynamicElementImpl() : super(Keyword.DYNAMIC.syntax, -1) {
2968 setModifier(Modifier.SYNTHETIC, true); 2970 setModifier(Modifier.SYNTHETIC, true);
2969 } 2971 }
2970 2972
2971 @override 2973 @override
2972 ElementKind get kind => ElementKind.DYNAMIC; 2974 ElementKind get kind => ElementKind.DYNAMIC;
2973 2975
2974 @override 2976 @override
2977 ElementLocation get location {
2978 return new DartElementLocation(null, null, nameOffset, kind);
2979 }
2980
2981 @override
2975 accept(ElementVisitor visitor) => null; 2982 accept(ElementVisitor visitor) => null;
2976 } 2983 }
2977 2984
2978 /** 2985 /**
2979 * The unique instance of the class `DynamicTypeImpl` implements the type `dynam ic`. 2986 * The unique instance of the class `DynamicTypeImpl` implements the type `dynam ic`.
2980 */ 2987 */
2981 class DynamicTypeImpl extends TypeImpl { 2988 class DynamicTypeImpl extends TypeImpl {
2982 /** 2989 /**
2983 * The unique instance of this class. 2990 * The unique instance of this class.
2984 */ 2991 */
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
3552 bool get isPublic => !isPrivate; 3559 bool get isPublic => !isPrivate;
3553 3560
3554 @override 3561 @override
3555 bool get isSynthetic => hasModifier(Modifier.SYNTHETIC); 3562 bool get isSynthetic => hasModifier(Modifier.SYNTHETIC);
3556 3563
3557 @override 3564 @override
3558 LibraryElement get library => 3565 LibraryElement get library =>
3559 getAncestor((element) => element is LibraryElement); 3566 getAncestor((element) => element is LibraryElement);
3560 3567
3561 @override 3568 @override
3562 ElementLocation get location => new ElementLocationImpl.con1(this); 3569 ElementLocation get location {
3570 // TODO(scheglov) add separate DartElementImpl
Brian Wilkerson 2014/11/18 15:11:22 I don't know what that means.
3571 LibraryElement library = this.library;
3572 if (library == null) {
3573 return new DartElementLocation(null, null, nameOffset, kind);
3574 }
3575 String librarySourceEncoding = library.source.encoding;
3576 String unitSourceEncoding = source.encoding;
3577 return new DartElementLocation(
3578 librarySourceEncoding,
3579 unitSourceEncoding,
3580 nameOffset,
3581 kind);
3582 }
3563 3583
3564 @override 3584 @override
3565 String get name => _name; 3585 String get name => _name;
3566 3586
3567 @override 3587 @override
3568 AstNode get node => getNodeMatching((node) => node is AstNode); 3588 AstNode get node => getNodeMatching((node) => node is AstNode);
3569 3589
3570 @override 3590 @override
3571 Source get source { 3591 Source get source {
3572 if (_enclosingElement == null) { 3592 if (_enclosingElement == null) {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
3906 */ 3926 */
3907 static ElementKind of(Element element) { 3927 static ElementKind of(Element element) {
3908 if (element == null) { 3928 if (element == null) {
3909 return ERROR; 3929 return ERROR;
3910 } 3930 }
3911 return element.kind; 3931 return element.kind;
3912 } 3932 }
3913 } 3933 }
3914 3934
3915 /** 3935 /**
3916 * The interface `ElementLocation` defines the behavior of objects that represen t the location 3936 * The interface `ElementLocation` defines the behavior of objects that
3917 * of an element within the element model. 3937 * represent the location of an element within the element model.
3918 */ 3938 */
3919 abstract class ElementLocation { 3939 abstract class ElementLocation {
3920 /**
3921 * Return the path to the element whose location is represented by this object . Clients must not
3922 * modify the returned array.
3923 *
3924 * @return the path to the element whose location is represented by this objec t
3925 */
3926 List<String> get components;
3927
3928 /**
3929 * Return an encoded representation of this location that can be used to creat e a location that is
3930 * equal to this location.
3931 *
3932 * @return an encoded representation of this location
3933 */
3934 String get encoding;
3935 } 3940 }
3936 3941
3937 /** 3942 /**
3938 * Instances of the class `ElementLocationImpl` implement an [ElementLocation]. 3943 * The interface `DartElementLocation` defines the behavior of objects that
3944 * represent the location of a Dart element within the element model.
3939 */ 3945 */
3940 class ElementLocationImpl implements ElementLocation { 3946 class DartElementLocation implements ElementLocation {
3941 /** 3947 /**
3942 * The character used to separate components in the encoded form. 3948 * An encoded representation of the library source that contains this element.
3943 */ 3949 */
3944 static int _SEPARATOR_CHAR = 0x3B; 3950 final String librarySourceEncoding;
3945 3951
3946 /** 3952 /**
3947 * The path to the element whose location is represented by this object. 3953 * An encoded representation of the unit source that contains this element.
3948 */ 3954 */
3949 List<String> _components; 3955 final String unitSourceEncoding;
3950 3956
3951 /** 3957 /**
3952 * Initialize a newly created location to represent the given element. 3958 * The offset of the name of this element in the file that contains
3953 * 3959 * the declaration of this element, or `-1` if this element is synthetic,
3954 * @param element the element whose location is being represented 3960 * does not have a name, or otherwise does not have an offset.
3955 */ 3961 */
3956 ElementLocationImpl.con1(Element element) { 3962 final int nameOffset;
3957 List<String> components = new List<String>();
3958 Element ancestor = element;
3959 while (ancestor != null) {
3960 components.insert(0, (ancestor as ElementImpl).identifier);
3961 ancestor = ancestor.enclosingElement;
3962 }
3963 this._components = components;
3964 }
3965 3963
3966 /** 3964 /**
3967 * Initialize a newly created location from the given encoded form. 3965 * The kind of this element.
3968 *
3969 * @param encoding the encoded form of a location
3970 */ 3966 */
3971 ElementLocationImpl.con2(String encoding) { 3967 final ElementKind kind;
3972 this._components = _decode(encoding);
3973 }
3974 3968
3975 /** 3969 DartElementLocation(this.librarySourceEncoding, this.unitSourceEncoding,
3976 * Initialize a newly created location from the given components. 3970 this.nameOffset, this.kind);
3977 *
3978 * @param components the components of a location
3979 */
3980 ElementLocationImpl.con3(List<String> components) {
3981 this._components = components;
3982 }
3983 3971
3984 @override 3972 @override
3985 List<String> get components => _components; 3973 bool operator ==(Object other) {
3986 3974 if (other is DartElementLocation) {
3987 @override 3975 return other.librarySourceEncoding == librarySourceEncoding &&
3988 String get encoding { 3976 other.unitSourceEncoding == unitSourceEncoding &&
3989 StringBuffer buffer = new StringBuffer(); 3977 other.nameOffset == nameOffset &&
3990 int length = _components.length; 3978 other.kind == kind;
3991 for (int i = 0; i < length; i++) {
3992 if (i > 0) {
3993 buffer.writeCharCode(_SEPARATOR_CHAR);
3994 }
3995 _encode(buffer, _components[i]);
3996 } 3979 }
3997 return buffer.toString(); 3980 return false;
3998 }
3999
4000 @override
4001 int get hashCode {
4002 int result = 1;
4003 for (int i = 0; i < _components.length; i++) {
4004 String component = _components[i];
4005 result = 31 * result + component.hashCode;
4006 }
4007 return result;
4008 }
4009
4010 @override
4011 bool operator ==(Object object) {
4012 if (identical(this, object)) {
4013 return true;
4014 }
4015 if (object is! ElementLocationImpl) {
4016 return false;
4017 }
4018 ElementLocationImpl location = object as ElementLocationImpl;
4019 List<String> otherComponents = location._components;
4020 int length = _components.length;
4021 if (otherComponents.length != length) {
4022 return false;
4023 }
4024 for (int i = 0; i < length; i++) {
4025 if (_components[i] != otherComponents[i]) {
4026 return false;
4027 }
4028 }
4029 return true;
4030 }
4031
4032 @override
4033 String toString() => encoding;
4034
4035 /**
4036 * Decode the encoded form of a location into an array of components.
4037 *
4038 * @param encoding the encoded form of a location
4039 * @return the components that were encoded
4040 */
4041 List<String> _decode(String encoding) {
4042 List<String> components = new List<String>();
4043 StringBuffer buffer = new StringBuffer();
4044 int index = 0;
4045 int length = encoding.length;
4046 while (index < length) {
4047 int currentChar = encoding.codeUnitAt(index);
4048 if (currentChar == _SEPARATOR_CHAR) {
4049 if (index + 1 < length &&
4050 encoding.codeUnitAt(index + 1) == _SEPARATOR_CHAR) {
4051 buffer.writeCharCode(_SEPARATOR_CHAR);
4052 index += 2;
4053 } else {
4054 components.add(buffer.toString());
4055 buffer = new StringBuffer();
4056 index++;
4057 }
4058 } else {
4059 buffer.writeCharCode(currentChar);
4060 index++;
4061 }
4062 }
4063 components.add(buffer.toString());
4064 return components;
4065 }
4066
4067 /**
4068 * Append an encoded form of the given component to the given builder.
4069 *
4070 * @param builder the builder to which the encoded component is to be appended
4071 * @param component the component to be appended to the builder
4072 */
4073 void _encode(StringBuffer buffer, String component) {
4074 int length = component.length;
4075 for (int i = 0; i < length; i++) {
4076 int currentChar = component.codeUnitAt(i);
4077 if (currentChar == _SEPARATOR_CHAR) {
4078 buffer.writeCharCode(_SEPARATOR_CHAR);
4079 }
4080 buffer.writeCharCode(currentChar);
4081 }
4082 } 3981 }
4083 } 3982 }
4084 3983
4085 /** 3984 /**
4086 * The class `ElementPair` is a pair of [Element]s. [Object.==] and 3985 * The class `ElementPair` is a pair of [Element]s. [Object.==] and
4087 * [Object.hashCode] so this class can be used in hashed data structures. 3986 * [Object.hashCode] so this class can be used in hashed data structures.
4088 */ 3987 */
4089 class ElementPair { 3988 class ElementPair {
4090 /** 3989 /**
4091 * The first [Element] 3990 * The first [Element]
(...skipping 4490 matching lines...) Expand 10 before | Expand all | Expand 10 after
8582 } 8481 }
8583 } 8482 }
8584 for (ExportElement exportElement in _exports) { 8483 for (ExportElement exportElement in _exports) {
8585 if ((exportElement as ExportElementImpl).identifier == identifier) { 8484 if ((exportElement as ExportElementImpl).identifier == identifier) {
8586 return exportElement as ExportElementImpl; 8485 return exportElement as ExportElementImpl;
8587 } 8486 }
8588 } 8487 }
8589 return null; 8488 return null;
8590 } 8489 }
8591 8490
8491 /**
8492 * Returns the child [Element] of this library.
8493 *
8494 * [unitSourceEncoding] - the encoding of the unit.
8495 * [offset] - the name offset of the element.
8496 * [kind] - the kind of the element.
8497 */
8498 ElementImpl getChildElement(String unitSourceEncoding, int offset,
8499 ElementKind kind) {
8500 for (CompilationUnitElement unit in units) {
8501 if (unit.source.encoding == unitSourceEncoding) {
8502 ElementImpl element = _findElementAt(unit, offset, kind);
8503 if (element != null) {
8504 return element;
8505 }
8506 break;
8507 }
8508 }
8509 for (ImportElement importElement in _imports) {
8510 if (importElement.nameOffset == offset) {
8511 return importElement as ImportElementImpl;
8512 }
8513 }
8514 for (ExportElement exportElement in _exports) {
8515 if (exportElement.nameOffset == offset) {
8516 return exportElement as ExportElementImpl;
8517 }
8518 }
8519 return null;
8520 }
8521
8522 ElementImpl _findElementAt(CompilationUnitElement unit, int offset,
Brian Wilkerson 2014/11/18 15:11:22 Seems like this should either be moved to Compilat
8523 ElementKind kind) {
8524 if (offset == -1) {
8525 return unit as ElementImpl;
8526 }
8527 _FindElementAt visitor = new _FindElementAt(offset, kind);
8528 try {
8529 unit.accept(visitor);
8530 } on _FindElementAtDone catch (e) {
8531 return visitor.result;
8532 }
8533 return null;
8534 }
8535
8592 @override 8536 @override
8593 List<ImportElement> getImportsWithPrefix(PrefixElement prefixElement) { 8537 List<ImportElement> getImportsWithPrefix(PrefixElement prefixElement) {
8594 int count = _imports.length; 8538 int count = _imports.length;
8595 List<ImportElement> importList = new List<ImportElement>(); 8539 List<ImportElement> importList = new List<ImportElement>();
8596 for (int i = 0; i < count; i++) { 8540 for (int i = 0; i < count; i++) {
8597 if (identical(_imports[i].prefix, prefixElement)) { 8541 if (identical(_imports[i].prefix, prefixElement)) {
8598 importList.add(_imports[i]); 8542 importList.add(_imports[i]);
8599 } 8543 }
8600 } 8544 }
8601 return importList; 8545 return importList;
(...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after
12463 // bottom <: void (as bottom is a subtype of all types). 12407 // bottom <: void (as bottom is a subtype of all types).
12464 // void <: dynamic (as dynamic is a supertype of all types) 12408 // void <: dynamic (as dynamic is a supertype of all types)
12465 return identical(type, this) || type.isDynamic; 12409 return identical(type, this) || type.isDynamic;
12466 } 12410 }
12467 12411
12468 @override 12412 @override
12469 VoidTypeImpl substitute2(List<DartType> argumentTypes, 12413 VoidTypeImpl substitute2(List<DartType> argumentTypes,
12470 List<DartType> parameterTypes) => 12414 List<DartType> parameterTypes) =>
12471 this; 12415 this;
12472 } 12416 }
12417
12418
12419 class _FindElementAt extends GeneralizingElementVisitor {
Brian Wilkerson 2014/11/18 15:11:22 I'm not sure why this is a private class. Seems li
12420 final int offset;
12421 final ElementKind kind;
12422 Element result;
12423
12424 _FindElementAt(this.offset, this.kind);
12425
12426 @override
12427 visitElement(Element element) {
12428 if (element.nameOffset == offset && element.kind == kind) {
12429 result = element;
12430 throw new _FindElementAtDone();
12431 }
12432 super.visitElement(element);
12433 }
12434 }
12435
12436
12437 class _FindElementAtDone {
12438 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698