[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [henshin-dev] Bug when using Attribute Conditions
|
I am sorry. My regular _expression_ accidentely required variable
names with at least two characters. Because of that the sort test
failed (having the variables x, y, i and j). Here is the fixed
patch.
Am 05.07.2014 13:54, schrieb Christian
Krause:
Hi Manuel,
thanks for the investigation and the patch. This part is
indeed not really clean.
Cheers,
Christian
_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/henshin-dev
|
Index: org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/info/ConditionInfo.java
===================================================================
--- org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/info/ConditionInfo.java (revision 1989)
+++ org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/info/ConditionInfo.java (working copy)
@@ -9,12 +9,13 @@
*/
package org.eclipse.emf.henshin.interpreter.info;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.emf.henshin.model.AttributeCondition;
import org.eclipse.emf.henshin.model.Parameter;
@@ -22,12 +23,14 @@
public class ConditionInfo {
+ private static final Pattern VALID_JS_VARIABLE_NAME=Pattern.compile("[$_\\p{Lu}\\p{Ll}\\p{Lt}\\p{Lm}\\p{Lo}\\p{Nl}][$_\\p{Lu}\\p{Ll}\\p{Lt}\\p{Lm}\\p{Lo}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}]*");
+
private Map<String, Collection<String>> conditionParameters;
public ConditionInfo(Rule rule) {
this.conditionParameters = new HashMap<String, Collection<String>>();
- Collection<String> parameterNames = new ArrayList<String>();
+ Collection<String> parameterNames = new HashSet<String>();
for (Parameter parameter : rule.getParameters()) {
parameterNames.add(parameter.getName());
}
@@ -41,17 +44,14 @@
private Collection<String> extractParameter(String testString, Collection<String> parameterNames) {
Collection<String> usedParameters = new HashSet<String>();
- StringTokenizer quoteParser = new StringTokenizer(testString, "\"\'");
+ StringTokenizer quoteParser = new StringTokenizer(testString, "\"\'"); //FIXME this can also lead to wrong results when escaped " or ' are used
while (quoteParser.hasMoreElements()) {
String nonQuotedString = quoteParser.nextToken();
- StringTokenizer variableParser = new StringTokenizer(nonQuotedString, ".,()\t\r\n<>=!+[] ");
- while (variableParser.hasMoreElements()) {
- String subString = variableParser.nextToken();
- for (String parameterName : parameterNames) {
- if (parameterName.equals(subString)) {
- usedParameters.add(parameterName);
- }
- }
+ Matcher m=VALID_JS_VARIABLE_NAME.matcher(nonQuotedString);
+ while(m.find()) {
+ String possibleVariableName=m.group();
+ if(parameterNames.contains(possibleVariableName))
+ usedParameters.add(possibleVariableName);
}
// discard the quoted part
if (quoteParser.hasMoreElements())