Skip to content

Commit

Permalink
Elements. Remove Fragment.name/nameOffset, use name2 instead.
Browse files Browse the repository at this point in the history
Change-Id: I36ab124af49c0bd8b85c8ede9c3918dbfdc518a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390812
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Oct 18, 2024
1 parent 6811e7f commit d230290
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ abstract class AbstractCodeLensProvider
/// If for any reason the location cannot be computed, returns `null`.
Location? getLocation(Fragment fragment) {
// We can't produce a location to a name if there isn't one.
var nameOffset = fragment.nameOffset;
var nameOffset = fragment.name2?.nameOffset;
var nameLength = fragment.element.displayName.length;
if (nameOffset == null || nameOffset == -1) {
if (nameOffset == null) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class AugmentationCodeLensProvider extends AbstractCodeLensProvider {
) {
var command =
getNavigationCommand(clientCapabilities, title, targetFragment);
var nameOffset = thisFragment.nameOffset;
var nameOffset = thisFragment.name2?.nameOffset;
var nameLength = thisFragment.element.displayName.length;
if (command != null && nameOffset != null && nameOffset != -1) {
if (command != null && nameOffset != null) {
var range = toRange(
result.lineInfo,
nameOffset,
Expand Down
4 changes: 2 additions & 2 deletions pkg/analysis_server/lib/src/protocol_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ Location? newLocation_fromElement2(engine.Element2? element) {
if (fragment == null) {
return null;
}
var offset = fragment.nameOffset ?? 0;
var length = fragment.name?.length ?? 0;
var offset = fragment.name2?.nameOffset ?? 0;
var length = fragment.name2?.name.length ?? 0;
var range = engine.SourceRange(offset, length);
return _locationForArgs2(fragment, range);
} else if (element is engine.LocalFunctionElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class AddFieldFormalParameters extends ResolvedCorrectionProducer {
// Compute uninitialized final fields.
var fields = ErrorVerifier.computeNotInitializedFields2(constructor);
fields.retainWhere((FieldElement2 field) => field.isFinal);
fields.sort(
(a, b) => a.firstFragment!.nameOffset! - b.firstFragment!.nameOffset!);
fields.sort((a, b) =>
a.firstFragment!.name2!.nameOffset -
b.firstFragment!.name2!.nameOffset);

// Specialize for Flutter widgets.
if (superType.isExactlyStatelessWidgetType ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,33 @@ class ReplaceReturnType extends ResolvedCorrectionProducer {

bool _isCompatibleWithReturnType(
MethodDeclaration method, DartType? newType) {
if (newType != null) {
var clazz = method.thisOrAncestorOfType<ClassDeclaration>();
if (clazz != null) {
var classElement = clazz.declaredFragment!.element;
var overriddenList = InheritanceManager3().getOverridden4(
classElement,
Name.forLibrary(
classElement.library2,
method.declaredFragment!.name!,
));

if (overriddenList != null) {
var notSubtype = overriddenList.any((element) => !libraryElement2
.typeSystem
.isSubtypeOf(newType, element.returnType));
if (notSubtype) {
return false;
}
}
if (newType == null) {
return false;
}

var clazz = method.thisOrAncestorOfType<ClassDeclaration>();
if (clazz == null) {
return false;
}

var methodName = method.declaredFragment!.name2;
if (methodName == null) {
return false;
}

var classElement = clazz.declaredFragment!.element;
var overriddenList = InheritanceManager3().getOverridden4(
classElement,
Name.forLibrary(classElement.library2, methodName.name),
);

if (overriddenList != null) {
var notSubtype = overriddenList.any((element) =>
!libraryElement2.typeSystem.isSubtypeOf(newType, element.returnType));
if (notSubtype) {
return false;
}
return true;
}
return false;
return true;
}
}
39 changes: 1 addition & 38 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,6 @@ abstract class Fragment {
/// This will be the fragment itself if it is a library fragment.
LibraryFragment get libraryFragment;

/// The name of this fragment.
///
/// Returns `null` if this fragment doesn't have a name.
String? get name;

/// The name of this fragment.
///
/// Returns `null` if the fragment does not have a name, e.g. an unnamed
Expand All @@ -876,11 +871,6 @@ abstract class Fragment {
/// specified, and the parser inserted a synthetic identifier.
FragmentName? get name2;

/// The offset of the name in this fragment.
///
/// Returns `null` if the fragment has no name.
int? get nameOffset;

/// The next fragment in the augmentation chain.
///
/// Returns `null` if this is the last fragment in the chain.
Expand Down Expand Up @@ -1017,9 +1007,6 @@ abstract class GetterFragment implements ExecutableFragment {
// @override
// GetterElement get element;

@override
String? get name;

/// The field or top-level variable associated with this getter.
///
/// If this getter was explicitly defined (is not synthetic) then the variable
Expand Down Expand Up @@ -1185,9 +1172,6 @@ abstract class InterfaceFragment implements InstanceFragment {
/// [MixinFragment] cannot have mixins, so the empty list is returned.
List<InterfaceType> get mixins;

@override
String get name;

/// The superclass declared by this fragment.
InterfaceType? get supertype;
}
Expand Down Expand Up @@ -1681,9 +1665,6 @@ abstract class MethodFragment implements ExecutableFragment {
@override
InstanceFragment? get enclosingFragment;

@override
String get name;

@override
MethodFragment? get nextFragment;

Expand Down Expand Up @@ -1781,7 +1762,7 @@ abstract class PrefixElement2 implements Element2, FragmentedElement {
LibraryElement2 get library2;

@override
String get name;
String? get name;

/// The name lookup scope for this import prefix.
///
Expand All @@ -1804,9 +1785,6 @@ abstract class PrefixFragment implements Fragment {
/// Whether the [LibraryImport] is deferred.
bool get isDeferred;

@override
String get name;

@override
PrefixFragment? get nextFragment;

Expand All @@ -1829,9 +1807,6 @@ abstract class PromotableElement2 implements VariableElement2 {
abstract class PromotableFragment implements VariableFragment {
@override
PromotableElement2 get element;

@override
String get name;
}

/// A variable that has an associated getter and possibly a setter. Note that
Expand Down Expand Up @@ -1916,9 +1891,6 @@ abstract class PropertyInducingFragment
// TODO(brianwilkerson): Should synthetic elements have a fragment?
bool get isSynthetic;

@override
String get name;

@override
PropertyInducingFragment? get nextFragment;

Expand Down Expand Up @@ -1978,9 +1950,6 @@ abstract class SetterFragment implements ExecutableFragment {
// @override
// SetterElement get element;

@override
String? get name;

/// The field or top-level variable associated with this setter.
///
/// If this setter was explicitly defined (is not synthetic) then the variable
Expand Down Expand Up @@ -2130,9 +2099,6 @@ abstract class TypeAliasFragment
@override
LibraryFragment? get enclosingFragment;

@override
String get name;

@override
TypeAliasFragment? get nextFragment;

Expand Down Expand Up @@ -2195,9 +2161,6 @@ abstract class TypeParameterFragment implements TypeDefiningFragment {
@override
TypeParameterElement2 get element;

@override
String get name;

@override
TypeParameterFragment? get nextFragment;

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 401;
static const int DATA_VERSION = 402;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
12 changes: 2 additions & 10 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9017,7 +9017,7 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement {

PrefixElementImpl2 get element2 {
return enclosingElement3.prefixes.firstWhere((element) {
return element.name == name;
return (element.name ?? '') == name;
});
}

Expand Down Expand Up @@ -9118,7 +9118,7 @@ class PrefixElementImpl2 extends ElementImpl2 implements PrefixElement2 {
}

@override
String get name => firstFragment.name;
String? get name => firstFragment.name2?.name;

@override
// TODO(scheglov): implement scope
Expand Down Expand Up @@ -9156,12 +9156,6 @@ class PrefixFragmentImpl implements PrefixFragment {
@override
final CompilationUnitElementImpl enclosingFragment;

@override
final String name;

@override
int nameOffset;

@override
FragmentNameImpl? name2;

Expand All @@ -9179,8 +9173,6 @@ class PrefixFragmentImpl implements PrefixFragment {

PrefixFragmentImpl({
required this.enclosingFragment,
required this.name,
required this.nameOffset,
required this.name2,
required this.isDeferred,
});
Expand Down
3 changes: 0 additions & 3 deletions pkg/analyzer/lib/src/summary2/bundle_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1324,12 +1324,9 @@ class LibraryReader {
return _reader.readOptionalObject((reader) {
var fragmentName = _readFragmentName();
var reference = _readReference();
var name = _reader.readStringReference();
var isDeferred = _reader.readBool();
var fragment = PrefixFragmentImpl(
enclosingFragment: libraryFragment,
name: name,
nameOffset: -1,
name2: fragmentName,
isDeferred: isDeferred,
);
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/summary2/bundle_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ class BundleWriter {
_sink.writeOptionalObject(fragment, (fragment) {
_writeFragmentName(fragment.name2);
_writeReference2(fragment.element.reference);
_sink._writeStringReference(fragment.name);
_sink.writeBool(fragment.isDeferred);
});
}
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/lib/src/summary2/informative_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,6 @@ class InformativeDataApplier {
}

if (element.prefix2 case var prefixFragment?) {
prefixFragment.nameOffset = info.prefixOffset;
if (prefixFragment.name2 case var name?) {
name.nameOffset = info.prefixOffset;
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,6 @@ class LibraryBuilder with MacroApplicationsContainer {

var fragment = PrefixFragmentImpl(
enclosingFragment: libraryFragment,
name: unlinkedName?.name ?? '',
nameOffset: unlinkedName?.nameOffset ?? -1,
name2: fragmentName,
isDeferred: isDeferred,
);
Expand Down
Loading

0 comments on commit d230290

Please sign in to comment.