mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
continue: local variables defined in the console should be available for resolve/completion/variables view
This commit is contained in:
@@ -9,6 +9,16 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public abstract class AsyncValueLoader<T> {
|
||||
private final AtomicReference<AsyncResult<T>> ref = new AtomicReference<AsyncResult<T>>();
|
||||
|
||||
private volatile long modificationCount;
|
||||
private volatile long loadedModificationCount;
|
||||
|
||||
private final Runnable doneHandler = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadedModificationCount = modificationCount;
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
public final AsyncResult<T> get() {
|
||||
return get(true);
|
||||
@@ -59,7 +69,7 @@ public abstract class AsyncValueLoader<T> {
|
||||
return asyncResult;
|
||||
}
|
||||
else if (asyncResult.isDone()) {
|
||||
if (!checkFreshness || checkFreshness(asyncResult.getResult())) {
|
||||
if (!checkFreshness || isUpToDate(asyncResult.getResult())) {
|
||||
return asyncResult;
|
||||
}
|
||||
|
||||
@@ -90,22 +100,24 @@ public abstract class AsyncValueLoader<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void callLoad(final AsyncResult<T> asyncResult) {
|
||||
private void callLoad(final @NotNull AsyncResult<T> result) {
|
||||
if (isCancelOnReject()) {
|
||||
asyncResult.doWhenRejected(new Runnable() {
|
||||
result.doWhenRejected(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ref.compareAndSet(asyncResult, null);
|
||||
ref.compareAndSet(result, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
result.doWhenDone(doneHandler);
|
||||
|
||||
try {
|
||||
load(asyncResult);
|
||||
load(result);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
ref.compareAndSet(asyncResult, null);
|
||||
rejectAndDispose(asyncResult);
|
||||
ref.compareAndSet(result, null);
|
||||
rejectAndDispose(result);
|
||||
//noinspection InstanceofCatchParameter
|
||||
throw e instanceof RuntimeException ? ((RuntimeException)e) : new RuntimeException(e);
|
||||
}
|
||||
@@ -113,7 +125,18 @@ public abstract class AsyncValueLoader<T> {
|
||||
|
||||
protected abstract void load(@NotNull AsyncResult<T> result) throws IOException;
|
||||
|
||||
protected boolean checkFreshness(@NotNull T result) {
|
||||
return true;
|
||||
protected boolean isUpToDate(@NotNull T result) {
|
||||
return loadedModificationCount == modificationCount;
|
||||
}
|
||||
|
||||
public final void set(@NotNull T result) {
|
||||
AsyncResult<T> oldValue = ref.getAndSet(AsyncResult.done(result));
|
||||
if (oldValue != null) {
|
||||
rejectAndDispose(oldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public final void markDirty() {
|
||||
modificationCount++;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ public abstract class AsyncValueLoaderManager<HOST, VALUE> {
|
||||
this.fieldUpdater = fieldUpdater;
|
||||
}
|
||||
|
||||
public boolean checkFreshness(@NotNull HOST host, @NotNull VALUE value) {
|
||||
public boolean isUpToDate(@NotNull HOST host, @NotNull VALUE value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public abstract class AsyncValueLoaderManager<HOST, VALUE> {
|
||||
return asyncResult;
|
||||
}
|
||||
else if (asyncResult.isDone()) {
|
||||
if (!checkFreshness || checkFreshness(host, asyncResult.getResult())) {
|
||||
if (!checkFreshness || isUpToDate(host, asyncResult.getResult())) {
|
||||
return asyncResult;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user