use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class ToggleFieldBreakpointAction method getPlace.
@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final Project project = event.getData(CommonDataKeys.PROJECT);
if (project == null) {
return null;
}
if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
if (psiElement instanceof PsiField) {
return SourcePosition.createFromElement(psiElement);
}
return null;
}
final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
if (debugProcess != null) {
// if there is an active debug session
final Ref<SourcePosition> positionRef = new Ref<>(null);
debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {
@Override
public Priority getPriority() {
return Priority.HIGH;
}
@Override
public void threadAction() {
ApplicationManager.getApplication().runReadAction(() -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)));
}
});
final SourcePosition sourcePosition = positionRef.get();
if (sourcePosition != null) {
return sourcePosition;
}
}
}
if (DebuggerAction.isContextView(event)) {
DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
if (tree != null && tree.getSelectionPath() != null) {
DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
if (psiClass != null) {
psiClass = (PsiClass) psiClass.getNavigationElement();
final PsiField psiField = psiClass.findFieldByName(field.name(), true);
if (psiField != null) {
return SourcePosition.createFromElement(psiField);
}
}
}
}
return null;
}
Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
}
if (editor != null) {
final Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
if (StdFileTypes.JAVA == fileType || StdFileTypes.CLASS == fileType) {
final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset());
if (field != null) {
return SourcePosition.createFromElement(field);
}
}
}
}
return null;
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class EditSourceAction method getSourcePosition.
private static SourcePosition getSourcePosition(DebuggerTreeNodeImpl selectedNode, DebuggerContextImpl debuggerContext) {
final DebuggerContextImpl context = debuggerContext;
if (selectedNode == null || context == null) {
return null;
}
final Project project = selectedNode.getProject();
final DebuggerSession debuggerSession = context.getDebuggerSession();
if (debuggerSession == null) {
return null;
}
NodeDescriptorImpl nodeDescriptor = selectedNode.getDescriptor();
if (nodeDescriptor instanceof WatchItemDescriptor) {
Modifier modifier = ((WatchItemDescriptor) nodeDescriptor).getModifier();
if (modifier == null) {
return null;
}
nodeDescriptor = (NodeDescriptorImpl) modifier.getInspectItem(project);
}
final NodeDescriptorImpl nodeDescriptor1 = nodeDescriptor;
return ApplicationManager.getApplication().runReadAction(new Computable<SourcePosition>() {
public SourcePosition compute() {
return SourcePositionProvider.getSourcePosition(nodeDescriptor1, project, context);
}
});
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class EvaluationDescriptor method calcValue.
public final Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
try {
PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(() -> {
});
EvaluationContextImpl thisEvaluationContext = getEvaluationContext(evaluationContext);
SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
PsiElement psiContext = ContextUtil.getContextElement(evaluationContext, position);
ExpressionEvaluator evaluator = ReadAction.compute(() -> {
PsiCodeFragment code = getEvaluationCode(thisEvaluationContext);
try {
return DebuggerUtilsEx.findAppropriateCodeFragmentFactory(getEvaluationText(), psiContext).getEvaluatorBuilder().build(code, position);
} catch (UnsupportedExpressionException ex) {
ExpressionEvaluator eval = CompilingEvaluatorImpl.create(myProject, code.getContext(), element -> code);
if (eval != null) {
return eval;
}
throw ex;
}
});
if (!thisEvaluationContext.getDebugProcess().isAttached()) {
throw EvaluateExceptionUtil.PROCESS_EXITED;
}
StackFrameProxyImpl frameProxy = thisEvaluationContext.getFrameProxy();
if (frameProxy == null) {
throw EvaluateExceptionUtil.NULL_STACK_FRAME;
}
Value value = evaluator.evaluate(thisEvaluationContext);
DebuggerUtilsEx.keep(value, thisEvaluationContext);
myModifier = evaluator.getModifier();
setLvalue(myModifier != null);
return value;
} catch (final EvaluateException ex) {
throw new EvaluateException(ex.getLocalizedMessage(), ex);
} catch (ObjectCollectedException ex) {
throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED;
}
}
use of com.intellij.debugger.SourcePosition in project kotlin by JetBrains.
the class AbstractPositionManagerTest method assertBreakpointIsHandledCorrectly.
private static void assertBreakpointIsHandledCorrectly(Breakpoint breakpoint, PositionManager positionManager) throws NoDataException {
SourcePosition position = SourcePosition.createFromLine(breakpoint.file, breakpoint.lineNumber);
List<ReferenceType> classes = positionManager.getAllClasses(position);
assertNotNull(classes);
assertEquals(1, classes.size());
ReferenceType type = classes.get(0);
assertTrue("Type name " + type.name() + " doesn't match " + breakpoint.classNameRegexp + " for line " + (breakpoint.lineNumber + 1), type.name().matches(breakpoint.classNameRegexp));
// JDI names are of form "package.Class$InnerClass"
ReferenceType typeWithFqName = new MockReferenceType(type.name().replace('/', '.'));
Location location = new MockLocation(typeWithFqName, breakpoint.file.getName(), breakpoint.lineNumber + 1);
SourcePosition actualPosition = positionManager.getSourcePosition(location);
assertNotNull(actualPosition);
assertEquals(position.getFile(), actualPosition.getFile());
assertEquals(position.getLine(), actualPosition.getLine());
}
use of com.intellij.debugger.SourcePosition in project smali by JesusFreke.
the class SmaliSteppingCommandProvider method getStepOverCommand.
@Override
public ResumeCommand getStepOverCommand(@NotNull final SuspendContextImpl suspendContext, boolean ignoreBreakpoints, int stepSize) {
final SourcePosition[] location = new SourcePosition[1];
suspendContext.getDebugProcess().getManagerThread().invokeAndWait(new DebuggerCommandImpl() {
@Override
protected void action() throws Exception {
location[0] = ContextUtil.getSourcePosition(suspendContext);
}
});
if (location[0] != null && location[0].getFile().getLanguage() == SmaliLanguage.INSTANCE) {
return suspendContext.getDebugProcess().createStepOverCommand(suspendContext, ignoreBreakpoints, StepRequest.STEP_MIN);
}
return null;
}
Aggregations