Skip to content

Commit

Permalink
Add kotlin detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
olegz committed Mar 26, 2024
1 parent 31c66fb commit eab0561
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,15 @@ public <T> T lookup(Class<?> type, String functionDefinition, String... expected
if (functionCandidate != null) {
Type functionType = null;
FunctionRegistration functionRegistration = null;
System.out.println("\n=======> " + functionCandidate.getClass().getSuperclass());
Annotation[] a = functionCandidate.getClass().getDeclaredAnnotations();
for (int i = 0; i < a.length; i++) {
System.out.println("===> KOTLIN ANNOTATION: " + a[i]);
}

if (functionCandidate instanceof FunctionRegistration) {
functionRegistration = (FunctionRegistration) functionCandidate;
}
else if (functionCandidate instanceof BiFunction || functionCandidate instanceof BiConsumer) {
functionRegistration = this.registerMessagingBiFunction(functionCandidate, functionName);
}
else if (KotlinDetector.isKotlinType(functionCandidate.getClass())) {
//else if (KotlinDetector.isKotlinType(functionCandidate.getClass())) {
else if (this.isKotlinType(functionCandidate)) {
KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper wrapper =
new KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper(functionCandidate);
wrapper.setName(functionName);
Expand Down Expand Up @@ -203,6 +199,16 @@ else if (this.isSpecialFunctionRegistration(functionNames, functionName)) {
return (T) function;
}

private boolean isKotlinType(Object functionCandidate) {
Annotation[] a = functionCandidate.getClass().getDeclaredAnnotations();
for (int i = 0; i < a.length; i++) {
if (a[i].annotationType().getName().contains("kotlin.")) {
return true;
}
}
return false;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private FunctionRegistration registerMessagingBiFunction(Object userFunction, String functionName) {
Type biFunctionType = FunctionContextUtils.findType(this.applicationContext.getBeanFactory(), functionName);
Expand Down

0 comments on commit eab0561

Please sign in to comment.