Skip to content

Commit

Permalink
fix edge case with file lookup for KotlinForExample
Browse files Browse the repository at this point in the history
  • Loading branch information
jillesvangurp committed May 9, 2020
1 parent 3a11324 commit 2078f82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
Binary file modified book.epub
Binary file not shown.
6 changes: 3 additions & 3 deletions manual/crud-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ Output:
"things" : {
"settings" : {
"index" : {
"creation_date" : "1589017970016",
"creation_date" : "1589019624602",
"number_of_shards" : "1",
"number_of_replicas" : "0",
"uuid" : "1jxpyqykQcmasEh0f5pvjw",
"uuid" : "7MpdXY4ySn-KQ_8sdhoOsA",
"version" : {
"created" : "7060099"
},
Expand All @@ -109,7 +109,7 @@ Output:
}
}
things -> {"_meta":{"content_hash":"VFD04UkOGUHI+2GGDIJ8PQ==","timestamp":"2020-
05-09T09:52:49.981296Z"},"properties":{"amount":{"type":"long","fields":{"abette
05-09T10:20:24.594074Z"},"properties":{"amount":{"type":"long","fields":{"abette
rway":{"type":"double"},"imadouble":{"type":"double"},"somesubfield":{"type":"ke
yword"}}},"title":{"type":"text"}}}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.inbot.eskotlinwrapper.manual

import mu.KLogger
import mu.KotlinLogging
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.PrintWriter
import kotlin.reflect.KClass
import mu.KLogger
import mu.KotlinLogging

private val logger: KLogger = KotlinLogging.logger { }

Expand Down Expand Up @@ -160,14 +160,25 @@ class KotlinForExample private constructor(
if (callerSourceBlock == null) {
logger.warn { "Could not find code block from stack trace and sourcePath" }
} else {
mdCodeBlock(code = callerSourceBlock, allowLongLines = allowLongLines, lineLength = lineLength, wrap = wrap)
mdCodeBlock(
code = callerSourceBlock,
allowLongLines = allowLongLines,
lineLength = lineLength,
wrap = wrap
)
}
writer.flush()
}
val output = outputBuffer.toString()
if (output.isNotEmpty()) {
buf.appendln("Output:\n")
mdCodeBlock(code = output, allowLongLines = allowLongLinesInOutput, wrap = wrapOutput, lineLength = lineLength, type = "")
mdCodeBlock(
code = output,
allowLongLines = allowLongLinesInOutput,
wrap = wrapOutput,
lineLength = lineLength,
type = ""
)
}
}

Expand All @@ -194,6 +205,7 @@ class KotlinForExample private constructor(
return source.substring(start + 1, index - 1).trimIndent()
}
}
logger.warn("no suitable file found for ${ste.fileName} ${ste.lineNumber}")
return null
}

Expand All @@ -208,10 +220,15 @@ class KotlinForExample private constructor(
internal fun getCallerStackTraceElement(): StackTraceElement {
return Thread.currentThread()
.stackTrace.first {
it.className != javaClass.name && it.className != "java.lang.Thread" && !it.className.contains(
"KotlinForExample"
)
}
!it.className.startsWith("java") &&
!it.className.startsWith("jdk.internal") &&
it.className != javaClass.name &&
it.className != "java.lang.Thread" &&
it.className != "io.inbot.eskotlinwrapper.manual.KotlinForExample" &&
it.className != "io.inbot.eskotlinwrapper.manual.KotlinForExample\$Companion" // edge case


}
}

override fun close() {
Expand Down

0 comments on commit 2078f82

Please sign in to comment.