| 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.occurrences; | 5 library computer.occurrences; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol2.dart' as protocol; | 9 import 'package:analysis_server/src/protocol2.dart' as protocol; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Returns the computed occurrences, not `null`. | 26 * Returns the computed occurrences, not `null`. |
| 27 */ | 27 */ |
| 28 List<protocol.Occurrences> compute() { | 28 List<protocol.Occurrences> compute() { |
| 29 _unit.accept(new _DartUnitOccurrencesComputerVisitor(this)); | 29 _unit.accept(new _DartUnitOccurrencesComputerVisitor(this)); |
| 30 List<protocol.Occurrences> occurrences = <protocol.Occurrences>[]; | 30 List<protocol.Occurrences> occurrences = <protocol.Occurrences>[]; |
| 31 _elementsOffsets.forEach((engineElement, offsets) { | 31 _elementsOffsets.forEach((engineElement, offsets) { |
| 32 var serverElement = new protocol.Element.fromEngine(engineElement); | 32 var serverElement = new protocol.Element.fromEngine(engineElement); |
| 33 var length = engineElement.displayName.length; | 33 var length = engineElement.displayName.length; |
| 34 occurrences.add(new protocol.Occurrences(serverElement, offsets, length)); | 34 occurrences.add(new protocol.Occurrences(serverElement, length, |
| 35 offsets: offsets)); |
| 35 }); | 36 }); |
| 36 return occurrences; | 37 return occurrences; |
| 37 } | 38 } |
| 38 | 39 |
| 39 void _addOccurrence(Element element, int offset) { | 40 void _addOccurrence(Element element, int offset) { |
| 40 if (element == null || element == DynamicElementImpl.instance) { | 41 if (element == null || element == DynamicElementImpl.instance) { |
| 41 return; | 42 return; |
| 42 } | 43 } |
| 43 element = _canonicalizeElement(element); | 44 element = _canonicalizeElement(element); |
| 44 List<int> offsets = _elementsOffsets[element]; | 45 List<int> offsets = _elementsOffsets[element]; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 71 | 72 |
| 72 @override | 73 @override |
| 73 visitSimpleIdentifier(SimpleIdentifier node) { | 74 visitSimpleIdentifier(SimpleIdentifier node) { |
| 74 Element element = node.bestElement; | 75 Element element = node.bestElement; |
| 75 if (element != null) { | 76 if (element != null) { |
| 76 computer._addOccurrence(element, node.offset); | 77 computer._addOccurrence(element, node.offset); |
| 77 } | 78 } |
| 78 return super.visitSimpleIdentifier(node); | 79 return super.visitSimpleIdentifier(node); |
| 79 } | 80 } |
| 80 } | 81 } |
| OLD | NEW |