| // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| /// Defines the element model. The element model describes the semantic (as |
| /// opposed to syntactic) structure of Dart code. The syntactic structure of the |
| /// code is modeled by the [AST |
| /// structure](../dart_ast_ast/dart_ast_ast-library.html). |
| /// |
| /// The element model consists of two closely related kinds of objects: elements |
| /// (instances of a subclass of `Element`) and types. This library defines the |
| /// elements, the types are defined in |
| /// [type.dart](../dart_element_type/dart_element_type-library.html). |
| /// |
| /// Generally speaking, an element represents something that is declared in the |
| /// code, such as a class, method, or variable. Elements are organized in a tree |
| /// structure in which the children of an element are the elements that are |
| /// logically (and often syntactically) part of the declaration of the parent. |
| /// For example, the elements representing the methods and fields in a class are |
| /// children of the element representing the class. |
| /// |
| /// Every complete element structure is rooted by an instance of the class |
| /// `LibraryElement`. A library element represents a single Dart library. Every |
| /// library is defined by one or more compilation units (the library and all of |
| /// its parts). The compilation units are represented by the class |
| /// `CompilationUnitElement` and are children of the library that is defined by |
| /// them. Each compilation unit can contain zero or more top-level declarations, |
| /// such as classes, functions, and variables. Each of these is in turn |
| /// represented as an element that is a child of the compilation unit. Classes |
| /// contain methods and fields, methods can contain local variables, etc. |
| /// |
| /// The element model does not contain everything in the code, only those things |
| /// that are declared by the code. For example, it does not include any |
| /// representation of the statements in a method body, but if one of those |
| /// statements declares a local variable then the local variable will be |
| /// represented by an element. |
| library; |
| |
| import 'package:_fe_analyzer_shared/src/base/analyzer_public_api.dart'; |
| import 'package:analyzer/dart/analysis/features.dart'; |
| import 'package:analyzer/dart/analysis/session.dart'; |
| import 'package:analyzer/dart/constant/value.dart'; |
| import 'package:analyzer/dart/element/element2.dart'; |
| import 'package:analyzer/dart/element/nullability_suffix.dart'; |
| import 'package:analyzer/dart/element/scope.dart'; |
| import 'package:analyzer/dart/element/type.dart'; |
| import 'package:analyzer/dart/element/type_provider.dart'; |
| import 'package:analyzer/dart/element/type_system.dart'; |
| import 'package:analyzer/error/error.dart'; |
| import 'package:analyzer/source/line_info.dart'; |
| import 'package:analyzer/source/source.dart'; |
| import 'package:analyzer/src/dart/constant/evaluation.dart'; |
| import 'package:analyzer/src/dart/element/element.dart' |
| show elementModelDeprecationMsg; |
| import 'package:analyzer/src/dart/resolver/scope.dart' show Namespace; |
| import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; |
| import 'package:analyzer/src/generated/utilities_dart.dart'; |
| // ignore: deprecated_member_use_from_same_package |
| import 'package:analyzer/src/task/api/model.dart' show AnalysisTarget; |
| import 'package:meta/meta.dart'; |
| import 'package:pub_semver/pub_semver.dart'; |
| |
| /// A pattern variable that is explicitly declared. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated( |
| 'Use BindPatternVariableFragment and BindPatternVariableElement2 instead') |
| abstract class BindPatternVariableElement implements PatternVariableElement {} |
| |
| /// An element that is contained within a [ClassElement]. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated(''' |
| There is no common interface for class members in the new analyzer element |
| model. If you are using this class in an `is` test or a pattern match, replace |
| it with checks for the specific element types you are interested in (e.g., |
| `ConstructorElement2`, `MethodElement2`, etc.). If you are using this class as |
| a type annotation for a variable that could hold any kind of class member, use |
| `Element2` instead.''') |
| abstract class ClassMemberElement implements Element { |
| // TODO(brianwilkerson): Either remove this class or rename it to something |
| // more correct. |
| |
| @override |
| Element get enclosingElement3; |
| |
| /// Whether the element is a static element. |
| /// |
| /// A static element is an element that is not associated with a particular |
| /// instance, but rather with an entire library or class. |
| bool get isStatic; |
| } |
| |
| /// An element representing a compilation unit. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated(elementModelDeprecationMsg) |
| abstract class CompilationUnitElement implements UriReferencedElement { |
| /// The [CompilationUnitElement] that uses `part` directive to include this |
| /// element, or `null` if this element is the defining unit of the library. |
| @override |
| CompilationUnitElement? get enclosingElement3; |
| |
| /// The libraries exported by this unit. |
| List<LibraryExportElement> get libraryExports; |
| |
| /// The prefixes used by [libraryImports]. |
| /// |
| /// Each prefix can be used in more than one `import` directive. |
| List<PrefixElement> get libraryImportPrefixes; |
| |
| /// The libraries imported by this unit. |
| List<LibraryImportElement> get libraryImports; |
| |
| /// The [LineInfo] for the [source]. |
| LineInfo get lineInfo; |
| |
| /// The parts included by this unit. |
| List<PartElement> get parts; |
| |
| /// The scope used to resolve names within this compilation unit. |
| /// |
| /// It includes all of the elements that are declared in the library, and all |
| /// of the elements imported into this unit or parent units. |
| Scope get scope; |
| |
| @override |
| AnalysisSession get session; |
| } |
| |
| /// [ImportElementPrefix] that is used together with `deferred`. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use PrefixElement2 instead') |
| abstract class DeferredImportElementPrefix implements ImportElementPrefix {} |
| |
| /// Meaning of a URI referenced in a directive. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class DirectiveUri {} |
| |
| /// [DirectiveUriWithSource] that references a [LibraryElement2]. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class DirectiveUriWithLibrary extends DirectiveUriWithSource { |
| /// The library referenced by the [source]. |
| @Deprecated(elementModelDeprecationMsg) |
| LibraryElement get library; |
| |
| /// The library referenced by the [source]. |
| LibraryElement2 get library2; |
| } |
| |
| /// [DirectiveUriWithRelativeUriString] that can be parsed into a relative URI. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class DirectiveUriWithRelativeUri |
| extends DirectiveUriWithRelativeUriString { |
| /// The relative URI, parsed from [relativeUriString]. |
| Uri get relativeUri; |
| } |
| |
| /// [DirectiveUri] for which we can get its relative URI string. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class DirectiveUriWithRelativeUriString extends DirectiveUri { |
| /// The relative URI string specified in code. |
| String get relativeUriString; |
| } |
| |
| /// [DirectiveUriWithRelativeUri] that resolves to a [Source]. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class DirectiveUriWithSource extends DirectiveUriWithRelativeUri { |
| /// The result of resolving [relativeUri] against the enclosing URI. |
| Source get source; |
| } |
| |
| /// [DirectiveUriWithSource] that references a [LibraryFragment]. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class DirectiveUriWithUnit extends DirectiveUriWithSource { |
| /// The library fragment referenced by the [source]. |
| @experimental |
| LibraryFragment get libraryFragment; |
| |
| /// The unit referenced by the [source]. |
| @Deprecated('Use libraryFragment instead') |
| CompilationUnitElement get unit; |
| } |
| |
| /// The base class for all of the elements in the element model. Generally |
| /// speaking, the element model is a semantic model of the program that |
| /// represents things that are declared with a name and hence can be referenced |
| /// elsewhere in the code. |
| /// |
| /// There are two exceptions to the general case. First, there are elements in |
| /// the element model that are created for the convenience of various kinds of |
| /// analysis but that do not have any corresponding declaration within the |
| /// source code. Such elements are marked as being <i>synthetic</i>. Examples of |
| /// synthetic elements include |
| /// * default constructors in classes that do not define any explicit |
| /// constructors, |
| /// * getters and setters that are induced by explicit field declarations, |
| /// * fields that are induced by explicit declarations of getters and setters, |
| /// and |
| /// * functions representing the initialization expression for a variable. |
| /// |
| /// Second, there are elements in the element model that do not have a name. |
| /// These correspond to unnamed functions and exist in order to more accurately |
| /// represent the semantic structure of the program. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated(elementModelDeprecationMsg) |
| abstract class Element implements AnalysisTarget { |
| /// The analysis context in which this element is defined. |
| AnalysisContext get context; |
| |
| /// The declaration of this element. |
| /// |
| /// If the element is a view on an element, e.g. a method from an interface |
| /// type, with substituted type parameters, return the corresponding element |
| /// from the class, without any substitutions. If this element is already a |
| /// declaration (or a synthetic element, e.g. a synthetic property accessor), |
| /// return itself. |
| @Deprecated(elementModelDeprecationMsg) |
| Element? get declaration; |
| |
| /// The display name of this element, possibly the empty string if the |
| /// element does not have a name. |
| /// |
| /// In most cases the name and the display name are the same. Differences |
| /// though are cases such as setters where the name of some setter `set f(x)` |
| /// is `f=`, instead of `f`. |
| String get displayName; |
| |
| /// The content of the documentation comment (including delimiters) for this |
| /// element, or `null` if this element does not or cannot have documentation. |
| String? get documentationComment; |
| |
| /// The element that either physically or logically encloses this element. |
| /// |
| /// For [LibraryElement] returns `null`, because libraries are the top-level |
| /// elements in the model. |
| /// |
| /// For [CompilationUnitElement] returns the [CompilationUnitElement] that |
| /// uses `part` directive to include this element, or `null` if this element |
| /// is the defining unit of the library. |
| @Deprecated('Use Element2.enclosingElement2 instead or ' |
| 'Fragment.enclosingFragment instead') |
| Element? get enclosingElement3; |
| |
| /// Whether the element has an annotation of the form `@alwaysThrows`. |
| bool get hasAlwaysThrows; |
| |
| /// Whether the element has an annotation of the form `@deprecated` |
| /// or `@Deprecated('..')`. |
| bool get hasDeprecated; |
| |
| /// Whether the element has an annotation of the form `@doNotStore`. |
| bool get hasDoNotStore; |
| |
| /// Whether the element has an annotation of the form `@doNotSubmit`. |
| bool get hasDoNotSubmit; |
| |
| /// Whether the element has an annotation of the form `@factory`. |
| bool get hasFactory; |
| |
| /// Whether the element has an annotation of the form `@immutable`. |
| bool get hasImmutable; |
| |
| /// Whether the element has an annotation of the form `@internal`. |
| bool get hasInternal; |
| |
| /// Whether the element has an annotation of the form `@isTest`. |
| bool get hasIsTest; |
| |
| /// Whether the element has an annotation of the form `@isTestGroup`. |
| bool get hasIsTestGroup; |
| |
| /// Whether the element has an annotation of the form `@JS(..)`. |
| bool get hasJS; |
| |
| /// Whether the element has an annotation of the form `@literal`. |
| bool get hasLiteral; |
| |
| /// Whether the element has an annotation of the form `@mustBeConst`. |
| bool get hasMustBeConst; |
| |
| /// Whether the element has an annotation of the form `@mustBeOverridden`. |
| bool get hasMustBeOverridden; |
| |
| /// Whether the element has an annotation of the form `@mustCallSuper`. |
| bool get hasMustCallSuper; |
| |
| /// Whether the element has an annotation of the form `@nonVirtual`. |
| bool get hasNonVirtual; |
| |
| /// Whether the element has an annotation of the form `@optionalTypeArgs`. |
| bool get hasOptionalTypeArgs; |
| |
| /// Whether the element has an annotation of the form `@override`. |
| bool get hasOverride; |
| |
| /// Whether the element has an annotation of the form `@protected`. |
| bool get hasProtected; |
| |
| /// Whether the element has an annotation of the form `@redeclare`. |
| bool get hasRedeclare; |
| |
| /// Whether the element has an annotation of the form `@reopen`. |
| bool get hasReopen; |
| |
| /// Whether the element has an annotation of the form `@required`. |
| bool get hasRequired; |
| |
| /// Whether the element has an annotation of the form `@sealed`. |
| bool get hasSealed; |
| |
| /// Whether the element has an annotation of the form `@useResult` |
| /// or `@UseResult('..')`. |
| bool get hasUseResult; |
| |
| /// Whether the element has an annotation of the form `@visibleForOverriding`. |
| bool get hasVisibleForOverriding; |
| |
| /// Whether the element has an annotation of the form `@visibleForTemplate`. |
| bool get hasVisibleForTemplate; |
| |
| /// Whether the element has an annotation of the form `@visibleForTesting`. |
| bool get hasVisibleForTesting; |
| |
| /// Whether the element has an annotation of the form |
| /// `@visibleOutsideTemplate`. |
| bool get hasVisibleOutsideTemplate; |
| |
| /// The unique integer identifier of this element. |
| int get id; |
| |
| /// Whether the element is private. |
| /// |
| /// Private elements are visible only within the library in which they are |
| /// declared. |
| bool get isPrivate; |
| |
| /// Whether the element is public. |
| /// |
| /// Public elements are visible within any library that imports the library |
| /// in which they are declared. |
| bool get isPublic; |
| |
| /// Whether the element is synthetic. |
| /// |
| /// A synthetic element is an element that is not represented in the source |
| /// code explicitly, but is implied by the source code, such as the default |
| /// constructor for a class that does not explicitly define any constructors. |
| bool get isSynthetic; |
| |
| /// The kind of element that this is. |
| ElementKind get kind; |
| |
| /// Library that contains this element. |
| /// |
| /// This will be the element itself if it is a library element. This will be |
| /// `null` if this element is [MultiplyDefinedElement2] that is not contained |
| /// in a library. |
| @Deprecated(elementModelDeprecationMsg) |
| LibraryElement? get library; |
| |
| /// The location of this element in the element model. |
| /// |
| /// The object can be used to locate this element at a later time. |
| ElementLocation? get location; |
| |
| /// All of the metadata associated with this element. |
| /// |
| /// The array will be empty if the element does not have any metadata or if |
| /// the library containing this element has not yet been resolved. |
| List<ElementAnnotation> get metadata; |
| |
| /// The name of this element, or `null` if this element does not have a name. |
| String? get name; |
| |
| /// The length of the name of this element in the file that contains the |
| /// declaration of this element, or `0` if this element does not have a name. |
| int get nameLength; |
| |
| /// The offset of the name of this element in the file that contains the |
| /// declaration of this element, or `-1` if this element is synthetic, does |
| /// not have a name, or otherwise does not have an offset. |
| int get nameOffset; |
| |
| /// The non-synthetic element that caused this element to be created. |
| /// |
| /// If this element is not synthetic, then the element itself is returned. |
| /// |
| /// If this element is synthetic, then the corresponding non-synthetic |
| /// element is returned. For example, for a synthetic getter of a |
| /// non-synthetic field the field is returned; for a synthetic constructor |
| /// the enclosing class is returned. |
| @Deprecated(elementModelDeprecationMsg) |
| Element get nonSynthetic; |
| |
| /// The analysis session in which this element is defined. |
| AnalysisSession? get session; |
| |
| /// The version where this SDK API was added. |
| /// |
| /// A `@Since()` annotation can be applied to a library declaration, |
| /// any public declaration in a library, or in a class, or to an optional |
| /// parameter, etc. |
| /// |
| /// The returned version is "effective", so that if a library is annotated |
| /// then all elements of the library inherit it; or if a class is annotated |
| /// then all members and constructors of the class inherit it. |
| /// |
| /// If multiple `@Since()` annotations apply to the same element, the latest |
| /// version takes precedence. |
| /// |
| /// Returns `null` if the element is not declared in SDK, or does not have |
| /// a `@Since()` annotation applicable to it. |
| Version? get sinceSdkVersion; |
| |
| @override |
| Source? get source; |
| |
| /// Returns the presentation of this element as it should appear when |
| /// presented to users. |
| /// |
| /// If [withNullability] is `true`, then [NullabilitySuffix.question] and |
| /// [NullabilitySuffix.star] in types will be represented as `?` and `*`. |
| /// [NullabilitySuffix.none] does not have any explicit presentation. |
| /// |
| /// If [withNullability] is `false`, nullability suffixes will not be |
| /// included into the presentation. |
| /// |
| /// If [multiline] is `true`, the string may be wrapped over multiple lines |
| /// with newlines to improve formatting. For example function signatures may |
| /// be formatted as if they had trailing commas. |
| /// |
| /// Clients should not depend on the content of the returned value as it will |
| /// be changed if doing so would improve the UX. |
| String getDisplayString({ |
| @Deprecated('Only non-nullable by default mode is supported') |
| bool withNullability = true, |
| bool multiline = false, |
| }); |
| |
| /// Returns a display name for the given element that includes the path to the |
| /// compilation unit in which the type is defined. If [shortName] is `null` |
| /// then [displayName] will be used as the name of this element. Otherwise |
| /// the provided name will be used. |
| // TODO(brianwilkerson): Make the parameter optional. |
| String getExtendedDisplayName(String? shortName); |
| |
| /// Whether the element, assuming that it is within scope, is accessible to |
| /// code in the given [library]. |
| /// |
| /// This is defined by the Dart Language Specification in section 6.2: |
| /// <blockquote> |
| /// A declaration <i>m</i> is accessible to a library <i>L</i> if <i>m</i> is |
| /// declared in <i>L</i> or if <i>m</i> is public. |
| /// </blockquote> |
| @Deprecated(elementModelDeprecationMsg) |
| bool isAccessibleIn(LibraryElement library); |
| |
| /// Returns either this element or the most immediate ancestor of this element |
| /// for which the [predicate] returns `true`, or `null` if there is no such |
| /// element. |
| @Deprecated('Use Element2.thisOrAncestorMatching2() instead') |
| E? thisOrAncestorMatching<E extends Element>( |
| bool Function(Element) predicate, |
| ); |
| |
| /// Returns either this element or the most immediate ancestor of this element |
| /// for which the [predicate] returns `true`, or `null` if there is no such |
| /// element. |
| @Deprecated('Use Element2.thisOrAncestorMatching2() instead') |
| E? thisOrAncestorMatching3<E extends Element>( |
| bool Function(Element) predicate, |
| ); |
| |
| /// Returns either this element or the most immediate ancestor of this element |
| /// that has the given type, or `null` if there is no such element. |
| @Deprecated('Use Element2.thisOrAncestorMatching2() instead') |
| E? thisOrAncestorOfType<E extends Element>(); |
| |
| /// Returns either this element or the most immediate ancestor of this element |
| /// that has the given type, or `null` if there is no such element. |
| @Deprecated('Use Element2.thisOrAncestorMatching2() instead') |
| E? thisOrAncestorOfType3<E extends Element>(); |
| } |
| |
| /// A single annotation associated with an element. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class ElementAnnotation implements ConstantEvaluationTarget { |
| /// The errors that were produced while computing a value for this |
| /// annotation, or `null` if no value has been computed. |
| /// |
| /// If a value has been produced but no errors were generated, then the |
| /// list will be empty. |
| List<AnalysisError>? get constantEvaluationErrors; |
| |
| /// Returns the element referenced by this annotation. |
| /// |
| /// In valid code this element can be a [PropertyAccessorElement] getter |
| /// of a constant top-level variable, or a constant static field of a |
| /// class; or a constant [ConstructorElement]. |
| /// |
| /// In invalid code this element can be `null`, or a reference to any |
| /// other element. |
| @Deprecated('Use element2 instead') |
| Element? get element; |
| |
| /// Returns the element referenced by this annotation. |
| /// |
| /// In valid code this element can be a [GetterElement] of a constant |
| /// top-level variable, or a constant static field of a class; or a |
| /// constant [ConstructorElement2]. |
| /// |
| /// In invalid code this element can be `null`, or a reference to any |
| /// other element. |
| Element2? get element2; |
| |
| /// Whether the annotation marks the associated function as always throwing. |
| bool get isAlwaysThrows; |
| |
| /// Whether the annotation marks the associated element as being deprecated. |
| bool get isDeprecated; |
| |
| /// Whether the annotation marks the associated element as not to be stored. |
| bool get isDoNotStore; |
| |
| /// Whether the annotation marks the associated member as not to be used. |
| bool get isDoNotSubmit; |
| |
| /// Whether the annotation marks the associated member as a factory. |
| bool get isFactory; |
| |
| /// Whether the annotation marks the associated class and its subclasses as |
| /// being immutable. |
| bool get isImmutable; |
| |
| /// Whether the annotation marks the associated element as being internal to |
| /// its package. |
| bool get isInternal; |
| |
| /// Whether the annotation marks the associated member as running a single |
| /// test. |
| bool get isIsTest; |
| |
| /// Whether the annotation marks the associated member as running a test |
| /// group. |
| bool get isIsTestGroup; |
| |
| /// Whether the annotation marks the associated element with the `JS` |
| /// annotation. |
| bool get isJS; |
| |
| /// Whether the annotation marks the associated constructor as being literal. |
| bool get isLiteral; |
| |
| /// Whether the annotation marks the associated returned element as |
| /// requiring a constant argument. |
| bool get isMustBeConst; |
| |
| /// Whether the annotation marks the associated member as requiring |
| /// subclasses to override this member. |
| bool get isMustBeOverridden; |
| |
| /// Whether the annotation marks the associated member as requiring |
| /// overriding methods to call super. |
| bool get isMustCallSuper; |
| |
| /// Whether the annotation marks the associated member as being non-virtual. |
| bool get isNonVirtual; |
| |
| /// Whether the annotation marks the associated type as having "optional" |
| /// type arguments. |
| bool get isOptionalTypeArgs; |
| |
| /// Whether the annotation marks the associated method as being expected to |
| /// override an inherited method. |
| bool get isOverride; |
| |
| /// Whether the annotation marks the associated member as being protected. |
| bool get isProtected; |
| |
| /// Whether the annotation marks the associated class as implementing a proxy |
| /// object. |
| bool get isProxy; |
| |
| /// Whether the annotation marks the associated member as redeclaring. |
| bool get isRedeclare; |
| |
| /// Whether the annotation marks the associated member as being reopened. |
| bool get isReopen; |
| |
| /// Whether the annotation marks the associated member as being required. |
| bool get isRequired; |
| |
| /// Whether the annotation marks the associated class as being sealed. |
| bool get isSealed; |
| |
| /// Whether the annotation marks the associated class as being intended to |
| /// be used as an annotation. |
| bool get isTarget; |
| |
| /// Whether the annotation marks the associated returned element as |
| /// requiring use. |
| bool get isUseResult; |
| |
| /// Whether the annotation marks the associated member as being visible for |
| /// overriding only. |
| bool get isVisibleForOverriding; |
| |
| /// Whether the annotation marks the associated member as being visible for |
| /// template files. |
| bool get isVisibleForTemplate; |
| |
| /// Whether the annotation marks the associated member as being visible for |
| /// testing. |
| bool get isVisibleForTesting; |
| |
| /// Whether the annotation marks the associated member as being visible |
| /// outside of template files. |
| bool get isVisibleOutsideTemplate; |
| |
| /// Whether the annotation marks the associated member as being a widget |
| /// factory. |
| bool get isWidgetFactory; |
| |
| /// Returns a representation of the value of this annotation, forcing the |
| /// value to be computed if it had not previously been computed, or `null` |
| /// if the value of this annotation could not be computed because of errors. |
| DartObject? computeConstantValue(); |
| |
| /// Returns a textual description of this annotation in a form approximating |
| /// valid source. |
| /// |
| /// The returned string will not be valid source primarily in the case where |
| /// the annotation itself is not well-formed. |
| String toSource(); |
| } |
| |
| /// The kind of elements in the element model. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| class ElementKind implements Comparable<ElementKind> { |
| static const ElementKind AUGMENTATION_IMPORT = |
| ElementKind('AUGMENTATION_IMPORT', 0, "augmentation import"); |
| |
| static const ElementKind CLASS = ElementKind('CLASS', 1, "class"); |
| |
| static const ElementKind CLASS_AUGMENTATION = |
| ElementKind('CLASS_AUGMENTATION', 2, "class augmentation"); |
| |
| static const ElementKind COMPILATION_UNIT = |
| ElementKind('COMPILATION_UNIT', 3, "compilation unit"); |
| |
| static const ElementKind CONSTRUCTOR = |
| ElementKind('CONSTRUCTOR', 4, "constructor"); |
| |
| static const ElementKind DYNAMIC = ElementKind('DYNAMIC', 5, "<dynamic>"); |
| |
| static const ElementKind ENUM = ElementKind('ENUM', 6, "enum"); |
| |
| static const ElementKind ERROR = ElementKind('ERROR', 7, "<error>"); |
| |
| static const ElementKind EXPORT = |
| ElementKind('EXPORT', 8, "export directive"); |
| |
| static const ElementKind EXTENSION = ElementKind('EXTENSION', 9, "extension"); |
| |
| static const ElementKind EXTENSION_TYPE = |
| ElementKind('EXTENSION_TYPE', 10, "extension type"); |
| |
| static const ElementKind FIELD = ElementKind('FIELD', 11, "field"); |
| |
| static const ElementKind FUNCTION = ElementKind('FUNCTION', 12, "function"); |
| |
| static const ElementKind GENERIC_FUNCTION_TYPE = |
| ElementKind('GENERIC_FUNCTION_TYPE', 13, 'generic function type'); |
| |
| static const ElementKind GETTER = ElementKind('GETTER', 14, "getter"); |
| |
| static const ElementKind IMPORT = |
| ElementKind('IMPORT', 15, "import directive"); |
| |
| static const ElementKind LABEL = ElementKind('LABEL', 16, "label"); |
| |
| static const ElementKind LIBRARY = ElementKind('LIBRARY', 17, "library"); |
| |
| static const ElementKind LIBRARY_AUGMENTATION = |
| ElementKind('LIBRARY_AUGMENTATION', 18, "library augmentation"); |
| |
| static const ElementKind LOCAL_VARIABLE = |
| ElementKind('LOCAL_VARIABLE', 19, "local variable"); |
| |
| static const ElementKind METHOD = ElementKind('METHOD', 20, "method"); |
| |
| static const ElementKind MIXIN = ElementKind('MIXIN', 21, "mixin"); |
| |
| static const ElementKind NAME = ElementKind('NAME', 22, "<name>"); |
| |
| static const ElementKind NEVER = ElementKind('NEVER', 23, "<never>"); |
| |
| static const ElementKind PARAMETER = |
| ElementKind('PARAMETER', 24, "parameter"); |
| |
| static const ElementKind PART = ElementKind('PART', 25, "part"); |
| |
| static const ElementKind PREFIX = ElementKind('PREFIX', 26, "import prefix"); |
| |
| static const ElementKind RECORD = ElementKind('RECORD', 27, "record"); |
| |
| static const ElementKind SETTER = ElementKind('SETTER', 28, "setter"); |
| |
| static const ElementKind TOP_LEVEL_VARIABLE = |
| ElementKind('TOP_LEVEL_VARIABLE', 29, "top level variable"); |
| |
| static const ElementKind FUNCTION_TYPE_ALIAS = |
| ElementKind('FUNCTION_TYPE_ALIAS', 30, "function type alias"); |
| |
| static const ElementKind TYPE_PARAMETER = |
| ElementKind('TYPE_PARAMETER', 31, "type parameter"); |
| |
| static const ElementKind TYPE_ALIAS = |
| ElementKind('TYPE_ALIAS', 32, "type alias"); |
| |
| static const ElementKind UNIVERSE = ElementKind('UNIVERSE', 33, "<universe>"); |
| |
| static const List<ElementKind> values = [ |
| CLASS, |
| CLASS_AUGMENTATION, |
| COMPILATION_UNIT, |
| CONSTRUCTOR, |
| DYNAMIC, |
| ENUM, |
| ERROR, |
| EXPORT, |
| EXTENSION, |
| EXTENSION_TYPE, |
| FIELD, |
| FUNCTION, |
| GENERIC_FUNCTION_TYPE, |
| GETTER, |
| IMPORT, |
| LABEL, |
| LIBRARY, |
| LOCAL_VARIABLE, |
| METHOD, |
| MIXIN, |
| NAME, |
| NEVER, |
| PARAMETER, |
| PART, |
| PREFIX, |
| RECORD, |
| SETTER, |
| TOP_LEVEL_VARIABLE, |
| FUNCTION_TYPE_ALIAS, |
| TYPE_PARAMETER, |
| UNIVERSE |
| ]; |
| |
| /// The name of this element kind. |
| final String name; |
| |
| /// The ordinal value of the element kind. |
| final int ordinal; |
| |
| /// The name displayed in the UI for this kind of element. |
| final String displayName; |
| |
| /// Initialize a newly created element kind to have the given [displayName]. |
| const ElementKind(this.name, this.ordinal, this.displayName); |
| |
| @override |
| int compareTo(ElementKind other) => ordinal - other.ordinal; |
| |
| @override |
| String toString() => name; |
| } |
| |
| /// The location of an element within the element model. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class ElementLocation { |
| /// The path to the element whose location is represented by this object. |
| /// |
| /// Clients must not modify the returned array. |
| List<String> get components; |
| |
| /// The encoded representation of this location that can be used to create a |
| /// location that is equal to this location. |
| String get encoding; |
| } |
| |
| /// A combinator that causes some of the names in a namespace to be hidden when |
| /// being imported. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class HideElementCombinator implements NamespaceCombinator { |
| /// The names that are not to be made visible in the importing library even |
| /// if they are defined in the imported library. |
| List<String> get hiddenNames; |
| } |
| |
| /// Usage of a [PrefixElement] in an `import` directive. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use PrefixElement2 instead') |
| abstract class ImportElementPrefix { |
| /// The prefix that was specified as part of the import directive, or `null` |
| /// if there was no prefix specified. |
| PrefixElement get element; |
| } |
| |
| /// A pattern variable that is a join of other pattern variables, created |
| /// for a logical-or patterns, or shared `case` bodies in `switch` statements. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated( |
| 'Use JoinPatternVariableFragment and JoinPatternVariableElement2 instead') |
| abstract class JoinPatternVariableElement implements PatternVariableElement { |
| /// Whether the [variables] are consistent, present in all branches, |
| /// and have the same type and finality. |
| bool get isConsistent; |
| |
| /// The variables that join into this variable. |
| List<PatternVariableElement> get variables; |
| } |
| |
| /// A library. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use LibraryElement2 instead') |
| abstract class LibraryElement implements _ExistingElement { |
| /// The compilation unit that defines this library. |
| @Deprecated(elementModelDeprecationMsg) |
| CompilationUnitElement get definingCompilationUnit; |
| |
| /// Returns `null`, because libraries are the top-level elements in the model. |
| @override |
| Null get enclosingElement3; |
| |
| /// The libraries that are exported from this library. |
| List<LibraryElement> get exportedLibraries; |
| |
| /// The export [Namespace] of this library. |
| Namespace get exportNamespace; |
| |
| /// The set of features available to this library. |
| /// |
| /// Determined by the combination of the language version for the enclosing |
| /// package, enabled experiments, and the presence of a `// @dart` language |
| /// version override comment at the top of the file. |
| FeatureSet get featureSet; |
| |
| /// The identifier that uniquely identifies this element among the children |
| /// of this element's parent. |
| String get identifier; |
| |
| /// The libraries that are imported into this library. |
| /// |
| /// This includes all of the libraries that are imported using a prefix, and |
| /// those that are imported without a prefix. |
| List<LibraryElement> get importedLibraries; |
| |
| /// Whether the library is the `dart:async` library. |
| bool get isDartAsync; |
| |
| /// Whether the library is the `dart:core` library. |
| bool get isDartCore; |
| |
| /// Whether the library is part of the SDK. |
| bool get isInSdk; |
| |
| /// The language version for this library. |
| LibraryLanguageVersion get languageVersion; |
| |
| @override |
| LibraryElement get library; |
| |
| /// The name of this library, possibly the empty string if this library does |
| /// not have an explicit name. |
| @override |
| String get name; |
| |
| /// The public [Namespace] of this library. |
| Namespace get publicNamespace; |
| |
| @override |
| AnalysisSession get session; |
| |
| /// The top-level elements defined in each of the compilation units that are |
| /// included in this library. This includes both public and private elements, |
| /// but does not include imports, exports, or synthetic elements. |
| Iterable<Element> get topLevelElements; |
| |
| /// The [TypeProvider] that is used in this library. |
| TypeProvider get typeProvider; |
| |
| /// The [TypeSystem] that is used in this library. |
| TypeSystem get typeSystem; |
| |
| /// The compilation units this library consists of. |
| /// |
| /// This includes the defining compilation unit and units included using the |
| /// `part` directive. |
| @Deprecated(elementModelDeprecationMsg) |
| List<CompilationUnitElement> get units; |
| } |
| |
| /// A single export directive within a library. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use LibraryExport instead') |
| abstract class LibraryExportElement implements _ExistingElement { |
| /// The combinators that were specified as part of the `export` directive in |
| /// the order in which they were specified. |
| List<NamespaceCombinator> get combinators; |
| |
| @Deprecated(elementModelDeprecationMsg) |
| @override |
| CompilationUnitElement get enclosingElement3; |
| |
| /// The [LibraryElement], if [uri] is a [DirectiveUriWithLibrary]. |
| LibraryElement? get exportedLibrary; |
| |
| /// The offset of the `export` keyword. |
| int get exportKeywordOffset; |
| |
| /// The interpretation of the URI specified in the directive. |
| DirectiveUri get uri; |
| } |
| |
| /// A single import directive within a library. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use LibraryImport instead') |
| abstract class LibraryImportElement implements _ExistingElement { |
| /// The combinators that were specified as part of the `import` directive in |
| /// the order in which they were specified. |
| List<NamespaceCombinator> get combinators; |
| |
| @Deprecated(elementModelDeprecationMsg) |
| @override |
| CompilationUnitElement get enclosingElement3; |
| |
| /// The [LibraryElement], if [uri] is a [DirectiveUriWithLibrary]. |
| LibraryElement? get importedLibrary; |
| |
| /// The offset of the `import` keyword. |
| int get importKeywordOffset; |
| |
| /// The [Namespace] that this directive contributes to the containing library. |
| Namespace get namespace; |
| |
| /// The prefix that was specified as part of the import directive, or `null` |
| /// if there was no prefix specified. |
| @Deprecated(elementModelDeprecationMsg) |
| ImportElementPrefix? get prefix; |
| |
| /// The interpretation of the URI specified in the directive. |
| DirectiveUri get uri; |
| } |
| |
| class LibraryLanguageVersion { |
| /// The version for the whole package that contains this library. |
| final Version package; |
| |
| /// The version specified using `@dart` override, `null` if absent or invalid. |
| final Version? override; |
| |
| LibraryLanguageVersion({ |
| required this.package, |
| required this.override, |
| }); |
| |
| /// The effective language version for the library. |
| Version get effective { |
| return override ?? package; |
| } |
| } |
| |
| /// An element that can be (but is not required to be) defined within a method |
| /// or function (an [ExecutableElement]). |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use LocalElement2 instead') |
| abstract class LocalElement implements Element {} |
| |
| /// A local variable. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use LocalVariableFragment and LocalVariableElement2 instead') |
| abstract class LocalVariableElement implements PromotableElement { |
| /// Whether the variable has an initializer at declaration. |
| bool get hasInitializer; |
| |
| @override |
| String get name; |
| } |
| |
| /// An object that controls how namespaces are combined. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| sealed class NamespaceCombinator { |
| /// The offset of the character immediately following the last character of |
| /// this node. |
| int get end; |
| |
| /// The offset of the first character of this node. |
| int get offset; |
| } |
| |
| /// A parameter defined within an executable element. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use FormalParameterElement instead') |
| abstract class ParameterElement |
| implements PromotableElement, ConstantEvaluationTarget { |
| @override |
| ParameterElement get declaration; |
| |
| /// The code of the default value, or `null` if no default value. |
| String? get defaultValueCode; |
| |
| @experimental |
| FormalParameterElement get element; |
| |
| /// Whether the parameter has a default value. |
| bool get hasDefaultValue; |
| |
| /// Whether the parameter is covariant, meaning it is allowed to have a |
| /// narrower type in an override. |
| bool get isCovariant; |
| |
| /// Whether the parameter is an initializing formal parameter. |
| bool get isInitializingFormal; |
| |
| /// Whether the parameter is a named parameter. |
| /// |
| /// Named parameters that are annotated with the `@required` annotation are |
| /// considered optional. Named parameters that are annotated with the |
| /// `required` syntax are considered required. |
| bool get isNamed; |
| |
| /// Whether the parameter is an optional parameter. |
| /// |
| /// Optional parameters can either be positional or named. Named parameters |
| /// that are annotated with the `@required` annotation are considered |
| /// optional. Named parameters that are annotated with the `required` syntax |
| /// are considered required. |
| bool get isOptional; |
| |
| /// Whether the parameter is both an optional and named parameter. |
| /// |
| /// Named parameters that are annotated with the `@required` annotation are |
| /// considered optional. Named parameters that are annotated with the |
| /// `required` syntax are considered required. |
| bool get isOptionalNamed; |
| |
| /// Whether the parameter is both an optional and positional parameter. |
| bool get isOptionalPositional; |
| |
| /// Whether the parameter is a positional parameter. |
| /// |
| /// Positional parameters can either be required or optional. |
| bool get isPositional; |
| |
| /// Whether the parameter is either a required positional parameter, or a |
| /// named parameter with the `required` keyword. |
| /// |
| /// Note: the presence or absence of the `@required` annotation does not |
| /// change the meaning of this getter. The parameter `{@required int x}` |
| /// will return `false` and the parameter `{@required required int x}` |
| /// will return `true`. |
| bool get isRequired; |
| |
| /// Whether the parameter is both a required and named parameter. |
| /// |
| /// Named parameters that are annotated with the `@required` annotation are |
| /// considered optional. Named parameters that are annotated with the |
| /// `required` syntax are considered required. |
| bool get isRequiredNamed; |
| |
| /// Whether the parameter is both a required and positional parameter. |
| bool get isRequiredPositional; |
| |
| /// Whether the parameter is a super formal parameter. |
| bool get isSuperFormal; |
| |
| @override |
| String get name; |
| |
| /// The kind of this parameter. |
| @Deprecated('Use the getters isOptionalNamed, isOptionalPositional, ' |
| 'isRequiredNamed, and isRequiredPositional') |
| ParameterKind get parameterKind; |
| |
| /// The parameters defined by this parameter. |
| /// |
| /// A parameter will only define other parameters if it is a function typed |
| /// parameter. |
| List<ParameterElement> get parameters; |
| |
| /// The type parameters defined by this parameter. |
| /// |
| /// A parameter will only define type parameters if it is a function typed |
| /// parameter. |
| @Deprecated(elementModelDeprecationMsg) |
| List<TypeParameterElement> get typeParameters; |
| |
| /// Appends the type, name and possibly the default value of this parameter |
| /// to the given [buffer]. |
| void appendToWithoutDelimiters( |
| StringBuffer buffer, { |
| @Deprecated('Only non-nullable by default mode is supported') |
| bool withNullability = true, |
| }); |
| } |
| |
| /// A 'part' directive within a library. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use PartInclude instead') |
| abstract class PartElement implements _ExistingElement { |
| /// The interpretation of the URI specified in the directive. |
| DirectiveUri get uri; |
| } |
| |
| /// A pattern variable. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use PatternVariableFragment and PatternVariableElement2 instead') |
| abstract class PatternVariableElement implements LocalVariableElement { |
| /// The variable in which this variable joins with other pattern variables |
| /// with the same name, in a logical-or pattern, or shared case scope. |
| JoinPatternVariableElement? get join; |
| } |
| |
| /// A prefix used to import one or more libraries into another library. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use PrefixElement2 instead') |
| abstract class PrefixElement implements _ExistingElement { |
| @Deprecated(elementModelDeprecationMsg) |
| @override |
| CompilationUnitElement get enclosingElement3; |
| |
| /// The imports that share this prefix. |
| List<LibraryImportElement> get imports; |
| |
| @override |
| String get name; |
| |
| /// The name lookup scope for this import prefix. |
| /// |
| /// It consists of elements imported into the enclosing library with this |
| /// prefix. The namespace combinators of the import directives are taken |
| /// into account. |
| Scope get scope; |
| } |
| |
| /// A variable that might be subject to type promotion. This might be a local |
| /// variable or a parameter. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use PromotableElement2 instead') |
| abstract class PromotableElement implements LocalElement, VariableElement { |
| // Promotable elements are guaranteed to have a name. |
| @override |
| String get name; |
| } |
| |
| /// A combinator that cause some of the names in a namespace to be visible (and |
| /// the rest hidden) when being imported. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| abstract class ShowElementCombinator implements NamespaceCombinator { |
| /// The names that are to be made visible in the importing library if they |
| /// are defined in the imported library. |
| List<String> get shownNames; |
| } |
| |
| /// An element that defines a type. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use TypeDefiningElement2 instead') |
| abstract class TypeDefiningElement implements Element {} |
| |
| /// A type parameter. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use TypeParameterElement2 instead') |
| abstract class TypeParameterElement implements TypeDefiningElement { |
| /// The type representing the bound associated with this parameter, or `null` |
| /// if this parameter does not have an explicit bound. Being able to |
| /// distinguish between an implicit and explicit bound is needed by the |
| /// instantiate to bounds algorithm. |
| DartType? get bound; |
| |
| @override |
| TypeParameterElement get declaration; |
| |
| @override |
| String get displayName; |
| |
| @override |
| String get name; |
| |
| /// Creates the [TypeParameterType] with the given [nullabilitySuffix] for |
| /// this type parameter. |
| TypeParameterType instantiate({ |
| required NullabilitySuffix nullabilitySuffix, |
| }); |
| } |
| |
| /// An element that has type parameters, such as a class or a typedef. This also |
| /// includes functions and methods if support for generic methods is enabled. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use TypeParameterizedElement2 instead') |
| abstract class TypeParameterizedElement implements _ExistingElement { |
| /// If the element defines a type, indicates whether the type may safely |
| /// appear without explicit type parameters as the bounds of a type parameter |
| /// declaration. |
| /// |
| /// If the element does not define a type, returns `true`. |
| bool get isSimplyBounded; |
| |
| /// The type parameters declared by this element directly. |
| /// |
| /// This does not include type parameters that are declared by any enclosing |
| /// elements. |
| @Deprecated(elementModelDeprecationMsg) |
| List<TypeParameterElement> get typeParameters; |
| } |
| |
| /// A pseudo-elements that represents names that are undefined. This situation |
| /// is not allowed by the language, so objects implementing this interface |
| /// always represent an error. As a result, most of the normal operations on |
| /// elements do not make sense and will return useless results. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Not used anymore') |
| abstract class UndefinedElement implements Element {} |
| |
| /// An element included into a library using some URI. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use Element2 instead') |
| abstract class UriReferencedElement implements _ExistingElement { |
| /// The URI that is used to include this element into the enclosing library, |
| /// or `null` if this is the defining compilation unit of a library. |
| String? get uri; |
| |
| /// The offset of the character immediately following the last character of |
| /// this node's URI, or `-1` for synthetic import. |
| int get uriEnd; |
| |
| /// The offset of the URI in the file, or `-1` if this element is synthetic. |
| int get uriOffset; |
| } |
| |
| /// A variable. There are more specific subclasses for more specific kinds of |
| /// variables. |
| /// |
| /// Clients may not extend, implement or mix-in this class. |
| @Deprecated('Use VariableElement2 instead') |
| abstract class VariableElement implements Element, ConstantEvaluationTarget { |
| @override |
| VariableElement get declaration; |
| |
| /// Whether the variable element did not have an explicit type specified |
| /// for it. |
| bool get hasImplicitType; |
| |
| /// Whether the variable was declared with the 'const' modifier. |
| bool get isConst; |
| |
| /// Whether the variable was declared with the 'final' modifier. |
| /// |
| /// Variables that are declared with the 'const' modifier will return `false` |
| /// even though they are implicitly final. |
| bool get isFinal; |
| |
| /// Whether the variable uses late evaluation semantics. |
| /// |
| /// This will always return `false` unless the experiment 'non-nullable' is |
| /// enabled. |
| bool get isLate; |
| |
| /// Whether the element is a static variable, as per section 8 of the Dart |
| /// Language Specification: |
| /// |
| /// > A static variable is a variable that is not associated with a particular |
| /// > instance, but rather with an entire library or class. Static variables |
| /// > include library variables and class variables. Class variables are |
| /// > variables whose declaration is immediately nested inside a class |
| /// > declaration and includes the modifier static. A library variable is |
| /// > implicitly static. |
| bool get isStatic; |
| |
| @override |
| String get name; |
| |
| /// The declared type of this variable. |
| DartType get type; |
| |
| /// Returns a representation of the value of this variable, forcing the value |
| /// to be computed if it had not previously been computed, or `null` if either |
| /// this variable was not declared with the 'const' modifier or if the value |
| /// of this variable could not be computed because of errors. |
| DartObject? computeConstantValue(); |
| } |
| |
| /// This class exists to provide non-nullable overrides for existing elements, |
| /// as opposite to artificial "multiply defined" element. |
| @Deprecated('Use Element2 instead') |
| @AnalyzerPublicApi( |
| message: 'Exposed because it is implemented by various elements') |
| abstract class _ExistingElement implements Element { |
| @Deprecated(elementModelDeprecationMsg) |
| @override |
| Element get declaration; |
| |
| @Deprecated(elementModelDeprecationMsg) |
| @override |
| LibraryElement get library; |
| |
| @override |
| Source get librarySource; |
| |
| @override |
| Source get source; |
| } |