1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

generator will set problem arguments based on pattern groups for non codan problems

This commit is contained in:
Alena Laskavaia 2010-07-22 02:51:48 +00:00
parent 4531b0f287
commit 8ce10b8b62
2 changed files with 49 additions and 2 deletions

View file

@ -120,7 +120,7 @@ public class CodanProblemMarker implements ICodanProblemMarker {
* @param args2 * @param args2
* @return * @return
*/ */
private String serializeArgs(Object[] args) { private static String serializeArgs(Object[] args) {
if (args != null) { if (args != null) {
Properties prop = new Properties(); Properties prop = new Properties();
prop.put("len", String.valueOf(args.length)); //$NON-NLS-1$ prop.put("len", String.valueOf(args.length)); //$NON-NLS-1$
@ -255,4 +255,15 @@ public class CodanProblemMarker implements ICodanProblemMarker {
marker.getResource(), charstart, charend, line); marker.getResource(), charstart, charend, line);
return loc; return loc;
} }
/**
* @param marker
* @param res
* @throws CoreException
*/
public static void setProblemArguments(IMarker marker, String[] args)
throws CoreException {
String propArgs = serializeArgs(args);
marker.setAttribute(PROBLEM_ARGS, propArgs);
}
} }

View file

@ -11,12 +11,15 @@
package org.eclipse.cdt.codan.internal.ui; package org.eclipse.cdt.codan.internal.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -58,8 +61,19 @@ public class CodanProblemMarkerResolutionGenerator implements
.iterator(); iterator.hasNext();) { .iterator(); iterator.hasNext();) {
ConditionalResolution res = iterator.next(); ConditionalResolution res = iterator.next();
if (res.messagePattern != null) { if (res.messagePattern != null) {
if (!message.matches(res.messagePattern)) try {
Pattern pattern = Pattern.compile(res.messagePattern);
Matcher matcher = pattern.matcher(message);
if (!matcher.matches())
continue; continue;
if (id == null) {
setArgumentsFromPattern(matcher, marker);
}
} catch (Exception e) {
CodanUIActivator
.log("Cannot compile regex: " + res.messagePattern); //$NON-NLS-1$
continue;
}
} }
if (res.res instanceof AbstractCodanCMarkerResolution) { if (res.res instanceof AbstractCodanCMarkerResolution) {
if (!((AbstractCodanCMarkerResolution) res.res) if (!((AbstractCodanCMarkerResolution) res.res)
@ -74,6 +88,28 @@ public class CodanProblemMarkerResolutionGenerator implements
return new IMarkerResolution[0]; return new IMarkerResolution[0];
} }
/**
* @param matcher
* @param marker
*/
private void setArgumentsFromPattern(Matcher matcher, IMarker marker) {
int n = matcher.groupCount();
if (n == 0)
return;
String[] res = new String[n];
for (int i = 0; i < n; i++) {
res[i] = matcher.group(i + 1);
}
String[] old = CodanProblemMarker.getProblemArguments(marker);
if (!Arrays.deepEquals(res, old)) {
try {
CodanProblemMarker.setProblemArguments(marker, res);
} catch (CoreException e) {
CodanUIActivator.log(e);
}
}
}
private static synchronized void readExtensions() { private static synchronized void readExtensions() {
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint( IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(
CodanUIActivator.PLUGIN_ID, EXTENSION_POINT_NAME); CodanUIActivator.PLUGIN_ID, EXTENSION_POINT_NAME);