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

Side by Side Diff: pkg/analysis_server/test/abstract_context.dart

Issue 367793002: Update Element/navigation/outline to use Location. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgotten file Created 6 years, 5 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.index;
6
7 import 'package:analysis_server/src/resource.dart';
8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/generated/sdk.dart';
12 import 'package:analyzer/src/generated/source_io.dart';
13
14 import 'mocks.dart';
15 import 'reflective_tests.dart';
16
17
18 /**
19 * Finds an [engine.Element] with the given [name].
20 */
21 Element findElementInUnit(CompilationUnit unit, String name, [ElementKind kind])
22 {
23 Element result = null;
24 unit.element.accept(new _ElementVisitorFunctionWrapper((Element element) {
25 if (element.name != name) {
26 return;
27 }
28 if (kind != null && element.kind != kind) {
29 return;
30 }
31 result = element;
32 }));
33 return result;
34 }
35
36
37 /**
38 * A function to be called for every [Element].
39 */
40 typedef void _ElementVisitorFunction(Element element);
41
42
43 @ReflectiveTestCase()
44 class AbstractContextTest {
45 static final DartSdk SDK = new MockSdk();
46
47 AnalysisContext context;
48 MemoryResourceProvider provider = new MemoryResourceProvider();
49
50 Source addSource(String path, String content) {
51 File file = provider.newFile(path, content);
52 Source source = file.createSource(UriKind.FILE_URI);
53 ChangeSet changeSet = new ChangeSet();
54 changeSet.addedSource(source);
55 context.applyChanges(changeSet);
56 context.setContents(source, content);
57 return source;
58 }
59
60 CompilationUnit resolveLibraryUnit(Source source) {
61 return context.resolveCompilationUnit2(source, source);
62 }
63
64 void setUp() {
65 context = AnalysisEngine.instance.createAnalysisContext();
66 context.sourceFactory = new SourceFactory(<UriResolver>[new DartUriResolver(
67 SDK), new ResourceUriResolver(provider)]);
68 }
69
70 void tearDown() {
71 context = null;
72 provider = null;
73 }
74 }
75
76
77 /**
78 * Wraps the given [_ElementVisitorFunction] into an instance of
79 * [engine.GeneralizingElementVisitor].
80 */
81 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor {
82 final _ElementVisitorFunction function;
83 _ElementVisitorFunctionWrapper(this.function);
84 visitElement(Element element) {
85 function(element);
86 super.visitElement(element);
87 }
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698