import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import sun.reflect.ConstructorAccessor;
import java.lang.reflect.Constructor;
public interface JavaDocElementType {
@SuppressWarnings("deprecation")
class JavaDocCompositeElementType extends IJavaDocElementType implements ICompositeElementType {
- private final ConstructorAccessor myConstructor;
+ private final Constructor<? extends ASTNode> myConstructor;
private JavaDocCompositeElementType(@NonNls final String debugName, final Class<? extends ASTNode> nodeClass) {
super(debugName);
- Constructor<? extends ASTNode> constructor = ReflectionUtil.getDefaultConstructor(nodeClass);
- myConstructor = ReflectionUtil.getConstructorAccessor(constructor);
+ myConstructor = ReflectionUtil.getDefaultConstructor(nodeClass);
}
@NotNull
@Override
public ASTNode createCompositeNode() {
- return ReflectionUtil.createInstanceViaConstructorAccessor(myConstructor);
+ return ReflectionUtil.createInstance(myConstructor);
}
}
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import sun.reflect.ConstructorAccessor;
import java.lang.reflect.Constructor;
public interface JavaElementType {
@SuppressWarnings("deprecation")
class JavaCompositeElementType extends IJavaElementType implements ICompositeElementType {
- private final ConstructorAccessor myConstructor;
+ private final Constructor<? extends ASTNode> myConstructor;
private JavaCompositeElementType(@NonNls final String debugName, final Class<? extends ASTNode> nodeClass) {
this(debugName, nodeClass, false);
private JavaCompositeElementType(@NonNls final String debugName, final Class<? extends ASTNode> nodeClass, final boolean leftBound) {
super(debugName, leftBound);
- Constructor<? extends ASTNode> constructor = ReflectionUtil.getDefaultConstructor(nodeClass);
- myConstructor = ReflectionUtil.getConstructorAccessor(constructor);
+ myConstructor = ReflectionUtil.getDefaultConstructor(nodeClass);
}
@NotNull
@Override
public ASTNode createCompositeNode() {
- return ReflectionUtil.createInstanceViaConstructorAccessor(myConstructor);
+ return ReflectionUtil.createInstance(myConstructor);
}
}
private static final Method getConstructorAccessorMethod = getDeclaredMethod(Constructor.class, "getConstructorAccessor");
/** @deprecated private API (to be removed in IDEA 17) */
+ @SuppressWarnings("unused")
public static ConstructorAccessor getConstructorAccessor(@NotNull Constructor constructor) {
if (acquireConstructorAccessorMethod == null || getConstructorAccessorMethod == null) {
throw new IllegalStateException();
}
/** @deprecated private API, use {@link #createInstance(Constructor, Object...)} instead (to be removed in IDEA 17) */
+ @SuppressWarnings("unused")
public static <T> T createInstanceViaConstructorAccessor(@NotNull ConstructorAccessor constructorAccessor, @NotNull Object... arguments) {
try {
@SuppressWarnings("unchecked") T t = (T)constructorAccessor.newInstance(arguments);
}
/** @deprecated private API, use {@link #newInstance(Class)} instead (to be removed in IDEA 17) */
+ @SuppressWarnings("unused")
public static <T> T createInstanceViaConstructorAccessor(@NotNull ConstructorAccessor constructorAccessor) {
try {
@SuppressWarnings("unchecked") T t = (T)constructorAccessor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY);
*/
package com.intellij.util.text;
-import com.intellij.util.ReflectionUtil;
import org.jetbrains.annotations.NotNull;
-import sun.reflect.ConstructorAccessor;
import java.lang.reflect.Constructor;
-@SuppressWarnings("deprecation")
public class StringFactory {
// String(char[], boolean). Works since JDK1.7, earlier JDKs have too slow reflection anyway
- private static final ConstructorAccessor ourConstructorAccessor;
+ private static final Constructor<String> ourConstructor;
static {
- ConstructorAccessor constructorAccessor = null;
+ Constructor<String> constructor = null;
try {
- Constructor<String> newC = String.class.getDeclaredConstructor(char[].class, boolean.class);
- constructorAccessor = ReflectionUtil.getConstructorAccessor(newC);
+ constructor = String.class.getDeclaredConstructor(char[].class, boolean.class);
+ constructor.setAccessible(true);
}
- catch (Exception ignored) {
- }
- ourConstructorAccessor = constructorAccessor;
+ catch (Exception ignored) { }
+ ourConstructor = constructor;
}
/**
- * @return new instance of String which backed by 'chars' array.
+ * @return new instance of String which backed by given char array.
*
- * CAUTION. EXTREMELY DANGEROUS.
- * DO NOT USE THIS METHOD UNLESS YOU ARE TOO DESPERATE
+ * CAUTION! EXTREMELY DANGEROUS!! DO NOT USE THIS METHOD UNLESS YOU ARE REALLY DESPERATE!!!
*/
@NotNull
public static String createShared(@NotNull char[] chars) {
- if (ourConstructorAccessor != null) {
- return ReflectionUtil.createInstanceViaConstructorAccessor(ourConstructorAccessor, chars, Boolean.TRUE);
+ if (ourConstructor != null) {
+ try {
+ return ourConstructor.newInstance(chars, Boolean.TRUE);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
+
return new String(chars);
}
}
\ No newline at end of file