Elements. Remove V1 ClassElement.
Change-Id: Iafae2a9c8910cb0a9f06d4b378bee1a67fd25b76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/api.txt b/pkg/analyzer/api.txt
index c7309a3..f581ea7 100644
--- a/pkg/analyzer/api.txt
+++ b/pkg/analyzer/api.txt
@@ -2958,9 +2958,6 @@
toSymbolValue (method: String? Function())
toTypeValue (method: DartType? Function())
package:analyzer/dart/element/element.dart:
- AugmentedClassElement (class extends Object implements AugmentedInterfaceElement, deprecated):
- new (constructor: AugmentedClassElement Function())
- firstFragment (getter: ClassElement)
AugmentedEnumElement (class extends Object implements AugmentedInterfaceElement, deprecated):
new (constructor: AugmentedEnumElement Function())
constants (getter: List<FieldElement>)
@@ -3003,25 +3000,6 @@
superclassConstraints (getter: List<InterfaceType>)
BindPatternVariableElement (class extends Object implements PatternVariableElement, deprecated):
new (constructor: BindPatternVariableElement Function())
- ClassElement (class extends Object implements InterfaceElement, deprecated):
- new (constructor: ClassElement Function())
- augmented (getter: AugmentedClassElement, deprecated)
- hasNonFinalField (getter: bool)
- isAbstract (getter: bool)
- isBase (getter: bool)
- isConstructable (getter: bool)
- isDartCoreEnum (getter: bool)
- isDartCoreObject (getter: bool)
- isExhaustive (getter: bool)
- isFinal (getter: bool)
- isInterface (getter: bool)
- isMixinApplication (getter: bool)
- isMixinClass (getter: bool)
- isSealed (getter: bool)
- isValidMixin (getter: bool)
- isExtendableIn (method: bool Function(LibraryElement))
- isImplementableIn (method: bool Function(LibraryElement))
- isMixableIn (method: bool Function(LibraryElement))
ClassMemberElement (class extends Object implements Element, deprecated):
new (constructor: ClassMemberElement Function())
enclosingElement3 (getter: Element)
@@ -3030,7 +3008,6 @@
new (constructor: CompilationUnitElement Function())
accessibleExtensions (getter: List<ExtensionElement>)
accessors (getter: List<PropertyAccessorElement>)
- classes (getter: List<ClassElement>)
enclosingElement3 (getter: CompilationUnitElement?)
enums (getter: List<EnumElement>)
extensionTypes (getter: List<ExtensionTypeElement>, experimental)
@@ -3046,7 +3023,6 @@
session (getter: AnalysisSession)
topLevelVariables (getter: List<TopLevelVariableElement>)
typeAliases (getter: List<TypeAliasElement>)
- getClass (method: ClassElement? Function(String))
getEnum (method: EnumElement? Function(String))
ConstructorElement (class extends Object implements ClassMemberElement, ExecutableElement, ConstantEvaluationTarget, deprecated):
new (constructor: ConstructorElement Function())
@@ -3355,7 +3331,6 @@
typeProvider (getter: TypeProvider)
typeSystem (getter: TypeSystem)
units (getter: List<CompilationUnitElement>, deprecated)
- getClass (method: ClassElement? Function(String), deprecated)
LibraryExportElement (class extends Object implements _ExistingElement, deprecated):
new (constructor: LibraryExportElement Function())
combinators (getter: List<NamespaceCombinator>)
diff --git a/pkg/analyzer/lib/dart/element/element.dart b/pkg/analyzer/lib/dart/element/element.dart
index e67d95d..ae4fdd2 100644
--- a/pkg/analyzer/lib/dart/element/element.dart
+++ b/pkg/analyzer/lib/dart/element/element.dart
@@ -60,15 +60,6 @@
import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';
-/// The result of applying augmentations to a [ClassElement].
-///
-/// Clients may not extend, implement or mix-in this class.
-@Deprecated(elementModelDeprecationMsg)
-abstract class AugmentedClassElement implements AugmentedInterfaceElement {
- @override
- ClassElement get firstFragment;
-}
-
/// The result of applying augmentations to an [EnumElement].
///
/// Clients may not extend, implement or mix-in this class.
@@ -247,105 +238,6 @@
'Use BindPatternVariableFragment and BindPatternVariableElement2 instead')
abstract class BindPatternVariableElement implements PatternVariableElement {}
-/// An element that represents a class or a mixin. The class can be defined by
-/// either a class declaration (with a class body), a mixin application (without
-/// a class body), a mixin declaration, or an enum declaration.
-///
-/// Clients may not extend, implement or mix-in this class.
-@Deprecated('Use ClassElement2 instead')
-abstract class ClassElement implements InterfaceElement {
- @Deprecated(elementModelDeprecationMsg)
- @override
- AugmentedClassElement get augmented;
-
- /// Whether the class or its superclass declares a non-final instance field.
- bool get hasNonFinalField;
-
- /// Whether the class is abstract. A class is abstract if it has an
- /// explicit `abstract` modifier. Note, that this definition of
- /// <i>abstract</i> is different from <i>has unimplemented members</i>.
- bool get isAbstract;
-
- /// Whether this class is a base class.
- ///
- /// A class is a base class if it has an explicit `base` modifier, or the
- /// class has a `base` induced modifier and [isSealed] is `true` as well.
- /// The base modifier allows the class to be extended but not implemented.
- bool get isBase;
-
- /// Whether the class can be instantiated.
- bool get isConstructable;
-
- /// Whether the class represents the class 'Enum' defined in `dart:core`.
- bool get isDartCoreEnum;
-
- /// Whether the class represents the class 'Object' defined in `dart:core`.
- bool get isDartCoreObject;
-
- /// Whether the class has the property where, in a switch, if you cover all
- /// of the subtypes of this element, then the compiler knows that you have
- /// covered all possible instances of the type.
- bool get isExhaustive;
-
- /// Whether the class is a final class.
- ///
- /// A class is a final class if it has an explicit `final` modifier, or the
- /// class has a `final` induced modifier and [isSealed] is `true` as well.
- /// The final modifier prohibits this class from being extended, implemented,
- /// or mixed in.
- bool get isFinal;
-
- /// Whether the class is an interface class.
- ///
- /// A class is an interface class if it has an explicit `interface` modifier,
- /// or the class has an `interface` induced modifier and [isSealed] is `true`
- /// as well. The interface modifier allows the class to be implemented, but
- /// not extended or mixed in.
- bool get isInterface;
-
- /// Whether the class is a mixin application.
- ///
- /// A class is a mixin application if it was declared using the syntax
- /// `class A = B with C;`.
- bool get isMixinApplication;
-
- /// Whether the class is a mixin class.
- ///
- /// A class is a mixin class if it has an explicit `mixin` modifier.
- bool get isMixinClass;
-
- /// Whether the class is a sealed class.
- ///
- /// A class is a sealed class if it has an explicit `sealed` modifier.
- bool get isSealed;
-
- /// Whether the class can validly be used as a mixin when defining
- /// another class.
- ///
- /// For classes defined by a class declaration or a mixin application, the
- /// behavior of this method is defined by the Dart Language Specification
- /// in section 9:
- /// <blockquote>
- /// It is a compile-time error if a declared or derived mixin refers to super.
- /// It is a compile-time error if a declared or derived mixin explicitly
- /// declares a constructor. It is a compile-time error if a mixin is derived
- /// from a class whose superclass is not Object.
- /// </blockquote>
- bool get isValidMixin;
-
- /// Whether the class, assuming that it is within scope, is extendable to
- /// classes in the given [library].
- bool isExtendableIn(LibraryElement library);
-
- /// Whether the class, assuming that it is within scope, is
- /// implementable to classes, mixins, and enums in the given [library].
- bool isImplementableIn(LibraryElement library);
-
- /// Whether the class, assuming that it is within scope, is able to be
- /// mixed-in by classes and enums in the given [library].
- bool isMixableIn(LibraryElement library);
-}
-
/// An element that is contained within a [ClassElement].
///
/// Clients may not extend, implement or mix-in this class.
@@ -382,9 +274,6 @@
/// compilation unit.
List<PropertyAccessorElement> get accessors;
- /// The classes declared in this compilation unit.
- List<ClassElement> get classes;
-
/// The [CompilationUnitElement] that uses `part` directive to include this
/// element, or `null` if this element is the defining unit of the library.
@override
@@ -438,11 +327,6 @@
/// The type aliases declared in this compilation unit.
List<TypeAliasElement> get typeAliases;
- /// Returns the class defined in this compilation unit that has the given
- /// [name], or `null` if this compilation unit does not define a class with
- /// the given name.
- ClassElement? getClass(String name);
-
/// Returns the enum defined in this compilation unit that has the given
/// [name], or `null` if this compilation unit does not define an enum with
/// the given name.
@@ -1855,11 +1739,6 @@
/// `part` directive.
@Deprecated(elementModelDeprecationMsg)
List<CompilationUnitElement> get units;
-
- /// The class defined in this library that has the given [name], or
- /// `null` if this library does not define a class with the given name.
- @Deprecated(elementModelDeprecationMsg)
- ClassElement? getClass(String name);
}
/// A single export directive within a library.
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 268adcf..bd5154a 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -90,17 +90,6 @@
}
@Deprecated(elementModelDeprecationMsg)
-class AugmentedClassElementImpl extends AugmentedInterfaceElementImpl
- implements AugmentedClassElement {
- AugmentedClassElementImpl(super.firstFragment);
-
- @override
- ClassElementImpl get firstFragment {
- return super.firstFragment as ClassElementImpl;
- }
-}
-
-@Deprecated(elementModelDeprecationMsg)
class AugmentedEnumElementImpl extends AugmentedInterfaceElementImpl
implements AugmentedEnumElement {
AugmentedEnumElementImpl(super.firstFragment);
@@ -331,10 +320,7 @@
/// An [InterfaceElementImpl] which is a class.
class ClassElementImpl extends ClassOrMixinElementImpl
- implements
- // ignore:deprecated_member_use_from_same_package,analyzer_use_new_elements
- ClassElement,
- ClassFragment {
+ implements ClassFragment {
late ClassElementImpl2 augmentedInternal;
/// Initialize a newly created class element to have the given [name] at the
@@ -347,10 +333,6 @@
super.accessors = accessors;
}
- @Deprecated(elementModelDeprecationMsg)
- @override
- AugmentedClassElement get augmented => AugmentedClassElementImpl(this);
-
@override
set constructors(List<ConstructorElementImpl> constructors) {
assert(!isMixinApplication);
@@ -381,12 +363,6 @@
return constructors.any((c) => !c.isFactory && c.isConst);
}
- @override
- bool get hasNonFinalField {
- return element.hasNonFinalField;
- }
-
- @override
bool get isAbstract {
return hasModifier(Modifier.ABSTRACT);
}
@@ -400,15 +376,12 @@
return hasModifier(Modifier.BASE);
}
- @override
bool get isConstructable => !isSealed && !isAbstract;
- @override
bool get isDartCoreEnum {
return name == 'Enum' && library.isDartCore;
}
- @override
bool get isDartCoreObject {
return name == 'Object' && library.isDartCore;
}
@@ -417,10 +390,8 @@
return name == 'Record' && library.isDartCore;
}
- @override
bool get isExhaustive => isSealed;
- @override
bool get isFinal {
return hasModifier(Modifier.FINAL);
}
@@ -429,7 +400,6 @@
setModifier(Modifier.FINAL, isFinal);
}
- @override
bool get isInterface {
return hasModifier(Modifier.INTERFACE);
}
@@ -438,7 +408,6 @@
setModifier(Modifier.INTERFACE, isInterface);
}
- @override
bool get isMixinApplication {
return hasModifier(Modifier.MIXIN_APPLICATION);
}
@@ -448,7 +417,6 @@
setModifier(Modifier.MIXIN_APPLICATION, isMixinApplication);
}
- @override
bool get isMixinClass {
return hasModifier(Modifier.MIXIN_CLASS);
}
@@ -457,7 +425,6 @@
setModifier(Modifier.MIXIN_CLASS, isMixinClass);
}
- @override
bool get isSealed {
return hasModifier(Modifier.SEALED);
}
@@ -466,7 +433,6 @@
setModifier(Modifier.SEALED, isSealed);
}
- @override
bool get isValidMixin {
var supertype = this.supertype;
if (supertype != null && !supertype.isDartCoreObject) {
@@ -504,35 +470,6 @@
builder.writeClassElement(this);
}
- @Deprecated('Use ClassElement2 instead')
- @override
- bool isExtendableIn(LibraryElement library) {
- if (library == this.library) {
- return true;
- }
- return !isInterface && !isFinal && !isSealed;
- }
-
- @Deprecated('Use ClassElement2 instead')
- @override
- bool isImplementableIn(LibraryElement library) {
- if (library == this.library) {
- return true;
- }
- return !isBase && !isFinal && !isSealed;
- }
-
- @Deprecated('Use ClassElement2 instead')
- @override
- bool isMixableIn(LibraryElement library) {
- if (library == this.library) {
- return true;
- } else if (this.library.featureSet.isEnabled(Feature.class_modifiers)) {
- return isMixinClass && !isInterface && !isFinal && !isSealed;
- }
- return true;
- }
-
@override
void _buildMixinAppConstructors() {
// Do nothing if not a mixin application.
@@ -1053,7 +990,6 @@
];
}
- @override
List<ClassElementImpl> get classes {
return _classes;
}
@@ -1367,16 +1303,6 @@
builder.writeCompilationUnitElement(this);
}
- @override
- ClassElementImpl? getClass(String className) {
- for (var class_ in classes) {
- if (class_.name == className) {
- return class_;
- }
- }
- return null;
- }
-
@Deprecated(elementModelDeprecationMsg)
@override
EnumElement? getEnum(String name) {
@@ -7609,17 +7535,6 @@
}
@override
- ClassElementImpl? getClass(String name) {
- for (var unitElement in units) {
- var element = unitElement.getClass(name);
- if (element != null) {
- return element;
- }
- }
- return null;
- }
-
- @override
ClassElementImpl2? getClass2(String name) {
return _getElementByName(classes, name);
}
diff --git a/pkg/analyzer/test/src/dart/resolution/constant_test.dart b/pkg/analyzer/test/src/dart/resolution/constant_test.dart
index 9172087..13b3208 100644
--- a/pkg/analyzer/test/src/dart/resolution/constant_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/constant_test.dart
@@ -32,13 +32,14 @@
]);
var aLib = findElement2.import('package:test/a.dart').importedLibrary!;
- var aConstructor = aLib.getClass('A')!.constructors.single;
- var p = aConstructor.parameters.single as DefaultParameterElementImpl;
+ var aConstructor = aLib.getClass2('A')!.constructors2.single;
+ var p = aConstructor.formalParameters.single;
+ var pf = p.firstFragment as DefaultParameterElementImpl;
// To evaluate `const A()` we have to evaluate `{int p}`.
// Even if its value is `null`.
- expect(p.isConstantEvaluated, isTrue);
- expect(p.computeConstantValue()!.isNull, isTrue);
+ expect(pf.isConstantEvaluated, isTrue);
+ expect(pf.computeConstantValue()!.isNull, isTrue);
}
test_constFactoryRedirection_super() async {