Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1462)

Unified Diff: pkg/kernel/lib/ast.dart

Issue 2876533004: Add FunctionType.getNamedParameter. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart ('k') | pkg/kernel/lib/type_checker.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/ast.dart
diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart
index f051b14ade22132f252350ab363b45c0099bf252..e39b541f09aa669e711d88d72b5bb6bd4a617dff 100644
--- a/pkg/kernel/lib/ast.dart
+++ b/pkg/kernel/lib/ast.dart
@@ -3991,6 +3991,26 @@ class FunctionType extends DartType {
namedParameters: namedParameters);
}
+ /// Looks up the type of the named parameter with the given name.
+ ///
+ /// Returns `null` if there is no named parameter with the given name.
+ DartType getNamedParameter(String name) {
+ int lower = 0;
+ int upper = namedParameters.length - 1;
+ while (lower <= upper) {
+ int pivot = (lower + upper) ~/ 2;
+ int comparison = name.compareTo(namedParameters[pivot].name);
scheglov 2017/05/10 18:03:35 It should be slightly faster to extract `namedPara
Paul Berry 2017/05/10 18:16:08 Done.
+ if (comparison == 0) {
+ return namedParameters[pivot].type;
+ } else if (comparison < 0) {
+ upper = pivot - 1;
+ } else {
+ lower = pivot + 1;
+ }
+ }
+ return null;
+ }
+
int get hashCode => _hashCode ??= _computeHashCode();
int _computeHashCode() {
« no previous file with comments | « pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart ('k') | pkg/kernel/lib/type_checker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698