Cleanup: fix some compiler warnings (mostly deprecations, javaClass)
This commit is contained in:
+2
-3
@@ -51,7 +51,6 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.util.supertypesWithAny
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.util.*
|
||||
|
||||
@@ -347,8 +346,8 @@ class BasicCompletionSession(
|
||||
if (userType != typeRef.typeElement) return null
|
||||
val parent = typeRef.parent
|
||||
return when (parent) {
|
||||
is KtNamedFunction -> parent.check { typeRef == it.receiverTypeReference }
|
||||
is KtProperty -> parent.check { typeRef == it.receiverTypeReference }
|
||||
is KtNamedFunction -> parent.takeIf { typeRef == it.receiverTypeReference }
|
||||
is KtProperty -> parent.takeIf { typeRef == it.receiverTypeReference }
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import java.util.*
|
||||
|
||||
tailrec fun <T : Any> LookupElement.putUserDataDeep(key: Key<T>, value: T?) {
|
||||
@@ -413,7 +412,7 @@ fun ImportableFqNameClassifier.isImportableDescriptorImported(descriptor: Declar
|
||||
|
||||
fun OffsetMap.tryGetOffset(key: OffsetKey): Int? {
|
||||
try {
|
||||
return getOffset(key).check { it != -1 } // prior to IDEA 2016.3 getOffset() returned -1 if not found, now it throws exception
|
||||
return getOffset(key).takeIf { it != -1 } // prior to IDEA 2016.3 getOffset() returned -1 if not found, now it throws exception
|
||||
}
|
||||
catch(e: Exception) {
|
||||
return null
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ abstract class DeclarationLookupObjectImpl(
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (other == null || javaClass != other.javaClass) return false
|
||||
if (other == null || this::class.java != other::class.java) return false
|
||||
val lookupObject = other as DeclarationLookupObjectImpl
|
||||
if (descriptor != null)
|
||||
return descriptorsEqualWithSubstitution(descriptor, lookupObject.descriptor)
|
||||
|
||||
+5
-6
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
class StaticMembersCompletion(
|
||||
@@ -52,11 +51,11 @@ class StaticMembersCompletion(
|
||||
return object : AbstractLookupElementFactory {
|
||||
override fun createStandardLookupElementsForDescriptor(descriptor: DeclarationDescriptor, useReceiverTypes: Boolean): Collection<LookupElement> {
|
||||
if (!useReceiverTypes) return emptyList()
|
||||
return lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false)
|
||||
.decorateAsStaticMember(descriptor, classNameAsLookupString = false)
|
||||
?.assignPriority(itemPriority)
|
||||
?.suppressAutoInsertion()
|
||||
.singletonOrEmptyList()
|
||||
return listOfNotNull(lookupElementFactory.createLookupElement(descriptor, useReceiverTypes = false)
|
||||
.decorateAsStaticMember(descriptor, classNameAsLookupString = false)
|
||||
?.assignPriority(itemPriority)
|
||||
?.suppressAutoInsertion()
|
||||
)
|
||||
}
|
||||
|
||||
override fun createLookupElement(descriptor: DeclarationDescriptor, useReceiverTypes: Boolean,
|
||||
|
||||
+2
-2
@@ -75,12 +75,12 @@ class ToFromOriginalFileMapper private constructor(
|
||||
fun <TElement : PsiElement> toOriginalFile(element: TElement): TElement? {
|
||||
if (element.containingFile != syntheticFile) return element
|
||||
val offset = toOriginalFile(element.startOffset) ?: return null
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(originalFile, offset, element.javaClass, true)
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(originalFile, offset, element::class.java, true)
|
||||
}
|
||||
|
||||
fun <TElement : PsiElement> toSyntheticFile(element: TElement): TElement? {
|
||||
if (element.containingFile != originalFile) return element
|
||||
val offset = toSyntheticFile(element.startOffset) ?: return null
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(syntheticFile, offset, element.javaClass, true)
|
||||
return PsiTreeUtil.findElementOfClassAtOffset(syntheticFile, offset, element::class.java, true)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ fun createKeywordConstructLookupElement(
|
||||
return LookupElementBuilder.create(KeywordLookupObject(), keyword)
|
||||
.bold()
|
||||
.withTailText(tailText)
|
||||
.withInsertHandler { insertionContext, lookupElement ->
|
||||
.withInsertHandler { insertionContext, _ ->
|
||||
if (insertionContext.completionChar == Lookup.NORMAL_SELECT_CHAR || insertionContext.completionChar == Lookup.REPLACE_SELECT_CHAR) {
|
||||
val offset = insertionContext.tailOffset
|
||||
val newIndent = detectIndent(insertionContext.document.charsSequence, offset - keyword.length)
|
||||
|
||||
@@ -58,7 +58,7 @@ object LambdaItems {
|
||||
for (functionType in distinctTypes) {
|
||||
val lookupString = lambdaPresentation(functionType)
|
||||
val lookupElement = LookupElementBuilder.create(lookupString)
|
||||
.withInsertHandler({ context, lookupElement ->
|
||||
.withInsertHandler({ context, _ ->
|
||||
val offset = context.startOffset
|
||||
val placeholder = "{}"
|
||||
context.document.replaceString(offset, context.tailOffset, placeholder)
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ class MultipleArgumentsItemProvider(
|
||||
|
||||
return LookupElementBuilder
|
||||
.create(variables.map { it.name.render() }.joinToString(", ")) //TODO: use code formatting settings
|
||||
.withInsertHandler { context, lookupElement ->
|
||||
.withInsertHandler { context, _ ->
|
||||
if (context.completionChar == Lookup.REPLACE_SELECT_CHAR) {
|
||||
val offset = context.offsetMap.tryGetOffset(SmartCompletion.MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET)
|
||||
if (offset != null) {
|
||||
|
||||
+3
-5
@@ -45,8 +45,6 @@ import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.isBooleanOrNullableBoolean
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptySet
|
||||
import java.util.*
|
||||
|
||||
@@ -94,7 +92,7 @@ class SmartCompletion(
|
||||
val descriptorFilter: ((DeclarationDescriptor, AbstractLookupElementFactory) -> Collection<LookupElement>)? =
|
||||
{ descriptor: DeclarationDescriptor, factory: AbstractLookupElementFactory ->
|
||||
filterDescriptor(descriptor, factory).map { postProcess(it) }
|
||||
}.check { expectedInfos.isNotEmpty() }
|
||||
}.takeIf { expectedInfos.isNotEmpty() }
|
||||
|
||||
fun additionalItems(lookupElementFactory: LookupElementFactory): Pair<Collection<LookupElement>, InheritanceItemsSearcher?> {
|
||||
val (items, inheritanceSearcher) = additionalItemsNoPostProcess(lookupElementFactory)
|
||||
@@ -287,7 +285,7 @@ class SmartCompletion(
|
||||
val types = smartCastCalculator.types(item.receiverParameter).map { it.toFuzzyType(emptyList()) }
|
||||
val matcher = { expectedInfo: ExpectedInfo -> types.matchExpectedInfo(expectedInfo) }
|
||||
addLookupElements(null, expectedInfos, matcher) {
|
||||
item.createLookupElement().assignSmartCompletionPriority(SmartCompletionItemPriority.THIS).singletonList()
|
||||
listOf(item.createLookupElement().assignSmartCompletionPriority(SmartCompletionItemPriority.THIS))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +326,7 @@ class SmartCompletion(
|
||||
private fun createNamedArgumentWithValueLookupElement(name: Name, value: String, priority: SmartCompletionItemPriority): LookupElement {
|
||||
val lookupElement = LookupElementBuilder.create("${name.asString()} = $value")
|
||||
.withIcon(KotlinIcons.PARAMETER)
|
||||
.withInsertHandler({ context, item -> context.document.replaceString(context.startOffset, context.tailOffset, "${name.render()} = $value") })
|
||||
.withInsertHandler({ context, _ -> context.document.replaceString(context.startOffset, context.tailOffset, "${name.render()} = $value") })
|
||||
lookupElement.putUserData(SmartCompletionInBasicWeigher.NAMED_ARGUMENT_KEY, Unit)
|
||||
lookupElement.assignSmartCompletionPriority(priority)
|
||||
return lookupElement
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ class TypeInstantiationItems(
|
||||
itemText = "object: $itemText{...}"
|
||||
lookupString = "object"
|
||||
allLookupStrings = setOf(lookupString, lookupElement.lookupString)
|
||||
insertHandler = InsertHandler<LookupElement> { context, item ->
|
||||
insertHandler = InsertHandler<LookupElement> { context, _ ->
|
||||
val startOffset = context.startOffset
|
||||
|
||||
val text1 = "object: $typeText"
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNullableNothing
|
||||
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.*
|
||||
|
||||
class ArtificialElementInsertHandler(
|
||||
@@ -299,7 +298,7 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
|
||||
): Collection<FuzzyType> {
|
||||
if (callTypeAndReceiver is CallTypeAndReceiver.CALLABLE_REFERENCE) {
|
||||
val lhs = callTypeAndReceiver.receiver?.let { bindingContext[BindingContext.DOUBLE_COLON_LHS, it] }
|
||||
return (this as? CallableDescriptor)?.callableReferenceType(resolutionFacade, lhs).singletonOrEmptyList()
|
||||
return listOfNotNull((this as? CallableDescriptor)?.callableReferenceType(resolutionFacade, lhs))
|
||||
}
|
||||
|
||||
if (this is CallableDescriptor) {
|
||||
|
||||
+2
-2
@@ -65,10 +65,10 @@ abstract class AbstractCompletionHandlerTest(private val defaultCompletionType:
|
||||
val settingName = line.substring(0, index).trim()
|
||||
val settingValue = line.substring(index + 1).trim()
|
||||
val (field, settings) = try {
|
||||
kotlinStyleSettings.javaClass.getDeclaredField(settingName) to kotlinStyleSettings
|
||||
kotlinStyleSettings::class.java.getDeclaredField(settingName) to kotlinStyleSettings
|
||||
}
|
||||
catch (e: NoSuchFieldException) {
|
||||
commonStyleSettings.javaClass.getDeclaredField(settingName) to commonStyleSettings
|
||||
commonStyleSettings::class.java.getDeclaredField(settingName) to commonStyleSettings
|
||||
}
|
||||
when (field.type.name) {
|
||||
"boolean" -> field.setBoolean(settings, settingValue.toBoolean())
|
||||
|
||||
Reference in New Issue
Block a user