Package org.codehaus.groovy.runtime
Class MethodRankHelper
java.lang.Object
org.codehaus.groovy.runtime.MethodRankHelper
Utility class for MissingMethodException, MissingPropertyException, etc.
Contains methods for assisting in ranking and listing probable intended
methods/fields when an exception is thrown.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCost for case change in Damerau-Levenshtein distance calculation.static final intCost for delete operation in Damerau-Levenshtein distance calculation (also used for insert).static final intCost for substitution in Damerau-Levenshtein distance calculation.static final intCost for transposition in Damerau-Levenshtein distance calculation.static final intMaximum score threshold for constructor ranking.static final intMaximum score threshold for field ranking.static final intMaximum score threshold for method ranking.static final intMaximum number of method recommendations to suggest. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static ClassIf c is a primitive class this method returns a boxed version otherwise c is returned.static intdamerauLevenshteinDistance(Object[] s, Object[] t) This is an implementation of DL distance between two Object arrays instead of character streams.static intThis is a slightly modified version of the Damerau Levenshtein distance algorithm.static StringgetConstructorSuggestionString(Class type, Object[] arguments) Returns a string detailing possible solutions to a missing constructor if no good solutions can be found an empty string is returned.static StringgetMethodSuggestionString(String methodName, Class type, Object[] arguments) Returns a string detailing possible solutions to a missing method if no good solutions can be found an empty string is returned.static StringgetPropertySuggestionString(String name, Class type) Returns a string detailing possible solutions to a missing field/property if no good solutions can be found an empty string is returned.
-
Field Details
-
DL_CASE
public static final int DL_CASECost for case change in Damerau-Levenshtein distance calculation.- See Also:
-
DL_DELETE
public static final int DL_DELETECost for delete operation in Damerau-Levenshtein distance calculation (also used for insert).- See Also:
-
DL_SUBSTITUTION
public static final int DL_SUBSTITUTIONCost for substitution in Damerau-Levenshtein distance calculation.- See Also:
-
DL_TRANSPOSITION
public static final int DL_TRANSPOSITIONCost for transposition in Damerau-Levenshtein distance calculation.- See Also:
-
MAX_RECOMENDATIONS
public static final int MAX_RECOMENDATIONSMaximum number of method recommendations to suggest.- See Also:
-
MAX_METHOD_SCORE
public static final int MAX_METHOD_SCOREMaximum score threshold for method ranking.- See Also:
-
MAX_CONSTRUCTOR_SCORE
public static final int MAX_CONSTRUCTOR_SCOREMaximum score threshold for constructor ranking.- See Also:
-
MAX_FIELD_SCORE
public static final int MAX_FIELD_SCOREMaximum score threshold for field ranking.- See Also:
-
-
Constructor Details
-
MethodRankHelper
public MethodRankHelper()
-
-
Method Details
-
getMethodSuggestionString
Returns a string detailing possible solutions to a missing method if no good solutions can be found an 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
Returns a string detailing possible solutions to a missing constructor if no good solutions can be found an 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
Returns a string detailing possible solutions to a missing field/property if no good solutions can be found an empty string is returned.- Parameters:
name- the missing field/propertytype- the class on which the field is sought- Returns:
- a string with probable solutions to the exception
-
boxVar
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
This is a slightly modified version of the Damerau Levenshtein distance algorithm. It has an 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
This is an 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
-