aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/compiler/ReflectionUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/compiler/ReflectionUtils.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/compiler/ReflectionUtils.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/compiler/ReflectionUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/compiler/ReflectionUtils.java
index 5dff149ee0..1d7c0daedc 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/compiler/ReflectionUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/compiler/ReflectionUtils.java
@@ -24,6 +24,26 @@ import java.util.Arrays;
public class ReflectionUtils {
/**
+ * Get a Byte Buddy {@link MethodDescription} for a constructor of a class.
+ *
+ * @throws Error when the constructor cannot be found via reflection
+ */
+ public static MethodDescription.ForLoadedConstructor getConstructor(
+ Class<?> clazz, Class<?>... parameterTypes) {
+ try {
+ return new MethodDescription.ForLoadedConstructor(clazz.getConstructor(parameterTypes));
+ } catch (NoSuchMethodException e) {
+ throw new Error(
+ String.format(
+ "Error when reflectively getting a constructor with parameter"
+ + " types %s from class %s",
+ Arrays.toString(parameterTypes),
+ clazz),
+ e);
+ }
+ }
+
+ /**
* Get a Byte Buddy {@link MethodDescription} for a method from a class.
*
* @throws Error when the method cannot be found via reflection