Skip to content

Commit

Permalink
simplify — rejectCallback as callback.reject
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Oct 16, 2015
1 parent 722a53a commit 3478b97
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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++
}
}
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)
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)
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"))
}

0 comments on commit 3478b97

Please sign in to comment.