aserg-ufmg / RefDiff

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

Missing an Extract and Move Method refactoring? #13

Closed osmarleandro closed 3 years ago

osmarleandro commented 3 years ago

Summary

In the source code of osmarleandro/google-maps-services-java@12a03c9 commit, I recognize an Extract and Move Method refactoring applied to handle() method in GaeRequestHandler class. I ran RefDiff but it yields an empty set of refactoring as result. Why this refactoring instance was not detected?

Code example

Diff fragment between the commit osmarleandro/google-maps-services-java@12a03c9 and their parent.

@@ -60,29 +60,9 @@ public class GaeRequestHandler implements GeoApiContext.RequestHandler {
-    FetchOptions fetchOptions = FetchOptions.Builder.withDeadline(10);
-    HTTPRequest req;
-    try {
-      req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
-      if (experienceIdHeaderValue != null) {
-        req.setHeader(
-            new HTTPHeader(HttpHeaders.X_GOOG_MAPS_EXPERIENCE_ID, experienceIdHeaderValue));
-      }
-    } catch (MalformedURLException e) {
-      LOG.error("Request: {}{}", hostName, url, e);
-      throw (new RuntimeException(e));
-    }
-
-    return new GaePendingResult<>(
-        req,
-        client,
-        clazz,
-        fieldNamingPolicy,
-        errorTimeout,
-        maxRetries,
-        exceptionsAllowedToRetry,
-        metrics);
-  }
+               return exceptionsAllowedToRetry.handle(hostName, url, userAgent, experienceIdHeaderValue, clazz,
+                               fieldNamingPolicy, errorTimeout, maxRetries, this, metrics);
+       }

@@ -15,7 +15,19 @@
 [...] 
 public final class ExceptionsAllowedToRetry extends HashSet<Class<? extends ApiException>> {
@@ -37,4 +49,30 @@ public final class ExceptionsAllowedToRetry extends HashSet<Class<? extends ApiE
     sb.append(']');
     return sb.toString();
   }
+
+public <T, R extends ApiResponse<T>> PendingResult<T> handle(
+      String hostName, String url, String userAgent, String experienceIdHeaderValue, Class<R> clazz, FieldNamingPolicy fieldNamingPolicy, long errorTimeout, Integer maxRetries, GaeRequestHandler gaeRequestHandler, RequestMetrics metrics) {
+    FetchOptions fetchOptions = Builder.withDeadline(10);
+    HTTPRequest req;
+    try {
+      req = new HTTPRequest(new URL(hostName + url), HTTPMethod.POST, fetchOptions);
+      if (experienceIdHeaderValue != null) {
+        req.setHeader(
+            new HTTPHeader(HttpHeaders.X_GOOG_MAPS_EXPERIENCE_ID, experienceIdHeaderValue));
+      }
+    } catch (MalformedURLException e) {
+      GaeRequestHandler.LOG.error("Request: {}{}", hostName, url, e);
+      throw (new RuntimeException(e));
+    }
+
+    return new GaePendingResult<>(
+        req,
+        gaeRequestHandler.client,
+        clazz,
+        fieldNamingPolicy,
+        errorTimeout,
+        maxRetries,
+        this,
+        metrics);
+  }
 }

Environment details

RefDiff 2.0

Steps to reproduce

  1. Run RefDiff and pass as input the commit osmarleandro/google-maps-services-java@12a03c9.

Actual results

RefDiff yields and empty set of refactoring.

Expected results

A single instance of Extract and Move Method refactoring applied to handle() method of GaeRequestHandler class.

danilofes commented 3 years ago

Hi Osmar, I'm not sure why, but RefDiff is not detecting the invocation of the handle method. It uses Eclipse JDT to resolve method invacation bindings. Now I'm trying to understand if it is a JDT problem or a RefDiff problem.

danilofes commented 3 years ago

Osmar, I've just pushed a fix for the issue. It's on the master branch, you will have to run RefDiff from its source code to test it. The easiest way is to clone the repo, run gradlew eclipse in the main folder, and open the projects in Eclipse.