-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache parsed library results. (#1307)
- Loading branch information
1 parent
25d356b
commit ac1883c
Showing
20 changed files
with
307 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2021, Google Inc. Please see the AUTHORS file for details. | ||
// All rights reserved. Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
import 'package:analyzer/dart/analysis/results.dart'; | ||
import 'package:analyzer/dart/element/element.dart'; | ||
|
||
/// Caches parsed library results across one generation. | ||
/// | ||
/// Substitutes a "throwing mock" if no parsed library is available. | ||
class ParsedLibraryResults { | ||
final Map<Uri, ParsedLibraryResult> _results = {}; | ||
|
||
ParsedLibraryResult parsedLibraryResultOrThrowingMock( | ||
LibraryElement element) { | ||
var uri = element.source.uri; | ||
return _results[uri] ??= _parsedLibraryResultOrThrowingMock(element); | ||
} | ||
|
||
ParsedLibraryResult _parsedLibraryResultOrThrowingMock( | ||
LibraryElement element) { | ||
var result = element.session.getParsedLibraryByElement(element); | ||
if (result is ParsedLibraryResult) { | ||
return result; | ||
} | ||
return _ParsedLibraryResultMock(); | ||
} | ||
} | ||
|
||
class _ParsedLibraryResultMock implements ParsedLibraryResult { | ||
@override | ||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | ||
} |
Oops, something went wrong.