Reformat and clean up idea.actions.internal
This commit is contained in:
+17
-10
@@ -47,7 +47,8 @@ class CheckComponentsUsageSearchAction : AnAction() {
|
|||||||
},
|
},
|
||||||
"Checking Data Classes",
|
"Checking Data Classes",
|
||||||
true,
|
true,
|
||||||
project)
|
project
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun process(files: Collection<KtFile>, project: Project) {
|
private fun process(files: Collection<KtFile>, project: Project) {
|
||||||
@@ -67,24 +68,31 @@ class CheckComponentsUsageSearchAction : AnAction() {
|
|||||||
try {
|
try {
|
||||||
var smartRefsCount = 0
|
var smartRefsCount = 0
|
||||||
var goldRefsCount = 0
|
var goldRefsCount = 0
|
||||||
ProgressManager.getInstance().runProcess({
|
ProgressManager.getInstance().runProcess(
|
||||||
ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.ALWAYS_SMART
|
{
|
||||||
|
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
|
goldRefsCount = ReferencesSearch.search(parameter).findAll().size
|
||||||
}, EmptyProgressIndicator())
|
}, EmptyProgressIndicator()
|
||||||
|
)
|
||||||
|
|
||||||
if (smartRefsCount != goldRefsCount) {
|
if (smartRefsCount != goldRefsCount) {
|
||||||
SwingUtilities.invokeLater {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.PLAIN_WHEN_NEEDED
|
ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.PLAIN_WHEN_NEEDED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,8 +109,7 @@ class CheckComponentsUsageSearchAction : AnAction() {
|
|||||||
if (!ApplicationManager.getApplication().isInternal) {
|
if (!ApplicationManager.getApplication().isInternal) {
|
||||||
e.presentation.isVisible = false
|
e.presentation.isVisible = false
|
||||||
e.presentation.isEnabled = false
|
e.presentation.isEnabled = false
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
e.presentation.isVisible = true
|
e.presentation.isVisible = true
|
||||||
e.presentation.isEnabled = true
|
e.presentation.isEnabled = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,9 @@ import com.intellij.openapi.actionSystem.AnActionEvent
|
|||||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
|
import org.jetbrains.kotlin.checkers.utils.CheckerTestUtil
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.*
|
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import java.awt.*
|
import java.awt.Toolkit
|
||||||
import java.awt.datatransfer.StringSelection
|
import java.awt.datatransfer.StringSelection
|
||||||
|
|
||||||
class CopyAsDiagnosticTestAction : AnAction() {
|
class CopyAsDiagnosticTestAction : AnAction() {
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ class CopyKotlinProjectOverviewAction : AnAction() {
|
|||||||
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
|
val clipboard = Toolkit.getDefaultToolkit().systemClipboard
|
||||||
clipboard.setContents(StringSelection(result), EmptyClipboardOwner.INSTANCE)
|
clipboard.setContents(StringSelection(result), EmptyClipboardOwner.INSTANCE)
|
||||||
} catch (_: IndexNotReadyException) {
|
} 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 java.util.*
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
class DumbModeTrembleAction: DumbAwareAction() {
|
class DumbModeTrembleAction : DumbAwareAction() {
|
||||||
override fun actionPerformed(e: AnActionEvent) {
|
override fun actionPerformed(e: AnActionEvent) {
|
||||||
val project = e.project ?: return
|
val project = e.project ?: return
|
||||||
|
|
||||||
|
|||||||
@@ -48,17 +48,20 @@ import java.util.*
|
|||||||
import javax.swing.SwingUtilities
|
import javax.swing.SwingUtilities
|
||||||
|
|
||||||
class FindImplicitNothingAction : AnAction() {
|
class FindImplicitNothingAction : AnAction() {
|
||||||
|
companion object {
|
||||||
private val LOG = Logger.getInstance("#org.jetbrains.kotlin.idea.actions.internal.FindImplicitNothingAction")
|
private val LOG = Logger.getInstance("#org.jetbrains.kotlin.idea.actions.internal.FindImplicitNothingAction")
|
||||||
|
}
|
||||||
|
|
||||||
override fun actionPerformed(e: AnActionEvent) {
|
override fun actionPerformed(e: AnActionEvent) {
|
||||||
val selectedFiles = selectedKotlinFiles(e).toList()
|
val selectedFiles = selectedKotlinFiles(e).toList()
|
||||||
val project = CommonDataKeys.PROJECT.getData(e.dataContext)!!
|
val project = CommonDataKeys.PROJECT.getData(e.dataContext)!!
|
||||||
|
|
||||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
ProgressManager.getInstance().runProcessWithProgressSynchronously(
|
||||||
Runnable { find(selectedFiles, project) },
|
{ find(selectedFiles, project) },
|
||||||
"Finding Implicit Nothing's",
|
"Finding Implicit Nothing's",
|
||||||
true,
|
true,
|
||||||
project)
|
project
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun find(files: Collection<KtFile>, project: 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?
|
if (KotlinBuiltIns.isNothing(type) && !expression.hasExplicitNothing(bindingContext)) { //TODO: what about nullable Nothing?
|
||||||
found.add(expression)
|
found.add(expression)
|
||||||
}
|
}
|
||||||
}
|
} catch (e: ProcessCanceledException) {
|
||||||
catch(e: ProcessCanceledException) {
|
|
||||||
throw e
|
throw e
|
||||||
}
|
} catch (t: Throwable) { // do not stop on internal error
|
||||||
catch(t: Throwable) { // do not stop on internal error
|
|
||||||
LOG.error(t)
|
LOG.error(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,14 +104,14 @@ class FindImplicitNothingAction : AnAction() {
|
|||||||
val presentation = UsageViewPresentation()
|
val presentation = UsageViewPresentation()
|
||||||
presentation.tabName = "Implicit Nothing's"
|
presentation.tabName = "Implicit Nothing's"
|
||||||
UsageViewManager.getInstance(project).showUsages(arrayOf<UsageTarget>(), usages, presentation)
|
UsageViewManager.getInstance(project).showUsages(arrayOf<UsageTarget>(), usages, presentation)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Messages.showInfoMessage(project, "Not found in ${files.size} file(s)", "Not Found")
|
Messages.showInfoMessage(project, "Not found in ${files.size} file(s)", "Not Found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtExpression.hasExplicitNothing(bindingContext: BindingContext): Boolean {
|
private fun KtExpression.hasExplicitNothing(bindingContext: BindingContext): Boolean {
|
||||||
|
@Suppress("MoveVariableDeclarationIntoWhen")
|
||||||
val callee = getCalleeExpressionIfAny() ?: return false
|
val callee = getCalleeExpressionIfAny() ?: return false
|
||||||
when (callee) {
|
when (callee) {
|
||||||
is KtSimpleNameExpression -> {
|
is KtSimpleNameExpression -> {
|
||||||
|
|||||||
+11
-11
@@ -47,8 +47,7 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
|||||||
val packageDesc = try {
|
val packageDesc = try {
|
||||||
val fqName = FqName.fromSegments(result!!.split('.'))
|
val fqName = FqName.fromSegments(result!!.split('.'))
|
||||||
desc.getPackage(fqName)
|
desc.getPackage(fqName)
|
||||||
}
|
} catch (e: Exception) {
|
||||||
catch (e: Exception) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +60,8 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
|||||||
},
|
},
|
||||||
"Searching for Not Property candidates",
|
"Searching for Not Property candidates",
|
||||||
true,
|
true,
|
||||||
project)
|
project
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +84,8 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
|||||||
val name = desc.fqNameUnsafe.shortName().asString()
|
val name = desc.fqNameUnsafe.shortName().asString()
|
||||||
if (name.length > 3 &&
|
if (name.length > 3 &&
|
||||||
((name.startsWith("get") && desc.valueParameters.isEmpty() && desc.returnType != null) ||
|
((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
|
if (desc in matchedDescriptors) return
|
||||||
matchedDescriptors += desc
|
matchedDescriptors += desc
|
||||||
}
|
}
|
||||||
@@ -116,22 +117,22 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
|||||||
|
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
resultDescriptors.forEach { descriptor ->
|
resultDescriptors.forEach { functionDescriptor ->
|
||||||
progress("Step 2: ${i++} of ${resultDescriptors.size}", "$descriptor")
|
progress("Step 2: ${i++} of ${resultDescriptors.size}", "$functionDescriptor")
|
||||||
val source = DescriptorToSourceUtilsIde.getAllDeclarations(project, descriptor)
|
val source = DescriptorToSourceUtilsIde.getAllDeclarations(project, functionDescriptor)
|
||||||
.filterIsInstance<PsiMethod>()
|
.filterIsInstance<PsiMethod>()
|
||||||
.firstOrNull() ?: return@forEach
|
.firstOrNull() ?: return@forEach
|
||||||
val abstract = source.modifierList.hasModifierProperty(PsiModifier.ABSTRACT)
|
val abstract = source.modifierList.hasModifierProperty(PsiModifier.ABSTRACT)
|
||||||
if (!abstract) {
|
if (!abstract) {
|
||||||
if (!source.isTrivial()) {
|
if (!source.isTrivial()) {
|
||||||
descriptorToPsiBinding[descriptor] = source
|
descriptorToPsiBinding[functionDescriptor] = source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val nonTrivial = mutableSetOf<FunctionDescriptor>()
|
val nonTrivial = mutableSetOf<FunctionDescriptor>()
|
||||||
i = 0
|
i = 0
|
||||||
descriptorToPsiBinding.forEach { t, u ->
|
descriptorToPsiBinding.forEach { (t, u) ->
|
||||||
progress("Step 3: ${i++} of ${descriptorToPsiBinding.size}", "$t")
|
progress("Step 3: ${i++} of ${descriptorToPsiBinding.size}", "$t")
|
||||||
val descriptors = t.overriddenDescriptors
|
val descriptors = t.overriddenDescriptors
|
||||||
var impl = false
|
var impl = false
|
||||||
@@ -155,8 +156,7 @@ class SearchNotPropertyCandidatesAction : AnAction() {
|
|||||||
if (!ApplicationManager.getApplication().isInternal) {
|
if (!ApplicationManager.getApplication().isInternal) {
|
||||||
e.presentation.isVisible = false
|
e.presentation.isVisible = false
|
||||||
e.presentation.isEnabled = false
|
e.presentation.isEnabled = false
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
e.presentation.isVisible = true
|
e.presentation.isVisible = true
|
||||||
e.presentation.isEnabled = e.getData(CommonDataKeys.PSI_FILE) is KtFile
|
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
|
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 {
|
override fun isSelected(e: AnActionEvent): Boolean {
|
||||||
return WrappedValues.throwWrappedProcessCanceledException
|
return WrappedValues.throwWrappedProcessCanceledException
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-11
@@ -64,7 +64,10 @@ 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 {
|
companion object {
|
||||||
fun showPopup(project: Project, text: String) {
|
fun showPopup(project: Project, text: String) {
|
||||||
@@ -76,8 +79,8 @@ abstract class AbstractCompletionBenchmarkAction : AnAction() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun <T> List<T>.randomElement(random: Random): T? = if (this.isNotEmpty()) this[random.nextInt(this.size)] else null
|
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> =
|
||||||
internal fun <T : Any> List<T>.shuffledSequence(random: Random): Sequence<T> = generateSequence { this.randomElement(random) }.distinct()
|
generateSequence { this.randomElement(random) }.distinct()
|
||||||
|
|
||||||
internal fun collectSuitableKotlinFiles(project: Project, filePredicate: (KtFile) -> Boolean): MutableList<KtFile> {
|
internal fun collectSuitableKotlinFiles(project: Project, filePredicate: (KtFile) -> Boolean): MutableList<KtFile> {
|
||||||
val scope = object : DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
val scope = object : DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||||
@@ -98,7 +101,7 @@ abstract class AbstractCompletionBenchmarkAction : AnAction() {
|
|||||||
.filterTo(mutableListOf()) { it.isUsableForBenchmark() && filePredicate(it) }
|
.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 })
|
this.add(JBLabel(label), GridConstraints().apply { row = i; column = 0 })
|
||||||
val textField = JBTextField().apply {
|
val textField = JBTextField().apply {
|
||||||
text = default
|
text = default
|
||||||
@@ -115,8 +118,9 @@ abstract class AbstractCompletionBenchmarkAction : AnAction() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal abstract class AbstractCompletionBenchmarkScenario(
|
internal abstract class AbstractCompletionBenchmarkScenario(
|
||||||
val project: Project, val benchmarkSink: CompletionBenchmarkSink.Impl,
|
val project: Project, private val benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||||
val random: Random = Random(), val timeout: Long = 15000) {
|
val random: Random = Random(), private val timeout: Long = 15000
|
||||||
|
) {
|
||||||
|
|
||||||
|
|
||||||
sealed class Result {
|
sealed class Result {
|
||||||
@@ -148,8 +152,8 @@ internal abstract class AbstractCompletionBenchmarkScenario(
|
|||||||
protected suspend fun typeAtOffsetAndGetResult(text: String, offset: Int, file: KtFile): Result {
|
protected suspend fun typeAtOffsetAndGetResult(text: String, offset: Int, file: KtFile): Result {
|
||||||
NavigationUtil.openFileWithPsiElement(file.navigationElement, false, true)
|
NavigationUtil.openFileWithPsiElement(file.navigationElement, false, true)
|
||||||
|
|
||||||
val document = PsiDocumentManager.getInstance(project).getDocument(file) ?:
|
val document =
|
||||||
return Result.ErrorResult("${file.virtualFile.path}:O$offset")
|
PsiDocumentManager.getInstance(project).getDocument(file) ?: return Result.ErrorResult("${file.virtualFile.path}:O$offset")
|
||||||
|
|
||||||
val location = "${file.virtualFile.path}:${document.getLineNumber(offset)}"
|
val location = "${file.virtualFile.path}:${document.getLineNumber(offset)}"
|
||||||
|
|
||||||
@@ -173,8 +177,7 @@ internal abstract class AbstractCompletionBenchmarkScenario(
|
|||||||
|
|
||||||
val result = try {
|
val result = try {
|
||||||
withTimeout(timeout) { collectResult(file, location) }
|
withTimeout(timeout) { collectResult(file, location) }
|
||||||
}
|
} catch (_: CancellationException) {
|
||||||
catch (_: CancellationException) {
|
|
||||||
Result.ErrorResult(location)
|
Result.ErrorResult(location)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +192,7 @@ internal abstract class AbstractCompletionBenchmarkScenario(
|
|||||||
return result
|
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()
|
val results = benchmarkSink.channel.receive()
|
||||||
return Result.SuccessResult(file.getLineCount(), location, results.firstFlush, results.full)
|
return Result.SuccessResult(file.getLineCount(), location, results.firstFlush, results.full)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -56,7 +56,7 @@ class HighlightingBenchmarkAction : AnAction() {
|
|||||||
|
|
||||||
fun collectFiles(): List<KtFile>? {
|
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) {
|
if (ktFiles.size < settings.files) {
|
||||||
AbstractCompletionBenchmarkAction.showPopup(project, "Number of attempts > then files in project, ${ktFiles.size}")
|
AbstractCompletionBenchmarkAction.showPopup(project, "Number of attempts > then files in project, ${ktFiles.size}")
|
||||||
@@ -88,8 +88,7 @@ class HighlightingBenchmarkAction : AnAction() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveResults(results, project)
|
saveResults(results, project)
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
connection.disconnect()
|
connection.disconnect()
|
||||||
finishListener.channel.close()
|
finishListener.channel.close()
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-8
@@ -34,7 +34,10 @@ import kotlin.properties.Delegates
|
|||||||
|
|
||||||
class LocalCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
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
|
val settings = showSettingsDialog() ?: return null
|
||||||
|
|
||||||
@@ -84,10 +87,12 @@ class LocalCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
|||||||
dialogBuilder.centerPanel(jPanel)
|
dialogBuilder.centerPanel(jPanel)
|
||||||
if (!dialogBuilder.showAndGet()) return null
|
if (!dialogBuilder.showAndGet()) return null
|
||||||
|
|
||||||
return Settings(cSeed.text.toLong(),
|
return Settings(
|
||||||
|
cSeed.text.toLong(),
|
||||||
cLines.text.toInt(),
|
cLines.text.toInt(),
|
||||||
cFiles.text.toInt(),
|
cFiles.text.toInt(),
|
||||||
cFunctions.text.toInt())
|
cFunctions.text.toInt()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -96,15 +101,14 @@ internal class LocalCompletionBenchmarkScenario(
|
|||||||
val files: List<KtFile>,
|
val files: List<KtFile>,
|
||||||
val settings: LocalCompletionBenchmarkAction.Settings,
|
val settings: LocalCompletionBenchmarkAction.Settings,
|
||||||
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||||
random: Random) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
random: Random
|
||||||
suspend override fun doBenchmark() {
|
) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
||||||
|
override suspend fun doBenchmark() {
|
||||||
val allResults = mutableListOf<Result>()
|
val allResults = mutableListOf<Result>()
|
||||||
files.forEach { file ->
|
files.forEach { file ->
|
||||||
val functions = file.collectDescendantsOfType<KtFunction> { it.hasBlockBody() && it.bodyExpression != null }.toMutableList()
|
val functions = file.collectDescendantsOfType<KtFunction> { it.hasBlockBody() && it.bodyExpression != null }.toMutableList()
|
||||||
val randomFunctions = generateSequence { functions.randomElement(random).also { functions.remove(it) } }
|
val randomFunctions = generateSequence { functions.randomElement(random).also { functions.remove(it) } }
|
||||||
randomFunctions.take(settings.functions).forEach {
|
randomFunctions.take(settings.functions).forEach { function ->
|
||||||
function ->
|
|
||||||
val offset = function.bodyExpression!!.endOffset - 1
|
val offset = function.bodyExpression!!.endOffset - 1
|
||||||
allResults += typeAtOffsetAndGetResult("listOf(1).", offset, file)
|
allResults += typeAtOffsetAndGetResult("listOf(1).", offset, file)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-10
@@ -16,14 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.actions.internal.benchmark
|
package org.jetbrains.kotlin.idea.actions.internal.benchmark
|
||||||
|
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.ui.DialogBuilder
|
import com.intellij.openapi.ui.DialogBuilder
|
||||||
import com.intellij.psi.PsiWhiteSpace
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
import com.intellij.ui.components.JBLabel
|
|
||||||
import com.intellij.ui.components.JBPanel
|
import com.intellij.ui.components.JBPanel
|
||||||
import com.intellij.ui.components.JBTextField
|
import com.intellij.ui.components.JBTextField
|
||||||
import com.intellij.uiDesigner.core.GridConstraints
|
|
||||||
import com.intellij.uiDesigner.core.GridLayoutManager
|
import com.intellij.uiDesigner.core.GridLayoutManager
|
||||||
import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.randomElement
|
import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.randomElement
|
||||||
import org.jetbrains.kotlin.idea.completion.CompletionBenchmarkSink
|
import org.jetbrains.kotlin.idea.completion.CompletionBenchmarkSink
|
||||||
@@ -39,7 +36,10 @@ import kotlin.properties.Delegates
|
|||||||
|
|
||||||
class TopLevelCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
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
|
val settings = showSettingsDialog() ?: return null
|
||||||
|
|
||||||
@@ -85,9 +85,11 @@ class TopLevelCompletionBenchmarkAction : AbstractCompletionBenchmarkAction() {
|
|||||||
dialogBuilder.centerPanel(jPanel)
|
dialogBuilder.centerPanel(jPanel)
|
||||||
if (!dialogBuilder.showAndGet()) return null
|
if (!dialogBuilder.showAndGet()) return null
|
||||||
|
|
||||||
return Settings(cSeed.text.toLong(),
|
return Settings(
|
||||||
|
cSeed.text.toLong(),
|
||||||
cLines.text.toInt(),
|
cLines.text.toInt(),
|
||||||
cFiles.text.toInt())
|
cFiles.text.toInt()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -96,8 +98,9 @@ internal class TopLevelCompletionBenchmarkScenario(
|
|||||||
val files: List<KtFile>,
|
val files: List<KtFile>,
|
||||||
val settings: TopLevelCompletionBenchmarkAction.Settings,
|
val settings: TopLevelCompletionBenchmarkAction.Settings,
|
||||||
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
project: Project, benchmarkSink: CompletionBenchmarkSink.Impl,
|
||||||
random: Random) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
random: Random
|
||||||
suspend override fun doBenchmark() {
|
) : AbstractCompletionBenchmarkScenario(project, benchmarkSink, random) {
|
||||||
|
override suspend fun doBenchmark() {
|
||||||
|
|
||||||
val allResults = mutableListOf<Result>()
|
val allResults = mutableListOf<Result>()
|
||||||
files.forEach { file ->
|
files.forEach { file ->
|
||||||
@@ -108,8 +111,8 @@ internal class TopLevelCompletionBenchmarkScenario(
|
|||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val classes = file.collectDescendantsOfType<KtClassOrObject> { it.getBody() != null }
|
val classes = file.collectDescendantsOfType<KtClassOrObject> { it.body != null }
|
||||||
val body = classes.randomElement(random)?.getBody() ?: return@run
|
val body = classes.randomElement(random)?.body ?: return@run
|
||||||
val offset = body.endOffset - 1
|
val offset = body.endOffset - 1
|
||||||
allResults += typeAtOffsetAndGetResult("fun Str", offset, file)
|
allResults += typeAtOffsetAndGetResult("fun Str", offset, file)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user