Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Wagiaalla2011-08-12 17:04:16 +0000
committerAndrew Gvozdev2011-08-12 17:04:16 +0000
commite34011c34b7d18a4021219864bcbc5b9fe638deb (patch)
tree86de0ec8836fa9c0b6209bc6544b50d61c22c054
parent7d03274d32b3a001475a0df0d03d08708e4665e2 (diff)
downloadorg.eclipse.cdt-e34011c34b7d18a4021219864bcbc5b9fe638deb.tar.gz
org.eclipse.cdt-e34011c34b7d18a4021219864bcbc5b9fe638deb.tar.xz
org.eclipse.cdt-e34011c34b7d18a4021219864bcbc5b9fe638deb.zip
bug 352166: ErrorParserManager does not have an API for adding markers
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java11
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ProblemMarkerInfo.java100
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java15
3 files changed, 114 insertions, 12 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java
index aa5fe227db2..8556ed529f4 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ErrorParserManager.java
@@ -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;
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ProblemMarkerInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ProblemMarkerInfo.java
index e89a04aa958..7e3b9ea4f87 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ProblemMarkerInfo.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ProblemMarkerInfo.java
@@ -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) {
+ /**
+ * 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 = desciption;
+ 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) {
- super();
- this.file = file;
- this.lineNumber = lineNumber;
- this.description = description;
- this.severity = severity;
- this.variableName = variableName;
+ 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;
+ }
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java
index d7569f64213..48e34fbf771 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java
@@ -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());

Back to the top