aserg-ufmg / RefDiff

A tool to mine refactorings in the commit history of git repositories.
MIT License
148 stars 44 forks source link

Is the instance a Move Method or Pull Up Method? #21

Open osmarleandro opened 3 years ago

osmarleandro commented 3 years ago

Summary

In the source code present in osmarleandro/RefactoringMiner@6c42a27 commit, I applied a single Move Method refactoring to setFinallyClause(CompositeStatementObject) method in TryStatementObject class. The method was moved to CompositeStatementObject superclass of TryStatementObject class.

RefDiff detects a single instance of Move Method refactoring, but is the instance a Pull Up Method?

Code example

Diff fragment between the commit osmarleandro/RefactoringMiner@6c42a27 and their parent.

@@ -531,4 +531,8 @@ public class CompositeStatementObject extends AbstractStatement {
                }
                return null;
        }
+
+       public void setFinallyClause(TryStatementObject tryStatementObject) {
+               tryStatementObject.finallyClause = this;
+       }
 }

@@ -250,7 +250,7 @@ public class OperationBody {
                        Block finallyBlock = tryStatement.getFinally();
                        if(finallyBlock != null) {
                                CompositeStatementObject finallyClauseStatementObject = new CompositeStatementObject(cu, filePath, finallyBlock, parent.getDepth()+1, CodeElementType.FINALLY_BLOCK);
-                               child.setFinallyClause(finallyClauseStatementObject);
+                               finallyClauseStatementObject.setFinallyClause(child);

@@ -10,7 +10,7 @@ import gr.uom.java.xmi.LocationInfo.CodeElementType;

 public class TryStatementObject extends CompositeStatementObject {
        private List<CompositeStatementObject> catchClauses;
-       private CompositeStatementObject finallyClause;
+       CompositeStatementObject finallyClause;

        public TryStatementObject(CompilationUnit cu, String filePath, Statement statement, int depth) {
                super(cu, filePath, statement, depth, CodeElementType.TRY_STATEMENT);
@@ -25,10 +25,6 @@ public class TryStatementObject extends CompositeStatementObject {
                return catchClauses;
        }

-       public void setFinallyClause(CompositeStatementObject finallyClause) {
-               this.finallyClause = finallyClause;
-       }
-

Environment details

RefDiff 2.0

Steps to reproduce

  1. Run RefDiff and give as input the commit osmarleandro/RefactoringMiner@6c42a27.

Actual results

MOVE    {Method setFinallyClause(CompositeStatementObject) at src/gr/uom/java/xmi/decomposition/TryStatementObject.java:28} {Method setFinallyClause(TryStatementObject) at src/gr/uom/java/xmi/decomposition/CompositeStatementObject.java:535})

Expected results

A single instance of the Pull Up Method refactoring applied to setFinallyClause(CompositeStatementObject) method in TryStatementObject class.