mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Convert to kotlin
This commit is contained in:
+27
-42
@@ -13,53 +13,38 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.debugger;
|
||||
package org.jetbrains.debugger
|
||||
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.xdebugger.frame.XCompositeNode;
|
||||
import com.intellij.xdebugger.frame.XValueChildrenList;
|
||||
import com.intellij.xdebugger.frame.XValueGroup;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.debugger.values.FunctionValue;
|
||||
import org.jetbrains.rpc.CommandProcessor;
|
||||
import com.intellij.util.Consumer
|
||||
import com.intellij.xdebugger.frame.XCompositeNode
|
||||
import com.intellij.xdebugger.frame.XValueChildrenList
|
||||
import com.intellij.xdebugger.frame.XValueGroup
|
||||
import org.jetbrains.concurrency.Promise
|
||||
import org.jetbrains.debugger.values.FunctionValue
|
||||
import org.jetbrains.rpc.CommandProcessor
|
||||
import java.util.*
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
class FunctionScopesValueGroup extends XValueGroup {
|
||||
private final FunctionValue value;
|
||||
private final VariableContext variableContext;
|
||||
|
||||
public FunctionScopesValueGroup(@NotNull FunctionValue value, @NotNull VariableContext variableContext) {
|
||||
super("Function scopes");
|
||||
|
||||
this.value = value;
|
||||
this.variableContext = variableContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeChildren(@NotNull final XCompositeNode node) {
|
||||
node.setAlreadySorted(true);
|
||||
internal class FunctionScopesValueGroup(private val value: FunctionValue, private val variableContext: VariableContext) : XValueGroup("Function scopes") {
|
||||
override fun computeChildren(node: XCompositeNode) {
|
||||
node.setAlreadySorted(true)
|
||||
|
||||
value.resolve()
|
||||
.done(new ObsolescentConsumer<FunctionValue>(node) {
|
||||
@Override
|
||||
public void consume(FunctionValue value) {
|
||||
Scope[] scopes = value.getScopes();
|
||||
if (scopes == null || scopes.length == 0) {
|
||||
node.addChildren(XValueChildrenList.EMPTY, true);
|
||||
.done(object : ObsolescentConsumer<FunctionValue>(node) {
|
||||
override fun consume(value: FunctionValue) {
|
||||
val scopes = value.scopes
|
||||
if (scopes == null || scopes.size() == 0) {
|
||||
node.addChildren(XValueChildrenList.EMPTY, true)
|
||||
}
|
||||
else {
|
||||
createAndAddScopeList(node, Arrays.asList(*scopes), variableContext, null)
|
||||
}
|
||||
}
|
||||
else {
|
||||
ScopeVariablesGroup.createAndAddScopeList(node, Arrays.asList(scopes), variableContext, null);
|
||||
})
|
||||
.rejected(object : Consumer<Throwable> {
|
||||
override fun consume(error: Throwable) {
|
||||
Promise.logError(CommandProcessor.LOG, error)
|
||||
node.setErrorMessage(error.getMessage()!!)
|
||||
}
|
||||
}
|
||||
})
|
||||
.rejected(new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void consume(Throwable error) {
|
||||
Promise.logError(CommandProcessor.LOG, error);
|
||||
node.setErrorMessage(error.getMessage());
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
+60
-117
@@ -13,139 +13,82 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.debugger;
|
||||
package org.jetbrains.debugger
|
||||
|
||||
import com.intellij.xdebugger.XDebuggerBundle;
|
||||
import com.intellij.xdebugger.frame.XCompositeNode;
|
||||
import com.intellij.xdebugger.frame.XValueChildrenList;
|
||||
import com.intellij.xdebugger.frame.XValueGroup;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import com.intellij.xdebugger.XDebuggerBundle
|
||||
import com.intellij.xdebugger.frame.XCompositeNode
|
||||
import com.intellij.xdebugger.frame.XValueChildrenList
|
||||
import com.intellij.xdebugger.frame.XValueGroup
|
||||
|
||||
import java.util.List;
|
||||
class ScopeVariablesGroup(val scope: Scope, parentContext: VariableContext, callFrame: CallFrame?) : XValueGroup(createScopeNodeName(scope)) {
|
||||
private val context = createVariableContext(scope, parentContext, callFrame)
|
||||
|
||||
public class ScopeVariablesGroup extends XValueGroup {
|
||||
private final Scope scope;
|
||||
private final VariableContext context;
|
||||
private val callFrame = if (scope.type == Scope.Type.LOCAL) callFrame else null
|
||||
|
||||
private final CallFrame callFrame;
|
||||
override fun isAutoExpand() = scope.type == Scope.Type.LOCAL || scope.type == Scope.Type.CATCH
|
||||
|
||||
public ScopeVariablesGroup(@NotNull Scope scope, @NotNull VariableContext parentContext, @Nullable CallFrame callFrame) {
|
||||
super(createScopeNodeName(scope));
|
||||
|
||||
this.scope = scope;
|
||||
context = createVariableContext(scope, parentContext, callFrame);
|
||||
this.callFrame = scope.getType() == Scope.Type.LOCAL ? callFrame : null;
|
||||
override fun getComment(): String? {
|
||||
val className = scope.description
|
||||
return if ("Object" == className) null else className
|
||||
}
|
||||
|
||||
// public only for tests
|
||||
@NotNull
|
||||
public static VariableContext createVariableContext(@NotNull Scope scope, @NotNull VariableContext parentContext, @Nullable CallFrame callFrame) {
|
||||
if (callFrame == null || scope.getType() == Scope.Type.LIBRARY) {
|
||||
// functions scopes - we can watch variables only from global scope
|
||||
return new ParentlessVariableContext(parentContext, scope, scope.getType() == Scope.Type.GLOBAL);
|
||||
}
|
||||
else {
|
||||
return new VariableContextWrapper(parentContext, scope);
|
||||
override fun computeChildren(node: XCompositeNode) {
|
||||
val promise = processScopeVariables(scope, node, context, callFrame == null)
|
||||
if (callFrame == null) {
|
||||
return
|
||||
}
|
||||
|
||||
promise.done(object : ObsolescentConsumer<Void>(node) {
|
||||
override fun consume(ignored: Void) {
|
||||
callFrame.receiverVariable.done(object : ObsolescentConsumer<Variable>(node) {
|
||||
override fun consume(variable: Variable?) {
|
||||
node.addChildren(if (variable == null) XValueChildrenList.EMPTY else XValueChildrenList.singleton(VariableView(variable, context)), true)
|
||||
}
|
||||
}).rejected(object : ObsolescentConsumer<Throwable>(node) {
|
||||
override fun consume(error: Throwable?) {
|
||||
node.addChildren(XValueChildrenList.EMPTY, true)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@NotNull
|
||||
public Scope getScope() {
|
||||
return scope;
|
||||
fun createAndAddScopeList(node: XCompositeNode, scopes: List<Scope>, context: VariableContext, callFrame: CallFrame?) {
|
||||
val list = XValueChildrenList(scopes.size())
|
||||
for (scope in scopes) {
|
||||
list.addTopGroup(ScopeVariablesGroup(scope, context, callFrame))
|
||||
}
|
||||
node.addChildren(list, true)
|
||||
}
|
||||
|
||||
public static void createAndAddScopeList(@NotNull XCompositeNode node, @NotNull List<Scope> scopes, @NotNull VariableContext context, @Nullable CallFrame callFrame) {
|
||||
XValueChildrenList list = new XValueChildrenList(scopes.size());
|
||||
for (Scope scope : scopes) {
|
||||
list.addTopGroup(new ScopeVariablesGroup(scope, context, callFrame));
|
||||
}
|
||||
node.addChildren(list, true);
|
||||
fun createVariableContext(scope: Scope, parentContext: VariableContext, callFrame: CallFrame?): VariableContext {
|
||||
if (callFrame == null || scope.type == Scope.Type.LIBRARY) {
|
||||
// functions scopes - we can watch variables only from global scope
|
||||
return ParentlessVariableContext(parentContext, scope, scope.type == Scope.Type.GLOBAL)
|
||||
}
|
||||
|
||||
private static String createScopeNodeName(@NotNull Scope scope) {
|
||||
switch (scope.getType()) {
|
||||
case GLOBAL:
|
||||
return XDebuggerBundle.message("scope.global");
|
||||
case LOCAL:
|
||||
return XDebuggerBundle.message("scope.local");
|
||||
case WITH:
|
||||
return XDebuggerBundle.message("scope.with");
|
||||
case CLOSURE:
|
||||
return XDebuggerBundle.message("scope.closure");
|
||||
case CATCH:
|
||||
return XDebuggerBundle.message("scope.catch");
|
||||
case LIBRARY:
|
||||
return XDebuggerBundle.message("scope.library");
|
||||
case INSTANCE:
|
||||
return XDebuggerBundle.message("scope.instance");
|
||||
case CLASS:
|
||||
return XDebuggerBundle.message("scope.class");
|
||||
case UNKNOWN:
|
||||
return XDebuggerBundle.message("scope.unknown");
|
||||
default:
|
||||
throw new IllegalArgumentException(scope.getType().name());
|
||||
}
|
||||
else {
|
||||
return VariableContextWrapper(parentContext, scope)
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoExpand() {
|
||||
return scope.getType() == Scope.Type.LOCAL || scope.getType() == Scope.Type.CATCH;
|
||||
}
|
||||
private class ParentlessVariableContext(parentContext: VariableContext, scope: Scope, private val watchableAsEvaluationExpression: Boolean) : VariableContextWrapper(parentContext, scope) {
|
||||
override fun watchableAsEvaluationExpression() = watchableAsEvaluationExpression
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getComment() {
|
||||
String className = scope.getDescription();
|
||||
return "Object".equals(className) ? null : className;
|
||||
}
|
||||
override fun getParent() = null
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeChildren(final @NotNull XCompositeNode node) {
|
||||
Promise<Void> promise = VariablesKt.processScopeVariables(scope, node, context, callFrame == null);
|
||||
if (callFrame != null) {
|
||||
promise.done(new ObsolescentConsumer<Void>(node) {
|
||||
@Override
|
||||
public void consume(Void ignored) {
|
||||
callFrame.getReceiverVariable()
|
||||
.done(new ObsolescentConsumer<Variable>(node) {
|
||||
@Override
|
||||
public void consume(Variable variable) {
|
||||
node.addChildren(variable == null ? XValueChildrenList.EMPTY : XValueChildrenList.singleton(VariableViewKt.VariableView(variable, context)), true);
|
||||
}
|
||||
})
|
||||
.rejected(new ObsolescentConsumer<Throwable>(node) {
|
||||
@Override
|
||||
public void consume(@Nullable Throwable error) {
|
||||
node.addChildren(XValueChildrenList.EMPTY, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ParentlessVariableContext extends VariableContextWrapper {
|
||||
private final boolean watchableAsEvaluationExpression;
|
||||
|
||||
public ParentlessVariableContext(@NotNull VariableContext parentContext, @NotNull Scope scope, boolean watchableAsEvaluationExpression) {
|
||||
super(parentContext, scope);
|
||||
|
||||
this.watchableAsEvaluationExpression = watchableAsEvaluationExpression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean watchableAsEvaluationExpression() {
|
||||
return watchableAsEvaluationExpression;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public VariableContext getParent() {
|
||||
return null;
|
||||
}
|
||||
private fun createScopeNodeName(scope: Scope): String {
|
||||
when (scope.type) {
|
||||
Scope.Type.GLOBAL -> return XDebuggerBundle.message("scope.global")
|
||||
Scope.Type.LOCAL -> return XDebuggerBundle.message("scope.local")
|
||||
Scope.Type.WITH -> return XDebuggerBundle.message("scope.with")
|
||||
Scope.Type.CLOSURE -> return XDebuggerBundle.message("scope.closure")
|
||||
Scope.Type.CATCH -> return XDebuggerBundle.message("scope.catch")
|
||||
Scope.Type.LIBRARY -> return XDebuggerBundle.message("scope.library")
|
||||
Scope.Type.INSTANCE -> return XDebuggerBundle.message("scope.instance")
|
||||
Scope.Type.CLASS -> return XDebuggerBundle.message("scope.class")
|
||||
Scope.Type.UNKNOWN -> return XDebuggerBundle.message("scope.unknown")
|
||||
else -> throw IllegalArgumentException(scope.type.name())
|
||||
}
|
||||
}
|
||||
+46
-116
@@ -13,155 +13,85 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.debugger.frame;
|
||||
package org.jetbrains.debugger.frame
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ui.ColoredTextContainer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
|
||||
import com.intellij.xdebugger.frame.XCompositeNode;
|
||||
import com.intellij.xdebugger.frame.XStackFrame;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.debugger.*;
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.ui.ColoredTextContainer
|
||||
import com.intellij.ui.SimpleTextAttributes
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator
|
||||
import com.intellij.xdebugger.frame.XCompositeNode
|
||||
import com.intellij.xdebugger.frame.XStackFrame
|
||||
import org.jetbrains.debugger.*
|
||||
|
||||
public final class CallFrameView extends XStackFrame implements VariableContext {
|
||||
private final SourceInfo sourceInfo;
|
||||
private final DebuggerViewSupport viewSupport;
|
||||
private final CallFrame callFrame;
|
||||
class CallFrameView(val callFrame: CallFrame,
|
||||
private val sourceInfo: SourceInfo?,
|
||||
private val viewSupport: DebuggerViewSupport,
|
||||
val script: Script?) : XStackFrame(), VariableContext {
|
||||
// isInLibraryContent call could be costly, so we compute it only once (our customizePresentation called on each repaint)
|
||||
private val inLibraryContent = sourceInfo != null && viewSupport.isInLibraryContent(sourceInfo, script)
|
||||
private var evaluator: XDebuggerEvaluator? = null
|
||||
|
||||
private final Script script;
|
||||
|
||||
private final boolean inLibraryContent;
|
||||
private XDebuggerEvaluator evaluator;
|
||||
|
||||
public CallFrameView(@NotNull CallFrame callFrame, @NotNull DebuggerViewSupport viewSupport, @Nullable Script script) {
|
||||
this(callFrame, viewSupport.getSourceInfo(script, callFrame), viewSupport, script);
|
||||
constructor(callFrame: CallFrame, viewSupport: DebuggerViewSupport, script: Script?) : this(callFrame, viewSupport.getSourceInfo(script, callFrame), viewSupport, script) {
|
||||
}
|
||||
|
||||
public CallFrameView(@NotNull CallFrame callFrame,
|
||||
@Nullable SourceInfo sourceInfo,
|
||||
@NotNull DebuggerViewSupport viewSupport,
|
||||
@Nullable Script script) {
|
||||
this.sourceInfo = sourceInfo;
|
||||
override fun getEqualityObject() = callFrame.equalityObject
|
||||
|
||||
this.viewSupport = viewSupport;
|
||||
this.callFrame = callFrame;
|
||||
this.script = script;
|
||||
|
||||
// isInLibraryContent call could be costly, so we compute it only once (our customizePresentation called on each repaint)
|
||||
inLibraryContent = sourceInfo != null && viewSupport.isInLibraryContent(sourceInfo, script);
|
||||
override fun computeChildren(node: XCompositeNode) {
|
||||
node.setAlreadySorted(true)
|
||||
createAndAddScopeList(node, callFrame.variableScopes, this, callFrame)
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Script getScript() {
|
||||
return script;
|
||||
}
|
||||
override fun getEvaluateContext() = callFrame.evaluateContext
|
||||
|
||||
@Override
|
||||
public Object getEqualityObject() {
|
||||
return callFrame.getEqualityObject();
|
||||
}
|
||||
override fun getName() = null
|
||||
|
||||
@Override
|
||||
public void computeChildren(@NotNull XCompositeNode node) {
|
||||
node.setAlreadySorted(true);
|
||||
ScopeVariablesGroup.createAndAddScopeList(node, callFrame.getVariableScopes(), this, callFrame);
|
||||
}
|
||||
override fun getParent() = null
|
||||
|
||||
@NotNull
|
||||
public CallFrame getCallFrame() {
|
||||
return callFrame;
|
||||
}
|
||||
override fun watchableAsEvaluationExpression() = true
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public EvaluateContext getEvaluateContext() {
|
||||
return callFrame.getEvaluateContext();
|
||||
}
|
||||
override fun getViewSupport() = viewSupport
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
override fun getMemberFilter() = viewSupport.getMemberFilter(this)
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public VariableContext getParent() {
|
||||
return null;
|
||||
}
|
||||
fun getMemberFilter(scope: Scope) = createVariableContext(scope, this, callFrame).memberFilter
|
||||
|
||||
@Override
|
||||
public boolean watchableAsEvaluationExpression() {
|
||||
return true;
|
||||
}
|
||||
override fun getScope() = null
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DebuggerViewSupport getViewSupport() {
|
||||
return viewSupport;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Promise<MemberFilter> getMemberFilter() {
|
||||
return viewSupport.getMemberFilter(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Promise<MemberFilter> getMemberFilter(@NotNull Scope scope) {
|
||||
return ScopeVariablesGroup.createVariableContext(scope, this, callFrame).getMemberFilter();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Scope getScope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final XDebuggerEvaluator getEvaluator() {
|
||||
override fun getEvaluator(): XDebuggerEvaluator? {
|
||||
if (evaluator == null) {
|
||||
evaluator = viewSupport.createFrameEvaluator(this);
|
||||
evaluator = viewSupport.createFrameEvaluator(this)
|
||||
}
|
||||
return evaluator;
|
||||
return evaluator
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public SourceInfo getSourcePosition() {
|
||||
return sourceInfo;
|
||||
}
|
||||
override fun getSourcePosition() = sourceInfo
|
||||
|
||||
@Override
|
||||
public final void customizePresentation(@NotNull ColoredTextContainer component) {
|
||||
override fun customizePresentation(component: ColoredTextContainer) {
|
||||
if (sourceInfo == null) {
|
||||
String scriptName = script == null ? "unknown" : script.getUrl().trimParameters().toDecodedForm();
|
||||
int line = callFrame.getLine();
|
||||
component.append(line != -1 ? scriptName + ':' + line : scriptName, SimpleTextAttributes.ERROR_ATTRIBUTES);
|
||||
return;
|
||||
val scriptName = if (script == null) "unknown" else script.url.trimParameters().toDecodedForm()
|
||||
val line = callFrame.line
|
||||
component.append(if (line != -1) scriptName + ':' + line else scriptName, SimpleTextAttributes.ERROR_ATTRIBUTES)
|
||||
return
|
||||
}
|
||||
|
||||
String fileName = sourceInfo.getFile().getName();
|
||||
int line = sourceInfo.getLine() + 1;
|
||||
val fileName = sourceInfo.file.name
|
||||
val line = sourceInfo.line + 1
|
||||
|
||||
SimpleTextAttributes textAttributes = inLibraryContent ? SimpleTextAttributes.GRAYED_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES;
|
||||
val textAttributes = if (inLibraryContent) SimpleTextAttributes.GRAYED_ATTRIBUTES else SimpleTextAttributes.REGULAR_ATTRIBUTES
|
||||
|
||||
String functionName = sourceInfo.getFunctionName();
|
||||
val functionName = sourceInfo.functionName
|
||||
if (functionName == null || (functionName.isEmpty() && callFrame.hasOnlyGlobalScope())) {
|
||||
component.append(fileName + ":" + line, textAttributes);
|
||||
component.append(fileName + ":" + line, textAttributes)
|
||||
}
|
||||
else {
|
||||
if (functionName.isEmpty()) {
|
||||
component.append("anonymous", inLibraryContent ? SimpleTextAttributes.GRAYED_ITALIC_ATTRIBUTES : SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES);
|
||||
component.append("anonymous", if (inLibraryContent) SimpleTextAttributes.GRAYED_ITALIC_ATTRIBUTES else SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES)
|
||||
}
|
||||
else {
|
||||
component.append(functionName, textAttributes);
|
||||
component.append(functionName, textAttributes)
|
||||
}
|
||||
component.append("(), " + fileName + ":" + line, textAttributes);
|
||||
component.append("(), $fileName:$line", textAttributes)
|
||||
}
|
||||
component.setIcon(AllIcons.Debugger.StackFrame);
|
||||
component.setIcon(AllIcons.Debugger.StackFrame)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user