|
From: <jbo...@li...> - 2006-06-21 22:39:49
|
Author: KrisVerlaenen
Date: 2006-06-21 18:39:43 -0400 (Wed, 21 Jun 2006)
New Revision: 4801
Modified:
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/LocationDeterminator.java
labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java
labs/jbossrules/trunk/drools-ide/src/test/java/org/drools/ide/editors/completion/LocationDeterminatorTest.java
Log:
JBRULES-314: Lhs Rule completion should have better support for exists, not, eval, and, or
- extended completion support for eval, and, or, not, exists
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/LocationDeterminator.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/LocationDeterminator.java 2006-06-21 22:37:56 UTC (rev 4800)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/LocationDeterminator.java 2006-06-21 22:39:43 UTC (rev 4801)
@@ -8,9 +8,11 @@
import org.drools.compiler.DrlParser;
import org.drools.compiler.DroolsParserException;
+import org.drools.lang.descr.AndDescr;
import org.drools.lang.descr.ColumnDescr;
import org.drools.lang.descr.ExistsDescr;
import org.drools.lang.descr.NotDescr;
+import org.drools.lang.descr.OrDescr;
import org.drools.lang.descr.PackageDescr;
import org.drools.lang.descr.PatternDescr;
import org.drools.lang.descr.RuleDescr;
@@ -24,13 +26,22 @@
static final Pattern COLUMN_PATTERN_EXCLUDES_ARGUMENT = Pattern.compile(".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:]+)\\s+excludes\\s+", Pattern.DOTALL);
static final Pattern COLUMN_PATTERN_COMPARATOR_ARGUMENT = Pattern.compile(".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:]+)\\s*([<>=!]+)\\s*[^\\s<>!=:]*", Pattern.DOTALL);
+ static final Pattern EXISTS_PATTERN = Pattern.compile(".*\\s+exists\\s*\\(?\\s*((\\S*)\\s*:)?\\s*\\S*", Pattern.DOTALL);
+ static final Pattern NOT_PATTERN = Pattern.compile(".*\\s+not\\s*\\(?\\s*((\\S*)\\s*:)?\\s*\\S*", Pattern.DOTALL);
+ static final Pattern EVAL_PATTERN = Pattern.compile(".*\\s+eval\\s*\\(\\s*[^)]*", Pattern.DOTALL);
+
static final int LOCATION_UNKNOWN = 0;
static final int LOCATION_BEGIN_OF_CONDITION = 1;
+ static final int LOCATION_BEGIN_OF_CONDITION_EXISTS = 2;
+ static final int LOCATION_BEGIN_OF_CONDITION_AND_OR = 3;
+ static final int LOCATION_BEGIN_OF_CONDITION_NOT = 4;
static final int LOCATION_INSIDE_CONDITION_START = 100;
static final int LOCATION_INSIDE_CONDITION_OPERATOR = 101;
static final int LOCATION_INSIDE_CONDITION_ARGUMENT = 102;
+ static final int LOCATION_INSIDE_EVAL = 200;
+
static final String LOCATION_PROPERTY_CLASS_NAME = "ClassName";
static final String LOCATION_PROPERTY_PROPERTY_NAME = "PropertyName";
@@ -81,6 +92,18 @@
}
PatternDescr subDescr = (PatternDescr) subDescrs.get(subDescrs.size() - 1);
if (subDescr == null) {
+ Matcher matcher = EXISTS_PATTERN.matcher(backText);
+ if (matcher.matches()) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+ }
+ matcher = NOT_PATTERN.matcher(backText);
+ if (matcher.matches()) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+ }
+ matcher = EVAL_PATTERN.matcher(backText);
+ if (matcher.matches()) {
+ return new Location(LOCATION_INSIDE_EVAL);
+ }
return new Location(LOCATION_BEGIN_OF_CONDITION);
}
if (subDescr.getEndLine() != 0 || subDescr.getEndColumn() != 0) {
@@ -145,36 +168,94 @@
} else if (descr instanceof ExistsDescr) {
List subDescrs = ((ExistsDescr) descr).getDescrs();
if (subDescrs.size() == 0) {
- return new Location(LOCATION_BEGIN_OF_CONDITION);
+ return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
}
if (subDescrs.size() == 1) {
PatternDescr subDescr = (PatternDescr) subDescrs.get(0);
if (subDescr == null) {
- return new Location(LOCATION_BEGIN_OF_CONDITION);
+ return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
}
- if (subDescr.getEndLine() != 0 || subDescr.getEndColumn() != 0) {
- return new Location(LOCATION_BEGIN_OF_CONDITION);
- }
+ // not needed because an exist description is ended if subdescr is ended
+ // if (subDescr.getEndLine() != 0 || subDescr.getEndColumn() != 0) {
+ // return new Location(LOCATION_BEGIN_OF_CONDITION);
+ // }
return determineLocationForDescr(subDescr, backText);
}
return determineLocationForDescr(descr, backText);
} else if (descr instanceof NotDescr) {
List subDescrs = ((NotDescr) descr).getDescrs();
if (subDescrs.size() == 0) {
- return new Location(LOCATION_BEGIN_OF_CONDITION);
+ return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
}
if (subDescrs.size() == 1) {
PatternDescr subDescr = (PatternDescr) subDescrs.get(0);
if (subDescr == null) {
- return new Location(LOCATION_BEGIN_OF_CONDITION);
+ return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
}
- if (subDescr.getEndLine() != 0 || subDescr.getEndColumn() != 0) {
- return new Location(LOCATION_BEGIN_OF_CONDITION);
+ // not needed because a not description is ended if subdescr is ended
+ // if (subDescr.getEndLine() != 0 || subDescr.getEndColumn() != 0) {
+ // return new Location(LOCATION_BEGIN_OF_CONDITION);
+ // }
+ Location location = determineLocationForDescr(subDescr, backText);
+ if (location.getType() == LOCATION_BEGIN_OF_CONDITION) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
}
- return determineLocationForDescr(subDescr, backText);
+ return location;
}
return determineLocationForDescr(descr, backText);
-
+ } else if (descr instanceof AndDescr) {
+ List subDescrs = ((AndDescr) descr).getDescrs();
+ int size = subDescrs.size();
+ if (size == 2) {
+ PatternDescr subDescr = (PatternDescr) subDescrs.get(1);
+ if (subDescr == null) {
+ Matcher matcher = EXISTS_PATTERN.matcher(backText);
+ if (matcher.matches()) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+ }
+ matcher = NOT_PATTERN.matcher(backText);
+ if (matcher.matches()) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+ }
+ return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+ // not needed because an and description is ended if subdescr is ended
+ // } else if (subDescr.getEndLine() != 0 || subDescr.getEndColumn() != 0) {
+ // return new Location(LOCATION_BEGIN_OF_CONDITION);
+ } else {
+ Location location = determineLocationForDescr(subDescr, backText);
+ if (location.getType() == LOCATION_BEGIN_OF_CONDITION) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+ }
+ return location;
+ }
+ }
+ return new Location(LOCATION_UNKNOWN);
+ } else if (descr instanceof OrDescr) {
+ List subDescrs = ((OrDescr) descr).getDescrs();
+ int size = subDescrs.size();
+ if (size == 2) {
+ PatternDescr subDescr = (PatternDescr) subDescrs.get(1);
+ if (subDescr == null) {
+ Matcher matcher = EXISTS_PATTERN.matcher(backText);
+ if (matcher.matches()) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_EXISTS);
+ }
+ matcher = NOT_PATTERN.matcher(backText);
+ if (matcher.matches()) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_NOT);
+ }return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+ // not needed because an or description is ended if subdescr is ended
+ // } else if (subDescr.getEndLine() != 0 || subDescr.getEndColumn() != 0) {
+ // return new Location(LOCATION_BEGIN_OF_CONDITION);
+ } else {
+ Location location = determineLocationForDescr(subDescr, backText);
+ if (location.getType() == LOCATION_BEGIN_OF_CONDITION) {
+ return new Location(LOCATION_BEGIN_OF_CONDITION_AND_OR);
+ }
+ return location;
+ }
+ }
+ return new Location(LOCATION_UNKNOWN);
}
return new Location(LOCATION_UNKNOWN);
Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-06-21 22:37:56 UTC (rev 4800)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java 2006-06-21 22:39:43 UTC (rev 4801)
@@ -128,13 +128,22 @@
case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION:
// if we are at the beginning of a new condition
// add drools keywords
- list.add( new RuleCompletionProposal(prefix.length(), "exists", "exists ", droolsIcon));
- list.add( new RuleCompletionProposal(prefix.length(), "not", "not ", droolsIcon));
list.add( new RuleCompletionProposal(prefix.length(), "and", "and ", droolsIcon));
list.add( new RuleCompletionProposal(prefix.length(), "or", "or ", droolsIcon));
RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), "eval", "eval( )", 6 );
prop.setImage(droolsIcon);
list.add(prop);
+ prop = new RuleCompletionProposal(prefix.length(), "then", "then" + System.getProperty("line.separator") + "\t");
+ prop.setImage(droolsIcon);
+ list.add(prop);
+ // we do not break but also add all elements that are needed for and/or
+ case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR:
+ list.add( new RuleCompletionProposal(prefix.length(), "not", "not ", droolsIcon));
+ // we do not break but also add all elements that are needed for not
+ case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT:
+ list.add( new RuleCompletionProposal(prefix.length(), "exists", "exists ", droolsIcon));
+ // we do not break but also add all elements that are needed for exists
+ case LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS:
// and add imported classes
List imports = getDRLEditor().getImports();
iterator = imports.iterator();
@@ -162,10 +171,7 @@
list.add(p);
}
}
- prop = new RuleCompletionProposal(prefix.length(), "then", "then" + System.getProperty("line.separator") + "\t");
- prop.setImage(droolsIcon);
- list.add(prop);
- break;
+ break;
case LocationDeterminator.LOCATION_INSIDE_CONDITION_START :
String className = (String) location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME);
if (className != null) {
@@ -255,6 +261,27 @@
// do nothing
}
break;
+ case LocationDeterminator.LOCATION_INSIDE_EVAL :
+ try {
+ parser = new DrlParser();
+ PackageDescr descr = parser.parse(backText);
+ List rules = descr.getRules();
+ if (rules != null && rules.size() == 1) {
+ Map result = new HashMap();
+ getRuleParameters(result, ((RuleDescr) rules.get(0)).getLhs().getDescrs());
+ Iterator iterator2 = result.keySet().iterator();
+ while (iterator2.hasNext()) {
+ String name = (String) iterator2.next();
+ RuleCompletionProposal proposal = new RuleCompletionProposal(prefix.length(), name);
+ proposal.setPriority(-1);
+ proposal.setImage(methodIcon);
+ list.add(proposal);
+ }
+ }
+ } catch (DroolsParserException exc) {
+ // do nothing
+ }
+ break;
}
}
}
Modified: labs/jbossrules/trunk/drools-ide/src/test/java/org/drools/ide/editors/completion/LocationDeterminatorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/test/java/org/drools/ide/editors/completion/LocationDeterminatorTest.java 2006-06-21 22:37:56 UTC (rev 4800)
+++ labs/jbossrules/trunk/drools-ide/src/test/java/org/drools/ide/editors/completion/LocationDeterminatorTest.java 2006-06-21 22:39:43 UTC (rev 4801)
@@ -342,54 +342,113 @@
" when \n" +
" exists ";
location = LocationDeterminator.getLocationInCondition(input);
- assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
input =
"rule MyRule \n" +
" when \n" +
+ " exists ( ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists(";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
" exists Cl";
location = LocationDeterminator.getLocationInCondition(input);
- assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
input =
"rule MyRule \n" +
" when \n" +
+ " exists ( Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ( name : Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
" exists Class (";
location = LocationDeterminator.getLocationInCondition(input);
assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-
+
input =
"rule MyRule \n" +
" when \n" +
- " exists Class () \n" +
- " ";
+ " exists Class ( ) \n" +
+ " ";
location = LocationDeterminator.getLocationInCondition(input);
assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-
+
/** NOT */
input =
"rule MyRule \n" +
" when \n" +
" not ";
location = LocationDeterminator.getLocationInCondition(input);
- assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
input =
"rule MyRule \n" +
" when \n" +
" not Cl";
location = LocationDeterminator.getLocationInCondition(input);
- assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
input =
"rule MyRule \n" +
" when \n" +
+ " not exists ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
" not Class (";
location = LocationDeterminator.getLocationInCondition(input);
assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
+// TODO
+// input =
+// "rule MyRule \n" +
+// " when \n" +
+// " not exists Class (";
+// location = LocationDeterminator.getLocationInCondition(input);
+// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
+// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
+//
+// input =
+// "rule MyRule \n" +
+// " when \n" +
+// " not exists name : Class (";
+// location = LocationDeterminator.getLocationInCondition(input);
+// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
+// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
+
input =
"rule MyRule \n" +
" when \n" +
@@ -397,6 +456,269 @@
" ";
location = LocationDeterminator.getLocationInCondition(input);
assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+
+ /** AND */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) && ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class () and ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " name : Class ( name: property ) and ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: property ) \n" +
+ " and ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and name : Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) && name : Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( ) \n" +
+ " ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and not Class ( ) \n" +
+ " ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and exists Class ( ) \n" +
+ " ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( name ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( name == ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) and not ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) and exists ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and not Class ( ) \n" +
+ " ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+
+ /** OR */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) || ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class () or ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " name : Class ( name: property ) or ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: property ) \n" +
+ " or ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or name : Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) || name : Cl";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( ) \n" +
+ " ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( name ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( name == ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) or not ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) or exists ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ /** EVAL */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval ( ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval(";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( myCla";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( true )";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( true ) \n" +
+ " ";
+ location = LocationDeterminator.getLocationInCondition(input);
+ assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
}
}
|