diff --git a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt index ec1e88e5ec4..ad59f303699 100644 --- a/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt @@ -119,30 +119,21 @@ OLD: KE1 is KtNamed -> element.getNameAsName()?.asString() ?: "" else -> "" } -/* -OLD: KE1 val loc = tw.getLocationString(element) - val context = logger.loggerBase.extractorContextStack + val context = logger.extractorContextStack context.push(ExtractorContext(kind, element, name, loc)) try { val depth = context.size val depthDescription = "${"-".repeat(depth)} (${depth.toString()})" logger.trace("$depthDescription: Starting a $kind ($name) at $loc") -*/ val result = f() -/* -OLD: KE1 logger.trace("$depthDescription: Finished a $kind ($name) at $loc") -*/ return result -/* -OLD: KE1 } catch (exception: Exception) { throw Exception("While extracting a $kind ($name) at $loc", exception) } finally { context.pop() } -*/ } fun extractFileContents(file: KtFile, id: Label) { diff --git a/java/kotlin-extractor2/src/main/kotlin/utils/Logger.kt b/java/kotlin-extractor2/src/main/kotlin/utils/Logger.kt index 9fc7f607145..3ec4f09c334 100644 --- a/java/kotlin-extractor2/src/main/kotlin/utils/Logger.kt +++ b/java/kotlin-extractor2/src/main/kotlin/utils/Logger.kt @@ -7,11 +7,7 @@ import java.io.OutputStreamWriter import java.io.Writer import java.text.SimpleDateFormat import java.util.Date -/* -OLD: KE1 import java.util.Stack -import org.jetbrains.kotlin.ir.IrElement -*/ /** * Counts the number of times each diagnostic message (based on the @@ -97,15 +93,12 @@ class LogMessage(private val kind: String, private val message: String) { } } -/* -OLD: KE1 data class ExtractorContext( val kind: String, - val element: IrElement, + val element: PsiElement, val name: String, val loc: String ) -*/ interface BasicLogger { abstract fun trace(dtw: DiagnosticTrapWriter, msg: String) @@ -172,6 +165,7 @@ OLD: KE1 severity: Severity, msg: String, extraInfo: String?, + extractorContextStack: Stack?, locationString: String? = null, mkLocationId: () -> Label = { dtw.unknownLocation } ) { @@ -199,14 +193,14 @@ OLD: KE1 fullMsgBuilder.append(extraInfo) } -/* -OLD: KE1 - val iter = extractorContextStack.listIterator(extractorContextStack.size) - while (iter.hasPrevious()) { - val x = iter.previous() - fullMsgBuilder.append(" ...while extracting a ${x.kind} (${x.name}) at ${x.loc}\n") + if (extractorContextStack != null) { + val iter = extractorContextStack.listIterator(extractorContextStack.size) + while (iter.hasPrevious()) { + val x = iter.previous() + fullMsgBuilder.append(" ...while extracting a ${x.kind} (${x.name}) at ${x.loc}\n") + } } -*/ + fullMsgBuilder.append(suffix) val fullMsg = fullMsgBuilder.toString() @@ -275,14 +269,22 @@ OLD: KE1 } override fun warn(dtw: DiagnosticTrapWriter, msg: String, extraInfo: String?) { + warn(dtw, msg, extraInfo, null) + } + + fun warn(dtw: DiagnosticTrapWriter, msg: String, extraInfo: String?, extractorContextStack: Stack?) { if (verbosity >= 2) { - diagnostic(dtw, Severity.Warn, msg, extraInfo) + diagnostic(dtw, Severity.Warn, msg, extraInfo, extractorContextStack) } } override fun error(dtw: DiagnosticTrapWriter, msg: String, extraInfo: String?) { + error(dtw, msg, extraInfo, null) + } + + fun error(dtw: DiagnosticTrapWriter, msg: String, extraInfo: String?, extractorContextStack: Stack?) { if (verbosity >= 1) { - diagnostic(dtw, Severity.Error, msg, extraInfo) + diagnostic(dtw, Severity.Error, msg, extraInfo, extractorContextStack) } } @@ -316,10 +318,7 @@ OLD: KE1 * Logger is the high-level interface for writint log messages. */ open class Logger(val loggerBase: LoggerBase, val dtw: DiagnosticTrapWriter): BasicLogger { -/* -OLD: KE1 val extractorContextStack = Stack() -*/ override fun flush() { dtw.flush() @@ -355,7 +354,7 @@ OLD: KE1 } override fun warn(dtw: DiagnosticTrapWriter, msg: String, extraInfo: String?) { - loggerBase.warn(dtw, msg, extraInfo) + loggerBase.warn(dtw, msg, extraInfo, extractorContextStack) } private fun warn(msg: String, extraInfo: String?) { @@ -371,7 +370,7 @@ OLD: KE1 } override fun error(dtw: DiagnosticTrapWriter, msg: String, extraInfo: String?) { - loggerBase.error(dtw, msg, extraInfo) + loggerBase.error(dtw, msg, extraInfo, extractorContextStack) } private fun error(msg: String, extraInfo: String?) { @@ -413,6 +412,7 @@ OLD: KE1 Severity.Error, msg, null, // OLD: KE1: exn?.stackTraceToString(), + extractorContextStack, locationString, mkLocationId )