[jboss-svn-commits] JBL Code SVN: r9281 - labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 1 20:31:27 EST 2007


Author: woolfel
Date: 2007-02-01 20:31:27 -0500 (Thu, 01 Feb 2007)
New Revision: 9281

Modified:
   labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java
Log:
ok, merged the code into trunk. still need to test this and make sure it all works. I'm not sure it will work, since trunk is different than 3.0.5. If it breaks, it's all conan's fault.
peter

Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java	2007-02-02 01:29:08 UTC (rev 9280)
+++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/completion/RuleCompletionProcessor.java	2007-02-02 01:31:27 UTC (rev 9281)
@@ -90,7 +90,21 @@
         			addRHSJavaCompletionProposals(list, backText, prefix);
 	            }
 	        } else if (condition(backText) || query(backText)) {
-	        	List dslConditions = adapter.listConditionItems();
+	        	String lastobj = this.getLastNonDashLine(backText);
+	        	String last = this.getLastLine(backText);
+	        	// we have to check if the last line is when. if it is we set 
+	        	// the last line to zero length string
+	        	if (last.equals("when")) {
+	        		last = "";
+	        		lastobj = "*";
+	        	}
+	        	// pass the last string in the backText to getProposals
+	        	List dslConditions = this.getProposals(lastobj,last);
+	        	// if we couldn't find any matches, we add the list from
+	        	// the DSLAdapter so that there's something
+	        	if (dslConditions.size() == 0) {
+		        	dslConditions.addAll(adapter.listConditionItems());
+	        	}
 	        	addDSLProposals(list, prefix, dslConditions);
 	            addLHSCompletionProposals(viewer, list, adapter, prefix, backText);
 	        } else {             
@@ -658,4 +672,90 @@
     	}
     	return true;
     }
+    
+    /**
+     * because of how the backText works, we need to get the last line, so
+     * that we can pass it to the DSLUtility
+     * @param backText
+     * @return
+     */
+    public String getLastLine(String backText) {
+    	BufferedReader breader = new BufferedReader(new StringReader(backText));
+    	String last = "";
+    	String line = null;
+    	try {
+        	while ( (line = breader.readLine()) != null) {
+        		// only if the line has text do we set last to it
+        		if (line.length() > 0) {
+            		last = line;
+        		}
+        	}
+    	} catch (IOException e) {
+    		// TODO need to log this.
+    		// I'm leaving this for mic_hat, so he has something to do
+    	}
+    	// now that all the conditions for a single object are on the same line
+    	// we need to check for the left parenthesis
+    	if (last.indexOf("(") > -1) {
+    		last = last.substring(last.lastIndexOf("(") + 1);
+    	}
+    	// if the string has a comma "," we get the substring starting from
+    	// the index after the last comma
+    	if (last.indexOf(",") > -1) {
+    		last = last.substring(last.lastIndexOf(",") + 1);
+    	}
+    	// if the line ends with right parenthesis, we change it to zero length string
+    	if (last.endsWith(")")) {
+    		last = "";
+    	}
+    	return last;
+    }
+    
+    /**
+     * Returns the last line that doesn't start with a dash
+     * @param backText
+     * @return
+     */
+    public String getLastNonDashLine(String backText) {
+    	BufferedReader breader = new BufferedReader(new StringReader(backText));
+    	String last = "";
+    	String line = null;
+    	try {
+        	while ( (line = breader.readLine()) != null) {
+        		// there may be blank lines, so we trim first
+        		line = line.trim();
+        		// only if the line has text do we set last to it
+        		if (line.length() > 0 && !line.startsWith("-")) {
+            		last = line;
+        		}
+        	}
+    	} catch (IOException e) {
+    		// TODO need to log this.
+    		// I'm leaving this for mic_hat, so he has something to do
+    	}
+    	if (last.indexOf("(") > -1 && !last.endsWith(")")) {
+    		last = last.substring(0,last.indexOf("("));
+    	} else if (last.indexOf("(") > -1 && last.endsWith(")")) {
+    		last = "";
+    	}
+    	return last;
+    }
+    
+    /**
+     * The DSLTree is configurable. It can either return just the child
+     * of the last token found, or it can traverse the tree and generate
+     * all the combinations beneath the last matching node.
+     * TODO
+     * I don't know how to add configuration to the editor, so it needs
+     * to be hooked up to the configuration  for the editor later.
+     * 
+     * @param last
+     * @return
+     */
+    protected List getProposals(String obj,String last) {
+    	if (last.length() == 0) {
+    		last = " ";
+    	}
+    	return this.dslTree.getChildrenList(obj,last,false);
+    }
 }




More information about the jboss-svn-commits mailing list