[ByteCodeViewer] Small Javadoc fixes, small code improvement

GitOrigin-RevId: 1bd56fbaf7e7a388f52fc257e01f091b410ce65a
This commit is contained in:
Bartek Pacia
2025-06-24 11:26:05 +00:00
committed by intellij-monorepo-bot
parent bdc8a86183
commit 3123d86a38
2 changed files with 10 additions and 12 deletions
@@ -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<Int>()
val lineNumbers = arrayListOf<Int>()
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
@@ -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 {