mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify suspend context base
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.debugger
|
||||
import com.intellij.util.Consumer
|
||||
import org.jetbrains.concurrency.Promise
|
||||
import org.jetbrains.debugger.values.ValueManager
|
||||
import org.jetbrains.debugger.values.VmAwareValueManager
|
||||
|
||||
/**
|
||||
* An object that matches the execution state of the VM while suspended
|
||||
@@ -27,6 +26,7 @@ interface SuspendContext<CALL_FRAME : CallFrame> {
|
||||
val state: SuspendState
|
||||
|
||||
val script: Script?
|
||||
get() = topFrame?.let { vm.scriptManager.getScript(it) }
|
||||
|
||||
/**
|
||||
* @return the current exception state, or `null` if current state is
|
||||
@@ -56,12 +56,16 @@ interface SuspendContext<CALL_FRAME : CallFrame> {
|
||||
|
||||
val valueManager: ValueManager
|
||||
|
||||
val vm: Vm
|
||||
get() = throw UnsupportedOperationException()
|
||||
|
||||
val workerId: String?
|
||||
get() = null
|
||||
}
|
||||
|
||||
abstract class ContextDependentAsyncResultConsumer<T>(private val context: SuspendContext<*>) : Consumer<T> {
|
||||
override final fun consume(result: T) {
|
||||
val vm = (context.valueManager as VmAwareValueManager<*>).vm
|
||||
val vm = context.vm
|
||||
if (vm.attachStateManager.isAttached && !vm.suspendContextManager.isContextObsolete(context)) {
|
||||
consume(result, vm)
|
||||
}
|
||||
@@ -71,7 +75,7 @@ abstract class ContextDependentAsyncResultConsumer<T>(private val context: Suspe
|
||||
}
|
||||
|
||||
|
||||
inline fun <T> Promise<out T>.done(context: SuspendContext<*>, crossinline handler: (result: T) -> Unit) = (this as Promise<T>).done(object : ContextDependentAsyncResultConsumer<T>(context) {
|
||||
inline fun <T> Promise<T>.done(context: SuspendContext<*>, crossinline handler: (result: T) -> Unit) = (this).done(object : ContextDependentAsyncResultConsumer<T>(context) {
|
||||
override fun consume(result: T, vm: Vm) = handler(result)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,18 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.debugger
|
||||
|
||||
import org.jetbrains.debugger.values.ValueManager
|
||||
import org.jetbrains.debugger.values.VmAwareValueManager
|
||||
|
||||
abstract class SuspendContextBase<VM: Vm, VALUE_MANAGER : ValueManager, F : CallFrame>(override final val valueManager: VALUE_MANAGER, protected val explicitPaused: Boolean) : SuspendContext<F> {
|
||||
abstract class SuspendContextBase<F : CallFrame>(protected val explicitPaused: Boolean) : SuspendContext<F> {
|
||||
override val state: SuspendState
|
||||
get() = if (exceptionData == null) (if (explicitPaused) SuspendState.PAUSED else SuspendState.NORMAL) else SuspendState.EXCEPTION
|
||||
|
||||
override val script: Script?
|
||||
get() {
|
||||
val topFrame = topFrame
|
||||
return if (topFrame == null || valueManager !is VmAwareValueManager<*>) null else valueManager.vm.scriptManager.getScript(topFrame)
|
||||
}
|
||||
|
||||
override val workerId: String? = null
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -68,7 +68,6 @@ enum class StepAction {
|
||||
*/
|
||||
IN,
|
||||
|
||||
|
||||
/**
|
||||
* Step into first scheduled async handler.
|
||||
* @see <a href="https://groups.google.com/a/chromium.org/forum/#!topic/blink-reviews-bindings/LRAHGXErvOc">Chrome debugger suggestion</a>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.concurrency.resolvedPromise
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
abstract class SuspendContextManagerBase<T : SuspendContextBase<*, *, CALL_FRAME>, CALL_FRAME : CallFrame> : SuspendContextManager<CALL_FRAME> {
|
||||
abstract class SuspendContextManagerBase<T : SuspendContextBase<CALL_FRAME>, CALL_FRAME : CallFrame> : SuspendContextManager<CALL_FRAME> {
|
||||
val contextRef = AtomicReference<T>()
|
||||
val threadSuspendContexts: MutableMap<String, JSExecutionStackSuspendContext<T, CALL_FRAME>> =
|
||||
Collections.synchronizedMap(LinkedHashMap<String, JSExecutionStackSuspendContext<T, CALL_FRAME>>())
|
||||
@@ -56,7 +56,7 @@ abstract class SuspendContextManagerBase<T : SuspendContextBase<*, *, CALL_FRAME
|
||||
|
||||
protected fun dismissContextOnDone(promise: Promise<*>): Promise<*> {
|
||||
val context = contextOrFail
|
||||
(promise as Promise<Any?>).done { contextDismissed(context) }
|
||||
promise.done { contextDismissed(context) }
|
||||
return promise
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ abstract class SuspendContextManagerBase<T : SuspendContextBase<*, *, CALL_FRAME
|
||||
if (callback != null) {
|
||||
return callback
|
||||
}
|
||||
return if (context != null) resolvedPromise() else doSuspend()
|
||||
return if (context == null) doSuspend() else resolvedPromise()
|
||||
}
|
||||
|
||||
protected abstract fun doSuspend(): Promise<*>
|
||||
@@ -98,7 +98,7 @@ abstract class SuspendContextManagerBase<T : SuspendContextBase<*, *, CALL_FRAME
|
||||
override val isRestartFrameSupported = false
|
||||
}
|
||||
|
||||
data class JSExecutionStackSuspendContext<T : SuspendContextBase<*, *, CALL_FRAME>, CALL_FRAME : CallFrame>(
|
||||
data class JSExecutionStackSuspendContext<T : SuspendContextBase<CALL_FRAME>, CALL_FRAME : CallFrame>(
|
||||
val suspendContext: T,
|
||||
val script: Script?,
|
||||
val additionalData: Any?
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface DebugEventListener extends EventListener {
|
||||
* breakpoints or a step end). The {@code context} can be used to access the
|
||||
* current backtrace.
|
||||
*/
|
||||
default void suspended(@NotNull Vm vm, @NotNull SuspendContext<?> context) {
|
||||
default void suspended(@NotNull SuspendContext<?> context) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ import org.jetbrains.concurrency.AsyncPromise
|
||||
import org.jetbrains.concurrency.Obsolescent
|
||||
import org.jetbrains.concurrency.Promise
|
||||
import org.jetbrains.concurrency.rejectedPromise
|
||||
import org.jetbrains.debugger.Vm
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
@@ -48,8 +47,7 @@ abstract class ValueManager() : Obsolescent {
|
||||
companion object {
|
||||
val OBSOLETE_CONTEXT_PROMISE = rejectedPromise<Any?>(AsyncPromise.OBSOLETE_ERROR)
|
||||
|
||||
@Suppress("CAST_NEVER_SUCCEEDS")
|
||||
fun <T> reject() = OBSOLETE_CONTEXT_PROMISE as Promise<T>
|
||||
}
|
||||
}
|
||||
|
||||
abstract class VmAwareValueManager<VM : Vm>(final val vm: VM) : ValueManager()
|
||||
}
|
||||
@@ -162,7 +162,7 @@ abstract class DebugProcessImpl<C : VmConnection<*>>(session: XDebugSession,
|
||||
}
|
||||
|
||||
protected fun setOverlay(context: SuspendContext<*>) {
|
||||
if (context.workerId == null) {
|
||||
if (context.vm == vm) {
|
||||
vm!!.suspendContextManager.setOverlayMessage("Paused in debugger")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user