From 7f33bb0a8e16ebccb4b85570f2f33def52a3cb0b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 11 Feb 2016 12:39:17 +0100 Subject: [PATCH] [platform] private API usages deprecated --- .../impl/source/tree/JavaDocElementType.java | 5 ++-- .../psi/impl/source/tree/JavaElementType.java | 5 ++-- .../src/com/intellij/util/ReflectionUtil.java | 26 +++++++++---------- .../com/intellij/util/text/StringFactory.java | 6 ++--- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java index 23c6df0f1c4a..9367fa5c490b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaDocElementType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import sun.reflect.ConstructorAccessor; import java.lang.reflect.Constructor; public interface JavaDocElementType { + @SuppressWarnings("deprecation") class JavaDocCompositeElementType extends IJavaDocElementType implements ICompositeElementType { private final ConstructorAccessor myConstructor; @@ -140,4 +141,4 @@ public interface JavaDocElementType { TokenSet ALL_JAVADOC_ELEMENTS = TokenSet.create( DOC_TAG, DOC_INLINE_TAG, DOC_METHOD_OR_FIELD_REF, DOC_PARAMETER_REF, DOC_TAG_VALUE_ELEMENT, DOC_REFERENCE_HOLDER, DOC_TYPE_HOLDER, DOC_COMMENT); -} +} \ No newline at end of file diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java index db39b310f242..836a4305e43f 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ import sun.reflect.ConstructorAccessor; import java.lang.reflect.Constructor; public interface JavaElementType { + @SuppressWarnings("deprecation") class JavaCompositeElementType extends IJavaElementType implements ICompositeElementType { private final ConstructorAccessor myConstructor; @@ -288,4 +289,4 @@ public interface JavaElementType { } } IElementType DUMMY_ELEMENT = new JavaDummyElementType(); -} +} \ No newline at end of file diff --git a/platform/util/src/com/intellij/util/ReflectionUtil.java b/platform/util/src/com/intellij/util/ReflectionUtil.java index e5fcdedea853..24bbe450d20d 100644 --- a/platform/util/src/com/intellij/util/ReflectionUtil.java +++ b/platform/util/src/com/intellij/util/ReflectionUtil.java @@ -16,7 +16,6 @@ package com.intellij.util; -import com.intellij.Patches; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.DifferenceFilter; @@ -421,17 +420,16 @@ public class ReflectionUtil { } } - static { - // method getConstructorAccessorMethod is not necessary since JDK7, use acquireConstructorAccessor return value instead - assert Patches.USE_REFLECTION_TO_ACCESS_JDK7; - } private static final Method acquireConstructorAccessorMethod = getDeclaredMethod(Constructor.class, "acquireConstructorAccessor"); private static final Method getConstructorAccessorMethod = getDeclaredMethod(Constructor.class, "getConstructorAccessor"); - @NotNull + /** @deprecated private API (to be removed in IDEA 17) */ public static ConstructorAccessor getConstructorAccessor(@NotNull Constructor constructor) { + if (acquireConstructorAccessorMethod == null || getConstructorAccessorMethod == null) { + throw new IllegalStateException(); + } + constructor.setAccessible(true); - // it is faster to invoke constructor via sun.reflect.ConstructorAccessor; it avoids AccessibleObject.checkAccess() try { acquireConstructorAccessorMethod.invoke(constructor); return (ConstructorAccessor)getConstructorAccessorMethod.invoke(constructor); @@ -441,20 +439,22 @@ public class ReflectionUtil { } } - @NotNull - public static T createInstanceViaConstructorAccessor(@NotNull ConstructorAccessor constructorAccessor, - @NotNull Object... arguments) { + /** @deprecated private API, use {@link #createInstance(Constructor, Object...)} instead (to be removed in IDEA 17) */ + public static T createInstanceViaConstructorAccessor(@NotNull ConstructorAccessor constructorAccessor, @NotNull Object... arguments) { try { - return (T)constructorAccessor.newInstance(arguments); + @SuppressWarnings("unchecked") T t = (T)constructorAccessor.newInstance(arguments); + return t; } catch (Exception e) { throw new RuntimeException(e); } } - @NotNull + + /** @deprecated private API, use {@link #newInstance(Class)} instead (to be removed in IDEA 17) */ public static T createInstanceViaConstructorAccessor(@NotNull ConstructorAccessor constructorAccessor) { try { - return (T)constructorAccessor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY); + @SuppressWarnings("unchecked") T t = (T)constructorAccessor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY); + return t; } catch (Exception e) { throw new RuntimeException(e); diff --git a/platform/util/src/com/intellij/util/text/StringFactory.java b/platform/util/src/com/intellij/util/text/StringFactory.java index c34dd1fe17b3..9aafd45a0165 100644 --- a/platform/util/src/com/intellij/util/text/StringFactory.java +++ b/platform/util/src/com/intellij/util/text/StringFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ 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; @@ -36,7 +37,6 @@ public class StringFactory { ourConstructorAccessor = constructorAccessor; } - /** * @return new instance of String which backed by 'chars' array. * @@ -50,4 +50,4 @@ public class StringFactory { } return new String(chars); } -} +} \ No newline at end of file