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

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

Issue 1768713002: Fixes to associating existing elements with an AST (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 9 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
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 library analyzer.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 /** 921 /**
922 * The source of the library containing this compilation unit. 922 * The source of the library containing this compilation unit.
923 * 923 *
924 * This is the same as the source of the containing [LibraryElement], 924 * This is the same as the source of the containing [LibraryElement],
925 * except that it does not require the containing [LibraryElement] to be 925 * except that it does not require the containing [LibraryElement] to be
926 * computed. 926 * computed.
927 */ 927 */
928 Source librarySource; 928 Source librarySource;
929 929
930 /** 930 /**
931 * A table mapping the offset of a directive to the annotations associated
932 * with that directive, or `null` if none of the annotations in the
933 * compilation unit have annotations.
934 */
935 Map<int, List<ElementAnnotation>> annotationMap = null;
936
937 /**
931 * A list containing all of the top-level accessors (getters and setters) 938 * A list containing all of the top-level accessors (getters and setters)
932 * contained in this compilation unit. 939 * contained in this compilation unit.
933 */ 940 */
934 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; 941 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST;
935 942
936 /** 943 /**
937 * A list containing all of the enums contained in this compilation unit. 944 * A list containing all of the enums contained in this compilation unit.
938 */ 945 */
939 List<ClassElement> _enums = ClassElement.EMPTY_LIST; 946 List<ClassElement> _enums = ClassElement.EMPTY_LIST;
940 947
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 if (source == null) { 1103 if (source == null) {
1097 buffer.write("{compilation unit}"); 1104 buffer.write("{compilation unit}");
1098 } else { 1105 } else {
1099 buffer.write(source.fullName); 1106 buffer.write(source.fullName);
1100 } 1107 }
1101 } 1108 }
1102 1109
1103 @override 1110 @override
1104 CompilationUnit computeNode() => unit; 1111 CompilationUnit computeNode() => unit;
1105 1112
1113 /**
1114 * Return the annotations associated with the directive at the given [offset],
1115 * or an empty list if the directive has no annotations or if there is no
1116 * directive at the given offset.
1117 */
1118 List<ElementAnnotation> getAnnotations(int offset) {
1119 if (annotationMap == null) {
1120 return ElementAnnotation.EMPTY_LIST;
1121 }
1122 return annotationMap[offset] ?? ElementAnnotation.EMPTY_LIST;
1123 }
1124
1106 @override 1125 @override
1107 ElementImpl getChild(String identifier) { 1126 ElementImpl getChild(String identifier) {
1108 // 1127 //
1109 // The casts in this method are safe because the set methods would have 1128 // The casts in this method are safe because the set methods would have
1110 // thrown a CCE if any of the elements in the arrays were not of the 1129 // thrown a CCE if any of the elements in the arrays were not of the
1111 // expected types. 1130 // expected types.
1112 // 1131 //
1113 for (PropertyAccessorElement accessor in _accessors) { 1132 for (PropertyAccessorElement accessor in _accessors) {
1114 if ((accessor as PropertyAccessorElementImpl).identifier == identifier) { 1133 if ((accessor as PropertyAccessorElementImpl).identifier == identifier) {
1115 return accessor as PropertyAccessorElementImpl; 1134 return accessor as PropertyAccessorElementImpl;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 1193
1175 /** 1194 /**
1176 * Replace the given [from] top-level variable with [to] in this compilation u nit. 1195 * Replace the given [from] top-level variable with [to] in this compilation u nit.
1177 */ 1196 */
1178 void replaceTopLevelVariable( 1197 void replaceTopLevelVariable(
1179 TopLevelVariableElement from, TopLevelVariableElement to) { 1198 TopLevelVariableElement from, TopLevelVariableElement to) {
1180 int index = _variables.indexOf(from); 1199 int index = _variables.indexOf(from);
1181 _variables[index] = to; 1200 _variables[index] = to;
1182 } 1201 }
1183 1202
1203 /**
1204 * Set the annotations associated with the directive at the given [offset] to
1205 * the given list of [annotations].
1206 */
1207 void setAnnotations(int offset, List<ElementAnnotation> annotations) {
1208 annotationMap ??= new HashMap<int, List<ElementAnnotation>>();
1209 annotationMap[offset] = annotations;
1210 }
1211
1184 @override 1212 @override
1185 void visitChildren(ElementVisitor visitor) { 1213 void visitChildren(ElementVisitor visitor) {
1186 super.visitChildren(visitor); 1214 super.visitChildren(visitor);
1187 safelyVisitChildren(_accessors, visitor); 1215 safelyVisitChildren(_accessors, visitor);
1188 safelyVisitChildren(_enums, visitor); 1216 safelyVisitChildren(_enums, visitor);
1189 safelyVisitChildren(_functions, visitor); 1217 safelyVisitChildren(_functions, visitor);
1190 safelyVisitChildren(_typeAliases, visitor); 1218 safelyVisitChildren(_typeAliases, visitor);
1191 safelyVisitChildren(_types, visitor); 1219 safelyVisitChildren(_types, visitor);
1192 safelyVisitChildren(_variables, visitor); 1220 safelyVisitChildren(_variables, visitor);
1193 } 1221 }
(...skipping 3676 matching lines...) Expand 10 before | Expand all | Expand 10 after
4870 4898
4871 @override 4899 @override
4872 void visitElement(Element element) { 4900 void visitElement(Element element) {
4873 int offset = element.nameOffset; 4901 int offset = element.nameOffset;
4874 if (offset != -1) { 4902 if (offset != -1) {
4875 map[offset] = element; 4903 map[offset] = element;
4876 } 4904 }
4877 super.visitElement(element); 4905 super.visitElement(element);
4878 } 4906 }
4879 } 4907 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/builder.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698