From ae2e8578436d9158d429e3cf5f1495fa0d5c6d6f Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 28 Oct 2016 20:46:00 +0300 Subject: [PATCH] Refactoring: remove lambda parameter from readClassFile() --- .../debugger/NoStrataPositionManagerHelper.kt | 6 +++--- .../jetbrains/kotlin/idea/debugger/smapUtil.kt | 16 +++++++++------- .../kotlin/idea/filters/KotlinExceptionFilter.kt | 5 +++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt index 620e536e743..1c61612f4ee 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/NoStrataPositionManagerHelper.kt @@ -110,16 +110,16 @@ internal fun getOriginalPositionOfInlinedLine(location: Location, project: Proje internal fun findAndReadClassFile( fqName: FqName, fileName: String, project: Project, searchScope: GlobalSearchScope, - sourceFileFilter: (VirtualFile) -> Boolean = { true }, - libFileFilter: (VirtualFile) -> Boolean = { true }): ByteArray? { + fileFilter: (VirtualFile) -> Boolean): ByteArray? { val internalName = fqName.asString().replace('.', '/') val jvmClassName = JvmClassName.byInternalName(internalName) val file = DebuggerUtils.findSourceFileForClassIncludeLibrarySources(project, searchScope, jvmClassName, fileName) ?: return null val virtualFile = file.virtualFile ?: return null + if (!fileFilter(virtualFile)) return null - return readClassFile(project, jvmClassName, virtualFile, sourceFileFilter = sourceFileFilter, libFileFilter = libFileFilter) + return readClassFile(project, jvmClassName, virtualFile) } internal fun getLocationsOfInlinedLine(type: ReferenceType, position: SourcePosition, sourceSearchScope: GlobalSearchScope): List { diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/smapUtil.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/smapUtil.kt index 86dc3ce10b8..6eccd4e1536 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/smapUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/smapUtil.kt @@ -41,19 +41,21 @@ import org.jetbrains.org.objectweb.asm.ClassVisitor import java.io.File fun isInlineFunctionLineNumber(file: VirtualFile, lineNumber: Int, project: Project): Boolean { - val linesInFile = file.toPsiFile(project)?.getLineCount() ?: return false - return lineNumber > linesInFile + if (ProjectRootsUtil.isProjectSourceFile(project, file)) { + val linesInFile = file.toPsiFile(project)?.getLineCount() ?: return false + return lineNumber > linesInFile + } + + return true } fun readClassFile(project: Project, jvmName: JvmClassName, - file: VirtualFile, - sourceFileFilter: (VirtualFile) -> Boolean = { true }, - libFileFilter: (VirtualFile) -> Boolean = { true }): ByteArray? { + file: VirtualFile): ByteArray? { val fqNameWithInners = jvmName.fqNameForClassNameWithoutDollars.tail(jvmName.packageFqName) when { - ProjectRootsUtil.isLibrarySourceFile(project, file) && libFileFilter(file) -> { + ProjectRootsUtil.isLibrarySourceFile(project, file) -> { val classId = ClassId(jvmName.packageFqName, Name.identifier(fqNameWithInners.asString())) val fileFinder = JvmVirtualFileFinder.SERVICE.getInstance(project) @@ -61,7 +63,7 @@ fun readClassFile(project: Project, return classFile.contentsToByteArray() } - ProjectRootsUtil.isProjectSourceFile(project, file) && sourceFileFilter(file) -> { + ProjectRootsUtil.isProjectSourceFile(project, file) -> { val module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(file) val outputDir = CompilerPaths.getModuleOutputDirectory(module, /*forTests = */ false) ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt b/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt index 49174885700..b7344132f75 100644 --- a/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/filters/KotlinExceptionFilter.kt @@ -73,8 +73,9 @@ class KotlinExceptionFilter(private val searchScope: GlobalSearchScope) : Filter } private fun createHyperlinks(jvmName: JvmClassName, file: VirtualFile, line: Int, project: Project): InlineFunctionHyperLinkInfo? { - val bytes = readClassFile(project, jvmName, file, - sourceFileFilter = { sourceFile -> isInlineFunctionLineNumber(sourceFile, line, project) }) ?: return null + if (!isInlineFunctionLineNumber(file, line, project)) return null + + val bytes = readClassFile(project, jvmName, file) ?: return null val smapData = readDebugInfo(bytes) ?: return null val inlineInfos = arrayListOf()