Split ProtoBuf.Callable to three messages: constructor, function, property
Serialize both at the moment, will drop the old one after bootstrap
Original commit: ad735cd788
This commit is contained in:
@@ -37,10 +37,19 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
open fun checkEquals(old: ProtoBuf.Package, new: ProtoBuf.Package): Boolean {
|
open fun checkEquals(old: ProtoBuf.Package, new: ProtoBuf.Package): Boolean {
|
||||||
if (!checkEqualsPackageMember(old, new)) return false
|
if (!checkEqualsPackageMember(old, new)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsPackageConstructor(old, new)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsPackageFunction(old, new)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsPackageProperty(old, new)) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
public enum class ProtoBufPackageKind {
|
public enum class ProtoBufPackageKind {
|
||||||
MEMBER_LIST
|
MEMBER_LIST,
|
||||||
|
CONSTRUCTOR_LIST,
|
||||||
|
FUNCTION_LIST,
|
||||||
|
PROPERTY_LIST
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun difference(old: ProtoBuf.Package, new: ProtoBuf.Package): EnumSet<ProtoBufPackageKind> {
|
public fun difference(old: ProtoBuf.Package, new: ProtoBuf.Package): EnumSet<ProtoBufPackageKind> {
|
||||||
@@ -48,6 +57,12 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
|
|
||||||
if (!checkEqualsPackageMember(old, new)) result.add(ProtoBufPackageKind.MEMBER_LIST)
|
if (!checkEqualsPackageMember(old, new)) result.add(ProtoBufPackageKind.MEMBER_LIST)
|
||||||
|
|
||||||
|
if (!checkEqualsPackageConstructor(old, new)) result.add(ProtoBufPackageKind.CONSTRUCTOR_LIST)
|
||||||
|
|
||||||
|
if (!checkEqualsPackageFunction(old, new)) result.add(ProtoBufPackageKind.FUNCTION_LIST)
|
||||||
|
|
||||||
|
if (!checkEqualsPackageProperty(old, new)) result.add(ProtoBufPackageKind.PROPERTY_LIST)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +85,12 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
|
|
||||||
if (!checkEqualsClassNestedClassName(old, new)) return false
|
if (!checkEqualsClassNestedClassName(old, new)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsClassConstructor(old, new)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsClassFunction(old, new)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsClassProperty(old, new)) return false
|
||||||
|
|
||||||
if (!checkEqualsClassMember(old, new)) return false
|
if (!checkEqualsClassMember(old, new)) return false
|
||||||
|
|
||||||
if (!checkEqualsClassEnumEntry(old, new)) return false
|
if (!checkEqualsClassEnumEntry(old, new)) return false
|
||||||
@@ -96,6 +117,9 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
TYPE_PARAMETER_LIST,
|
TYPE_PARAMETER_LIST,
|
||||||
SUPERTYPE_LIST,
|
SUPERTYPE_LIST,
|
||||||
NESTED_CLASS_NAME_LIST,
|
NESTED_CLASS_NAME_LIST,
|
||||||
|
CONSTRUCTOR_LIST,
|
||||||
|
FUNCTION_LIST,
|
||||||
|
PROPERTY_LIST,
|
||||||
MEMBER_LIST,
|
MEMBER_LIST,
|
||||||
ENUM_ENTRY_LIST,
|
ENUM_ENTRY_LIST,
|
||||||
PRIMARY_CONSTRUCTOR,
|
PRIMARY_CONSTRUCTOR,
|
||||||
@@ -124,6 +148,12 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
|
|
||||||
if (!checkEqualsClassNestedClassName(old, new)) result.add(ProtoBufClassKind.NESTED_CLASS_NAME_LIST)
|
if (!checkEqualsClassNestedClassName(old, new)) result.add(ProtoBufClassKind.NESTED_CLASS_NAME_LIST)
|
||||||
|
|
||||||
|
if (!checkEqualsClassConstructor(old, new)) result.add(ProtoBufClassKind.CONSTRUCTOR_LIST)
|
||||||
|
|
||||||
|
if (!checkEqualsClassFunction(old, new)) result.add(ProtoBufClassKind.FUNCTION_LIST)
|
||||||
|
|
||||||
|
if (!checkEqualsClassProperty(old, new)) result.add(ProtoBufClassKind.PROPERTY_LIST)
|
||||||
|
|
||||||
if (!checkEqualsClassMember(old, new)) result.add(ProtoBufClassKind.MEMBER_LIST)
|
if (!checkEqualsClassMember(old, new)) result.add(ProtoBufClassKind.MEMBER_LIST)
|
||||||
|
|
||||||
if (!checkEqualsClassEnumEntry(old, new)) result.add(ProtoBufClassKind.ENUM_ENTRY_LIST)
|
if (!checkEqualsClassEnumEntry(old, new)) result.add(ProtoBufClassKind.ENUM_ENTRY_LIST)
|
||||||
@@ -191,6 +221,74 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun checkEquals(old: ProtoBuf.Constructor, new: ProtoBuf.Constructor): Boolean {
|
||||||
|
if (old.hasFlags() != new.hasFlags()) return false
|
||||||
|
if (old.hasFlags()) {
|
||||||
|
if (old.flags != new.flags) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkEqualsConstructorValueParameter(old, new)) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEquals(old: ProtoBuf.Function, new: ProtoBuf.Function): Boolean {
|
||||||
|
if (old.hasFlags() != new.hasFlags()) return false
|
||||||
|
if (old.hasFlags()) {
|
||||||
|
if (old.flags != new.flags) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkStringEquals(old.name, new.name)) return false
|
||||||
|
|
||||||
|
if (!checkEquals(old.returnType, new.returnType)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsFunctionTypeParameter(old, new)) return false
|
||||||
|
|
||||||
|
if (old.hasReceiverType() != new.hasReceiverType()) return false
|
||||||
|
if (old.hasReceiverType()) {
|
||||||
|
if (!checkEquals(old.receiverType, new.receiverType)) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkEqualsFunctionValueParameter(old, new)) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEquals(old: ProtoBuf.Property, new: ProtoBuf.Property): Boolean {
|
||||||
|
if (old.hasFlags() != new.hasFlags()) return false
|
||||||
|
if (old.hasFlags()) {
|
||||||
|
if (old.flags != new.flags) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkStringEquals(old.name, new.name)) return false
|
||||||
|
|
||||||
|
if (!checkEquals(old.returnType, new.returnType)) return false
|
||||||
|
|
||||||
|
if (!checkEqualsPropertyTypeParameter(old, new)) return false
|
||||||
|
|
||||||
|
if (old.hasReceiverType() != new.hasReceiverType()) return false
|
||||||
|
if (old.hasReceiverType()) {
|
||||||
|
if (!checkEquals(old.receiverType, new.receiverType)) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old.hasSetterValueParameter() != new.hasSetterValueParameter()) return false
|
||||||
|
if (old.hasSetterValueParameter()) {
|
||||||
|
if (!checkEquals(old.setterValueParameter, new.setterValueParameter)) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old.hasGetterFlags() != new.hasGetterFlags()) return false
|
||||||
|
if (old.hasGetterFlags()) {
|
||||||
|
if (old.getterFlags != new.getterFlags) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old.hasSetterFlags() != new.hasSetterFlags()) return false
|
||||||
|
if (old.hasSetterFlags()) {
|
||||||
|
if (old.setterFlags != new.setterFlags) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
open fun checkEquals(old: ProtoBuf.TypeParameter, new: ProtoBuf.TypeParameter): Boolean {
|
open fun checkEquals(old: ProtoBuf.TypeParameter, new: ProtoBuf.TypeParameter): Boolean {
|
||||||
if (old.id != new.id) return false
|
if (old.id != new.id) return false
|
||||||
|
|
||||||
@@ -416,6 +514,36 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsPackageConstructor(old: ProtoBuf.Package, new: ProtoBuf.Package): Boolean {
|
||||||
|
if (old.constructorCount != new.constructorCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.constructorCount - 1) {
|
||||||
|
if (!checkEquals(old.getConstructor(i), new.getConstructor(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsPackageFunction(old: ProtoBuf.Package, new: ProtoBuf.Package): Boolean {
|
||||||
|
if (old.functionCount != new.functionCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.functionCount - 1) {
|
||||||
|
if (!checkEquals(old.getFunction(i), new.getFunction(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsPackageProperty(old: ProtoBuf.Package, new: ProtoBuf.Package): Boolean {
|
||||||
|
if (old.propertyCount != new.propertyCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.propertyCount - 1) {
|
||||||
|
if (!checkEquals(old.getProperty(i), new.getProperty(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
open fun checkEqualsClassTypeParameter(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
open fun checkEqualsClassTypeParameter(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||||
if (old.typeParameterCount != new.typeParameterCount) return false
|
if (old.typeParameterCount != new.typeParameterCount) return false
|
||||||
|
|
||||||
@@ -446,6 +574,36 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsClassConstructor(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||||
|
if (old.constructorCount != new.constructorCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.constructorCount - 1) {
|
||||||
|
if (!checkEquals(old.getConstructor(i), new.getConstructor(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsClassFunction(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||||
|
if (old.functionCount != new.functionCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.functionCount - 1) {
|
||||||
|
if (!checkEquals(old.getFunction(i), new.getFunction(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsClassProperty(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||||
|
if (old.propertyCount != new.propertyCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.propertyCount - 1) {
|
||||||
|
if (!checkEquals(old.getProperty(i), new.getProperty(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
open fun checkEqualsClassMember(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
open fun checkEqualsClassMember(old: ProtoBuf.Class, new: ProtoBuf.Class): Boolean {
|
||||||
if (old.memberCount != new.memberCount) return false
|
if (old.memberCount != new.memberCount) return false
|
||||||
|
|
||||||
@@ -496,6 +654,46 @@ open class ProtoCompareGenerated(public val oldNameResolver: NameResolver, publi
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsConstructorValueParameter(old: ProtoBuf.Constructor, new: ProtoBuf.Constructor): Boolean {
|
||||||
|
if (old.valueParameterCount != new.valueParameterCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.valueParameterCount - 1) {
|
||||||
|
if (!checkEquals(old.getValueParameter(i), new.getValueParameter(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsFunctionTypeParameter(old: ProtoBuf.Function, new: ProtoBuf.Function): Boolean {
|
||||||
|
if (old.typeParameterCount != new.typeParameterCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.typeParameterCount - 1) {
|
||||||
|
if (!checkEquals(old.getTypeParameter(i), new.getTypeParameter(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsFunctionValueParameter(old: ProtoBuf.Function, new: ProtoBuf.Function): Boolean {
|
||||||
|
if (old.valueParameterCount != new.valueParameterCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.valueParameterCount - 1) {
|
||||||
|
if (!checkEquals(old.getValueParameter(i), new.getValueParameter(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun checkEqualsPropertyTypeParameter(old: ProtoBuf.Property, new: ProtoBuf.Property): Boolean {
|
||||||
|
if (old.typeParameterCount != new.typeParameterCount) return false
|
||||||
|
|
||||||
|
for(i in 0..old.typeParameterCount - 1) {
|
||||||
|
if (!checkEquals(old.getTypeParameter(i), new.getTypeParameter(i))) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
open fun checkEqualsTypeParameterUpperBound(old: ProtoBuf.TypeParameter, new: ProtoBuf.TypeParameter): Boolean {
|
open fun checkEqualsTypeParameterUpperBound(old: ProtoBuf.TypeParameter, new: ProtoBuf.TypeParameter): Boolean {
|
||||||
if (old.upperBoundCount != new.upperBoundCount) return false
|
if (old.upperBoundCount != new.upperBoundCount) return false
|
||||||
|
|
||||||
@@ -574,6 +772,18 @@ public fun ProtoBuf.Package.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes:
|
|||||||
hashCode = 31 * hashCode + getMember(i).hashCode(stringIndexes, fqNameIndexes)
|
hashCode = 31 * hashCode + getMember(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i in 0..constructorCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getConstructor(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i in 0..functionCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getFunction(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i in 0..propertyCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getProperty(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
return hashCode
|
return hashCode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,6 +812,18 @@ public fun ProtoBuf.Class.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (
|
|||||||
hashCode = 31 * hashCode + stringIndexes(getNestedClassName(i))
|
hashCode = 31 * hashCode + stringIndexes(getNestedClassName(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i in 0..constructorCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getConstructor(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i in 0..functionCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getFunction(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i in 0..propertyCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getProperty(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
for(i in 0..memberCount - 1) {
|
for(i in 0..memberCount - 1) {
|
||||||
hashCode = 31 * hashCode + getMember(i).hashCode(stringIndexes, fqNameIndexes)
|
hashCode = 31 * hashCode + getMember(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
}
|
}
|
||||||
@@ -671,6 +893,80 @@ public fun ProtoBuf.Callable.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes
|
|||||||
return hashCode
|
return hashCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun ProtoBuf.Constructor.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||||
|
var hashCode = 1
|
||||||
|
|
||||||
|
if (hasFlags()) {
|
||||||
|
hashCode = 31 * hashCode + flags
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i in 0..valueParameterCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getValueParameter(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
return hashCode
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun ProtoBuf.Function.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||||
|
var hashCode = 1
|
||||||
|
|
||||||
|
if (hasFlags()) {
|
||||||
|
hashCode = 31 * hashCode + flags
|
||||||
|
}
|
||||||
|
|
||||||
|
hashCode = 31 * hashCode + stringIndexes(name)
|
||||||
|
|
||||||
|
hashCode = 31 * hashCode + returnType.hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
|
||||||
|
for(i in 0..typeParameterCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getTypeParameter(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasReceiverType()) {
|
||||||
|
hashCode = 31 * hashCode + receiverType.hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i in 0..valueParameterCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getValueParameter(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
return hashCode
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun ProtoBuf.Property.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||||
|
var hashCode = 1
|
||||||
|
|
||||||
|
if (hasFlags()) {
|
||||||
|
hashCode = 31 * hashCode + flags
|
||||||
|
}
|
||||||
|
|
||||||
|
hashCode = 31 * hashCode + stringIndexes(name)
|
||||||
|
|
||||||
|
hashCode = 31 * hashCode + returnType.hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
|
||||||
|
for(i in 0..typeParameterCount - 1) {
|
||||||
|
hashCode = 31 * hashCode + getTypeParameter(i).hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasReceiverType()) {
|
||||||
|
hashCode = 31 * hashCode + receiverType.hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasSetterValueParameter()) {
|
||||||
|
hashCode = 31 * hashCode + setterValueParameter.hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasGetterFlags()) {
|
||||||
|
hashCode = 31 * hashCode + getterFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasSetterFlags()) {
|
||||||
|
hashCode = 31 * hashCode + setterFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
return hashCode
|
||||||
|
}
|
||||||
|
|
||||||
public fun ProtoBuf.TypeParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
public fun ProtoBuf.TypeParameter.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||||
var hashCode = 1
|
var hashCode = 1
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jps.incremental
|
package org.jetbrains.kotlin.jps.incremental
|
||||||
|
|
||||||
|
import com.google.protobuf.MessageLite
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
|
import org.jetbrains.kotlin.jps.incremental.ProtoCompareGenerated.ProtoBufClassKind
|
||||||
|
import org.jetbrains.kotlin.jps.incremental.ProtoCompareGenerated.ProtoBufPackageKind
|
||||||
import org.jetbrains.kotlin.serialization.Flags
|
import org.jetbrains.kotlin.serialization.Flags
|
||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.Deserialization
|
import org.jetbrains.kotlin.serialization.deserialization.Deserialization
|
||||||
@@ -52,17 +55,16 @@ private abstract class DifferenceCalculator() {
|
|||||||
|
|
||||||
protected fun membersOrNone(names: Collection<String>): DifferenceKind = if (names.isEmpty()) DifferenceKind.NONE else DifferenceKind.MEMBERS(names)
|
protected fun membersOrNone(names: Collection<String>): DifferenceKind = if (names.isEmpty()) DifferenceKind.NONE else DifferenceKind.MEMBERS(names)
|
||||||
|
|
||||||
protected fun calcDifferenceForMembers(
|
protected fun calcDifferenceForMembers(oldList: List<MessageLite>, newList: List<MessageLite>): Collection<String> {
|
||||||
oldList: List<ProtoBuf.Callable>,
|
|
||||||
newList: List<ProtoBuf.Callable>
|
|
||||||
): Collection<String> {
|
|
||||||
val result = hashSetOf<String>()
|
val result = hashSetOf<String>()
|
||||||
|
|
||||||
val oldMap = oldList.groupBy { it.hashCode({ compareObject.oldGetIndexOfString(it) }, { compareObject.oldGetIndexOfClassId(it) } )}
|
fun List<MessageLite>.names(nameResolver: NameResolver): List<String> =
|
||||||
val newMap = newList.groupBy { it.hashCode({ compareObject.newGetIndexOfString(it) }, { compareObject.newGetIndexOfClassId(it) } )}
|
map { it.name(nameResolver) }
|
||||||
|
|
||||||
fun List<ProtoBuf.Callable>.names(nameResolver: NameResolver): List<String> =
|
val oldMap =
|
||||||
map { nameResolver.getString(it.name) }
|
oldList.groupBy { it.getHashCode({ compareObject.oldGetIndexOfString(it) }, { compareObject.oldGetIndexOfClassId(it) }) }
|
||||||
|
val newMap =
|
||||||
|
newList.groupBy { it.getHashCode({ compareObject.newGetIndexOfString(it) }, { compareObject.newGetIndexOfClassId(it) }) }
|
||||||
|
|
||||||
val hashes = oldMap.keySet() + newMap.keySet()
|
val hashes = oldMap.keySet() + newMap.keySet()
|
||||||
for (hash in hashes) {
|
for (hash in hashes) {
|
||||||
@@ -81,8 +83,8 @@ private abstract class DifferenceCalculator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calcDifferenceForEqualHashes(
|
private fun calcDifferenceForEqualHashes(
|
||||||
oldList: List<ProtoBuf.Callable>,
|
oldList: List<MessageLite>,
|
||||||
newList: List<ProtoBuf.Callable>
|
newList: List<MessageLite>
|
||||||
): Collection<String> {
|
): Collection<String> {
|
||||||
val result = hashSetOf<String>()
|
val result = hashSetOf<String>()
|
||||||
val newSet = HashSet(newList)
|
val newSet = HashSet(newList)
|
||||||
@@ -93,12 +95,12 @@ private abstract class DifferenceCalculator() {
|
|||||||
newSet.remove(newMember)
|
newSet.remove(newMember)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result.add(compareObject.oldNameResolver.getString(oldMember.name))
|
result.add(oldMember.name(compareObject.oldNameResolver))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newSet.forEach { newMember ->
|
newSet.forEach { newMember ->
|
||||||
result.add(compareObject.newNameResolver.getString(newMember.name))
|
result.add(newMember.name(compareObject.newNameResolver))
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -113,8 +115,45 @@ private abstract class DifferenceCalculator() {
|
|||||||
return HashSetUtil.symmetricDifference(oldNames, newNames)
|
return HashSetUtil.symmetricDifference(oldNames, newNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected val ProtoBuf.Callable.isPrivate: Boolean
|
protected val MessageLite.isPrivate: Boolean
|
||||||
get() = Visibilities.isPrivate(Deserialization.visibility(Flags.VISIBILITY.get(flags)))
|
get() = Visibilities.isPrivate(Deserialization.visibility(
|
||||||
|
when (this) {
|
||||||
|
is ProtoBuf.Callable -> Flags.VISIBILITY.get(flags)
|
||||||
|
is ProtoBuf.Constructor -> Flags.VISIBILITY.get(flags)
|
||||||
|
is ProtoBuf.Function -> Flags.VISIBILITY.get(flags)
|
||||||
|
is ProtoBuf.Property -> Flags.VISIBILITY.get(flags)
|
||||||
|
else -> error("Unknown message: $this")
|
||||||
|
}))
|
||||||
|
|
||||||
|
private fun MessageLite.getHashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) -> Int): Int {
|
||||||
|
return when (this) {
|
||||||
|
is ProtoBuf.Callable -> hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
is ProtoBuf.Constructor -> hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
is ProtoBuf.Function -> hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
is ProtoBuf.Property -> hashCode(stringIndexes, fqNameIndexes)
|
||||||
|
else -> error("Unknown message: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun MessageLite.name(nameResolver: NameResolver): String {
|
||||||
|
return when (this) {
|
||||||
|
is ProtoBuf.Callable -> nameResolver.getString(name)
|
||||||
|
is ProtoBuf.Constructor -> "<init>"
|
||||||
|
is ProtoBuf.Function -> nameResolver.getString(name)
|
||||||
|
is ProtoBuf.Property -> nameResolver.getString(name)
|
||||||
|
else -> error("Unknown message: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ProtoCompareGenerated.checkEquals(old: MessageLite, new: MessageLite): Boolean {
|
||||||
|
return when {
|
||||||
|
old is ProtoBuf.Callable && new is ProtoBuf.Callable -> checkEquals(old, new)
|
||||||
|
old is ProtoBuf.Constructor && new is ProtoBuf.Constructor -> checkEquals(old, new)
|
||||||
|
old is ProtoBuf.Function && new is ProtoBuf.Function -> checkEquals(old, new)
|
||||||
|
old is ProtoBuf.Property && new is ProtoBuf.Property -> checkEquals(old, new)
|
||||||
|
else -> error("Unknown message: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DifferenceCalculatorForClass(oldData: ProtoMapValue, newData: ProtoMapValue) : DifferenceCalculator() {
|
private class DifferenceCalculatorForClass(oldData: ProtoMapValue, newData: ProtoMapValue) : DifferenceCalculator() {
|
||||||
@@ -122,11 +161,11 @@ private class DifferenceCalculatorForClass(oldData: ProtoMapValue, newData: Prot
|
|||||||
private val CONSTRUCTOR = "<init>"
|
private val CONSTRUCTOR = "<init>"
|
||||||
|
|
||||||
private val CLASS_SIGNATURE_ENUMS = EnumSet.of(
|
private val CLASS_SIGNATURE_ENUMS = EnumSet.of(
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.FLAGS,
|
ProtoBufClassKind.FLAGS,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.FQ_NAME,
|
ProtoBufClassKind.FQ_NAME,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.TYPE_PARAMETER_LIST,
|
ProtoBufClassKind.TYPE_PARAMETER_LIST,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.SUPERTYPE_LIST,
|
ProtoBufClassKind.SUPERTYPE_LIST,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.CLASS_ANNOTATION_LIST
|
ProtoBufClassKind.CLASS_ANNOTATION_LIST
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,34 +194,43 @@ private class DifferenceCalculatorForClass(oldData: ProtoMapValue, newData: Prot
|
|||||||
fun Int.oldToNames() = names.add(oldNameResolver.getString(this))
|
fun Int.oldToNames() = names.add(oldNameResolver.getString(this))
|
||||||
fun Int.newToNames() = names.add(newNameResolver.getString(this))
|
fun Int.newToNames() = names.add(newNameResolver.getString(this))
|
||||||
|
|
||||||
|
fun calcDifferenceForNonPrivateMembers(members: (ProtoBuf.Class) -> List<MessageLite>): Collection<String> {
|
||||||
|
val oldMembers = members(oldProto).filterNot { it.isPrivate }
|
||||||
|
val newMembers = members(newProto).filterNot { it.isPrivate }
|
||||||
|
return calcDifferenceForMembers(oldMembers, newMembers)
|
||||||
|
}
|
||||||
|
|
||||||
for (kind in diff) {
|
for (kind in diff) {
|
||||||
when (kind!!) {
|
when (kind!!) {
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.COMPANION_OBJECT_NAME -> {
|
ProtoBufClassKind.COMPANION_OBJECT_NAME -> {
|
||||||
if (oldProto.hasCompanionObjectName()) oldProto.companionObjectName.oldToNames()
|
if (oldProto.hasCompanionObjectName()) oldProto.companionObjectName.oldToNames()
|
||||||
if (newProto.hasCompanionObjectName()) newProto.companionObjectName.newToNames()
|
if (newProto.hasCompanionObjectName()) newProto.companionObjectName.newToNames()
|
||||||
}
|
}
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.NESTED_CLASS_NAME_LIST ->
|
ProtoBufClassKind.NESTED_CLASS_NAME_LIST ->
|
||||||
names.addAll(calcDifferenceForNames(oldProto.nestedClassNameList, newProto.nestedClassNameList))
|
names.addAll(calcDifferenceForNames(oldProto.nestedClassNameList, newProto.nestedClassNameList))
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.MEMBER_LIST -> {
|
ProtoBufClassKind.CONSTRUCTOR_LIST ->
|
||||||
val oldMembers = oldProto.memberList.filter { !it.isPrivate }
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Class::getConstructorList))
|
||||||
val newMembers = newProto.memberList.filter { !it.isPrivate }
|
ProtoBufClassKind.FUNCTION_LIST ->
|
||||||
names.addAll(calcDifferenceForMembers(oldMembers, newMembers))
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Class::getFunctionList))
|
||||||
}
|
ProtoBufClassKind.PROPERTY_LIST ->
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.ENUM_ENTRY_LIST ->
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Class::getPropertyList))
|
||||||
|
ProtoBufClassKind.MEMBER_LIST ->
|
||||||
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Class::getMemberList))
|
||||||
|
ProtoBufClassKind.ENUM_ENTRY_LIST ->
|
||||||
names.addAll(calcDifferenceForNames(oldProto.enumEntryList, newProto.enumEntryList))
|
names.addAll(calcDifferenceForNames(oldProto.enumEntryList, newProto.enumEntryList))
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.PRIMARY_CONSTRUCTOR ->
|
ProtoBufClassKind.PRIMARY_CONSTRUCTOR ->
|
||||||
if (areNonPrivatePrimaryConstructorsDifferent()) {
|
if (areNonPrivatePrimaryConstructorsDifferent()) {
|
||||||
names.add(CONSTRUCTOR)
|
names.add(CONSTRUCTOR)
|
||||||
}
|
}
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.SECONDARY_CONSTRUCTOR_LIST ->
|
ProtoBufClassKind.SECONDARY_CONSTRUCTOR_LIST ->
|
||||||
if (areNonPrivateSecondaryConstructorsDifferent()) {
|
if (areNonPrivateSecondaryConstructorsDifferent()) {
|
||||||
names.add(CONSTRUCTOR)
|
names.add(CONSTRUCTOR)
|
||||||
}
|
}
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.FLAGS,
|
ProtoBufClassKind.FLAGS,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.FQ_NAME,
|
ProtoBufClassKind.FQ_NAME,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.TYPE_PARAMETER_LIST,
|
ProtoBufClassKind.TYPE_PARAMETER_LIST,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.SUPERTYPE_LIST,
|
ProtoBufClassKind.SUPERTYPE_LIST,
|
||||||
ProtoCompareGenerated.ProtoBufClassKind.CLASS_ANNOTATION_LIST ->
|
ProtoBufClassKind.CLASS_ANNOTATION_LIST ->
|
||||||
throw IllegalArgumentException("Unexpected kind: $kind")
|
throw IllegalArgumentException("Unexpected kind: $kind")
|
||||||
else ->
|
else ->
|
||||||
throw IllegalArgumentException("Unsupported kind: $kind")
|
throw IllegalArgumentException("Unsupported kind: $kind")
|
||||||
@@ -237,14 +285,27 @@ private class DifferenceCalculatorForPackageFacade(oldData: ProtoMapValue, newDa
|
|||||||
private fun getChangedMembersNames(): Set<String> {
|
private fun getChangedMembersNames(): Set<String> {
|
||||||
val names = hashSetOf<String>()
|
val names = hashSetOf<String>()
|
||||||
|
|
||||||
|
fun calcDifferenceForNonPrivateMembers(members: (ProtoBuf.Package) -> List<MessageLite>): Collection<String> {
|
||||||
|
val oldMembers = members(oldProto).filterNot { it.isPrivate }
|
||||||
|
val newMembers = members(newProto).filterNot { it.isPrivate }
|
||||||
|
return calcDifferenceForMembers(oldMembers, newMembers)
|
||||||
|
}
|
||||||
|
|
||||||
for (kind in diff) {
|
for (kind in diff) {
|
||||||
when (kind!!) {
|
when (kind!!) {
|
||||||
ProtoCompareGenerated.ProtoBufPackageKind.MEMBER_LIST ->
|
ProtoBufPackageKind.CONSTRUCTOR_LIST ->
|
||||||
names.addAll(calcDifferenceForMembers(oldProto.memberList.filter { !it.isPrivate }, newProto.memberList.filter { !it.isPrivate }))
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Package::getConstructorList))
|
||||||
|
ProtoBufPackageKind.FUNCTION_LIST ->
|
||||||
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Package::getFunctionList))
|
||||||
|
ProtoBufPackageKind.PROPERTY_LIST ->
|
||||||
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Package::getPropertyList))
|
||||||
|
ProtoBufPackageKind.MEMBER_LIST ->
|
||||||
|
names.addAll(calcDifferenceForNonPrivateMembers(ProtoBuf.Package::getMemberList))
|
||||||
else ->
|
else ->
|
||||||
throw IllegalArgumentException("Unsupported kind: $kind")
|
throw IllegalArgumentException("Unsupported kind: $kind")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user