Cleanup (deprecated API)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 11 May 2016 10:07:48 +0000 (12:07 +0200)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 11 May 2016 10:08:29 +0000 (12:08 +0200)
java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java
java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java
platform/util/src/com/intellij/util/ReflectionUtil.java
platform/util/src/com/intellij/util/text/StringFactory.java

index 9367fa5c490b310800cdf2b4ee035d214f9410a1..383cc802fdd4c68de248dd7708fe557cf33864d5 100644 (file)
@@ -34,25 +34,23 @@ import com.intellij.util.ReflectionUtil;
 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);
     }
   }
 
index 836a4305e43f55a3e8b9de0ebe443643af4165a9..c207c2d6740be3b43b1a674ebd27184f73389547 100644 (file)
@@ -35,14 +35,13 @@ import com.intellij.util.diff.FlyweightCapableTreeStructure;
 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);
@@ -50,14 +49,13 @@ public interface JavaElementType {
 
     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);
     }
   }
 
index 405811a216d79ca310b6a15e88d1e474b2dc81cc..ddfdc9175e3c0e74e93ec74b9195f65800370c32 100644 (file)
@@ -421,6 +421,7 @@ public class ReflectionUtil {
   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();
@@ -437,6 +438,7 @@ public class ReflectionUtil {
   }
 
   /** @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);
@@ -448,6 +450,7 @@ public class ReflectionUtil {
   }
 
   /** @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);
index 9aafd45a0165770050e34ecfaeef743fcc47f52a..fc1c2ac001b9de019b28321ff630e19355405d98 100644 (file)
  */
 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