Package org.codehaus.groovy.runtime
Class MethodRankHelper
java.lang.Object
org.codehaus.groovy.runtime.MethodRankHelper
public class MethodRankHelper
extends java.lang.Object
Utility class for MissingMethodException, MissingPropertyException etc.
This class contains methods assisting in ranking and listing probable intended
methods/fields when a exception is thrown.
-
Field Summary
Fields Modifier and Type Field Description static int
DL_CASE
static int
DL_DELETE
static int
DL_SUBSTITUTION
static int
DL_TRANSPOSITION
static int
MAX_CONSTRUCTOR_SCORE
static int
MAX_FIELD_SCORE
static int
MAX_METHOD_SCORE
static int
MAX_RECOMENDATIONS
-
Constructor Summary
Constructors Constructor Description MethodRankHelper()
-
Method Summary
Modifier and Type Method Description protected static java.lang.Class
boxVar(java.lang.Class c)
If c is a primitive class this method returns a boxed version otherwise c is returned.static int
damerauLevenshteinDistance(java.lang.Object[] s, java.lang.Object[] t)
This is a implementation of DL distance between two Object arrays instead of character streams.static int
delDistance(java.lang.CharSequence s, java.lang.CharSequence t)
This is a slightly modified version of the Damerau Levenshtein distance algorithm.static java.lang.String
getConstructorSuggestionString(java.lang.Class type, java.lang.Object[] arguments)
Returns a string detailing possible solutions to a missing constructor if no good solutions can be found a empty string is returned.static java.lang.String
getMethodSuggestionString(java.lang.String methodName, java.lang.Class type, java.lang.Object[] arguments)
Returns a string detailing possible solutions to a missing method if no good solutions can be found a empty string is returned.static java.lang.String
getPropertySuggestionString(java.lang.String fieldName, java.lang.Class type)
Returns a string detailing possible solutions to a missing field or property if no good solutions can be found a empty string is returned.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DL_SUBSTITUTION
public static final int DL_SUBSTITUTION- See Also:
- Constant Field Values
-
DL_DELETE
public static final int DL_DELETE- See Also:
- Constant Field Values
-
DL_TRANSPOSITION
public static final int DL_TRANSPOSITION- See Also:
- Constant Field Values
-
DL_CASE
public static final int DL_CASE- See Also:
- Constant Field Values
-
MAX_RECOMENDATIONS
public static final int MAX_RECOMENDATIONS- See Also:
- Constant Field Values
-
MAX_METHOD_SCORE
public static final int MAX_METHOD_SCORE- See Also:
- Constant Field Values
-
MAX_CONSTRUCTOR_SCORE
public static final int MAX_CONSTRUCTOR_SCORE- See Also:
- Constant Field Values
-
MAX_FIELD_SCORE
public static final int MAX_FIELD_SCORE- See Also:
- Constant Field Values
-
-
Constructor Details
-
MethodRankHelper
public MethodRankHelper()
-
-
Method Details
-
getMethodSuggestionString
public static java.lang.String getMethodSuggestionString(java.lang.String methodName, java.lang.Class type, java.lang.Object[] arguments)Returns a string detailing possible solutions to a missing method if no good solutions can be found a empty string is returned.- Parameters:
methodName
- the name of the method that doesn't existtype
- the class on which the method is invokedarguments
- the arguments passed to the method- Returns:
- a string with probable solutions to the exception
-
getConstructorSuggestionString
public static java.lang.String getConstructorSuggestionString(java.lang.Class type, java.lang.Object[] arguments)Returns a string detailing possible solutions to a missing constructor if no good solutions can be found a empty string is returned.- Parameters:
arguments
- the arguments passed to the constructortype
- the class on which the constructor is invoked- Returns:
- a string with probable solutions to the exception
-
getPropertySuggestionString
public static java.lang.String getPropertySuggestionString(java.lang.String fieldName, java.lang.Class type)Returns a string detailing possible solutions to a missing field or property if no good solutions can be found a empty string is returned.- Parameters:
fieldName
- the missing fieldtype
- the class on which the field is sought- Returns:
- a string with probable solutions to the exception
-
boxVar
protected static java.lang.Class boxVar(java.lang.Class c)If c is a primitive class this method returns a boxed version otherwise c is returned. In java 1.5 this can be simplified thanks to the Type class.- Parameters:
c
-- Returns:
- a boxed version of c if c can be boxed, else c
-
delDistance
public static int delDistance(java.lang.CharSequence s, java.lang.CharSequence t)This is a slightly modified version of the Damerau Levenshtein distance algorithm. It has a additional test to see if a character has switched case, in the original algorithm this counts as a substitution. The "cost" for a substitution is given as 10 instead of 1 in this version, this enables transpositions and case modifications to have a lower cost than substitutions. Currently the lowercase versions of t_j and s_i isn't cached, its probable that some speed could be gained from this. This version is based on Chas Emerick's implementation of Levenshtein Distance for jakarta commons.- Parameters:
s
- a CharSequencet
- the CharSequence to be compared to s- Returns:
- a value representing the edit distance between s and t
-
damerauLevenshteinDistance
public static int damerauLevenshteinDistance(java.lang.Object[] s, java.lang.Object[] t)This is a implementation of DL distance between two Object arrays instead of character streams. The objects are compared using their equals method. No objects may be null. This implementation is based on Chas Emerick's implementation of Levenshtein Distance for jakarta commons.- Parameters:
s
- an Object arrayt
- this array is compared to s- Returns:
- the edit distance between the two arrays
-