summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Metchev2013-08-16 01:40:26 (EDT)
committer Noopur Gupta2013-08-16 01:40:26 (EDT)
commitc8bde6abd9e953bb360e0e6bed3d101b6b664401 (patch)
treecd6c8b8fd455c0a2df7c038e092f99f7e2990741
parente3f3b6e3499f1cfacbdcbf53ff024ba429dc6d6f (diff)
downloadeclipse.jdt.ui-c8bde6abd9e953bb360e0e6bed3d101b6b664401.zip
eclipse.jdt.ui-c8bde6abd9e953bb360e0e6bed3d101b6b664401.tar.gz
eclipse.jdt.ui-c8bde6abd9e953bb360e0e6bed3d101b6b664401.tar.bz2
Fixed bug 159917: [convert anonymous] Convert Anonymous to nested
generates wrong code Signed-off-by: Nikolay Metchev <nikolaymetchev@gmail.com>
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_in.java24
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_out.java30
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_in.java28
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_out.java34
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java12
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ConvertAnonymousToNestedRefactoring.java7
6 files changed, 133 insertions, 2 deletions
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_in.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_in.java
new file mode 100644
index 0000000..9f1fdd8
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_in.java
@@ -0,0 +1,24 @@
+package p;
+
+import java.util.Date;
+
+public class Sup {
+ interface ISup {
+ void m();
+ }
+
+ public Sup(ISup isup) {
+ }
+}
+
+class Sub extends Sup {
+ public Sub(final Date d) {
+ super(new ISup() {
+ private final long x= d.getTime();
+
+ public void m() {
+ System.out.println(x);
+ }
+ });
+ }
+}
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_out.java
new file mode 100644
index 0000000..20aaf11
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test34_out.java
@@ -0,0 +1,30 @@
+package p;
+
+import java.util.Date;
+
+public class Sup {
+ interface ISup {
+ void m();
+ }
+
+ public Sup(ISup isup) {
+ }
+}
+
+class Sub extends Sup {
+ private static class Nested implements ISup {
+ private final Date d;
+ private final long x;
+ private Nested(Date d) {
+ this.d= d;
+ x= d.getTime();
+ }
+ public void m() {
+ System.out.println(x);
+ }
+ }
+
+ public Sub(final Date d) {
+ super(new Nested(d));
+ }
+}
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_in.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_in.java
new file mode 100644
index 0000000..4dd7993
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_in.java
@@ -0,0 +1,28 @@
+package p;
+
+import java.util.Date;
+
+public class Sup {
+ interface ISup {
+ void m();
+ }
+
+ public Sup(ISup isup) {
+ }
+}
+
+class Sub extends Sup {
+ public Sub(final Date d) {
+ this(new ISup() {
+ private final long x= d.getTime();
+
+ public void m() {
+ System.out.println(x);
+ }
+ });
+ }
+
+ public Sub(ISup p) {
+ super(p);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_out.java
new file mode 100644
index 0000000..7dd69ec
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ConvertAnonymousToNested/canConvert/A_test35_out.java
@@ -0,0 +1,34 @@
+package p;
+
+import java.util.Date;
+
+public class Sup {
+ interface ISup {
+ void m();
+ }
+
+ public Sup(ISup isup) {
+ }
+}
+
+class Sub extends Sup {
+ private static class Nested implements ISup {
+ private final Date d;
+ private final long x;
+ private Nested(Date d) {
+ this.d= d;
+ x= d.getTime();
+ }
+ public void m() {
+ System.out.println(x);
+ }
+ }
+
+ public Sub(final Date d) {
+ this(new Nested(d));
+ }
+
+ public Sub(ISup p) {
+ super(p);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java
index b8d144a..cc1349f 100644
--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java
+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java
@@ -12,6 +12,8 @@
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=43360)
* - [refactoring][convert anonymous] gets confused with generic methods
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=124978)
+ * - [convert anonymous] Convert Anonymous to nested generates wrong code
+ * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=159917)
*******************************************************************************/
package org.eclipse.jdt.ui.tests.refactoring;
@@ -385,4 +387,12 @@ public class ConvertAnonymousToNestedTests extends RefactoringTest {
public void test33() throws Exception { // for bug 124978
helper1(9, 21, 12, 7, true, true, "AImpl", Modifier.PRIVATE);
}
-}
+
+ public void test34() throws Exception { // for bug 159917
+ helper1(16, 27, 22, 9, false, false, "Nested", Modifier.PRIVATE);
+ }
+
+ public void test35() throws Exception { // for bug 159917
+ helper1(16, 26, 22, 9, false, false, "Nested", Modifier.PRIVATE);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ConvertAnonymousToNestedRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ConvertAnonymousToNestedRefactoring.java
index d7f7f81..89e25a0 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ConvertAnonymousToNestedRefactoring.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ConvertAnonymousToNestedRefactoring.java
@@ -14,6 +14,8 @@
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48282)
* - [refactoring][convert anonymous] gets confused with generic methods
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=124978)
+ * - [convert anonymous] Convert Anonymous to nested generates wrong code
+ * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=159917)
*******************************************************************************/
package org.eclipse.jdt.internal.corext.refactoring.code;
@@ -1092,7 +1094,10 @@ public class ConvertAnonymousToNestedRefactoring extends Refactoring {
boolean ans = false;
while(current != null) {
switch(current.getNodeType()) {
- case ASTNode.ANONYMOUS_CLASS_DECLARATION:
+ case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
+ case ASTNode.CONSTRUCTOR_INVOCATION:
+ return true;
+ case ASTNode.ANONYMOUS_CLASS_DECLARATION:
{
AnonymousClassDeclaration enclosingAnonymousClassDeclaration= (AnonymousClassDeclaration)current;
ITypeBinding binding= enclosingAnonymousClassDeclaration.resolveBinding();