core: cleanup 'public', property access syntax

This commit is contained in:
Dmitry Jemerov
2016-01-07 18:03:08 +01:00
parent 117a0d8b7b
commit 3870bd04b8
173 changed files with 1198 additions and 1240 deletions
@@ -36,13 +36,13 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
public class AnnotationDeserializer(private val module: ModuleDescriptor) {
class AnnotationDeserializer(private val module: ModuleDescriptor) {
private val builtIns: KotlinBuiltIns
get() = module.builtIns
private val factory = ConstantValueFactory(builtIns)
public fun deserializeAnnotation(proto: Annotation, nameResolver: NameResolver): AnnotationDescriptor {
fun deserializeAnnotation(proto: Annotation, nameResolver: NameResolver): AnnotationDescriptor {
val annotationClass = resolveClass(nameResolver.getClassId(proto.id))
var arguments = emptyMap<ValueParameterDescriptor, ConstantValue<*>>()
@@ -62,40 +62,40 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
parameterByName: Map<Name, ValueParameterDescriptor>,
nameResolver: NameResolver
): Pair<ValueParameterDescriptor, ConstantValue<*>>? {
val parameter = parameterByName[nameResolver.getName(proto.getNameId())] ?: return null
return Pair(parameter, resolveValue(parameter.getType(), proto.getValue(), nameResolver))
val parameter = parameterByName[nameResolver.getName(proto.nameId)] ?: return null
return Pair(parameter, resolveValue(parameter.type, proto.value, nameResolver))
}
public fun resolveValue(
fun resolveValue(
expectedType: KotlinType,
value: Value,
nameResolver: NameResolver
): ConstantValue<*> {
val result: ConstantValue<*> = when (value.getType()) {
Type.BYTE -> factory.createByteValue(value.getIntValue().toByte())
Type.CHAR -> factory.createCharValue(value.getIntValue().toChar())
Type.SHORT -> factory.createShortValue(value.getIntValue().toShort())
Type.INT -> factory.createIntValue(value.getIntValue().toInt())
Type.LONG -> factory.createLongValue(value.getIntValue())
Type.FLOAT -> factory.createFloatValue(value.getFloatValue())
Type.DOUBLE -> factory.createDoubleValue(value.getDoubleValue())
Type.BOOLEAN -> factory.createBooleanValue(value.getIntValue() != 0L)
val result: ConstantValue<*> = when (value.type) {
Type.BYTE -> factory.createByteValue(value.intValue.toByte())
Type.CHAR -> factory.createCharValue(value.intValue.toChar())
Type.SHORT -> factory.createShortValue(value.intValue.toShort())
Type.INT -> factory.createIntValue(value.intValue.toInt())
Type.LONG -> factory.createLongValue(value.intValue)
Type.FLOAT -> factory.createFloatValue(value.floatValue)
Type.DOUBLE -> factory.createDoubleValue(value.doubleValue)
Type.BOOLEAN -> factory.createBooleanValue(value.intValue != 0L)
Type.STRING -> {
factory.createStringValue(nameResolver.getString(value.getStringValue()))
factory.createStringValue(nameResolver.getString(value.stringValue))
}
Type.CLASS -> {
// TODO: support class literals
error("Class literal annotation arguments are not supported yet (${nameResolver.getClassId(value.getClassId())})")
error("Class literal annotation arguments are not supported yet (${nameResolver.getClassId(value.classId)})")
}
Type.ENUM -> {
resolveEnumValue(nameResolver.getClassId(value.getClassId()), nameResolver.getName(value.getEnumValueId()))
resolveEnumValue(nameResolver.getClassId(value.classId), nameResolver.getName(value.enumValueId))
}
Type.ANNOTATION -> {
AnnotationValue(deserializeAnnotation(value.getAnnotation(), nameResolver))
AnnotationValue(deserializeAnnotation(value.annotation, nameResolver))
}
Type.ARRAY -> {
val expectedIsArray = KotlinBuiltIns.isArray(expectedType) || KotlinBuiltIns.isPrimitiveArray(expectedType)
val arrayElements = value.getArrayElementList()
val arrayElements = value.arrayElementList
val actualArrayType =
if (arrayElements.isNotEmpty()) {
@@ -119,7 +119,7 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
actualArrayType
)
}
else -> error("Unsupported annotation argument type: ${value.getType()} (expected $expectedType)")
else -> error("Unsupported annotation argument type: ${value.type} (expected $expectedType)")
}
if (result.type.isSubtypeOf(expectedType)) {
@@ -134,8 +134,8 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
// NOTE: see analogous code in BinaryClassAnnotationAndConstantLoaderImpl
private fun resolveEnumValue(enumClassId: ClassId, enumEntryName: Name): ConstantValue<*> {
val enumClass = resolveClass(enumClassId)
if (enumClass.getKind() == ClassKind.ENUM_CLASS) {
val enumEntry = enumClass.getUnsubstitutedInnerClassesScope().getContributedClassifier(enumEntryName, NoLookupLocation.FROM_DESERIALIZATION)
if (enumClass.kind == ClassKind.ENUM_CLASS) {
val enumEntry = enumClass.unsubstitutedInnerClassesScope.getContributedClassifier(enumEntryName, NoLookupLocation.FROM_DESERIALIZATION)
if (enumEntry is ClassDescriptor) {
return factory.createEnumValue(enumEntry)
}
@@ -145,7 +145,7 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
private fun resolveArrayElementType(value: Value, nameResolver: NameResolver): KotlinType =
with(builtIns) {
when (value.getType()) {
when (value.type) {
Type.BYTE -> getByteType()
Type.CHAR -> getCharType()
Type.SHORT -> getShortType()
@@ -156,10 +156,10 @@ public class AnnotationDeserializer(private val module: ModuleDescriptor) {
Type.BOOLEAN -> getBooleanType()
Type.STRING -> getStringType()
Type.CLASS -> error("Arrays of class literals are not supported yet") // TODO: support arrays of class literals
Type.ENUM -> resolveClass(nameResolver.getClassId(value.getClassId())).getDefaultType()
Type.ANNOTATION -> resolveClass(nameResolver.getClassId(value.getAnnotation().getId())).getDefaultType()
Type.ENUM -> resolveClass(nameResolver.getClassId(value.classId)).defaultType
Type.ANNOTATION -> resolveClass(nameResolver.getClassId(value.annotation.id)).defaultType
Type.ARRAY -> error("Array of arrays is impossible")
else -> error("Unknown type: ${value.getType()}")
else -> error("Unknown type: ${value.type}")
}
}
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.name.ClassId
public interface ClassDescriptorFactory {
public fun createClass(classId: ClassId): ClassDescriptor?
interface ClassDescriptorFactory {
fun createClass(classId: ClassId): ClassDescriptor?
public object EMPTY : ClassDescriptorFactory {
object EMPTY : ClassDescriptorFactory {
override fun createClass(classId: ClassId): ClassDescriptor? = null
}
}
@@ -21,13 +21,13 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.serialization.ClassDataWithSource
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
public class ClassDeserializer(private val components: DeserializationComponents) {
class ClassDeserializer(private val components: DeserializationComponents) {
private val classes: (ClassKey) -> ClassDescriptor? =
components.storageManager.createMemoizedFunctionWithNullableValues { key -> createClass(key) }
// Additional ClassDataWithSource parameter is needed to avoid calling ClassDataFinder#findClassData()
// if it is already computed at the call site
public fun deserializeClass(classId: ClassId, classDataWithSource: ClassDataWithSource? = null): ClassDescriptor? =
fun deserializeClass(classId: ClassId, classDataWithSource: ClassDataWithSource? = null): ClassDescriptor? =
classes(ClassKey(classId, classDataWithSource))
private fun createClass(key: ClassKey): ClassDescriptor? {
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.storage.getValue
import java.io.InputStream
import javax.inject.Inject
public abstract class DeserializedPackageFragment(
abstract class DeserializedPackageFragment(
fqName: FqName,
protected val storageManager: StorageManager,
module: ModuleDescriptor,
@@ -19,6 +19,6 @@ package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.name.ClassId
public interface LocalClassResolver {
public fun resolveLocalClass(classId: ClassId): ClassDescriptor?
interface LocalClassResolver {
fun resolveLocalClass(classId: ClassId): ClassDescriptor?
}
@@ -21,12 +21,11 @@ import org.jetbrains.kotlin.name.ClassId
import javax.inject.Inject
import kotlin.properties.Delegates
public class LocalClassResolverImpl : LocalClassResolver {
public var components: DeserializationComponents by Delegates.notNull()
class LocalClassResolverImpl : LocalClassResolver {
var components: DeserializationComponents by Delegates.notNull()
// component dependency cycle
@Inject
public fun setDeserializationComponents(components: DeserializationComponents) {
@Inject fun setDeserializationComponents(components: DeserializationComponents) {
this.components = components
}
@@ -30,9 +30,9 @@ import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
import org.jetbrains.kotlin.utils.toReadOnlyList
public class MemberDeserializer(private val c: DeserializationContext) {
public fun loadProperty(proto: ProtoBuf.Property): PropertyDescriptor {
val flags = proto.getFlags()
class MemberDeserializer(private val c: DeserializationContext) {
fun loadProperty(proto: ProtoBuf.Property): PropertyDescriptor {
val flags = proto.flags
val property = DeserializedPropertyDescriptor(
c.containingDeclaration, null,
@@ -50,7 +50,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
c.packagePartSource
)
val local = c.childContext(property, proto.getTypeParameterList())
val local = c.childContext(property, proto.typeParameterList)
val hasGetter = Flags.HAS_GETTER.get(flags)
val receiverAnnotations = if (hasGetter && proto.hasReceiver())
@@ -66,7 +66,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
)
val getter = if (hasGetter) {
val getterFlags = proto.getGetterFlags()
val getterFlags = proto.getterFlags
val isNotDefault = proto.hasGetterFlags() && Flags.IS_NOT_DEFAULT.get(getterFlags)
val isExternal = proto.hasGetterFlags() && Flags.IS_EXTERNAL_ACCESSOR.get(getterFlags)
val getter = if (isNotDefault) {
@@ -92,7 +92,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
}
val setter = if (Flags.HAS_SETTER.get(flags)) {
val setterFlags = proto.getSetterFlags()
val setterFlags = proto.setterFlags
val isNotDefault = proto.hasSetterFlags() && Flags.IS_NOT_DEFAULT.get(setterFlags)
val isExternal = proto.hasSetterFlags() && Flags.IS_EXTERNAL_ACCESSOR.get(setterFlags)
if (isNotDefault) {
@@ -135,7 +135,7 @@ public class MemberDeserializer(private val c: DeserializationContext) {
return property
}
public fun loadFunction(proto: ProtoBuf.Function): FunctionDescriptor {
fun loadFunction(proto: ProtoBuf.Function): FunctionDescriptor {
val annotations = getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION)
val receiverAnnotations = if (proto.hasReceiver())
getReceiverParameterAnnotations(proto, AnnotatedCallableKind.FUNCTION)
@@ -163,10 +163,10 @@ public class MemberDeserializer(private val c: DeserializationContext) {
}
private fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? {
return (c.containingDeclaration as? ClassDescriptor)?.getThisAsReceiverParameter()
return (c.containingDeclaration as? ClassDescriptor)?.thisAsReceiverParameter
}
public fun loadConstructor(proto: ProtoBuf.Constructor, isPrimary: Boolean): ConstructorDescriptor {
fun loadConstructor(proto: ProtoBuf.Constructor, isPrimary: Boolean): ConstructorDescriptor {
val classDescriptor = c.containingDeclaration as ClassDescriptor
val descriptor = DeserializedConstructorDescriptor(
classDescriptor, null, getAnnotations(proto, proto.flags, AnnotatedCallableKind.FUNCTION),
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.types.TypeCapabilities
public abstract class TypeCapabilitiesLoader {
public object NONE : TypeCapabilitiesLoader() {
abstract class TypeCapabilitiesLoader {
object NONE : TypeCapabilitiesLoader() {
override fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities = TypeCapabilities.NONE
}
public abstract fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities
abstract fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities
}
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
public class TypeDeserializer(
class TypeDeserializer(
private val c: DeserializationContext,
private val parent: TypeDeserializer?,
private val typeParameterProtos: List<ProtoBuf.TypeParameter>,
@@ -40,26 +40,26 @@ import org.jetbrains.kotlin.utils.singletonOrEmptyList
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
public class DeserializedClassDescriptor(
class DeserializedClassDescriptor(
outerContext: DeserializationContext,
val classProto: ProtoBuf.Class,
nameResolver: NameResolver,
private val sourceElement: SourceElement
) : ClassDescriptor, AbstractClassDescriptor(
outerContext.storageManager,
nameResolver.getClassId(classProto.getFqName()).getShortClassName()
nameResolver.getClassId(classProto.fqName).shortClassName
) {
private val modality = Deserialization.modality(Flags.MODALITY.get(classProto.getFlags()))
private val visibility = Deserialization.visibility(Flags.VISIBILITY.get(classProto.getFlags()))
private val kindFromProto = Flags.CLASS_KIND.get(classProto.getFlags())
private val modality = Deserialization.modality(Flags.MODALITY.get(classProto.flags))
private val visibility = Deserialization.visibility(Flags.VISIBILITY.get(classProto.flags))
private val kindFromProto = Flags.CLASS_KIND.get(classProto.flags)
private val kind = Deserialization.classKind(kindFromProto)
private val isCompanion = kindFromProto == ProtoBuf.Class.Kind.COMPANION_OBJECT
private val isInner = Flags.IS_INNER.get(classProto.getFlags())
private val isInner = Flags.IS_INNER.get(classProto.flags)
private val isData = Flags.IS_DATA.get(classProto.flags)
val c = outerContext.childContext(this, classProto.typeParameterList, nameResolver, TypeTable(classProto.typeTable))
private val classId = nameResolver.getClassId(classProto.getFqName())
private val classId = nameResolver.getClassId(classProto.fqName)
private val staticScope = StaticScopeForKotlinClass(this)
private val typeConstructor = DeserializedClassTypeConstructor()
@@ -73,7 +73,7 @@ public class DeserializedClassDescriptor(
private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() }
private val annotations =
if (!Flags.HAS_ANNOTATIONS.get(classProto.getFlags())) {
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
Annotations.EMPTY
}
else DeserializedAnnotations(c.storageManager) {
@@ -129,7 +129,7 @@ public class DeserializedClassDescriptor(
private fun computeCompanionObjectDescriptor(): ClassDescriptor? {
if (!classProto.hasCompanionObjectName()) return null
val companionObjectName = c.nameResolver.getName(classProto.getCompanionObjectName())
val companionObjectName = c.nameResolver.getName(classProto.companionObjectName)
return memberScope.getContributedClassifier(companionObjectName, NoLookupLocation.FROM_DESERIALIZATION) as? ClassDescriptor
}
@@ -273,7 +273,7 @@ public class DeserializedClassDescriptor(
private fun nestedClassNames(): Set<Name> {
val result = LinkedHashSet<Name>()
val nameResolver = c.nameResolver
for (index in classProto.getNestedClassNameList()) {
for (index in classProto.nestedClassNameList) {
result.add(nameResolver.getName(index!!))
}
return result
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
public abstract class DeserializedMemberScope protected constructor(
abstract class DeserializedMemberScope protected constructor(
protected val c: DeserializationContext,
functionList: Collection<ProtoBuf.Function>,
propertyList: Collection<ProtoBuf.Property>
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.serialization.deserialization.TypeTable
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.utils.addIfNotNull
public open class DeserializedPackageMemberScope(
open class DeserializedPackageMemberScope(
packageDescriptor: PackageFragmentDescriptor,
proto: ProtoBuf.Package,
nameResolver: NameResolver,
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.ClassId
public fun ModuleDescriptor.findClassAcrossModuleDependencies(classId: ClassId): ClassDescriptor? {
fun ModuleDescriptor.findClassAcrossModuleDependencies(classId: ClassId): ClassDescriptor? {
val packageViewDescriptor = getPackage(classId.packageFqName)
val segments = classId.relativeClassName.pathSegments()
val topLevelClass = packageViewDescriptor.memberScope.getContributedClassifier(segments.first(), NoLookupLocation.FROM_DESERIALIZATION) as? ClassDescriptor ?: return null