RefDiff icon indicating copy to clipboard operation
RefDiff copied to clipboard

Is the Inline Method refactoring a true instance?

Open osmarleandro opened this issue 4 years ago • 2 comments

Summary

In the source code of osmarleandro/spring-boot@0022080 commit, I applied a single Move Method refactoring to getType(Class) method in MBeanInfoFactory class, moving to JmxOperationResponseMapper interface. RefDiff yields a single Inline Method refactoring as result. Why is the Move Method refactoring instance not detected?

Code example

Diff fragment between the commit osmarleandro/spring-boot@0022080 and their parent.

@@ -38,4 +38,8 @@ public interface JmxOperationResponseMapper {
         */
        Object mapResponse(Object response);
 
+       default String getType(MBeanInfoFactory mBeanInfoFactory, Class<?> outputType) {
+               return mapResponseType(outputType).getName();
+       }
+
 }

@@ -69,7 +69,7 @@ class MBeanInfoFactory {
                String name = operation.getName();
                String description = operation.getDescription();
                MBeanParameterInfo[] signature = getSignature(operation.getParameters());
-               String type = getType(operation.getOutputType());
+               String type = responseMapper.getType(this, operation.getOutputType());
                int impact = getImpact(operation.getType());
                return new ModelMBeanOperationInfo(name, description, signature, type, impact);
        }
        
@@ -92,8 +92,4 @@ class MBeanInfoFactory {
                return MBeanOperationInfo.UNKNOWN;
        }
 
-       private String getType(Class<?> outputType) {
-               return this.responseMapper.mapResponseType(outputType).getName();
-       }
-
 }

Environment details

RefDiff 2.0

Steps to reproduce

  1. Run RefDiff and pass as input the commit osmarleandro/spring-boot@0022080.

Actual results

INLINE	{Method getType(Class) at spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/MBeanInfoFactory.java:95}	{Method getMBeanOperation(JmxOperation) at spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/MBeanInfoFactory.java:68})

Expected results

An instance of the Move Method refactoring applied to getType(Class) method in MBeanInfoFactory class and moved to JmxOperationResponseMapper interface.

osmarleandro avatar Jan 17 '21 22:01 osmarleandro

Osmar, In this case, the MOVE was not detected because the similarity score between the method before/after is not higher than 0.5 (in fact is exactly 0.5). Unfortunately, when the method is very small, even small changes may cause this.

By the way, you may want to take a look at RefDiffExampleWithDebugger.java. It may help finding out the reason why a refactoring is not detected.

danilofes avatar Feb 06 '21 14:02 danilofes

Hi @danilofes, thanks for your attention and support.

As you explained, I understand that the similarity score in small programs is not high enough. Is there any future solution to this issue?

osmarleandro avatar Feb 09 '21 22:02 osmarleandro