-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Room kotlin gencode #630
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eae14ed
updated Room option to enable Kotlin generation
stefanosiano b9a7482
Merge branch 'main' into fix/room-generate-kotlin
stefanosiano 1178f81
removed try catch from room instrumentation, as twp makes it useless
stefanosiano 5e2c2e9
updated changelog
stefanosiano 44aa82b
reverted room version to 2.5.0 in the sample app
stefanosiano 4ad18be
Merge branch 'main' into fix/room-generate-kotlin
romtsn 8fe87d6
AndroidXRoomDaoVisitor now takes the RoomMethodType into consideratio…
stefanosiano 3609c86
Merge remote-tracking branch 'origin/fix/room-generate-kotlin' into f…
stefanosiano 67ae736
AndroidXRoomDaoVisitor now takes the RoomMethodType into consideratio…
stefanosiano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
...lin/io/sentry/android/gradle/instrumentation/androidx/room/visitor/AbstractRoomVisitor.kt
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
.../io/sentry/android/gradle/instrumentation/androidx/room/visitor/AndroidXRoomDaoVisitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.sentry.android.gradle.instrumentation.androidx.room.visitor | ||
|
||
import io.sentry.android.gradle.instrumentation.AbstractSpanAddingMethodVisitor | ||
import io.sentry.android.gradle.instrumentation.SpanOperations | ||
import org.objectweb.asm.Label | ||
import org.objectweb.asm.MethodVisitor | ||
import org.objectweb.asm.Opcodes | ||
|
||
class AndroidXRoomDaoVisitor( | ||
private val className: String, | ||
api: Int, | ||
private val originalVisitor: MethodVisitor, | ||
access: Int, | ||
descriptor: String? | ||
) : AbstractSpanAddingMethodVisitor( | ||
api = api, | ||
originalVisitor = originalVisitor, | ||
access = access, | ||
descriptor = descriptor | ||
) { | ||
private val childIfNullStatusOk = Label() | ||
private val childIfNullFinallyPositive = Label() | ||
private val childIfNullFinallyNegative = Label() | ||
private val startSpanIfNull = Label() | ||
private var finallyVisitCount = 0 | ||
|
||
override fun visitCode() { | ||
super.visitCode() | ||
originalVisitor.visitStartSpan(startSpanIfNull) { | ||
visitLdcInsn(SpanOperations.DB_SQL_ROOM) | ||
visitLdcInsn(className) | ||
} | ||
originalVisitor.visitLabel(startSpanIfNull) | ||
} | ||
|
||
override fun visitMethodInsn( | ||
opcode: Int, | ||
owner: String?, | ||
name: String?, | ||
descriptor: String?, | ||
isInterface: Boolean | ||
) { | ||
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface) | ||
// The backend binds the exception to the current span, via tracing without performance, so we don't need any special try/catch management. | ||
if (opcode == Opcodes.INVOKEVIRTUAL) { | ||
when (name) { | ||
SET_TRANSACTION_SUCCESSFUL -> { | ||
// the original method wants to return, but we intervene here to set status | ||
originalVisitor.visitSetStatus(status = "OK", gotoIfNull = childIfNullStatusOk) | ||
originalVisitor.visitLabel(childIfNullStatusOk) | ||
} | ||
CLOSE, END_TRANSACTION -> { | ||
// room's finally block ends here, we add our code to finish the span | ||
|
||
// we visit finally block 2 times - one for the positive path in control flow (try) one for negative (catch) | ||
// hence we need to use different labels | ||
val visitCount = ++finallyVisitCount | ||
val label = if (visitCount == 1) { | ||
childIfNullFinallyPositive | ||
} else { | ||
childIfNullFinallyNegative | ||
} | ||
originalVisitor.visitFinallyBlock(gotoIfNull = label) | ||
originalVisitor.visitLabel(label) | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private const val CLOSE = "close" | ||
private const val END_TRANSACTION = "endTransaction" | ||
private const val SET_TRANSACTION_SUCCESSFUL = "setTransactionSuccessful" | ||
} | ||
} |
94 changes: 0 additions & 94 deletions
94
...kotlin/io/sentry/android/gradle/instrumentation/androidx/room/visitor/RoomQueryVisitor.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrm, does
INVOKEVIRTUAL
work with theCLOSE
method? It used to beINVOKEINTERFACE
beforeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!
I updated the instrumentation to take the method type into consideration and updated the condition for the close method