[jboss-svn-commits] JBL Code SVN: r19756 - in labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/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 Apr 29 08:15:49 EDT 2008


Author: KrisVerlaenen
Date: 2008-04-29 08:15:48 -0400 (Tue, 29 Apr 2008)
New Revision: 19756

Modified:
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java
   labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/Node.java
Log:
JBRULES-1592: Better code completion in dsl rule editor
 - fixed code completion for DSLs

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java	2008-04-29 10:04:21 UTC (rev 19755)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/dsl/editor/completion/DSLRuleCompletionProcessor.java	2008-04-29 12:15:48 UTC (rev 19756)
@@ -52,17 +52,19 @@
 			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")) {
+			boolean firstLine = false;
+			if (lastobj.equals("when")) {
+				firstLine = true;
 				last = "";
 				lastobj = "*";
 			}
 			// pass the last string in the backText to getProposals
-			List dslConditions = this.getProposals(adapter, lastobj, last);
+			List dslConditions = this.getProposals(adapter, lastobj, last, firstLine);
 			// 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());
-			}
+//			if (dslConditions.size() == 0) {
+//				dslConditions.addAll(adapter.listConditionItems());
+//			}
 			addDSLProposals(list, documentOffset, prefix, dslConditions);
 		}
 	}
@@ -159,10 +161,10 @@
 	 * @param last
 	 * @return
 	 */
-	protected List getProposals(DSLAdapter adapter, String obj, String last) {
+	protected List getProposals(DSLAdapter adapter, String obj, String last, boolean firstLine) {
 		if (last.length() == 0) {
 			last = " ";
 		}
-		return adapter.getDSLTree().getChildrenList(obj, last, true);
+		return adapter.getDSLTree().getChildrenList(obj, last, true, firstLine);
 	}
 }

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java	2008-04-29 10:04:21 UTC (rev 19755)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/DSLTree.java	2008-04-29 12:15:48 UTC (rev 19756)
@@ -131,7 +131,7 @@
     
     private void addEntry(Section section, String nl, String objname) {
         if (!nl.startsWith("-")) {
-        	if (objname != null) {
+        	if (objname != null && !"".equals(objname)) {
         		this.addObjToNLMap(objname, nl);
         	}
             String[] tokenz = nl.split("\\s");
@@ -314,6 +314,21 @@
      */
     public Node[] getChildren(String obj, String text) {
         Node thenode = this.rootCond.getChild(obj);
+        if (thenode == null) {
+        	for (Node child: this.rootCond.getChildren()) {
+        		String tokenText = child.getToken();
+        		if (tokenText != null) {
+	        		int index = tokenText.indexOf("{");
+	        		if (index != -1) {
+	        			String substring = tokenText.substring(0, index);
+	        			System.out.println(substring);
+	        			if (obj != null && obj.startsWith(substring)) {
+	        				thenode = child;
+	        			}
+	        		}
+        		}
+        	}
+        }
     	if (thenode != null && text.length() > 0) {
             StringTokenizer tokenz = new StringTokenizer(text);
             this.last = this.current;
@@ -388,7 +403,7 @@
      * @param addChildren
      * @return
      */
-    public ArrayList getChildrenList(String obj, String text, boolean addChildren) {
+    public ArrayList getChildrenList(String obj, String text, boolean addChildren, boolean firstLine) {
     	Node[] c = getChildren(obj,text);
     	this.suggestions.clear();
     	if (c != null) {
@@ -400,13 +415,13 @@
 	    		}
 	    	}
     	}
-    	if (c == null || text.trim().length() == 0) {
+    	if (text.trim().length() == 0) {
 	    	// in the event the line is zero length after it is trimmed, we also add
 	    	// the top level nodes
     		Iterator top = this.rootCond.getChildren().iterator();
         	while (top.hasNext()) {
         		Node t = (Node)top.next();
-        		if (!this.suggestions.contains(t.getToken())) {
+        		if ((!firstLine || t.getToken() != null) && !this.suggestions.contains(t.getToken())) {
             		if (addChildren) {
                 		this.addChildToList(t, t.getToken(), this.suggestions);
             		} else {
@@ -430,12 +445,20 @@
     		Iterator itr = n.getChildren().iterator();
     		while (itr.hasNext()) {
     			Node child = (Node)itr.next();
-    			String text = prefix + " " + child.getToken();
+    			if (prefix != null && "-".equals(child.getToken())) {
+    				if (!list.contains(prefix)) {
+        				list.add(prefix);
+    				}
+    				return;
+    			}
+    			String text = (prefix == null ? "" : prefix + " ") + child.getToken();
     			// list.add(text);
     			addChildToList(child,text,list);
     		}
     	} else {
-    		list.add(prefix);
+    		if (!list.contains(prefix)) {
+    			list.add(prefix);
+    		}
     	}
     }
     

Modified: labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/Node.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/Node.java	2008-04-29 10:04:21 UTC (rev 19755)
+++ labs/jbossrules/trunk/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/completion/Node.java	2008-04-29 12:15:48 UTC (rev 19756)
@@ -4,7 +4,7 @@
 import java.util.HashMap;
 
 public class Node {
-    private HashMap children = new HashMap();
+    private HashMap<String, Node> children = new HashMap<String, Node>();
     private Node parent = null;
     private String token;
     private int depth = 0;
@@ -67,7 +67,7 @@
         this.children.remove(n.getToken());
     }
     
-    public Collection getChildren() {
+    public Collection<Node> getChildren() {
         return this.children.values();
     }
 




More information about the jboss-svn-commits mailing list