Element.session can be nullable

This is not convenient, and not nice, but it can be.
We have to accept that it can for now, and plan to make it better.

Bug: https://github.com/dart-lang/sdk/issues/44837
Change-Id: Icbd2d55b6690ed817b38a7768198c41ce36cf002
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182960
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-02-04 22:02:29 +00:00 committed by commit-bot@chromium.org
parent d052156ea4
commit 9cbe1cafe0
3 changed files with 13 additions and 4 deletions

View file

@ -418,6 +418,9 @@ abstract class CompilationUnitElement implements Element, UriReferencedElement {
/// unit. /// unit.
List<ClassElement> get mixins; List<ClassElement> get mixins;
@override
AnalysisSession get session;
/// Return a list containing all of the top-level variables contained in this /// Return a list containing all of the top-level variables contained in this
/// compilation unit. /// compilation unit.
List<TopLevelVariableElement> get topLevelVariables; List<TopLevelVariableElement> get topLevelVariables;
@ -655,7 +658,7 @@ abstract class Element implements AnalysisTarget {
int get nameOffset; int get nameOffset;
/// Return the analysis session in which this element is defined. /// Return the analysis session in which this element is defined.
AnalysisSession get session; AnalysisSession? get session;
@override @override
Source? get source; Source? get source;
@ -1377,6 +1380,9 @@ abstract class LibraryElement implements _ExistingElement {
/// that are either declared in the library, or imported into it. /// that are either declared in the library, or imported into it.
Scope get scope; Scope get scope;
@override
AnalysisSession get session;
/// Return the top-level elements defined in each of the compilation units /// Return the top-level elements defined in each of the compilation units
/// that are included in this library. This includes both public and private /// that are included in this library. This includes both public and private
/// elements, but does not include imports, exports, or synthetic elements. /// elements, but does not include imports, exports, or synthetic elements.

View file

@ -1383,6 +1383,9 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
_mixins = mixins; _mixins = mixins;
} }
@override
AnalysisSession get session => enclosingElement.session;
@override @override
List<TopLevelVariableElement> get topLevelVariables { List<TopLevelVariableElement> get topLevelVariables {
if (_variables != null) return _variables!; if (_variables != null) return _variables!;
@ -2888,8 +2891,8 @@ abstract class ElementImpl implements Element {
} }
@override @override
AnalysisSession get session { AnalysisSession? get session {
return enclosingElement!.session; return enclosingElement?.session;
} }
@override @override

View file

@ -561,7 +561,7 @@ abstract class Member implements Element {
int get nameOffset => _declaration.nameOffset; int get nameOffset => _declaration.nameOffset;
@override @override
AnalysisSession get session => _declaration.session; AnalysisSession? get session => _declaration.session;
@override @override
Source get source => _declaration.source!; Source get source => _declaration.source!;