Skip to content

Commit

Permalink
Elements. Migrate BuildSdkSummaryTest.
Browse files Browse the repository at this point in the history
Adds `LibraryElement2.getClass2()`

Change-Id: Idb6168ba320e54b26625a9847658908e81be2229
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396622
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Nov 20, 2024
1 parent af9cc50 commit 7c3e294
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 0 additions & 1 deletion pkg/analyzer/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ lib/src/utilities/extensions/ast.dart
lib/src/utilities/extensions/element.dart
lib/src/utilities/extensions/flutter.dart
lib/src/utilities/extensions/library_element.dart
test/dart/sdk/build_sdk_summary_test.dart
test/error/error_reporter_test.dart
test/generated/element_resolver_test.dart
test/generated/elements_types_mixin.dart
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,9 @@ abstract class LibraryElement2 implements Element2, Annotatable {
///
/// This is the same URI as `firstFragment.source.uri` returns.
Uri get uri;

/// Returns the class defined in this library that has the given [name].
ClassElement2? getClass2(String name);
}

/// An `export` directive within a library fragment.
Expand Down
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6836,6 +6836,16 @@ class LibraryElementImpl extends ElementImpl
return null;
}

@override
ClassElement2? getClass2(String name) {
for (var class_ in classes) {
if (class_.name3 == name) {
return class_;
}
}
return null;
}

EnumElement? getEnum(String name) {
for (var unitElement in units) {
var element = unitElement.getEnum(name);
Expand Down
22 changes: 11 additions & 11 deletions pkg/analyzer/test/dart/sdk/build_sdk_summary_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/sdk/build_sdk_summary.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
Expand Down Expand Up @@ -87,11 +87,11 @@ embedded_libs:
var dartCore = await analysisSession.getLibrary('dart:core');
var dartMath = await analysisSession.getLibrary('dart:math');
var dartUi = await analysisSession.getLibrary('dart:ui');
expect(dartAsync.getClass('Stream'), isNotNull);
expect(dartCore.getClass('String'), isNotNull);
expect(dartMath.getClass('Random'), isNotNull);
expect(dartUi.getClass('FontStyle'), isNotNull);
expect(dartUi.getClass('Offset'), isNotNull);
expect(dartAsync.getClass2('Stream'), isNotNull);
expect(dartCore.getClass2('String'), isNotNull);
expect(dartMath.getClass2('Random'), isNotNull);
expect(dartUi.getClass2('FontStyle'), isNotNull);
expect(dartUi.getClass2('Offset'), isNotNull);
}

test_it() async {
Expand Down Expand Up @@ -133,16 +133,16 @@ embedded_libs:
var dartAsync = await analysisSession.getLibrary('dart:async');
var dartCore = await analysisSession.getLibrary('dart:core');
var dartMath = await analysisSession.getLibrary('dart:math');
expect(dartAsync.getClass('Stream'), isNotNull);
expect(dartCore.getClass('String'), isNotNull);
expect(dartMath.getClass('Random'), isNotNull);
expect(dartAsync.getClass2('Stream'), isNotNull);
expect(dartCore.getClass2('String'), isNotNull);
expect(dartMath.getClass2('Random'), isNotNull);
}
}

extension on AnalysisSession {
Future<LibraryElement> getLibrary(String uriStr) async {
Future<LibraryElement2> getLibrary(String uriStr) async {
var libraryResult = await getLibraryByUri(uriStr);
libraryResult as LibraryElementResult;
return libraryResult.element;
return libraryResult.element2;
}
}

0 comments on commit 7c3e294

Please sign in to comment.