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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 10582003: Issue 1355. Support for call(). Tweaks for element locator and rename refactoring (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check target range Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index d492a5f37326dac234de52ef1678489a38f3e46f..150b4b83f271310ef43d43fa28e813363d85bea7 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -36,6 +36,7 @@ import com.google.dart.compiler.ast.DartNode;
import com.google.dart.compiler.ast.DartParameter;
import com.google.dart.compiler.ast.DartUnit;
import com.google.dart.compiler.ast.DartUnqualifiedInvocation;
+import com.google.dart.compiler.common.SourceInfo;
import com.google.dart.compiler.parser.ParserErrorCode;
import com.google.dart.compiler.resolver.ClassElement;
import com.google.dart.compiler.resolver.Element;
@@ -48,7 +49,9 @@ import com.google.dart.compiler.resolver.TypeErrorCode;
import java.io.Reader;
import java.io.StringReader;
import java.net.URI;
+import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Variant of {@link TypeAnalyzerTest}, which is based on {@link CompilerTestCase}. It is probably
@@ -75,6 +78,36 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
}
/**
+ * We should support resolving to the method "call".
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=1355
+ */
+ public void test_resolveCallMethod() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " call() => 42;",
+ "}",
+ "main() {",
+ " A a = new A();",
+ " a();",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ // find a()
+ DartIdentifier aVar = findNode(libraryResult, DartIdentifier.class, "a()");
+ assertNotNull(aVar);
+ DartUnqualifiedInvocation invocation = (DartUnqualifiedInvocation) aVar.getParent();
+ // analyze a() element
+ MethodElement element = (MethodElement) invocation.getElement();
+ assertNotNull(element);
+ assertEquals("call", element.getName());
+ assertEquals(
+ libraryResult.source.indexOf("call() => 42"),
+ element.getNameLocation().getOffset());
+ }
+
+ /**
* It is a compile-time error if a typedef refers to itself via a chain of references that does
* not include a class or interface type.
* <p>
@@ -2613,4 +2646,30 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
private AnalyzeLibraryResult analyzeLibrary(String... lines) throws Exception {
return analyzeLibrary(getName(), makeCode(lines));
}
+
+ private static <T extends DartNode> T findNode(
+ AnalyzeLibraryResult libraryResult,
+ final Class<T> clazz,
+ String pattern) {
+ final int index = libraryResult.source.indexOf(pattern);
+ assertTrue(index != -1);
+ final AtomicReference<T> result = new AtomicReference<T>();
+ Iterator<DartUnit> unitsIterator = libraryResult.getLibraryUnitResult().getUnits().iterator();
+ unitsIterator.next();
+ DartUnit unit = unitsIterator.next();
+ unit.accept(new ASTVisitor<Void>() {
+ @Override
+ @SuppressWarnings("unchecked")
+ public Void visitNode(DartNode node) {
+ SourceInfo sourceInfo = node.getSourceInfo();
+ if (sourceInfo.getOffset() <= index
+ && index < sourceInfo.getEnd()
+ && clazz.isInstance(node)) {
+ result.set((T) node);
+ }
+ return super.visitNode(node);
+ }
+ });
+ return result.get();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698