OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler; | 5 package com.google.dart.compiler; |
6 | 6 |
7 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; | 7 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; |
8 | 8 |
9 import com.google.common.collect.Lists; | 9 import com.google.common.collect.Lists; |
10 import com.google.common.collect.Maps; | 10 import com.google.common.collect.Maps; |
11 import com.google.common.collect.Sets; | 11 import com.google.common.collect.Sets; |
12 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; | 12 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; |
13 import com.google.dart.compiler.ast.ASTVisitor; | 13 import com.google.dart.compiler.ast.ASTVisitor; |
14 import com.google.dart.compiler.ast.DartExpression; | 14 import com.google.dart.compiler.ast.DartExpression; |
15 import com.google.dart.compiler.ast.DartFunctionTypeAlias; | 15 import com.google.dart.compiler.ast.DartFunctionTypeAlias; |
16 import com.google.dart.compiler.ast.DartIdentifier; | 16 import com.google.dart.compiler.ast.DartIdentifier; |
17 import com.google.dart.compiler.ast.DartNode; | 17 import com.google.dart.compiler.ast.DartNode; |
18 import com.google.dart.compiler.ast.DartUnit; | 18 import com.google.dart.compiler.ast.DartUnit; |
19 import com.google.dart.compiler.ast.LibraryUnit; | 19 import com.google.dart.compiler.ast.LibraryUnit; |
20 import com.google.dart.compiler.common.ErrorExpectation; | 20 import com.google.dart.compiler.common.ErrorExpectation; |
21 import com.google.dart.compiler.common.SourceInfo; | 21 import com.google.dart.compiler.common.SourceInfo; |
22 import com.google.dart.compiler.end2end.inc.MemoryLibrarySource; | |
23 import com.google.dart.compiler.parser.DartParser; | 22 import com.google.dart.compiler.parser.DartParser; |
24 import com.google.dart.compiler.parser.DartParserRunner; | 23 import com.google.dart.compiler.parser.DartParserRunner; |
25 import com.google.dart.compiler.resolver.Element; | 24 import com.google.dart.compiler.resolver.Element; |
26 import com.google.dart.compiler.type.Type; | 25 import com.google.dart.compiler.type.Type; |
27 import com.google.dart.compiler.type.TypeKind; | 26 import com.google.dart.compiler.type.TypeKind; |
28 | 27 |
29 import junit.framework.TestCase; | 28 import junit.framework.TestCase; |
30 | 29 |
31 import java.io.IOException; | 30 import java.io.IOException; |
32 import java.io.InputStreamReader; | 31 import java.io.InputStreamReader; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 180 |
182 @Override | 181 @Override |
183 protected void tearDown() throws Exception { | 182 protected void tearDown() throws Exception { |
184 compilerConfiguration = null; | 183 compilerConfiguration = null; |
185 testSource = null; | 184 testSource = null; |
186 testUnit = null; | 185 testUnit = null; |
187 super.tearDown(); | 186 super.tearDown(); |
188 } | 187 } |
189 | 188 |
190 protected AnalyzeLibraryResult analyzeLibrary(String... lines) throws Exceptio
n { | 189 protected AnalyzeLibraryResult analyzeLibrary(String... lines) throws Exceptio
n { |
| 190 String name = getName(); |
191 testSource = makeCode(lines); | 191 testSource = makeCode(lines); |
192 AnalyzeLibraryResult libraryResult = analyzeLibrary(testSource); | 192 AnalyzeLibraryResult libraryResult = analyzeLibrary(name, testSource); |
193 testUnit = libraryResult.getLibraryUnitResult().getUnits().iterator().next()
; | 193 testUnit = libraryResult.getLibraryUnitResult().getUnit(name); |
194 return libraryResult; | 194 return libraryResult; |
195 } | 195 } |
196 | 196 |
197 /** | 197 /** |
198 * Simulate running {@code analyzeLibrary} the way the IDE will. | 198 * Simulate running {@code analyzeLibrary} the way the IDE will. |
199 * <p> | 199 * <p> |
200 * <b>Note:</b> if the IDE changes how it calls analyzeLibrary, this should | 200 * <b>Note:</b> if the IDE changes how it calls analyzeLibrary, this should |
201 * be changed to match. | 201 * be changed to match. |
| 202 * |
| 203 * @param name the name to use for the source file |
202 * @param code the Dart code to parse/analyze | 204 * @param code the Dart code to parse/analyze |
203 * | |
204 * @return an {@link AnalyzeLibraryResult} containing the {@link LibraryUnit} | 205 * @return an {@link AnalyzeLibraryResult} containing the {@link LibraryUnit} |
205 * and all the errors/warnings generated from the supplied code | 206 * and all the errors/warnings generated from the supplied code |
206 * @throws Exception | 207 * @throws Exception |
207 */ | 208 */ |
208 protected AnalyzeLibraryResult analyzeLibrary(String code) | 209 protected AnalyzeLibraryResult analyzeLibrary(String name, String code) |
209 throws Exception { | 210 throws Exception { |
210 AnalyzeLibraryResult result = new AnalyzeLibraryResult(); | 211 AnalyzeLibraryResult result = new AnalyzeLibraryResult(); |
211 result.source = code; | 212 result.source = code; |
212 // Prepare library. | 213 // Prepare library. |
213 MemoryLibrarySource lib = new MemoryLibrarySource("Test.dart"); | 214 MockLibrarySource lib = new MockLibrarySource(); |
214 lib.setContent("Test.dart", code); | |
215 // Prepare unit. | 215 // Prepare unit. |
216 Map<URI, DartUnit> testUnits = Maps.newHashMap(); | 216 Map<URI, DartUnit> testUnits = Maps.newHashMap(); |
217 { | 217 { |
218 DartSource src = lib.getSourceFor("Test.dart"); | 218 DartSource src = new DartSourceTest(name, code, lib); |
219 DartUnit unit = makeParser(src, code, result).parseUnit(); | 219 DartUnit unit = makeParser(src, code, result).parseUnit(); |
| 220 // Remember unit. |
| 221 lib.addSource(src); |
220 testUnits.put(src.getUri(), unit); | 222 testUnits.put(src.getUri(), unit); |
221 } | 223 } |
222 DartArtifactProvider provider = new MockArtifactProvider(); | 224 DartArtifactProvider provider = new MockArtifactProvider(); |
223 result.setLibraryUnitResult(DartCompiler.analyzeLibrary( | 225 result.setLibraryUnitResult(DartCompiler.analyzeLibrary( |
224 lib, | 226 lib, |
225 testUnits, | 227 testUnits, |
226 compilerConfiguration, | 228 compilerConfiguration, |
227 provider, | 229 provider, |
228 result)); | 230 result)); |
229 // TODO(zundel): One day, we want all AST nodes that are identifiers to poin
t to | 231 // TODO(zundel): One day, we want all AST nodes that are identifiers to poin
t to |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 Element element = node.getElement(); | 496 Element element = node.getElement(); |
495 if (element != null && element.getName().equals(name)) { | 497 if (element != null && element.getName().equals(name)) { |
496 result[0] = element; | 498 result[0] = element; |
497 } | 499 } |
498 return super.visitIdentifier(node); | 500 return super.visitIdentifier(node); |
499 } | 501 } |
500 }); | 502 }); |
501 return result[0]; | 503 return result[0]; |
502 } | 504 } |
503 } | 505 } |
OLD | NEW |