Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Batkovich
2015-10-16 14:48:08 +03:00
6 changed files with 80 additions and 72 deletions
@@ -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<VALUE_LOADER : ValueManager<out Vm>>(type: ValueT
@Suppress("CAST_NEVER_SUCCEEDS")
override val variablesHost: VariablesHost<ValueManager<Vm>>
get() = childrenManager as VariablesHost<ValueManager<Vm>>
}
companion object {
protected fun getSpecifiedProperties(variables: List<Variable>, names: List<String>, evaluateContext: EvaluateContext): Promise<List<Variable>> {
val properties = SmartList<Variable>()
var getterCount = 0
for (property in variables) {
if (!property.isReadable || !names.contains(property.name)) {
continue
}
fun getSpecifiedProperties(variables: List<Variable>, names: List<String>, evaluateContext: EvaluateContext): Promise<List<Variable>> {
val properties = SmartList<Variable>()
var getterCount = 0
for (property in variables) {
if (!property.isReadable || !names.contains(property.name)) {
continue
}
if (!properties.isEmpty()) {
Collections.sort(properties, object : Comparator<Variable> {
override fun compare(o1: Variable, o2: Variable) = names.indexOf(o1.name) - names.indexOf(o2.name)
})
}
if (!properties.isEmpty()) {
Collections.sort(properties, object : Comparator<Variable> {
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<Promise<*>>()
for (variable in properties) {
if (variable.value == null) {
val valueModifier = variable.valueModifier
assert(valueModifier != null)
promises.add(valueModifier!!.evaluateGet(variable, evaluateContext))
}
}
return Promise.all<List<Variable>>(promises, properties)
}
properties.add(property)
if (property.value == null) {
getterCount++
}
}
if (getterCount == 0) {
return Promise.resolve(properties)
}
else {
val promises = SmartList<Promise<*>>()
for (variable in properties) {
if (variable.value == null) {
val valueModifier = variable.valueModifier
assert(valueModifier != null)
promises.add(valueModifier!!.evaluateGet(variable, evaluateContext))
}
}
return Promise.all<List<Variable>>(promises, properties)
}
}
@@ -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<REQUEST, INCOMING, INCOMING_WITH_SEQ : Any, SUCCESS>(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()
}
}
}
@@ -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"))
}
@@ -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();
}
@@ -37,11 +37,10 @@ import java.util.concurrent.atomic.AtomicReference
abstract class RemoteVmConnection : VmConnection<Vm>() {
private val connectCancelHandler = AtomicReference<Runnable>()
override fun getBrowser() = null
abstract fun createBootstrap(address: InetSocketAddress, vmResult: AsyncPromise<Vm>): Bootstrap
public abstract fun createBootstrap(address: InetSocketAddress, vmResult: AsyncPromise<Vm>): Bootstrap
public fun open(address: InetSocketAddress, stopCondition: Condition<Void>? = null) {
@JvmOverloads
fun open(address: InetSocketAddress, stopCondition: Condition<Void>? = null) {
setState(ConnectionStatus.WAITING_FOR_CONNECTION, "Connecting to ${address.hostName}:${address.port}")
val future = ApplicationManager.getApplication().executeOnPooledThread(object : Runnable {
override fun run() {
@@ -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<T : Vm> : Disposable, BrowserConnection {
private val state = AtomicReference(ConnectionState(ConnectionStatus.NOT_CONNECTED))
abstract class VmConnection<T : Vm> : 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<T : Vm> : Disposable, BrowserConnection {
private val opened = AsyncPromise<Any?>()
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<T : Vm> : 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<T : Vm> : Disposable, BrowserConnection {
}
}
override fun addListener(listener: SocketConnectionListener) {
fun addListener(listener: SocketConnectionListener) {
connectionDispatcher.addListener(listener)
}