Extract abstract FileBasedKotlinClass out of VirtualFileKotlinClass
Add another implementation of FileBasedKotlinClass which was indirectly used in
jps-plugin (LocalFileKotlinClass)
Original commit: fa39bf03a0
This commit is contained in:
@@ -24,10 +24,8 @@ import com.intellij.util.io.IOUtil
|
||||
import java.io.DataInput
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import com.intellij.util.io.DataExternalizer
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.jet.descriptors.serialization.BitEncoding
|
||||
import org.jetbrains.jet.utils.intellij.*
|
||||
import java.util.Arrays
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor
|
||||
@@ -37,7 +35,6 @@ import java.util.HashSet
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCache
|
||||
import java.util.HashMap
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import java.security.MessageDigest
|
||||
import org.jetbrains.jps.incremental.storage.StorageOwner
|
||||
@@ -62,11 +59,13 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
private val maps = listOf(protoMap, constantsMap, inlineFunctionsMap, packagePartMap)
|
||||
|
||||
public fun saveFileToCache(sourceFiles: Collection<File>, classFile: File): RecompilationDecision {
|
||||
val fileBytes = classFile.readBytes()
|
||||
val classNameAndHeader = VirtualFileKotlinClass.readClassNameAndHeader(fileBytes)
|
||||
if (classNameAndHeader == null) return DO_NOTHING
|
||||
val kotlinClass = LocalFileKotlinClass.create(classFile)
|
||||
if (kotlinClass == null) return DO_NOTHING
|
||||
|
||||
val fileBytes = kotlinClass.getFileContents()
|
||||
val className = kotlinClass.getClassName()
|
||||
val header = kotlinClass.getClassHeader()
|
||||
|
||||
val (className, header) = classNameAndHeader
|
||||
val annotationDataEncoded = header.annotationData
|
||||
if (annotationDataEncoded != null) {
|
||||
val data = BitEncoding.decodeBytes(annotationDataEncoded)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.jps.incremental
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.FileBasedKotlinClass
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
|
||||
import java.io.File
|
||||
|
||||
class LocalFileKotlinClass private(
|
||||
private val file: File,
|
||||
private val fileContents: ByteArray,
|
||||
className: JvmClassName,
|
||||
classHeader: KotlinClassHeader
|
||||
) : FileBasedKotlinClass(className, classHeader) {
|
||||
|
||||
class object {
|
||||
fun create(file: File): LocalFileKotlinClass? {
|
||||
val fileContents = file.readBytes()
|
||||
val nameAndHeader = FileBasedKotlinClass.readClassNameAndHeader(fileContents)
|
||||
if (nameAndHeader == null) return null
|
||||
|
||||
return LocalFileKotlinClass(file, fileContents, nameAndHeader.first!!, nameAndHeader.second!!)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun getFileContents(): ByteArray = fileContents
|
||||
|
||||
override fun hashCode(): Int = file.hashCode()
|
||||
override fun equals(other: Any?): Boolean = other is LocalFileKotlinClass && file == other.file
|
||||
override fun toString(): String = "$javaClass: $file"
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import com.google.protobuf.ExtensionRegistry
|
||||
import java.io.ByteArrayInputStream
|
||||
import org.jetbrains.jet.descriptors.serialization.DebugProtoBuf
|
||||
import java.util.Arrays
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass
|
||||
import org.jetbrains.jet.jps.incremental.LocalFileKotlinClass
|
||||
|
||||
// Set this to true if you want to dump all bytecode (test will fail in this case)
|
||||
val DUMP_ALL = System.getProperty("comparison.dump.all") == "true"
|
||||
@@ -116,12 +116,10 @@ fun assertEqualDirectories(expected: File, actual: File) {
|
||||
fun classFileToString(classFile: File): String {
|
||||
val out = StringWriter()
|
||||
|
||||
val classBytes = classFile.readBytes()
|
||||
|
||||
val traceVisitor = TraceClassVisitor(PrintWriter(out))
|
||||
ClassReader(classBytes).accept(traceVisitor, 0)
|
||||
ClassReader(classFile.readBytes()).accept(traceVisitor, 0)
|
||||
|
||||
val classHeader = VirtualFileKotlinClass.readClassHeader(classBytes)
|
||||
val classHeader = LocalFileKotlinClass.create(classFile)?.getClassHeader()
|
||||
|
||||
val annotationDataEncoded = classHeader?.annotationData
|
||||
if (annotationDataEncoded != null) {
|
||||
|
||||
Reference in New Issue
Block a user