lazy toString renderer, not enabled for now

This commit is contained in:
Egor.Ushakov
2017-06-28 15:37:09 +03:00
parent f3d58363e9
commit edab85d266
5 changed files with 105 additions and 0 deletions
@@ -306,6 +306,9 @@ public class JavaValue extends XNamedValue implements NodeDescriptorProvider, XV
lastRenderer = ((CompoundTypeRenderer)lastRenderer).getLabelRenderer();
}
if (lastRenderer instanceof ToStringRenderer) {
if (lastRenderer instanceof LazyToStringRenderer && !((LazyToStringRenderer)lastRenderer).isCalculated(myValueDescriptor)) {
return;
}
value = StringUtil.wrapWithDoubleQuote(value);
}
renderer.renderValue(value);
@@ -0,0 +1,78 @@
/*
* Copyright 2000-2017 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 com.intellij.debugger.ui.tree.render
import com.intellij.debugger.DebuggerBundle
import com.intellij.debugger.engine.FullValueEvaluatorProvider
import com.intellij.debugger.engine.evaluation.EvaluateException
import com.intellij.debugger.engine.evaluation.EvaluationContext
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl
import com.intellij.debugger.ui.tree.ValueDescriptor
import com.intellij.openapi.util.Key
import com.intellij.xdebugger.frame.XFullValueEvaluator
import com.intellij.xdebugger.frame.XValuePlace
import com.intellij.xdebugger.impl.ui.tree.nodes.HeadlessValueEvaluationCallback
/**
* @author egor
*/
class LazyToStringRenderer : ToStringRenderer(), FullValueEvaluatorProvider {
init {
isEnabled = true
}
override fun getFullValueEvaluator(evaluationContext: EvaluationContextImpl?, valueDescriptor: ValueDescriptorImpl): XFullValueEvaluator? {
if (!isCalculated(valueDescriptor)) {
return object : XFullValueEvaluator(DebuggerBundle.message("message.node.toString")) {
override fun startEvaluation(callback: XFullValueEvaluator.XFullValueEvaluationCallback) {
if (callback is HeadlessValueEvaluationCallback) {
val node = callback.node
node.clearFullValueEvaluator()
valueDescriptor.putUserData(LAZY_CALCULATED, true)
node.valueContainer.computePresentation(node, XValuePlace.TREE)
}
callback.evaluated("")
}
}.setShowValuePopup(false)
}
return null
}
@Throws(EvaluateException::class)
override fun calcLabel(descriptor: ValueDescriptor, evaluationContext: EvaluationContext, listener: DescriptorLabelListener): String? {
if (!isCalculated(descriptor)) {
return ""
}
return super.calcLabel(descriptor, evaluationContext, listener)
}
fun isCalculated(descriptor: ValueDescriptor): Boolean {
return java.lang.Boolean.TRUE == descriptor.getUserData(LAZY_CALCULATED)
}
override fun getName(): String {
return "Lazy" + super.getName()
}
override fun getUniqueId(): String {
return "Lazy" + super.getUniqueId()
}
companion object {
private val LAZY_CALCULATED = Key.create<Boolean>("LAZY_CALCULATED")
}
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2017 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 com.intellij.xdebugger.impl.ui.tree.nodes;
import com.intellij.notification.NotificationType;
@@ -64,6 +79,10 @@ public class HeadlessValueEvaluationCallback implements XFullValueEvaluator.XFul
}
}
public XValueNodeImpl getNode() {
return myNode;
}
protected void evaluationComplete(@NotNull String value, @NotNull Project project) {
}
@@ -173,6 +173,10 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
});
}
public void clearFullValueEvaluator() {
myFullValueEvaluator = null;
}
private void updateText() {
myText.clear();
XValueMarkers<?, ?> markers = myTree.getValueMarkers();
@@ -428,6 +428,7 @@ message.node.evaluation.not.possible=Target VM is not paused by breakpoint reque
message.node.show.image=\u2026 Show image
message.node.show.icon=\u2026 Show icon
message.node.navigate=\u2026 Navigate
message.node.toString=\u2026 toString
label.thread.node.thread.collected=Thread ''{0}'' has been garbage-collected
label.thread.node=\"{0}\"@{1}: {2}
label.thread.node.in.group=\"{0}\"@{1} in group \"{3}\": {2}