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

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameTypeProcessorTest.java

Issue 10162026: Report warnings and non-fatal errors for shadowing declaration and usage. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks for review comments Created 8 years, 8 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.ui_test/src/com/google/dart/tools/ui/refactoring/RenameTypeProcessorTest.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameTypeProcessorTest.java b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameTypeProcessorTest.java
index 30751b7fcf75d5b1a0407e321472c55dcac707e9..a27e1946a3e2a7f8667f3d9e49329568eba569ce 100644
--- a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameTypeProcessorTest.java
+++ b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/refactoring/RenameTypeProcessorTest.java
@@ -19,6 +19,7 @@ import com.google.dart.tools.core.test.util.TestProject;
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;
@@ -69,6 +70,7 @@ public final class RenameTypeProcessorTest 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 RenameTypeProcessorTest extends RefactoringTest {
// warning should be displayed
assertThat(openInformationMessages).isEmpty();
assertThat(showStatusMessages).hasSize(1);
+ assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
assertEquals(
"By convention, type names usually start with an uppercase letter",
showStatusMessages.get(0));
@@ -217,6 +220,88 @@ public final class RenameTypeProcessorTest 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",
+ "class Test {}",
+ "class A {",
+ " var NewName;",
+ "}",
+ "class B extends A {",
+ " foo() {",
+ " NewName = 1;", // will be shadowed by top-level element
+ " }",
+ "}",
+ "");
+ Type 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 type 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 type",
+ 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",
+ "class Test {}",
+ "class A {",
+ " var NewName;",
+ " foo() {",
+ " NewName = 1;", // field of the enclosing class
+ " new Test();",
+ " }",
+ "}",
+ "");
+ Type 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 type 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 type 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",
@@ -225,6 +310,7 @@ public final class RenameTypeProcessorTest extends RefactoringTest {
"class A {",
" f() {",
" var NewName;",
+ " new Test();",
" }",
"}",
"");
@@ -238,10 +324,19 @@ public final class RenameTypeProcessorTest 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 type",
- showStatusMessages.get(0));
+ {
+ assertThat(showStatusMessages).hasSize(2);
+ // warning for shadowing declaration
+ assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
+ assertEquals(
+ "Declaration of renamed type 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 type will be shadowed by variable in method 'A.f()' in file 'Test/Test.dart'",
+ showStatusMessages.get(1));
+ }
// no source changes
assertEquals(source, testUnit.getSource());
}
@@ -253,6 +348,7 @@ public final class RenameTypeProcessorTest extends RefactoringTest {
"}",
"f() {",
" var NewName;",
+ " new Test();",
"}",
"");
Type type = findElement("Test {");
@@ -265,10 +361,101 @@ public final class RenameTypeProcessorTest 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 type",
- showStatusMessages.get(0));
+ {
+ assertThat(showStatusMessages).hasSize(2);
+ // warning for shadowing declaration
+ assertEquals(RefactoringStatus.WARNING, showStatusSeverities.get(0).intValue());
+ assertEquals(
+ "Declaration of renamed type 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 type 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",
+ "class Test {}",
+ "class A {",
+ " NewName() {}",
+ "}",
+ "class B extends A {",
+ " foo() {",
+ " NewName();", // will be shadowed by top-level element
+ " }",
+ "}",
+ "");
+ Type 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 type 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 type",
+ 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",
+ "class Test {}",
+ "class A {",
+ " NewName() {}",
+ " foo() {",
+ " NewName();", // method of the enclosing class
+ " new Test();",
+ " }",
+ "}",
+ "");
+ Type 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 type 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 type will be shadowed by method 'A.NewName' in 'Test/Test.dart'",
+ showStatusMessages.get(1));
+ }
// no source changes
assertEquals(source, testUnit.getSource());
}
@@ -330,30 +517,6 @@ public final class RenameTypeProcessorTest 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",
- "class 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",
- "class Test {",
- "}",
- "class A {",
- " NewName() {}",
- "}",
- "");
- check_postCondition_typeMember("method");
- }
-
public void test_preCondition_hasCompilationErrors() throws Exception {
setUnitContent(
"Test1.dart",
@@ -382,6 +545,7 @@ public final class RenameTypeProcessorTest 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));
@@ -416,6 +580,7 @@ public final class RenameTypeProcessorTest 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 "
@@ -424,23 +589,4 @@ public final class RenameTypeProcessorTest extends RefactoringTest {
// no source changes
assertEquals(source, testUnit.getSource());
}
-
- private void check_postCondition_typeMember(String shadowName) throws Exception {
- Type 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(1);
- assertEquals("Type 'A' in 'Test/Test.dart' declares "
- + shadowName
- + " 'NewName' which will shadow renamed type", showStatusMessages.get(0));
- // no source changes
- assertEquals(source, testUnit.getSource());
- }
}

Powered by Google App Engine
This is Rietveld 408576698