[jboss-svn-commits] JBL Code SVN: r31258 - in labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban: drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jan 27 11:38:17 EST 2010


Author: baunax
Date: 2010-01-27 11:38:16 -0500 (Wed, 27 Jan 2010)
New Revision: 31258

Added:
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/ModelField.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionField.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionFormLine.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionMethod.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionPart.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionVariable.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromAccumulateCompositeFactPattern.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCollectCompositeFactPattern.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCompositeFactPattern.java
Modified:
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionCallMethod.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngineTest.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/dt/GuidedDecisionTableTest.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SomeFact.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java
   labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java
Log:
merge with https://svn.jboss.org/repos/labs/labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/MethodInfo.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -8,75 +8,112 @@
 /**
  * 
  * @author Toni Rikkola
- *
+ * 
  */
-public class MethodInfo
-    implements
-    PortableObject {
+public class MethodInfo implements PortableObject {
 
-    private String       name;
-    private List<String> params;
+	private String name;
+	private List<String> params;
+	private String returnClassType;
+	private String parametricReturnType;
 
-    public MethodInfo() {
+	public MethodInfo() {
+	}
 
-    }
+	/**
+	 * 
+	 * @param name
+	 *            method name
+	 * @param params
+	 *            method params list
+	 * @param returnType
+	 *            method's return type
+	 */
+	public MethodInfo(String name, List<String> params, Class<?> returnType, String parametricReturnType) {
+		this.name = name;
+		this.params = params;
+		this.returnClassType = returnType.getName();
+		this.parametricReturnType = parametricReturnType;
+	}
 
-    public MethodInfo(String name,
-                      List<String> params) {
-        this.name = name;
-        this.params = params;
-    }
+	public String getNameWithParameters() {
+		if (params.isEmpty()) {
+			return name + "()";
+		}
+		StringBuilder p = new StringBuilder();
+		
+		for (Iterator<String> iterator = params.iterator(); iterator.hasNext();) {
+			p.append(", ").append(iterator.next());
+		}
 
-    public String getNameWithParameters() {
+		return name + "(" + p.substring(2)  + ")";
+	}
 
-        String n = name + "(";
+	public String getName() {
+		return name;
+	}
 
-        for ( Iterator<String> iterator = params.iterator(); iterator.hasNext(); ) {
-            n += iterator.next();
+	public List<String> getParams() {
+		return params;
+	}
 
-            if ( iterator.hasNext() ) {
-                n += ",";
-            }
-        }
+	public String getReturnClassType() {
+		return returnClassType;
+	}
 
-        n += ")";
+	public String getParametricReturnType() {
+		return parametricReturnType;
+	}
 
-        return n;
-    }
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((name == null) ? 0 : name.hashCode());
+		result = prime
+				* result
+				+ ((parametricReturnType == null) ? 0 : parametricReturnType
+						.hashCode());
+		result = prime * result + ((params == null) ? 0 : params.hashCode());
+		result = prime * result
+				+ ((returnClassType == null) ? 0 : returnClassType.hashCode());
+		return result;
+	}
 
-    public String getName() {
-        return name;
-    }
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		MethodInfo other = (MethodInfo) obj;
+		if (name == null) {
+			if (other.name != null)
+				return false;
+		} else if (!name.equals(other.name))
+			return false;
+		if (parametricReturnType == null) {
+			if (other.parametricReturnType != null)
+				return false;
+		} else if (!parametricReturnType.equals(other.parametricReturnType))
+			return false;
+		if (params == null) {
+			if (other.params != null)
+				return false;
+		} else if (!params.equals(other.params))
+			return false;
+		if (returnClassType == null) {
+			if (other.returnClassType != null)
+				return false;
+		} else if (!returnClassType.equals(other.returnClassType))
+			return false;
+		return true;
+	}
 
-    public List<String> getParams() {
-        return params;
-    }
-
-    public boolean equals(Object o) {
-        if ( o instanceof MethodInfo ) {
-            MethodInfo m = (MethodInfo) o;
-
-            if ( this.getName().equals( m.getName() ) && this.getParams().size() == m.getParams().size() ) {
-                int i = 0;
-                for ( String param : this.params ) {
-                    param.equals( m.getParams().get( i ) );
-                    i++;
-                }
-            }
-        }
-
-        return false;
-    }
-
-    public int hashCode() {
-        int hash = name.hashCode();
-
-        int i = 0;
-        for ( String p : params ) {
-            hash = hash + (p.hashCode() * i);
-            i++;
-        }
-
-        return hash;
-    }
+	@Override
+	public String toString() {
+		return getNameWithParameters();
+	}
 }

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/ModelField.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/ModelField.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/ModelField.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/ModelField.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,71 @@
+package org.drools.guvnor.client.modeldriven;
+
+import org.drools.guvnor.client.modeldriven.brl.PortableObject;
+
+public class ModelField implements PortableObject {
+
+    public static enum FIELD_CLASS_TYPE implements PortableObject{
+        REGULAR_CLASS,
+        TYPE_DECLARATION_CLASS
+    }
+
+    private String name;
+    private String className;
+    /**
+     * parametrized type of clazz
+     */
+    private String type;
+
+    private FIELD_CLASS_TYPE classType;
+
+    public ModelField() {
+    }
+
+    
+    /**
+     * Creates a new ModelField instance
+     * @param name field's name
+     * @param clazz the class of the field. For fields defined as a type declaration
+     * this clazz should be null.
+     * @param type the type of the clazz.
+     */
+    public ModelField(String name, String clazz, String type) {
+        this.name = name;
+        
+        //if clazz==null it is considered as a Type Declaration
+        if (clazz == null){
+            this.classType = FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS;
+        }else{
+            this.classType = FIELD_CLASS_TYPE.REGULAR_CLASS;
+            this.className = clazz;
+        }
+
+        this.type = type;
+    }
+
+    public String getClassName() {
+        return this.className;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public FIELD_CLASS_TYPE getClassType() {
+        return classType;
+    }
+
+
+	@Override
+	public String toString() {
+		return "ModelField [classType=" + classType + ", name=" + name
+				+ ", type=" + type + ", className=" + className + "]";
+	}
+
+    
+    
+}

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -1,11 +1,13 @@
 package org.drools.guvnor.client.modeldriven;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 
 import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
 import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
@@ -50,51 +52,33 @@
     /** The top level conditional elements (first order logic) */
     private static final String[]         CONDITIONAL_ELEMENTS   = new String[]{"not", "exists", "or"};
 
+   
     /**
-     * A list of fact types (never fully qualified).
-     */
-    public String[]                       factTypes;
-
-    /**
-     * A map of types to the fields. key is type, value is (String[] of fields)
-     * 
-     */
-    public Map<String, String[]>          fieldsForType;
-
-    /**
-     * A map of the Fields to their types, needed for operator completions, as
-     * well as other things like rendering strings, dates etc. This is in the
-     * format of: { 'Type.field' => 'typename' }. Should not be the exact type,
-     * perhaps just a high level interface, eg "Comparable".
-     * 
-     */
-    public Map<String, String>            fieldTypes;
-    /**
-    * A map of the field that containts the parametrized type of a collection
+    * A map of the field that contains the parametrized type of a collection
     * List<String> name
     * key = "name"
-    * value = "Strint" 
+    * value = "String"
     *
     */
-    public Map<String, String>            fieldParametersType    = new HashMap<String, String>();
+    private Map<String, String>            fieldParametersType    = new HashMap<String, String>();
 
     /**
      * Contains a map of globals (name is key) and their type (value).
      */
-    public Map<String, String>            globalTypes            = new HashMap();
+    private Map<String, String>            globalTypes            = new HashMap<String, String>();
 
     /**
      * A map of types to the modifying methods they expose. key is type, value
      * is (Sting[] of modifying methods)
      * 
      **/
-    public Map<String, String>            modifiers;
+    private Map<String, String[]>            modifiers;
 
     /**
      * Contains a map of { TypeName.field : String[] } - where a list is valid
      * values to display in a drop down for a given Type.field combination.
      */
-    public Map<String, String[]>          dataEnumLists          = new HashMap<String, String[]>();                                                                            // TODO this is
+    private Map<String, String[]>          dataEnumLists          = new HashMap<String, String[]>();                                                                            // TODO this is
     // a PROBLEM as
     // its not
     // always
@@ -103,7 +87,7 @@
     /**
      * This will show the names of globals that are a collection type.
      */
-    public String[]                       globalCollections;
+    private String[]                       globalCollections;
 
     /** Operators (from the grammar):
          *      op=(    '=='
@@ -131,7 +115,7 @@
      * This is used to calculate what fields an enum list may depend on.
      * Optional.
      */
-    private transient Map                 dataEnumLookupFields;
+    private transient Map<String, Object>                 dataEnumLookupFields;
 
     // /**
     // * For bulk loading up the data (from a previous rule save)
@@ -169,6 +153,9 @@
 
     private Map<String, List<MethodInfo>> methodInfos            = new HashMap<String, List<MethodInfo>>();
 
+
+    private Map<String, ModelField[]> modelFields = new HashMap<String, ModelField[]>();
+
     public SuggestionCompletionEngine() {
 
     }
@@ -187,7 +174,7 @@
 
     public String[] getConnectiveOperatorCompletions(final String factType,
                                                      final String fieldName) {
-        final String type = (String) this.fieldTypes.get( factType + "." + fieldName );
+        final String type = this.getFieldType( factType + "." + fieldName );
         if ( type == null ) {
             return STANDARD_CONNECTIVES;
         } else if ( type.equals( TYPE_STRING ) ) {
@@ -202,18 +189,13 @@
 
     }
 
-    public String[] getFactTypes() {
-        return this.factTypes;
-    }
-
     public String[] getFieldCompletions(final String factType) {
-        return (String[]) this.fieldsForType.get( factType );
-
+        return this.getModelFields( factType );
     }
 
     public String[] getOperatorCompletions(final String factType,
                                            final String fieldName) {
-        final String type = (String) this.fieldTypes.get( factType + "." + fieldName );
+        final String type = this.getFieldType( factType, fieldName );
         if ( type == null ) {
             return STANDARD_OPERATORS;
         } else if ( type.equals( TYPE_STRING ) ) {
@@ -228,58 +210,25 @@
 
     }
 
-    /**
-     * A map of the Fields to their types, needed for operator completions, as
-     * well as other things like rendering strings, dates etc. This is in the
-     * format of: { 'Type.field' => 'typename' }. Should not be the exact type,
-     * perhaps just a high level interface, eg "Comparable", "Numeric",
-     * "String".
-     * 
-     */
-    public String getFieldType(final String factType,
-                               final String fieldName) {
-        return (String) this.fieldTypes.get( factType + "." + fieldName );
-    }
-
-    /*
-     * returns the type of parametric class
-     * List<String> a in a class called Toto
-     * key =   "Toto.a"
-     * value = "String"
-     */
-    public String getParametricFieldType(final String factType,
-                                         final String fieldName) {
-        return (String) this.fieldParametersType.get( factType + "." + fieldName );
-    }
-
-    public boolean isGlobalVariable(final String variable) {
-        return this.globalTypes.containsKey( variable );
-    }
-
     public String[] getFieldCompletionsForGlobalVariable(final String varName) {
-        final String type = (String) this.globalTypes.get( varName );
-        return (String[]) this.fieldsForType.get( type );
+        final String type = this.getGlobalVariable( varName );
+        return this.getModelFields(type);
     }
 
     public List<MethodInfo> getMethodInfosForGlobalVariable(final String varName) {
-        final String type = (String) this.globalTypes.get( varName );
+        final String type = this.getGlobalVariable( varName );
         return this.methodInfos.get( type );
     }
 
-    private String[] toStringArray(final Set set) {
+    private String[] toStringArray(final Set<?> set) {
         final String[] f = new String[set.size()];
         int i = 0;
-        for ( final Iterator iter = set.iterator(); iter.hasNext(); ) {
-            f[i] = (String) iter.next();
-            i++;
+        for ( final Iterator<?> iter = set.iterator(); iter.hasNext(); i++) {
+            f[i] = iter.next().toString();
         }
         return f;
     }
 
-    public String[] getGlobalVariables() {
-        return toStringArray( this.globalTypes.keySet() );
-    }
-
     /**
      * This returns a list of enums options (values) that can be used for the
      * given field of the given FactPattern.
@@ -387,7 +336,7 @@
                     ActionFieldValue val = currentValues[i];
                     if ( val.field.equals( typeField ) ) {
                         String key = type + "." + field + "[" + typeField + "=" + val.value + "]";
-                        return DropDownData.create( (String[]) this.dataEnumLists.get( key ) );
+                        return DropDownData.create( this.getDataEnumList( key ) );
                     }
                 }
             } else if ( _typeField != null ) {
@@ -414,7 +363,7 @@
             }
         }
 
-        String[] vals = (String[]) this.dataEnumLists.get( type + "." + field );
+        String[] vals = this.getDataEnumList( type + "." + field );
         return DropDownData.create( vals );
 
     }
@@ -453,10 +402,10 @@
                     continue;
                 }
 
-                String[] qry = (String[]) dataEnumLists.get( key );
+                String[] qry = getDataEnumList( key );
                 return qry[0];
             } else if ( key.startsWith( factType + "." + field ) && (fieldsNeeded == null || fieldsNeeded.length == 0) ) {
-                String[] qry = (String[]) dataEnumLists.get( key );
+                String[] qry = getDataEnumList( key );
                 return qry[0];
             }
         }
@@ -468,7 +417,7 @@
      */
     public String[] getEnumValues(String factType,
                                   String field) {
-        return (String[]) this.dataEnumLists.get( factType + "." + field );
+        return this.getDataEnumList( factType + "." + field );
     }
 
     /**
@@ -522,7 +471,7 @@
         this.methodInfos.put( factName,
                               methodInfos );
     }
-
+    
     public List<String> getMethodFields(String factName,
                                         String methodNameWithParams) {
         if ( methodInfos.get( factName ) != null ) {
@@ -540,7 +489,7 @@
 
     public List<String> getMethodNames(String factName) {
         List<MethodInfo> infos = methodInfos.get( factName );
-        List<String> methodList = new ArrayList<String>();;
+        List<String> methodList = new ArrayList<String>();
 
         if ( infos != null ) {
             for ( MethodInfo info : infos ) {
@@ -550,4 +499,223 @@
 
         return methodList;
     }
+
+    public String getMethodClassType(String factName, String methodFullName) {
+    	List<MethodInfo> infos = methodInfos.get( factName );
+
+        if ( infos != null ) {
+            for ( MethodInfo info : infos ) {
+                if (info.getNameWithParameters().equals(methodFullName)) {
+                	return info.getReturnClassType();
+                }
+            }
+        }
+
+        return null;
+    }
+    
+    public List<String> getMethodFullNames(String factName) {
+        List<MethodInfo> infos = methodInfos.get( factName );
+        List<String> methodList = new ArrayList<String>();
+
+        if ( infos != null ) {
+            for ( MethodInfo info : infos ) {
+                methodList.add( info.getNameWithParameters() );
+            }
+        }
+
+        return methodList;
+    }    
+
+    /**
+     * Returns fact's name from class type
+     *  
+     * @param type
+     * @return
+     */
+    public String getFactNameFromType(String type) {
+    	if (modelFields.containsKey(type)) {
+    		return type;
+    	}
+    	for (Map.Entry<String, ModelField[]> entry : modelFields.entrySet()) {
+			for (ModelField mf : entry.getValue()) {
+				if ("this".equals(mf.getName()) && type.equals(mf.getClassName())) {
+					return entry.getKey();
+				}
+			}
+		}
+    	return null;
+    }
+    
+    /**
+     * returns the type of parametric class
+     * List<String> a in a class called Toto
+     * key =   "Toto.a"
+     * value = "String"
+     */
+    public String getParametricFieldType(final String factType,
+                                         final String fieldName) {
+        return this.getParametricFieldType( factType + "." + fieldName );
+    }
+
+    public String getParametricFieldType(String fieldName){
+        return this.fieldParametersType.get(fieldName);
+    }
+
+    public void putParametricFieldType(String fieldName, String type){
+        this.fieldParametersType.put(fieldName, type);
+    }
+    
+    public String getGlobalVariable(String name){
+        return this.globalTypes.get(name);
+    }
+
+    public boolean isGlobalVariable(String name){
+        return this.globalTypes.containsKey(name);
+    }
+
+    public void setGlobalVariables(Map<String, String> globalTypes){
+         this.globalTypes = globalTypes;
+    }
+
+    public String[] getGlobalVariables() {
+        return toStringArray( this.globalTypes.keySet() );
+    }
+
+    public void setModifiers(Map<String,String[]> map){
+        this.modifiers = map;
+    }
+
+    public String[] getModifiers(String name){
+        return this.modifiers.get(name);
+    }
+
+    public void setGlobalCollections(String[] globalCollections){
+        this.globalCollections = globalCollections;
+    }
+
+    public String[] getGlobalCollections() {
+        return this.globalCollections;
+    }
+
+    public String[] getDataEnumList(String type){
+        return this.dataEnumLists.get(type);
+    }
+
+    public void setDataEnumLists(Map<String,String[]> data){
+        this.dataEnumLists = data;
+    }
+
+    public void putDataEnumList(String name,String[] value){
+        this.dataEnumLists.put(name, value);
+    }
+
+    public void putAllDataEnumLists(Map<String,String[]> value){
+        this.dataEnumLists.putAll(value);
+    }
+
+    public int getDataEnumListsSize(){
+        return this.dataEnumLists.size();
+    }
+
+    public boolean hasDataEnumLists(){
+        return this.dataEnumLists != null && this.dataEnumLists.size() > 0;
+    }
+
+
+    ////
+
+    public void setFactTypes(String[] factTypes) {
+        for (String factType : factTypes) {
+            //adds the fact type with no fields.
+            this.modelFields.put(factType, new ModelField[0]);
+        }
+    }
+
+    public void setFieldsForTypes(Map<String,ModelField[]> fieldsForType){
+    	this.modelFields.clear();
+        this.modelFields.putAll(fieldsForType);
+    }
+
+    /**
+     * Returns all the fact types.
+     * @return
+     */
+    public String[] getFactTypes() {
+        String[] types = this.modelFields.keySet().toArray(new String[this.modelFields.size()]);
+        Arrays.sort(types);
+		return types;
+    }
+
+    private ModelField getField(String modelClassName, String fieldName){
+        ModelField[] fields = this.modelFields.get(modelClassName);
+
+        if (fields == null){
+            return null;
+        }
+
+        for (ModelField modelField : fields) {
+            if (modelField.getName().equals(fieldName)){
+                return modelField;
+            }
+        }
+
+        return null;
+    }
+
+
+    public String[] getModelFields(String modelClassName){
+
+        if (!this.modelFields.containsKey(modelClassName)){
+            return new String[0];
+        }
+
+        ModelField[] fields = this.modelFields.get(modelClassName);
+
+        String[] fieldNames = new String[fields.length];
+
+        for (int i=0;i<fields.length; i++) {
+            fieldNames[i] = fields[i].getName();
+        }
+
+        return fieldNames;
+    }
+
+    /**
+     *
+     * @param propertyName of the type class.field
+     * @return
+     */
+    public String getFieldClassName(String propertyName){
+        String[] split = propertyName.split("\\.");
+        if (split.length!=2){
+            throw new IllegalArgumentException("Invalid format '"+propertyName+"'. It must be of type className.propertyName");
+        }
+        return this.getFieldClassName(split[0], split[1]);
+    }
+
+    public String getFieldClassName(String modelClassName, String fieldName){
+        ModelField field = this.getField(modelClassName, fieldName);
+        return field==null?null:field.getClassName();
+    }
+
+    public ModelField.FIELD_CLASS_TYPE getFieldClassType(String modelClassName, String fieldName){
+        ModelField field = this.getField(modelClassName, fieldName);
+        return field==null?null:field.getClassType();
+    }
+
+    public String getFieldType(String propertyName){
+        String[] split = propertyName.split("\\.", 3);
+        if (split.length!=2){
+            throw new IllegalArgumentException("Invalid format '"+propertyName+"'. It must be of type className.propertyName");
+        }
+        return this.getFieldType(split[0], split[1]);
+    }
+
+    public String getFieldType(String modelClassName, String fieldName){
+        ModelField field = this.getField(modelClassName, fieldName);
+        return field==null?null:field.getType();
+    }
+
+
 }

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionCallMethod.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionCallMethod.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionCallMethod.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -24,8 +24,8 @@
 	 */
 	public static final int TYPE_DEFINED = 1;
 	/*
-	 * shows the sstate;tate of the method call TYPE_UNDEFINED => the user has
-	 * not choosen a method or TYPE_DEFINED => The user has choosen a functin
+	 * shows the state of the method call TYPE_UNDEFINED => the user has
+	 * not choosen a method or TYPE_DEFINED => The user has choosen a function
 	 */
 	public int state;
 

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionField.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionField.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionField.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionField.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,39 @@
+package org.drools.guvnor.client.modeldriven.brl;
+
+
+public class ExpressionField extends ExpressionPart {
+	private String fieldName;
+	private String fieldType; 
+	
+	@SuppressWarnings("unused")
+	private ExpressionField() {}
+
+	public ExpressionField(String fieldName, String fieldType) {
+		super();
+		this.fieldName = fieldName;
+		this.fieldType = fieldType;
+	}
+
+	@Override
+	public String getText() {
+		return "." + getFieldName() + (getNext() == null ? "" : getNext().getText());
+	}
+
+	public String getFieldName() {
+		return fieldName;
+	}
+
+	public String getFieldType() {
+		return fieldType;
+	}
+	
+	@Override
+	public String getType() {
+		return fieldType;
+	}
+
+	@Override
+	public String getName() {
+		return getFieldName();
+	}
+}

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionFormLine.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionFormLine.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionFormLine.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionFormLine.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,36 @@
+package org.drools.guvnor.client.modeldriven.brl;
+
+import java.util.LinkedList;
+
+public class ExpressionFormLine implements IAction, IPattern {
+	
+    private LinkedList<ExpressionPart> parts = new LinkedList<ExpressionPart>() ;
+    
+    public ExpressionFormLine() {}
+
+	public String getText() {
+		return parts.isEmpty() ? "" : parts.getFirst().getText();
+	}
+	
+	public void appendPart(ExpressionPart part) {
+		if (!parts.isEmpty()) {
+			parts.getLast().setNext(part);
+		}
+		parts.add(part);
+	}
+	
+	public void removeLast() {
+		if (!parts.isEmpty()) {
+			parts.removeLast();
+		}
+	}
+	
+	public String getPreviousType() {
+		ExpressionPart last = parts.getLast();
+		return last.getPrevious() == null ? null : last.getPrevious().getType(); 
+	}
+	
+	public String getType() {
+		return parts.getLast().getType();
+	}
+}

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionMethod.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionMethod.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionMethod.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionMethod.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,73 @@
+package org.drools.guvnor.client.modeldriven.brl;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class ExpressionMethod extends ExpressionPart {
+	private String methodName;
+	private String returnType;
+
+	private Map<String, ExpressionPart> params = new LinkedHashMap<String, ExpressionPart>();
+
+	@SuppressWarnings("unused")
+	private ExpressionMethod() {
+	}
+	
+	public ExpressionMethod(String methodName, String returnType) {
+		super();
+		this.methodName = methodName;
+		this.returnType = returnType;
+	}
+
+	public String getMethodName() {
+		return methodName;
+	}
+
+	public Map<String, ExpressionPart> getParams() {
+		return params;
+	}
+
+	public void setParams(Map<String, ExpressionPart> params) {
+		this.params = params;
+	}
+
+	public void setMethodName(String methodName) {
+		this.methodName = methodName;
+	}
+
+	public String getReturnType() {
+		return returnType;
+	}
+
+	public void setReturnType(String returnType) {
+		this.returnType = returnType;
+	}
+
+	@Override
+	public String getText() {
+		return "." + methodName + paramsToString()
+				+ (getNext() == null ? "" : getNext().getText());
+	}
+
+	private String paramsToString() {
+		if (params.isEmpty()) {
+			return "()";
+		}
+		String sep = ", ";
+		StringBuilder s = new StringBuilder();
+		for (ExpressionPart expr : params.values()) {
+			s.append(sep).append(expr.getText());
+		}
+		return "(" + s.substring(sep.length()) + ")";
+	}
+
+	@Override
+	public String getType() {
+		return returnType;
+	}
+	
+	@Override
+	public String getName() {
+		return getMethodName();
+	}
+}

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionPart.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionPart.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionPart.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionPart.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,37 @@
+package org.drools.guvnor.client.modeldriven.brl;
+
+public abstract class ExpressionPart implements IPattern, IAction {
+	private ExpressionPart prev;
+	private ExpressionPart next;
+
+	public ExpressionPart() {}
+
+	public abstract String getName();
+	
+	public abstract String getText();
+
+	public abstract String getType();
+	
+	public ExpressionPart getPrevious() {
+		return prev;
+	}
+
+	public void setPrevious(ExpressionPart prev) {
+		this.prev = prev;
+		prev.next = this;
+	}
+
+	public ExpressionPart getNext() {
+		return next;
+	}
+
+	public void setNext(ExpressionPart next) {
+		this.next = next;
+		next.prev = this;
+	}
+
+	@Override
+	public String toString() {
+		return getText();
+	}
+}

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionVariable.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionVariable.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionVariable.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ExpressionVariable.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,35 @@
+package org.drools.guvnor.client.modeldriven.brl;
+
+
+public class ExpressionVariable extends ExpressionPart {
+	private FactPattern fact;
+	
+	@SuppressWarnings("unused")
+	private ExpressionVariable() {}
+
+	public ExpressionVariable(FactPattern fact) {
+		if (!fact.isBound()) {
+			throw new RuntimeException("the fact is not bounded: " + fact);
+		}
+		this.fact = fact;
+	}
+
+	@Override
+	public String getText() {
+		return fact.boundName + (getNext() != null ? getNext().getText() : "");
+	}
+
+	public FactPattern getFact() {
+		return fact;
+	}
+
+	@Override
+	public String getType() {
+		return fact.factType;
+	}
+	
+	@Override
+	public String getName() {
+		return fact.boundName;
+	}
+}

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FactPattern.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -44,11 +44,7 @@
      * Returns true if there is a variable bound to this fact.
      */
     public boolean isBound() {
-        if ( this.boundName != null && !"".equals( this.boundName ) ) {
-            return true;
-        } else {
-            return false;
-        }
+        return this.boundName != null && !"".equals( this.boundName ) ;
     }
 
     /**

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromAccumulateCompositeFactPattern.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromAccumulateCompositeFactPattern.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromAccumulateCompositeFactPattern.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromAccumulateCompositeFactPattern.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,94 @@
+
+package org.drools.guvnor.client.modeldriven.brl;
+
+/**
+ *
+ * @author esteban
+ */
+public class FromAccumulateCompositeFactPattern extends FromCompositeFactPattern {
+    
+    public static final String USE_FUNCTION = "use_function";
+    public static final String USE_CODE = "use_code";
+
+    private IPattern sourcePattern;
+    private String initCode;
+    private String actionCode;
+    private String reverseCode;
+    private String resultCode;
+
+    private String function;
+
+    public FromAccumulateCompositeFactPattern() {
+    }
+
+
+    public String useFunctionOrCode(){
+        if (this.initCode!=null && !this.initCode.trim().equals("")){
+            //if the initCode is set, we must use it.
+            return FromAccumulateCompositeFactPattern.USE_CODE;
+        }
+
+        //otherwise use Function. (this is the default)
+        return FromAccumulateCompositeFactPattern.USE_FUNCTION;
+    }
+
+    public void clearCodeFields(){
+        this.initCode = null;
+        this.actionCode = null;
+        this.reverseCode = null;
+        this.resultCode = null;
+    }
+    
+
+    public String getActionCode() {
+        return actionCode;
+    }
+
+    public void setActionCode(String actionCode) {
+        this.actionCode = actionCode;
+    }
+
+    public String getInitCode() {
+        return initCode;
+    }
+
+    public void setInitCode(String initCode) {
+        this.initCode = initCode;
+    }
+
+    public String getResultCode() {
+        return resultCode;
+    }
+
+    public void setResultCode(String resultCode) {
+        this.resultCode = resultCode;
+    }
+
+    public String getReverseCode() {
+        return reverseCode;
+    }
+
+    public void setReverseCode(String reverseCode) {
+        this.reverseCode = reverseCode;
+    }
+
+    public IPattern getSourcePattern() {
+        return sourcePattern;
+    }
+
+    public void setSourcePattern(IPattern sourcePattern) {
+        this.sourcePattern = sourcePattern;
+    }
+
+    public String getFunction() {
+        return function;
+    }
+
+    public void setFunction(String function) {
+        this.function = function;
+    }
+
+
+
+
+}

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCollectCompositeFactPattern.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCollectCompositeFactPattern.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCollectCompositeFactPattern.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCollectCompositeFactPattern.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,23 @@
+
+package org.drools.guvnor.client.modeldriven.brl;
+
+/**
+ *
+ * @author esteban
+ */
+public class FromCollectCompositeFactPattern extends FromCompositeFactPattern {
+
+    private IPattern rightPattern;
+
+    public FromCollectCompositeFactPattern() {
+    }
+
+    public IPattern getRightPattern() {
+        return rightPattern;
+    }
+
+    public void setRightPattern(IPattern rightPattern) {
+        this.rightPattern = rightPattern;
+    }
+
+}

Copied: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCompositeFactPattern.java (from rev 31255, labs/jbossrules/branches/guvnor_expressionEditor2_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCompositeFactPattern.java)
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCompositeFactPattern.java	                        (rev 0)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/FromCompositeFactPattern.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -0,0 +1,32 @@
+package org.drools.guvnor.client.modeldriven.brl;
+
+/**
+ *
+ * @author esteban.aliverti at gmail.com
+ */
+public class FromCompositeFactPattern implements IPattern {
+
+    public FactPattern factPattern;
+    private ExpressionFormLine expression = new ExpressionFormLine();
+
+    public FromCompositeFactPattern() {
+    }
+
+    public ExpressionFormLine getExpression() {
+        return expression;
+    }
+
+    public void setExpression(ExpressionFormLine expression) {
+        this.expression = expression;
+    }
+
+    public FactPattern getFactPattern() {
+        return factPattern;
+    }
+
+    public void setFactPattern(FactPattern pattern) {
+        this.factPattern = pattern;
+    }
+
+
+}

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -1,6 +1,7 @@
 package org.drools.guvnor.client.modeldriven.brl;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 public class RuleModel
@@ -102,21 +103,18 @@
     /**
      * @return A list of bound facts (String). Or empty list if none are found.
      */
-    public List getBoundFacts() {
+    public List<String> getBoundFacts() {
         if ( this.lhs == null ) {
-            return null;
+            return Collections.emptyList();
         }
-        final List list = new ArrayList();
+        final List<String> list = new ArrayList<String>();
         for ( int i = 0; i < this.lhs.length; i++ ) {
             if ( this.lhs[i] instanceof FactPattern ) {
                 final FactPattern p = (FactPattern) this.lhs[i];
                 if ( p.boundName != null ) {
                     list.add( p.boundName );
                 }
-                List<String> fieldBindings = getListFieldBinding( p );
-                if ( fieldBindings != null ) {
-                    list.addAll( fieldBindings );
-                }
+                list.addAll( getListFieldBinding( p ) );
             }
         }
         return list;
@@ -156,11 +154,11 @@
      * @return A list of bound facts of the rhs(String). Or empty list if none are found.
      *         Fix nheron
      */
-    public List getRhsBoundFacts() {
+    public List<String> getRhsBoundFacts() {
         if ( this.rhs == null ) {
             return null;
         }
-        final List list = new ArrayList();
+        final List<String> list = new ArrayList<String>();
         for ( int i = 0; i < this.rhs.length; i++ ) {
             if ( this.rhs[i] instanceof ActionInsertFact ) {
                 final ActionInsertFact p = (ActionInsertFact) this.rhs[i];
@@ -373,8 +371,8 @@
      * what bound variables are in scope for a given constraint (including connectives).
      * Does not take into account globals.
      */
-    public List getBoundVariablesInScope(final ISingleFieldConstraint con) {
-        final List result = new ArrayList();
+    public List<String> getBoundVariablesInScope(final ISingleFieldConstraint con) {
+        final List<String> result = new ArrayList<String>();
         for ( int i = 0; i < this.lhs.length; i++ ) {
             final IPattern pat = this.lhs[i];
             if ( pat instanceof FactPattern ) {
@@ -420,8 +418,8 @@
     /**
      * This will get a list of all bound variables, including bound fields.
      */
-    public List getAllVariables() {
-        List result = new ArrayList();
+    public List<String> getAllVariables() {
+        List<String> result = new ArrayList<String>();
         for ( int i = 0; i < this.lhs.length; i++ ) {
             IPattern pat = this.lhs[i];
             if ( pat instanceof FactPattern ) {

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -2,9 +2,8 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -15,13 +14,15 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.jar.JarEntry;
 import java.util.jar.JarInputStream;
 
 import org.drools.base.ClassTypeResolver;
 import org.drools.compiler.DrlParser;
+import org.drools.compiler.DroolsError;
 import org.drools.compiler.DroolsParserException;
-import org.drools.compiler.ParserError;
+import org.drools.guvnor.client.modeldriven.MethodInfo;
 import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
 import org.drools.guvnor.server.util.ClassMethodInspector;
 import org.drools.guvnor.server.util.DataEnumLoader;
@@ -141,8 +142,6 @@
 
         populateDateEnums(dataEnums, sce);
 
-        Arrays.sort(sce.factTypes);
-
         return sce;
     }
 
@@ -153,7 +152,7 @@
             if (enumLoader.hasErrors()) {
                 this.errors.addAll(enumLoader.getErrors());
             } else {
-                sce.dataEnumLists.putAll(enumLoader.getData());
+                sce.putAllDataEnumLists(enumLoader.getData());
             }
         }
 
@@ -170,9 +169,8 @@
         }
 
         if (this.parser.hasErrors()) {
-            for (final Iterator iter = this.parser.getErrors().iterator(); iter.hasNext();) {
-                final ParserError element = (ParserError) iter.next();
-                this.errors.add(element.getMessage());
+            for (final Iterator<DroolsError> iter = this.parser.getErrors().iterator(); iter.hasNext();) {
+                this.errors.add(iter.next().getMessage());
             }
         }
 
@@ -307,11 +305,16 @@
 
         for (final Iterator<TypeDeclarationDescr> it = pkgDescr.getTypeDeclarations().iterator(); it.hasNext();) {
             TypeDeclarationDescr td = it.next();
+            declaredTypes.add(td.getTypeName());
+        }
 
+        for (final Iterator<TypeDeclarationDescr> it = pkgDescr.getTypeDeclarations().iterator(); it.hasNext();) {
+            TypeDeclarationDescr td = it.next();
+
             if (td.getFields().size() > 0) {
                 //add the type to the map
                 String declaredType = td.getTypeName();
-                declaredTypes.add(declaredType);
+                
                 this.builder.addFactType(declaredType);
                 List<String> fieldNames = new ArrayList<String>();
                 for (Map.Entry<String, TypeFieldDescr> f : td.getFields().entrySet()) {
@@ -321,16 +324,15 @@
 
 
                     if (declaredTypes.contains(fieldClass)) {
-                        this.builder.addFieldType(declaredType + "." + fieldName, fieldClass);//SuggestionCompletionEngine.TYPE_OBJECT );
+                        this.builder.addFieldType(declaredType + "." + fieldName, fieldClass,null);//SuggestionCompletionEngine.TYPE_OBJECT );
                     } else {
                         try {
                             Class clz = resolver.resolveType(fieldClass);
-                            this.builder.addFieldType(declaredType + "." + fieldName, getFieldType(clz));
+                            this.builder.addFieldType(declaredType + "." + fieldName, getFieldType(clz),clz);
                         } catch (ClassNotFoundException e) {
                             this.errors.add("Class of field not found: " + fieldClass);
                         }
                     }
-
                 }
 
                 this.builder.addFieldsForType(declaredType, fieldNames.toArray(new String[fieldNames.size()]));
@@ -371,7 +373,7 @@
                     this.errors.add("Fact template field type not found: " + fieldType);
                 }
                 this.builder.addFieldType(factType + "." + fieldDescr.getName(),
-                        getFieldType(fieldTypeClass));
+                        getFieldType(fieldTypeClass),fieldTypeClass);
             }
 
             Arrays.sort(fields);
@@ -410,24 +412,19 @@
         return clazz;
     }
 
-    private void loadClassFields(final Class clazz,
+    private void loadClassFields(final Class<?> clazz,
                                  final String shortTypeName) throws IOException {
         if (clazz == null) {
             return;
         }
 
         final ClassFieldInspector inspector = new ClassFieldInspector(clazz);
-        Set<String> fieldSet = new HashSet<String>();
+        Set<String> fieldSet = new TreeSet<String>();
         fieldSet.addAll(inspector.getFieldNames().keySet());
         // add the "this" field. This won't come out from the inspector
         fieldSet.add("this");
 
-        String [] fields = fieldSet.toArray(new String []{});
-        Arrays.sort(fields);
-
-        fields = removeIrrelevantFields(fields);
-
-        this.builder.addFieldsForType(shortTypeName, fields);
+        this.builder.addFieldsForType(shortTypeName, removeIrrelevantFields(fieldSet));
         
         Method[] methods = clazz.getMethods();
         List<String> modifierStrings = new ArrayList<String>();
@@ -439,21 +436,29 @@
 
         this.builder.addModifiersForType(shortTypeName, modifiers);
 
-        // remove this back out because there is no type for it. We add it explicity
+        // remove this back out because there is no type for it. We add it explicitly
         fieldSet.remove("this");
-        this.builder.addFieldType(shortTypeName + ".this", SuggestionCompletionEngine.TYPE_OBJECT);
+        this.builder.addFieldType(shortTypeName + ".this", SuggestionCompletionEngine.TYPE_OBJECT,clazz);
 
         for (String field : fieldSet) {
-            final Class type = inspector.getFieldTypes().get(field);
+            final Class<?> type = inspector.getFieldTypes().get(field);
             final String fieldType = getFieldType(type);
-            this.builder.addFieldType(shortTypeName + "." + field, fieldType);
+            this.builder.addFieldType(shortTypeName + "." + field, fieldType,type);
             Field f = inspector.getFieldTypesField().get(field);
             this.builder.addFieldTypeField(shortTypeName + "." + field,f);
         }
         
         ClassMethodInspector methodInspector = new ClassMethodInspector(clazz);
         
-        this.builder.getInstance().addMethodInfo( shortTypeName, methodInspector.getMethodInfos() );
+        List<MethodInfo> methodInfos = methodInspector.getMethodInfos();
+        for (MethodInfo mi : methodInfos) {
+				String genericType = mi.getParametricReturnType();
+				if (genericType != null) {
+					this.builder.putParametricFieldType(shortTypeName + "."
+							+ mi.getNameWithParameters(), genericType);
+				}
+		}
+		this.builder.getInstance().addMethodInfo( shortTypeName, methodInfos );
     }
 
     String getShortNameOfClass(final String clazz) {
@@ -464,25 +469,22 @@
      * This will remove the unneeded "fields" that come from java.lang.Object
      * these are really not needed for the modeller.
      */
-    String[] removeIrrelevantFields(final String[] fields) {
-        final List result = new ArrayList();
-        for (int i = 0; i < fields.length; i++) {
-            final String field = fields[i];
-            if (field.equals("class") || field.equals("hashCode") || field.equals("toString")) {
-                // ignore
-            } else {
+    String[] removeIrrelevantFields(Collection<String> fields) {
+        final List<String> result = new ArrayList<String>();
+        for (String field : fields) {
+            if (!(field.equals("class") || field.equals("hashCode") || field.equals("toString"))) {
                 result.add(field);
             }
         }
-        return (String[]) result.toArray(new String[result.size()]);
+        return result.toArray(new String[result.size()]);
     }
 
     /**
      * This will add the given jars to the classloader.
      */
-    private void addJars(final List jars) throws IOException {
-        for (final Iterator it = jars.iterator(); it.hasNext();) {
-            final JarInputStream jis = (JarInputStream) it.next();
+    private void addJars(final List<JarInputStream> jars) throws IOException {
+        for (final Iterator<JarInputStream> it = jars.iterator(); it.hasNext();) {
+            final JarInputStream jis = it.next();
             JarEntry entry  ;
             final byte[] buf = new byte[1024];
             int len  ;

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -11,535 +11,620 @@
  */
 public class BRDRLPersistence implements BRLPersistence {
 
-	private static final BRLPersistence INSTANCE = new BRDRLPersistence();
+    private static final BRLPersistence INSTANCE = new BRDRLPersistence();
 
-	private BRDRLPersistence() {
-	}
+    private BRDRLPersistence() {
+    }
 
-	public static BRLPersistence getInstance() {
-		return INSTANCE;
-	}
+    public static BRLPersistence getInstance() {
+        return INSTANCE;
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.drools.guvnor.server.util.BRLPersistence#marshal(org.drools.guvnor
-	 * .client.modeldriven.brl.RuleModel)
-	 */
-	public String marshal(RuleModel model) {
-		boolean isDSLEnhanced = model.hasDSLSentences();
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.drools.guvnor.server.util.BRLPersistence#marshal(org.drools.guvnor
+     * .client.modeldriven.brl.RuleModel)
+     */
+    public String marshal(RuleModel model) {
+        boolean isDSLEnhanced = model.hasDSLSentences();
 
-		StringBuilder buf = new StringBuilder();
-		buf.append("rule \"" + model.name + "\"");
-		if (null != model.parentName && model.parentName.length() > 0) {
-			buf.append(" extends \"" + model.parentName + "\"\n");
-		} else {
-			buf.append("\n");
-		}
-		this.marshalMetadata(buf, model);
-		this.marshalAttributes(buf, model);
+        StringBuilder buf = new StringBuilder();
+        buf.append("rule \"" + model.name + "\"");
+        if (null != model.parentName && model.parentName.length() > 0) {
+            buf.append(" extends \"" + model.parentName + "\"\n");
+        } else {
+            buf.append("\n");
+        }
+        this.marshalMetadata(buf, model);
+        this.marshalAttributes(buf, model);
 
-		buf.append("\twhen\n");
-		this.marshalLHS(buf, model, isDSLEnhanced);
-		buf.append("\tthen\n");
-		this.marshalRHS(buf, model, isDSLEnhanced);
-		buf.append("end\n");
-		return buf.toString();
-	}
+        buf.append("\twhen\n");
+        this.marshalLHS(buf, model, isDSLEnhanced);
+        buf.append("\tthen\n");
+        this.marshalRHS(buf, model, isDSLEnhanced);
+        buf.append("end\n");
+        return buf.toString();
+    }
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.drools.guvnor.server.util.BRLPersistence#unmarshal(java.lang.String)
-	 */
-	public RuleModel unmarshal(String str) {
-		throw new UnsupportedOperationException(
-				"Still not possible to convert pure DRL to RuleModel");
-	}
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.drools.guvnor.server.util.BRLPersistence#unmarshal(java.lang.String)
+     */
+    public RuleModel unmarshal(String str) {
+        throw new UnsupportedOperationException(
+                "Still not possible to convert pure DRL to RuleModel");
+    }
 
-	/**
-	 * Marshal model attributes
-	 * 
-	 * @param buf
-	 * @param model
-	 */
-	private void marshalAttributes(StringBuilder buf, RuleModel model) {
-		boolean hasDialect = false;
-		for (int i = 0; i < model.attributes.length; i++) {
-			RuleAttribute attr = model.attributes[i];
+    /**
+     * Marshal model attributes
+     *
+     * @param buf
+     * @param model
+     */
+    private void marshalAttributes(StringBuilder buf, RuleModel model) {
+        boolean hasDialect = false;
+        for (int i = 0; i < model.attributes.length; i++) {
+            RuleAttribute attr = model.attributes[i];
 
-			buf.append("\t");
-			buf.append(attr);
+            buf.append("\t");
+            buf.append(attr);
 
-			buf.append("\n");
-			if (attr.attributeName.equals("dialect")) {
-				hasDialect = true;
-			}
-		}
-		// Un comment below for mvel
-		if (!hasDialect) {
-			RuleAttribute attr = new RuleAttribute("dialect", "mvel");
-			buf.append("\t");
-			buf.append(attr);
-			buf.append("\n");
-		}
-	}
+            buf.append("\n");
+            if (attr.attributeName.equals("dialect")) {
+                hasDialect = true;
+            }
+        }
+        // Un comment below for mvel
+        if (!hasDialect) {
+            RuleAttribute attr = new RuleAttribute("dialect", "mvel");
+            buf.append("\t");
+            buf.append(attr);
+            buf.append("\n");
+        }
+    }
 
-	/**
-	 * Marshal model metadata
-	 * 
-	 * @param buf
-	 * @param model
-	 */
-	private void marshalMetadata(StringBuilder buf, RuleModel model) {
-		if (model.metadataList != null) {
-			for (int i = 0; i < model.metadataList.length; i++) {
-				buf.append("\t").append(model.metadataList[i]).append("\n");
-			}
-		}
-	}
+    /**
+     * Marshal model metadata
+     *
+     * @param buf
+     * @param model
+     */
+    private void marshalMetadata(StringBuilder buf, RuleModel model) {
+        if (model.metadataList != null) {
+            for (int i = 0; i < model.metadataList.length; i++) {
+                buf.append("\t").append(model.metadataList[i]).append("\n");
+            }
+        }
+    }
 
-	/**
-	 * Marshal LHS patterns
-	 * 
-	 * @param buf
-	 * @param model
-	 */
-	private void marshalLHS(StringBuilder buf, RuleModel model,
-			boolean isDSLEnhanced) {
-		IPattern[] lhs = model.lhs;
-		LHSPatternVisitor visitor = new LHSPatternVisitor(isDSLEnhanced, buf);
-		for (int i = 0; i < lhs.length; i++) {
-			final IPattern cond = lhs[i];
-			visitor.visit(cond);
-		}
-	}
+    /**
+     * Marshal LHS patterns
+     *
+     * @param buf
+     * @param model
+     */
+    private void marshalLHS(StringBuilder buf, RuleModel model,
+            boolean isDSLEnhanced) {
+        IPattern[] lhs = model.lhs;
+        LHSPatternVisitor visitor = new LHSPatternVisitor(isDSLEnhanced, buf);
+        for (int i = 0; i < lhs.length; i++) {
+            final IPattern cond = lhs[i];
+            visitor.visit(cond);
+        }
+    }
 
-	private void marshalRHS(StringBuilder buf, RuleModel model,
-			boolean isDSLEnhanced) {
-		IAction[] rhs = model.rhs;
-		RHSActionVisitor visitor = new RHSActionVisitor(isDSLEnhanced, buf);
-		for (int i = 0; i < rhs.length; i++) {
-			final IAction action = rhs[i];
-			visitor.visit(action);
-		}
-	}
+    private void marshalRHS(StringBuilder buf, RuleModel model,
+            boolean isDSLEnhanced) {
+        IAction[] rhs = model.rhs;
+        RHSActionVisitor visitor = new RHSActionVisitor(isDSLEnhanced, buf);
+        for (int i = 0; i < rhs.length; i++) {
+            final IAction action = rhs[i];
+            visitor.visit(action);
+        }
+    }
 
-	public static class LHSPatternVisitor extends ReflectiveVisitor {
-		private StringBuilder buf;
-		private boolean isDSLEnhanced;
+    public static class LHSPatternVisitor extends ReflectiveVisitor {
 
-		public LHSPatternVisitor(boolean isDSLEnhanced, StringBuilder b) {
-			this.isDSLEnhanced = isDSLEnhanced;
-			buf = b;
-		}
+        private StringBuilder buf;
+        private boolean isDSLEnhanced;
 
-		public void visitFactPattern(FactPattern pattern) {
-			buf.append("\t\t");
-			if (isDSLEnhanced) {
-				// adding passthrough markup
-				buf.append(">");
-			}
-			generateFactPattern(pattern);
-			buf.append("\n");
-		}
+        public LHSPatternVisitor(boolean isDSLEnhanced, StringBuilder b) {
+            this.isDSLEnhanced = isDSLEnhanced;
+            buf = b;
+        }
 
-		public void visitFreeFormLine(FreeFormLine ffl) {
+        public void visitFactPattern(FactPattern pattern) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                // adding passthrough markup
+                buf.append(">");
+            }
+            generateFactPattern(pattern);
+            buf.append("\n");
+        }
 
-			this.buf.append("\t\t");
-			if (isDSLEnhanced) {
-				buf.append(">");
-			}
-			this.buf.append(ffl.text);
-			this.buf.append("\n");
-		}
+        public void visitFreeFormLine(FreeFormLine ffl) {
 
-		public void visitCompositeFactPattern(CompositeFactPattern pattern) {
-			buf.append("\t\t");
-			if (isDSLEnhanced) {
-				// adding passthrough markup
-				buf.append(">");
-			}
-			if (CompositeFactPattern.COMPOSITE_TYPE_EXISTS.equals(pattern.type)) {
-				renderCompositeFOL(pattern);
-			} else if (CompositeFactPattern.COMPOSITE_TYPE_NOT
-					.equals(pattern.type)) {
-				renderCompositeFOL(pattern);
-			} else if (CompositeFactPattern.COMPOSITE_TYPE_OR
-					.equals(pattern.type)) {
-				buf.append("( ");
-				if (pattern.patterns != null) {
-					for (int i = 0; i < pattern.patterns.length; i++) {
-						if (i > 0) {
-							buf.append(" ");
-							buf.append(pattern.type);
-							buf.append(" ");
-						}
-						renderSubPattern(pattern, i);
-					}
-				}
-				buf.append(" )\n");
-			}
-		}
+            this.buf.append("\t\t");
+            if (isDSLEnhanced) {
+                buf.append(">");
+            }
+            this.buf.append(ffl.text);
+            this.buf.append("\n");
+        }
 
-		private void renderCompositeFOL(CompositeFactPattern pattern) {
-			buf.append(pattern.type);
-			if (pattern.patterns != null && pattern.patterns.length > 1) {
-				buf.append(" (");
-				for (int i = 0; i < pattern.patterns.length; i++) {
-					renderSubPattern(pattern, i);
-					if (i != pattern.patterns.length - 1) {
-						buf.append(" and ");
-					}
-				}
-				buf.append(") \n");
-			} else {
-				buf.append(" ");
-				renderSubPattern(pattern, 0);
-				buf.append("\n");
-			}
-		}
+        public void visitCompositeFactPattern(CompositeFactPattern pattern) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                // adding passthrough markup
+                buf.append(">");
+            }
+            if (CompositeFactPattern.COMPOSITE_TYPE_EXISTS.equals(pattern.type)) {
+                renderCompositeFOL(pattern);
+            } else if (CompositeFactPattern.COMPOSITE_TYPE_NOT.equals(pattern.type)) {
+                renderCompositeFOL(pattern);
+            } else if (CompositeFactPattern.COMPOSITE_TYPE_OR.equals(pattern.type)) {
+                buf.append("( ");
+                if (pattern.patterns != null) {
+                    for (int i = 0; i < pattern.patterns.length; i++) {
+                        if (i > 0) {
+                            buf.append(" ");
+                            buf.append(pattern.type);
+                            buf.append(" ");
+                        }
+                        renderSubPattern(pattern, i);
+                    }
+                }
+                buf.append(" )\n");
+            }
+        }
 
-		private void renderSubPattern(CompositeFactPattern pattern, int subIndex) {
-			if (pattern.patterns == null || pattern.patterns.length == 0)
-				return;
-			this.generateFactPattern(pattern.patterns[subIndex]);
-		}
+        public void visitFromCompositeFactPattern(FromCompositeFactPattern pattern) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                // adding passthrough markup
+                buf.append(">");
+            }
+            if (pattern.getFactPattern() != null) {
+                generateFactPattern(pattern.getFactPattern());
+            }
+            buf.append(" from\n\t\t  ");
+            renderExpression(pattern.getExpression());
+            buf.append("\n");
+        }
 
-		public void visitDSLSentence(final DSLSentence sentence) {
-			buf.append("\t\t");
-			buf.append(sentence.toString());
-			buf.append("\n");
-		}
+        public void visitFromCollectCompositeFactPattern(FromCollectCompositeFactPattern pattern) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                // adding passthrough markup
+                buf.append(">");
+            }
+            if (pattern.getFactPattern() != null) {
+                generateFactPattern(pattern.getFactPattern());
+            }
+            buf.append(" from collect ( ");
+            if (pattern.getRightPattern() != null) {
+                if (pattern.getRightPattern() instanceof FactPattern) {
+                    generateFactPattern((FactPattern) pattern.getRightPattern());
+                } else if (pattern.getRightPattern() instanceof FromCompositeFactPattern) {
+                    visitFromCompositeFactPattern((FromCompositeFactPattern) pattern.getRightPattern());
+                } else {
+                    throw new IllegalArgumentException("Unuported pattern " + pattern.getRightPattern() + " for FROM COLLECT");
+                }
+            }
+            buf.append(") \n");
+        }
 
-		private void generateFactPattern(FactPattern pattern) {
-			if (pattern.boundName != null) {
-				buf.append(pattern.boundName);
-				buf.append(" : ");
-			}
-			if (pattern.factType != null) {
-				buf.append(pattern.factType);
-			}
-			buf.append("( ");
+        public void visitFromAccumulateCompositeFactPattern(FromAccumulateCompositeFactPattern pattern) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                // adding passthrough markup
+                buf.append(">");
+            }
+            if (pattern.getFactPattern() != null) {
+                generateFactPattern(pattern.getFactPattern());
+            }
+            buf.append(" from accumulate ( ");
+            if (pattern.getSourcePattern() != null) {
+                if (pattern.getSourcePattern() instanceof FactPattern) {
+                    generateFactPattern((FactPattern) pattern.getSourcePattern());
+                } else if (pattern.getSourcePattern() instanceof FromAccumulateCompositeFactPattern) {
+                    visitFromAccumulateCompositeFactPattern((FromAccumulateCompositeFactPattern) pattern.getSourcePattern());
+                } else if (pattern.getSourcePattern() instanceof FromCollectCompositeFactPattern) {
+                    visitFromCollectCompositeFactPattern((FromCollectCompositeFactPattern) pattern.getSourcePattern());
+                } else if (pattern.getSourcePattern() instanceof FromCompositeFactPattern) {
+                    visitFromCompositeFactPattern((FromCompositeFactPattern) pattern.getSourcePattern());
+                } else {
+                    throw new IllegalArgumentException("Unuported pattern " + pattern.getSourcePattern() + " for FROM ACCUMULATE");
+                }
+            }
+            buf.append(",\n");
 
-			// top level constraints
-			if (pattern.constraintList != null) {
-				generateConstraints(pattern);
-			}
-			buf.append(")");
-		}
+            if (pattern.useFunctionOrCode().equals(FromAccumulateCompositeFactPattern.USE_FUNCTION)){
+                buf.append("\t\t\t");
+                buf.append(pattern.getFunction());
+            }else{
+                buf.append("\t\t\tinit( ");
+                buf.append(pattern.getInitCode());
+                buf.append(" ),\n");
+                buf.append("\t\t\taction( ");
+                buf.append(pattern.getActionCode());
+                buf.append(" ),\n");
+                if (pattern.getReverseCode() != null && !pattern.getReverseCode().trim().equals("")) {
+                    buf.append("\t\t\treverse( ");
+                    buf.append(pattern.getReverseCode());
+                    buf.append(" ),\n");
+                }
+                buf.append("\t\t\tresult( ");
+                buf.append(pattern.getResultCode());
+                buf.append(" )\n");
+            }
+            buf.append(") \n");
 
-		private void generateConstraints(FactPattern pattern) {
-			int printedCount = 0;
-			for (int i = 0; i < pattern.getFieldConstraints().length; i++) {
-				StringBuilder buffer = new StringBuilder();
-				generateConstraint(pattern.constraintList.constraints[i],
-						false, buffer);
-				if (buffer.length() > 0) {
-					if (printedCount > 0) {
-						buf.append(", ");
-					}
-					buf.append(buffer);
-					printedCount++;
-				}
-			}
-		}
-		/**
-		 * Recursively process the nested constraints. It will only put brackets
-		 * in for the ones that aren't at top level. This makes for more
-		 * readable DRL in the most common cases.
-		 */
-		private void generateConstraint(FieldConstraint con, boolean nested,
-				StringBuilder buf) {
-			if (con instanceof CompositeFieldConstraint) {
-				CompositeFieldConstraint cfc = (CompositeFieldConstraint) con;
-				if (nested)
-					buf.append("( ");
-				FieldConstraint[] nestedConstraints = cfc.constraints;
-				if (nestedConstraints != null) {
-					for (int i = 0; i < nestedConstraints.length; i++) {
-						generateConstraint(nestedConstraints[i], true, buf);
-						if (i < (nestedConstraints.length - 1)) {
-							// buf.append(" ) ");
-							buf.append(cfc.compositeJunctionType + " ");
-							// buf.append(" ( ");
-						}
-					}
-				}
-				if (nested)
-					buf.append(")");
-			} else {
-				generateSingleFieldConstraint((SingleFieldConstraint) con, buf);
-			}
-		}
 
-		private void generateSingleFieldConstraint(
-				final SingleFieldConstraint constr, StringBuilder buf) {
-			if (constr.constraintValueType == ISingleFieldConstraint.TYPE_PREDICATE) {
-				buf.append("eval( ");
-				buf.append(constr.value);
-				buf.append(" )");
-			} else {
-				if (constr.fieldBinding != null) {
-					buf.append(constr.fieldBinding);
-					buf.append(" : ");
-				}
-				if ((constr.operator != null && constr.value != null)
-						|| constr.fieldBinding != null) {
-					SingleFieldConstraint parent = (SingleFieldConstraint) constr.parent;
-					StringBuilder parentBuf = new StringBuilder();
-					while (parent != null) {
-						parentBuf.insert(0, parent.fieldName + ".");
-						parent = (SingleFieldConstraint) parent.parent;
-					}
-					buf.append(parentBuf);
-					buf.append(constr.fieldName);
-				}
+        }
 
-				addFieldRestriction(buf, constr.constraintValueType,
-						constr.operator, constr.value);
+        private void renderCompositeFOL(CompositeFactPattern pattern) {
+            buf.append(pattern.type);
+            if (pattern.patterns != null && pattern.patterns.length > 1) {
+                buf.append(" (");
+                for (int i = 0; i < pattern.patterns.length; i++) {
+                    renderSubPattern(pattern, i);
+                    if (i != pattern.patterns.length - 1) {
+                        buf.append(" and ");
+                    }
+                }
+                buf.append(") \n");
+            } else {
+                buf.append(" ");
+                renderSubPattern(pattern, 0);
+                buf.append("\n");
+            }
+        }
 
-				// and now do the connectives.
-				if (constr.connectives != null) {
-					for (int j = 0; j < constr.connectives.length; j++) {
-						final ConnectiveConstraint conn = constr.connectives[j];
-						addFieldRestriction(buf, conn.constraintValueType,
-								conn.operator, conn.value);
-					}
-				}
-			}
-		}
+        private void renderSubPattern(CompositeFactPattern pattern, int subIndex) {
+            if (pattern.patterns == null || pattern.patterns.length == 0) {
+                return;
+            }
+            this.generateFactPattern(pattern.patterns[subIndex]);
+        }
 
-		private void addFieldRestriction(final StringBuilder buf,
-				final int type, final String operator, final String value) {
-			if (operator == null) {
-				return;
-			}
+        private void renderExpression(ExpressionFormLine expression) {
+            buf.append(expression.getText());
+        }
 
-			buf.append(" ");
-			buf.append(operator);
-			buf.append(" ");
-			switch (type) {
-			case ISingleFieldConstraint.TYPE_RET_VALUE:
-				buf.append("( ");
-				buf.append(value);
-				buf.append(" )");
-				break;
-			case ISingleFieldConstraint.TYPE_LITERAL:
-                if (operator.equals("in")) {
+        public void visitDSLSentence(final DSLSentence sentence) {
+            buf.append("\t\t");
+            buf.append(sentence);
+            buf.append("\n");
+        }
+
+        private void generateFactPattern(FactPattern pattern) {
+            if (pattern.boundName != null) {
+                buf.append(pattern.boundName);
+                buf.append(" : ");
+            }
+            if (pattern.factType != null) {
+                buf.append(pattern.factType);
+            }
+            buf.append("( ");
+
+            // top level constraints
+            if (pattern.constraintList != null) {
+                generateConstraints(pattern);
+            }
+            buf.append(")");
+        }
+
+        private void generateConstraints(FactPattern pattern) {
+            int printedCount = 0;
+            for (int i = 0; i < pattern.getFieldConstraints().length; i++) {
+                StringBuilder buffer = new StringBuilder();
+                generateConstraint(pattern.constraintList.constraints[i],
+                        false, buffer);
+                if (buffer.length() > 0) {
+                    if (printedCount > 0) {
+                        buf.append(", ");
+                    }
+                    buf.append(buffer);
+                    printedCount++;
+                }
+            }
+        }
+
+        /**
+         * Recursively process the nested constraints. It will only put brackets
+         * in for the ones that aren't at top level. This makes for more
+         * readable DRL in the most common cases.
+         */
+        private void generateConstraint(FieldConstraint con, boolean nested,
+                StringBuilder buf) {
+            if (con instanceof CompositeFieldConstraint) {
+                CompositeFieldConstraint cfc = (CompositeFieldConstraint) con;
+                if (nested) {
+                    buf.append("( ");
+                }
+                FieldConstraint[] nestedConstraints = cfc.constraints;
+                if (nestedConstraints != null) {
+                    for (int i = 0; i < nestedConstraints.length; i++) {
+                        generateConstraint(nestedConstraints[i], true, buf);
+                        if (i < (nestedConstraints.length - 1)) {
+                            // buf.append(" ) ");
+                            buf.append(cfc.compositeJunctionType + " ");
+                            // buf.append(" ( ");
+                        }
+                    }
+                }
+                if (nested) {
+                    buf.append(")");
+                }
+            } else {
+                generateSingleFieldConstraint((SingleFieldConstraint) con, buf);
+            }
+        }
+
+        private void generateSingleFieldConstraint(
+                final SingleFieldConstraint constr, StringBuilder buf) {
+            if (constr.constraintValueType == ISingleFieldConstraint.TYPE_PREDICATE) {
+                buf.append("eval( ");
+                buf.append(constr.value);
+                buf.append(" )");
+            } else {
+                if (constr.fieldBinding != null) {
+                    buf.append(constr.fieldBinding);
+                    buf.append(" : ");
+                }
+                if ((constr.operator != null && constr.value != null)
+                        || constr.fieldBinding != null) {
+                    SingleFieldConstraint parent = (SingleFieldConstraint) constr.parent;
+                    StringBuilder parentBuf = new StringBuilder();
+                    while (parent != null) {
+                        parentBuf.insert(0, parent.fieldName + ".");
+                        parent = (SingleFieldConstraint) parent.parent;
+                    }
+                    buf.append(parentBuf);
+                    buf.append(constr.fieldName);
+                }
+
+                addFieldRestriction(buf, constr.constraintValueType,
+                        constr.operator, constr.value);
+
+                // and now do the connectives.
+                if (constr.connectives != null) {
+                    for (int j = 0; j < constr.connectives.length; j++) {
+                        final ConnectiveConstraint conn = constr.connectives[j];
+                        addFieldRestriction(buf, conn.constraintValueType,
+                                conn.operator, conn.value);
+                    }
+                }
+            }
+        }
+
+        private void addFieldRestriction(final StringBuilder buf,
+                final int type, final String operator, final String value) {
+            if (operator == null) {
+                return;
+            }
+
+            buf.append(" ");
+            buf.append(operator);
+            buf.append(" ");
+            switch (type) {
+                case ISingleFieldConstraint.TYPE_RET_VALUE:
+                    buf.append("( ");
                     buf.append(value);
-                } else {
-                    buf.append('"');
+                    buf.append(" )");
+                    break;
+                case ISingleFieldConstraint.TYPE_LITERAL:
+                    if (operator.equals("in")) {
+                        buf.append(value);
+                    } else {
+                        buf.append('"');
+                        buf.append(value);
+                        buf.append('"');
+                    }
+                    break;
+                default:
                     buf.append(value);
-                    buf.append('"');
-                }
-				break;
-			default:
-				buf.append(value);
-			}
-			buf.append(" ");
-		}
+            }
+            buf.append(" ");
+        }
+    }
 
-	}
+    public static class RHSActionVisitor extends ReflectiveVisitor {
 
-	public static class RHSActionVisitor extends ReflectiveVisitor {
-		private StringBuilder buf;
-		private boolean isDSLEnhanced;
-		private int idx = 0;
+        private StringBuilder buf;
+        private boolean isDSLEnhanced;
+        private int idx = 0;
 
-		public RHSActionVisitor(boolean isDSLEnhanced, StringBuilder b) {
-			this.isDSLEnhanced = isDSLEnhanced;
-			buf = b;
-		}
+        public RHSActionVisitor(boolean isDSLEnhanced, StringBuilder b) {
+            this.isDSLEnhanced = isDSLEnhanced;
+            buf = b;
+        }
 
-		public void visitActionInsertFact(final ActionInsertFact action) {
-			this.generateInsertCall(action, false);
-		}
+        public void visitActionInsertFact(final ActionInsertFact action) {
+            this.generateInsertCall(action, false);
+        }
 
-		public void visitActionInsertLogicalFact(
-				final ActionInsertLogicalFact action) {
-			this.generateInsertCall(action, true);
-		}
+        public void visitActionInsertLogicalFact(
+                final ActionInsertLogicalFact action) {
+            this.generateInsertCall(action, true);
+        }
 
-		public void visitFreeFormLine(FreeFormLine ffl) {
+        public void visitFreeFormLine(FreeFormLine ffl) {
 
-			this.buf.append("\t\t");
-			if (isDSLEnhanced) {
-				buf.append(">");
-			}
-			this.buf.append(ffl.text);
-			this.buf.append("\n");
-		}
+            this.buf.append("\t\t");
+            if (isDSLEnhanced) {
+                buf.append(">");
+            }
+            this.buf.append(ffl.text);
+            this.buf.append("\n");
+        }
 
-		private void generateInsertCall(final ActionInsertFact action,
-				final boolean isLogic) {
-			buf.append("\t\t");
-			if (isDSLEnhanced) {
-				buf.append(">");
-			}
-			if (action.fieldValues.length == 0 && action.getBoundName() == null) {
-				buf.append((isLogic) ? "insertLogical( new " : "insert( new ");
+        private void generateInsertCall(final ActionInsertFact action,
+                final boolean isLogic) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                buf.append(">");
+            }
+            if (action.fieldValues.length == 0 && action.getBoundName() == null) {
+                buf.append((isLogic) ? "insertLogical( new " : "insert( new ");
 
-				buf.append(action.factType);
-				buf.append("() );\n");
-			} else {
-				buf.append(action.factType);
-				if (action.getBoundName()==null)
-				{
-					buf.append(" fact");
-					buf.append(idx);
-				} else {
-					buf.append(" " + action.getBoundName());
-				}
-				buf.append(" = new ");
-				buf.append(action.factType);
-				buf.append("();\n");
-				if (action.getBoundName()==null)
-				{
-					generateSetMethodCalls("fact" + idx, action.fieldValues);
-				}else{
-					generateSetMethodCalls(action.getBoundName(), action.fieldValues);
-				}
-					
-				buf.append("\t\t");
-				if (isDSLEnhanced) {
-					buf.append(">");
-				}
-				if (isLogic) {
-					buf.append("insertLogical(");
-					if (action.getBoundName()==null){
-						buf.append("fact");
-						buf.append(idx++);
-					}else{
-						buf.append(action.getBoundName());
-					}
-					buf.append(" );\n");
-				} else {
-					buf.append("insert(");
-					if (action.getBoundName()==null){
-						buf.append("fact");
-						buf.append(idx++);
-					}else {
-						buf.append(action.getBoundName());
-					}
+                buf.append(action.factType);
+                buf.append("() );\n");
+            } else {
+                buf.append(action.factType);
+                if (action.getBoundName() == null) {
+                    buf.append(" fact");
+                    buf.append(idx);
+                } else {
+                    buf.append(" " + action.getBoundName());
+                }
+                buf.append(" = new ");
+                buf.append(action.factType);
+                buf.append("();\n");
+                if (action.getBoundName() == null) {
+                    generateSetMethodCalls("fact" + idx, action.fieldValues);
+                } else {
+                    generateSetMethodCalls(action.getBoundName(), action.fieldValues);
+                }
 
-					buf.append(" );\n");
-				}
+                buf.append("\t\t");
+                if (isDSLEnhanced) {
+                    buf.append(">");
+                }
+                if (isLogic) {
+                    buf.append("insertLogical(");
+                    if (action.getBoundName() == null) {
+                        buf.append("fact");
+                        buf.append(idx++);
+                    } else {
+                        buf.append(action.getBoundName());
+                    }
+                    buf.append(" );\n");
+                } else {
+                    buf.append("insert(");
+                    if (action.getBoundName() == null) {
+                        buf.append("fact");
+                        buf.append(idx++);
+                    } else {
+                        buf.append(action.getBoundName());
+                    }
+
+                    buf.append(" );\n");
+                }
 //				buf.append(idx++);
 //				buf.append(" );\n");
-			}
-		}
+            }
+        }
 
-		public void visitActionUpdateField(final ActionUpdateField action) {
-			this.visitActionSetField(action);
-			buf.append("\t\t");
-			if (isDSLEnhanced) {
-				buf.append(">");
-			}
-			buf.append("update( ");
-			buf.append(action.variable);
-			buf.append(" );\n");
-		}
+        public void visitActionUpdateField(final ActionUpdateField action) {
+            this.visitActionSetField(action);
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                buf.append(">");
+            }
+            buf.append("update( ");
+            buf.append(action.variable);
+            buf.append(" );\n");
+        }
 
-		public void visitActionGlobalCollectionAdd(
-				final ActionGlobalCollectionAdd add) {
-			buf.append("\t\t");
-			if (isDSLEnhanced) {
-				buf.append(">");
-			}
-			buf.append(add.globalName + ".add(" + add.factName + ");\n");
-		}
+        public void visitActionGlobalCollectionAdd(
+                final ActionGlobalCollectionAdd add) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                buf.append(">");
+            }
+            buf.append(add.globalName + ".add(" + add.factName + ");\n");
+        }
 
-		public void visitActionRetractFact(final ActionRetractFact action) {
-			buf.append("\t\t");
-			if (isDSLEnhanced) {
-				buf.append(">");
-			}
-			buf.append("retract( ");
-			buf.append(action.variableName);
-			buf.append(" );\n");
-		}
+        public void visitActionRetractFact(final ActionRetractFact action) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                buf.append(">");
+            }
+            buf.append("retract( ");
+            buf.append(action.variableName);
+            buf.append(" );\n");
+        }
 
-		public void visitDSLSentence(final DSLSentence sentence) {
-			buf.append("\t\t");
-			buf.append(sentence.toString());
-			buf.append("\n");
-		}
+        public void visitDSLSentence(final DSLSentence sentence) {
+            buf.append("\t\t");
+            buf.append(sentence.toString());
+            buf.append("\n");
+        }
 
-		public void visitActionSetField(final ActionSetField action) {
-            if ( action instanceof ActionCallMethod ) {
-                this.generateSetMethodCallsMethod( (ActionCallMethod) action,
-                                                   action.fieldValues );
+        public void visitActionSetField(final ActionSetField action) {
+            if (action instanceof ActionCallMethod) {
+                this.generateSetMethodCallsMethod((ActionCallMethod) action,
+                        action.fieldValues);
             } else {
-                this.generateSetMethodCalls( action.variable,
-                                             action.fieldValues );
+                this.generateSetMethodCalls(action.variable,
+                        action.fieldValues);
             }
         }
 
-		private void generateSetMethodCalls(final String variableName,
-				final ActionFieldValue[] fieldValues) {
-			for (int i = 0; i < fieldValues.length; i++) {
-				buf.append("\t\t");
-				if (isDSLEnhanced) {
-					buf.append(">");
-				}
-				buf.append(variableName);
+        private void generateSetMethodCalls(final String variableName,
+                final ActionFieldValue[] fieldValues) {
+            for (int i = 0; i < fieldValues.length; i++) {
+                buf.append("\t\t");
+                if (isDSLEnhanced) {
+                    buf.append(">");
+                }
+                buf.append(variableName);
 
-				ActionFieldValue value = fieldValues[i];
-				if (value instanceof ActionFieldFunction) {
-					buf.append(".");
-					buf.append(value.field);
-				} else {
-					buf.append(".set");
-					buf.append(Character.toUpperCase(fieldValues[i].field
-							.charAt(0)));
-					buf.append(fieldValues[i].field.substring(1));
-				}
-				buf.append("( ");
-				if (fieldValues[i].isFormula()) {
-					buf.append(fieldValues[i].value.substring(1));
-				} else if (SuggestionCompletionEngine.TYPE_STRING
-						.equals(fieldValues[i].type)) {
-					buf.append("\"");
-					buf.append(fieldValues[i].value);
-					buf.append("\"");
-				} else {
-					buf.append(fieldValues[i].value);
-				}
-				buf.append(" );\n");
-			}
-		}
+                ActionFieldValue value = fieldValues[i];
+                if (value instanceof ActionFieldFunction) {
+                    buf.append(".");
+                    buf.append(value.field);
+                } else {
+                    buf.append(".set");
+                    buf.append(Character.toUpperCase(fieldValues[i].field.charAt(0)));
+                    buf.append(fieldValues[i].field.substring(1));
+                }
+                buf.append("( ");
+                if (fieldValues[i].isFormula()) {
+                    buf.append(fieldValues[i].value.substring(1));
+                } else if (SuggestionCompletionEngine.TYPE_STRING.equals(fieldValues[i].type)) {
+                    buf.append("\"");
+                    buf.append(fieldValues[i].value);
+                    buf.append("\"");
+                } else {
+                    buf.append(fieldValues[i].value);
+                }
+                buf.append(" );\n");
+            }
+        }
 
-
-
-		private void generateSetMethodCallsMethod(final ActionCallMethod action,
-                                                  final ActionFieldValue[] fieldValues) {
-            buf.append( "\t\t" );
-            if ( isDSLEnhanced ) {
-                buf.append( ">" );
+        private void generateSetMethodCallsMethod(final ActionCallMethod action,
+                final ActionFieldValue[] fieldValues) {
+            buf.append("\t\t");
+            if (isDSLEnhanced) {
+                buf.append(">");
             }
-            buf.append( action.variable );
-            buf.append( "." );
+            buf.append(action.variable);
+            buf.append(".");
 
-            buf.append( action.methodName );
+            buf.append(action.methodName);
 
-            buf.append( "(" );
+            buf.append("(");
             boolean isFirst = true;
-            for ( int i = 0; i < fieldValues.length; i++ ) {
+            for (int i = 0; i < fieldValues.length; i++) {
                 ActionFieldFunction valueFunction = (ActionFieldFunction) fieldValues[i];
-                if ( isFirst == true ) {
+                if (isFirst == true) {
                     isFirst = false;
                 } else {
-                    buf.append( "," );
+                    buf.append(",");
                 }
 
-                buf.append( valueFunction.value );
+                buf.append(valueFunction.value);
             }
-            buf.append( " );\n" );
+            buf.append(" );\n");
 
         }
-	}
-
+    }
 }

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -38,6 +38,12 @@
                        DSLSentence.class );
         this.xt.alias( "compositePattern",
                        CompositeFactPattern.class );
+        this.xt.alias( "fromCompositePattern",
+                       FromCompositeFactPattern.class );
+        this.xt.alias( "fromCollectCompositePattern",
+                       FromCollectCompositeFactPattern.class );
+        this.xt.alias( "fromAccumulateCompositePattern",
+                       FromAccumulateCompositeFactPattern.class );
         this.xt.alias( "metadata",
                        RuleMetadata.class );
         this.xt.alias( "attribute",

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/ClassMethodInspector.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -32,14 +32,17 @@
             int modifiers = methods[i].getModifiers();
             String methodName = aMethod.getName();
 
-            if ( isNotGetterOrSetter( methodName ) && isReasonableMethod( clazz,
-                                                                          methodName ) && Modifier.isPublic( modifiers ) ) {
+            if ( isNotGetterOrSetter(aMethod) && isReasonableMethod( clazz,
+            		methodName ) && Modifier.isPublic( modifiers ) ) {
 
-                Class< ? >[] listParam = aMethod.getParameterTypes();
-
-                MethodInfo info = new MethodInfo( methodName,
-                                                  solveParams( listParam ) );
-                this.methods.add( info );
+                Class<?>[] listParam = aMethod.getParameterTypes();
+                
+                
+				MethodInfo info = new MethodInfo(methodName,
+						solveParams(listParam), aMethod.getReturnType(),
+						SuggestionCompletionEngineBuilder
+								.obtainGenericType(aMethod.getGenericReturnType()));
+				this.methods.add(info);
             }
         }
     }
@@ -114,10 +117,12 @@
      * 
      * @param methodName
      */
-    private boolean isNotGetterOrSetter(String methodName) {
-        boolean isGetterOrSetter = (methodName.length() > 3 && (methodName.startsWith( "set" ) || methodName.startsWith( "get" )));
-
-        return !isGetterOrSetter;
+    private boolean isNotGetterOrSetter(Method m) {
+    	String name = m.getName();
+        return !((name.length() > 3 && (name.startsWith( "set" ) || name.startsWith( "get" ))) ||
+        	(name.length() > 2 && name.startsWith("is") 
+        			&& (Boolean.class.isAssignableFrom(m.getReturnType()) || Boolean.TYPE == m.getReturnType())));
+        
     }
 
     public List<String> getMethodFields(String methodName) {

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -13,17 +13,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.drools.guvnor.server.util;
 
-import java.util.*;
 import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
-import java.lang.reflect.ParameterizedType;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
+import org.drools.guvnor.client.modeldriven.ModelField;
 import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
 import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
-import org.drools.lang.dsl.AbstractDSLMappingEntry;
 import org.drools.lang.dsl.DSLMappingEntry;
 
 /**
@@ -33,19 +35,19 @@
  */
 public class SuggestionCompletionEngineBuilder {
 
-    private SuggestionCompletionEngine instance              = new SuggestionCompletionEngine();
-    private List                       factTypes             = new ArrayList();
-    private Map                        fieldsForType         = new HashMap();
-    private Map                        modifiersForType      = new HashMap();
-    private Map                        fieldTypes            = new HashMap();
-    private Map<String,Field>          fieldTypesField       = new HashMap<String,Field>();
-    private Map                        globalTypes           = new HashMap();
-    private List                       actionDSLSentences    = new ArrayList();
-    private List                       conditionDSLSentences = new ArrayList();
-    private List                       keywordDSLItems = new ArrayList();
-    private List                       anyScopeDSLItems = new ArrayList();
-    private List<String>                globalCollections = new ArrayList();
- 
+    private SuggestionCompletionEngine instance = new SuggestionCompletionEngine();
+    private List<String> factTypes = new ArrayList<String>();
+    private Map<String, String[]> fieldsForType = new HashMap<String, String[]>();
+    private Map<String, String[]> modifiersForType = new HashMap<String, String[]>();
+    private Map<String, String> fieldTypes = new HashMap<String, String>();
+    private Map<String, Class<?>> fieldClasses = new HashMap<String, Class<?>>();
+    private Map<String, Field> fieldTypesField = new HashMap<String, Field>();
+    private Map<String, String> globalTypes = new HashMap<String, String>();
+    private List<DSLSentence> actionDSLSentences = new ArrayList<DSLSentence>();
+    private List<DSLSentence> conditionDSLSentences = new ArrayList<DSLSentence>();
+    private List<DSLSentence> keywordDSLItems = new ArrayList<DSLSentence>();
+    private List<DSLSentence> anyScopeDSLItems = new ArrayList<DSLSentence>();
+    private List<String> globalCollections = new ArrayList<String>();
 
     public SuggestionCompletionEngineBuilder() {
     }
@@ -55,16 +57,16 @@
      */
     public void newCompletionEngine() {
         this.instance = new SuggestionCompletionEngine();
-        this.factTypes = new ArrayList();
-        this.fieldsForType = new HashMap();
-        this.modifiersForType = new HashMap();
-        this.fieldTypes = new HashMap();
-        this.fieldTypesField = new HashMap();
-        this.globalTypes = new HashMap();
-        this.actionDSLSentences = new ArrayList();
-        this.conditionDSLSentences = new ArrayList();
-        this.keywordDSLItems = new ArrayList();
-        this.anyScopeDSLItems = new ArrayList();
+        this.factTypes = new ArrayList<String>();
+        this.fieldsForType = new HashMap<String, String[]>();
+        this.modifiersForType = new HashMap<String, String[]>();
+        this.fieldTypes = new HashMap<String, String>();
+        this.fieldTypesField = new HashMap<String, Field>();
+        this.globalTypes = new HashMap<String, String>();
+        this.actionDSLSentences = new ArrayList<DSLSentence>();
+        this.conditionDSLSentences = new ArrayList<DSLSentence>();
+        this.keywordDSLItems = new ArrayList<DSLSentence>();
+        this.anyScopeDSLItems = new ArrayList<DSLSentence>();
         this.globalCollections = new ArrayList<String>();
     }
 
@@ -74,7 +76,7 @@
      * @param factType
      */
     public void addFactType(final String factType) {
-        this.factTypes.add( factType );
+        this.factTypes.add(factType);
     }
 
     /**
@@ -84,9 +86,9 @@
      * @param fields
      */
     public void addFieldsForType(final String type,
-                                 final String[] fields) {
-        this.fieldsForType.put( type,
-                                fields );
+            final String[] fields) {
+        this.fieldsForType.put(type,
+                fields);
     }
 
     /**
@@ -96,40 +98,41 @@
      * @param fields
      */
     public void addModifiersForType(final String type,
-                                 final String[] fields) {
-        this.modifiersForType.put( type,
-                                fields );
+            final String[] fields) {
+        this.modifiersForType.put(type,
+                fields);
     }
 
     /**
      * @return true if this has the type already registered (field information).
      */
     public boolean hasFieldsForType(final String type) {
-        return this.fieldsForType.containsKey( type );
+        return this.fieldsForType.containsKey(type);
     }
 
     /**
      * Adds a type declaration for a field
      *
-     * @param field
-     * @param type
+     * @param field format: class.field
+     * @param type parametrized type of clazz
+     * @param clazz the class of field
      */
-    public void addFieldType(final String field,
-                             final String type) {
-        this.fieldTypes.put( field,
-                             type );
-    }
-      /**
+	public void addFieldType(final String field, final String type,
+			final Class<?> clazz) {
+		this.fieldTypes.put(field, type);
+		this.fieldClasses.put(field, clazz);
+	}
+
+    /**
      * Adds a type declaration for a field
      *
-     * @param field
+     * @param field format: class.field
      * @param type
      */
-    public void addFieldTypeField(final String field,
-                             final Field type) {
-        this.fieldTypesField.put( field,
-                             type );
-    }
+	public void addFieldTypeField(final String field, final Field type) {
+		this.fieldTypesField.put(field, type);
+	}
+
     /**
      * Adds a global and its corresponding type to the engine
      *
@@ -137,9 +140,8 @@
      * @param type
      */
     public void addGlobalType(final String global,
-                              final String type) {
-        this.globalTypes.put( global,
-                              type );
+            final String type) {
+        this.globalTypes.put(global, type);
     }
 
     public void addGlobalCollection(String global) {
@@ -152,7 +154,7 @@
     public void addDSLActionSentence(final String sentence) {
         final DSLSentence sen = new DSLSentence();
         sen.sentence = sentence;
-        this.actionDSLSentences.add( sen );
+        this.actionDSLSentences.add(sen);
     }
 
     /**
@@ -161,9 +163,26 @@
     public void addDSLConditionSentence(final String sentence) {
         final DSLSentence sen = new DSLSentence();
         sen.sentence = sentence;
-        this.conditionDSLSentences.add( sen );
+        this.conditionDSLSentences.add(sen);
     }
 
+    static public String obtainGenericType(Type type) {
+        if (type instanceof ParameterizedType) {
+            ParameterizedType pt = (ParameterizedType) type;
+            Type goodType = null;
+            for (Type t : pt.getActualTypeArguments()) {
+                goodType = t;
+            }
+            int index = goodType.toString().lastIndexOf(".");
+            return goodType.toString().substring(index + 1);
+        }
+        return null;
+    }
+    
+    public void putParametricFieldType(String fieldName, String genericType) {
+    	this.instance.putParametricFieldType(fieldName, genericType);
+    }
+    
     /**
      * Returns a SuggestionCompletionEngine instance populated with
      * all the data since last call to newCompletionEngine() method
@@ -171,34 +190,45 @@
      * @return
      */
     public SuggestionCompletionEngine getInstance() {
-        this.instance.factTypes = (String[]) this.factTypes.toArray( new String[this.factTypes.size()] );
-        this.instance.fieldsForType = this.fieldsForType;
-        this.instance.modifiers = this.modifiersForType;
-        this.instance.fieldTypes = this.fieldTypes;
-        for (String fieldName  : this.fieldTypesField.keySet()){
-            Field field =  (Field) this.fieldTypesField.get(fieldName);
-            if (field != null){
-                Type type = field.getGenericType();
-                if (type instanceof ParameterizedType) {
-                    ParameterizedType pt = (ParameterizedType) type;
-                    Type goodType = null;
-                    for (Type t : pt.getActualTypeArguments()) {
-                        goodType = t;
-                    }
-                    int index = goodType.toString().lastIndexOf(".");
-                    String className = goodType.toString().substring(index + 1);
-                    this.instance.fieldParametersType.put(fieldName, className);
+        this.instance.setFactTypes(this.factTypes.toArray(new String[this.factTypes.size()]));
+        this.instance.setModifiers(this.modifiersForType);
 
+
+        //convert this.fieldsForType, this.fieldClasses and this.fieldTypes into Map<String,ModelField[]>.
+        Map<String, ModelField[]> modelMap = new HashMap<String, ModelField[]>();
+        for (Map.Entry<String, String[]> typeEntry : this.fieldsForType.entrySet()) {
+            
+            List<ModelField> fields = new ArrayList<ModelField>();
+            for (String field : typeEntry.getValue()) {
+                String fieldName = field;
+                String fieldType = this.fieldTypes.get(typeEntry.getKey() + "." + field);
+                Class<?> fieldClazz = this.fieldClasses.get(typeEntry.getKey() + "." + field);
+
+                fields.add(new ModelField(
+                        fieldName, fieldClazz.getName(), fieldType));
+            }
+
+            modelMap.put(typeEntry.getKey(), fields.toArray(new ModelField[fields.size()]));
+        }
+
+        this.instance.setFieldsForTypes(modelMap);
+
+        for (String fieldName : this.fieldTypesField.keySet()) {
+            Field field = this.fieldTypesField.get(fieldName);
+            if (field != null) {
+                String genericType = obtainGenericType(field.getGenericType());
+                if (genericType != null) {
+                	this.instance.putParametricFieldType(fieldName, genericType);	
                 }
-
+                
                 Class<?> fieldClass = field.getType();
-                if(fieldClass.isEnum()) {
+                if (fieldClass.isEnum()) {
                     Field[] flds = fieldClass.getDeclaredFields();
                     List<String> listEnum = new ArrayList<String>();
-                    int i=0;
+                    int i = 0;
                     for (Field f : flds) {
-                        if(f.isEnumConstant()) {
-                            listEnum.add(i+ "="+f.getName());
+                        if (f.isEnumConstant()) {
+                            listEnum.add(i + "=" + f.getName());
                             i++;
                         }
                     }
@@ -208,39 +238,36 @@
                         a[i] = value;
                         i++;
                     }
-                    this.instance.dataEnumLists.put(fieldName, a);
+                    this.instance.putDataEnumList(fieldName, a);
                 }
             }
 
         }
-        this.instance.globalTypes = this.globalTypes;
+        this.instance.setGlobalVariables(this.globalTypes);
         this.instance.actionDSLSentences = makeArray(this.actionDSLSentences);
         this.instance.conditionDSLSentences = makeArray(this.conditionDSLSentences);
         this.instance.keywordDSLItems = makeArray(this.keywordDSLItems);
         this.instance.anyScopeDSLItems = makeArray(this.anyScopeDSLItems);
-        this.instance.globalCollections = this.globalCollections.toArray(new String[globalCollections.size()]);
+        this.instance.setGlobalCollections(this.globalCollections.toArray(new String[globalCollections.size()]));
         return this.instance;
     }
 
-	private DSLSentence[] makeArray(List ls) {
-        return (DSLSentence[]) ls.toArray( new DSLSentence[ls.size()] );
+    private DSLSentence[] makeArray(List<DSLSentence> ls) {
+        return ls.toArray(new DSLSentence[ls.size()]);
     }
 
-	public void addDSLMapping(DSLMappingEntry entry) {
-		DSLSentence sen = new DSLSentence();
-		sen.sentence = entry.getMappingKey();
-		if (entry.getSection() == DSLMappingEntry.CONDITION) {
-			this.conditionDSLSentences.add(sen);
-		} else if (entry.getSection() == DSLMappingEntry.CONSEQUENCE) {
-			this.actionDSLSentences.add(sen);
-		} else if (entry.getSection() == DSLMappingEntry.KEYWORD) {
-			this.keywordDSLItems.add(sen);
-		} else if (entry.getSection() == DSLMappingEntry.ANY) {
-			this.anyScopeDSLItems.add(sen);
-		}
+    public void addDSLMapping(DSLMappingEntry entry) {
+        DSLSentence sen = new DSLSentence();
+        sen.sentence = entry.getMappingKey();
+        if (entry.getSection() == DSLMappingEntry.CONDITION) {
+            this.conditionDSLSentences.add(sen);
+        } else if (entry.getSection() == DSLMappingEntry.CONSEQUENCE) {
+            this.actionDSLSentences.add(sen);
+        } else if (entry.getSection() == DSLMappingEntry.KEYWORD) {
+            this.keywordDSLItems.add(sen);
+        } else if (entry.getSection() == DSLMappingEntry.ANY) {
+            this.anyScopeDSLItems.add(sen);
+        }
 
-	}
-
-
-
+    }
 }

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngineTest.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngineTest.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngineTest.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -47,7 +47,7 @@
 
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
 
-        List enums = new ArrayList();
+        List<String> enums = new ArrayList<String>();
 
         enums.add( "'Person.age' : [42, 43] \n 'Person.sex' : ['M', 'F']" );
         enums.add( "'Driver.sex' : ['M', 'F']" );
@@ -61,8 +61,8 @@
                                            "name" ) );
 
         assertEquals( 3,
-                      engine.dataEnumLists.size() );
-        String[] items = (String[]) engine.dataEnumLists.get( "Person.age" );
+                      engine.getDataEnumListsSize());
+        String[] items = engine.getDataEnumList( "Person.age" );
         assertEquals( 2,
                       items.length );
         assertEquals( "42",
@@ -125,7 +125,7 @@
 
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
 
-        List enums = new ArrayList();
+        List<String> enums = new ArrayList<String>();
 
         enums.add( "'Fact.field1' : ['val1', 'val2'] 'Fact.field2' : ['val3', 'val4'] 'Fact.field2[field1=val1]' : ['f1val1a', 'f1val1b'] 'Fact.field2[field1=val2]' : ['f1val2a', 'f1val2b']" );
 
@@ -141,9 +141,9 @@
                                            "field2" ) );
 
         assertEquals( 4,
-                      engine.dataEnumLists.size() );
+                      engine.getDataEnumListsSize() );
 
-        String[] items = (String[]) engine.dataEnumLists.get( "Fact.field2" );
+        String[] items = engine.getDataEnumList( "Fact.field2" );
         assertEquals( 2,
                       items.length );
         assertEquals( "val3",
@@ -163,7 +163,7 @@
         assertEquals( "val4",
                       items[1] );
 
-        items = (String[]) engine.dataEnumLists.get( "Fact.field1" );
+        items = engine.getDataEnumList( "Fact.field1" );
         assertEquals( 2,
                       items.length );
         assertEquals( "val1",
@@ -186,37 +186,33 @@
 
         final SuggestionCompletionEngine com = new SuggestionCompletionEngine();
 
-        com.factTypes = new String[]{"Person", "Vehicle"};
-        com.fieldsForType = new HashMap() {
+        com.setFactTypes(new String[]{"Person", "Vehicle"});
+        
+        com.setFieldsForTypes(new HashMap<String,ModelField[]>() {
             {
                 put( "Person",
-                     new String[]{"age", "name", "rank"} );
+                     new ModelField[]{
+                        new ModelField("age", Integer.class.getName(), SuggestionCompletionEngine.TYPE_NUMERIC),
+                        new ModelField("rank", Integer.class.getName(), SuggestionCompletionEngine.TYPE_COMPARABLE),
+                        new ModelField("name", String.class.getName(), SuggestionCompletionEngine.TYPE_STRING)
+                } );
+
                 put( "Vehicle",
-                     new String[]{"type", "make"} );
+                     new ModelField[]{
+                        new ModelField("make", String.class.getName(), SuggestionCompletionEngine.TYPE_STRING),
+                        new ModelField("type", String.class.getName(), SuggestionCompletionEngine.TYPE_STRING)
+                } );
             }
-        };
-        com.fieldTypes = new HashMap() {
+        });
+
+        com.setGlobalVariables(new HashMap<String, String>() {
             {
-                put( "Person.age",
-                     "Numeric" );
-                put( "Person.rank",
-                     "Comparable" );
-                put( "Person.name",
-                     "String" );
-                put( "Vehicle.make",
-                     "String" );
-                put( "Vehicle.type",
-                     "String" );
-            }
-        };
-        com.globalTypes = new HashMap() {
-            {
                 put( "bar",
                      "Person" );
                 put( "baz",
                      "Vehicle" );
             }
-        };
+        });
 
         String[] c = com.getConditionalElements();
         assertEquals( "not",
@@ -237,14 +233,16 @@
         c = com.getFieldCompletions( "Person" );
         assertEquals( "age",
                       c[0] );
+        assertEquals( "rank",
+                      c[1] );
         assertEquals( "name",
-                      c[1] );
+                      c[2] );
 
         c = com.getFieldCompletions( "Vehicle" );
         assertEquals( "type",
+                      c[1] );
+        assertEquals( "make",
                       c[0] );
-        assertEquals( "make",
-                      c[1] );
 
         c = com.getOperatorCompletions( "Person",
                                         "name" );
@@ -303,15 +301,17 @@
                       c.length );
         assertEquals( "age",
                       c[0] );
+        assertEquals( "rank",
+                      c[1] );
         assertEquals( "name",
-                      c[1] );
+                      c[2] );
 
         c = com.getFieldCompletionsForGlobalVariable( "baz" );
         assertEquals( 2,
                       c.length );
+        assertEquals( "make",
+                      c[0] );
         assertEquals( "type",
-                      c[0] );
-        assertEquals( "make",
                       c[1] );
 
         //check that it has default operators for general objects
@@ -328,13 +328,15 @@
 
     public void testAdd() {
         final SuggestionCompletionEngine com = new SuggestionCompletionEngine();
-        com.factTypes = new String[]{"Foo"};
-        com.fieldsForType = new HashMap() {
+        com.setFactTypes(new String[]{"Foo"});
+        com.setFieldsForTypes(new HashMap<String,ModelField[]>() {
             {
                 put( "Foo",
-                     new String[]{"a"} );
+                     new ModelField[]{
+                        new ModelField("a", String.class.getName(), "String")
+                });
             }
-        };
+        });
 
         assertEquals( 1,
                       com.getFactTypes().length );
@@ -350,12 +352,12 @@
 
     public void testSmartEnums() {
         final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-        sce.dataEnumLists = new HashMap();
-        sce.dataEnumLists.put( "Fact.type",
+        sce.setDataEnumLists(new HashMap());
+        sce.putDataEnumList( "Fact.type",
                                new String[]{"sex", "colour"} );
-        sce.dataEnumLists.put( "Fact.value[type=sex]",
+        sce.putDataEnumList( "Fact.value[type=sex]",
                                new String[]{"M", "F"} );
-        sce.dataEnumLists.put( "Fact.value[type=colour]",
+        sce.putDataEnumList( "Fact.value[type=colour]",
                                new String[]{"RED", "WHITE", "BLUE"} );
 
         FactPattern pat = new FactPattern( "Fact" );
@@ -422,14 +424,14 @@
 
     public void testSmartEnumsDependingOfSeveralFieldsTwo() {
         final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-        sce.dataEnumLists = new HashMap();
-        sce.dataEnumLists.put( "Fact.field1",
+        sce.setDataEnumLists(new HashMap());
+        sce.putDataEnumList( "Fact.field1",
                                new String[]{"a1", "a2"} );
-        sce.dataEnumLists.put( "Fact.field2",
+        sce.putDataEnumList( "Fact.field2",
                                new String[]{"b1", "b2"} );
-        sce.dataEnumLists.put( "Fact.field3[field1=a1,field2=b1]",
+        sce.putDataEnumList( "Fact.field3[field1=a1,field2=b1]",
                                new String[]{"c1", "c2", "c3"} );
-        sce.dataEnumLists.put( "Fact.field4[field1=a1]",
+        sce.putDataEnumList( "Fact.field4[field1=a1]",
                                new String[]{"d1", "d2"} );
 
         FactPattern pat = new FactPattern( "Fact" );
@@ -455,18 +457,18 @@
 
     public void testSmartEnumsDependingOfSeveralFieldsFive() {
         final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-        sce.dataEnumLists = new HashMap();
-        sce.dataEnumLists.put( "Fact.field1",
+        sce.setDataEnumLists(new HashMap());
+        sce.putDataEnumList( "Fact.field1",
                                new String[]{"a1", "a2"} );
-        sce.dataEnumLists.put( "Fact.field2",
+        sce.putDataEnumList( "Fact.field2",
                                new String[]{"b1", "b2"} );
-        sce.dataEnumLists.put( "Fact.field3",
+        sce.putDataEnumList( "Fact.field3",
                                new String[]{"c1", "c2", "c3"} );
-        sce.dataEnumLists.put( "Fact.longerField4",
+        sce.putDataEnumList( "Fact.longerField4",
                                new String[]{"d1", "d2"} );
-        sce.dataEnumLists.put( "Fact.field5",
+        sce.putDataEnumList( "Fact.field5",
                                new String[]{"e1", "e2"} );
-        sce.dataEnumLists.put( "Fact.field6[field1=a1, field2=b2, field3=c3,longerField4=d1,field5=e2]",
+        sce.putDataEnumList( "Fact.field6[field1=a1, field2=b2, field3=c3,longerField4=d1,field5=e2]",
                                new String[]{"f1", "f2"} );
 
         FactPattern pat = new FactPattern( "Fact" );
@@ -502,10 +504,10 @@
 
     public void testSmarterLookupEnums() {
         final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-        sce.dataEnumLists = new HashMap();
-        sce.dataEnumLists.put( "Fact.type",
+        sce.setDataEnumLists(new HashMap());
+        sce.putDataEnumList( "Fact.type",
                                new String[]{"sex", "colour"} );
-        sce.dataEnumLists.put( "Fact.value[f1, f2]",
+        sce.putDataEnumList( "Fact.value[f1, f2]",
                                new String[]{"select something from database where x=@{f1} and y=@{f2}"} );
 
         FactPattern fp = new FactPattern( "Fact" );
@@ -579,12 +581,12 @@
 
     public void testSmarterLookupEnumsDifferentOrder() {
         final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-        sce.dataEnumLists = new HashMap();
-        sce.dataEnumLists.put( "Fact.type",
+        sce.setDataEnumLists(new HashMap());
+        sce.putDataEnumList( "Fact.type",
                                new String[]{"sex", "colour"} );
-        sce.dataEnumLists.put( "Fact.value[e1, e2]",
+        sce.putDataEnumList( "Fact.value[e1, e2]",
                                new String[]{"select something from database where x=@{e1} and y=@{e2}"} );
-        sce.dataEnumLists.put( "Fact.value[f1, f2]",
+        sce.putDataEnumList( "Fact.value[f1, f2]",
                                new String[]{"select something from database where x=@{f1} and y=@{f2}"} );
         
         FactPattern fp = new FactPattern( "Fact" );
@@ -658,8 +660,8 @@
 
     public void testSimpleEnums() {
         final SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-        sce.dataEnumLists = new HashMap();
-        sce.dataEnumLists.put( "Fact.type",
+        sce.setDataEnumLists(new HashMap());
+        sce.putDataEnumList( "Fact.type",
                                new String[]{"sex", "colour"} );
         assertEquals( 2,
                       sce.getEnumValues( "Fact",
@@ -688,18 +690,21 @@
     public void testGlobalAndFacts() {
         final SuggestionCompletionEngine com = new SuggestionCompletionEngine();
 
-        com.globalTypes = new HashMap() {
+        com.setGlobalVariables(new HashMap() {
             {
                 put( "y",
                      "Foo" );
             }
-        };
-        com.fieldsForType = new HashMap() {
+        });
+
+        com.setFieldsForTypes(new HashMap<String,ModelField[]>() {
             {
                 put( "Foo",
-                     new String[]{"a"} );
+                     new ModelField[]{
+                        new ModelField("a", String.class.getName(), "String")
+                });
             }
-        };
+        });
 
         assertFalse( com.isGlobalVariable( "x" ) );
         assertTrue( com.isGlobalVariable( "y" ) );

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/dt/GuidedDecisionTableTest.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/dt/GuidedDecisionTableTest.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/modeldriven/dt/GuidedDecisionTableTest.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -3,6 +3,7 @@
 import java.util.HashMap;
 
 import junit.framework.TestCase;
+import org.drools.guvnor.client.modeldriven.ModelField;
 
 import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
 import org.drools.guvnor.client.modeldriven.brl.ISingleFieldConstraint;
@@ -71,257 +72,267 @@
 //
 //
 //	}
+    public void testValueLists() {
+        GuidedDecisionTable dt = new GuidedDecisionTable();
 
-	public void testValueLists() {
-		GuidedDecisionTable dt = new GuidedDecisionTable();
+        //add cols for LHS
+        ConditionCol c1 = new ConditionCol();
+        c1.boundName = "c1";
+        c1.factType = "Driver";
+        c1.factField = "name";
+        c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        dt.conditionCols.add(c1);
 
-		//add cols for LHS
-		ConditionCol c1 = new ConditionCol();
-		c1.boundName = "c1";
-		c1.factType = "Driver";
-		c1.factField = "name";
-		c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		dt.conditionCols.add(c1);
+        ConditionCol c1_ = new ConditionCol();
+        c1_.boundName = "c1";
+        c1_.factType = "Driver";
+        c1_.factField = "name";
+        c1_.constraintValueType = ISingleFieldConstraint.TYPE_RET_VALUE;
 
-		ConditionCol c1_ = new ConditionCol();
-		c1_.boundName = "c1";
-		c1_.factType = "Driver";
-		c1_.factField = "name";
-		c1_.constraintValueType = ISingleFieldConstraint.TYPE_RET_VALUE;
+        dt.conditionCols.add(c1_);
 
-		dt.conditionCols.add(c1_);
+        ConditionCol c1__ = new ConditionCol();
+        c1__.boundName = "c1";
+        c1__.factType = "Driver";
+        c1__.factField = "name";
+        c1__.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        c1__.valueList = "one,two,three";
+        dt.conditionCols.add(c1__);
 
-		ConditionCol c1__ = new ConditionCol();
-		c1__.boundName = "c1";
-		c1__.factType = "Driver";
-		c1__.factField = "name";
-		c1__.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		c1__.valueList = "one,two,three";
-		dt.conditionCols.add(c1__);
+        ConditionCol c2 = new ConditionCol();
+        c2.boundName = "c2";
+        c2.factType = "Driver";
+        c2.factField = "nothing";
+        c2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        dt.conditionCols.add(c2);
 
-		ConditionCol c2 = new ConditionCol();
-		c2.boundName = "c2";
-		c2.factType = "Driver";
-		c2.factField = "nothing";
-		c2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		dt.conditionCols.add(c2);
 
+        ActionSetFieldCol asf = new ActionSetFieldCol();
+        asf.boundName = "c1";
+        asf.factField = "name";
+        dt.actionCols.add(asf);
 
-		ActionSetFieldCol asf = new ActionSetFieldCol();
-		asf.boundName = "c1";
-		asf.factField = "name";
-		dt.actionCols.add(asf);
+        ActionInsertFactCol ins = new ActionInsertFactCol();
+        ins.boundName = "x";
+        ins.factField = "rating";
+        ins.factType = "Person";
+        dt.actionCols.add(ins);
 
-		ActionInsertFactCol ins = new ActionInsertFactCol();
-		ins.boundName = "x";
-		ins.factField = "rating";
-		ins.factType = "Person";
-		dt.actionCols.add(ins);
+        ActionInsertFactCol ins_ = new ActionInsertFactCol();
+        ins_.boundName = "x";
+        ins_.factField = "rating";
+        ins_.factType = "Person";
+        ins_.valueList = "one,two,three";
+        dt.actionCols.add(ins_);
 
-		ActionInsertFactCol ins_ = new ActionInsertFactCol();
-		ins_.boundName = "x";
-		ins_.factField = "rating";
-		ins_.factType = "Person";
-		ins_.valueList = "one,two,three";
-		dt.actionCols.add(ins_);
+        ActionSetFieldCol asf_ = new ActionSetFieldCol();
+        asf_.boundName = "c1";
+        asf_.factField = "goo";
+        dt.actionCols.add(asf_);
 
-		ActionSetFieldCol asf_ = new ActionSetFieldCol();
-		asf_.boundName = "c1";
-		asf_.factField = "goo";
-		dt.actionCols.add(asf_);
+        ActionSetFieldCol asf__ = new ActionSetFieldCol();
+        asf__.boundName = "c1";
+        asf__.factField = "goo";
+        asf__.valueList = "one,two,three";
+        dt.actionCols.add(asf__);
 
-		ActionSetFieldCol asf__ = new ActionSetFieldCol();
-		asf__.boundName = "c1";
-		asf__.factField = "goo";
-		asf__.valueList = "one,two,three";
-		dt.actionCols.add(asf__);
 
+        SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
+        sce.putDataEnumList("Driver.name", new String[]{"bob", "michael"});
+        sce.putDataEnumList("Person.rating", new String[]{"1", "2"});
 
-		SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-		sce.dataEnumLists.put("Driver.name", new String[] {"bob", "michael"});
-		sce.dataEnumLists.put("Person.rating", new String[] {"1", "2"});
 
 
 
+        String[] r = dt.getValueList(c1, sce);
+        assertEquals(2, r.length);
+        assertEquals("bob", r[0]);
+        assertEquals("michael", r[1]);
 
-		String[] r = dt.getValueList(c1, sce);
-		assertEquals(2, r.length);
-		assertEquals("bob", r[0]);
-		assertEquals("michael", r[1]);
+        assertEquals(0, dt.getValueList(c1_, sce).length);
 
-		assertEquals(0, dt.getValueList(c1_, sce).length);
+        r = dt.getValueList(c1__, sce);
+        assertEquals(3, r.length);
+        assertEquals("one", r[0]);
+        assertEquals("two", r[1]);
+        assertEquals("three", r[2]);
 
-		r = dt.getValueList(c1__, sce);
-		assertEquals(3, r.length);
-		assertEquals("one", r[0]);
-		assertEquals("two", r[1]);
-		assertEquals("three", r[2]);
+        assertEquals(0, dt.getValueList(c2, sce).length);
 
-		assertEquals(0, dt.getValueList(c2, sce).length);
+        r = dt.getValueList(asf, sce);
+        assertEquals(2, r.length);
+        assertEquals("bob", r[0]);
+        assertEquals("michael", r[1]);
 
-		r = dt.getValueList(asf, sce);
-		assertEquals(2, r.length);
-		assertEquals("bob", r[0]);
-		assertEquals("michael", r[1]);
+        r = dt.getValueList(ins, sce);
+        assertEquals(2, r.length);
+        assertEquals("1", r[0]);
+        assertEquals("2", r[1]);
 
-		r = dt.getValueList(ins, sce);
-		assertEquals(2, r.length);
-		assertEquals("1", r[0]);
-		assertEquals("2", r[1]);
+        r = dt.getValueList(ins_, sce);
+        assertEquals(3, r.length);
+        assertEquals("one", r[0]);
+        assertEquals("two", r[1]);
+        assertEquals("three", r[2]);
 
-		r = dt.getValueList(ins_, sce);
-		assertEquals(3, r.length);
-		assertEquals("one", r[0]);
-		assertEquals("two", r[1]);
-		assertEquals("three", r[2]);
+        assertEquals(0, dt.getValueList(asf_, sce).length);
 
-		assertEquals(0, dt.getValueList(asf_, sce).length);
 
+        r = dt.getValueList(asf__, sce);
+        assertEquals(3, r.length);
+        assertEquals("one", r[0]);
+        assertEquals("two", r[1]);
+        assertEquals("three", r[2]);
 
-		r = dt.getValueList(asf__, sce);
-		assertEquals(3, r.length);
-		assertEquals("one", r[0]);
-		assertEquals("two", r[1]);
-		assertEquals("three", r[2]);
+        AttributeCol at = new AttributeCol();
+        at.attr = "no-loop";
+        dt.attributeCols.add(at);
 
-		AttributeCol at = new AttributeCol();
-		at.attr = "no-loop";
-		dt.attributeCols.add(at);
+        r = dt.getValueList(at, sce);
+        assertEquals(2, r.length);
+        assertEquals("true", r[0]);
+        assertEquals("false", r[1]);
 
-		r = dt.getValueList(at, sce);
-		assertEquals(2, r.length);
-		assertEquals("true", r[0]);
-		assertEquals("false", r[1]);
+        at.attr = "enabled";
+        assertEquals(2, dt.getValueList(at, sce).length);
 
-		at.attr = "enabled";
-		assertEquals(2, dt.getValueList(at, sce).length);
+        at.attr = "salience";
+        assertEquals(0, dt.getValueList(at, sce).length);
 
-		at.attr = "salience";
-		assertEquals(0, dt.getValueList(at, sce).length);
+    }
 
-	}
+    public void testNumeric() {
+        SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
 
+        sce.setFieldsForTypes(new HashMap<String, ModelField[]>() {
+            {
+                put("Driver",
+                        new ModelField[]{
+                            new ModelField("age", Integer.class.getName(), SuggestionCompletionEngine.TYPE_NUMERIC),
+                            new ModelField("name", String.class.getName(), SuggestionCompletionEngine.TYPE_STRING)
+                        });
+            }
+        });
 
-	public void testNumeric() {
-		SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-		sce.fieldTypes = new HashMap();
-		sce.fieldTypes.put("Driver.age", SuggestionCompletionEngine.TYPE_NUMERIC);
-		sce.fieldTypes.put("Driver.name", SuggestionCompletionEngine.TYPE_STRING);
+        GuidedDecisionTable dt = new GuidedDecisionTable();
 
-		GuidedDecisionTable dt = new GuidedDecisionTable();
+        AttributeCol at = new AttributeCol();
+        at.attr = "salience";
+        AttributeCol at_ = new AttributeCol();
+        at_.attr = "enabled";
 
-		AttributeCol at = new AttributeCol();
-		at.attr = "salience";
-		AttributeCol at_ = new AttributeCol();
-		at_.attr = "enabled";
+        dt.attributeCols.add(at);
+        dt.attributeCols.add(at_);
 
-		dt.attributeCols.add(at);
-		dt.attributeCols.add(at_);
+        ConditionCol c1 = new ConditionCol();
+        c1.boundName = "c1";
+        c1.factType = "Driver";
+        c1.factField = "name";
+        c1.operator = "==";
+        c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        dt.conditionCols.add(c1);
 
-		ConditionCol c1 = new ConditionCol();
-		c1.boundName = "c1";
-		c1.factType = "Driver";
-		c1.factField = "name";
-		c1.operator = "==";
-		c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		dt.conditionCols.add(c1);
+        ConditionCol c1_ = new ConditionCol();
+        c1_.boundName = "c1";
+        c1_.factType = "Driver";
+        c1_.factField = "age";
+        c1_.operator = "==";
+        c1_.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        dt.conditionCols.add(c1_);
 
-		ConditionCol c1_ = new ConditionCol();
-		c1_.boundName = "c1";
-		c1_.factType = "Driver";
-		c1_.factField = "age";
-		c1_.operator = "==";
-		c1_.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		dt.conditionCols.add(c1_);
+        ConditionCol c2 = new ConditionCol();
+        c2.boundName = "c1";
+        c2.factType = "Driver";
+        c2.factField = "age";
+        c2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        dt.conditionCols.add(c2);
 
-		ConditionCol c2 = new ConditionCol();
-		c2.boundName = "c1";
-		c2.factType = "Driver";
-		c2.factField = "age";
-		c2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		dt.conditionCols.add(c2);
+        ActionSetFieldCol a = new ActionSetFieldCol();
+        a.boundName = "c1";
+        a.factField = "name";
+        dt.actionCols.add(a);
 
-		ActionSetFieldCol a = new ActionSetFieldCol();
-		a.boundName = "c1";
-		a.factField = "name";
-		dt.actionCols.add(a);
+        ActionSetFieldCol a2 = new ActionSetFieldCol();
+        a2.boundName = "c1";
+        a2.factField = "age";
+        dt.actionCols.add(a2);
 
-		ActionSetFieldCol a2 = new ActionSetFieldCol();
-		a2.boundName = "c1";
-		a2.factField = "age";
-		dt.actionCols.add(a2);
+        ActionInsertFactCol ins = new ActionInsertFactCol();
+        ins.boundName = "x";
+        ins.factType = "Driver";
+        ins.factField = "name";
+        dt.actionCols.add(ins);
 
-		ActionInsertFactCol ins = new ActionInsertFactCol();
-		ins.boundName = "x";
-		ins.factType = "Driver";
-		ins.factField = "name";
-		dt.actionCols.add(ins);
+        ActionInsertFactCol ins_ = new ActionInsertFactCol();
+        ins_.boundName = "x";
+        ins_.factType = "Driver";
+        ins_.factField = "age";
+        dt.actionCols.add(ins_);
 
-		ActionInsertFactCol ins_ = new ActionInsertFactCol();
-		ins_.boundName = "x";
-		ins_.factType = "Driver";
-		ins_.factField = "age";
-		dt.actionCols.add(ins_);
+        assertTrue(dt.isNumeric(at, sce));
+        assertFalse(dt.isNumeric(at_, sce));
+        assertFalse(dt.isNumeric(c1, sce));
+        assertTrue(dt.isNumeric(c1_, sce));
+        assertFalse(dt.isNumeric(a, sce));
+        assertTrue(dt.isNumeric(a2, sce));
+        assertFalse(dt.isNumeric(ins, sce));
+        assertTrue(dt.isNumeric(ins_, sce));
+        assertFalse(dt.isNumeric(c2, sce));
 
-		assertTrue(dt.isNumeric(at, sce));
-		assertFalse(dt.isNumeric(at_, sce));
-		assertFalse(dt.isNumeric(c1, sce));
-		assertTrue(dt.isNumeric(c1_, sce));
-		assertFalse(dt.isNumeric(a, sce));
-		assertTrue(dt.isNumeric(a2, sce));
-		assertFalse(dt.isNumeric(ins, sce));
-		assertTrue(dt.isNumeric(ins_, sce));
-		assertFalse(dt.isNumeric(c2, sce));
 
 
+    }
 
-	}
+    public void testNoConstraintLists() {
+        GuidedDecisionTable dt = new GuidedDecisionTable();
 
-	public void testNoConstraintLists() {
-		GuidedDecisionTable dt = new GuidedDecisionTable();
+        //add cols for LHS
+        ConditionCol c1 = new ConditionCol();
+        c1.boundName = "c1";
+        c1.factType = "Driver";
+        c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        dt.conditionCols.add(c1);
 
-		//add cols for LHS
-		ConditionCol c1 = new ConditionCol();
-		c1.boundName = "c1";
-		c1.factType = "Driver";
-		c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		dt.conditionCols.add(c1);
+        ConditionCol c2 = new ConditionCol();
+        c2.boundName = "c2";
+        c2.factType = "Driver";
+        c2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        c2.valueList = "a,b,c";
+        dt.conditionCols.add(c2);
 
-		ConditionCol c2 = new ConditionCol();
-		c2.boundName = "c2";
-		c2.factType = "Driver";
-		c2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		c2.valueList = "a,b,c";
-		dt.conditionCols.add(c2);
 
+        SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
+        sce.putDataEnumList("Driver.name", new String[]{"bob", "michael"});
 
-		SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-		sce.dataEnumLists.put("Driver.name", new String[] {"bob", "michael"});
+        assertEquals(0, dt.getValueList(c1, sce).length);
+        assertEquals(3, dt.getValueList(c2, sce).length);
 
-		assertEquals(0, dt.getValueList(c1, sce).length);
-		assertEquals(3, dt.getValueList(c2, sce).length);
 
+    }
 
-	}
+    public void testNoConstraintsNumeric() {
+        GuidedDecisionTable dt = new GuidedDecisionTable();
 
-	public void testNoConstraintsNumeric() {
-		GuidedDecisionTable dt = new GuidedDecisionTable();
+        //add cols for LHS
+        ConditionCol c1 = new ConditionCol();
+        c1.boundName = "c1";
+        c1.factType = "Driver";
+        c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+        dt.conditionCols.add(c1);
 
-		//add cols for LHS
-		ConditionCol c1 = new ConditionCol();
-		c1.boundName = "c1";
-		c1.factType = "Driver";
-		c1.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
-		dt.conditionCols.add(c1);
+        SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
 
-		SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
-		sce.fieldTypes = new HashMap();
-		sce.fieldTypes.put("Driver.age", SuggestionCompletionEngine.TYPE_NUMERIC);
-		sce.fieldTypes.put("Driver.name", SuggestionCompletionEngine.TYPE_STRING);
+        sce.setFieldsForTypes(new HashMap<String, ModelField[]>() {
+            {
+                put("Driver",
+                        new ModelField[]{
+                            new ModelField("age", Integer.class.getName(), SuggestionCompletionEngine.TYPE_NUMERIC),
+                            new ModelField("name", String.class.getName(), SuggestionCompletionEngine.TYPE_STRING)
+                        });
+            }
+        });
 
-		assertFalse(dt.isNumeric(c1, sce));
+        assertFalse(dt.isNumeric(c1, sce));
 
-	}
-
-
+    }
 }

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SomeFact.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SomeFact.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SomeFact.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -154,4 +154,8 @@
     public void setAnEnum(EnumClass anEnum) {
         this.anEnum = anEnum;
     }
+    
+    public List<SomeFact> aMethod(int anInt) {
+    	return null;
+    }
 }

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -1,8 +1,10 @@
 package org.drools.guvnor.server.rules;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import junit.framework.TestCase;
+import org.drools.guvnor.client.modeldriven.ModelField.FIELD_CLASS_TYPE;
 
 import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
 
@@ -15,19 +17,14 @@
 
     }
 
-
     public void testSuggestionCompLoaderWildcards() throws Exception {
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
         loader.getSuggestionEngine( "package foo \n import org.drools.*", new ArrayList(), new ArrayList() );
         assertEquals(1, loader.getErrors().size());
         String err = loader.getErrors().get(0);
         assertTrue(err.startsWith("Unable"));
-
-
     }
 
-
-
     public void testLoadDifferentFieldTypes() throws Exception {
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
         SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n import org.drools.guvnor.server.rules.SomeFact", new ArrayList(), new ArrayList() );
@@ -37,6 +34,7 @@
         assertEquals(SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "SomeFact", "likes"));
         assertEquals(SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "SomeFact","name"));
         assertEquals(SuggestionCompletionEngine.TYPE_NUMERIC, eng.getFieldType("SomeFact", "bigDecimal"));
+        assertEquals(SuggestionCompletionEngine.TYPE_BOOLEAN, eng.getFieldType("SomeFact", "alive"));
 //        assertEquals(SuggestionCompletionEngine.TYPE_COMPARABLE, eng.getFieldType( "SomeFact", "date"));
         assertEquals(SuggestionCompletionEngine.TYPE_DATE, eng.getFieldType( "SomeFact", "date"));
         assertEquals("Cheese", eng.getFieldType( "SomeFact", "cheese"));
@@ -46,7 +44,15 @@
         assertEquals("SomeFact",eng.getParametricFieldType("SomeFact", "factList"));
         assertEquals(SuggestionCompletionEngine.TYPE_COLLECTION,eng.getFieldType( "SomeFact", "factListString"));
         assertEquals("String",eng.getParametricFieldType("SomeFact", "factListString"));
+    }
+    
+    public void testLoadDifferentMethodTypes() throws Exception {
+        SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
+        SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n import org.drools.guvnor.server.rules.SomeFact", new ArrayList(), new ArrayList() );
+        assertNotNull(eng);
 
+        assertEquals(List.class.getName(), eng.getMethodClassType("SomeFact", "aMethod(int)"));
+        assertEquals("SomeFact", eng.getParametricFieldType("SomeFact", "aMethod(int)"));
     }
 
     public void testGeneratedBeans() throws Exception {
@@ -55,18 +61,16 @@
         assertFalse(loader.hasErrors());
         assertNotNull(eng);
 
-        assertEquals(2, eng.factTypes.length);
-        assertEquals("GenBean", eng.factTypes[0]);
-        assertEquals("GenBean2", eng.factTypes[1]);
+        assertEquals(2, eng.getFactTypes().length);
+        assertEquals("GenBean", eng.getFactTypes()[0]);
+        assertEquals("GenBean2", eng.getFactTypes()[1]);
 
         assertEquals(SuggestionCompletionEngine.TYPE_NUMERIC, eng.getFieldType( "GenBean", "id" ));
         assertEquals(SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "GenBean", "name"));
 
         assertEquals("GenBean", eng.getFieldType("GenBean2", "gb"));
-
     }
 
-
     public void testGlobal() throws Exception {
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
         SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n global org.drools.Person p", new ArrayList(), new ArrayList() );
@@ -75,16 +79,14 @@
 
         assertEquals(1, eng.getGlobalVariables().length);
         assertEquals("p", eng.getGlobalVariables()[0]);
-        assertEquals("Person", eng.globalTypes.get("p"));
-        String[] flds = (String[]) eng.fieldsForType.get("Person");
+        assertEquals("Person", eng.getGlobalVariable("p"));
+        String[] flds = (String[]) eng.getModelFields("Person");
         assertNotNull(flds);
 
-        assertEquals(0, eng.globalCollections.length);
-
+        assertEquals(0, eng.getGlobalCollections().length);
     }
 
-
-     public void testGlobalCollections() throws Exception {
+    public void testGlobalCollections() throws Exception {
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
         SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n global java.util.List ls", new ArrayList(), new ArrayList() );
         assertNotNull(eng);
@@ -92,13 +94,11 @@
 
         assertEquals(1, eng.getGlobalVariables().length);
         assertEquals("ls", eng.getGlobalVariables()[0]);
-        assertEquals("List", eng.globalTypes.get("ls"));
+        assertEquals("List", eng.getGlobalVariable("ls"));
 
-        assertNotNull(eng.globalCollections);
-        assertEquals(1, eng.globalCollections.length);
-         assertEquals("ls", eng.globalCollections[0]);
-
-
+        assertNotNull(eng.getGlobalCollections());
+        assertEquals(1, eng.getGlobalCollections().length);
+        assertEquals("ls", eng.getGlobalCollections()[0]);
     }
 
     public void testSortOrderOfFields() throws Exception {
@@ -113,22 +113,20 @@
 	    assertEquals("alive", fields[1]);
         assertEquals("anEnum", fields[2]);
 	    assertEquals("bigDecimal", fields[3]);
-
     }
+    
     public void testEnumFields() throws Exception {
-
 	    SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
 	    SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n import org.drools.guvnor.server.rules.SomeFact", new ArrayList(), new ArrayList() );
 	    assertNotNull(eng);
-        assertNotNull(eng.dataEnumLists);
-        assertEquals(eng.dataEnumLists.get("SomeFact.anEnum").length,3);
-        String a[] = eng.dataEnumLists.get("SomeFact.anEnum") ;
+        assertTrue(eng.hasDataEnumLists());
+        assertEquals(eng.getDataEnumList("SomeFact.anEnum").length,3);
+        String a[] = eng.getDataEnumList("SomeFact.anEnum") ;
         assertEquals(a[0],"0="+EnumClass.v1);
         assertEquals(a[1],"1="+EnumClass.v2);
         assertEquals(a[2],"2="+EnumClass.v3);
+    }
 
-
-    }
     public void testSortOrderOfFacts() throws Exception {
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
         SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n import org.drools.guvnor.server.rules.SomeFact\n import org.drools.Person", new ArrayList(), new ArrayList() );
@@ -138,27 +136,63 @@
 
         assertEquals("Person", facts[0]);
         assertEquals("SomeFact", facts[1]);
+    }
 
+    public void testTypeDeclarations() throws Exception {
+        SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
 
+        String header ="";
+        header += "package foo\n";
+
+        header += "declare Applicant\n";
+	header += "     creditRating: String\n";
+	header += "     approved: Boolean\n";
+	header += "     applicationDate: java.util.Date\n";
+	header += "     age: Integer\n";
+	header += "     name: String\n";
+        header += "end\n";
+
+        header += "declare LoanApplication\n";
+	header += "     amount: Integer\n";
+	header += "     approved: Boolean\n";
+	header += "     deposit: Integer\n";
+	header += "     approvedRate: Integer\n";
+	header += "     lengthYears: Integer\n";
+	header += "     explanation: String\n";
+	header += "     insuranceCost: Integer\n";
+	header += "     applicant: Applicant\n";
+        header += "end\n";
+
+        SuggestionCompletionEngine eng = loader.getSuggestionEngine( header, new ArrayList(), new ArrayList() );
+        assertNotNull(eng);
+
+        assertEquals(SuggestionCompletionEngine.TYPE_STRING, eng.getFieldType( "Applicant", "creditRating" ));
+        assertEquals("java.lang.String", eng.getFieldClassName( "Applicant", "creditRating" ));
+        assertEquals(FIELD_CLASS_TYPE.REGULAR_CLASS, eng.getFieldClassType( "Applicant", "creditRating" ));
+
+        assertEquals(SuggestionCompletionEngine.TYPE_NUMERIC, eng.getFieldType( "LoanApplication", "deposit" ));
+        assertEquals("java.lang.Integer", eng.getFieldClassName( "LoanApplication", "deposit" ));
+        assertEquals(FIELD_CLASS_TYPE.REGULAR_CLASS, eng.getFieldClassType( "LoanApplication", "deposit" ));
+
+        assertEquals("Applicant", eng.getFieldType( "LoanApplication", "applicant" ));
+        assertNull(eng.getFieldClassName( "LoanApplication", "applicant" ));
+        assertEquals(FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS, eng.getFieldClassType( "LoanApplication", "applicant" ));
     }
 
-
     public void testLoaderWithExistingClassloader() throws Exception {
         MockClassLoader mcl = new MockClassLoader();
         SuggestionCompletionLoader loader = new SuggestionCompletionLoader(mcl);
         SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n import org.foo.Bar", new ArrayList(), new ArrayList() );
         assertNotNull(eng);
-        assertNotNull(eng.dataEnumLists);
+        //assertNotNull(eng.dataEnumLists);
         assertTrue(mcl.called);
-
     }
 
-
     static class MockClassLoader extends ClassLoader {
 
         public boolean called = false;
 
-        public Class loadClass(String name) {
+        public Class<?> loadClass(String name) {
             called = true;
             return Object.class;
         }

Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java	2010-01-27 16:33:21 UTC (rev 31257)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-core/src/main/java/org/drools/base/ClassTypeResolver.java	2010-01-27 16:38:16 UTC (rev 31258)
@@ -109,8 +109,8 @@
     /* (non-Javadoc)
      * @see org.drools.semantics.java.TypeResolver#resolveType(java.lang.String)
      */
-    public Class resolveType(String className) throws ClassNotFoundException {
-        Class clazz = null;
+    public Class<?> resolveType(String className) throws ClassNotFoundException {
+        Class<?> clazz = null;
         boolean isArray = false;
         final StringBuilder arrayClassName = new StringBuilder();
 



More information about the jboss-svn-commits mailing list