Skip to content

Commit

Permalink
avoid busy and possibly infinite loop in JavaEditorExtension
Browse files Browse the repository at this point in the history
Maybe due to a bug in Platform not correctly closing or saving editors.
  • Loading branch information
LorenzoBettini committed Jan 19, 2024
1 parent f393871 commit 7727972
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,22 @@ class JavaEditorExtension {
}
], eventMask)
producer.apply
while (!changed.get) {
var retries = 30
while (!changed.get && retries-- > 0) {
if (Display.getCurrent() !== null) {
while (Display.getDefault().readAndDispatch()) {
// process queued ui events
}
}
if (!changed.get) {
if (VERBOSE) {
println('''sleeping, left retries: «retries»''')
}
Thread.sleep(100)
}
}
if (!changed.get)
throw new AssertionError("No event has been received")
if (VERBOSE) {
println('''end waiting for an element changed event: «eventMask»''')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,49 +109,72 @@ public String waitForPostChangeEvent(final Procedure0 producer) {
}

public String waitForElementChangedEvent(final int eventMask, final Procedure0 producer) {
String _xblockexpression = null;
{
if ((JavaEditorExtension.VERBOSE).booleanValue()) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("start waiting for an element changed event: ");
_builder.append(eventMask);
InputOutput.<String>println(_builder.toString());
}
final AtomicBoolean changed = new AtomicBoolean(false);
final IElementChangedListener _function = new IElementChangedListener() {
@Override
public void elementChanged(final ElementChangedEvent it) {
JavaCore.removeElementChangedListener(this);
boolean _get = changed.get();
boolean _not = (!_get);
if (_not) {
changed.set(true);
if ((JavaEditorExtension.VERBOSE).booleanValue()) {
InputOutput.<ElementChangedEvent>println(it);
try {
String _xblockexpression = null;
{
if ((JavaEditorExtension.VERBOSE).booleanValue()) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("start waiting for an element changed event: ");
_builder.append(eventMask);
InputOutput.<String>println(_builder.toString());
}
final AtomicBoolean changed = new AtomicBoolean(false);
final IElementChangedListener _function = new IElementChangedListener() {
@Override
public void elementChanged(final ElementChangedEvent it) {
JavaCore.removeElementChangedListener(this);
boolean _get = changed.get();
boolean _not = (!_get);
if (_not) {
changed.set(true);
if ((JavaEditorExtension.VERBOSE).booleanValue()) {
InputOutput.<ElementChangedEvent>println(it);
}
}
}
}
};
JavaCore.addElementChangedListener(_function, eventMask);
producer.apply();
while ((!changed.get())) {
Display _current = Display.getCurrent();
boolean _tripleNotEquals = (_current != null);
if (_tripleNotEquals) {
while (Display.getDefault().readAndDispatch()) {
};
JavaCore.addElementChangedListener(_function, eventMask);
producer.apply();
int retries = 30;
while (((!changed.get()) && (retries-- > 0))) {
{
Display _current = Display.getCurrent();
boolean _tripleNotEquals = (_current != null);
if (_tripleNotEquals) {
while (Display.getDefault().readAndDispatch()) {
}
}
boolean _get = changed.get();
boolean _not = (!_get);
if (_not) {
if ((JavaEditorExtension.VERBOSE).booleanValue()) {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("sleeping, left retries: ");
_builder_1.append(retries);
InputOutput.<String>println(_builder_1.toString());
}
Thread.sleep(100);
}
}
}
boolean _get = changed.get();
boolean _not = (!_get);
if (_not) {
throw new AssertionError("No event has been received");
}
String _xifexpression = null;
if ((JavaEditorExtension.VERBOSE).booleanValue()) {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("end waiting for an element changed event: ");
_builder_1.append(eventMask);
_xifexpression = InputOutput.<String>println(_builder_1.toString());
}
_xblockexpression = _xifexpression;
}
String _xifexpression = null;
if ((JavaEditorExtension.VERBOSE).booleanValue()) {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("end waiting for an element changed event: ");
_builder_1.append(eventMask);
_xifexpression = InputOutput.<String>println(_builder_1.toString());
}
_xblockexpression = _xifexpression;
return _xblockexpression;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
return _xblockexpression;
}

public ITextEditor openJavaEditor(final String fileName) {
Expand Down

0 comments on commit 7727972

Please sign in to comment.