VirtualFileFinder update to search files without kotlin headers
This commit is contained in:
@@ -98,7 +98,7 @@ public class InlineCodegenUtil {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private static VirtualFile findVirtualFile(@NotNull Project project, @NotNull FqName containerFqName) {
|
private static VirtualFile findVirtualFile(@NotNull Project project, @NotNull FqName containerFqName) {
|
||||||
VirtualFileFinder fileFinder = ServiceManager.getService(project, VirtualFileFinder.class);
|
VirtualFileFinder fileFinder = ServiceManager.getService(project, VirtualFileFinder.class);
|
||||||
VirtualFile virtualFile = fileFinder.find(containerFqName);
|
VirtualFile virtualFile = fileFinder.findVirtualFile(containerFqName);
|
||||||
if (virtualFile == null) {
|
if (virtualFile == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,26 @@ public class CliVirtualFileFinder extends VirtualFileKotlinClassFinder implement
|
|||||||
@Override
|
@Override
|
||||||
public VirtualFile findVirtualFile(@NotNull FqName className) {
|
public VirtualFile findVirtualFile(@NotNull FqName className) {
|
||||||
for (VirtualFile root : classPath) {
|
for (VirtualFile root : classPath) {
|
||||||
VirtualFile fileInRoot = findFileInRoot(className.asString(), root);
|
VirtualFile fileInRoot = findKotlinFile(className, root);
|
||||||
|
if (fileInRoot != null) {
|
||||||
|
return fileInRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualFile findKotlinFile(@NotNull FqName className, @NotNull VirtualFile root) {
|
||||||
|
VirtualFile vFile = findFileInRoot(className.asString(), root, '.');
|
||||||
|
if (vFile != null && createKotlinClass(vFile).getClassHeader() != null) {
|
||||||
|
return vFile;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VirtualFile findVirtualFile(@NotNull String internalName) {
|
||||||
|
for (VirtualFile root : classPath) {
|
||||||
|
VirtualFile fileInRoot = findFileInRoot(internalName, root, '/');
|
||||||
if (fileInRoot != null) {
|
if (fileInRoot != null) {
|
||||||
return fileInRoot;
|
return fileInRoot;
|
||||||
}
|
}
|
||||||
@@ -46,12 +65,12 @@ public class CliVirtualFileFinder extends VirtualFileKotlinClassFinder implement
|
|||||||
|
|
||||||
//NOTE: copied with some changes from CoreJavaFileManager
|
//NOTE: copied with some changes from CoreJavaFileManager
|
||||||
@Nullable
|
@Nullable
|
||||||
private VirtualFile findFileInRoot(@NotNull String qName, @NotNull VirtualFile root) {
|
private static VirtualFile findFileInRoot(@NotNull String qName, @NotNull VirtualFile root, char separator) {
|
||||||
String pathRest = qName;
|
String pathRest = qName;
|
||||||
VirtualFile cur = root;
|
VirtualFile cur = root;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int dot = pathRest.indexOf('.');
|
int dot = pathRest.indexOf(separator);
|
||||||
if (dot < 0) break;
|
if (dot < 0) break;
|
||||||
|
|
||||||
String pathComponent = pathRest.substring(0, dot);
|
String pathComponent = pathRest.substring(0, dot);
|
||||||
@@ -69,11 +88,9 @@ public class CliVirtualFileFinder extends VirtualFileKotlinClassFinder implement
|
|||||||
//TODO: log
|
//TODO: log
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//NOTE: currently we use VirtualFileFinder to find Kotlin binaries only
|
return vFile;
|
||||||
if (createKotlinClass(vFile).getClassHeader() != null) {
|
|
||||||
return vFile;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -34,4 +34,8 @@ public interface VirtualFileFinder extends KotlinClassFinder {
|
|||||||
// TODO: support scope
|
// TODO: support scope
|
||||||
@Nullable
|
@Nullable
|
||||||
VirtualFile findVirtualFile(@NotNull FqName className);
|
VirtualFile findVirtualFile(@NotNull FqName className);
|
||||||
|
|
||||||
|
/*Also finds files without kotlin header*/
|
||||||
|
@Nullable
|
||||||
|
VirtualFile findVirtualFile(@NotNull String internalName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.vfilefinder;
|
package org.jetbrains.jet.plugin.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;
|
||||||
@@ -52,4 +55,26 @@ 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, GlobalSearchScope.allScope(project));
|
||||||
|
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, GlobalSearchScope.allScope(project));
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user