Skip to content

Commit 359aa74

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Add LibraryElement2.uri
We used it often enough, and the question "what is the URI of the library" makes sense. Change-Id: I58baebd7b32154ae7a2f90770e4edcade8a49a63 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395680 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 3f7df09 commit 359aa74

File tree

21 files changed

+29
-34
lines changed

21 files changed

+29
-34
lines changed

pkg/analysis_server/lib/src/services/completion/dart/override_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OverrideHelper {
3636
var interface = inheritanceManager.getInterface2(interfaceElement);
3737
var interfaceMap = interface.map2;
3838
var namesToOverride = _namesToOverride(
39-
interfaceElement.library2.firstFragment.source.uri,
39+
interfaceElement.library2.uri,
4040
interface,
4141
);
4242

pkg/analysis_server/lib/src/services/correction/fix/data_driven/element_matcher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ElementMatcher {
172172
for (var libraryImport in part.libraryImports2) {
173173
// TODO(brianwilkerson): Filter based on combinators to help avoid making
174174
// invalid suggestions.
175-
var uri = libraryImport.importedLibrary2?.firstFragment.source.uri;
175+
var uri = libraryImport.importedLibrary2?.uri;
176176
if (uri != null) {
177177
// The [uri] is `null` if the literal string is not a valid URI.
178178
importedUris.add(uri);

pkg/analysis_server/lib/src/services/correction/fix/data_driven/rename_parameter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ extension on MethodDeclaration {
142142
var enclosingElement = element.enclosingElement2;
143143
if (enclosingElement is InterfaceElement2) {
144144
var name = Name(
145-
enclosingElement.library2.firstFragment.source.uri,
145+
enclosingElement.library2.uri,
146146
element.name3!,
147147
);
148148
return inheritanceManager.getInherited4(enclosingElement, name);

pkg/analysis_server/lib/src/services/refactoring/move_top_level_to_file.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class MoveTopLevelToFile extends RefactoringProducer {
215215
var hasShowCombinator =
216216
import.combinators.whereType<ShowElementCombinator>().isNotEmpty;
217217
builder.importLibrary(
218-
library.firstFragment.source.uri,
218+
library.uri,
219219
prefix: import.prefix2?.element.name3,
220220
showName: element.name3,
221221
useShow: hasShowCombinator,

pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class AbstractChangeMethodSignatureTest extends AbstractContextTest {
131131

132132
String _referenceToString(Reference reference) {
133133
var selfLibrary = refactoringContext.resolvedLibraryResult.element2;
134-
var selfUriStr = '${selfLibrary.firstFragment.source.uri}';
134+
var selfUriStr = '${selfLibrary.uri}';
135135

136136
var name = reference.name;
137137
if (name == selfUriStr) {

pkg/analysis_server/test/src/utilities/selection_coverage_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class SelectionCoverageTest {
247247
var overridden = inheritanceManager.getOverridden4(
248248
visitedNodeList.enclosingElement2 as InterfaceElement2,
249249
Name(
250-
visitedNodeList.library2!.firstFragment.source.uri,
250+
visitedNodeList.library2!.uri,
251251
visitedNodeList.name3!,
252252
),
253253
);

pkg/analysis_server/tool/code_completion/flutter_metrics.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ class FlutterDataCollector extends RecursiveAstVisitor<void> {
141141
var childWidget = element.enclosingElement2.name3!;
142142
var library = element.library2;
143143
if (library != null &&
144-
!library.firstFragment.source.uri.toString().startsWith(
145-
'package:flutter/',
146-
)) {
144+
!library.uri.toString().startsWith('package:flutter/')) {
147145
childWidget = 'user-defined';
148146
}
149147
data.recordWidgetCreation(childWidget, parentWidget);

pkg/analyzer/lib/dart/element/element2.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,11 @@ abstract class LibraryElement2 implements Element2, Annotatable {
15101510

15111511
/// The [TypeSystem] that is used in this library.
15121512
TypeSystem get typeSystem;
1513+
1514+
/// The canonical URI of the library.
1515+
///
1516+
/// This is the same URI as `firstFragment.source.uri` returns.
1517+
Uri get uri;
15131518
}
15141519

15151520
/// An `export` directive within a library fragment.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6788,6 +6788,9 @@ class LibraryElementImpl extends ElementImpl
67886788
];
67896789
}
67906790

6791+
@override
6792+
Uri get uri => firstFragment.source.uri;
6793+
67916794
List<CompilationUnitElementImpl> get _partUnits {
67926795
var result = <CompilationUnitElementImpl>[];
67936796

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,7 @@ class Name {
13191319
}
13201320

13211321
factory Name.forLibrary(LibraryElement2? library, String name) {
1322-
var uri = library?.firstFragment.source.uri;
1323-
return Name(uri, name);
1322+
return Name(library?.uri, name);
13241323
}
13251324

13261325
Name._internal(this.libraryUri, this.name, this.isPublic, this.hashCode);

0 commit comments

Comments
 (0)