Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap
import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine

import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import org.codehaus.groovy.runtime.GStringImpl
Expand All @@ -39,6 +40,7 @@ import grails.util.GrailsMetaClassUtils
* @author Lari Hotari
* @since 2.3
*/
@CompileStatic
class CodecMetaClassSupport {

static final Object[] EMPTY_ARGS = []
Expand All @@ -53,7 +55,6 @@ class CodecMetaClassSupport {
*
* @param codecClass the codec class
*/
@CompileStatic
void configureCodecMethods(CodecFactory codecFactory, boolean cacheLookup = !Environment.getCurrent().isDevelopmentMode(), List<ExpandoMetaClass> targetMetaClasses = resolveDefaultMetaClasses()) {
Closure<String> encodeMethodNameClosure = { String codecName -> "${ENCODE_AS_PREFIX}${codecName}".toString() }
Closure<String> decodeMethodNameClosure = { String codecName -> "${DECODE_PREFIX}${codecName}".toString() }
Expand Down Expand Up @@ -133,12 +134,10 @@ class CodecMetaClassSupport {
* @param delegate
* @return
*/
@CompileStatic
private static Object filterNullObject(Object delegate) {
delegate != null && delegate.getClass() != NullObject ? delegate : null
}

@CompileStatic
private addAliasMetaMethods(List<ExpandoMetaClass> targetMetaClasses, Set<String> aliases, Closure<String> methodNameClosure, Closure methodClosure,
boolean cacheLookup, Set<MetaMethodRegistrationKey> registeredMetaMethodKeys) {
aliases?.each { String aliasName ->
Expand All @@ -162,6 +161,9 @@ class CodecMetaClassSupport {
}
}

// The metamethod name is only known at run time, and a GString property name is the one
// thing static compilation cannot express.
@CompileDynamic
protected void addMetaMethod(List<ExpandoMetaClass> targetMetaClasses, String methodName, Closure closure) {
targetMetaClasses.each { ExpandoMetaClass emc ->
emc."${methodName}" << closure
Expand All @@ -185,18 +187,15 @@ class CodecMetaClassSupport {
}
}

@CompileStatic
private static boolean shouldRegisterMetaMethod(ExpandoMetaClass emc, String methodName, Set<MetaMethodRegistrationKey> registeredMetaMethodKeys) {
MetaMethodRegistrationKey key = registrationKey(emc, methodName)
registeredMetaMethodKeys.add(key) || emc.getMetaMethod(methodName, EMPTY_ARGS) == null
}

@CompileStatic
private static MetaMethodRegistrationKey registrationKey(ExpandoMetaClass emc, String methodName) {
new MetaMethodRegistrationKey(emc.getTheClass(), methodName)
}

@CompileStatic
private static Set<MetaMethodRegistrationKey> registeredMetaMethodKeys(CodecFactory codecFactory) {
REGISTERED_META_METHODS.get(codecFactory) { CodecFactory ignored ->
Collections.newSetFromMap(new ConcurrentHashMap<MetaMethodRegistrationKey, Boolean>())
Expand Down
2 changes: 1 addition & 1 deletion grails-forge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ postgresSocketFactoryVersion=1.17.1
picocliVersion=4.7.6
reflectionsVersion=0.10.2
rockerVersion=2.2.1
shadowVersion=8.3.6
shadowVersion=8.3.11
spotlessVersion=6.25.0
testcontainersVersion=1.20.4
testRetryVersion=1.6.2
Expand Down
Loading