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

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

Issue 629283002: Simplify conversion of empty lists to null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
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/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
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
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
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
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
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 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/collections.dart ('k') | pkg/analysis_server/lib/src/computer/computer_overrides.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698