Class SourceAwareCustomizer
java.lang.Object
org.codehaus.groovy.control.customizers.CompilationCustomizer
org.codehaus.groovy.control.customizers.DelegatingCustomizer
org.codehaus.groovy.control.customizers.SourceAwareCustomizer
- All Implemented Interfaces:
CompilationUnitAware,CompilationUnit.IPrimaryClassNodeOperation
A base class for customizers which only have to be applied on specific source units.
This is for example useful if you want a customizer to be applied only for files
matching some extensions.
For convenience, this class implements several methods that you may extend to customize
the behaviour of this utility. For example, if you want to apply a customizer only
for classes matching the '.foo' file extension, then you only have to override the
acceptExtension(String) method:
return "foo".equals(extension)- Since:
- 2.1.0
-
Field Summary
Fields inherited from class org.codehaus.groovy.control.customizers.DelegatingCustomizer
delegate -
Constructor Summary
ConstructorsConstructorDescriptionSourceAwareCustomizer(CompilationCustomizer delegate) Creates a source-aware wrapper around another compilation customizer. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether a source file name is accepted by the base-name and extension validators.booleanacceptBaseName(String baseName) Checks whether a base file name is accepted.booleanacceptClass(ClassNode cnode) Checks whether a class node is accepted.booleanacceptExtension(String extension) Checks whether a file extension is accepted.booleanacceptSource(SourceUnit unit) Checks whether a source unit is accepted.voidcall(SourceUnit source, GeneratorContext context, ClassNode classNode) Invokes the delegate only when the source and class validators accept the current input.voidsetBaseNameValidator(Closure<Boolean> baseNameValidator) Sets the predicate used to validate source base names.voidsetClassValidator(Closure<Boolean> classValidator) Sets the predicate used to validate class nodes.voidsetExtensionValidator(Closure<Boolean> extensionValidator) Sets the predicate used to validate source file extensions.voidsetSourceUnitValidator(Closure<Boolean> sourceUnitValidator) Sets the predicate used to validate whole source units.Methods inherited from class org.codehaus.groovy.control.customizers.DelegatingCustomizer
setCompilationUnitMethods inherited from class org.codehaus.groovy.control.customizers.CompilationCustomizer
getPhaseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.control.CompilationUnit.IPrimaryClassNodeOperation
doPhaseOperation, needSortedInput
-
Constructor Details
-
SourceAwareCustomizer
Creates a source-aware wrapper around another compilation customizer.- Parameters:
delegate- the customizer to invoke when the source matches
-
-
Method Details
-
call
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException Invokes the delegate only when the source and class validators accept the current input.- Specified by:
callin interfaceCompilationUnit.IPrimaryClassNodeOperation- Overrides:
callin classDelegatingCustomizer- Parameters:
source- the source unit being customizedcontext- the current generator contextclassNode- the class node being customized- Throws:
CompilationFailedException- if the delegate fails
-
setBaseNameValidator
Sets the predicate used to validate source base names.- Parameters:
baseNameValidator- the validator to use
-
setExtensionValidator
Sets the predicate used to validate source file extensions.- Parameters:
extensionValidator- the validator to use
-
setSourceUnitValidator
Sets the predicate used to validate whole source units.- Parameters:
sourceUnitValidator- the validator to use
-
setClassValidator
Sets the predicate used to validate class nodes.- Parameters:
classValidator- the validator to use
-
accept
Checks whether a source file name is accepted by the base-name and extension validators.- Parameters:
fileName- the file name to inspect- Returns:
trueif the file name is accepted
-
acceptClass
Checks whether a class node is accepted.- Parameters:
cnode- the class node to inspect- Returns:
trueif the class is accepted
-
acceptSource
Checks whether a source unit is accepted.- Parameters:
unit- the source unit to inspect- Returns:
trueif the source is accepted
-
acceptExtension
Checks whether a file extension is accepted.- Parameters:
extension- the extension to inspect- Returns:
trueif the extension is accepted
-
acceptBaseName
Checks whether a base file name is accepted.- Parameters:
baseName- the base file name to inspect- Returns:
trueif the base name is accepted
-