| 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.domain.analysis.notification.outline; | 5 library test.domain.analysis.notification.outline; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:mirrors'; | |
| 9 | 8 |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/computer/computer_outline.dart'; |
| 11 import 'package:analysis_server/src/computer/element.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 12 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 13 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 14 | 15 |
| 15 import 'analysis_abstract.dart'; | 16 import 'analysis_abstract.dart'; |
| 16 import 'reflective_tests.dart'; | 17 import 'reflective_tests.dart'; |
| 17 | 18 |
| 18 | 19 |
| 19 main() { | 20 main() { |
| 20 group('notification.outline', () { | 21 group('notification.outline', () { |
| 21 runReflectiveTests(_AnalysisNotificationOutlineTest); | 22 runReflectiveTests(_AnalysisNotificationOutlineTest); |
| 22 }); | 23 }); |
| 23 } | 24 } |
| 24 | 25 |
| 25 | 26 |
| 26 @ReflectiveTestCase() | 27 @ReflectiveTestCase() |
| 27 class _AnalysisNotificationOutlineTest extends AbstractAnalysisTest { | 28 class _AnalysisNotificationOutlineTest extends AbstractAnalysisTest { |
| 28 _Outline outline; | 29 Outline outline; |
| 29 | 30 |
| 30 @override | 31 Future prepareOutline(then()) { |
| 31 void setUp() { | 32 addAnalysisSubscription(AnalysisService.OUTLINE, testFile); |
| 32 super.setUp(); | 33 return waitForTasksFinished().then((_) { |
| 33 createProject(); | 34 then(); |
| 35 }); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void processNotification(Notification notification) { | 38 void processNotification(Notification notification) { |
| 37 if (notification.event == ANALYSIS_OUTLINE) { | 39 if (notification.event == ANALYSIS_OUTLINE) { |
| 38 String file = notification.getParameter(FILE); | 40 String file = notification.getParameter(FILE); |
| 39 if (file == testFile) { | 41 if (file == testFile) { |
| 40 Map<String, Object> json = notification.getParameter(OUTLINE); | 42 Map<String, Object> json = notification.getParameter(OUTLINE); |
| 41 outline = new _Outline.fromJson(json); | 43 outline = new Outline.fromJson(json); |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 } | 46 } |
| 45 | 47 |
| 46 Future prepareOutline(then()) { | 48 @override |
| 47 addAnalysisSubscription(AnalysisService.OUTLINE, testFile); | 49 void setUp() { |
| 50 super.setUp(); |
| 51 createProject(); |
| 52 } |
| 53 |
| 54 test_afterAnalysis() { |
| 55 addTestFile(''' |
| 56 class AAA { |
| 57 } |
| 58 class BBB { |
| 59 } |
| 60 '''); |
| 48 return waitForTasksFinished().then((_) { | 61 return waitForTasksFinished().then((_) { |
| 49 then(); | 62 expect(outline, isNull); |
| 63 return prepareOutline(() { |
| 64 Outline unitOutline = outline; |
| 65 List<Outline> outlines = unitOutline.children; |
| 66 expect(outlines, hasLength(2)); |
| 67 }); |
| 50 }); | 68 }); |
| 51 } | 69 } |
| 52 | 70 |
| 53 test_class() { | 71 test_class() { |
| 54 addTestFile(''' | 72 addTestFile(''' |
| 55 class A { | 73 class A { |
| 56 int fa, fb; | 74 int fa, fb; |
| 57 String fc; | 75 String fc; |
| 58 A(int i, String s); | 76 A(int i, String s); |
| 59 A.name(num p); | 77 A.name(num p); |
| 60 A._privateName(num p); | 78 A._privateName(num p); |
| 61 static String ma(int pa) => null; | 79 static String ma(int pa) => null; |
| 62 _mb(int pb); | 80 _mb(int pb); |
| 63 String get propA => null; | 81 String get propA => null; |
| 64 set propB(int v) {} | 82 set propB(int v) {} |
| 65 } | 83 } |
| 66 class B { | 84 class B { |
| 67 B(int p); | 85 B(int p); |
| 68 }"); | 86 }"); |
| 69 '''); | 87 '''); |
| 70 return prepareOutline(() { | 88 return prepareOutline(() { |
| 71 _Outline unitOutline = outline; | 89 Outline unitOutline = outline; |
| 72 List<_Outline> topOutlines = unitOutline.children; | 90 List<Outline> topOutlines = unitOutline.children; |
| 73 expect(topOutlines, hasLength(2)); | 91 expect(topOutlines, hasLength(2)); |
| 74 // A | 92 // A |
| 75 { | 93 { |
| 76 _Outline outline_A = topOutlines[0]; | 94 Outline outline_A = topOutlines[0]; |
| 77 expect(outline_A.kind, _OutlineKind.CLASS); | 95 Element element_A = outline_A.element; |
| 78 expect(outline_A.name, "A"); | 96 expect(element_A.kind, ElementKind.CLASS); |
| 79 expect(outline_A.nameOffset, testCode.indexOf("A {")); | 97 expect(element_A.name, "A"); |
| 80 expect(outline_A.nameLength, 1); | 98 expect(element_A.offset, testCode.indexOf("A {")); |
| 81 expect(outline_A.parameters, null); | 99 expect(element_A.length, 1); |
| 82 expect(outline_A.returnType, null); | 100 expect(element_A.parameters, null); |
| 101 expect(element_A.returnType, null); |
| 83 // A children | 102 // A children |
| 84 List<_Outline> outlines_A = outline_A.children; | 103 List<Outline> outlines_A = outline_A.children; |
| 85 expect(outlines_A, hasLength(10)); | 104 expect(outlines_A, hasLength(10)); |
| 86 { | 105 { |
| 87 _Outline outline = outlines_A[0]; | 106 Outline outline = outlines_A[0]; |
| 88 expect(outline.kind, _OutlineKind.FIELD); | 107 Element element = outline.element; |
| 89 expect(outline.name, "fa"); | 108 expect(element.kind, ElementKind.FIELD); |
| 90 expect(outline.parameters, isNull); | 109 expect(element.name, "fa"); |
| 91 expect(outline.returnType, "int"); | 110 expect(element.parameters, isNull); |
| 92 } | 111 expect(element.returnType, "int"); |
| 93 { | 112 } |
| 94 _Outline outline = outlines_A[1]; | 113 { |
| 95 expect(outline.kind, _OutlineKind.FIELD); | 114 Outline outline = outlines_A[1]; |
| 96 expect(outline.name, "fb"); | 115 Element element = outline.element; |
| 97 expect(outline.parameters, isNull); | 116 expect(element.kind, ElementKind.FIELD); |
| 98 expect(outline.returnType, "int"); | 117 expect(element.name, "fb"); |
| 99 } | 118 expect(element.parameters, isNull); |
| 100 { | 119 expect(element.returnType, "int"); |
| 101 _Outline outline = outlines_A[2]; | 120 } |
| 102 expect(outline.kind, _OutlineKind.FIELD); | 121 { |
| 103 expect(outline.name, "fc"); | 122 Outline outline = outlines_A[2]; |
| 104 expect(outline.parameters, isNull); | 123 Element element = outline.element; |
| 105 expect(outline.returnType, "String"); | 124 expect(element.kind, ElementKind.FIELD); |
| 106 } | 125 expect(element.name, "fc"); |
| 107 { | 126 expect(element.parameters, isNull); |
| 108 _Outline outline = outlines_A[3]; | 127 expect(element.returnType, "String"); |
| 109 expect(outline.kind, _OutlineKind.CONSTRUCTOR); | 128 } |
| 110 expect(outline.name, "A"); | 129 { |
| 111 expect(outline.nameOffset, testCode.indexOf("A(int i, String s);")); | 130 Outline outline = outlines_A[3]; |
| 112 expect(outline.nameLength, "A".length); | 131 Element element = outline.element; |
| 113 expect(outline.parameters, "(int i, String s)"); | 132 expect(element.kind, ElementKind.CONSTRUCTOR); |
| 114 expect(outline.returnType, isNull); | 133 expect(element.name, "A"); |
| 115 expect(outline.isAbstract, isFalse); | 134 expect(element.offset, testCode.indexOf("A(int i, String s);")); |
| 116 expect(outline.isStatic, isFalse); | 135 expect(element.length, "A".length); |
| 117 } | 136 expect(element.parameters, "(int i, String s)"); |
| 118 { | 137 expect(element.returnType, isNull); |
| 119 _Outline outline = outlines_A[4]; | 138 expect(element.isAbstract, isFalse); |
| 120 expect(outline.kind, _OutlineKind.CONSTRUCTOR); | 139 expect(element.isStatic, isFalse); |
| 121 expect(outline.name, "A.name"); | 140 } |
| 122 expect(outline.nameOffset, testCode.indexOf("name(num p);")); | 141 { |
| 123 expect(outline.nameLength, "name".length); | 142 Outline outline = outlines_A[4]; |
| 124 expect(outline.parameters, "(num p)"); | 143 Element element = outline.element; |
| 125 expect(outline.returnType, isNull); | 144 expect(element.kind, ElementKind.CONSTRUCTOR); |
| 126 expect(outline.isAbstract, isFalse); | 145 expect(element.name, "A.name"); |
| 127 expect(outline.isStatic, isFalse); | 146 expect(element.offset, testCode.indexOf("name(num p);")); |
| 128 } | 147 expect(element.length, "name".length); |
| 129 { | 148 expect(element.parameters, "(num p)"); |
| 130 _Outline outline = outlines_A[5]; | 149 expect(element.returnType, isNull); |
| 131 expect(outline.kind, _OutlineKind.CONSTRUCTOR); | 150 expect(element.isAbstract, isFalse); |
| 132 expect(outline.name, "A._privateName"); | 151 expect(element.isStatic, isFalse); |
| 133 expect(outline.nameOffset, testCode.indexOf("_privateName(num p);")); | 152 } |
| 134 expect(outline.nameLength, "_privateName".length); | 153 { |
| 135 expect(outline.parameters, "(num p)"); | 154 Outline outline = outlines_A[5]; |
| 136 expect(outline.returnType, isNull); | 155 Element element = outline.element; |
| 137 expect(outline.isAbstract, isFalse); | 156 expect(element.kind, ElementKind.CONSTRUCTOR); |
| 138 expect(outline.isStatic, isFalse); | 157 expect(element.name, "A._privateName"); |
| 139 } | 158 expect(element.offset, testCode.indexOf("_privateName(num p);")); |
| 140 { | 159 expect(element.length, "_privateName".length); |
| 141 _Outline outline = outlines_A[6]; | 160 expect(element.parameters, "(num p)"); |
| 142 expect(outline.kind, _OutlineKind.METHOD); | 161 expect(element.returnType, isNull); |
| 143 expect(outline.name, "ma"); | 162 expect(element.isAbstract, isFalse); |
| 144 expect(outline.nameOffset, testCode.indexOf("ma(int pa) => null;")); | 163 expect(element.isStatic, isFalse); |
| 145 expect(outline.nameLength, "ma".length); | 164 } |
| 146 expect(outline.parameters, "(int pa)"); | 165 { |
| 147 expect(outline.returnType, "String"); | 166 Outline outline = outlines_A[6]; |
| 148 expect(outline.isAbstract, isFalse); | 167 Element element = outline.element; |
| 149 expect(outline.isStatic, isTrue); | 168 expect(element.kind, ElementKind.METHOD); |
| 150 } | 169 expect(element.name, "ma"); |
| 151 { | 170 expect(element.offset, testCode.indexOf("ma(int pa) => null;")); |
| 152 _Outline outline = outlines_A[7]; | 171 expect(element.length, "ma".length); |
| 153 expect(outline.kind, _OutlineKind.METHOD); | 172 expect(element.parameters, "(int pa)"); |
| 154 expect(outline.name, "_mb"); | 173 expect(element.returnType, "String"); |
| 155 expect(outline.nameOffset, testCode.indexOf("_mb(int pb);")); | 174 expect(element.isAbstract, isFalse); |
| 156 expect(outline.nameLength, "_mb".length); | 175 expect(element.isStatic, isTrue); |
| 157 expect(outline.parameters, "(int pb)"); | 176 } |
| 158 expect(outline.returnType, ""); | 177 { |
| 159 expect(outline.isAbstract, isTrue); | 178 Outline outline = outlines_A[7]; |
| 160 expect(outline.isStatic, isFalse); | 179 Element element = outline.element; |
| 161 } | 180 expect(element.kind, ElementKind.METHOD); |
| 162 { | 181 expect(element.name, "_mb"); |
| 163 _Outline outline = outlines_A[8]; | 182 expect(element.offset, testCode.indexOf("_mb(int pb);")); |
| 164 expect(outline.kind, _OutlineKind.GETTER); | 183 expect(element.length, "_mb".length); |
| 165 expect(outline.name, "propA"); | 184 expect(element.parameters, "(int pb)"); |
| 166 expect(outline.nameOffset, testCode.indexOf("propA => null;")); | 185 expect(element.returnType, ""); |
| 167 expect(outline.nameLength, "propA".length); | 186 expect(element.isAbstract, isTrue); |
| 168 expect(outline.parameters, ""); | 187 expect(element.isStatic, isFalse); |
| 169 expect(outline.returnType, "String"); | 188 } |
| 170 } | 189 { |
| 171 { | 190 Outline outline = outlines_A[8]; |
| 172 _Outline outline = outlines_A[9]; | 191 Element element = outline.element; |
| 173 expect(outline.kind, _OutlineKind.SETTER); | 192 expect(element.kind, ElementKind.GETTER); |
| 174 expect(outline.name, "propB"); | 193 expect(element.name, "propA"); |
| 175 expect(outline.nameOffset, testCode.indexOf("propB(int v) {}")); | 194 expect(element.offset, testCode.indexOf("propA => null;")); |
| 176 expect(outline.nameLength, "propB".length); | 195 expect(element.length, "propA".length); |
| 177 expect(outline.parameters, "(int v)"); | 196 expect(element.parameters, ""); |
| 178 expect(outline.returnType, ""); | 197 expect(element.returnType, "String"); |
| 198 } |
| 199 { |
| 200 Outline outline = outlines_A[9]; |
| 201 Element element = outline.element; |
| 202 expect(element.kind, ElementKind.SETTER); |
| 203 expect(element.name, "propB"); |
| 204 expect(element.offset, testCode.indexOf("propB(int v) {}")); |
| 205 expect(element.length, "propB".length); |
| 206 expect(element.parameters, "(int v)"); |
| 207 expect(element.returnType, ""); |
| 179 } | 208 } |
| 180 } | 209 } |
| 181 // B | 210 // B |
| 182 { | 211 { |
| 183 _Outline outline_B = topOutlines[1]; | 212 Outline outline_B = topOutlines[1]; |
| 184 expect(outline_B.kind, _OutlineKind.CLASS); | 213 Element element_B = outline_B.element; |
| 185 expect(outline_B.name, "B"); | 214 expect(element_B.kind, ElementKind.CLASS); |
| 186 expect(outline_B.nameOffset, testCode.indexOf("B {")); | 215 expect(element_B.name, "B"); |
| 187 expect(outline_B.nameLength, 1); | 216 expect(element_B.offset, testCode.indexOf("B {")); |
| 188 expect(outline_B.parameters, null); | 217 expect(element_B.length, 1); |
| 189 expect(outline_B.returnType, null); | 218 expect(element_B.parameters, null); |
| 219 expect(element_B.returnType, null); |
| 190 // B children | 220 // B children |
| 191 List<_Outline> outlines_B = outline_B.children; | 221 List<Outline> outlines_B = outline_B.children; |
| 192 expect(outlines_B, hasLength(1)); | 222 expect(outlines_B, hasLength(1)); |
| 193 { | 223 { |
| 194 _Outline outline = outlines_B[0]; | 224 Outline outline = outlines_B[0]; |
| 195 expect(outline.kind, _OutlineKind.CONSTRUCTOR); | 225 Element element = outline.element; |
| 196 expect(outline.name, "B"); | 226 expect(element.kind, ElementKind.CONSTRUCTOR); |
| 197 expect(outline.nameOffset, testCode.indexOf("B(int p);")); | 227 expect(element.name, "B"); |
| 198 expect(outline.nameLength, "B".length); | 228 expect(element.offset, testCode.indexOf("B(int p);")); |
| 199 expect(outline.parameters, "(int p)"); | 229 expect(element.length, "B".length); |
| 200 expect(outline.returnType, isNull); | 230 expect(element.parameters, "(int p)"); |
| 231 expect(element.returnType, isNull); |
| 201 } | 232 } |
| 202 } | 233 } |
| 203 }); | 234 }); |
| 204 } | 235 } |
| 205 | 236 |
| 206 test_afterAnalysis() { | 237 test_localFunctions() { |
| 207 addTestFile(''' | 238 addTestFile(''' |
| 208 class AAA { | 239 class A { |
| 240 A() { |
| 241 int local_A() {} |
| 242 } |
| 243 m() { |
| 244 local_m() {} |
| 245 } |
| 209 } | 246 } |
| 210 class BBB { | 247 f() { |
| 248 local_f1(int i) {} |
| 249 local_f2(String s) { |
| 250 local_f21(int p) {} |
| 251 } |
| 211 } | 252 } |
| 212 '''); | 253 '''); |
| 213 return waitForTasksFinished().then((_) { | 254 return prepareOutline(() { |
| 214 expect(outline, isNull); | 255 Outline unitOutline = outline; |
| 215 return prepareOutline(() { | 256 List<Outline> topOutlines = unitOutline.children; |
| 216 _Outline unitOutline = outline; | 257 expect(topOutlines, hasLength(2)); |
| 217 List<_Outline> outlines = unitOutline.children; | 258 // A |
| 218 expect(outlines, hasLength(2)); | 259 { |
| 219 }); | 260 Outline outline_A = topOutlines[0]; |
| 261 Element element_A = outline_A.element; |
| 262 expect(element_A.kind, ElementKind.CLASS); |
| 263 expect(element_A.name, "A"); |
| 264 expect(element_A.offset, testCode.indexOf("A {")); |
| 265 expect(element_A.length, "A".length); |
| 266 expect(element_A.parameters, null); |
| 267 expect(element_A.returnType, null); |
| 268 // A children |
| 269 List<Outline> outlines_A = outline_A.children; |
| 270 expect(outlines_A, hasLength(2)); |
| 271 { |
| 272 Outline constructorOutline = outlines_A[0]; |
| 273 Element constructorElement = constructorOutline.element; |
| 274 expect(constructorElement.kind, ElementKind.CONSTRUCTOR); |
| 275 expect(constructorElement.name, "A"); |
| 276 expect(constructorElement.offset, testCode.indexOf("A() {")); |
| 277 expect(constructorElement.length, "A".length); |
| 278 expect(constructorElement.parameters, "()"); |
| 279 expect(constructorElement.returnType, isNull); |
| 280 // local function |
| 281 List<Outline> outlines_constructor = constructorOutline.children; |
| 282 expect(outlines_constructor, hasLength(1)); |
| 283 { |
| 284 Outline outline = outlines_constructor[0]; |
| 285 Element element = outline.element; |
| 286 expect(element.kind, ElementKind.FUNCTION); |
| 287 expect(element.name, "local_A"); |
| 288 expect(element.offset, testCode.indexOf("local_A() {}")); |
| 289 expect(element.length, "local_A".length); |
| 290 expect(element.parameters, "()"); |
| 291 expect(element.returnType, "int"); |
| 292 } |
| 293 } |
| 294 { |
| 295 Outline outline_m = outlines_A[1]; |
| 296 Element element_m = outline_m.element; |
| 297 expect(element_m.kind, ElementKind.METHOD); |
| 298 expect(element_m.name, "m"); |
| 299 expect(element_m.offset, testCode.indexOf("m() {")); |
| 300 expect(element_m.length, "m".length); |
| 301 expect(element_m.parameters, "()"); |
| 302 expect(element_m.returnType, ""); |
| 303 // local function |
| 304 List<Outline> methodChildren = outline_m.children; |
| 305 expect(methodChildren, hasLength(1)); |
| 306 { |
| 307 Outline outline = methodChildren[0]; |
| 308 Element element = outline.element; |
| 309 expect(element.kind, ElementKind.FUNCTION); |
| 310 expect(element.name, "local_m"); |
| 311 expect(element.offset, testCode.indexOf("local_m() {}")); |
| 312 expect(element.length, "local_m".length); |
| 313 expect(element.parameters, "()"); |
| 314 expect(element.returnType, ""); |
| 315 } |
| 316 } |
| 317 } |
| 318 // f() |
| 319 { |
| 320 Outline outline_f = topOutlines[1]; |
| 321 Element element_f = outline_f.element; |
| 322 expect(element_f.kind, ElementKind.FUNCTION); |
| 323 expect(element_f.name, "f"); |
| 324 expect(element_f.offset, testCode.indexOf("f() {")); |
| 325 expect(element_f.length, "f".length); |
| 326 expect(element_f.parameters, "()"); |
| 327 expect(element_f.returnType, ""); |
| 328 // f() children |
| 329 List<Outline> outlines_f = outline_f.children; |
| 330 expect(outlines_f, hasLength(2)); |
| 331 { |
| 332 Outline outline_f1 = outlines_f[0]; |
| 333 Element element_f1 = outline_f1.element; |
| 334 expect(element_f1.kind, ElementKind.FUNCTION); |
| 335 expect(element_f1.name, "local_f1"); |
| 336 expect(element_f1.offset, testCode.indexOf("local_f1(int i) {}")); |
| 337 expect(element_f1.length, "local_f1".length); |
| 338 expect(element_f1.parameters, "(int i)"); |
| 339 expect(element_f1.returnType, ""); |
| 340 } |
| 341 { |
| 342 Outline outline_f2 = outlines_f[1]; |
| 343 Element element_f2 = outline_f2.element; |
| 344 expect(element_f2.kind, ElementKind.FUNCTION); |
| 345 expect(element_f2.name, "local_f2"); |
| 346 expect(element_f2.offset, testCode.indexOf("local_f2(String s) {")); |
| 347 expect(element_f2.length, "local_f2".length); |
| 348 expect(element_f2.parameters, "(String s)"); |
| 349 expect(element_f2.returnType, ""); |
| 350 // local_f2() local function |
| 351 List<Outline> outlines_f2 = outline_f2.children; |
| 352 expect(outlines_f2, hasLength(1)); |
| 353 { |
| 354 Outline outline_f21 = outlines_f2[0]; |
| 355 Element element_f21 = outline_f21.element; |
| 356 expect(element_f21.kind, ElementKind.FUNCTION); |
| 357 expect(element_f21.name, "local_f21"); |
| 358 expect(element_f21.offset, testCode.indexOf("local_f21(int p) {")); |
| 359 expect(element_f21.length, "local_f21".length); |
| 360 expect(element_f21.parameters, "(int p)"); |
| 361 expect(element_f21.returnType, ""); |
| 362 } |
| 363 } |
| 364 } |
| 220 }); | 365 }); |
| 221 } | 366 } |
| 222 | 367 |
| 223 test_sourceRange_inClass() { | 368 test_sourceRange_inClass() { |
| 224 addTestFile(''' | 369 addTestFile(''' |
| 225 class A { // leftA | 370 class A { // leftA |
| 226 int methodA() {} // endA | 371 int methodA() {} // endA |
| 227 int methodB() {} // endB | 372 int methodB() {} // endB |
| 228 } | 373 } |
| 229 '''); | 374 '''); |
| 230 return prepareOutline(() { | 375 return prepareOutline(() { |
| 231 _Outline unitOutline = outline; | 376 Outline unitOutline = outline; |
| 232 List<_Outline> outlines = unitOutline.children[0].children; | 377 List<Outline> outlines = unitOutline.children[0].children; |
| 233 expect(outlines, hasLength(2)); | 378 expect(outlines, hasLength(2)); |
| 234 // methodA | 379 // methodA |
| 235 { | 380 { |
| 236 _Outline outline = outlines[0]; | 381 Outline outline = outlines[0]; |
| 237 expect(outline.kind, _OutlineKind.METHOD); | 382 Element element = outline.element; |
| 238 expect(outline.name, "methodA"); | 383 expect(element.kind, ElementKind.METHOD); |
| 384 expect(element.name, "methodA"); |
| 239 { | 385 { |
| 240 int offset = testCode.indexOf(" // leftA"); | 386 int offset = testCode.indexOf(" // leftA"); |
| 241 int end = testCode.indexOf(" // endA"); | 387 int end = testCode.indexOf(" // endA"); |
| 242 expect(outline.elementOffset, offset); | 388 expect(outline.offset, offset); |
| 243 expect(outline.elementLength, end - offset); | 389 expect(outline.length, end - offset); |
| 244 } | 390 } |
| 245 } | 391 } |
| 246 // methodB | 392 // methodB |
| 247 { | 393 { |
| 248 _Outline outline = outlines[1]; | 394 Outline outline = outlines[1]; |
| 249 expect(outline.kind, _OutlineKind.METHOD); | 395 Element element = outline.element; |
| 250 expect(outline.name, "methodB"); | 396 expect(element.kind, ElementKind.METHOD); |
| 397 expect(element.name, "methodB"); |
| 251 { | 398 { |
| 252 int offset = testCode.indexOf(" // endA"); | 399 int offset = testCode.indexOf(" // endA"); |
| 253 int end = testCode.indexOf(" // endB"); | 400 int end = testCode.indexOf(" // endB"); |
| 254 expect(outline.elementOffset, offset); | 401 expect(outline.offset, offset); |
| 255 expect(outline.elementLength, end - offset); | 402 expect(outline.length, end - offset); |
| 256 } | 403 } |
| 257 } | 404 } |
| 258 }); | 405 }); |
| 259 } | 406 } |
| 260 | 407 |
| 261 test_sourceRange_inClass_inVariableList() { | 408 test_sourceRange_inClass_inVariableList() { |
| 262 addTestFile(''' | 409 addTestFile(''' |
| 263 class A { // leftA | 410 class A { // leftA |
| 264 int fieldA, fieldB, fieldC; // marker | 411 int fieldA, fieldB, fieldC; // marker |
| 265 int fieldD; // marker2 | 412 int fieldD; // marker2 |
| 266 } | 413 } |
| 267 '''); | 414 '''); |
| 268 return prepareOutline(() { | 415 return prepareOutline(() { |
| 269 _Outline unitOutline = outline; | 416 Outline unitOutline = outline; |
| 270 List<_Outline> outlines = unitOutline.children[0].children; | 417 List<Outline> outlines = unitOutline.children[0].children; |
| 271 expect(outlines, hasLength(4)); | 418 expect(outlines, hasLength(4)); |
| 272 // fieldA | 419 // fieldA |
| 273 { | 420 { |
| 274 _Outline outline = outlines[0]; | 421 Outline outline = outlines[0]; |
| 275 expect(outline.kind, _OutlineKind.FIELD); | 422 Element element = outline.element; |
| 276 expect(outline.name, "fieldA"); | 423 expect(element.kind, ElementKind.FIELD); |
| 424 expect(element.name, "fieldA"); |
| 277 { | 425 { |
| 278 int offset = testCode.indexOf(" // leftA"); | 426 int offset = testCode.indexOf(" // leftA"); |
| 279 int end = testCode.indexOf(", fieldB"); | 427 int end = testCode.indexOf(", fieldB"); |
| 280 expect(outline.elementOffset, offset); | 428 expect(outline.offset, offset); |
| 281 expect(outline.elementLength, end - offset); | 429 expect(outline.length, end - offset); |
| 282 } | 430 } |
| 283 } | 431 } |
| 284 // fieldB | 432 // fieldB |
| 285 { | 433 { |
| 286 _Outline outline = outlines[1]; | 434 Outline outline = outlines[1]; |
| 287 expect(outline.kind, _OutlineKind.FIELD); | 435 Element element = outline.element; |
| 288 expect(outline.name, "fieldB"); | 436 expect(element.kind, ElementKind.FIELD); |
| 437 expect(element.name, "fieldB"); |
| 289 { | 438 { |
| 290 int offset = testCode.indexOf(", fieldB"); | 439 int offset = testCode.indexOf(", fieldB"); |
| 291 int end = testCode.indexOf(", fieldC"); | 440 int end = testCode.indexOf(", fieldC"); |
| 292 expect(outline.elementOffset, offset); | 441 expect(outline.offset, offset); |
| 293 expect(outline.elementLength, end - offset); | 442 expect(outline.length, end - offset); |
| 294 } | 443 } |
| 295 } | 444 } |
| 296 // fieldC | 445 // fieldC |
| 297 { | 446 { |
| 298 _Outline outline = outlines[2]; | 447 Outline outline = outlines[2]; |
| 299 expect(outline.kind, _OutlineKind.FIELD); | 448 Element element = outline.element; |
| 300 expect(outline.name, "fieldC"); | 449 expect(element.kind, ElementKind.FIELD); |
| 450 expect(element.name, "fieldC"); |
| 301 { | 451 { |
| 302 int offset = testCode.indexOf(", fieldC"); | 452 int offset = testCode.indexOf(", fieldC"); |
| 303 int end = testCode.indexOf(" // marker"); | 453 int end = testCode.indexOf(" // marker"); |
| 304 expect(outline.elementOffset, offset); | 454 expect(outline.offset, offset); |
| 305 expect(outline.elementLength, end - offset); | 455 expect(outline.length, end - offset); |
| 306 } | 456 } |
| 307 } | 457 } |
| 308 // fieldD | 458 // fieldD |
| 309 { | 459 { |
| 310 _Outline outline = outlines[3]; | 460 Outline outline = outlines[3]; |
| 311 expect(outline.kind, _OutlineKind.FIELD); | 461 Element element = outline.element; |
| 312 expect(outline.name, "fieldD"); | 462 expect(element.kind, ElementKind.FIELD); |
| 463 expect(element.name, "fieldD"); |
| 313 { | 464 { |
| 314 int offset = testCode.indexOf(" // marker"); | 465 int offset = testCode.indexOf(" // marker"); |
| 315 int end = testCode.indexOf(" // marker2"); | 466 int end = testCode.indexOf(" // marker2"); |
| 316 expect(outline.elementOffset, offset); | 467 expect(outline.offset, offset); |
| 317 expect(outline.elementLength, end - offset); | 468 expect(outline.length, end - offset); |
| 318 } | 469 } |
| 319 } | 470 } |
| 320 }); | 471 }); |
| 321 } | 472 } |
| 322 | 473 |
| 323 test_sourceRange_inUnit() { | 474 test_sourceRange_inUnit() { |
| 324 addTestFile(''' | 475 addTestFile(''' |
| 325 class A { | 476 class A { |
| 326 } // endA | 477 } // endA |
| 327 class B { | 478 class B { |
| 328 } // endB | 479 } // endB |
| 329 '''); | 480 '''); |
| 330 return prepareOutline(() { | 481 return prepareOutline(() { |
| 331 _Outline unitOutline = outline; | 482 Outline unitOutline = outline; |
| 332 List<_Outline> topOutlines = unitOutline.children; | 483 List<Outline> topOutlines = unitOutline.children; |
| 333 expect(topOutlines, hasLength(2)); | 484 expect(topOutlines, hasLength(2)); |
| 334 // A | 485 // A |
| 335 { | 486 { |
| 336 _Outline outline = topOutlines[0]; | 487 Outline outline = topOutlines[0]; |
| 337 expect(outline.kind, _OutlineKind.CLASS); | 488 Element element = outline.element; |
| 338 expect(outline.name, "A"); | 489 expect(element.kind, ElementKind.CLASS); |
| 490 expect(element.name, "A"); |
| 339 { | 491 { |
| 340 int offset = 0; | 492 int offset = 0; |
| 341 int end = testCode.indexOf(" // endA"); | 493 int end = testCode.indexOf(" // endA"); |
| 342 expect(outline.elementOffset, offset); | 494 expect(outline.offset, offset); |
| 343 expect(outline.elementLength, end - offset); | 495 expect(outline.length, end - offset); |
| 344 } | 496 } |
| 345 } | 497 } |
| 346 // B | 498 // B |
| 347 { | 499 { |
| 348 _Outline outline = topOutlines[1]; | 500 Outline outline = topOutlines[1]; |
| 349 expect(outline.kind, _OutlineKind.CLASS); | 501 Element element = outline.element; |
| 350 expect(outline.name, "B"); | 502 expect(element.kind, ElementKind.CLASS); |
| 503 expect(element.name, "B"); |
| 351 { | 504 { |
| 352 int offset = testCode.indexOf(" // endA"); | 505 int offset = testCode.indexOf(" // endA"); |
| 353 int end = testCode.indexOf(" // endB"); | 506 int end = testCode.indexOf(" // endB"); |
| 354 expect(outline.elementOffset, offset); | 507 expect(outline.offset, offset); |
| 355 expect(outline.elementLength, end - offset); | 508 expect(outline.length, end - offset); |
| 356 } | 509 } |
| 357 } | 510 } |
| 358 }); | 511 }); |
| 359 } | 512 } |
| 360 | 513 |
| 361 test_sourceRange_inUnit_inVariableList() { | 514 test_sourceRange_inUnit_inVariableList() { |
| 362 addTestFile(''' | 515 addTestFile(''' |
| 363 int fieldA, fieldB, fieldC; // marker | 516 int fieldA, fieldB, fieldC; // marker |
| 364 int fieldD; // marker2 | 517 int fieldD; // marker2 |
| 365 '''); | 518 '''); |
| 366 return prepareOutline(() { | 519 return prepareOutline(() { |
| 367 _Outline unitOutline = outline; | 520 Outline unitOutline = outline; |
| 368 List<_Outline> outlines = unitOutline.children; | 521 List<Outline> outlines = unitOutline.children; |
| 369 expect(outlines, hasLength(4)); | 522 expect(outlines, hasLength(4)); |
| 370 // fieldA | 523 // fieldA |
| 371 { | 524 { |
| 372 _Outline outline = outlines[0]; | 525 Outline outline = outlines[0]; |
| 373 expect(outline.kind, _OutlineKind.TOP_LEVEL_VARIABLE); | 526 Element element = outline.element; |
| 374 expect(outline.name, "fieldA"); | 527 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); |
| 528 expect(element.name, "fieldA"); |
| 375 { | 529 { |
| 376 int offset = 0; | 530 int offset = 0; |
| 377 int end = testCode.indexOf(", fieldB"); | 531 int end = testCode.indexOf(", fieldB"); |
| 378 expect(outline.elementOffset, offset); | 532 expect(outline.offset, offset); |
| 379 expect(outline.elementLength, end - offset); | 533 expect(outline.length, end - offset); |
| 380 } | 534 } |
| 381 } | 535 } |
| 382 // fieldB | 536 // fieldB |
| 383 { | 537 { |
| 384 _Outline outline = outlines[1]; | 538 Outline outline = outlines[1]; |
| 385 expect(outline.kind, _OutlineKind.TOP_LEVEL_VARIABLE); | 539 Element element = outline.element; |
| 386 expect(outline.name, "fieldB"); | 540 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); |
| 541 expect(element.name, "fieldB"); |
| 387 { | 542 { |
| 388 int offset = testCode.indexOf(", fieldB"); | 543 int offset = testCode.indexOf(", fieldB"); |
| 389 int end = testCode.indexOf(", fieldC"); | 544 int end = testCode.indexOf(", fieldC"); |
| 390 expect(outline.elementOffset, offset); | 545 expect(outline.offset, offset); |
| 391 expect(outline.elementLength, end - offset); | 546 expect(outline.length, end - offset); |
| 392 } | 547 } |
| 393 } | 548 } |
| 394 // fieldC | 549 // fieldC |
| 395 { | 550 { |
| 396 _Outline outline = outlines[2]; | 551 Outline outline = outlines[2]; |
| 397 expect(outline.kind, _OutlineKind.TOP_LEVEL_VARIABLE); | 552 Element element = outline.element; |
| 398 expect(outline.name, "fieldC"); | 553 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); |
| 554 expect(element.name, "fieldC"); |
| 399 { | 555 { |
| 400 int offset = testCode.indexOf(", fieldC"); | 556 int offset = testCode.indexOf(", fieldC"); |
| 401 int end = testCode.indexOf(" // marker"); | 557 int end = testCode.indexOf(" // marker"); |
| 402 expect(outline.elementOffset, offset); | 558 expect(outline.offset, offset); |
| 403 expect(outline.elementLength, end - offset); | 559 expect(outline.length, end - offset); |
| 404 } | 560 } |
| 405 } | 561 } |
| 406 // fieldD | 562 // fieldD |
| 407 { | 563 { |
| 408 _Outline outline = outlines[3]; | 564 Outline outline = outlines[3]; |
| 409 expect(outline.kind, _OutlineKind.TOP_LEVEL_VARIABLE); | 565 Element element = outline.element; |
| 410 expect(outline.name, "fieldD"); | 566 expect(element.kind, ElementKind.TOP_LEVEL_VARIABLE); |
| 567 expect(element.name, "fieldD"); |
| 411 { | 568 { |
| 412 int offset = testCode.indexOf(" // marker"); | 569 int offset = testCode.indexOf(" // marker"); |
| 413 int end = testCode.indexOf(" // marker2"); | 570 int end = testCode.indexOf(" // marker2"); |
| 414 expect(outline.elementOffset, offset); | 571 expect(outline.offset, offset); |
| 415 expect(outline.elementLength, end - offset); | 572 expect(outline.length, end - offset); |
| 416 } | 573 } |
| 417 } | 574 } |
| 418 }); | 575 }); |
| 419 } | |
| 420 | |
| 421 test_localFunctions() { | |
| 422 addTestFile(''' | |
| 423 class A { | |
| 424 A() { | |
| 425 int local_A() {} | |
| 426 } | |
| 427 m() { | |
| 428 local_m() {} | |
| 429 } | |
| 430 } | |
| 431 f() { | |
| 432 local_f1(int i) {} | |
| 433 local_f2(String s) { | |
| 434 local_f21(int p) {} | |
| 435 } | |
| 436 } | |
| 437 '''); | |
| 438 return prepareOutline(() { | |
| 439 _Outline unitOutline = outline; | |
| 440 List<_Outline> topOutlines = unitOutline.children; | |
| 441 expect(topOutlines, hasLength(2)); | |
| 442 // A | |
| 443 { | |
| 444 _Outline outline_A = topOutlines[0]; | |
| 445 expect(outline_A.kind, _OutlineKind.CLASS); | |
| 446 expect(outline_A.name, "A"); | |
| 447 expect(outline_A.nameOffset, testCode.indexOf("A {")); | |
| 448 expect(outline_A.nameLength, "A".length); | |
| 449 expect(outline_A.parameters, null); | |
| 450 expect(outline_A.returnType, null); | |
| 451 // A children | |
| 452 List<_Outline> outlines_A = outline_A.children; | |
| 453 expect(outlines_A, hasLength(2)); | |
| 454 { | |
| 455 _Outline constructorOutline = outlines_A[0]; | |
| 456 expect(constructorOutline.kind, _OutlineKind.CONSTRUCTOR); | |
| 457 expect(constructorOutline.name, "A"); | |
| 458 expect(constructorOutline.nameOffset, testCode.indexOf("A() {")); | |
| 459 expect(constructorOutline.nameLength, "A".length); | |
| 460 expect(constructorOutline.parameters, "()"); | |
| 461 expect(constructorOutline.returnType, isNull); | |
| 462 // local function | |
| 463 List<_Outline> outlines_constructor = constructorOutline.children; | |
| 464 expect(outlines_constructor, hasLength(1)); | |
| 465 { | |
| 466 _Outline outline = outlines_constructor[0]; | |
| 467 expect(outline.kind, _OutlineKind.FUNCTION); | |
| 468 expect(outline.name, "local_A"); | |
| 469 expect(outline.nameOffset, testCode.indexOf("local_A() {}")); | |
| 470 expect(outline.nameLength, "local_A".length); | |
| 471 expect(outline.parameters, "()"); | |
| 472 expect(outline.returnType, "int"); | |
| 473 } | |
| 474 } | |
| 475 { | |
| 476 _Outline outline_m = outlines_A[1]; | |
| 477 expect(outline_m.kind, _OutlineKind.METHOD); | |
| 478 expect(outline_m.name, "m"); | |
| 479 expect(outline_m.nameOffset, testCode.indexOf("m() {")); | |
| 480 expect(outline_m.nameLength, "m".length); | |
| 481 expect(outline_m.parameters, "()"); | |
| 482 expect(outline_m.returnType, ""); | |
| 483 // local function | |
| 484 List<_Outline> methodChildren = outline_m.children; | |
| 485 expect(methodChildren, hasLength(1)); | |
| 486 { | |
| 487 _Outline outline = methodChildren[0]; | |
| 488 expect(outline.kind, _OutlineKind.FUNCTION); | |
| 489 expect(outline.name, "local_m"); | |
| 490 expect(outline.nameOffset, testCode.indexOf("local_m() {}")); | |
| 491 expect(outline.nameLength, "local_m".length); | |
| 492 expect(outline.parameters, "()"); | |
| 493 expect(outline.returnType, ""); | |
| 494 } | |
| 495 } | |
| 496 } | |
| 497 // f() | |
| 498 { | |
| 499 _Outline outline_f = topOutlines[1]; | |
| 500 expect(outline_f.kind, _OutlineKind.FUNCTION); | |
| 501 expect(outline_f.name, "f"); | |
| 502 expect(outline_f.nameOffset, testCode.indexOf("f() {")); | |
| 503 expect(outline_f.nameLength, "f".length); | |
| 504 expect(outline_f.parameters, "()"); | |
| 505 expect(outline_f.returnType, ""); | |
| 506 // f() children | |
| 507 List<_Outline> outlines_f = outline_f.children; | |
| 508 expect(outlines_f, hasLength(2)); | |
| 509 { | |
| 510 _Outline outline_f1 = outlines_f[0]; | |
| 511 expect(outline_f1.kind, _OutlineKind.FUNCTION); | |
| 512 expect(outline_f1.name, "local_f1"); | |
| 513 expect(outline_f1.nameOffset, testCode.indexOf("local_f1(int i) {}")); | |
| 514 expect(outline_f1.nameLength, "local_f1".length); | |
| 515 expect(outline_f1.parameters, "(int i)"); | |
| 516 expect(outline_f1.returnType, ""); | |
| 517 } | |
| 518 { | |
| 519 _Outline outline_f2 = outlines_f[1]; | |
| 520 expect(outline_f2.kind, _OutlineKind.FUNCTION); | |
| 521 expect(outline_f2.name, "local_f2"); | |
| 522 expect(outline_f2.nameOffset, testCode.indexOf("local_f2(String s) {")
); | |
| 523 expect(outline_f2.nameLength, "local_f2".length); | |
| 524 expect(outline_f2.parameters, "(String s)"); | |
| 525 expect(outline_f2.returnType, ""); | |
| 526 // local_f2() local function | |
| 527 List<_Outline> outlines_f2 = outline_f2.children; | |
| 528 expect(outlines_f2, hasLength(1)); | |
| 529 { | |
| 530 _Outline outline_f21 = outlines_f2[0]; | |
| 531 expect(outline_f21.kind, _OutlineKind.FUNCTION); | |
| 532 expect(outline_f21.name, "local_f21"); | |
| 533 expect(outline_f21.nameOffset, testCode.indexOf("local_f21(int p) {"
)); | |
| 534 expect(outline_f21.nameLength, "local_f21".length); | |
| 535 expect(outline_f21.parameters, "(int p)"); | |
| 536 expect(outline_f21.returnType, ""); | |
| 537 } | |
| 538 } | |
| 539 } | |
| 540 }); | |
| 541 } | 576 } |
| 542 | 577 |
| 543 test_topLevel() { | 578 test_topLevel() { |
| 544 addTestFile(''' | 579 addTestFile(''' |
| 545 typedef String FTA(int i, String s); | 580 typedef String FTA(int i, String s); |
| 546 typedef FTB(int p); | 581 typedef FTB(int p); |
| 547 class A {} | 582 class A {} |
| 548 class B {} | 583 class B {} |
| 549 class CTA = A with B; | 584 class CTA = A with B; |
| 550 String fA(int i, String s) => null; | 585 String fA(int i, String s) => null; |
| 551 fB(int p) => null; | 586 fB(int p) => null; |
| 552 String get propA => null; | 587 String get propA => null; |
| 553 set propB(int v) {} | 588 set propB(int v) {} |
| 554 '''); | 589 '''); |
| 555 return prepareOutline(() { | 590 return prepareOutline(() { |
| 556 _Outline unitOutline = outline; | 591 Outline unitOutline = outline; |
| 557 List<_Outline> topOutlines = unitOutline.children; | 592 List<Outline> topOutlines = unitOutline.children; |
| 558 expect(topOutlines, hasLength(9)); | 593 expect(topOutlines, hasLength(9)); |
| 559 // FTA | 594 // FTA |
| 560 { | 595 { |
| 561 _Outline outline = topOutlines[0]; | 596 Outline outline = topOutlines[0]; |
| 562 expect(outline.kind, _OutlineKind.FUNCTION_TYPE_ALIAS); | 597 Element element = outline.element; |
| 563 expect(outline.name, "FTA"); | 598 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); |
| 564 expect(outline.nameOffset, testCode.indexOf("FTA(")); | 599 expect(element.name, "FTA"); |
| 565 expect(outline.nameLength, "FTA".length); | 600 expect(element.offset, testCode.indexOf("FTA(")); |
| 566 expect(outline.parameters, "(int i, String s)"); | 601 expect(element.length, "FTA".length); |
| 567 expect(outline.returnType, "String"); | 602 expect(element.parameters, "(int i, String s)"); |
| 603 expect(element.returnType, "String"); |
| 568 } | 604 } |
| 569 // FTB | 605 // FTB |
| 570 { | 606 { |
| 571 _Outline outline = topOutlines[1]; | 607 Outline outline = topOutlines[1]; |
| 572 expect(outline.kind, _OutlineKind.FUNCTION_TYPE_ALIAS); | 608 Element element = outline.element; |
| 573 expect(outline.name, "FTB"); | 609 expect(element.kind, ElementKind.FUNCTION_TYPE_ALIAS); |
| 574 expect(outline.nameOffset, testCode.indexOf("FTB(")); | 610 expect(element.name, "FTB"); |
| 575 expect(outline.nameLength, "FTB".length); | 611 expect(element.offset, testCode.indexOf("FTB(")); |
| 576 expect(outline.parameters, "(int p)"); | 612 expect(element.length, "FTB".length); |
| 577 expect(outline.returnType, ""); | 613 expect(element.parameters, "(int p)"); |
| 614 expect(element.returnType, ""); |
| 578 } | 615 } |
| 579 // CTA | 616 // CTA |
| 580 { | 617 { |
| 581 _Outline outline = topOutlines[4]; | 618 Outline outline = topOutlines[4]; |
| 582 expect(outline.kind, _OutlineKind.CLASS_TYPE_ALIAS); | 619 Element element = outline.element; |
| 583 expect(outline.name, "CTA"); | 620 expect(element.kind, ElementKind.CLASS_TYPE_ALIAS); |
| 584 expect(outline.nameOffset, testCode.indexOf("CTA =")); | 621 expect(element.name, "CTA"); |
| 585 expect(outline.nameLength, "CTA".length); | 622 expect(element.offset, testCode.indexOf("CTA =")); |
| 586 expect(outline.parameters, isNull); | 623 expect(element.length, "CTA".length); |
| 587 expect(outline.returnType, isNull); | 624 expect(element.parameters, isNull); |
| 625 expect(element.returnType, isNull); |
| 588 } | 626 } |
| 589 // fA | 627 // fA |
| 590 { | 628 { |
| 591 _Outline outline = topOutlines[5]; | 629 Outline outline = topOutlines[5]; |
| 592 expect(outline.kind, _OutlineKind.FUNCTION); | 630 Element element = outline.element; |
| 593 expect(outline.name, "fA"); | 631 expect(element.kind, ElementKind.FUNCTION); |
| 594 expect(outline.nameOffset, testCode.indexOf("fA(")); | 632 expect(element.name, "fA"); |
| 595 expect(outline.nameLength, "fA".length); | 633 expect(element.offset, testCode.indexOf("fA(")); |
| 596 expect(outline.parameters, "(int i, String s)"); | 634 expect(element.length, "fA".length); |
| 597 expect(outline.returnType, "String"); | 635 expect(element.parameters, "(int i, String s)"); |
| 636 expect(element.returnType, "String"); |
| 598 } | 637 } |
| 599 // fB | 638 // fB |
| 600 { | 639 { |
| 601 _Outline outline = topOutlines[6]; | 640 Outline outline = topOutlines[6]; |
| 602 expect(outline.kind, _OutlineKind.FUNCTION); | 641 Element element = outline.element; |
| 603 expect(outline.name, "fB"); | 642 expect(element.kind, ElementKind.FUNCTION); |
| 604 expect(outline.nameOffset, testCode.indexOf("fB(")); | 643 expect(element.name, "fB"); |
| 605 expect(outline.nameLength, "fB".length); | 644 expect(element.offset, testCode.indexOf("fB(")); |
| 606 expect(outline.parameters, "(int p)"); | 645 expect(element.length, "fB".length); |
| 607 expect(outline.returnType, ""); | 646 expect(element.parameters, "(int p)"); |
| 647 expect(element.returnType, ""); |
| 608 } | 648 } |
| 609 // propA | 649 // propA |
| 610 { | 650 { |
| 611 _Outline outline = topOutlines[7]; | 651 Outline outline = topOutlines[7]; |
| 612 expect(outline.kind, _OutlineKind.GETTER); | 652 Element element = outline.element; |
| 613 expect(outline.name, "propA"); | 653 expect(element.kind, ElementKind.GETTER); |
| 614 expect(outline.nameOffset, testCode.indexOf("propA => null;")); | 654 expect(element.name, "propA"); |
| 615 expect(outline.nameLength, "propA".length); | 655 expect(element.offset, testCode.indexOf("propA => null;")); |
| 616 expect(outline.parameters, ""); | 656 expect(element.length, "propA".length); |
| 617 expect(outline.returnType, "String"); | 657 expect(element.parameters, ""); |
| 658 expect(element.returnType, "String"); |
| 618 } | 659 } |
| 619 // propB | 660 // propB |
| 620 { | 661 { |
| 621 _Outline outline = topOutlines[8]; | 662 Outline outline = topOutlines[8]; |
| 622 expect(outline.kind, _OutlineKind.SETTER); | 663 Element element = outline.element; |
| 623 expect(outline.name, "propB"); | 664 expect(element.kind, ElementKind.SETTER); |
| 624 expect(outline.nameOffset, testCode.indexOf("propB(int v) {}")); | 665 expect(element.name, "propB"); |
| 625 expect(outline.nameLength, "propB".length); | 666 expect(element.offset, testCode.indexOf("propB(int v) {}")); |
| 626 expect(outline.parameters, "(int v)"); | 667 expect(element.length, "propB".length); |
| 627 expect(outline.returnType, ""); | 668 expect(element.parameters, "(int v)"); |
| 669 expect(element.returnType, ""); |
| 628 } | 670 } |
| 629 }); | 671 }); |
| 630 } | 672 } |
| 631 } | 673 } |
| 632 | |
| 633 | |
| 634 /** | |
| 635 * Element outline kinds. | |
| 636 */ | |
| 637 class _OutlineKind { | |
| 638 static const _OutlineKind CLASS = const _OutlineKind('CLASS'); | |
| 639 static const _OutlineKind CLASS_TYPE_ALIAS = const _OutlineKind('CLASS_TYPE_AL
IAS'); | |
| 640 static const _OutlineKind COMPILATION_UNIT = const _OutlineKind('COMPILATION_U
NIT'); | |
| 641 static const _OutlineKind CONSTRUCTOR = const _OutlineKind('CONSTRUCTOR'); | |
| 642 static const _OutlineKind GETTER = const _OutlineKind('GETTER'); | |
| 643 static const _OutlineKind FIELD = const _OutlineKind('FIELD'); | |
| 644 static const _OutlineKind FUNCTION = const _OutlineKind('FUNCTION'); | |
| 645 static const _OutlineKind FUNCTION_TYPE_ALIAS = const _OutlineKind('FUNCTION_T
YPE_ALIAS'); | |
| 646 static const _OutlineKind LIBRARY = const _OutlineKind('LIBRARY'); | |
| 647 static const _OutlineKind METHOD = const _OutlineKind('METHOD'); | |
| 648 static const _OutlineKind SETTER = const _OutlineKind('SETTER'); | |
| 649 static const _OutlineKind TOP_LEVEL_VARIABLE = const _OutlineKind('TOP_LEVEL_V
ARIABLE'); | |
| 650 static const _OutlineKind UNKNOWN = const _OutlineKind('UNKNOWN'); | |
| 651 static const _OutlineKind UNIT_TEST_CASE = const _OutlineKind('UNIT_TEST_CASE'
); | |
| 652 static const _OutlineKind UNIT_TEST_GROUP = const _OutlineKind('UNIT_TEST_GROU
P'); | |
| 653 | |
| 654 final String name; | |
| 655 | |
| 656 const _OutlineKind(this.name); | |
| 657 | |
| 658 static _OutlineKind valueOf(String name) { | |
| 659 ClassMirror classMirror = reflectClass(_OutlineKind); | |
| 660 return classMirror.getField(new Symbol(name)).reflectee; | |
| 661 } | |
| 662 } | |
| 663 | |
| 664 | |
| 665 /** | |
| 666 * An element outline. | |
| 667 */ | |
| 668 class _Outline { | |
| 669 static const List<_Outline> EMPTY_ARRAY = const <_Outline>[]; | |
| 670 | |
| 671 final _OutlineKind kind; | |
| 672 final String name; | |
| 673 final int nameOffset; | |
| 674 final int nameLength; | |
| 675 final int elementOffset; | |
| 676 final int elementLength; | |
| 677 final bool isAbstract; | |
| 678 final bool isStatic; | |
| 679 final String parameters; | |
| 680 final String returnType; | |
| 681 final List<_Outline> children = <_Outline>[]; | |
| 682 | |
| 683 _Outline(this.kind, this.name, | |
| 684 this.nameOffset, this.nameLength, | |
| 685 this.elementOffset, this.elementLength, | |
| 686 this.isAbstract, this.isStatic, | |
| 687 this.parameters, this.returnType); | |
| 688 | |
| 689 factory _Outline.fromJson(Map<String, Object> map) { | |
| 690 _Outline outline = new _Outline( | |
| 691 _OutlineKind.valueOf(map[KIND]), map[NAME], | |
| 692 map[NAME_OFFSET], map[NAME_LENGTH], | |
| 693 map[ELEMENT_OFFSET], map[ELEMENT_LENGTH], | |
| 694 map[IS_ABSTRACT], map[IS_STATIC], | |
| 695 map[PARAMETERS], map[RETURN_TYPE]); | |
| 696 List<Map<String, Object>> childrenMaps = map[CHILDREN]; | |
| 697 if (childrenMaps != null) { | |
| 698 childrenMaps.forEach((childMap) { | |
| 699 outline.children.add(new _Outline.fromJson(childMap)); | |
| 700 }); | |
| 701 } | |
| 702 return outline; | |
| 703 } | |
| 704 } | |
| OLD | NEW |