Skip to content

Commit

Permalink
[element model] migrate session_helper API
Browse files Browse the repository at this point in the history
Change-Id: Ia2717bb24c83a409e853fb5271a3d5ed91cd3306
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402142
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
pq committed Dec 20, 2024
1 parent 9f3e0cf commit 8a08c1b
Show file tree
Hide file tree
Showing 35 changed files with 107 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class DocumentColorPresentationHandler
var editRange = SourceRange(editStart, editEnd - editStart);

var sessionHelper = AnalysisSessionHelper(unit.session);
var colorType = await sessionHelper.getFlutterClass2('Color');
var colorType = await sessionHelper.getFlutterClass('Color');
if (colorType == null) {
// If we can't find the class (perhaps because this isn't a Flutter
// project) we will not include any results. In theory the client should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AddEnumConstant extends ResolvedCorrectionProducer {
if (targetElement.library2.isInSdk) return;

var targetFragment = targetElement.firstFragment;
var targetDeclarationResult = await sessionHelper.getElementDeclaration2(
var targetDeclarationResult = await sessionHelper.getElementDeclaration(
targetFragment,
);
if (targetDeclarationResult == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class AddKeyToConstructors extends ResolvedCorrectionProducer {

/// Return the type for the class `Key`.
Future<DartType?> _getKeyType() async {
var keyClass = await sessionHelper.getFlutterClass2('Key');
var keyClass = await sessionHelper.getFlutterClass('Key');
if (keyClass == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AddLate extends ResolvedCorrectionProducer {
!variableElement.isLate &&
variableElement.setter2 == null) {
var variableFragment = variableElement.firstFragment;
var declarationResult = await sessionHelper.getElementDeclaration2(
var declarationResult = await sessionHelper.getElementDeclaration(
variableFragment,
);
if (declarationResult == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CreateConstructor extends ResolvedCorrectionProducer {
// prepare target ClassDeclaration
var targetElement = targetType.element3;
var targetFragment = targetElement.firstFragment;
var targetResult = await sessionHelper.getElementDeclaration2(
var targetResult = await sessionHelper.getElementDeclaration(
targetFragment,
);
if (targetResult == null) {
Expand Down Expand Up @@ -130,9 +130,7 @@ class CreateConstructor extends ResolvedCorrectionProducer {
}

// prepare target interface type
var targetResult = await sessionHelper.getElementDeclaration2(
targetElement,
);
var targetResult = await sessionHelper.getElementDeclaration(targetElement);
if (targetResult == null) {
return;
}
Expand Down Expand Up @@ -185,7 +183,7 @@ class CreateConstructor extends ResolvedCorrectionProducer {
}

// prepare target ClassDeclaration
var targetResult = await sessionHelper.getElementDeclaration2(
var targetResult = await sessionHelper.getElementDeclaration(
targetFragment,
);
if (targetResult == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class CreateConstructorForFinalFields extends ResolvedCorrectionProducer {
required _FixContext fixContext,
required NamedCompilationUnitMember classDeclaration,
}) async {
var keyClass = await sessionHelper.getFlutterClass2('Key');
var keyClass = await sessionHelper.getFlutterClass('Key');
if (keyClass == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CreateField extends CreateFieldOrGetter {
}
// Prepare target `ClassDeclaration`.
var targetFragment = targetElement.firstFragment;
var targetDeclarationResult = await sessionHelper.getElementDeclaration2(
var targetDeclarationResult = await sessionHelper.getElementDeclaration(
targetFragment,
);
if (targetDeclarationResult == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class CreateGetter extends CreateFieldOrGetter {
return;
}
// prepare target declaration
var targetDeclarationResult = await sessionHelper.getElementDeclaration2(
var targetDeclarationResult = await sessionHelper.getElementDeclaration(
targetFragment,
);
if (targetDeclarationResult == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ class CreateMethod extends ResolvedCorrectionProducer {
if (target is ExtensionOverride) {
targetFragment = target.element2.firstFragment;
if (targetFragment is ExtensionFragment) {
targetNode = await getExtensionDeclaration2(targetFragment);
targetNode = await getExtensionDeclaration(targetFragment);
if (targetNode == null) {
return;
}
}
} else if (target is Identifier && target.element is ExtensionElement2) {
targetFragment = (target.element as ExtensionElement2).firstFragment;
if (targetFragment is ExtensionFragment) {
targetNode = await getExtensionDeclaration2(targetFragment);
targetNode = await getExtensionDeclaration(targetFragment);
if (targetNode == null) {
return;
}
Expand Down Expand Up @@ -144,13 +144,13 @@ class CreateMethod extends ResolvedCorrectionProducer {
// Prepare target ClassDeclaration.
if (targetClassElement is MixinElement2) {
var fragment = targetClassElement.firstFragment;
targetNode = await getMixinDeclaration2(fragment);
targetNode = await getMixinDeclaration(fragment);
} else if (targetClassElement is ClassElement2) {
var fragment = targetClassElement.firstFragment;
targetNode = await getClassDeclaration2(fragment);
targetNode = await getClassDeclaration(fragment);
} else if (targetClassElement is ExtensionTypeElement2) {
var fragment = targetClassElement.firstFragment;
targetNode = await getExtensionTypeDeclaration2(fragment);
targetNode = await getExtensionTypeDeclaration(fragment);
}
if (targetNode == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ class CreateMethodOrFunction extends ResolvedCorrectionProducer {
List<ClassMember>? classMembers;
if (targetClassElement is MixinElement2) {
var fragment = targetClassElement.firstFragment;
var node = targetNode = await getMixinDeclaration2(fragment);
var node = targetNode = await getMixinDeclaration(fragment);
classMembers = node?.members;
} else if (targetClassElement is ClassElement2) {
var fragment = targetClassElement.firstFragment;
var node = targetNode = await getClassDeclaration2(fragment);
var node = targetNode = await getClassDeclaration(fragment);
classMembers = node?.members;
}
if (targetNode == null || classMembers == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CreateSetter extends ResolvedCorrectionProducer {
return;
}
// prepare target declaration
var targetDeclarationResult = await sessionHelper.getElementDeclaration2(
var targetDeclarationResult = await sessionHelper.getElementDeclaration(
targetFragment,
);
if (targetDeclarationResult == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ class FlutterConvertToStatefulWidget extends ResolvedCorrectionProducer {
return SourceEdit.applySequence(text, visitor.edits.reversed);
}

var statefulWidgetClass = await sessionHelper.getFlutterClass2(
var statefulWidgetClass = await sessionHelper.getFlutterClass(
'StatefulWidget',
);
var stateClass = await sessionHelper.getFlutterClass2('State');
var stateClass = await sessionHelper.getFlutterClass('State');
if (statefulWidgetClass == null || stateClass == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class FlutterConvertToStatelessWidget extends ResolvedCorrectionProducer {
return SourceEdit.applySequence(text, visitor.edits.reversed);
}

var statelessWidgetClass = await sessionHelper.getFlutterClass2(
var statelessWidgetClass = await sessionHelper.getFlutterClass(
'StatelessWidget',
);
if (statelessWidgetClass == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ abstract class _WrapMultipleWidgets extends ResolvedCorrectionProducer {
Future<void> compute(ChangeBuilder builder) async {
var selectedRange = range.startEnd(firstWidget, lastWidget);
var src = utils.getRangeText(selectedRange);
var parentClassElement = await sessionHelper.getClass2(
var parentClassElement = await sessionHelper.getClass(
_parentLibraryUri,
_parentClassName,
);
var widgetClassElement = await sessionHelper.getFlutterClass2('Widget');
var widgetClassElement = await sessionHelper.getFlutterClass('Widget');
if (parentClassElement == null || widgetClassElement == null) {
return;
}
Expand Down Expand Up @@ -341,7 +341,7 @@ abstract class _WrapSingleWidget extends ResolvedCorrectionProducer {
var parentClassName = _parentClassName;
ClassElement2? parentClassElement;
if (parentLibraryUri != null && parentClassName != null) {
parentClassElement = await sessionHelper.getClass2(
parentClassElement = await sessionHelper.getClass(
parentLibraryUri,
parentClassName,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FlutterWrapBuilder extends ResolvedCorrectionProducer {
}
var widgetSrc = utils.getNodeText(widgetExpr);

var builderElement = await sessionHelper.getFlutterClass2('Builder');
var builderElement = await sessionHelper.getFlutterClass('Builder');
if (builderElement == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FlutterWrapStreamBuilder extends ResolvedCorrectionProducer {
}
var widgetSrc = utils.getNodeText(widgetExpr);

var streamBuilderElement = await sessionHelper.getFlutterClass2(
var streamBuilderElement = await sessionHelper.getFlutterClass(
'StreamBuilder',
);
if (streamBuilderElement == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MakeFieldNotFinal extends ResolvedCorrectionProducer {
return;
}

var declaration = await sessionHelper.getElementDeclaration2(
var declaration = await sessionHelper.getElementDeclaration(
variable.firstFragment,
);
var variableNode = declaration?.node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ExecutableParameters {
/// Return the [FormalParameterList] of the [executable], or `null` if it
/// can't be found.
Future<FormalParameterList?> getParameterList() async {
var result = await sessionHelper.getElementDeclaration2(firstFragment);
var result = await sessionHelper.getElementDeclaration(firstFragment);
var targetDeclaration = result?.node;
if (targetDeclaration is ConstructorDeclaration) {
return targetDeclaration.parameters;
Expand All @@ -61,7 +61,7 @@ class ExecutableParameters {
Future<FormalParameter?> getParameterNode2(
FormalParameterFragment fragment,
) async {
var result = await sessionHelper.getElementDeclaration2(fragment);
var result = await sessionHelper.getElementDeclaration(fragment);
var declaration = result?.node;
for (var node = declaration; node != null; node = node.parent) {
if (node is FormalParameter && node.parent is FormalParameterList) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/analysis_server/lib/src/services/flutter/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ class PropertyDescription {
var enumValue = value.enumValue;
if (enumValue != null) {
var helper = AnalysisSessionHelper(resolvedUnit.session);
enumElement = await helper.getClass2(
enumElement = await helper.getClass(
enumValue.libraryUri,
enumValue.className,
);
enumElement ??= await helper.getEnum2(
enumElement ??= await helper.getEnum(
enumValue.libraryUri,
enumValue.className,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,12 @@ class _WidgetDescriptionComputer {

Future<void> _fetchClassElements() async {
var sessionHelper = AnalysisSessionHelper(resolvedUnit.session);
_classAlignment = await sessionHelper.getFlutterClass2('Alignment');
_classAlignmentDirectional = await sessionHelper.getFlutterClass2(
_classAlignment = await sessionHelper.getFlutterClass('Alignment');
_classAlignmentDirectional = await sessionHelper.getFlutterClass(
'AlignmentDirectional',
);
_classContainer = await sessionHelper.getFlutterClass2('Container');
_classEdgeInsets = await sessionHelper.getFlutterClass2('EdgeInsets');
_classContainer = await sessionHelper.getFlutterClass('Container');
_classEdgeInsets = await sessionHelper.getFlutterClass('EdgeInsets');
}

protocol.FlutterWidgetPropertyEditor? _getEditor(DartType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class _SelectionAnalyzer {

Future<AstNode?> _elementDeclaration(ExecutableElement2 element) async {
var helper = refactoringContext.sessionHelper;
var nodeResult = await helper.getElementDeclaration2(element.firstFragment);
var nodeResult = await helper.getElementDeclaration(element.firstFragment);
return nodeResult?.node;
}
}
Expand Down Expand Up @@ -668,7 +668,7 @@ class _SignatureUpdater {
/// Returns the [MethodDeclaration] for a [MethodElement2].
Future<AstNode?> elementDeclaration(ExecutableElement2 element) async {
var helper = sessionHelper;
var result = await helper.getElementDeclaration2(element.firstFragment);
var result = await helper.getElementDeclaration(element.firstFragment);
return result?.node;
}

Expand All @@ -685,7 +685,7 @@ class _SignatureUpdater {
/// Returns the resolved unit with [reference].
Future<ResolvedUnitResult?> referenceUnitResult(SearchMatch reference) async {
var element = reference.element2;
return await sessionHelper.getResolvedUnitByElement2(element);
return await sessionHelper.getResolvedUnitByElement(element);
}

/// Replaces [argumentList] with new code that has arguments as requested
Expand Down Expand Up @@ -745,7 +745,7 @@ class _SignatureUpdater {
}) async {
var path = element.firstFragment.libraryFragment.source.fullName;

var unitResult = await sessionHelper.getResolvedUnitByElement2(element);
var unitResult = await sessionHelper.getResolvedUnitByElement(element);
if (unitResult == null) {
return ChangeStatusFailure();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ConvertGetterToMethodRefactoringImpl extends RefactoringImpl
return;
}
var sessionHelper = AnalysisSessionHelper(session);
var result = await sessionHelper.getElementDeclaration2(fragment);
var result = await sessionHelper.getElementDeclaration(fragment);
var declaration = result?.node;
if (declaration is MethodDeclaration) {
getKeyword = declaration.propertyKeyword;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl
fragment != null;
fragment = fragment.nextFragment as GetterFragment?
) {
var result = await sessionHelper.getElementDeclaration2(fragment);
var result = await sessionHelper.getElementDeclaration(fragment);
var declaration = result?.node;
if (declaration is MethodDeclaration) {
parameters = declaration.parameters;
Expand Down Expand Up @@ -148,7 +148,7 @@ class ConvertMethodToGetterRefactoringImpl extends RefactoringImpl
var refRange = reference.range;
// prepare invocation

var resolvedUnit = await sessionHelper.getResolvedUnitByElement2(
var resolvedUnit = await sessionHelper.getResolvedUnitByElement(
refElement,
);
var refUnit = resolvedUnit?.unit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class ExtractWidgetRefactoringImpl extends RefactoringImpl
var result = RefactoringStatus();

Future<ClassElement2?> getClass(String name) async {
var element = await sessionHelper.getFlutterClass2(name);
var element = await sessionHelper.getFlutterClass(name);
if (element == null) {
result.addFatalError("Unable to find '$name' in $widgetsUri");
}
Expand All @@ -259,7 +259,7 @@ class ExtractWidgetRefactoringImpl extends RefactoringImpl
String uri,
String name,
) async {
var element = await sessionHelper.getTopLevelPropertyAccessor2(uri, name);
var element = await sessionHelper.getTopLevelPropertyAccessor(uri, name);
if (element == null) {
result.addFatalError("Unable to find 'required' in $uri");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class InlineLocalRefactoringImpl extends RefactoringImpl
}

var helper = AnalysisSessionHelper(resolveResult.session);
var declarationResult = await helper.getElementDeclaration2(
var declarationResult = await helper.getElementDeclaration(
element.firstFragment,
);
var node = declarationResult?.node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class InlineMethodRefactoringImpl extends RefactoringImpl
}
_methodElement = element;

var declaration = await sessionHelper.getElementDeclaration2(
var declaration = await sessionHelper.getElementDeclaration(
element.firstFragment,
);
var methodNode = declaration!.node;
Expand Down Expand Up @@ -512,7 +512,7 @@ class _ReferenceProcessor {
refElement = reference.element2;

// prepare CorrectionUtils
var result = await ref.sessionHelper.getResolvedUnitByElement2(refElement);
var result = await ref.sessionHelper.getResolvedUnitByElement(refElement);
_refUtils = CorrectionUtils(result!);

// prepare node and environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class RenameClassMemberRefactoringImpl extends RenameRefactoringImpl {
) async {
FieldFormalParameterFragment? fragment = element.firstFragment;
while (fragment != null) {
var result = await sessionHelper.getElementDeclaration2(fragment);
var result = await sessionHelper.getElementDeclaration(fragment);
var node = result?.node;
if (node is! DefaultFormalParameter) return;
var parameter = node.parameter as FieldFormalParameter;
Expand Down Expand Up @@ -439,7 +439,7 @@ class _RenameClassMemberValidator extends _BaseClassMemberValidator {
var localElements = localElementMap[unitFragment];

if (localElements == null) {
var result = await sessionHelper.getResolvedUnitByElement2(element);
var result = await sessionHelper.getResolvedUnitByElement(element);
if (result == null) {
return const [];
}
Expand Down
Loading

0 comments on commit 8a08c1b

Please sign in to comment.