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

Unified 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: Clean up 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/dart/element/element.dart
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index e3f4dfeeab2c9f4feb4b3fb7b5647c04d8e0d28a..462a95eea6df41288bb2914ebc3ace7986bafe22 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -928,6 +928,13 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
Source librarySource;
/**
+ * A table mapping the offset of a directive to the annotations associated
+ * with that directive, or `null` if none of the annotations in the
+ * compilation unit have annotations.
+ */
+ Map<int, List<ElementAnnotation>> annotationMap = null;
+
+ /**
* A list containing all of the top-level accessors (getters and setters)
* contained in this compilation unit.
*/
@@ -1103,6 +1110,18 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
@override
CompilationUnit computeNode() => unit;
+ /**
+ * Return the annotations associated with the directive at the given [offset],
+ * or an empty list if the directive has no annotations or if there is no
+ * directive at the given offset.
+ */
+ List<ElementAnnotation> getAnnotations(int offset) {
+ if (annotationMap == null) {
+ return ElementAnnotation.EMPTY_LIST;
+ }
+ return annotationMap[offset] ?? ElementAnnotation.EMPTY_LIST;
+ }
+
@override
ElementImpl getChild(String identifier) {
//
@@ -1181,6 +1200,17 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
_variables[index] = to;
}
+ /**
+ * Set the annotations associated with the directive at the given [offset] to
+ * the given list of [annotations].
+ */
+ void setAnnotations(int offset, List<ElementAnnotation> annotations) {
+ if (annotationMap == null) {
Paul Berry 2016/03/04 22:02:11 Nit: this seems like a premature optimization (the
Brian Wilkerson 2016/03/07 16:20:28 I have almost 3000 CompilationUnitElements in my e
+ annotationMap = new HashMap<int, List<ElementAnnotation>>();
scheglov 2016/03/04 21:49:30 annotationMap ??= new HashMap<int, List<ElementAnn
Brian Wilkerson 2016/03/07 16:20:28 Done
+ }
+ annotationMap[offset] = annotations;
+ }
+
@override
void visitChildren(ElementVisitor visitor) {
super.visitChildren(visitor);
@@ -1274,6 +1304,7 @@ class ConstructorElementImpl extends ExecutableElementImpl
/**
* The constructor to which this constructor is redirecting.
*/
+ @override
Paul Berry 2016/03/04 22:02:11 Normally I am ok with rolling this sort of clean-u
Brian Wilkerson 2016/03/07 16:20:28 Not sure it didn't take more time to remove them,
ConstructorElement redirectedConstructor;
/**
@@ -1285,12 +1316,14 @@ class ConstructorElementImpl extends ExecutableElementImpl
/**
* The offset of the `.` before this constructor name or `null` if not named.
*/
+ @override
int periodOffset;
/**
* Return the offset of the character immediately following the last character
* of this constructor's name, or `null` if not named.
*/
+ @override
int nameEnd;
/**
@@ -1594,6 +1627,7 @@ class ElementAnnotationImpl implements ElementAnnotation {
* The element representing the field, variable, or constructor being used as
* an annotation.
*/
+ @override
Element element;
/**
@@ -1679,6 +1713,7 @@ abstract class ElementImpl implements Element {
static int _NEXT_ID = 0;
+ @override
final int id = _NEXT_ID++;
/**
@@ -1706,6 +1741,7 @@ abstract class ElementImpl implements Element {
/**
* A list containing all of the metadata associated with this element.
*/
+ @override
List<ElementAnnotation> metadata = ElementAnnotation.EMPTY_LIST;
/**
@@ -2303,11 +2339,13 @@ abstract class ExecutableElementImpl extends ElementImpl
/**
* The return type defined by this executable element.
*/
+ @override
DartType returnType;
/**
* The type of function defined by this executable element.
*/
+ @override
FunctionType type;
/**
@@ -2535,12 +2573,14 @@ class ExportElementImpl extends UriReferencedElementImpl
/**
* The library that is exported from this library by this export directive.
*/
+ @override
LibraryElement exportedLibrary;
/**
* The combinators that were specified as part of the export directive in the
* order in which they were specified.
*/
+ @override
List<NamespaceCombinator> combinators = NamespaceCombinator.EMPTY_LIST;
/**
@@ -2619,6 +2659,7 @@ class FieldFormalParameterElementImpl extends ParameterElementImpl
/**
* The field associated with this field formal parameter.
*/
+ @override
FieldElement field;
/**
@@ -2773,11 +2814,13 @@ class FunctionTypeAliasElementImpl extends ElementImpl
/**
* The return type defined by this type alias.
*/
+ @override
DartType returnType;
/**
* The type of function defined by this type alias.
*/
+ @override
FunctionType type;
/**
@@ -2908,6 +2951,7 @@ class HideElementCombinatorImpl implements HideElementCombinator {
* The names that are not to be made visible in the importing library even if
* they are defined in the imported library.
*/
+ @override
List<String> hiddenNames = StringUtilities.EMPTY_ARRAY;
@override
@@ -2934,23 +2978,27 @@ class ImportElementImpl extends UriReferencedElementImpl
* The offset of the prefix of this import in the file that contains the this
* import directive, or `-1` if this import is synthetic.
*/
+ @override
int prefixOffset = 0;
/**
* The library that is imported into this library by this import directive.
*/
+ @override
LibraryElement importedLibrary;
/**
* The combinators that were specified as part of the import directive in the
* order in which they were specified.
*/
+ @override
List<NamespaceCombinator> combinators = NamespaceCombinator.EMPTY_LIST;
/**
* The prefix that was specified as part of the import directive, or `null` if
* there was no prefix specified.
*/
+ @override
PrefixElement prefix;
/**
@@ -3058,6 +3106,7 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
/**
* The analysis context in which this library is defined.
*/
+ @override
final AnalysisContext context;
/**
@@ -3069,6 +3118,7 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
* The entry point for this library, or `null` if this library does not have
* an entry point.
*/
+ @override
FunctionElement entryPoint;
/**
@@ -3939,11 +3989,13 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement {
/**
* The unique integer identifier of this element.
*/
+ @override
final int id = ElementImpl._NEXT_ID++;
/**
* The analysis context in which the multiply defined elements are defined.
*/
+ @override
final AnalysisContext context;
/**
@@ -3954,6 +4006,7 @@ class MultiplyDefinedElementImpl implements MultiplyDefinedElement {
/**
* A list containing all of the elements that conflict.
*/
+ @override
final List<Element> conflictingElements;
/**
@@ -4201,6 +4254,7 @@ class ParameterElementImpl extends VariableElementImpl
/**
* The kind of this parameter.
*/
+ @override
ParameterKind parameterKind;
/**
@@ -4420,6 +4474,7 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl
/**
* The variable associated with this accessor.
*/
+ @override
PropertyInducingElement variable;
/**
@@ -4562,6 +4617,7 @@ abstract class PropertyInducingElementImpl extends VariableElementImpl
/**
* The getter associated with this element.
*/
+ @override
PropertyAccessorElement getter;
/**
@@ -4569,12 +4625,14 @@ abstract class PropertyInducingElementImpl extends VariableElementImpl
* effectively `final` and therefore does not have a setter associated with
* it.
*/
+ @override
PropertyAccessorElement setter;
/**
* The propagated type of this variable, or `null` if type propagation has not
* been performed.
*/
+ @override
DartType propagatedType;
/**
@@ -4597,17 +4655,20 @@ class ShowElementCombinatorImpl implements ShowElementCombinator {
* The names that are to be made visible in the importing library if they are
* defined in the imported library.
*/
+ @override
List<String> shownNames = StringUtilities.EMPTY_ARRAY;
/**
* The offset of the character immediately following the last character of
* this node.
*/
+ @override
int end = -1;
/**
* The offset of the 'show' keyword of this element.
*/
+ @override
int offset = 0;
@override
@@ -4664,12 +4725,14 @@ class TypeParameterElementImpl extends ElementImpl
/**
* The type defined by this type parameter.
*/
+ @override
TypeParameterType type;
/**
* The type representing the bound associated with this parameter, or `null`
* if this parameter does not have an explicit bound.
*/
+ @override
DartType bound;
/**
@@ -4715,17 +4778,20 @@ abstract class UriReferencedElementImpl extends ElementImpl
/**
* The offset of the URI in the file, may be `-1` if synthetic.
*/
+ @override
int uriOffset = -1;
/**
* The offset of the character immediately following the last character of
* this node's URI, may be `-1` if synthetic.
*/
+ @override
int uriEnd = -1;
/**
* The URI that is specified by this directive.
*/
+ @override
String uri;
/**
@@ -4743,6 +4809,7 @@ abstract class VariableElementImpl extends ElementImpl
/**
* The declared type of this variable.
*/
+ @override
DartType type;
/**

Powered by Google App Engine
This is Rietveld 408576698