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

Side by Side Diff: editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/context/AnalysisContextFactory.java

Issue 14007011: Test clean-up (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/TypePropagationTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, the Dart project authors. 2 * Copyright (c) 2013, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
11 * or implied. See the License for the specific language governing permissions a nd limitations under 11 * or implied. See the License for the specific language governing permissions a nd limitations under
12 * the License. 12 * the License.
13 */ 13 */
14 package com.google.dart.engine.context; 14 package com.google.dart.engine.context;
15 15
16 import com.google.dart.engine.element.ClassElement; 16 import com.google.dart.engine.element.ClassElement;
17 import com.google.dart.engine.element.FunctionElement;
17 import com.google.dart.engine.element.LibraryElement; 18 import com.google.dart.engine.element.LibraryElement;
19 import com.google.dart.engine.element.MethodElement;
20 import com.google.dart.engine.element.TopLevelVariableElement;
18 import com.google.dart.engine.internal.context.AnalysisContextImpl; 21 import com.google.dart.engine.internal.context.AnalysisContextImpl;
22 import com.google.dart.engine.internal.element.ClassElementImpl;
19 import com.google.dart.engine.internal.element.CompilationUnitElementImpl; 23 import com.google.dart.engine.internal.element.CompilationUnitElementImpl;
20 import com.google.dart.engine.internal.element.LibraryElementImpl; 24 import com.google.dart.engine.internal.element.LibraryElementImpl;
25 import com.google.dart.engine.internal.element.TopLevelVariableElementImpl;
21 import com.google.dart.engine.internal.resolver.TestTypeProvider; 26 import com.google.dart.engine.internal.resolver.TestTypeProvider;
22 import com.google.dart.engine.sdk.DartSdk; 27 import com.google.dart.engine.sdk.DartSdk;
23 import com.google.dart.engine.sdk.DirectoryBasedDartSdk; 28 import com.google.dart.engine.sdk.DirectoryBasedDartSdk;
24 import com.google.dart.engine.source.DartUriResolver; 29 import com.google.dart.engine.source.DartUriResolver;
25 import com.google.dart.engine.source.FileUriResolver; 30 import com.google.dart.engine.source.FileUriResolver;
26 import com.google.dart.engine.source.Source; 31 import com.google.dart.engine.source.Source;
27 import com.google.dart.engine.source.SourceFactory; 32 import com.google.dart.engine.source.SourceFactory;
33 import com.google.dart.engine.type.InterfaceType;
34 import com.google.dart.engine.type.Type;
28 35
29 import static com.google.dart.engine.ast.ASTFactory.libraryIdentifier; 36 import static com.google.dart.engine.ast.ASTFactory.libraryIdentifier;
37 import static com.google.dart.engine.element.ElementFactory.classElement;
38 import static com.google.dart.engine.element.ElementFactory.functionElement;
39 import static com.google.dart.engine.element.ElementFactory.methodElement;
40 import static com.google.dart.engine.element.ElementFactory.topLevelVariableElem ent;
30 41
31 import java.util.HashMap; 42 import java.util.HashMap;
32 43
33 /** 44 /**
34 * The class {@code AnalysisContextFactory} defines utility methods used to crea te analysis contexts 45 * The class {@code AnalysisContextFactory} defines utility methods used to crea te analysis contexts
35 * for testing purposes. 46 * for testing purposes.
36 */ 47 */
37 public final class AnalysisContextFactory { 48 public final class AnalysisContextFactory {
38 /** 49 /**
39 * Create an analysis context that has a fake core library already resolved. 50 * Create an analysis context that has a fake core library already resolved.
(...skipping 22 matching lines...) Expand all
62 LibraryElementImpl coreLibrary = new LibraryElementImpl(context, libraryIden tifier( 73 LibraryElementImpl coreLibrary = new LibraryElementImpl(context, libraryIden tifier(
63 "dart", 74 "dart",
64 "core")); 75 "core"));
65 coreLibrary.setDefiningCompilationUnit(coreUnit); 76 coreLibrary.setDefiningCompilationUnit(coreUnit);
66 // 77 //
67 // dart:html 78 // dart:html
68 // 79 //
69 CompilationUnitElementImpl htmlUnit = new CompilationUnitElementImpl("html_d artium.dart"); 80 CompilationUnitElementImpl htmlUnit = new CompilationUnitElementImpl("html_d artium.dart");
70 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); 81 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML);
71 htmlUnit.setSource(htmlSource); 82 htmlUnit.setSource(htmlSource);
83 ClassElementImpl elementElement = classElement("Element");
84 InterfaceType elementType = elementElement.getType();
85 ClassElementImpl documentElement = classElement("Document", elementType);
86 ClassElementImpl htmlDocumentElement = classElement("HtmlDocument", document Element.getType());
87 htmlDocumentElement.setMethods(new MethodElement[] {methodElement(
88 "query",
89 elementType,
90 new Type[] {provider.getStringType()})});
91 htmlUnit.setTypes(new ClassElement[] {
92 classElement("AnchorElement", elementType), classElement("BodyElement", elementType),
93 classElement("ButtonElement", elementType), classElement("DivElement", e lementType),
94 documentElement, elementElement, htmlDocumentElement,
95 classElement("InputElement", elementType), classElement("SelectElement", elementType),});
96 htmlUnit.setFunctions(new FunctionElement[] {functionElement(
97 "query",
98 elementElement,
99 new ClassElement[] {provider.getStringType().getElement()},
100 ClassElementImpl.EMPTY_ARRAY)});
101 TopLevelVariableElementImpl document = topLevelVariableElement("document");
102 document.setType(htmlDocumentElement.getType());
103 htmlUnit.setTopLevelVariables(new TopLevelVariableElement[] {document});
72 LibraryElementImpl htmlLibrary = new LibraryElementImpl(context, libraryIden tifier( 104 LibraryElementImpl htmlLibrary = new LibraryElementImpl(context, libraryIden tifier(
73 "dart", 105 "dart",
74 "dom", 106 "dom",
75 "html")); 107 "html"));
76 htmlLibrary.setDefiningCompilationUnit(htmlUnit); 108 htmlLibrary.setDefiningCompilationUnit(htmlUnit);
77 109
78 HashMap<Source, LibraryElement> elementMap = new HashMap<Source, LibraryElem ent>(); 110 HashMap<Source, LibraryElement> elementMap = new HashMap<Source, LibraryElem ent>();
79 elementMap.put(coreSource, coreLibrary); 111 elementMap.put(coreSource, coreLibrary);
80 elementMap.put(htmlSource, htmlLibrary); 112 elementMap.put(htmlSource, htmlLibrary);
81 113
82 context.setContents(coreSource, ""); 114 context.setContents(coreSource, "");
83 context.setContents(htmlSource, ""); 115 context.setContents(htmlSource, "");
84 context.recordLibraryElements(elementMap); 116 context.recordLibraryElements(elementMap);
85 return context; 117 return context;
86 } 118 }
87 119
88 /** 120 /**
89 * Prevent the creation of instances of this class. 121 * Prevent the creation of instances of this class.
90 */ 122 */
91 private AnalysisContextFactory() { 123 private AnalysisContextFactory() {
92 } 124 }
93 } 125 }
OLDNEW
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/resolver/TypePropagationTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698