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

Side by Side Diff: compiler/javatests/com/google/dart/compiler/IdeTest.java

Issue 9633009: Use Element instead of Symbol. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 com.google.dart.compiler.ast.DartClass; 7 import com.google.dart.compiler.ast.DartClass;
8 import com.google.dart.compiler.ast.DartExprStmt; 8 import com.google.dart.compiler.ast.DartExprStmt;
9 import com.google.dart.compiler.ast.DartExpression; 9 import com.google.dart.compiler.ast.DartExpression;
10 import com.google.dart.compiler.ast.DartIdentifier; 10 import com.google.dart.compiler.ast.DartIdentifier;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 " Function voidFunction;", 144 " Function voidFunction;",
145 " void foo() {", 145 " void foo() {",
146 " void", // Missing semicolon and keyword 146 " void", // Missing semicolon and keyword
147 " }", 147 " }",
148 "}"); 148 "}");
149 // Expected identifier and missing semicolon. 149 // Expected identifier and missing semicolon.
150 assertEquals("errorCount", 2, context.getErrorCount()); 150 assertEquals("errorCount", 2, context.getErrorCount());
151 assertEquals("typeErrorCount", 1, context.getTypeErrorCount()); // void cann ot be resolved. 151 assertEquals("typeErrorCount", 1, context.getTypeErrorCount()); // void cann ot be resolved.
152 DartExprStmt statement = (DartExprStmt) firstStatementOfMethod(unit, "Foo", "foo"); 152 DartExprStmt statement = (DartExprStmt) firstStatementOfMethod(unit, "Foo", "foo");
153 DartIdentifier expression = (DartIdentifier) statement.getExpression(); 153 DartIdentifier expression = (DartIdentifier) statement.getExpression();
154 assertEquals("void", expression.getTargetName()); 154 assertEquals("void", expression.getName());
155 } 155 }
156 156
157 public void testAnalyseVoidKeywordPropertyAccess() { 157 public void testAnalyseVoidKeywordPropertyAccess() {
158 DartUnit unit = analyzeUnit("void_keyword_property_access", 158 DartUnit unit = analyzeUnit("void_keyword_property_access",
159 "class Foo {", 159 "class Foo {",
160 " Function voidFunction;", 160 " Function voidFunction;",
161 " void foo() {", 161 " void foo() {",
162 " this.void", // Missing semicolon and keywor d 162 " this.void", // Missing semicolon and keywor d
163 " }", 163 " }",
164 "}"); 164 "}");
(...skipping 10 matching lines...) Expand all
175 "class Foo {", 175 "class Foo {",
176 " int i;", 176 " int i;",
177 " int foo() {", 177 " int foo() {",
178 " return i;", 178 " return i;",
179 " }", 179 " }",
180 "}"); 180 "}");
181 Scope unitScope = unit.getLibrary().getElement().getScope(); 181 Scope unitScope = unit.getLibrary().getElement().getScope();
182 CoreTypeProvider typeProvider = new CoreTypeProviderImplementation(unitScope , context); 182 CoreTypeProvider typeProvider = new CoreTypeProviderImplementation(unitScope , context);
183 DartClass classNode = firstClassOfUnit(unit, "Foo"); 183 DartClass classNode = firstClassOfUnit(unit, "Foo");
184 DartReturnStatement rtnStmt = (DartReturnStatement) firstStatementOfMethod(u nit, "Foo", "foo"); 184 DartReturnStatement rtnStmt = (DartReturnStatement) firstStatementOfMethod(u nit, "Foo", "foo");
185 ClassElement classElement = classNode.getSymbol(); 185 ClassElement classElement = classNode.getElement();
186 InterfaceType definingType = classElement.getType(); 186 InterfaceType definingType = classElement.getType();
187 Type type = TypeAnalyzer.analyze(rtnStmt.getValue(), typeProvider, context, definingType); 187 Type type = TypeAnalyzer.analyze(rtnStmt.getValue(), typeProvider, context, definingType);
188 assertNotNull(type); 188 assertNotNull(type);
189 assertEquals("int", type.getElement().getName()); 189 assertEquals("int", type.getElement().getName());
190 } 190 }
191 191
192 private Element targetElement(DartExpression expression) { 192 private Element targetElement(DartExpression expression) {
193 DartIdentifier identifier = (DartIdentifier) expression; 193 DartIdentifier identifier = (DartIdentifier) expression;
194 Element element = identifier.getTargetSymbol(); 194 Element element = identifier.getElement();
195 assertNotNull(element); 195 assertNotNull(element);
196 return element; 196 return element;
197 } 197 }
198 198
199 private Element qualifierElement(DartExpression node) { 199 private Element qualifierElement(DartExpression node) {
200 DartPropertyAccess propertyAccess = (DartPropertyAccess) node; 200 DartPropertyAccess propertyAccess = (DartPropertyAccess) node;
201 DartIdentifier identifier = (DartIdentifier) propertyAccess.getQualifier(); 201 DartIdentifier identifier = (DartIdentifier) propertyAccess.getQualifier();
202 Element element = identifier.getTargetSymbol(); 202 Element element = identifier.getElement();
203 assertNotNull(element); 203 assertNotNull(element);
204 return element; 204 return element;
205 } 205 }
206 206
207 private DartClass firstClassOfUnit(DartUnit unit, String cls) { 207 private DartClass firstClassOfUnit(DartUnit unit, String cls) {
208 DartClass dartClass = null; 208 DartClass dartClass = null;
209 for (DartNode dartNode : unit.getTopLevelNodes()) { 209 for (DartNode dartNode : unit.getTopLevelNodes()) {
210 Element element = (Element) dartNode.getSymbol(); 210 Element element = (Element) dartNode.getElement();
211 if (element.getName().equals(cls)) { 211 if (element.getName().equals(cls)) {
212 dartClass = (DartClass) dartNode; 212 dartClass = (DartClass) dartNode;
213 break; 213 break;
214 } 214 }
215 } 215 }
216 assertNotNull(dartClass); 216 assertNotNull(dartClass);
217 return dartClass; 217 return dartClass;
218 } 218 }
219 219
220 private DartStatement firstStatementOfMethod(DartUnit unit, String cls, String member) { 220 private DartStatement firstStatementOfMethod(DartUnit unit, String cls, String member) {
221 ClassElement classElement = firstClassOfUnit(unit, cls).getSymbol(); 221 ClassElement classElement = firstClassOfUnit(unit, cls).getElement();
222 MethodElement method = (MethodElement) classElement.lookupLocalElement(membe r); 222 MethodElement method = (MethodElement) classElement.lookupLocalElement(membe r);
223 assertNotNull(String.format("Member '%s' not found in %s", member, cls), met hod); 223 assertNotNull(String.format("Member '%s' not found in %s", member, cls), met hod);
224 DartMethodDefinition methodNode = (DartMethodDefinition) method.getNode(); 224 DartMethodDefinition methodNode = (DartMethodDefinition) method.getNode();
225 assertNotNull(methodNode); 225 assertNotNull(methodNode);
226 return methodNode.getFunction().getBody().getStatements().get(0); 226 return methodNode.getFunction().getBody().getStatements().get(0);
227 } 227 }
228 228
229 private DartUnit analyzeUnit(String name, String... sourceLines) throws Assert ionError { 229 private DartUnit analyzeUnit(String name, String... sourceLines) throws Assert ionError {
230 TestLibrarySource lib = new TestLibrarySource(name); 230 TestLibrarySource lib = new TestLibrarySource(name);
231 lib.addSource(name + ".dart", sourceLines); 231 lib.addSource(name + ".dart", sourceLines);
232 LibraryUnit libraryUnit; 232 LibraryUnit libraryUnit;
233 try { 233 try {
234 libraryUnit = DartCompiler.analyzeLibrary(lib, null, config, provider, lis tener); 234 libraryUnit = DartCompiler.analyzeLibrary(lib, null, config, provider, lis tener);
235 assertNotNull("libraryUnit == null", libraryUnit); 235 assertNotNull("libraryUnit == null", libraryUnit);
236 } catch (IOException e) { 236 } catch (IOException e) {
237 throw new AssertionError(e); 237 throw new AssertionError(e);
238 } 238 }
239 DartUnit unit = libraryUnit.getUnit(name + ".dart"); 239 DartUnit unit = libraryUnit.getUnit(name + ".dart");
240 assertNotNull("unit == null", unit); 240 assertNotNull("unit == null", unit);
241 return unit; 241 return unit;
242 } 242 }
243 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698