Fix minor compile warnings

This commit is contained in:
Dmitry Gridin
2019-04-17 17:48:26 +07:00
parent 79793a4bda
commit 37c856290f
226 changed files with 618 additions and 479 deletions
@@ -18,7 +18,8 @@ package org.jetbrains.kotlin.android.parcel
import kotlinx.android.parcel.Parceler
import kotlinx.android.parcel.Parcelize
import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.*
import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.DESCRIBE_CONTENTS
import org.jetbrains.kotlin.android.parcel.ParcelableSyntheticComponent.ComponentKind.WRITE_TO_PARCEL
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
@@ -82,33 +83,35 @@ open class ParcelableResolveExtension : SyntheticResolveExtension {
override fun getSyntheticCompanionObjectNameIfNeeded(thisDescriptor: ClassDescriptor) = null
override fun generateSyntheticMethods(
clazz: ClassDescriptor,
thisDescriptor: ClassDescriptor,
name: Name,
bindingContext: BindingContext,
fromSupertypes: List<SimpleFunctionDescriptor>,
result: MutableCollection<SimpleFunctionDescriptor>
) {
fun isExperimental(): Boolean {
val sourceElement = (clazz.source as? PsiSourceElement)?.psi as? KtElement ?: return false
val sourceElement = (thisDescriptor.source as? PsiSourceElement)?.psi as? KtElement ?: return false
return isExperimental(sourceElement)
}
if (name.asString() == DESCRIBE_CONTENTS.methodName
&& clazz.isParcelize
&& isExperimental()
&& result.none { it.isDescribeContents() }
&& fromSupertypes.none { it.isDescribeContents() }
&& thisDescriptor.isParcelize
&& isExperimental()
&& result.none { it.isDescribeContents() }
&& fromSupertypes.none { it.isDescribeContents() }
) {
result += createMethod(clazz, DESCRIBE_CONTENTS, Modality.OPEN, clazz.builtIns.intType)
result += createMethod(thisDescriptor, DESCRIBE_CONTENTS, Modality.OPEN, thisDescriptor.builtIns.intType)
} else if (name.asString() == WRITE_TO_PARCEL.methodName
&& clazz.isParcelize
&& isExperimental()
&& result.none { it.isWriteToParcel() }
&& thisDescriptor.isParcelize
&& isExperimental()
&& result.none { it.isWriteToParcel() }
) {
val builtIns = clazz.builtIns
val parcelClassType = resolveParcelClassType(clazz.module) ?: ErrorUtils.createErrorType("Unresolved 'Parcel' type")
result += createMethod(clazz, WRITE_TO_PARCEL, Modality.OPEN,
builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType)
val builtIns = thisDescriptor.builtIns
val parcelClassType = resolveParcelClassType(thisDescriptor.module) ?: ErrorUtils.createErrorType("Unresolved 'Parcel' type")
result += createMethod(
thisDescriptor, WRITE_TO_PARCEL, Modality.OPEN,
builtIns.unitType, "parcel" to parcelClassType, "flags" to builtIns.intType
)
}
}
@@ -816,12 +816,12 @@ private fun writeValueNullAware(v: InstructionAdapter, block: () -> Unit) {
v.goTo(labelReturn)
labelNull@ v.visitLabel(labelNull)
v.visitLabel(labelNull)
v.pop()
v.aconst(0)
v.invokevirtual(PARCEL_TYPE.internalName, "writeInt", "(I)V", false)
labelReturn@ v.visitLabel(labelReturn)
v.visitLabel(labelReturn)
}
internal class Method<out T : String?>(val name: String, val signature: T) {
@@ -37,6 +37,7 @@ class AndroidExtensionsReferenceSearchExecutor : QueryExecutorBase<PsiReference,
override fun processQuery(queryParameters: ReferencesSearch.SearchParameters, consumer: Processor<in PsiReference>) {
val elementToSearch = queryParameters.elementToSearch as? XmlAttributeValue ?: return
val scopeElements = (queryParameters.effectiveSearchScope as? LocalSearchScope)?.scope ?: return
@Suppress("UNNECESSARY_SAFE_CALL", "USELESS_ELVIS") // BUNCH: 182
val referenceName = elementToSearch.value?.substringAfterLast("/") ?: return
scopeElements.filterIsInstance<KtElement>().forEach {
@@ -33,7 +33,7 @@ class AndroidSimpleNameReferenceExtension : SimpleNameReferenceExtension {
element is XmlFile && reference.isReferenceToXmlFile(element)
private fun isLayoutPackageIdentifier(reference: KtSimpleNameReference): Boolean {
val probablyVariant = reference.element?.parent as? KtDotQualifiedExpression ?: return false
val probablyVariant = reference.element.parent as? KtDotQualifiedExpression ?: return false
val probablyKAS = probablyVariant.receiverExpression as? KtDotQualifiedExpression ?: return false
return probablyKAS.receiverExpression.text == AndroidConst.SYNTHETIC_PACKAGE
}
@@ -51,6 +51,7 @@ class AndroidSimpleNameReferenceExtension : SimpleNameReferenceExtension {
return null
}
@Suppress("UNNECESSARY_SAFE_CALL", "USELESS_ELVIS") // BUNCH: 182
private fun isIdDeclaration(declaration: XmlAttributeValue) = declaration.value?.startsWith("@+id/") ?: false
private fun KtSimpleNameReference.isReferenceToXmlFile(xmlFile: XmlFile): Boolean {
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.android
abstract class AbstractAndroidFindUsagesTest : KotlinAndroidTestCase() {
@Suppress("UNREACHABLE_CODE")
fun doTest(path: String) {
return // TODO: investigate and fix this test
copyResourceDirectoryForTest(path)
@@ -108,7 +108,7 @@ class JvmAbiAnalysisHandlerExtension(
val visitor = InnerClassesCollectingVisitor()
output.accept(visitor)
val outputInternalName = visitor.ownInternalName!!
val outputInternalName = visitor.ownInternalName
internalNameToFile[outputInternalName] = output.file
innerClasses[outputInternalName] = visitor.innerClasses
}
@@ -112,7 +112,7 @@ private class TypeTreeVisitor(val elementUtils: Elements, val trees: Trees, val
val newVisibility = if (node.sym.getKind() == ElementKind.FIELD) {
val flags = node.modifiers.getFlags()
node.sym.constValue?.let { constValue ->
node.sym.constValue?.let { _ ->
constantTreeVisitor.scan(trees.getPath(compilationUnit, node.init), null)
}
if (flags.contains(Modifier.PRIVATE)) Visibility.NON_ABI else Visibility.ABI
@@ -475,7 +475,7 @@ interface IrBuilderExtension {
compilerContext.externalSymbols.referenceClass(module.getClassFromInternalSerializationPackage(SpecialBuiltins.nullableSerializer))
if (serializerClassOriginal == null) {
if (genericIndex == null) return null
val thiz = enclosingGenerator.irClass.thisReceiver!!
val prop = enclosingGenerator.localSerializersFieldsDescriptors[genericIndex]
return irGetField(irGet(dispatchReceiverParameter), compilerContext.localSymbolTable.referenceField(prop).owner)
}
@@ -176,7 +176,6 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
serializerTower(this@SerializerIrGenerator, irFun.dispatchReceiverParameter!!, it)) { "Property ${it.name} must have a serializer" }
}
val kSer = serializableDescriptor.module.getClassFromSerializationPackage(KSERIALIZER_NAME.identifier)
val kSerType = ((irFun.returnType as IrSimpleType).arguments.first() as IrTypeProjection).type
val array = createArrayOfExpression(kSerType, allSerializers)
+irReturn(array)
@@ -350,14 +350,12 @@ object KSerializerDescriptorResolver {
)
val serializerClass = classDescriptor.getClassFromSerializationPackage(SerialEntityNames.KSERIALIZER_CLASS)
assert(serializableDescriptor.declaredTypeParameters.size == typeParameters.size)
val args = serializableDescriptor.declaredTypeParameters.mapIndexed { index, param ->
val pType =
KotlinTypeFactory.simpleNotNullType(
Annotations.EMPTY,
serializerClass,
listOf(TypeProjectionImpl(typeParameters[index].defaultType))
)
val args = List(serializableDescriptor.declaredTypeParameters.size) { index ->
val pType = KotlinTypeFactory.simpleNotNullType(
Annotations.EMPTY,
serializerClass,
listOf(TypeProjectionImpl(typeParameters[index].defaultType))
)
ValueParameterDescriptorImpl(
constrDesc, null, index, Annotations.EMPTY, Name.identifier("$typeArgPrefix$index"), pType,
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.psi.KtScript
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.script.experimental.dependencies.DependenciesResolver
import kotlin.script.experimental.location.ScriptExpectedLocation
import kotlin.script.templates.standard.ScriptTemplateWithArgs
open class KotlinScriptDefinition(open val template: KClass<out Any>) : UserDataHolderBase() {
@@ -48,8 +47,12 @@ open class KotlinScriptDefinition(open val template: KClass<out Any>) : UserData
@Deprecated("temporary workaround for missing functionality, will be replaced by the new API soon")
open val additionalCompilerArguments: Iterable<String>? = null
open val scriptExpectedLocations: List<ScriptExpectedLocation> =
listOf(ScriptExpectedLocation.SourcesOnly, ScriptExpectedLocation.TestsOnly)
@Suppress("DEPRECATION")
open val scriptExpectedLocations: List<kotlin.script.experimental.location.ScriptExpectedLocation> =
listOf(
kotlin.script.experimental.location.ScriptExpectedLocation.SourcesOnly,
kotlin.script.experimental.location.ScriptExpectedLocation.TestsOnly
)
open val implicitReceivers: List<KType> get() = emptyList()
@@ -57,7 +57,10 @@ abstract class KotlinScriptDefinitionAdapterFromNewAPIBase : KotlinScriptDefinit
override val acceptedAnnotations: List<KClass<out Annotation>> by lazy(LazyThreadSafetyMode.PUBLICATION) {
scriptCompilationConfiguration[ScriptCompilationConfiguration.refineConfigurationOnAnnotations]?.annotations
.orEmpty()
.map { getScriptingClass(it) as KClass<out Annotation> }
.map {
@Suppress("UNCHECKED_CAST")
getScriptingClass(it) as KClass<out Annotation>
}
}
override val implicitReceivers: List<KType> by lazy(LazyThreadSafetyMode.PUBLICATION) {
@@ -75,9 +78,10 @@ abstract class KotlinScriptDefinitionAdapterFromNewAPIBase : KotlinScriptDefinit
get() = scriptCompilationConfiguration[ScriptCompilationConfiguration.compilerOptions]
.orEmpty()
@Suppress("DEPRECATION")
override val scriptExpectedLocations: List<ScriptExpectedLocation>
get() = scriptCompilationConfiguration[ScriptCompilationConfiguration.ide.acceptedLocations]?.map {
when(it) {
when (it) {
ScriptAcceptedLocation.Sources -> ScriptExpectedLocation.SourcesOnly
ScriptAcceptedLocation.Tests -> ScriptExpectedLocation.TestsOnly
ScriptAcceptedLocation.Libraries -> ScriptExpectedLocation.Libraries
@@ -37,6 +37,7 @@ class ScriptContentLoader(private val project: Project) {
scriptDefinition.acceptedAnnotations.find { ann ->
psiAnn.typeName.let { it == ann.simpleName || it == ann.qualifiedName }
}?.let {
@Suppress("UNCHECKED_CAST")
constructAnnotation(
psiAnn,
classLoader.loadClass(it.qualifiedName).kotlin as KClass<out Annotation>,
@@ -202,7 +202,10 @@ internal object KotlinConverter {
expectedTypes: Array<out Class<out UElement>>
): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? {
return { ctor(element as P, givenParent) }
return {
@Suppress("UNCHECKED_CAST")
ctor(element as P, givenParent)
}
}
return with (expectedTypes) { when (element) {
@@ -306,7 +309,10 @@ internal object KotlinConverter {
requiredType: Array<out Class<out UElement>>
): UExpression? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UExpression): () -> UExpression? {
return { ctor(expression as P, givenParent) }
return {
@Suppress("UNCHECKED_CAST")
ctor(expression as P, givenParent)
}
}
return with (requiredType) { when (expression) {
@@ -448,13 +454,20 @@ internal object KotlinConverter {
givenParent: UElement?,
expectedTypes: Array<out Class<out UElement>>
): UElement? {
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? = { ctor(element as P, givenParent) }
fun <P : PsiElement> build(ctor: (P, UElement?) -> UElement): () -> UElement? = {
@Suppress("UNCHECKED_CAST")
ctor(element as P, givenParent)
}
fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? =
{ ctor(element as P, ktElement, givenParent) }
fun <P : PsiElement, K : KtElement> buildKt(ktElement: K, ctor: (P, K, UElement?) -> UElement): () -> UElement? = {
@Suppress("UNCHECKED_CAST")
ctor(element as P, ktElement, givenParent)
}
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? =
{ ctor(element as P, ktElement, givenParent) }
fun <P : PsiElement, K : KtElement> buildKtOpt(ktElement: K?, ctor: (P, K?, UElement?) -> UElement): () -> UElement? = {
@Suppress("UNCHECKED_CAST")
ctor(element as P, ktElement, givenParent)
}
val original = element.originalElement
return with(expectedTypes) {
@@ -631,6 +644,7 @@ internal object KotlinConverter {
val file = createAnalyzableFile("dummy.kt", text, context)
val declarations = file.declarations
assert(declarations.size == 1) { "${declarations.size} declarations in $text" }
@Suppress("UNCHECKED_CAST")
return declarations.first() as TDeclaration
}
}
@@ -102,17 +102,15 @@ open class KotlinUSimpleReferenceExpression(
null
}
if (resolvedCall != null) {
if (access.isRead) {
val getDescriptor = resultingDescriptor.getMethod
KotlinAccessorCallExpression(psi, this, resolvedCall, getDescriptor, null).accept(visitor)
}
if (access.isRead) {
val getDescriptor = resultingDescriptor.getMethod
KotlinAccessorCallExpression(psi, this, resolvedCall, getDescriptor, null).accept(visitor)
}
if (access.isWrite && setterValue != null) {
val setDescriptor = resultingDescriptor.setMethod
if (setDescriptor != null) {
KotlinAccessorCallExpression(psi, this, resolvedCall, setDescriptor, setterValue).accept(visitor)
}
if (access.isWrite && setterValue != null) {
val setDescriptor = resultingDescriptor.setMethod
if (setDescriptor != null) {
KotlinAccessorCallExpression(psi, this, resolvedCall, setDescriptor, setterValue).accept(visitor)
}
}
}
@@ -1,6 +1,7 @@
package org.jetbrains.uast.kotlin.expressions
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiExpression
import com.intellij.psi.PsiType
import com.intellij.psi.PsiVariable
import org.jetbrains.kotlin.psi.KtFunction
@@ -11,9 +12,9 @@ import org.jetbrains.uast.kotlin.psi.UastKotlinPsiVariable
internal class KotlinLocalFunctionUVariable(
val function: KtFunction,
override val psi: PsiVariable,
givenParent: UElement?
val function: KtFunction,
override val psi: PsiVariable,
givenParent: UElement?
) : KotlinAbstractUElement(givenParent), UVariableExPlaceHolder, PsiVariable by psi {
override val javaPsi = psi
@@ -25,6 +26,13 @@ internal class KotlinLocalFunctionUVariable(
override val typeReference: UTypeReferenceExpression? = null
override val uastAnchor: UElement? = null
override val annotations: List<UAnnotation> = emptyList()
override fun getOriginalElement(): PsiElement {
return psi.originalElement
}
override fun getInitializer(): PsiExpression? {
return psi.initializer
}
}