/*
 * FindBugs Eclipse Plug-in.
 * Copyright (C) 2003 - 2004, Peter Friese
 * Copyright (C) 2005, University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package de.tobject.findbugs.reporter;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import de.tobject.findbugs.marker.FindBugsMarker;
import edu.umd.cs.findbugs.BugInstance;

/**
 * Creates a FindBugs marker in a runnable window.
 */
public class MarkerReporter implements IWorkspaceRunnable {
	BugInstance bug;
	IResource resource;
	int startLine;

	public MarkerReporter(BugInstance bug, IResource resource, int startLine) {
		this.startLine = startLine;
		this.bug=bug;
		this.resource=resource;
	}

	public void run(IProgressMonitor monitor) throws CoreException {

		IMarker marker = resource.createMarker(FindBugsMarker.NAME);
		marker.setAttribute(IMarker.LINE_NUMBER, startLine);
		marker.setAttribute(FindBugsMarker.BUG_TYPE, bug.getType());
		marker.setAttribute(IMarker.MESSAGE, bug.getMessage());
		marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
		
		// Set unique id of warning, so we can easily refer back
		// to it later: for example, when the user classifies the warning.
		String uniqueId = bug.getUniqueId();
		if (uniqueId != null) {
			marker.setAttribute(FindBugsMarker.UNIQUE_ID, uniqueId);
		}

	}
}

@@ -1223,16 +1223,53 @@
 nstance;
+%0Aimport edu.umd.cs.findbugs.Detector;
 %0A%0A/**%0A *
@@ -1963,16 +1963,325 @@
 RNING);%0A
+%09%09if (bug.getPriority() == Detector.HIGH_PRIORITY)%0A%09%09%09marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);%0A%09%09else if (bug.getPriority() == Detector.NORMAL_PRIORITY)%0A%09%09%09marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);%0A%09%09else marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_LOW);%0A
 %09%09%0A%09%09// 

Set marker priority based on bug priority