| 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 computer.outline; | 5 library computer.outline; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 7 import 'package:analysis_server/src/collections.dart'; | 8 import 'package:analysis_server/src/collections.dart'; |
| 8 import 'package:analysis_server/src/protocol.dart'; | |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart' as engine; | 10 import 'package:analyzer/src/generated/element.dart' as engine; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * A computer for [CompilationUnit] outline. | 14 * A computer for [CompilationUnit] outline. |
| 15 */ | 15 */ |
| 16 class DartUnitOutlineComputer { | 16 class DartUnitOutlineComputer { |
| 17 final String file; | 17 final String file; |
| 18 final CompilationUnit unit; | 18 final CompilationUnit unit; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 339 } |
| 340 | 340 |
| 341 Outline _newUnitOutline(List<Outline> unitContents) { | 341 Outline _newUnitOutline(List<Outline> unitContents) { |
| 342 Element element = new Element( | 342 Element element = new Element( |
| 343 ElementKind.COMPILATION_UNIT, '<unit>', Element.makeFlags(), | 343 ElementKind.COMPILATION_UNIT, '<unit>', Element.makeFlags(), |
| 344 location: _getLocationNode(unit)); | 344 location: _getLocationNode(unit)); |
| 345 return new Outline(element, unit.offset, unit.length, | 345 return new Outline(element, unit.offset, unit.length, |
| 346 children: nullIfEmpty(unitContents)); | 346 children: nullIfEmpty(unitContents)); |
| 347 } | 347 } |
| 348 | 348 |
| 349 static String _getTypeParametersStr(TypeParameterList parameters) { | |
| 350 if (parameters == null) { | |
| 351 return null; | |
| 352 } | |
| 353 return parameters.toSource(); | |
| 354 } | |
| 355 | |
| 356 Outline _newVariableOutline(String typeName, ElementKind kind, | 349 Outline _newVariableOutline(String typeName, ElementKind kind, |
| 357 VariableDeclaration variable, bool isStatic) { | 350 VariableDeclaration variable, bool isStatic) { |
| 358 SimpleIdentifier nameNode = variable.name; | 351 SimpleIdentifier nameNode = variable.name; |
| 359 String name = nameNode.name; | 352 String name = nameNode.name; |
| 360 _SourceRegion sourceRegion = _getSourceRegion(variable); | 353 _SourceRegion sourceRegion = _getSourceRegion(variable); |
| 361 Element element = new Element( | 354 Element element = new Element( |
| 362 kind, | 355 kind, |
| 363 name, | 356 name, |
| 364 Element.makeFlags( | 357 Element.makeFlags( |
| 365 isPrivate: Identifier.isPrivateName(name), | 358 isPrivate: Identifier.isPrivateName(name), |
| 366 isDeprecated: _isDeprecated(variable), | 359 isDeprecated: _isDeprecated(variable), |
| 367 isStatic: isStatic, | 360 isStatic: isStatic, |
| 368 isConst: variable.isConst, | 361 isConst: variable.isConst, |
| 369 isFinal: variable.isFinal), | 362 isFinal: variable.isFinal), |
| 370 location: _getLocationNode(nameNode), | 363 location: _getLocationNode(nameNode), |
| 371 returnType: typeName); | 364 returnType: typeName); |
| 372 Outline outline = | 365 Outline outline = |
| 373 new Outline(element, sourceRegion.offset, sourceRegion.length); | 366 new Outline(element, sourceRegion.offset, sourceRegion.length); |
| 374 return outline; | 367 return outline; |
| 375 } | 368 } |
| 376 | 369 |
| 370 static String _getTypeParametersStr(TypeParameterList parameters) { |
| 371 if (parameters == null) { |
| 372 return null; |
| 373 } |
| 374 return parameters.toSource(); |
| 375 } |
| 376 |
| 377 /** | 377 /** |
| 378 * Returns `true` if the given [element] is not `null` and deprecated. | 378 * Returns `true` if the given [element] is not `null` and deprecated. |
| 379 */ | 379 */ |
| 380 static bool _isDeprecated(Declaration declaration) { | 380 static bool _isDeprecated(Declaration declaration) { |
| 381 engine.Element element = declaration.element; | 381 engine.Element element = declaration.element; |
| 382 return element != null && element.isDeprecated; | 382 return element != null && element.isDeprecated; |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 | 385 |
| 386 /** | 386 /** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 399 } | 399 } |
| 400 | 400 |
| 401 /** | 401 /** |
| 402 * A range of characters. | 402 * A range of characters. |
| 403 */ | 403 */ |
| 404 class _SourceRegion { | 404 class _SourceRegion { |
| 405 final int length; | 405 final int length; |
| 406 final int offset; | 406 final int offset; |
| 407 _SourceRegion(this.offset, this.length); | 407 _SourceRegion(this.offset, this.length); |
| 408 } | 408 } |
| OLD | NEW |