Use of substringBefore/After

This commit is contained in:
Valentin Kipyatkov
2015-03-04 18:49:42 +03:00
parent 2ef80d1b34
commit efa83000a2
3 changed files with 4 additions and 12 deletions
@@ -286,8 +286,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
addReferenceVariants(kindFilter, runtimeReceiverType = false)
}
val ampIndex = prefix.indexOf("@")
val keywordsPrefix = if (ampIndex < 0) prefix else prefix.substring(0, ampIndex) // if there is '@' in the prefix - use shorter prefix to not loose 'this' etc
val keywordsPrefix = prefix.substringBefore('@') // if there is '@' in the prefix - use shorter prefix to not loose 'this' etc
KeywordCompletion.complete(expression ?: parameters.getPosition(), keywordsPrefix) { lookupElement ->
val keyword = lookupElement.getLookupString()
when (keyword) {
@@ -110,8 +110,7 @@ public class LookupElementFactory(
}
val qualifiedName = psiClass.getQualifiedName()!!
val dotIndex = qualifiedName.lastIndexOf('.')
val packageName = if (dotIndex <= 0) "<root>" else qualifiedName.substring(0, dotIndex)
val packageName = qualifiedName.substringBeforeLast('.', "<root>")
element = element.appendTailText(" ($packageName)", true)
if (psiClass.isDeprecated()) {
@@ -136,15 +136,9 @@ public abstract class AbstractJavaToKotlinConverterSingleFileTest : AbstractJava
override fun getProjectDescriptor()
= JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
private fun String.removeFirstLine(): String {
val lastNewLine = indexOf('\n')
return if (lastNewLine == -1) "" else substring(lastNewLine)
}
private fun String.removeFirstLine() = substringAfter('\n', "")
private fun String.removeLastLine(): String {
val lastNewLine = lastIndexOf('\n')
return if (lastNewLine == -1) "" else substring(0, lastNewLine)
}
private fun String.removeLastLine() = substringBeforeLast('\n', "")
private fun createJavaFile(text: String): PsiJavaFile {
return myFixture.configureByText("converterTestFile.java", text) as PsiJavaFile