-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2e1d2c
commit 353e063
Showing
19 changed files
with
345 additions
and
149 deletions.
There are no files selected for viewing
8 changes: 3 additions & 5 deletions
8
designer/server/src/main/scala/pl/touk/nussknacker/ui/suggester/ExpressionSuggester.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...pl/touk/nussknacker/engine/spel/internal/ConversionAndExtensionAwareMethodsDiscovery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package pl.touk.nussknacker.engine.spel.internal; | ||
|
||
import pl.touk.nussknacker.engine.extension.Cast; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class ConversionAndExtensionAwareMethodsDiscovery { | ||
private static final Method[] CAST_METHODS = Cast.class.getMethods(); | ||
private static final Method[] LIST_AND_CAST_METHODS = concatArrays(List.class.getMethods(), CAST_METHODS); | ||
|
||
public Method[] discover(Class<?> type) { | ||
// todo: lbg I'm planning to remove below branch for the sake of implementing array auto conversion to list as | ||
// an extension methods added to array. | ||
// Additionally appropriate extension methods should be added to classes automatically. | ||
if (type.isArray()) { | ||
return LIST_AND_CAST_METHODS; | ||
} | ||
return concatArrays(type.getMethods(), CAST_METHODS); | ||
} | ||
|
||
private static Method[] concatArrays(Method[] a, Method[] b) { | ||
return Stream | ||
.concat(Arrays.stream(a), Arrays.stream(b)) | ||
.toArray(Method[]::new); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...a/pl/touk/nussknacker/engine/spel/internal/ConversionAndExtensionsAwareMethodInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package pl.touk.nussknacker.engine.spel.internal; | ||
|
||
import pl.touk.nussknacker.engine.extension.ExtensionMethodsInvoker; | ||
import scala.PartialFunction; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
public class ConversionAndExtensionsAwareMethodInvoker { | ||
private final ExtensionMethodsInvoker extensionMethodsInvoker; | ||
|
||
public ConversionAndExtensionsAwareMethodInvoker(ExtensionMethodsInvoker extensionMethodsInvoker) { | ||
this.extensionMethodsInvoker = extensionMethodsInvoker; | ||
} | ||
|
||
public Object invoke(Method method, | ||
Object target, | ||
Object[] arguments) throws IllegalAccessException, InvocationTargetException { | ||
Class<?> methodDeclaringClass = method.getDeclaringClass(); | ||
// todo: lbg I'm planning to remove below branch for the sake of implementing array auto conversion to list as | ||
// an extension methods added to array | ||
if (target != null && target.getClass().isArray() && methodDeclaringClass.isAssignableFrom(List.class)) { | ||
return method.invoke(RuntimeConversionHandler.convert(target), arguments); | ||
} | ||
PartialFunction<Method, Object> extMethod = extensionMethodsInvoker.invoke(target, arguments); | ||
if (extMethod.isDefinedAt(method)) { | ||
return extMethod.apply(method); | ||
} else { | ||
return method.invoke(target, arguments); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.