1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 352166: ErrorParserManager does not have an API for adding markers

This commit is contained in:
Sami Wagiaalla 2011-08-12 13:04:16 -04:00 committed by Andrew Gvozdev
parent 7d03274d32
commit e34011c34b
3 changed files with 117 additions and 15 deletions

View file

@ -564,9 +564,18 @@ outer:
*/
public void generateExternalMarker(IResource file, int lineNumber, String desc, int severity, String varName, IPath externalPath) {
ProblemMarkerInfo problemMarkerInfo = new ProblemMarkerInfo(file, lineNumber, desc, severity, varName, externalPath);
this.addProblemMarker(problemMarkerInfo);
}
/**
* Add the given marker to the list of error markers.
* @param problemMarkerInfo - The marker to be added.
* @since 5.4
*/
public void addProblemMarker(ProblemMarkerInfo problemMarkerInfo){
fErrors.add(problemMarkerInfo);
fMarkerGenerator.addMarker(problemMarkerInfo);
if (severity == IMarkerGenerator.SEVERITY_ERROR_RESOURCE)
if (problemMarkerInfo.severity == IMarkerGenerator.SEVERITY_ERROR_RESOURCE)
hasErrors = true;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 Siemens AG.
* Copyright (c) 2006, 2009, 2011 Siemens AG and others.
* All rights reserved. This content and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,14 +7,26 @@
*
* Contributors:
* Norbert Ploett - Initial implementation
* Sami Wagiaalla (Red Hat) - Bug 352166: Added attributes and type API
* and improved documentation.
*******************************************************************************/
package org.eclipse.cdt.core;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.resources.ACBuilder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
/**
* {@link ProblemMarkerInfo} is an object used to pass error properties to {@link ErrorParserManager}.
* @see ErrorParserManager#addProblemMarker(ProblemMarkerInfo) and
* @see ErrorParserManager#generateMarker(IResource, int, String, int, String) and
* @see ErrorParserManager#generateExternalMarker(IResource, int, String, int, String, IPath)
* The information stored in this object will later be used to create an {@link IMarker} by {@link ACBuilder}
* @noextend This class is not intended to be subclassed by clients.
*/
public class ProblemMarkerInfo {
@ -25,25 +37,93 @@ public class ProblemMarkerInfo {
public int severity;
public String variableName;
public IPath externalPath ;
private Map<String, String> attributes;
private String type;
public ProblemMarkerInfo(IResource file, int lineNumber, String desciption, int severity, String variableName) {
this.file = file;
this.lineNumber = lineNumber;
this.description = desciption;
this.severity = severity;
this.variableName = variableName;
this.externalPath = null ;
}
public ProblemMarkerInfo(IResource file, int lineNumber, String description, int severity, String variableName, IPath externalPath) {
super();
/**
* Create a new {@link ProblemMarkerInfo} object.
* @param file - the file where the problem has occurred.
* @param lineNumber - the line number of the problem.
* @param description - a description of the problem.
* @param severity - the severity of the problem @see {@link IMarkerGenerator}
* for acceptable severity values
* @param variableName - the name of the variable involved in the error if any.
*/
public ProblemMarkerInfo(IResource file, int lineNumber, String description, int severity, String variableName) {
this.file = file;
this.lineNumber = lineNumber;
this.description = description;
this.severity = severity;
this.variableName = variableName;
this.externalPath = null ;
this.type = null;
this.attributes = new HashMap<String, String>();
}
/**
* Create a new {@link ProblemMarkerInfo} object.
* @param file - the file where the problem has occurred.
* @param lineNumber - the line number of the problem.
* @param description - a description of the problem.
* @param severity - the severity of the problem @see {@link IMarkerGenerator}
* for acceptable severity values
* @param variableName - the name of the variable involved in the error if any.
* @param externalPath - if this error involves a file outside the workspace this parameter should
* contain the path to that file.
*/
public ProblemMarkerInfo(IResource file, int lineNumber, String description, int severity, String variableName, IPath externalPath) {
this(file, lineNumber, description, severity, variableName);
this.externalPath = externalPath;
}
/**
* Get the attribute map.
* @return Map of attributes and their values.
* @since 5.4
*/
public Map<String, String> getAttributes(){
return this.attributes;
}
/**
* Return the value of the attribute with the given key,
* or null if no such attribute exists.
* @param key - attribute key.
* @return attribute value
* @since 5.4
*/
public String getAttribute (String key){
return this.attributes.get(key);
}
/**
* Set the value of the attribute with the given key
* to the given value, or add one if one does not already
* exist.
* @param key - attribute key.
* @param value - new attribute value.
* @since 5.4
*/
public void setAttribute (String key, String value){
this.attributes.put(key, value);
}
/**
* Return the type of this problem marker or null
* if type was not set.
* @return the type.
* @since 5.4
*/
public String getType() {
return this.type;
}
/**
* Set the type of this problem marker.
* @param type - the new type.
* @since 5.4
*/
public void setType(String type){
this.type = type;
}
}

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.core.resources;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
@ -85,7 +86,11 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa
}
}
IMarker marker = markerResource.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
String type = problemMarkerInfo.getType();
if (type == null)
type = ICModelMarker.C_MODEL_PROBLEM_MARKER;
IMarker marker = markerResource.createMarker(type);
marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description);
marker.setAttribute(IMarker.SEVERITY, mapMarkerSeverity(problemMarkerInfo.severity));
marker.setAttribute(IMarker.LINE_NUMBER, problemMarkerInfo.lineNumber);
@ -105,6 +110,14 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa
} else if (problemMarkerInfo.lineNumber==0){
marker.setAttribute(IMarker.LOCATION, " "); //$NON-NLS-1$
}
// Add all other client defined attributes.
Map<String, String> attributes = problemMarkerInfo.getAttributes();
if (attributes != null){
for (Entry<String, String> entry : attributes.entrySet()) {
marker.setAttribute(entry.getKey(), entry.getValue());
}
}
}
catch (CoreException e) {
CCorePlugin.log(e.getStatus());