[JBoss JIRA] (ROASTER-43) Class rename error when a class has inner classes
by George Gastaldi (JIRA)
[ https://issues.jboss.org/browse/ROASTER-43?page=com.atlassian.jira.plugin... ]
George Gastaldi closed ROASTER-43.
----------------------------------
Fix Version/s: 2.11.1.Final
(was: 2.x Future)
Resolution: Done
> Class rename error when a class has inner classes
> -------------------------------------------------
>
> Key: ROASTER-43
> URL: https://issues.jboss.org/browse/ROASTER-43
> Project: Roaster
> Issue Type: Bug
> Affects Versions: 2.7.1.Final
> Reporter: Walter Medvedeo
> Assignee: George Gastaldi
> Fix For: 2.11.1.Final
>
>
> We have some processing that needs to change the class name for a java class programatically.
> So what we do is basically to invoke:
> JavaClassSource javaClassSource = "we have an instance readed with the parser"
> and then we do: javaClassSource.setName( "TheNewName" ); to change the class name.
> And this works fine for simple clases.
> But when we have a class, that have inner clases the class rename is not working well.
> The problem is that when the Outer class is renamed, the constructors for the Inner class are also renamed.
> Example, we have a class like this.
> {code:java}
> public class Outer
> {
> public class Inner
> {
> String innerField1;
> public Inner()
> {
> }
> public Inner(String innerField1) {
> this.innerField1 = innerField1;
> }
> }
> public Outer()
> {
> }
> }
> {code}
> And when we try to rename the Outer class to "RenamedOuter", we get a code like this. The constructors for the Inner class were also renamed.
> {code:java}
> public class RenamedOuter
> {
> public class Inner
> {
> String innerField1;
> public RenamedOuter()
> {
> }
> public RenamedOuter(String innerField1) {
> this.innerField1 = innerField1;
> }
> }
> public RenamedOuter()
> {
> }
> }
> {code}
> Doing some debuging we could find some pointer to the problem.
> If you go to the JavaClassImpl, you will see that the following method is invoked when a class is about to be renamed.
> And we found that the loop is processing all methods, outer class methods an inner class metods. I means that inner class
> constructors are procesed, and that's why they are also renamed to "RenamedOuter".
> {code:java}
> @Override
> protected JavaClassSource updateTypeNames(final String newName)
> {
> for (MethodSource<JavaClassSource> m : getMethods())
> {
> if (m.isConstructor())
> {
> m.setConstructor(false);
> m.setConstructor(true);
> }
> }
> return this;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.11#6341)