Code cleanup: KotlinPsiChecker
This commit is contained in:
@@ -79,7 +79,7 @@ open class KotlinPsiChecker : Annotator, HighlightRangeExtension {
|
||||
return file is KtFile
|
||||
}
|
||||
|
||||
open protected fun shouldSuppressUnusedParameter(parameter: KtParameter): Boolean = false
|
||||
protected open fun shouldSuppressUnusedParameter(parameter: KtParameter): Boolean = false
|
||||
|
||||
fun annotateElement(element: PsiElement, holder: AnnotationHolder, diagnostics: Diagnostics) {
|
||||
val diagnosticsForElement = diagnostics.forElement(element)
|
||||
@@ -92,7 +92,9 @@ open class KotlinPsiChecker : Annotator, HighlightRangeExtension {
|
||||
if (diagnosticsForElement.isEmpty()) return
|
||||
|
||||
if (KotlinHighlightingUtil.shouldHighlightErrors(element)) {
|
||||
ElementAnnotator(element, holder, { param -> shouldSuppressUnusedParameter(param) }).registerDiagnosticsAnnotations(diagnosticsForElement)
|
||||
ElementAnnotator(element, holder) { param ->
|
||||
shouldSuppressUnusedParameter(param)
|
||||
}.registerDiagnosticsAnnotations(diagnosticsForElement)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +124,9 @@ private fun createQuickFixes(similarDiagnostics: Collection<Diagnostic>): MultiM
|
||||
val intentionActionsFactories = QuickFixes.getInstance().getActionFactories(factory)
|
||||
for (intentionActionsFactory in intentionActionsFactories) {
|
||||
val allProblemsActions = intentionActionsFactory.createActionsForAllProblems(similarDiagnostics)
|
||||
if (!allProblemsActions.isEmpty()) {
|
||||
if (allProblemsActions.isNotEmpty()) {
|
||||
actions.putValues(first, allProblemsActions)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (diagnostic in similarDiagnostics) {
|
||||
actions.putValues(diagnostic, intentionActionsFactory.createActions(diagnostic))
|
||||
}
|
||||
@@ -168,9 +169,11 @@ private object NoDeclarationDescriptorsChecker {
|
||||
when (type) {
|
||||
is Class<*> -> {
|
||||
if (DeclarationDescriptor::class.java.isAssignableFrom(type) || KotlinType::class.java.isAssignableFrom(type)) {
|
||||
LOG.error("QuickFix class ${field.declaringClass.name} contains field ${field.name} that holds ${type.simpleName}. "
|
||||
LOG.error(
|
||||
"QuickFix class ${field.declaringClass.name} contains field ${field.name} that holds ${type.simpleName}. "
|
||||
+ "This leads to holding too much memory through this quick-fix instance. "
|
||||
+ "Possible solution can be wrapping it using KotlinIntentionActionFactoryWithDelegate.")
|
||||
+ "Possible solution can be wrapping it using KotlinIntentionActionFactoryWithDelegate."
|
||||
)
|
||||
}
|
||||
|
||||
if (IntentionAction::class.java.isAssignableFrom(type)) {
|
||||
@@ -192,9 +195,11 @@ private object NoDeclarationDescriptorsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private class ElementAnnotator(private val element: PsiElement,
|
||||
private class ElementAnnotator(
|
||||
private val element: PsiElement,
|
||||
private val holder: AnnotationHolder,
|
||||
private val shouldSuppressUnusedParameter: (KtParameter) -> Boolean) {
|
||||
private val shouldSuppressUnusedParameter: (KtParameter) -> Boolean
|
||||
) {
|
||||
fun registerDiagnosticsAnnotations(diagnostics: Collection<Diagnostic>) {
|
||||
diagnostics.groupBy { it.factory }.forEach { group -> registerDiagnosticAnnotations(group.value) }
|
||||
}
|
||||
@@ -221,17 +226,20 @@ private class ElementAnnotator(private val element: PsiElement,
|
||||
if (reference is MultiRangeReference) {
|
||||
AnnotationPresentationInfo(
|
||||
ranges = reference.ranges.map { it.shiftRight(referenceExpression.textOffset) },
|
||||
highlightType = ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
|
||||
}
|
||||
else {
|
||||
highlightType = ProblemHighlightType.LIKE_UNKNOWN_SYMBOL
|
||||
)
|
||||
} else {
|
||||
AnnotationPresentationInfo(ranges, highlightType = ProblemHighlightType.LIKE_UNKNOWN_SYMBOL)
|
||||
}
|
||||
}
|
||||
|
||||
Errors.ILLEGAL_ESCAPE -> AnnotationPresentationInfo(ranges, textAttributes = KotlinHighlightingColors.INVALID_STRING_ESCAPE)
|
||||
Errors.ILLEGAL_ESCAPE -> AnnotationPresentationInfo(
|
||||
ranges, textAttributes = KotlinHighlightingColors.INVALID_STRING_ESCAPE
|
||||
)
|
||||
|
||||
Errors.REDECLARATION -> AnnotationPresentationInfo(
|
||||
ranges = listOf(diagnostic.textRanges.first()), nonDefaultMessage = "")
|
||||
ranges = listOf(diagnostic.textRanges.first()), nonDefaultMessage = ""
|
||||
)
|
||||
|
||||
else -> {
|
||||
AnnotationPresentationInfo(
|
||||
@@ -239,7 +247,8 @@ private class ElementAnnotator(private val element: PsiElement,
|
||||
highlightType = if (factory == Errors.INVISIBLE_REFERENCE)
|
||||
ProblemHighlightType.LIKE_UNKNOWN_SYMBOL
|
||||
else
|
||||
null)
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,8 +280,7 @@ private class ElementAnnotator(private val element: PsiElement,
|
||||
private fun setUpAnnotations(diagnostics: List<Diagnostic>, data: AnnotationPresentationInfo) {
|
||||
val fixesMap = try {
|
||||
createQuickFixes(diagnostics)
|
||||
}
|
||||
catch (e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
if (e is ControlFlowException) {
|
||||
throw e
|
||||
}
|
||||
@@ -324,8 +332,7 @@ private class AnnotationPresentationInfo(
|
||||
Severity.WARNING -> {
|
||||
if (highlightType == ProblemHighlightType.WEAK_WARNING) {
|
||||
holder.createWeakWarningAnnotation(range, defaultMessage)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
holder.createWarningAnnotation(range, defaultMessage)
|
||||
}
|
||||
}
|
||||
@@ -351,8 +358,7 @@ private class AnnotationPresentationInfo(
|
||||
val factoryName = diagnostic.factory.name
|
||||
message = if (message.startsWith("<html>")) {
|
||||
"<html>[$factoryName] ${message.substring("<html>".length)}"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
"[$factoryName] $message"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user