From f03bc43a095589cabe44feeec7b22e4e299ef644 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 12 Mar 2014 18:50:46 +0100 Subject: [PATCH] cleanup --- .../debugger/engine/SuspendManagerUtil.java | 13 +++------- .../evaluation/EvaluationContextImpl.java | 7 ++--- .../expression/BlockStatementEvaluator.java | 2 ++ .../ConditionalExpressionEvaluator.java | 6 +++-- .../expression/ExpressionEvaluatorImpl.java | 15 +++++++---- .../expression/LocalVariableEvaluator.java | 13 ++++++++-- .../expression/MethodEvaluator.java | 5 +++- .../intellij/debugger/impl/InvokeThread.java | 3 ++- .../debugger/jdi/StackFrameProxyImpl.java | 26 +++++++++++-------- .../engine/evaluation/EvaluationContext.java | 2 ++ 10 files changed, 56 insertions(+), 36 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerUtil.java b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerUtil.java index e53f9d5a520e..8113121d3e1d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerUtil.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/SuspendManagerUtil.java @@ -19,8 +19,6 @@ import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.openapi.diagnostic.Logger; import java.util.HashSet; -import java.util.Iterator; -import java.util.ListIterator; import java.util.Set; public class SuspendManagerUtil { @@ -36,9 +34,8 @@ public class SuspendManagerUtil { } public static SuspendContextImpl findContextByThread(SuspendManager suspendManager, ThreadReferenceProxyImpl thread) { - for (ListIterator iterator = ((SuspendManagerImpl) suspendManager).getPausedContexts().listIterator(); iterator.hasNext();) { - SuspendContextImpl context = iterator.next(); - if(context.getThread() == thread) { + for (SuspendContextImpl context : ((SuspendManagerImpl)suspendManager).getPausedContexts()) { + if (context.getThread() == thread) { return context; } } @@ -78,8 +75,7 @@ public class SuspendManagerUtil { LOG.assertTrue(context.myResumedThreads == null); if(data.myResumedThreads != null) { - for (Iterator iterator = data.myResumedThreads.iterator(); iterator.hasNext();) { - ThreadReferenceProxyImpl resumedThreads = iterator.next(); + for (ThreadReferenceProxyImpl resumedThreads : data.myResumedThreads) { resumedThreads.resume(); } context.myResumedThreads = data.myResumedThreads; @@ -101,8 +97,7 @@ public class SuspendManagerUtil { LOG.debug("Resuming SuspendContextImpl..."); } if(context.myResumedThreads != null) { - for (Iterator iterator = context.myResumedThreads.iterator(); iterator.hasNext();) { - ThreadReferenceProxyImpl resumedThreads = iterator.next(); + for (ThreadReferenceProxyImpl resumedThreads : context.myResumedThreads) { resumedThreads.suspend(); } context.myResumedThreads = null; diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java index a205bb25fd70..b6ca9eafe1f1 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/EvaluationContextImpl.java @@ -25,11 +25,6 @@ import com.sun.jdi.Value; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * User: lex - * Date: Aug 28, 2003 - * Time: 2:02:29 PM - */ public final class EvaluationContextImpl implements EvaluationContext{ private final Value myThisObject; private final SuspendContextImpl mySuspendContext; @@ -48,6 +43,7 @@ public final class EvaluationContextImpl implements EvaluationContext{ return myThisObject; } + @NotNull @Override public SuspendContextImpl getSuspendContext() { return mySuspendContext; @@ -77,6 +73,7 @@ public final class EvaluationContextImpl implements EvaluationContext{ return copy; } + @Nullable @Override public ClassLoaderReference getClassLoader() throws EvaluateException { DebuggerManagerThreadImpl.assertIsManagerThread(); diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/BlockStatementEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/BlockStatementEvaluator.java index 464aa6ea4f35..57b1a44bb3c5 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/BlockStatementEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/BlockStatementEvaluator.java @@ -28,6 +28,7 @@ public class BlockStatementEvaluator implements Evaluator { myStatements = statements; } + @Override public Object evaluate(EvaluationContextImpl context) throws EvaluateException { Object result = context.getSuspendContext().getDebugProcess().getVirtualMachineProxy().mirrorOf(); for (Evaluator statement : myStatements) { @@ -36,6 +37,7 @@ public class BlockStatementEvaluator implements Evaluator { return result; } + @Override public Modifier getModifier() { return myStatements.length > 0 ? myStatements[myStatements.length - 1].getModifier() : null; } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java index 3514d357610b..7eacd4ace313 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ConditionalExpressionEvaluator.java @@ -20,10 +20,10 @@ */ package com.intellij.debugger.engine.evaluation.expression; -import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; +import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; -import com.intellij.debugger.DebuggerBundle; +import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.sun.jdi.BooleanValue; import com.sun.jdi.Value; @@ -38,10 +38,12 @@ class ConditionalExpressionEvaluator implements Evaluator { myElseEvaluator = elseEvaluator; } + @Override public Modifier getModifier() { return null; } + @Override public Object evaluate(EvaluationContextImpl context) throws EvaluateException { Value condition = (Value)myConditionEvaluator.evaluate(context); if (condition == null || !(condition instanceof BooleanValue)) { diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ExpressionEvaluatorImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ExpressionEvaluatorImpl.java index 4b974c183b54..66fd0eb3971e 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ExpressionEvaluatorImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/ExpressionEvaluatorImpl.java @@ -15,11 +15,11 @@ */ package com.intellij.debugger.engine.evaluation.expression; +import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; import com.intellij.debugger.engine.evaluation.EvaluationContext; import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; -import com.intellij.debugger.DebuggerBundle; import com.intellij.openapi.diagnostic.Logger; import com.sun.jdi.Value; @@ -40,16 +40,19 @@ public class ExpressionEvaluatorImpl implements ExpressionEvaluator { } //call evaluate before + @Override public Value getValue() { return myValue; } //call evaluate before + @Override public Modifier getModifier() { return myEvaluator.getModifier(); } // EvaluationContextImpl should be at the same stackFrame as it was in the call to EvaluatorBuilderImpl.build + @Override public Value evaluate(final EvaluationContext context) throws EvaluateException { if (!context.getDebugProcess().isAttached()) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("error.vm.disconnected")); @@ -61,22 +64,24 @@ public class ExpressionEvaluatorImpl implements ExpressionEvaluator { Object value = myEvaluator.evaluate((EvaluationContextImpl)context); - if(value != null && !(value instanceof Value)) { + if (value != null && !(value instanceof Value)) { throw EvaluateExceptionUtil .createEvaluateException(DebuggerBundle.message("evaluation.error.invalid.expression", "")); } - myValue = (Value) value; + myValue = (Value)value; return myValue; } catch (Throwable/*IncompatibleThreadStateException*/ e) { if (LOG.isDebugEnabled()) { LOG.debug(e); } - if(e instanceof EvaluateException) + if (e instanceof EvaluateException) { throw ((EvaluateException)e); - else + } + else { throw EvaluateExceptionUtil.createEvaluateException(e); + } } } } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/LocalVariableEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/LocalVariableEvaluator.java index ce060c0bfd26..b02ec96fad31 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/LocalVariableEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/LocalVariableEvaluator.java @@ -53,6 +53,7 @@ class LocalVariableEvaluator implements Evaluator { myParameterIndex = parameterIndex; } + @Override public Object evaluate(EvaluationContextImpl context) throws EvaluateException { StackFrameProxyImpl frameProxy = context.getFrameProxy(); if (frameProxy == null) { @@ -109,37 +110,45 @@ class LocalVariableEvaluator implements Evaluator { } } + @Override public Modifier getModifier() { Modifier modifier = null; if (myEvaluatedVariable != null && myContext != null) { modifier = new Modifier() { + @Override public boolean canInspect() { return true; } + @Override public boolean canSetValue() { return true; } + @Override public void setValue(Value value) throws ClassNotLoadedException, InvalidTypeException { StackFrameProxyImpl frameProxy = myContext.getFrameProxy(); try { + assert frameProxy != null; frameProxy.setValue(myEvaluatedVariable, value); } catch (EvaluateException e) { - LOG.error(e); + LOG.error(e); } } + @Override public Type getExpectedType() throws ClassNotLoadedException { try { return myEvaluatedVariable.getType(); - } catch (EvaluateException e) { + } + catch (EvaluateException e) { LOG.error(e); return null; } } + @Override public NodeDescriptorImpl getInspectItem(Project project) { return new LocalVariableDescriptorImpl(project, myEvaluatedVariable); } diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java index a4f9a8d55d48..ed1ad4c2ab46 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/MethodEvaluator.java @@ -22,6 +22,7 @@ package com.intellij.debugger.engine.evaluation.expression; import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.engine.DebugProcessImpl; +import com.intellij.debugger.engine.DebuggerUtils; import com.intellij.debugger.engine.JVMName; import com.intellij.debugger.engine.evaluation.EvaluateException; import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; @@ -53,10 +54,12 @@ public class MethodEvaluator implements Evaluator { myArgumentEvaluators = argumentEvaluators; } + @Override public Modifier getModifier() { return null; } + @Override public Object evaluate(EvaluationContextImpl context) throws EvaluateException { if(!context.getDebugProcess().isAttached()) return null; DebugProcessImpl debugProcess = context.getDebugProcess(); @@ -126,7 +129,7 @@ public class MethodEvaluator implements Evaluator { if (requiresSuperObject && (referenceType instanceof ClassType)) { _refType = ((ClassType)referenceType).superclass(); } - final Method jdiMethod = DebuggerUtilsEx.findMethod(_refType, myMethodName, signature); + final Method jdiMethod = DebuggerUtils.findMethod(_refType, myMethodName, signature); if (jdiMethod == null) { throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.no.instance.method", methodName)); } diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java b/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java index 8b2d875279da..72f9abf97af3 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java @@ -39,6 +39,7 @@ public abstract class InvokeThread { myOwner = owner; } + @Override public void run() { synchronized (this) { while (myRequestFuture == null) { @@ -174,7 +175,7 @@ public abstract class InvokeThread { } if (LOG.isDebugEnabled()) { - LOG.debug("Request " + this.toString() + " exited"); + LOG.debug("Request " + toString() + " exited"); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java index a7fbffa5906e..94ff89a4dc31 100644 --- a/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/jdi/StackFrameProxyImpl.java @@ -26,11 +26,15 @@ import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil; import com.intellij.debugger.engine.jdi.StackFrameProxy; import com.intellij.openapi.diagnostic.Logger; import com.sun.jdi.*; +import gnu.trove.THashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.jdi.StackFrameProxyImpl"); @@ -43,7 +47,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { private ObjectReference myThisReference; private ClassLoaderReference myClassLoader; private Boolean myIsObsolete = null; - private Map myAllValues; + private Map myAllValues; public StackFrameProxyImpl(ThreadReferenceProxyImpl threadProxy, @NotNull StackFrame frame, int fromBottomIndex /* 1-based */) { super(threadProxy.getVirtualMachine()); @@ -252,6 +256,12 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { return variable != null ? new LocalVariableProxyImpl(this, variable) : null; } + @Nullable + public Value visibleValueByName(@NotNull String name) throws EvaluateException { + LocalVariable variable = visibleVariableByNameInt(name); + return variable != null ? getValue(new LocalVariableProxyImpl(this, variable)) : null; + } + protected LocalVariable visibleVariableByNameInt(String name) throws EvaluateException { DebuggerManagerThreadImpl.assertIsManagerThread(); InvalidStackFrameException error = null; @@ -283,8 +293,7 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { InvalidStackFrameException error = null; for (int attempt = 0; attempt < 2; attempt++) { try { - final Map allValues = getAllValues(); - return allValues.get(localVariable.getVariable()); + return getAllValues().get(localVariable.getVariable()); } catch (InvalidStackFrameException e) { error = e; @@ -332,13 +341,8 @@ public class StackFrameProxyImpl extends JdiProxy implements StackFrameProxy { checkValid(); if (myAllValues == null) { try { - final StackFrame stackFrame = getStackFrame(); - final Map values = stackFrame.getValues(stackFrame.visibleVariables()); - myAllValues = new HashMap(values.size()); - for (final LocalVariable variable : values.keySet()) { - final Value value = values.get(variable); - myAllValues.put(variable, value); - } + StackFrame stackFrame = getStackFrame(); + myAllValues = new THashMap(stackFrame.getValues(stackFrame.visibleVariables())); } catch (InconsistentDebugInfoException ignored) { clearCaches(); diff --git a/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/EvaluationContext.java b/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/EvaluationContext.java index 4df12415a9b1..f6e1531cb978 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/EvaluationContext.java +++ b/java/debugger/openapi/src/com/intellij/debugger/engine/evaluation/EvaluationContext.java @@ -31,10 +31,12 @@ public interface EvaluationContext extends StackFrameContext{ EvaluationContext createEvaluationContext(Value value); + @NotNull SuspendContext getSuspendContext(); Project getProject(); + @Nullable ClassLoaderReference getClassLoader() throws EvaluateException; @Nullable