Skip to content

Commit

Permalink
PHP: Implemented display of exception message when exception breakpoi…
Browse files Browse the repository at this point in the history
…nts are hit
  • Loading branch information
troizet committed Jan 24, 2024
1 parent 2100f39 commit 401c2ce
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class BreakpointModel extends ViewModelSupport implements NodeModel {
private static final String METHOD = "TXT_Method"; // NOI18N
private static final String EXCEPTION = "TXT_Exception"; // NOI18N
private static final String PARENS = "()"; // NOI18N
private static final String MESSAGE = "Message: "; // NOI18N
private static final String CODE = "Code: "; // NOI18N
private static final String FONT_COLOR = "<font color=\"#7D694A\">"; //NOI18N
private static final String CLOSE_FONT = "</font>"; //NOI18N
private static final String OPEN_HTML = "<html>"; //NOI18N
private static final String CLOSE_HTML = "</html>"; //NOI18N
private final Map<DebugSession, AbstractBreakpoint> myCurrentBreakpoints;
private volatile boolean searchCurrentBreakpointById = false;

Expand All @@ -79,14 +85,39 @@ public String getDisplayName(Object node) throws UnknownTypeException {
return builder.toString();
} else if (node instanceof ExceptionBreakpoint) {
ExceptionBreakpoint breakpoint = (ExceptionBreakpoint) node;
StringBuilder builder = new StringBuilder(NbBundle.getMessage(BreakpointModel.class, EXCEPTION));
StringBuilder builder = new StringBuilder();
builder.append(OPEN_HTML);
builder.append(NbBundle.getMessage(BreakpointModel.class, EXCEPTION));
builder.append(" "); // NOI18N
builder.append(breakpoint.getException());
String message = breakpoint.getExceptionMessage();
String code = breakpoint.getExceptionCode();
synchronized (myCurrentBreakpoints) {
for (AbstractBreakpoint brkp : myCurrentBreakpoints.values()) {
if (breakpoint.equals(brkp)) {
if (message != null) {
buildAppend(builder, MESSAGE, message);
}
if (code != null) {
buildAppend(builder, CODE, code);
}
}
}
}
builder.append(CLOSE_HTML);
return builder.toString();
}
throw new UnknownTypeException(node);
}

private void buildAppend(StringBuilder builder, String prepend, String text) {
builder.append(" "); // NOI18N
builder.append(FONT_COLOR);
builder.append(prepend);
builder.append(text);
builder.append(CLOSE_FONT);
}

@Override
public String getIconBase(Object node) throws UnknownTypeException {
synchronized (myCurrentBreakpoints) {
Expand Down Expand Up @@ -221,6 +252,12 @@ private void updateCurrentBreakpoint(DebugSession session, Breakpoint breakpoint
}
}

public AbstractBreakpoint getCurrentBreakpoint(DebugSession session) {
synchronized (myCurrentBreakpoints) {
return myCurrentBreakpoints.get(session);
}
}

public void setSearchCurrentBreakpointById(boolean flag) {
searchCurrentBreakpointById = flag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
*/
public class ExceptionBreakpoint extends AbstractBreakpoint {
private final String exceptionName;
private String message;
private String code;
private static final String FONT_GRAY_COLOR = "<font color=\"#999999\">"; //NOI18N
private static final String CLOSE_FONT = "</font>"; //NOI18N

public ExceptionBreakpoint(String exceptionName) {
this.exceptionName = exceptionName;
Expand All @@ -36,6 +40,34 @@ public String getException() {
return exceptionName;
}

public void setExceptionMessage(String message) {
this.message = message;
}

public String getExceptionMessage() {
return buildText(message);
}

public void setExceptionCode(String code) {
this.code = code;
}

public String getExceptionCode() {
return buildText(code);
}

private String buildText(String text) {
if (text != null && !text.isEmpty()) {
StringBuilder builder = new StringBuilder();
builder.append(FONT_GRAY_COLOR);
builder.append(text);
builder.append(CLOSE_FONT);
return builder.toString();
}

return null;
}

@Override
public boolean isSessionRelated(DebugSession session) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
package org.netbeans.modules.php.dbgp.packets;

import org.netbeans.modules.php.dbgp.DebugSession;
import org.netbeans.modules.php.dbgp.breakpoints.AbstractBreakpoint;
import org.netbeans.modules.php.dbgp.breakpoints.BreakpointModel;
import org.netbeans.modules.php.dbgp.breakpoints.ExceptionBreakpoint;
import org.w3c.dom.Node;

public class RunResponse extends StatusResponse {
private static final String BREAKPOINT = "breakpoint"; //NOI18N
private static final String BREAKPOINT_ID = "id"; //NOI18N
private static final String MESSAGE = "xdebug:message"; //NOI18N
private static final String CODE = "code"; //NOI18N

RunResponse(Node node) {
super(node);
Expand All @@ -38,16 +42,25 @@ public void process(DebugSession dbgSession, DbgpCommand command) {
dbgSession.processStatus(status, reason, command);
}

Node message = getChild(getNode(), MESSAGE);
String code = null;
if (message != null) {
code = getAttribute(message, CODE);
}

Node breakpoint = getChild(getNode(), BREAKPOINT);
if (breakpoint != null) {
String id = DbgpMessage.getAttribute(breakpoint, BREAKPOINT_ID);
if (id != null) {
updateBreakpointsView(dbgSession, id);
setCurrentBreakpoint(dbgSession, id);
if (message != null) {
setCurrentBreakpointText(dbgSession, message.getTextContent(), code);
}
}
}
}

private void updateBreakpointsView(DebugSession session, String id) {
private void setCurrentBreakpoint(DebugSession session, String id) {
DebugSession.IDESessionBridge bridge = session.getBridge();
if (bridge != null) {
BreakpointModel breakpointModel = bridge.getBreakpointModel();
Expand All @@ -57,4 +70,18 @@ private void updateBreakpointsView(DebugSession session, String id) {
}
}

private void setCurrentBreakpointText(DebugSession session, String message, String code) {
DebugSession.IDESessionBridge bridge = session.getBridge();
if (bridge != null) {
BreakpointModel breakpointModel = bridge.getBreakpointModel();
if (breakpointModel != null && breakpointModel.isSearchCurrentBreakpointById()) {
AbstractBreakpoint bp = breakpointModel.getCurrentBreakpoint(session);
if (bp != null && bp instanceof ExceptionBreakpoint) {
((ExceptionBreakpoint) bp).setExceptionMessage(message);
((ExceptionBreakpoint) bp).setExceptionCode(code);
}
}
}
}

}

0 comments on commit 401c2ce

Please sign in to comment.