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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/abstract_context.dart
diff --git a/pkg/analysis_server/test/abstract_context.dart b/pkg/analysis_server/test/abstract_context.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b1e5a5151200b2bcaab0f69d7f7b1b01ff113a3d
--- /dev/null
+++ b/pkg/analysis_server/test/abstract_context.dart
@@ -0,0 +1,88 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.index;
+
+import 'package:analysis_server/src/resource.dart';
+import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/element.dart';
+import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/sdk.dart';
+import 'package:analyzer/src/generated/source_io.dart';
+
+import 'mocks.dart';
+import 'reflective_tests.dart';
+
+
+/**
+ * Finds an [engine.Element] with the given [name].
+ */
+Element findElementInUnit(CompilationUnit unit, String name, [ElementKind kind])
+ {
+ Element result = null;
+ unit.element.accept(new _ElementVisitorFunctionWrapper((Element element) {
+ if (element.name != name) {
+ return;
+ }
+ if (kind != null && element.kind != kind) {
+ return;
+ }
+ result = element;
+ }));
+ return result;
+}
+
+
+/**
+ * A function to be called for every [Element].
+ */
+typedef void _ElementVisitorFunction(Element element);
+
+
+@ReflectiveTestCase()
+class AbstractContextTest {
+ static final DartSdk SDK = new MockSdk();
+
+ AnalysisContext context;
+ MemoryResourceProvider provider = new MemoryResourceProvider();
+
+ Source addSource(String path, String content) {
+ File file = provider.newFile(path, content);
+ Source source = file.createSource(UriKind.FILE_URI);
+ ChangeSet changeSet = new ChangeSet();
+ changeSet.addedSource(source);
+ context.applyChanges(changeSet);
+ context.setContents(source, content);
+ return source;
+ }
+
+ CompilationUnit resolveLibraryUnit(Source source) {
+ return context.resolveCompilationUnit2(source, source);
+ }
+
+ void setUp() {
+ context = AnalysisEngine.instance.createAnalysisContext();
+ context.sourceFactory = new SourceFactory(<UriResolver>[new DartUriResolver(
+ SDK), new ResourceUriResolver(provider)]);
+ }
+
+ void tearDown() {
+ context = null;
+ provider = null;
+ }
+}
+
+
+/**
+ * Wraps the given [_ElementVisitorFunction] into an instance of
+ * [engine.GeneralizingElementVisitor].
+ */
+class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor {
+ final _ElementVisitorFunction function;
+ _ElementVisitorFunctionWrapper(this.function);
+ visitElement(Element element) {
+ function(element);
+ super.visitElement(element);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698