Top Description Inners Fields Constructors Methods
org.codehaus.groovy.runtime

public Class MethodRankHelper

extends Object
Class Inheritance
Imports
groovy.lang.MetaMethod, .MetaProperty, org.codehaus.groovy.reflection.CachedClass, .ClassInfo, java.lang.reflect.Constructor, java.util.ArrayList, .Arrays, .Collections, .HashSet, .LinkedList, .List, .Set

Utility class for MissingMethodException, MissingPropertyException etc. This class contains methods assisting in ranking and listing probable intended methods/fields when a exception is thrown.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MethodRankHelper.NullObject

This is a small wrapper for nulls

private static class
private static class
MethodRankHelper.RankableConstructor

This class wraps a method object and a score variable so methods Can easily be ranked by their likeness to a another method

private static class
MethodRankHelper.RankableField

This class wraps a method object and a score variable so methods Can easily be ranked by their likeness to a another method

private static class
MethodRankHelper.RankableMethod

This class wraps a method object and a score variable so methods Can easily be ranked by their likeness to a another method

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
private static final Object[]
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static Class<T>

Returns:

a boxed version of c if c can be boxed, else c
boxVar
(Class<T> c)

If c is a primitive class this method returns a boxed version otherwise c is returned.

private static boolean

Returns:

true if the characters are equal
caselessCompare
(char
the first character
a
,
char
the second character
b
)

Compares two characters whilst ignoring case.

public static int

Returns:

the edit distance between the two arrays
damerauLevenshteinDistance
(Object[]
an Object array
s
,
Object[]
this array is compared to s
t
)

This is a implementation of DL distance between two Object arrays instead of character streams.

public static int

Returns:

a value representing the edit distance between s and t
delDistance
(CharSequence
a CharSequence
s
,
CharSequence
the CharSequence to be compared to s
t
)

This is a slightly modified version of the Damerau Levenshtein distance algorithm.

private static Class<T>[]
private static List<MethodRankHelper.Pair<Class<T>, Class<T>>>
getConflictClasses(List<MetaMethod> sugg, Class<T>[] argumentClasses)

public static String

Returns:

a string with probable solutions to the exception
getConstructorSuggestionString
(Class<T>
the class on which the constructor is invoked
type
,
Object[]
the arguments passed to the constructor
arguments
)

Returns a string detailing possible solutions to a missing constructor if no good solutions can be found a empty string is returned.

public static String

Returns:

a string with probable solutions to the exception
getMethodSuggestionString
(String
the name of the method that doesn't exist
methodName
,
Class<T>
the class on which the method is invoked
type
,
Object[]
the arguments passed to the method
arguments
)

Returns a string detailing possible solutions to a missing method if no good solutions can be found a empty string is returned.

public static String

Returns:

a string with probable solutions to the exception
getPropertySuggestionString
(String
the missing field
fieldName
,
Class<T>
the class on which the field is sought
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.

private static String

Returns:

the Class names
listParameterNames
(Class<T>[]
the array of Classes
cachedClasses
)

creates a comma separated list of each of the class names.

private static String
private static Constructor<T>[]

Returns:

a sorted lists of Methods
rankConstructors
(Object[] original, Constructor<T>[] candidates)

Returns a sorted(ranked) list of a selection of the constructors among candidates which most closely resembles original.

private static List<MetaMethod>

Returns:

a sorted lists of Methods
rankMethods
(String name, Object[] original, List<MetaMethod> methods)

Returns a sorted(ranked) list of a selection of the methods among candidates which most closely resembles original.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DL_CASEback to summary
public static final int DL_CASE
DL_DELETEback to summary
public static final int DL_DELETE
DL_SUBSTITUTIONback to summary
public static final int DL_SUBSTITUTION
DL_TRANSPOSITIONback to summary
public static final int DL_TRANSPOSITION
EMPTY_OBJECT_ARRAYback to summary
private static final Object[] EMPTY_OBJECT_ARRAY
MAX_CONSTRUCTOR_SCOREback to summary
public static final int MAX_CONSTRUCTOR_SCORE
MAX_FIELD_SCOREback to summary
public static final int MAX_FIELD_SCORE
MAX_METHOD_SCOREback to summary
public static final int MAX_METHOD_SCORE
MAX_RECOMENDATIONSback to summary
public static final int MAX_RECOMENDATIONS

Constructor Detail

MethodRankHelperback to summary
public MethodRankHelper()

Method Detail

boxVarback to summary
protected static Class<T> boxVar(Class<T> 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.

Returns:Class<T>

a boxed version of c if c can be boxed, else c

caselessCompareback to summary
private static boolean caselessCompare(char a, char b)

Compares two characters whilst ignoring case.

Parameters
a:char

the first character

b:char

the second character

Returns:boolean

true if the characters are equal

damerauLevenshteinDistanceback to summary
public static int damerauLevenshteinDistance(Object[] s, 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:Object[]

an Object array

t:Object[]

this array is compared to s

Returns:int

the edit distance between the two arrays

delDistanceback to summary
public static int delDistance(CharSequence s, 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:CharSequence

a CharSequence

t:CharSequence

the CharSequence to be compared to s

Returns:int

a value representing the edit distance between s and t

getArgumentClassesback to summary
private static Class<T>[] getArgumentClasses(Object[] arguments)
getConflictClassesback to summary
private static List<MethodRankHelper.Pair<Class<T>, Class<T>>> getConflictClasses(List<MetaMethod> sugg, Class<T>[] argumentClasses)
getConstructorSuggestionStringback to summary
public static String getConstructorSuggestionString(Class<T> type, 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
type:Class<T>

the class on which the constructor is invoked

arguments:Object[]

the arguments passed to the constructor

Returns:String

a string with probable solutions to the exception

getMethodSuggestionStringback to summary
public static String getMethodSuggestionString(String methodName, Class<T> type, 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:String

the name of the method that doesn't exist

type:Class<T>

the class on which the method is invoked

arguments:Object[]

the arguments passed to the method

Returns:String

a string with probable solutions to the exception

getPropertySuggestionStringback to summary
public static String getPropertySuggestionString(String fieldName, Class<T> 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:String

the missing field

type:Class<T>

the class on which the field is sought

Returns:String

a string with probable solutions to the exception

listParameterNamesback to summary
private static String listParameterNames(Class<T>[] cachedClasses)

creates a comma separated list of each of the class names.

Parameters
cachedClasses:Class<T>[]

the array of Classes

Returns:String

the Class names

listParameterNamesback to summary
private static String listParameterNames(CachedClass[] cachedClasses)
rankConstructorsback to summary
private static Constructor<T>[] rankConstructors(Object[] original, Constructor<T>[] candidates)

Returns a sorted(ranked) list of a selection of the constructors among candidates which most closely resembles original.

Returns:Constructor<T>[]

a sorted lists of Methods

rankMethodsback to summary
private static List<MetaMethod> rankMethods(String name, Object[] original, List<MetaMethod> methods)

Returns a sorted(ranked) list of a selection of the methods among candidates which most closely resembles original.

Returns:List<MetaMethod>

a sorted lists of Methods

org.codehaus.groovy.runtime back to summary

private Class MethodRankHelper.NullObject

extends Object
Class Inheritance

This is a small wrapper for nulls

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NullObjectback to summary
private NullObject()
org.codehaus.groovy.runtime back to summary

private final Class MethodRankHelper.Pair<U, V>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final U
u

private final V
v

Constructor Summary

AccessConstructor and Description
public
Pair(U u, V v)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

uback to summary
private final U u
vback to summary
private final V v

Constructor Detail

Pairback to summary
public Pair(U u, V v)
org.codehaus.groovy.runtime back to summary

private final Class MethodRankHelper.RankableConstructor

extends Object
implements Comparable
Class Inheritance
  • java.lang.Object
  • org.codehaus.groovy.runtime.MethodRankHelper.RankableConstructor
All Implemented Interfaces
java.lang.Comparable

This class wraps a method object and a score variable so methods Can easily be ranked by their likeness to a another method

Field Summary

Modifier and TypeField and Description
pack-priv final Constructor<T>
c

pack-priv final Integer

Constructor Summary

AccessConstructor and Description
public
RankableConstructor(Class<T>[] argumentTypes, Constructor<T> c)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Object
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cback to summary
pack-priv final Constructor<T> c
scoreback to summary
pack-priv final Integer score

Constructor Detail

RankableConstructorback to summary
public RankableConstructor(Class<T>[] argumentTypes, Constructor<T> c)

Method Detail

compareToback to summary
public int compareTo(Object o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:Object

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

org.codehaus.groovy.runtime back to summary

private final Class MethodRankHelper.RankableField

extends Object
implements Comparable
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

This class wraps a method object and a score variable so methods Can easily be ranked by their likeness to a another method

Field Summary

Modifier and TypeField and Description
pack-priv final MetaProperty
f

pack-priv final Integer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Object
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fback to summary
pack-priv final MetaProperty f
scoreback to summary
pack-priv final Integer score

Constructor Detail

RankableFieldback to summary
public RankableField(String name, MetaProperty mp)

Method Detail

compareToback to summary
public int compareTo(Object o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:Object

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

org.codehaus.groovy.runtime back to summary

private final Class MethodRankHelper.RankableMethod

extends Object
implements Comparable
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

This class wraps a method object and a score variable so methods Can easily be ranked by their likeness to a another method

Field Summary

Modifier and TypeField and Description
pack-priv final MetaMethod
m

pack-priv final Integer

Constructor Summary

AccessConstructor and Description
public
RankableMethod(String name, Class<T>[] argumentTypes, MetaMethod m2)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Object
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mback to summary
pack-priv final MetaMethod m
scoreback to summary
pack-priv final Integer score

Constructor Detail

RankableMethodback to summary
public RankableMethod(String name, Class<T>[] argumentTypes, MetaMethod m2)

Method Detail

compareToback to summary
public int compareTo(Object o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
o:Object

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.