Move caching of kotlin binaries classes to application level
Fix code in DecompiledUtils
This commit is contained in:
@@ -105,6 +105,9 @@
|
||||
<applicationService serviceInterface="org.jetbrains.jet.OperationModeProvider"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.IdeModeProvider"/>
|
||||
|
||||
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"
|
||||
serviceImplementation="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.descriptors.serialization.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaResolverPsiUtils;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
||||
@@ -111,7 +112,7 @@ public class JetFromJavaDescriptorHelper {
|
||||
private static String[] getAnnotationDataForKotlinClass(@NotNull PsiClass psiClass) {
|
||||
VirtualFile virtualFile = getVirtualFileForPsiClass(psiClass);
|
||||
if (virtualFile != null) {
|
||||
KotlinJvmBinaryClass kotlinClass = VirtualFileFinder.SERVICE.getInstance(psiClass.getProject()).createKotlinClass(virtualFile);
|
||||
KotlinJvmBinaryClass kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(virtualFile);
|
||||
KotlinClassHeader header = kotlinClass.getClassHeader();
|
||||
if (header != null) {
|
||||
return header.getAnnotationData();
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.MemberComparator;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
@@ -66,7 +66,7 @@ public final class DecompiledDataFactory {
|
||||
InjectorForJavaDescriptorResolver injector = InjectorForJavaDescriptorResolverUtil.create(project, new BindingTraceContext());
|
||||
this.javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
||||
|
||||
KotlinJvmBinaryClass kotlinClass = VirtualFileFinder.SERVICE.getInstance(project).createKotlinClass(classFile);
|
||||
KotlinJvmBinaryClass kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(classFile);
|
||||
this.classFqName = kotlinClass.getClassName().getFqNameForClassNameWithoutDollars();
|
||||
|
||||
KotlinClassHeader header = kotlinClass.getClassHeader();
|
||||
|
||||
@@ -21,47 +21,23 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
public final class DecompiledUtils {
|
||||
private static final String PACKAGE_FRAGMENT_SIGNATURE = PackageClassUtils.PACKAGE_CLASS_NAME_SUFFIX + "-";
|
||||
|
||||
public static boolean isKotlinCompiledFile(@NotNull VirtualFile file) {
|
||||
if (!StdFileTypes.CLASS.getDefaultExtension().equals(file.getExtension())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isKotlinInternalClass(file) || checkFile(file);
|
||||
KotlinClassHeader header = KotlinBinaryClassCache.getKotlinBinaryClass(file).getClassHeader();
|
||||
return header != null;
|
||||
}
|
||||
|
||||
public static boolean isKotlinInternalClass(@NotNull VirtualFile file) {
|
||||
// FIXME: not sure if this is a good heuristic
|
||||
String name = file.getName();
|
||||
int pos = name.indexOf('$');
|
||||
if (pos > 0) {
|
||||
name = name.substring(0, pos) + ".class";
|
||||
VirtualFile supposedHost = file.getParent().findChild(name);
|
||||
if (supposedHost != null) {
|
||||
return checkFile(supposedHost);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.contains(PACKAGE_FRAGMENT_SIGNATURE)) {
|
||||
KotlinClassHeader header = new VirtualFileKotlinClass(LockBasedStorageManager.NO_LOCKS, file).getClassHeader();
|
||||
if (header != null && header.getKind() == KotlinClassHeader.Kind.PACKAGE_FRAGMENT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean checkFile(@NotNull VirtualFile file) {
|
||||
KotlinClassHeader header = new VirtualFileKotlinClass(LockBasedStorageManager.NO_LOCKS, file).getClassHeader();
|
||||
return header != null && header.getAnnotationData() != null;
|
||||
public static boolean isKotlinInternalCompiledFile(@NotNull VirtualFile file) {
|
||||
KotlinClassHeader header = KotlinBinaryClassCache.getKotlinBinaryClass(file).getClassHeader();
|
||||
return header != null && header.getKind() == KotlinClassHeader.Kind.PACKAGE_FRAGMENT;
|
||||
}
|
||||
|
||||
public static CharSequence decompile(@NotNull VirtualFile file) {
|
||||
|
||||
@@ -40,6 +40,6 @@ public class JetClassFileDecompiler extends ClassFileDecompilers.Full {
|
||||
@NotNull
|
||||
@Override
|
||||
public FileViewProvider createFileViewProvider(@NotNull VirtualFile file, @NotNull PsiManager manager, boolean physical) {
|
||||
return new JetClassFileViewProvider(manager, file, physical, DecompiledUtils.isKotlinInternalClass(file));
|
||||
return new JetClassFileViewProvider(manager, file, physical, DecompiledUtils.isKotlinInternalCompiledFile(file));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class JetClsStubBuilder extends ClsStubBuilder {
|
||||
public PsiFileStub<?> buildFileStub(@NotNull FileContent content) throws ClsFormatException {
|
||||
VirtualFile file = content.getFile();
|
||||
|
||||
if (DecompiledUtils.isKotlinInternalClass(file)) {
|
||||
if (DecompiledUtils.isKotlinInternalCompiledFile(file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.indexing.*;
|
||||
import com.intellij.util.io.KeyDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
@@ -75,8 +75,7 @@ public final class KotlinClassFileIndex extends ScalarIndexExtension<FqName> {
|
||||
@Override
|
||||
public Map<FqName, Void> map(FileContent inputData) {
|
||||
try {
|
||||
KotlinJvmBinaryClass kotlinClass = VirtualFileFinder.SERVICE.getInstance(inputData.getProject())
|
||||
.createKotlinClass(inputData.getFile());
|
||||
KotlinJvmBinaryClass kotlinClass = KotlinBinaryClassCache.getKotlinBinaryClass(inputData.getFile());
|
||||
KotlinClassHeader header = kotlinClass.getClassHeader();
|
||||
if (header != null && header.getKind() != KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION) {
|
||||
return Collections.singletonMap(kotlinClass.getClassName().getFqNameForClassNameWithoutDollars(), null);
|
||||
|
||||
Reference in New Issue
Block a user