[Groovy] Class ReflectionCompletor

  • org.codehaus.groovy.tools.shell.completion.ReflectionCompletor

Completes fields and methods of Classes or instances. Does not quite respect the contract of IdentifierCompletor, as last Token may be a dot or not, thus also returns as int the cursor position.

Properties Summary

Properties
Type Name and description
Groovysh shell

Constructor Summary

Constructors
Constructor and description
ReflectionCompletor (Groovysh shell)
@param shell

Methods Summary

Methods
Type Params Return Type Name and description
static boolean acceptName(String name, String prefix)
int complete(List<GroovySourceToken> tokens, List<CharSequence> candidates)
static List<String> getDefaultMethods(Object instance, String prefix)
Offering all DefaultGroovyMethods on any object is too verbose, hiding all removes user-friendliness.
static CharSequence getFieldnameForAccessor(String accessor, int parameterLength)
Object getInvokerClassOrInstance(List<GroovySourceToken> groovySourceTokens)
Takes the last ?
static List<GroovySourceToken> getInvokerTokens(List<GroovySourceToken> groovySourceTokens)
return the last tokens of a list that form an expression to be completed after the next dot, or null if expression cannot be detected.
static Collection<String> getMetaclassMethods(Object instance, String prefix, boolean includeMetaClassImplMethods)
static Collection<ReflectionCompletionCandidate> getPublicFieldsAndMethods(Object instance, String prefix)
Build a list of public fields and methods for an object that match a given prefix.
static def removeStandardMethods(Collection<ReflectionCompletionCandidate> candidates)
removes candidates that, most of the times, a programmer does not want to see in completion
static String tokenListToEvalString(List<GroovySourceToken> groovySourceTokens)

Inherited Methods Summary

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

Property Detail

final Groovysh shell

Constructor Detail

ReflectionCompletor(Groovysh shell)

Parameters:
shell
metaclass_completion_prefix_length - how long the prefix must be to display candidates from metaclass

Method Detail

static boolean acceptName(String name, String prefix)

int complete(List<GroovySourceToken> tokens, List<CharSequence> candidates)

static List<String> getDefaultMethods(Object instance, String prefix)

Offering all DefaultGroovyMethods on any object is too verbose, hiding all removes user-friendliness. So here util methods will be added to candidates if the instance is of a suitable type. This does not need to be strictly complete, only the most useful functions may appear.

static CharSequence getFieldnameForAccessor(String accessor, int parameterLength)

Object getInvokerClassOrInstance(List<GroovySourceToken> groovySourceTokens)

Takes the last ? tokens of the list that form a simple expression, evaluates it and returns a result. "Simple" means evaluation is known to be side-effect free.

static List<GroovySourceToken> getInvokerTokens(List<GroovySourceToken> groovySourceTokens)

return the last tokens of a list that form an expression to be completed after the next dot, or null if expression cannot be detected. This discards Expressions that could easily have side effects or be long in evaluation. However it assumes that operators can be evaluated without side-effect or long running operation. Users who use operators for which this does not hold should not use tab completion.

Parameters:
groovySourceTokens
Returns:

static Collection<String> getMetaclassMethods(Object instance, String prefix, boolean includeMetaClassImplMethods)

static Collection<ReflectionCompletionCandidate> getPublicFieldsAndMethods(Object instance, String prefix)

Build a list of public fields and methods for an object that match a given prefix.

Parameters:
instance - the object
prefix - the prefix that must be matched
Returns:
the list of public methods and fields that begin with the prefix

static def removeStandardMethods(Collection<ReflectionCompletionCandidate> candidates)

removes candidates that, most of the times, a programmer does not want to see in completion

Parameters:
candidates

static String tokenListToEvalString(List<GroovySourceToken> groovySourceTokens)

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.5.14/html/gapi/org/codehaus/groovy/tools/shell/completion/ReflectionCompletor.html