You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "assdfsdafasfa (via GitHub)" <gi...@apache.org> on 2024/09/26 10:51:20 UTC

[I] [Pull Down Method Refactoring Bug] Pull down method refactoring leads to changes in code calling relationships [netbeans]

assdfsdafasfa opened a new issue, #7800:
URL: https://github.com/apache/netbeans/issues/7800

   ### Apache NetBeans version
   
   Apache NetBeans 23
   
   ### What happened
   
   When test() is selected to perform pull down refactoring into class A, before refactoring, test() method calls method() of class ParentClass, after refactoring, test() method calls method() of class SubClass, resulting in a change in code behavior.
   
   Code before refactoring
   ```java
   class ParentClass {
   void method() {
    System.out.println("ParentClass method");
    }
   }
   class A extends SubClass { 
   void method() {
    System.out.println("Class A method");
    }
   }
   class SubClass extends ParentClass {
   void test() {
    method(); 
    }
   }
   ```
   
   
   ### Language / Project Type / NetBeans Component
   
   _No response_
   
   ### How to reproduce
   
   When test() is selected to perform pull down refactoring into class A, before refactoring, test() method calls method() of class ParentClass, after refactoring, test() method calls method() of class SubClass, resulting in a change in code behavior.
   
   Code before refactoring
   ```java
   class ParentClass {
   void method() {
    System.out.println("ParentClass method");
    }
   }
   class A extends SubClass { 
   void method() {
    System.out.println("Class A method");
    }
   }
   class SubClass extends ParentClass {
   void test() {
    method(); 
    }
   }
   ```
   
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   Windows11
   
   ### JDK
   
   20
   
   ### Apache NetBeans packaging
   
   Apache NetBeans provided installer
   
   ### Anything else
   
   Code after refactoring
   ```java
   class ParentClass {
   void method() {
    System.out.println("ParentClass method");
    }
   }
   class A extends SubClass { 
   void method() {
    System.out.println("Class A method");
    }
   void test() {
    method(); 
    }
   }
   class SubClass extends ParentClass {
   }
   ```
   
   ### Are you willing to submit a pull request?
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] [Pull Down Method Refactoring Bug] Pull down method refactoring leads to changes in code calling relationships [netbeans]

Posted by "homberghp (via GitHub)" <gi...@apache.org>.
homberghp commented on issue #7800:
URL: https://github.com/apache/netbeans/issues/7800#issuecomment-2977544277

   What NetBeans refactoring does is pull the element(s) up to the nearest super, which can be a class, an abstract class, or 
   interface. In the later, and optionally in the penultimate (the abstract class) the member (method) can be made abstract.
   
   In your case the Hierarchy is 
   ```mermaid
   classDiagram
      SuperClass <|-- SubClass
      SubClass <|-- A
      SubClass: + test()
   ```
   
   Pulling up member `test` from Subclass will and should result in 
   ```mermaid
   classDiagram
      SuperClass <|-- SubClass
      SubClass <|-- A
      SuperClass: + test()
   ```
   
   This implies that as far as I am concerned, there is nothing wrong.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] [Pull Down Method Refactoring Bug] Pull down method refactoring leads to changes in code calling relationships [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on issue #7800:
URL: https://github.com/apache/netbeans/issues/7800#issuecomment-3192560442

   @homberghp I had a look at your PR and I don't think that the test address the point opened here. In fact I think this is not a bug. The provided code is incomplete so I took the code and made it executable:
   
   ```java
   public class TestX {
   
       static class ParentClass {
   
           void method() {
               System.out.println("ParentClass method");
           }
       }
   
       static class A extends SubClass {
   
           void method() {
               System.out.println("Class A method");
           }
       }
   
       static class SubClass extends ParentClass {
   
           void test() {
               method();
           }
       }
   
       public static void main(String[] argv) {
           A a = new A();
           a.test();
       }
   }
   ```
   
   now @assdfsdafasfa  writes:
   
   > before refactoring, test() method calls method() of class ParentClass, after refactoring, test() method calls method() of class SubClass
   
   this is a wrong assumption. As `method` is overriden in `A` calls to `method` invoked on an instance of `A` will always yield `Class A method`. It does not matter that `method` is called via `SubClass#test`.
   
   Running the above code yields:
   
   ```
   --- exec:1.5.0:exec (default-cli) @ MavenSpielwiese ---
   Class A method
   ```
   
   Running "Push down" refactoring yields (as described in the issue):
   
   ```java
   public class TestX {
   
       static class ParentClass {
   
           void method() {
               System.out.println("ParentClass method");
           }
       }
   
       static class A extends SubClass {
   
           void method() {
               System.out.println("Class A method");
           }
   
           void test() {
               method();
           }
       }
   
       static class SubClass extends ParentClass {
       }
   
       public static void main(String[] argv) {
           A a = new A();
           a.test();
       }
   }
   ```
   
   And that yields unsurprisingly:
   
   ```
   --- exec:1.5.0:exec (default-cli) @ MavenSpielwiese ---
   Class A method
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] [Pull Down Method Refactoring Bug] Pull down method refactoring leads to changes in code calling relationships [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing closed issue #7800: [Pull Down Method Refactoring Bug] Pull down method refactoring leads to changes in code calling relationships
URL: https://github.com/apache/netbeans/issues/7800


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists