1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 09:45:39 +02:00

added utility methods to access marker data

This commit is contained in:
Alena Laskavaia 2010-07-22 02:28:49 +00:00
parent 7b9acc4aae
commit c6ea6624d7

View file

@ -16,9 +16,11 @@ import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;
import org.eclipse.cdt.codan.core.model.CodanSeverity;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemLocation;
import org.eclipse.cdt.codan.internal.core.CheckersRegistry;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@ -196,10 +198,50 @@ public class CodanProblemMarker implements ICodanProblemMarker {
* @return problem message
*/
public static String getMessage(IMarker marker) {
try {
return (String) marker.getAttribute(IMarker.MESSAGE);
} catch (CoreException e) {
return marker.getAttribute(IMarker.MESSAGE, (String) null);
}
/**
* @param marker
* @return codan severity
*/
public static CodanSeverity getSeverity(IMarker marker) {
int sev = marker.getAttribute(IMarker.SEVERITY, 0);
return CodanSeverity.valueOf(sev);
}
/**
* Attempt to restore CodamProblemMaker from the resource marker
*
* @param marker
* @return new instanceof of ICodanProblemMarker or null if marker is not
* codan marker
*/
public static ICodanProblemMarker createCodanProblemMarkerFromResourceMarker(
IMarker marker) {
String id = getProblemId(marker);
if (id == null)
return null;
}
CodanSeverity sev = getSeverity(marker);
CodanProblemLocation loc = getLocation(marker);
CodanProblem problem = (CodanProblem) ((CodanProblem) CheckersRegistry
.getInstance().getWorkspaceProfile().findProblem(id)).clone();
if (problem == null)
return null;
problem.setSeverity(sev);
return new CodanProblemMarker(problem, loc, getProblemArguments(marker));
}
/**
* @param marker
* @return location object using marker attributes
*/
public static CodanProblemLocation getLocation(IMarker marker) {
int line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
int charend = marker.getAttribute(IMarker.CHAR_END, -1);
int charstart = marker.getAttribute(IMarker.CHAR_START, -1);
CodanProblemLocation loc = new CodanProblemLocation(
marker.getResource(), charstart, charend, line);
return loc;
}
}