[jboss-svn-commits] JBL Code SVN: r13717 - labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 22 19:47:45 EDT 2007
Author: pombredanne
Date: 2007-07-22 19:47:44 -0400 (Sun, 22 Jul 2007)
New Revision: 13717
Modified:
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
Log:
Fixed a couple issues in mvel code completion: no more duplicates. And better construction of incomplete yet compilable expssion for internal analysis
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java 2007-07-22 22:56:27 UTC (rev 13716)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java 2007-07-22 23:47:44 UTC (rev 13717)
@@ -1,216 +1,191 @@
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 {
- protected static final Pattern INCOMPLETED_MVEL_EXPRESSION = Pattern.compile( "[\\.\\(\\{\\[]\\Z",
- Pattern.DOTALL );
+ protected static final Pattern INCOMPLETED_MVEL_EXPRESSION = Pattern
+ .compile("[\\.\\(\\{\\[]\\Z", Pattern.DOTALL);
- protected static final Pattern COMPLETED_MVEL_EXPRESSION = Pattern.compile( "]\\)\\}\\]\\Z",
- Pattern.DOTALL );
+ protected static final Pattern COMPLETED_MVEL_EXPRESSION = Pattern.compile(
+ "]\\)\\}\\]\\Z", Pattern.DOTALL);
- private CompletionUtil() {
- }
+ 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;
- }
- }
+ /**
+ * 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;
+ }
+ }
- 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;
- }
- }
+ 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;
+ }
+ }
- /**
- *
- * @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;
- }
- }
+ /**
+ *
+ * @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.trim().endsWith(";")) {
+ // RHS expression should compile if it ends with ;. but to hget the last object, we do no want it
+ return backText.substring(0, backText.length() - 1);
+ }
+ else if (backText.endsWith(".")) {
+ // RHS expression should compile if it ends with ;
+ return backText.substring(0, backText.length() - 1) ;
+ } 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
- */
+ /*
+ * 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 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 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 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 ) ) {
+ 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;
+ prefixLength = 2;
- } else if ( isGetter( simpleName,
- parameterCount,
- returnType ) //
- || isSetter( methodName,
- parameterCount,
- returnType ) ) {
+ } else if (isGetter(simpleName, parameterCount, returnType) //
+ || isSetter(methodName, parameterCount, returnType)) {
- prefixLength = 3;
- } else {
- return methodName;
- }
+ prefixLength = 3;
+ } else {
+ return methodName;
+ }
- char firstChar = Character.toLowerCase( simpleName.charAt( prefixLength ) );
- String propertyName = firstChar + simpleName.substring( prefixLength + 1 );
- return propertyName;
- }
+ 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;
- }
+ 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 ) );
+ int parameterCount = Signature.getParameterCount(signature);
+ String returnType = new String(Signature.getReturnType(signature));
- return getPropertyName( methodName,
- parameterCount,
- returnType );
- }
+ return getPropertyName(methodName, parameterCount, returnType);
+ }
- private static boolean isAccessor(String methodName,
- int actualParameterCount,
- int requiredParameterCount,
- String prefix,
- String returnType,
- String requiredReturnType,
- boolean includeType) {
+ 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.length() < prefix.length() + 1) {
+ return false;
+ }
- if ( !methodName.startsWith( prefix ) ) {
- return false;
- }
+ if (!methodName.startsWith(prefix)) {
+ return false;
+ }
- if ( actualParameterCount != requiredParameterCount ) {
- return false;
- }
+ if (actualParameterCount != requiredParameterCount) {
+ return false;
+ }
- if ( includeType ) {
- if ( !requiredReturnType.equals( returnType ) ) {
- return false;
- }
- } else {
- if ( requiredReturnType.equals( returnType ) ) {
- return false;
- }
- }
- return true;
- }
+ 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() );
+ 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;
- }
+ if ("".equals(javaTextWithoutPrefix.trim())
+ || DefaultCompletionProcessor.START_OF_NEW_JAVA_STATEMENT
+ .matcher(javaTextWithoutPrefix).matches()) {
+ return true;
+ }
+ return false;
+ }
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2007-07-22 22:56:27 UTC (rev 13716)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java 2007-07-22 23:47:44 UTC (rev 13717)
@@ -225,26 +225,26 @@
* 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,
+ protected Collection getJavaMvelCompletionProposals(final String javaText,
final String prefix,
Map params) {
final Collection set = new HashSet();
CompletionRequestor requestor = new MvelCompletionRequestor( prefix,
javaText,
set );
+ System.out.println("MVEL: java text sent to JDT is:"+javaText);
requestJavaCompletionProposals( javaText,
prefix,
params,
requestor );
- List list = new ArrayList();
- list.addAll( set );
- return list;
+ return set;
}
protected void requestJavaCompletionProposals(final String javaText,
final String prefix,
Map params,
CompletionRequestor requestor) {
+ System.out.println("MVEL: java text sent to JDT is:"+javaText);
IEditorInput input = getEditor().getEditorInput();
if ( !(input instanceof IFileEditorInput) ) {
@@ -270,8 +270,8 @@
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 );
+// System.out.println( "" );
+// System.out.println( "MVEL: synthetic Java text:" + text );
evalContext.codeComplete( text,
text.length(),
requestor );
Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2007-07-22 22:56:27 UTC (rev 13716)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java 2007-07-22 23:47:44 UTC (rev 13717)
@@ -2,13 +2,15 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.drools.base.ClassTypeResolver;
-import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.eclipse.DRLInfo;
import org.drools.eclipse.DroolsEclipsePlugin;
@@ -27,7 +29,6 @@
import org.drools.lang.descr.GlobalDescr;
import org.drools.lang.descr.NotDescr;
import org.drools.lang.descr.OrDescr;
-import org.drools.lang.descr.PackageDescr;
import org.drools.lang.descr.PatternDescr;
import org.drools.rule.builder.dialect.mvel.MVELDialect;
import org.drools.util.asm.ClassFieldInspector;
@@ -45,1053 +46,908 @@
*/
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);
- /**
- * A CompletionContext contains the DRL backtext parsing results, to avoid multilpe parser invocations
- */
- private CompletionContext context;
+ /**
+ * A CompletionContext contains the DRL backtext parsing results, to avoid
+ * multilpe parser invocations
+ */
+ private CompletionContext context;
- public RuleCompletionProcessor(AbstractRuleEditor editor) {
- super( editor );
- }
+ public RuleCompletionProcessor(AbstractRuleEditor editor) {
+ super(editor);
+ }
- protected List getCompletionProposals(ITextViewer viewer,
- int documentOffset) {
- try {
- final List list = new ArrayList();
+ protected List getCompletionProposals(ITextViewer viewer, int documentOffset) {
+ try {
+ final List list = new ArrayList();
- IDocument doc = viewer.getDocument();
+ IDocument doc = viewer.getDocument();
- String backText = readBackwards( documentOffset,
- doc );
- final String prefix = CompletionUtil.stripLastWord( backText );
+ String backText = readBackwards(documentOffset, doc);
+ final String prefix = CompletionUtil.stripLastWord(backText);
- //FIXME:where does the magic number 5 come from? "rule "?
- if ( backText.length() < 5 ) {
- return list;
- }
+ // FIXME:where does the magic number 5 come from? "rule "?
+ if (backText.length() < 5) {
+ return list;
+ }
- this.context = new CompletionContext( backText );
- Location location = context.getLocation();
+ this.context = new CompletionContext(backText);
+ Location location = context.getLocation();
- 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 );
- }
+ 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);
+ }
- filterProposalsOnPrefix( prefix,
- list );
- return list;
- } catch ( Throwable t ) {
- t.printStackTrace();
- DroolsEclipsePlugin.log( t );
- }
- return null;
- }
+ filterProposalsOnPrefix(prefix, list);
+ return list;
+ } catch (Throwable t) {
+ t.printStackTrace();
+ DroolsEclipsePlugin.log(t);
+ }
+ return null;
+ }
- 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 );
- }
+ 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);
+ }
- boolean startOfDialectExpression = isStartOfDialectExpression( consequenceWithoutPrefix );
- if ( startOfDialectExpression ) {
- addRHSKeywordCompletionProposals( list,
- prefix );
- addRHSFunctionCompletionProposals( list,
- prefix );
- }
+ boolean startOfDialectExpression = isStartOfDialectExpression(consequenceWithoutPrefix);
+ if (startOfDialectExpression) {
+ addRHSKeywordCompletionProposals(list, prefix);
+ addRHSFunctionCompletionProposals(list, prefix);
+ }
- 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 (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);
+ }
+ }
- 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 ) );
+ 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 );
+ 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(),
- "==",
- "== ",
- 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 ) );
+ 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));
- 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 );
+ 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);
- if ( "in".equals( operator ) ) {
- list.add( new RuleCompletionProposal( prefix.length(),
- "()",
- "( )",
- 2,
- DROOLS_ICON ) );
- break;
- }
+ if ("in".equals(operator)) {
+ list.add(new RuleCompletionProposal(prefix.length(), "()",
+ "( )", 2, DROOLS_ICON));
+ break;
+ }
- if ( "contains".equals( operator ) || "excludes".equals( operator ) ) {
- type = "java.lang.Object";
- }
+ if ("contains".equals(operator) || "excludes".equals(operator)) {
+ type = "java.lang.Object";
+ }
- if ( "memberOf".equals( operator ) ) {
- type = "java.util.Collection";
- }
+ if ("memberOf".equals(operator)) {
+ type = "java.util.Collection";
+ }
- boolean isObject = false;
- if ( "java.lang.Object".equals( type ) ) {
- isObject = true;
- }
+ boolean isObject = false;
+ if ("java.lang.Object".equals(type)) {
+ isObject = true;
+ }
- 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 );
- }
+ 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);
+ }
- 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;
- }
- }
+ 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;
+ }
+ }
- 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 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 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 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 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 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());
+ }
+ }
- if ( context == null ) {
- context = new CompletionContext( backText );
- }
- if ( context.getRule() == null ) {
- return result;
- }
+ if (context == null) {
+ context = new CompletionContext(backText);
+ }
+ if (context.getRule() == null) {
+ return result;
+ }
- // add parameters defined in conditions
- addRuleParameters( result,
- context.getRule().getLhs().getDescrs() );
- return result;
- }
+ // add parameters defined in conditions
+ addRuleParameters(result, context.getRule().getLhs().getDescrs());
+ return result;
+ }
- 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 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 boolean isPrimitiveType(String type) {
- return isPrimitiveNumericType( type ) || type.equals( "boolean" );
- }
+ private boolean isPrimitiveType(String type) {
+ return isPrimitiveNumericType(type) || type.equals("boolean");
+ }
- 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 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 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 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");
+ }
- /**
- * 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;
- }
- }
+ /**
+ * 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 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 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 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 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) {
+ 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 );
- }
+ Collection 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) {
+ private Collection getMvelCompletionProposals(final String consequence,
+ final String prefix, Map params, String backText,
+ boolean startOfExpression) {
- final List proposals = new ArrayList();
+ final Set proposals = new HashSet();
- if ( !(getEditor() instanceof DRLRuleEditor) ) {
- return proposals;
- }
+ if (!(getEditor() instanceof DRLRuleEditor)) {
+ return proposals;
+ }
- String compilableConsequence = CompletionUtil.getCompilableText( consequence );
+ String compilableConsequence = CompletionUtil
+ .getCompilableText(consequence);
- //attempt to compile and analyze
- try {
- DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( (DRLRuleEditor) getEditor(),
- true,
- true );
+ // attempt to compile and analyze
+ try {
+ DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(
+ (DRLRuleEditor) getEditor(), true, true);
- ParserContext compilationContext = createMvelAnalysisContext( params,
- drlInfo,
- compilableConsequence );
+ ParserContext compilationContext = createMvelAnalysisContext(
+ params, drlInfo, compilableConsequence);
- if ( startOfExpression ) {
- List jdtProps = getJavaMvelCompletionProposals( "",
- prefix,
- params );
- proposals.addAll( jdtProps );
- addMvelVariables( proposals,
- compilationContext );
+ if (startOfExpression) {
+ Collection jdtProps = getJavaMvelCompletionProposals("",
+ prefix, params);
+ proposals.addAll(jdtProps);
+ addMvelVariables(proposals, compilationContext);
- addMvelInputs( 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();
+ } else {
+ // we are completing the methods for an existing type or
+ // variable
+ // find the last type in the expression to complete against
- String type = lastType.getPackage().getName() + "." + lastType.getName();
- String javaText = "\n"+type + " o = new " + type + "(); o.";
- List jdtProps = getJavaMvelCompletionProposals( javaText,
- prefix,
- params );
- proposals.addAll( jdtProps );
- }
+ String analyzableExpression = compilableConsequence;
+ if (compilableConsequence.contains(";")) {
+ String[] lines = compilableConsequence.split(";");
+ analyzableExpression = lines[lines.length - 1];
+ }
+ if (!"".equals(analyzableExpression.trim())) {
- } catch ( Throwable e ) {
- // do nothing
- e.printStackTrace();
- }
+ Class lastType = new PropertyVerifier(analyzableExpression,
+ compilationContext).analyze();
- return proposals;
- }
+ String javaText = "\n" + lastType.getName() + " o = new " + lastType.getName()
+ + "();\no.";
+ Collection jdtProps = getJavaMvelCompletionProposals(
+ javaText, prefix, params);
+ proposals.addAll(jdtProps);
- 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();
+ } catch (Throwable e) {
+ // do nothing
+ //e.printStackTrace();
+ }
- ExpressionCompiler compiler = new ExpressionCompiler( compilableConsequence );
+ return proposals;
+ }
- 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 );
+ private ParserContext createMvelAnalysisContext(Map params,
+ DRLInfo drlInfo, String compilableConsequence) {
- compiler.compile( initialContext );
+ 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();
- ParserContext compilationContext = compiler.getParserContextState();
- return compilationContext;
- }
+ ExpressionCompiler compiler = new ExpressionCompiler(
+ compilableConsequence);
- 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 );
+ 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);
- System.out.println( " MVEL: added inputs from mvel eval: name:" + prop + " type:" + inputs.get( prop ).getClass() );
- }
- }
+ try {
+ compiler.compile(initialContext);
+ ParserContext compilationContext = compiler.getParserContextState();
+ return compilationContext;
+ } catch (Exception e) {
+ return initialContext;
+ }
- 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 addMvelInputs(final Collection 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);
- 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 );
- }
- }
+ // System.out.println( " MVEL: added inputs from mvel eval: name:" +
+ // prop + " type:" + inputs.get( prop ).getClass() );
+ }
+ }
- 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 addMvelVariables(final Collection 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);
- 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 );
- }
- }
- }
- }
+ // System.out.println( " MVEL: added completion: got variable from
+ // mvel eval: name:" + prop + " type:" + variables.get( prop
+ // ).getClass() );
+ }
+ }
- 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 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 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;
- }
+ 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;
+ }
+
}
More information about the jboss-svn-commits
mailing list