package jetbrains.mps.debugger.java.runtime.breakpoints;
/*Generated by MPS */
import jetbrains.mps.debug.api.breakpoints.ILocationBreakpoint;
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
import org.jetbrains.mps.openapi.model.SNodeReference;
import jetbrains.mps.debug.api.breakpoints.BreakpointLocation;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.project.Project;
import org.jetbrains.mps.openapi.model.SNode;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.debugger.java.runtime.engine.events.EventsProcessor;
import com.sun.jdi.ReferenceType;
import jetbrains.mps.debugger.java.runtime.engine.RequestManager;
import jetbrains.mps.textgen.trace.TraceablePositionInfo;
import com.sun.jdi.Field;
import jetbrains.mps.debugger.java.api.evaluation.EvaluationUtils;
import com.sun.jdi.ClassType;
import com.sun.jdi.request.AccessWatchpointRequest;
import com.sun.jdi.request.ModificationWatchpointRequest;
import com.sun.jdi.ClassNotPreparedException;
import com.sun.jdi.ObjectCollectedException;
import com.sun.jdi.InternalException;
public class FieldBreakpoint extends JavaBreakpoint implements ILocationBreakpoint {
private static final Logger LOG = LogManager.getLogger(FieldBreakpoint.class);
private final SNodeReference myNode;
private BreakpointLocation myLocation;
public FieldBreakpoint(@NotNull SNodeReference nodePointer, Project project) {
super(project);
myNode = nodePointer;
}
public FieldBreakpoint(@NotNull SNode node, Project project) {
this(node.getReference(), project);
}
@NotNull
@Override
public BreakpointLocation getLocation() {
if (myLocation == null) {
myLocation = new BreakpointLocationUpdate(myNode, getRepository()).get();
}
return myLocation;
}
@Override
@Nullable
protected String getClassNameToPrepare() {
return getLocation().getTargetUnitName();
}
@NotNull
@Override
public JavaBreakpointKind getKind() {
return JavaBreakpointKind.FIELD_BREAKPOINT;
}
@Override
public String getPresentation() {
return new BreakpointPresentation(getLocation(), getRepository()).getText();
}
@Override
protected void createRequestForPreparedClass(EventsProcessor debugProcess, ReferenceType classType) {
RequestManager requestManager = debugProcess.getRequestManager();
TraceablePositionInfo targetCodePosition = getLocation().getTargetCodePosition();
String fieldName = (targetCodePosition == null ? null : targetCodePosition.getPropertyString());
if ((fieldName == null || fieldName.length() == 0)) {
return;
}
try {
Field field = EvaluationUtils.getInstance().findField((ClassType) classType, fieldName);
AccessWatchpointRequest fieldAccessRequest = requestManager.createFieldAccessRequest(this, field);
ModificationWatchpointRequest fieldModificationRequest = requestManager.createFieldModificationRequest(this, field);
requestManager.enableRequest(fieldAccessRequest);
requestManager.enableRequest(fieldModificationRequest);
} catch (ClassNotPreparedException ex) {
LOG.warn("ClassNotPreparedException: " + ex.getMessage());
// there's a chance to add a breakpoint when the class is prepared
} catch (ObjectCollectedException ex) {
LOG.warn("ObjectCollectedException: " + ex.getMessage());
} catch (InternalException ex) {
LOG.error(null, ex);
} catch (Exception ex) {
LOG.error(null, ex);
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
return eq_he6f5h_a0d0n(getLocation(), ((FieldBreakpoint) o).getLocation());
}
@Override
public int hashCode() {
return myNode.hashCode() + getKind().hashCode() * 31;
}
private static boolean eq_he6f5h_a0d0n(Object a, Object b) {
return (a != null ? a.equals(b) : a == b);
}
}