openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r681807 - in /openjpa/trunk/openjpa-kernel/src/main: java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java java/org/apache/openjpa/meta/ClassMetaData.java resources/org/apache/openjpa/kernel/jpql/localizer.properties
Date Fri, 01 Aug 2008 20:05:19 GMT
Author: ppoddar
Date: Fri Aug  1 13:05:18 2008
New Revision: 681807

URL: http://svn.apache.org/viewvc?rev=681807&view=rev
Log:
OPENJPA-75: Error message for missing identification variable shows nearest Levensthien choice
and all avaialble choices

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java?rev=681807&r1=681806&r2=681807&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
Fri Aug  1 13:05:18 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.kernel.exps;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -27,6 +28,7 @@
 
 import org.apache.openjpa.kernel.Filters;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.StringDistance;
 import org.apache.openjpa.lib.util.Localizer.Message;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -280,9 +282,14 @@
         FieldMetaData fmd = meta.getField(field);
         if (fmd == null) {
             Object val = traverseStaticField(meta.getDescribedType(), field);
-            if (val == null)
+            if (val == null) {
+            	String[] all = meta.getFieldNames();
+            	Class cls = meta.getDescribedType();
                 throw parseException(EX_USER, "no-field",
-                    new Object[]{ meta.getDescribedType(), field }, null);
+                    new Object[] {field, cls.getSimpleName(), 
+                	StringDistance.getClosestLevenshteinDistance(field, all), 
+                	cls.getName(), Arrays.toString(all)}, null);
+            }
 
             return factory.newLiteral(val, Literal.TYPE_UNKNOWN);
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=681807&r1=681806&r2=681807&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Fri Aug  1 13:05:18 2008
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -2375,4 +2376,29 @@
     		_cacheTimeout = Integer.MIN_VALUE;
     	}
     }
+    
+    /**
+     * Utility method to get names of all fields including the superclasses'
+     * sorted in lexical order.
+     */
+    public String[] getFieldNames() {
+    	return toNames(getFields());
+    }
+    
+    /**
+     * Utility method to get names of all declared fields excluding the 
+     * superclasses' sorted in lexical order.
+     */
+    public String[] getDeclaredFieldNames() {
+    	return toNames(getDeclaredFields());
+    }
+    
+    String[] toNames(FieldMetaData[] fields) {
+    	List<String> result = new ArrayList<String>();
+    	for (FieldMetaData fmd : fields) {
+    		result.add(fmd.getName());
+    	}
+    	Collections.sort(result);
+    	return result.toArray(new String[result.size()]);
+    }
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties?rev=681807&r1=681806&r2=681807&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/jpql/localizer.properties
Fri Aug  1 13:05:18 2008
@@ -28,9 +28,10 @@
 cant-resolve-type: The entity "{0}" cannot be resolved; please ensure that \
 	the entity name has been declared for the class.
 not-identifer: The specified node ("{0}") is not a valid identifier.
-no-field: No field named "{1}" in class "{0}".
+no-field: No field named "{0}" in "{1}". Did you mean "{2}"? Expected one of \
+	the available field names in "{3}": "{4}".
 unaccessible-field: The field named "{1}" in class "{0}" could not be accessed.
-multi-children: Expression "{0}" does not allow mutliple children ("{1}").
+multi-children: Expression "{0}" does not allow multiple children ("{1}").
 no-children: Expression "{0}" requires at least one child.
 unknown-comp: Unknown comparison operator "{0}".
 wrong-child-count: Wrong number of arguments to expression \



Mime
View raw message