Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2010-2015 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.kotlin.incremental.storage
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.io.DataExternalizer
import com.intellij.util.io.EnumeratorStringDescriptor
import com.intellij.util.io.IOUtil
import com.intellij.util.io.KeyDescriptor
import org.jetbrains.kotlin.inline.InlineFunction
import org.jetbrains.kotlin.inline.InlineFunctionOrAccessor
import org.jetbrains.kotlin.inline.InlinePropertyAccessor
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMemberSignature
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import java.io.*
/**
* Externalizer that works correctly when [com.intellij.util.io.PersistentHashMap.appendData] is called
*
* Besides the [append] method, it should support incremental [save] and [read]. E.g. if [save] was called multiple times, [read] should be able to collect them together
*/
interface AppendableDataExternalizer : DataExternalizer {
/**
* Creates an empty appendable object
*/
fun createNil(): T
/**
* Combines two non-serialized appendable objects
*/
fun append(currentValue: T, appendData: T): T
}
class LookupSymbolKeyDescriptor(
/** If `true`, original values are saved; if `false`, only hashes are saved. */
private val storeFullFqNames: Boolean = false
) : KeyDescriptor {
override fun read(input: DataInput): LookupSymbolKey {
// Note: The value of the storeFullFqNames variable below may or may not be the same as LookupSymbolKeyDescriptor.storeFullFqNames.
// Byte value `0` means storeFullFqNames == true, see `save` function below.
val storeFullFqNames = when (val byteValue = input.readByte().toInt()) {
0 -> true
1 -> false
else -> error("Unexpected byte value for storeFullFqNames: $byteValue")
}
return if (storeFullFqNames) {
val name = input.readUTF()
val scope = input.readUTF()
LookupSymbolKey(name.hashCode(), scope.hashCode(), name, scope)
} else {
val nameHash = input.readInt()
val scopeHash = input.readInt()
LookupSymbolKey(nameHash, scopeHash, "", "")
}
}
override fun save(output: DataOutput, value: LookupSymbolKey) {
// Write a Byte value `0` to represent storeFullFqNames == true for historical reasons (if we switch this value to `1` or write a
// Boolean instead, it might impact some tests).
output.writeByte(if (storeFullFqNames) 0 else 1)
if (storeFullFqNames) {
output.writeUTF(value.name)
output.writeUTF(value.scope)
} else {
output.writeInt(value.nameHash)
output.writeInt(value.scopeHash)
}
}
override fun getHashCode(value: LookupSymbolKey): Int = value.hashCode()
override fun isEqual(val1: LookupSymbolKey, val2: LookupSymbolKey): Boolean = val1 == val2
}
object FqNameExternalizer : DataExternalizer {
override fun save(output: DataOutput, fqName: FqName) {
output.writeString(fqName.asString())
}
override fun read(input: DataInput): FqName {
return FqName(input.readString())
}
}
object ClassIdExternalizer : DataExternalizer {
override fun save(output: DataOutput, classId: ClassId) {
FqNameExternalizer.save(output, classId.packageFqName)
FqNameExternalizer.save(output, classId.relativeClassName)
output.writeBoolean(classId.isLocal)
}
override fun read(input: DataInput): ClassId {
return ClassId(
/* packageFqName */ FqNameExternalizer.read(input),
/* relativeClassName */ FqNameExternalizer.read(input),
/* isLocal */ input.readBoolean()
)
}
}
object JvmClassNameExternalizer : DataExternalizer {
override fun save(output: DataOutput, jvmClassName: JvmClassName) {
output.writeString(jvmClassName.internalName)
}
override fun read(input: DataInput): JvmClassName {
return JvmClassName.byInternalName(input.readString())
}
}
object ProtoMapValueExternalizer : DataExternalizer {
override fun save(output: DataOutput, value: ProtoMapValue) {
output.writeBoolean(value.isPackageFacade)
output.writeInt(value.bytes.size)
output.write(value.bytes)
output.writeInt(value.strings.size)
for (string in value.strings) {
output.writeUTF(string)
}
}
override fun read(input: DataInput): ProtoMapValue {
val isPackageFacade = input.readBoolean()
val bytesLength = input.readInt()
val bytes = ByteArray(bytesLength)
input.readFully(bytes, 0, bytesLength)
val stringsLength = input.readInt()
val strings = Array(stringsLength) { input.readUTF() }
return ProtoMapValue(isPackageFacade, bytes, strings)
}
}
abstract class StringMapExternalizer : DataExternalizer