Snap for 4633553 from 889e9302a7f0629812928da0d4363d5b482f8943 to studio-3.1-release

Change-Id: I4dc6e6173bb99015a457b1a7ab3fe11daf6ad2df
diff --git a/test-recorder/src/com/google/gct/testrecorder/ui/TestClassNameInputDialog.java b/test-recorder/src/com/google/gct/testrecorder/ui/TestClassNameInputDialog.java
index 1fbe0bc..b57ff61 100644
--- a/test-recorder/src/com/google/gct/testrecorder/ui/TestClassNameInputDialog.java
+++ b/test-recorder/src/com/google/gct/testrecorder/ui/TestClassNameInputDialog.java
@@ -49,6 +49,7 @@
 import java.util.List;
 
 import static com.android.builder.model.AndroidProject.ARTIFACT_ANDROID_TEST;
+import static com.intellij.openapi.vfs.VfsUtil.findFileByIoFile;
 
 public class TestClassNameInputDialog extends DialogWrapper {
   private final Project myProject;
@@ -118,11 +119,10 @@
                                        .setCategory(EventCategory.TEST_RECORDER)
                                        .setKind(EventKind.TEST_RECORDER_MISSING_INSTRUMENTATION_TEST_FOLDER));
 
-      final VirtualFile moduleFile = myTestClassModule.getModuleFile();
-      if (moduleFile == null) {
-        throw new RuntimeException("Could not find module file for module " + myTestClassModule.getName());
+      VirtualFile moduleRoot = findFileByIoFile(new File(myTestClassModule.getModuleFilePath()).getParentFile(), true);
+      if (moduleRoot == null) {
+        throw new RuntimeException("Could not find module root for module " + myTestClassModule.getName());
       }
-      VirtualFile moduleDirectory = moduleFile.getParent();
 
       List<String> androidTestSourceRoots = getAndroidTestSourceRoots();
 
@@ -131,17 +131,17 @@
         // create a test source root following naming convention, i.e., $MODULE_DIR$/src/androidTest/java.
         // TODO: If there are examples when naming convention fails, consider updating .iml as well,
         // e.g., using contentEntry.addSourceFolder(VfsUtilCore.pathToUrl(parentSourceRoot.getCanonicalPath() + "/androidTest/java"), true);
-        return getOrCreateSubdirectory(moduleDirectory, new String[]{"src", "androidTest", "java"}, true);
+        return getOrCreateSubdirectory(moduleRoot, new String[]{"src", "androidTest", "java"}, true);
       } else {
         String closestAndroidTestSourcePath =
           androidTestSourceRoots.get(findClosestAndroidTestSourceRootIndex(launchedActivitySourceRoot, androidTestSourceRoots));
-        String moduleDirectoryCanonicalPath = moduleDirectory.getCanonicalPath();
-        if (moduleDirectoryCanonicalPath == null || !closestAndroidTestSourcePath.startsWith(moduleDirectoryCanonicalPath)) {
+        String moduleRootCanonicalPath = moduleRoot.getCanonicalPath();
+        if (moduleRootCanonicalPath == null || !closestAndroidTestSourcePath.startsWith(moduleRootCanonicalPath)) {
           // Why this should ever be the case?
           throw new RuntimeException("Android test source path is not inside the module: " + closestAndroidTestSourcePath);
         }
         return getOrCreateSubdirectory(
-          moduleDirectory, closestAndroidTestSourcePath.substring(moduleDirectoryCanonicalPath.length() + 1).split("/"), true);
+          moduleRoot, closestAndroidTestSourcePath.substring(moduleRootCanonicalPath.length() + 1).split("/"), true);
       }
     } else {
       return existingAndroidTestSourceRoots.get(