Skip to content

Commit 3f159b2

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Updates as needed for google3.
Change-Id: Ib76bf37a41d2fc0923ccddb1da37599589da3a5f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396571 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 4565792 commit 3f159b2

File tree

26 files changed

+408
-26
lines changed

26 files changed

+408
-26
lines changed

pkg/analysis_server/lib/src/computer/computer_outline.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ class _FunctionBodyOutlinesVisitor extends RecursiveAstVisitor<void> {
653653
/// Return `true` if the given [element] is a top-level member of the test
654654
/// package.
655655
bool _isInsideTestPackage(engine.TopLevelFunctionElement element) {
656-
var parent = element.library2!;
656+
var parent = element.library2;
657657
return parent.firstFragment.source.fullName.endsWith('test.dart');
658658
}
659659
}

pkg/analysis_server/lib/src/services/completion/dart/candidate_suggestion.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ final class ConstructorSuggestion extends ExecutableSuggestion
186186

187187
var className = enclosingClass.displayName;
188188

189-
var completion = element.displayName;
189+
// TODO(scheglov): Wrong, if no name, should be no completion.
190+
var completion = element.name3 ?? '';
190191
if (suggestUnnamedAsNew) {
191192
if (completion.isEmpty) {
192193
completion = 'new';

pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class DeclarationHelper {
465465
prefix: null,
466466
isNotImported: true,
467467
);
468-
_addConstructors(library.asElement as LibraryElement, importData);
468+
_addConstructors(library.asElement, importData);
469469
}
470470

471471
/// Add members from all the applicable extensions that are visible in the
@@ -477,7 +477,7 @@ class DeclarationHelper {
477477
required bool includeMethods,
478478
required bool includeSetters,
479479
}) {
480-
var libraryElement = library.asElement as LibraryElement;
480+
var libraryElement = library.asElement;
481481
var applicableExtensions = library.exportNamespace.definedNames.values
482482
.whereType<ExtensionElement>()
483483
.applicableTo(
@@ -511,7 +511,7 @@ class DeclarationHelper {
511511
isNotImported: true,
512512
);
513513
_addExternalTopLevelDeclarations(
514-
library: library.asElement as LibraryElement,
514+
library: library.asElement,
515515
namespace: library.exportNamespace,
516516
importData: importData,
517517
);

pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
741741
if (constructorElement == null) {
742742
return;
743743
}
744-
var libraryElement = state.libraryElement.asElement as LibraryElement;
744+
var libraryElement = state.libraryElement.asElement;
745745
declarationHelper(
746746
mustBeConstant: constructorElement.isConst,
747747
).addPossibleRedirectionsInLibrary(constructorElement, libraryElement);

pkg/analysis_server/lib/src/services/refactoring/legacy/extract_method.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Future<void> addLibraryImports(
6161

6262
// TODO(brianwilkerson): Use `targetLibrary2` everywhere below and rename it
6363
// to `targetLibrary`.
64-
var targetLibrary = targetLibrary2.asElement as LibraryElement;
64+
var targetLibrary = targetLibrary2.asElement;
6565
var libUtils = CorrectionUtils(resolveResult);
6666
var eol = libUtils.endOfLine;
6767
// Prepare information about existing imports.

pkg/analysis_server/lib/src/services/search/hierarchy.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ Future<List<FormalParameterElement>> getHierarchyNamedParameters2(
304304
) async {
305305
var result = await getHierarchyNamedParameters(
306306
searchEngine,
307-
element.asElement as ParameterElement,
307+
element.asElement,
308308
);
309309
return result.map((e) => e.asElement2).toList();
310310
}

pkg/analyzer/lib/dart/analysis/session.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ abstract class AnalysisSession {
5555
/// with the given library [element].
5656
SomeParsedLibraryResult getParsedLibraryByElement(LibraryElement element);
5757

58+
/// Return information about the results of parsing units of the library file
59+
/// with the given library [element].
60+
@experimental
61+
SomeParsedLibraryResult getParsedLibraryByElement2(LibraryElement2 element);
62+
5863
/// Return information about the results of parsing the file with the given
5964
/// absolute, normalized [path].
6065
SomeParsedUnitResult getParsedUnit(String path);

pkg/analyzer/lib/dart/constant/value.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ abstract class DartObject {
7171
/// If this object is the value of a constant variable, the variable.
7272
VariableElement? get variable;
7373

74+
/// If this object is the value of a constant variable, the variable.
75+
VariableElement2? get variable2;
76+
7477
/// Return a representation of the value of the field with the given [name].
7578
///
7679
/// Return `null` if either the object being represented does not have a field

pkg/analyzer/lib/dart/element/element.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ abstract class DirectiveUri {}
515515
abstract class DirectiveUriWithLibrary extends DirectiveUriWithSource {
516516
/// The library referenced by the [source].
517517
LibraryElement get library;
518+
519+
/// The library referenced by the [source].
520+
LibraryElement2 get library2;
518521
}
519522

520523
/// [DirectiveUriWithRelativeUriString] that can be parsed into a relative URI.
@@ -1987,6 +1990,9 @@ abstract class LibraryExportElement implements _ExistingElement {
19871990
/// the order in which they were specified.
19881991
List<NamespaceCombinator> get combinators;
19891992

1993+
@override
1994+
CompilationUnitElement get enclosingElement3;
1995+
19901996
/// The [LibraryElement], if [uri] is a [DirectiveUriWithLibrary].
19911997
LibraryElement? get exportedLibrary;
19921998

pkg/analyzer/lib/dart/element/element2.dart

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,13 @@ abstract class Element2 {
495495
/// be changed if doing so would improve the UX.
496496
String displayString2({bool multiline = false, bool preferTypeAlias = false});
497497

498+
/// Returns a display name for the given element that includes the path to the
499+
/// compilation unit in which the type is defined. If [shortName] is `null`
500+
/// then [displayName] will be used as the name of this element. Otherwise
501+
/// the provided name will be used.
502+
// TODO(brianwilkerson): Make the parameter optional.
503+
String getExtendedDisplayName(String? shortName);
504+
498505
/// Whether the element, assuming that it is within scope, is accessible to
499506
/// code in the given [library].
500507
///
@@ -1165,6 +1172,28 @@ abstract class InstanceElement2
11651172

11661173
/// Returns the setter from [setters2] that has the given [name].
11671174
SetterElement? getSetter2(String name);
1175+
1176+
/// Returns the element representing the getter that results from looking up
1177+
/// the given [name] in this class with respect to the given [library],
1178+
/// or `null` if the look up fails.
1179+
///
1180+
/// The behavior of this method is defined by the Dart Language Specification
1181+
/// in section 17.18 Lookup.
1182+
PropertyAccessorElement2? lookUpGetter2({
1183+
required String name,
1184+
required LibraryElement2 library,
1185+
});
1186+
1187+
/// Returns the element representing the method that results from looking up
1188+
/// the given [name] in this class with respect to the given [library],
1189+
/// or `null` if the look up fails.
1190+
///
1191+
/// The behavior of this method is defined by the Dart Language Specification
1192+
/// in section 17.18 Lookup.
1193+
MethodElement2? lookUpMethod2({
1194+
required String name,
1195+
required LibraryElement2 library,
1196+
});
11681197
}
11691198

11701199
/// The portion of an [InstanceElement2] contributed by a single declaration.
@@ -1279,6 +1308,25 @@ abstract class InterfaceElement2 implements InstanceElement2 {
12791308
required List<DartType> typeArguments,
12801309
required NullabilitySuffix nullabilitySuffix,
12811310
});
1311+
1312+
/// Returns the element representing the method that results from looking up
1313+
/// the given [methodName] in the superclass of this class with respect to the
1314+
/// given [library], or `null` if the look up fails.
1315+
///
1316+
/// The behavior of this method is defined by the Dart Language Specification
1317+
/// in section 16.15.1:
1318+
/// <blockquote>
1319+
/// The result of looking up method <i>m</i> in class <i>C</i> with respect to
1320+
/// library <i>L</i> is: If <i>C</i> declares an instance method named
1321+
/// <i>m</i> that is accessible to <i>L</i>, then that method is the result of
1322+
/// the lookup. Otherwise, if <i>C</i> has a superclass <i>S</i>, then the
1323+
/// result of the lookup is the result of looking up method <i>m</i> in
1324+
/// <i>S</i> with respect to <i>L</i>. Otherwise, we say that the lookup has
1325+
/// failed.
1326+
/// </blockquote>
1327+
// TODO(scheglov): Deprecate and remove it.
1328+
MethodElement2? lookUpInheritedMethod2(
1329+
String methodName, LibraryElement2 library);
12821330
}
12831331

12841332
/// The portion of an [InterfaceElement2] contributed by a single declaration.
@@ -1455,6 +1503,12 @@ abstract class LibraryElement2 implements Element2, Annotatable {
14551503
/// of this element's parent.
14561504
String get identifier;
14571505

1506+
/// The libraries that are imported into this library.
1507+
///
1508+
/// This includes all of the libraries that are imported using a prefix, and
1509+
/// those that are imported without a prefix.
1510+
List<LibraryElement2> get importedLibraries2;
1511+
14581512
/// Whether the library is the `dart:async` library.
14591513
bool get isDartAsync;
14601514

@@ -1902,6 +1956,9 @@ abstract class MethodElement2 implements ExecutableElement2 {
19021956
/// The test might be based on the name of the executable element, in which
19031957
/// case the result will be correct when the name is legal.
19041958
bool get isOperator;
1959+
1960+
@override
1961+
LibraryElement2 get library2;
19051962
}
19061963

19071964
/// The portion of a [MethodElement2] contributed by a single declaration.
@@ -2352,6 +2409,9 @@ abstract class TopLevelFunctionElement implements ExecutableElement2 {
23522409
///
23532410
/// A top-level function is an entry point if it has the name `main`.
23542411
bool get isEntryPoint;
2412+
2413+
@override
2414+
LibraryElement2 get library2;
23552415
}
23562416

23572417
/// The portion of a [TopLevelFunctionElement] contributed by a single

0 commit comments

Comments
 (0)