[jboss-svn-commits] JBL Code SVN: r15517 - in labs/jbossrules/trunk/drools-eclipse: drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 2 17:45:59 EDT 2007


Author: pombredanne
Date: 2007-10-02 17:45:59 -0400 (Tue, 02 Oct 2007)
New Revision: 15517

Added:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MvelParsingTest.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/RuleCompletionProcessorTest.java
Modified:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java
   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
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java
Log:
Adding support in MVEl completion for completion withing modiify with block. refined completion and completion sorting.

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java	2007-10-02 21:16:19 UTC (rev 15516)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionContext.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -47,26 +47,25 @@
                                                                                 Pattern.DOTALL );
 
     static final Pattern ENDS_WITH_COLON                     = Pattern.compile( ".*:\\s*",
-            																	Pattern.DOTALL );
+                                                                                Pattern.DOTALL );
 
     static final Pattern ENDS_WITH_BRACKET                   = Pattern.compile( ".*\\)\\s*",
-																				Pattern.DOTALL );
+                                                                                Pattern.DOTALL );
 
-    static final Pattern MVEL_DIALECT_PATTERN                        = Pattern.compile( ".*dialect\\s+\"mvel\".*",
+    static final Pattern MVEL_DIALECT_PATTERN                = Pattern.compile( ".*dialect\\s+\"mvel\".*",
                                                                                 Pattern.DOTALL );
 
-    static final Pattern JAVA_DIALECT_PATTERN                        = Pattern.compile( ".*dialect\\s+\"java\".*",
-            																	Pattern.DOTALL );
+    static final Pattern JAVA_DIALECT_PATTERN                = Pattern.compile( ".*dialect\\s+\"java\".*",
+                                                                                Pattern.DOTALL );
 
-	static final String MVEL_DIALECT 								 = "mvel";
-	static final String JAVA_DIALECT 								 = "java";
+    static final String  MVEL_DIALECT                        = "mvel";
+    static final String  JAVA_DIALECT                        = "java";
 
     private String       backText;
     private DrlParser    parser;
     private RuleDescr    rule;
     private PackageDescr packageDescr;
     private String       dialect;
-    private Class        mvelReturnedType;
 
     public CompletionContext(String backText) {
         this.backText = backText;
@@ -87,20 +86,18 @@
         determineDialect( backText );
     }
 
-
     public boolean isJavaDialect() {
-        return JAVA_DIALECT.equalsIgnoreCase(dialect);
+        return JAVA_DIALECT.equalsIgnoreCase( dialect );
     }
 
     public boolean isMvelDialect() {
-        return MVEL_DIALECT.equalsIgnoreCase(dialect);
+        return MVEL_DIALECT.equalsIgnoreCase( dialect );
     }
 
     public boolean isDefaultDialect() {
         return !isJavaDialect() && !isMvelDialect();
     }
 
-
     public PackageDescr getPackageDescr() {
         return packageDescr;
     }
@@ -108,16 +105,16 @@
     //note: this is a crude but reasonably fast way to determine the dialect,
     //especially when parsing imcomplete rules
     private void determineDialect(String backText) {
-    	dialect = null;
+        dialect = null;
         boolean mvel = MVEL_DIALECT_PATTERN.matcher( backText ).matches();
         boolean java = JAVA_DIALECT_PATTERN.matcher( backText ).matches();
-		//which dialect may be defined for this rule?
+        //which dialect may be defined for this rule?
         if ( mvel ) {
             dialect = MVEL_DIALECT;
         }
-		if (java) {
-			dialect = JAVA_DIALECT;
-		}
+        if ( java ) {
+            dialect = JAVA_DIALECT;
+        }
     }
 
     public Location getLocation() {
@@ -137,8 +134,7 @@
                                                       Location location,
                                                       String backText) {
         if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR ) {
-            if ( !ENDS_WITH_SPACES.matcher( backText ).matches() 
-            	 || ENDS_WITH_COLON.matcher( backText ).matches()) {
+            if ( !ENDS_WITH_SPACES.matcher( backText ).matches() || ENDS_WITH_COLON.matcher( backText ).matches() ) {
                 location.setType( Location.LOCATION_LHS_INSIDE_CONDITION_START );
             }
         } else if ( location.getType() == Location.LOCATION_LHS_INSIDE_CONDITION_END ) {
@@ -170,9 +166,7 @@
             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()
-            		    	|| ENDS_WITH_BRACKET.matcher( backText ).matches() )) {
+            } else if ( ((String) location.getProperty( Location.LOCATION_FROM_CONTENT )).length() > 0 && (ENDS_WITH_SPACES.matcher( backText ).matches() || ENDS_WITH_BRACKET.matcher( backText ).matches()) ) {
                 location.setType( Location.LOCATION_LHS_BEGIN_OF_CONDITION );
             }
         } else if ( location.getType() == Location.LOCATION_LHS_FROM_ACCUMULATE_INIT ) {
@@ -222,12 +216,4 @@
 
         return location;
     }
-
-	public Class getMvelReturnedType() {
-		return mvelReturnedType;
-	}
-
-	public void setMvelReturnedType(Class getMvelReturnedType) {
-		this.mvelReturnedType = getMvelReturnedType;
-	}
 }
\ No newline at end of file

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-10-02 21:16:19 UTC (rev 15516)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/CompletionUtil.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -3,6 +3,7 @@
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
+import java.util.StringTokenizer;
 import java.util.regex.Pattern;
 
 import org.eclipse.jdt.core.Signature;
@@ -15,6 +16,9 @@
     protected static final Pattern COMPLETED_MVEL_EXPRESSION   = Pattern.compile( "]\\)\\}\\]\\Z",
                                                                                   Pattern.DOTALL );
 
+    protected static final Pattern MODIFY_PATTERN              = Pattern.compile( ".*modify\\s*\\(\\s*(.*)\\s*\\)(\\s*\\{(.*)\\s*\\}?)?",
+                                                                                  Pattern.DOTALL );
+
     private CompletionUtil() {
     }
 
@@ -43,6 +47,81 @@
         }
     }
 
+    public static String getPreviousExpression(String backText) {
+        int separator = backText.lastIndexOf( ';' );
+        if ( separator < 0 ) {
+            return backText;
+        }
+        return backText.substring( 0,
+                                   separator + 1 );
+    }
+
+    public static String getLastExpression(String backText) {
+        StringTokenizer st = new StringTokenizer( backText,
+                                                  ";" );
+        String last = "";
+        while ( st.hasMoreTokens() ) {
+            last = st.nextToken();
+        }
+        if ( last.trim().length() == 0 ) {
+            return backText;
+        }
+        return last;
+    }
+
+    public static String getInnerExpression(String backText) {
+        String last = getLastExpression( backText ).trim();
+
+        char[] c = last.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] == '>' || c[i] == ',' || c[i] == '{' || c[i] == '}' ) {
+                start = i + 1;
+                break;
+            }
+        }
+        last = last.substring( start );
+        return last;
+    }
+
+    public static int nestedExpressionIndex(char[] chars,
+                                            int start,
+                                            char type) {
+        int depth = 1;
+        char term = type;
+        switch ( type ) {
+            case '[' :
+                term = ']';
+                break;
+            case '{' :
+                term = '}';
+                break;
+            case '(' :
+                term = ')';
+                break;
+        }
+
+        if ( type == term ) {
+            for ( start++; start < chars.length; start++ ) {
+                if ( chars[start] == type ) {
+                    return start;
+                }
+            }
+        } else {
+            for ( start++; start < chars.length; start++ ) {
+                if ( chars[start] == '\'' || chars[start] == '"' ) {
+                    //start = captureStringLiteral(chars[start], chars, start, chars.length);
+                } else if ( chars[start] == type ) {
+                    depth++;
+                } else if ( chars[start] == term && --depth == 0 ) {
+                    return start;
+                }
+            }
+        }
+
+        return -1;
+    }
+
     public static String stripWhiteSpace(String prefix) {
         if ( "".equals( prefix ) ) {
             return prefix;
@@ -68,27 +147,34 @@
      * Attempt to enhance a consequence backtext such that it should compile in MVEL
      * @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
+     *         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
+        String trimed = backText.trim();
+        if ( trimed.endsWith( ";" ) ) {
+            // RHS expression should compile if it ends with ; but to get the last object,
+            // we do no want it, to simulate a return statement
             return backText.substring( 0,
                                        backText.length() - 1 );
-        } else if ( backText.endsWith( "." ) ) {
-            // RHS expression should compile if it ends with ;
+        } else if ( trimed.endsWith( "." ) || trimed.endsWith( "," ) ) {
+            // RHS expression should compile if it ends with no dot or comma
             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 if ( INCOMPLETED_MVEL_EXPRESSION.matcher( backText ).matches() ) {
+            //            // remove the last char and close the statement
+            //            return backText.substring( 0,
+            //                                       backText.length() - 1 );
         } else {
+            //TODO: support completion within with {} blocks
+            //TODO: support completion within nested expression.
+
             return backText;
         }
     }
@@ -197,7 +283,8 @@
      * @param requiredReturnType
      * @param includeType
      * @return true if the method is a bean accessor, false otherwise
-     */private static boolean isAccessor(String methodName,
+     */
+    private static boolean isAccessor(String methodName,
                                       int actualParameterCount,
                                       int requiredParameterCount,
                                       String prefix,
@@ -234,7 +321,8 @@
 
     public static boolean isStartOfNewStatement(String text,
                                                 String prefix) {
-        String javaTextWithoutPrefix = text.substring( 0, text.length() - prefix.length() );
+        String javaTextWithoutPrefix = text.substring( 0,
+                                                       text.length() - prefix.length() );
 
         if ( "".equals( javaTextWithoutPrefix.trim() ) || DefaultCompletionProcessor.START_OF_NEW_JAVA_STATEMENT.matcher( javaTextWithoutPrefix ).matches() ) {
             return true;
@@ -242,20 +330,49 @@
         return false;
     }
 
-
     public static String getLastLine(String text) {
         final BufferedReader reader = new BufferedReader( new StringReader( text ) );
         String line = null;
         String lastLine = null;
         try {
             while ( (line = reader.readLine()) != null ) {
-                if ( line.trim().length()>0 ) {
+                if ( line.trim().length() > 0 ) {
                     lastLine = line;
                 }
             }
         } catch ( final IOException e ) {
             // should never happen, it's just reading over a string.
         }
-     return lastLine;
+        return lastLine;
     }
+
+    /**
+     * COMPENSATES FOR LACK OF getSimpleName IN java.lang.Class
+     * Borrowed and adpated from MVEL's org.mvel.util.ParseTools.getSimpleClassName(Class)
+     * @param cls -- class reference
+     * @return Simple name of class
+     */
+    public static String getSimpleClassName(Class cls) {
+        int lastIndex = cls.getName().lastIndexOf( '$' );
+        if ( lastIndex < 0 ) {
+            lastIndex = cls.getName().lastIndexOf( '.' );
+        }
+        if ( cls.isArray() ) {
+            return cls.getName().substring( lastIndex + 1 ) + "[]";
+        } else {
+            return cls.getName().substring( lastIndex + 1 );
+        }
+    }
+
+    public static String getTextWithoutPrefix(final String javaText,
+                                              final String prefix) {
+        int endIndex = javaText.length() - prefix.length();
+        String javaTextWithoutPrefix = javaText;
+        //javaText can be an empty string.
+        if ( endIndex >= 0 ) {
+            javaTextWithoutPrefix = javaText.substring( 0,
+                                                        endIndex );
+        }
+        return javaTextWithoutPrefix;
+    }
 }

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-10-02 21:16:19 UTC (rev 15516)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DefaultCompletionProcessor.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -57,7 +57,7 @@
     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";
-    protected static final Pattern   IMPORT_PATTERN              = Pattern.compile( ".*\n\\W*import\\W[^;\\s]*",
+    protected 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*\\{([^\\}]*)",
@@ -76,39 +76,50 @@
     protected List getCompletionProposals(ITextViewer viewer,
                                           int documentOffset) {
         try {
-	        IDocument doc = viewer.getDocument();
-	        String backText = readBackwards( documentOffset, doc );
+            IDocument doc = viewer.getDocument();
+            String backText = readBackwards( documentOffset,
+                                             doc );
 
-	        String prefix = CompletionUtil.stripLastWord(backText);
+            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, prefix);
-	        } 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(documentOffset, functionText, prefix, params);
-	        		filterProposalsOnPrefix(prefix, props);
-	        	} else {
-	        		props = getPossibleProposals(viewer, documentOffset, backText, prefix);
-	        	}
-	        }
-	        return props;
-        } catch (Throwable t) {
-        	DroolsEclipsePlugin.log(t);
+            List props = null;
+            Matcher matcher = IMPORT_PATTERN.matcher( backText );
+            if ( matcher.matches() ) {
+                String classNameStart = backText.substring( backText.lastIndexOf( "import" ) + 7 );
+                props = getAllClassProposals( classNameStart,
+                                              documentOffset,
+                                              prefix );
+            } 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( documentOffset,
+                                                        functionText,
+                                                        prefix,
+                                                        params );
+                    filterProposalsOnPrefix( prefix,
+                                             props );
+                } else {
+                    props = getPossibleProposals( viewer,
+                                                  documentOffset,
+                                                  backText,
+                                                  prefix );
+                }
+            }
+            return props;
+        } catch ( Throwable t ) {
+            DroolsEclipsePlugin.log( t );
         }
         return null;
     }
@@ -131,56 +142,57 @@
      * create and returns a java project based on the current editor input or returns null
      */
     private IJavaProject getCurrentJavaProject() {
-		IEditorInput input = getEditor().getEditorInput();
-		if (!(input instanceof IFileEditorInput)) {
-			return null;
-		}
-		IProject project = ((IFileEditorInput) input).getFile().getProject();
-		IJavaProject javaProject = JavaCore.create(project);
-    	return javaProject;
+        IEditorInput input = getEditor().getEditorInput();
+        if ( !(input instanceof IFileEditorInput) ) {
+            return null;
+        }
+        IProject project = ((IFileEditorInput) input).getFile().getProject();
+        IJavaProject javaProject = JavaCore.create( project );
+        return javaProject;
     }
 
-	protected List getAllClassProposals(final String classNameStart, final int documentOffset, final String prefix) {
+    protected List getAllClassProposals(final String classNameStart,
+                                        final int documentOffset,
+                                        final String prefix) {
         List result = new ArrayList();
-		IJavaProject javaProject = getCurrentJavaProject();
-		if (javaProject == null) {
-			return result;
-		}
-		CompletionProposalCollector	collector = new CompletionProposalCollector(javaProject) {
-			public void accept(CompletionProposal proposal) {
-				if (proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.PACKAGE_REF ||
-					proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF) {
-						super.accept(proposal);
-				}
-			}
-		};
-		collector.acceptContext(new CompletionContext());
+        IJavaProject javaProject = getCurrentJavaProject();
+        if ( javaProject == null ) {
+            return result;
+        }
+        CompletionProposalCollector collector = new CompletionProposalCollector( javaProject ) {
+            public void accept(CompletionProposal proposal) {
+                if ( proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.PACKAGE_REF || proposal.getKind() == org.eclipse.jdt.core.CompletionProposal.TYPE_REF ) {
+                    super.accept( proposal );
+                }
+            }
+        };
+        collector.acceptContext( new CompletionContext() );
         try {
             IEvaluationContext evalContext = javaProject.newEvaluationContext();
             evalContext.codeComplete( classNameStart,
-            						  classNameStart.length(),
+                                      classNameStart.length(),
                                       collector );
-			IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
-			for (int i = 0; i < proposals.length; i++) {
-				if (proposals[i] instanceof AbstractJavaCompletionProposal) {
-					AbstractJavaCompletionProposal javaProposal = (AbstractJavaCompletionProposal) proposals[i];
-					int replacementOffset = documentOffset - (classNameStart.length() - javaProposal.getReplacementOffset());
-					javaProposal.setReplacementOffset(replacementOffset);
-					if (javaProposal instanceof LazyJavaTypeCompletionProposal) {
-						String completionPrefix = classNameStart.substring(classNameStart.length() - javaProposal.getReplacementLength());
-						int dotIndex = completionPrefix.lastIndexOf('.');
-						// match up to the last dot in order to make higher level matching still work (camel case...)
-						if (dotIndex != -1) {
-							javaProposal.setReplacementString(((LazyJavaTypeCompletionProposal) javaProposal).getQualifiedTypeName());
-						}
-					}
-					result.add(proposals[i]);
-				}
-			}
+            IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
+            for ( int i = 0; i < proposals.length; i++ ) {
+                if ( proposals[i] instanceof AbstractJavaCompletionProposal ) {
+                    AbstractJavaCompletionProposal javaProposal = (AbstractJavaCompletionProposal) proposals[i];
+                    int replacementOffset = documentOffset - (classNameStart.length() - javaProposal.getReplacementOffset());
+                    javaProposal.setReplacementOffset( replacementOffset );
+                    if ( javaProposal instanceof LazyJavaTypeCompletionProposal ) {
+                        String completionPrefix = classNameStart.substring( classNameStart.length() - javaProposal.getReplacementLength() );
+                        int dotIndex = completionPrefix.lastIndexOf( '.' );
+                        // match up to the last dot in order to make higher level matching still work (camel case...)
+                        if ( dotIndex != -1 ) {
+                            javaProposal.setReplacementString( ((LazyJavaTypeCompletionProposal) javaProposal).getQualifiedTypeName() );
+                        }
+                    }
+                    result.add( proposals[i] );
+                }
+            }
         } catch ( Throwable t ) {
             DroolsEclipsePlugin.log( t );
         }
-		return result;
+        return result;
     }
 
     protected List getPossibleProposals(ITextViewer viewer,
@@ -188,112 +200,161 @@
                                         String backText,
                                         final String prefix) {
         List list = new ArrayList();
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "rule", NEW_RULE_TEMPLATE, 6));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "import", "import "));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "expander", "expander "));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "global", "global "));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "package", "package "));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "query", NEW_QUERY_TEMPLATE));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "function", NEW_FUNCTION_TEMPLATE, 14));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "template", NEW_TEMPLATE_TEMPLATE, 9));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "dialect \"java\"", "dialect \"java\" "));
-        list.add(new RuleCompletionProposal(documentOffset - prefix.length(), prefix.length(), "dialect \"mvel\"", "dialect \"mvel\" "));
-        filterProposalsOnPrefix(prefix, list);
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "rule",
+                                              NEW_RULE_TEMPLATE,
+                                              6 ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "import",
+                                              "import " ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "expander",
+                                              "expander " ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "global",
+                                              "global " ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "package",
+                                              "package " ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "query",
+                                              NEW_QUERY_TEMPLATE ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "function",
+                                              NEW_FUNCTION_TEMPLATE,
+                                              14 ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "template",
+                                              NEW_TEMPLATE_TEMPLATE,
+                                              9 ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "dialect \"java\"",
+                                              "dialect \"java\" " ) );
+        list.add( new RuleCompletionProposal( documentOffset - prefix.length(),
+                                              prefix.length(),
+                                              "dialect \"mvel\"",
+                                              "dialect \"mvel\" " ) );
+        filterProposalsOnPrefix( prefix,
+                                 list );
         return list;
     }
 
-	protected List getJavaCompletionProposals(final int documentOffset, final String javaText, final String prefix, Map params) {
-		final List list = new ArrayList();
-		requestJavaCompletionProposals(javaText, prefix, documentOffset, params, list);
-		return list;
-	}
+    protected List getJavaCompletionProposals(final int documentOffset,
+                                              final String javaText,
+                                              final String prefix,
+                                              Map params) {
+        final List list = new ArrayList();
+        requestJavaCompletionProposals( javaText,
+                                        prefix,
+                                        documentOffset,
+                                        params,
+                                        list );
+        return list;
+    }
 
     /**
      * @return a list of "MVELified" RuleCompletionProposal. That list contains only unique 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 Collection getJavaMvelCompletionProposals(final int documentOffset, final String javaText, final String prefix, Map params) {
-    	final List list = new ArrayList();
-		requestJavaCompletionProposals(javaText, prefix, documentOffset, params, list);
+    protected Collection getJavaMvelCompletionProposals(final int documentOffset,
+                                                        final String javaText,
+                                                        final String prefix,
+                                                        Map params) {
+        final List list = new ArrayList();
+        requestJavaCompletionProposals( javaText,
+                                        prefix,
+                                        documentOffset,
+                                        params,
+                                        list );
 
-		Collection mvelList = mvelifyProposals(list);
-		return mvelList;
-	}
+        Collection mvelList = mvelifyProposals( list );
+        return mvelList;
+    }
 
-
     /*
      * Filters accessor method proposals to replace them with their mvel expression equivalent
      * For instance a completion for getStatus() would be replaced by a completion for status
      */
-	private static Collection mvelifyProposals(List list) {
-		final Collection set = new HashSet();
+    private static Collection mvelifyProposals(List list) {
+        final Collection set = new HashSet();
 
-		for (Iterator iter = list.iterator(); iter.hasNext();) {
-			Object o = iter.next();
-			if (o instanceof JavaMethodCompletionProposal) {
-				LazyJavaCompletionProposal javaProposal = (LazyJavaCompletionProposal) o;
-				//TODO: FIXME: this is very fragile ass it uses reflection to access the private completion field.
-				//Yet this is needed to do mvel filtering based on the method signtures, IF we use the richer JDT completion
-				Object field = ReflectionUtils.getField(o, "fProposal");
-				if (field != null && field instanceof CompletionProposal) {
-					CompletionProposal proposal = (CompletionProposal) field;
+        for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
+            Object o = iter.next();
+            if ( o instanceof JavaMethodCompletionProposal ) {
+                LazyJavaCompletionProposal javaProposal = (LazyJavaCompletionProposal) o;
+                //TODO: FIXME: this is very fragile ass it uses reflection to access the private completion field.
+                //Yet this is needed to do mvel filtering based on the method signtures, IF we use the richer JDT completion
+                Object field = ReflectionUtils.getField( o,
+                                                         "fProposal" );
+                if ( field != null && field instanceof CompletionProposal ) {
+                    CompletionProposal proposal = (CompletionProposal) field;
 
-					String completion = new String(proposal.getCompletion());
+                    String completion = new String( proposal.getCompletion() );
 
-					// get the eventual property name for that method name and signature
-					String propertyOrMethodName = CompletionUtil.getPropertyName(
-							completion, proposal.getSignature());
+                    // get the eventual property name for that method name and signature
+                    String propertyOrMethodName = CompletionUtil.getPropertyName( completion,
+                                                                                  proposal.getSignature() );
                     //if we got a proeprty name that differs from the orginal method name
                     //, this is a a bean accessor
-					boolean isAccessor = !completion.equals(propertyOrMethodName);
+                    boolean isAccessor = !completion.equals( propertyOrMethodName );
 
-					// is the completion for a bean accessor? and do we have already some relevant completion?
-					if (isAccessor && doesNotContainFieldCompletion(propertyOrMethodName, list)) {
+                    // is the completion for a bean accessor? and do we have already some relevant completion?
+                    if ( isAccessor && doesNotContainFieldCompletion( propertyOrMethodName,
+                                                                      list ) ) {
                         //TODO: craft a better JDTish display name
-						RuleCompletionProposal prop = new RuleCompletionProposal(
-								javaProposal.getReplacementOffset(),
-								javaProposal.getReplacementLength(),
-								propertyOrMethodName);
-						prop.setImage(DefaultCompletionProcessor.VARIABLE_ICON);
-						set.add(prop);
+                        RuleCompletionProposal prop = new RuleCompletionProposal( javaProposal.getReplacementOffset(),
+                                                                                  javaProposal.getReplacementLength(),
+                                                                                  propertyOrMethodName );
+                        prop.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
+                        prop.setPriority( 1000 );
+                        set.add( prop );
 
-					} else {
-						set.add(o);
-					}
-				}
+                    } else {
+                        set.add( o );
+                    }
+                }
 
-			} else {
-				//add other proposals as is
-				set.add(o);
-			}
-		}
-		return set;
-	}
+            } else {
+                //add other proposals as is
+                set.add( o );
+            }
+        }
+        return set;
+    }
 
-	/*
-	 * do we already have a completion for that string that would be either a local variable or a field?
-	 */
-	private static boolean doesNotContainFieldCompletion(String completion, List completions) {
-		if (completion == null || completion.length() == 0 || completions == null ){
-			return false;
-		}
-		for (Iterator iter = completions.iterator(); iter.hasNext();) {
-			Object o = iter.next();
-			if (o instanceof AbstractJavaCompletionProposal) {
-				AbstractJavaCompletionProposal prop = (AbstractJavaCompletionProposal) o;
-				String content = prop.getReplacementString();
-				if (completion.equals(content)) {
-					IJavaElement javaElement = prop.getJavaElement();
-					if (javaElement instanceof ILocalVariable
-							|| javaElement instanceof IField) {
-						return false;
-					}
-				}
-			}
-		}
-		return true;
-	}
+    /*
+     * do we already have a completion for that string that would be either a local variable or a field?
+     */
+    private static boolean doesNotContainFieldCompletion(String completion,
+                                                         List completions) {
+        if ( completion == null || completion.length() == 0 || completions == null ) {
+            return false;
+        }
+        for ( Iterator iter = completions.iterator(); iter.hasNext(); ) {
+            Object o = iter.next();
+            if ( o instanceof AbstractJavaCompletionProposal ) {
+                AbstractJavaCompletionProposal prop = (AbstractJavaCompletionProposal) o;
+                String content = prop.getReplacementString();
+                if ( completion.equals( content ) ) {
+                    IJavaElement javaElement = prop.getJavaElement();
+                    if ( javaElement instanceof ILocalVariable || javaElement instanceof IField ) {
+                        return false;
+                    }
+                }
+            }
+        }
+        return true;
+    }
 
     protected void requestJavaCompletionProposals(final String javaText,
                                                   final String prefix,
@@ -301,20 +362,20 @@
                                                   Map params,
                                                   Collection results) {
 
-		String javaTextWithoutPrefix = getTextWithoutPrefix( javaText,
-                                                             prefix );
-		// boolean to filter default Object methods produced by code completion when in the beginning of a statement
-		boolean filterObjectMethods = false;
-		if ("".equals(javaTextWithoutPrefix.trim()) || START_OF_NEW_JAVA_STATEMENT.matcher(javaTextWithoutPrefix).matches()) {
-			filterObjectMethods = true;
-		}
-		IJavaProject javaProject = getCurrentJavaProject();
-		if (javaProject ==null) {
-			return ;
-		}
+        String javaTextWithoutPrefix = CompletionUtil.getTextWithoutPrefix( javaText,
+                                                                            prefix );
+        // boolean to filter default Object methods produced by code completion when in the beginning of a statement
+        boolean filterObjectMethods = false;
+        if ( "".equals( javaTextWithoutPrefix.trim() ) || START_OF_NEW_JAVA_STATEMENT.matcher( javaTextWithoutPrefix ).matches() ) {
+            filterObjectMethods = true;
+        }
+        IJavaProject javaProject = getCurrentJavaProject();
+        if ( javaProject == null ) {
+            return;
+        }
 
-		CompletionProposalCollector	collector = new CompletionProposalCollector(javaProject);
-		collector.acceptContext(new CompletionContext());
+        CompletionProposalCollector collector = new CompletionProposalCollector( javaProject );
+        collector.acceptContext( new CompletionContext() );
 
         try {
             IEvaluationContext evalContext = javaProject.newEvaluationContext();
@@ -336,42 +397,30 @@
             evalContext.codeComplete( text,
                                       text.length(),
                                       collector );
-			IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
-			for (int i = 0; i < proposals.length; i++) {
-				if (proposals[i] instanceof AbstractJavaCompletionProposal) {
-					AbstractJavaCompletionProposal javaProposal = (AbstractJavaCompletionProposal) proposals[i];
-					int replacementOffset = documentOffset - (text.length() - javaProposal.getReplacementOffset());
-					javaProposal.setReplacementOffset(replacementOffset);
-					if (javaProposal instanceof LazyJavaTypeCompletionProposal) {
-						String completionPrefix = javaText.substring(javaText.length() - javaProposal.getReplacementLength());
-						int dotIndex = completionPrefix.lastIndexOf('.');
-						// match up to the last dot in order to make higher level matching still work (camel case...)
-						if (dotIndex != -1) {
-							javaProposal.setReplacementString(((LazyJavaTypeCompletionProposal) javaProposal).getQualifiedTypeName());
-						}
-					}
-					if (!filterObjectMethods || !(proposals[i] instanceof JavaMethodCompletionProposal)) {
-						results.add(proposals[i]);
-					}
-				}
-			}
+            IJavaCompletionProposal[] proposals = collector.getJavaCompletionProposals();
+            for ( int i = 0; i < proposals.length; i++ ) {
+                if ( proposals[i] instanceof AbstractJavaCompletionProposal ) {
+                    AbstractJavaCompletionProposal javaProposal = (AbstractJavaCompletionProposal) proposals[i];
+                    int replacementOffset = documentOffset - (text.length() - javaProposal.getReplacementOffset());
+                    javaProposal.setReplacementOffset( replacementOffset );
+                    if ( javaProposal instanceof LazyJavaTypeCompletionProposal ) {
+                        String completionPrefix = javaText.substring( javaText.length() - javaProposal.getReplacementLength() );
+                        int dotIndex = completionPrefix.lastIndexOf( '.' );
+                        // match up to the last dot in order to make higher level matching still work (camel case...)
+                        if ( dotIndex != -1 ) {
+                            javaProposal.setReplacementString( ((LazyJavaTypeCompletionProposal) javaProposal).getQualifiedTypeName() );
+                        }
+                    }
+                    if ( !filterObjectMethods || !(proposals[i] instanceof JavaMethodCompletionProposal) ) {
+                        results.add( proposals[i] );
+                    }
+                }
+            }
         } catch ( Throwable t ) {
             DroolsEclipsePlugin.log( t );
         }
     }
 
-    public static String getTextWithoutPrefix(final String javaText,
-                                              final String prefix) {
-        int endIndex = javaText.length() - prefix.length();
-        String javaTextWithoutPrefix = javaText;
-        //javaText can be an empty string.
-        if ( endIndex > 0 ) {
-            javaTextWithoutPrefix = javaText.substring( 0,
-                                                        endIndex );
-        }
-        return javaTextWithoutPrefix;
-    }
-
     protected String getPackage() {
         if ( getEditor() instanceof DRLRuleEditor ) {
             return ((DRLRuleEditor) getEditor()).getPackage();
@@ -387,9 +436,9 @@
     }
 
     protected Set getUniqueImports() {
-            HashSet set = new HashSet();
-			set.addAll(getImports());
-			return set;
+        HashSet set = new HashSet();
+        set.addAll( getImports() );
+        return set;
     }
 
     protected List getFunctions() {

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-10-02 21:16:19 UTC (rev 15516)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProcessor.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -9,6 +9,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
 
 import org.drools.base.ClassTypeResolver;
 import org.drools.compiler.PackageBuilderConfiguration;
@@ -133,7 +134,7 @@
         }
 
         boolean startOfDialectExpression = isStartOfDialectExpression( consequenceWithoutPrefix );
-        if ( startOfDialectExpression ) {
+        if ( isJavaDialect() && startOfDialectExpression ) {
             addRHSKeywordCompletionProposals( list,
                                               documentOffset,
                                               prefix );
@@ -939,11 +940,11 @@
         list.addAll( mvelCompletionProposals );
     }
 
-    private Collection getMvelCompletionProposals(final String consequence,
+    private Collection getMvelCompletionProposals(final String consequenceBackText,
                                                   final int documentOffset,
                                                   final String prefix,
                                                   Map params,
-                                                  String backText,
+                                                  String ruleBackText,
                                                   boolean startOfExpression) {
 
         final Set proposals = new HashSet();
@@ -952,68 +953,132 @@
             return proposals;
         }
 
-        String mvelTextWithoutPrefix = getTextWithoutPrefix( consequence,
-                                                             prefix );
-
-        String compilableConsequence = CompletionUtil.getCompilableText( mvelTextWithoutPrefix );
-        MVELConsequenceBuilder builder = new MVELConsequenceBuilder();
-        compilableConsequence = builder.processMacros( compilableConsequence );
-
-        // attempt to compile and analyze
         try {
             DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( (DRLRuleEditor) getEditor(),
                                                                               true,
                                                                               true );
 
-            ParserContext compilationContext = createMvelAnalysisContext( params,
-                                                                          drlInfo,
-                                                                          compilableConsequence );
+            String textWithoutPrefix = CompletionUtil.getTextWithoutPrefix( consequenceBackText,
+                                                                            prefix );
+            boolean expressionStart = isStartOfDialectExpression( textWithoutPrefix );
+            System.out.println("start of expre:"+expressionStart);
 
-            if ( startOfExpression ) {
+            boolean isConstrained = textWithoutPrefix.endsWith( "." );
+
+            // we split the expression in various regions:
+            // *the previous expression
+            // *the last expression
+            // *the last inner expression
+
+            // attempt to compile and analyze the previous expression to collect inputs and vars
+            String previousExpression = CompletionUtil.getPreviousExpression( consequenceBackText );
+            MvelContext previousExprContext = analyzeMvelExpression( getResolvedMvelInputs( params ),
+                                                                     drlInfo,
+                                                                     previousExpression );
+
+            // attempt to compile and analyze the last and last inner expression, using as inputs the previous expression inputs and vars
+            Map variables = previousExprContext.getContext().getVariables();
+            Map inputs = previousExprContext.getContext().getInputs();
+            inputs.putAll( variables );
+
+            //last inner expression
+            String lastInnerExpression = CompletionUtil.getTextWithoutPrefix( CompletionUtil.getInnerExpression( consequenceBackText ),
+                                                                              prefix );
+            System.out.println( "Lastinner:" + lastInnerExpression );
+            String compilableLastInnerExpression = CompletionUtil.getCompilableText( lastInnerExpression );
+
+            MvelContext lastInnerExprContext = analyzeMvelExpression( inputs,
+                                                                      drlInfo,
+                                                                      compilableLastInnerExpression );
+
+            //last expression
+            String lastExpression = CompletionUtil.getLastExpression( consequenceBackText ).trim();
+            System.out.println( "Last:" + lastExpression );
+            //is this a modify expression?
+            //group 1 is the body of modify
+            //group 2 if present is the whole with block including brackets
+            //group 3 if present is the inner content of the with block
+            Matcher modMatcher = CompletionUtil.MODIFY_PATTERN.matcher( lastExpression );
+
+            boolean isModifyBlock = modMatcher.matches() && modMatcher.groupCount() == 3;
+
+            //if constrained, get completion for egress of last inner, filtered on prefix
+            if ( isConstrained ) {
+                System.out.println( "constrained" );
+                return getMvelCompletionsFromJDT( documentOffset,
+                                                  "",
+                                                  params,
+                                                  lastInnerExprContext.getReturnedType() );
+            }
+            //if expression start inside with block, then get completion for prefix with egrss of modif var + prev expr var&inputs
+            else if ( expressionStart && isModifyBlock ) {
+                System.out.println( "modify block start" );
+                System.out.println( "match" );
+                String modifyVar = modMatcher.group( 1 );
+                //String modifyWith = modMatcher.group( 3 );
+
+                //get the egress type of the modify var
+                MvelContext modVarContext = analyzeMvelExpression( inputs,
+                                                                   drlInfo,
+                                                                   modifyVar );
+
+                Class modVarType = modVarContext.getReturnedType();
+                System.out.println( "modVarType:" + modVarType );
+
+                Collection modVarComps = getMvelCompletionsFromJDT( documentOffset,
+                                                                    "",
+                                                                    params,
+                                                                    modVarType );
+
+                //set high prio on those
+                proposals.addAll( modVarComps );
+
+                addMvelCompletions( proposals,
+                                    documentOffset,
+                                    "",
+                                    lastInnerExprContext.getContext().getVariables() );
+
+                addMvelCompletions( proposals,
+                                    documentOffset,
+                                    "",
+                                    lastInnerExprContext.getContext().getInputs() );
+
                 Collection jdtProps = getJavaCompletionProposals( documentOffset,
                                                                   prefix,
                                                                   prefix,
                                                                   params );
+
                 proposals.addAll( jdtProps );
 
+            }
+            //If expression start, then get completion for prefix with prev expr var&inputs
+            else if ( expressionStart ) {
                 addMvelCompletions( proposals,
                                     documentOffset,
                                     prefix,
-                                    compilationContext.getVariables() );
+                                    lastInnerExprContext.getContext().getVariables() );
 
                 addMvelCompletions( proposals,
                                     documentOffset,
                                     prefix,
-                                    compilationContext.getInputs() );
+                                    lastInnerExprContext.getContext().getInputs() );
 
-            } else {
-                // we are completing the methods for an existing type or
-                // variable, we need find the last type in the expression to complete against
+                Collection jdtProps = getJavaCompletionProposals( documentOffset,
+                                                                  prefix,
+                                                                  prefix,
+                                                                  params );
 
-                if ( !"".equals( compilableConsequence.trim() ) ) {
-                    Class lastType = context.getMvelReturnedType();
-                    if ( lastType == null ) {
-                        lastType = Object.class;
-                    }
+                proposals.addAll( jdtProps );
 
-                    //FIXME: there is a small chance of var name collision using this arbitrary mvdrlofc as a variable name.
-                    //ideally the varibale name should be inferred from the last memeber of the expression
-                    String syntheticVarName = "mvdrlofc";
-                    String javaText = "\n" + lastType.getName().replace( '$',
-                                                                         '.' ) + " " + syntheticVarName + ";\n" + syntheticVarName + ".";
-                    Collection jdtProps = getJavaMvelCompletionProposals( documentOffset,
-                                                                          javaText,
-                                                                          prefix,
-                                                                          params );
-                    proposals.addAll( jdtProps );
-                }
             }
 
         } catch ( Throwable e ) {
             DroolsEclipsePlugin.log( e );
         }
-
-        return proposals;
+        Set uniqueProposals = new HashSet();
+        addAllNewProposals( uniqueProposals,
+                            proposals );
+        return uniqueProposals;
     }
 
     private Map getResolvedMvelInputs(Map params) {
@@ -1035,112 +1100,212 @@
         return resolved;
     }
 
-    private ParserContext createMvelAnalysisContext(Map params,
-                                                    DRLInfo drlInfo,
-                                                    String compilableConsequence) {
-        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;
+    class MvelContext {
+        private CompiledExpression expression;
+        private ParserContext      initialContext;
+        private Class              returnedType;
+
+        public ParserContext getContext() {
+            if ( getExpression() != null ) {
+                if ( getExpression().getParserContext() != null ) {
+                    return getExpression().getParserContext();
+                }
             }
+            return getInitialContext();
         }
-        MVELDialect dialect = (MVELDialect) currentRule.getDialect();
 
-        final ParserContext initialContext = new ParserContext( dialect.getImports(),
-                                                               null,
-                                                               drlInfo.getPackageName() + "." + currentRule.getRuleName() );
+        void setExpression(CompiledExpression expression) {
+            this.expression = expression;
+        }
 
-        for ( Iterator it = dialect.getPackgeImports().values().iterator(); it.hasNext(); ) {
-            String packageImport = (String) it.next();
-            initialContext.addPackageImport( packageImport );
+        CompiledExpression getExpression() {
+            return expression;
         }
 
-        try {
+        void setInitialContext(ParserContext initialContext) {
+            this.initialContext = initialContext;
+        }
 
-            initialContext.setStrictTypeEnforcement( dialect.isStrictMode() );
+        ParserContext getInitialContext() {
+            return initialContext;
+        }
 
-            initialContext.setInterceptors( dialect.getInterceptors() );
-            initialContext.setInputs( getResolvedMvelInputs( params ) );
-            initialContext.addInput( "drools",
-                                    KnowledgeHelper.class );
-            initialContext.setCompiled( true );
+        void setReturnedType(Class returnedType) {
+            this.returnedType = returnedType;
+        }
 
-            //compile the expression
-            ExpressionCompiler compiler = new ExpressionCompiler( compilableConsequence );
+        Class getReturnedType() {
+            return returnedType;
+        }
+    }
+
+    private MvelContext analyzeMvelExpression(Map params,
+                                              DRLInfo drlInfo,
+                                              String mvel) {
+
+        String macroMvel = processMacros( mvel );
+
+        String name = context.getRule().getName();
+        RuleInfo currentRule = getCurrentRule( drlInfo,
+                                               name );
+        String qName = drlInfo.getPackageName() + "." + currentRule.getRuleName();
+        MVELDialect dialect = (MVELDialect) currentRule.getDialect();
+        ParserContext initialContext = createInitialContext( params,
+                                                             qName,
+                                                             dialect );
+        MvelContext mCon = new MvelContext();
+        mCon.setInitialContext( initialContext );
+
+        try {
+            ExpressionCompiler compiler = new ExpressionCompiler( macroMvel );
             CompiledExpression expression = compiler.compile( initialContext );
+            mCon.setExpression( expression );
+
             ParserContext compilationContext = compiler.getParserContextState();
 
             Class lastType = expression.getKnownEgressType();
             if ( lastType == null ) {
                 lastType = Object.class;
+                //                mCon.setReturnedType( lastType );
             }
-            context.setMvelReturnedType( lastType );
 
             if ( "java.lang.Object".equals( lastType.getName() ) ) {
                 // attempt to use the property verifier to get
-                // a better type  resolution (a recommend by cbrock, though egress gives consistent results
-                String lastExpression = CompletionUtil.getLastLine( compilableConsequence );
-                lastType = new PropertyVerifier( lastExpression,
+                // a better type  resolution (a recommend by cbrock, though egress gives consistent results)
+                //String lastExpression = CompletionUtil.getLastLine( macroMvel );
+                lastType = new PropertyVerifier( macroMvel,
                                                  compilationContext ).analyze();
             }
 
-            return compilationContext;
+            mCon.setReturnedType( lastType );
         } catch ( Exception e ) {
-            return initialContext;
+            //TODO: Log me?
+            //            DroolsEclipsePlugin.log( e );
         }
+        return mCon;
     }
 
+    private static ParserContext createInitialContext(Map params,
+                                                      String qualifiedName,
+                                                      MVELDialect dialect) {
+
+        final ParserContext context = new ParserContext( dialect.getImports(),
+                                                         null,
+                                                         qualifiedName );
+
+        for ( Iterator it = dialect.getPackgeImports().values().iterator(); it.hasNext(); ) {
+            String packageImport = (String) it.next();
+            context.addPackageImport( packageImport );
+        }
+        context.setStrictTypeEnforcement( false );
+
+        context.setInterceptors( dialect.getInterceptors() );
+        context.setInputs( params );
+        context.addInput( "drools",
+                          KnowledgeHelper.class );
+        context.setCompiled( true );
+        return context;
+    }
+
+    private String processMacros(String mvel) {
+        MVELConsequenceBuilder builder = new MVELConsequenceBuilder();
+        String macrosProcessedCompilableConsequence = builder.processMacros( mvel.trim() );
+        return macrosProcessedCompilableConsequence;
+    }
+
+    private RuleInfo getCurrentRule(DRLInfo drlInfo,
+                                    String currentRulename) {
+        RuleInfo currentRule = null;
+        RuleInfo[] ruleInfos = drlInfo.getRuleInfos();
+        for ( int i = 0; i < ruleInfos.length; i++ ) {
+            if ( currentRulename.equals( ruleInfos[i].getRuleName() ) ) {
+                currentRule = ruleInfos[i];
+                break;
+            }
+        }
+        return currentRule;
+    }
+
+    private Collection getMvelCompletionsFromJDT(final int documentOffset,
+                                                 final String prefix,
+                                                 Map params,
+                                                 Class lastType) {
+        if ( lastType == null ) {
+            lastType = Object.class;
+        }
+
+        //FIXME: there is a small chance of var name collision using this arbitrary mvdrlofc as a variable name.
+        //ideally the variable name should be inferred from the last member of the expression
+        String syntheticVarName = "mvdrlofc";
+        String javaText = "\n" + lastType.getName().replace( '$',
+                                                             '.' ) + " " + syntheticVarName + ";\n" + syntheticVarName + ".";
+        Collection jdtProps = getJavaMvelCompletionProposals( documentOffset,
+                                                              javaText,
+                                                              prefix,
+                                                              params );
+        return jdtProps;
+    }
+
     private void addMvelCompletions(final Collection proposals,
                                     int documentOffset,
                                     String prefix,
                                     Map inputs) {
+        Set newProposals = new HashSet();
         for ( Iterator iter = inputs.entrySet().iterator(); iter.hasNext(); ) {
             Map.Entry entry = (Map.Entry) iter.next();
             String prop = (String) entry.getKey();
 
-            //JBRULES-1134 do not add completions if they already exist
-            if (containsProposal( proposals, prop )) {
-                continue ;
-            }
-
             Class type = (Class) entry.getValue();
-            String display = prop + " - " + type.getName().replace( '$',
-                                                                    '.' );
+            String display = prop + "  " + CompletionUtil.getSimpleClassName( type );
 
             RuleCompletionProposal rcp = new RuleCompletionProposal( documentOffset - prefix.length(),
                                                                      prefix.length(),
                                                                      display,
                                                                      prop );
             rcp.setImage( DefaultCompletionProcessor.VARIABLE_ICON );
-            proposals.add( rcp );
+            newProposals.add( rcp );
         }
+        addAllNewProposals( proposals,
+                            newProposals );
     }
 
+    public static void addAllNewProposals(final Collection proposals,
+                                          final Collection newProposals) {
+        for ( Iterator iter = newProposals.iterator(); iter.hasNext(); ) {
+            ICompletionProposal newProp = (ICompletionProposal) iter.next();
+            String displayString = newProp.getDisplayString();
+
+            //JBRULES-1134 do not add completions if they already exist
+            if ( !containsProposal( proposals,
+                                    displayString ) ) {
+                proposals.add( newProp );
+            }
+        }
+    }
+
     /**
      * Attempt to compare proposals of different types based on the tokenized display string
      * @param proposals
      * @param newProposal
-     * @return true if the collection contains a prposal which matches the new Proposal.
+     * @return true if the collection contains a proposal which matches the new Proposal.
      * The match is based on the first token based on a space split
      */
-    boolean containsProposal(final Collection proposals, String newProposal) {
+    public static boolean containsProposal(final Collection proposals,
+                                           String newProposal) {
         for ( Iterator iter = proposals.iterator(); iter.hasNext(); ) {
             ICompletionProposal prop = (ICompletionProposal) iter.next();
             String displayString = prop.getDisplayString();
             String[] existings = displayString.split( " " );
-            if (existings.length == 0) {
+            if ( existings.length == 0 ) {
                 continue;
             }
 
             String[] newProposals = newProposal.split( " " );
-            if (newProposals.length == 0) {
+            if ( newProposals.length == 0 ) {
                 continue;
             }
 
-            if (existings[0].equals( newProposals[0] )) {
+            if ( existings[0].equals( newProposals[0] ) ) {
                 return true;
             }
         }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java	2007-10-02 21:16:19 UTC (rev 15516)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/RuleCompletionProposal.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -15,39 +15,76 @@
  * @author Michael Neale
  *
  */
-public class RuleCompletionProposal implements ICompletionProposal {
+public class RuleCompletionProposal
+    implements
+    ICompletionProposal {
 
     private String content;
     private String display;
-    private int replacementOffset;
-    private int replacementLength;
-    private int cursorPosition;
-    private Image image;
-    private int priority;
+    private int    replacementOffset;
+    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 replacementOffset, int replacementLength, String content) {
-        this(replacementOffset, replacementLength, content, content);
+    public RuleCompletionProposal(int replacementOffset,
+                                  int replacementLength,
+                                  String content) {
+        this( replacementOffset,
+              replacementLength,
+              content,
+              content );
     }
 
     /** This is used when a different display value is shown to what is put in when selected. */
-    public RuleCompletionProposal(int replacementOffset, int replacementLength, String display, String content) {
-        this(replacementOffset, replacementLength, display, content, content.length());
+    public RuleCompletionProposal(int replacementOffset,
+                                  int replacementLength,
+                                  String display,
+                                  String content) {
+        this( replacementOffset,
+              replacementLength,
+              display,
+              content,
+              content.length() );
     }
 
     /** Also allows an icon to be used */
-    public RuleCompletionProposal(int replacementOffset, int replacementLength, String display, String content, Image image) {
-        this(replacementOffset, replacementLength, display, content, content.length(), image);
+    public RuleCompletionProposal(int replacementOffset,
+                                  int replacementLength,
+                                  String display,
+                                  String content,
+                                  Image image) {
+        this( replacementOffset,
+              replacementLength,
+              display,
+              content,
+              content.length(),
+              image );
     }
 
-    public RuleCompletionProposal(int replacementOffset, int replacementLength, String display, String content, int cursorPosition) {
-    	this(replacementOffset, replacementLength, display, content, cursorPosition, null);
+    public RuleCompletionProposal(int replacementOffset,
+                                  int replacementLength,
+                                  String display,
+                                  String content,
+                                  int cursorPosition) {
+        this( replacementOffset,
+              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 replacementOffset, int replacementLength, String display, String content, int cursorPosition, Image image) {
-    	this.replacementOffset = replacementOffset;
-    	this.replacementLength = replacementLength;
+    public RuleCompletionProposal(int replacementOffset,
+                                  int replacementLength,
+                                  String display,
+                                  String content,
+                                  int cursorPosition,
+                                  Image image) {
+        this.replacementOffset = replacementOffset;
+        this.replacementLength = replacementLength;
         this.content = content;
         this.display = display;
         this.cursorPosition = cursorPosition;
@@ -70,9 +107,9 @@
         return image;
     }
 
-	public String getContent() {
-		return content;
-	}
+    public String getContent() {
+        return content;
+    }
 
     public void setImage(Image image) {
         this.image = image;
@@ -90,54 +127,59 @@
         return content;
     }
 
-    //TODO:fixme now that we mix,JDT  and own propsals, comparison is all wrong, resulting in wrong ordering of mixed proposals (such as with mvel
-    public static class RuleCompletionProposalComparator implements Comparator {
-		public int compare(Object arg0, Object arg1) {
-			if (arg0 instanceof RuleCompletionProposal) {
-				if (arg1 instanceof RuleCompletionProposal) {
-					RuleCompletionProposal prop0 = (RuleCompletionProposal) arg0;
-					RuleCompletionProposal prop1 = (RuleCompletionProposal) arg1;
-					if (prop0.getPriority() == prop1.getPriority()) {
-						return prop0.display.compareTo(prop1.display);
-					} else if (prop0.getPriority() > prop1.getPriority()) {
-						return -1;
-					} else {
-						return 1;
-					}
-				} else {
-					return -1;
-				}
-			} else {
-				if (arg1 instanceof RuleCompletionProposal) {
-					return 1;
-				}
-				return 0;
-			}
-		}
+    //TODO:fixme now that we mix JDT and own proposals, comparison is all wrong, resulting in wrong ordering of mixed proposals (such as with mvel
+    public static class RuleCompletionProposalComparator
+        implements
+        Comparator {
+        public int compare(Object arg0,
+                           Object arg1) {
+            if ( arg0 instanceof RuleCompletionProposal ) {
+                if ( arg1 instanceof RuleCompletionProposal ) {
+                    RuleCompletionProposal prop0 = (RuleCompletionProposal) arg0;
+                    RuleCompletionProposal prop1 = (RuleCompletionProposal) arg1;
+                    if ( prop0.getPriority() == prop1.getPriority() ) {
+                        return prop0.display.compareTo( prop1.display );
+                    } else if ( prop0.getPriority() > prop1.getPriority() ) {
+                        return -1;
+                    } else {
+                        return 1;
+                    }
+                } else {
+                    return -1;
+                }
+            } else {
+                if ( arg1 instanceof RuleCompletionProposal ) {
+                    return 1;
+                }
+                return 0;
+            }
+        }
     }
 
-	public void apply(IDocument document) {
-		try {
-			document.replace(replacementOffset, replacementLength, content);
-		} catch (BadLocationException x) {
-			// ignore
-		}
-	}
+    public void apply(IDocument document) {
+        try {
+            document.replace( replacementOffset,
+                              replacementLength,
+                              content );
+        } catch ( BadLocationException x ) {
+            // ignore
+        }
+    }
 
-	public String getAdditionalProposalInfo() {
-		return null;
-	}
+    public String getAdditionalProposalInfo() {
+        return null;
+    }
 
-	public IContextInformation getContextInformation() {
-		return null;
-	}
+    public IContextInformation getContextInformation() {
+        return null;
+    }
 
-	public String getDisplayString() {
-		if (display != null) {
-			return display;
-		}
-		return content;
-	}
+    public String getDisplayString() {
+        if ( display != null ) {
+            return display;
+        }
+        return content;
+    }
 
     public int hashCode() {
         final int PRIME = 31;
@@ -161,7 +203,8 @@
         return true;
     }
 
-	public Point getSelection(IDocument document) {
-		return new Point(replacementOffset + cursorPosition, 0);
-	}
+    public Point getSelection(IDocument document) {
+        return new Point( replacementOffset + cursorPosition,
+                          0 );
+    }
 }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java	2007-10-02 21:16:19 UTC (rev 15516)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/CompletionUtilTest.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -154,4 +154,269 @@
     	String lastword = "last";
     	assertEquals(lastword, CompletionUtil.stripLastWord(backtext));
     }
+
+    public void testGetPreviousExpression1() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';";
+        String previous =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';";
+        assertEquals(previous, CompletionUtil.getPreviousExpression( backText ));
+    }
+
+    public void testGetPreviousExpression2() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message== ";
+        String previous =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;";
+        assertEquals(previous, CompletionUtil.getPreviousExpression( backText ));
+    }
+
+    public void testGetPreviousExpression3() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message(sdasdasd, ";
+        String previous =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;";
+        assertEquals(previous, CompletionUtil.getPreviousExpression( backText ));
+    }
+
+    public void testGetPreviousExpression4() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message( ";
+        String previous =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;";
+        assertEquals(previous, CompletionUtil.getPreviousExpression( backText ));
+    }
+
+    public void testGetPreviousExpression5() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   this.asd ";
+        String previous =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;";
+        assertEquals(previous, CompletionUtil.getPreviousExpression( backText ));
+    }
+
+    public void testGetPreviousExpression6() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message(){ ";
+        String previous =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;";
+        assertEquals(previous, CompletionUtil.getPreviousExpression( backText ));
+    }
+
+    public void testGetPreviousExpression7() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';message== ";
+        String previous =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';";
+        assertEquals(previous, CompletionUtil.getPreviousExpression( backText ));
+    }
+
+    public void testGetLastExpression11() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d'";
+        String previous = "\r\n" + "   adasd ='d'";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression1() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';";
+        String previous = "\r\n   adasd ='d'";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression10() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';\r\n";
+        assertEquals(backText, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression2() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message== ";
+        String previous = "\r\n   message== ";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression3() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message(sdasdasd, ";
+        String previous ="\r\n   message(sdasdasd, ";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression4() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message( ";
+        String previous ="\r\n   message( ";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression5() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   this.asd ";
+        String previous =   "\r\n   this.asd ";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression6() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   message(){ ";
+        String previous =  "\r\n   message(){ ";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetLastExpression7() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';message== ";
+        String previous ="message== ";
+        assertEquals(previous, CompletionUtil.getLastExpression( backText ));
+    }
+
+    public void testGetInnerExpression() {
+        String backText =
+            "  \r\n" +
+            "   System.out.println( message );\r\n" +
+            "   m.message = \"Goodbyte cruel world\";\r\n" +
+            "   m.status = 1;\r\n" +
+            "   adasd ='d';message== ";
+        String previous ="";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+
+    public void testGetInnerExpression2() {
+        String backText =
+            "System.out.println(m ";
+        String previous ="m";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+
+    public void testGetInnerExpression3() {
+        String backText =
+            "update(m) {";
+        String previous ="";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+
+    public void testGetInnerExpression4() {
+        String backText =
+            "update(m) {some=";
+        String previous ="";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+    public void testGetInnerExpression5() {
+        String backText =
+            "update(m) {asdasdas==asdasd, asdasd";
+        String previous ="asdasd";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+    public void testGetInnerExpression6() {
+        String backText =
+            "update(m) {asdasdas==asdasd, asdasd}";
+        String previous ="";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+
+    public void testGetTextWithoutPrefix() {
+        String text =
+            "modify(m) {asdasdas==asdasd, asdasd.asa";
+        String expected ="modify(m) {asdasdas==asdasd, asdasd.";
+        assertEquals(expected, CompletionUtil.getTextWithoutPrefix( text,"asa"));
+    }
+
+    public void testGetTextWithoutPrefix2() {
+        String text =
+            "it";
+        String expected ="";
+        assertEquals(expected, CompletionUtil.getTextWithoutPrefix( text,text));
+    }
+
+
 }
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MvelParsingTest.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MvelParsingTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/MvelParsingTest.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -0,0 +1,25 @@
+package org.drools.eclipse.editors.completion;
+
+import junit.framework.TestCase;
+
+public class MvelParsingTest extends TestCase {
+    public void testGetInnerExpression4() {
+        String backText =
+            "modify(m) {some=";
+        String previous ="";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+    public void testGetInnerExpression5() {
+        String backText =
+            "modify(m) {asdasdas==asdasd, asdasd";
+        String previous ="asdasd";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+    public void testGetInnerExpression6() {
+        String backText =
+            "modify(m) {asdasdas==asdasd, asdasd}";
+        String previous ="";
+        assertEquals(previous, CompletionUtil.getInnerExpression( backText ));
+    }
+
+}

Added: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/RuleCompletionProcessorTest.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/RuleCompletionProcessorTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-test/src/test/java/org/drools/eclipse/editors/completion/RuleCompletionProcessorTest.java	2007-10-02 21:45:59 UTC (rev 15517)
@@ -0,0 +1,91 @@
+package org.drools.eclipse.editors.completion;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+import junit.framework.TestCase;
+
+public class RuleCompletionProcessorTest extends TestCase {
+
+    class MockCompletionProposal implements ICompletionProposal {
+
+        String displayString;
+
+        public MockCompletionProposal(String displayString) {
+            this.displayString = displayString;
+        }
+
+        public void apply(IDocument document) {
+            // TODO Auto-generated method stub
+
+        }
+
+        public String getAdditionalProposalInfo() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public IContextInformation getContextInformation() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public String getDisplayString() {
+            return displayString;
+        }
+
+        public Image getImage() {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public Point getSelection(IDocument document) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+    }
+
+    public void testContainsProposal() {
+        Collection proposals = new ArrayList();
+
+        MockCompletionProposal c1 = new MockCompletionProposal("getName() Object - MyObject");
+        proposals.add (c1);
+
+        String newProposal ="getName() String - CompletionProposal";
+
+        assertTrue(RuleCompletionProcessor.containsProposal( proposals, newProposal ));
+
+        MockCompletionProposal c2 = new MockCompletionProposal("getNoName() Object - MyObject");
+        proposals.add (c2);
+        assertFalse(RuleCompletionProcessor.containsProposal( proposals, "getNoName"));
+    }
+
+    public void testAddAllNewProposals() {
+        ArrayList proposals = new ArrayList();
+        MockCompletionProposal c = new MockCompletionProposal("getName() Object - MyObject");
+        proposals.add (c);
+
+
+        ArrayList newProposals = new ArrayList();
+        MockCompletionProposal c1 = new MockCompletionProposal("getName() Objectw - MyObject");
+        newProposals.add (c1);
+        MockCompletionProposal c2 = new MockCompletionProposal("getNoName() Object - MyObject");
+        newProposals.add (c2);
+        MockCompletionProposal c3 = new MockCompletionProposal("getNoName() NoObject - MyObject");
+        newProposals.add (c3);
+
+        RuleCompletionProcessor.addAllNewProposals( proposals, newProposals );
+
+        assertTrue(proposals.size()==2);
+
+        ICompletionProposal prop = (ICompletionProposal) proposals.get( 1 );
+        assertEquals("getNoName() Object - MyObject", prop.getDisplayString());
+    }
+}




More information about the jboss-svn-commits mailing list