InlineCodegen: find virtual file using findVirtualFileWithHeader
This commit is contained in:
@@ -179,7 +179,7 @@ public class InlineCodegenUtil {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static VirtualFile findVirtualFile(@NotNull Project project, @NotNull String internalName) {
|
public static VirtualFile findVirtualFile(@NotNull Project project, @NotNull String internalName) {
|
||||||
VirtualFileFinder fileFinder = VirtualFileFinder.SERVICE.getInstance(project);
|
VirtualFileFinder fileFinder = VirtualFileFinder.SERVICE.getInstance(project);
|
||||||
return fileFinder.findVirtualFile(internalName);
|
return fileFinder.findVirtualFileWithHeader(new FqName(internalName.replace('/', '.')));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: navigate to inner classes
|
//TODO: navigate to inner classes
|
||||||
|
|||||||
@@ -46,17 +46,6 @@ public class CliVirtualFileFinder extends VirtualFileKotlinClassFinder implement
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public VirtualFile findVirtualFile(@NotNull String internalName) {
|
|
||||||
for (VirtualFile root : classPath) {
|
|
||||||
VirtualFile fileInRoot = findFileInRoot(internalName, root, '/');
|
|
||||||
if (fileInRoot != null) {
|
|
||||||
return fileInRoot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//NOTE: copied with some changes from CoreJavaFileManager
|
//NOTE: copied with some changes from CoreJavaFileManager
|
||||||
@Nullable
|
@Nullable
|
||||||
private static VirtualFile findFileInRoot(@NotNull String qName, @NotNull VirtualFile root, char separator) {
|
private static VirtualFile findFileInRoot(@NotNull String qName, @NotNull VirtualFile root, char separator) {
|
||||||
|
|||||||
@@ -34,8 +34,4 @@ public interface VirtualFileFinder extends KotlinClassFinder {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
VirtualFile findVirtualFileWithHeader(@NotNull FqName className);
|
VirtualFile findVirtualFileWithHeader(@NotNull FqName className);
|
||||||
|
|
||||||
/*Also finds files without kotlin header*/
|
|
||||||
@Nullable
|
|
||||||
VirtualFile findVirtualFile(@NotNull String internalName);
|
|
||||||
}
|
}
|
||||||
|
|||||||
-25
@@ -16,12 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.vfilefinder;
|
package org.jetbrains.kotlin.idea.vfilefinder;
|
||||||
|
|
||||||
import com.intellij.openapi.components.ServiceManager;
|
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.PsiClass;
|
|
||||||
import com.intellij.psi.impl.file.impl.JavaFileManager;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.util.indexing.FileBasedIndex;
|
import com.intellij.util.indexing.FileBasedIndex;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -60,26 +57,4 @@ public final class IDEVirtualFileFinder extends VirtualFileKotlinClassFinder imp
|
|||||||
}
|
}
|
||||||
return files.iterator().next();
|
return files.iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public VirtualFile findVirtualFile(@NotNull String internalName) {
|
|
||||||
JavaFileManager fileFinder = ServiceManager.getService(project, JavaFileManager.class);
|
|
||||||
|
|
||||||
String qName = internalName.replace('/', '.');
|
|
||||||
PsiClass psiClass = fileFinder.findClass(qName, scope);
|
|
||||||
if (psiClass == null) {
|
|
||||||
int dollarIndex = qName.indexOf('$');
|
|
||||||
assert dollarIndex > 0 : "Only inner classes could be found with this patch: " + internalName;
|
|
||||||
String newName = qName.substring(0, dollarIndex);
|
|
||||||
psiClass = fileFinder.findClass(newName, scope);
|
|
||||||
if (psiClass != null) {
|
|
||||||
int i = qName.lastIndexOf('.');
|
|
||||||
return psiClass.getContainingFile().getVirtualFile().getParent().findChild(qName.substring(i + 1) + ".class");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (psiClass != null) {
|
|
||||||
return psiClass.getContainingFile().getVirtualFile();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ Compile bytecode for javaClass<String>()
|
|||||||
Compile bytecode for javaClass<Int>()
|
Compile bytecode for javaClass<Int>()
|
||||||
Compile bytecode for 100.toInt()
|
Compile bytecode for 100.toInt()
|
||||||
Compile bytecode for 100.toLong()
|
Compile bytecode for 100.toLong()
|
||||||
|
Compile bytecode for args.sortBy { it }.size()
|
||||||
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||||
|
|
||||||
Process finished with exit code 0
|
Process finished with exit code 0
|
||||||
|
|||||||
@@ -25,3 +25,6 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
// EXPRESSION: 100.toLong()
|
// EXPRESSION: 100.toLong()
|
||||||
// RESULT: 100: J
|
// RESULT: 100: J
|
||||||
|
|
||||||
|
// EXPRESSION: args.sortBy { it }.size()
|
||||||
|
// RESULT: 0: I
|
||||||
Reference in New Issue
Block a user