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

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

Issue 652903006: Issue 21373. Fix for removing line info in case of exception (causes NPE in outline computer). (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/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;
11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/source.dart'; 11 import 'package:analyzer/src/generated/source.dart';
13 12
14 13
15 /** 14 /**
16 * A computer for [CompilationUnit] outline. 15 * A computer for [CompilationUnit] outline.
17 */ 16 */
18 class DartUnitOutlineComputer { 17 class DartUnitOutlineComputer {
19 final CompilationUnit _unit; 18 final String file;
20 String file; 19 final CompilationUnit unit;
21 LineInfo lineInfo; 20 final LineInfo lineInfo;
22 21
23 DartUnitOutlineComputer(AnalysisContext context, Source source, this._unit) { 22 DartUnitOutlineComputer(Source source, this.lineInfo, this.unit)
24 file = source.fullName; 23 : file = source.fullName;
25 lineInfo = context.getLineInfo(source);
26 }
27 24
28 /** 25 /**
29 * Returns the computed outline, not `null`. 26 * Returns the computed outline, not `null`.
30 */ 27 */
31 Outline compute() { 28 Outline compute() {
32 List<Outline> unitContents = <Outline>[]; 29 List<Outline> unitContents = <Outline>[];
33 for (CompilationUnitMember unitMember in _unit.declarations) { 30 for (CompilationUnitMember unitMember in unit.declarations) {
34 if (unitMember is ClassDeclaration) { 31 if (unitMember is ClassDeclaration) {
35 ClassDeclaration classDeclaration = unitMember; 32 ClassDeclaration classDeclaration = unitMember;
36 List<Outline> classContents = <Outline>[]; 33 List<Outline> classContents = <Outline>[];
37 for (ClassMember classMember in classDeclaration.members) { 34 for (ClassMember classMember in classDeclaration.members) {
38 if (classMember is ConstructorDeclaration) { 35 if (classMember is ConstructorDeclaration) {
39 ConstructorDeclaration constructorDeclaration = classMember; 36 ConstructorDeclaration constructorDeclaration = classMember;
40 classContents.add(_newConstructorOutline(constructorDeclaration)); 37 classContents.add(_newConstructorOutline(constructorDeclaration));
41 } 38 }
42 if (classMember is FieldDeclaration) { 39 if (classMember is FieldDeclaration) {
43 FieldDeclaration fieldDeclaration = classMember; 40 FieldDeclaration fieldDeclaration = classMember;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 sourceRegion.length, 318 sourceRegion.length,
322 children: nullIfEmpty(contents)); 319 children: nullIfEmpty(contents));
323 return outline; 320 return outline;
324 } 321 }
325 322
326 Outline _newUnitOutline(List<Outline> unitContents) { 323 Outline _newUnitOutline(List<Outline> unitContents) {
327 Element element = new Element( 324 Element element = new Element(
328 ElementKind.COMPILATION_UNIT, 325 ElementKind.COMPILATION_UNIT,
329 '<unit>', 326 '<unit>',
330 Element.makeFlags(), 327 Element.makeFlags(),
331 location: _getLocationNode(_unit)); 328 location: _getLocationNode(unit));
332 return new Outline( 329 return new Outline(
333 element, 330 element,
334 _unit.offset, 331 unit.offset,
335 _unit.length, 332 unit.length,
336 children: nullIfEmpty(unitContents)); 333 children: nullIfEmpty(unitContents));
337 } 334 }
338 335
339 Outline _newVariableOutline(String typeName, ElementKind kind, 336 Outline _newVariableOutline(String typeName, ElementKind kind,
340 VariableDeclaration variable, bool isStatic) { 337 VariableDeclaration variable, bool isStatic) {
341 SimpleIdentifier nameNode = variable.name; 338 SimpleIdentifier nameNode = variable.name;
342 String name = nameNode.name; 339 String name = nameNode.name;
343 _SourceRegion sourceRegion = _getSourceRegion(variable); 340 _SourceRegion sourceRegion = _getSourceRegion(variable);
344 Element element = new Element( 341 Element element = new Element(
345 kind, 342 kind,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 381
385 382
386 /** 383 /**
387 * A range of characters. 384 * A range of characters.
388 */ 385 */
389 class _SourceRegion { 386 class _SourceRegion {
390 final int length; 387 final int length;
391 final int offset; 388 final int offset;
392 _SourceRegion(this.offset, this.length); 389 _SourceRegion(this.offset, this.length);
393 } 390 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/operation/operation_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698