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

Side by Side Diff: editor/tools/plugins/com.google.dart.engine.services_test/src/com/google/dart/engine/services/completion/CompletionTestCase.java

Issue 587743002: Version 1.7.0-dev.3.2 . (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 3 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
1 package com.google.dart.engine.services.completion; 1 package com.google.dart.engine.services.completion;
2 2
3 import com.google.common.base.Joiner; 3 import com.google.common.base.Joiner;
4 import com.google.dart.engine.ast.CompilationUnit; 4 import com.google.dart.engine.ast.CompilationUnit;
5 import com.google.dart.engine.context.AnalysisContext; 5 import com.google.dart.engine.context.AnalysisContext;
6 import com.google.dart.engine.context.AnalysisException; 6 import com.google.dart.engine.context.AnalysisException;
7 import com.google.dart.engine.element.CompilationUnitElement; 7 import com.google.dart.engine.element.CompilationUnitElement;
8 import com.google.dart.engine.element.Element;
8 import com.google.dart.engine.element.LibraryElement; 9 import com.google.dart.engine.element.LibraryElement;
9 import com.google.dart.engine.index.Index; 10 import com.google.dart.engine.index.Index;
10 import com.google.dart.engine.index.IndexFactory; 11 import com.google.dart.engine.index.IndexFactory;
12 import com.google.dart.engine.index.Location;
13 import com.google.dart.engine.index.Relationship;
14 import com.google.dart.engine.index.RelationshipCallback;
15 import com.google.dart.engine.internal.index.IndexConstants;
11 import com.google.dart.engine.internal.index.file.MemoryNodeManager; 16 import com.google.dart.engine.internal.index.file.MemoryNodeManager;
12 import com.google.dart.engine.resolver.ResolverTestCase; 17 import com.google.dart.engine.resolver.ResolverTestCase;
13 import com.google.dart.engine.search.SearchEngine; 18 import com.google.dart.engine.search.SearchEngine;
14 import com.google.dart.engine.search.SearchEngineFactory; 19 import com.google.dart.engine.search.SearchEngineFactory;
15 import com.google.dart.engine.services.assist.AssistContext; 20 import com.google.dart.engine.services.assist.AssistContext;
16 import com.google.dart.engine.services.util.LocationSpec; 21 import com.google.dart.engine.services.util.LocationSpec;
17 import com.google.dart.engine.services.util.MockCompletionRequestor; 22 import com.google.dart.engine.services.util.MockCompletionRequestor;
18 import com.google.dart.engine.source.Source; 23 import com.google.dart.engine.source.Source;
19 24
20 import java.net.URISyntaxException; 25 import java.net.URISyntaxException;
21 import java.util.ArrayList; 26 import java.util.ArrayList;
22 import java.util.Collection; 27 import java.util.Collection;
23 import java.util.List; 28 import java.util.List;
24 29
25 public class CompletionTestCase extends ResolverTestCase { 30 public class CompletionTestCase extends ResolverTestCase {
26 /** 31 /**
27 * Replaces "!" with the {@link CompletionProposal#CURSOR_MARKER}. 32 * Replaces "!" with the {@link CompletionProposal#CURSOR_MARKER}.
28 */ 33 */
29 protected static String resultWithCursor(String result) { 34 protected static String resultWithCursor(String result) {
30 return result.replace('!', CompletionProposal.CURSOR_MARKER); 35 return result.replace('!', CompletionProposal.CURSOR_MARKER);
31 } 36 }
32 37
33 protected static String src(String... parts) { 38 protected static String src(String... parts) {
34 return Joiner.on('\n').join(parts); 39 return Joiner.on('\n').join(parts);
35 } 40 }
36 41
37 protected Index index; 42 protected Index index;
38
39 protected SearchEngine searchEngine; 43 protected SearchEngine searchEngine;
40 44
41 @Override 45 @Override
42 public void setUp() { 46 public void setUp() {
43 super.setUp(); 47 super.setUp();
44 index = IndexFactory.newIndex(IndexFactory.newSplitIndexStore(new MemoryNode Manager())); 48 index = IndexFactory.newIndex(IndexFactory.newSplitIndexStore(new MemoryNode Manager()));
45 new Thread() { 49 new Thread() {
46 @Override 50 @Override
47 public void run() { 51 public void run() {
48 index.run(); 52 index.run();
53 index = null;
49 } 54 }
50 }.start(); 55 }.start();
51 searchEngine = SearchEngineFactory.createSearchEngine(index); 56 searchEngine = SearchEngineFactory.createSearchEngine(index);
52 } 57 }
53 58
54 /** 59 /**
55 * Resolve and index all of the compilation units that comprise the libraries specified by the 60 * Resolve and index all of the compilation units that comprise the libraries specified by the
56 * given sources, returning the resolved compilation unit for the last library in the list. 61 * given sources, returning the resolved compilation unit for the last library in the list.
57 * 62 *
58 * @param sources the sources of the libraries to be resolved and indexed 63 * @param sources the sources of the libraries to be resolved and indexed
59 * @throws AnalysisException if the libraries could not be resolved or indexed 64 * @throws AnalysisException if the libraries could not be resolved or indexed
60 */ 65 */
61 protected CompilationUnit resolveAndIndex(List<Source> sources) throws Analysi sException { 66 protected CompilationUnit resolveAndIndex(List<Source> sources) throws Analysi sException {
62 AnalysisContext context = getAnalysisContext(); 67 AnalysisContext context = getAnalysisContext();
63 CompilationUnit libraryUnit = null; 68 CompilationUnit libraryUnit = null;
64 for (Source source : sources) { 69 for (Source source : sources) {
65 LibraryElement library = resolve(source); 70 LibraryElement library = resolve(source);
66 libraryUnit = getAnalysisContext().resolveCompilationUnit(source, library) ; 71 libraryUnit = getAnalysisContext().resolveCompilationUnit(source, library) ;
67 index.indexUnit(context, libraryUnit); 72 index.indexUnit(context, libraryUnit);
68 for (CompilationUnitElement partElement : library.getParts()) { 73 for (CompilationUnitElement partElement : library.getParts()) {
69 CompilationUnit partUnit = getAnalysisContext().resolveCompilationUnit( 74 CompilationUnit partUnit = getAnalysisContext().resolveCompilationUnit(
70 partElement.getSource(), 75 partElement.getSource(),
71 library); 76 library);
72 index.indexUnit(context, partUnit); 77 index.indexUnit(context, partUnit);
73 } 78 }
74 } 79 }
75 return libraryUnit; 80 return libraryUnit;
76 } 81 }
77 82
83 @Override
84 protected void tearDown() throws Exception {
85 index.getRelationships(
86 IndexConstants.UNIVERSE,
87 IndexConstants.IS_READ_BY,
88 new RelationshipCallback() {
89 @Override
90 public void hasRelationships(Element a, Relationship b, Location[] c) {
91 index.stop();
92 }
93 });
94 searchEngine = null;
95 super.tearDown();
96 }
97
78 /** 98 /**
79 * Run a set of completion tests on the given <code>originalSource</code>. The source string has 99 * Run a set of completion tests on the given <code>originalSource</code>. The source string has
80 * completion points embedded in it, which are identified by '!X' where X is a single character. 100 * completion points embedded in it, which are identified by '!X' where X is a single character.
81 * Each X is matched to positive or negative results in the array of 101 * Each X is matched to positive or negative results in the array of
82 * <code>validationStrings</code>. Validation strings contain the name of a pr ediction with a two 102 * <code>validationStrings</code>. Validation strings contain the name of a pr ediction with a two
83 * character prefix. The first character of the prefix corresponds to an X in the 103 * character prefix. The first character of the prefix corresponds to an X in the
84 * <code>originalSource</code>. The second character is either a '+' or a '-' indicating whether 104 * <code>originalSource</code>. The second character is either a '+' or a '-' indicating whether
85 * the string is a positive or negative result. 105 * the string is a positive or negative result.
86 * 106 *
87 * @param originalSource The source for a completion test that contains comple tion points 107 * @param originalSource The source for a completion test that contains comple tion points
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 * the string is a positive or negative result. 156 * the string is a positive or negative result.
137 * 157 *
138 * @param originalSource The source for a completion test that contains comple tion points 158 * @param originalSource The source for a completion test that contains comple tion points
139 * @param validationStrings The positive and negative predictions 159 * @param validationStrings The positive and negative predictions
140 */ 160 */
141 protected void test(String originalSource, String... results) throws URISyntax Exception, 161 protected void test(String originalSource, String... results) throws URISyntax Exception,
142 AnalysisException { 162 AnalysisException {
143 test(originalSource, new ArrayList<Source>(), results); 163 test(originalSource, new ArrayList<Source>(), results);
144 } 164 }
145 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698