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

Side by Side Diff: pkg/analysis_server/lib/src/services/index/index_contributor.dart

Issue 1359113002: Use IndexContributor(s) in LocalIndex. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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) 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 services.src.index.index_contributor; 5 library services.src.index.index_contributor;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import 'package:analysis_server/analysis/index/index_core.dart'; 9 import 'package:analysis_server/analysis/index_core.dart';
10 import 'package:analysis_server/analysis/index/index_dart.dart';
11 import 'package:analysis_server/src/services/correction/namespace.dart'; 10 import 'package:analysis_server/src/services/correction/namespace.dart';
12 import 'package:analysis_server/src/services/index/index.dart'; 11 import 'package:analysis_server/src/services/index/index.dart';
13 import 'package:analysis_server/src/services/index/index_store.dart'; 12 import 'package:analysis_server/src/services/index/index_store.dart';
14 import 'package:analysis_server/src/services/index/indexable_element.dart'; 13 import 'package:analysis_server/src/services/index/indexable_element.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 14 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/element.dart'; 15 import 'package:analyzer/src/generated/element.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 16 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/html.dart' as ht;
19 import 'package:analyzer/src/generated/java_engine.dart'; 17 import 'package:analyzer/src/generated/java_engine.dart';
20 import 'package:analyzer/src/generated/scanner.dart'; 18 import 'package:analyzer/src/generated/scanner.dart';
21 import 'package:analyzer/src/generated/source.dart'; 19 import 'package:analyzer/src/generated/source.dart';
22 20
23 /** 21 /**
24 * Adds data to [store] based on the resolved Dart [unit]. 22 * An [IndexContributor] that contributes relationships for Dart files.
25 */ 23 */
26 void indexDartUnit( 24 class DartIndexContributor extends IndexContributor {
27 InternalIndexStore store, AnalysisContext context, CompilationUnit unit) { 25 @override
28 // check unit 26 void contributeTo(IndexStore store, AnalysisContext context, Object object) {
29 if (unit == null) { 27 if (store is InternalIndexStore && object is CompilationUnit) {
30 return; 28 _IndexContributor contributor = new _IndexContributor(store);
31 } 29 object.accept(contributor);
32 // prepare unit element 30 }
33 CompilationUnitElement unitElement = unit.element;
34 if (unitElement == null) {
35 return;
36 }
37 // about to index
38 bool mayIndex = store.aboutToIndex(context, unitElement);
39 if (!mayIndex) {
40 return;
41 }
42 // do index
43 try {
44 unit.accept(new _IndexContributor(store));
45 store.doneIndex();
46 } catch (e) {
47 store.cancelIndex();
48 rethrow;
49 } 31 }
50 } 32 }
51 33
52 /**
53 * Adds data to [store] based on the resolved HTML [unit].
54 */
55 void indexHtmlUnit(
56 InternalIndexStore store, AnalysisContext context, ht.HtmlUnit unit) {
57 // TODO(scheglov) remove or implement
58 // // check unit
59 // if (unit == null) {
60 // return;
61 // }
62 // // prepare unit element
63 // HtmlElement unitElement = unit.element;
64 // if (unitElement == null) {
65 // return;
66 // }
67 // // about to index
68 // bool mayIndex = store.aboutToIndexHtml(context, unitElement);
69 // if (!mayIndex) {
70 // return;
71 // }
72 // // do index
73 // store.doneIndex();
74 }
75
76 /**
77 * An [IndexContributor] that can be used to contribute relationships for Dart
78 * files.
79 */
80 class DefaultDartIndexContributor extends DartIndexContributor {
81 @override
82 void internalContributeTo(IndexStore store, CompilationUnit unit) {
83 _IndexContributor contributor =
84 new _IndexContributor(store as InternalIndexStore);
85 unit.accept(contributor);
86 }
87 }
88
89 /** 34 /**
90 * Visits a resolved AST and adds relationships into [InternalIndexStore]. 35 * Visits a resolved AST and adds relationships into [InternalIndexStore].
91 */ 36 */
92 class _IndexContributor extends GeneralizingAstVisitor { 37 class _IndexContributor extends GeneralizingAstVisitor {
93 final InternalIndexStore _store; 38 final InternalIndexStore _store;
94 39
95 LibraryElement _libraryElement; 40 LibraryElement _libraryElement;
96 41
97 Map<ImportElement, Set<Element>> _importElementsMap = {}; 42 Map<ImportElement, Set<Element>> _importElementsMap = {};
98 43
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 } 774 }
830 775
831 /** 776 /**
832 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node ". 777 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node ".
833 */ 778 */
834 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { 779 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) {
835 AstNode parent = node.parent; 780 AstNode parent = node.parent;
836 return parent is PrefixedIdentifier && parent.identifier == node; 781 return parent is PrefixedIdentifier && parent.identifier == node;
837 } 782 }
838 } 783 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/index/index.dart ('k') | pkg/analysis_server/lib/src/services/index/index_store.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698