summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Metchev2013-08-12 02:22:10 (EDT)
committer Noopur Gupta2013-08-12 02:22:10 (EDT)
commit7d8aced3a2b62980351820fd7f095b3ffa419391 (patch)
tree441120cffe2cf5d73cbb12bb9ccd2bcb4aeea1aa
parentbc01471bb9bd65a3c133006714462002a4c84c6c (diff)
downloadeclipse.jdt.ui-7d8aced3a2b62980351820fd7f095b3ffa419391.zip
eclipse.jdt.ui-7d8aced3a2b62980351820fd7f095b3ffa419391.tar.gz
eclipse.jdt.ui-7d8aced3a2b62980351820fd7f095b3ffa419391.tar.bz2
Fixed bug 394547: [extract class] Extract class refactoring on a fieldI20130813-0800
in an inner non-static class yields compilation error Signed-off-by: Nikolay Metchev <nikolaymetchev@gmail.com>
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/in/Nested1.java7
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/out/Nested1.java13
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/in/Nested2.java7
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/out/Nested2.java13
-rw-r--r--org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java22
-rw-r--r--org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractClassRefactoring.java16
6 files changed, 76 insertions, 2 deletions
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/in/Nested1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/in/Nested1.java
new file mode 100644
index 0000000..c3f7559
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/in/Nested1.java
@@ -0,0 +1,7 @@
+package p;
+
+class Nested1 {
+ class Inner {
+ int m;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/out/Nested1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/out/Nested1.java
new file mode 100644
index 0000000..d72a12d
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested1/out/Nested1.java
@@ -0,0 +1,13 @@
+package p;
+
+class Nested1 {
+ class Inner {
+ public class Extracted {
+ public int m;
+ public Extracted() {
+ }
+ }
+
+ Extracted parameterObject = new Extracted();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/in/Nested2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/in/Nested2.java
new file mode 100644
index 0000000..08766ca
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/in/Nested2.java
@@ -0,0 +1,7 @@
+package p;
+
+interface Nested2 {
+ class Inner {
+ int m;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/out/Nested2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/out/Nested2.java
new file mode 100644
index 0000000..64a22d0
--- /dev/null
+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractClass/testNested2/out/Nested2.java
@@ -0,0 +1,13 @@
+package p;
+
+interface Nested2 {
+ class Inner {
+ public static class Extracted {
+ public int m;
+ public Extracted() {
+ }
+ }
+
+ Extracted parameterObject = new Extracted();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java
index 85d2093..2ede807 100644
--- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java
+++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract class] Extract class refactoring on a field in an inner non-static class yields compilation error - https://bugs.eclipse.org/394547
*******************************************************************************/
package org.eclipse.jdt.ui.tests.refactoring;
@@ -410,4 +411,25 @@ public class ExtractClassTests extends RefactoringTest {
runRefactoring(false);
}
+ // see bug 394547
+ public void testNested1() throws Exception {
+ IType outer= setupType();
+ IType inner= outer.getType("Inner");
+ assertTrue(inner.exists());
+ fDescriptor.setType(inner);
+ fDescriptor.setClassName("Extracted");
+ fDescriptor.setCreateTopLevel(false);
+ runRefactoring(false);
+ }
+
+ // see bug 394547
+ public void testNested2() throws Exception {
+ IType outer= setupType();
+ IType inner= outer.getType("Inner");
+ assertTrue(inner.exists());
+ fDescriptor.setType(inner);
+ fDescriptor.setClassName("Extracted");
+ fDescriptor.setCreateTopLevel(false);
+ runRefactoring(false);
+ }
}
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractClassRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractClassRefactoring.java
index fa169ab..ae3ea70 100644
--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractClassRefactoring.java
+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ExtractClassRefactoring.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Nikolay Metchev <nikolaymetchev@gmail.com> - [extract class] Extract class refactoring on a field in an inner non-static class yields compilation error - https://bugs.eclipse.org/394547
*******************************************************************************/
package org.eclipse.jdt.internal.corext.refactoring.structure;
@@ -481,18 +482,29 @@ public class ExtractClassRefactoring extends Refactoring {
ListRewrite listRewrite= rewrite.getListRewrite(typeDecl, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
TypeDeclaration paramClass= pof.createClassDeclaration(typeDecl.getName().getFullyQualifiedName(), fBaseCURewrite, fieldUpdate);
paramClass.modifiers().add(rewrite.getAST().newModifier(ModifierKeyword.PUBLIC_KEYWORD));
- paramClass.modifiers().add(rewrite.getAST().newModifier(ModifierKeyword.STATIC_KEYWORD));
+ if (shouldParamClassBeStatic(typeDecl)) {
+ paramClass.modifiers().add(rewrite.getAST().newModifier(ModifierKeyword.STATIC_KEYWORD));
+ }
listRewrite.insertFirst(paramClass, fBaseCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractClassRefactoring_group_insert_parameter));
return new ArrayList<ResourceChange>(); //Change will be generated later for fBaseCURewrite
}
}
+ private boolean shouldParamClassBeStatic(TypeDeclaration enclosingTypeDecl) {
+ if (enclosingTypeDecl.isPackageMemberTypeDeclaration()) {
+ return true;
+ }
+ ITypeBinding binding= enclosingTypeDecl.resolveBinding();
+ int modifiers= binding != null ? binding.getModifiers() : enclosingTypeDecl.getModifiers();
+ return Modifier.isStatic(modifiers);
+ }
+
private ParameterObjectFactory initializeFactory() {
ParameterObjectFactory pof= new ParameterObjectFactory();
pof.setClassName(fDescriptor.getClassName());
pof.setPackage(fDescriptor.getPackage());
- pof.setEnclosingType(fDescriptor.getType().getFullyQualifiedName());
+ pof.setEnclosingType(fDescriptor.getType().getFullyQualifiedName('.'));
pof.setCreateGetter(fDescriptor.isCreateGetterSetter());
pof.setCreateSetter(fDescriptor.isCreateGetterSetter());
List<ParameterInfo> variables= new ArrayList<ParameterInfo>();