Convert VirtualFileKotlinClass to Kotlin
This commit is contained in:
+2
-1
@@ -37,8 +37,9 @@ public final class KotlinBinaryClassCache implements Disposable {
|
|||||||
return new SLRUCache<VirtualFile, Ref<VirtualFileKotlinClass>>(2, 2) {
|
return new SLRUCache<VirtualFile, Ref<VirtualFileKotlinClass>>(2, 2) {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public Ref<VirtualFileKotlinClass> createValue(VirtualFile virtualFile) {
|
public Ref<VirtualFileKotlinClass> createValue(VirtualFile virtualFile) {
|
||||||
return Ref.create(VirtualFileKotlinClass.create(virtualFile));
|
return Ref.create(VirtualFileKotlinClass.OBJECT$.create(virtualFile));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-76
@@ -14,93 +14,57 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.kotlin;
|
package org.jetbrains.jet.lang.resolve.kotlin
|
||||||
|
|
||||||
import com.intellij.ide.highlighter.JavaClassFileType;
|
import com.intellij.ide.highlighter.JavaClassFileType
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import kotlin.Function3;
|
import org.jetbrains.jet.descriptors.serialization.ClassId
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.jet.utils.*
|
||||||
import org.jetbrains.jet.descriptors.serialization.ClassId;
|
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
|
||||||
import org.jetbrains.jet.utils.UtilsPackage;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException
|
||||||
|
|
||||||
public final class VirtualFileKotlinClass extends FileBasedKotlinClass {
|
public class VirtualFileKotlinClass private(
|
||||||
private final static Logger LOG = Logger.getInstance(FileBasedKotlinClass.class);
|
public val file: VirtualFile,
|
||||||
|
className: ClassId,
|
||||||
|
classHeader: KotlinClassHeader,
|
||||||
|
innerClasses: FileBasedKotlinClass.InnerClassesInfo
|
||||||
|
) : FileBasedKotlinClass(className, classHeader, innerClasses) {
|
||||||
|
|
||||||
private final VirtualFile file;
|
override fun getFileContents(): ByteArray {
|
||||||
|
|
||||||
private VirtualFileKotlinClass(
|
|
||||||
@NotNull VirtualFile file,
|
|
||||||
@NotNull ClassId className,
|
|
||||||
@NotNull KotlinClassHeader classHeader,
|
|
||||||
@NotNull InnerClassesInfo innerClasses
|
|
||||||
) {
|
|
||||||
super(className, classHeader, innerClasses);
|
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
/* package */ static VirtualFileKotlinClass create(@NotNull final VirtualFile file) {
|
|
||||||
assert file.getFileType() == JavaClassFileType.INSTANCE : "Trying to read binary data from a non-class file " + file;
|
|
||||||
try {
|
try {
|
||||||
return create(file.contentsToByteArray(),
|
return file.contentsToByteArray()
|
||||||
new Function3<ClassId, KotlinClassHeader, InnerClassesInfo, VirtualFileKotlinClass>() {
|
|
||||||
@Override
|
|
||||||
public VirtualFileKotlinClass invoke(
|
|
||||||
ClassId name, KotlinClassHeader header, InnerClassesInfo innerClasses
|
|
||||||
) {
|
|
||||||
return new VirtualFileKotlinClass(file, name, header, innerClasses);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (e: IOException) {
|
||||||
LOG.warn(renderFileReadingErrorMessage(file));
|
LOG.error(renderFileReadingErrorMessage(file), e)
|
||||||
return null;
|
throw rethrow(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun equals(other: Any?) = other is VirtualFileKotlinClass && other.file == file
|
||||||
public VirtualFile getFile() {
|
override fun hashCode() = file.hashCode()
|
||||||
return file;
|
override fun toString() = "${javaClass.getSimpleName()}: $file"
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
class object {
|
||||||
@Override
|
private val LOG = Logger.getInstance(javaClass<VirtualFileKotlinClass>())
|
||||||
protected byte[] getFileContents() {
|
|
||||||
try {
|
deprecated("Use KotlinBinaryClassCache")
|
||||||
return file.contentsToByteArray();
|
fun create(file: VirtualFile): VirtualFileKotlinClass? {
|
||||||
|
assert(file.getFileType() == JavaClassFileType.INSTANCE) { "Trying to read binary data from a non-class file $file" }
|
||||||
|
try {
|
||||||
|
return FileBasedKotlinClass.create(file.contentsToByteArray()) {
|
||||||
|
name, header, innerClasses ->
|
||||||
|
VirtualFileKotlinClass(file, name, header, innerClasses)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e: Throwable) {
|
||||||
|
LOG.warn(renderFileReadingErrorMessage(file))
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
|
||||||
LOG.error(renderFileReadingErrorMessage(file), e);
|
|
||||||
// Seems to be a bug in IDEA inspection
|
|
||||||
//noinspection Contract
|
|
||||||
throw UtilsPackage.rethrow(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
private fun renderFileReadingErrorMessage(file: VirtualFile): String =
|
||||||
private static String renderFileReadingErrorMessage(@NotNull VirtualFile file) {
|
"Could not read file: ${file.getPath()}; size in bytes: ${file.getLength()}; file type: ${file.getFileType().getName()}"
|
||||||
return "Could not read file: " + file.getPath() + "; "
|
|
||||||
+ "size in bytes: " + file.getLength() + "; "
|
|
||||||
+ "file type: " + file.getFileType().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return file.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return obj instanceof VirtualFileKotlinClass && ((VirtualFileKotlinClass) obj).file.equals(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getClass().getSimpleName() + ": " + file.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user