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

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

Issue 1060063008: Add API for contributing to the index (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/analysis/index/index_dart.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analysis_server.analysis.index.index_core;
6
7 import 'dart:async';
8
9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source.dart';
11
12 /**
13 * An object that can have a [Relationship] with various [Location]s in a code
14 * base.
15 *
16 * Clients are expected to subtype this class when implementing plugins.
17 */
18 abstract class IndexableObject {
19 // TODO(brianwilkerson) Figure out the subset of the Element API that is used
20 // by the index.
21 }
22
23 /**
24 * An object used to add relationships to the index.
25 *
26 * Clients are expected to subtype this class when implementing plugins.
27 */
28 abstract class IndexContributor {
29 /**
30 * Contribute relationships to the given index [store] as a result of
31 * analyzing the given [source] in the given [context].
32 */
33 void contributeTo(IndexStore store, AnalysisContext context, Source source);
34 }
35
36 // A sketch of what the driver routine might look like:
37 //
38 //void buildIndexForSource(AnalysisContext context, Source source) {
39 // IndexStoreImpl store;
40 // store.aboutToIndex(context, source);
41 // try {
42 // for (IndexContributor contributor in contributors) {
43 // contributor.contributeTo(store, context, source);
44 // }
45 // } finally {
46 // store.doneIndexing();
47 // }
48 //}
49
50 /**
51 * An object that stores information about the relationships between locations
52 * in a code base.
53 *
54 * Clients are not expected to subtype this class.
55 */
56 abstract class IndexStore {
57 /**
58 * Remove all of the information from the index.
59 */
60 void clear();
61
62 /**
63 * Return a future that completes with the locations that have the given
64 * [relationship] with the given [indexable] object.
65 *
66 * For example, if the [indexable] object represents a function and the
67 * relationship is the `is-invoked-by` relationship, then the returned
68 * locations will be all of the places where the function is invoked.
69 */
70 Future<List<Location>> getRelationships(
71 IndexableObject indexable, Relationship relationship);
72
73 /**
74 * Record that the given [indexable] object and [location] have the given
75 * [relationship].
76 *
77 * For example, if the [relationship] is the `is-invoked-by` relationship,
78 * then the [indexable] object would be the function being invoked and
79 * [location] would be the point at which it is invoked. Each element can have
80 * the same relationship with multiple locations. In other words, if the
81 * following code were executed
82 *
83 * recordRelationship(indexable, isReferencedBy, location1);
84 * recordRelationship(indexable, isReferencedBy, location2);
85 *
86 * (where `location1 != location2`) then both relationships would be
87 * maintained in the index and the result of executing
88 *
89 * getRelationship(indexable, isReferencedBy);
90 *
91 * would be a list containing both `location1` and `location2`.
92 */
93 void recordRelationship(
94 IndexableObject indexable, Relationship relationship, Location location);
95
96 /**
97 * Remove from the index all of the information associated with the given
98 * [context].
99 *
100 * This method should be invoked when the [context] is disposed.
101 */
102 void removeContext(AnalysisContext context);
103
104 /**
105 * Remove from the index all of the information associated with elements or
106 * locations in the given [source]. This includes relationships between an
107 * element in [source] and any other locations, relationships between any
108 * other elements and locations within [source].
109 *
110 * This method should be invoked when [source] is no longer part of the given
111 * [context].
112 */
113 void removeSource(AnalysisContext context, Source source);
114
115 /**
116 * Remove from the index all of the information associated with elements or
117 * locations in the given sources. This includes relationships between an
118 * element in the given sources and any other locations, relationships between
119 * any other elements and a location within the given sources.
120 *
121 * This method should be invoked when the sources described by the given
122 * [container] are no longer part of the given [context].
123 */
124 void removeSources(AnalysisContext context, SourceContainer container);
125 }
126
127 /**
128 * Instances of the class [Location] represent a location related to an element.
scheglov 2015/04/22 19:34:12 Replace "element -> object" in this class. Or name
Brian Wilkerson 2015/04/22 20:11:11 Done. Here and elsewhere.
129 *
130 * The location is expressed as an offset and length, but the offset is relative
131 * to the source containing the element rather than the start of the element
132 * within that source.
133 *
134 * Clients are not expected to subtype this class.
135 */
136 abstract class Location {
137 /**
138 * An empty list of locations.
139 */
140 static const List<Location> EMPTY_LIST = const <Location>[];
141
142 /**
143 * Return the indexable object containing this location.
144 */
145 IndexableObject get indexable;
146
147 /**
148 * Return `true` if this location is a qualified reference.
149 */
150 bool get isQualified;
151
152 /**
153 * Return `true` if this location is a resolved reference.
154 */
155 bool get isResolved;
156
157 /**
158 * Return the length of this location.
159 */
160 int get length;
161
162 /**
163 * Return the offset of this location within the source containing the element .
164 */
165 int get offset;
166 }
167
168 /**
169 * A relationship between an element and a location. Relationships are
170 * identified by a globally unique identifier.
171 *
172 * Clients are not expected to subtype this class.
173 */
174 abstract class Relationship {
175 /**
176 * Return a relationship that has the given [identifier]. If the relationship
177 * has already been created, then it will be returned, otherwise a new
178 * relationship will be created
179 */
180 factory Relationship(String identifier) => null;
181 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/analysis/index/index_dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698