Naive kotlin-jdk-headers.jar usage implementation
This commit is contained in:
+12
@@ -132,10 +132,22 @@ public class JavaDescriptorResolver {
|
||||
public boolean contains(VirtualFile file) {
|
||||
return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(VirtualFile file1, VirtualFile file2) {
|
||||
if (isInJdkHeaders(file1)) return 1;
|
||||
if (isInJdkHeaders(file2)) return -1;
|
||||
return super.compare(file1, file2);
|
||||
}
|
||||
};
|
||||
this.semanticServices = semanticServices;
|
||||
}
|
||||
|
||||
public static boolean isInJdkHeaders(VirtualFile file) {
|
||||
// TODO: need faster check
|
||||
return file.getUrl().contains("kotlin-jdk-headers.jar");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ClassDescriptor resolveClass(@NotNull PsiClass psiClass) {
|
||||
String qualifiedName = psiClass.getQualifiedName();
|
||||
|
||||
@@ -79,6 +79,8 @@
|
||||
<java.elementFinder implementation="org.jetbrains.jet.asJava.JavaElementFinder"/>
|
||||
<java.shortNamesCache implementation="org.jetbrains.jet.plugin.caches.JetShortNamesCache"/>
|
||||
|
||||
<java.elementFinder implementation="org.jetbrains.jet.plugin.caches.JdkHeadersFinder"/>
|
||||
|
||||
<editorNotificationProvider implementation="org.jetbrains.jet.plugin.quickfix.ConfigureKotlinLibraryNotificationProvider"/>
|
||||
|
||||
<psi.treeChangePreprocessor implementation="org.jetbrains.jet.asJava.JetCodeBlockModificationListener"/>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package org.jetbrains.jet.plugin.caches;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.NonClasspathClassFinder;
|
||||
import org.jetbrains.jet.plugin.compiler.CompilerUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JdkHeadersFinder extends NonClasspathClassFinder {
|
||||
public JdkHeadersFinder(Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<VirtualFile> calcClassRoots() {
|
||||
File jdk_headers = CompilerUtil.getJdkHeadersPath();
|
||||
if (jdk_headers == null) return Collections.emptyList();
|
||||
|
||||
VirtualFile jarVfs = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jdk_headers);
|
||||
if (jarVfs == null) return Collections.emptyList();
|
||||
jarVfs.refresh(true, false);
|
||||
|
||||
return Collections.singletonList(JarFileSystem.getInstance().getJarRootForLocalFile(jarVfs));
|
||||
}
|
||||
}
|
||||
@@ -29,4 +29,13 @@ public class CompilerUtil {
|
||||
|
||||
return answer.exists() ? answer : null;
|
||||
}
|
||||
|
||||
public static File getJdkHeadersPath() {
|
||||
File compilerPath = getDefaultCompilerPath();
|
||||
if (compilerPath == null) return null;
|
||||
|
||||
File answer = new File(compilerPath, "lib/kotlin-jdk-headers.jar");
|
||||
|
||||
return answer.exists() ? answer : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user