| 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/protocol_server.dart' as protocol; | 9 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 = protocol.newElement_fromEngine(engineElement); | 32 var serverElement = protocol.newElement_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, offsets, length)); |
| 35 }); | 35 }); |
| 36 return occurrences; | 36 return occurrences; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void _addOccurrence(Element element, int offset) { | 39 void _addOccurrence(Element element, int offset) { |
| 40 element = _canonicalizeElement(element); |
| 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 List<int> offsets = _elementsOffsets[element]; | 44 List<int> offsets = _elementsOffsets[element]; |
| 45 if (offsets == null) { | 45 if (offsets == null) { |
| 46 offsets = <int>[]; | 46 offsets = <int>[]; |
| 47 _elementsOffsets[element] = offsets; | 47 _elementsOffsets[element] = offsets; |
| 48 } | 48 } |
| 49 offsets.add(offset); | 49 offsets.add(offset); |
| 50 } | 50 } |
| 51 | 51 |
| 52 Element _canonicalizeElement(Element element) { | 52 Element _canonicalizeElement(Element element) { |
| 53 if (element is FieldFormalParameterElement) { | 53 if (element is FieldFormalParameterElement) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 | 71 |
| 72 @override | 72 @override |
| 73 visitSimpleIdentifier(SimpleIdentifier node) { | 73 visitSimpleIdentifier(SimpleIdentifier node) { |
| 74 Element element = node.bestElement; | 74 Element element = node.bestElement; |
| 75 if (element != null) { | 75 if (element != null) { |
| 76 computer._addOccurrence(element, node.offset); | 76 computer._addOccurrence(element, node.offset); |
| 77 } | 77 } |
| 78 return super.visitSimpleIdentifier(node); | 78 return super.visitSimpleIdentifier(node); |
| 79 } | 79 } |
| 80 } | 80 } |
| OLD | NEW |