Skip to content

Commit f1bf958

Browse files
fshcheglovCommit Queue
authored andcommitted
Move withoutLoadingResolution to a helper class.
Change-Id: Ib21a673bc45a552bb0baa48f6b8d8da711f6dd0d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450948 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent f8e3820 commit f1bf958

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,13 +1002,22 @@ mixin DeferredMembersReadingMixin {
10021002
}
10031003
}
10041004

1005+
class DeferredResolutionReadingHelper {
1006+
static int _lockResolutionLoading = 0;
1007+
1008+
static void withoutLoadingResolution(void Function() operation) {
1009+
_lockResolutionLoading++;
1010+
operation();
1011+
_lockResolutionLoading--;
1012+
}
1013+
}
1014+
10051015
/// This mixin is used to set up loading resolution information from summaries
10061016
/// on demand, and after all elements are loaded, so for example types can
10071017
/// reference them. The summary reader uses [deferReadResolution], and getters
10081018
/// invoke [_ensureReadResolution].
10091019
mixin DeferredResolutionReadingMixin {
10101020
// TODO(scheglov): review whether we need this
1011-
static int _lockResolutionLoading = 0;
10121021
void Function()? _readResolutionCallback;
10131022
void Function()? _applyResolutionConstantOffsets;
10141023

@@ -1023,7 +1032,7 @@ mixin DeferredResolutionReadingMixin {
10231032
}
10241033

10251034
void _ensureReadResolution() {
1026-
if (_lockResolutionLoading > 0) {
1035+
if (DeferredResolutionReadingHelper._lockResolutionLoading > 0) {
10271036
return;
10281037
}
10291038

@@ -1038,12 +1047,6 @@ mixin DeferredResolutionReadingMixin {
10381047
}
10391048
}
10401049
}
1041-
1042-
static void withoutLoadingResolution(void Function() operation) {
1043-
_lockResolutionLoading++;
1044-
operation();
1045-
_lockResolutionLoading--;
1046-
}
10471050
}
10481051

10491052
class DirectiveUriImpl implements DirectiveUri {}
@@ -3547,7 +3550,7 @@ class FormalParameterFragmentImpl extends VariableFragmentImpl
35473550
List<T> fragments, {
35483551
required List<FormalParameterFragmentImpl> Function(T) getFragments,
35493552
}) {
3550-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
3553+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
35513554
var firstFormalParameters = getFragments(fragments.first);
35523555
for (var fragment in firstFormalParameters) {
35533556
switch (fragment) {
@@ -11045,7 +11048,7 @@ class TypeParameterFragmentImpl extends FragmentImpl
1104511048
List<T> fragments, {
1104611049
required List<TypeParameterFragmentImpl> Function(T) getFragments,
1104711050
}) {
11048-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
11051+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
1104911052
var firstFragments = getFragments(fragments.first);
1105011053
for (var i = 0; i < firstFragments.length; i++) {
1105111054
// Side effect: set element for the fragment.

pkg/analyzer/lib/src/summary2/informative_data.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class InformativeDataApplier {
6969
unitElement.setCodeRange(unitInfo.codeOffset, unitInfo.codeLength);
7070
unitElement.lineInfo = LineInfo(unitInfo.lineStarts);
7171

72-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
72+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
7373
_applyToImports(unitElement.libraryImports, unitInfo);
7474
_applyToExports(unitElement.libraryExports, unitInfo);
7575
_applyToPartIncludes(unitElement.parts, unitInfo);
@@ -173,7 +173,7 @@ class InformativeDataApplier {
173173
element.nameOffset = info.nameOffset;
174174
element.documentationComment = info.documentationComment;
175175

176-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
176+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
177177
_applyToFormalParameters(element.formalParameters, info.parameters);
178178
});
179179

@@ -194,7 +194,7 @@ class InformativeDataApplier {
194194
element.nameOffset = info.nameOffset;
195195
element.documentationComment = info.documentationComment;
196196

197-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
197+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
198198
_applyToTypeParameters(element.typeParameters, info.typeParameters);
199199
});
200200

@@ -204,7 +204,7 @@ class InformativeDataApplier {
204204
});
205205

206206
_scheduleApplyMembersOffsets(element, () {
207-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
207+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
208208
_applyToConstructors(element.constructors, info.constructors);
209209
_applyToFields(element.fields, info.fields);
210210
_applyToAccessors(element.getters, info.getters);
@@ -223,7 +223,7 @@ class InformativeDataApplier {
223223
element.nameOffset = info.nameOffset;
224224
element.documentationComment = info.documentationComment;
225225

226-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
226+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
227227
_applyToTypeParameters(element.typeParameters, info.typeParameters);
228228
});
229229

@@ -266,7 +266,7 @@ class InformativeDataApplier {
266266
element.nameOffset = info.nameOffset;
267267
element.documentationComment = info.documentationComment;
268268

269-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
269+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
270270
_applyToFormalParameters(element.formalParameters, info.parameters);
271271
});
272272

@@ -287,7 +287,7 @@ class InformativeDataApplier {
287287
element.nameOffset = info.nameOffset;
288288
element.documentationComment = info.documentationComment;
289289

290-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
290+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
291291
_applyToTypeParameters(element.typeParameters, info.typeParameters);
292292
_applyToConstructors(element.constructors, info.constructors);
293293
_applyToFields(element.fields, info.fields);
@@ -318,7 +318,7 @@ class InformativeDataApplier {
318318
element.nameOffset = info.nameOffset;
319319
element.documentationComment = info.documentationComment;
320320

321-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
321+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
322322
_applyToTypeParameters(element.typeParameters, info.typeParameters);
323323
});
324324

@@ -342,7 +342,7 @@ class InformativeDataApplier {
342342
element.nameOffset = info.nameOffset;
343343
element.documentationComment = info.documentationComment;
344344

345-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
345+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
346346
_applyToTypeParameters(element.typeParameters, info.typeParameters);
347347
});
348348

@@ -358,7 +358,7 @@ class InformativeDataApplier {
358358
applier.applyToMetadata(representationField.metadata);
359359
});
360360

361-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
361+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
362362
var primaryConstructor = element.constructors.first;
363363
primaryConstructor.setCodeRange(infoRep.codeOffset, infoRep.codeLength);
364364
primaryConstructor.typeNameOffset = info.nameOffset;
@@ -367,7 +367,7 @@ class InformativeDataApplier {
367367
primaryConstructor.nameOffset = infoRep.constructorNameOffset;
368368
primaryConstructor.nameEnd = infoRep.constructorNameEnd;
369369

370-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
370+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
371371
var representation = primaryConstructor.formalParameters.first;
372372
representation.firstTokenOffset = infoRep.firstTokenOffset;
373373
representation.nameOffset = infoRep.fieldNameOffset;
@@ -431,7 +431,7 @@ class InformativeDataApplier {
431431
element.nameOffset = info.nameOffset;
432432
element.documentationComment = info.documentationComment;
433433

434-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
434+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
435435
_applyToTypeParameters(element.typeParameters, info.typeParameters);
436436
_applyToFormalParameters(element.formalParameters, info.parameters);
437437
});
@@ -452,7 +452,7 @@ class InformativeDataApplier {
452452
element.nameOffset = info.nameOffset;
453453
element.documentationComment = info.documentationComment;
454454

455-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
455+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
456456
_applyToTypeParameters(element.typeParameters, info.typeParameters);
457457
if (element.aliasedElement case GenericFunctionTypeFragmentImpl aliased) {
458458
_applyToFormalParameters(aliased.formalParameters, info.parameters);
@@ -475,7 +475,7 @@ class InformativeDataApplier {
475475
element.nameOffset = info.nameOffset;
476476
element.documentationComment = info.documentationComment;
477477

478-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
478+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
479479
_applyToTypeParameters(element.typeParameters, info.typeParameters);
480480
if (element.aliasedElement case GenericFunctionTypeFragmentImpl aliased) {
481481
_applyToTypeParameters(
@@ -528,7 +528,7 @@ class InformativeDataApplier {
528528
element.nameOffset = info.nameOffset;
529529
element.documentationComment = info.documentationComment;
530530

531-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
531+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
532532
_applyToTypeParameters(element.typeParameters, info.typeParameters);
533533
_applyToFormalParameters(element.formalParameters, info.parameters);
534534
});
@@ -550,7 +550,7 @@ class InformativeDataApplier {
550550
element.nameOffset = info.nameOffset;
551551
element.documentationComment = info.documentationComment;
552552

553-
DeferredResolutionReadingMixin.withoutLoadingResolution(() {
553+
DeferredResolutionReadingHelper.withoutLoadingResolution(() {
554554
_applyToTypeParameters(element.typeParameters, info.typeParameters);
555555
_applyToConstructors(element.constructors, info.constructors);
556556
_applyToFields(element.fields, info.fields);

0 commit comments

Comments
 (0)