Groovy 1.7.0

org.codehaus.groovy.runtime
Class MethodRankHelper

java.lang.Object
  org.codehaus.groovy.runtime.MethodRankHelper

class MethodRankHelper
extends Object

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

author:
Hjalmar Ekengren


Nested Class Summary
class MethodRankHelper.NullObject

This is a small wrapper for nulls

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

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

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
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
MethodRankHelper()

 
Method Summary
protected static Class boxVar(Class c)

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

static int damerauLevenshteinDistance(Object[] s, Object[] t)

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

static int delDistance(CharSequence s, CharSequence t)

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

static String getConstructorSuggestionString(Class 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.

static String getMethodSuggestionString(String methodName, Class 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.

static String getPropertySuggestionString(String fieldName, Class type)

Returns a string detailing possible solutions to a missning field or property if no good solutions can be found a empty string is returned.

 
Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll
 

Field Detail

DL_CASE

static final int DL_CASE


DL_DELETE

static final int DL_DELETE


DL_SUBSTITUTION

static final int DL_SUBSTITUTION


DL_TRANSPOSITION

static final int DL_TRANSPOSITION


MAX_CONSTRUCTOR_SCORE

static final int MAX_CONSTRUCTOR_SCORE


MAX_FIELD_SCORE

static final int MAX_FIELD_SCORE


MAX_METHOD_SCORE

static final int MAX_METHOD_SCORE


MAX_RECOMENDATIONS

static final int MAX_RECOMENDATIONS


 
Constructor Detail

MethodRankHelper

MethodRankHelper()


 
Method Detail

boxVar

protected static Class boxVar(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.
param:
c
return:
a boxed version of c if c can be boxed, else c


damerauLevenshteinDistance

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 Lenenshtein Distance for jakarta commons.
param:
s a Object array
param:
t this array is compared to s
return:
the edit distance between the two arrays


delDistance

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 charackter 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 isnt cached, its probable that some speed could be gained from this. This version is based on Chas Emerick's implementation of Lenenshtein Distance for jakarta commons.
param:
s a CharSequence
param:
t the CharSequence to be compared to s
return:
a value representing the edit distance between s and t


getConstructorSuggestionString

public static String getConstructorSuggestionString(Class 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.
param:
arguments the arguments passed to the constructor
param:
type the class on which the constructor is invoked
return:
a string with probable solutions to the exception


getMethodSuggestionString

public static String getMethodSuggestionString(String methodName, Class 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.
param:
methodName the name of the method that doesn't exist
param:
type the class on which the method is invoked
param:
arguments the arguments passed to the method
return:
a string with probable solutions to the exception


getPropertySuggestionString

public static String getPropertySuggestionString(String fieldName, Class type)
Returns a string detailing possible solutions to a missning field or property if no good solutions can be found a empty string is returned.
param:
fieldname the missing field
param:
type the class on which the field is sought
return:
a string with probable solutions to the exception


 

Copyright © 2003-2009 The Codehaus. All rights reserved.