| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.services.completion.dart.keyword; | 5 library test.services.completion.dart.keyword; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 8 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 8 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; | 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart
'; |
| 10 import 'package:analyzer/src/generated/scanner.dart'; | 10 import 'package:analyzer/src/generated/scanner.dart'; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 static const List<String> NO_PSEUDO_KEYWORDS = const []; | 78 static const List<String> NO_PSEUDO_KEYWORDS = const []; |
| 79 | 79 |
| 80 static const List<Keyword> STMT_START_IN_CLASS = const [ | 80 static const List<Keyword> STMT_START_IN_CLASS = const [ |
| 81 Keyword.ASSERT, | 81 Keyword.ASSERT, |
| 82 Keyword.CONST, | 82 Keyword.CONST, |
| 83 Keyword.DO, | 83 Keyword.DO, |
| 84 Keyword.FINAL, | 84 Keyword.FINAL, |
| 85 Keyword.FOR, | 85 Keyword.FOR, |
| 86 Keyword.IF, | 86 Keyword.IF, |
| 87 Keyword.NEW, | 87 Keyword.NEW, |
| 88 Keyword.RETHROW, | |
| 89 Keyword.RETURN, | 88 Keyword.RETURN, |
| 90 Keyword.SUPER, | 89 Keyword.SUPER, |
| 91 Keyword.SWITCH, | 90 Keyword.SWITCH, |
| 92 Keyword.THIS, | 91 Keyword.THIS, |
| 93 Keyword.THROW, | 92 Keyword.THROW, |
| 94 Keyword.TRY, | 93 Keyword.TRY, |
| 95 Keyword.VAR, | 94 Keyword.VAR, |
| 96 Keyword.VOID, | 95 Keyword.VOID, |
| 97 Keyword.WHILE | 96 Keyword.WHILE |
| 98 ]; | 97 ]; |
| 99 | 98 |
| 100 static const List<Keyword> STMT_START_IN_LOOP_IN_CLASS = const [ | 99 static const List<Keyword> STMT_START_IN_LOOP_IN_CLASS = const [ |
| 101 Keyword.ASSERT, | 100 Keyword.ASSERT, |
| 102 Keyword.BREAK, | 101 Keyword.BREAK, |
| 103 Keyword.CONST, | 102 Keyword.CONST, |
| 104 Keyword.CONTINUE, | 103 Keyword.CONTINUE, |
| 105 Keyword.DO, | 104 Keyword.DO, |
| 106 Keyword.FINAL, | 105 Keyword.FINAL, |
| 107 Keyword.FOR, | 106 Keyword.FOR, |
| 108 Keyword.IF, | 107 Keyword.IF, |
| 109 Keyword.NEW, | 108 Keyword.NEW, |
| 110 Keyword.RETHROW, | |
| 111 Keyword.RETURN, | 109 Keyword.RETURN, |
| 112 Keyword.SUPER, | 110 Keyword.SUPER, |
| 113 Keyword.SWITCH, | 111 Keyword.SWITCH, |
| 114 Keyword.THIS, | 112 Keyword.THIS, |
| 115 Keyword.THROW, | 113 Keyword.THROW, |
| 116 Keyword.TRY, | 114 Keyword.TRY, |
| 117 Keyword.VAR, | 115 Keyword.VAR, |
| 118 Keyword.VOID, | 116 Keyword.VOID, |
| 119 Keyword.WHILE | 117 Keyword.WHILE |
| 120 ]; | 118 ]; |
| 121 | 119 |
| 122 static const List<Keyword> STMT_START_IN_SWITCH_IN_CLASS = const [ | 120 static const List<Keyword> STMT_START_IN_SWITCH_IN_CLASS = const [ |
| 123 Keyword.ASSERT, | 121 Keyword.ASSERT, |
| 124 Keyword.BREAK, | 122 Keyword.BREAK, |
| 125 Keyword.CASE, | 123 Keyword.CASE, |
| 126 Keyword.CONST, | 124 Keyword.CONST, |
| 127 Keyword.DEFAULT, | 125 Keyword.DEFAULT, |
| 128 Keyword.DO, | 126 Keyword.DO, |
| 129 Keyword.FINAL, | 127 Keyword.FINAL, |
| 130 Keyword.FOR, | 128 Keyword.FOR, |
| 131 Keyword.IF, | 129 Keyword.IF, |
| 132 Keyword.NEW, | 130 Keyword.NEW, |
| 133 Keyword.RETHROW, | |
| 134 Keyword.RETURN, | 131 Keyword.RETURN, |
| 135 Keyword.SUPER, | 132 Keyword.SUPER, |
| 136 Keyword.SWITCH, | 133 Keyword.SWITCH, |
| 137 Keyword.THIS, | 134 Keyword.THIS, |
| 138 Keyword.THROW, | 135 Keyword.THROW, |
| 139 Keyword.TRY, | 136 Keyword.TRY, |
| 140 Keyword.VAR, | 137 Keyword.VAR, |
| 141 Keyword.VOID, | 138 Keyword.VOID, |
| 142 Keyword.WHILE | 139 Keyword.WHILE |
| 143 ]; | 140 ]; |
| 144 | 141 |
| 145 static const List<Keyword> STMT_START_IN_SWITCH_OUTSIDE_CLASS = const [ | 142 static const List<Keyword> STMT_START_IN_SWITCH_OUTSIDE_CLASS = const [ |
| 146 Keyword.ASSERT, | 143 Keyword.ASSERT, |
| 147 Keyword.BREAK, | 144 Keyword.BREAK, |
| 148 Keyword.CASE, | 145 Keyword.CASE, |
| 149 Keyword.CONST, | 146 Keyword.CONST, |
| 150 Keyword.DEFAULT, | 147 Keyword.DEFAULT, |
| 151 Keyword.DO, | 148 Keyword.DO, |
| 152 Keyword.FINAL, | 149 Keyword.FINAL, |
| 153 Keyword.FOR, | 150 Keyword.FOR, |
| 154 Keyword.IF, | 151 Keyword.IF, |
| 155 Keyword.NEW, | 152 Keyword.NEW, |
| 156 Keyword.RETHROW, | |
| 157 Keyword.RETURN, | 153 Keyword.RETURN, |
| 158 Keyword.SWITCH, | 154 Keyword.SWITCH, |
| 159 Keyword.THROW, | 155 Keyword.THROW, |
| 160 Keyword.TRY, | 156 Keyword.TRY, |
| 161 Keyword.VAR, | 157 Keyword.VAR, |
| 162 Keyword.VOID, | 158 Keyword.VOID, |
| 163 Keyword.WHILE | 159 Keyword.WHILE |
| 164 ]; | 160 ]; |
| 165 | 161 |
| 166 static const List<Keyword> STMT_START_OUTSIDE_CLASS = const [ | 162 static const List<Keyword> STMT_START_OUTSIDE_CLASS = const [ |
| 167 Keyword.ASSERT, | 163 Keyword.ASSERT, |
| 168 Keyword.CONST, | 164 Keyword.CONST, |
| 169 Keyword.DO, | 165 Keyword.DO, |
| 170 Keyword.FINAL, | 166 Keyword.FINAL, |
| 171 Keyword.FOR, | 167 Keyword.FOR, |
| 172 Keyword.IF, | 168 Keyword.IF, |
| 173 Keyword.NEW, | 169 Keyword.NEW, |
| 174 Keyword.RETHROW, | |
| 175 Keyword.RETURN, | 170 Keyword.RETURN, |
| 176 Keyword.SWITCH, | 171 Keyword.SWITCH, |
| 177 Keyword.THROW, | 172 Keyword.THROW, |
| 178 Keyword.TRY, | 173 Keyword.TRY, |
| 179 Keyword.VAR, | 174 Keyword.VAR, |
| 180 Keyword.VOID, | 175 Keyword.VOID, |
| 181 Keyword.WHILE | 176 Keyword.WHILE |
| 182 ]; | 177 ]; |
| 183 | 178 |
| 184 static const List<Keyword> STMT_START_IN_LOOP_OUTSIDE_CLASS = const [ | 179 static const List<Keyword> STMT_START_IN_LOOP_OUTSIDE_CLASS = const [ |
| 185 Keyword.ASSERT, | 180 Keyword.ASSERT, |
| 186 Keyword.BREAK, | 181 Keyword.BREAK, |
| 187 Keyword.CONST, | 182 Keyword.CONST, |
| 188 Keyword.CONTINUE, | 183 Keyword.CONTINUE, |
| 189 Keyword.DO, | 184 Keyword.DO, |
| 190 Keyword.FINAL, | 185 Keyword.FINAL, |
| 191 Keyword.FOR, | 186 Keyword.FOR, |
| 192 Keyword.IF, | 187 Keyword.IF, |
| 193 Keyword.NEW, | 188 Keyword.NEW, |
| 194 Keyword.RETHROW, | |
| 195 Keyword.RETURN, | 189 Keyword.RETURN, |
| 196 Keyword.SWITCH, | 190 Keyword.SWITCH, |
| 197 Keyword.THROW, | 191 Keyword.THROW, |
| 198 Keyword.TRY, | 192 Keyword.TRY, |
| 199 Keyword.VAR, | 193 Keyword.VAR, |
| 200 Keyword.VOID, | 194 Keyword.VOID, |
| 201 Keyword.WHILE | 195 Keyword.WHILE |
| 202 ]; | 196 ]; |
| 203 | 197 |
| 204 static const List<Keyword> EXPRESSION_START_INSTANCE = const [ | 198 static const List<Keyword> EXPRESSION_START_INSTANCE = const [ |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 relevance: DART_RELEVANCE_HIGH); | 600 relevance: DART_RELEVANCE_HIGH); |
| 607 } | 601 } |
| 608 | 602 |
| 609 test_for_break_continue() { | 603 test_for_break_continue() { |
| 610 addTestSource('main() {for (int x in myList) {^}}'); | 604 addTestSource('main() {for (int x in myList) {^}}'); |
| 611 expect(computeFast(), isTrue); | 605 expect(computeFast(), isTrue); |
| 612 assertSuggestKeywords(STMT_START_IN_LOOP_OUTSIDE_CLASS, | 606 assertSuggestKeywords(STMT_START_IN_LOOP_OUTSIDE_CLASS, |
| 613 relevance: DART_RELEVANCE_KEYWORD); | 607 relevance: DART_RELEVANCE_KEYWORD); |
| 614 } | 608 } |
| 615 | 609 |
| 610 test_catch() { |
| 611 addTestSource('main() {try {} catch (e) {^}}}'); |
| 612 expect(computeFast(), isTrue); |
| 613 var keywords = <Keyword>[]; |
| 614 keywords.addAll(STMT_START_OUTSIDE_CLASS); |
| 615 keywords.add(Keyword.RETHROW); |
| 616 assertSuggestKeywords(keywords, |
| 617 relevance: DART_RELEVANCE_KEYWORD); |
| 618 } |
| 619 |
| 616 test_for_break_continue2() { | 620 test_for_break_continue2() { |
| 617 addTestSource('class A {foo() {for (int x in myList) {^}}}'); | 621 addTestSource('class A {foo() {for (int x in myList) {^}}}'); |
| 618 expect(computeFast(), isTrue); | 622 expect(computeFast(), isTrue); |
| 619 assertSuggestKeywords(STMT_START_IN_LOOP_IN_CLASS, | 623 assertSuggestKeywords(STMT_START_IN_LOOP_IN_CLASS, |
| 620 relevance: DART_RELEVANCE_KEYWORD); | 624 relevance: DART_RELEVANCE_KEYWORD); |
| 621 } | 625 } |
| 622 | 626 |
| 623 test_for_expression_in() { | 627 test_for_expression_in() { |
| 624 addTestSource('main() {for (int x i^)}'); | 628 addTestSource('main() {for (int x i^)}'); |
| 625 expect(computeFast(), isTrue); | 629 expect(computeFast(), isTrue); |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); | 1395 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); |
| 1392 } | 1396 } |
| 1393 | 1397 |
| 1394 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { | 1398 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { |
| 1395 if (iter1.length != iter2.length) return false; | 1399 if (iter1.length != iter2.length) return false; |
| 1396 if (iter1.any((c) => !iter2.contains(c))) return false; | 1400 if (iter1.any((c) => !iter2.contains(c))) return false; |
| 1397 if (iter2.any((c) => !iter1.contains(c))) return false; | 1401 if (iter2.any((c) => !iter1.contains(c))) return false; |
| 1398 return true; | 1402 return true; |
| 1399 } | 1403 } |
| 1400 } | 1404 } |
| OLD | NEW |