Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analysis_server.analysis.index.index_core; | 5 library analysis_server.analysis.index.index_core; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 12 import 'package:analyzer/src/generated/source.dart'; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Return the integer value that corresponds to the given [str]. | |
| 16 */ | |
| 17 typedef int StringToInt(String str); | |
| 18 | |
| 19 /** | |
| 15 * An object that can have a [Relationship] with various [Location]s in a code | 20 * An object that can have a [Relationship] with various [Location]s in a code |
| 16 * base. The object is abstractly represented by a [kind] and an [offset] within | 21 * base. The object is abstractly represented by a [kind] and an [offset] within |
| 17 * a [source]. | 22 * a [source]. |
| 18 * | 23 * |
| 19 * Clients must ensure that two distinct objects in the same source cannot have | 24 * Clients must ensure that two distinct objects in the same source cannot have |
| 20 * the same kind and offset. Failure to do so will make it impossible for | 25 * the same kind and offset. Failure to do so will make it impossible for |
| 21 * clients to identify the model element corresponding to the indexable object. | 26 * clients to identify the model element corresponding to the indexable object. |
| 22 * | 27 * |
| 23 * Clients are expected to subtype this class when implementing plugins. | 28 * Clients are expected to subtype this class when implementing plugins. |
| 24 */ | 29 */ |
| 25 abstract class IndexableObject { | 30 abstract class IndexableObject { |
| 26 /** | 31 /** |
| 27 * Return the kind of this object. | 32 * Return the kind of this object. |
| 28 */ | 33 */ |
| 29 IndexableObjectKind get kind; | 34 IndexableObjectKind get kind; |
| 30 | 35 |
| 31 /** | 36 /** |
| 32 * Return the length of the indexable object within its source. | |
| 33 */ | |
| 34 int get length; | |
| 35 | |
| 36 /** | |
| 37 * Return the name of this element. | |
| 38 */ | |
| 39 // TODO(brianwilkerson) Remove the need for this getter. | |
| 40 String get name; | |
| 41 | |
| 42 /** | |
| 43 * Return the offset of the indexable object within its source. | 37 * Return the offset of the indexable object within its source. |
| 44 */ | 38 */ |
| 45 int get offset; | 39 int get offset; |
| 46 | 40 |
| 47 /** | 41 /** |
| 48 * Return the source containing the indexable object. | 42 * Return the source containing the indexable object. |
| 49 */ | 43 */ |
| 50 Source get source; | 44 Source get source; |
| 51 } | 45 } |
| 52 | 46 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 81 int get index; | 75 int get index; |
| 82 | 76 |
| 83 /** | 77 /** |
| 84 * Return the indexable object of this kind that exists in the given | 78 * Return the indexable object of this kind that exists in the given |
| 85 * [context], in the source with the given [filePath], and at the given | 79 * [context], in the source with the given [filePath], and at the given |
| 86 * [offset]. | 80 * [offset]. |
| 87 */ | 81 */ |
| 88 IndexableObject decode(AnalysisContext context, String filePath, int offset); | 82 IndexableObject decode(AnalysisContext context, String filePath, int offset); |
| 89 | 83 |
| 90 /** | 84 /** |
| 85 * Returns an integer that corresponds to the name of [indexable]. | |
|
Brian Wilkerson
2015/10/05 14:01:02
This needs to be more complete. What should it ret
scheglov
2015/10/05 14:28:16
Done.
| |
| 86 */ | |
| 87 int encodeHash(StringToInt stringToInt, IndexableObject indexable); | |
| 88 | |
| 89 /** | |
| 91 * Return the object kind with the given [index]. | 90 * Return the object kind with the given [index]. |
| 92 */ | 91 */ |
| 93 static IndexableObjectKind getKind(int index) { | 92 static IndexableObjectKind getKind(int index) { |
| 94 return _registry[index]; | 93 return _registry[index]; |
| 95 } | 94 } |
| 96 | 95 |
| 97 /** | 96 /** |
| 98 * Register the given object [kind] so that it can be found by it's unique | 97 * Register the given object [kind] so that it can be found by it's unique |
| 99 * index. The index of the [kind] must not be changed after it is passed to | 98 * index. The index of the [kind] must not be changed after it is passed to |
| 100 * this method. | 99 * this method. |
| 101 */ | 100 */ |
| 102 static void register(IndexableObjectKind kind) { | 101 static void register(IndexableObjectKind kind) { |
| 103 int index = kind.index; | 102 int index = kind.index; |
| 104 if (_registry.containsKey(index)) { | 103 if (_registry.containsKey(index)) { |
| 105 throw new ArgumentError('duplicate index for kind: $index'); | 104 throw new ArgumentError('duplicate index for kind: $index'); |
| 106 } | 105 } |
| 107 _registry[index] = kind; | 106 _registry[index] = kind; |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 | 109 |
| 111 /** | |
| 112 * An object used to add relationships to the index. | |
| 113 * | |
| 114 * Clients are expected to subtype this class when implementing plugins. | |
| 115 */ | |
| 116 abstract class IndexContributor { | |
| 117 /** | |
| 118 * Contribute relationships existing in the given [object] to the given | |
| 119 * index [store] in the given [context]. | |
| 120 */ | |
| 121 void contributeTo(IndexStore store, AnalysisContext context, Object object); | |
| 122 } | |
| 123 | |
| 124 // A sketch of what the driver routine might look like: | 110 // A sketch of what the driver routine might look like: |
| 125 // | 111 // |
| 126 //void buildIndexForSource(AnalysisContext context, Source source) { | 112 //void buildIndexForSource(AnalysisContext context, Source source) { |
| 127 // IndexStoreImpl store; | 113 // IndexStoreImpl store; |
| 128 // store.aboutToIndex(context, source); | 114 // store.aboutToIndex(context, source); |
| 129 // try { | 115 // try { |
| 130 // for (IndexContributor contributor in contributors) { | 116 // for (IndexContributor contributor in contributors) { |
| 131 // contributor.contributeTo(store, context, source); | 117 // contributor.contributeTo(store, context, source); |
| 132 // } | 118 // } |
| 133 // } finally { | 119 // } finally { |
| 134 // store.doneIndexing(); | 120 // store.doneIndexing(); |
| 135 // } | 121 // } |
| 136 //} | 122 //} |
| 137 | 123 |
| 138 /** | 124 /** |
| 125 * An object used to add relationships to the index. | |
| 126 * | |
| 127 * Clients are expected to subtype this class when implementing plugins. | |
| 128 */ | |
| 129 abstract class IndexContributor { | |
| 130 /** | |
| 131 * Contribute relationships existing in the given [object] to the given | |
| 132 * index [store] in the given [context]. | |
| 133 */ | |
| 134 void contributeTo(IndexStore store, AnalysisContext context, Object object); | |
| 135 } | |
| 136 | |
| 137 /** | |
| 139 * An object that stores information about the relationships between locations | 138 * An object that stores information about the relationships between locations |
| 140 * in a code base. | 139 * in a code base. |
| 141 * | 140 * |
| 142 * Clients are not expected to subtype this class. | 141 * Clients are not expected to subtype this class. |
| 143 */ | 142 */ |
| 144 abstract class IndexStore { | 143 abstract class IndexStore { |
| 145 /** | 144 /** |
| 146 * Remove all of the information from the index. | 145 * Remove all of the information from the index. |
| 147 */ | 146 */ |
| 148 void clear(); | 147 void clear(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 */ | 264 */ |
| 266 abstract class Relationship { | 265 abstract class Relationship { |
| 267 /** | 266 /** |
| 268 * Return a relationship that has the given [identifier]. If the relationship | 267 * Return a relationship that has the given [identifier]. If the relationship |
| 269 * has already been created, then it will be returned, otherwise a new | 268 * has already been created, then it will be returned, otherwise a new |
| 270 * relationship will be created | 269 * relationship will be created |
| 271 */ | 270 */ |
| 272 factory Relationship(String identifier) => | 271 factory Relationship(String identifier) => |
| 273 RelationshipImpl.getRelationship(identifier); | 272 RelationshipImpl.getRelationship(identifier); |
| 274 } | 273 } |
| OLD | NEW |