Fix "Should be replaced with Kotlin function" warnings
This commit is contained in:
+3
-2
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import kotlin.math.max
|
||||
|
||||
var KtFile.doNotComplete: Boolean? by UserDataProperty(Key.create("DO_NOT_COMPLETE"))
|
||||
|
||||
@@ -71,7 +72,7 @@ class KotlinCompletionContributor : CompletionContributor() {
|
||||
context.replacementOffset = context.replacementOffset
|
||||
|
||||
val offset = context.startOffset
|
||||
val tokenBefore = psiFile.findElementAt(Math.max(0, offset - 1))
|
||||
val tokenBefore = psiFile.findElementAt(max(0, offset - 1))
|
||||
|
||||
if (offset > 0 && tokenBefore!!.node.elementType == KtTokens.REGULAR_STRING_PART && tokenBefore.text.startsWith(".")) {
|
||||
val prev = tokenBefore.parent.prevSibling
|
||||
@@ -104,7 +105,7 @@ class KotlinCompletionContributor : CompletionContributor() {
|
||||
?: DEFAULT_DUMMY_IDENTIFIER
|
||||
}
|
||||
|
||||
val tokenAt = psiFile.findElementAt(Math.max(0, offset))
|
||||
val tokenAt = psiFile.findElementAt(max(0, offset))
|
||||
if (tokenAt != null) {
|
||||
if (context.completionType == CompletionType.SMART && !isAtEndOfLine(offset, context.editor.document) /* do not use parent expression if we are at the end of line - it's probably parsed incorrectly */) {
|
||||
var parent = tokenAt.parent
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertH
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
|
||||
class LookupElementsCollector(
|
||||
private val onFlush: () -> Unit,
|
||||
@@ -157,7 +158,7 @@ class LookupElementsCollector(
|
||||
}
|
||||
|
||||
val matchingDegree = RealPrefixMatchingWeigher.getBestMatchingDegree(result, prefixMatcher)
|
||||
bestMatchingDegree = Math.max(bestMatchingDegree, matchingDegree)
|
||||
bestMatchingDegree = max(bestMatchingDegree, matchingDegree)
|
||||
}
|
||||
|
||||
// used to avoid insertion of spaces before/after ',', '=' on just typing
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import kotlin.math.min
|
||||
|
||||
class ToFromOriginalFileMapper private constructor(
|
||||
val originalFile: KtFile,
|
||||
@@ -49,7 +50,7 @@ class ToFromOriginalFileMapper private constructor(
|
||||
|
||||
syntheticLength = syntheticText.length
|
||||
originalLength = originalText.length
|
||||
val minLength = Math.min(originalLength, syntheticLength)
|
||||
val minLength = min(originalLength, syntheticLength)
|
||||
tailLength = (0..minLength-1).firstOrNull {
|
||||
syntheticText[syntheticLength - it - 1] != originalText[originalLength - it - 1]
|
||||
} ?: minLength
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.lookup.WeighingContext
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.codeStyle.NameUtil
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfo
|
||||
import kotlin.math.min
|
||||
|
||||
val NAME_SIMILARITY_KEY = Key<Int>("NAME_SIMILARITY_KEY")
|
||||
|
||||
@@ -49,7 +50,7 @@ private fun calcNameSimilarity(name: String, expectedName: String): Int {
|
||||
val nonNumberWords2 = words2.filter(::isNonNumber)
|
||||
|
||||
// count number of words matched at the end (but ignore number words - they are less important)
|
||||
val minWords = Math.min(nonNumberWords1.size, nonNumberWords2.size)
|
||||
val minWords = min(nonNumberWords1.size, nonNumberWords2.size)
|
||||
val matchedTailLength = (0..minWords-1).firstOrNull {
|
||||
i -> nonNumberWords1[nonNumberWords1.size - i - 1] != nonNumberWords2[nonNumberWords2.size - i - 1]
|
||||
} ?: minWords
|
||||
|
||||
Reference in New Issue
Block a user