| Index: editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionProcessorTest.java
|
| diff --git a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionProcessorTest.java b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionProcessorTest.java
|
| index b4ea813cde89ca32dcf4ab62ac420f156b157e8d..eb560b135bb3797642e277d55de138899b0d80fd 100644
|
| --- a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionProcessorTest.java
|
| +++ b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionProcessorTest.java
|
| @@ -19,6 +19,7 @@ import com.google.dart.tools.core.test.util.TestProject;
|
| import com.google.dart.tools.internal.corext.refactoring.rename.RenameFunctionProcessor;
|
| import com.google.dart.tools.ui.internal.refactoring.RenameSupport;
|
|
|
| +import org.eclipse.ltk.core.refactoring.RefactoringStatus;
|
| import org.eclipse.ui.IWorkbenchWindow;
|
| import org.eclipse.ui.PlatformUI;
|
|
|
| @@ -69,6 +70,7 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| // error should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| assertThat(showStatusMessages).hasSize(1);
|
| + assertEquals(RefactoringStatus.FATAL, showStatusSeverities.get(0).intValue());
|
| assertEquals("Choose another name.", showStatusMessages.get(0));
|
| // no source changes
|
| assertEquals(source, testUnit.getSource());
|
| @@ -86,6 +88,7 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| // warning should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| assertThat(showStatusMessages).hasSize(1);
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| assertEquals(
|
| "By convention, function names usually start with a lowercase letter",
|
| showStatusMessages.get(0));
|
| @@ -173,6 +176,88 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| "");
|
| }
|
|
|
| + /**
|
| + * http://code.google.com/p/dart/issues/detail?id=1180
|
| + */
|
| + public void test_postCondition_field_shadowedBy_topLevel() throws Exception {
|
| + setTestUnitContent(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "test() {}",
|
| + "class A {",
|
| + " var newName;",
|
| + "}",
|
| + "class B extends A {",
|
| + " foo() {",
|
| + " newName = 1;", // will be shadowed by top-level element
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunction function = findElement("test() {");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameFunction(function, "newName");
|
| + fail();
|
| + } catch (InterruptedException e) {
|
| + }
|
| + // error should be displayed
|
| + assertThat(openInformationMessages).isEmpty();
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for declaration in A
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function will be shadowed by field 'A.newName' in 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // error for usage in B
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of field 'A.newName' declared in 'Test/Test.dart' will be shadowed by renamed function",
|
| + showStatusMessages.get(1));
|
| + }
|
| + // no source changes
|
| + assertEquals(source, testUnit.getSource());
|
| + }
|
| +
|
| + public void test_postCondition_field_shadows_topLevel() throws Exception {
|
| + setTestUnitContent(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "test() {}",
|
| + "class A {",
|
| + " var newName;",
|
| + " foo() {",
|
| + " newName = 1;", // field of the enclosing class
|
| + " test();",
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunction function = findElement("test() {");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameFunction(function, "newName");
|
| + fail();
|
| + } catch (InterruptedException e) {
|
| + }
|
| + // error should be displayed
|
| + assertThat(openInformationMessages).isEmpty();
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for shadowing declaration
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function will be shadowed by field 'A.newName' in 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // error for shadowing usage
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of renamed function will be shadowed by field 'A.newName' in 'Test/Test.dart'",
|
| + showStatusMessages.get(1));
|
| + }
|
| + // no source changes
|
| + assertEquals(source, testUnit.getSource());
|
| + }
|
| +
|
| public void test_postCondition_localVariable_inMethod() throws Exception {
|
| setTestUnitContent(
|
| "// filler filler filler filler filler filler filler filler filler filler",
|
| @@ -180,6 +265,7 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| "class A {",
|
| " f() {",
|
| " var newName;",
|
| + " test();",
|
| " }",
|
| "}",
|
| "");
|
| @@ -193,10 +279,19 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| }
|
| // error should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| - assertThat(showStatusMessages).hasSize(1);
|
| - assertEquals(
|
| - "Method 'A.f()' in 'Test/Test.dart' declares variable 'newName' which will shadow renamed function",
|
| - showStatusMessages.get(0));
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for declaration
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function will be shadowed by variable in method 'A.f()' in file 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // error for usage
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of renamed function will be shadowed by variable in method 'A.f()' in file 'Test/Test.dart'",
|
| + showStatusMessages.get(1));
|
| + }
|
| // no source changes
|
| assertEquals(source, testUnit.getSource());
|
| }
|
| @@ -207,6 +302,7 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| "test() {}",
|
| "f() {",
|
| " var newName;",
|
| + " test();",
|
| "}",
|
| "");
|
| DartFunction function = findElement("test() {");
|
| @@ -219,10 +315,101 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| }
|
| // error should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| - assertThat(showStatusMessages).hasSize(1);
|
| - assertEquals(
|
| - "Function 'f()' in 'Test/Test.dart' declares variable 'newName' which will shadow renamed function",
|
| - showStatusMessages.get(0));
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for declaration
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function will be shadowed by variable in function 'f()' in file 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // error for usage
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of renamed function will be shadowed by variable in function 'f()' in file 'Test/Test.dart'",
|
| + showStatusMessages.get(1));
|
| + }
|
| + // no source changes
|
| + assertEquals(source, testUnit.getSource());
|
| + }
|
| +
|
| + /**
|
| + * http://code.google.com/p/dart/issues/detail?id=1180
|
| + */
|
| + public void test_postCondition_method_shadowedBy_topLevel() throws Exception {
|
| + setTestUnitContent(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "test() {}",
|
| + "class A {",
|
| + " newName() {}",
|
| + "}",
|
| + "class B extends A {",
|
| + " foo() {",
|
| + " newName();", // will be shadowed by top-level element
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunction function = findElement("test() {");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameFunction(function, "newName");
|
| + fail();
|
| + } catch (InterruptedException e) {
|
| + }
|
| + // error should be displayed
|
| + assertThat(openInformationMessages).isEmpty();
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for declaration in A
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function will be shadowed by method 'A.newName' in 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // error for usage in B
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of method 'A.newName' declared in 'Test/Test.dart' will be shadowed by renamed function",
|
| + showStatusMessages.get(1));
|
| + }
|
| + // no source changes
|
| + assertEquals(source, testUnit.getSource());
|
| + }
|
| +
|
| + public void test_postCondition_method_shadows_topLevel() throws Exception {
|
| + setTestUnitContent(
|
| + "// filler filler filler filler filler filler filler filler filler filler",
|
| + "test() {}",
|
| + "class A {",
|
| + " newName() {}",
|
| + " foo() {",
|
| + " newName();", // method of the enclosing class
|
| + " test();",
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunction function = findElement("test() {");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameFunction(function, "newName");
|
| + fail();
|
| + } catch (InterruptedException e) {
|
| + }
|
| + // error should be displayed
|
| + assertThat(openInformationMessages).isEmpty();
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for shadowing declaration
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function will be shadowed by method 'A.newName' in 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // error for shadowing usage
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of renamed function will be shadowed by method 'A.newName' in 'Test/Test.dart'",
|
| + showStatusMessages.get(1));
|
| + }
|
| // no source changes
|
| assertEquals(source, testUnit.getSource());
|
| }
|
| @@ -279,28 +466,6 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| check_postCondition_topLevel("variable");
|
| }
|
|
|
| - public void test_postCondition_type_field() throws Exception {
|
| - setTestUnitContent(
|
| - "// filler filler filler filler filler filler filler filler filler filler",
|
| - "test() {}",
|
| - "class A {",
|
| - " var newName;",
|
| - "}",
|
| - "");
|
| - check_postCondition_typeMember("field");
|
| - }
|
| -
|
| - public void test_postCondition_type_method() throws Exception {
|
| - setTestUnitContent(
|
| - "// filler filler filler filler filler filler filler filler filler filler",
|
| - "test() {}",
|
| - "class A {",
|
| - " newName() {}",
|
| - "}",
|
| - "");
|
| - check_postCondition_typeMember("method");
|
| - }
|
| -
|
| public void test_preCondition_hasCompilationErrors() throws Exception {
|
| setUnitContent(
|
| "Test1.dart",
|
| @@ -329,6 +494,7 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| // warning should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| assertThat(showStatusMessages).hasSize(1);
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| assertEquals(
|
| "Code modification may not be accurate as affected resource 'Test/Test2.dart' has compile errors.",
|
| showStatusMessages.get(0));
|
| @@ -362,6 +528,7 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| }
|
| // error should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(0).intValue());
|
| assertThat(showStatusMessages).hasSize(1);
|
| assertEquals("File 'Test/"
|
| + unitName
|
| @@ -371,23 +538,4 @@ public final class RenameFunctionProcessorTest extends RefactoringTest {
|
| // no source changes
|
| assertEquals(source, testUnit.getSource());
|
| }
|
| -
|
| - private void check_postCondition_typeMember(String shadowName) throws Exception {
|
| - DartFunction function = findElement("test() {");
|
| - // try to rename
|
| - String source = testUnit.getSource();
|
| - try {
|
| - renameFunction(function, "newName");
|
| - fail();
|
| - } catch (InterruptedException e) {
|
| - }
|
| - // error should be displayed
|
| - assertThat(openInformationMessages).isEmpty();
|
| - assertThat(showStatusMessages).hasSize(1);
|
| - assertEquals("Type 'A' in 'Test/Test.dart' declares "
|
| - + shadowName
|
| - + " 'newName' which will shadow renamed function", showStatusMessages.get(0));
|
| - // no source changes
|
| - assertEquals(source, testUnit.getSource());
|
| - }
|
| }
|
|
|