Skip to content

Commit 91f5aad

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Deprecate V1 APIs in dart/element/type.dart
Add InterfaceType.getGetter2() and getSetter2(). Change-Id: I9f32fff71a9b643cc9fd46f0aaa87233689a9660 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412940 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent fb6fed1 commit 91f5aad

35 files changed

+565
-501
lines changed

pkg/analysis_server/lib/src/services/correction/dart/create_missing_overrides.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ class CreateMissingOverrides extends ResolvedCorrectionProducer {
1919

2020
@override
2121
CorrectionApplicability get applicability =>
22-
// TODO(applicability): comment on why.
23-
CorrectionApplicability
24-
.singleLocation;
22+
// TODO(applicability): comment on why.
23+
CorrectionApplicability.singleLocation;
2524

2625
@override
2726
List<String> get fixArguments => [
@@ -44,9 +43,7 @@ class CreateMissingOverrides extends ResolvedCorrectionProducer {
4443
}
4544
var signatures = [
4645
...InheritanceOverrideVerifier.missingOverrides2(targetDeclaration),
47-
...InheritanceOverrideVerifier.missingMustBeOverridden2(
48-
targetDeclaration,
49-
),
46+
...InheritanceOverrideVerifier.missingMustBeOverridden(targetDeclaration),
5047
];
5148
// Sort by name, getters before setters.
5249
signatures.sort((ExecutableElement2 a, ExecutableElement2 b) {

pkg/analyzer/api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4424,9 +4424,11 @@ package:analyzer/dart/element/type.dart:
44244424
superclass (getter: InterfaceType?)
44254425
superclassConstraints (getter: List<InterfaceType>)
44264426
getGetter (method: PropertyAccessorElement? Function(String))
4427+
getGetter2 (method: GetterElement? Function(String))
44274428
getMethod (method: MethodElement? Function(String))
44284429
getMethod2 (method: MethodElement2? Function(String))
44294430
getSetter (method: PropertyAccessorElement? Function(String))
4431+
getSetter2 (method: SetterElement? Function(String))
44304432
lookUpConstructor (method: ConstructorElement? Function(String?, LibraryElement))
44314433
lookUpConstructor2 (method: ConstructorElement2? Function(String?, LibraryElement2))
44324434
lookUpGetter2 (method: PropertyAccessorElement? Function(String, LibraryElement, {bool concrete, bool inherited, bool recoveryStatic}))

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
65
import 'package:analyzer/dart/analysis/analysis_context.dart';
76
import 'package:analyzer/dart/analysis/declared_variables.dart';
87
import 'package:analyzer/dart/analysis/results.dart';
@@ -54,6 +53,7 @@ abstract class AnalysisSession {
5453

5554
/// Return information about the results of parsing units of the library file
5655
/// with the given library [element].
56+
@Deprecated('Use getParsedLibraryByElement2() instead')
5757
SomeParsedLibraryResult getParsedLibraryByElement(LibraryElement element);
5858

5959
/// Return information about the results of parsing units of the library file
@@ -74,6 +74,7 @@ abstract class AnalysisSession {
7474
/// resolving all of the files in the library with the library [element].
7575
///
7676
/// Throw [ArgumentError] if the [element] was not produced by this session.
77+
@Deprecated('Use getResolvedLibraryByElement2() instead')
7778
Future<SomeResolvedLibraryResult> getResolvedLibraryByElement(
7879
LibraryElement element);
7980

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
/// [element model](../element/element.dart).
1313
library;
1414

15-
// ignore_for_file: analyzer_use_new_elements, as_much_as_we_can
1615
import 'package:analyzer/dart/element/element.dart';
1716
import 'package:analyzer/dart/element/element2.dart';
1817
import 'package:analyzer/dart/element/type.dart';
@@ -70,6 +69,7 @@ abstract class DartObject {
7069
DartType? get type;
7170

7271
/// If this object is the value of a constant variable, the variable.
72+
@Deprecated('Use variable2 instead')
7373
VariableElement? get variable;
7474

7575
/// If this object is the value of a constant variable, the variable.
@@ -106,6 +106,7 @@ abstract class DartObject {
106106
/// * this object is not of a function type,
107107
/// * the value of the object being represented is not known, or
108108
/// * the value of the object being represented is `null`.
109+
@Deprecated('Use toFunctionValue2() instead')
109110
ExecutableElement? toFunctionValue();
110111

111112
/// Return an element corresponding to the value of the object being

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
75
import 'package:analyzer/dart/element/element.dart';
86
import 'package:analyzer/dart/element/element2.dart';
97
import 'package:analyzer/src/utilities/extensions/element.dart';
@@ -24,9 +22,12 @@ abstract class Scope {
2422
///
2523
/// Clients may not extend, implement or mix-in this class.
2624
abstract class ScopeLookupResult {
25+
@Deprecated('Use getter2 instead')
2726
Element? get getter => getter2?.asElement;
27+
2828
Element2? get getter2;
2929

30+
@Deprecated('Use setter2 instead')
3031
Element? get setter => setter2?.asElement;
3132

3233
Element2? get setter2;

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
6-
75
/// Defines the type model. The type model is part of the
86
/// [element model](../dart_element_element/dart_element_element-library.html)
97
/// in that most types are defined by Dart code (the types `dynamic` and `void`
@@ -14,7 +12,7 @@
1412
/// interface defined by a class (an instance of [InterfaceType]) or the type of
1513
/// a function (an instance of [FunctionType]).
1614
///
17-
/// We make a distinction between the declaration of a class (a [ClassElement])
15+
/// We make a distinction between the declaration of a class (a [ClassElement2])
1816
/// and the type defined by that class (an [InterfaceType]). The biggest reason
1917
/// for the distinction is to allow us to more cleanly represent the distinction
2018
/// between type parameters and type arguments. For example, if we define a
@@ -41,6 +39,7 @@ abstract class DartType {
4139

4240
/// Return the element representing the declaration of this type, or `null`
4341
/// if the type is not associated with an element.
42+
@Deprecated('Use element3 instead')
4443
Element? get element;
4544

4645
/// Return the element representing the declaration of this type, or `null`
@@ -171,6 +170,7 @@ abstract class DartType {
171170
///
172171
/// For a [TypeParameterType] with a bound (declared or promoted), returns
173172
/// the interface implemented by the bound.
173+
@Deprecated('Use asInstanceOf2() instead')
174174
InterfaceType? asInstanceOf(InterfaceElement element);
175175

176176
/// Return the canonical interface that this type implements for [element],
@@ -271,6 +271,7 @@ abstract class FunctionType implements DartType {
271271
///
272272
/// The parameter types are not necessarily in the same order as they appear
273273
/// in the declaration of the function.
274+
@Deprecated('Use formalParameters instead')
274275
List<ParameterElement> get parameters;
275276

276277
/// All the positional parameter types, starting with the required ones, and
@@ -307,11 +308,7 @@ abstract class FunctionType implements DartType {
307308

308309
/// The formal type parameters of this generic function; for example,
309310
/// `<T> T -> T`.
310-
//
311-
// TODO(scheglov): Remove the mention for "typeParameters".
312-
// These are distinct from the `typeParameters` list, which contains type
313-
// parameters from surrounding contexts, and thus are free type variables
314-
// from the perspective of this function type.
311+
@Deprecated('Use typeParameters instead')
315312
List<TypeParameterElement> get typeFormals;
316313

317314
/// The type parameters.
@@ -325,18 +322,19 @@ abstract class FunctionType implements DartType {
325322
FunctionType instantiate(List<DartType> argumentTypes);
326323
}
327324

328-
/// Information about an instantiated [TypeAliasElement] and the type
325+
/// Information about an instantiated [TypeAliasElement2] and the type
329326
/// arguments with which it is instantiated.
330327
abstract class InstantiatedTypeAliasElement {
331328
/// The alias element that is instantiated to produce a [DartType].
329+
@Deprecated('Use element2 instead')
332330
TypeAliasElement get element;
333331

334332
/// The alias element that is instantiated to produce a [DartType].
335333
@experimental
336334
TypeAliasElement2 get element2;
337335

338-
/// The type arguments with which the [element] was instantiated.
339-
/// This list will be empty if the [element] is not generic.
336+
/// The type arguments with which the [element2] was instantiated.
337+
/// This list will be empty if the [element2] is not generic.
340338
List<DartType> get typeArguments;
341339
}
342340

@@ -347,19 +345,22 @@ abstract class InstantiatedTypeAliasElement {
347345
abstract class InterfaceType implements ParameterizedType {
348346
/// Return a list containing all of the accessors (getters and setters)
349347
/// declared in this type.
348+
@Deprecated('Use getters or setters instead')
350349
List<PropertyAccessorElement> get accessors;
351350

352351
/// Return all the super-interfaces implemented by this interface. This
353352
/// includes superclasses, mixins, interfaces, and superclass constraints.
354353
List<InterfaceType> get allSupertypes;
355354

356355
/// Return a list containing all of the constructors declared in this type.
356+
@Deprecated('Use constructors2 instead')
357357
List<ConstructorElement> get constructors;
358358

359359
/// Return a list containing all of the constructors declared in this type.
360360
@experimental
361361
List<ConstructorElement2> get constructors2;
362362

363+
@Deprecated('Use element3 instead')
363364
@override
364365
InterfaceElement get element;
365366

@@ -378,6 +379,7 @@ abstract class InterfaceType implements ParameterizedType {
378379
List<InterfaceType> get interfaces;
379380

380381
/// Return a list containing all of the methods declared in this type.
382+
@Deprecated('Use methods2 instead')
381383
List<MethodElement> get methods;
382384

383385
/// Return a list containing all of the methods declared in this type.
@@ -410,11 +412,18 @@ abstract class InterfaceType implements ParameterizedType {
410412
/// Return the element representing the getter with the given [name] that is
411413
/// declared in this class, or `null` if this class does not declare a getter
412414
/// with the given name.
415+
@Deprecated('Use getGetter2() instead')
413416
PropertyAccessorElement? getGetter(String name);
414417

418+
/// Return the element representing the getter with the given [name] that is
419+
/// declared in this class, or `null` if this class does not declare a getter
420+
/// with the given name.
421+
GetterElement? getGetter2(String name);
422+
415423
/// Return the element representing the method with the given [name] that is
416424
/// declared in this class, or `null` if this class does not declare a method
417425
/// with the given name.
426+
@Deprecated('Use getMethod2() instead')
418427
MethodElement? getMethod(String name);
419428

420429
/// Return the element representing the method with the given [name] that is
@@ -425,8 +434,14 @@ abstract class InterfaceType implements ParameterizedType {
425434
/// Return the element representing the setter with the given [name] that is
426435
/// declared in this class, or `null` if this class does not declare a setter
427436
/// with the given name.
437+
@Deprecated('Use getSetter2() instead')
428438
PropertyAccessorElement? getSetter(String name);
429439

440+
/// Return the element representing the setter with the given [name] that is
441+
/// declared in this class, or `null` if this class does not declare a setter
442+
/// with the given name.
443+
SetterElement? getSetter2(String name);
444+
430445
/// Return the element representing the constructor that results from looking
431446
/// up the constructor with the given [name] in this class with respect to the
432447
/// given [library], or `null` if the look up fails. The behavior of this
@@ -437,6 +452,7 @@ abstract class InterfaceType implements ParameterizedType {
437452
/// <i>T<i>. Otherwise, if <i>q</i> is not defined or not accessible, a
438453
/// NoSuchMethodException is thrown.
439454
/// </blockquote>
455+
@Deprecated('Use lookUpConstructor2() instead')
440456
ConstructorElement? lookUpConstructor(String? name, LibraryElement library);
441457

442458
/// Return the element representing the constructor that results from looking
@@ -449,7 +465,8 @@ abstract class InterfaceType implements ParameterizedType {
449465
/// <i>T<i>. Otherwise, if <i>q</i> is not defined or not accessible, a
450466
/// NoSuchMethodException is thrown.
451467
/// </blockquote>
452-
ConstructorElement2? lookUpConstructor2(String? name, LibraryElement2 library);
468+
ConstructorElement2? lookUpConstructor2(
469+
String? name, LibraryElement2 library);
453470

454471
/// Return the getter with the given [name].
455472
///
@@ -461,6 +478,7 @@ abstract class InterfaceType implements ParameterizedType {
461478
///
462479
/// If [recoveryStatic] is `true`, then static getters of the class,
463480
/// and its superclasses are considered. Clients should not use it.
481+
@Deprecated('Use lookUpGetter3() instead')
464482
PropertyAccessorElement? lookUpGetter2(
465483
String name,
466484
LibraryElement library, {
@@ -497,6 +515,7 @@ abstract class InterfaceType implements ParameterizedType {
497515
///
498516
/// If [recoveryStatic] is `true`, then static methods of the class,
499517
/// and its superclasses are considered. Clients should not use it.
518+
@Deprecated('Use lookUpMethod3() instead')
500519
MethodElement? lookUpMethod2(
501520
String name,
502521
LibraryElement library, {
@@ -533,6 +552,7 @@ abstract class InterfaceType implements ParameterizedType {
533552
///
534553
/// If [recoveryStatic] is `true`, then static setters of the class,
535554
/// and its superclasses are considered. Clients should not use it.
555+
@Deprecated('Use lookUpSetter3() instead')
536556
PropertyAccessorElement? lookUpSetter2(
537557
String name,
538558
LibraryElement library, {
@@ -578,7 +598,7 @@ abstract class NeverType implements DartType {}
578598
///
579599
/// This substitution will be propagated to its members. For example, say our
580600
/// `Foo<T>` class has a field `T bar;`. When we look up this field, we will get
581-
/// back a [FieldElement] that tracks the substituted type as `{S/T}T`, so when
601+
/// back a [FieldElement2] that tracks the substituted type as `{S/T}T`, so when
582602
/// we ask for the field type we will get `S`.
583603
///
584604
/// Clients may not extend, implement or mix-in this class.
@@ -667,6 +687,7 @@ abstract class TypeParameterType implements DartType {
667687
/// Always consult the bound if that could be relevant.
668688
ElementLocation get definition;
669689

690+
@Deprecated('Use element3 instead')
670691
@override
671692
TypeParameterElement get element;
672693

0 commit comments

Comments
 (0)