Small refactoring of StandardGStringTemplateViewMetaClass.
This commit is contained in:
parent
eb1c372109
commit
77400ddece
@ -1,13 +1,9 @@
|
|||||||
package groowt.view;
|
package groowt.view;
|
||||||
|
|
||||||
import groovy.lang.*;
|
import groovy.lang.*;
|
||||||
import org.codehaus.groovy.runtime.metaclass.MethodSelectionException;
|
|
||||||
import org.codehaus.groovy.util.FastArray;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class StandardGStringTemplateViewMetaClass extends ExpandoMetaClass {
|
public class StandardGStringTemplateViewMetaClass extends ExpandoMetaClass {
|
||||||
@ -25,21 +21,6 @@ public class StandardGStringTemplateViewMetaClass extends ExpandoMetaClass {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MetaMethod findMetaMethod(MetaClass metaClass, String methodName, Object[] argsArray) {
|
|
||||||
final List<MetaMethod> metaMethods = metaClass.getMetaMethods().stream().filter(metaMethod ->
|
|
||||||
metaMethod.getName().equals(methodName) && metaMethod.isValidMethod(argsArray)
|
|
||||||
).toList();
|
|
||||||
if (metaMethods.size() > 1) {
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
final Class[] argTypes = Arrays.stream(argsArray).map(Object::getClass).toArray(Class[]::new);
|
|
||||||
throw new MethodSelectionException(methodName, new FastArray(metaMethods), argTypes);
|
|
||||||
} else if (metaMethods.size() == 1) {
|
|
||||||
return metaMethods.getFirst();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void warnWrongType(Object object) {
|
private static void warnWrongType(Object object) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"StandardGStringTemplateViewMetaClass should only be used as a MetaClass of StandardGStringTemplateViewMetaClass or a subclass thereof; given "
|
"StandardGStringTemplateViewMetaClass should only be used as a MetaClass of StandardGStringTemplateViewMetaClass or a subclass thereof; given "
|
||||||
@ -48,10 +29,11 @@ public class StandardGStringTemplateViewMetaClass extends ExpandoMetaClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static MetaClass findMetaClass(Object object) {
|
private static MetaClass findMetaClass(Object object) {
|
||||||
return switch (object) {
|
if (object instanceof GroovyObject groovyObject) {
|
||||||
case GroovyObject groovyObject -> groovyObject.getMetaClass();
|
return groovyObject.getMetaClass();
|
||||||
default -> GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass());
|
} else {
|
||||||
};
|
return GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StandardGStringTemplateViewMetaClass() {
|
public StandardGStringTemplateViewMetaClass() {
|
||||||
|
Loading…
Reference in New Issue
Block a user