Reformat and clean up idea.actions.internal
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.storage.CacheResetOnProcessCanceled
|
||||
|
||||
class CacheResetOnProcessCanceledToggleAction : ToggleAction() {
|
||||
override fun isSelected(e: AnActionEvent): Boolean =
|
||||
CacheResetOnProcessCanceled.enabled
|
||||
CacheResetOnProcessCanceled.enabled
|
||||
|
||||
override fun setSelected(e: AnActionEvent, state: Boolean) {
|
||||
CacheResetOnProcessCanceled.enabled = state
|
||||
|
||||
+30
-23
@@ -42,20 +42,21 @@ class CheckComponentsUsageSearchAction : AnAction() {
|
||||
val selectedKotlinFiles = selectedKotlinFiles(e).toList()
|
||||
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||
{
|
||||
runReadAction { process(selectedKotlinFiles, project) }
|
||||
},
|
||||
"Checking Data Classes",
|
||||
true,
|
||||
project)
|
||||
{
|
||||
runReadAction { process(selectedKotlinFiles, project) }
|
||||
},
|
||||
"Checking Data Classes",
|
||||
true,
|
||||
project
|
||||
)
|
||||
}
|
||||
|
||||
private fun process(files: Collection<KtFile>, project: Project) {
|
||||
val dataClasses = files.asSequence()
|
||||
.flatMap { it.declarations.asSequence() }
|
||||
.filterIsInstance<KtClass>()
|
||||
.filter { it.isData() }
|
||||
.toList()
|
||||
.flatMap { it.declarations.asSequence() }
|
||||
.filterIsInstance<KtClass>()
|
||||
.filter { it.isData() }
|
||||
.toList()
|
||||
|
||||
val progressIndicator = ProgressManager.getInstance().progressIndicator
|
||||
for ((i, dataClass) in dataClasses.withIndex()) {
|
||||
@@ -67,24 +68,31 @@ class CheckComponentsUsageSearchAction : AnAction() {
|
||||
try {
|
||||
var smartRefsCount = 0
|
||||
var goldRefsCount = 0
|
||||
ProgressManager.getInstance().runProcess({
|
||||
ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.ALWAYS_SMART
|
||||
ProgressManager.getInstance().runProcess(
|
||||
{
|
||||
ExpressionsOfTypeProcessor.mode =
|
||||
ExpressionsOfTypeProcessor.Mode.ALWAYS_SMART
|
||||
|
||||
smartRefsCount = ReferencesSearch.search(parameter).findAll().size
|
||||
smartRefsCount = ReferencesSearch.search(parameter).findAll().size
|
||||
|
||||
ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.ALWAYS_PLAIN
|
||||
ExpressionsOfTypeProcessor.mode =
|
||||
ExpressionsOfTypeProcessor.Mode.ALWAYS_PLAIN
|
||||
|
||||
goldRefsCount = ReferencesSearch.search(parameter).findAll().size
|
||||
}, EmptyProgressIndicator())
|
||||
goldRefsCount = ReferencesSearch.search(parameter).findAll().size
|
||||
}, EmptyProgressIndicator()
|
||||
)
|
||||
|
||||
if (smartRefsCount != goldRefsCount) {
|
||||
SwingUtilities.invokeLater {
|
||||
Messages.showInfoMessage(project, "Difference found for data class ${dataClass.fqName?.asString()}. Found $smartRefsCount usage(s) but $goldRefsCount expected", "Error")
|
||||
Messages.showInfoMessage(
|
||||
project,
|
||||
"Difference found for data class ${dataClass.fqName?.asString()}. Found $smartRefsCount usage(s) but $goldRefsCount expected",
|
||||
"Error"
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.PLAIN_WHEN_NEEDED
|
||||
}
|
||||
}
|
||||
@@ -101,8 +109,7 @@ class CheckComponentsUsageSearchAction : AnAction() {
|
||||
if (!ApplicationManager.getApplication().isInternal) {
|
||||
e.presentation.isVisible = false
|
||||
e.presentation.isEnabled = false
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
e.presentation.isVisible = true
|
||||
e.presentation.isEnabled = true
|
||||
}
|
||||
@@ -117,8 +124,8 @@ class CheckComponentsUsageSearchAction : AnAction() {
|
||||
private fun allKotlinFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<KtFile> {
|
||||
val manager = PsiManager.getInstance(project)
|
||||
return allFiles(filesOrDirs)
|
||||
.asSequence()
|
||||
.mapNotNull { manager.findFile(it) as? KtFile }
|
||||
.asSequence()
|
||||
.mapNotNull { manager.findFile(it) as? KtFile }
|
||||
}
|
||||
|
||||
private fun allFiles(filesOrDirs: Array<VirtualFile>): Collection<VirtualFile> {
|
||||
|
||||
@@ -21,10 +21,9 @@ import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.awt.*
|
||||
import java.awt.Toolkit
|
||||
import java.awt.datatransfer.StringSelection
|
||||
|
||||
class CopyAsDiagnosticTestAction : AnAction() {
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ class CopyKotlinProjectOverviewAction : AnAction() {
|
||||
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
|
||||
clipboard.setContents(StringSelection(result), EmptyClipboardOwner.INSTANCE)
|
||||
} catch (_: IndexNotReadyException) {
|
||||
DumbService.getInstance(project).showDumbModeNotification("Can't finish while indexing is in progress");
|
||||
DumbService.getInstance(project).showDumbModeNotification("Can't finish while indexing is in progress")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.intellij.util.TimeoutUtil
|
||||
import java.util.*
|
||||
import kotlin.random.Random
|
||||
|
||||
class DumbModeTrembleAction: DumbAwareAction() {
|
||||
class DumbModeTrembleAction : DumbAwareAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val project = e.project ?: return
|
||||
|
||||
|
||||
@@ -48,17 +48,20 @@ import java.util.*
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
class FindImplicitNothingAction : AnAction() {
|
||||
private val LOG = Logger.getInstance("#org.jetbrains.kotlin.idea.actions.internal.FindImplicitNothingAction")
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance("#org.jetbrains.kotlin.idea.actions.internal.FindImplicitNothingAction")
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val selectedFiles = selectedKotlinFiles(e).toList()
|
||||
val project = CommonDataKeys.PROJECT.getData(e.dataContext)!!
|
||||
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||
Runnable { find(selectedFiles, project) },
|
||||
"Finding Implicit Nothing's",
|
||||
true,
|
||||
project)
|
||||
{ find(selectedFiles, project) },
|
||||
"Finding Implicit Nothing's",
|
||||
true,
|
||||
project
|
||||
)
|
||||
}
|
||||
|
||||
private fun find(files: Collection<KtFile>, project: Project) {
|
||||
@@ -84,11 +87,9 @@ class FindImplicitNothingAction : AnAction() {
|
||||
if (KotlinBuiltIns.isNothing(type) && !expression.hasExplicitNothing(bindingContext)) { //TODO: what about nullable Nothing?
|
||||
found.add(expression)
|
||||
}
|
||||
}
|
||||
catch(e: ProcessCanceledException) {
|
||||
} catch (e: ProcessCanceledException) {
|
||||
throw e
|
||||
}
|
||||
catch(t: Throwable) { // do not stop on internal error
|
||||
} catch (t: Throwable) { // do not stop on internal error
|
||||
LOG.error(t)
|
||||
}
|
||||
}
|
||||
@@ -103,14 +104,14 @@ class FindImplicitNothingAction : AnAction() {
|
||||
val presentation = UsageViewPresentation()
|
||||
presentation.tabName = "Implicit Nothing's"
|
||||
UsageViewManager.getInstance(project).showUsages(arrayOf<UsageTarget>(), usages, presentation)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Messages.showInfoMessage(project, "Not found in ${files.size} file(s)", "Not Found")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtExpression.hasExplicitNothing(bindingContext: BindingContext): Boolean {
|
||||
@Suppress("MoveVariableDeclarationIntoWhen")
|
||||
val callee = getCalleeExpressionIfAny() ?: return false
|
||||
when (callee) {
|
||||
is KtSimpleNameExpression -> {
|
||||
@@ -130,7 +131,7 @@ class FindImplicitNothingAction : AnAction() {
|
||||
|
||||
private fun KotlinType.isNothingOrNothingFunctionType(): Boolean {
|
||||
return KotlinBuiltIns.isNothing(this) ||
|
||||
(isFunctionType && this.getReturnTypeFromFunctionType().isNothingOrNothingFunctionType())
|
||||
(isFunctionType && this.getReturnTypeFromFunctionType().isNothingOrNothingFunctionType())
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
@@ -147,8 +148,8 @@ class FindImplicitNothingAction : AnAction() {
|
||||
private fun allKotlinFiles(filesOrDirs: Array<VirtualFile>, project: Project): Sequence<KtFile> {
|
||||
val manager = PsiManager.getInstance(project)
|
||||
return allFiles(filesOrDirs)
|
||||
.asSequence()
|
||||
.mapNotNull { manager.findFile(it) as? KtFile }
|
||||
.asSequence()
|
||||
.mapNotNull { manager.findFile(it) as? KtFile }
|
||||
}
|
||||
|
||||
private fun allFiles(filesOrDirs: Array<VirtualFile>): Collection<VirtualFile> {
|
||||
|
||||
+21
-21
@@ -47,21 +47,21 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
||||
val packageDesc = try {
|
||||
val fqName = FqName.fromSegments(result!!.split('.'))
|
||||
desc.getPackage(fqName)
|
||||
}
|
||||
catch (e: Exception) {
|
||||
} catch (e: Exception) {
|
||||
return
|
||||
}
|
||||
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||
{
|
||||
runReadAction {
|
||||
ProgressManager.getInstance().progressIndicator!!.isIndeterminate = true
|
||||
processAllDescriptors(packageDesc, project)
|
||||
}
|
||||
},
|
||||
"Searching for Not Property candidates",
|
||||
true,
|
||||
project)
|
||||
{
|
||||
runReadAction {
|
||||
ProgressManager.getInstance().progressIndicator!!.isIndeterminate = true
|
||||
processAllDescriptors(packageDesc, project)
|
||||
}
|
||||
},
|
||||
"Searching for Not Property candidates",
|
||||
true,
|
||||
project
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,8 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
||||
val name = desc.fqNameUnsafe.shortName().asString()
|
||||
if (name.length > 3 &&
|
||||
((name.startsWith("get") && desc.valueParameters.isEmpty() && desc.returnType != null) ||
|
||||
(name.startsWith("set") && desc.valueParameters.size == 1))) {
|
||||
(name.startsWith("set") && desc.valueParameters.size == 1))
|
||||
) {
|
||||
if (desc in matchedDescriptors) return
|
||||
matchedDescriptors += desc
|
||||
}
|
||||
@@ -116,22 +117,22 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
||||
|
||||
|
||||
var i = 0
|
||||
resultDescriptors.forEach { descriptor ->
|
||||
progress("Step 2: ${i++} of ${resultDescriptors.size}", "$descriptor")
|
||||
val source = DescriptorToSourceUtilsIde.getAllDeclarations(project, descriptor)
|
||||
.filterIsInstance<PsiMethod>()
|
||||
.firstOrNull() ?: return@forEach
|
||||
resultDescriptors.forEach { functionDescriptor ->
|
||||
progress("Step 2: ${i++} of ${resultDescriptors.size}", "$functionDescriptor")
|
||||
val source = DescriptorToSourceUtilsIde.getAllDeclarations(project, functionDescriptor)
|
||||
.filterIsInstance<PsiMethod>()
|
||||
.firstOrNull() ?: return@forEach
|
||||
val abstract = source.modifierList.hasModifierProperty(PsiModifier.ABSTRACT)
|
||||
if (!abstract) {
|
||||
if (!source.isTrivial()) {
|
||||
descriptorToPsiBinding[descriptor] = source
|
||||
descriptorToPsiBinding[functionDescriptor] = source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val nonTrivial = mutableSetOf<FunctionDescriptor>()
|
||||
i = 0
|
||||
descriptorToPsiBinding.forEach { t, u ->
|
||||
descriptorToPsiBinding.forEach { (t, u) ->
|
||||
progress("Step 3: ${i++} of ${descriptorToPsiBinding.size}", "$t")
|
||||
val descriptors = t.overriddenDescriptors
|
||||
var impl = false
|
||||
@@ -155,8 +156,7 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
||||
if (!ApplicationManager.getApplication().isInternal) {
|
||||
e.presentation.isVisible = false
|
||||
e.presentation.isEnabled = false
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
e.presentation.isVisible = true
|
||||
e.presentation.isEnabled = e.getData(CommonDataKeys.PSI_FILE) is KtFile
|
||||
}
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import org.jetbrains.kotlin.utils.WrappedValues
|
||||
|
||||
|
||||
class StoredExceptionsThrowToggleAction : ToggleAction("Internal: toggle throwing cached PCE", "Rethrow stored PCE as a new runtime exception", null) {
|
||||
class StoredExceptionsThrowToggleAction :
|
||||
ToggleAction("Internal: toggle throwing cached PCE", "Rethrow stored PCE as a new runtime exception", null) {
|
||||
override fun isSelected(e: AnActionEvent): Boolean {
|
||||
return WrappedValues.throwWrappedProcessCanceledException
|
||||
}
|
||||
|
||||
+20
-17
@@ -64,20 +64,23 @@ abstract class AbstractCompletionBenchmarkAction : AnAction() {
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract fun createBenchmarkScenario(project: Project, benchmarkSink: CompletionBenchmarkSink.Impl): AbstractCompletionBenchmarkScenario?
|
||||
internal abstract fun createBenchmarkScenario(
|
||||
project: Project,
|
||||
benchmarkSink: CompletionBenchmarkSink.Impl
|
||||
): AbstractCompletionBenchmarkScenario?
|
||||
|
||||
companion object {
|
||||
fun showPopup(project: Project, text: String) {
|
||||
val statusBar = WindowManager.getInstance().getStatusBar(project)
|
||||
JBPopupFactory.getInstance()
|
||||
.createHtmlTextBalloonBuilder(text, MessageType.ERROR, null)
|
||||
.setFadeoutTime(5000)
|
||||
.createBalloon().showInCenterOf(statusBar.component)
|
||||
.createHtmlTextBalloonBuilder(text, MessageType.ERROR, null)
|
||||
.setFadeoutTime(5000)
|
||||
.createBalloon().showInCenterOf(statusBar.component)
|
||||
}
|
||||
|
||||
internal fun <T> List<T>.randomElement(random: Random): T? = if (this.isNotEmpty()) this[random.nextInt(this.size)] else null
|
||||
internal fun <T> Array<T>.randomElement(random: Random): T? = if (this.isNotEmpty()) this[random.nextInt(this.size)] else null
|
||||
internal fun <T : Any> List<T>.shuffledSequence(random: Random): Sequence<T> = generateSequence { this.randomElement(random) }.distinct()
|
||||
internal fun <T : Any> List<T>.shuffledSequence(random: Random): Sequence<T> =
|
||||
generateSequence { this.randomElement(random) }.distinct()
|
||||
|
||||
internal fun collectSuitableKotlinFiles(project: Project, filePredicate: (KtFile) -> Boolean): MutableList<KtFile> {
|
||||
val scope = object : DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||
@@ -93,12 +96,12 @@ abstract class AbstractCompletionBenchmarkAction : AnAction() {
|
||||
val kotlinVFiles = FileTypeIndex.getFiles(KotlinFileType.INSTANCE, scope)
|
||||
|
||||
return kotlinVFiles
|
||||
.asSequence()
|
||||
.mapNotNull { vfile -> (vfile.toPsiFile(project) as? KtFile) }
|
||||
.filterTo(mutableListOf()) { it.isUsableForBenchmark() && filePredicate(it) }
|
||||
.asSequence()
|
||||
.mapNotNull { vfile -> (vfile.toPsiFile(project) as? KtFile) }
|
||||
.filterTo(mutableListOf()) { it.isUsableForBenchmark() && filePredicate(it) }
|
||||
}
|
||||
|
||||
internal fun JPanel.addBoxWithLabel(tooltip: String, label: String = tooltip + ":", default: String, i: Int): JBTextField {
|
||||
internal fun JPanel.addBoxWithLabel(tooltip: String, label: String = "$tooltip:", default: String, i: Int): JBTextField {
|
||||
this.add(JBLabel(label), GridConstraints().apply { row = i; column = 0 })
|
||||
val textField = JBTextField().apply {
|
||||
text = default
|
||||
@@ -115,8 +118,9 @@ abstract class AbstractCompletionBenchmarkAction : AnAction() {
|
||||
}
|
||||
|
||||
internal abstract class AbstractCompletionBenchmarkScenario(
|
||||
val project: Project, val benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||
val random: Random = Random(), val timeout: Long = 15000) {
|
||||
val project: Project, private val benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||
val random: Random = Random(), private val timeout: Long = 15000
|
||||
) {
|
||||
|
||||
|
||||
sealed class Result {
|
||||
@@ -148,8 +152,8 @@ internal abstract class AbstractCompletionBenchmarkScenario(
|
||||
protected suspend fun typeAtOffsetAndGetResult(text: String, offset: Int, file: KtFile): Result {
|
||||
NavigationUtil.openFileWithPsiElement(file.navigationElement, false, true)
|
||||
|
||||
val document = PsiDocumentManager.getInstance(project).getDocument(file) ?:
|
||||
return Result.ErrorResult("${file.virtualFile.path}:O$offset")
|
||||
val document =
|
||||
PsiDocumentManager.getInstance(project).getDocument(file) ?: return Result.ErrorResult("${file.virtualFile.path}:O$offset")
|
||||
|
||||
val location = "${file.virtualFile.path}:${document.getLineNumber(offset)}"
|
||||
|
||||
@@ -173,8 +177,7 @@ internal abstract class AbstractCompletionBenchmarkScenario(
|
||||
|
||||
val result = try {
|
||||
withTimeout(timeout) { collectResult(file, location) }
|
||||
}
|
||||
catch (_: CancellationException) {
|
||||
} catch (_: CancellationException) {
|
||||
Result.ErrorResult(location)
|
||||
}
|
||||
|
||||
@@ -189,7 +192,7 @@ internal abstract class AbstractCompletionBenchmarkScenario(
|
||||
return result
|
||||
}
|
||||
|
||||
protected suspend fun collectResult(file: KtFile, location: String): Result {
|
||||
private suspend fun collectResult(file: KtFile, location: String): Result {
|
||||
val results = benchmarkSink.channel.receive()
|
||||
return Result.SuccessResult(file.getLineCount(), location, results.firstFlush, results.full)
|
||||
}
|
||||
|
||||
+11
-12
@@ -56,7 +56,7 @@ class HighlightingBenchmarkAction : AnAction() {
|
||||
|
||||
fun collectFiles(): List<KtFile>? {
|
||||
|
||||
val ktFiles = collectSuitableKotlinFiles(project, { it.getLineCount() >= settings.lines })
|
||||
val ktFiles = collectSuitableKotlinFiles(project) { it.getLineCount() >= settings.lines }
|
||||
|
||||
if (ktFiles.size < settings.files) {
|
||||
AbstractCompletionBenchmarkAction.showPopup(project, "Number of attempts > then files in project, ${ktFiles.size}")
|
||||
@@ -81,15 +81,14 @@ class HighlightingBenchmarkAction : AnAction() {
|
||||
try {
|
||||
delay(100)
|
||||
ktFiles
|
||||
.shuffledSequence(random)
|
||||
.take(settings.files)
|
||||
.forEach { file ->
|
||||
results += openFileAndMeasureTimeToHighlight(file, project, finishListener)
|
||||
}
|
||||
.shuffledSequence(random)
|
||||
.take(settings.files)
|
||||
.forEach { file ->
|
||||
results += openFileAndMeasureTimeToHighlight(file, project, finishListener)
|
||||
}
|
||||
|
||||
saveResults(results, project)
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
connection.disconnect()
|
||||
finishListener.channel.close()
|
||||
}
|
||||
@@ -188,10 +187,10 @@ class HighlightingBenchmarkAction : AnAction() {
|
||||
val severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project)
|
||||
|
||||
val maxSeverity = model.allHighlighters
|
||||
.mapNotNull { highlighter ->
|
||||
val info = highlighter.errorStripeTooltip as? HighlightInfo ?: return@mapNotNull null
|
||||
info.severity
|
||||
}.maxWith(Comparator { o1, o2 -> severityRegistrar.compare(o1, o2) })
|
||||
.mapNotNull { highlighter ->
|
||||
val info = highlighter.errorStripeTooltip as? HighlightInfo ?: return@mapNotNull null
|
||||
info.severity
|
||||
}.maxWith(Comparator { o1, o2 -> severityRegistrar.compare(o1, o2) })
|
||||
return Result.Success(location, lines, analysisTime, maxSeverity?.myName ?: "clean")
|
||||
}
|
||||
|
||||
|
||||
+17
-13
@@ -34,7 +34,10 @@ import kotlin.properties.Delegates
|
||||
|
||||
class LocalCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
||||
|
||||
override fun createBenchmarkScenario(project: Project, benchmarkSink: CompletionBenchmarkSink.Impl): AbstractCompletionBenchmarkScenario? {
|
||||
override fun createBenchmarkScenario(
|
||||
project: Project,
|
||||
benchmarkSink: CompletionBenchmarkSink.Impl
|
||||
): AbstractCompletionBenchmarkScenario? {
|
||||
|
||||
val settings = showSettingsDialog() ?: return null
|
||||
|
||||
@@ -84,27 +87,28 @@ class LocalCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
||||
dialogBuilder.centerPanel(jPanel)
|
||||
if (!dialogBuilder.showAndGet()) return null
|
||||
|
||||
return Settings(cSeed.text.toLong(),
|
||||
cLines.text.toInt(),
|
||||
cFiles.text.toInt(),
|
||||
cFunctions.text.toInt())
|
||||
return Settings(
|
||||
cSeed.text.toLong(),
|
||||
cLines.text.toInt(),
|
||||
cFiles.text.toInt(),
|
||||
cFunctions.text.toInt()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class LocalCompletionBenchmarkScenario(
|
||||
val files: List<KtFile>,
|
||||
val settings: LocalCompletionBenchmarkAction.Settings,
|
||||
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||
random: Random) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
||||
suspend override fun doBenchmark() {
|
||||
|
||||
val files: List<KtFile>,
|
||||
val settings: LocalCompletionBenchmarkAction.Settings,
|
||||
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||
random: Random
|
||||
) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
||||
override suspend fun doBenchmark() {
|
||||
val allResults = mutableListOf<Result>()
|
||||
files.forEach { file ->
|
||||
val functions = file.collectDescendantsOfType<KtFunction> { it.hasBlockBody() && it.bodyExpression != null }.toMutableList()
|
||||
val randomFunctions = generateSequence { functions.randomElement(random).also { functions.remove(it) } }
|
||||
randomFunctions.take(settings.functions).forEach {
|
||||
function ->
|
||||
randomFunctions.take(settings.functions).forEach { function ->
|
||||
val offset = function.bodyExpression!!.endOffset - 1
|
||||
allResults += typeAtOffsetAndGetResult("listOf(1).", offset, file)
|
||||
}
|
||||
|
||||
+17
-14
@@ -16,14 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.actions.internal.benchmark
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.DialogBuilder
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.ui.components.JBLabel
|
||||
import com.intellij.ui.components.JBPanel
|
||||
import com.intellij.ui.components.JBTextField
|
||||
import com.intellij.uiDesigner.core.GridConstraints
|
||||
import com.intellij.uiDesigner.core.GridLayoutManager
|
||||
import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.randomElement
|
||||
import org.jetbrains.kotlin.idea.completion.CompletionBenchmarkSink
|
||||
@@ -39,7 +36,10 @@ import kotlin.properties.Delegates
|
||||
|
||||
class TopLevelCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
||||
|
||||
override fun createBenchmarkScenario(project: Project, benchmarkSink: CompletionBenchmarkSink.Impl): AbstractCompletionBenchmarkScenario? {
|
||||
override fun createBenchmarkScenario(
|
||||
project: Project,
|
||||
benchmarkSink: CompletionBenchmarkSink.Impl
|
||||
): AbstractCompletionBenchmarkScenario? {
|
||||
|
||||
val settings = showSettingsDialog() ?: return null
|
||||
|
||||
@@ -85,19 +85,22 @@ class TopLevelCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
||||
dialogBuilder.centerPanel(jPanel)
|
||||
if (!dialogBuilder.showAndGet()) return null
|
||||
|
||||
return Settings(cSeed.text.toLong(),
|
||||
cLines.text.toInt(),
|
||||
cFiles.text.toInt())
|
||||
return Settings(
|
||||
cSeed.text.toLong(),
|
||||
cLines.text.toInt(),
|
||||
cFiles.text.toInt()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class TopLevelCompletionBenchmarkScenario(
|
||||
val files: List<KtFile>,
|
||||
val settings: TopLevelCompletionBenchmarkAction.Settings,
|
||||
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||
random: Random) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
||||
suspend override fun doBenchmark() {
|
||||
val files: List<KtFile>,
|
||||
val settings: TopLevelCompletionBenchmarkAction.Settings,
|
||||
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||
random: Random
|
||||
) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
||||
override suspend fun doBenchmark() {
|
||||
|
||||
val allResults = mutableListOf<Result>()
|
||||
files.forEach { file ->
|
||||
@@ -108,8 +111,8 @@ internal class TopLevelCompletionBenchmarkScenario(
|
||||
}
|
||||
|
||||
run {
|
||||
val classes = file.collectDescendantsOfType<KtClassOrObject> { it.getBody() != null }
|
||||
val body = classes.randomElement(random)?.getBody() ?: return@run
|
||||
val classes = file.collectDescendantsOfType<KtClassOrObject> { it.body != null }
|
||||
val body = classes.randomElement(random)?.body ?: return@run
|
||||
val offset = body.endOffset - 1
|
||||
allResults += typeAtOffsetAndGetResult("fun Str", offset, file)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user