Community
Participate
Working Groups
if you extract method where indicated below. you will see that the extracted method declares its paramater with too many final modifiers: ------------------------------------- package p; class Container<T> { private final T m_t; public Container(T t) { m_t = t; } T get() { return m_t; } } class GenericContainer { private final Container<?> m_c; public GenericContainer(Container<?> c) { m_c = c; } public Container<?> getC() { return m_c; } } public class A { GenericContainer createContainer() { final Container<String> innerContainer = new Container<String>("hello"); final Container<Container<String>> outerContainer = new Container<Container<String>>(innerContainer); return new GenericContainer(outerContainer); } void method() { final GenericContainer createContainer = createContainer(); @SuppressWarnings("unchecked") final Container<Container<String>> c = (Container<Container<String>>) createContainer.getC(); //extract method from here final Container<String> container = c.get(); final String string = container.get(); //to here } } ----------------------------------------------- results in ----------------------------------------------- package p; class Container<T> { private final T m_t; public Container(T t) { m_t = t; } T get() { return m_t; } } class GenericContainer { private final Container<?> m_c; public GenericContainer(Container<?> c) { m_c = c; } public Container<?> getC() { return m_c; } } public class A { GenericContainer createContainer() { final Container<String> innerContainer = new Container<String>("hello"); final Container<Container<String>> outerContainer = new Container<Container<String>>(innerContainer); return new GenericContainer(outerContainer); } void method() { final GenericContainer createContainer = createContainer(); @SuppressWarnings("unchecked") final Container<Container<String>> c = (Container<Container<String>>) createContainer.getC(); //extract method from here extractedMethod(c); //to here } private void extractedMethod(final final final Container<Container<String>> c) { final Container<String> container = c.get(); final String string = container.get(); } } ----------------------------------------------------------- notice the 3 final modifiers in the extractedMethod signature.
Eclipse 3.1RC1, JDK 1.5.0_03
Still exists in RC2 candidate.
The problem is that the underlying AST already contains three final modifiers for the declaration: final Container<Container<String>> c = (Container<Container<String>>) createContainer.getC(); Since the variable C is passed to the method the refactoring creates a new parameter and copies the modifiers from the declaration. The ASTFlattener then puts three final strings into the source code. Moving to JDT/Core. Philippe, IMO we should consider this for RC3 since none of the tooling currently expects doubled modifiers.
Created attachment 22873 [details] Screen shot showing the three final modifiers in the AST view
+1 for RC3 Dirk - pls append your vote.
+1 for RC3.
P.S. I forgot to mention that in the original code that this occured the end result was a little more drastic. There was a lot more than 3 final modifiers (around about 10). However even more bizzarely there were a few private modifiers scattered in between the final modifiers. I hope that by code expection it is possible to see how those things could have happend. If not please let me know and I will try and come up with a test case.
Reproduced. I am investigating.
Created attachment 22935 [details] But in the AST converter parsing of modifiers Proposed patch.
Fixed and released in HEAD. Regression test added in org.eclipse.jdt.core.tests.dom.ASTConverter15Test.test190
Verified using build N20050616-0010 + JDT Core HEAD.