| 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/src/collections.dart'; | 7 import 'package:analysis_server/src/collections.dart'; |
| 8 import 'package:analysis_server/src/protocol.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; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 if (classMember is MethodDeclaration) { | 55 if (classMember is MethodDeclaration) { |
| 56 MethodDeclaration methodDeclaration = classMember; | 56 MethodDeclaration methodDeclaration = classMember; |
| 57 classContents.add(_newMethodOutline(methodDeclaration)); | 57 classContents.add(_newMethodOutline(methodDeclaration)); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 unitContents.add(_newClassOutline(classDeclaration, classContents)); | 60 unitContents.add(_newClassOutline(classDeclaration, classContents)); |
| 61 } | 61 } |
| 62 if (unitMember is EnumDeclaration) { |
| 63 EnumDeclaration enumDeclaration = unitMember; |
| 64 List<Outline> constantOutlines = <Outline>[]; |
| 65 for (EnumConstantDeclaration constant in enumDeclaration.constants) { |
| 66 constantOutlines.add(_newEnumConstant(constant)); |
| 67 } |
| 68 unitContents.add(_newEnumOutline(enumDeclaration, constantOutlines)); |
| 69 } |
| 62 if (unitMember is TopLevelVariableDeclaration) { | 70 if (unitMember is TopLevelVariableDeclaration) { |
| 63 TopLevelVariableDeclaration fieldDeclaration = unitMember; | 71 TopLevelVariableDeclaration fieldDeclaration = unitMember; |
| 64 VariableDeclarationList fields = fieldDeclaration.variables; | 72 VariableDeclarationList fields = fieldDeclaration.variables; |
| 65 if (fields != null) { | 73 if (fields != null) { |
| 66 TypeName fieldType = fields.type; | 74 TypeName fieldType = fields.type; |
| 67 String fieldTypeName = fieldType != null ? fieldType.toSource() : ''; | 75 String fieldTypeName = fieldType != null ? fieldType.toSource() : ''; |
| 68 for (VariableDeclaration field in fields.variables) { | 76 for (VariableDeclaration field in fields.variables) { |
| 69 unitContents.add( | 77 unitContents.add( |
| 70 _newVariableOutline( | 78 _newVariableOutline( |
| 71 fieldTypeName, | 79 fieldTypeName, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 parameters: parametersStr); | 228 parameters: parametersStr); |
| 221 List<Outline> contents = _addLocalFunctionOutlines(constructor.body); | 229 List<Outline> contents = _addLocalFunctionOutlines(constructor.body); |
| 222 Outline outline = new Outline( | 230 Outline outline = new Outline( |
| 223 element, | 231 element, |
| 224 sourceRegion.offset, | 232 sourceRegion.offset, |
| 225 sourceRegion.length, | 233 sourceRegion.length, |
| 226 children: nullIfEmpty(contents)); | 234 children: nullIfEmpty(contents)); |
| 227 return outline; | 235 return outline; |
| 228 } | 236 } |
| 229 | 237 |
| 238 Outline _newEnumConstant(EnumConstantDeclaration node) { |
| 239 SimpleIdentifier nameNode = node.name; |
| 240 String name = nameNode.name; |
| 241 _SourceRegion sourceRegion = _getSourceRegion(node); |
| 242 Element element = new Element( |
| 243 ElementKind.ENUM_CONSTANT, |
| 244 name, |
| 245 Element.makeFlags( |
| 246 isPrivate: Identifier.isPrivateName(name), |
| 247 isDeprecated: _isDeprecated(node)), |
| 248 location: _getLocationNode(nameNode)); |
| 249 return new Outline(element, sourceRegion.offset, sourceRegion.length); |
| 250 } |
| 251 |
| 252 Outline _newEnumOutline(EnumDeclaration node, List<Outline> children) { |
| 253 SimpleIdentifier nameNode = node.name; |
| 254 String name = nameNode.name; |
| 255 _SourceRegion sourceRegion = _getSourceRegion(node); |
| 256 Element element = new Element( |
| 257 ElementKind.ENUM, |
| 258 name, |
| 259 Element.makeFlags( |
| 260 isPrivate: Identifier.isPrivateName(name), |
| 261 isDeprecated: _isDeprecated(node)), |
| 262 location: _getLocationNode(nameNode)); |
| 263 return new Outline( |
| 264 element, |
| 265 sourceRegion.offset, |
| 266 sourceRegion.length, |
| 267 children: nullIfEmpty(children)); |
| 268 } |
| 269 |
| 230 Outline _newFunctionOutline(FunctionDeclaration function, bool isStatic) { | 270 Outline _newFunctionOutline(FunctionDeclaration function, bool isStatic) { |
| 231 TypeName returnType = function.returnType; | 271 TypeName returnType = function.returnType; |
| 232 SimpleIdentifier nameNode = function.name; | 272 SimpleIdentifier nameNode = function.name; |
| 233 String name = nameNode.name; | 273 String name = nameNode.name; |
| 234 FunctionExpression functionExpression = function.functionExpression; | 274 FunctionExpression functionExpression = function.functionExpression; |
| 235 FormalParameterList parameters = functionExpression.parameters; | 275 FormalParameterList parameters = functionExpression.parameters; |
| 236 ElementKind kind; | 276 ElementKind kind; |
| 237 if (function.isGetter) { | 277 if (function.isGetter) { |
| 238 kind = ElementKind.GETTER; | 278 kind = ElementKind.GETTER; |
| 239 } else if (function.isSetter) { | 279 } else if (function.isSetter) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 420 |
| 381 | 421 |
| 382 /** | 422 /** |
| 383 * A range of characters. | 423 * A range of characters. |
| 384 */ | 424 */ |
| 385 class _SourceRegion { | 425 class _SourceRegion { |
| 386 final int length; | 426 final int length; |
| 387 final int offset; | 427 final int offset; |
| 388 _SourceRegion(this.offset, this.length); | 428 _SourceRegion(this.offset, this.length); |
| 389 } | 429 } |
| OLD | NEW |