[jboss-svn-commits] JBL Code SVN: r13682 - in labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse: drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 20 14:11:08 EDT 2007
Author: pombredanne
Date: 2007-07-20 14:11:07 -0400 (Fri, 20 Jul 2007)
New Revision: 13682
Added:
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MockCompletionProcessor.java
Removed:
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DialectDeterminator.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java
Modified:
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java
labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java
Log:
Last commit before merge in trunk. Reamining fxies on code completion and highlighting.
Copied: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java (from rev 13406, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java)
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,196 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.drools.compiler.DrlParser;
+import org.drools.compiler.DroolsParserException;
+import org.drools.lang.Location;
+import org.drools.lang.descr.BaseDescr;
+import org.drools.lang.descr.PackageDescr;
+import org.drools.lang.descr.RuleDescr;
+
+/**
+ * A utility class that invokes the DRLParser on some partial drl text, and provides
+ * information back about the context of that parserd drl,
+ * such as a location type, a dialect, and so on.
+ *
+ */
+public class CompletionContext {
+
+ static final Pattern PATTERN_PATTERN_OPERATOR = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\),]+)(\\s*([<>=!]+)\\s*[^\\s<>!=:]*\\s*(&&|\\|\\|))*\\s+",
+ Pattern.DOTALL );
+
+ static final Pattern PATTERN_PATTERN_COMPARATOR_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s*(([<>=!]+)\\s*[^\\s<>!=:]+\\s*(&&|\\|\\|)\\s*)*([<>=!]+)\\s*[^\\s<>!=:]*",
+ Pattern.DOTALL );
+
+ static final Pattern EVAL_PATTERN = Pattern.compile( ".*\\s+eval\\s*\\(\\s*([(^\\))(\\([^\\)]*\\)?)]*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_INIT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_ACTION = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_REVERSE = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?\\s*reverse\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ACCUMULATE_PATTERN_RESULT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?(\\s*reverse\\s*\\(\\s*(.*)\\)\\s*,?)?\\s*result\\s*\\(\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern THEN_PATTERN = Pattern.compile( ".*\n\\s*when\\s*(.*)\n\\s*then\\s*(.*)",
+ Pattern.DOTALL );
+
+ static final Pattern ENDS_WITH_SPACES = Pattern.compile( ".*\\s+",
+ Pattern.DOTALL );
+
+ static final Pattern MVEL_DIALECT = Pattern.compile( ".*dialect\\s+\"mvel\".*",
+ Pattern.DOTALL );
+
+ private String backText;
+ private DrlParser parser;
+ private RuleDescr rule;
+ private PackageDescr packageDescr;
+ private boolean javaDialect = true;
+
+ public CompletionContext(String ruleText) {
+ this.backText = ruleText;
+ this.parser = new DrlParser();
+
+ try {
+ packageDescr = parser.parse( ruleText );
+ List rules = packageDescr.getRules();
+ if ( rules != null && rules.size() == 1 ) {
+ this.rule = (RuleDescr) rules.get( 0 );
+ }
+
+ } catch ( DroolsParserException exc ) {
+ // do nothing
+ }
+
+ determineDialect( ruleText );
+ }
+
+ public boolean isJavaDialect() {
+ return javaDialect;
+ }
+
+ public PackageDescr getPackageDescr() {
+ return packageDescr;
+ }
+
+ //note: this is a crude but reasonably fast way to determine the dialect,
+ //especially when parsing imcomplete rules
+ private void determineDialect(String backText) {
+ //which dialect are we using for this rule?
+ //we test only for mvel for now: java is the default dialect
+ if ( MVEL_DIALECT.matcher( backText ).matches() ) {
+ javaDialect = false;
+ } else {
+ javaDialect = true;
+ }
+ }
+
+ public Location getLocation() {
+ if ( backText == null || rule == null ) {
+ return new Location( Location.LOCATION_UNKNOWN );
+ }
+ return determineLocationForDescr( rule,
+ parser.getLocation(),
+ backText );
+ }
+
+ public RuleDescr getRule() {
+ return rule;
+ }
+
+ private static Location determineLocationForDescr(BaseDescr descr,
+ Location location,
+ String backText) {
+ if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR ) {
+ if ( !ENDS_WITH_SPACES.matcher( backText ).matches() ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_START );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_END ) {
+ if ( !backText.endsWith( " " ) ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_EVAL ) {
+ Matcher matcher = EVAL_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ String content = matcher.group( 1 );
+ location.setProperty( Location.LOCATION_EVAL_CONTENT,
+ content );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_START ) {
+ Matcher matcher = PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
+ location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
+ matcher.group( 7 ) );
+ return location;
+ }
+
+ matcher = PATTERN_PATTERN_OPERATOR.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR );
+ return location;
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM ) {
+ if ( location.getProperty( Location.LOCATION_FROM_CONTENT ) == null ) {
+ location.setProperty( Location.LOCATION_FROM_CONTENT,
+ "" );
+ } else if ( ((String) location.getProperty( Location.LOCATION_FROM_CONTENT )).length() > 0 && ENDS_WITH_SPACES.matcher( backText ).matches() ) {
+ location.setType( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_INIT ) {
+ Matcher matcher = ACCUMULATE_PATTERN_INIT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT,
+ matcher.group( 1 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION ) {
+ Matcher matcher = ACCUMULATE_PATTERN_ACTION.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT,
+ matcher.group( 2 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE ) {
+ Matcher matcher = ACCUMULATE_PATTERN_REVERSE.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_REVERSE_CONTENT,
+ matcher.group( 3 ) );
+ }
+ matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
+ matcher.group( 5 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT ) {
+ Matcher matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
+ location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
+ matcher.group( 5 ) );
+ }
+ } else if ( location.getType() == Location.LOCATION_RHS ) {
+ Matcher matcher = THEN_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ location.setProperty( Location.LOCATION_LHS_CONTENT,
+ matcher.group( 1 ) );
+ location.setProperty( Location.LOCATION_RHS_CONTENT,
+ matcher.group( 2 ) );
+ return location;
+ }
+ }
+
+ return location;
+ }
+
+}
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -1,49 +1,216 @@
package org.drools.eclipse.editors.completion;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.eclipse.jdt.core.Signature;
+
public class CompletionUtil {
-
- private CompletionUtil() {
- }
+ protected static final Pattern INCOMPLETED_MVEL_EXPRESSION = Pattern.compile( "[\\.\\(\\{\\[]\\Z",
+ Pattern.DOTALL );
+
+ protected static final Pattern COMPLETED_MVEL_EXPRESSION = Pattern.compile( "]\\)\\}\\]\\Z",
+ Pattern.DOTALL );
+
+ private CompletionUtil() {
+ }
+
/** Looks behind, gets stuff after the white space. Basically ripping out the last word.*/
public static String stripLastWord(String prefix) {
- if ("".equals(prefix)) {
- return prefix;
- }
- if (prefix.charAt(prefix.length() - 1) == ' ') {
- return "";
- } else {
- char[] c = prefix.toCharArray();
- int start = 0;
- for (int i = c.length - 1; i >=0; i-- ) {
- if (Character.isWhitespace(c[i]) || c[i] == '(' || c[i] == ':' || c[i] == ';' || c[i] == '=' || c[i] == '<' || c[i] == '>' || c[i] == '.' || c[i] == '{' || c[i] == '}') {
- start = i + 1;
- break;
- }
- }
- prefix = prefix.substring(start, prefix.length());
- return prefix;
- }
+ if ( "".equals( prefix ) ) {
+ return prefix;
+ }
+ if ( prefix.charAt( prefix.length() - 1 ) == ' ' ) {
+ return "";
+ } else {
+ char[] c = prefix.toCharArray();
+ int start = 0;
+ for ( int i = c.length - 1; i >= 0; i-- ) {
+ if ( Character.isWhitespace( c[i] ) || c[i] == '(' || c[i] == ':' || c[i] == ';' || c[i] == '=' || c[i] == '<' || c[i] == '>' || c[i] == '.' || c[i] == '{' || c[i] == '}' ) {
+ start = i + 1;
+ break;
+ }
+ }
+ prefix = prefix.substring( start,
+ prefix.length() );
+ return prefix;
+ }
}
-
+
public static String stripWhiteSpace(String prefix) {
- if ("".equals(prefix)) {
- return prefix;
- }
- if (prefix.charAt(prefix.length() - 1) == ' ') {
- return "";
- } else {
- char[] c = prefix.toCharArray();
- int start = 0;
- for (int i = c.length - 1; i >=0; i-- ) {
- if (Character.isWhitespace(c[i])) {
- start = i + 1;
- break;
- }
- }
- prefix = prefix.substring(start, prefix.length());
- return prefix;
- }
+ if ( "".equals( prefix ) ) {
+ return prefix;
+ }
+ if ( prefix.charAt( prefix.length() - 1 ) == ' ' ) {
+ return "";
+ } else {
+ char[] c = prefix.toCharArray();
+ int start = 0;
+ for ( int i = c.length - 1; i >= 0; i-- ) {
+ if ( Character.isWhitespace( c[i] ) ) {
+ start = i + 1;
+ break;
+ }
+ }
+ prefix = prefix.substring( start,
+ prefix.length() );
+ return prefix;
+ }
}
-
+
+ /**
+ *
+ * @param backText
+ * @return a substring of the back text, that should be compilable
+ * without syntax errors by the mvel compiler
+ * TODO: add tests and more use cases
+ */
+ public static String getCompilableText(String backText) {
+ if ( backText.endsWith( ";" ) ) {
+ //RHS expression should compile if it ends with ;
+ return backText;
+ } else if ( CompletionUtil.COMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
+ //RHS expression should compile if closed. just need to close the statement
+ return backText + ";";
+ } else if ( INCOMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
+ //remove the last char and close the statement
+ return backText.substring( 0,
+ backText.length() - 1 ) + ";";
+ } else {
+ return backText;
+ }
+ }
+
+ /*
+ * propertyname extraction and bean convention methods names checks
+ */
+
+ public static boolean isGetter(String methodName,
+ int argCount,
+ String returnedType) {
+ return isAccessor( methodName,
+ argCount,
+ 0,
+ "get",
+ returnedType,
+ Signature.SIG_VOID,
+ false );
+ }
+
+ public static boolean isSetter(String methodName,
+ int argCount,
+ String returnedType) {
+ return isAccessor( methodName,
+ argCount,
+ 1,
+ "set",
+ returnedType,
+ Signature.SIG_VOID,
+ true );
+ }
+
+ public static boolean isIsGetter(String methodName,
+ int argCount,
+ String returnedType) {
+ return isAccessor( methodName,
+ argCount,
+ 0,
+ "is",
+ returnedType,
+ Signature.SIG_BOOLEAN,
+ true );
+ }
+
+ public static String getPropertyName(String methodName,
+ int parameterCount,
+ String returnType) {
+ if ( methodName == null ) {
+ return null;
+ }
+ String simpleName = methodName.replaceAll( "\\(\\)",
+ "" );
+ int prefixLength = 0;
+ if ( isIsGetter( simpleName,
+ parameterCount,
+ returnType ) ) {
+
+ prefixLength = 2;
+
+ } else if ( isGetter( simpleName,
+ parameterCount,
+ returnType ) //
+ || isSetter( methodName,
+ parameterCount,
+ returnType ) ) {
+
+ prefixLength = 3;
+ } else {
+ return methodName;
+ }
+
+ char firstChar = Character.toLowerCase( simpleName.charAt( prefixLength ) );
+ String propertyName = firstChar + simpleName.substring( prefixLength + 1 );
+ return propertyName;
+ }
+
+ public static String getPropertyName(String methodName,
+ char[] signature) {
+ if ( signature == null || methodName == null ) {
+ return methodName;
+ }
+
+ int parameterCount = Signature.getParameterCount( signature );
+ String returnType = new String( Signature.getReturnType( signature ) );
+
+ return getPropertyName( methodName,
+ parameterCount,
+ returnType );
+ }
+
+ private static boolean isAccessor(String methodName,
+ int actualParameterCount,
+ int requiredParameterCount,
+ String prefix,
+ String returnType,
+ String requiredReturnType,
+ boolean includeType) {
+
+ if ( methodName.length() < prefix.length() + 1 ) {
+ return false;
+ }
+
+ if ( !methodName.startsWith( prefix ) ) {
+ return false;
+ }
+
+ if ( actualParameterCount != requiredParameterCount ) {
+ return false;
+ }
+
+ if ( includeType ) {
+ if ( !requiredReturnType.equals( returnType ) ) {
+ return false;
+ }
+ } else {
+ if ( requiredReturnType.equals( returnType ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean isStartOfNewStatement(String text,
+ String prefix) {
+ String javaTextWithoutPrefix = text.substring( 0,
+ text.length() - prefix.length() );
+
+ if ( "".equals( javaTextWithoutPrefix.trim() ) || DefaultCompletionProcessor.START_OF_NEW_JAVA_STATEMENT.matcher( javaTextWithoutPrefix ).matches() ) {
+ return true;
+ }
+ return false;
+ }
}
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -1,8 +1,10 @@
package org.drools.eclipse.editors.completion;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -18,7 +20,6 @@
import org.drools.lang.descr.GlobalDescr;
import org.drools.util.StringUtils;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.CompletionRequestor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -29,230 +30,306 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
-
/**
* This is the basic completion processor that is used when the editor is outside of a rule block
* partition.
* The provides the content assistance for basic rule assembly stuff.
- *
- * This processor will also read behind the current editing position, to provide some context to
+ *
+ * This processor will also read behind the current editing position, to provide some context to
* help provide the pop up list.
- *
+ *
* @author Michael Neale, Kris Verlaenen
*/
public class DefaultCompletionProcessor extends AbstractCompletionProcessor {
- private static final String NEW_RULE_TEMPLATE = "rule \"new rule\"" + System.getProperty("line.separator") + "\twhen" + System.getProperty("line.separator") + "\t\t" + System.getProperty("line.separator") + "\tthen" + System.getProperty("line.separator") + "\t\t" + System.getProperty("line.separator") + "end";
- private static final String NEW_QUERY_TEMPLATE = "query \"query name\"" + System.getProperty("line.separator") + "\t#conditions" + System.getProperty("line.separator") + "end";
- private static final String NEW_FUNCTION_TEMPLATE = "function void yourFunction(Type arg) {" + System.getProperty("line.separator") + "\t/* code goes here*/" + System.getProperty("line.separator") + "}";
- private static final String NEW_TEMPLATE_TEMPLATE = "template Name" + System.getProperty("line.separator") + "\t" + System.getProperty("line.separator") + "end";
- private static final Pattern IMPORT_PATTERN = Pattern.compile(".*\n\\W*import\\W[^;\\s]*", Pattern.DOTALL);
+ private static final String NEW_RULE_TEMPLATE = "rule \"new rule\"" + System.getProperty( "line.separator" ) + "\twhen" + System.getProperty( "line.separator" ) + "\t\t" + System.getProperty( "line.separator" ) + "\tthen"
+ + System.getProperty( "line.separator" ) + "\t\t" + System.getProperty( "line.separator" ) + "end";
+ private static final String NEW_QUERY_TEMPLATE = "query \"query name\"" + System.getProperty( "line.separator" ) + "\t#conditions" + System.getProperty( "line.separator" ) + "end";
+ private static final String NEW_FUNCTION_TEMPLATE = "function void yourFunction(Type arg) {" + System.getProperty( "line.separator" ) + "\t/* code goes here*/" + System.getProperty( "line.separator" ) + "}";
+ private static final String NEW_TEMPLATE_TEMPLATE = "template Name" + System.getProperty( "line.separator" ) + "\t" + System.getProperty( "line.separator" ) + "end";
+ private static final Pattern IMPORT_PATTERN = Pattern.compile( ".*\n\\W*import\\W[^;\\s]*",
+ Pattern.DOTALL );
// TODO: doesn't work for { inside functions
- private static final Pattern FUNCTION_PATTERN = Pattern.compile( ".*\n\\W*function\\s+(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)\\s*\\{([^\\}]*)", Pattern.DOTALL);
- protected static final Image VARIABLE_ICON = DroolsPluginImages.getImage(DroolsPluginImages.VARIABLE);
- protected static final Image METHOD_ICON = DroolsPluginImages.getImage(DroolsPluginImages.METHOD);
- private static final Pattern START_OF_NEW_JAVA_STATEMENT = Pattern.compile(".*[;{}]\\s*", Pattern.DOTALL);
+ private static final Pattern FUNCTION_PATTERN = Pattern.compile( ".*\n\\W*function\\s+(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)\\s*\\{([^\\}]*)",
+ Pattern.DOTALL );
+ protected static final Image VARIABLE_ICON = DroolsPluginImages.getImage( DroolsPluginImages.VARIABLE );
+ protected static final Image METHOD_ICON = DroolsPluginImages.getImage( DroolsPluginImages.METHOD );
+ protected static final Image CLASS_ICON = DroolsPluginImages.getImage( DroolsPluginImages.CLASS );
+ protected static final Pattern START_OF_NEW_JAVA_STATEMENT = Pattern.compile( ".*[;{}]\\s*",
+ Pattern.DOTALL );
+
public DefaultCompletionProcessor(AbstractRuleEditor editor) {
- super(editor);
+ super( editor );
}
-
- protected List getCompletionProposals(ITextViewer viewer, int documentOffset) {
+
+ protected List getCompletionProposals(ITextViewer viewer,
+ int documentOffset) {
try {
- IDocument doc = viewer.getDocument();
- String backText = readBackwards( documentOffset, doc );
-
- String prefix = CompletionUtil.stripLastWord(backText);
-
- List props = null;
- Matcher matcher = IMPORT_PATTERN.matcher(backText);
- if (matcher.matches()) {
- String classNameStart = backText.substring(backText.lastIndexOf("import") + 7);
- props = getAllClassProposals(classNameStart, documentOffset);
- } else {
- matcher = FUNCTION_PATTERN.matcher(backText);
- if (matcher.matches()) {
- // extract function parameters
- Map params = extractParams(matcher.group(3));
- // add global parameters
- List globals = getGlobals();
- if (globals != null) {
- for (Iterator iterator = globals.iterator(); iterator.hasNext(); ) {
- GlobalDescr global = (GlobalDescr) iterator.next();
- params.put(global.getIdentifier(), global.getType());
- }
- }
- String functionText = matcher.group(4);
- props = getJavaCompletionProposals(functionText, prefix, params);
- filterProposalsOnPrefix(prefix, props);
- } else {
- props = getPossibleProposals(viewer, documentOffset, backText, prefix);
- }
- }
- return props;
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
+ IDocument doc = viewer.getDocument();
+ String backText = readBackwards( documentOffset,
+ doc );
+
+ String prefix = CompletionUtil.stripLastWord( backText );
+
+ List props = null;
+ Matcher matcher = IMPORT_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ String classNameStart = backText.substring( backText.lastIndexOf( "import" ) + 7 );
+ props = getAllClassProposals( classNameStart,
+ documentOffset );
+ } else {
+ matcher = FUNCTION_PATTERN.matcher( backText );
+ if ( matcher.matches() ) {
+ // extract function parameters
+ Map params = extractParams( matcher.group( 3 ) );
+ // add global parameters
+ List globals = getGlobals();
+ if ( globals != null ) {
+ for ( Iterator iterator = globals.iterator(); iterator.hasNext(); ) {
+ GlobalDescr global = (GlobalDescr) iterator.next();
+ params.put( global.getIdentifier(),
+ global.getType() );
+ }
+ }
+ String functionText = matcher.group( 4 );
+ props = getJavaCompletionProposals( functionText,
+ prefix,
+ params );
+ filterProposalsOnPrefix( prefix,
+ props );
+ } else {
+ props = getPossibleProposals( viewer,
+ documentOffset,
+ backText,
+ prefix );
+ }
+ }
+ return props;
+ } catch ( Throwable t ) {
+ DroolsEclipsePlugin.log( t );
}
return null;
- }
-
- private Map extractParams(String params) {
- Map result = new HashMap();
- String[] parameters = StringUtils.split(params, ",");
- for (int i = 0; i < parameters.length; i++) {
- String[] typeAndName = StringUtils.split(parameters[i]);
- if (typeAndName.length == 2) {
- result.put(typeAndName[1], typeAndName[0]);
- }
- }
- return result;
- }
+ }
- private List getAllClassProposals(final String classNameStart, final int documentOffset) {
- final List list = new ArrayList();
- IEditorInput input = getEditor().getEditorInput();
- if (input instanceof IFileEditorInput) {
- IProject project = ((IFileEditorInput) input).getFile().getProject();
- IJavaProject javaProject = JavaCore.create(project);
-
- CompletionRequestor requestor = new CompletionRequestor() {
- public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
- String className = new String(proposal.getCompletion());
- if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.PACKAGE_REF) {
- RuleCompletionProposal prop = new RuleCompletionProposal(classNameStart.length(), className, className + ".");
- prop.setImage(DroolsPluginImages.getImage(DroolsPluginImages.PACKAGE));
- list.add(prop);
- } else if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF) {
- RuleCompletionProposal prop = new RuleCompletionProposal(classNameStart.length() - proposal.getReplaceStart(), className, className + ";");
- prop.setImage(DroolsPluginImages.getImage(DroolsPluginImages.CLASS));
- list.add(prop);
- }
- // ignore all other proposals
- }
- };
+ private Map extractParams(String params) {
+ Map result = new HashMap();
+ String[] parameters = StringUtils.split( params,
+ "," );
+ for ( int i = 0; i < parameters.length; i++ ) {
+ String[] typeAndName = StringUtils.split( parameters[i] );
+ if ( typeAndName.length == 2 ) {
+ result.put( typeAndName[1],
+ typeAndName[0] );
+ }
+ }
+ return result;
+ }
- try {
- javaProject.newEvaluationContext().codeComplete(classNameStart, classNameStart.length(), requestor);
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
- }
- }
- return list;
- }
-
- protected List getPossibleProposals(ITextViewer viewer, int documentOffset, String backText, final String prefix) {
+ private List getAllClassProposals(final String classNameStart,
+ final int documentOffset) {
+ final List list = new ArrayList();
+ IEditorInput input = getEditor().getEditorInput();
+ if ( input instanceof IFileEditorInput ) {
+ IProject project = ((IFileEditorInput) input).getFile().getProject();
+ IJavaProject javaProject = JavaCore.create( project );
+
+ CompletionRequestor requestor = new CompletionRequestor() {
+ public void accept(org.eclipse.jdt.core.CompletionProposal proposal) {
+ String className = new String( proposal.getCompletion() );
+ if ( proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.PACKAGE_REF ) {
+ RuleCompletionProposal prop = new RuleCompletionProposal( classNameStart.length(),
+ className,
+ className + "." );
+ prop.setImage( DroolsPluginImages.getImage( DroolsPluginImages.PACKAGE ) );
+ list.add( prop );
+ } else if ( proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF ) {
+ RuleCompletionProposal prop = new RuleCompletionProposal( classNameStart.length() - proposal.getReplaceStart(),
+ className,
+ className + ";" );
+ prop.setImage( DroolsPluginImages.getImage( DroolsPluginImages.CLASS ) );
+ list.add( prop );
+ }
+ // ignore all other proposals
+ }
+ };
+
+ try {
+ javaProject.newEvaluationContext().codeComplete( classNameStart,
+ classNameStart.length(),
+ requestor );
+ } catch ( Throwable t ) {
+ DroolsEclipsePlugin.log( t );
+ }
+ }
+ return list;
+ }
+
+ protected List getPossibleProposals(ITextViewer viewer,
+ int documentOffset,
+ String backText,
+ final String prefix) {
List list = new ArrayList();
- list.add(new RuleCompletionProposal(prefix.length(), "rule", NEW_RULE_TEMPLATE, 6));
- list.add(new RuleCompletionProposal(prefix.length(), "import", "import "));
- list.add(new RuleCompletionProposal(prefix.length(), "expander", "expander "));
- list.add(new RuleCompletionProposal(prefix.length(), "global", "global "));
- list.add(new RuleCompletionProposal(prefix.length(), "package", "package "));
- list.add(new RuleCompletionProposal(prefix.length(), "query", NEW_QUERY_TEMPLATE));
- list.add(new RuleCompletionProposal(prefix.length(), "function", NEW_FUNCTION_TEMPLATE, 14));
- list.add(new RuleCompletionProposal(prefix.length(), "template", NEW_TEMPLATE_TEMPLATE, 9));
- filterProposalsOnPrefix(prefix, list);
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "rule",
+ NEW_RULE_TEMPLATE,
+ 6 ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "import",
+ "import " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "expander",
+ "expander " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "global",
+ "global " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "package",
+ "package " ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "query",
+ NEW_QUERY_TEMPLATE ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "function",
+ NEW_FUNCTION_TEMPLATE,
+ 14 ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "template",
+ NEW_TEMPLATE_TEMPLATE,
+ 9 ) );
+ filterProposalsOnPrefix( prefix,
+ list );
return list;
}
- protected List getJavaCompletionProposals(final String javaText, final String prefix, Map params) {
- final List list = new ArrayList();
- IEditorInput input = getEditor().getEditorInput();
- if (input instanceof IFileEditorInput) {
- IProject project = ((IFileEditorInput) input).getFile().getProject();
- IJavaProject javaProject = JavaCore.create(project);
-
- CompletionRequestor requestor = new CompletionRequestor() {
- public void accept(CompletionProposal proposal) {
- // TODO set other proposal properties too (display name, icon, ...)
- String completion = new String(proposal.getCompletion());
- RuleCompletionProposal prop = new RuleCompletionProposal(prefix.length(), completion);
- switch (proposal.getKind()) {
- case CompletionProposal.LOCAL_VARIABLE_REF:
- prop.setImage(VARIABLE_ICON);
- break;
- case CompletionProposal.METHOD_REF:
- // TODO: Object methods are proposed when in the start of a line
- String javaTextWithoutPrefix = javaText.substring(0, javaText.length() - prefix.length());
- if ("".equals(javaTextWithoutPrefix.trim()) || START_OF_NEW_JAVA_STATEMENT.matcher(javaTextWithoutPrefix).matches()) {
- return;
- }
- prop.setImage(METHOD_ICON);
- break;
- default:
- }
- list.add(prop);
- }
- };
+ /**
+ * @return a list of regular Java'ish RuleCompletionProposal
+ */
+ protected List getJavaCompletionProposals(final String javaText,
+ final String prefix,
+ Map params) {
+ final List list = new ArrayList();
+ CompletionRequestor requestor = new JavaCompletionRequestor( prefix,
+ javaText,
+ list );
- try {
- IEvaluationContext evalContext = javaProject.newEvaluationContext();
- List imports = getImports();
- if (imports != null && imports.size() > 0) {
- evalContext.setImports((String[]) imports.toArray(new String[imports.size()]));
- }
- StringBuffer javaTextWithParams = new StringBuffer();
- Iterator iterator = params.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry entry = (Map.Entry) iterator.next();
- // this does not seem to work, so adding variables manually
- // evalContext.newVariable((String) entry.getValue(), (String) entry.getKey(), null);
- javaTextWithParams.append(entry.getValue() + " " + entry.getKey() + ";\n");
- }
- javaTextWithParams.append("org.drools.spi.KnowledgeHelper drools;");
- javaTextWithParams.append(javaText);
- String text = javaTextWithParams.toString();
- evalContext.codeComplete(text, text.length(), requestor);
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
- }
- }
- return list;
- }
-
- protected List getImports() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getImports();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected List getFunctions() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getFunctions();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected Set getTemplates() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getTemplates();
- }
- return Collections.EMPTY_SET;
- }
-
- protected FactTemplateDescr getTemplate(String name) {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getTemplate(name);
- }
- return null;
- }
-
- protected List getGlobals() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getGlobals();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected List getClassesInPackage() {
- if (getEditor() instanceof DRLRuleEditor) {
- return ((DRLRuleEditor) getEditor()).getClassesInPackage();
- }
- return Collections.EMPTY_LIST;
- }
-
- protected boolean isStartOfJavaExpression(String text) {
- return "".equals(text.trim()) || START_OF_NEW_JAVA_STATEMENT.matcher(text).matches();
- }
+ requestJavaCompletionProposals( javaText,
+ prefix,
+ params,
+ requestor );
+ return list;
+ }
+ /**
+ * @return a list of "MVELified" RuleCompletionProposal. Thta list contains only unqiue proposal based on
+ * the overrriden equals in {@link RuleCompletionProposal} to avoid the situation when several
+ * accessors can exist for one property. for that case we want to keep only one proposal.
+ */
+ protected List getJavaMvelCompletionProposals(final String javaText,
+ final String prefix,
+ Map params) {
+ final Collection set = new HashSet();
+ CompletionRequestor requestor = new MvelCompletionRequestor( prefix,
+ javaText,
+ set );
+ requestJavaCompletionProposals( javaText,
+ prefix,
+ params,
+ requestor );
+ List list = new ArrayList();
+ list.addAll( set );
+ return list;
+ }
+
+ protected void requestJavaCompletionProposals(final String javaText,
+ final String prefix,
+ Map params,
+ CompletionRequestor requestor) {
+
+ IEditorInput input = getEditor().getEditorInput();
+ if ( !(input instanceof IFileEditorInput) ) {
+ return;
+ }
+ IProject project = ((IFileEditorInput) input).getFile().getProject();
+ IJavaProject javaProject = JavaCore.create( project );
+
+ try {
+ IEvaluationContext evalContext = javaProject.newEvaluationContext();
+ List imports = getImports();
+ if ( imports != null && imports.size() > 0 ) {
+ evalContext.setImports( (String[]) imports.toArray( new String[imports.size()] ) );
+ }
+ StringBuffer javaTextWithParams = new StringBuffer();
+ Iterator iterator = params.entrySet().iterator();
+ while ( iterator.hasNext() ) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ // this does not seem to work, so adding variables manually
+ // evalContext.newVariable((String) entry.getValue(), (String) entry.getKey(), null);
+ javaTextWithParams.append( entry.getValue() + " " + entry.getKey() + ";\n" );
+ }
+ javaTextWithParams.append( "org.drools.spi.KnowledgeHelper drools;" );
+ javaTextWithParams.append( javaText );
+ String text = javaTextWithParams.toString();
+ System.out.println( "" );
+ System.out.println( "MVEL: synthetic Java text:" + text );
+ evalContext.codeComplete( text,
+ text.length(),
+ requestor );
+ } catch ( Throwable t ) {
+ DroolsEclipsePlugin.log( t );
+ }
+ }
+
+ protected String getPackage() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getPackage();
+ }
+ return "";
+ }
+
+ protected List getImports() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getImports();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected List getFunctions() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getFunctions();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected Set getTemplates() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getTemplates();
+ }
+ return Collections.EMPTY_SET;
+ }
+
+ protected FactTemplateDescr getTemplate(String name) {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getTemplate( name );
+ }
+ return null;
+ }
+
+ protected List getGlobals() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getGlobals();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected List getClassesInPackage() {
+ if ( getEditor() instanceof DRLRuleEditor ) {
+ return ((DRLRuleEditor) getEditor()).getClassesInPackage();
+ }
+ return Collections.EMPTY_LIST;
+ }
+
+ protected boolean isStartOfDialectExpression(String text) {
+ return "".equals( text.trim() ) || START_OF_NEW_JAVA_STATEMENT.matcher( text ).matches();
+ }
}
Deleted: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DialectDeterminator.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DialectDeterminator.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DialectDeterminator.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -1,34 +0,0 @@
-package org.drools.eclipse.editors.completion;
-
-import java.util.List;
-
-import org.drools.compiler.Dialect;
-import org.drools.compiler.DrlParser;
-import org.drools.compiler.DroolsParserException;
-import org.drools.lang.descr.PackageDescr;
-import org.drools.lang.descr.RuleDescr;
-
-public class DialectDeterminator {
-
- private DialectDeterminator() {
- }
-
- public static Dialect getDialect(String backText) {
- DrlParser parser = new DrlParser();
- try {
- PackageDescr packageDescr = parser.parse(backText);
- List rules = packageDescr.getRules();
-
- if (rules != null && rules.size() == 1) {
- Object o = rules.get(0);
- if (o instanceof RuleDescr) {
- RuleDescr desc = (RuleDescr) o;
- return desc.getDialect();
- }
- }
- } catch (DroolsParserException exc) {
- // do nothing
- }
- return null;
- }
-}
Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/JavaCompletionRequestor.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,43 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.Collection;
+
+import org.eclipse.jdt.core.CompletionProposal;
+import org.eclipse.jdt.core.CompletionRequestor;
+
+public class JavaCompletionRequestor extends CompletionRequestor {
+ private final String prefix;
+ private final String text;
+ private final Collection list;
+
+ public JavaCompletionRequestor(String prefix,
+ String text,
+ Collection list) {
+ this.prefix = prefix;
+ this.text = text;
+ this.list = list;
+ }
+
+ public void accept(CompletionProposal proposal) {
+ // TODO set other proposal properties too (display name, icon, ...)
+ String completion = new String( proposal.getCompletion() );
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ completion );
+
+ switch ( proposal.getKind() ) {
+ case CompletionProposal.LOCAL_VARIABLE_REF :
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ break;
+ case CompletionProposal.METHOD_REF :
+ // TODO: Object methods are proposed when in the start of a line
+ if ( CompletionUtil.isStartOfNewStatement( text,
+ prefix ) ) {
+ return;
+ }
+ prop.setImage( DefaultCompletionProcessor.METHOD_ICON );
+ break;
+ default :
+ }
+ list.add( prop );
+ }
+}
\ No newline at end of file
Deleted: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/LocationDeterminator.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -1,639 +0,0 @@
-package org.drools.eclipse.editors.completion;
-
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.drools.compiler.DrlParser;
-import org.drools.compiler.DroolsParserException;
-import org.drools.lang.Location;
-import org.drools.lang.descr.BaseDescr;
-import org.drools.lang.descr.PackageDescr;
-import org.drools.lang.descr.RuleDescr;
-
-public class LocationDeterminator {
-
-// private static final Pattern PATTERN_PATTERN_START = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*[^\\s<>!=:]*",
-// Pattern.DOTALL );
- static final Pattern PATTERN_PATTERN_OPERATOR = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\),]+)(\\s*([<>=!]+)\\s*[^\\s<>!=:]*\\s*(&&|\\|\\|))*\\s+",
- Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_CONTAINS_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+contains\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MATCHES_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+matches\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_EXCLUDES_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+excludes\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_IN_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?in\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MEMBER_OF_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?memberOf\\s+[^\\s<>!=:]*",
-// Pattern.DOTALL );
- static final Pattern PATTERN_PATTERN_COMPARATOR_ARGUMENT = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s*(([<>=!]+)\\s*[^\\s<>!=:]+\\s*(&&|\\|\\|)\\s*)*([<>=!]+)\\s*[^\\s<>!=:]*",
- Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_CONTAINS_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+contains\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MATCHES_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+matches\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_EXCLUDES_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+excludes\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_IN_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?in\\s+\\([^\\)]+\\)\\s*",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_MEMBER_OF_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s+(not\\s+)?memberOf\\s+[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-// private static final Pattern PATTERN_PATTERN_COMPARATOR_END = Pattern.compile( ".*[(,](\\s*(\\S*)\\s*:)?\\s*([^\\s<>!=:\\(\\)]+)\\s*([<>=!]+)\\s*[^\\s<>!=:,]+\\s+",
-// Pattern.DOTALL );
-
-// private static final Pattern PATTERN_PATTERN = Pattern.compile( "((\\S+)\\s*:\\s*)?(\\S+)\\s*(\\(.*)",
-// Pattern.DOTALL );
-// private static final Pattern EXISTS_PATTERN = Pattern.compile( ".*\\s+exists\\s*\\(?\\s*((\\S*)\\s*:)?\\s*\\S*",
-// Pattern.DOTALL );
-// private 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 );
-// private static final Pattern FROM_PATTERN = Pattern.compile( ".*\\)\\s+from\\s+",
-// Pattern.DOTALL );
-// private static final Pattern ACCUMULATE_PATTERN = Pattern.compile( ".*\\)\\s+from\\s+accumulate\\s*\\(\\s*",
-// Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_INIT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_ACTION = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_REVERSE = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?\\s*reverse\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
- static final Pattern ACCUMULATE_PATTERN_RESULT = Pattern.compile( ".*,?\\s*init\\s*\\(\\s*(.*)\\)\\s*,?\\s*action\\s*\\(\\s*(.*)\\)\\s*,?(\\s*reverse\\s*\\(\\s*(.*)\\)\\s*,?)?\\s*result\\s*\\(\\s*(.*)",
- Pattern.DOTALL );
-// private static final Pattern COLLECT_PATTERN = Pattern.compile( ".*\\)\\s+from\\s+collect\\s*\\(\\s*",
-// Pattern.DOTALL );
-
- static final Pattern THEN_PATTERN = Pattern.compile( ".*\n\\s*when\\s*(.*)\n\\s*then\\s*(.*)",
- Pattern.DOTALL );
-
- static final Pattern ENDS_WITH_SPACES = Pattern.compile( ".*\\s+",
- Pattern.DOTALL );
-
- private LocationDeterminator() {
- }
-
- public static Location getLocation(String backText) {
- DrlParser parser = new DrlParser();
- try {
- PackageDescr packageDescr = parser.parse( backText );
- List rules = packageDescr.getRules();
- if ( rules != null && rules.size() == 1 ) {
- return determineLocationForDescr( (RuleDescr) rules.get( 0 ),
- parser.getLocation(),
- backText );
- }
- } catch ( DroolsParserException exc ) {
- // do nothing
- }
- return new Location( Location.LOCATION_UNKNOWN );
- }
-
- public static Location determineLocationForDescr(BaseDescr descr,
- Location location,
- String backText) {
- if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR ) {
- if ( !ENDS_WITH_SPACES.matcher( backText ).matches() ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_START );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_END ) {
- if ( !backText.endsWith( " " ) ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_EVAL ) {
- Matcher matcher = EVAL_PATTERN.matcher( backText );
- if ( matcher.matches() ) {
- String content = matcher.group( 1 );
- location.setProperty( Location.LOCATION_EVAL_CONTENT,
- content );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_START ) {
- Matcher matcher = PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
- location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
- matcher.group( 7 ) );
- return location;
- }
-
- matcher = PATTERN_PATTERN_OPERATOR.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR );
- return location;
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM ) {
- if ( location.getProperty( Location.LOCATION_FROM_CONTENT ) == null ) {
- location.setProperty( Location.LOCATION_FROM_CONTENT,
- "" );
- } else if ( ((String) location.getProperty( Location.LOCATION_FROM_CONTENT )).length() > 0 && ENDS_WITH_SPACES.matcher( backText ).matches() ) {
- location.setType( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_INIT ) {
- Matcher matcher = ACCUMULATE_PATTERN_INIT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT,
- matcher.group( 1 ) );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION ) {
- Matcher matcher = ACCUMULATE_PATTERN_ACTION.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT,
- matcher.group( 2 ) );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE) {
- Matcher matcher = ACCUMULATE_PATTERN_REVERSE.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_REVERSE_CONTENT,
- matcher.group( 3 ) );
- }
- matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
- matcher.group( 5 ) );
- }
- } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT ) {
- Matcher matcher = ACCUMULATE_PATTERN_RESULT.matcher( backText );
- if ( matcher.matches() ) {
- location.setType( Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE );
- location.setProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT,
- matcher.group( 5 ) );
- }
- } else if ( location.getType() == Location.LOCATION_RHS ) {
- Matcher matcher = THEN_PATTERN.matcher( backText );
- if ( matcher.matches() ) {
- location.setProperty( Location.LOCATION_LHS_CONTENT,
- matcher.group( 1 ) );
- location.setProperty( Location.LOCATION_RHS_CONTENT,
- matcher.group( 2 ) );
- return location;
- }
- }
-
- return location;
- // if (descr instanceof RuleDescr) {
- // RuleDescr ruleDescr = (RuleDescr) descr;
- // Object o = ruleDescr.getConsequence();
- // if (o == null) {
- // Matcher matcher = THEN_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_RHS);
- // location.setProperty(Location.LOCATION_LHS_CONTENT, matcher.group(1));
- // location.setProperty(Location.LOCATION_RHS_CONTENT, matcher.group(2));
- // return location;
- // }
- // }
- // AndDescr lhs = ruleDescr.getLhs();
- // if (lhs == null) {
- // return new Location(Location.LOCATION_RULE_HEADER);
- // }
- // List subDescrs = lhs.getDescrs();
- // if (subDescrs.size() == 0) {
- // Matcher matcher = EXISTS_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // matcher = NOT_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // matcher = FROM_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM);
- // location.setProperty(Location.LOCATION_FROM_CONTENT, "");
- // return location;
- // }
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(subDescrs.size() - 1);
- // if (subDescr == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // if (endReached(subDescr)) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // return determineLocationForDescr(subDescr, backText);
- // } else if (descr instanceof PatternDescr) {
- // PatternDescr patternDescr = (PatternDescr) descr;
- //// int locationType;
- //// String propertyName = null;
- //// String evaluator = null;
- //// boolean endOfConstraint = false;
- //// List subDescrs = columnDescr.getDescrs();
- //// if (subDescrs.size() > 0) {
- //// BaseDescr lastDescr = (BaseDescr) subDescrs.get(subDescrs.size() - 1);
- //// if (lastDescr.getEndCharacter() != -1) {
- //// endOfConstraint = true;
- //// }
- //// if (lastDescr instanceof FieldConstraintDescr) {
- //// FieldConstraintDescr lastFieldDescr = (FieldConstraintDescr) lastDescr;
- //// propertyName = lastFieldDescr.getFieldName();
- //// List restrictions = lastFieldDescr.getRestrictions();
- //// if (restrictions.size() > 0) {
- //// RestrictionDescr restriction = (RestrictionDescr) restrictions.get(restrictions.size() - 1);
- //// if (restriction instanceof LiteralRestrictionDescr) {
- //// LiteralRestrictionDescr literal = (LiteralRestrictionDescr) restriction;
- //// evaluator = literal.getEvaluator();
- //// } else if (restriction instanceof VariableRestrictionDescr) {
- //// VariableRestrictionDescr variable = (VariableRestrictionDescr) restriction;
- //// evaluator = variable.getEvaluator();
- //// }
- //// }
- //// }
- //// }
- //// if (endOfConstraint) {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_END;
- //// } else if (evaluator != null) {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_ARGUMENT;
- //// } else if (propertyName != null) {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_OPERATOR;
- //// } else {
- //// locationType = Location.LOCATION_INSIDE_CONDITION_START;
- //// }
- //// Location location = new Location(locationType);
- //// location.setProperty(Location.LOCATION_PROPERTY_CLASS_NAME, columnDescr.getObjectType());
- //// location.setProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME, propertyName);
- //// location.setProperty(Location.LOCATION_PROPERTY_OPERATOR, evaluator);
- //// return location;
- // // TODO: this is not completely safe, there are rare occasions where this could fail
- // Pattern pattern = Pattern.compile(".*(" + patternDescr.getObjectType() + ")\\s*\\((.*)", Pattern.DOTALL);
- // Matcher matcher = pattern.matcher(backText);
- // String patternContents = null;
- // while (matcher.find()) {
- // patternContents = "(" + matcher.group(2);
- // }
- // if (patternContents == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
- // }
- // List subDescrs = patternDescr.getDescrs();
- // if (subDescrs.size() > 0) {
- // Object lastDescr = subDescrs.get(subDescrs.size() - 1);
- // if (lastDescr instanceof FieldConstraintDescr) {
- // FieldConstraintDescr lastFieldDescr = (FieldConstraintDescr) lastDescr;
- // List restrictions = lastFieldDescr.getRestrictions();
- // // if there are multiple restrictions, filter out all the rest so that
- // // only the last one remains
- // if (restrictions.size() > 2) {
- // Object last = restrictions.get(restrictions.size() - 2);
- // if (last instanceof RestrictionConnectiveDescr) {
- // RestrictionConnectiveDescr lastRestr = (RestrictionConnectiveDescr) last;
- // String connective = "&&";
- // if (lastRestr.getConnective() == RestrictionConnectiveDescr.OR) {
- // connective = "||";
- // }
- // int connectiveLocation = patternContents.lastIndexOf(connective);
- // patternContents = "( " + lastFieldDescr.getFieldName() + " " + patternContents.substring(connectiveLocation + 1);
- // }
- // }
- // if (restrictions.size() > 1) {
- // Object last = restrictions.get(restrictions.size() - 1);
- // if (last instanceof RestrictionConnectiveDescr) {
- // RestrictionConnectiveDescr lastRestr = (RestrictionConnectiveDescr) last;
- // String connective = "&&";
- // if (lastRestr.getConnective() == RestrictionConnectiveDescr.OR) {
- // connective = "||";
- // }
- // int connectiveLocation = patternContents.lastIndexOf(connective);
- // patternContents = "( " + lastFieldDescr.getFieldName() + " " + patternContents.substring(connectiveLocation + 1);
- // }
- // }
- // }
- // }
- // return getLocationForPatttern(patternContents, patternDescr.getObjectType());
- // } else if (descr instanceof ExistsDescr) {
- // List subDescrs = ((ExistsDescr) descr).getDescrs();
- // if (subDescrs.size() == 0) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // if (subDescrs.size() == 1) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(0);
- // if (subDescr == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // Location result = determineLocationForDescr(subDescr, backText);
- // if (result.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // result.setType(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // return result;
- // }
- // return determineLocationForDescr(descr, backText);
- // } else if (descr instanceof NotDescr) {
- // List subDescrs = ((NotDescr) descr).getDescrs();
- // if (subDescrs.size() == 0) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // if (subDescrs.size() == 1) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(0);
- // if (subDescr == null) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // Location location = determineLocationForDescr(subDescr, backText);
- // if (location.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // return location;
- // }
- // return determineLocationForDescr(descr, backText);
- // } else if (descr instanceof AndDescr) {
- // List subDescrs = ((AndDescr) descr).getDescrs();
- // int size = subDescrs.size();
- // if (size == 2) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(1);
- // if (subDescr == null) {
- // Matcher matcher = EXISTS_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // matcher = NOT_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // } else {
- // Location location = determineLocationForDescr(subDescr, backText);
- // if (location.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // }
- // return location;
- // }
- // }
- // return new Location(Location.LOCATION_UNKNOWN);
- // } else if (descr instanceof OrDescr) {
- // List subDescrs = ((OrDescr) descr).getDescrs();
- // int size = subDescrs.size();
- // if (size == 2) {
- // BaseDescr subDescr = (BaseDescr) subDescrs.get(1);
- // if (subDescr == null) {
- // Matcher matcher = EXISTS_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS);
- // }
- // matcher = NOT_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT);
- // }return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // } else {
- // Location location = determineLocationForDescr(subDescr, backText);
- // if (location.getType() == Location.LOCATION_LHS_BEGIN_OF_CONDITION) {
- // return new Location(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
- // }
- // return location;
- // }
- // }
- // return new Location(Location.LOCATION_UNKNOWN);
- // } else if (descr instanceof FromDescr) {
- // Location location = new Location(Location.LOCATION_LHS_FROM);
- // String content = CompletionUtil.stripWhiteSpace(backText);
- // location.setProperty(Location.LOCATION_FROM_CONTENT, content);
- // return location;
- // } else if (descr instanceof AccumulateDescr) {
- // Matcher matcher = ACCUMULATE_PATTERN.matcher(backText);
- // int end = -1;
- // while (matcher.find()) {
- // end = matcher.end();
- // }
- // String accumulateText = backText.substring(end);
- // matcher = ACCUMULATE_PATTERN_RESULT.matcher(accumulateText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE);
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, matcher.group(2));
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT, matcher.group(3));
- // return location;
- // }
- // matcher = ACCUMULATE_PATTERN_ACTION.matcher(accumulateText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE);
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT, matcher.group(2));
- // return location;
- // }
- // matcher = ACCUMULATE_PATTERN_INIT.matcher(accumulateText);
- // if (matcher.matches()) {
- // Location location = new Location(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE);
- // location.setProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT, matcher.group(1));
- // return location;
- // }
- // matcher = PATTERN_PATTERN.matcher(accumulateText);
- // if (matcher.matches()) {
- // String className = matcher.group(3);
- // String patternContents = matcher.group(4);
- // return getLocationForPatttern(patternContents, className);
- // }
- // return new Location(Location.LOCATION_LHS_FROM_ACCUMULATE);
- // } else if (descr instanceof CollectDescr) {
- // Matcher matcher = COLLECT_PATTERN.matcher(backText);
- // int end = -1;
- // while (matcher.find()) {
- // end = matcher.end();
- // }
- // String collectText = backText.substring(end);
- // matcher = PATTERN_PATTERN.matcher(collectText);
- // if (matcher.matches()) {
- // String className = matcher.group(3);
- // String columnContents = matcher.group(4);
- // return getLocationForPatttern(columnContents, className);
- // }
- // return new Location(Location.LOCATION_LHS_FROM_COLLECT);
- // } else if (descr instanceof EvalDescr) {
- // Matcher matcher = EVAL_PATTERN.matcher(backText);
- // if (matcher.matches()) {
- // String content = matcher.group(1);
- // Location location = new Location(Location.LOCATION_LHS_INSIDE_EVAL);
- // location.setProperty(Location.LOCATION_EVAL_CONTENT, content);
- // return location;
- // }
- // }
- //
- // return new Location(Location.LOCATION_UNKNOWN);
- }
-
-// private static boolean endReached(BaseDescr descr) {
-// if ( descr == null ) {
-// return false;
-// }
-// if ( descr instanceof PatternDescr ) {
-// return descr.getEndCharacter() != -1;
-// } else if ( descr instanceof ExistsDescr ) {
-// List descrs = ((ExistsDescr) descr).getDescrs();
-// if ( descrs.isEmpty() ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) );
-// } else if ( descr instanceof NotDescr ) {
-// List descrs = ((NotDescr) descr).getDescrs();
-// if ( descrs.isEmpty() ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) );
-// } else if ( descr instanceof NotDescr ) {
-// List descrs = ((NotDescr) descr).getDescrs();
-// if ( descrs.isEmpty() ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) );
-// } else if ( descr instanceof AndDescr ) {
-// List descrs = ((AndDescr) descr).getDescrs();
-// if ( descrs.size() != 2 ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) ) && endReached( (BaseDescr) descrs.get( 1 ) );
-// } else if ( descr instanceof OrDescr ) {
-// List descrs = ((OrDescr) descr).getDescrs();
-// if ( descrs.size() != 2 ) {
-// return false;
-// }
-// return endReached( (BaseDescr) descrs.get( 0 ) ) && endReached( (BaseDescr) descrs.get( 1 ) );
-// } else if ( descr instanceof EvalDescr ) {
-// return ((EvalDescr) descr).getContent() != null;
-// }
-// return descr.getEndCharacter() != -1;
-// // else if (descr instanceof AccumulateDescr) {
-// // return ((AccumulateDescr) descr).getResultCode() != null;
-// // } else if (descr instanceof CollectDescr) {
-// // return ((CollectDescr) descr).getSourceColumn() != null;
-// // }
-// // return false;
-// }
-//
-// private static Location getLocationForPatttern(String patternContents,
-// String className) {
-// Matcher matcher = PATTERN_PATTERN_OPERATOR.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_START.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_START );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// if ( matcher.group( 8 ) != null ) {
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// matcher.group( 8 ) );
-// } else {
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// matcher.group( 4 ) );
-// }
-// return location;
-// }
-// matcher = PATTERN_PATTERN_CONTAINS_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "contains" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_EXCLUDES_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "excludes" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_IN_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "in" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MEMBER_OF_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "memberOf" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MATCHES_ARGUMENT.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// location.setProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME,
-// matcher.group( 3 ) );
-// location.setProperty( Location.LOCATION_PROPERTY_OPERATOR,
-// "matches" );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_CONTAINS_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MATCHES_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_EXCLUDES_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_IN_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_MEMBER_OF_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// matcher = PATTERN_PATTERN_COMPARATOR_END.matcher( patternContents );
-// if ( matcher.matches() ) {
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-// Location location = new Location( Location.LOCATION_LHS_INSIDE_CONDITION_END );
-// location.setProperty( Location.LOCATION_PROPERTY_CLASS_NAME,
-// className );
-// return location;
-// }
-}
Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/MvelCompletionRequestor.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,64 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.Collection;
+
+import org.eclipse.jdt.core.CompletionProposal;
+import org.eclipse.jdt.core.CompletionRequestor;
+
+public class MvelCompletionRequestor extends CompletionRequestor {
+ private final String prefix;
+ private final String text;
+ private final Collection list;
+
+ public MvelCompletionRequestor(String prefix,
+ String text,
+ Collection list) {
+ this.prefix = prefix;
+ this.text = text;
+ this.list = list;
+ }
+
+ public void accept(CompletionProposal proposal) {
+ // TODO set other proposal properties too (display name, icon, ...)
+ String completion = new String( proposal.getCompletion() );
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ completion );;
+
+ switch ( proposal.getKind() ) {
+ case CompletionProposal.LOCAL_VARIABLE_REF :
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ break;
+
+ case CompletionProposal.METHOD_REF :
+ // TODO: Object methods are proposed when in the start of a line
+
+ //get the eventual property name for that method name and signature
+ String propertyOrMethodName = CompletionUtil.getPropertyName( completion,
+ proposal.getSignature() );
+ //is the completion for a bean accessor?
+ boolean isAccessor = completion.equals( propertyOrMethodName );
+
+ prop = new RuleCompletionProposal( prefix.length(),
+ propertyOrMethodName );
+ boolean startOfNewStatement = CompletionUtil.isStartOfNewStatement( text,
+ prefix );
+ if ( startOfNewStatement ) {
+ //ignore non accessor methods when starting a new statement
+ if ( isAccessor ) {
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ }
+ } else {
+ if ( isAccessor ) {
+ prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ } else {
+ prop.setImage( DefaultCompletionProcessor.METHOD_ICON );
+ }
+ }
+
+ break;
+
+ default :
+ }
+ list.add( prop );
+ }
+}
\ No newline at end of file
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -8,13 +8,14 @@
import java.util.Map;
import org.drools.base.ClassTypeResolver;
-import org.drools.compiler.Dialect;
-import org.drools.compiler.DrlParser;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilderConfiguration;
+import org.drools.eclipse.DRLInfo;
import org.drools.eclipse.DroolsEclipsePlugin;
import org.drools.eclipse.DroolsPluginImages;
+import org.drools.eclipse.DRLInfo.RuleInfo;
import org.drools.eclipse.editors.AbstractRuleEditor;
+import org.drools.eclipse.editors.DRLRuleEditor;
import org.drools.eclipse.util.ProjectClassLoader;
import org.drools.lang.Location;
import org.drools.lang.descr.AndDescr;
@@ -28,11 +29,14 @@
import org.drools.lang.descr.OrDescr;
import org.drools.lang.descr.PackageDescr;
import org.drools.lang.descr.PatternDescr;
-import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.builder.dialect.mvel.MVELDialect;
import org.drools.util.asm.ClassFieldInspector;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.graphics.Image;
+import org.mvel.ExpressionCompiler;
+import org.mvel.ParserContext;
+import org.mvel.PropertyVerifier;
/**
* For handling within rules.
@@ -41,754 +45,1053 @@
*/
public class RuleCompletionProcessor extends DefaultCompletionProcessor {
- private static final Image DROOLS_ICON = DroolsPluginImages
- .getImage(DroolsPluginImages.DROOLS);
+ private static final Image DROOLS_ICON = DroolsPluginImages.getImage( DroolsPluginImages.DROOLS );
- private static final Image CLASS_ICON = DroolsPluginImages
- .getImage(DroolsPluginImages.CLASS);
+ private static final Image CLASS_ICON = DroolsPluginImages.getImage( DroolsPluginImages.CLASS );
- public RuleCompletionProcessor(AbstractRuleEditor editor) {
- super(editor);
- }
+ /**
+ * A CompletionContext contains the DRL backtext parsing results, to avoid multilpe parser invocations
+ */
+ private CompletionContext context;
- protected List getCompletionProposals(ITextViewer viewer, int documentOffset) {
- try {
- final List list = new ArrayList();
+ public RuleCompletionProcessor(AbstractRuleEditor editor) {
+ super( editor );
+ }
- IDocument doc = viewer.getDocument();
- String backText = readBackwards(documentOffset, doc);
- final String prefix = CompletionUtil.stripLastWord(backText);
+ protected List getCompletionProposals(ITextViewer viewer,
+ int documentOffset) {
+ try {
+ final List list = new ArrayList();
- if (backText.length() < 5) {
- return list;
- }
+ IDocument doc = viewer.getDocument();
- Location location = LocationDeterminator.getLocation(backText);
- Dialect dialect = DialectDeterminator.getDialect(backText);
- //MVEL: completion
- if (location.getType() == Location.LOCATION_RULE_HEADER) {
- addRuleHeaderProposals(list, prefix, backText);
- } else if (location.getType() == Location.LOCATION_RHS) {
- addRHSCompletionProposals(list, prefix, backText,
- (String) location
- .getProperty(Location.LOCATION_LHS_CONTENT),
- (String) location
- .getProperty(Location.LOCATION_RHS_CONTENT));
- } else {
- addLHSCompletionProposals(list, location, prefix, backText);
- }
+ String backText = readBackwards( documentOffset,
+ doc );
+ final String prefix = CompletionUtil.stripLastWord( backText );
- filterProposalsOnPrefix(prefix, list);
- return list;
- } catch (Throwable t) {
- DroolsEclipsePlugin.log(t);
- }
- return null;
- }
+ //FIXME:where does the magic number 5 come from? "rule "?
+ if ( backText.length() < 5 ) {
+ return list;
+ }
- protected void addRHSCompletionProposals(List list, String prefix,
- String backText, String conditions, String consequence) {
- // only add functions and keywords if at the beginning of a
- // new statement
- String consequenceWithoutPrefix = consequence.substring(0, consequence
- .length()
- - prefix.length());
- if (isStartOfJavaExpression(consequenceWithoutPrefix)) {
- addRHSKeywordCompletionProposals(list, prefix);
- addRHSFunctionCompletionProposals(list, prefix);
- }
- addRHSJavaCompletionProposals(list, prefix, backText, conditions,
- consequence);
- }
+ this.context = new CompletionContext( backText );
+ Location location = context.getLocation();
- protected void addLHSCompletionProposals(List list, Location location,
- String prefix, String backText) {
- switch (location.getType()) {
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION:
- // if we are at the beginning of a new condition
- // add drools keywords
- list.add(new RuleCompletionProposal(prefix.length(), "and", "and ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "or", "or ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "from",
- "from ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "forall",
- "forall( )", 8, DROOLS_ICON));
- RuleCompletionProposal prop = new RuleCompletionProposal(prefix
- .length(), "eval", "eval( )", 6);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "then", "then"
- + System.getProperty("line.separator") + "\t");
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- // we do not break but also add all elements that are needed for
- // and/or
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR:
- list.add(new RuleCompletionProposal(prefix.length(), "not", "not ",
- DROOLS_ICON));
- // we do not break but also add all elements that are needed for
- // not
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT:
- list.add(new RuleCompletionProposal(prefix.length(), "exists",
- "exists ", DROOLS_ICON));
- // we do not break but also add all elements that are needed for
- // exists
- case Location.LOCATION_LHS_FROM_ACCUMULATE:
- case Location.LOCATION_LHS_FROM_COLLECT:
- case Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS:
- // and add imported classes
- Iterator iterator = getImports().iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next();
- int index = name.lastIndexOf(".");
- if (index != -1) {
- String className = name.substring(index + 1);
- RuleCompletionProposal p = new RuleCompletionProposal(
- prefix.length(), className, className + "( )",
- className.length() + 2);
- p.setPriority(-1);
- p.setImage(CLASS_ICON);
- list.add(p);
- }
- }
- iterator = getClassesInPackage().iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next();
- int index = name.lastIndexOf(".");
- if (index != -1) {
- String className = name.substring(index + 1);
- RuleCompletionProposal p = new RuleCompletionProposal(
- prefix.length(), className, className + "( )",
- className.length() + 2);
- p.setPriority(-1);
- p.setImage(CLASS_ICON);
- list.add(p);
- }
- }
- iterator = getTemplates().iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next();
- RuleCompletionProposal p = new RuleCompletionProposal(prefix
- .length(), name, name + "( )", name.length() + 2);
- p.setPriority(-1);
- p.setImage(CLASS_ICON);
- list.add(p);
- }
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_START:
- String className = (String) location
- .getProperty(Location.LOCATION_PROPERTY_CLASS_NAME);
- String propertyName = (String) location
- .getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME);
- if (className != null) {
- boolean isTemplate = addFactTemplatePropertyProposals(prefix,
- className, list);
- if (!isTemplate) {
- ClassTypeResolver resolver = new ClassTypeResolver(
- getImports(), ProjectClassLoader
- .getProjectClassLoader(getEditor()));
- try {
- String currentClass = className;
- if (propertyName != null) {
- String[] nestedProperties = propertyName
- .split("\\.");
- int nbSuperProperties = nestedProperties.length - 1;
- if (propertyName.endsWith(".")) {
- nbSuperProperties++;
- }
- for (int i = 0; i < nbSuperProperties; i++) {
- String simplePropertyName = nestedProperties[i];
- currentClass = getSimplePropertyClass(
- currentClass, simplePropertyName);
- currentClass = convertToNonPrimitiveClass(currentClass);
- }
- }
- RuleCompletionProposal p = new RuleCompletionProposal(
- prefix.length(), "this");
- p.setImage(METHOD_ICON);
- list.add(p);
- Class clazz = resolver.resolveType(currentClass);
- if (clazz != null) {
- if (Map.class.isAssignableFrom(clazz)) {
- p = new RuleCompletionProposal(prefix.length(),
- "this['']", "this['']", 6);
- p.setImage(METHOD_ICON);
- list.add(p);
- }
- ClassFieldInspector inspector = new ClassFieldInspector(
- clazz);
- Map types = inspector.getFieldTypes();
- Iterator iterator2 = inspector.getFieldNames()
- .keySet().iterator();
- while (iterator2.hasNext()) {
- String name = (String) iterator2.next();
- p = new RuleCompletionProposal(prefix.length(),
- name, name + " ");
- p.setImage(METHOD_ICON);
- list.add(p);
- Class type = (Class) types.get(name);
- if (type != null
- && Map.class.isAssignableFrom(type)) {
- name += "['']";
- p = new RuleCompletionProposal(prefix
- .length(), name, name, name
- .length() - 2);
- p.setImage(METHOD_ICON);
- list.add(p);
- }
- }
- }
- } catch (IOException exc) {
- // Do nothing
- } catch (ClassNotFoundException exc) {
- // Do nothing
- }
- }
- }
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR:
- className = (String) location
- .getProperty(Location.LOCATION_PROPERTY_CLASS_NAME);
- String property = (String) location
- .getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME);
- String type = getPropertyClass(className, property);
+ if ( location.getType() == Location.LOCATION_RULE_HEADER ) {
+ addRuleHeaderProposals( list,
+ prefix,
+ backText );
+ } else if ( location.getType() == Location.LOCATION_RHS ) {
+ addRHSCompletionProposals( list,
+ prefix,
+ backText,
+ (String) location.getProperty( Location.LOCATION_LHS_CONTENT ),
+ (String) location.getProperty( Location.LOCATION_RHS_CONTENT ) );
+ } else {
+ addLHSCompletionProposals( list,
+ location,
+ prefix,
+ backText );
+ }
- list.add(new RuleCompletionProposal(prefix.length(), "==", "== ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "!=", "!= ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ":", ": ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "->",
- "-> ( )", 5, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "memberOf",
- "memberOf ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "not memberOf", "not memberOf ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "in",
- "in ( )", 5, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "not in",
- "not in ( )", 9, DROOLS_ICON));
+ filterProposalsOnPrefix( prefix,
+ list );
+ return list;
+ } catch ( Throwable t ) {
+ t.printStackTrace();
+ DroolsEclipsePlugin.log( t );
+ }
+ return null;
+ }
- if (isComparable(type)) {
- list.add(new RuleCompletionProposal(prefix.length(), "<", "< ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "<=",
- "<= ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ">", "> ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ">=",
- ">= ", DROOLS_ICON));
- }
- if (type.equals("java.lang.String")) {
- list.add(new RuleCompletionProposal(prefix.length(), "matches",
- "matches \"\"", 9, DROOLS_ICON));
- }
- if (isSubtypeOf(type, "java.util.Collection")) {
- list.add(new RuleCompletionProposal(prefix.length(),
- "contains", "contains ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "excludes", "excludes ", DROOLS_ICON));
- }
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT:
- // determine type
- className = (String) location
- .getProperty(Location.LOCATION_PROPERTY_CLASS_NAME);
- property = (String) location
- .getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME);
- String operator = (String) location
- .getProperty(Location.LOCATION_PROPERTY_OPERATOR);
- type = getPropertyClass(className, property);
+ protected void addRHSCompletionProposals(List list,
+ String prefix,
+ String backText,
+ String conditions,
+ String consequence) {
+ // only add functions and keywords if at the beginning of a
+ // new statement
+ String consequenceWithoutPrefix = consequence.substring( 0,
+ consequence.length() - prefix.length() );
+ if ( context == null ) {
+ context = new CompletionContext( backText );
+ }
- if ("in".equals(operator)) {
- list.add(new RuleCompletionProposal(prefix.length(), "()",
- "( )", 2, DROOLS_ICON));
- break;
- }
+ boolean startOfDialectExpression = isStartOfDialectExpression( consequenceWithoutPrefix );
+ if ( startOfDialectExpression ) {
+ addRHSKeywordCompletionProposals( list,
+ prefix );
+ addRHSFunctionCompletionProposals( list,
+ prefix );
+ }
- if ("contains".equals(operator) || "excludes".equals(operator)) {
- type = "java.lang.Object";
- }
+ if ( context.isJavaDialect() ) {
+ System.out.println( "MVEL: Adding Java Dialect completions" );
+ addRHSJavaCompletionProposals( list,
+ prefix,
+ backText,
+ consequence );
+ } else {
+ System.out.println( "MVEL: Adding MVEL Dialect completions" );
+ addRHSMvelCompletionProposals( list,
+ prefix,
+ backText,
+ consequence,
+ startOfDialectExpression );
+ }
+ }
- if ("memberOf".equals(operator)) {
- type = "java.util.Collection";
- }
+ protected void addLHSCompletionProposals(List list,
+ Location location,
+ String prefix,
+ String backText) {
+ switch ( location.getType() ) {
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION :
+ // if we are at the beginning of a new condition
+ // add drools keywords
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "and",
+ "and ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "or",
+ "or ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "from",
+ "from ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "forall",
+ "forall( )",
+ 8,
+ DROOLS_ICON ) );
- boolean isObject = false;
- if ("java.lang.Object".equals(type)) {
- isObject = true;
- }
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ "eval",
+ "eval( )",
+ 6 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "then",
+ "then" + System.getProperty( "line.separator" ) + "\t" );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ // we do not break but also add all elements that are needed for
+ // and/or
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR :
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "not",
+ "not ",
+ DROOLS_ICON ) );
+ // we do not break but also add all elements that are needed for
+ // not
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT :
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "exists",
+ "exists ",
+ DROOLS_ICON ) );
+ // we do not break but also add all elements that are needed for
+ // exists
+ case Location.LOCATION_LHS_FROM_ACCUMULATE :
+ case Location.LOCATION_LHS_FROM_COLLECT :
+ case Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS :
+ // and add imported classes
+ Iterator iterator = getImports().iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next();
+ int index = name.lastIndexOf( "." );
+ if ( index != -1 ) {
+ String className = name.substring( index + 1 );
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ className,
+ className + "( )",
+ className.length() + 2 );
+ p.setPriority( -1 );
+ p.setImage( CLASS_ICON );
+ list.add( p );
+ }
+ }
+ iterator = getClassesInPackage().iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next();
+ int index = name.lastIndexOf( "." );
+ if ( index != -1 ) {
+ String className = name.substring( index + 1 );
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ className,
+ className + "( )",
+ className.length() + 2 );
+ p.setPriority( -1 );
+ p.setImage( CLASS_ICON );
+ list.add( p );
+ }
+ }
+ iterator = getTemplates().iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next();
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ name,
+ name + "( )",
+ name.length() + 2 );
+ p.setPriority( -1 );
+ p.setImage( CLASS_ICON );
+ list.add( p );
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_START :
+ String className = (String) location.getProperty( Location.LOCATION_PROPERTY_CLASS_NAME );
+ String propertyName = (String) location.getProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME );
+ if ( className != null ) {
+ boolean isTemplate = addFactTemplatePropertyProposals( prefix,
+ className,
+ list );
+ if ( !isTemplate ) {
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ String currentClass = className;
+ if ( propertyName != null ) {
+ String[] nestedProperties = propertyName.split( "\\." );
+ int nbSuperProperties = nestedProperties.length - 1;
+ if ( propertyName.endsWith( "." ) ) {
+ nbSuperProperties++;
+ }
+ for ( int i = 0; i < nbSuperProperties; i++ ) {
+ String simplePropertyName = nestedProperties[i];
+ currentClass = getSimplePropertyClass( currentClass,
+ simplePropertyName );
+ currentClass = convertToNonPrimitiveClass( currentClass );
+ }
+ }
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ "this" );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ Class clazz = resolver.resolveType( currentClass );
+ if ( clazz != null ) {
+ if ( Map.class.isAssignableFrom( clazz ) ) {
+ p = new RuleCompletionProposal( prefix.length(),
+ "this['']",
+ "this['']",
+ 6 );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ }
+ ClassFieldInspector inspector = new ClassFieldInspector( clazz );
+ Map types = inspector.getFieldTypes();
+ Iterator iterator2 = inspector.getFieldNames().keySet().iterator();
+ while ( iterator2.hasNext() ) {
+ String name = (String) iterator2.next();
+ p = new RuleCompletionProposal( prefix.length(),
+ name,
+ name + " " );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ Class type = (Class) types.get( name );
+ if ( type != null && Map.class.isAssignableFrom( type ) ) {
+ name += "['']";
+ p = new RuleCompletionProposal( prefix.length(),
+ name,
+ name,
+ name.length() - 2 );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ }
+ }
+ }
+ } catch ( IOException exc ) {
+ // Do nothing
+ } catch ( ClassNotFoundException exc ) {
+ // Do nothing
+ }
+ }
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR :
+ className = (String) location.getProperty( Location.LOCATION_PROPERTY_CLASS_NAME );
+ String property = (String) location.getProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME );
+ String type = getPropertyClass( className,
+ property );
- list.add(new RuleCompletionProposal(prefix.length(), "null",
- "null ", DROOLS_ICON));
- if ("boolean".equals(type)) {
- list.add(new RuleCompletionProposal(prefix.length(), "true",
- "true ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "false",
- "false ", DROOLS_ICON));
- }
- if (isObject || "java.lang.String".equals(type)) {
- list.add(new RuleCompletionProposal(prefix.length(), "\"\"",
- "\"\"", 1, DROOLS_ICON));
- }
- if (isObject || "java.util.Date".equals(type)) {
- list.add(new RuleCompletionProposal(prefix.length(),
- "\"dd-mmm-yyyy\"", "\"dd-mmm-yyyy\"", 1, DROOLS_ICON));
- }
- list.add(new RuleCompletionProposal(prefix.length(), "()", "( )",
- 2, DROOLS_ICON));
- // add parameters with possibly matching type
- DrlParser parser = new DrlParser();
- try {
- 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.entrySet().iterator();
- while (iterator2.hasNext()) {
- Map.Entry entry = (Map.Entry) iterator2.next();
- String paramName = (String) entry.getKey();
- String paramType = (String) entry.getValue();
- if (isSubtypeOf(paramType, type)) {
- RuleCompletionProposal proposal = new RuleCompletionProposal(
- prefix.length(), paramName);
- proposal.setPriority(-1);
- proposal.setImage(VARIABLE_ICON);
- list.add(proposal);
- }
- }
- }
- } catch (DroolsParserException exc) {
- // do nothing
- }
- // add globals with possibly matching type
- List globals = getGlobals();
- if (globals != null) {
- for (iterator = globals.iterator(); iterator.hasNext();) {
- GlobalDescr global = (GlobalDescr) iterator.next();
- if (isSubtypeOf(global.getType(), type)) {
- RuleCompletionProposal proposal = new RuleCompletionProposal(
- prefix.length(), global.getIdentifier());
- proposal.setPriority(-1);
- proposal.setImage(VARIABLE_ICON);
- list.add(proposal);
- }
- }
- }
- break;
- case Location.LOCATION_LHS_INSIDE_EVAL:
- String content = (String) location
- .getProperty(Location.LOCATION_EVAL_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- case Location.LOCATION_LHS_INSIDE_CONDITION_END:
- list.add(new RuleCompletionProposal(prefix.length(), "&&", "&& ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "||", "|| ",
- DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), ",", ", ",
- DROOLS_ICON));
- break;
- case Location.LOCATION_LHS_FROM:
- String fromText = (String) location
- .getProperty(Location.LOCATION_FROM_CONTENT);
- int index = fromText.indexOf('.');
- if (index == -1) {
- // add accumulate and collect keyword
- list
- .add(new RuleCompletionProposal(
- prefix.length(),
- "accumulate",
- "accumulate ( , init ( ), action ( ), result ( ) )",
- 13, DROOLS_ICON));
- PackageBuilderConfiguration config = new PackageBuilderConfiguration(
- ProjectClassLoader.getProjectClassLoader(getEditor()),
- null);
- Map accumulateFunctions = config.getAccumulateFunctionsMap();
- for (Iterator iterator2 = accumulateFunctions.keySet()
- .iterator(); iterator2.hasNext();) {
- String accumulateFunction = (String) iterator2.next();
- list.add(new RuleCompletionProposal(prefix.length(),
- "accumulate " + accumulateFunction,
- "accumulate ( , " + accumulateFunction + "( ) )",
- 13, DROOLS_ICON));
- }
- list.add(new RuleCompletionProposal(prefix.length(), "collect",
- "collect ( )", 10, DROOLS_ICON));
- // add all functions
- if ("".equals(fromText)) {
- List functions = getFunctions();
- iterator = functions.iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next() + "()";
- prop = new RuleCompletionProposal(prefix.length(),
- name, name, name.length() - 1);
- prop.setPriority(-1);
- prop.setImage(METHOD_ICON);
- list.add(prop);
- }
- }
- list.addAll(getJavaCompletionProposals(fromText, prefix,
- getRuleParameters(backText)));
- }
- break;
- case Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE:
- content = (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- case Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE:
- content = (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
- content += (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- case Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE:
- content = (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT);
- content += (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT);
- content += (String) location
- .getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT);
- list.addAll(getJavaCompletionProposals(content, prefix,
- getRuleParameters(backText)));
- break;
- }
- }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "==",
+ "== ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "!=",
+ "!= ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ":",
+ ": ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "->",
+ "-> ( )",
+ 5,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "memberOf",
+ "memberOf ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "not memberOf",
+ "not memberOf ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "in",
+ "in ( )",
+ 5,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "not in",
+ "not in ( )",
+ 9,
+ DROOLS_ICON ) );
- private String getPropertyClass(String className, String propertyName) {
- if (className != null && propertyName != null) {
- FactTemplateDescr template = getTemplate(className);
- if (template != null) {
- Iterator iterator = template.getFields().iterator();
- while (iterator.hasNext()) {
- FieldTemplateDescr field = (FieldTemplateDescr) iterator
- .next();
- if (propertyName.equals(field.getName())) {
- String type = field.getClassType();
- if (isPrimitiveType(type)) {
- return type;
- }
- ClassTypeResolver resolver = new ClassTypeResolver(
- getImports(), ProjectClassLoader
- .getProjectClassLoader(getEditor()));
- try {
- Class clazz = resolver.resolveType(type);
- if (clazz != null) {
- return clazz.getName();
- }
- } catch (ClassNotFoundException exc) {
- exc.printStackTrace();
- // Do nothing
- }
- }
- }
- // if not found, return null
- } else {
- String[] nestedProperties = propertyName.split("\\.");
- String currentClass = className;
- for (int i = 0; i < nestedProperties.length; i++) {
- String simplePropertyName = nestedProperties[i];
- currentClass = getSimplePropertyClass(currentClass,
- simplePropertyName);
- }
- return currentClass;
- }
- }
- return null;
- }
+ if ( isComparable( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "<",
+ "< ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "<=",
+ "<= ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ">",
+ "> ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ">=",
+ ">= ",
+ DROOLS_ICON ) );
+ }
+ if ( type.equals( "java.lang.String" ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "matches",
+ "matches \"\"",
+ 9,
+ DROOLS_ICON ) );
+ }
+ if ( isSubtypeOf( type,
+ "java.util.Collection" ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "contains",
+ "contains ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "excludes",
+ "excludes ",
+ DROOLS_ICON ) );
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT :
+ // determine type
+ className = (String) location.getProperty( Location.LOCATION_PROPERTY_CLASS_NAME );
+ property = (String) location.getProperty( Location.LOCATION_PROPERTY_PROPERTY_NAME );
+ String operator = (String) location.getProperty( Location.LOCATION_PROPERTY_OPERATOR );
+ type = getPropertyClass( className,
+ property );
- private String getSimplePropertyClass(String className, String propertyName) {
- if ("this".equals(propertyName)) {
- return className;
- }
- if (propertyName.endsWith("]")) {
- // TODO can we take advantage of generics here?
- return "java.lang.Object";
- }
- ClassTypeResolver resolver = new ClassTypeResolver(getImports(),
- ProjectClassLoader.getProjectClassLoader(getEditor()));
- try {
- Class clazz = resolver.resolveType(className);
- if (clazz != null) {
- Class clazzz = (Class) new ClassFieldInspector(clazz)
- .getFieldTypes().get(propertyName);
- if (clazzz != null) {
- return clazzz.getName();
- }
- }
- } catch (IOException exc) {
- // Do nothing
- } catch (ClassNotFoundException exc) {
- // Do nothing
- }
- return "java.lang.Object";
- }
+ if ( "in".equals( operator ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "()",
+ "( )",
+ 2,
+ DROOLS_ICON ) );
+ break;
+ }
- private Map getRuleParameters(String backText) {
- Map result = new HashMap();
- // add globals
- List globals = getGlobals();
- if (globals != null) {
- for (Iterator iterator = globals.iterator(); iterator.hasNext();) {
- GlobalDescr global = (GlobalDescr) iterator.next();
- result.put(global.getIdentifier(), global.getType());
- }
- }
- // add parameters defined in conditions
- try {
- DrlParser parser = new DrlParser();
- PackageDescr descr = parser.parse(backText);
- List rules = descr.getRules();
- if (rules != null && rules.size() == 1) {
- getRuleParameters(result, ((RuleDescr) rules.get(0)).getLhs()
- .getDescrs());
- }
- } catch (DroolsParserException exc) {
- // do nothing
- }
- return result;
- }
+ if ( "contains".equals( operator ) || "excludes".equals( operator ) ) {
+ type = "java.lang.Object";
+ }
- private boolean isComparable(String type) {
- if (type == null) {
- return false;
- }
- if (isPrimitiveNumericType(type)) {
- return true;
- }
- if (isObjectNumericType(type)) {
- return true;
- }
- if (isSubtypeOf(type, "java.lang.Comparable")) {
- return true;
- }
- return false;
- }
+ if ( "memberOf".equals( operator ) ) {
+ type = "java.util.Collection";
+ }
- private boolean isPrimitiveType(String type) {
- return isPrimitiveNumericType(type) || type.equals("boolean");
- }
+ boolean isObject = false;
+ if ( "java.lang.Object".equals( type ) ) {
+ isObject = true;
+ }
- private boolean isPrimitiveNumericType(String type) {
- return type.equals("byte") || type.equals("short")
- || type.equals("int") || type.equals("long")
- || type.equals("float") || type.equals("double")
- || type.equals("char");
- }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "null",
+ "null ",
+ DROOLS_ICON ) );
+ if ( "boolean".equals( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "true",
+ "true ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "false",
+ "false ",
+ DROOLS_ICON ) );
+ }
+ if ( isObject || "java.lang.String".equals( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "\"\"",
+ "\"\"",
+ 1,
+ DROOLS_ICON ) );
+ }
+ if ( isObject || "java.util.Date".equals( type ) ) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "\"dd-mmm-yyyy\"",
+ "\"dd-mmm-yyyy\"",
+ 1,
+ DROOLS_ICON ) );
+ }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "()",
+ "( )",
+ 2,
+ DROOLS_ICON ) );
+ // add parameters with possibly matching type
+ if ( context == null ) {
+ context = new CompletionContext( backText );
+ }
- private boolean isObjectNumericType(String type) {
- return type.equals("java.lang.Byte") || type.equals("java.lang.Short")
- || type.equals("java.lang.Integer")
- || type.equals("java.lang.Long")
- || type.equals("java.lang.Float")
- || type.equals("java.lang.Double")
- || type.equals("java.lang.Char");
- }
+ if ( context.getRule() != null ) {
+ Map result = new HashMap();
+ addRuleParameters( result,
+ context.getRule().getLhs().getDescrs() );
+ Iterator iterator2 = result.entrySet().iterator();
+ while ( iterator2.hasNext() ) {
+ Map.Entry entry = (Map.Entry) iterator2.next();
+ String paramName = (String) entry.getKey();
+ String paramType = (String) entry.getValue();
+ if ( isSubtypeOf( paramType,
+ type ) ) {
+ RuleCompletionProposal proposal = new RuleCompletionProposal( prefix.length(),
+ paramName );
+ proposal.setPriority( -1 );
+ proposal.setImage( VARIABLE_ICON );
+ list.add( proposal );
+ }
+ }
+ } // add globals with possibly matching type
+ List globals = getGlobals();
+ if ( globals != null ) {
+ for ( iterator = globals.iterator(); iterator.hasNext(); ) {
+ GlobalDescr global = (GlobalDescr) iterator.next();
+ if ( isSubtypeOf( global.getType(),
+ type ) ) {
+ RuleCompletionProposal proposal = new RuleCompletionProposal( prefix.length(),
+ global.getIdentifier() );
+ proposal.setPriority( -1 );
+ proposal.setImage( VARIABLE_ICON );
+ list.add( proposal );
+ }
+ }
+ }
+ break;
+ case Location.LOCATION_LHS_INSIDE_EVAL :
+ String content = (String) location.getProperty( Location.LOCATION_EVAL_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ case Location.LOCATION_LHS_INSIDE_CONDITION_END :
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "&&",
+ "&& ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "||",
+ "|| ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ ",",
+ ", ",
+ DROOLS_ICON ) );
+ break;
+ case Location.LOCATION_LHS_FROM :
+ String fromText = (String) location.getProperty( Location.LOCATION_FROM_CONTENT );
+ int index = fromText.indexOf( '.' );
+ if ( index == -1 ) {
+ // add accumulate and collect keyword
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "accumulate",
+ "accumulate ( , init ( ), action ( ), result ( ) )",
+ 13,
+ DROOLS_ICON ) );
+ PackageBuilderConfiguration config = new PackageBuilderConfiguration( ProjectClassLoader.getProjectClassLoader( getEditor() ),
+ null );
+ Map accumulateFunctions = config.getAccumulateFunctionsMap();
+ for ( Iterator iterator2 = accumulateFunctions.keySet().iterator(); iterator2.hasNext(); ) {
+ String accumulateFunction = (String) iterator2.next();
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "accumulate " + accumulateFunction,
+ "accumulate ( , " + accumulateFunction + "( ) )",
+ 13,
+ DROOLS_ICON ) );
+ }
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "collect",
+ "collect ( )",
+ 10,
+ DROOLS_ICON ) );
+ // add all functions
+ if ( "".equals( fromText ) ) {
+ List functions = getFunctions();
+ iterator = functions.iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next() + "()";
+ prop = new RuleCompletionProposal( prefix.length(),
+ name,
+ name,
+ name.length() - 1 );
+ prop.setPriority( -1 );
+ prop.setImage( METHOD_ICON );
+ list.add( prop );
+ }
+ }
+ list.addAll( getJavaCompletionProposals( fromText,
+ prefix,
+ getRuleParameters( backText ) ) );
+ }
+ break;
+ case Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE :
+ content = (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ case Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE :
+ content = (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT );
+ content += (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ case Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE :
+ content = (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT );
+ content += (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT );
+ content += (String) location.getProperty( Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT );
+ list.addAll( getJavaCompletionProposals( content,
+ prefix,
+ getRuleParameters( backText ) ) );
+ break;
+ }
+ }
- /**
- * Returns true if the first class is the same or a subtype of the second
- * class.
- *
- * @param class1
- * @param class2
- * @return
- */
- private boolean isSubtypeOf(String class1, String class2) {
- if (class1 == null || class2 == null) {
- return false;
- }
- class1 = convertToNonPrimitiveClass(class1);
- class2 = convertToNonPrimitiveClass(class2);
- // TODO add code to take primitive types into account
- ClassTypeResolver resolver = new ClassTypeResolver(getImports(),
- ProjectClassLoader.getProjectClassLoader(getEditor()));
- try {
- Class clazz1 = resolver.resolveType(class1);
- Class clazz2 = resolver.resolveType(class2);
- if (clazz1 == null || clazz2 == null) {
- return false;
- }
- return clazz2.isAssignableFrom(clazz1);
- } catch (ClassNotFoundException exc) {
- return false;
- }
- }
+ private String getPropertyClass(String className,
+ String propertyName) {
+ if ( className != null && propertyName != null ) {
+ FactTemplateDescr template = getTemplate( className );
+ if ( template != null ) {
+ Iterator iterator = template.getFields().iterator();
+ while ( iterator.hasNext() ) {
+ FieldTemplateDescr field = (FieldTemplateDescr) iterator.next();
+ if ( propertyName.equals( field.getName() ) ) {
+ String type = field.getClassType();
+ if ( isPrimitiveType( type ) ) {
+ return type;
+ }
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ Class clazz = resolver.resolveType( type );
+ if ( clazz != null ) {
+ return clazz.getName();
+ }
+ } catch ( ClassNotFoundException exc ) {
+ exc.printStackTrace();
+ // Do nothing
+ }
+ }
+ }
+ // if not found, return null
+ } else {
+ String[] nestedProperties = propertyName.split( "\\." );
+ String currentClass = className;
+ for ( int i = 0; i < nestedProperties.length; i++ ) {
+ String simplePropertyName = nestedProperties[i];
+ currentClass = getSimplePropertyClass( currentClass,
+ simplePropertyName );
+ }
+ return currentClass;
+ }
+ }
+ return null;
+ }
- private String convertToNonPrimitiveClass(String clazz) {
- if (!isPrimitiveType(clazz)) {
- return clazz;
- }
- if ("byte".equals(clazz)) {
- return "java.lang.Byte";
- } else if ("short".equals(clazz)) {
- return "java.lang.Short";
- } else if ("int".equals(clazz)) {
- return "java.lang.Integer";
- } else if ("long".equals(clazz)) {
- return "java.lang.Long";
- } else if ("float".equals(clazz)) {
- return "java.lang.Float";
- } else if ("double".equals(clazz)) {
- return "java.lang.Double";
- } else if ("char".equals(clazz)) {
- return "java.lang.Char";
- } else if ("boolean".equals(clazz)) {
- return "java.lang.Boolean";
- }
- // should never occur
- return null;
- }
+ private String getSimplePropertyClass(String className,
+ String propertyName) {
+ if ( "this".equals( propertyName ) ) {
+ return className;
+ }
+ if ( propertyName.endsWith( "]" ) ) {
+ // TODO can we take advantage of generics here?
+ return "java.lang.Object";
+ }
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ Class clazz = resolver.resolveType( className );
+ if ( clazz != null ) {
+ Class clazzz = (Class) new ClassFieldInspector( clazz ).getFieldTypes().get( propertyName );
+ if ( clazzz != null ) {
+ return clazzz.getName();
+ }
+ }
+ } catch ( IOException exc ) {
+ // Do nothing
+ } catch ( ClassNotFoundException exc ) {
+ // Do nothing
+ }
+ return "java.lang.Object";
+ }
- private void addRHSFunctionCompletionProposals(List list, String prefix) {
- Iterator iterator;
- RuleCompletionProposal prop;
- List functions = getFunctions();
- iterator = functions.iterator();
- while (iterator.hasNext()) {
- String name = (String) iterator.next() + "()";
- prop = new RuleCompletionProposal(prefix.length(), name,
- name + ";", name.length() - 1);
- prop.setPriority(-1);
- prop.setImage(METHOD_ICON);
- list.add(prop);
- }
- }
+ private Map getRuleParameters(String backText) {
+ Map result = new HashMap();
+ // add globals
+ List globals = getGlobals();
+ if ( globals != null ) {
+ for ( Iterator iterator = globals.iterator(); iterator.hasNext(); ) {
+ GlobalDescr global = (GlobalDescr) iterator.next();
+ result.put( global.getIdentifier(),
+ global.getType() );
+ }
+ }
- private void addRHSKeywordCompletionProposals(List list, String prefix) {
- RuleCompletionProposal prop = new RuleCompletionProposal(prefix
- .length(), "update", "update();", 7);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "retract",
- "retract();", 8);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "insert",
- "insert();", 7);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- prop = new RuleCompletionProposal(prefix.length(), "insertLogical",
- "insertLogical();", 14);
- prop.setImage(DROOLS_ICON);
- list.add(prop);
- }
+ if ( context == null ) {
+ context = new CompletionContext( backText );
+ }
+ if ( context.getRule() == null ) {
+ return result;
+ }
- private void addRHSJavaCompletionProposals(List list, String prefix,
- String backText, String conditions, String consequence) {
- list.addAll(getJavaCompletionProposals(consequence, prefix,
- getRuleParameters(backText)));
- }
+ // add parameters defined in conditions
+ addRuleParameters( result,
+ context.getRule().getLhs().getDescrs() );
+ return result;
+ }
- private void getRuleParameters(Map result, List descrs) {
- if (descrs == null) {
- return;
- }
- Iterator iterator = descrs.iterator();
- while (iterator.hasNext()) {
- BaseDescr descr = (BaseDescr) iterator.next();
- getRuleParameters(result, descr);
- }
- }
+ private boolean isComparable(String type) {
+ if ( type == null ) {
+ return false;
+ }
+ if ( isPrimitiveNumericType( type ) ) {
+ return true;
+ }
+ if ( isObjectNumericType( type ) ) {
+ return true;
+ }
+ if ( isSubtypeOf( type,
+ "java.lang.Comparable" ) ) {
+ return true;
+ }
+ return false;
+ }
- private void getRuleParameters(Map result, BaseDescr descr) {
- if (descr == null) {
- return;
- }
- if (descr instanceof PatternDescr) {
- String name = ((PatternDescr) descr).getIdentifier();
- if (name != null) {
- result.put(name, ((PatternDescr) descr).getObjectType());
- }
- getRuleSubParameters(result, ((PatternDescr) descr).getDescrs(),
- ((PatternDescr) descr).getObjectType());
- } else if (descr instanceof AndDescr) {
- getRuleParameters(result, ((AndDescr) descr).getDescrs());
- } else if (descr instanceof OrDescr) {
- getRuleParameters(result, ((OrDescr) descr).getDescrs());
- } else if (descr instanceof ExistsDescr) {
- getRuleParameters(result, ((ExistsDescr) descr).getDescrs());
- } else if (descr instanceof NotDescr) {
- getRuleParameters(result, ((NotDescr) descr).getDescrs());
- }
- }
+ private boolean isPrimitiveType(String type) {
+ return isPrimitiveNumericType( type ) || type.equals( "boolean" );
+ }
- private void getRuleSubParameters(Map result, List descrs, String clazz) {
- if (descrs == null) {
- return;
- }
- Iterator iterator = descrs.iterator();
- while (iterator.hasNext()) {
- BaseDescr descr = (BaseDescr) iterator.next();
- if (descr instanceof FieldBindingDescr) {
- FieldBindingDescr fieldDescr = (FieldBindingDescr) descr;
- String name = fieldDescr.getIdentifier();
- String field = fieldDescr.getFieldName();
- String type = getPropertyClass(clazz, field);
- if (name != null) {
- result.put(name, type);
- }
- }
- }
- }
+ private boolean isPrimitiveNumericType(String type) {
+ return type.equals( "byte" ) || type.equals( "short" ) || type.equals( "int" ) || type.equals( "long" ) || type.equals( "float" ) || type.equals( "double" ) || type.equals( "char" );
+ }
- private void addRuleHeaderProposals(List list, String prefix,
- String backText) {
- list.add(new RuleCompletionProposal(prefix.length(), "salience",
- "salience ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "no-loop",
- "no-loop ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "agenda-group",
- "agenda-group ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "duration",
- "duration ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "auto-focus",
- "auto-focus ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "when", "when"
- + System.getProperty("line.separator") + "\t ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "activation-group", "activation-group ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "date-effective",
- "date-effective \"dd-MMM-yyyy\"", 16, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "date-expires",
- "date-expires \"dd-MMM-yyyy\"", 14, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "enabled",
- "enabled false", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "ruleflow-group",
- "ruleflow-group \"\"", 16, DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(), "lock-on-active",
- "lock-on-active ", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "dialect \"java\"", "dialect \"java\"", DROOLS_ICON));
- list.add(new RuleCompletionProposal(prefix.length(),
- "dialect \"mvel\"", "dialect \"mvel\"", DROOLS_ICON));
- }
+ private boolean isObjectNumericType(String type) {
+ return type.equals( "java.lang.Byte" ) || type.equals( "java.lang.Short" ) || type.equals( "java.lang.Integer" ) || type.equals( "java.lang.Long" ) || type.equals( "java.lang.Float" ) || type.equals( "java.lang.Double" )
+ || type.equals( "java.lang.Char" );
+ }
- private boolean addFactTemplatePropertyProposals(String prefix,
- String templateName, List list) {
- FactTemplateDescr descr = getTemplate(templateName);
- if (descr == null) {
- return false;
- }
- Iterator iterator = descr.getFields().iterator();
- while (iterator.hasNext()) {
- FieldTemplateDescr field = (FieldTemplateDescr) iterator.next();
- String fieldName = field.getName();
- RuleCompletionProposal p = new RuleCompletionProposal(prefix
- .length(), fieldName, fieldName + " ");
- p.setImage(METHOD_ICON);
- list.add(p);
- }
- return true;
- }
+ /**
+ * Returns true if the first class is the same or a subtype of the second
+ * class.
+ *
+ * @param class1
+ * @param class2
+ * @return
+ */
+ private boolean isSubtypeOf(String class1,
+ String class2) {
+ if ( class1 == null || class2 == null ) {
+ return false;
+ }
+ class1 = convertToNonPrimitiveClass( class1 );
+ class2 = convertToNonPrimitiveClass( class2 );
+ // TODO add code to take primitive types into account
+ ClassTypeResolver resolver = new ClassTypeResolver( getImports(),
+ ProjectClassLoader.getProjectClassLoader( getEditor() ) );
+ try {
+ Class clazz1 = resolver.resolveType( class1 );
+ Class clazz2 = resolver.resolveType( class2 );
+ if ( clazz1 == null || clazz2 == null ) {
+ return false;
+ }
+ return clazz2.isAssignableFrom( clazz1 );
+ } catch ( ClassNotFoundException exc ) {
+ return false;
+ }
+ }
+ private String convertToNonPrimitiveClass(String clazz) {
+ if ( !isPrimitiveType( clazz ) ) {
+ return clazz;
+ }
+ if ( "byte".equals( clazz ) ) {
+ return "java.lang.Byte";
+ } else if ( "short".equals( clazz ) ) {
+ return "java.lang.Short";
+ } else if ( "int".equals( clazz ) ) {
+ return "java.lang.Integer";
+ } else if ( "long".equals( clazz ) ) {
+ return "java.lang.Long";
+ } else if ( "float".equals( clazz ) ) {
+ return "java.lang.Float";
+ } else if ( "double".equals( clazz ) ) {
+ return "java.lang.Double";
+ } else if ( "char".equals( clazz ) ) {
+ return "java.lang.Char";
+ } else if ( "boolean".equals( clazz ) ) {
+ return "java.lang.Boolean";
+ }
+ // should never occur
+ return null;
+ }
+
+ private void addRHSFunctionCompletionProposals(List list,
+ String prefix) {
+ Iterator iterator;
+ RuleCompletionProposal prop;
+ List functions = getFunctions();
+ iterator = functions.iterator();
+ while ( iterator.hasNext() ) {
+ String name = (String) iterator.next() + "()";
+ prop = new RuleCompletionProposal( prefix.length(),
+ name,
+ name + ";",
+ name.length() - 1 );
+ prop.setPriority( -1 );
+ prop.setImage( METHOD_ICON );
+ list.add( prop );
+ }
+ }
+
+ private void addRHSKeywordCompletionProposals(List list,
+ String prefix) {
+ RuleCompletionProposal prop = new RuleCompletionProposal( prefix.length(),
+ "update",
+ "update();",
+ 7 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "retract",
+ "retract();",
+ 8 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "insert",
+ "insert();",
+ 7 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ prop = new RuleCompletionProposal( prefix.length(),
+ "insertLogical",
+ "insertLogical();",
+ 14 );
+ prop.setImage( DROOLS_ICON );
+ list.add( prop );
+ }
+
+ private void addRHSJavaCompletionProposals(List list,
+ String prefix,
+ String backText,
+ String consequence) {
+ list.addAll( getJavaCompletionProposals( consequence,
+ prefix,
+ getRuleParameters( backText ) ) );
+ }
+
+ private void addRHSMvelCompletionProposals(List list,
+ String prefix,
+ String backText,
+ String consequence,
+ boolean expressionStart) {
+
+ List mvelCompletionProposals = getMvelCompletionProposals( consequence,
+ prefix,
+ getRuleParameters( backText ),
+ backText,
+ expressionStart );
+ list.addAll( mvelCompletionProposals );
+ }
+
+ private List getMvelCompletionProposals(final String consequence,
+ final String prefix,
+ Map params,
+ String backText,
+ boolean startOfExpression) {
+
+ final List proposals = new ArrayList();
+
+ if ( !(getEditor() instanceof DRLRuleEditor) ) {
+ return proposals;
+ }
+
+ String compilableConsequence = CompletionUtil.getCompilableText( consequence );
+
+ //attempt to compile and analyze
+ try {
+ DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( (DRLRuleEditor) getEditor(),
+ true,
+ true );
+
+ ParserContext compilationContext = createMvelAnalysisContext( params,
+ drlInfo,
+ compilableConsequence );
+
+ if ( startOfExpression ) {
+ List jdtProps = getJavaMvelCompletionProposals( "",
+ prefix,
+ params );
+ proposals.addAll( jdtProps );
+ addMvelVariables( proposals,
+ compilationContext );
+
+ addMvelInputs( proposals,
+ compilationContext );
+
+ } else {
+ //we are completing the methods for an existing type or variable
+ //find the last type in the expression to complete against
+ String[] lines = compilableConsequence.split( ";" );
+ String lastLine = lines[lines.length - 1];
+ Class lastType = new PropertyVerifier( lastLine,
+ compilationContext ).analyze();
+
+ String type = lastType.getPackage().getName() + "." + lastType.getName();
+ String javaText = "\n"+type + " o = new " + type + "(); o.";
+ List jdtProps = getJavaMvelCompletionProposals( javaText,
+ prefix,
+ params );
+ proposals.addAll( jdtProps );
+ }
+
+ } catch ( Throwable e ) {
+ // do nothing
+ e.printStackTrace();
+ }
+
+ return proposals;
+ }
+
+ private ParserContext createMvelAnalysisContext(Map params,
+ DRLInfo drlInfo,
+ String compilableConsequence) throws DroolsParserException {
+
+ String currentRulename = context.getRule().getName();
+ RuleInfo[] ruleInfos = drlInfo.getRuleInfos();
+ RuleInfo currentRule = null;
+ for ( int i = 0; i < ruleInfos.length; i++ ) {
+ if ( currentRulename.equals( ruleInfos[i].getRuleName() ) ) {
+ currentRule = ruleInfos[i];
+ break;
+ }
+ }
+ MVELDialect dialect = (MVELDialect) currentRule.getDialect();
+
+ ExpressionCompiler compiler = new ExpressionCompiler( compilableConsequence );
+
+ final ParserContext initialContext = new ParserContext();
+ initialContext.setStrictTypeEnforcement( false );
+ Map imports = dialect.getClassImportResolverFactory().getImportedClasses();
+ imports.putAll( dialect.getStaticMethodImportResolverFactory().getImportedMethods() );
+ initialContext.setImports( imports );
+ initialContext.setInterceptors( dialect.getInterceptors() );
+ initialContext.setInputs( params );
+
+ compiler.compile( initialContext );
+
+ ParserContext compilationContext = compiler.getParserContextState();
+ return compilationContext;
+ }
+
+ private void addMvelInputs(final List proposals,
+ ParserContext compilationContext) {
+ Map inputs = compilationContext.getInputs();
+ for ( Iterator iter = inputs.keySet().iterator(); iter.hasNext(); ) {
+ String prop = (String) iter.next();
+ RuleCompletionProposal rcp = new RuleCompletionProposal( prop.length(),
+ prop );
+ rcp.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ proposals.add( rcp );
+
+ System.out.println( " MVEL: added inputs from mvel eval: name:" + prop + " type:" + inputs.get( prop ).getClass() );
+ }
+ }
+
+ private void addMvelVariables(final List proposals,
+ ParserContext compilationContext) {
+ Map variables = compilationContext.getVariables();
+ for ( Iterator iter = variables.keySet().iterator(); iter.hasNext(); ) {
+ String prop = (String) iter.next();
+ RuleCompletionProposal rcp = new RuleCompletionProposal( prop.length(),
+ prop );
+ rcp.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+ proposals.add( rcp );
+
+ System.out.println( " MVEL: added completion: got variable from mvel eval: name:" + prop + " type:" + variables.get( prop ).getClass() );
+ }
+ }
+
+ private void addRuleParameters(Map result,
+ List descrs) {
+ if ( descrs == null ) {
+ return;
+ }
+ Iterator iterator = descrs.iterator();
+ while ( iterator.hasNext() ) {
+ BaseDescr descr = (BaseDescr) iterator.next();
+ addRuleParameters( result,
+ descr );
+ }
+ }
+
+ private void addRuleParameters(Map result,
+ BaseDescr descr) {
+ if ( descr == null ) {
+ return;
+ }
+ if ( descr instanceof PatternDescr ) {
+ String name = ((PatternDescr) descr).getIdentifier();
+ if ( name != null ) {
+ result.put( name,
+ ((PatternDescr) descr).getObjectType() );
+ }
+ addRuleSubParameters( result,
+ ((PatternDescr) descr).getDescrs(),
+ ((PatternDescr) descr).getObjectType() );
+ } else if ( descr instanceof AndDescr ) {
+ addRuleParameters( result,
+ ((AndDescr) descr).getDescrs() );
+ } else if ( descr instanceof OrDescr ) {
+ addRuleParameters( result,
+ ((OrDescr) descr).getDescrs() );
+ } else if ( descr instanceof ExistsDescr ) {
+ addRuleParameters( result,
+ ((ExistsDescr) descr).getDescrs() );
+ } else if ( descr instanceof NotDescr ) {
+ addRuleParameters( result,
+ ((NotDescr) descr).getDescrs() );
+ }
+ }
+
+ private void addRuleSubParameters(Map result,
+ List descrs,
+ String clazz) {
+ if ( descrs == null ) {
+ return;
+ }
+ Iterator iterator = descrs.iterator();
+ while ( iterator.hasNext() ) {
+ BaseDescr descr = (BaseDescr) iterator.next();
+ if ( descr instanceof FieldBindingDescr ) {
+ FieldBindingDescr fieldDescr = (FieldBindingDescr) descr;
+ String name = fieldDescr.getIdentifier();
+ String field = fieldDescr.getFieldName();
+ String type = getPropertyClass( clazz,
+ field );
+ if ( name != null ) {
+ result.put( name,
+ type );
+ }
+ }
+ }
+ }
+
+ private void addRuleHeaderProposals(List list,
+ String prefix,
+ String backText) {
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "salience",
+ "salience ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "no-loop",
+ "no-loop ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "agenda-group",
+ "agenda-group ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "duration",
+ "duration ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "auto-focus",
+ "auto-focus ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "when",
+ "when" + System.getProperty( "line.separator" ) + "\t ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "activation-group",
+ "activation-group ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "date-effective",
+ "date-effective \"dd-MMM-yyyy\"",
+ 16,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "date-expires",
+ "date-expires \"dd-MMM-yyyy\"",
+ 14,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "enabled",
+ "enabled false",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "ruleflow-group",
+ "ruleflow-group \"\"",
+ 16,
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "lock-on-active",
+ "lock-on-active ",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "dialect \"java\"",
+ "dialect \"java\"",
+ DROOLS_ICON ) );
+ list.add( new RuleCompletionProposal( prefix.length(),
+ "dialect \"mvel\"",
+ "dialect \"mvel\"",
+ DROOLS_ICON ) );
+ }
+
+ private boolean addFactTemplatePropertyProposals(String prefix,
+ String templateName,
+ List list) {
+ FactTemplateDescr descr = getTemplate( templateName );
+ if ( descr == null ) {
+ return false;
+ }
+ Iterator iterator = descr.getFields().iterator();
+ while ( iterator.hasNext() ) {
+ FieldTemplateDescr field = (FieldTemplateDescr) iterator.next();
+ String fieldName = field.getName();
+ RuleCompletionProposal p = new RuleCompletionProposal( prefix.length(),
+ fieldName,
+ fieldName + " " );
+ p.setImage( METHOD_ICON );
+ list.add( p );
+ }
+ return true;
+ }
+
}
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -6,41 +6,67 @@
/**
* Holds a completion proposal to be popped up.
- *
+ *
* @author Michael Neale
*
*/
public class RuleCompletionProposal {
-
+
private String content;
private String display;
- private int replacementLength;
- private int cursorPosition;
- private Image image;
- private int priority;
-
+ private int replacementLength;
+ private int cursorPosition;
+ private Image image;
+ private int priority;
+
/** This is used when the stuff that is displayed, is the stuff that is used. */
- public RuleCompletionProposal(int replacementLength, String content) {
- this(replacementLength, content, content);
+ public RuleCompletionProposal(int replacementLength,
+ String content) {
+ this( replacementLength,
+ content,
+ content );
}
/** This is used when a different display value is shown to what is put in when selected. */
- public RuleCompletionProposal(int replacementLength, String display, String content) {
- this(replacementLength, display, content, content.length());
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content) {
+ this( replacementLength,
+ display,
+ content,
+ content.length() );
}
-
+
/** Also allows an icon to be used */
- public RuleCompletionProposal(int replacementLength, String display, String content, Image image) {
- this(replacementLength, display, content, content.length(), image);
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content,
+ Image image) {
+ this( replacementLength,
+ display,
+ content,
+ content.length(),
+ image );
}
- public RuleCompletionProposal(int replacementLength, String display, String content, int cursorPosition) {
- this(replacementLength, display, content, cursorPosition, null);
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content,
+ int cursorPosition) {
+ this( replacementLength,
+ display,
+ content,
+ cursorPosition,
+ null );
}
-
+
/** This is used when a different display value is shown to what is put in when selected. */
- public RuleCompletionProposal(int replacementLength, String display, String content, int cursorPosition, Image image) {
- this.replacementLength = replacementLength;
+ public RuleCompletionProposal(int replacementLength,
+ String display,
+ String content,
+ int cursorPosition,
+ Image image) {
+ this.replacementLength = replacementLength;
this.content = content;
this.display = display;
this.cursorPosition = cursorPosition;
@@ -54,46 +80,71 @@
public String getDisplay() {
return display;
}
-
+
public int getReplacementLength() {
- return replacementLength;
- }
+ return replacementLength;
+ }
- public int getCursorPosition() {
- return cursorPosition;
+ public int getCursorPosition() {
+ return cursorPosition;
}
-
- public Image getImage() {
- return image;
- }
- public void setImage(Image image) {
- this.image = image;
- }
-
- public int getPriority() {
- return priority;
- }
+ public Image getImage() {
+ return image;
+ }
- public void setPriority(int priority) {
- this.priority = priority;
- }
-
+ public void setImage(Image image) {
+ this.image = image;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
+ public void setPriority(int priority) {
+ this.priority = priority;
+ }
+
public String toString() {
return content;
}
-
- public static class RuleCompletionProposalComparator implements Comparator {
- public int compare(Object arg0, Object arg1) {
- RuleCompletionProposal prop0 = (RuleCompletionProposal) arg0;
- RuleCompletionProposal prop1 = (RuleCompletionProposal) arg1;
- if (prop0.getPriority() == prop1.getPriority()) {
- return prop0.getDisplay().compareTo(prop1.getDisplay());
- } else if (prop0.getPriority() > prop1.getPriority()) {
- return -1;
- } else {
- return 1;
- }
- }
+
+ public static class RuleCompletionProposalComparator
+ implements
+ Comparator {
+ public int compare(Object arg0,
+ Object arg1) {
+ RuleCompletionProposal prop0 = (RuleCompletionProposal) arg0;
+ RuleCompletionProposal prop1 = (RuleCompletionProposal) arg1;
+ if ( prop0.getPriority() == prop1.getPriority() ) {
+ return prop0.getDisplay().compareTo( prop1.getDisplay() );
+ } else if ( prop0.getPriority() > prop1.getPriority() ) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
}
-}
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((content == null) ? 0 : content.hashCode());
+ result = PRIME * result + ((display == null) ? 0 : display.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if ( this == obj ) return true;
+ if ( obj == null ) return false;
+ if ( getClass() != obj.getClass() ) return false;
+ final RuleCompletionProposal other = (RuleCompletionProposal) obj;
+ if ( content == null ) {
+ if ( other.content != null ) return false;
+ } else if ( !content.equals( other.content ) ) return false;
+ if ( display == null ) {
+ if ( other.display != null ) return false;
+ } else if ( !display.equals( other.display ) ) return false;
+ return true;
+ }
+}
\ No newline at end of file
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLPartionScanner.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -13,31 +13,31 @@
/**
* Break apart the rule source, very very simply.
- *
+ *
* The job of the partitioner is to identify if the cursor position
* is in a rule block, or not. Comments are also generated as a
* separate partition.
- *
+ * TODO: add support for dialect based partitioning for correct syntaxhighlighting
* @author Michael Neale
*/
public class DRLPartionScanner extends RuleBasedPartitionScanner {
public static final String RULE_PART_CONTENT = "__partition_rule_content";
public static final String RULE_COMMENT = "__partition_multiline_comment";
-
+
public static final String[] LEGAL_CONTENT_TYPES = {
IDocument.DEFAULT_CONTENT_TYPE,
RULE_PART_CONTENT,
RULE_COMMENT
};
-
+
public DRLPartionScanner() {
initialise();
}
-
+
private void initialise() {
List rules = new ArrayList();
-
+
// rules
IToken rulePartition = new Token(RULE_PART_CONTENT);
rules.add(new MultiLineRule("\nrule", "\nend", rulePartition));
@@ -47,7 +47,7 @@
// comments
IToken comment = new Token(RULE_COMMENT);
rules.add( new MultiLineRule("/*", "*/", comment, (char) 0, true));
-
+
setPredicateRules((IPredicateRule[]) rules.toArray(new IPredicateRule[rules.size()]));
}
}
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/scanners/DRLScanner.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -21,43 +21,45 @@
/**
* Basic keyword scanner for syntax highlighting.
- *
+ *
* @author Michael Neale
*/
public class DRLScanner extends RuleBasedScanner {
-
+
private static final Color KEYWORD_COLOR = ColorManager.getInstance().getColor(ColorManager.KEYWORD);
private static final Color COMMENT_COLOR = ColorManager.getInstance().getColor(ColorManager.SINGLE_LINE_COMMENT);
private static final Color STRING_COLOR = ColorManager.getInstance().getColor(ColorManager.STRING);
private static final Color DEFAULT_COLOR = ColorManager.getInstance().getColor(ColorManager.DEFAULT);
-
+
private static final String[] DROOLS_KEYWORDS = Keywords.getInstance().getAllDroolsKeywords();
private static final String[] JAVA_KEYWORDS = Keywords.getInstance().getAllJavaKeywords();
+ private static final String[] MVEL_KEYWORDS = Keywords.getInstance().getAllMvelKeywords();
- private static final String[] TYPES = { "void", "boolean", "char", "byte", "short", "strictfp", "int", "long", "float", "double" };
+ private static final String[] JAVA_TYPES = { "void", "boolean", "char", "byte", "short", "strictfp", "int", "long", "float", "double" };
- private static final String[] CONSTANTS = { "false", "true", "null" };
-
+ private static final String[] JAVA_CONSTANTS = { "false", "true", "null" };
+ private static final String[] MVEL_CONSTANTS = { "false", "true", "null", "nil", "empty", "this" };
+
public DRLScanner() {
-
+
IToken keyword = new Token(new TextAttribute(KEYWORD_COLOR, null, SWT.BOLD));
IToken comment= new Token(new TextAttribute(COMMENT_COLOR));
IToken string = new Token(new TextAttribute(STRING_COLOR));
IToken other = new Token(new TextAttribute(DEFAULT_COLOR));
-
+
List rules = new ArrayList();
rules.add(new EndOfLineRule("//", comment));
rules.add(new EndOfLineRule("#", comment));
-
+
// Add rule for strings and character constants.
- rules.add(new SingleLineRule("\"", "\"", string, '\\'));
- rules.add(new SingleLineRule("'", "'", string, '\\'));
-
- //for unfilled "holes"
+ rules.add(new SingleLineRule("\"", "\"", string, '\\'));
+ rules.add(new SingleLineRule("'", "'", string, '\\'));
+
+ //for unfilled "holes"
//rules.add(new SingleLineRule("{", "}", comment));
-
+
// Add generic whitespace rule.
rules.add(new WhitespaceRule(new WhitespaceDetector()));
@@ -65,18 +67,27 @@
WordRule wordRule= new WordRule(new RuleWordDetector(), other);
for (int i= 0; i < DROOLS_KEYWORDS.length; i++)
wordRule.addWord(DROOLS_KEYWORDS[i], keyword);
+
for (int i= 0; i < JAVA_KEYWORDS.length; i++)
wordRule.addWord(JAVA_KEYWORDS[i], keyword);
- for (int i= 0; i < TYPES.length; i++)
- wordRule.addWord(TYPES[i], keyword);
- for (int i= 0; i < CONSTANTS.length; i++)
- wordRule.addWord(CONSTANTS[i], keyword);
- rules.add(wordRule);
-
+ for (int i= 0; i < JAVA_TYPES.length; i++)
+ wordRule.addWord(JAVA_TYPES[i], keyword);
+ for (int i= 0; i < JAVA_CONSTANTS.length; i++)
+ wordRule.addWord(JAVA_CONSTANTS[i], keyword);
+
+ //FIXME: this a bit brutal. we should identify different highlighting for Java and Mvel
+ for (int i= 0; i < MVEL_KEYWORDS.length; i++)
+ wordRule.addWord(MVEL_KEYWORDS[i], keyword);
+ for (int i= 0; i < MVEL_CONSTANTS.length; i++)
+ wordRule.addWord(MVEL_CONSTANTS[i], keyword);
+
+
+ rules.add(wordRule);
+
IRule[] result= new IRule[rules.size()];
- rules.toArray(result);
-
+ rules.toArray(result);
+
setRules(result);
}
-
+
}
Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/resources/org/drools/eclipse/editors/mvel_keywords.properties 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,20 @@
+# this contains the mvel keywords for syntax highlighting
+if
+else
+foreach
+switch
+var
+while
+do
+for
+return
+instanceof
+is
+contains
+soundslike
+strsim
+convertable_to
+new
+in
+with
+
Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/AbstractCompletionProcessorTest.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,55 @@
+package org.drools.eclipse.editors.completion;
+
+import org.drools.eclipse.editors.scanners.DRLPartionScanner;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.FastPartitioner;
+
+import junit.framework.TestCase;
+
+public class AbstractCompletionProcessorTest extends TestCase {
+
+ public void testReadBackwards() throws BadLocationException {
+ //setup
+ IDocument doc = getDoc();
+ int rhsStartOffset = 150;
+
+ AbstractCompletionProcessor proc = new MockCompletionProcessor();
+ String backText = proc.readBackwards( rhsStartOffset,
+ doc );
+ String rule2 = "\nrule YourRule \n" + //
+ " dialect \"mvel\"\n" + //
+ " when\n" + //
+ " Class ( )\n" + //
+ " then\n";
+
+ assertEquals( rule2,
+ backText );
+ }
+
+ private IDocument getDoc() {
+ String input = "rule MyRule \n" + //
+ " when\n" + //
+ " Class ( )\n" + //
+ " then\n" + //
+ " System.out.println(\"Hey\");\n" + //
+ "end\n" + //
+ "rule YourRule \n" + //
+ " dialect \"mvel\"\n" + //
+ " when\n" + //
+ " Class ( )\n" + //
+ " then\n" + //
+ " " +//
+ "end\n\n" ;
+
+ IDocument doc = new Document( input );
+ IDocumentPartitioner partitioner = new FastPartitioner( new DRLPartionScanner(),
+ DRLPartionScanner.LEGAL_CONTENT_TYPES );
+ partitioner.connect( doc );
+ doc.setDocumentPartitioner( partitioner );
+ return doc;
+ }
+
+}
Copied: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java (from rev 13406, labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java)
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionContextTest.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,1542 @@
+package org.drools.eclipse.editors.completion;
+
+import org.drools.lang.Location;
+
+import junit.framework.TestCase;
+
+/**
+ * Test to check the location determination when doing code completion inside
+ * rule condtions.
+ *
+ * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
+ *
+ */
+public class CompletionContextTest extends TestCase {
+
+ public void testColumnOperatorPattern() {
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(name:property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name:property2 ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name:prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(name:prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property <= ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( name : property == ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("(property==").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property contains ").matches());
+ assertFalse(CompletionContext.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 >= ").matches());
+ }
+
+ public void testColumnArgumentPattern() {
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property >= ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property== ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(name:property== ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\",property2== ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == otherProp").matches());
+ assertTrue(CompletionContext.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property==otherProp").matches());
+ }
+
+ public void testCheckLHSLocationDetermination() {
+ String input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class( condition == true ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " class: Class( condition == true, condition2 == null ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class( condition == true ) \n" +
+ " Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " class: Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " class:Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** Inside of condition: start */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( na";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("na", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name.subProperty['test'].subsu";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("name.subProperty['test'].subsu", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( condition == true, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( condition == true, na";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( condition == true, \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( c: condition, \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name:";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ /** Inside of condition: Operator */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class(property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (name:property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (name:property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1, name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1 == \"value\", name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1 == \"value\",property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1, \n" +
+ " name : property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ /** Inside of condition: argument */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property== ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property <= ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("<=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name:property != ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("!=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name1 : property1, property2 == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class (name:property== ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == otherPropertyN";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == \"someth";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property contains ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("contains", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property excludes ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("excludes", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property matches \"prop";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("matches", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property in ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property in ('1', '2') ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property in ('1', '2'), ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not in ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not in ('1', '2') ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not in ('1', '2'), ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property memberOf ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property memberOf collection ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property memberOf collection, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not memberOf ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not memberOf collection ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property not memberOf collection, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+
+ /** EXISTS */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ( Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists ( name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** NOT */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ // TODO
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not exists name : Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " not Class () \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** AND */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class () and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " name : Class ( name: property ) and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: property ) \n" +
+ " and ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) && name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and not Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and exists Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( name ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and Class ( name == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) and not ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) and exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) and not Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** OR */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class () or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " name : Class ( name: property ) or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name: property ) \n" +
+ " or ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) || name : Cl";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( name ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( ) or Class ( name == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) or not ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " exists Class ( ) or exists ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
+
+ /** EVAL */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( myCla";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("myCla", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMetho";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMetho", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod(", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod().get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod().get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod(\"someStringWith)))\").get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod(\"someStringWith)))\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getMethod(\"someStringWith(((\").get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getMethod(\"someStringWith(((\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( true )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty(name).isTrue() )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty(\"someStringWith(((\").isTrue() )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty((((String) s) )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
+ assertEquals("param.getProperty((((String) s) )", location.getProperty(Location.LOCATION_EVAL_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( param.getProperty((((String) s))))";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " eval( true ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** MULTIPLE RESTRICTIONS */
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property1, property2 > 0 && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property1 < 20, property2 > 0 && ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("<", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < 10 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < 10, ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 || \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( name : property1, property2 > 0 || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property1 < 20, property2 > 0 || ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 && < 10 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 || < 10 ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property == \"test\" || == \"test2\" ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
+
+ /** FROM */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) fr";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_FROM_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from myGlob";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+ assertEquals("myGlob", location.getProperty(Location.LOCATION_FROM_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from myGlobal.get";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+ assertEquals("myGlobal.get", location.getProperty(Location.LOCATION_FROM_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from myGlobal.getList() \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from getDroolsFunction() \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** FROM ACCUMULATE */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $cheese.getPrice(); ), \n" +
+ " result( new Integer( total ) ) \n" +
+ " ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $cheese.getPrice(); ), \n" +
+ " result( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+ assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total =";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
+ assertEquals("int total =", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $ch";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals("total += $ch", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == $likes ), \n" +
+ " init( int total = 0; ), \n" +
+ " action( total += $cheese.getPrice(); ), \n" +
+ " result( new Integer( tot";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
+ assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
+ assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
+ assertEquals("new Integer( tot", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from accumulate( \n" +
+ " $cheese : Cheese( type == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ /** FROM COLLECT */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect(";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( type == $likes )" +
+ " ) \n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( type ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " Class ( property > 0 ) from collect ( \n" +
+ " Cheese( type == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ /** NESTED FROM */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_FROM, location.getType());
+
+//moved to testCheckLHSLocationDetermination_Failing
+// input =
+// "rule MyRule \n" +
+// " when \n" +
+// " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
+// location = new CompletionContext(input).getLocation();
+// assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ /** FORALL */
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( pr";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("pr", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( property ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( property == ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
+ assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
+
+ input =
+ "rule MyRule \n" +
+ " when \n" +
+ " forall ( " +
+ " Class ( property == \"test\")" +
+ " C";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+ }
+
+ public void testCheckLHSLocationDetermination_Failing() {
+ String input =
+ "rule MyRule \n" +
+ " when \n" +
+ " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ }
+
+ public void testCheckRHSLocationDetermination() {
+ String input =
+ "rule MyRule \n" +
+ " when\n" +
+ " Class ( )\n" +
+ " then\n" +
+ " ";
+
+ Location location = new CompletionContext(input).getLocation();
+
+ assertEquals(Location.LOCATION_RHS, location.getType());
+ assertEquals("", location.getProperty(Location.LOCATION_RHS_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when\n" +
+ " Class ( )\n" +
+ " then\n" +
+ " assert(null);\n" +
+ " ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RHS, location.getType());
+ assertEquals("assert(null);\n ", location.getProperty(Location.LOCATION_RHS_CONTENT));
+
+ input =
+ "rule MyRule \n" +
+ " when\n" +
+ " Class ( )\n" +
+ " then\n" +
+ " meth";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RHS, location.getType());
+ assertEquals("meth", location.getProperty(Location.LOCATION_RHS_CONTENT));
+ }
+
+ public void testCheckRuleHeaderLocationDetermination() {
+ String input =
+ "rule MyRule ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ input =
+ "rule MyRule \n" +
+ " salience 12 activation-group \"my";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ // KRISV: still can't make this work... apparently, ANTLR is trying to recover from
+ // the error (unkown token) by deleting the token. I don't know why it continues to
+ // execute actions though, if the EOF is found.
+// input =
+// "rule \"Hello World\" ruleflow-group \"hello\" s";
+// location = new CompletionContext(input).getLocation();
+// assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect1() {
+ String input =
+ "rule MyRule \n" +
+ " dialect \"java\"";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect2() {
+ String input =
+ "rule MyRule \n" +
+ " dialect \"mvel\"";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect3() {
+ String input =
+ "rule MyRule \n" +
+ " dialect ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckRuleHeaderLocationDetermination_dialect4() {
+ String input =
+ "rule MyRule \n" +
+ " dialect \"";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+ }
+
+ public void testCheckQueryLocationDetermination() {
+ String input =
+ "query MyQuery ";
+ Location location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ input =
+ "query \"MyQuery\" ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
+
+ input =
+ "query MyQuery() ";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
+
+ input =
+ "query MyQuery \n" +
+ " Class (";
+ location = new CompletionContext(input).getLocation();
+ assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
+ assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
+ }
+
+}
Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,143 @@
+package org.drools.eclipse.editors.completion;
+
+import org.eclipse.jdt.core.Signature;
+
+import junit.framework.TestCase;
+
+public class CompletionUtilTest extends TestCase {
+
+ public void testIsGetter() {
+ assertTrue( CompletionUtil.isGetter( "getThis",
+ 0,
+ "String" ) );
+ }
+
+ public void testIsGetterCannotReturnVoid() {
+ assertFalse( CompletionUtil.isGetter( "getThis",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsGetterWrongPrefix() {
+ assertFalse( CompletionUtil.isGetter( "hasThis",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsGetterTooManyArgs() {
+ assertFalse( CompletionUtil.isGetter( "getThis",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsGetterMethodNameTooShort() {
+ assertFalse( CompletionUtil.isGetter( "get",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsIsGetter() {
+ assertTrue( CompletionUtil.isIsGetter( "isGood",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ }
+
+ public void testIsIsGetterWrongPrefix() {
+ assertFalse( CompletionUtil.isIsGetter( "getThis",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ }
+
+ public void testIsIsGetterAlwaysReturnsBoolean() {
+ assertFalse( CompletionUtil.isIsGetter( "isThis",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsIsGetterTooManyArgs() {
+ assertFalse( CompletionUtil.isIsGetter( "isThis",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsIsGetterMethodNameTooShort() {
+ assertFalse( CompletionUtil.isIsGetter( "is",
+ 2,
+ "String" ) );
+ }
+
+ public void testIsSetter() {
+ assertTrue( CompletionUtil.isSetter( "setThat",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterWrongPrefix() {
+ assertFalse( CompletionUtil.isSetter( "getThat",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterTooShort() {
+ assertFalse( CompletionUtil.isSetter( "se",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterNoArgs() {
+ assertFalse( CompletionUtil.isSetter( "setThat",
+ 0,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testIsSetterWrongType() {
+ assertFalse( CompletionUtil.isSetter( "setThat",
+ 1,
+ "String" ) );
+ }
+
+ public void testGetPropertyName() {
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "getMe",
+ 0,
+ "String" ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "isMe",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "setMe",
+ 1,
+ Signature.SIG_VOID ) );
+
+ assertEquals( "setMe",
+ CompletionUtil.getPropertyName( "setMe",
+ 0,
+ Signature.SIG_VOID ) );
+
+ assertEquals( "MySuperMethod",
+ CompletionUtil.getPropertyName( "MySuperMethod",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+
+ public void testGetPropertyNameStripsParenthesis() {
+
+ assertEquals( "MySuperMethod()",
+ CompletionUtil.getPropertyName( "MySuperMethod()",
+ 1,
+ Signature.SIG_VOID ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "getMe()",
+ 0,
+ "String" ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "isMe()",
+ 0,
+ Signature.SIG_BOOLEAN ) );
+ assertEquals( "me",
+ CompletionUtil.getPropertyName( "setMe()",
+ 1,
+ Signature.SIG_VOID ) );
+ }
+}
\ No newline at end of file
Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/IncompleteParsingTest.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -18,8 +18,8 @@
import org.drools.lang.descr.VariableRestrictionDescr;
/**
- * Test to check the results from parsing incomplete rule fragments.
- *
+ * Test to check the results from parsing incomplete rule fragments.
+ *
* @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
*/
public class IncompleteParsingTest extends TestCase {
@@ -34,7 +34,7 @@
}
return null;
}
-
+
private PackageDescr parseString(String s) {
DrlParser parser = new DrlParser();
try {
@@ -44,26 +44,26 @@
}
return null;
}
-
-
+
+
public void testParsingColumn() {
- String input =
+ String input =
"rule MyRule \n" +
" when \n" +
" ";
RuleDescr rule = parseRuleString(input);
assertEquals(0, rule.getLhs().getDescrs().size());
-
+
/**
* This is how the parsed tree should look like:
- *
+ *
* RuleDescr
* PatternDescr [objectType = "Class"]
* FieldConstraintDescr [fieldName = "condition"]
* LiteralRestrictionDescr [evaluator = "==", text = "true"]
*/
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class( condition == true ) \n" +
@@ -85,7 +85,7 @@
assertEquals("==", restriction.getEvaluator());
assertEquals("true", restriction.getText());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class: Class( condition == true, condition2 == null ) \n" +
@@ -95,14 +95,14 @@
pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertTrue(pattern.getEndCharacter() != -1);
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Cl";
rule = parseRuleString(input);
assertEquals(0, rule.getLhs().getDescrs().size());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class( condition == true ) \n" +
@@ -112,7 +112,7 @@
pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertTrue(pattern.getEndCharacter() != -1);
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class:";
@@ -123,7 +123,7 @@
assertNull(pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class: Cl";
@@ -136,7 +136,7 @@
assertEquals(0, pattern.getDescrs().size());
assertEquals(-1, pattern.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" class:Cl";
@@ -150,7 +150,7 @@
assertEquals(-1, pattern.getEndCharacter());
/** Inside of condition: start */
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class (";
@@ -162,9 +162,9 @@
assertEquals(0, pattern.getDescrs().size());
assertEquals(-1, pattern.getEndCharacter());
- input =
- "rule MyRule \n" +
- " when \n" +
+ input =
+ "rule MyRule \n" +
+ " when \n" +
" Class ( na";
rule = parseRuleString(input);
assertEquals(1, rule.getLhs().getDescrs().size());
@@ -172,13 +172,13 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals( "na", field.getFieldName() );
assertEquals(-1, field.getEndCharacter());
- input =
- "rule MyRule \n" +
- " when \n" +
+ input =
+ "rule MyRule \n" +
+ " when \n" +
" Class ( name['xyz'].subname.subsubn";
rule = parseRuleString(input);
assertEquals(1, rule.getLhs().getDescrs().size());
@@ -186,11 +186,11 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals( "name['xyz'].subname.subsubn", field.getFieldName() );
assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( condition == true, ";
@@ -200,10 +200,10 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( c : condition, ";
@@ -213,10 +213,10 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(1, pattern.getDescrs().size());
- FieldBindingDescr fieldBinding = (FieldBindingDescr) pattern.getDescrs().get(0);
+ FieldBindingDescr fieldBinding = (FieldBindingDescr) pattern.getDescrs().get(0);
assertEquals(-1, fieldBinding.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( condition == true, na";
@@ -226,14 +226,14 @@
assertEquals("Class", pattern.getObjectType());
assertEquals(-1, pattern.getEndCharacter());
assertEquals(2, pattern.getDescrs().size());
- field = (FieldConstraintDescr) pattern.getDescrs().get(0);
+ field = (FieldConstraintDescr) pattern.getDescrs().get(0);
assertEquals(-1, field.getEndCharacter());
assertEquals( "condition", field.getFieldName() );
field = (FieldConstraintDescr) pattern.getDescrs().get(1);
assertEquals( "na", field.getFieldName() );
assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( name:";
@@ -246,8 +246,8 @@
FieldBindingDescr binding1 = (FieldBindingDescr) pattern.getDescrs().get(0);
assertEquals("name", binding1.getIdentifier());
assertNull(binding1.getFieldName());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property ";
@@ -261,8 +261,8 @@
assertEquals("property", field.getFieldName());
assertEquals(0, field.getRestrictions().size());
assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( name: property ";
@@ -275,8 +275,8 @@
FieldBindingDescr binding = (FieldBindingDescr) pattern.getDescrs().get(0);
assertEquals("name", binding.getIdentifier());
assertEquals("property", binding.getFieldName());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( name1: property1 == \"value1\", name2: property2 ";
@@ -298,8 +298,8 @@
binding = (FieldBindingDescr) pattern.getDescrs().get(2);
assertEquals("name2", binding.getIdentifier());
assertEquals("property2", binding.getFieldName());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class(name:property==";
@@ -315,8 +315,8 @@
field = (FieldConstraintDescr) pattern.getDescrs().get(1);
assertEquals("property", field.getFieldName());
assertEquals(1, field.getRestrictions().size());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property == otherPropertyN";
@@ -333,8 +333,8 @@
assertEquals("==", variable.getEvaluator());
assertEquals("otherPropertyN", variable.getIdentifier());
assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property == \"someth";
@@ -358,7 +358,7 @@
// TODO this method does not yet exist
// assertEquals(-1, field.getEndCharacter());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property contains ";
@@ -381,8 +381,8 @@
// starting character of this FieldConstraintDescr?
// TODO this method does not yet exist
assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class( property matches \"someth";
@@ -403,8 +403,8 @@
// assertEquals("someth", literal.getText());
// TODO this method does not yet exist
// assertEquals(-1, field.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" eval ( ";
@@ -413,8 +413,8 @@
EvalDescr eval = (EvalDescr) rule.getLhs().getDescrs().get(0);
assertEquals(input.indexOf( "eval" ), eval.getStartCharacter());
assertEquals(-1, eval.getEndCharacter());
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property > 0 & ";
@@ -433,7 +433,7 @@
RestrictionConnectiveDescr connective = (RestrictionConnectiveDescr) field.getRestriction();
assertEquals(RestrictionConnectiveDescr.AND, connective.getConnective());
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( ) from a";
@@ -441,11 +441,11 @@
assertEquals(1, rule.getLhs().getDescrs().size());
pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Class", pattern.getObjectType());
- FromDescr from = (FromDescr) pattern.getSource();
+ FromDescr from = (FromDescr) pattern.getSource();
assertEquals(-1, from.getEndCharacter());
assertTrue(pattern.getEndCharacter() != -1);
-
- input =
+
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property > 0 ) from myGlobal.getList() \n" +
@@ -457,7 +457,7 @@
from = (FromDescr) pattern.getSource();
assertTrue(from.getEndCharacter() != -1);
- input =
+ input =
"rule MyRule \n" +
" when \n" +
" Class ( property > 0 ) from getDroolsFunction() \n" +
@@ -469,9 +469,9 @@
from = (FromDescr) pattern.getSource();
assertTrue(from.getEndCharacter() != -1);
}
-
+
public void testParsingCharactersStartEnd() {
- String input =
+ String input =
"package test; \n" +
"rule MyRule \n" +
" when \n" +
@@ -488,825 +488,4 @@
assertEquals(input.indexOf( ")" ), pattern.getRightParentCharacter());
assertEquals(input.indexOf( ")" ), pattern.getEndCharacter());
}
-
-// public void doTestRemainder() {
-//
-// /** EXISTS */
-// 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(";
-// 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_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" +
-// " ";
-// 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_NOT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " not Cl";
-// location = LocationDeterminator.getLocationInCondition(input);
-// 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" +
-// " not Class () \n" +
-// " ";
-// 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());
-// assertEquals("name", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// 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());
-// assertEquals("name", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// 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());
-//// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval(";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( myCla";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("myCla", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMetho";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMetho", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod(";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod(", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod().get";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod().get", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod(\"someStringWith)))\").get";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod(\"someStringWith)))\").get", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getMethod(\"someStringWith(((\").get";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getMethod(\"someStringWith(((\").get", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// 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( param.getProperty(name).isTrue() )";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getProperty(\"someStringWith(((\").isTrue() )";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getProperty((((String) s) )";
-//// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_EVAL, location.getType());
-//// assertEquals("param.getProperty((((String) s) )", location.getProperty(LocationDeterminator.LOCATION_EVAL_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " eval( param.getProperty((((String) s))))";
-// 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());
-//
-// /** MULTIPLE RESTRICTIONS */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & " +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( name : property1, property2 > 0 & ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property1 < 20, property2 > 0 & ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & < ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//// assertEquals("<", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_OPERATOR));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 | ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 | \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( name : property1, property2 > 0 | ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property1 < 20, property2 > 0 | ";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-//// assertEquals("Class", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//// assertEquals("property2", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 & < 10 ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 | < 10 ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property == \"test\" | == \"test2\" ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_END, location.getType());
-//
-// /** FROM */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) fr";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM, location.getType());
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from myGlob";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_FROM, location.getType());
-//// assertEquals("myGlob", location.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from myGlobal.get";
-// location = LocationDeterminator.getLocationInCondition(input);
-//// assertEquals(LocationDeterminator.LOCATION_FROM, location.getType());
-//// assertEquals("myGlobal.get", location.getProperty(LocationDeterminator.LOCATION_FROM_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from myGlobal.getList() \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from getDroolsFunction() \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// /** FROM ACCUMULATE */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate ( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate(";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $cheese.getPrice(); ), \n" +
-// " result( new Integer( total ) ) \n" +
-// " ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $cheese.getPrice(); ), \n" +
-// " result( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("total += $cheese.getPrice(); ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-// assertEquals("", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total =";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
-// assertEquals("int total =", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $ch";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("total += $ch", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == $likes ), \n" +
-// " init( int total = 0; ), \n" +
-// " action( total += $cheese.getPrice(); ), \n" +
-// " result( new Integer( tot";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
-// assertEquals("int total = 0; ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-// assertEquals("total += $cheese.getPrice(); ", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-// assertEquals("new Integer( tot", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from accumulate( \n" +
-// " $cheese : Cheese( type == ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// /** FROM COLLECT */
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_COLLECT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect(";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_FROM_COLLECT, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( type == $likes )" +
-// " ) \n" +
-// " ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_BEGIN_OF_CONDITION, location.getType());
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_START, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( type ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_OPERATOR, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-//
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " Class ( property > 0 ) from collect ( \n" +
-// " Cheese( type == ";
-// location = LocationDeterminator.getLocationInCondition(input);
-// assertEquals(LocationDeterminator.LOCATION_INSIDE_CONDITION_ARGUMENT, location.getType());
-// assertEquals("Cheese", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_CLASS_NAME));
-// assertEquals("type", location.getProperty(LocationDeterminator.LOCATION_PROPERTY_PROPERTY_NAME));
-// }
-
}
Deleted: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java 2007-07-20 17:51:32 UTC (rev 13681)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/LocationDeterminatorTest.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -1,1540 +0,0 @@
-package org.drools.eclipse.editors.completion;
-
-import org.drools.lang.Location;
-
-import junit.framework.TestCase;
-
-/**
- * Test to check the location determination when doing code completion inside
- * rule condtions.
- *
- * @author <a href="mailto:kris_verlaenen at hotmail.com">kris verlaenen </a>
- *
- */
-public class LocationDeterminatorTest extends TestCase {
-
- public void testColumnOperatorPattern() {
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(name:property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name:property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : property ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name:property2 ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", name : property2 ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name:prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(name:prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : prop").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property <= ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( name : property == ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("(property==").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property contains ").matches());
- assertFalse(LocationDeterminator.PATTERN_PATTERN_OPERATOR.matcher("( property1 == \"value\", property2 >= ").matches());
- }
-
- public void testColumnArgumentPattern() {
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property >= ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property== ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(name:property== ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( name : property == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\",property2== ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property1 == \"value\", property2 == ").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("( property == otherProp").matches());
- assertTrue(LocationDeterminator.PATTERN_PATTERN_COMPARATOR_ARGUMENT.matcher("(property==otherProp").matches());
- }
-
- public void testCheckLHSLocationDetermination() {
- String input =
- "rule MyRule \n" +
- " when \n" +
- " ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class( condition == true ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " class: Class( condition == true, condition2 == null ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class( condition == true ) \n" +
- " Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " class: Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " class:Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** Inside of condition: start */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( na";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("na", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name.subProperty['test'].subsu";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("name.subProperty['test'].subsu", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( condition == true, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( condition == true, na";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( condition == true, \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( c: condition, \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name: ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name:";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- /** Inside of condition: Operator */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class(property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (name:property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (name:property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1, name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1 == \"value\", name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1 == \"value\",property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1, \n" +
- " name : property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- /** Inside of condition: argument */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property== ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property <= ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("<=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name:property != ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("!=", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name1 : property1, property2 == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class (name:property== ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == otherPropertyN";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == \"someth";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property contains ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("contains", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property excludes ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("excludes", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property matches \"prop";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("matches", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property in ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property in ('1', '2') ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property in ('1', '2'), ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not in ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("in", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not in ('1', '2') ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not in ('1', '2'), ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property memberOf ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property memberOf collection ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property memberOf collection, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not memberOf ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("memberOf", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not memberOf collection ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property not memberOf collection, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
-
- /** EXISTS */
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ( Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists ( name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** NOT */
- input =
- "rule MyRule \n" +
- " when \n" +
- " not ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- // TODO
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not exists name : Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " not Class () \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** AND */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class () and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " name : Class ( name: property ) and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name: property ) \n" +
- " and ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) && name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and not Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and exists Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( name ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and Class ( name == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) and not ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) and exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) and not Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** OR */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class () or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " name : Class ( name: property ) or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name: property ) \n" +
- " or ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) || name : Cl";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( name ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("name", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( ) or Class ( name == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) or not ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_NOT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " exists Class ( ) or exists ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION_EXISTS, location.getType());
-
- /** EVAL */
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( myCla";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("myCla", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMetho";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMetho", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod(", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod().get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod().get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod(\"someStringWith)))\").get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod(\"someStringWith)))\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getMethod(\"someStringWith(((\").get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getMethod(\"someStringWith(((\").get", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( true )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty(name).isTrue() )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty(\"someStringWith(((\").isTrue() )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty((((String) s) )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_EVAL, location.getType());
- assertEquals("param.getProperty((((String) s) )", location.getProperty(Location.LOCATION_EVAL_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( param.getProperty((((String) s))))";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " eval( true ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** MULTIPLE RESTRICTIONS */
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property1, property2 > 0 && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property1 < 20, property2 > 0 && ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("<", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < 10 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < 10, ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 || \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( name : property1, property2 > 0 || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property1 < 20, property2 > 0 || ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property2", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 && < 10 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 || < 10 ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property == \"test\" || == \"test2\" ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, location.getType());
-
- /** FROM */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) fr";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_FROM_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from myGlob";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
- assertEquals("myGlob", location.getProperty(Location.LOCATION_FROM_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from myGlobal.get";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
- assertEquals("myGlobal.get", location.getProperty(Location.LOCATION_FROM_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from myGlobal.getList() \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from getDroolsFunction() \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** FROM ACCUMULATE */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $cheese.getPrice(); ), \n" +
- " result( new Integer( total ) ) \n" +
- " ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $cheese.getPrice(); ), \n" +
- " result( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
- assertEquals("", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total =";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE, location.getType());
- assertEquals("int total =", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $ch";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals("total += $ch", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == $likes ), \n" +
- " init( int total = 0; ), \n" +
- " action( total += $cheese.getPrice(); ), \n" +
- " result( new Integer( tot";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE, location.getType());
- assertEquals(" int total = 0; ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_INIT_CONTENT));
- assertEquals(" total += $cheese.getPrice(); ", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_ACTION_CONTENT));
- assertEquals("new Integer( tot", location.getProperty(Location.LOCATION_PROPERTY_FROM_ACCUMULATE_RESULT_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from accumulate( \n" +
- " $cheese : Cheese( type == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- /** FROM COLLECT */
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect(";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM_COLLECT, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( type == $likes )" +
- " ) \n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( type ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " Class ( property > 0 ) from collect ( \n" +
- " Cheese( type == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Cheese", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("type", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- /** NESTED FROM */
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from collect( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_FROM, location.getType());
-
-//moved to testCheckLHSLocationDetermination_Failing
-// input =
-// "rule MyRule \n" +
-// " when \n" +
-// " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
-// location = LocationDeterminator.getLocation(input);
-// assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- /** FORALL */
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( pr";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("pr", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( property ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( property == ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- assertEquals("property", location.getProperty(Location.LOCATION_PROPERTY_PROPERTY_NAME));
- assertEquals("==", location.getProperty(Location.LOCATION_PROPERTY_OPERATOR));
-
- input =
- "rule MyRule \n" +
- " when \n" +
- " forall ( " +
- " Class ( property == \"test\")" +
- " C";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
- }
-
- public void testCheckLHSLocationDetermination_Failing() {
- String input =
- "rule MyRule \n" +
- " when \n" +
- " ArrayList(size > 50) from accumulate( Person( disabled == \"yes\", income > 100000 ) from town.getPersons() )";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- }
-
- public void testCheckRHSLocationDetermination() {
- String input =
- "rule MyRule \n" +
- " when\n" +
- " Class ( )\n" +
- " then\n" +
- " ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RHS, location.getType());
- assertEquals("", location.getProperty(Location.LOCATION_RHS_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when\n" +
- " Class ( )\n" +
- " then\n" +
- " assert(null);\n" +
- " ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RHS, location.getType());
- assertEquals("assert(null);\n ", location.getProperty(Location.LOCATION_RHS_CONTENT));
-
- input =
- "rule MyRule \n" +
- " when\n" +
- " Class ( )\n" +
- " then\n" +
- " meth";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RHS, location.getType());
- assertEquals("meth", location.getProperty(Location.LOCATION_RHS_CONTENT));
- }
-
- public void testCheckRuleHeaderLocationDetermination() {
- String input =
- "rule MyRule ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- input =
- "rule MyRule \n" +
- " salience 12 activation-group \"my";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- // KRISV: still can't make this work... apparently, ANTLR is trying to recover from
- // the error (unkown token) by deleting the token. I don't know why it continues to
- // execute actions though, if the EOF is found.
-// input =
-// "rule \"Hello World\" ruleflow-group \"hello\" s";
-// location = LocationDeterminator.getLocation(input);
-// assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
- }
-
- public void testCheckRuleHeaderLocationDetermination_dialect1() {
- String input =
- "rule MyRule \n" +
- " dialect =\"java\" howdy";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
- }
-
- public void testCheckRuleHeaderLocationDetermination_dialect2() {
- String input =
- "rule MyRule \n" +
- " dialect =\"mvel\"";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
- }
-
- public void testCheckRuleHeaderLocationDetermination_dialect3() {
- String input =
- "rule MyRule \n" +
- " dialect =";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
- }
-
- public void testCheckRuleHeaderLocationDetermination_dialect4() {
- String input =
- "rule MyRule \n" +
- " dialect =\"";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
- }
-
- public void testCheckQueryLocationDetermination() {
- String input =
- "query MyQuery ";
- Location location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- input =
- "query \"MyQuery\" ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_RULE_HEADER, location.getType());
-
- input =
- "query MyQuery() ";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_BEGIN_OF_CONDITION, location.getType());
-
- input =
- "query MyQuery \n" +
- " Class (";
- location = LocationDeterminator.getLocation(input);
- assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_START, location.getType());
- assertEquals("Class", location.getProperty(Location.LOCATION_PROPERTY_CLASS_NAME));
- }
-
-}
Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MockCompletionProcessor.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MockCompletionProcessor.java (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MockCompletionProcessor.java 2007-07-20 18:11:07 UTC (rev 13682)
@@ -0,0 +1,17 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.List;
+
+import org.eclipse.jface.text.ITextViewer;
+
+public class MockCompletionProcessor extends AbstractCompletionProcessor {
+
+ public MockCompletionProcessor() {
+ super( null );
+ }
+
+ protected List getCompletionProposals(ITextViewer viewer,
+ int documentOffset) {
+ return null;
+ }
+}
More information about the jboss-svn-commits
mailing list