summaryrefslogtreecommitdiff
path: root/platform/util/src/com/intellij/util/ReflectionUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/util/src/com/intellij/util/ReflectionUtil.java')
-rw-r--r--platform/util/src/com/intellij/util/ReflectionUtil.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/platform/util/src/com/intellij/util/ReflectionUtil.java b/platform/util/src/com/intellij/util/ReflectionUtil.java
index a4bf4318a76e..df33a80d4cba 100644
--- a/platform/util/src/com/intellij/util/ReflectionUtil.java
+++ b/platform/util/src/com/intellij/util/ReflectionUtil.java
@@ -426,6 +426,26 @@ public class ReflectionUtil {
}
}
+ /**
+ * {@link Class#newInstance()} cannot instantiate private classes
+ */
+ @NotNull
+ public static <T> T newInstance(@NotNull Class<T> aClass, @NotNull Class... parameterTypes) {
+ try {
+ Constructor<T> constructor = aClass.getDeclaredConstructor(parameterTypes);
+ try {
+ constructor.setAccessible(true);
+ }
+ catch (SecurityException e) {
+ return aClass.newInstance();
+ }
+ return constructor.newInstance();
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@NotNull
public static <T> T createInstance(@NotNull Constructor<T> constructor, @NotNull Object... args) {
try {