From 6ffc407158639e6a54dcec7f120e3f12079ae73e Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 29 Dec 2015 04:33:58 +0300 Subject: [PATCH] Cleanup in idea plugin modules, idea-completion --- .../idea/completion/AllClassesCompletion.kt | 2 +- .../idea/completion/InsertHandlerProvider.kt | 6 ++--- .../completion/KDocCompletionContributor.kt | 8 +++---- .../idea/completion/KeywordCompletion.kt | 6 ++--- .../completion/KotlinCompletionContributor.kt | 6 ++--- .../idea/completion/LeafElementFilter.kt | 2 +- .../idea/completion/LookupCancelWatcher.kt | 2 +- .../idea/completion/LookupElementFactory.kt | 2 +- .../completion/NamedArgumentCompletion.kt | 2 +- .../completion/PackageDirectiveCompletion.kt | 2 +- .../ParameterNameAndTypeCompletion.kt | 4 ++-- .../completion/ToFromOriginalFileMapper.kt | 8 +++---- .../handlers/CastReceiverInsertHandler.kt | 4 ++-- .../completion/handlers/GenerateLambda.kt | 10 ++++----- .../handlers/KotlinClassifierInsertHandler.kt | 6 ++--- .../handlers/KotlinFunctionInsertHandler.kt | 6 ++--- .../handlers/WithTailInsertHandler.kt | 4 ++-- .../idea/completion/handlers/handlerUtils.kt | 10 ++++----- .../completion/smart/ClassLiteralItems.kt | 2 +- .../idea/completion/smart/LambdaItems.kt | 6 ++--- .../smart/MultipleArgumentsItemProvider.kt | 2 +- .../idea/completion/smart/NameSimilarity.kt | 6 ++--- .../idea/completion/smart/SmartCompletion.kt | 2 +- .../smart/TypeInstantiationItems.kt | 12 +++++----- .../kotlin/idea/completion/smart/Utils.kt | 6 ++--- .../completion/test/CompletionTestUtil.kt | 4 ++-- .../test/ExpectedCompletionUtils.kt | 22 +++++++++---------- .../SmartCompletionMultifileHandlerTest.kt | 2 +- 28 files changed, 77 insertions(+), 77 deletions(-) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/AllClassesCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/AllClassesCompletion.kt index 6bd1c9367ce..975557b51c0 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/AllClassesCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/AllClassesCompletion.kt @@ -88,6 +88,6 @@ class AllClassesCompletion(private val parameters: CompletionParameters, private fun PsiClass.isSyntheticKotlinClass(): Boolean { if (!getName()!!.contains('$')) return false // optimization to not analyze annotations of all classes - return getModifierList()?.findAnnotation(javaClass().getName()) != null + return getModifierList()?.findAnnotation(kotlin.jvm.internal.KotlinSyntheticClass::class.java.getName()) != null } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt index 28f7d8f427b..d0bd00220bc 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/InsertHandlerProvider.kt @@ -45,14 +45,14 @@ class InsertHandlerProvider( CallType.DEFAULT, CallType.DOT, CallType.SAFE, CallType.SUPER_MEMBERS -> { val needTypeArguments = needTypeArguments(descriptor) val parameters = descriptor.valueParameters - when (parameters.size()) { + when (parameters.size) { 0 -> KotlinFunctionInsertHandler.Normal(needTypeArguments, inputValueArguments = false) 1 -> { if (callType != CallType.SUPER_MEMBERS) { // for super call we don't suggest to generate "super.foo { ... }" (seems to be non-typical use) val parameterType = parameters.single().getType() if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(parameterType)) { - val parameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(parameterType).size() + val parameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(parameterType).size if (parameterCount <= 1) { // otherwise additional item with lambda template is to be added return KotlinFunctionInsertHandler.Normal(needTypeArguments, inputValueArguments = false, lambdaInfo = GenerateLambdaInfo(parameterType, false)) @@ -96,7 +96,7 @@ class InsertHandlerProvider( potentiallyInferred.add(descriptor) } - if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) && KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(type).size() <= 1) { + if (KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) && KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(type).size <= 1) { // do not rely on inference from input of function type with one or no arguments - use only return type of functional type addPotentiallyInferred(KotlinBuiltIns.getReturnTypeFromFunctionType(type)) return diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt index 6951fb89b16..725b02e4ee7 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KDocCompletionContributor.kt @@ -44,8 +44,8 @@ import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy class KDocCompletionContributor(): CompletionContributor() { init { - extend(CompletionType.BASIC, psiElement().inside(javaClass()), - KDocNameCompletionProvider) + extend(CompletionType.BASIC, psiElement().inside(KDocName::class.java), + KDocNameCompletionProvider) extend(CompletionType.BASIC, psiElement().afterLeaf( @@ -128,12 +128,12 @@ object KDocTagCompletionProvider: CompletionProvider() { StandardPatterns.character().javaIdentifierPart() or singleCharPattern('@'), StandardPatterns.character().javaIdentifierStart() or singleCharPattern('@')) - if (prefix.length() > 0 && !prefix.startsWith('@')) { + if (prefix.length > 0 && !prefix.startsWith('@')) { return } val resultWithPrefix = result.withPrefixMatcher(prefix) KDocKnownTag.values().forEach { - resultWithPrefix.addElement(LookupElementBuilder.create("@" + it.name().toLowerCase())) + resultWithPrefix.addElement(LookupElementBuilder.create("@" + it.name.toLowerCase())) } } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt index f2d756b841d..be7aad94fcc 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KeywordCompletion.kt @@ -108,8 +108,8 @@ object KeywordCompletion { private val GENERAL_FILTER = NotFilter(OrFilter( CommentFilter(), - ParentFilter(ClassFilter(javaClass())), - ParentFilter(ClassFilter(javaClass())), + ParentFilter(ClassFilter(KtLiteralStringTemplateEntry::class.java)), + ParentFilter(ClassFilter(KtConstantExpression::class.java)), LeftNeighbour(TextFilter(".")), LeftNeighbour(TextFilter("?.")) )) @@ -202,7 +202,7 @@ object KeywordCompletion { return fun (keywordTokenType): Boolean { val postfix = if (prefixText.endsWith("@")) ":X" else " X" val file = psiFactory.createFile(prefixText + keywordTokenType.getValue() + postfix) - val elementAt = file.findElementAt(prefixText.length())!! + val elementAt = file.findElementAt(prefixText.length)!! when { !elementAt.getNode()!!.getElementType().matchesKeyword(keywordTokenType) -> return false diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index 5c0b4ca7b8f..2bb66385f25 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -220,7 +220,7 @@ public class KotlinCompletionContributor : CompletionContributor() { val text = builder.toString() val file = KtPsiFactory(tokenBefore.getProject()).createFile(text) val declaration = file.getDeclarations().singleOrNull() ?: return null - if (declaration.getTextLength() != text.length()) return null + if (declaration.getTextLength() != text.length) return null val containsErrorElement = !PsiTreeUtil.processElements(file, PsiElementProcessor{ it !is PsiErrorElement }) return if (containsErrorElement) null else tail + "$" } @@ -395,8 +395,8 @@ public class KotlinCompletionContributor : CompletionContributor() { private fun isAtEndOfLine(offset: Int, document: Document): Boolean { var i = offset val chars = document.getCharsSequence() - while (i < chars.length()) { - val c = chars.charAt(i) + while (i < chars.length) { + val c = chars[i] if (c == '\n') return true if (!Character.isWhitespace(c)) return false i++ diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LeafElementFilter.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LeafElementFilter.kt index 6d0a17c437f..c29dbcdcc2a 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LeafElementFilter.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LeafElementFilter.kt @@ -31,6 +31,6 @@ public class LeafElementFilter(private val elementType: IElementType) : ElementF = LEAF_CLASS_FILTER.isClassAcceptable(hintClass) companion object { - private val LEAF_CLASS_FILTER = ClassFilter(javaClass()) + private val LEAF_CLASS_FILTER = ClassFilter(LeafPsiElement::class.java) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupCancelWatcher.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupCancelWatcher.kt index d74cf5a1995..aa54edea512 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupCancelWatcher.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupCancelWatcher.kt @@ -66,7 +66,7 @@ class LookupCancelWatcher(project: Project) : AbstractProjectComponent(project) private var lastReminiscence: Reminiscence? = null companion object { - fun getInstance(project: Project): LookupCancelWatcher = project.getComponent(javaClass())!! + fun getInstance(project: Project): LookupCancelWatcher = project.getComponent(LookupCancelWatcher::class.java)!! val AUTO_POPUP_AT = Key("LookupCancelWatcher.AUTO_POPUP_AT") } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt index ee2ae1d66a1..6a09e172e10 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementFactory.kt @@ -136,7 +136,7 @@ class LookupElementFactory( // render only the last parameter because all other should be optional and will be omitted var parametersRenderer = DescriptorRenderer.SHORT_NAMES_IN_TYPES - if (descriptor.valueParameters.size() > 1) { + if (descriptor.valueParameters.size > 1) { parametersRenderer = parametersRenderer.withOptions { valueParametersHandler = object: DescriptorRenderer.ValueParametersHandler by this.valueParametersHandler { override fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/NamedArgumentCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/NamedArgumentCompletion.kt index 4443e023fc4..7e2d64dee21 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/NamedArgumentCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/NamedArgumentCompletion.kt @@ -73,7 +73,7 @@ object NamedArgumentCompletion { val editor = context.getEditor() val text = parameterName.render() editor.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), text) - editor.getCaretModel().moveToOffset(context.getStartOffset() + text.length()) + editor.getCaretModel().moveToOffset(context.getStartOffset() + text.length) WithTailInsertHandler.EQ.postHandleInsert(context, item) } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt index 49825352a5e..e7d94327e70 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/PackageDirectiveCompletion.kt @@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter */ object PackageDirectiveCompletion { val DUMMY_IDENTIFIER = "___package___" - val ACTIVATION_PATTERN = PlatformPatterns.psiElement().inside(javaClass()) + val ACTIVATION_PATTERN = PlatformPatterns.psiElement().inside(KtPackageDirective::class.java) fun perform(parameters: CompletionParameters, result: CompletionResultSet): Boolean { val position = parameters.getPosition() diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt index 724ad09a5b5..33d161ba812 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ParameterNameAndTypeCompletion.kt @@ -144,7 +144,7 @@ class ParameterNameAndTypeCompletion( if (prefixMatcher.isStartMatch(parameterName)) { val lookupElement = MyLookupElement.create(parameterName, type, lookupElementFactory) if (lookupElement != null) { - lookupElement.putUserData(PRIORITY_KEY, userPrefix.length()) // suggestions with longer user prefix get lower priority + lookupElement.putUserData(PRIORITY_KEY, userPrefix.length) // suggestions with longer user prefix get lower priority collector.addElement(lookupElement, notImported) suggestionsByTypesAdded.add(type) } @@ -214,7 +214,7 @@ class ParameterNameAndTypeCompletion( context.getDocument().insertString(startOffset, text) // update start offset so that it does not include the text we inserted - context.getOffsetMap().addOffset(CompletionInitializationContext.START_OFFSET, startOffset + text.length()) + context.getOffsetMap().addOffset(CompletionInitializationContext.START_OFFSET, startOffset + text.length) super.handleInsert(context) } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt index b83529390a2..f00166921ab 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/ToFromOriginalFileMapper.kt @@ -38,8 +38,8 @@ class ToFromOriginalFileMapper( val syntheticText = syntheticFile.getText() assert(originalText.subSequence(0, completionOffset) == syntheticText.subSequence(0, completionOffset)) - syntheticLength = syntheticText.length() - originalLength = originalText.length() + syntheticLength = syntheticText.length + originalLength = originalText.length val minLength = Math.min(originalLength, syntheticLength) tailLength = (0..minLength-1).firstOrNull { syntheticText[syntheticLength - it - 1] != originalText[originalLength - it - 1] @@ -66,12 +66,12 @@ class ToFromOriginalFileMapper( public fun toOriginalFile(declaration: KtDeclaration): KtDeclaration? { if (declaration.getContainingFile() != syntheticFile) return declaration val offset = toOriginalFile(declaration.startOffset) ?: return null - return PsiTreeUtil.findElementOfClassAtOffset(originalFile, offset, javaClass(), true) + return PsiTreeUtil.findElementOfClassAtOffset(originalFile, offset, KtDeclaration::class.java, true) } public fun toSyntheticFile(declaration: KtDeclaration): KtDeclaration? { if (declaration.getContainingFile() != originalFile) return declaration val offset = toSyntheticFile(declaration.startOffset) ?: return null - return PsiTreeUtil.findElementOfClassAtOffset(syntheticFile, offset, javaClass(), true) + return PsiTreeUtil.findElementOfClassAtOffset(syntheticFile, offset, KtDeclaration::class.java, true) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/CastReceiverInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/CastReceiverInsertHandler.kt index 8c529dc5937..a0b9f867068 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/CastReceiverInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/CastReceiverInsertHandler.kt @@ -28,8 +28,8 @@ import org.jetbrains.kotlin.psi.* object CastReceiverInsertHandler { fun postHandleInsert(context: InsertionContext, item: LookupElement) { - val expression = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), javaClass(), false) - val qualifiedExpression = PsiTreeUtil.getParentOfType(expression, javaClass(), true) + val expression = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), KtSimpleNameExpression::class.java, false) + val qualifiedExpression = PsiTreeUtil.getParentOfType(expression, KtQualifiedExpression::class.java, true) if (qualifiedExpression != null) { val receiver = qualifiedExpression.getReceiverExpression() diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt index 59fc2d9c278..43cf6f414c1 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/GenerateLambda.kt @@ -74,7 +74,7 @@ fun lambdaPresentation(lambdaType: KotlinType?): String { private fun needExplicitParameterTypes(context: InsertionContext, placeholderRange: TextRange, lambdaType: KotlinType): Boolean { PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments() val file = context.getFile() as KtFile - val expression = PsiTreeUtil.findElementOfClassAtRange(file, placeholderRange.getStartOffset(), placeholderRange.getEndOffset(), javaClass()) + val expression = PsiTreeUtil.findElementOfClassAtRange(file, placeholderRange.getStartOffset(), placeholderRange.getEndOffset(), KtExpression::class.java) ?: return false val resolutionFacade = file.getResolutionFacade() @@ -85,10 +85,10 @@ private fun needExplicitParameterTypes(context: InsertionContext, placeholderRan .mapNotNull { it.fuzzyType?.type } .filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it) } .toSet() - if (functionTypes.size() <= 1) return false + if (functionTypes.size <= 1) return false - val lambdaParameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(lambdaType).size() - return functionTypes.filter { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size() == lambdaParameterCount }.size() > 1 + val lambdaParameterCount = KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(lambdaType).size + return functionTypes.filter { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size() == lambdaParameterCount }.size > 1 } private fun buildTemplate(lambdaType: KotlinType, explicitParameterTypes: Boolean, project: Project): Template { @@ -124,7 +124,7 @@ private class ParameterNameExpression(val nameSuggestions: Array) : Expr override fun calculateQuickResult(context: ExpressionContext?): Result? = null override fun calculateLookupItems(context: ExpressionContext?) - = Array(nameSuggestions.size(), { LookupElementBuilder.create(nameSuggestions[it]) }) + = Array(nameSuggestions.size, { LookupElementBuilder.create(nameSuggestions[it]) }) } fun functionParameterTypes(functionType: KotlinType): List diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt index 8c91ae5ceb0..7595b9f5fc2 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt @@ -76,10 +76,10 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() { psiDocumentManager.commitAllDocuments() - val classNameStart = startOffset + tempPrefix.length() - val classNameEnd = classNameStart + qualifiedName.length() + val classNameStart = startOffset + tempPrefix.length + val classNameEnd = classNameStart + qualifiedName.length val rangeMarker = document.createRangeMarker(classNameStart, classNameEnd) - val wholeRangeMarker = document.createRangeMarker(startOffset, classNameEnd + tempSuffix.length()) + val wholeRangeMarker = document.createRangeMarker(startOffset, classNameEnd + tempSuffix.length) ShortenReferences.DEFAULT.process(file, classNameStart, classNameEnd) psiDocumentManager.doPostponedOperationsAndUnblockDocument(document) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinFunctionInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinFunctionInsertHandler.kt index ca0ff0aa391..62338058a3f 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinFunctionInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinFunctionInsertHandler.kt @@ -98,7 +98,7 @@ sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() { if (completionChar == Lookup.REPLACE_SELECT_CHAR) { val offset1 = chars.skipSpaces(offset) - if (offset1 < chars.length()) { + if (offset1 < chars.length) { if (chars[offset1] == '<') { PsiDocumentManager.getInstance(project).commitDocument(document) val token = context.getFile().findElementAt(offset1)!! @@ -167,7 +167,7 @@ sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() { document.insertString(openingBracketOffset + 1, argumentText) if (closeBracketOffset != null) { - closeBracketOffset += argumentText.length() + closeBracketOffset += argumentText.length } if (!insertTypeArguments) { @@ -190,7 +190,7 @@ sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() { } private fun isInsertSpacesInOneLineFunctionEnabled(project: Project) - = CodeStyleSettingsManager.getSettings(project).getCustomSettings(javaClass())!!.INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD + = CodeStyleSettingsManager.getSettings(project).getCustomSettings(KotlinCodeStyleSettings::class.java)!!.INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD } object Infix : KotlinFunctionInsertHandler() { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/WithTailInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/WithTailInsertHandler.kt index bd85e567eee..265e3984a56 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/WithTailInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/WithTailInsertHandler.kt @@ -58,7 +58,7 @@ class WithTailInsertHandler(val tailText: String, var offset = document.charsSequence.skipSpacesAndLineBreaks(tailOffset) if (document.isTextAt(offset, tailText)) { insert = false - offset += tailText.length() + offset += tailText.length tailOffset = offset if (spaceAfter && document.charsSequence.isCharAt(offset, ' ')) { @@ -77,7 +77,7 @@ class WithTailInsertHandler(val tailText: String, document.insertString(tailOffset, textToInsert) if (moveCaret) { - context.getEditor().getCaretModel().moveToOffset(tailOffset + textToInsert.length()) + context.getEditor().getCaretModel().moveToOffset(tailOffset + textToInsert.length) if (tailText == ",") { AutoPopupController.getInstance(context.getProject())?.autoPopupParameterInfo(context.getEditor(), null) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/handlerUtils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/handlerUtils.kt index 62ad697f1fd..936ced22b44 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/handlerUtils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/handlerUtils.kt @@ -44,7 +44,7 @@ fun surroundWithBracesIfInStringTemplate(context: InsertionContext) { } fun CharSequence.indexOfSkippingSpace(c: Char, startIndex: Int): Int? { - for (i in startIndex..this.length() - 1) { + for (i in startIndex..this.length - 1) { val currentChar = this[i] if (c == currentChar) return i if (currentChar != ' ' && currentChar != '\t') return null @@ -53,11 +53,11 @@ fun CharSequence.indexOfSkippingSpace(c: Char, startIndex: Int): Int? { } fun CharSequence.skipSpaces(index: Int): Int - = (index..length() - 1).firstOrNull { val c = this[it]; c != ' ' && c != '\t' } ?: this.length() + = (index..length - 1).firstOrNull { val c = this[it]; c != ' ' && c != '\t' } ?: this.length fun CharSequence.skipSpacesAndLineBreaks(index: Int): Int - = (index..length() - 1).firstOrNull { val c = this[it]; c != ' ' && c != '\t' && c != '\n' && c != '\r' } ?: this.length() + = (index..length - 1).firstOrNull { val c = this[it]; c != ' ' && c != '\t' && c != '\n' && c != '\r' } ?: this.length -fun CharSequence.isCharAt(offset: Int, c: Char) = offset < length() && charAt(offset) == c +fun CharSequence.isCharAt(offset: Int, c: Char) = offset < length && this[offset] == c -fun Document.isTextAt(offset: Int, text: String) = offset + text.length() <= getTextLength() && getText(TextRange(offset, offset + text.length())) == text +fun Document.isTextAt(offset: Int, text: String) = offset + text.length <= getTextLength() && getText(TextRange(offset, offset + text.length)) == text diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/ClassLiteralItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/ClassLiteralItems.kt index ae7bb65ace6..376b712b8ab 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/ClassLiteralItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/ClassLiteralItems.kt @@ -75,7 +75,7 @@ object ClassLiteralItems { super.handleInsert(context) val offset = context.tailOffset context.document.insertString(offset, suffix) - context.editor.moveCaret(offset + suffix.length()) + context.editor.moveCaret(offset + suffix.length) } } lookupElement.assignSmartCompletionPriority(SmartCompletionItemPriority.CLASS_LITERAL) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt index 334d116882d..3528ddaba23 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/LambdaItems.kt @@ -42,8 +42,8 @@ object LambdaItems { .mapNotNull { it.fuzzyType?.type } .toSet() - val singleType = if (distinctTypes.size() == 1) distinctTypes.single() else null - val singleSignatureLength = singleType?.let { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size() } + val singleType = if (distinctTypes.size == 1) distinctTypes.single() else null + val singleSignatureLength = singleType?.let { KotlinBuiltIns.getParameterTypeProjectionsFromFunctionType(it).size } val offerNoParametersLambda = singleSignatureLength == 0 || singleSignatureLength == 1 if (offerNoParametersLambda) { val lookupElement = LookupElementBuilder.create(lambdaPresentation(null)) @@ -62,7 +62,7 @@ object LambdaItems { val offset = context.getStartOffset() val placeholder = "{}" context.getDocument().replaceString(offset, context.getTailOffset(), placeholder) - insertLambdaTemplate(context, TextRange(offset, offset + placeholder.length()), functionType) + insertLambdaTemplate(context, TextRange(offset, offset + placeholder.length), functionType) }) .suppressAutoInsertion() .assignSmartCompletionPriority(SmartCompletionItemPriority.LAMBDA) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt index b2a4f0433e6..c4f2af10d35 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/MultipleArgumentsItemProvider.kt @@ -58,7 +58,7 @@ class MultipleArgumentsItemProvider( val additionalData = expectedInfo.additionalData if (additionalData is ArgumentPositionData.Positional && additionalData.argumentIndex == 0) { val parameters = additionalData.function.valueParameters - if (parameters.size() > 1) { + if (parameters.size > 1) { val tail = when (additionalData.callType) { Call.CallType.ARRAY_GET_METHOD, Call.CallType.ARRAY_SET_METHOD -> Tail.RBRACKET else -> Tail.RPARENTH diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt index 12c85f72610..b741e40cb34 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/NameSimilarity.kt @@ -49,10 +49,10 @@ 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 = Math.min(nonNumberWords1.size, nonNumberWords2.size) val matchedTailLength = (0..minWords-1).firstOrNull { - i -> nonNumberWords1[nonNumberWords1.size() - i - 1] != nonNumberWords2[nonNumberWords2.size() - i - 1] + i -> nonNumberWords1[nonNumberWords1.size - i - 1] != nonNumberWords2[nonNumberWords2.size - i - 1] } ?: minWords - return matchedWords.size() * 1000 + matchedTailLength + return matchedWords.size * 1000 + matchedTailLength } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt index e1291290811..115585caddf 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/SmartCompletion.kt @@ -222,7 +222,7 @@ class SmartCompletion( val entry = whenCondition.parent as KtWhenEntry val whenExpression = entry.parent as KtWhenExpression val entries = whenExpression.entries - if (whenExpression.elseExpression == null && entry == entries.last() && entries.size() != 1) { + if (whenExpression.elseExpression == null && entry == entries.last() && entries.size != 1) { val lookupElement = LookupElementBuilder.create("else").bold().withTailText(" ->") items.add(object: LookupElementDecorator(lookupElement) { override fun handleInsert(context: InsertionContext) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt index a44859f452c..043d95ee8f1 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/TypeInstantiationItems.kt @@ -182,16 +182,16 @@ class TypeInstantiationItems( context.document.replaceString(startOffset, context.tailOffset, text) if (allTypeArgsKnown) { - context.editor.caretModel.moveToOffset(startOffset + text.length() - 1) + context.editor.caretModel.moveToOffset(startOffset + text.length - 1) - shortenReferences(context, startOffset, startOffset + text.length()) + shortenReferences(context, startOffset, startOffset + text.length) ImplementMembersHandler().invoke(context.project, context.editor, context.file, true) } else { - context.editor.caretModel.moveToOffset(startOffset + text1.length() + 1) // put caret into "<>" + context.editor.caretModel.moveToOffset(startOffset + text1.length + 1) // put caret into "<>" - shortenReferences(context, startOffset, startOffset + text.length()) + shortenReferences(context, startOffset, startOffset + text.length) } } lookupElement = lookupElement.suppressAutoInsertion() @@ -199,7 +199,7 @@ class TypeInstantiationItems( } else { //TODO: when constructor has one parameter of lambda type with more than one parameter, generate special additional item - signatureText = when (visibleConstructors.size()) { + signatureText = when (visibleConstructors.size) { 0 -> "()" 1 -> DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(visibleConstructors.single()) else -> "(...)" @@ -217,7 +217,7 @@ class TypeInstantiationItems( insertHandler = object : InsertHandler { override fun handleInsert(context: InsertionContext, item: LookupElement) { context.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), typeText) - context.setTailOffset(context.getStartOffset() + typeText.length()) + context.setTailOffset(context.getStartOffset() + typeText.length) baseInsertHandler.handleInsert(context, item) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 1ce7b9cf3ff..92c5995e3fa 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -45,13 +45,13 @@ class ArtificialElementInsertHandler( val textBeforeCaret: String, val textAfterCaret: String, val shortenRefs: Boolean) : InsertHandler{ override fun handleInsert(context: InsertionContext, item: LookupElement) { val offset = context.getEditor().getCaretModel().getOffset() - val startOffset = offset - item.getLookupString().length() + val startOffset = offset - item.getLookupString().length context.getDocument().deleteString(startOffset, offset) // delete inserted lookup string context.getDocument().insertString(startOffset, textBeforeCaret + textAfterCaret) - context.getEditor().getCaretModel().moveToOffset(startOffset + textBeforeCaret.length()) + context.getEditor().getCaretModel().moveToOffset(startOffset + textBeforeCaret.length) if (shortenRefs) { - shortenReferences(context, startOffset, startOffset + textBeforeCaret.length() + textAfterCaret.length()) + shortenReferences(context, startOffset, startOffset + textBeforeCaret.length + textAfterCaret.length) } } } diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompletionTestUtil.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompletionTestUtil.kt index f8be71dd75a..21611511bf4 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompletionTestUtil.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/CompletionTestUtil.kt @@ -40,13 +40,13 @@ fun testCompletion(fileText: String, platform: TargetPlatform?, complete: (Compl val itemsNumber = ExpectedCompletionUtils.getExpectedNumber(fileText, platform) val nothingElse = ExpectedCompletionUtils.isNothingElseExpected(fileText) - Assert.assertTrue("Should be some assertions about completion", expected.size() != 0 || unexpected.size() != 0 || itemsNumber != null || nothingElse) + Assert.assertTrue("Should be some assertions about completion", expected.size != 0 || unexpected.size != 0 || itemsNumber != null || nothingElse) ExpectedCompletionUtils.assertContainsRenderedItems(expected, items, ExpectedCompletionUtils.isWithOrder(fileText), nothingElse) ExpectedCompletionUtils.assertNotContainsRenderedItems(unexpected, items) if (itemsNumber != null) { val expectedItems = ExpectedCompletionUtils.listToString(ExpectedCompletionUtils.getItemsInformation(items)) - Assert.assertEquals("Invalid number of completion items: ${expectedItems}", itemsNumber, items.size()) + Assert.assertEquals("Invalid number of completion items: ${expectedItems}", itemsNumber, items.size) } } } diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ExpectedCompletionUtils.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ExpectedCompletionUtils.kt index 10a2a459396..7c458f27e88 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ExpectedCompletionUtils.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/ExpectedCompletionUtils.kt @@ -51,7 +51,7 @@ public object ExpectedCompletionUtils { public constructor(map: MutableMap) { this.map = map - for (key in map.keySet()) { + for (key in map.keys) { if (key !in validKeys) { throw RuntimeException("Invalid key '$key'") } @@ -61,7 +61,7 @@ public object ExpectedCompletionUtils { public constructor(json: JsonObject) { map = HashMap() for (entry in json.entrySet()) { - val key = entry.getKey() + val key = entry.key if (key !in validKeys) { throw RuntimeException("Invalid json property '$key'") } @@ -71,7 +71,7 @@ public object ExpectedCompletionUtils { } public fun matches(expectedProposal: CompletionProposal): Boolean - = expectedProposal.map.entrySet().none { it.value != map[it.key] } + = expectedProposal.map.entries.none { it.value != map[it.key] } override fun toString(): String { val jsonObject = JsonObject() @@ -168,7 +168,7 @@ public object ExpectedCompletionUtils { proposals.add(CompletionProposal(json as JsonObject)) } else if (proposalStr.startsWith("\"") && proposalStr.endsWith("\"")) { - proposals.add(CompletionProposal(proposalStr.substring(1, proposalStr.length() - 1))) + proposals.add(CompletionProposal(proposalStr.substring(1, proposalStr.length - 1))) } else { for (item in proposalStr.split(",")) { @@ -177,7 +177,7 @@ public object ExpectedCompletionUtils { } } - return ArrayUtil.toObjectArray(proposals, javaClass()) + return ArrayUtil.toObjectArray(proposals, CompletionProposal::class.java) } public fun getExpectedNumber(fileText: String, platform: TargetPlatform?): Int? { @@ -287,7 +287,7 @@ public object ExpectedCompletionUtils { public fun getItemsInformation(items: Array): List { val presentation = LookupElementPresentation() - val result = ArrayList(items.size()) + val result = ArrayList(items.size) for (item in items) { item.renderElement(presentation) @@ -315,25 +315,25 @@ public object ExpectedCompletionUtils { } private fun textAttributes(presentation: LookupElementPresentation): String { - return StringBuilder { + return buildString { if (presentation.isItemTextBold) { append("bold") } if (presentation.isItemTextUnderlined) { - if (length() > 0) append(" ") + if (length > 0) append(" ") append("underlined") } val foreground = presentation.itemTextForeground if (foreground != JBColor.foreground()) { assert(foreground == LookupCellRenderer.getGrayedForeground(false)) - if (length() > 0) append(" ") + if (length > 0) append(" ") append("grayed") } if (presentation.isStrikeout) { - if (length() > 0) append(" ") + if (length > 0) append(" ") append("strikeout") } - }.toString() + } } public fun listToString(items: Collection): String = items.joinToString("\n") diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt index 9fa9d8da59c..a5dd100d2dd 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/handlers/SmartCompletionMultifileHandlerTest.kt @@ -44,7 +44,7 @@ public class SmartCompletionMultifileHandlerTest : KotlinCompletionTestCase() { complete(1) if (myItems != null) { - assertTrue(myItems.size() == 1, "Multiple items in completion") + assertTrue(myItems.size == 1, "Multiple items in completion") selectItem(myItems[0]) }