continue: local variables defined in the console should be available for resolve/completion/variables view

This commit is contained in:
Vladimir Krivosheev
2014-03-28 12:12:59 +01:00
parent 247e21d04d
commit 6a59fbc5ec
2 changed files with 34 additions and 11 deletions
@@ -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;
}