void (PsiFile file) { Runnable runnable = () -> { BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager(); Document document = PsiDocumentManager.getInstance(myProject).getDocument(file); assert document != null; String text = document.getText(); for (int offset = -1; (offset = text.indexOf("Breakpoint!", offset + 1)) != -1; ) { int commentLine = document.getLineNumber(offset); String fileName = file.getVirtualFile().getName(); String breakpointLocation = fileName + ":" + (commentLine + 1 + 1); String commentText = text.substring(document.getLineStartOffset(commentLine), document.getLineEndOffset(commentLine)); BreakpointComment comment = BreakpointComment.parse(commentText, file.getVirtualFile().getPresentableUrl(), commentLine); Breakpoint breakpoint; String kind = comment.readKind(); switch (kind) { case "Method" -> { breakpoint = breakpointManager.addMethodBreakpoint(document, commentLine + 1); if (breakpoint != null) { systemPrintln("MethodBreakpoint created at " + breakpointLocation); Boolean emulated = comment.readBooleanValue("Emulated"); if (emulated != null) { ((JavaMethodBreakpointProperties)breakpoint.getXBreakpoint().getProperties()).EMULATED = emulated; systemPrintln("Emulated = " + emulated); } Boolean entry = comment.readBooleanValue("OnEntry"); if (entry != null) { ((JavaMethodBreakpointProperties)breakpoint.getXBreakpoint().getProperties()).WATCH_ENTRY = entry; systemPrintln("On Entry = " + entry); } Boolean exit = comment.readBooleanValue("OnExit"); if (exit != null) { ((JavaMethodBreakpointProperties)breakpoint.getXBreakpoint().getProperties()).WATCH_EXIT = exit; systemPrintln("On Exit = " + exit); } } } case "Field" -> { breakpoint = breakpointManager.addFieldBreakpoint(document, commentLine + 1, comment.readKindValue()); if (breakpoint != null) { systemPrintln("FieldBreakpoint created at " + breakpointLocation); } } case "Exception" -> { String exceptionClassName = Objects.requireNonNull(comment.readKindValue()); breakpoint = breakpointManager.addExceptionBreakpoint(exceptionClassName, ""); if (breakpoint == null) break; systemPrintln("ExceptionBreakpoint created at " + breakpointLocation); String catchClassFiltersStr = comment.readValue("Catch class filters"); if (catchClassFiltersStr != null) { Pair<ClassFilter[], ClassFilter[]> filters = BreakpointComment.parseClassFilters(catchClassFiltersStr); ExceptionBreakpoint exceptionBreakpoint = (ExceptionBreakpoint)breakpoint; exceptionBreakpoint.setCatchFiltersEnabled(true); exceptionBreakpoint.setCatchClassFilters(filters.first); exceptionBreakpoint.setCatchClassExclusionFilters(filters.second); systemPrintln("Catch class filters = " + catchClassFiltersStr); } } case "ConditionalReturn" -> { breakpoint = breakpointManager.addLineBreakpoint(document, commentLine + 1, p -> { int lambdaOrdinal = -1; // Note that we don't support `return` inside of lambda in unit tests. p.setEncodedInlinePosition(JavaLineBreakpointProperties.encodeInlinePosition(lambdaOrdinal, true)); }); if (breakpoint != null) { systemPrintln("ConditionalReturnBreakpoint created at " + breakpointLocation); } } case "Line" -> { breakpoint = breakpointManager.addLineBreakpoint(document, commentLine + 1); if (breakpoint != null) { systemPrintln("LineBreakpoint created at " + breakpointLocation); } } default -> throw new IllegalArgumentException("Invalid kind '" + kind + "' at " + fileName + ":" + (commentLine + 1)); } if (breakpoint == null) { LOG.error("Unable to set a breakpoint at line " + (commentLine + 1)); continue; } String enabled = comment.readValue("Enabled"); if (enabled != null) { breakpoint.getXBreakpoint().setEnabled(Boolean.parseBoolean(enabled)); systemPrintln("Enabled = " + enabled); } String suspendPolicy = comment.readValue("suspendPolicy"); if (suspendPolicy != null) { //breakpoint.setSuspend(!DebuggerSettings.SUSPEND_NONE.equals(suspendPolicy)); breakpoint.setSuspendPolicy(suspendPolicy); systemPrintln("SUSPEND_POLICY = " + suspendPolicy); } String condition = comment.readValue("Condition"); if (condition != null) { //breakpoint.CONDITION_ENABLED = true; breakpoint.setCondition(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, condition)); systemPrintln("Condition = " + condition); } String logExpression = comment.readValue("LogExpression"); if (logExpression != null) { breakpoint.getXBreakpoint().setLogExpression(logExpression); systemPrintln("LogExpression = " + logExpression); } Integer passCount = comment.readIntValue("Pass count"); if (passCount != null) { breakpoint.setCountFilterEnabled(true); breakpoint.setCountFilter(passCount); systemPrintln("Pass count = " + passCount); } String classFiltersStr = comment.readValue("Class filters"); if (classFiltersStr != null) { breakpoint.setClassFiltersEnabled(true); Pair<ClassFilter[], ClassFilter[]> filters = BreakpointComment.parseClassFilters(classFiltersStr); breakpoint.setClassFilters(filters.first); breakpoint.setClassExclusionFilters(filters.second); systemPrintln("Class filters = " + classFiltersStr); } comment.done(); } }; if (!SwingUtilities.isEventDispatchThread()) { DebuggerInvocationUtil.invokeAndWait(myProject, runnable, ModalityState.defaultModalityState()); } else { runnable.run(); } }