| Index: editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionTypeAliasProcessorTest.java
|
| diff --git a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionTypeAliasProcessorTest.java b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionTypeAliasProcessorTest.java
|
| index 0ae8f35d84e9e7a9e8dd33eabba8e06f7ac0b652..0abb47bd42863b01f44de0feb70b398bf1fd5a37 100644
|
| --- a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionTypeAliasProcessorTest.java
|
| +++ b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameFunctionTypeAliasProcessorTest.java
|
| @@ -20,6 +20,7 @@ import com.google.dart.tools.internal.corext.refactoring.rename.RenameFunctionTy
|
| import com.google.dart.tools.internal.corext.refactoring.rename.RenameTypeProcessor;
|
| 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;
|
|
|
| @@ -72,6 +73,7 @@ public final class RenameFunctionTypeAliasProcessorTest 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());
|
| @@ -89,6 +91,7 @@ public final class RenameFunctionTypeAliasProcessorTest extends RefactoringTest
|
| // warning should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| assertThat(showStatusMessages).hasSize(1);
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| assertEquals(
|
| "By convention, function type alias names usually start with an uppercase letter",
|
| showStatusMessages.get(0));
|
| @@ -168,6 +171,88 @@ public final class RenameFunctionTypeAliasProcessorTest 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",
|
| + "typedef Test();",
|
| + "class A {",
|
| + " var NewName;",
|
| + "}",
|
| + "class B extends A {",
|
| + " foo() {",
|
| + " NewName = 1;", // will be shadowed by top-level element
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunctionTypeAlias type = findElement("Test()");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameType(type, "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 type alias 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 type alias",
|
| + 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",
|
| + "typedef Test();",
|
| + "class A {",
|
| + " var NewName;",
|
| + " foo() {",
|
| + " NewName = 1;", // field of the enclosing class
|
| + " Test t;",
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunctionTypeAlias type = findElement("Test()");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameType(type, "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 type alias 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 type alias 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",
|
| @@ -175,23 +260,33 @@ public final class RenameFunctionTypeAliasProcessorTest extends RefactoringTest
|
| "class A {",
|
| " f() {",
|
| " var NewName;",
|
| + " Test t;",
|
| " }",
|
| "}",
|
| "");
|
| - DartFunctionTypeAlias functionTypeAlias = findElement("Test();");
|
| + DartFunctionTypeAlias type = findElement("Test()");
|
| // try to rename
|
| String source = testUnit.getSource();
|
| try {
|
| - renameType(functionTypeAlias, "NewName");
|
| + renameType(type, "NewName");
|
| fail();
|
| } catch (InterruptedException e) {
|
| }
|
| // 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 type alias",
|
| - showStatusMessages.get(0));
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for shadowing declaration
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function type alias will be shadowed by variable in method 'A.f()' in file 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // warning for shadowing usage
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of renamed function type alias will be shadowed by variable in method 'A.f()' in file 'Test/Test.dart'",
|
| + showStatusMessages.get(1));
|
| + }
|
| // no source changes
|
| assertEquals(source, testUnit.getSource());
|
| }
|
| @@ -202,22 +297,114 @@ public final class RenameFunctionTypeAliasProcessorTest extends RefactoringTest
|
| "typedef Test();",
|
| "f() {",
|
| " var NewName;",
|
| + " Test t;",
|
| "}",
|
| "");
|
| - DartFunctionTypeAlias functionTypeAlias = findElement("Test();");
|
| + DartFunctionTypeAlias type = findElement("Test()");
|
| // try to rename
|
| String source = testUnit.getSource();
|
| try {
|
| - renameType(functionTypeAlias, "NewName");
|
| + renameType(type, "NewName");
|
| fail();
|
| } catch (InterruptedException e) {
|
| }
|
| // 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 type alias",
|
| - showStatusMessages.get(0));
|
| + {
|
| + assertThat(showStatusMessages).hasSize(2);
|
| + // warning for shadowing declaration
|
| + assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
|
| + assertEquals(
|
| + "Declaration of renamed function type alias will be shadowed by variable in function 'f()' in file 'Test/Test.dart'",
|
| + showStatusMessages.get(0));
|
| + // warning for shadowing usage
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(1).intValue());
|
| + assertEquals(
|
| + "Usage of renamed function type alias 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",
|
| + "typedef Test();",
|
| + "class A {",
|
| + " NewName() {}",
|
| + "}",
|
| + "class B extends A {",
|
| + " foo() {",
|
| + " NewName();", // will be shadowed by top-level element
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunctionTypeAlias type = findElement("Test()");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameType(type, "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 type alias 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 type alias",
|
| + 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",
|
| + "typedef Test();",
|
| + "class A {",
|
| + " NewName() {}",
|
| + " foo() {",
|
| + " NewName();", // method of the enclosing class
|
| + " Test t;",
|
| + " }",
|
| + "}",
|
| + "");
|
| + DartFunctionTypeAlias type = findElement("Test()");
|
| + // try to rename
|
| + String source = testUnit.getSource();
|
| + try {
|
| + renameType(type, "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 type alias 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 type alias will be shadowed by method 'A.NewName' in 'Test/Test.dart'",
|
| + showStatusMessages.get(1));
|
| + }
|
| // no source changes
|
| assertEquals(source, testUnit.getSource());
|
| }
|
| @@ -274,28 +461,6 @@ public final class RenameFunctionTypeAliasProcessorTest 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",
|
| - "typedef 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",
|
| - "typedef Test();",
|
| - "class A {",
|
| - " NewName() {}",
|
| - "}",
|
| - "");
|
| - check_postCondition_typeMember("method");
|
| - }
|
| -
|
| public void test_preCondition_hasCompilationErrors() throws Exception {
|
| setUnitContent(
|
| "Test1.dart",
|
| @@ -323,6 +488,7 @@ public final class RenameFunctionTypeAliasProcessorTest 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));
|
| @@ -356,6 +522,7 @@ public final class RenameFunctionTypeAliasProcessorTest extends RefactoringTest
|
| // error should be displayed
|
| assertThat(openInformationMessages).isEmpty();
|
| assertThat(showStatusMessages).hasSize(1);
|
| + assertEquals(RefactoringStatus.ERROR, showStatusSeverities.get(0).intValue());
|
| assertEquals("File 'Test/"
|
| + unitName
|
| + "' in library 'Test' already declares top-level "
|
| @@ -364,23 +531,4 @@ public final class RenameFunctionTypeAliasProcessorTest extends RefactoringTest
|
| // no source changes
|
| assertEquals(source, testUnit.getSource());
|
| }
|
| -
|
| - private void check_postCondition_typeMember(String shadowName) throws Exception {
|
| - DartFunctionTypeAlias functionTypeAlias = findElement("Test();");
|
| - // try to rename
|
| - String source = testUnit.getSource();
|
| - try {
|
| - renameType(functionTypeAlias, "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 type alias", showStatusMessages.get(0));
|
| - // no source changes
|
| - assertEquals(source, testUnit.getSource());
|
| - }
|
| }
|
|
|