Reformat: idea.highlighter package
This commit is contained in:
@@ -103,8 +103,7 @@ var <PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCounter</MUTABLE_VARIABLE></PACKAG
|
||||
if (Modifier.isStatic(field.modifiers)) {
|
||||
try {
|
||||
map.put(field.name, field.get(null) as TextAttributesKey)
|
||||
}
|
||||
catch (e: IllegalAccessException) {
|
||||
} catch (e: IllegalAccessException) {
|
||||
assert(false)
|
||||
}
|
||||
|
||||
@@ -118,66 +117,68 @@ var <PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCounter</MUTABLE_VARIABLE></PACKAG
|
||||
|
||||
override fun getAttributeDescriptors(): Array<AttributesDescriptor> {
|
||||
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> = ColorDescriptor.EMPTY_ARRAY
|
||||
@@ -185,6 +186,6 @@ var <PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCounter</MUTABLE_VARIABLE></PACKAG
|
||||
|
||||
override fun isRainbowType(type: TextAttributesKey): Boolean {
|
||||
return type == KotlinHighlightingColors.LOCAL_VARIABLE ||
|
||||
type == KotlinHighlightingColors.PARAMETER
|
||||
type == KotlinHighlightingColors.PARAMETER
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -40,9 +40,9 @@ class KotlinHighlightExitPointsHandlerFactory : HighlightUsagesHandlerFactoryBas
|
||||
override fun createHighlightUsagesHandler(editor: Editor, file: PsiFile, target: PsiElement): HighlightUsagesHandlerBase<*>? {
|
||||
if (target is LeafPsiElement && (target.elementType in RETURN_AND_THROW)) {
|
||||
val returnOrThrow = PsiTreeUtil.getParentOfType<KtExpression>(
|
||||
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<PsiElement>(editor, file) {
|
||||
private class MyHandler(editor: Editor, file: PsiFile, val target: KtExpression) :
|
||||
HighlightUsagesHandlerBase<PsiElement>(editor, file) {
|
||||
override fun getTargets() = listOf(target)
|
||||
|
||||
override fun selectTargets(targets: MutableList<PsiElement>, selectionConsumer: Consumer<MutableList<PsiElement>>) {
|
||||
|
||||
+7
-7
@@ -38,19 +38,19 @@ class KotlinHighlightImplicitItHandlerFactory : HighlightUsagesHandlerFactoryBas
|
||||
override fun getTargets() = listOf(refExpr)
|
||||
|
||||
override fun selectTargets(
|
||||
targets: MutableList<KtNameReferenceExpression>,
|
||||
selectionConsumer: Consumer<MutableList<KtNameReferenceExpression>>
|
||||
targets: MutableList<KtNameReferenceExpression>,
|
||||
selectionConsumer: Consumer<MutableList<KtNameReferenceExpression>>
|
||||
) = selectionConsumer.consume(targets)
|
||||
|
||||
override fun computeUsages(targets: MutableList<KtNameReferenceExpression>?) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+25
-21
@@ -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<PsiElement>(
|
||||
callElement,
|
||||
callElement.textRange,
|
||||
AllIcons.Gutter.RecursiveMethod,
|
||||
Pass.LINE_MARKERS,
|
||||
{ "Recursive call" },
|
||||
null,
|
||||
GutterIconRenderer.Alignment.RIGHT
|
||||
private class RecursiveMethodCallMarkerInfo(callElement: PsiElement) : LineMarkerInfo<PsiElement>(
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
+18
-14
@@ -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<KtElement>(
|
||||
callElement,
|
||||
callElement.textRange,
|
||||
AllIcons.Gutter.RecursiveMethod,
|
||||
Pass.LINE_MARKERS,
|
||||
{ "Recursive call" },
|
||||
null,
|
||||
GutterIconRenderer.Alignment.RIGHT
|
||||
private class RecursiveMethodCallMarkerInfo(callElement: KtElement) : LineMarkerInfo<KtElement>(
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
+9
-10
@@ -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<PsiElement>(
|
||||
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<PsiElement>(this) {
|
||||
@@ -47,8 +46,8 @@ class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider {
|
||||
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? = null
|
||||
|
||||
override fun collectSlowLineMarkers(
|
||||
elements: MutableList<PsiElement>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
elements: MutableList<PsiElement>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
val markedLineNumbers = HashSet<Int>()
|
||||
|
||||
|
||||
+9
-9
@@ -29,13 +29,13 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider {
|
||||
private class SuspendCallMarkerInfo(callElement: KtElement, message: String) : LineMarkerInfo<KtElement>(
|
||||
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<KtElement>(this) {
|
||||
@@ -47,8 +47,8 @@ class KotlinSuspendCallLineMarkerProvider : LineMarkerProvider {
|
||||
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? = null
|
||||
|
||||
override fun collectSlowLineMarkers(
|
||||
elements: MutableList<PsiElement>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
elements: MutableList<PsiElement>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
val markedLineNumbers = HashSet<Int>()
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
@@ -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<PsiMethod>): Set<PsiClass> {
|
||||
|
||||
+62
-53
@@ -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<NavigatablePsiElement>,
|
||||
val title: String,
|
||||
val findUsagesTitle: String,
|
||||
val renderer: ListCellRenderer<*>,
|
||||
val updater: ListBackgroundUpdaterTask? = null
|
||||
val targets: Collection<NavigatablePsiElement>,
|
||||
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<Nothing> {
|
||||
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<PsiElement> {
|
||||
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<PsiElement> {
|
||||
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<CallableMemberDescriptor>): Boolean {
|
||||
private fun isImplementsAndNotOverrides(
|
||||
descriptor: CallableMemberDescriptor,
|
||||
overriddenMembers: Collection<CallableMemberDescriptor>
|
||||
): 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<KtNamedDeclaration>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>) {
|
||||
private fun collectOverriddenPropertyAccessors(
|
||||
properties: Collection<KtNamedDeclaration>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
val mappingToJava = HashMap<PsiElement, KtNamedDeclaration>()
|
||||
for (property in properties) {
|
||||
if (property.isOverridable()) {
|
||||
@@ -335,13 +340,15 @@ private fun collectOverriddenPropertyAccessors(properties: Collection<KtNamedDec
|
||||
private val KtNamedDeclaration.expectOrActualAnchor
|
||||
get() =
|
||||
nameIdentifier
|
||||
?: (this as? KtConstructor<*>)?.let {
|
||||
it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis
|
||||
}
|
||||
?: this
|
||||
?: (this as? KtConstructor<*>)?.let {
|
||||
it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis
|
||||
}
|
||||
?: this
|
||||
|
||||
private fun collectActualMarkers(declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>) {
|
||||
private fun collectActualMarkers(
|
||||
declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
|
||||
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<LineMarkerInfo<*>>) {
|
||||
private fun collectExpectedMarkers(
|
||||
declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
|
||||
val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return
|
||||
val platformModuleDescriptor = declaration.containingKtFile.findModuleDescriptor()
|
||||
|
||||
+61
-52
@@ -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<NavigatablePsiElement>,
|
||||
val title: String,
|
||||
val findUsagesTitle: String,
|
||||
val renderer: ListCellRenderer<*>,
|
||||
val updater: ListBackgroundUpdaterTask? = null
|
||||
val targets: Collection<NavigatablePsiElement>,
|
||||
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<PsiElement> {
|
||||
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<PsiElement> {
|
||||
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<CallableMemberDescriptor>): Boolean {
|
||||
private fun isImplementsAndNotOverrides(
|
||||
descriptor: CallableMemberDescriptor,
|
||||
overriddenMembers: Collection<CallableMemberDescriptor>
|
||||
): 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<KtNamedDeclaration>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>) {
|
||||
private fun collectOverriddenPropertyAccessors(
|
||||
properties: Collection<KtNamedDeclaration>,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
val mappingToJava = HashMap<PsiElement, KtNamedDeclaration>()
|
||||
for (property in properties) {
|
||||
if (property.isOverridable()) {
|
||||
@@ -326,13 +331,15 @@ private fun collectOverriddenPropertyAccessors(properties: Collection<KtNamedDec
|
||||
private val KtNamedDeclaration.expectOrActualAnchor
|
||||
get() =
|
||||
nameIdentifier
|
||||
?: (this as? KtConstructor<*>)?.let {
|
||||
it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis
|
||||
}
|
||||
?: this
|
||||
?: (this as? KtConstructor<*>)?.let {
|
||||
it.getConstructorKeyword() ?: it.getValueParameterList()?.leftParenthesis
|
||||
}
|
||||
?: this
|
||||
|
||||
private fun collectActualMarkers(declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>) {
|
||||
private fun collectActualMarkers(
|
||||
declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
|
||||
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<LineMarkerInfo<*>>) {
|
||||
private fun collectExpectedMarkers(
|
||||
declaration: KtNamedDeclaration,
|
||||
result: MutableCollection<LineMarkerInfo<*>>
|
||||
) {
|
||||
|
||||
val descriptor = declaration.toDescriptor() as? MemberDescriptor ?: return
|
||||
val platformModuleDescriptor = declaration.containingKtFile.findModuleDescriptor()
|
||||
|
||||
@@ -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<out PsiElement>) :
|
||||
ListBackgroundUpdaterTask(myMethod.project, "Searching for overriding methods") {
|
||||
private val myMethod: PsiMethod,
|
||||
private val myRenderer: PsiElementListCellRenderer<out PsiElement>
|
||||
) :
|
||||
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)!!
|
||||
|
||||
@@ -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<PsiClass>(5)
|
||||
|
||||
val consumer = AdapterProcessor<PsiMethod, PsiClass>(
|
||||
CommonProcessors.UniqueProcessor<PsiClass>(PsiElementProcessorAdapter(overriddenInClassesProcessor)),
|
||||
Function { method: PsiMethod? -> method?.containingClass }
|
||||
CommonProcessors.UniqueProcessor<PsiClass>(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<PsiElement>()
|
||||
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<NavigatablePsiElement>()
|
||||
.sortedWith(renderer.comparator)
|
||||
.filterIsInstance<NavigatablePsiElement>()
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.renderer.RenderingFormat
|
||||
import java.awt.event.MouseEvent
|
||||
import java.util.*
|
||||
|
||||
object SuperDeclarationMarkerTooltip: Function<PsiElement, String> {
|
||||
object SuperDeclarationMarkerTooltip : Function<PsiElement, String> {
|
||||
override fun `fun`(element: PsiElement): String? {
|
||||
val ktDeclaration = element.getParentOfType<KtDeclaration>(false) ?: return null
|
||||
val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(ktDeclaration!!)
|
||||
@@ -83,16 +83,19 @@ class SuperDeclarationMarkerNavigationHandler : GutterIconNavigationHandler<PsiE
|
||||
}
|
||||
|
||||
val elementName = elementDescriptor!!.name
|
||||
return NavigationPopupDescriptor(superDeclarations,
|
||||
KotlinBundle.message("navigation.title.super.declaration", elementName),
|
||||
KotlinBundle.message("navigation.findUsages.title.super.declaration", elementName),
|
||||
KtFunctionPsiElementCellRenderer())
|
||||
return NavigationPopupDescriptor(
|
||||
superDeclarations,
|
||||
KotlinBundle.message("navigation.title.super.declaration", elementName),
|
||||
KotlinBundle.message("navigation.findUsages.title.super.declaration", elementName),
|
||||
KtFunctionPsiElementCellRenderer()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class ResolveWithParentsResult(
|
||||
val descriptor: CallableMemberDescriptor?,
|
||||
val overriddenDescriptors: Collection<CallableMemberDescriptor>)
|
||||
val descriptor: CallableMemberDescriptor?,
|
||||
val overriddenDescriptors: Collection<CallableMemberDescriptor>
|
||||
)
|
||||
|
||||
fun resolveDeclarationWithParents(element: KtDeclaration): ResolveWithParentsResult {
|
||||
val descriptor = if (element is KtParameter)
|
||||
|
||||
Reference in New Issue
Block a user