remove deprecated members, more deprecation warnings

GitOrigin-RevId: fcdfbb8e2daa5369cbe39613bc92f725a4f8559d
This commit is contained in:
Alexey Kudravtsev
2020-12-20 16:35:31 +00:00
committed by intellij-monorepo-bot
parent 7177b50706
commit 19b12745bd
13 changed files with 108 additions and 346 deletions
@@ -97,13 +97,10 @@ public abstract class WriteAction<T> extends BaseActionRunnable<T> {
* Must be called from the EDT.
*/
public static <E extends Throwable> void run(@NotNull ThrowableRunnable<E> action) throws E {
@SuppressWarnings("deprecation") AccessToken token = start(action.getClass());
try {
ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Void, E>)() -> {
action.run();
}
finally {
token.finish();
}
return null;
});
}
/**
@@ -171,8 +168,8 @@ public abstract class WriteAction<T> extends BaseActionRunnable<T> {
if (t != null) {
t.addSuppressed(new RuntimeException()); // preserve the calling thread stacktrace
ExceptionUtil.rethrowUnchecked(t);
@SuppressWarnings("unchecked") E e = (E)t;
throw e;
//noinspection unchecked
throw (E)t;
}
return result.get();
@@ -285,26 +285,7 @@ public abstract class WriteCommandAction<T> extends BaseActionRunnable<T> {
return true;
}
/**
* @deprecated Use {@link CommandProcessor#executeCommand(Project, Runnable, String, Object)} instead
*/
@Deprecated
public void performCommand() throws Throwable {
//this is needed to prevent memory leak, since command
// is put into undo queue
final RunResult[] results = {new RunResult<>(this)};
final Ref<Throwable> exception = new Ref<>();
doExecuteCommand(() -> {
exception.set(results[0].run().getThrowable());
results[0] = null;
});
Throwable throwable = exception.get();
if (throwable != null) throw throwable;
}
private void doExecuteCommand(final Runnable runnable) {
private void doExecuteCommand(@NotNull Runnable runnable) {
Runnable wrappedRunnable = () -> {
if (isGlobalUndoAction()) CommandProcessor.getInstance().markCurrentCommandAsGlobal(getProject());
runnable.run();
@@ -0,0 +1,15 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs;
public class Foo {
void f() {
//java.util.function.Function<String, AbsList> f = s -> new IntArrayList();
}
IntList crea() {
return new IntArrayList();
}
public static void main(String[] args) { }
}
class IntList { }
abstract class AbsList extends IntList {}
class IntArrayList extends AbsList { }
@@ -1140,6 +1140,8 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
@Override
public @NotNull AccessToken acquireReadActionLock() {
DeprecatedMethodException.report("Use runReadAction() instead");
// if we are inside read action, do not try to acquire read lock again since it will deadlock if there is a pending writeAction
return checkReadAccessAllowedAndNoPendingWrites() ? AccessToken.EMPTY_ACCESS_TOKEN : new ReadAccessToken();
}
@@ -1218,6 +1220,8 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
@Override
public @NotNull AccessToken acquireWriteActionLock(@NotNull Class<?> clazz) {
DeprecatedMethodException.report("Use runWriteAction() instead");
return new WriteAccessToken(clazz);
}
@@ -16,9 +16,7 @@ import com.intellij.openapi.progress.impl.ProgressManagerImpl;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.testFramework.CpuUsageData;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.RunFirst;
@@ -33,9 +31,13 @@ import org.junit.Assert;
import javax.swing.*;
import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import static com.intellij.util.TestTimeOut.setTimeout;
import static org.hamcrest.CoreMatchers.containsString;
@@ -60,60 +62,6 @@ public class ApplicationImplTest extends LightPlatformTestCase {
}
private volatile Throwable exception;
public void testAcquireReadActionLockVsRunReadActionPerformance() throws Throwable {
final int N = 100_000_000;
final Application application = ApplicationManager.getApplication();
String err = null;
for (int i=0; i<4; i++) {
Callable<String> runnable = () -> {
try {
assertFalse(application.isReadAccessAllowed());
CpuUsageData dataAcq = CpuUsageData.measureCpuUsage(() -> {
for (int i1 = 0; i1 < N; i1++) {
AccessToken token = application.acquireReadActionLock();
//noinspection EmptyTryBlock
try {
// do it
}
finally {
token.finish();
}
}
});
CpuUsageData dataRun = CpuUsageData.measureCpuUsage(() -> {
for (int i1 = 0; i1 < N; i1++) {
application.runReadAction(() -> {
});
}
});
long l1 = dataRun.durationMs;
long l2 = dataAcq.durationMs;
assertFalse(application.isReadAccessAllowed());
int ratioPercent = (int)((l1 - l2) * 100.0 / l1);
String msg = "acquireReadActionLock(" + l2 + "ms) vs runReadAction(" + l1 + "ms). Ratio: " + ratioPercent + "% (in "+(ratioPercent<0 ? "my" : "Maxim's") +" favor)";
LOG.debug(msg + "\nAcquire:\n" + dataAcq.getSummary(" ") + "\nRun:\n" + dataRun.getSummary(" "));
if (Math.abs(ratioPercent) > 40) {
return "Suspiciously different times for " + msg;
}
}
catch (Throwable e) {
exception = e;
}
return null;
};
err = application.executeOnPooledThread(runnable).get();
if (err == null) break;
System.err.println("Still trying, attempt "+i+": "+err);
System.gc();
}
assertNull(err);
if (exception != null) throw exception;
}
public void testRead50Write50LockPerformance() {
runReadWrites(600_000, 600_000, 2000);
@@ -199,9 +147,9 @@ public class ApplicationImplTest extends LightPlatformTestCase {
assertFalse(application.isWriteAccessAllowed());
assertFalse(application.isWriteActionPending());
// take read lock1.
// take read lock1 in separate thread.
// try to take write lock - must wait (because of taken read lock)
// try to take read lock2 - must wait (because of write preference - write lock is pending)
// try to take read lock2 in separate thread - must wait (because of write preference - write lock is pending)
// release read lock1 - write lock must be taken first
// release write - read lock2 must be taken
LOG.debug("-----");
@@ -216,15 +164,22 @@ public class ApplicationImplTest extends LightPlatformTestCase {
Future<?> readAction1 = ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
assertFalse(application.isDispatchThread());
AccessToken stamp = application.acquireReadActionLock();
try {
LOG.debug("read lock1 acquired");
read1Acquired.set(true);
while (holdRead1.get()) checkTimeout();
application.runReadAction(() -> {
read1Acquired.set(true);
LOG.debug("read lock1 acquired");
while (holdRead1.get()) {
try {
checkTimeout();
}
catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
});
}
finally {
read1Released.set(true);
stamp.finish();
LOG.debug("read lock1 released");
}
}
@@ -236,8 +191,8 @@ public class ApplicationImplTest extends LightPlatformTestCase {
while (!read1Acquired.get()) checkTimeout();
AtomicBoolean aboutToAcquireWrite = new AtomicBoolean();
// readActions2 should try to acquire read action when write action is pending
Future<?> readActions2 = ApplicationManager.getApplication().executeOnPooledThread(() -> {
// readAction2 should try to acquire read action when write action is pending
Future<?> readAction2 = ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
assertFalse(application.isDispatchThread());
while (!aboutToAcquireWrite.get()) checkTimeout();
@@ -245,17 +200,17 @@ public class ApplicationImplTest extends LightPlatformTestCase {
while (!application.myLock.writeRequested) checkTimeout();
assertTrue(application.isWriteActionPending());
//assertFalse(application.tryRunReadAction(EmptyRunnable.getInstance()));
AccessToken stamp = application.acquireReadActionLock();
assertFalse(application.isWriteActionPending());
try {
LOG.debug("read lock2 acquired");
read2Acquired.set(true);
application.runReadAction(() -> {
read2Acquired.set(true);
assertFalse(application.isWriteActionPending());
LOG.debug("read lock2 acquired");
});
}
finally {
read2Released.set(true);
stamp.finish();
LOG.debug("read lock2 released");
}
LOG.debug("read lock2 released");
}
catch (Throwable e) {
exception = e;
@@ -335,25 +290,30 @@ public class ApplicationImplTest extends LightPlatformTestCase {
});
aboutToAcquireWrite.set(true);
AccessToken stamp = application.acquireWriteActionLock(getClass());
try {
LOG.debug("write lock acquired");
writeAcquired.set(true);
application.runWriteAction(() -> {
writeAcquired.set(true);
LOG.debug("write lock acquired");
while (holdWrite.get()) {
checkTimeout();
assertTrue(application.isWriteActionInProgress());
assertTrue(application.isWriteAccessAllowed());
assertFalse(application.isWriteActionPending());
}
while (holdWrite.get()) {
try {
checkTimeout();
}
catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
assertTrue(application.isWriteActionInProgress());
assertTrue(application.isWriteAccessAllowed());
assertFalse(application.isWriteActionPending());
}
});
}
finally {
writeReleased.set(true);
stamp.finish();
LOG.debug("write lock released");
}
joinWithTimeout(readAction1, readActions2, checkThread);
joinWithTimeout(readAction1, readAction2, checkThread);
if (exception != null) throw exception;
}
@@ -572,20 +532,6 @@ public class ApplicationImplTest extends LightPlatformTestCase {
});
}
private static void safeWrite(ThrowableRunnable<RuntimeException> r) throws Throwable {
Ref<Throwable> e = new Ref<>();
ApplicationManager.getApplication().invokeLater(() -> {
try {
WriteAction.run(r);
}
catch (Throwable e1) {
e.set(e1);
}
});
UIUtil.dispatchAllInvocationEvents();
if (e.get() != null) throw e.get();
}
private static void waitForFuture(Future<?> future) {
try {
future.get(10_000, TimeUnit.MILLISECONDS);
@@ -597,21 +543,35 @@ public class ApplicationImplTest extends LightPlatformTestCase {
public void testHasWriteActionWorksInOtherThreads() throws Throwable {
ApplicationImpl app = (ApplicationImpl)ApplicationManager.getApplication();
ThrowableRunnable<RuntimeException> runnable = new ThrowableRunnable<>() {
ThrowableComputable<Void, RuntimeException> runnable = new ThrowableComputable<>() {
@Override
public void run() throws RuntimeException {
Class<? extends ThrowableRunnable<RuntimeException>> actionClass = getClass();
public Void compute() throws RuntimeException {
Class<?> actionClass = getClass();
assertTrue(app.hasWriteAction(actionClass));
app.executeSuspendingWriteAction(getProject(), "", () -> ReadAction.run(() -> {
assertTrue(app.hasWriteAction(actionClass));
waitForFuture(app.executeOnPooledThread(() -> ReadAction.run(() -> assertTrue(app.hasWriteAction(actionClass)))));
}));
return null;
}
};
assertFalse(app.hasWriteAction(runnable.getClass()));
safeWrite(runnable);
}
private static <T> void safeWrite(ThrowableComputable<T, RuntimeException> r) throws Throwable {
AtomicReference<Throwable> e = new AtomicReference<>();
ApplicationManager.getApplication().invokeLater(() -> {
try {
WriteAction.compute(r);
}
catch (Throwable e1) {
e.set(e1);
}
});
UIUtil.dispatchAllInvocationEvents();
if (e.get() != null) throw e.get();
}
public void testReadActionInImpatientModeShouldThrowWhenThereIsAPendingWrite() throws Throwable {
AtomicBoolean stopRead = new AtomicBoolean();
@@ -11,20 +11,12 @@ import org.jetbrains.annotations.NotNull;
*/
@Deprecated
public final class ReflectionCache {
/**
* @deprecated doesn't cache
*/
@Deprecated
public static boolean isAssignable(@NotNull Class ancestor, Class descendant) {
DeprecatedMethodException.report("Use 'ancestor.isAssignableFrom(descendant)' instead");
return ancestor == descendant || ancestor.isAssignableFrom(descendant);
}
/**
* @deprecated doesn't cache
*/
@Deprecated
public static boolean isInstance(Object instance, @NotNull Class clazz) {
return clazz.isInstance(instance);
}
}
@@ -11,10 +11,20 @@ public final class StringBuilderSpinAllocator {
private StringBuilderSpinAllocator() {
}
/**
* @deprecated Use {@link StringBuilder}
*/
@Deprecated
public static StringBuilder alloc() {
DeprecatedMethodException.report("Use 'new StringBuilder()' instead");
return new StringBuilder();
}
/**
* @deprecated Use nothing instead, stop worrying, let GC do its job and start living
*/
@Deprecated
public static void dispose(StringBuilder instance) {
DeprecatedMethodException.report("Do not use");
}
}
@@ -1,40 +0,0 @@
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Iterator;
/**
* @deprecated Use {@link Collections#emptyList()} instead
*/
@Deprecated
public class EmptyIterable<T> implements Iterable<T> {
private static final EmptyIterable INSTANCE = new EmptyIterable();
public static <T> EmptyIterable<T> getInstance() {
//noinspection unchecked
return INSTANCE;
}
@NotNull
@Override
public Iterator<T> iterator() {
return Collections.emptyIterator();
}
}
@@ -1,6 +1,8 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.containers;
import com.intellij.util.DeprecatedMethodException;
/**
* @deprecated Use {@link MultiMap#createLinked()}
*/
@@ -8,5 +10,6 @@ package com.intellij.util.containers;
public class LinkedMultiMap<K, V> extends MultiMap<K, V> {
public LinkedMultiMap() {
super(CollectionFactory.createSmallMemoryFootprintLinkedMap());
DeprecatedMethodException.report("Use MultiMap.createLinked() instead");
}
}
@@ -1,169 +0,0 @@
/*
* Copyright 2000-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util.containers;
import com.intellij.util.DeprecatedMethodException;
import java.util.Arrays;
/**
* @deprecated use TLongArrayList instead
*/
@Deprecated
public class LongArrayList implements Cloneable {
private long[] myData;
private int mySize;
/**
* @deprecated use TLongArrayList instead
*/
@Deprecated
public LongArrayList() {
myData = new long[10];
DeprecatedMethodException.report("Use gnu.trove.TLongArrayList instead");
}
public void trimToSize() {
int oldCapacity = myData.length;
if (mySize < oldCapacity){
myData = Arrays.copyOf(myData, mySize);
}
}
public void ensureCapacity(int minCapacity) {
int oldCapacity = myData.length;
if (minCapacity > oldCapacity){
long[] oldData = myData;
int newCapacity = (oldCapacity * 3) / 2 + 1;
if (newCapacity < minCapacity){
newCapacity = minCapacity;
}
myData = Arrays.copyOf(myData, newCapacity);
}
}
public int size() {
return mySize;
}
public boolean isEmpty() {
return mySize == 0;
}
public boolean contains(long elem) {
return indexOf(elem) >= 0;
}
public int indexOf(long elem) {
for(int i = 0; i < mySize; i++){
if (elem == myData[i]) return i;
}
return -1;
}
public int lastIndexOf(long elem) {
for(int i = mySize - 1; i >= 0; i--){
if (elem == myData[i]) return i;
}
return -1;
}
@Override
public Object clone() {
try{
LongArrayList v = (LongArrayList)super.clone();
v.myData = myData.clone();
return v;
}
catch(CloneNotSupportedException e){
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
public long[] toArray() {
return Arrays.copyOf(myData, mySize);
}
public long[] toArray(long[] a) {
if (a.length < mySize){
a = new long[mySize];
}
System.arraycopy(myData, 0, a, 0, mySize);
return a;
}
public long get(int index) {
checkRange(index);
return myData[index];
}
public long set(int index, long element) {
checkRange(index);
long oldValue = myData[index];
myData[index] = element;
return oldValue;
}
public void add(long o) {
ensureCapacity(mySize + 1);
myData[mySize++] = o;
}
public void add(int index, long element) {
if (index > mySize || index < 0){
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + mySize);
}
ensureCapacity(mySize + 1);
System.arraycopy(myData, index, myData, index + 1, mySize - index);
myData[index] = element;
mySize++;
}
public long remove(int index) {
checkRange(index);
long oldValue = myData[index];
int numMoved = mySize - index - 1;
if (numMoved > 0){
System.arraycopy(myData, index + 1, myData, index,numMoved);
}
mySize--;
return oldValue;
}
public void clear() {
mySize = 0;
}
protected void removeRange(int fromIndex, int toIndex) {
int numMoved = mySize - toIndex;
System.arraycopy(myData, toIndex, myData, fromIndex, numMoved);
mySize -= (toIndex - fromIndex);
}
private void checkRange(int index) {
if (index >= mySize || index < 0){
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + mySize);
}
}
}
@@ -1,6 +1,8 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.containers;
import com.intellij.util.DeprecatedMethodException;
/**
* Allow to reuse equal strings to avoid memory being wasted on them. Strings are cached on weak references
* and garbage-collected when not needed anymore.
@@ -11,4 +13,7 @@ package com.intellij.util.containers;
*/
@Deprecated
public class WeakStringInterner extends WeakInterner<String> {
public WeakStringInterner() {
DeprecatedMethodException.report("Use Interner#createWeakInterner() instead");
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.util.containers.hash;
import com.intellij.util.DeprecatedMethodException;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@@ -42,6 +43,7 @@ public class HashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
public HashMap(int capacity, float loadFactor) {
this.loadFactor = loadFactor;
clear(capacity);
DeprecatedMethodException.report("Use java.util.HashMap instead");
}
@Override
@@ -15,6 +15,7 @@
*/
package com.intellij.util.containers.hash;
import com.intellij.util.DeprecatedMethodException;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@@ -44,6 +45,7 @@ public class HashSet<E> extends AbstractSet<E> implements Set<E> {
public HashSet(int capacity, float loadFactor) {
this.loadFactor = loadFactor;
clear(capacity);
DeprecatedMethodException.report("Use java.util.HashSet instead");
}
@Override