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

Unified Diff: editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/NewSearchEngineTest.java

Issue 10381080: Support for renaming getters and setters (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: If no getter/setter, keep FieldElement Created 8 years, 7 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: editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/NewSearchEngineTest.java
diff --git a/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/NewSearchEngineTest.java b/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/NewSearchEngineTest.java
index 1cfd70e3ca67a1e293424529a43e9ff6b7c04295..fb8919b5c0441fc37922169dd1637e85034e0757 100644
--- a/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/NewSearchEngineTest.java
+++ b/editor/tools/plugins/com.google.dart.tools.core_test/src/com/google/dart/tools/core/search/NewSearchEngineTest.java
@@ -13,6 +13,9 @@
*/
package com.google.dart.tools.core.search;
+import static com.google.dart.tools.core.test.util.MoneyProjectUtilities.getMoneyProject;
+import static org.fest.assertions.Assertions.assertThat;
+
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.dart.compiler.DartCompilationError;
@@ -36,15 +39,11 @@ import com.google.dart.tools.core.model.Type;
import com.google.dart.tools.core.test.util.TestProject;
import com.google.dart.tools.core.utilities.compiler.DartCompilerUtilities;
-import static com.google.dart.tools.core.test.util.MoneyProjectUtilities.getMoneyProject;
-
import junit.framework.TestCase;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
-import static org.fest.assertions.Assertions.assertThat;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -218,6 +217,72 @@ public class NewSearchEngineTest extends TestCase {
}
}
+ public void test_SearchEngine_searchReferences_function_getter() throws Exception {
+ TestProject testProject = new TestProject();
+ try {
+ String source = buildSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "int get test() {",
+ " return 42;",
+ "}",
+ "f() {",
+ " process(test);",
+ "}",
+ "process(x) {}",
+ "");
+ CompilationUnit unit = testProject.setUnitContent("Test.dart", source);
+ indexUnits(unit);
+ // find references
+ DartFunction function = (DartFunction) unit.getChildren()[0];
+ SearchEngine engine = createSearchEngine();
+ List<SearchMatch> matches = engine.searchReferences(
+ function,
+ SearchScopeFactory.createWorkspaceScope(),
+ null,
+ new NullProgressMonitor());
+ assertThat(matches).hasSize(1);
+ // assert references
+ SearchMatch match = matches.get(0);
+ int matchOffset = match.getSourceRange().getOffset();
+ assertEquals(source.indexOf("test);"), matchOffset);
+ assertFalse(match.isQualified());
+ } finally {
+ testProject.dispose();
+ }
+ }
+
+ public void test_SearchEngine_searchReferences_function_setter() throws Exception {
+ TestProject testProject = new TestProject();
+ try {
+ String source = buildSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "int set test(x) {",
+ "}",
+ "f() {",
+ " test = 42;",
+ "}",
+ "");
+ CompilationUnit unit = testProject.setUnitContent("Test.dart", source);
+ indexUnits(unit);
+ // find references
+ DartFunction function = (DartFunction) unit.getChildren()[0];
+ SearchEngine engine = createSearchEngine();
+ List<SearchMatch> matches = engine.searchReferences(
+ function,
+ SearchScopeFactory.createWorkspaceScope(),
+ null,
+ new NullProgressMonitor());
+ assertThat(matches).hasSize(1);
+ // assert references
+ SearchMatch match = matches.get(0);
+ int matchOffset = match.getSourceRange().getOffset();
+ assertEquals(source.indexOf("test = 42;"), matchOffset);
+ assertFalse(match.isQualified());
+ } finally {
+ testProject.dispose();
+ }
+ }
+
/**
* There was bug that argument of {@link DartMethodInvocation} was not in search results.
* <p>
@@ -474,6 +539,78 @@ public class NewSearchEngineTest extends TestCase {
}
}
+ public void test_SearchEngine_searchReferences_method_getter() throws Exception {
+ TestProject testProject = new TestProject();
+ try {
+ String source = buildSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " int get test() {",
+ " return 42;",
+ " }",
+ "}",
+ "f() {",
+ " A a = new A();",
+ " process(a.test);",
+ "}",
+ "process(x) {}",
+ "");
+ CompilationUnit unit = testProject.setUnitContent("Test.dart", source);
+ indexUnits(unit);
+ // find references
+ Method method = ((Type) unit.getChildren()[0]).getMethod("test", null);
+ SearchEngine engine = createSearchEngine();
+ List<SearchMatch> matches = engine.searchReferences(
+ method,
+ SearchScopeFactory.createWorkspaceScope(),
+ null,
+ new NullProgressMonitor());
+ assertThat(matches).hasSize(1);
+ // assert references
+ SearchMatch match = matches.get(0);
+ int matchOffset = match.getSourceRange().getOffset();
+ assertEquals(source.indexOf("test);"), matchOffset);
+ assertTrue(match.isQualified());
+ } finally {
+ testProject.dispose();
+ }
+ }
+
+ public void test_SearchEngine_searchReferences_method_setter() throws Exception {
+ TestProject testProject = new TestProject();
+ try {
+ String source = buildSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " void set test(x) {",
+ " }",
+ "}",
+ "f() {",
+ " A a = new A();",
+ " a.test = 42;",
+ "}",
+ "");
+ CompilationUnit unit = testProject.setUnitContent("Test.dart", source);
+ indexUnits(unit);
+ // find references
+ Method method = ((Type) unit.getChildren()[0]).getMethod("test", null);
+ SearchEngine engine = createSearchEngine();
+ List<SearchMatch> matches = engine.searchReferences(
+ method,
+ SearchScopeFactory.createWorkspaceScope(),
+ null,
+ new NullProgressMonitor());
+ assertThat(matches).hasSize(1);
+ // assert references
+ SearchMatch match = matches.get(0);
+ int matchOffset = match.getSourceRange().getOffset();
+ assertEquals(source.indexOf("test = 42;"), matchOffset);
+ assertTrue(match.isQualified());
+ } finally {
+ testProject.dispose();
+ }
+ }
+
public void test_SearchEngine_searchReferences_type() throws Exception {
Type type = moneyLibrary.getCompilationUnit("simple_money.dart").getType("SimpleMoney");
SearchEngine engine = createSearchEngine();

Powered by Google App Engine
This is Rietveld 408576698