[forge-issues] [JBoss JIRA] (ROASTER-43) Class rename error when a class has inner classes

Walter Medvedeo (JIRA) issues at jboss.org
Wed Oct 29 08:12:34 EDT 2014


Walter Medvedeo created ROASTER-43:
--------------------------------------

             Summary: 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


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. 

public class Outer 
{
   public class Inner
   {
      String innerField1;

      public Inner()
      {
      }
      public Inner(String innerField1) {
           this.innerField1 = innerField1;
      }
   }

   public Outer()
   {
   }

}

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.

public class RenamedOuter 
{
   public class Inner
   {
      String innerField1;

      public RenamedOuter()
      {
      }

      public RenamedOuter(String innerField1) {
           this.innerField1 = innerField1;
      }
   }

   public RenamedOuter()
   {
   }
}


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".


   @Override
   protected JavaClassSource updateTypeNames(final String newName)
   {
      for (MethodSource<JavaClassSource> m : getMethods())
      {
         if (m.isConstructor())
         {
            m.setConstructor(false);
            m.setConstructor(true);
         }
      }
      return this;
   }





--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the forge-issues mailing list