Chromium Code Reviews| 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/protocol.dart'; | 8 import 'package:analysis_server/src/protocol.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart' as engine; | 10 import 'package:analyzer/src/generated/element.dart' as engine; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 12 | 13 |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * A computer for [CompilationUnit] outline. | 16 * A computer for [CompilationUnit] outline. |
| 16 */ | 17 */ |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 name, | 172 name, |
| 172 Element.makeFlags( | 173 Element.makeFlags( |
| 173 isPrivate: Identifier.isPrivateName(name), | 174 isPrivate: Identifier.isPrivateName(name), |
| 174 isDeprecated: _isDeprecated(classDeclaration), | 175 isDeprecated: _isDeprecated(classDeclaration), |
| 175 isAbstract: classDeclaration.isAbstract), | 176 isAbstract: classDeclaration.isAbstract), |
| 176 location: _getLocationNode(nameNode)); | 177 location: _getLocationNode(nameNode)); |
| 177 return new Outline( | 178 return new Outline( |
| 178 element, | 179 element, |
| 179 sourceRegion.offset, | 180 sourceRegion.offset, |
| 180 sourceRegion.length, | 181 sourceRegion.length, |
| 181 children: classContents.isEmpty ? null : classContents); | 182 children: nullIfEmpty(classContents)); |
|
scheglov
2014/10/06 17:53:35
Actually, we could probably change the Outline con
| |
| 182 } | 183 } |
| 183 | 184 |
| 184 Outline _newClassTypeAlias(ClassTypeAlias alias) { | 185 Outline _newClassTypeAlias(ClassTypeAlias alias) { |
| 185 SimpleIdentifier nameNode = alias.name; | 186 SimpleIdentifier nameNode = alias.name; |
| 186 String name = nameNode.name; | 187 String name = nameNode.name; |
| 187 _SourceRegion sourceRegion = _getSourceRegion(alias); | 188 _SourceRegion sourceRegion = _getSourceRegion(alias); |
| 188 Element element = new Element( | 189 Element element = new Element( |
| 189 ElementKind.CLASS_TYPE_ALIAS, | 190 ElementKind.CLASS_TYPE_ALIAS, |
| 190 name, | 191 name, |
| 191 Element.makeFlags( | 192 Element.makeFlags( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 219 Element.makeFlags( | 220 Element.makeFlags( |
| 220 isPrivate: isPrivate, | 221 isPrivate: isPrivate, |
| 221 isDeprecated: _isDeprecated(constructor)), | 222 isDeprecated: _isDeprecated(constructor)), |
| 222 location: _getLocationOffsetLength(offset, length), | 223 location: _getLocationOffsetLength(offset, length), |
| 223 parameters: parametersStr); | 224 parameters: parametersStr); |
| 224 List<Outline> contents = _addLocalFunctionOutlines(constructor.body); | 225 List<Outline> contents = _addLocalFunctionOutlines(constructor.body); |
| 225 Outline outline = new Outline( | 226 Outline outline = new Outline( |
| 226 element, | 227 element, |
| 227 sourceRegion.offset, | 228 sourceRegion.offset, |
| 228 sourceRegion.length, | 229 sourceRegion.length, |
| 229 children: contents.isEmpty ? null : contents); | 230 children: nullIfEmpty(contents)); |
| 230 return outline; | 231 return outline; |
| 231 } | 232 } |
| 232 | 233 |
| 233 Outline _newFunctionOutline(FunctionDeclaration function, bool isStatic) { | 234 Outline _newFunctionOutline(FunctionDeclaration function, bool isStatic) { |
| 234 TypeName returnType = function.returnType; | 235 TypeName returnType = function.returnType; |
| 235 SimpleIdentifier nameNode = function.name; | 236 SimpleIdentifier nameNode = function.name; |
| 236 String name = nameNode.name; | 237 String name = nameNode.name; |
| 237 FunctionExpression functionExpression = function.functionExpression; | 238 FunctionExpression functionExpression = function.functionExpression; |
| 238 FormalParameterList parameters = functionExpression.parameters; | 239 FormalParameterList parameters = functionExpression.parameters; |
| 239 ElementKind kind; | 240 ElementKind kind; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 255 isDeprecated: _isDeprecated(function), | 256 isDeprecated: _isDeprecated(function), |
| 256 isStatic: isStatic), | 257 isStatic: isStatic), |
| 257 location: _getLocationNode(nameNode), | 258 location: _getLocationNode(nameNode), |
| 258 parameters: parametersStr, | 259 parameters: parametersStr, |
| 259 returnType: returnTypeStr); | 260 returnType: returnTypeStr); |
| 260 List<Outline> contents = _addLocalFunctionOutlines(functionExpression.body); | 261 List<Outline> contents = _addLocalFunctionOutlines(functionExpression.body); |
| 261 Outline outline = new Outline( | 262 Outline outline = new Outline( |
| 262 element, | 263 element, |
| 263 sourceRegion.offset, | 264 sourceRegion.offset, |
| 264 sourceRegion.length, | 265 sourceRegion.length, |
| 265 children: contents.isEmpty ? null : contents); | 266 children: nullIfEmpty(contents)); |
| 266 return outline; | 267 return outline; |
| 267 } | 268 } |
| 268 | 269 |
| 269 Outline _newFunctionTypeAliasOutline(FunctionTypeAlias alias) { | 270 Outline _newFunctionTypeAliasOutline(FunctionTypeAlias alias) { |
| 270 TypeName returnType = alias.returnType; | 271 TypeName returnType = alias.returnType; |
| 271 SimpleIdentifier nameNode = alias.name; | 272 SimpleIdentifier nameNode = alias.name; |
| 272 String name = nameNode.name; | 273 String name = nameNode.name; |
| 273 _SourceRegion sourceRegion = _getSourceRegion(alias); | 274 _SourceRegion sourceRegion = _getSourceRegion(alias); |
| 274 FormalParameterList parameters = alias.parameters; | 275 FormalParameterList parameters = alias.parameters; |
| 275 String parametersStr = parameters != null ? parameters.toSource() : ''; | 276 String parametersStr = parameters != null ? parameters.toSource() : ''; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 isAbstract: method.isAbstract, | 312 isAbstract: method.isAbstract, |
| 312 isStatic: method.isStatic), | 313 isStatic: method.isStatic), |
| 313 location: _getLocationNode(nameNode), | 314 location: _getLocationNode(nameNode), |
| 314 parameters: parametersStr, | 315 parameters: parametersStr, |
| 315 returnType: returnTypeStr); | 316 returnType: returnTypeStr); |
| 316 List<Outline> contents = _addLocalFunctionOutlines(method.body); | 317 List<Outline> contents = _addLocalFunctionOutlines(method.body); |
| 317 Outline outline = new Outline( | 318 Outline outline = new Outline( |
| 318 element, | 319 element, |
| 319 sourceRegion.offset, | 320 sourceRegion.offset, |
| 320 sourceRegion.length, | 321 sourceRegion.length, |
| 321 children: contents.isEmpty ? null : contents); | 322 children: nullIfEmpty(contents)); |
| 322 return outline; | 323 return outline; |
| 323 } | 324 } |
| 324 | 325 |
| 325 Outline _newUnitOutline(List<Outline> unitContents) { | 326 Outline _newUnitOutline(List<Outline> unitContents) { |
| 326 Element element = new Element( | 327 Element element = new Element( |
| 327 ElementKind.COMPILATION_UNIT, | 328 ElementKind.COMPILATION_UNIT, |
| 328 '<unit>', | 329 '<unit>', |
| 329 Element.makeFlags(), | 330 Element.makeFlags(), |
| 330 location: _getLocationNode(_unit)); | 331 location: _getLocationNode(_unit)); |
| 331 return new Outline( | 332 return new Outline( |
| 332 element, | 333 element, |
| 333 _unit.offset, | 334 _unit.offset, |
| 334 _unit.length, | 335 _unit.length, |
| 335 children: unitContents.isEmpty ? null : unitContents); | 336 children: nullIfEmpty(unitContents)); |
| 336 } | 337 } |
| 337 | 338 |
| 338 Outline _newVariableOutline(String typeName, ElementKind kind, | 339 Outline _newVariableOutline(String typeName, ElementKind kind, |
| 339 VariableDeclaration variable, bool isStatic) { | 340 VariableDeclaration variable, bool isStatic) { |
| 340 SimpleIdentifier nameNode = variable.name; | 341 SimpleIdentifier nameNode = variable.name; |
| 341 String name = nameNode.name; | 342 String name = nameNode.name; |
| 342 _SourceRegion sourceRegion = _getSourceRegion(variable); | 343 _SourceRegion sourceRegion = _getSourceRegion(variable); |
| 343 Element element = new Element( | 344 Element element = new Element( |
| 344 kind, | 345 kind, |
| 345 name, | 346 name, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 | 384 |
| 384 | 385 |
| 385 /** | 386 /** |
| 386 * A range of characters. | 387 * A range of characters. |
| 387 */ | 388 */ |
| 388 class _SourceRegion { | 389 class _SourceRegion { |
| 389 final int length; | 390 final int length; |
| 390 final int offset; | 391 final int offset; |
| 391 _SourceRegion(this.offset, this.length); | 392 _SourceRegion(this.offset, this.length); |
| 392 } | 393 } |
| OLD | NEW |