Skip to content

it

The current context object. This is the most important tool as it provides access to the element being processed. The type of it depends on the rule context.

Context Types

The type of it depends on the rule context:

Rule Contextit TypeDescription
Class rulesScriptPsiClassContextClass-level operations
Method rulesScriptPsiMethodContextMethod-level operations
Field rulesScriptPsiFieldContextField-level operations
Parameter rulesScriptPsiParameterContextParameter-level operations
Type rulesScriptTypeContextType information

Common Methods (All Contexts)

These methods are available on all context types:

Name and Documentation

MethodReturn TypeDescription
it.name()StringGet the element name
it.getName()String?Get the element name (nullable)
it.doc()String?Get the Javadoc/KDoc comment text
it.doc(tag)String?Get a specific doc tag value
it.docs(tag)List<String>?Get all values for a doc tag
it.hasDoc(tag)BooleanCheck if a doc tag exists
it.doc(tag, subTag)String?Get a doc tag with sub-tag (e.g., @param name desc)

Annotations

MethodReturn TypeDescription
it.hasAnn(name)BooleanCheck if an annotation exists
it.ann(name)String?Get annotation attribute value (defaults to "value")
it.ann(name, attr)String?Get specific annotation attribute as string
it.annValue(name)Any?Get annotation attribute value as Any
it.annValue(name, attr)Any?Get specific annotation attribute as Any
it.annMap(name)Map<String, Any?>?Get all annotation attributes as map
it.annMaps(name)List<Map<String, Any?>>?Get all repeatable annotations

Modifiers

MethodReturn TypeDescription
it.hasModifier(modifier)BooleanCheck if a modifier exists (e.g., "static", "final")
it.modifiers()List<String>Get all modifiers

Source Code

MethodReturn TypeDescription
it.sourceCode()String?Get the full source code
it.defineCode()String?Get the declaration without body
it.psi()PsiElement?Get the underlying PSI element

Extension Data

MethodReturn TypeDescription
it.getExt(name)Any?Get extension value from context
it.setExt(name, value)voidSet extension value on context

Context Info

MethodReturn TypeDescription
it.contextType()StringGet the context type ("class", "method", "field", "param")

Class Context Methods

Available when it is a ScriptPsiClassContext (class rules):

Basic Info

MethodReturn TypeDescription
it.qualifiedName()String?Get fully qualified class name
it.packageName()String?Get package name
it.type()ScriptTypeContextGet type information

Members

MethodReturn TypeDescription
it.methods()Array<ScriptPsiMethodContext>Get all methods
it.methodCnt()IntGet method count
it.fields()Array<ScriptPsiFieldContext>Get all fields
it.fieldCnt()IntGet field count

Type Checking

MethodReturn TypeDescription
it.isExtend(superClass)BooleanCheck if extends/implements a class
it.isMap()BooleanCheck if is a Map type
it.isCollection()BooleanCheck if is a Collection type
it.isArray()BooleanCheck if is an array type
it.isInterface()BooleanCheck if is an interface
it.isAnnotationType()BooleanCheck if is an annotation type
it.isEnum()BooleanCheck if is an enum
it.isPrimitive()BooleanCheck if is a primitive type
it.isPrimitiveWrapper()BooleanCheck if is a primitive wrapper
it.isNormalType()BooleanCheck if is a normal type (primitive, wrapper, String, Object)

Visibility

MethodReturn TypeDescription
it.isPublic()BooleanCheck if is public
it.isProtected()BooleanCheck if is protected
it.isPrivate()BooleanCheck if is private
it.isPackagePrivate()BooleanCheck if is package-private

Class Hierarchy

MethodReturn TypeDescription
it.isInnerClass()BooleanCheck if is an inner class
it.isStatic()BooleanCheck if is static (for inner classes)
it.outerClass()ScriptPsiClassContext?Get outer class for inner classes
it.superClass()ScriptPsiClassContext?Get super class
it.extends()Array<ScriptPsiClassContext>?Get extended classes
it.implements()Array<ScriptPsiClassContext>?Get implemented interfaces

Method Context Methods

Available when it is a ScriptPsiMethodContext (method rules):

Return Type

MethodReturn TypeDescription
it.returnType()ScriptTypeContext?Get return type
it.type()ScriptTypeContext?Alias for returnType()

Parameters

MethodReturn TypeDescription
it.args()Array<ScriptPsiParameterContext>Get all parameters
it.params()Array<ScriptPsiParameterContext>Alias for args()
it.parameters()Array<ScriptPsiParameterContext>Alias for args()
it.argTypes()Array<ScriptTypeContext>Get parameter types
it.argCnt()IntGet parameter count
it.paramCnt()IntAlias for argCnt()
it.isVarArgs()BooleanCheck if has varargs

Containing Class

MethodReturn TypeDescription
it.containingClass()ScriptPsiClassContext?Get the containing class
it.defineClass()ScriptPsiClassContext?Alias for containingClass()

Method Properties

MethodReturn TypeDescription
it.isConstructor()BooleanCheck if is a constructor
it.isOverride()BooleanCheck if overrides a super method
it.isDefault()BooleanCheck if is a default method (interface)
it.isAbstract()BooleanCheck if is abstract
it.isSynchronized()BooleanCheck if is synchronized
it.isNative()BooleanCheck if is native
it.throwsExceptions()Array<String>Get thrown exceptions

Field Context Methods

Available when it is a ScriptPsiFieldContext (field rules):

Type

MethodReturn TypeDescription
it.type()ScriptTypeContextGet field type
it.jsonType()ScriptTypeContextAlias for type()

Containing Class

MethodReturn TypeDescription
it.containingClass()ScriptPsiClassContext?Get the containing class
it.defineClass()ScriptPsiClassContext?Alias for containingClass()

Field Properties

MethodReturn TypeDescription
it.isEnumField()BooleanCheck if is an enum constant
it.asEnumField()ScriptPsiEnumConstantContext?Get enum constant context
it.isStatic()BooleanCheck if is static
it.isFinal()BooleanCheck if is final
it.isTransient()BooleanCheck if is transient
it.isVolatile()BooleanCheck if is volatile
it.constantValue()Any?Get compile-time constant value

Parameter Context Methods

Available when it is a ScriptPsiParameterContext (parameter rules):

Type

MethodReturn TypeDescription
it.type()ScriptTypeContextGet parameter type
it.jsonType()ScriptTypeContextAlias for type()

Parameter Properties

MethodReturn TypeDescription
it.isVarArgs()BooleanCheck if is varargs
it.isFinal()BooleanCheck if is final

Declaration

MethodReturn TypeDescription
it.method()ScriptPsiMethodContext?Get the declaring method
it.declaration()ScriptItContext?Get the declaring element

Type Context Methods

Available when it is a ScriptTypeContext:

Name

MethodReturn TypeDescription
it.name()StringGet full type name (e.g., "java.util.List<java.lang.String>")
it.getName()StringAlias for name()
it.simpleName()StringGet simple type name (e.g., "List")
it.getSimpleName()StringAlias for simpleName()

Type Checking

MethodReturn TypeDescription
it.isExtend(superClass)BooleanCheck if extends a class
it.isMap()BooleanCheck if is a Map type
it.isCollection()BooleanCheck if is a Collection type
it.isArray()BooleanCheck if is an array type
it.isPrimitive()BooleanCheck if is a primitive type
it.isPrimitiveWrapper()BooleanCheck if is a primitive wrapper
it.isNormalType()BooleanCheck if is a normal type
it.isInterface()BooleanCheck if is an interface
it.isAnnotationType()BooleanCheck if is an annotation type
it.isEnum()BooleanCheck if is an enum

Members

MethodReturn TypeDescription
it.methods()Array<ScriptPsiMethodContext>Get all methods
it.fields()Array<ScriptPsiFieldContext>Get all fields

Examples

Class Rule Example

properties
class.name=groovy:'''
if (it.isExtend("java.lang.Exception")) {
    return it.simpleName() + "Exception"
}
return it.name()
'''

Method Rule Example

properties
method.name=groovy:'''
def name = it.name()
if (it.hasAnn("org.springframework.web.bind.annotation.GetMapping")) {
    def path = it.ann("GetMapping", "value")
    return path ?: name
}
return name
'''

Field Rule Example

properties
field.mock=groovy:'''
def type = it.type()
if (type.isExtend("java.lang.Number")) {
    return "0"
}
if (type.name() == "java.lang.String") {
    return "mock_" + it.name()
}
if (type.isCollection()) {
    return "[]"
}
return null
'''

Parameter Rule Example

properties
param.name=groovy:'''
def name = it.name()
if (it.hasAnn("org.springframework.web.bind.annotation.RequestParam")) {
    return it.ann("RequestParam", "value") ?: name
}
return name
'''

See Also

  • api - API utilities for modifying endpoint metadata
  • fieldContext - Field context utilities

Released under the Apache-2.0 License.