From c8654a00331816a5e152be7db61828c1dde042b4 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 23 May 2018 12:50:20 +0300 Subject: [PATCH] Minor: reformat and fix warnings in internal package --- .../idea/internal/KotlinBytecodeToolWindow.kt | 14 ++-- .../internal/KotlinDecompilerServiceImpl.kt | 31 ++++---- .../KotlinDecompilerServiceImpl.kt.182 | 31 ++++---- .../CreateIncrementalCompilationBackup.kt | 79 ++++++++++--------- .../makeBackup/MakeBackupCompileTask.kt | 3 +- .../idea/internal/makeBackup/makeBackup.kt | 2 +- 6 files changed, 80 insertions(+), 80 deletions(-) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt index c1f8adaa9ba..376a851fe30 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinBytecodeToolWindow.kt @@ -54,8 +54,7 @@ sealed class BytecodeGenerationResult { } class KotlinBytecodeToolWindow(private val myProject: Project, private val toolWindow: ToolWindow) : JPanel(BorderLayout()), Disposable { - private val LOG = Logger.getInstance(KotlinBytecodeToolWindow::class.java) - + @Suppress("JoinDeclarationAndAssignment") private val myEditor: Editor private val enableInline: JCheckBox private val enableOptimization: JCheckBox @@ -166,7 +165,6 @@ class KotlinBytecodeToolWindow(private val myProject: Project, private val toolW } init { - myEditor = EditorFactory.getInstance().createEditor( EditorFactory.getInstance().createDocument(""), myProject, JavaFileType.INSTANCE, true ) @@ -223,9 +221,10 @@ class KotlinBytecodeToolWindow(private val myProject: Project, private val toolW } companion object { + private val LOG = Logger.getInstance(KotlinBytecodeToolWindow::class.java) - private val UPDATE_DELAY = 1000 - private val DEFAULT_TEXT = "/*\n" + + private const val UPDATE_DELAY = 1000 + private const val DEFAULT_TEXT = "/*\n" + "Generated bytecode for Kotlin source file.\n" + "No Kotlin source file is opened.\n" + "*/" @@ -283,7 +282,7 @@ class KotlinBytecodeToolWindow(private val myProject: Project, private val toolW ) val generateClassFilter = object : GenerationState.GenerateClassFilter() { - override fun shouldGeneratePackagePart(file: KtFile): Boolean { + override fun shouldGeneratePackagePart(@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") file: KtFile): Boolean { return file === ktFile } @@ -319,6 +318,7 @@ class KotlinBytecodeToolWindow(private val myProject: Project, private val toolW } private fun mapLines(text: String, startLine: Int, endLine: Int): Pair { + @Suppress("NAME_SHADOWING") var startLine = startLine var byteCodeLine = 0 var byteCodeStartLine = -1 @@ -331,7 +331,7 @@ class KotlinBytecodeToolWindow(private val myProject: Project, private val toolW lines.add(ktLineNum) } } - Collections.sort(lines) + lines.sort() for (line in lines) { if (line >= startLine) { diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt index 2095dc46edf..0a7c9e74c29 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt @@ -35,7 +35,6 @@ import java.util.jar.Manifest class KotlinDecompilerServiceImpl : KotlinDecompilerService { override fun decompile(file: KtFile): String? { - try { val bytecodeMap = when { file.canBeDecompiledToJava() -> bytecodeMapForExistingClassfile(file.virtualFile) @@ -44,11 +43,10 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } val resultSaver = KotlinResultSaver() val options = hashMapOf( - IFernflowerPreferences.REMOVE_BRIDGE to "0" + IFernflowerPreferences.REMOVE_BRIDGE to "0" ) - val bytecodeProvider = IBytecodeProvider { - externalPath, _ -> + val bytecodeProvider = IBytecodeProvider { externalPath, _ -> val path = File(FileUtil.toSystemIndependentName(externalPath)) bytecodeMap[path]?.invoke() } @@ -59,8 +57,7 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } decompiler.decompileContext() return resultSaver.resultText - } - catch (ex: IdeaLogger.InternalException) { + } catch (ex: IdeaLogger.InternalException) { throw DecompileFailedException(ex.message ?: "Unknown error", ex) } } @@ -68,10 +65,10 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { private fun bytecodeMapForExistingClassfile(file: VirtualFile): Map ByteArray> { val mask = "${file.nameWithoutExtension}$" val files = - mapOf(file.path to file) + - file.parent.children.filter { - it.nameWithoutExtension.startsWith(mask) && it.fileType === StdFileTypes.CLASS - }.map { it.path to it } + mapOf(file.path to file) + + file.parent.children.filter { + it.nameWithoutExtension.startsWith(mask) && it.fileType === StdFileTypes.CLASS + }.map { it.path to it } return files.entries.associate { Pair(File(it.key), { it.value.contentsToByteArray(false) }) @@ -105,13 +102,13 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } } - override fun saveFolder(path: String?) { } + override fun saveFolder(path: String?) {} - override fun closeArchive(path: String?, archiveName: String?) { } + override fun closeArchive(path: String?, archiveName: String?) {} - override fun copyEntry(source: String?, path: String?, archiveName: String?, entry: String?) { } + override fun copyEntry(source: String?, path: String?, archiveName: String?, entry: String?) {} - override fun createArchive(path: String?, archiveName: String?, manifest: Manifest?) { } + override fun createArchive(path: String?, archiveName: String?, manifest: Manifest?) {} override fun saveClassFile(path: String?, qualifiedName: String?, entryName: String?, content: String?, mapping: IntArray?) { if (entryName != null && content != null) { @@ -119,11 +116,11 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } } - override fun copyFile(source: String?, path: String?, entryName: String?) { } + override fun copyFile(source: String?, path: String?, entryName: String?) {} - override fun saveClassEntry(path: String?, archiveName: String?, qualifiedName: String?, entryName: String?, content: String?) { } + override fun saveClassEntry(path: String?, archiveName: String?, qualifiedName: String?, entryName: String?, content: String?) {} - override fun saveDirEntry(path: String?, archiveName: String?, entryName: String?) { } + override fun saveDirEntry(path: String?, archiveName: String?, entryName: String?) {} } } \ No newline at end of file diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt.182 b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt.182 index cc69bff59a4..aabb06de6b8 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt.182 +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/KotlinDecompilerServiceImpl.kt.182 @@ -35,7 +35,6 @@ import java.util.jar.Manifest class KotlinDecompilerServiceImpl : KotlinDecompilerService { override fun decompile(file: KtFile): String? { - try { val bytecodeMap = when { file.canBeDecompiledToJava() -> bytecodeMapForExistingClassfile(file.virtualFile) @@ -44,11 +43,10 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } val resultSaver = KotlinResultSaver() val options = hashMapOf( - IFernflowerPreferences.REMOVE_BRIDGE to "0" + IFernflowerPreferences.REMOVE_BRIDGE to "0" ) - val bytecodeProvider = IBytecodeProvider { - externalPath, _ -> + val bytecodeProvider = IBytecodeProvider { externalPath, _ -> val path = File(FileUtil.toSystemIndependentName(externalPath)) bytecodeMap[path]?.invoke() } @@ -59,8 +57,7 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } decompiler.decompileContext() return resultSaver.resultText - } - catch (ex: IdeaLogger.InternalException) { + } catch (ex: IdeaLogger.InternalException) { throw DecompileFailedException(ex.message ?: "Unknown error", ex) } } @@ -68,10 +65,10 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { private fun bytecodeMapForExistingClassfile(file: VirtualFile): Map ByteArray> { val mask = "${file.nameWithoutExtension}$" val files = - mapOf(file.path to file) + - file.parent.children.filter { - it.nameWithoutExtension.startsWith(mask) && it.fileType === StdFileTypes.CLASS - }.map { it.path to it } + mapOf(file.path to file) + + file.parent.children.filter { + it.nameWithoutExtension.startsWith(mask) && it.fileType === StdFileTypes.CLASS + }.map { it.path to it } return files.entries.associate { Pair(File(it.key), { it.value.contentsToByteArray(false) }) @@ -105,13 +102,13 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } } - override fun saveFolder(path: String?) { } + override fun saveFolder(path: String?) {} - override fun closeArchive(path: String?, archiveName: String?) { } + override fun closeArchive(path: String?, archiveName: String?) {} - override fun copyEntry(source: String?, path: String?, archiveName: String?, entry: String?) { } + override fun copyEntry(source: String?, path: String?, archiveName: String?, entry: String?) {} - override fun createArchive(path: String?, archiveName: String?, manifest: Manifest?) { } + override fun createArchive(path: String?, archiveName: String?, manifest: Manifest?) {} override fun saveClassFile(path: String?, qualifiedName: String?, entryName: String?, content: String?, mapping: IntArray?) { if (entryName != null && content != null) { @@ -119,11 +116,11 @@ class KotlinDecompilerServiceImpl : KotlinDecompilerService { } } - override fun copyFile(source: String?, path: String?, entryName: String?) { } + override fun copyFile(source: String?, path: String?, entryName: String?) {} - override fun saveClassEntry(path: String?, archiveName: String?, qualifiedName: String?, entryName: String?, content: String?) { } + override fun saveClassEntry(path: String?, archiveName: String?, qualifiedName: String?, entryName: String?, content: String?) {} - override fun saveDirEntry(path: String?, archiveName: String?, entryName: String?) { } + override fun saveDirEntry(path: String?, archiveName: String?, entryName: String?) {} } } \ No newline at end of file diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt index 6edd3eced12..b0eac39d0c2 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/CreateIncrementalCompilationBackup.kt @@ -39,15 +39,15 @@ import java.text.SimpleDateFormat import java.util.* import java.util.zip.ZipOutputStream -class CreateIncrementalCompilationBackup: AnAction("Create backup for debugging Kotlin incremental compilation") { +class CreateIncrementalCompilationBackup : AnAction("Create backup for debugging Kotlin incremental compilation") { companion object { - val BACKUP_DIR_NAME = ".backup" - val PATCHES_TO_CREATE = 5 + const val BACKUP_DIR_NAME = ".backup" + const val PATCHES_TO_CREATE = 5 - val PATCHES_FRACTION = .25 - val LOGS_FRACTION = .05 - val PROJECT_SYSTEM_FRACTION = .05 - val ZIP_FRACTION = 1.0 - PATCHES_FRACTION - LOGS_FRACTION - PROJECT_SYSTEM_FRACTION + const val PATCHES_FRACTION = .25 + const val LOGS_FRACTION = .05 + const val PROJECT_SYSTEM_FRACTION = .05 + const val ZIP_FRACTION = 1.0 - PATCHES_FRACTION - LOGS_FRACTION - PROJECT_SYSTEM_FRACTION } override fun actionPerformed(e: AnActionEvent) { @@ -56,15 +56,15 @@ class CreateIncrementalCompilationBackup: AnAction("Create backup for debugging val backupDir = File(FileUtil.createTempDirectory("makeBackup", null), BACKUP_DIR_NAME) ProgressManager.getInstance().run( - object : Task.Backgroundable(project, "Creating backup for debugging Kotlin incremental compilation", true) { - override fun run(indicator: ProgressIndicator) { - createPatches(backupDir, project, indicator) - copyLogs(backupDir, indicator) - copyProjectSystemDir(backupDir, project, indicator) + object : Task.Backgroundable(project, "Creating backup for debugging Kotlin incremental compilation", true) { + override fun run(indicator: ProgressIndicator) { + createPatches(backupDir, project, indicator) + copyLogs(backupDir, indicator) + copyProjectSystemDir(backupDir, project, indicator) - zipProjectDir(backupDir, project, projectBaseDir, indicator) - } + zipProjectDir(backupDir, project, projectBaseDir, indicator) } + } ) } @@ -74,7 +74,13 @@ class CreateIncrementalCompilationBackup: AnAction("Create backup for debugging val gateway = localHistoryImpl.gateway!! val localHistoryFacade = localHistoryImpl.facade - val revisionsCollector = RevisionsCollector(localHistoryFacade, gateway.createTransientRootEntry(), project.baseDir!!.path, project.locationHash, null) + val revisionsCollector = RevisionsCollector( + localHistoryFacade, + gateway.createTransientRootEntry(), + project.baseDir!!.path, + project.locationHash, + null + ) var patchesCreated = 0 @@ -91,8 +97,7 @@ class CreateIncrementalCompilationBackup: AnAction("Create backup for debugging indicator.fraction = PATCHES_FRACTION * patchesCreated / PATCHES_TO_CREATE val differences = revisions[0].getDifferencesWith(rev)!! - val changes = differences.map { - d -> + val changes = differences.map { d -> Change(d.getLeftContentRevision(gateway), d.getRightContentRevision(gateway)) } @@ -134,24 +139,24 @@ class CreateIncrementalCompilationBackup: AnAction("Create backup for debugging for (dir in listOf(projectDir, backupDir.parentFile!!)) { FileUtil.processFilesRecursively( - dir, - /*processor*/ { - if (it!!.isFile - && !it.name.endsWith(".hprof") - && !(it.name.startsWith("make_backup_") && it.name.endsWith(".zip")) - ) { + dir, + /*processor*/ { + if (it!!.isFile + && !it.name.endsWith(".hprof") + && !(it.name.startsWith("make_backup_") && it.name.endsWith(".zip")) + ) { - indicator.text = "Scanning project dir: $it" + indicator.text = "Scanning project dir: $it" - files.add(Pair(it, FileUtil.getRelativePath(dir, it)!!)) - totalBytes += it.length() - } - true - }, - /*directoryFilter*/ { - val name = it!!.name - name != ".git" && name != "out" + files.add(Pair(it, FileUtil.getRelativePath(dir, it)!!)) + totalBytes += it.length() } + true + }, + /*directoryFilter*/ { + val name = it!!.name + name != ".git" && name != "out" + } ) } @@ -176,14 +181,16 @@ class CreateIncrementalCompilationBackup: AnAction("Create backup for debugging FileUtil.delete(backupDir) - WaitForProgressToShow.runOrInvokeLaterAboveProgress({ - ShowFilePathAction.showDialog( + WaitForProgressToShow.runOrInvokeLaterAboveProgress( + { + ShowFilePathAction.showDialog( project, "Successfully created backup " + backupFile.absolutePath, "Created backup", backupFile, null - ) - }, null, project) + ) + }, null, project + ) } } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt index 6a31f393cea..0290ced66ff 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/MakeBackupCompileTask.kt @@ -26,7 +26,7 @@ val random = Random() val HISTORY_LABEL_KEY = Key.create("history label") -class MakeBackupCompileTask: CompileTask { +class MakeBackupCompileTask : CompileTask { override fun execute(context: CompileContext?): Boolean { val project = context!!.project!! @@ -38,5 +38,4 @@ class MakeBackupCompileTask: CompileTask { return true } - } diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/makeBackup.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/makeBackup.kt index 30ce5f03142..655c45367c1 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/makeBackup.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/internal/makeBackup/makeBackup.kt @@ -16,4 +16,4 @@ package org.jetbrains.kotlin.idea.internal.makeBackup -val HISTORY_LABEL_PREFIX = "build started " +const val HISTORY_LABEL_PREFIX = "build started "