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

Side by Side Diff: pkg/analysis_server/lib/analysis/index/index_core.dart

Issue 1156493004: Move index closer to the plugin API (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
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 9
10 import 'package:analysis_server/src/services/index/index.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 11 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
11 13
12 /** 14 /**
13 * An object that can have a [Relationship] with various [Location]s in a code 15 * An object that can have a [Relationship] with various [Location]s in a code
14 * base. 16 * base. The object is abstractly represented by a [kind] and an [offset] within
17 * a [source].
18 *
19 * 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
21 * clients to identify the model element corresponding to the indexable object.
15 * 22 *
16 * Clients are expected to subtype this class when implementing plugins. 23 * Clients are expected to subtype this class when implementing plugins.
17 */ 24 */
18 abstract class IndexableObject { 25 abstract class IndexableObject {
19 // TODO(brianwilkerson) Figure out the subset of the Element API that is used 26 /**
20 // by the index. 27 * Return the kind of this object.
28 */
29 IndexableObjectKind get kind;
30
31 /**
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.
44 */
45 int get offset;
46
47 /**
48 * Return the source containing the indexable object.
49 */
50 Source get source;
21 } 51 }
22 52
23 /** 53 /**
54 * The kind associated with an [IndexableObject].
55 *
56 * Clients are expected to implement this class when implementing plugins.
57 */
58 abstract class IndexableObjectKind {
59 /**
60 * The next available index for a newly created kind of indexable object.
61 */
62 static int _nextIndex = 0;
63
64 /**
65 * A table mapping indexes to object kinds.
66 */
67 static Map<int, IndexableObjectKind> _registry =
68 new HashMap<int, IndexableObjectKind>();
69
70 /**
71 * Return the next available index for a newly created kind of indexable
72 * object.
73 */
74 static int get nextIndex => _nextIndex++;
75
76 /**
77 * Return the unique index for this kind of indexable object. Implementations
78 * should invoke [nextIndex] to allocate an index that cannot be used by any
79 * other object kind.
80 */
81 int get index;
82
83 /**
84 * 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
86 * [offset].
87 */
88 IndexableObject decode(AnalysisContext context, String filePath, int offset);
89
90 /**
91 * Return the object kind with the given [index].
92 */
93 static IndexableObjectKind getKind(int index) {
94 return _registry[index];
95 }
96
97 /**
98 * 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
100 * this method.
101 */
102 static void register(IndexableObjectKind kind) {
103 int index = kind.index;
104 if (_registry.containsKey(index)) {
105 throw new ArgumentError('duplicate index for kind: $index');
106 }
107 _registry[index] = kind;
108 }
109 }
110
111 /**
24 * An object used to add relationships to the index. 112 * An object used to add relationships to the index.
25 * 113 *
26 * Clients are expected to subtype this class when implementing plugins. 114 * Clients are expected to subtype this class when implementing plugins.
27 */ 115 */
28 abstract class IndexContributor { 116 abstract class IndexContributor {
29 /** 117 /**
30 * Contribute relationships to the given index [store] as a result of 118 * Contribute relationships to the given index [store] as a result of
31 * analyzing the given [source] in the given [context]. 119 * analyzing the given [source] in the given [context].
32 */ 120 */
33 void contributeTo(IndexStore store, AnalysisContext context, Source source); 121 void contributeTo(IndexStore store, AnalysisContext context, Source source);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 * identified by a globally unique identifier. 262 * identified by a globally unique identifier.
175 * 263 *
176 * Clients are not expected to subtype this class. 264 * Clients are not expected to subtype this class.
177 */ 265 */
178 abstract class Relationship { 266 abstract class Relationship {
179 /** 267 /**
180 * Return a relationship that has the given [identifier]. If the relationship 268 * Return a relationship that has the given [identifier]. If the relationship
181 * has already been created, then it will be returned, otherwise a new 269 * has already been created, then it will be returned, otherwise a new
182 * relationship will be created 270 * relationship will be created
183 */ 271 */
184 factory Relationship(String identifier) => null; 272 factory Relationship(String identifier) =>
273 RelationshipImpl.getRelationship(identifier);
185 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698