[platform] private API usages deprecated

This commit is contained in:
Roman Shevchenko
2016-02-11 12:41:12 +01:00
parent b2359ee731
commit 7f33bb0a8e
4 changed files with 22 additions and 20 deletions
@@ -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);
}
}
@@ -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();
}
}
@@ -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> 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> 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> 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);
@@ -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);
}
}
}