| 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 protocol.server; | 5 library protocol.server; |
| 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/search/search_engine.dart' as | 8 import 'package:analysis_server/src/services/search/search_engine.dart' as |
| 9 engine; | 9 engine; |
| 10 import 'package:analyzer/src/generated/ast.dart' as engine; | 10 import 'package:analyzer/src/generated/ast.dart' as engine; |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } else { | 323 } else { |
| 324 element = element.enclosingElement; | 324 element = element.enclosingElement; |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 return path; | 327 return path; |
| 328 } | 328 } |
| 329 | 329 |
| 330 | 330 |
| 331 String _getParametersString(engine.Element element) { | 331 String _getParametersString(engine.Element element) { |
| 332 // TODO(scheglov) expose the corresponding feature from ExecutableElement | 332 // TODO(scheglov) expose the corresponding feature from ExecutableElement |
| 333 List<engine.ParameterElement> parameters; |
| 333 if (element is engine.ExecutableElement) { | 334 if (element is engine.ExecutableElement) { |
| 334 // valid getters don't have parameters | 335 // valid getters don't have parameters |
| 335 if (element.kind == engine.ElementKind.GETTER && | 336 if (element.kind == engine.ElementKind.GETTER && |
| 336 element.parameters.isEmpty) { | 337 element.parameters.isEmpty) { |
| 337 return null; | 338 return null; |
| 338 } | 339 } |
| 339 // append parameters | 340 parameters = element.parameters; |
| 340 StringBuffer sb = new StringBuffer(); | 341 } else if (element is engine.FunctionTypeAliasElement) { |
| 341 String closeOptionalString = ''; | 342 parameters = element.parameters; |
| 342 for (engine.ParameterElement parameter in element.parameters) { | |
| 343 if (sb.isNotEmpty) { | |
| 344 sb.write(', '); | |
| 345 } | |
| 346 if (closeOptionalString.isEmpty) { | |
| 347 if (parameter.kind == engine.ParameterKind.NAMED) { | |
| 348 sb.write('{'); | |
| 349 closeOptionalString = '}'; | |
| 350 } | |
| 351 if (parameter.kind == engine.ParameterKind.POSITIONAL) { | |
| 352 sb.write('['); | |
| 353 closeOptionalString = ']'; | |
| 354 } | |
| 355 } | |
| 356 sb.write(parameter.toString()); | |
| 357 } | |
| 358 sb.write(closeOptionalString); | |
| 359 return '(' + sb.toString() + ')'; | |
| 360 } else { | 343 } else { |
| 361 return null; | 344 return null; |
| 362 } | 345 } |
| 346 StringBuffer sb = new StringBuffer(); |
| 347 String closeOptionalString = ''; |
| 348 for (engine.ParameterElement parameter in parameters) { |
| 349 if (sb.isNotEmpty) { |
| 350 sb.write(', '); |
| 351 } |
| 352 if (closeOptionalString.isEmpty) { |
| 353 if (parameter.kind == engine.ParameterKind.NAMED) { |
| 354 sb.write('{'); |
| 355 closeOptionalString = '}'; |
| 356 } |
| 357 if (parameter.kind == engine.ParameterKind.POSITIONAL) { |
| 358 sb.write('['); |
| 359 closeOptionalString = ']'; |
| 360 } |
| 361 } |
| 362 sb.write(parameter.toString()); |
| 363 } |
| 364 sb.write(closeOptionalString); |
| 365 return '(' + sb.toString() + ')'; |
| 363 } | 366 } |
| 364 | 367 |
| 365 | |
| 366 String _getReturnTypeString(engine.Element element) { | 368 String _getReturnTypeString(engine.Element element) { |
| 367 if (element is engine.ExecutableElement) { | 369 if (element is engine.ExecutableElement) { |
| 368 if (element.kind == engine.ElementKind.SETTER) { | 370 if (element.kind == engine.ElementKind.SETTER) { |
| 369 return null; | 371 return null; |
| 370 } else { | 372 } else { |
| 371 return element.returnType.toString(); | 373 return element.returnType.toString(); |
| 372 } | 374 } |
| 373 } else if (element is engine.VariableElement) { | 375 } else if (element is engine.VariableElement) { |
| 374 engine.DartType type = element.type; | 376 engine.DartType type = element.type; |
| 375 return type != null ? type.displayName : 'dynamic'; | 377 return type != null ? type.displayName : 'dynamic'; |
| 378 } else if (element is engine.FunctionTypeAliasElement) { |
| 379 return element.returnType.toString(); |
| 376 } else { | 380 } else { |
| 377 return null; | 381 return null; |
| 378 } | 382 } |
| 379 } | 383 } |
| 380 | 384 |
| 381 bool _isAbstract(engine.Element element) { | 385 bool _isAbstract(engine.Element element) { |
| 382 // TODO(scheglov) add isAbstract to Element API | 386 // TODO(scheglov) add isAbstract to Element API |
| 383 if (element is engine.ClassElement) { | 387 if (element is engine.ClassElement) { |
| 384 return element.isAbstract; | 388 return element.isAbstract; |
| 385 } | 389 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 startColumn = offsetLocation.columnNumber; | 442 startColumn = offsetLocation.columnNumber; |
| 439 } | 443 } |
| 440 } | 444 } |
| 441 return new Location( | 445 return new Location( |
| 442 source.fullName, | 446 source.fullName, |
| 443 range.offset, | 447 range.offset, |
| 444 range.length, | 448 range.length, |
| 445 startLine, | 449 startLine, |
| 446 startColumn); | 450 startColumn); |
| 447 } | 451 } |
| OLD | NEW |