Runnable: replace anonymous class with lambda
In Java 8 Runnable is functional interface and can be replaced with lambda expressions or method references. Change-Id: I2896b39c27b2e5a91a60149155a8c00a8eb48e39
This commit is contained in:
committed by
Shawn Pearce
parent
8f0528f3b5
commit
8785d73fa5
@@ -133,17 +133,14 @@ public class GerritServer {
|
||||
static GerritServer start(Description desc, Config baseConfig) throws Exception {
|
||||
Config cfg = desc.buildConfig(baseConfig);
|
||||
Logger.getLogger("com.google.gerrit").setLevel(Level.DEBUG);
|
||||
final CyclicBarrier serverStarted = new CyclicBarrier(2);
|
||||
final Daemon daemon =
|
||||
CyclicBarrier serverStarted = new CyclicBarrier(2);
|
||||
Daemon daemon =
|
||||
new Daemon(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
serverStarted.await();
|
||||
} catch (InterruptedException | BrokenBarrierException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
serverStarted.await();
|
||||
} catch (InterruptedException | BrokenBarrierException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
},
|
||||
Paths.get(baseConfig.getString("gerrit", null, "tempSiteDir")));
|
||||
|
||||
@@ -79,12 +79,9 @@ abstract class ChunkManager {
|
||||
cm.addLineClass(line, where, className);
|
||||
}
|
||||
undo.add(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int line = start; line < end; line++) {
|
||||
cm.removeLineClass(line, where, className);
|
||||
}
|
||||
() -> {
|
||||
for (int line = start; line < end; line++) {
|
||||
cm.removeLineClass(line, where, className);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -203,32 +203,26 @@ abstract class CommentManager {
|
||||
|
||||
abstract String getTokenSuffixForActiveLine(CodeMirror cm);
|
||||
|
||||
Runnable signInCallback(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String token = host.getToken();
|
||||
if (cm.extras().hasActiveLine()) {
|
||||
token += "@" + getTokenSuffixForActiveLine(cm);
|
||||
}
|
||||
Gerrit.doSignIn(token);
|
||||
Runnable signInCallback(CodeMirror cm) {
|
||||
return () -> {
|
||||
String token = host.getToken();
|
||||
if (cm.extras().hasActiveLine()) {
|
||||
token += "@" + getTokenSuffixForActiveLine(cm);
|
||||
}
|
||||
Gerrit.doSignIn(token);
|
||||
};
|
||||
}
|
||||
|
||||
abstract void newDraft(CodeMirror cm);
|
||||
|
||||
Runnable newDraftCallback(final CodeMirror cm) {
|
||||
Runnable newDraftCallback(CodeMirror cm) {
|
||||
if (!Gerrit.isSignedIn()) {
|
||||
return signInCallback(cm);
|
||||
}
|
||||
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (cm.extras().hasActiveLine()) {
|
||||
newDraft(cm);
|
||||
}
|
||||
return () -> {
|
||||
if (cm.extras().hasActiveLine()) {
|
||||
newDraft(cm);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -268,51 +262,48 @@ abstract class CommentManager {
|
||||
abstract SortedMap<Integer, CommentGroup> getMapForNav(DisplaySide side);
|
||||
|
||||
Runnable commentNav(final CodeMirror src, final Direction dir) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Every comment appears in both side maps as a linked pair.
|
||||
// It is only necessary to search one side to find a comment
|
||||
// on either side of the editor pair.
|
||||
SortedMap<Integer, CommentGroup> map = getMapForNav(src.side());
|
||||
int line =
|
||||
src.extras().hasActiveLine() ? src.getLineNumber(src.extras().activeLine()) + 1 : 0;
|
||||
return () -> {
|
||||
// Every comment appears in both side maps as a linked pair.
|
||||
// It is only necessary to search one side to find a comment
|
||||
// on either side of the editor pair.
|
||||
SortedMap<Integer, CommentGroup> map = getMapForNav(src.side());
|
||||
int line =
|
||||
src.extras().hasActiveLine() ? src.getLineNumber(src.extras().activeLine()) + 1 : 0;
|
||||
|
||||
CommentGroup g;
|
||||
if (dir == Direction.NEXT) {
|
||||
map = map.tailMap(line + 1);
|
||||
CommentGroup g;
|
||||
if (dir == Direction.NEXT) {
|
||||
map = map.tailMap(line + 1);
|
||||
if (map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
g = map.get(map.firstKey());
|
||||
while (g.getBoxCount() == 0) {
|
||||
map = map.tailMap(map.firstKey() + 1);
|
||||
if (map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
g = map.get(map.firstKey());
|
||||
while (g.getBoxCount() == 0) {
|
||||
map = map.tailMap(map.firstKey() + 1);
|
||||
if (map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
g = map.get(map.firstKey());
|
||||
}
|
||||
} else {
|
||||
map = map.headMap(line);
|
||||
}
|
||||
} else {
|
||||
map = map.headMap(line);
|
||||
if (map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
g = map.get(map.lastKey());
|
||||
while (g.getBoxCount() == 0) {
|
||||
map = map.headMap(map.lastKey());
|
||||
if (map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
g = map.get(map.lastKey());
|
||||
while (g.getBoxCount() == 0) {
|
||||
map = map.headMap(map.lastKey());
|
||||
if (map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
g = map.get(map.lastKey());
|
||||
}
|
||||
}
|
||||
|
||||
CodeMirror cm = g.getCm();
|
||||
double y = cm.heightAtLine(g.getLine() - 1, "local");
|
||||
cm.setCursor(Pos.create(g.getLine() - 1));
|
||||
cm.scrollToY(y - 0.5 * cm.scrollbarV().getClientHeight());
|
||||
cm.focus();
|
||||
}
|
||||
|
||||
CodeMirror cm = g.getCm();
|
||||
double y = cm.heightAtLine(g.getLine() - 1, "local");
|
||||
cm.setCursor(Pos.create(g.getLine() - 1));
|
||||
cm.scrollToY(y - 0.5 * cm.scrollbarV().getClientHeight());
|
||||
cm.focus();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -425,26 +416,20 @@ abstract class CommentManager {
|
||||
|
||||
abstract CommentGroup getCommentGroupOnActiveLine(CodeMirror cm);
|
||||
|
||||
Runnable toggleOpenBox(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
||||
if (group != null) {
|
||||
group.openCloseLast();
|
||||
}
|
||||
Runnable toggleOpenBox(CodeMirror cm) {
|
||||
return () -> {
|
||||
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
||||
if (group != null) {
|
||||
group.openCloseLast();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Runnable openCloseAll(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
||||
if (group != null) {
|
||||
group.openCloseAll();
|
||||
}
|
||||
Runnable openCloseAll(CodeMirror cm) {
|
||||
return () -> {
|
||||
CommentGroup group = getCommentGroupOnActiveLine(cm);
|
||||
if (group != null) {
|
||||
group.openCloseAll();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ abstract class DiffScreen extends Screen {
|
||||
handlers.clear();
|
||||
}
|
||||
|
||||
void registerCmEvents(final CodeMirror cm) {
|
||||
void registerCmEvents(CodeMirror cm) {
|
||||
cm.on("cursorActivity", updateActiveLine(cm));
|
||||
cm.on("focus", updateActiveLine(cm));
|
||||
KeyMap keyMap =
|
||||
@@ -356,169 +356,108 @@ abstract class DiffScreen extends Screen {
|
||||
.on("Shift-O", getCommentManager().openCloseAll(cm))
|
||||
.on(
|
||||
"I",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
switch (getIntraLineStatus()) {
|
||||
case OFF:
|
||||
case OK:
|
||||
toggleShowIntraline();
|
||||
break;
|
||||
case FAILURE:
|
||||
case TIMEOUT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
.on(
|
||||
"','",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
prefsAction.show();
|
||||
() -> {
|
||||
switch (getIntraLineStatus()) {
|
||||
case OFF:
|
||||
case OK:
|
||||
toggleShowIntraline();
|
||||
break;
|
||||
case FAILURE:
|
||||
case TIMEOUT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
.on("','", prefsAction::show)
|
||||
.on(
|
||||
"Shift-/",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new ShowHelpCommand().onKeyPress(null);
|
||||
}
|
||||
() -> {
|
||||
new ShowHelpCommand().onKeyPress(null);
|
||||
})
|
||||
.on(
|
||||
"Space",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.vim().handleKey("<C-d>");
|
||||
}
|
||||
() -> {
|
||||
cm.vim().handleKey("<C-d>");
|
||||
})
|
||||
.on(
|
||||
"Shift-Space",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.vim().handleKey("<C-u>");
|
||||
}
|
||||
() -> {
|
||||
cm.vim().handleKey("<C-u>");
|
||||
})
|
||||
.on(
|
||||
"Ctrl-F",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.execCommand("find");
|
||||
}
|
||||
() -> {
|
||||
cm.execCommand("find");
|
||||
})
|
||||
.on(
|
||||
"Ctrl-G",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.execCommand("findNext");
|
||||
}
|
||||
() -> {
|
||||
cm.execCommand("findNext");
|
||||
})
|
||||
.on("Enter", maybeNextCmSearch(cm))
|
||||
.on(
|
||||
"Shift-Ctrl-G",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.execCommand("findPrev");
|
||||
}
|
||||
() -> {
|
||||
cm.execCommand("findPrev");
|
||||
})
|
||||
.on(
|
||||
"Shift-Enter",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.execCommand("findPrev");
|
||||
}
|
||||
() -> {
|
||||
cm.execCommand("findPrev");
|
||||
})
|
||||
.on(
|
||||
"Esc",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.setCursor(cm.getCursor());
|
||||
cm.execCommand("clearSearch");
|
||||
cm.vim().handleEx("nohlsearch");
|
||||
}
|
||||
() -> {
|
||||
cm.setCursor(cm.getCursor());
|
||||
cm.execCommand("clearSearch");
|
||||
cm.vim().handleEx("nohlsearch");
|
||||
})
|
||||
.on(
|
||||
"Ctrl-A",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm.execCommand("selectAll");
|
||||
}
|
||||
() -> {
|
||||
cm.execCommand("selectAll");
|
||||
})
|
||||
.on(
|
||||
"G O",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.toChangeQuery("status:open"));
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.toChangeQuery("status:open"));
|
||||
})
|
||||
.on(
|
||||
"G M",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.toChangeQuery("status:merged"));
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.toChangeQuery("status:merged"));
|
||||
})
|
||||
.on(
|
||||
"G A",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.toChangeQuery("status:abandoned"));
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.toChangeQuery("status:abandoned"));
|
||||
});
|
||||
if (Gerrit.isSignedIn()) {
|
||||
keyMap
|
||||
.on(
|
||||
"G I",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.MINE);
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.MINE);
|
||||
})
|
||||
.on(
|
||||
"G D",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.toChangeQuery("owner:self is:draft"));
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.toChangeQuery("owner:self is:draft"));
|
||||
})
|
||||
.on(
|
||||
"G C",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.toChangeQuery("has:draft"));
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.toChangeQuery("has:draft"));
|
||||
})
|
||||
.on(
|
||||
"G W",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.toChangeQuery("is:watched status:open"));
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.toChangeQuery("is:watched status:open"));
|
||||
})
|
||||
.on(
|
||||
"G S",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Gerrit.display(PageLinks.toChangeQuery("is:starred"));
|
||||
}
|
||||
() -> {
|
||||
Gerrit.display(PageLinks.toChangeQuery("is:starred"));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -700,13 +639,10 @@ abstract class DiffScreen extends Screen {
|
||||
|
||||
void setContext(final int context) {
|
||||
operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
skipManager.removeAll();
|
||||
skipManager.render(context, diff);
|
||||
updateRenderEntireFile();
|
||||
}
|
||||
() -> {
|
||||
skipManager.removeAll();
|
||||
skipManager.render(context, diff);
|
||||
updateRenderEntireFile();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -753,21 +689,18 @@ abstract class DiffScreen extends Screen {
|
||||
return line - offset;
|
||||
}
|
||||
|
||||
private Runnable openEditScreen(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LineHandle handle = cm.extras().activeLine();
|
||||
int line = cm.getLineNumber(handle) + 1;
|
||||
if (Patch.COMMIT_MSG.equals(path)) {
|
||||
line = adjustCommitMessageLine(line);
|
||||
}
|
||||
String token = Dispatcher.toEditScreen(revision, path, line);
|
||||
if (!Gerrit.isSignedIn()) {
|
||||
Gerrit.doSignIn(token);
|
||||
} else {
|
||||
Gerrit.display(token);
|
||||
}
|
||||
private Runnable openEditScreen(CodeMirror cm) {
|
||||
return () -> {
|
||||
LineHandle handle = cm.extras().activeLine();
|
||||
int line = cm.getLineNumber(handle) + 1;
|
||||
if (Patch.COMMIT_MSG.equals(path)) {
|
||||
line = adjustCommitMessageLine(line);
|
||||
}
|
||||
String token = Dispatcher.toEditScreen(revision, path, line);
|
||||
if (!Gerrit.isSignedIn()) {
|
||||
Gerrit.doSignIn(token);
|
||||
} else {
|
||||
Gerrit.display(token);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -832,63 +765,51 @@ abstract class DiffScreen extends Screen {
|
||||
|
||||
abstract void operation(Runnable apply);
|
||||
|
||||
private Runnable upToChange(final boolean openReplyBox) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
CallbackGroup group = new CallbackGroup();
|
||||
getCommentManager().saveAllDrafts(group);
|
||||
group.done();
|
||||
group.addListener(
|
||||
new GerritCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
String rev = String.valueOf(revision.get());
|
||||
Gerrit.display(
|
||||
PageLinks.toChange(changeId, base.asString(), rev),
|
||||
new ChangeScreen(changeId, base, rev, openReplyBox, FileTable.Mode.REVIEW));
|
||||
}
|
||||
});
|
||||
private Runnable upToChange(boolean openReplyBox) {
|
||||
return () -> {
|
||||
CallbackGroup group = new CallbackGroup();
|
||||
getCommentManager().saveAllDrafts(group);
|
||||
group.done();
|
||||
group.addListener(
|
||||
new GerritCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
String rev = String.valueOf(revision.get());
|
||||
Gerrit.display(
|
||||
PageLinks.toChange(changeId, base.asString(), rev),
|
||||
new ChangeScreen(changeId, base, rev, openReplyBox, FileTable.Mode.REVIEW));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private Runnable maybePrevVimSearch(CodeMirror cm) {
|
||||
return () -> {
|
||||
if (cm.vim().hasSearchHighlight()) {
|
||||
cm.vim().handleKey("N");
|
||||
} else {
|
||||
getCommentManager().commentNav(cm, Direction.NEXT).run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Runnable maybePrevVimSearch(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (cm.vim().hasSearchHighlight()) {
|
||||
cm.vim().handleKey("N");
|
||||
} else {
|
||||
getCommentManager().commentNav(cm, Direction.NEXT).run();
|
||||
}
|
||||
private Runnable maybeNextVimSearch(CodeMirror cm) {
|
||||
return () -> {
|
||||
if (cm.vim().hasSearchHighlight()) {
|
||||
cm.vim().handleKey("n");
|
||||
} else {
|
||||
getChunkManager().diffChunkNav(cm, Direction.NEXT).run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Runnable maybeNextVimSearch(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (cm.vim().hasSearchHighlight()) {
|
||||
cm.vim().handleKey("n");
|
||||
} else {
|
||||
getChunkManager().diffChunkNav(cm, Direction.NEXT).run();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Runnable maybeNextCmSearch(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (cm.hasSearchHighlight()) {
|
||||
cm.execCommand("findNext");
|
||||
} else {
|
||||
cm.execCommand("clearSearch");
|
||||
getCommentManager().toggleOpenBox(cm).run();
|
||||
}
|
||||
Runnable maybeNextCmSearch(CodeMirror cm) {
|
||||
return () -> {
|
||||
if (cm.hasSearchHighlight()) {
|
||||
cm.execCommand("findNext");
|
||||
} else {
|
||||
cm.execCommand("clearSearch");
|
||||
getCommentManager().toggleOpenBox(cm).run();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -973,7 +894,7 @@ abstract class DiffScreen extends Screen {
|
||||
}
|
||||
|
||||
void reloadDiffInfo() {
|
||||
final int id = ++reloadVersionId;
|
||||
int id = ++reloadVersionId;
|
||||
DiffApi.diff(revision, path)
|
||||
.base(base.asPatchSetId())
|
||||
.wholeFile()
|
||||
@@ -986,16 +907,13 @@ abstract class DiffScreen extends Screen {
|
||||
if (id == reloadVersionId && isAttached()) {
|
||||
diff = diffInfo;
|
||||
operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
skipManager.removeAll();
|
||||
getChunkManager().reset();
|
||||
getDiffTable().scrollbar.removeDiffAnnotations();
|
||||
setShowIntraline(prefs.intralineDifference());
|
||||
render(diff);
|
||||
skipManager.render(prefs.context(), diff);
|
||||
}
|
||||
() -> {
|
||||
skipManager.removeAll();
|
||||
getChunkManager().reset();
|
||||
getDiffTable().scrollbar.removeDiffAnnotations();
|
||||
setShowIntraline(prefs.intralineDifference());
|
||||
render(diff);
|
||||
skipManager.render(prefs.context(), diff);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,47 +318,32 @@ public class Header extends Composite {
|
||||
}
|
||||
|
||||
Runnable toggleReviewed() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reviewed.setValue(!reviewed.getValue(), true);
|
||||
}
|
||||
return () -> {
|
||||
reviewed.setValue(!reviewed.getValue(), true);
|
||||
};
|
||||
}
|
||||
|
||||
Runnable navigate(Direction dir) {
|
||||
switch (dir) {
|
||||
case PREV:
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
(hasPrev ? prev : up).go();
|
||||
}
|
||||
return () -> {
|
||||
(hasPrev ? prev : up).go();
|
||||
};
|
||||
case NEXT:
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
(hasNext ? next : up).go();
|
||||
}
|
||||
return () -> {
|
||||
(hasNext ? next : up).go();
|
||||
};
|
||||
default:
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {}
|
||||
};
|
||||
return () -> {};
|
||||
}
|
||||
}
|
||||
|
||||
Runnable reviewedAndNext() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Gerrit.isSignedIn()) {
|
||||
reviewed.setValue(true, true);
|
||||
}
|
||||
navigate(Direction.NEXT).run();
|
||||
return () -> {
|
||||
if (Gerrit.isSignedIn()) {
|
||||
reviewed.setValue(true, true);
|
||||
}
|
||||
navigate(Direction.NEXT).run();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -322,13 +322,10 @@ public class PreferencesBox extends Composite {
|
||||
prefs.tabSize(Math.max(1, Integer.parseInt(v)));
|
||||
if (view != null) {
|
||||
view.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int v = prefs.tabSize();
|
||||
for (CodeMirror cm : view.getCms()) {
|
||||
cm.setOption("tabSize", v);
|
||||
}
|
||||
() -> {
|
||||
int size = prefs.tabSize();
|
||||
for (CodeMirror cm : view.getCms()) {
|
||||
cm.setOption("tabSize", size);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -342,11 +339,8 @@ public class PreferencesBox extends Composite {
|
||||
prefs.lineLength(Math.max(1, Integer.parseInt(v)));
|
||||
if (view != null) {
|
||||
view.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
view.setLineLength(prefs.lineLength());
|
||||
}
|
||||
() -> {
|
||||
view.setLineLength(prefs.lineLength());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -461,12 +455,9 @@ public class PreferencesBox extends Composite {
|
||||
&& Objects.equals(mode, getSelectedMode())
|
||||
&& view.isAttached()) {
|
||||
view.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
view.getCmFromSide(DisplaySide.A).setOption("mode", mode);
|
||||
view.getCmFromSide(DisplaySide.B).setOption("mode", mode);
|
||||
}
|
||||
() -> {
|
||||
view.getCmFromSide(DisplaySide.A).setOption("mode", mode);
|
||||
view.getCmFromSide(DisplaySide.B).setOption("mode", mode);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -483,13 +474,10 @@ public class PreferencesBox extends Composite {
|
||||
prefs.showWhitespaceErrors(e.getValue());
|
||||
if (view != null) {
|
||||
view.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean s = prefs.showWhitespaceErrors();
|
||||
for (CodeMirror cm : view.getCms()) {
|
||||
cm.setOption("showTrailingSpace", s);
|
||||
}
|
||||
() -> {
|
||||
boolean s = prefs.showWhitespaceErrors();
|
||||
for (CodeMirror cm : view.getCms()) {
|
||||
cm.setOption("showTrailingSpace", s);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -546,15 +534,12 @@ public class PreferencesBox extends Composite {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
view.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (getSelectedTheme() == newTheme && isAttached()) {
|
||||
String t = newTheme.name().toLowerCase();
|
||||
view.getCmFromSide(DisplaySide.A).setOption("theme", t);
|
||||
view.getCmFromSide(DisplaySide.B).setOption("theme", t);
|
||||
view.setThemeStyles(newTheme.isDark());
|
||||
}
|
||||
() -> {
|
||||
if (getSelectedTheme() == newTheme && isAttached()) {
|
||||
String t = newTheme.name().toLowerCase();
|
||||
view.getCmFromSide(DisplaySide.A).setOption("theme", t);
|
||||
view.getCmFromSide(DisplaySide.B).setOption("theme", t);
|
||||
view.setThemeStyles(newTheme.isDark());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -64,12 +64,9 @@ class ScrollbarAnnotation extends Widget implements ClickHandler {
|
||||
refresh =
|
||||
cmB.on(
|
||||
"refresh",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (updateScale()) {
|
||||
updatePosition();
|
||||
}
|
||||
() -> {
|
||||
if (updateScale()) {
|
||||
updatePosition();
|
||||
}
|
||||
});
|
||||
updateScale();
|
||||
|
||||
@@ -102,14 +102,11 @@ public class SideBySide extends DiffScreen {
|
||||
super.onShowView();
|
||||
|
||||
operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resizeCodeMirror();
|
||||
chunkManager.adjustPadding();
|
||||
cmA.refresh();
|
||||
cmB.refresh();
|
||||
}
|
||||
() -> {
|
||||
resizeCodeMirror();
|
||||
chunkManager.adjustPadding();
|
||||
cmA.refresh();
|
||||
cmB.refresh();
|
||||
});
|
||||
setLineLength(Patch.COMMIT_MSG.equals(path) ? 72 : prefs.lineLength());
|
||||
diffTable.refresh();
|
||||
@@ -209,18 +206,15 @@ public class SideBySide extends DiffScreen {
|
||||
chunkManager = new SideBySideChunkManager(this, cmA, cmB, diffTable.scrollbar);
|
||||
|
||||
operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Estimate initial CodeMirror height, fixed up in onShowView.
|
||||
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
||||
cmA.setHeight(height);
|
||||
cmB.setHeight(height);
|
||||
() -> {
|
||||
// Estimate initial CodeMirror height, fixed up in onShowView.
|
||||
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
||||
cmA.setHeight(height);
|
||||
cmB.setHeight(height);
|
||||
|
||||
render(diff);
|
||||
commentManager.render(comments, prefs.expandAllComments());
|
||||
skipManager.render(prefs.context(), diff);
|
||||
}
|
||||
render(diff);
|
||||
commentManager.render(comments, prefs.expandAllComments());
|
||||
skipManager.render(prefs.context(), diff);
|
||||
});
|
||||
|
||||
registerCmEvents(cmA);
|
||||
@@ -321,64 +315,50 @@ public class SideBySide extends DiffScreen {
|
||||
@Override
|
||||
Runnable updateActiveLine(final CodeMirror cm) {
|
||||
final CodeMirror other = otherCm(cm);
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// The rendering of active lines has to be deferred. Reflow
|
||||
// caused by adding and removing styles chokes Firefox when arrow
|
||||
// key (or j/k) is held down. Performance on Chrome is fine
|
||||
// without the deferral.
|
||||
//
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LineHandle handle =
|
||||
cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
||||
if (!cm.extras().activeLine(handle)) {
|
||||
return;
|
||||
}
|
||||
return () -> {
|
||||
// The rendering of active lines has to be deferred. Reflow
|
||||
// caused by adding and removing styles chokes Firefox when arrow
|
||||
// key (or j/k) is held down. Performance on Chrome is fine
|
||||
// without the deferral.
|
||||
//
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
operation(
|
||||
() -> {
|
||||
LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
||||
if (!cm.extras().activeLine(handle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LineOnOtherInfo info = lineOnOther(cm.side(), cm.getLineNumber(handle));
|
||||
if (info.isAligned()) {
|
||||
other.extras().activeLine(other.getLineHandle(info.getLine()));
|
||||
} else {
|
||||
other.extras().clearActiveLine();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
LineOnOtherInfo info = lineOnOther(cm.side(), cm.getLineNumber(handle));
|
||||
if (info.isAligned()) {
|
||||
other.extras().activeLine(other.getLineHandle(info.getLine()));
|
||||
} else {
|
||||
other.extras().clearActiveLine();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private Runnable moveCursorToSide(final CodeMirror cmSrc, DisplaySide sideDst) {
|
||||
final CodeMirror cmDst = getCmFromSide(sideDst);
|
||||
if (cmDst == cmSrc) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {}
|
||||
};
|
||||
return () -> {};
|
||||
}
|
||||
|
||||
final DisplaySide sideSrc = cmSrc.side();
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (cmSrc.extras().hasActiveLine()) {
|
||||
cmDst.setCursor(
|
||||
Pos.create(
|
||||
lineOnOther(sideSrc, cmSrc.getLineNumber(cmSrc.extras().activeLine()))
|
||||
.getLine()));
|
||||
}
|
||||
cmDst.focus();
|
||||
return () -> {
|
||||
if (cmSrc.extras().hasActiveLine()) {
|
||||
cmDst.setCursor(
|
||||
Pos.create(
|
||||
lineOnOther(sideSrc, cmSrc.getLineNumber(cmSrc.extras().activeLine())).getLine()));
|
||||
}
|
||||
cmDst.focus();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -389,19 +369,10 @@ public class SideBySide extends DiffScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
void operation(final Runnable apply) {
|
||||
void operation(Runnable apply) {
|
||||
cmA.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmB.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
apply.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
() -> {
|
||||
cmB.operation(apply::run);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -246,15 +246,12 @@ class SideBySideChunkManager extends ChunkManager {
|
||||
|
||||
@Override
|
||||
Runnable diffChunkNav(final CodeMirror cm, final Direction dir) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
||||
int res =
|
||||
Collections.binarySearch(
|
||||
chunks, new DiffChunkInfo(cm.side(), line, 0, false), getDiffChunkComparator());
|
||||
diffChunkNavHelper(chunks, host, res, dir);
|
||||
}
|
||||
return () -> {
|
||||
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
||||
int res =
|
||||
Collections.binarySearch(
|
||||
chunks, new DiffChunkInfo(cm.side(), line, 0, false), getDiffChunkComparator());
|
||||
diffChunkNavHelper(chunks, host, res, dir);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -88,29 +88,26 @@ class SideBySideCommentGroup extends CommentGroup implements Comparable<SideBySi
|
||||
void handleRedraw() {
|
||||
getLineWidget()
|
||||
.onRedraw(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
||||
if (getResizeTimer() != null) {
|
||||
getResizeTimer().cancel();
|
||||
setResizeTimer(null);
|
||||
}
|
||||
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
||||
} else if (getResizeTimer() == null) {
|
||||
setResizeTimer(
|
||||
new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
||||
cancel();
|
||||
setResizeTimer(null);
|
||||
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
||||
}
|
||||
}
|
||||
});
|
||||
getResizeTimer().scheduleRepeating(5);
|
||||
() -> {
|
||||
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
||||
if (getResizeTimer() != null) {
|
||||
getResizeTimer().cancel();
|
||||
setResizeTimer(null);
|
||||
}
|
||||
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
||||
} else if (getResizeTimer() == null) {
|
||||
setResizeTimer(
|
||||
new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (canComputeHeight() && peers.peek().canComputeHeight()) {
|
||||
cancel();
|
||||
setResizeTimer(null);
|
||||
adjustPadding(SideBySideCommentGroup.this, peers.peek());
|
||||
}
|
||||
}
|
||||
});
|
||||
getResizeTimer().scheduleRepeating(5);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,11 +75,8 @@ class SideBySideTable extends DiffTable {
|
||||
}
|
||||
|
||||
Runnable toggleA() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setVisibleA(!isVisibleA());
|
||||
}
|
||||
return () -> {
|
||||
setVisibleA(!isVisibleA());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -91,12 +91,9 @@ class SkipBar extends Composite {
|
||||
}
|
||||
if (isNew) {
|
||||
lineWidget.onFirstRedraw(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int w = cm.getGutterElement().getOffsetWidth();
|
||||
getElement().getStyle().setPaddingLeft(w, Unit.PX);
|
||||
}
|
||||
() -> {
|
||||
int w = cm.getGutterElement().getOffsetWidth();
|
||||
getElement().getStyle().setPaddingLeft(w, Unit.PX);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -110,14 +107,7 @@ class SkipBar extends Composite {
|
||||
.set("inclusiveLeft", true)
|
||||
.set("inclusiveRight", true));
|
||||
|
||||
textMarker.on(
|
||||
"beforeCursorEnter",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
expandAll();
|
||||
}
|
||||
});
|
||||
textMarker.on("beforeCursorEnter", this::expandAll);
|
||||
|
||||
int skipped = end - start + 1;
|
||||
if (skipped <= UP_DOWN_THRESHOLD) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArrayString;
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.event.dom.client.FocusEvent;
|
||||
import com.google.gwt.event.dom.client.FocusHandler;
|
||||
@@ -102,12 +101,9 @@ public class Unified extends DiffScreen {
|
||||
super.onShowView();
|
||||
|
||||
operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resizeCodeMirror();
|
||||
cm.refresh();
|
||||
}
|
||||
() -> {
|
||||
resizeCodeMirror();
|
||||
cm.refresh();
|
||||
});
|
||||
setLineLength(Patch.COMMIT_MSG.equals(path) ? 72 : prefs.lineLength());
|
||||
diffTable.refresh();
|
||||
@@ -142,13 +138,10 @@ public class Unified extends DiffScreen {
|
||||
|
||||
cm.on(
|
||||
"scroll",
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ScrollInfo si = cm.getScrollInfo();
|
||||
if (autoHideDiffTableHeader) {
|
||||
updateDiffTableHeader(si);
|
||||
}
|
||||
() -> {
|
||||
ScrollInfo si = cm.getScrollInfo();
|
||||
if (autoHideDiffTableHeader) {
|
||||
updateDiffTableHeader(si);
|
||||
}
|
||||
});
|
||||
maybeRegisterRenderEntireFileKeyMap(cm);
|
||||
@@ -186,17 +179,14 @@ public class Unified extends DiffScreen {
|
||||
chunkManager = new UnifiedChunkManager(this, cm, diffTable.scrollbar);
|
||||
|
||||
operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Estimate initial CodeMirror height, fixed up in onShowView.
|
||||
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
||||
cm.setHeight(height);
|
||||
() -> {
|
||||
// Estimate initial CodeMirror height, fixed up in onShowView.
|
||||
int height = Window.getClientHeight() - (Gerrit.getHeaderFooterHeight() + 18);
|
||||
cm.setHeight(height);
|
||||
|
||||
render(diff);
|
||||
commentManager.render(comments, prefs.expandAllComments());
|
||||
skipManager.render(prefs.context(), diff);
|
||||
}
|
||||
render(diff);
|
||||
commentManager.render(comments, prefs.expandAllComments());
|
||||
skipManager.render(prefs.context(), diff);
|
||||
});
|
||||
|
||||
registerCmEvents(cm);
|
||||
@@ -318,24 +308,18 @@ public class Unified extends DiffScreen {
|
||||
|
||||
@Override
|
||||
Runnable updateActiveLine(final CodeMirror cm) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// The rendering of active lines has to be deferred. Reflow
|
||||
// caused by adding and removing styles chokes Firefox when arrow
|
||||
// key (or j/k) is held down. Performance on Chrome is fine
|
||||
// without the deferral.
|
||||
//
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
||||
cm.extras().activeLine(handle);
|
||||
}
|
||||
});
|
||||
}
|
||||
return () -> {
|
||||
// The rendering of active lines has to be deferred. Reflow
|
||||
// caused by adding and removing styles chokes Firefox when arrow
|
||||
// key (or j/k) is held down. Performance on Chrome is fine
|
||||
// without the deferral.
|
||||
//
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
() -> {
|
||||
LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
|
||||
cm.extras().activeLine(handle);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -354,14 +338,8 @@ public class Unified extends DiffScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
void operation(final Runnable apply) {
|
||||
cm.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
apply.run();
|
||||
}
|
||||
});
|
||||
void operation(Runnable apply) {
|
||||
cm.operation(apply::run);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -214,17 +214,14 @@ class UnifiedChunkManager extends ChunkManager {
|
||||
|
||||
@Override
|
||||
Runnable diffChunkNav(final CodeMirror cm, final Direction dir) {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
||||
int res =
|
||||
Collections.binarySearch(
|
||||
chunks,
|
||||
new UnifiedDiffChunkInfo(cm.side(), 0, 0, line, false),
|
||||
getDiffChunkComparatorCmLine());
|
||||
diffChunkNavHelper(chunks, host, res, dir);
|
||||
}
|
||||
return () -> {
|
||||
int line = cm.extras().hasActiveLine() ? cm.getLineNumber(cm.extras().activeLine()) : 0;
|
||||
int res =
|
||||
Collections.binarySearch(
|
||||
chunks,
|
||||
new UnifiedDiffChunkInfo(cm.side(), 0, 0, line, false),
|
||||
getDiffChunkComparatorCmLine());
|
||||
diffChunkNavHelper(chunks, host, res, dir);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -50,29 +50,26 @@ class UnifiedCommentGroup extends CommentGroup {
|
||||
void handleRedraw() {
|
||||
getLineWidget()
|
||||
.onRedraw(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (canComputeHeight()) {
|
||||
if (getResizeTimer() != null) {
|
||||
getResizeTimer().cancel();
|
||||
setResizeTimer(null);
|
||||
}
|
||||
reportHeightChange();
|
||||
} else if (getResizeTimer() == null) {
|
||||
setResizeTimer(
|
||||
new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (canComputeHeight()) {
|
||||
cancel();
|
||||
setResizeTimer(null);
|
||||
reportHeightChange();
|
||||
}
|
||||
}
|
||||
});
|
||||
getResizeTimer().scheduleRepeating(5);
|
||||
() -> {
|
||||
if (canComputeHeight()) {
|
||||
if (getResizeTimer() != null) {
|
||||
getResizeTimer().cancel();
|
||||
setResizeTimer(null);
|
||||
}
|
||||
reportHeightChange();
|
||||
} else if (getResizeTimer() == null) {
|
||||
setResizeTimer(
|
||||
new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (canComputeHeight()) {
|
||||
cancel();
|
||||
setResizeTimer(null);
|
||||
reportHeightChange();
|
||||
}
|
||||
}
|
||||
});
|
||||
getResizeTimer().scheduleRepeating(5);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
@@ -318,11 +317,8 @@ public class EditScreen extends Screen {
|
||||
}
|
||||
|
||||
private Runnable gotoLine() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmEdit.execCommand("jumpToLine");
|
||||
}
|
||||
return () -> {
|
||||
cmEdit.execCommand("jumpToLine");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -474,18 +470,12 @@ public class EditScreen extends Screen {
|
||||
|
||||
void setTheme(final Theme newTheme) {
|
||||
cmBase.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmBase.setOption("theme", newTheme.name().toLowerCase());
|
||||
}
|
||||
() -> {
|
||||
cmBase.setOption("theme", newTheme.name().toLowerCase());
|
||||
});
|
||||
cmEdit.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmEdit.setOption("theme", newTheme.name().toLowerCase());
|
||||
}
|
||||
() -> {
|
||||
cmEdit.setOption("theme", newTheme.name().toLowerCase());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -506,18 +496,12 @@ public class EditScreen extends Screen {
|
||||
|
||||
void setShowWhitespaceErrors(final boolean show) {
|
||||
cmBase.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmBase.setOption("showTrailingSpace", show);
|
||||
}
|
||||
() -> {
|
||||
cmBase.setOption("showTrailingSpace", show);
|
||||
});
|
||||
cmEdit.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cmEdit.setOption("showTrailingSpace", show);
|
||||
}
|
||||
() -> {
|
||||
cmEdit.setOption("showTrailingSpace", show);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -643,29 +627,17 @@ public class EditScreen extends Screen {
|
||||
}
|
||||
|
||||
private Runnable updateCursorPosition() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// The rendering of active lines has to be deferred. Reflow
|
||||
// caused by adding and removing styles chokes Firefox when arrow
|
||||
// key (or j/k) is held down. Performance on Chrome is fine
|
||||
// without the deferral.
|
||||
//
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
cmEdit.operation(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateActiveLine();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return () -> {
|
||||
// The rendering of active lines has to be deferred. Reflow
|
||||
// caused by adding and removing styles chokes Firefox when arrow
|
||||
// key (or j/k) is held down. Performance on Chrome is fine
|
||||
// without the deferral.
|
||||
//
|
||||
Scheduler.get()
|
||||
.scheduleDeferred(
|
||||
() -> {
|
||||
cmEdit.operation(this::updateActiveLine);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -683,37 +655,34 @@ public class EditScreen extends Screen {
|
||||
}
|
||||
|
||||
private Runnable save() {
|
||||
return new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!cmEdit.isClean(generation)) {
|
||||
close.setEnabled(false);
|
||||
String text = cmEdit.getValue();
|
||||
if (Patch.COMMIT_MSG.equals(path)) {
|
||||
String trimmed = text.trim() + "\r";
|
||||
if (!trimmed.equals(text)) {
|
||||
text = trimmed;
|
||||
cmEdit.setValue(text);
|
||||
}
|
||||
return () -> {
|
||||
if (!cmEdit.isClean(generation)) {
|
||||
close.setEnabled(false);
|
||||
String text = cmEdit.getValue();
|
||||
if (Patch.COMMIT_MSG.equals(path)) {
|
||||
String trimmed = text.trim() + "\r";
|
||||
if (!trimmed.equals(text)) {
|
||||
text = trimmed;
|
||||
cmEdit.setValue(text);
|
||||
}
|
||||
final int g = cmEdit.changeGeneration(false);
|
||||
ChangeEditApi.put(
|
||||
revision.getParentKey().get(),
|
||||
path,
|
||||
text,
|
||||
new GerritCallback<VoidResult>() {
|
||||
@Override
|
||||
public void onSuccess(VoidResult result) {
|
||||
generation = g;
|
||||
setClean(cmEdit.isClean(g));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(final Throwable caught) {
|
||||
close.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
final int g = cmEdit.changeGeneration(false);
|
||||
ChangeEditApi.put(
|
||||
revision.getParentKey().get(),
|
||||
path,
|
||||
text,
|
||||
new GerritCallback<VoidResult>() {
|
||||
@Override
|
||||
public void onSuccess(VoidResult result) {
|
||||
generation = g;
|
||||
setClean(cmEdit.isClean(g));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(final Throwable caught) {
|
||||
close.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -121,28 +121,25 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
|
||||
@SuppressWarnings("unused") // Error handling within Runnable.
|
||||
Future<?> possiblyIgnoredError =
|
||||
autoCommitExecutor.scheduleAtFixedRate(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
() -> {
|
||||
try {
|
||||
if (autoCommitWriter.hasUncommittedChanges()) {
|
||||
autoCommitWriter.manualFlush();
|
||||
autoCommitWriter.commit();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error committing " + index + " Lucene index", e);
|
||||
} catch (OutOfMemoryError e) {
|
||||
log.error("Error committing " + index + " Lucene index", e);
|
||||
try {
|
||||
if (autoCommitWriter.hasUncommittedChanges()) {
|
||||
autoCommitWriter.manualFlush();
|
||||
autoCommitWriter.commit();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("Error committing " + index + " Lucene index", e);
|
||||
} catch (OutOfMemoryError e) {
|
||||
log.error("Error committing " + index + " Lucene index", e);
|
||||
try {
|
||||
autoCommitWriter.close();
|
||||
} catch (IOException e2) {
|
||||
log.error(
|
||||
"SEVERE: Error closing "
|
||||
+ index
|
||||
+ " Lucene index after OOM;"
|
||||
+ " index may be corrupted.",
|
||||
e);
|
||||
}
|
||||
autoCommitWriter.close();
|
||||
} catch (IOException e2) {
|
||||
log.error(
|
||||
"SEVERE: Error closing "
|
||||
+ index
|
||||
+ " Lucene index after OOM;"
|
||||
+ " index may be corrupted.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -228,12 +228,9 @@ public class Daemon extends SiteProgram {
|
||||
try {
|
||||
start();
|
||||
RuntimeShutdown.add(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.info("caught shutdown, cleaning up");
|
||||
stop();
|
||||
}
|
||||
() -> {
|
||||
log.info("caught shutdown, cleaning up");
|
||||
stop();
|
||||
});
|
||||
|
||||
log.info("Gerrit Code Review " + myVersion() + " ready");
|
||||
|
||||
@@ -45,16 +45,13 @@ public class Gsql extends SiteProgram {
|
||||
manager.add(dbInjector);
|
||||
manager.start();
|
||||
RuntimeShutdown.add(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
System.in.close();
|
||||
} catch (IOException e) {
|
||||
// Ignored
|
||||
}
|
||||
manager.stop();
|
||||
() -> {
|
||||
try {
|
||||
System.in.close();
|
||||
} catch (IOException e) {
|
||||
// Ignored
|
||||
}
|
||||
manager.stop();
|
||||
});
|
||||
final QueryShell shell = shellFactory().create(System.in, System.out);
|
||||
shell.setOutputFormat(format);
|
||||
|
||||
@@ -85,13 +85,7 @@ public class ProtobufImport extends SiteProgram {
|
||||
Injector dbInjector = createDbInjector(SINGLE_USER);
|
||||
manager.add(dbInjector);
|
||||
manager.start();
|
||||
RuntimeShutdown.add(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
manager.stop();
|
||||
}
|
||||
});
|
||||
RuntimeShutdown.add(manager::stop);
|
||||
dbInjector.injectMembers(this);
|
||||
|
||||
ProgressMonitor progress = new TextProgressMonitor();
|
||||
|
||||
@@ -79,19 +79,16 @@ public abstract class MetricMaker {
|
||||
* @param value only value of the metric.
|
||||
* @param desc description of the metric.
|
||||
*/
|
||||
public <V> void newConstantMetric(String name, final V value, Description desc) {
|
||||
public <V> void newConstantMetric(String name, V value, Description desc) {
|
||||
desc.setConstant();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<V> type = (Class<V>) value.getClass();
|
||||
final CallbackMetric0<V> metric = newCallbackMetric(name, type, desc);
|
||||
CallbackMetric0<V> metric = newCallbackMetric(name, type, desc);
|
||||
newTrigger(
|
||||
metric,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
metric.set(value);
|
||||
}
|
||||
() -> {
|
||||
metric.set(value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -116,15 +113,12 @@ public abstract class MetricMaker {
|
||||
* @param trigger function to compute the value of the metric.
|
||||
*/
|
||||
public <V> void newCallbackMetric(
|
||||
String name, Class<V> valueClass, Description desc, final Supplier<V> trigger) {
|
||||
final CallbackMetric0<V> metric = newCallbackMetric(name, valueClass, desc);
|
||||
String name, Class<V> valueClass, Description desc, Supplier<V> trigger) {
|
||||
CallbackMetric0<V> metric = newCallbackMetric(name, valueClass, desc);
|
||||
newTrigger(
|
||||
metric,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
metric.set(trigger.get());
|
||||
}
|
||||
() -> {
|
||||
metric.set(trigger.get());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -147,23 +147,20 @@ public class ProcMetricModule extends MetricModule {
|
||||
metrics.newTrigger(
|
||||
ImmutableSet.<CallbackMetric<?>>of(
|
||||
heapCommitted, heapUsed, nonHeapCommitted, nonHeapUsed, objectPendingFinalizationCount),
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
MemoryUsage stats = memory.getHeapMemoryUsage();
|
||||
heapCommitted.set(stats.getCommitted());
|
||||
heapUsed.set(stats.getUsed());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// MXBean may throw due to a bug in Java 7; ignore.
|
||||
}
|
||||
|
||||
MemoryUsage stats = memory.getNonHeapMemoryUsage();
|
||||
nonHeapCommitted.set(stats.getCommitted());
|
||||
nonHeapUsed.set(stats.getUsed());
|
||||
|
||||
objectPendingFinalizationCount.set(memory.getObjectPendingFinalizationCount());
|
||||
() -> {
|
||||
try {
|
||||
MemoryUsage stats = memory.getHeapMemoryUsage();
|
||||
heapCommitted.set(stats.getCommitted());
|
||||
heapUsed.set(stats.getUsed());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// MXBean may throw due to a bug in Java 7; ignore.
|
||||
}
|
||||
|
||||
MemoryUsage stats = memory.getNonHeapMemoryUsage();
|
||||
nonHeapCommitted.set(stats.getCommitted());
|
||||
nonHeapUsed.set(stats.getUsed());
|
||||
|
||||
objectPendingFinalizationCount.set(memory.getObjectPendingFinalizationCount());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -187,18 +184,15 @@ public class ProcMetricModule extends MetricModule {
|
||||
metrics.newTrigger(
|
||||
gcCount,
|
||||
gcTime,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
|
||||
long count = gc.getCollectionCount();
|
||||
if (count != -1) {
|
||||
gcCount.set(gc.getName(), count);
|
||||
}
|
||||
long time = gc.getCollectionTime();
|
||||
if (time != -1) {
|
||||
gcTime.set(gc.getName(), time);
|
||||
}
|
||||
() -> {
|
||||
for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
|
||||
long count = gc.getCollectionCount();
|
||||
if (count != -1) {
|
||||
gcCount.set(gc.getName(), count);
|
||||
}
|
||||
long time = gc.getCollectionTime();
|
||||
if (time != -1) {
|
||||
gcTime.set(gc.getName(), time);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -119,19 +119,13 @@ public final class StoredValues {
|
||||
GitRepositoryManager gitMgr = env.getArgs().getGitRepositoryManager();
|
||||
Change change = getChange(engine);
|
||||
Project.NameKey projectKey = change.getProject();
|
||||
final Repository repo;
|
||||
Repository repo;
|
||||
try {
|
||||
repo = gitMgr.openRepository(projectKey);
|
||||
} catch (IOException e) {
|
||||
throw new SystemException(e.getMessage());
|
||||
}
|
||||
env.addToCleanup(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
repo.close();
|
||||
}
|
||||
});
|
||||
env.addToCleanup(repo::close);
|
||||
return repo;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,26 +69,23 @@ public class CacheMetrics {
|
||||
|
||||
metrics.newTrigger(
|
||||
cacheMetrics,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (DynamicMap.Entry<Cache<?, ?>> e : cacheMap) {
|
||||
Cache<?, ?> c = e.getProvider().get();
|
||||
String name = metricNameOf(e);
|
||||
CacheStats cstats = c.stats();
|
||||
memEnt.set(name, c.size());
|
||||
memHit.set(name, cstats.hitRate() * 100);
|
||||
memEvict.set(name, cstats.evictionCount());
|
||||
if (c instanceof PersistentCache) {
|
||||
PersistentCache.DiskStats d = ((PersistentCache) c).diskStats();
|
||||
perDiskEnt.set(name, d.size());
|
||||
perDiskHit.set(name, hitRatio(d));
|
||||
}
|
||||
}
|
||||
for (CallbackMetric<?> cbm : cacheMetrics) {
|
||||
cbm.prune();
|
||||
() -> {
|
||||
for (DynamicMap.Entry<Cache<?, ?>> e : cacheMap) {
|
||||
Cache<?, ?> c = e.getProvider().get();
|
||||
String name = metricNameOf(e);
|
||||
CacheStats cstats = c.stats();
|
||||
memEnt.set(name, c.size());
|
||||
memHit.set(name, cstats.hitRate() * 100);
|
||||
memEvict.set(name, cstats.evictionCount());
|
||||
if (c instanceof PersistentCache) {
|
||||
PersistentCache.DiskStats d = ((PersistentCache) c).diskStats();
|
||||
perDiskEnt.set(name, d.size());
|
||||
perDiskHit.set(name, hitRatio(d));
|
||||
}
|
||||
}
|
||||
for (CallbackMetric<?> cbm : cacheMetrics) {
|
||||
cbm.prune();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -51,12 +51,9 @@ public class RequestScopedReviewDbProvider implements Provider<ReviewDb> {
|
||||
cleanup
|
||||
.get()
|
||||
.add(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
c.close();
|
||||
db = null;
|
||||
}
|
||||
() -> {
|
||||
c.close();
|
||||
db = null;
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
c.close();
|
||||
|
||||
@@ -54,25 +54,19 @@ public class ProjectCacheWarmer implements LifecycleListener {
|
||||
|
||||
log.info("Loading project cache");
|
||||
scheduler.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (final Project.NameKey name : cache.all()) {
|
||||
pool.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cache.get(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
pool.shutdown();
|
||||
try {
|
||||
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
log.info("Finished loading project cache");
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Interrupted while waiting for project cache to load");
|
||||
}
|
||||
() -> {
|
||||
for (final Project.NameKey name : cache.all()) {
|
||||
pool.execute(
|
||||
() -> {
|
||||
cache.get(name);
|
||||
});
|
||||
}
|
||||
pool.shutdown();
|
||||
try {
|
||||
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
log.info("Finished loading project cache");
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Interrupted while waiting for project cache to load");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,8 +161,8 @@ public class DataSourceProvider implements Provider<DataSource>, LifecycleListen
|
||||
}
|
||||
}
|
||||
|
||||
private void exportPoolMetrics(final BasicDataSource pool) {
|
||||
final CallbackMetric1<Boolean, Integer> cnt =
|
||||
private void exportPoolMetrics(BasicDataSource pool) {
|
||||
CallbackMetric1<Boolean, Integer> cnt =
|
||||
metrics.newCallbackMetric(
|
||||
"sql/connection_pool/connections",
|
||||
Integer.class,
|
||||
@@ -170,13 +170,10 @@ public class DataSourceProvider implements Provider<DataSource>, LifecycleListen
|
||||
Field.ofBoolean("active"));
|
||||
metrics.newTrigger(
|
||||
cnt,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (pool) {
|
||||
cnt.set(true, pool.getNumActive());
|
||||
cnt.set(false, pool.getNumIdle());
|
||||
}
|
||||
() -> {
|
||||
synchronized (pool) {
|
||||
cnt.set(true, pool.getNumActive());
|
||||
cnt.set(false, pool.getNumIdle());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -133,12 +133,9 @@ public class ProcMetricModuleTest {
|
||||
final AtomicInteger invocations = new AtomicInteger(0);
|
||||
metrics.newTrigger(
|
||||
cntr,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
invocations.getAndIncrement();
|
||||
cntr.set(42L);
|
||||
}
|
||||
() -> {
|
||||
invocations.getAndIncrement();
|
||||
cntr.set(42L);
|
||||
});
|
||||
|
||||
// Triggers run immediately with DropWizard binding.
|
||||
|
||||
@@ -159,14 +159,11 @@ public class RepoSequenceTest {
|
||||
// Seed existing ref value.
|
||||
writeBlob("id", "1");
|
||||
|
||||
final AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
|
||||
AtomicBoolean doneBgUpdate = new AtomicBoolean(false);
|
||||
Runnable bgUpdate =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!doneBgUpdate.getAndSet(true)) {
|
||||
writeBlob("id", "1234");
|
||||
}
|
||||
() -> {
|
||||
if (!doneBgUpdate.getAndSet(true)) {
|
||||
writeBlob("id", "1234");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -203,13 +200,10 @@ public class RepoSequenceTest {
|
||||
|
||||
@Test
|
||||
public void failAfterRetryerGivesUp() throws Exception {
|
||||
final AtomicInteger bgCounter = new AtomicInteger(1234);
|
||||
AtomicInteger bgCounter = new AtomicInteger(1234);
|
||||
Runnable bgUpdate =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000)));
|
||||
}
|
||||
() -> {
|
||||
writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000)));
|
||||
};
|
||||
RepoSequence s =
|
||||
newSequence(
|
||||
|
||||
@@ -230,13 +230,7 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
Future<?> future = task.getAndSet(null);
|
||||
if (future != null) {
|
||||
future.cancel(true);
|
||||
destroyExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onDestroy();
|
||||
}
|
||||
});
|
||||
destroyExecutor.execute(this::onDestroy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user