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

Side by Side Diff: pkg/analysis_services/test/index/abstract_single_unit.dart

Issue 402333006: Implementation of the 'edit.getFixes' API in server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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.services.src.index.abstract_single_file;
6
7 import 'package:analysis_testing/abstract_context.dart';
8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/error.dart';
11 import 'package:analyzer/src/generated/java_engine.dart';
12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:unittest/unittest.dart';
14
15
16 class AbstractSingleUnitTest extends AbstractContextTest {
17 bool verifyNoTestUnitErrors = true;
18
19 String testCode;
20 String testFile = '/test.dart';
21 Source testSource;
22 CompilationUnit testUnit;
23 CompilationUnitElement testUnitElement;
24 LibraryElement testLibraryElement;
25
26 void assertNoErrorsInSource(Source source) {
27 List<AnalysisError> errors = context.getErrors(source).errors;
28 expect(errors, isEmpty);
29 }
30
31 Element findElement(String name, [ElementKind kind]) {
32 return findChildElement(testUnitElement, name, kind);
33 }
34
35 AstNode findNodeAtOffset(int offset, [Predicate<AstNode> predicate]) {
36 AstNode result = new NodeLocator.con1(offset).searchWithin(testUnit);
37 if (result != null && predicate != null) {
38 result = result.getAncestor(predicate);
39 }
40 return result;
41 }
42
43 AstNode findNodeAtString(String search, [Predicate<AstNode> predicate]) {
44 int offset = findOffset(search);
45 return findNodeAtOffset(offset, predicate);
46 }
47
48 Element findNodeElementAtString(String search,
49 [Predicate<AstNode> predicate]) {
50 AstNode node = findNodeAtString(search, predicate);
51 if (node == null) {
52 return null;
53 }
54 return ElementLocator.locate(node);
55 }
56
57 int findOffset(String search) {
58 int offset = testCode.indexOf(search);
59 expect(offset, isNonNegative, reason: "Not found '$search' in\n$testCode");
60 return offset;
61 }
62
63 int getLeadingIdentifierLength(String search) {
64 int length = 0;
65 while (length < search.length) {
66 int c = search.codeUnitAt(length);
67 if (c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0)) {
68 length++;
69 continue;
70 }
71 if (c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0)) {
72 length++;
73 continue;
74 }
75 if (c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0)) {
76 length++;
77 continue;
78 }
79 break;
80 }
81 return length;
82 }
83
84 void resolveTestUnit(String code) {
85 testCode = code;
86 testSource = addSource(testFile, code);
87 testUnit = resolveLibraryUnit(testSource);
88 if (verifyNoTestUnitErrors) {
89 assertNoErrorsInSource(testSource);
90 }
91 testUnitElement = testUnit.element;
92 testLibraryElement = testUnitElement.library;
93 }
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698