diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt index 6ccc1e0e61e..a112a376636 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt @@ -103,8 +103,7 @@ var globalCounterglobalCounter { infix fun String.to(key: TextAttributesKey) = AttributesDescriptor(this, key) - - return arrayOf(OptionsBundle.message("options.java.attribute.descriptor.keyword") to KotlinHighlightingColors.KEYWORD, - KotlinBundle.message("options.kotlin.attribute.descriptor.builtin.annotation") to KotlinHighlightingColors.BUILTIN_ANNOTATION, - OptionsBundle.message("options.java.attribute.descriptor.number") to KotlinHighlightingColors.NUMBER, - OptionsBundle.message("options.java.attribute.descriptor.string") to KotlinHighlightingColors.STRING, - KotlinBundle.message("options.kotlin.attribute.descriptor.string.escape") to KotlinHighlightingColors.STRING_ESCAPE, - OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string") to KotlinHighlightingColors.INVALID_STRING_ESCAPE, - OptionsBundle.message("options.java.attribute.descriptor.operator.sign") to KotlinHighlightingColors.OPERATOR_SIGN, - OptionsBundle.message("options.java.attribute.descriptor.parentheses") to KotlinHighlightingColors.PARENTHESIS, - OptionsBundle.message("options.java.attribute.descriptor.braces") to KotlinHighlightingColors.BRACES, - KotlinBundle.message("options.kotlin.attribute.descriptor.closure.braces") to KotlinHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW, - KotlinBundle.message("options.kotlin.attribute.descriptor.arrow") to KotlinHighlightingColors.ARROW, - OptionsBundle.message("options.java.attribute.descriptor.brackets") to KotlinHighlightingColors.BRACKETS, - OptionsBundle.message("options.java.attribute.descriptor.comma") to KotlinHighlightingColors.COMMA, - OptionsBundle.message("options.java.attribute.descriptor.semicolon") to KotlinHighlightingColors.SEMICOLON, - KotlinBundle.message("options.kotlin.attribute.descriptor.colon") to KotlinHighlightingColors.COLON, - KotlinBundle.message("options.kotlin.attribute.descriptor.double.colon") to KotlinHighlightingColors.DOUBLE_COLON, - OptionsBundle.message("options.java.attribute.descriptor.dot") to KotlinHighlightingColors.DOT, - KotlinBundle.message("options.kotlin.attribute.descriptor.safe.access") to KotlinHighlightingColors.SAFE_ACCESS, - KotlinBundle.message("options.kotlin.attribute.descriptor.quest") to KotlinHighlightingColors.QUEST, - KotlinBundle.message("options.kotlin.attribute.descriptor.exclexcl") to KotlinHighlightingColors.EXCLEXCL, - OptionsBundle.message("options.java.attribute.descriptor.line.comment") to KotlinHighlightingColors.LINE_COMMENT, - OptionsBundle.message("options.java.attribute.descriptor.block.comment") to KotlinHighlightingColors.BLOCK_COMMENT, - KotlinBundle.message("options.kotlin.attribute.descriptor.kdoc.comment") to KotlinHighlightingColors.DOC_COMMENT, - KotlinBundle.message("options.kotlin.attribute.descriptor.kdoc.tag") to KotlinHighlightingColors.KDOC_TAG, - KotlinBundle.message("options.kotlin.attribute.descriptor.kdoc.value") to KotlinHighlightingColors.KDOC_LINK, - OptionsBundle.message("options.java.attribute.descriptor.class") to KotlinHighlightingColors.CLASS, - OptionsBundle.message("options.java.attribute.descriptor.type.parameter") to KotlinHighlightingColors.TYPE_PARAMETER, - OptionsBundle.message("options.java.attribute.descriptor.abstract.class") to KotlinHighlightingColors.ABSTRACT_CLASS, - OptionsBundle.message("options.java.attribute.descriptor.interface") to KotlinHighlightingColors.TRAIT, - KotlinBundle.message("options.kotlin.attribute.descriptor.annotation") to KotlinHighlightingColors.ANNOTATION, - KotlinBundle.message("options.kotlin.attribute.descriptor.object") to KotlinHighlightingColors.OBJECT, - KotlinBundle.message("options.kotlin.attribute.descriptor.enumEntry") to KotlinHighlightingColors.ENUM_ENTRY, - KotlinBundle.message("options.kotlin.attribute.descriptor.typeAlias") to KotlinHighlightingColors.TYPE_ALIAS, - KotlinBundle.message("options.kotlin.attribute.descriptor.var") to KotlinHighlightingColors.MUTABLE_VARIABLE, - KotlinBundle.message("options.kotlin.attribute.descriptor.local.variable") to KotlinHighlightingColors.LOCAL_VARIABLE, - OptionsBundle.message("options.java.attribute.descriptor.parameter") to KotlinHighlightingColors.PARAMETER, - KotlinBundle.message("options.kotlin.attribute.descriptor.captured.variable") to KotlinHighlightingColors.WRAPPED_INTO_REF, - KotlinBundle.message("options.kotlin.attribute.descriptor.instance.property") to KotlinHighlightingColors.INSTANCE_PROPERTY, - KotlinBundle.message("options.kotlin.attribute.descriptor.package.property") to KotlinHighlightingColors.PACKAGE_PROPERTY, - KotlinBundle.message("options.kotlin.attribute.descriptor.field") to KotlinHighlightingColors.BACKING_FIELD_VARIABLE, - KotlinBundle.message("options.kotlin.attribute.descriptor.extension.property") to KotlinHighlightingColors.EXTENSION_PROPERTY, - KotlinBundle.message("options.kotlin.attribute.descriptor.synthetic.extension.property") to KotlinHighlightingColors.SYNTHETIC_EXTENSION_PROPERTY, - KotlinBundle.message("options.kotlin.attribute.descriptor.dynamic.property") to KotlinHighlightingColors.DYNAMIC_PROPERTY_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.android.extensions.property") to KotlinHighlightingColors.ANDROID_EXTENSIONS_PROPERTY_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.it") to KotlinHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER, - KotlinBundle.message("options.kotlin.attribute.descriptor.fun") to KotlinHighlightingColors.FUNCTION_DECLARATION, - KotlinBundle.message("options.kotlin.attribute.descriptor.fun.call") to KotlinHighlightingColors.FUNCTION_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.dynamic.fun.call") to KotlinHighlightingColors.DYNAMIC_FUNCTION_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.package.fun.call") to KotlinHighlightingColors.PACKAGE_FUNCTION_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.extension.fun.call") to KotlinHighlightingColors.EXTENSION_FUNCTION_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.constructor.call") to KotlinHighlightingColors.CONSTRUCTOR_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.variable.as.function.call") to KotlinHighlightingColors.VARIABLE_AS_FUNCTION_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.variable.as.function.like.call") to KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL, - KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast") to KotlinHighlightingColors.SMART_CAST_VALUE, - KotlinBundle.message("options.kotlin.attribute.descriptor.smart.constant") to KotlinHighlightingColors.SMART_CONSTANT, - KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast.receiver") to KotlinHighlightingColors.SMART_CAST_RECEIVER, - KotlinBundle.message("options.kotlin.attribute.descriptor.label") to KotlinHighlightingColors.LABEL, - "Named argument" to KotlinHighlightingColors.NAMED_ARGUMENT) + - DslHighlighterExtension.descriptionsToStyles.map { (description, key) -> description to key }.toTypedArray() + + return arrayOf( + OptionsBundle.message("options.java.attribute.descriptor.keyword") to KotlinHighlightingColors.KEYWORD, + KotlinBundle.message("options.kotlin.attribute.descriptor.builtin.annotation") to KotlinHighlightingColors.BUILTIN_ANNOTATION, + OptionsBundle.message("options.java.attribute.descriptor.number") to KotlinHighlightingColors.NUMBER, + OptionsBundle.message("options.java.attribute.descriptor.string") to KotlinHighlightingColors.STRING, + KotlinBundle.message("options.kotlin.attribute.descriptor.string.escape") to KotlinHighlightingColors.STRING_ESCAPE, + OptionsBundle.message("options.java.attribute.descriptor.invalid.escape.in.string") to KotlinHighlightingColors.INVALID_STRING_ESCAPE, + OptionsBundle.message("options.java.attribute.descriptor.operator.sign") to KotlinHighlightingColors.OPERATOR_SIGN, + OptionsBundle.message("options.java.attribute.descriptor.parentheses") to KotlinHighlightingColors.PARENTHESIS, + OptionsBundle.message("options.java.attribute.descriptor.braces") to KotlinHighlightingColors.BRACES, + KotlinBundle.message("options.kotlin.attribute.descriptor.closure.braces") to KotlinHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW, + KotlinBundle.message("options.kotlin.attribute.descriptor.arrow") to KotlinHighlightingColors.ARROW, + OptionsBundle.message("options.java.attribute.descriptor.brackets") to KotlinHighlightingColors.BRACKETS, + OptionsBundle.message("options.java.attribute.descriptor.comma") to KotlinHighlightingColors.COMMA, + OptionsBundle.message("options.java.attribute.descriptor.semicolon") to KotlinHighlightingColors.SEMICOLON, + KotlinBundle.message("options.kotlin.attribute.descriptor.colon") to KotlinHighlightingColors.COLON, + KotlinBundle.message("options.kotlin.attribute.descriptor.double.colon") to KotlinHighlightingColors.DOUBLE_COLON, + OptionsBundle.message("options.java.attribute.descriptor.dot") to KotlinHighlightingColors.DOT, + KotlinBundle.message("options.kotlin.attribute.descriptor.safe.access") to KotlinHighlightingColors.SAFE_ACCESS, + KotlinBundle.message("options.kotlin.attribute.descriptor.quest") to KotlinHighlightingColors.QUEST, + KotlinBundle.message("options.kotlin.attribute.descriptor.exclexcl") to KotlinHighlightingColors.EXCLEXCL, + OptionsBundle.message("options.java.attribute.descriptor.line.comment") to KotlinHighlightingColors.LINE_COMMENT, + OptionsBundle.message("options.java.attribute.descriptor.block.comment") to KotlinHighlightingColors.BLOCK_COMMENT, + KotlinBundle.message("options.kotlin.attribute.descriptor.kdoc.comment") to KotlinHighlightingColors.DOC_COMMENT, + KotlinBundle.message("options.kotlin.attribute.descriptor.kdoc.tag") to KotlinHighlightingColors.KDOC_TAG, + KotlinBundle.message("options.kotlin.attribute.descriptor.kdoc.value") to KotlinHighlightingColors.KDOC_LINK, + OptionsBundle.message("options.java.attribute.descriptor.class") to KotlinHighlightingColors.CLASS, + OptionsBundle.message("options.java.attribute.descriptor.type.parameter") to KotlinHighlightingColors.TYPE_PARAMETER, + OptionsBundle.message("options.java.attribute.descriptor.abstract.class") to KotlinHighlightingColors.ABSTRACT_CLASS, + OptionsBundle.message("options.java.attribute.descriptor.interface") to KotlinHighlightingColors.TRAIT, + KotlinBundle.message("options.kotlin.attribute.descriptor.annotation") to KotlinHighlightingColors.ANNOTATION, + KotlinBundle.message("options.kotlin.attribute.descriptor.object") to KotlinHighlightingColors.OBJECT, + KotlinBundle.message("options.kotlin.attribute.descriptor.enumEntry") to KotlinHighlightingColors.ENUM_ENTRY, + KotlinBundle.message("options.kotlin.attribute.descriptor.typeAlias") to KotlinHighlightingColors.TYPE_ALIAS, + KotlinBundle.message("options.kotlin.attribute.descriptor.var") to KotlinHighlightingColors.MUTABLE_VARIABLE, + KotlinBundle.message("options.kotlin.attribute.descriptor.local.variable") to KotlinHighlightingColors.LOCAL_VARIABLE, + OptionsBundle.message("options.java.attribute.descriptor.parameter") to KotlinHighlightingColors.PARAMETER, + KotlinBundle.message("options.kotlin.attribute.descriptor.captured.variable") to KotlinHighlightingColors.WRAPPED_INTO_REF, + KotlinBundle.message("options.kotlin.attribute.descriptor.instance.property") to KotlinHighlightingColors.INSTANCE_PROPERTY, + KotlinBundle.message("options.kotlin.attribute.descriptor.package.property") to KotlinHighlightingColors.PACKAGE_PROPERTY, + KotlinBundle.message("options.kotlin.attribute.descriptor.field") to KotlinHighlightingColors.BACKING_FIELD_VARIABLE, + KotlinBundle.message("options.kotlin.attribute.descriptor.extension.property") to KotlinHighlightingColors.EXTENSION_PROPERTY, + KotlinBundle.message("options.kotlin.attribute.descriptor.synthetic.extension.property") to KotlinHighlightingColors.SYNTHETIC_EXTENSION_PROPERTY, + KotlinBundle.message("options.kotlin.attribute.descriptor.dynamic.property") to KotlinHighlightingColors.DYNAMIC_PROPERTY_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.android.extensions.property") to KotlinHighlightingColors.ANDROID_EXTENSIONS_PROPERTY_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.it") to KotlinHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER, + KotlinBundle.message("options.kotlin.attribute.descriptor.fun") to KotlinHighlightingColors.FUNCTION_DECLARATION, + KotlinBundle.message("options.kotlin.attribute.descriptor.fun.call") to KotlinHighlightingColors.FUNCTION_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.dynamic.fun.call") to KotlinHighlightingColors.DYNAMIC_FUNCTION_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.package.fun.call") to KotlinHighlightingColors.PACKAGE_FUNCTION_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.extension.fun.call") to KotlinHighlightingColors.EXTENSION_FUNCTION_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.constructor.call") to KotlinHighlightingColors.CONSTRUCTOR_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.variable.as.function.call") to KotlinHighlightingColors.VARIABLE_AS_FUNCTION_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.variable.as.function.like.call") to KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL, + KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast") to KotlinHighlightingColors.SMART_CAST_VALUE, + KotlinBundle.message("options.kotlin.attribute.descriptor.smart.constant") to KotlinHighlightingColors.SMART_CONSTANT, + KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast.receiver") to KotlinHighlightingColors.SMART_CAST_RECEIVER, + KotlinBundle.message("options.kotlin.attribute.descriptor.label") to KotlinHighlightingColors.LABEL, + "Named argument" to KotlinHighlightingColors.NAMED_ARGUMENT + ) + + DslHighlighterExtension.descriptionsToStyles.map { (description, key) -> description to key }.toTypedArray() } override fun getColorDescriptors(): Array = ColorDescriptor.EMPTY_ARRAY @@ -185,6 +186,6 @@ var globalCounter? { if (target is LeafPsiElement && (target.elementType in RETURN_AND_THROW)) { val returnOrThrow = PsiTreeUtil.getParentOfType( - target, - KtReturnExpression::class.java, - KtThrowExpression::class.java + target, + KtReturnExpression::class.java, + KtThrowExpression::class.java ) ?: return null return MyHandler(editor, file, returnOrThrow) @@ -50,7 +50,8 @@ class KotlinHighlightExitPointsHandlerFactory : HighlightUsagesHandlerFactoryBas return null } - private class MyHandler(editor: Editor, file: PsiFile, val target: KtExpression) : HighlightUsagesHandlerBase(editor, file) { + private class MyHandler(editor: Editor, file: PsiFile, val target: KtExpression) : + HighlightUsagesHandlerBase(editor, file) { override fun getTargets() = listOf(target) override fun selectTargets(targets: MutableList, selectionConsumer: Consumer>) { diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightImplicitItHandlerFactory.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightImplicitItHandlerFactory.kt index fd93115c4ca..8ba248cd6ce 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightImplicitItHandlerFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightImplicitItHandlerFactory.kt @@ -38,19 +38,19 @@ class KotlinHighlightImplicitItHandlerFactory : HighlightUsagesHandlerFactoryBas override fun getTargets() = listOf(refExpr) override fun selectTargets( - targets: MutableList, - selectionConsumer: Consumer> + targets: MutableList, + selectionConsumer: Consumer> ) = selectionConsumer.consume(targets) override fun computeUsages(targets: MutableList?) { lambda.accept( - object : KtTreeVisitorVoid() { - override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) { - if (expression is KtNameReferenceExpression && getLambdaByImplicitItReference(expression) == lambda) { - addOccurrence(expression) - } + object : KtTreeVisitorVoid() { + override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) { + if (expression is KtNameReferenceExpression && getLambdaByImplicitItReference(expression) == lambda) { + addOccurrence(expression) } } + } ) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt index 53d0f29d2b0..7e553048473 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt @@ -62,7 +62,12 @@ class KotlinRecursiveCallLineMarkerProvider : LineMarkerProvider { private fun getEnclosingFunction(element: KtElement, stopOnNonInlinedLambdas: Boolean): KtNamedFunction? { for (parent in element.parents) { when (parent) { - is KtFunctionLiteral -> if (stopOnNonInlinedLambdas && !InlineUtil.isInlinedArgument(parent, parent.analyze(), false)) return null + is KtFunctionLiteral -> if (stopOnNonInlinedLambdas && !InlineUtil.isInlinedArgument( + parent, + parent.analyze(), + false + ) + ) return null is KtNamedFunction -> { when (parent.parent) { is KtBlockExpression, is KtClassBody, is KtFile, is KtScript -> return parent @@ -84,7 +89,8 @@ class KotlinRecursiveCallLineMarkerProvider : LineMarkerProvider { val enclosingFunctionName = enclosingFunction.name if (enclosingFunctionName != OperatorNameConventions.INVOKE.asString() - && enclosingFunctionName != resolveName.asString()) return false + && enclosingFunctionName != resolveName.asString() + ) return false // Check that there were no not-inlined lambdas on the way to enclosing function if (enclosingFunction != getEnclosingFunction(element, true)) return false @@ -113,15 +119,14 @@ class KotlinRecursiveCallLineMarkerProvider : LineMarkerProvider { return true } - private class RecursiveMethodCallMarkerInfo(callElement: PsiElement) - : LineMarkerInfo( - callElement, - callElement.textRange, - AllIcons.Gutter.RecursiveMethod, - Pass.LINE_MARKERS, - { "Recursive call" }, - null, - GutterIconRenderer.Alignment.RIGHT + private class RecursiveMethodCallMarkerInfo(callElement: PsiElement) : LineMarkerInfo( + callElement, + callElement.textRange, + AllIcons.Gutter.RecursiveMethod, + Pass.LINE_MARKERS, + { "Recursive call" }, + null, + GutterIconRenderer.Alignment.RIGHT ) { override fun createGutterRenderer(): GutterIconRenderer? { @@ -134,13 +139,13 @@ class KotlinRecursiveCallLineMarkerProvider : LineMarkerProvider { } internal fun getElementForLineMark(callElement: PsiElement): PsiElement = - when (callElement) { - is KtSimpleNameExpression -> callElement.getReferencedNameElement() - else -> - // a fallback, - //but who knows what to reference in KtArrayAccessExpression ? - generateSequence(callElement, { it.firstChild }).last() - } + when (callElement) { + is KtSimpleNameExpression -> callElement.getReferencedNameElement() + else -> + // a fallback, + //but who knows what to reference in KtArrayAccessExpression ? + generateSequence(callElement, { it.firstChild }).last() + } private fun PsiElement.getLineNumber(): Int { return PsiDocumentManager.getInstance(project).getDocument(containingFile)!!.getLineNumber(textOffset) @@ -158,13 +163,12 @@ private fun getCallNameFromPsi(element: KtElement): Name? { val node = operationReference.getReferencedNameElementType() return if (node is KtToken) { val conventionName = if (elementParent is KtPrefixExpression) - OperatorConventions.getNameForOperationSymbol(node, true, false) + OperatorConventions.getNameForOperationSymbol(node, true, false) else OperatorConventions.getNameForOperationSymbol(node) conventionName ?: Name.identifier(element.getText()) - } - else { + } else { Name.identifier(element.getText()) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt.172 b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt.172 index 231be8d8fc5..dfb6c46646c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt.172 +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt.172 @@ -62,7 +62,12 @@ class KotlinRecursiveCallLineMarkerProvider : LineMarkerProvider { private fun getEnclosingFunction(element: KtElement, stopOnNonInlinedLambdas: Boolean): KtNamedFunction? { for (parent in element.parents) { when (parent) { - is KtFunctionLiteral -> if (stopOnNonInlinedLambdas && !InlineUtil.isInlinedArgument(parent, parent.analyze(), false)) return null + is KtFunctionLiteral -> if (stopOnNonInlinedLambdas && !InlineUtil.isInlinedArgument( + parent, + parent.analyze(), + false + ) + ) return null is KtNamedFunction -> { when (parent.parent) { is KtBlockExpression, is KtClassBody, is KtFile, is KtScript -> return parent @@ -84,7 +89,8 @@ class KotlinRecursiveCallLineMarkerProvider : LineMarkerProvider { val enclosingFunctionName = enclosingFunction.name if (enclosingFunctionName != OperatorNameConventions.INVOKE.asString() - && enclosingFunctionName != resolveName.asString()) return false + && enclosingFunctionName != resolveName.asString() + ) return false // Check that there were no not-inlined lambdas on the way to enclosing function if (enclosingFunction != getEnclosingFunction(element, true)) return false @@ -113,15 +119,14 @@ class KotlinRecursiveCallLineMarkerProvider : LineMarkerProvider { return true } - private class RecursiveMethodCallMarkerInfo(callElement: KtElement) - : LineMarkerInfo( - callElement, - callElement.textRange, - AllIcons.Gutter.RecursiveMethod, - Pass.LINE_MARKERS, - { "Recursive call" }, - null, - GutterIconRenderer.Alignment.RIGHT + private class RecursiveMethodCallMarkerInfo(callElement: KtElement) : LineMarkerInfo( + callElement, + callElement.textRange, + AllIcons.Gutter.RecursiveMethod, + Pass.LINE_MARKERS, + { "Recursive call" }, + null, + GutterIconRenderer.Alignment.RIGHT ) { override fun createGutterRenderer(): GutterIconRenderer? { @@ -149,13 +154,12 @@ private fun getCallNameFromPsi(element: KtElement): Name? { val node = operationReference.getReferencedNameElementType() return if (node is KtToken) { val conventionName = if (elementParent is KtPrefixExpression) - OperatorConventions.getNameForOperationSymbol(node, true, false) + OperatorConventions.getNameForOperationSymbol(node, true, false) else OperatorConventions.getNameForOperationSymbol(node) conventionName ?: Name.identifier(element.getText()) - } - else { + } else { Name.identifier(element.getText()) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt index e6dcccbd68b..93d2c77ba4b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt @@ -23,19 +23,18 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext.* import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall -import org.jetbrains.kotlin.resolve.calls.checkers.isBuiltInCoroutineContext import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider { private class SuspendCallMarkerInfo(callElement: PsiElement, message: String) : LineMarkerInfo( - callElement, - callElement.textRange, - KotlinIcons.SUSPEND_CALL, - Pass.LINE_MARKERS, - { message }, - null, - GutterIconRenderer.Alignment.RIGHT + callElement, + callElement.textRange, + KotlinIcons.SUSPEND_CALL, + Pass.LINE_MARKERS, + { message }, + null, + GutterIconRenderer.Alignment.RIGHT ) { override fun createGutterRenderer(): GutterIconRenderer? { return object : LineMarkerInfo.LineMarkerGutterIconRenderer(this) { @@ -47,8 +46,8 @@ class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider { override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? = null override fun collectSlowLineMarkers( - elements: MutableList, - result: MutableCollection> + elements: MutableList, + result: MutableCollection> ) { val markedLineNumbers = HashSet() diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt.172 b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt.172 index aa413b3cd83..26ad7843158 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt.172 +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuspendCallLineMarkerProvider.kt.172 @@ -29,13 +29,13 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider { private class SuspendCallMarkerInfo(callElement: KtElement, message: String) : LineMarkerInfo( - callElement, - callElement.textRange, - KotlinIcons.SUSPEND_CALL, - Pass.LINE_MARKERS, - { message }, - null, - GutterIconRenderer.Alignment.RIGHT + callElement, + callElement.textRange, + KotlinIcons.SUSPEND_CALL, + Pass.LINE_MARKERS, + { message }, + null, + GutterIconRenderer.Alignment.RIGHT ) { override fun createGutterRenderer(): GutterIconRenderer? { return object : LineMarkerInfo.LineMarkerGutterIconRenderer(this) { @@ -47,8 +47,8 @@ class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider { override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? = null override fun collectSlowLineMarkers( - elements: MutableList, - result: MutableCollection> + elements: MutableList, + result: MutableCollection> ) { val markedLineNumbers = HashSet() diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt index 47a992a3c98..51d54c037eb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinTestRunLineMarkerContributor.kt @@ -95,7 +95,7 @@ class KotlinTestRunLineMarkerContributor : RunLineMarkerContributor() { } private fun DeclarationDescriptor.isIgnored(): Boolean = - annotations.any { it.fqName == IGNORE_FQ_NAME } || ((containingDeclaration as? ClassDescriptor)?.isIgnored() ?: false) + annotations.any { it.fqName == IGNORE_FQ_NAME } || ((containingDeclaration as? ClassDescriptor)?.isIgnored() ?: false) private fun DeclarationDescriptor.isTest(): Boolean { if (isIgnored()) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/PlatformExpectedAnnotator.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/PlatformExpectedAnnotator.kt index 0b582f1e7da..f5a7155dda6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/PlatformExpectedAnnotator.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/PlatformExpectedAnnotator.kt @@ -51,8 +51,10 @@ class PlatformExpectedAnnotator : Annotator { val trace = BindingTraceContext() for (module in implementingModules) { - ExpectedActualDeclarationChecker.checkExpectedDeclarationHasActual(declaration, descriptor, trace, module, - ExpectActualTracker.DoNothing) + ExpectedActualDeclarationChecker.checkExpectedDeclarationHasActual( + declaration, descriptor, trace, module, + ExpectActualTracker.DoNothing + ) } val suppressionCache = KotlinCacheService.getInstance(declaration.project).getSuppressionCache() @@ -66,6 +68,6 @@ class PlatformExpectedAnnotator : Annotator { private fun isExpectedDeclaration(declaration: KtDeclaration): Boolean { return declaration.hasExpectModifier() || - declaration is KtClassOrObject && KtPsiUtil.getOutermostClassOrObject(declaration)?.hasExpectModifier() == true + declaration is KtClassOrObject && KtPsiUtil.getOutermostClassOrObject(declaration)?.hasExpectModifier() == true } } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/HasActualMarker.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/HasActualMarker.kt index 8dc650dcc37..fef9c813622 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/HasActualMarker.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/HasActualMarker.kt @@ -51,9 +51,11 @@ fun navigateToPlatformActual(e: MouseEvent?, declaration: KtDeclaration?) { val renderer = object : DefaultPsiElementCellRenderer() { override fun getContainerText(element: PsiElement?, name: String?) = "" } - PsiElementListNavigator.openTargets(e, - actualDeclarations.toTypedArray(), - "Choose actual for ${declaration.name}", - "Actuals for ${declaration.name}", - renderer) + PsiElementListNavigator.openTargets( + e, + actualDeclarations.toTypedArray(), + "Choose actual for ${declaration.name}", + "Actuals for ${declaration.name}", + renderer + ) } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/JavaPsiUtils.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/JavaPsiUtils.kt index cd7c0500ca2..9008c5c7cfc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/JavaPsiUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/JavaPsiUtils.kt @@ -21,10 +21,14 @@ import com.intellij.psi.CommonClassNames import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod -import org.jetbrains.kotlin.asJava.* +import org.jetbrains.kotlin.asJava.LightClassUtil +import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.idea.caches.lightClasses.KtFakeLightClass import org.jetbrains.kotlin.idea.caches.lightClasses.KtFakeLightMethod -import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtFunction +import org.jetbrains.kotlin.psi.KtNamedFunction +import org.jetbrains.kotlin.psi.KtSecondaryConstructor import java.util.* fun collectContainingClasses(methods: Collection): Set { diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt index c20bcdcdedf..422c02a0414 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt @@ -57,7 +57,8 @@ class KotlinLineMarkerProvider : LineMarkerProvider { if (element.canHaveSeparator()) { val prevSibling = element.getPrevSiblingIgnoringWhitespaceAndComments() if (prevSibling.canHaveSeparator() && - (element.wantsSeparator() || prevSibling?.wantsSeparator() == true)) { + (element.wantsSeparator() || prevSibling?.wantsSeparator() == true) + ) { return createLineSeparatorByElement(element) } } @@ -122,8 +123,7 @@ class KotlinLineMarkerProvider : LineMarkerProvider { if (element.isExpectDeclaration()) { collectActualMarkers(element, result) - } - else if (element.isEffectivelyActual()) { + } else if (element.isEffectivelyActual()) { collectExpectedMarkers(element, result) } } @@ -136,11 +136,11 @@ private val OVERRIDDEN_MARK: Icon = AllIcons.Gutter.OverridenMethod private val IMPLEMENTED_MARK: Icon = AllIcons.Gutter.ImplementedMethod data class NavigationPopupDescriptor( - val targets: Collection, - val title: String, - val findUsagesTitle: String, - val renderer: ListCellRenderer<*>, - val updater: ListBackgroundUpdaterTask? = null + val targets: Collection, + val title: String, + val findUsagesTitle: String, + val renderer: ListCellRenderer<*>, + val updater: ListBackgroundUpdaterTask? = null ) { fun showPopup(e: MouseEvent?) { PsiElementListNavigator.openTargets(e, targets.toTypedArray(), title, findUsagesTitle, renderer, updater) @@ -151,7 +151,7 @@ interface TestableLineMarkerNavigator { fun getTargetsPopupDescriptor(element: PsiElement?): NavigationPopupDescriptor? } -private class SubclassRenderer: PsiClassOrFunctionalExpressionListCellRenderer() { +private class SubclassRenderer : PsiClassOrFunctionalExpressionListCellRenderer() { override fun getComparingObject(element: NavigatablePsiElement?): Comparable { val baseText = super.getComparingObject(element) val moduleName = element?.module?.name ?: return baseText @@ -160,22 +160,22 @@ private class SubclassRenderer: PsiClassOrFunctionalExpressionListCellRenderer() } private val SUBCLASSED_CLASS = MarkerType( - "SUBCLASSED_CLASS", - { getPsiClass(it)?.let { MarkerType.getSubclassedClassTooltip(it) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - getPsiClass(element)?.let { MarkerType.navigateToSubclassedClass(e, it, SubclassRenderer()) } - } - }) + "SUBCLASSED_CLASS", + { getPsiClass(it)?.let { MarkerType.getSubclassedClassTooltip(it) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + getPsiClass(element)?.let { MarkerType.navigateToSubclassedClass(e, it, SubclassRenderer()) } + } + }) private val OVERRIDDEN_FUNCTION = object : MarkerType( - "OVERRIDDEN_FUNCTION", - { getPsiMethod(it)?.let(::getOverriddenMethodTooltip) }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - buildNavigateToOverriddenMethodPopup(e, element)?.showPopup(e) - } - }) { + "OVERRIDDEN_FUNCTION", + { getPsiMethod(it)?.let(::getOverriddenMethodTooltip) }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + buildNavigateToOverriddenMethodPopup(e, element)?.showPopup(e) + } + }) { override fun getNavigationHandler(): GutterIconNavigationHandler { val superHandler = super.getNavigationHandler() @@ -190,13 +190,13 @@ private val OVERRIDDEN_FUNCTION = object : MarkerType( } private val OVERRIDDEN_PROPERTY = object : MarkerType( - "OVERRIDDEN_PROPERTY", - { it?.let { getOverriddenPropertyTooltip(it.parent as KtNamedDeclaration) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - buildNavigateToPropertyOverriddenDeclarationsPopup(e, element)?.showPopup(e) - } - }) { + "OVERRIDDEN_PROPERTY", + { it?.let { getOverriddenPropertyTooltip(it.parent as KtNamedDeclaration) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + buildNavigateToPropertyOverriddenDeclarationsPopup(e, element)?.showPopup(e) + } + }) { override fun getNavigationHandler(): GutterIconNavigationHandler { val superHandler = super.getNavigationHandler() @@ -214,26 +214,29 @@ private val PsiElement.markerDeclaration get() = (this as? KtDeclaration) ?: (parent as? KtDeclaration) private val PLATFORM_ACTUAL = MarkerType( - "PLATFORM_ACTUAL", - { it?.let { getPlatformActualTooltip(it.markerDeclaration) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - element?.let { navigateToPlatformActual(e, it.markerDeclaration) } - } + "PLATFORM_ACTUAL", + { it?.let { getPlatformActualTooltip(it.markerDeclaration) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + element?.let { navigateToPlatformActual(e, it.markerDeclaration) } } + } ) private val EXPECTED_DECLARATION = MarkerType( - "EXPECTED_DECLARATION", - { it?.let { getExpectedDeclarationTooltip(it.markerDeclaration) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - element?.let { navigateToExpectedDeclaration(it.markerDeclaration) } - } + "EXPECTED_DECLARATION", + { it?.let { getExpectedDeclarationTooltip(it.markerDeclaration) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + element?.let { navigateToExpectedDeclaration(it.markerDeclaration) } } + } ) -private fun isImplementsAndNotOverrides(descriptor: CallableMemberDescriptor, overriddenMembers: Collection): Boolean { +private fun isImplementsAndNotOverrides( + descriptor: CallableMemberDescriptor, + overriddenMembers: Collection +): Boolean { return descriptor.modality != Modality.ABSTRACT && overriddenMembers.all { it.modality == Modality.ABSTRACT } } @@ -297,8 +300,10 @@ private fun collectInheritedClassMarker(element: KtClass, result: MutableCollect result.add(lineMarkerInfo) } -private fun collectOverriddenPropertyAccessors(properties: Collection, - result: MutableCollection>) { +private fun collectOverriddenPropertyAccessors( + properties: Collection, + result: MutableCollection> +) { val mappingToJava = HashMap() for (property in properties) { if (property.isOverridable()) { @@ -335,13 +340,15 @@ private fun collectOverriddenPropertyAccessors(properties: Collection)?.let { - it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis - } - ?: this + ?: (this as? KtConstructor<*>)?.let { + it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis + } + ?: this -private fun collectActualMarkers(declaration: KtNamedDeclaration, - result: MutableCollection>) { +private fun collectActualMarkers( + declaration: KtNamedDeclaration, + result: MutableCollection> +) { val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return val commonModuleDescriptor = declaration.containingKtFile.findModuleDescriptor() @@ -367,8 +374,10 @@ private fun collectActualMarkers(declaration: KtNamedDeclaration, result.add(lineMarkerInfo) } -private fun collectExpectedMarkers(declaration: KtNamedDeclaration, - result: MutableCollection>) { +private fun collectExpectedMarkers( + declaration: KtNamedDeclaration, + result: MutableCollection> +) { val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return val platformModuleDescriptor = declaration.containingKtFile.findModuleDescriptor() diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt.172 b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt.172 index 1e62f57f4bc..76606fa260f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt.172 +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt.172 @@ -56,7 +56,8 @@ class KotlinLineMarkerProvider : LineMarkerProvider { if (element.canHaveSeparator()) { val prevSibling = element.getPrevSiblingIgnoringWhitespaceAndComments() if (prevSibling.canHaveSeparator() && - (element.wantsSeparator() || prevSibling?.wantsSeparator() == true)) { + (element.wantsSeparator() || prevSibling?.wantsSeparator() == true) + ) { return createLineSeparatorByElement(element) } } @@ -121,8 +122,7 @@ class KotlinLineMarkerProvider : LineMarkerProvider { if (element.isExpectDeclaration()) { collectActualMarkers(element, result) - } - else if (element.isEffectivelyActual()) { + } else if (element.isEffectivelyActual()) { collectExpectedMarkers(element, result) } } @@ -135,11 +135,11 @@ private val OVERRIDDEN_MARK: Icon = AllIcons.Gutter.OverridenMethod private val IMPLEMENTED_MARK: Icon = AllIcons.Gutter.ImplementedMethod data class NavigationPopupDescriptor( - val targets: Collection, - val title: String, - val findUsagesTitle: String, - val renderer: ListCellRenderer<*>, - val updater: ListBackgroundUpdaterTask? = null + val targets: Collection, + val title: String, + val findUsagesTitle: String, + val renderer: ListCellRenderer<*>, + val updater: ListBackgroundUpdaterTask? = null ) { fun showPopup(e: MouseEvent?) { PsiElementListNavigator.openTargets(e, targets.toTypedArray(), title, findUsagesTitle, renderer, updater) @@ -151,22 +151,22 @@ interface TestableLineMarkerNavigator { } private val SUBCLASSED_CLASS = MarkerType( - "SUBCLASSED_CLASS", - { getPsiClass(it)?.let { MarkerType.getSubclassedClassTooltip(it) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - getPsiClass(element)?.let { MarkerType.navigateToSubclassedClass(e, it) } - } - }) + "SUBCLASSED_CLASS", + { getPsiClass(it)?.let { MarkerType.getSubclassedClassTooltip(it) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + getPsiClass(element)?.let { MarkerType.navigateToSubclassedClass(e, it) } + } + }) private val OVERRIDDEN_FUNCTION = object : MarkerType( - "OVERRIDDEN_FUNCTION", - { getPsiMethod(it)?.let(::getOverriddenMethodTooltip) }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - buildNavigateToOverriddenMethodPopup(e, element)?.showPopup(e) - } - }) { + "OVERRIDDEN_FUNCTION", + { getPsiMethod(it)?.let(::getOverriddenMethodTooltip) }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + buildNavigateToOverriddenMethodPopup(e, element)?.showPopup(e) + } + }) { override fun getNavigationHandler(): GutterIconNavigationHandler { val superHandler = super.getNavigationHandler() @@ -181,13 +181,13 @@ private val OVERRIDDEN_FUNCTION = object : MarkerType( } private val OVERRIDDEN_PROPERTY = object : MarkerType( - "OVERRIDDEN_PROPERTY", - { it?.let { getOverriddenPropertyTooltip(it.parent as KtNamedDeclaration) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - buildNavigateToPropertyOverriddenDeclarationsPopup(e, element)?.showPopup(e) - } - }) { + "OVERRIDDEN_PROPERTY", + { it?.let { getOverriddenPropertyTooltip(it.parent as KtNamedDeclaration) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + buildNavigateToPropertyOverriddenDeclarationsPopup(e, element)?.showPopup(e) + } + }) { override fun getNavigationHandler(): GutterIconNavigationHandler { val superHandler = super.getNavigationHandler() @@ -205,26 +205,29 @@ private val PsiElement.markerDeclaration get() = (this as? KtDeclaration) ?: (parent as? KtDeclaration) private val PLATFORM_ACTUAL = MarkerType( - "PLATFORM_ACTUAL", - { it?.let { getPlatformActualTooltip(it.markerDeclaration) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - element?.let { navigateToPlatformActual(e, it.markerDeclaration) } - } + "PLATFORM_ACTUAL", + { it?.let { getPlatformActualTooltip(it.markerDeclaration) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + element?.let { navigateToPlatformActual(e, it.markerDeclaration) } } + } ) private val EXPECTED_DECLARATION = MarkerType( - "EXPECTED_DECLARATION", - { it?.let { getExpectedDeclarationTooltip(it.markerDeclaration) } }, - object : LineMarkerNavigator() { - override fun browse(e: MouseEvent?, element: PsiElement?) { - element?.let { navigateToExpectedDeclaration(it.markerDeclaration) } - } + "EXPECTED_DECLARATION", + { it?.let { getExpectedDeclarationTooltip(it.markerDeclaration) } }, + object : LineMarkerNavigator() { + override fun browse(e: MouseEvent?, element: PsiElement?) { + element?.let { navigateToExpectedDeclaration(it.markerDeclaration) } } + } ) -private fun isImplementsAndNotOverrides(descriptor: CallableMemberDescriptor, overriddenMembers: Collection): Boolean { +private fun isImplementsAndNotOverrides( + descriptor: CallableMemberDescriptor, + overriddenMembers: Collection +): Boolean { return descriptor.modality != Modality.ABSTRACT && overriddenMembers.all { it.modality == Modality.ABSTRACT } } @@ -288,8 +291,10 @@ private fun collectInheritedClassMarker(element: KtClass, result: MutableCollect result.add(lineMarkerInfo) } -private fun collectOverriddenPropertyAccessors(properties: Collection, - result: MutableCollection>) { +private fun collectOverriddenPropertyAccessors( + properties: Collection, + result: MutableCollection> +) { val mappingToJava = HashMap() for (property in properties) { if (property.isOverridable()) { @@ -326,13 +331,15 @@ private fun collectOverriddenPropertyAccessors(properties: Collection)?.let { - it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis - } - ?: this + ?: (this as? KtConstructor<*>)?.let { + it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis + } + ?: this -private fun collectActualMarkers(declaration: KtNamedDeclaration, - result: MutableCollection>) { +private fun collectActualMarkers( + declaration: KtNamedDeclaration, + result: MutableCollection> +) { val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return val commonModuleDescriptor = declaration.containingKtFile.findModuleDescriptor() @@ -358,8 +365,10 @@ private fun collectActualMarkers(declaration: KtNamedDeclaration, result.add(lineMarkerInfo) } -private fun collectExpectedMarkers(declaration: KtNamedDeclaration, - result: MutableCollection>) { +private fun collectExpectedMarkers( + declaration: KtNamedDeclaration, + result: MutableCollection> +) { val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return val platformModuleDescriptor = declaration.containingKtFile.findModuleDescriptor() diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenFunctionMarker.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenFunctionMarker.kt index 3c2dbb81dcb..186610549aa 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenFunctionMarker.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenFunctionMarker.kt @@ -30,7 +30,6 @@ import com.intellij.psi.PsiMethod import com.intellij.psi.PsiModifier import com.intellij.psi.search.PsiElementProcessor import com.intellij.psi.search.PsiElementProcessorAdapter -import com.intellij.psi.search.searches.OverridingMethodsSearch import com.intellij.util.CommonProcessors import gnu.trove.THashSet import org.jetbrains.kotlin.asJava.elements.KtLightMethod @@ -91,7 +90,8 @@ fun buildNavigateToOverriddenMethodPopup(e: MouseEvent?, element: PsiElement?): val method = getPsiMethod(element) ?: return null if (DumbService.isDumb(method.project)) { - DumbService.getInstance(method.project)?.showDumbModeNotification("Navigation to overriding classes is not possible during index update") + DumbService.getInstance(method.project) + ?.showDumbModeNotification("Navigation to overriding classes is not possible during index update") return null } @@ -104,7 +104,9 @@ fun buildNavigateToOverriddenMethodPopup(e: MouseEvent?, element: PsiElement?): } } }, - "Searching for overriding declarations", true, method.project, e?.component as JComponent?)) { + "Searching for overriding declarations", true, method.project, e?.component as JComponent? + ) + ) { return null } @@ -115,17 +117,20 @@ fun buildNavigateToOverriddenMethodPopup(e: MouseEvent?, element: PsiElement?): overridingJavaMethods = overridingJavaMethods.sortedWith(renderer.comparator) val methodsUpdater = OverridingMethodsUpdater(method, renderer) - return NavigationPopupDescriptor(overridingJavaMethods, - methodsUpdater.getCaption(overridingJavaMethods.size), - "Overriding declarations of " + method.name, - renderer, - methodsUpdater) + return NavigationPopupDescriptor( + overridingJavaMethods, + methodsUpdater.getCaption(overridingJavaMethods.size), + "Overriding declarations of " + method.name, + renderer, + methodsUpdater + ) } private class OverridingMethodsUpdater( - private val myMethod: PsiMethod, - private val myRenderer: PsiElementListCellRenderer) : - ListBackgroundUpdaterTask(myMethod.project, "Searching for overriding methods") { + private val myMethod: PsiMethod, + private val myRenderer: PsiElementListCellRenderer +) : + ListBackgroundUpdaterTask(myMethod.project, "Searching for overriding methods") { override fun getCaption(size: Int): String { return if (myMethod.hasModifierProperty(PsiModifier.ABSTRACT)) DaemonBundle.message("navigation.title.implementation.method", myMethod.name, size)!! diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt index 771b2dec511..c825f0531f3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt @@ -29,11 +29,9 @@ import com.intellij.psi.PsiMethod import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.PsiElementProcessor import com.intellij.psi.search.PsiElementProcessorAdapter -import com.intellij.psi.search.searches.OverridingMethodsSearch import com.intellij.util.AdapterProcessor import com.intellij.util.CommonProcessors import com.intellij.util.Function -import org.jetbrains.kotlin.asJava.getAccessorLightMethods import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.search.declarationsSearch.forEachOverridingMethod import org.jetbrains.kotlin.idea.search.declarationsSearch.toPossiblyFakeLightMethods @@ -47,8 +45,8 @@ fun getOverriddenPropertyTooltip(property: KtNamedDeclaration): String? { val overriddenInClassesProcessor = PsiElementProcessor.CollectElementsWithLimit(5) val consumer = AdapterProcessor( - CommonProcessors.UniqueProcessor(PsiElementProcessorAdapter(overriddenInClassesProcessor)), - Function { method: PsiMethod? -> method?.containingClass } + CommonProcessors.UniqueProcessor(PsiElementProcessorAdapter(overriddenInClassesProcessor)), + Function { method: PsiMethod? -> method?.containingClass } ) for (method in property.toPossiblyFakeLightMethods()) { @@ -90,28 +88,33 @@ fun buildNavigateToPropertyOverriddenDeclarationsPopup(e: MouseEvent?, element: val elementProcessor = CommonProcessors.CollectUniquesProcessor() val ktPsiMethodProcessor = Runnable { KotlinDefinitionsSearcher.processPropertyImplementationsMethods( - psiPropertyMethods, - GlobalSearchScope.allScope(project), - elementProcessor) + psiPropertyMethods, + GlobalSearchScope.allScope(project), + elementProcessor + ) } if (!ProgressManager.getInstance().runProcessWithProgressSynchronously( /* runnable */ ktPsiMethodProcessor, - MarkerType.SEARCHING_FOR_OVERRIDING_METHODS, + MarkerType.SEARCHING_FOR_OVERRIDING_METHODS, /* can be canceled */ true, - project, - e?.component as JComponent?)) { + project, + e?.component as JComponent? + ) + ) { return null } val renderer = DefaultPsiElementCellRenderer() val navigatingOverrides = elementProcessor.results - .sortedWith(renderer.comparator) - .filterIsInstance() + .sortedWith(renderer.comparator) + .filterIsInstance() - return NavigationPopupDescriptor(navigatingOverrides, - KotlinBundle.message("navigation.title.overriding.property", propertyOrParameter.name), - KotlinBundle.message("navigation.findUsages.title.overriding.property", propertyOrParameter.name), renderer) + return NavigationPopupDescriptor( + navigatingOverrides, + KotlinBundle.message("navigation.title.overriding.property", propertyOrParameter.name), + KotlinBundle.message("navigation.findUsages.title.overriding.property", propertyOrParameter.name), renderer + ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt index 885aea1b1b3..ab01c0f135f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/SuperDeclarationMarker.kt @@ -38,7 +38,7 @@ import org.jetbrains.kotlin.renderer.RenderingFormat import java.awt.event.MouseEvent import java.util.* -object SuperDeclarationMarkerTooltip: Function { +object SuperDeclarationMarkerTooltip : Function { override fun `fun`(element: PsiElement): String? { val ktDeclaration = element.getParentOfType(false) ?: return null val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(ktDeclaration!!) @@ -83,16 +83,19 @@ class SuperDeclarationMarkerNavigationHandler : GutterIconNavigationHandler) + val descriptor: CallableMemberDescriptor?, + val overriddenDescriptors: Collection +) fun resolveDeclarationWithParents(element: KtDeclaration): ResolveWithParentsResult { val descriptor = if (element is KtParameter)