Switch to 201 platform

This commit is contained in:
Nikolay Krasko
2020-06-30 19:50:57 +03:00
parent 50863b6985
commit 21fa2bf98c
186 changed files with 1877 additions and 1878 deletions
@@ -9,6 +9,6 @@ import com.intellij.psi.PsiMethod
import com.intellij.util.Processor
// FIX ME WHEN BUNCH 193 REMOVED
typealias StringProcessor = Processor<String>
typealias PsiMethodProcessor = Processor<PsiMethod>
typealias StringProcessor = Processor<in String>
typealias PsiMethodProcessor = Processor<in PsiMethod>
@@ -9,6 +9,6 @@ import com.intellij.psi.PsiMethod
import com.intellij.util.Processor
// FIX ME WHEN BUNCH 193 REMOVED
typealias StringProcessor = Processor<in String>
typealias PsiMethodProcessor = Processor<in PsiMethod>
typealias StringProcessor = Processor<String>
typealias PsiMethodProcessor = Processor<PsiMethod>
@@ -8,13 +8,17 @@ package org.jetbrains.kotlin.idea.highlighter
import com.intellij.codeInsight.intention.EmptyIntentionAction
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.lang.annotation.Annotation
import com.intellij.lang.annotation.AnnotationBuilder
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.util.TextRange
import com.intellij.util.containers.MultiMap
import com.intellij.xml.util.XmlStringUtil
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
class AnnotationPresentationInfo(
@@ -28,35 +32,67 @@ class AnnotationPresentationInfo(
for (range in ranges) {
for (diagnostic in diagnostics) {
val fixes = fixesMap[diagnostic]
val annotation = create(diagnostic, range, holder)
fixes.forEach {
when (it) {
is KotlinUniversalQuickFix -> annotation.registerUniversalFix(it, null, null)
is IntentionAction -> annotation.registerFix(it)
create(diagnostic, range, holder) { annotation ->
fixes.forEach {
when (it) {
is KotlinUniversalQuickFix -> annotation.newFix(it).universal().registerFix()
is IntentionAction -> annotation.newFix(it).registerFix()
}
}
}
if (diagnostic.severity == Severity.WARNING) {
annotation.problemGroup = KotlinSuppressableWarningProblemGroup(diagnostic.factory)
if (diagnostic.severity == Severity.WARNING) {
annotation.problemGroup(KotlinSuppressableWarningProblemGroup(diagnostic.factory))
if (fixes.isEmpty()) {
// if there are no quick fixes we need to register an EmptyIntentionAction to enable 'suppress' actions
annotation.registerFix(EmptyIntentionAction(diagnostic.factory.name))
if (fixes.isEmpty()) {
// if there are no quick fixes we need to register an EmptyIntentionAction to enable 'suppress' actions
annotation.newFix(EmptyIntentionAction(diagnostic.factory.name)).registerFix()
}
}
}
}
}
}
private fun create(diagnostic: Diagnostic, range: TextRange, holder: AnnotationHolder): Annotation =
Diagnostic2Annotation.createAnnotation(
diagnostic,
range,
holder,
nonDefaultMessage,
textAttributes,
highlightType,
IdeErrorMessages::render
)
private fun create(diagnostic: Diagnostic, range: TextRange, holder: AnnotationHolder, consumer: (AnnotationBuilder) -> Unit) {
val severity = when (diagnostic.severity) {
Severity.ERROR -> HighlightSeverity.ERROR
Severity.WARNING -> if (highlightType == ProblemHighlightType.WEAK_WARNING) {
HighlightSeverity.WEAK_WARNING
} else HighlightSeverity.WARNING
Severity.INFO -> HighlightSeverity.WEAK_WARNING
}
holder.newAnnotation(severity, nonDefaultMessage ?: getDefaultMessage(diagnostic))
.range(range)
.tooltip(getMessage(diagnostic))
.also { builder -> highlightType?.let { builder.highlightType(it) } }
.also { builder -> textAttributes?.let { builder.textAttributes(it) } }
.also { consumer(it) }
.create()
}
private fun getMessage(diagnostic: Diagnostic): String {
var message = IdeErrorMessages.render(diagnostic)
if (ApplicationManager.getApplication().isInternal || ApplicationManager.getApplication().isUnitTestMode) {
val factoryName = diagnostic.factory.name
message = if (message.startsWith("<html>")) {
"<html>[$factoryName] ${message.substring("<html>".length)}"
} else {
"[$factoryName] $message"
}
}
if (!message.startsWith("<html>")) {
message = "<html><body>${XmlStringUtil.escapeString(message)}</body></html>"
}
return message
}
private fun getDefaultMessage(diagnostic: Diagnostic): String {
val message = DefaultErrorMessages.render(diagnostic)
if (ApplicationManager.getApplication().isInternal || ApplicationManager.getApplication().isUnitTestMode) {
return "[${diagnostic.factory.name}] $message"
}
return message
}
}
@@ -0,0 +1,62 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.highlighter
import com.intellij.codeInsight.intention.EmptyIntentionAction
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.lang.annotation.Annotation
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.util.TextRange
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
class AnnotationPresentationInfo(
val ranges: List<TextRange>,
val nonDefaultMessage: String? = null,
val highlightType: ProblemHighlightType? = null,
val textAttributes: TextAttributesKey? = null
) {
fun processDiagnostics(holder: AnnotationHolder, diagnostics: List<Diagnostic>, fixesMap: MultiMap<Diagnostic, IntentionAction>) {
for (range in ranges) {
for (diagnostic in diagnostics) {
val fixes = fixesMap[diagnostic]
val annotation = create(diagnostic, range, holder)
fixes.forEach {
when (it) {
is KotlinUniversalQuickFix -> annotation.registerUniversalFix(it, null, null)
is IntentionAction -> annotation.registerFix(it)
}
}
if (diagnostic.severity == Severity.WARNING) {
annotation.problemGroup = KotlinSuppressableWarningProblemGroup(diagnostic.factory)
if (fixes.isEmpty()) {
// if there are no quick fixes we need to register an EmptyIntentionAction to enable 'suppress' actions
annotation.registerFix(EmptyIntentionAction(diagnostic.factory.name))
}
}
}
}
}
private fun create(diagnostic: Diagnostic, range: TextRange, holder: AnnotationHolder): Annotation =
Diagnostic2Annotation.createAnnotation(
diagnostic,
range,
holder,
nonDefaultMessage,
textAttributes,
highlightType,
IdeErrorMessages::render
)
}
@@ -1,98 +0,0 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.highlighter
import com.intellij.codeInsight.intention.EmptyIntentionAction
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.lang.annotation.AnnotationBuilder
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.openapi.util.TextRange
import com.intellij.util.containers.MultiMap
import com.intellij.xml.util.XmlStringUtil
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix
class AnnotationPresentationInfo(
val ranges: List<TextRange>,
val nonDefaultMessage: String? = null,
val highlightType: ProblemHighlightType? = null,
val textAttributes: TextAttributesKey? = null
) {
fun processDiagnostics(holder: AnnotationHolder, diagnostics: List<Diagnostic>, fixesMap: MultiMap<Diagnostic, IntentionAction>) {
for (range in ranges) {
for (diagnostic in diagnostics) {
val fixes = fixesMap[diagnostic]
create(diagnostic, range, holder) { annotation ->
fixes.forEach {
when (it) {
is KotlinUniversalQuickFix -> annotation.newFix(it).universal().registerFix()
is IntentionAction -> annotation.newFix(it).registerFix()
}
}
if (diagnostic.severity == Severity.WARNING) {
annotation.problemGroup(KotlinSuppressableWarningProblemGroup(diagnostic.factory))
if (fixes.isEmpty()) {
// if there are no quick fixes we need to register an EmptyIntentionAction to enable 'suppress' actions
annotation.newFix(EmptyIntentionAction(diagnostic.factory.name)).registerFix()
}
}
}
}
}
}
private fun create(diagnostic: Diagnostic, range: TextRange, holder: AnnotationHolder, consumer: (AnnotationBuilder) -> Unit) {
val severity = when (diagnostic.severity) {
Severity.ERROR -> HighlightSeverity.ERROR
Severity.WARNING -> if (highlightType == ProblemHighlightType.WEAK_WARNING) {
HighlightSeverity.WEAK_WARNING
} else HighlightSeverity.WARNING
Severity.INFO -> HighlightSeverity.WEAK_WARNING
}
holder.newAnnotation(severity, nonDefaultMessage ?: getDefaultMessage(diagnostic))
.range(range)
.tooltip(getMessage(diagnostic))
.also { builder -> highlightType?.let { builder.highlightType(it) } }
.also { builder -> textAttributes?.let { builder.textAttributes(it) } }
.also { consumer(it) }
.create()
}
private fun getMessage(diagnostic: Diagnostic): String {
var message = IdeErrorMessages.render(diagnostic)
if (ApplicationManager.getApplication().isInternal || ApplicationManager.getApplication().isUnitTestMode) {
val factoryName = diagnostic.factory.name
message = if (message.startsWith("<html>")) {
"<html>[$factoryName] ${message.substring("<html>".length)}"
} else {
"[$factoryName] $message"
}
}
if (!message.startsWith("<html>")) {
message = "<html><body>${XmlStringUtil.escapeString(message)}</body></html>"
}
return message
}
private fun getDefaultMessage(diagnostic: Diagnostic): String {
val message = DefaultErrorMessages.render(diagnostic)
if (ApplicationManager.getApplication().isInternal || ApplicationManager.getApplication().isUnitTestMode) {
return "[${diagnostic.factory.name}] $message"
}
return message
}
}
@@ -64,7 +64,7 @@ public class ModuleHighlightUtil2 {
}
}
else if (root.getFileSystem() instanceof JarFileSystem && "jar".equalsIgnoreCase(root.getExtension())) {
return LightJavaModule.getModule(PsiManager.getInstance(project), root);
return LightJavaModule.findModule(PsiManager.getInstance(project), root);
}
}
else if ((root = index.getSourceRootForFile(file)) != null) {
@@ -64,7 +64,7 @@ public class ModuleHighlightUtil2 {
}
}
else if (root.getFileSystem() instanceof JarFileSystem && "jar".equalsIgnoreCase(root.getExtension())) {
return LightJavaModule.findModule(PsiManager.getInstance(project), root);
return LightJavaModule.getModule(PsiManager.getInstance(project), root);
}
}
else if ((root = index.getSourceRootForFile(file)) != null) {
@@ -6,12 +6,9 @@
package org.jetbrains.kotlin.idea.search.ideaExtensions
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.cache.CacheManager
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.ScopeOptimizer
import com.intellij.psi.search.SearchScope
import com.intellij.psi.search.UsageSearchContext
import com.intellij.psi.search.*
import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.search.excludeFileTypes
@@ -31,19 +28,22 @@ class KotlinReferenceScopeOptimizer : ScopeOptimizer {
val file = callable.parent as KtFile
val packageName = file.packageFqName.takeUnless { it.isRoot } ?: return null
val project = file.project
val cacheManager = CacheManager.SERVICE.getInstance(project)
val searchHelper = PsiSearchHelper.getInstance(project)
val kotlinScope = GlobalSearchScope.getScopeRestrictedByFileTypes(useScope, KotlinFileType.INSTANCE)
val javaScope = GlobalSearchScope.getScopeRestrictedByFileTypes(useScope, JavaFileType.INSTANCE)
val restScope = useScope.excludeFileTypes(KotlinFileType.INSTANCE, JavaFileType.INSTANCE) as GlobalSearchScope
//TODO: use all components of package name?
val shortPackageName = packageName.shortName().identifier
val kotlinFiles = cacheManager.getVirtualFilesWithWord(shortPackageName, UsageSearchContext.IN_CODE, kotlinScope, true)
val kotlinFiles = mutableListOf<VirtualFile>()
searchHelper.processCandidateFilesForText(kotlinScope, UsageSearchContext.IN_CODE, true, packageName.asString()) {
kotlinFiles.add(it)
}
val javaFacadeName = file.javaFileFacadeFqName.shortName().identifier
val javaFiles = cacheManager.getVirtualFilesWithWord(javaFacadeName, UsageSearchContext.IN_CODE, javaScope, true)
val javaFiles = mutableListOf<VirtualFile>()
searchHelper.processCandidateFilesForText(javaScope, UsageSearchContext.IN_CODE, true, file.javaFileFacadeFqName.asString()) {
javaFiles.add(it)
}
return GlobalSearchScope.filesScope(project, (kotlinFiles + javaFiles).asList()).uniteWith(restScope)
return GlobalSearchScope.filesScope(project, kotlinFiles + javaFiles).uniteWith(restScope)
}
}
@@ -6,9 +6,12 @@
package org.jetbrains.kotlin.idea.search.ideaExtensions
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
import com.intellij.psi.search.*
import com.intellij.psi.impl.cache.CacheManager
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.ScopeOptimizer
import com.intellij.psi.search.SearchScope
import com.intellij.psi.search.UsageSearchContext
import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.search.excludeFileTypes
@@ -28,22 +31,19 @@ class KotlinReferenceScopeOptimizer : ScopeOptimizer {
val file = callable.parent as KtFile
val packageName = file.packageFqName.takeUnless { it.isRoot } ?: return null
val project = file.project
val searchHelper = PsiSearchHelper.getInstance(project)
val cacheManager = CacheManager.SERVICE.getInstance(project)
val kotlinScope = GlobalSearchScope.getScopeRestrictedByFileTypes(useScope, KotlinFileType.INSTANCE)
val javaScope = GlobalSearchScope.getScopeRestrictedByFileTypes(useScope, JavaFileType.INSTANCE)
val restScope = useScope.excludeFileTypes(KotlinFileType.INSTANCE, JavaFileType.INSTANCE) as GlobalSearchScope
val kotlinFiles = mutableListOf<VirtualFile>()
searchHelper.processCandidateFilesForText(kotlinScope, UsageSearchContext.IN_CODE, true, packageName.asString()) {
kotlinFiles.add(it)
}
//TODO: use all components of package name?
val shortPackageName = packageName.shortName().identifier
val kotlinFiles = cacheManager.getVirtualFilesWithWord(shortPackageName, UsageSearchContext.IN_CODE, kotlinScope, true)
val javaFiles = mutableListOf<VirtualFile>()
searchHelper.processCandidateFilesForText(javaScope, UsageSearchContext.IN_CODE, true, file.javaFileFacadeFqName.asString()) {
javaFiles.add(it)
}
val javaFacadeName = file.javaFileFacadeFqName.shortName().identifier
val javaFiles = cacheManager.getVirtualFilesWithWord(javaFacadeName, UsageSearchContext.IN_CODE, javaScope, true)
return GlobalSearchScope.filesScope(project, kotlinFiles + javaFiles).uniteWith(restScope)
return GlobalSearchScope.filesScope(project, (kotlinFiles + javaFiles).asList()).uniteWith(restScope)
}
}