InlineCodegen: find virtual file using findVirtualFileWithHeader

This commit is contained in:
Natalia Ukhorskaya
2015-03-27 11:05:53 +03:00
parent ef6698bd52
commit 785f7e749f
6 changed files with 6 additions and 42 deletions
@@ -179,7 +179,7 @@ public class InlineCodegenUtil {
@Nullable
public static VirtualFile findVirtualFile(@NotNull Project project, @NotNull String internalName) {
VirtualFileFinder fileFinder = VirtualFileFinder.SERVICE.getInstance(project);
return fileFinder.findVirtualFile(internalName);
return fileFinder.findVirtualFileWithHeader(new FqName(internalName.replace('/', '.')));
}
//TODO: navigate to inner classes
@@ -46,17 +46,6 @@ public class CliVirtualFileFinder extends VirtualFileKotlinClassFinder implement
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
@Nullable
private static VirtualFile findFileInRoot(@NotNull String qName, @NotNull VirtualFile root, char separator) {
@@ -34,8 +34,4 @@ public interface VirtualFileFinder extends KotlinClassFinder {
@Nullable
VirtualFile findVirtualFileWithHeader(@NotNull FqName className);
/*Also finds files without kotlin header*/
@Nullable
VirtualFile findVirtualFile(@NotNull String internalName);
}
@@ -16,12 +16,9 @@
package org.jetbrains.kotlin.idea.vfilefinder;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
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.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NotNull;
@@ -60,26 +57,4 @@ public final class IDEVirtualFileFinder extends VirtualFileKotlinClassFinder imp
}
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 100.toInt()
Compile bytecode for 100.toLong()
Compile bytecode for args.sortBy { it }.size()
Disconnected from the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
Process finished with exit code 0
@@ -24,4 +24,7 @@ fun main(args: Array<String>) {
// RESULT: 100: I
// EXPRESSION: 100.toLong()
// RESULT: 100: J
// RESULT: 100: J
// EXPRESSION: args.sortBy { it }.size()
// RESULT: 0: I