-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Roenke/tests-with-debugger
Add tests to tracing which use a java debugger
- Loading branch information
Showing
119 changed files
with
1,735 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 0 additions & 153 deletions
153
src/main/java/com/intellij/debugger/streams/action/JvmStreamDebuggerActionHandler.java
This file was deleted.
Oops, something went wrong.
75 changes: 62 additions & 13 deletions
75
src/main/java/com/intellij/debugger/streams/action/TraceStreamAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,81 @@ | ||
package com.intellij.debugger.streams.action; | ||
|
||
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; | ||
import com.intellij.debugger.streams.psi.DebuggerPositionResolver; | ||
import com.intellij.debugger.streams.psi.impl.DebuggerPositionResolverImpl; | ||
import com.intellij.debugger.streams.resolve.ResolvedTrace; | ||
import com.intellij.debugger.streams.trace.*; | ||
import com.intellij.debugger.streams.trace.impl.TraceExpressionBuilderImpl; | ||
import com.intellij.debugger.streams.trace.impl.TraceResultInterpreterImpl; | ||
import com.intellij.debugger.streams.ui.EvaluationAwareTraceWindow; | ||
import com.intellij.debugger.streams.wrapper.StreamChain; | ||
import com.intellij.debugger.streams.wrapper.StreamChainBuilder; | ||
import com.intellij.debugger.streams.wrapper.impl.StreamChainBuilderImpl; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.xdebugger.XDebugSession; | ||
import com.intellij.xdebugger.XDebuggerManager; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Vitaliy.Bibaev | ||
*/ | ||
public class TraceStreamAction extends AnAction { | ||
private static class Holder { | ||
private static final JvmStreamDebuggerActionHandler HANDLER = new JvmStreamDebuggerActionHandler(); | ||
private static final Logger LOG = Logger.getInstance(TraceStreamAction.class); | ||
|
||
private final DebuggerPositionResolver myPositionResolver = new DebuggerPositionResolverImpl(); | ||
private final TraceExpressionBuilder myExpressionBuilder = new TraceExpressionBuilderImpl(); | ||
private final TraceResultInterpreter myResultInterpreter = new TraceResultInterpreterImpl(); | ||
private final StreamChainBuilder myChainBuilder = new StreamChainBuilderImpl(); | ||
|
||
@Override | ||
public void update(@NotNull AnActionEvent e) { | ||
final XDebugSession session = getCurrentSession(e); | ||
final PsiElement element = session == null ? null : myPositionResolver.getNearestElementToBreakpoint(session); | ||
e.getPresentation().setEnabled(element != null && myChainBuilder.isChainExists(element)); | ||
} | ||
|
||
@Override | ||
public void update(AnActionEvent e) { | ||
final Project project = e.getProject(); | ||
if (project != null) { | ||
e.getPresentation().setEnabled(Holder.HANDLER.isEnabled(project)); | ||
return; | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
final XDebugSession session = getCurrentSession(e); | ||
final PsiElement element = session == null ? null : myPositionResolver.getNearestElementToBreakpoint(session); | ||
final StreamChain chain = element == null ? null : myChainBuilder.build(element); | ||
|
||
if (chain != null) { | ||
final EvaluationAwareTraceWindow window = new EvaluationAwareTraceWindow(session.getProject(), chain); | ||
ApplicationManager.getApplication().invokeLater(window::show); | ||
final StreamTracer tracer = new EvaluateExpressionTracer(session, myExpressionBuilder, myResultInterpreter); | ||
tracer.trace(chain, new TracingCallback() { | ||
@Override | ||
public void evaluated(@NotNull TracingResult result, @NotNull EvaluationContextImpl context) { | ||
final ResolvedTracingResult resolvedTrace = result.resolve(); | ||
final List<ResolvedTrace> calls = resolvedTrace.getResolvedTraces(); | ||
ApplicationManager.getApplication() | ||
.invokeLater(() -> window.setTrace(calls, result.getResult(), context)); | ||
} | ||
|
||
@Override | ||
public void failed(@NotNull String traceExpression, @NotNull String reason) { | ||
LOG.warn(reason + System.lineSeparator() + "expression:" + System.lineSeparator() + traceExpression); | ||
ApplicationManager.getApplication().invokeLater(() -> window.setFailMessage(reason)); | ||
} | ||
}); | ||
} | ||
else { | ||
LOG.warn("stream chain is not built"); | ||
} | ||
e.getPresentation().setEnabled(false); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(AnActionEvent e) { | ||
@Nullable | ||
private XDebugSession getCurrentSession(@NotNull AnActionEvent e) { | ||
final Project project = e.getProject(); | ||
if (project != null && Holder.HANDLER.isEnabled(project)) { | ||
Holder.HANDLER.perform(project); | ||
} | ||
return project == null ? null : XDebuggerManager.getInstance(project).getCurrentSession(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/intellij/debugger/streams/psi/DebuggerPositionResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.intellij.debugger.streams.psi; | ||
|
||
import com.intellij.psi.PsiElement; | ||
import com.intellij.xdebugger.XDebugSession; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* @author Vitaliy.Bibaev | ||
*/ | ||
public interface DebuggerPositionResolver { | ||
@Nullable | ||
PsiElement getNearestElementToBreakpoint(@NotNull XDebugSession session); | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/intellij/debugger/streams/psi/impl/DebuggerPositionResolverImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.intellij.debugger.streams.psi.impl; | ||
|
||
import com.intellij.debugger.DebuggerManagerEx; | ||
import com.intellij.debugger.SourcePosition; | ||
import com.intellij.debugger.impl.DebuggerContextImpl; | ||
import com.intellij.debugger.impl.DebuggerUtilsEx; | ||
import com.intellij.debugger.streams.psi.DebuggerPositionResolver; | ||
import com.intellij.openapi.editor.Document; | ||
import com.intellij.openapi.fileEditor.FileDocumentManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.psi.PsiDocumentManager; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.xdebugger.XDebugSession; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* @author Vitaliy.Bibaev | ||
*/ | ||
public class DebuggerPositionResolverImpl implements DebuggerPositionResolver { | ||
@Nullable | ||
@Override | ||
public PsiElement getNearestElementToBreakpoint(@NotNull XDebugSession session) { | ||
final Project project = session.getProject(); | ||
final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(session.getProject()).getContext(); | ||
final SourcePosition position = debuggerContext.getSourcePosition(); | ||
|
||
if (position == null) { | ||
return null; | ||
} | ||
|
||
final int line = position.getLine(); | ||
final PsiFile psiFile = position.getFile(); | ||
final VirtualFile file = psiFile.getVirtualFile(); | ||
|
||
if (line >= 0 && file != null) { | ||
final Document document = FileDocumentManager.getInstance().getDocument(file); | ||
if (document != null) { | ||
final int offset = document.getLineStartOffset(line); | ||
return DebuggerUtilsEx.findElementAt(PsiDocumentManager.getInstance(project).getPsiFile(document), offset); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
src/main/java/com/intellij/debugger/streams/remote/InvokeMethodProxy.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.