Skip to content

Commit 69fef4b

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Use impl types in a few places to avoid casts.
Change-Id: Ie33893b896d6259a8604d1768cd21f7d44a6fefd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401120 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent ad92d28 commit 69fef4b

File tree

9 files changed

+25
-24
lines changed

9 files changed

+25
-24
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ class AnalysisDriver {
914914
}
915915

916916
var unitResult = await getUnitElement(file.path);
917-
if (unitResult is UnitElementResult) {
917+
if (unitResult is UnitElementResultImpl) {
918918
return LibraryElementResultImpl(unitResult.element.library);
919919
}
920920

pkg/analyzer/lib/src/dart/analysis/library_context.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import 'dart:collection';
99
import 'dart:typed_data';
1010

1111
import 'package:analyzer/dart/analysis/declared_variables.dart';
12-
import 'package:analyzer/dart/element/element.dart'
13-
show CompilationUnitElement, LibraryElement;
12+
import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement;
1413
import 'package:analyzer/file_system/file_system.dart';
1514
import 'package:analyzer/src/context/context.dart';
1615
import 'package:analyzer/src/dart/analysis/analysis_options_map.dart';
@@ -116,8 +115,8 @@ class LibraryContext {
116115
return keys;
117116
}
118117

119-
/// Get the [LibraryElement] for the given library.
120-
LibraryElement getLibraryElement(Uri uri) {
118+
/// Get the [LibraryElementImpl] for the given library.
119+
LibraryElementImpl getLibraryElement(Uri uri) {
121120
_createElementFactoryTypeProvider();
122121
return elementFactory.libraryOfUri2(uri);
123122
}

pkg/analyzer/lib/src/dart/analysis/results.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:analyzer/error/error.dart';
1414
import 'package:analyzer/file_system/file_system.dart';
1515
import 'package:analyzer/source/line_info.dart';
1616
import 'package:analyzer/src/dart/analysis/file_state.dart';
17+
import 'package:analyzer/src/dart/element/element.dart';
1718
import 'package:analyzer/src/dart/element/type_system.dart';
1819
import 'package:analyzer/src/generated/engine.dart';
1920

@@ -266,12 +267,12 @@ class FileResultImpl extends AnalysisResultImpl implements FileResult {
266267

267268
class LibraryElementResultImpl implements LibraryElementResult {
268269
@override
269-
final LibraryElement element;
270+
final LibraryElementImpl element;
270271

271272
LibraryElementResultImpl(this.element);
272273

273274
@override
274-
LibraryElement2 get element2 => element as LibraryElement2;
275+
LibraryElementImpl get element2 => element;
275276
}
276277

277278
class ParsedLibraryResultImpl extends AnalysisResultImpl
@@ -486,8 +487,9 @@ class ResolvedUnitResultImpl extends FileResultImpl
486487
bool get exists => fileState.exists;
487488

488489
@override
489-
LibraryElement get libraryElement {
490-
return unit.declaredElement!.library;
490+
LibraryElementImpl get libraryElement {
491+
var element = unit.declaredElement as CompilationUnitElementImpl;
492+
return element.library;
491493
}
492494

493495
@override
@@ -500,13 +502,13 @@ class ResolvedUnitResultImpl extends FileResultImpl
500502
TypeProvider get typeProvider => libraryElement.typeProvider;
501503

502504
@override
503-
TypeSystemImpl get typeSystem => libraryElement.typeSystem as TypeSystemImpl;
505+
TypeSystemImpl get typeSystem => libraryElement.typeSystem;
504506
}
505507

506508
class UnitElementResultImpl extends FileResultImpl
507509
implements UnitElementResult {
508510
@override
509-
final CompilationUnitElement element;
511+
final CompilationUnitElementImpl element;
510512

511513
UnitElementResultImpl({
512514
required super.session,
@@ -515,5 +517,5 @@ class UnitElementResultImpl extends FileResultImpl
515517
});
516518

517519
@override
518-
LibraryFragment get fragment => element as LibraryFragment;
520+
LibraryFragment get fragment => element;
519521
}

pkg/analyzer/lib/src/dart/analysis/search.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ class _FindDeclarations {
13311331
(performance) async {
13321332
var result = await analysisDriver.getLibraryByUri('$uri');
13331333
if (result is LibraryElementResultImpl) {
1334-
return result.element as LibraryElementImpl;
1334+
return result.element;
13351335
}
13361336
return null;
13371337
},

pkg/analyzer/lib/src/dart/micro/analysis_context.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1919
import 'package:analyzer/src/dart/micro/resolve_file.dart';
2020
import 'package:analyzer/src/generated/source.dart';
2121
import 'package:analyzer/src/summary2/linked_element_factory.dart';
22-
import 'package:analyzer/src/utilities/extensions/element.dart';
2322

2423
MicroContextObjects createMicroContextObjects({
2524
required FileResolver fileResolver,
@@ -163,7 +162,7 @@ class _MicroAnalysisSessionImpl extends AnalysisSessionImpl {
163162
var element = await analysisContext.fileResolver.getLibraryByUri2(
164163
uriStr: uriStr,
165164
);
166-
return LibraryElementResultImpl(element.asElement);
165+
return LibraryElementResultImpl(element);
167166
}
168167

169168
@override

pkg/analyzer/lib/src/dart/micro/resolve_file.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:analyzer/dart/analysis/declared_variables.dart';
88
import 'package:analyzer/dart/analysis/features.dart';
99
import 'package:analyzer/dart/analysis/results.dart';
1010
import 'package:analyzer/dart/element/element.dart';
11-
import 'package:analyzer/dart/element/element2.dart';
1211
import 'package:analyzer/error/error.dart';
1312
import 'package:analyzer/file_system/file_system.dart';
1413
import 'package:analyzer/source/line_info.dart';
@@ -28,6 +27,7 @@ import 'package:analyzer/src/dart/analysis/performance_logger.dart';
2827
import 'package:analyzer/src/dart/analysis/results.dart';
2928
import 'package:analyzer/src/dart/analysis/search.dart';
3029
import 'package:analyzer/src/dart/analysis/unlinked_unit_store.dart';
30+
import 'package:analyzer/src/dart/element/element.dart';
3131
import 'package:analyzer/src/dart/micro/analysis_context.dart';
3232
import 'package:analyzer/src/dart/micro/utils.dart';
3333
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
@@ -390,7 +390,7 @@ class FileResolver {
390390
return fsState.getFilesWithTopLevelDeclarations(name);
391391
}
392392

393-
Future<LibraryElement2> getLibraryByUri2({
393+
Future<LibraryElementImpl> getLibraryByUri2({
394394
required String uriStr,
395395
OperationPerformanceImpl? performance,
396396
}) async {

pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:analyzer/dart/analysis/analysis_context.dart';
66
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
77
import 'package:analyzer/dart/analysis/context_root.dart';
8-
import 'package:analyzer/dart/analysis/results.dart';
98
import 'package:analyzer/dart/sdk/build_sdk_summary.dart';
109
import 'package:analyzer/file_system/file_system.dart';
1110
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
@@ -308,7 +307,7 @@ abstract class ContextResolutionTest
308307
var uriStr = uri.toString();
309308
var libraryResult = await analysisSession.getLibraryByUri(uriStr);
310309
libraryResult as LibraryElementResultImpl;
311-
return libraryResult.element2 as LibraryElementImpl;
310+
return libraryResult.element2;
312311
}
313312

314313
@override
@@ -321,10 +320,11 @@ abstract class ContextResolutionTest
321320
}
322321

323322
@override
324-
Future<ResolvedUnitResult> resolveFile(File file) async {
323+
Future<ResolvedUnitResultImpl> resolveFile(File file) async {
325324
var analysisContext = contextFor(fileForContextSelection ?? file);
326325
var session = analysisContext.currentSession;
327-
return await session.getResolvedUnit(file.path) as ResolvedUnitResult;
326+
var result = await session.getResolvedUnit(file.path);
327+
return result as ResolvedUnitResultImpl;
328328
}
329329

330330
@mustCallSuper

pkg/analyzer/test/src/summary/macro_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19352,7 +19352,7 @@ elementFactory
1935219352

1935319353
// Check that it has `class B2 {}`, as requested.
1935419354
result2 as LibraryElementResultImpl;
19355-
_assertMacroCode(result2.element as LibraryElementImpl, r'''
19355+
_assertMacroCode(result2.element, r'''
1935619356
part of 'package:test/test.dart';
1935719357

1935819358
class B2 {}

pkg/analyzer/test/src/utilities/extensions/analysis_session_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:analyzer/dart/analysis/session.dart';
77
import 'package:analyzer/dart/element/element.dart';
88
import 'package:analyzer/file_system/file_system.dart';
99
import 'package:analyzer/src/dart/analysis/results.dart';
10+
import 'package:analyzer/src/dart/element/element.dart';
1011
import 'package:analyzer/src/test_utilities/test_code_format.dart';
1112
import 'package:analyzer/src/utilities/extensions/analysis_session.dart';
1213
import 'package:test/test.dart';
@@ -91,9 +92,9 @@ class LocateElementTest extends PubPackageResolutionTest {
9192
}
9293

9394
class _MockAnalysisSession implements AnalysisSession {
94-
final _libraries = <String, LibraryElement>{};
95+
final _libraries = <String, LibraryElementImpl>{};
9596

96-
void addLibrary(LibraryElement library) =>
97+
void addLibrary(LibraryElementImpl library) =>
9798
_libraries[library.identifier] = library;
9899

99100
@override

0 commit comments

Comments
 (0)