Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: pkg/analysis_server/lib/src/computer/computer_outline.dart

Issue 2622303006: Reapply "Add support for generic function type syntax, part 1" (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/plugin/protocol/protocol.dart';
8 import 'package:analysis_server/src/collections.dart'; 8 import 'package:analysis_server/src/collections.dart';
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
(...skipping 22 matching lines...) Expand all
33 List<Outline> classContents = <Outline>[]; 33 List<Outline> classContents = <Outline>[];
34 for (ClassMember classMember in classDeclaration.members) { 34 for (ClassMember classMember in classDeclaration.members) {
35 if (classMember is ConstructorDeclaration) { 35 if (classMember is ConstructorDeclaration) {
36 ConstructorDeclaration constructorDeclaration = classMember; 36 ConstructorDeclaration constructorDeclaration = classMember;
37 classContents.add(_newConstructorOutline(constructorDeclaration)); 37 classContents.add(_newConstructorOutline(constructorDeclaration));
38 } 38 }
39 if (classMember is FieldDeclaration) { 39 if (classMember is FieldDeclaration) {
40 FieldDeclaration fieldDeclaration = classMember; 40 FieldDeclaration fieldDeclaration = classMember;
41 VariableDeclarationList fields = fieldDeclaration.fields; 41 VariableDeclarationList fields = fieldDeclaration.fields;
42 if (fields != null) { 42 if (fields != null) {
43 TypeName fieldType = fields.type; 43 TypeAnnotation fieldType = fields.type;
44 String fieldTypeName = _safeToSource(fieldType); 44 String fieldTypeName = _safeToSource(fieldType);
45 for (VariableDeclaration field in fields.variables) { 45 for (VariableDeclaration field in fields.variables) {
46 classContents.add(_newVariableOutline(fieldTypeName, 46 classContents.add(_newVariableOutline(fieldTypeName,
47 ElementKind.FIELD, field, fieldDeclaration.isStatic)); 47 ElementKind.FIELD, field, fieldDeclaration.isStatic));
48 } 48 }
49 } 49 }
50 } 50 }
51 if (classMember is MethodDeclaration) { 51 if (classMember is MethodDeclaration) {
52 MethodDeclaration methodDeclaration = classMember; 52 MethodDeclaration methodDeclaration = classMember;
53 classContents.add(_newMethodOutline(methodDeclaration)); 53 classContents.add(_newMethodOutline(methodDeclaration));
54 } 54 }
55 } 55 }
56 unitContents.add(_newClassOutline(classDeclaration, classContents)); 56 unitContents.add(_newClassOutline(classDeclaration, classContents));
57 } 57 }
58 if (unitMember is EnumDeclaration) { 58 if (unitMember is EnumDeclaration) {
59 EnumDeclaration enumDeclaration = unitMember; 59 EnumDeclaration enumDeclaration = unitMember;
60 List<Outline> constantOutlines = <Outline>[]; 60 List<Outline> constantOutlines = <Outline>[];
61 for (EnumConstantDeclaration constant in enumDeclaration.constants) { 61 for (EnumConstantDeclaration constant in enumDeclaration.constants) {
62 constantOutlines.add(_newEnumConstant(constant)); 62 constantOutlines.add(_newEnumConstant(constant));
63 } 63 }
64 unitContents.add(_newEnumOutline(enumDeclaration, constantOutlines)); 64 unitContents.add(_newEnumOutline(enumDeclaration, constantOutlines));
65 } 65 }
66 if (unitMember is TopLevelVariableDeclaration) { 66 if (unitMember is TopLevelVariableDeclaration) {
67 TopLevelVariableDeclaration fieldDeclaration = unitMember; 67 TopLevelVariableDeclaration fieldDeclaration = unitMember;
68 VariableDeclarationList fields = fieldDeclaration.variables; 68 VariableDeclarationList fields = fieldDeclaration.variables;
69 if (fields != null) { 69 if (fields != null) {
70 TypeName fieldType = fields.type; 70 TypeAnnotation fieldType = fields.type;
71 String fieldTypeName = _safeToSource(fieldType); 71 String fieldTypeName = _safeToSource(fieldType);
72 for (VariableDeclaration field in fields.variables) { 72 for (VariableDeclaration field in fields.variables) {
73 unitContents.add(_newVariableOutline( 73 unitContents.add(_newVariableOutline(
74 fieldTypeName, ElementKind.TOP_LEVEL_VARIABLE, field, false)); 74 fieldTypeName, ElementKind.TOP_LEVEL_VARIABLE, field, false));
75 } 75 }
76 } 76 }
77 } 77 }
78 if (unitMember is FunctionDeclaration) { 78 if (unitMember is FunctionDeclaration) {
79 FunctionDeclaration functionDeclaration = unitMember; 79 FunctionDeclaration functionDeclaration = unitMember;
80 unitContents.add(_newFunctionOutline(functionDeclaration, true)); 80 unitContents.add(_newFunctionOutline(functionDeclaration, true));
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 name, 244 name,
245 Element.makeFlags( 245 Element.makeFlags(
246 isPrivate: Identifier.isPrivateName(name), 246 isPrivate: Identifier.isPrivateName(name),
247 isDeprecated: _isDeprecated(node)), 247 isDeprecated: _isDeprecated(node)),
248 location: _getLocationNode(nameNode)); 248 location: _getLocationNode(nameNode));
249 return new Outline(element, sourceRegion.offset, sourceRegion.length, 249 return new Outline(element, sourceRegion.offset, sourceRegion.length,
250 children: nullIfEmpty(children)); 250 children: nullIfEmpty(children));
251 } 251 }
252 252
253 Outline _newFunctionOutline(FunctionDeclaration function, bool isStatic) { 253 Outline _newFunctionOutline(FunctionDeclaration function, bool isStatic) {
254 TypeName returnType = function.returnType; 254 TypeAnnotation returnType = function.returnType;
255 SimpleIdentifier nameNode = function.name; 255 SimpleIdentifier nameNode = function.name;
256 String name = nameNode.name; 256 String name = nameNode.name;
257 FunctionExpression functionExpression = function.functionExpression; 257 FunctionExpression functionExpression = function.functionExpression;
258 FormalParameterList parameters = functionExpression.parameters; 258 FormalParameterList parameters = functionExpression.parameters;
259 ElementKind kind; 259 ElementKind kind;
260 if (function.isGetter) { 260 if (function.isGetter) {
261 kind = ElementKind.GETTER; 261 kind = ElementKind.GETTER;
262 } else if (function.isSetter) { 262 } else if (function.isSetter) {
263 kind = ElementKind.SETTER; 263 kind = ElementKind.SETTER;
264 } else { 264 } else {
(...skipping 13 matching lines...) Expand all
278 parameters: parametersStr, 278 parameters: parametersStr,
279 returnType: returnTypeStr); 279 returnType: returnTypeStr);
280 List<Outline> contents = _addLocalFunctionOutlines(functionExpression.body); 280 List<Outline> contents = _addLocalFunctionOutlines(functionExpression.body);
281 Outline outline = new Outline( 281 Outline outline = new Outline(
282 element, sourceRegion.offset, sourceRegion.length, 282 element, sourceRegion.offset, sourceRegion.length,
283 children: nullIfEmpty(contents)); 283 children: nullIfEmpty(contents));
284 return outline; 284 return outline;
285 } 285 }
286 286
287 Outline _newFunctionTypeAliasOutline(FunctionTypeAlias node) { 287 Outline _newFunctionTypeAliasOutline(FunctionTypeAlias node) {
288 TypeName returnType = node.returnType; 288 TypeAnnotation returnType = node.returnType;
289 SimpleIdentifier nameNode = node.name; 289 SimpleIdentifier nameNode = node.name;
290 String name = nameNode.name; 290 String name = nameNode.name;
291 _SourceRegion sourceRegion = _getSourceRegion(node); 291 _SourceRegion sourceRegion = _getSourceRegion(node);
292 FormalParameterList parameters = node.parameters; 292 FormalParameterList parameters = node.parameters;
293 String parametersStr = _safeToSource(parameters); 293 String parametersStr = _safeToSource(parameters);
294 String returnTypeStr = _safeToSource(returnType); 294 String returnTypeStr = _safeToSource(returnType);
295 Element element = new Element( 295 Element element = new Element(
296 ElementKind.FUNCTION_TYPE_ALIAS, 296 ElementKind.FUNCTION_TYPE_ALIAS,
297 name, 297 name,
298 Element.makeFlags( 298 Element.makeFlags(
299 isPrivate: Identifier.isPrivateName(name), 299 isPrivate: Identifier.isPrivateName(name),
300 isDeprecated: _isDeprecated(node)), 300 isDeprecated: _isDeprecated(node)),
301 location: _getLocationNode(nameNode), 301 location: _getLocationNode(nameNode),
302 parameters: parametersStr, 302 parameters: parametersStr,
303 returnType: returnTypeStr, 303 returnType: returnTypeStr,
304 typeParameters: _getTypeParametersStr(node.typeParameters)); 304 typeParameters: _getTypeParametersStr(node.typeParameters));
305 return new Outline(element, sourceRegion.offset, sourceRegion.length); 305 return new Outline(element, sourceRegion.offset, sourceRegion.length);
306 } 306 }
307 307
308 Outline _newMethodOutline(MethodDeclaration method) { 308 Outline _newMethodOutline(MethodDeclaration method) {
309 TypeName returnType = method.returnType; 309 TypeAnnotation returnType = method.returnType;
310 SimpleIdentifier nameNode = method.name; 310 SimpleIdentifier nameNode = method.name;
311 String name = nameNode.name; 311 String name = nameNode.name;
312 FormalParameterList parameters = method.parameters; 312 FormalParameterList parameters = method.parameters;
313 ElementKind kind; 313 ElementKind kind;
314 if (method.isGetter) { 314 if (method.isGetter) {
315 kind = ElementKind.GETTER; 315 kind = ElementKind.GETTER;
316 } else if (method.isSetter) { 316 } else if (method.isSetter) {
317 kind = ElementKind.SETTER; 317 kind = ElementKind.SETTER;
318 } else { 318 } else {
319 kind = ElementKind.METHOD; 319 kind = ElementKind.METHOD;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 403 }
404 404
405 /** 405 /**
406 * A range of characters. 406 * A range of characters.
407 */ 407 */
408 class _SourceRegion { 408 class _SourceRegion {
409 final int length; 409 final int length;
410 final int offset; 410 final int offset;
411 _SourceRegion(this.offset, this.length); 411 _SourceRegion(this.offset, this.length);
412 } 412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698