diff --git a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ObjectValueBase.kt b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ObjectValueBase.kt index f6db099fc20f..12ccce2c9cac 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ObjectValueBase.kt +++ b/platform/script-debugger/backend/src/org/jetbrains/debugger/values/ObjectValueBase.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jetbrains.debugger.values import com.intellij.util.SmartList @@ -32,42 +47,40 @@ abstract class ObjectValueBase>(type: ValueT @Suppress("CAST_NEVER_SUCCEEDS") override val variablesHost: VariablesHost> get() = childrenManager as VariablesHost> +} - companion object { - protected fun getSpecifiedProperties(variables: List, names: List, evaluateContext: EvaluateContext): Promise> { - val properties = SmartList() - var getterCount = 0 - for (property in variables) { - if (!property.isReadable || !names.contains(property.name)) { - continue - } +fun getSpecifiedProperties(variables: List, names: List, evaluateContext: EvaluateContext): Promise> { + val properties = SmartList() + var getterCount = 0 + for (property in variables) { + if (!property.isReadable || !names.contains(property.name)) { + continue + } - if (!properties.isEmpty()) { - Collections.sort(properties, object : Comparator { - override fun compare(o1: Variable, o2: Variable) = names.indexOf(o1.name) - names.indexOf(o2.name) - }) - } + if (!properties.isEmpty()) { + Collections.sort(properties, object : Comparator { + override fun compare(o1: Variable, o2: Variable) = names.indexOf(o1.name) - names.indexOf(o2.name) + }) + } - properties.add(property) - if (property.value == null) { - getterCount++ - } - } - - if (getterCount == 0) { - return Promise.resolve(properties) - } - else { - val promises = SmartList>() - for (variable in properties) { - if (variable.value == null) { - val valueModifier = variable.valueModifier - assert(valueModifier != null) - promises.add(valueModifier!!.evaluateGet(variable, evaluateContext)) - } - } - return Promise.all>(promises, properties) - } + properties.add(property) + if (property.value == null) { + getterCount++ } } + + if (getterCount == 0) { + return Promise.resolve(properties) + } + else { + val promises = SmartList>() + for (variable in properties) { + if (variable.value == null) { + val valueModifier = variable.valueModifier + assert(valueModifier != null) + promises.add(valueModifier!!.evaluateGet(variable, evaluateContext)) + } + } + return Promise.all>(promises, properties) + } } \ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManager.kt b/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManager.kt index 820be7cce07f..5f638734bc47 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManager.kt +++ b/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManager.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -104,10 +104,7 @@ class MessageManager(privat val keys = map.keys() Arrays.sort(keys) for (key in keys) { - val callback = map.get(key) - if (callback != null) { - MessageManagerBase.rejectCallback(callback) - } + map.get(key)?.reject() } } } \ No newline at end of file diff --git a/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManagerBase.kt b/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManagerBase.kt index 03c61a90f9f9..aa5d08171c7c 100644 --- a/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManagerBase.kt +++ b/platform/script-debugger/backend/src/org/jetbrains/rpc/MessageManagerBase.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jetbrains.rpc import org.jetbrains.concurrency.Promise @@ -16,10 +31,8 @@ abstract class MessageManagerBase { fun closed() { closed = true } +} - companion object { - protected fun rejectCallback(callback: RequestCallback<*>) { - callback.onError(Promise.createError("Connection closed")) - } - } +fun RequestCallback<*>.reject() { + onError(Promise.createError("Connection closed")) } \ No newline at end of file diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/BrowserConnection.java b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/BrowserConnection.java deleted file mode 100644 index 352138ddfd7b..000000000000 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/BrowserConnection.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.jetbrains.debugger.connection; - -import com.intellij.ide.browsers.WebBrowser; -import com.intellij.util.io.socketConnection.ConnectionState; -import com.intellij.util.io.socketConnection.SocketConnectionListener; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface BrowserConnection { - @NotNull - ConnectionState getState(); - - void addListener(@NotNull SocketConnectionListener listener); - - void executeOnStart(@NotNull Runnable runnable); - - @Nullable - WebBrowser getBrowser(); -} diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt index 79b6c9025d2f..89e01e825ef8 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/RemoteVmConnection.kt @@ -37,11 +37,10 @@ import java.util.concurrent.atomic.AtomicReference abstract class RemoteVmConnection : VmConnection() { private val connectCancelHandler = AtomicReference() - override fun getBrowser() = null + abstract fun createBootstrap(address: InetSocketAddress, vmResult: AsyncPromise): Bootstrap - public abstract fun createBootstrap(address: InetSocketAddress, vmResult: AsyncPromise): Bootstrap - - public fun open(address: InetSocketAddress, stopCondition: Condition? = null) { + @JvmOverloads + fun open(address: InetSocketAddress, stopCondition: Condition? = null) { setState(ConnectionStatus.WAITING_FOR_CONNECTION, "Connecting to ${address.hostName}:${address.port}") val future = ApplicationManager.getApplication().executeOnPooledThread(object : Runnable { override fun run() { diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.kt b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.kt index 1678681eed35..ce966892bd35 100644 --- a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.kt +++ b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/connection/VmConnection.kt @@ -15,6 +15,7 @@ */ package org.jetbrains.debugger.connection +import com.intellij.ide.browsers.WebBrowser import com.intellij.openapi.Disposable import com.intellij.openapi.util.Disposer import com.intellij.util.EventDispatcher @@ -32,8 +33,11 @@ import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicReference import javax.swing.event.HyperlinkListener -abstract class VmConnection : Disposable, BrowserConnection { - private val state = AtomicReference(ConnectionState(ConnectionStatus.NOT_CONNECTED)) +abstract class VmConnection : Disposable { + open val browser: WebBrowser? = null + + private val stateRef = AtomicReference(ConnectionState(ConnectionStatus.NOT_CONNECTED)) + private val dispatcher = EventDispatcher.create(DebugEventListener::class.java) private val connectionDispatcher = EventDispatcher.create(SocketConnectionListener::class.java) @@ -43,7 +47,8 @@ abstract class VmConnection : Disposable, BrowserConnection { private val opened = AsyncPromise() private val closed = AtomicBoolean() - override fun getState() = state.get() + val state: ConnectionState + get() = stateRef.get() fun addDebugListener(listener: DebugEventListener) { dispatcher.addListener(listener) @@ -52,13 +57,13 @@ abstract class VmConnection : Disposable, BrowserConnection { @TestOnly fun opened(): Promise<*> = opened - override fun executeOnStart(runnable: Runnable) { + fun executeOnStart(runnable: Runnable) { opened.done { runnable.run() } } protected fun setState(status: ConnectionStatus, message: String? = null, messageLinkListener: HyperlinkListener? = null) { val newState = ConnectionState(status, message, messageLinkListener) - val oldState = state.getAndSet(newState) + val oldState = stateRef.getAndSet(newState) if (oldState == null || oldState.status != status) { if (status == ConnectionStatus.CONNECTION_FAILED) { opened.setError(newState.message) @@ -67,7 +72,7 @@ abstract class VmConnection : Disposable, BrowserConnection { } } - override fun addListener(listener: SocketConnectionListener) { + fun addListener(listener: SocketConnectionListener) { connectionDispatcher.addListener(listener) }