Cryptic-looking functions (iif, eq, neq etc) removed
This commit is contained in:
-1
@@ -28,7 +28,6 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.util.iif
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaEnumClassObjectDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.Modality
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl
|
||||
|
||||
-1
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContextWithTypes
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaArrayType
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage
|
||||
import org.jetbrains.kotlin.util.iif
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaConstructorResolver
|
||||
|
||||
+2
-4
@@ -5,7 +5,6 @@ import org.jetbrains.jet.storage.NotNullLazyValue
|
||||
import org.jetbrains.jet.lang.resolve.name.LabelName
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.utils.emptyList
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContextWithTypes
|
||||
@@ -21,7 +20,6 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.hasNotNullAnnotation
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.types.LazyJavaTypeAttributes
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.hasMutableAnnotation
|
||||
import org.jetbrains.kotlin.util.iif
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.hasReadOnlyAnnotation
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaValueParameter
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaFunctionResolver
|
||||
@@ -172,7 +170,7 @@ public abstract class LazyJavaMemberScope(
|
||||
val (index, javaParameter) = pair
|
||||
|
||||
val typeUsage = LazyJavaTypeAttributes(c, javaParameter, TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT) {
|
||||
c.hasMutableAnnotation(javaParameter).iif(TypeUsage.MEMBER_SIGNATURE_COVARIANT, TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT)
|
||||
if (c.hasMutableAnnotation(javaParameter)) TypeUsage.MEMBER_SIGNATURE_COVARIANT else TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT
|
||||
}
|
||||
|
||||
val (outType, varargElementType) =
|
||||
@@ -269,7 +267,7 @@ public abstract class LazyJavaMemberScope(
|
||||
protected open fun getAllPropertyNames(): Collection<Name> = memberIndex().getAllFieldNames()
|
||||
|
||||
override fun getLocalVariable(name: Name): VariableDescriptor? = null
|
||||
override fun getDeclarationsByLabel(labelName: LabelName) = emptyList<DeclarationDescriptor>()
|
||||
override fun getDeclarationsByLabel(labelName: LabelName) = listOf<DeclarationDescriptor>()
|
||||
|
||||
override fun getClassifiers(name: Name) = emptyOrSingletonList(getClassifier(name))
|
||||
|
||||
|
||||
+4
-6
@@ -25,8 +25,6 @@ import org.jetbrains.jet.lang.resolve.java.resolver.*
|
||||
import org.jetbrains.jet.lang.types.Variance.*
|
||||
import org.jetbrains.jet.lang.types.*
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import org.jetbrains.kotlin.util.iif
|
||||
import org.jetbrains.kotlin.util.eq
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaPrimitiveType
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaArrayType
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClassifierType
|
||||
@@ -74,7 +72,7 @@ class LazyJavaTypeResolver(
|
||||
|
||||
val projectionKind = if (attr.howThisTypeIsUsed == MEMBER_SIGNATURE_CONTRAVARIANT && !isVararg) OUT_VARIANCE else INVARIANT
|
||||
|
||||
val howArgumentTypeIsUsed = isVararg.iif(MEMBER_SIGNATURE_CONTRAVARIANT, TYPE_ARGUMENT)
|
||||
val howArgumentTypeIsUsed = if (isVararg) MEMBER_SIGNATURE_CONTRAVARIANT else TYPE_ARGUMENT
|
||||
val componentType = transformJavaType(javaComponentType, howArgumentTypeIsUsed.toAttributes())
|
||||
return TypeUtils.makeNullableAsSpecified(KotlinBuiltIns.getInstance().getArrayType(projectionKind, componentType), !attr.isMarkedNotNull)
|
||||
}
|
||||
@@ -83,7 +81,7 @@ class LazyJavaTypeResolver(
|
||||
c: LazyJavaResolverContext,
|
||||
val typeParameter: TypeParameterDescriptor
|
||||
) : TypeProjectionBase() {
|
||||
override fun getProjectionKind() = typeParameter.getVariance().eq(OUT_VARIANCE).iif(INVARIANT, OUT_VARIANCE)
|
||||
override fun getProjectionKind() = if (typeParameter.getVariance() == OUT_VARIANCE) INVARIANT else OUT_VARIANCE
|
||||
override fun getType() = typeParameter.getUpperBoundsAsType()
|
||||
}
|
||||
|
||||
@@ -191,7 +189,7 @@ class LazyJavaTypeResolver(
|
||||
// Most of the time this means there is an error in the Java code
|
||||
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.getName().asString())) }
|
||||
}
|
||||
var howTheProjectionIsUsed = attr.howThisTypeIsUsed.eq(SUPERTYPE).iif(SUPERTYPE_ARGUMENT, TYPE_ARGUMENT)
|
||||
var howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
|
||||
return javaType.getTypeArguments().withIndices().map {
|
||||
javaTypeParameter ->
|
||||
val (i, t) = javaTypeParameter
|
||||
@@ -213,7 +211,7 @@ class LazyJavaTypeResolver(
|
||||
if (bound == null)
|
||||
LazyStarProjection(c, typeParameter)
|
||||
else {
|
||||
var projectionKind = javaType.isExtends().iif(OUT_VARIANCE, IN_VARIANCE)
|
||||
var projectionKind = if (javaType.isExtends()) OUT_VARIANCE else IN_VARIANCE
|
||||
if (projectionKind == typeParameter.getVariance()) {
|
||||
projectionKind = Variance.INVARIANT
|
||||
}
|
||||
|
||||
@@ -62,4 +62,6 @@ public fun <T, C: Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpty()) bo
|
||||
|
||||
public fun <T> Iterable<Iterable<T>>.flatten(): List<T> {
|
||||
return flatMapTo(ArrayList<T>(), {it})
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T: Any> emptyOrSingletonList(item: T?): List<T> = if (item == null) listOf() else listOf(item)
|
||||
@@ -16,20 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.util
|
||||
|
||||
fun Boolean.iif<T>(then: T, _else: T): T = if (this) then else _else
|
||||
|
||||
fun <T: Any, R> T?.inn(then: (T) -> R, _else: R): R = if (this != null) then(this) else _else
|
||||
|
||||
// These two functions are needed in conjunction with iif:
|
||||
// foo.eq(bar).iif(a, b)
|
||||
fun <T> T.eq(eq: T): Boolean = this == eq
|
||||
fun <T> T.neq(eq: T): Boolean = this != eq
|
||||
|
||||
fun <T: Any> T?.sure(message: String): T {
|
||||
if (this == null)
|
||||
throw AssertionError(message)
|
||||
return this
|
||||
}
|
||||
fun <T: Any> T?.sure(message: String): T = this ?: throw AssertionError(message)
|
||||
|
||||
fun <T> T.printAndReturn(message: String = ""): T {
|
||||
if (!message.isEmpty()) {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package org.jetbrains.jet.utils
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
public fun <T> emptyList(): MutableList<T> = Collections.emptyList<T>() as MutableList
|
||||
public fun <T: Any> emptyOrSingletonList(item: T?): MutableList<T> = if (item == null) emptyList() else Collections.singletonList(item) as MutableList
|
||||
|
||||
public fun <T> emptySet(): MutableSet<T> = Collections.emptySet<T>() as MutableSet
|
||||
public fun <K, V> emptyMap(): MutableMap<K, V> = Collections.emptyMap<K, V>() as MutableMap
|
||||
|
||||
Reference in New Issue
Block a user