Code cleanup: type parameters can have in / out variance

This commit is contained in:
Mikhail Glukhikh
2016-04-29 15:09:06 +03:00
parent 9afb0d5f59
commit 733f3e8025
45 changed files with 76 additions and 74 deletions
@@ -26,7 +26,7 @@ interface FunctionHandle {
fun getOverridden(): Iterable<FunctionHandle>
}
data class Bridge<Signature>(
data class Bridge<out Signature>(
val from: Signature,
val to: Signature
) {
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.singletonOrEmptyList
import java.util.*
class BridgeForBuiltinSpecial<Signature : Any>(
class BridgeForBuiltinSpecial<out Signature : Any>(
val from: Signature, val to: Signature,
val isSpecial: Boolean = false,
val isDelegateToSuper: Boolean = false
@@ -26,7 +26,7 @@ import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode
import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode
import org.jetbrains.org.objectweb.asm.tree.MethodNode
abstract class ObjectTransformer<T : TransformationInfo>(@JvmField val transformationInfo: T, val state: GenerationState) {
abstract class ObjectTransformer<out T : TransformationInfo>(@JvmField val transformationInfo: T, val state: GenerationState) {
abstract fun doTransform(parentRemapper: FieldRemapper): InlineResult
@@ -26,7 +26,7 @@ enum class TryCatchPosition {
INNER
}
class SplitPair<T: Interval>(val patchedPart: T, val newPart: T)
class SplitPair<out T: Interval>(val patchedPart: T, val newPart: T)
class SimpleInterval(override val startLabel: LabelNode, override val endLabel: LabelNode ) : Interval
@@ -115,7 +115,7 @@ class JvmDependenciesIndex(_roots: List<JavaRoot>) {
return result
}
private data class HandleResult<T : Any>(val result: T?, val continueSearch: Boolean)
private data class HandleResult<out T : Any>(val result: T?, val continueSearch: Boolean)
private fun <T : Any> search(
request: SearchRequest,
@@ -38,7 +38,7 @@ interface CompileService : Remote {
sealed class CallResult<out R> : Serializable {
class Good<R>(val result: R) : CallResult<R>() {
class Good<out R>(val result: R) : CallResult<R>() {
override fun get(): R = result
override fun equals(other: Any?): Boolean = other is Good<*> && this.result == other.result
override fun hashCode(): Int = this.javaClass.hashCode() + (result?.hashCode() ?: 1)
@@ -55,13 +55,13 @@ val COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH: String get() =
val CLASSPATH_ID_DIGEST = "MD5"
open class PropMapper<C, V, P : KMutableProperty1<C, V>>(val dest: C,
val prop: P,
val names: List<String> = listOf(prop.name),
val fromString: (String) -> V,
val toString: ((V) -> String?) = { it.toString() },
val skipIf: ((V) -> Boolean) = { false },
val mergeDelimiter: String? = null) {
open class PropMapper<C, V, out P : KMutableProperty1<C, V>>(val dest: C,
val prop: P,
val names: List<String> = listOf(prop.name),
val fromString: (String) -> V,
val toString: ((V) -> String?) = { it.toString() },
val skipIf: ((V) -> Boolean) = { false },
val mergeDelimiter: String? = null) {
open fun toArgs(prefix: String = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX): List<String> =
when {
skipIf(prop.get(dest)) -> listOf<String>()
@@ -73,34 +73,34 @@ open class PropMapper<C, V, P : KMutableProperty1<C, V>>(val dest: C,
}
class NullablePropMapper<C, V : Any?, P : KMutableProperty1<C, V>>(dest: C,
prop: P,
names: List<String> = listOf(),
fromString: ((String) -> V),
toString: ((V) -> String?) = { it.toString() },
skipIf: ((V) -> Boolean) = { it == null },
mergeDelimiter: String? = null)
class NullablePropMapper<C, V : Any?, out P : KMutableProperty1<C, V>>(dest: C,
prop: P,
names: List<String> = listOf(),
fromString: ((String) -> V),
toString: ((V) -> String?) = { it.toString() },
skipIf: ((V) -> Boolean) = { it == null },
mergeDelimiter: String? = null)
: PropMapper<C, V, P>(dest = dest, prop = prop, names = if (names.any()) names else listOf(prop.name),
fromString = fromString, toString = toString, skipIf = skipIf, mergeDelimiter = mergeDelimiter)
class StringPropMapper<C, P : KMutableProperty1<C, String>>(dest: C,
prop: P,
names: List<String> = listOf(),
fromString: ((String) -> String) = { it },
toString: ((String) -> String?) = { it.toString() },
skipIf: ((String) -> Boolean) = { it.isEmpty() },
mergeDelimiter: String? = null)
class StringPropMapper<C, out P : KMutableProperty1<C, String>>(dest: C,
prop: P,
names: List<String> = listOf(),
fromString: ((String) -> String) = { it },
toString: ((String) -> String?) = { it.toString() },
skipIf: ((String) -> Boolean) = { it.isEmpty() },
mergeDelimiter: String? = null)
: PropMapper<C, String, P>(dest = dest, prop = prop, names = if (names.any()) names else listOf(prop.name),
fromString = fromString, toString = toString, skipIf = skipIf, mergeDelimiter = mergeDelimiter)
class BoolPropMapper<C, P : KMutableProperty1<C, Boolean>>(dest: C, prop: P, names: List<String> = listOf())
class BoolPropMapper<C, out P : KMutableProperty1<C, Boolean>>(dest: C, prop: P, names: List<String> = listOf())
: PropMapper<C, Boolean, P>(dest = dest, prop = prop, names = if (names.any()) names else listOf(prop.name),
fromString = { true }, toString = { null }, skipIf = { !prop.get(dest) })
class RestPropMapper<C, P : KMutableProperty1<C, MutableCollection<String>>>(dest: C, prop: P)
class RestPropMapper<C, out P : KMutableProperty1<C, MutableCollection<String>>>(dest: C, prop: P)
: PropMapper<C, MutableCollection<String>, P>(dest = dest, prop = prop, toString = { null }, fromString = { arrayListOf() }) {
override fun toArgs(prefix: String): List<String> = prop.get(dest).map { prefix + it }
override fun apply(s: String) = add(s)
@@ -170,7 +170,7 @@ private fun <I : ControlFlowInfo<*>> updateEdgeDataForInstruction(
}
}
data class Edges<T>(val incoming: T, val outgoing: T)
data class Edges<out T>(val incoming: T, val outgoing: T)
enum class TraverseInstructionResult {
CONTINUE,
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.*
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.*
abstract class InstructionVisitorWithResult<R>() {
abstract class InstructionVisitorWithResult<out R>() {
abstract fun visitInstruction(instruction: Instruction): R
open fun visitAccessInstruction(instruction: AccessValueInstruction): R {
@@ -25,7 +25,7 @@ import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
open class PositioningStrategy<E : PsiElement> {
open class PositioningStrategy<in E : PsiElement> {
open fun markDiagnostic(diagnostic: ParametrizedDiagnostic<out E>): List<TextRange> {
return mark(diagnostic.psiElement)
}
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.diagnostics.*
sealed class RenderingContext {
abstract operator fun <T> get(key: Key<T>): T
abstract class Key<T>(val name: String) {
abstract class Key<out T>(val name: String) {
abstract fun compute(objectsToRender: Collection<Any?>): T
}
@@ -88,7 +88,7 @@ class DelegationResolver<T : CallableMemberDescriptor> private constructor(
}
}
interface MemberExtractor<T : CallableMemberDescriptor> {
interface MemberExtractor<out T : CallableMemberDescriptor> {
fun getMembersByType(type: KotlinType): Collection<T>
}
@@ -136,7 +136,7 @@ object NonExpansiveInheritanceRestrictionChecker {
}
}
private data class ExpansiveEdge<T>(val from: T, val to: T)
private data class ExpansiveEdge<out T>(val from: T, val to: T)
private interface Graph<T> {
fun getNeighbors(node: T): Collection<T>
@@ -896,8 +896,8 @@ internal fun <A> unaryOperation(
checker: Function1<Long, Long>
) = UnaryOperationKey(a, functionName) to Pair(operation, checker) as Pair<Function1<Any?, Any>, Function1<Long, Long>>
internal data class BinaryOperationKey<A, B>(val f: CompileTimeType<out A>, val s: CompileTimeType<out B>, val functionName: String)
internal data class UnaryOperationKey<A>(val f: CompileTimeType<out A>, val functionName: String)
internal data class BinaryOperationKey<out A, out B>(val f: CompileTimeType<out A>, val s: CompileTimeType<out B>, val functionName: String)
internal data class UnaryOperationKey<out A>(val f: CompileTimeType<out A>, val functionName: String)
fun ConstantValue<*>.isStandaloneOnlyConstant(): Boolean {
return this is KClassValue || this is EnumValue || this is AnnotationValue || this is ArrayValue
@@ -19,7 +19,9 @@ package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.types.TypeSubstitutor
abstract class ImportedFromObjectCallableDescriptor<TCallable : CallableDescriptor>(val callableFromObject: TCallable) : CallableDescriptor {
abstract class ImportedFromObjectCallableDescriptor<out TCallable : CallableDescriptor>(
val callableFromObject: TCallable
) : CallableDescriptor {
val containingObject = callableFromObject.containingDeclaration as ClassDescriptor
}
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.*
abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : DeclarationProvider>
abstract class AbstractLazyMemberScope<out D : DeclarationDescriptor, out DP : DeclarationProvider>
protected constructor(
protected val c: LazyClassContext,
protected val declarationProvider: DP,
@@ -86,7 +86,7 @@ open class LazyClassMemberScope(
return result
}
private interface MemberExtractor<T : CallableMemberDescriptor> {
private interface MemberExtractor<out T : CallableMemberDescriptor> {
fun extract(extractFrom: KotlinType, name: Name): Collection<T>
}
@@ -21,7 +21,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.extensions.ExtensionPointName
import java.lang.ref.WeakReference
open class MappedExtensionProvider<T, R>
open class MappedExtensionProvider<T, out R>
protected constructor(
private val epName: ExtensionPointName<T>,
private val map: (List<T>) -> R
@@ -21,10 +21,10 @@ import com.intellij.psi.PsiNamedElement
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtElement
interface KtLightElement<T : KtElement, D : PsiElement> : PsiNamedElement {
interface KtLightElement<out T : KtElement, out D : PsiElement> : PsiNamedElement {
val kotlinOrigin: T?
val clsDelegate: D
}
interface KtLightDeclaration<T: KtDeclaration, D: PsiElement>: KtLightElement<T, D>
interface KtLightDeclaration<out T: KtDeclaration, out D: PsiElement>: KtLightElement<T, D>
@@ -27,14 +27,14 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.utils.addToStdlib.check
class KnownResultProcessor<C>(
class KnownResultProcessor<out C>(
val result: Collection<C>
): ScopeTowerProcessor<C> {
override fun process(data: TowerData)
= if (data == TowerData.Empty) listOfNotNull(result.check { it.isNotEmpty() }) else emptyList()
}
class CompositeScopeTowerProcessor<C>(
class CompositeScopeTowerProcessor<out C>(
vararg val processors: ScopeTowerProcessor<C>
) : ScopeTowerProcessor<C> {
override fun process(data: TowerData): List<Collection<C>> = processors.flatMap { it.process(data) }
@@ -38,7 +38,7 @@ interface Candidate<out D : CallableDescriptor> {
val status: ResolutionCandidateStatus
}
interface TowerContext<D : CallableDescriptor, C: Candidate<D>> {
interface TowerContext<D : CallableDescriptor, out C: Candidate<D>> {
val name: Name
val scopeTower: ScopeTower
@@ -31,7 +31,7 @@ val CandidateWithBoundDispatchReceiver<*>.requiresExtensionReceiver: Boolean
fun DataFlowDecorator.getAllPossibleTypes(receiver: ReceiverValue) = getSmartCastTypes(receiver) + receiver.type
internal class CandidateWithBoundDispatchReceiverImpl<D : CallableDescriptor>(
internal class CandidateWithBoundDispatchReceiverImpl<out D : CallableDescriptor>(
override val dispatchReceiver: ReceiverValue?,
override val descriptor: D,
override val diagnostics: List<ResolutionDiagnostic>
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.utils
import kotlin.reflect.KProperty
class CachedValueProperty<TValue : Any, TTimestamp : Any>(
class CachedValueProperty<out TValue : Any, TTimestamp : Any>(
private val calculator: () -> TValue,
private val timestampCalculator: () -> TTimestamp
) {
@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.utils.concurrent.block
class LockedClearableLazyValue<T: Any>(val lock: Any, val init: () -> T) {
class LockedClearableLazyValue<out T: Any>(val lock: Any, val init: () -> T) {
@Volatile private var value: T? = null
fun get(): T {