Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/com/google/devtools/intellij/ijaas/OpenFileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import java.io.File;
import java.net.URI;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
Expand All @@ -39,7 +44,11 @@ public class OpenFileManager {

@Nullable
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now looking at the code, we don't use this method at all. Let's delete this getByPath

public OpenedFile getByPath(String filePath) {
return getByURI("file:/" + filePath);
try {
return getByURI(new File(filePath).toURI().toURL().toExternalForm());
} catch (MalformedURLException e) {
return null;
}
}

@Nullable
Expand Down Expand Up @@ -103,8 +112,15 @@ private OpenedFile(String uri, int version, String text) {
Pair<Editor, PsiFile> p =
MoreWriteActions.computeAndWaitForDocument(
() -> {
;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

String path = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= null is not needed because the path is always initialized (or bail out by throwing an exception). Keep this uninitialized unless the default initialized value makes sense for all cases. Usage of uninitialized variables is easy to detect, vs initializing with a wrong value is not.

try {
path = Paths.get(new URI(uri)).toFile().getPath();
} catch(URISyntaxException e) {
throw new RuntimeException("Cannot find the VirtualFile");
}
VirtualFile vf =
LocalFileSystem.getInstance().findFileByPath(uri.replace("file:/", ""));
LocalFileSystem.getInstance().findFileByPath(path);
if (vf == null) {
throw new RuntimeException("Cannot find the VirtualFile");
}
Expand Down