Use FooImpl in BarImpl getters/setters, property related.

I think we might get away with this now, because we don't let users
create elements manually.

Presubmit in google3 looks green.
https://fusion2.corp.google.com/presubmit/tap/483535261/OCL:483535261:BASE:483575659:1666678949553:5d26313d/targets

Change-Id: Id9618e2d8a15ab98c5919750461c508e87f76c7b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265405
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2022-10-26 03:49:43 +00:00 committed by Commit Queue
parent 5f063cb155
commit 9f35115b90
11 changed files with 57 additions and 56 deletions

View file

@ -177,10 +177,7 @@ class DefinitionHandler extends MessageHandler<TextDocumentPositionParams,
// For synthetic getters created for fields, we need to access the associated
// variable to get the codeOffset/codeLength.
if (codeElement.isSynthetic && codeElement is PropertyAccessorElementImpl) {
final variable = codeElement.variable;
if (variable is ElementImpl) {
codeElement = variable as ElementImpl;
}
codeElement = codeElement.variable;
}
// Read the main codeOffset from the element. This may include doc comments

View file

@ -74,7 +74,7 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl
List<PropertyAccessorElement> _accessors = _Sentinel.propertyAccessorElement;
/// A list containing all of the fields contained in this class.
List<FieldElement> _fields = _Sentinel.fieldElement;
List<FieldElementImpl> _fields = _Sentinel.fieldElement;
/// A list containing all of the methods contained in this class.
List<MethodElement> _methods = _Sentinel.methodElement;
@ -122,10 +122,13 @@ abstract class AbstractClassElementImpl extends _ExistingElementImpl
@override
CompilationUnitElementImpl get enclosingElement3 => enclosingElement;
@override
List<FieldElementImpl> get fields;
/// Set the fields contained in this class to the given [fields].
set fields(List<FieldElement> fields) {
for (FieldElement field in fields) {
(field as FieldElementImpl).enclosingElement = this;
set fields(List<FieldElementImpl> fields) {
for (var field in fields) {
field.enclosingElement = this;
}
_fields = fields;
}
@ -609,7 +612,7 @@ class ClassElementImpl extends ClassOrMixinElementImpl implements ClassElement {
}
@override
set fields(List<FieldElement> fields) {
set fields(List<FieldElementImpl> fields) {
assert(!isMixinApplication);
super.fields = fields;
}
@ -968,7 +971,7 @@ abstract class ClassOrMixinElementImpl extends AbstractClassElementImpl {
}
@override
List<FieldElement> get fields {
List<FieldElementImpl> get fields {
if (!identical(_fields, _Sentinel.fieldElement)) {
return _fields;
}
@ -1099,7 +1102,7 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
List<TypeAliasElement> _typeAliases = const [];
/// A list containing all of the variables contained in this compilation unit.
List<TopLevelVariableElement> _variables = const [];
List<TopLevelVariableElementImpl> _variables = const [];
ElementLinkedData? linkedData;
@ -1255,15 +1258,15 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
AnalysisSession get session => enclosingElement.session;
@override
List<TopLevelVariableElement> get topLevelVariables {
List<TopLevelVariableElementImpl> get topLevelVariables {
return _variables;
}
/// Set the top-level variables contained in this compilation unit to the
/// given[variables].
set topLevelVariables(List<TopLevelVariableElement> variables) {
for (TopLevelVariableElement field in variables) {
(field as TopLevelVariableElementImpl).enclosingElement = this;
set topLevelVariables(List<TopLevelVariableElementImpl> variables) {
for (var variable in variables) {
variable.enclosingElement = this;
}
_variables = variables;
}
@ -2947,7 +2950,7 @@ class EnumElementImpl extends AbstractClassElementImpl implements EnumElement {
}
@override
List<FieldElement> get fields {
List<FieldElementImpl> get fields {
return _fields;
}
@ -3242,7 +3245,7 @@ class ExtensionElementImpl extends _ExistingElementImpl
List<PropertyAccessorElement> _accessors = const [];
/// A list containing all of the fields contained in this extension.
List<FieldElement> _fields = const [];
List<FieldElementImpl> _fields = const [];
/// A list containing all of the methods contained in this extension.
List<MethodElement> _methods = const [];
@ -3303,13 +3306,13 @@ class ExtensionElementImpl extends _ExistingElementImpl
}
@override
List<FieldElement> get fields {
List<FieldElementImpl> get fields {
return _fields;
}
set fields(List<FieldElement> fields) {
for (FieldElement field in fields) {
(field as FieldElementImpl).enclosingElement = this;
set fields(List<FieldElementImpl> fields) {
for (var field in fields) {
field.enclosingElement = this;
}
_fields = fields;
}
@ -5506,7 +5509,7 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl
implements PropertyAccessorElement {
/// The variable associated with this accessor.
@override
late PropertyInducingElement variable;
late PropertyInducingElementImpl variable;
/// If this method is a synthetic element which is based on another method
/// with some modifications (such as making some parameters covariant),
@ -5632,7 +5635,7 @@ class PropertyAccessorElementImpl_ImplicitGetter
}
@override
Element get enclosingElement => variable.enclosingElement!;
Element get enclosingElement => variable.enclosingElement;
@Deprecated('Use enclosingElement instead')
@override
@ -5697,7 +5700,7 @@ class PropertyAccessorElementImpl_ImplicitSetter
}
@override
Element get enclosingElement => variable.enclosingElement!;
Element get enclosingElement => variable.enclosingElement;
@Deprecated('Use enclosingElement instead')
@override
@ -5760,13 +5763,13 @@ abstract class PropertyInducingElementImpl
extends NonParameterVariableElementImpl implements PropertyInducingElement {
/// The getter associated with this element.
@override
PropertyAccessorElement? getter;
PropertyAccessorElementImpl? getter;
/// The setter associated with this element, or `null` if the element is
/// effectively `final` and therefore does not have a setter associated with
/// it.
@override
PropertyAccessorElement? setter;
PropertyAccessorElementImpl? setter;
/// This field is set during linking, and performs type inference for
/// this property. After linking this field is always `null`.
@ -6554,7 +6557,7 @@ class _Sentinel {
List.unmodifiable([]);
static final List<ConstructorElement> constructorElement =
List.unmodifiable([]);
static final List<FieldElement> fieldElement = List.unmodifiable([]);
static final List<FieldElementImpl> fieldElement = List.unmodifiable([]);
static final List<LibraryExportElement> libraryExportElement =
List.unmodifiable([]);
static final List<LibraryImportElement> libraryImportElement =

View file

@ -779,7 +779,7 @@ class InheritanceManager3 {
return result;
}
if (executable is PropertyAccessorElement) {
if (executable is PropertyAccessorElementImpl) {
assert(executable.isSetter);
var result = PropertyAccessorElementImpl(executable.name, -1);
result.enclosingElement = class_;

View file

@ -630,7 +630,7 @@ class LibraryReader {
Reference reference,
) {
var accessors = <PropertyAccessorElementImpl>[];
var fields = <FieldElement>[];
var fields = <FieldElementImpl>[];
_readFields(unitElement, element, reference, accessors, fields);
_readPropertyAccessors(
unitElement, element, reference, accessors, fields, '@field');
@ -783,7 +783,7 @@ class LibraryReader {
element.typeParameters = _readTypeParameters();
var accessors = <PropertyAccessorElement>[];
var fields = <FieldElement>[];
var fields = <FieldElementImpl>[];
_readFields(unitElement, element, reference, accessors, fields);
_readPropertyAccessors(
@ -869,7 +869,7 @@ class LibraryReader {
element.typeParameters = _readTypeParameters();
var accessors = <PropertyAccessorElement>[];
var fields = <FieldElement>[];
var fields = <FieldElementImpl>[];
_readPropertyAccessors(
unitElement, element, reference, accessors, fields, '@field');
_readFields(unitElement, element, reference, accessors, fields);
@ -1127,7 +1127,7 @@ class LibraryReader {
element.typeParameters = _readTypeParameters();
var fields = <FieldElement>[];
var fields = <FieldElementImpl>[];
var accessors = <PropertyAccessorElement>[];
_readFields(unitElement, element, reference, accessors, fields);
_readPropertyAccessors(

View file

@ -242,8 +242,7 @@ class BundleWriter {
_writeList(
element.fields.where((e) {
return !e.isSynthetic ||
e is FieldElementImpl && e.isSyntheticEnumField;
return !e.isSynthetic || e.isSyntheticEnumField;
}).toList(),
_writeFieldElement,
);

View file

@ -434,7 +434,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
_visitPropertyFirst<FieldDeclaration>(node.members);
});
element.accessors = holder.propertyAccessors;
element.fields = holder.properties.whereType<FieldElement>().toList();
element.fields = holder.properties.whereType<FieldElementImpl>().toList();
element.methods = holder.methods;
}
@ -1140,7 +1140,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
element.accessors = holder.propertyAccessors;
element.constructors = holder.constructors;
element.fields = holder.properties.whereType<FieldElement>().toList();
element.fields = holder.properties.whereType<FieldElementImpl>().toList();
element.methods = holder.methods;
_resolveConstructorFieldFormals(element);
@ -1179,7 +1179,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
element.accessors = holder.propertyAccessors;
element.constructors = holder.constructors;
element.fields = holder.properties.whereType<FieldElement>().toList();
element.fields = holder.properties.whereType<FieldElementImpl>().toList();
element.methods = holder.methods;
_resolveConstructorFieldFormals(element);

View file

@ -273,6 +273,7 @@ class LibraryBuilder {
// Transplant built elements as if the augmentation was applied.
final augmentedUnitElement = element.definingCompilationUnit;
for (final augmentation in unitElement.classes) {
augmentation as ClassElementImpl;
// TODO(scheglov) if augmentation
final augmented = element.getClass(augmentation.name);
if (augmented is ClassElementImpl) {

View file

@ -327,7 +327,7 @@ class InstanceMemberInferrer {
currentInterfaceElement = classElement;
for (var field in classElement.fields) {
_inferAccessorOrField(
field: field as FieldElementImpl,
field: field,
);
}
for (var accessor in classElement.accessors) {

View file

@ -138,7 +138,7 @@ class _MockSdkElementsBuilder {
_deprecatedElement = deprecatedElement = _class(name: 'Deprecated');
deprecatedElement.supertype = objectType;
deprecatedElement.fields = <FieldElement>[
deprecatedElement.fields = [
_field('message', stringType, isFinal: true),
];
@ -167,11 +167,11 @@ class _MockSdkElementsBuilder {
);
doubleElement.supertype = numType;
FieldElement staticConstDoubleField(String name) {
FieldElementImpl staticConstDoubleField(String name) {
return _field(name, doubleType, isStatic: true, isConst: true);
}
doubleElement.fields = <FieldElement>[
doubleElement.fields = <FieldElementImpl>[
staticConstDoubleField('nan'),
staticConstDoubleField('infinity'),
staticConstDoubleField('negativeInfinity'),
@ -969,7 +969,7 @@ class _MockSdkElementsBuilder {
overrideVariable.getter!,
proxyVariable.getter!,
];
coreUnit.topLevelVariables = <TopLevelVariableElement>[
coreUnit.topLevelVariables = <TopLevelVariableElementImpl>[
deprecatedVariable,
overrideVariable,
proxyVariable,
@ -1014,7 +1014,7 @@ class _MockSdkElementsBuilder {
return element;
}
FieldElement _field(
FieldElementImpl _field(
String name,
DartType type, {
bool isConst = false,
@ -1133,11 +1133,14 @@ class _MockSdkElementsBuilder {
classElement.accessors = accessors;
classElement.fields = accessors
.map((accessor) => accessor.variable)
.cast<FieldElement>()
.cast<FieldElementImpl>()
.toList();
}
TopLevelVariableElement _topLevelVariableConst(String name, DartType type) {
TopLevelVariableElementImpl _topLevelVariableConst(
String name,
DartType type,
) {
final variable = ConstTopLevelVariableElementImpl(name, -1)
..isConst = true
..type = type;

View file

@ -40,7 +40,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
String fieldName = "f";
FieldElementImpl field =
ElementFactory.fieldElement(fieldName, false, false, false, intNone);
classA.fields = <FieldElement>[field];
classA.fields = [field];
expect(classA.getField(fieldName), same(field));
expect(field.isEnumConstant, false);
// no such field
@ -65,7 +65,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
void test_hasNonFinalField_false_const() {
var classA = class_(name: 'A');
classA.fields = <FieldElement>[
classA.fields = [
ElementFactory.fieldElement(
"f", false, false, true, interfaceTypeStar(classA))
];
@ -74,7 +74,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
void test_hasNonFinalField_false_final() {
var classA = class_(name: 'A');
classA.fields = <FieldElement>[
classA.fields = [
ElementFactory.fieldElement(
"f", false, true, false, interfaceTypeStar(classA))
];
@ -93,7 +93,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
void test_hasNonFinalField_true_immediate() {
var classA = class_(name: 'A');
classA.fields = <FieldElement>[
classA.fields = [
ElementFactory.fieldElement(
"f", false, false, false, interfaceTypeStar(classA))
];
@ -105,7 +105,7 @@ class ClassElementImplTest extends AbstractTypeSystemTest {
var classA = class_(name: 'A');
ClassElementImpl classB =
ElementFactory.classElement("B", interfaceTypeStar(classA));
classA.fields = <FieldElement>[
classA.fields = [
ElementFactory.fieldElement(
"f", false, false, false, interfaceTypeStar(classA))
];
@ -421,7 +421,7 @@ class ElementImplTest extends AbstractTypeSystemTest {
LibraryElementImpl library = ElementFactory.library(analysisContext, "lib");
ClassElementImpl classElement = ElementFactory.classElement2("C");
(library.definingCompilationUnit).classes = <ClassElement>[classElement];
FieldElement field = ElementFactory.fieldElement(
var field = ElementFactory.fieldElement(
"next",
false,
false,
@ -431,7 +431,7 @@ class ElementImplTest extends AbstractTypeSystemTest {
nullabilitySuffix: NullabilitySuffix.star,
),
);
classElement.fields = <FieldElement>[field];
classElement.fields = [field];
expect(field == field, isTrue);
// ignore: unrelated_type_equality_checks
expect(field == field.getter, isFalse);

View file

@ -11236,16 +11236,14 @@ library
synthetic static get y @-1
returnType: Object
''');
var x = library.definingCompilationUnit.topLevelVariables[0]
as TopLevelVariableElementImpl;
var x = library.definingCompilationUnit.topLevelVariables[0];
var xExpr = x.constantInitializer as InstanceCreationExpression;
var xType = xExpr.constructorName.staticElement!.returnType;
_assertTypeStr(
xType,
'C<int>',
);
var y = library.definingCompilationUnit.topLevelVariables[0]
as TopLevelVariableElementImpl;
var y = library.definingCompilationUnit.topLevelVariables[0];
var yExpr = y.constantInitializer as InstanceCreationExpression;
var yType = yExpr.constructorName.staticElement!.returnType;
_assertTypeStr(yType, 'C<int>');