blob: 805fbdd17fe2d85a2f4cbb5c859f804140350dc5 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2016, 2019 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.r.debug.core.breakpoints;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.statet.r.debug.core.RDebugModel;
import org.eclipse.statet.r.debug.core.breakpoints.IRExceptionBreakpoint;
public class RExceptionBreakpoint extends RBreakpoint implements IRExceptionBreakpoint {
public static final String R_EXCEPTION_BREAKPOINT_MARKER_TYPE= "org.eclipse.statet.r.resourceMarkers.RExceptionBreakpoint"; //$NON-NLS-1$
public static final String EXCEPTION_ID_MARKER_ATTR= "org.eclipse.statet.r.resourceMarkers.ExceptionIdAttribute"; //$NON-NLS-1$
public RExceptionBreakpoint(final IResource resource, final String exceptionId,
final boolean temporary) throws DebugException {
final Map<String, Object> attributes= new HashMap<>();
attributes.put(IBreakpoint.ID, getModelIdentifier());
attributes.put(IBreakpoint.ENABLED, Boolean.TRUE);
attributes.put(EXCEPTION_ID_MARKER_ATTR, exceptionId);
final IWorkspaceRunnable wr = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
// create the marker
setMarker(resource.createMarker(R_EXCEPTION_BREAKPOINT_MARKER_TYPE));
// update attributes
ensureMarker().setAttributes(attributes);
register(!temporary);
if (temporary) {
setPersisted(false);
}
}
};
run(ResourcesPlugin.getWorkspace().getRuleFactory().markerRule(resource), wr);
}
public RExceptionBreakpoint() {
}
@Override
public String getBreakpointType() {
return RDebugModel.R_EXCEPTION_BREAKPOINT_TYPE_ID;
}
@Override
public String getExceptionId() throws DebugException {
return ensureMarker().getAttribute(EXCEPTION_ID_MARKER_ATTR, null);
}
}