From 3123d86a383e6dff83cb9cf646ba7595d62ff97f Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Mon, 23 Jun 2025 16:13:25 +0200 Subject: [PATCH] [ByteCodeViewer] Small Javadoc fixes, small code improvement GitOrigin-RevId: 1bd56fbaf7e7a388f52fc257e01f091b410ce65a --- .../intellij/byteCodeViewer/bytecodeLineMapping.kt | 14 +++++++------- .../byteCodeViewer/BytecodeLineMappingTest.kt | 8 +++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeLineMapping.kt b/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeLineMapping.kt index a8190c5c37ba..52f7bb18ccd9 100644 --- a/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeLineMapping.kt +++ b/plugins/ByteCodeViewer/src/com/intellij/byteCodeViewer/bytecodeLineMapping.kt @@ -1,9 +1,9 @@ // Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.byteCodeViewer +import org.jetbrains.org.objectweb.asm.ClassReader import java.util.* - /** * This method removes the following debugging information from `bytecode`: * - `LINENUMBER` @@ -27,7 +27,7 @@ internal fun removeDebugInfo(bytecodeWithDebugInfo: String): String = bytecodeWi /** * Maps the line numbers from the provided bytecode to the source code line numbers within a specified range. * - * @param bytecodeWithDebugInfo The Java bytecode in ASM format, with debugging information included (see `ClassReader#SKIP_DEBUG`) + * @param bytecodeWithDebugInfo The Java bytecode in ASM format, with debugging information included (see [ClassReader.SKIP_DEBUG]) * @param sourceStartLine The starting line number in the source code to map from. * @param sourceEndLine The ending line number in the source code to map to. * @return A pair where the first element is the start line number in the bytecode, and the second element is the end line number in the bytecode. Returns (0, 0) if no valid mapping @@ -39,17 +39,17 @@ internal fun mapLines(bytecodeWithDebugInfo: String, sourceStartLine: Int, sourc var bytecodeStartLine = -1 var bytecodeEndLine = -1 - val lines = arrayListOf() + val lineNumbers = arrayListOf() for (line in bytecodeWithDebugInfo.split("\n").dropLastWhile { it.isEmpty() }.map { line -> line.trim { it <= ' ' } }) { if (line.startsWith("LINENUMBER")) { // `line` is e.g. "LINENUMBER 3 L0" or "LINENUMBER 6 L1", but we are only interested in the 3 or 6, respectively. - val ktLineNum = Scanner(line.substring("LINENUMBER".length)).nextInt() - 1 - lines.add(ktLineNum) + val sourceLineNumber = Scanner(line.substring("LINENUMBER".length)).nextInt() - 1 + lineNumbers.add(sourceLineNumber) } } - lines.sort() + lineNumbers.sort() - for (line in lines) { + for (line in lineNumbers) { if (line >= sourceStartLine) { sourceStartLine = line break diff --git a/plugins/ByteCodeViewer/test/com/intellij/byteCodeViewer/BytecodeLineMappingTest.kt b/plugins/ByteCodeViewer/test/com/intellij/byteCodeViewer/BytecodeLineMappingTest.kt index 27c24117d03b..ff394b7307e7 100644 --- a/plugins/ByteCodeViewer/test/com/intellij/byteCodeViewer/BytecodeLineMappingTest.kt +++ b/plugins/ByteCodeViewer/test/com/intellij/byteCodeViewer/BytecodeLineMappingTest.kt @@ -73,6 +73,7 @@ class BytecodeLineMappingTest : BasePlatformTestCase() { """.trimMargin("|") assertEquals(expectedStrippedBytecode, actualStrippedBytecode) + assertEquals(expectedStrippedBytecode, sampleBytecode_1_noDebugInfo) } fun `test simple 1 method body start`() { @@ -413,12 +414,9 @@ class BytecodeLineMappingTest : BasePlatformTestCase() { } /** - * Bytecode was compiled using javac 23. + * Bytecode fixtures, as compiled with javac 23. * - * Human-readable sample bytecode was read with ASM ClassReader, with flags applied: SKIP_FRAMES - * - * NOT-TRUE: Human-readable sample bytecode without debug info was read with ASM ClassReader, with flags applied: SKIP_FRAMES, SKIP_DEBUG - * Actually, it was created with [BytecodeLineMapping.removeDebugInfo]. + * Human-readable sample bytecode without debug info was created with [removeDebugInfo]. */ companion object Fixtures {