2 Replies Latest reply on Jun 13, 2007 12:31 PM by atticjim

    refactor / renaming a class variable causes unexpected renaming of xml node names in XML variable in same class

    atticjim
      renaming a class variable seems to also cause a renaming of nodes in an xml variable in that class,
      which I found rather unexpected since in my head at least their scope seems entirely different.
      Is this a subtle error in the refactoring, or have I completely missed the point and I should expect it for some good reason that's escaped me for the moment?
      Thanks, I'm not being sarcastic, I really don't know!

      apologies for the poor code formatting ...

      jim



      ORIGINAL code before refactoring :

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="test()">

      <mx:Script>
      <![CDATA[
      private function test():void
      {
      var t:TestRefactor = new TestRefactor();
      trace(t.testXml.testVar[0]);
      }
      ]]>
      </mx:Script>

      </mx:Application>




      package
      {
      public class TestRefactor
      {
      public var testVar:String;
      public var testXml:XML;

      function TestRefactor():void
      {
      testVar = "some String";
      testXml = <testVariables>
      <testVar>{testVar}</testVar>
      </testVariables>;
      }
      }
      }

      --------------------------------------------------------------------------

      REFACTORED : refactor|rename the variable "testVar" to "testVariable" . NOTICE that the nodes named "testVar" in XML variable "testXml" have also changed, breaking the application which still refers to "t.testXml.testVar[0]"

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="test()">

      <mx:Script>
      <![CDATA[
      private function test():void
      {
      var t:TestRefactor = new TestRefactor();
      trace(t.testXml.testVar[0]);
      }
      ]]>
      </mx:Script>

      </mx:Application>


      package
      {
      public class TestRefactor
      {
      public var testVariable:String;
      public var testXml:XML;

      function TestRefactor():void
      {
      testVariable = "some String";
      testXml = <testVariables>
      <testVariable>{testVariable}</testVariable>
      </testVariables>;
      }
      }
      }