| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // first child: [endOfParent, endOfNode] | 150 // first child: [endOfParent, endOfNode] |
| 151 int index = siblings.indexOf(node); | 151 int index = siblings.indexOf(node); |
| 152 if (index == 0) { | 152 if (index == 0) { |
| 153 return new _SourceRegion(firstOffset, endOffset - firstOffset); | 153 return new _SourceRegion(firstOffset, endOffset - firstOffset); |
| 154 } | 154 } |
| 155 // not first child: [endOfPreviousSibling, endOfNode] | 155 // not first child: [endOfPreviousSibling, endOfNode] |
| 156 int prevSiblingEnd = siblings[index - 1].end; | 156 int prevSiblingEnd = siblings[index - 1].end; |
| 157 return new _SourceRegion(prevSiblingEnd, endOffset - prevSiblingEnd); | 157 return new _SourceRegion(prevSiblingEnd, endOffset - prevSiblingEnd); |
| 158 } | 158 } |
| 159 | 159 |
| 160 Outline _newClassOutline( | 160 Outline _newClassOutline(ClassDeclaration node, List<Outline> classContents) { |
| 161 ClassDeclaration classDeclaration, List<Outline> classContents) { | 161 SimpleIdentifier nameNode = node.name; |
| 162 SimpleIdentifier nameNode = classDeclaration.name; | |
| 163 String name = nameNode.name; | 162 String name = nameNode.name; |
| 164 _SourceRegion sourceRegion = _getSourceRegion(classDeclaration); | 163 _SourceRegion sourceRegion = _getSourceRegion(node); |
| 165 Element element = new Element(ElementKind.CLASS, name, Element.makeFlags( | 164 Element element = new Element(ElementKind.CLASS, name, Element.makeFlags( |
| 166 isPrivate: Identifier.isPrivateName(name), | 165 isPrivate: Identifier.isPrivateName(name), |
| 167 isDeprecated: _isDeprecated(classDeclaration), | 166 isDeprecated: _isDeprecated(node), |
| 168 isAbstract: classDeclaration.isAbstract), | 167 isAbstract: node.isAbstract), |
| 169 location: _getLocationNode(nameNode)); | 168 location: _getLocationNode(nameNode), |
| 169 typeParameters: _getTypeParametersStr(node.typeParameters)); |
| 170 return new Outline(element, sourceRegion.offset, sourceRegion.length, | 170 return new Outline(element, sourceRegion.offset, sourceRegion.length, |
| 171 children: nullIfEmpty(classContents)); | 171 children: nullIfEmpty(classContents)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 Outline _newClassTypeAlias(ClassTypeAlias alias) { | 174 Outline _newClassTypeAlias(ClassTypeAlias node) { |
| 175 SimpleIdentifier nameNode = alias.name; | 175 SimpleIdentifier nameNode = node.name; |
| 176 String name = nameNode.name; | 176 String name = nameNode.name; |
| 177 _SourceRegion sourceRegion = _getSourceRegion(alias); | 177 _SourceRegion sourceRegion = _getSourceRegion(node); |
| 178 Element element = new Element(ElementKind.CLASS_TYPE_ALIAS, name, Element | 178 Element element = new Element(ElementKind.CLASS_TYPE_ALIAS, name, Element |
| 179 .makeFlags( | 179 .makeFlags( |
| 180 isPrivate: Identifier.isPrivateName(name), | 180 isPrivate: Identifier.isPrivateName(name), |
| 181 isDeprecated: _isDeprecated(alias), | 181 isDeprecated: _isDeprecated(node), |
| 182 isAbstract: alias.isAbstract), | 182 isAbstract: node.isAbstract), |
| 183 location: _getLocationNode(nameNode)); | 183 location: _getLocationNode(nameNode), |
| 184 typeParameters: _getTypeParametersStr(node.typeParameters)); |
| 184 return new Outline(element, sourceRegion.offset, sourceRegion.length); | 185 return new Outline(element, sourceRegion.offset, sourceRegion.length); |
| 185 } | 186 } |
| 186 | 187 |
| 187 Outline _newConstructorOutline(ConstructorDeclaration constructor) { | 188 Outline _newConstructorOutline(ConstructorDeclaration constructor) { |
| 188 Identifier returnType = constructor.returnType; | 189 Identifier returnType = constructor.returnType; |
| 189 String name = returnType.name; | 190 String name = returnType.name; |
| 190 int offset = returnType.offset; | 191 int offset = returnType.offset; |
| 191 int length = returnType.length; | 192 int length = returnType.length; |
| 192 SimpleIdentifier constructorNameNode = constructor.name; | 193 SimpleIdentifier constructorNameNode = constructor.name; |
| 193 bool isPrivate = false; | 194 bool isPrivate = false; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 location: _getLocationNode(nameNode), | 262 location: _getLocationNode(nameNode), |
| 262 parameters: parametersStr, | 263 parameters: parametersStr, |
| 263 returnType: returnTypeStr); | 264 returnType: returnTypeStr); |
| 264 List<Outline> contents = _addLocalFunctionOutlines(functionExpression.body); | 265 List<Outline> contents = _addLocalFunctionOutlines(functionExpression.body); |
| 265 Outline outline = new Outline( | 266 Outline outline = new Outline( |
| 266 element, sourceRegion.offset, sourceRegion.length, | 267 element, sourceRegion.offset, sourceRegion.length, |
| 267 children: nullIfEmpty(contents)); | 268 children: nullIfEmpty(contents)); |
| 268 return outline; | 269 return outline; |
| 269 } | 270 } |
| 270 | 271 |
| 271 Outline _newFunctionTypeAliasOutline(FunctionTypeAlias alias) { | 272 Outline _newFunctionTypeAliasOutline(FunctionTypeAlias node) { |
| 272 TypeName returnType = alias.returnType; | 273 TypeName returnType = node.returnType; |
| 273 SimpleIdentifier nameNode = alias.name; | 274 SimpleIdentifier nameNode = node.name; |
| 274 String name = nameNode.name; | 275 String name = nameNode.name; |
| 275 _SourceRegion sourceRegion = _getSourceRegion(alias); | 276 _SourceRegion sourceRegion = _getSourceRegion(node); |
| 276 FormalParameterList parameters = alias.parameters; | 277 FormalParameterList parameters = node.parameters; |
| 277 String parametersStr = parameters != null ? parameters.toSource() : ''; | 278 String parametersStr = parameters != null ? parameters.toSource() : ''; |
| 278 String returnTypeStr = returnType != null ? returnType.toSource() : ''; | 279 String returnTypeStr = returnType != null ? returnType.toSource() : ''; |
| 279 Element element = new Element(ElementKind.FUNCTION_TYPE_ALIAS, name, Element | 280 Element element = new Element(ElementKind.FUNCTION_TYPE_ALIAS, name, Element |
| 280 .makeFlags( | 281 .makeFlags( |
| 281 isPrivate: Identifier.isPrivateName(name), | 282 isPrivate: Identifier.isPrivateName(name), |
| 282 isDeprecated: _isDeprecated(alias)), | 283 isDeprecated: _isDeprecated(node)), |
| 283 location: _getLocationNode(nameNode), | 284 location: _getLocationNode(nameNode), |
| 284 parameters: parametersStr, | 285 parameters: parametersStr, |
| 285 returnType: returnTypeStr); | 286 returnType: returnTypeStr, |
| 287 typeParameters: _getTypeParametersStr(node.typeParameters)); |
| 286 return new Outline(element, sourceRegion.offset, sourceRegion.length); | 288 return new Outline(element, sourceRegion.offset, sourceRegion.length); |
| 287 } | 289 } |
| 288 | 290 |
| 289 Outline _newMethodOutline(MethodDeclaration method) { | 291 Outline _newMethodOutline(MethodDeclaration method) { |
| 290 TypeName returnType = method.returnType; | 292 TypeName returnType = method.returnType; |
| 291 SimpleIdentifier nameNode = method.name; | 293 SimpleIdentifier nameNode = method.name; |
| 292 String name = nameNode.name; | 294 String name = nameNode.name; |
| 293 FormalParameterList parameters = method.parameters; | 295 FormalParameterList parameters = method.parameters; |
| 294 ElementKind kind; | 296 ElementKind kind; |
| 295 if (method.isGetter) { | 297 if (method.isGetter) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 318 } | 320 } |
| 319 | 321 |
| 320 Outline _newUnitOutline(List<Outline> unitContents) { | 322 Outline _newUnitOutline(List<Outline> unitContents) { |
| 321 Element element = new Element( | 323 Element element = new Element( |
| 322 ElementKind.COMPILATION_UNIT, '<unit>', Element.makeFlags(), | 324 ElementKind.COMPILATION_UNIT, '<unit>', Element.makeFlags(), |
| 323 location: _getLocationNode(unit)); | 325 location: _getLocationNode(unit)); |
| 324 return new Outline(element, unit.offset, unit.length, | 326 return new Outline(element, unit.offset, unit.length, |
| 325 children: nullIfEmpty(unitContents)); | 327 children: nullIfEmpty(unitContents)); |
| 326 } | 328 } |
| 327 | 329 |
| 330 static String _getTypeParametersStr(TypeParameterList parameters) { |
| 331 if (parameters == null) { |
| 332 return null; |
| 333 } |
| 334 return parameters.toSource(); |
| 335 } |
| 336 |
| 328 Outline _newVariableOutline(String typeName, ElementKind kind, | 337 Outline _newVariableOutline(String typeName, ElementKind kind, |
| 329 VariableDeclaration variable, bool isStatic) { | 338 VariableDeclaration variable, bool isStatic) { |
| 330 SimpleIdentifier nameNode = variable.name; | 339 SimpleIdentifier nameNode = variable.name; |
| 331 String name = nameNode.name; | 340 String name = nameNode.name; |
| 332 _SourceRegion sourceRegion = _getSourceRegion(variable); | 341 _SourceRegion sourceRegion = _getSourceRegion(variable); |
| 333 Element element = new Element(kind, name, Element.makeFlags( | 342 Element element = new Element(kind, name, Element.makeFlags( |
| 334 isPrivate: Identifier.isPrivateName(name), | 343 isPrivate: Identifier.isPrivateName(name), |
| 335 isDeprecated: _isDeprecated(variable), | 344 isDeprecated: _isDeprecated(variable), |
| 336 isStatic: isStatic, | 345 isStatic: isStatic, |
| 337 isConst: variable.isConst, | 346 isConst: variable.isConst, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 367 } | 376 } |
| 368 | 377 |
| 369 /** | 378 /** |
| 370 * A range of characters. | 379 * A range of characters. |
| 371 */ | 380 */ |
| 372 class _SourceRegion { | 381 class _SourceRegion { |
| 373 final int length; | 382 final int length; |
| 374 final int offset; | 383 final int offset; |
| 375 _SourceRegion(this.offset, this.length); | 384 _SourceRegion(this.offset, this.length); |
| 376 } | 385 } |
| OLD | NEW |