org.eclipse.jdt.core.IElementChangedListener Java Examples
The following examples show how to use
org.eclipse.jdt.core.IElementChangedListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TypeResourceUnloaderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Wait explicitly for an {@link ElementChangedEvent} that is propagated when the given Callable is executed. * May also be used to assert that no such event occurred. */ protected <T> T waitForElementChangedEvent(Callable<T> callMe, boolean expectEvent) throws Exception { class Listener implements IElementChangedListener { private volatile boolean eventSeen = false; @Override public void elementChanged(ElementChangedEvent event) { eventSeen = true; JavaCore.removeElementChangedListener(this); } } Listener listener = new Listener(); JavaCore.addElementChangedListener(listener); try { return callMe.call(); } finally { // usually a counter of 100 is way more than enough, but on the CI server we see a longer // delay, maybe the threading model on linux is slightly different. Anyway, the overall runtime // on dev boxes is not affected but the test is green on the server long before = System.currentTimeMillis(); int counter = expectEvent ? 350 : 150; while(!listener.eventSeen && counter > 0) { counter--; Thread.sleep(15); } long timeWaited = System.currentTimeMillis() - before; assertEquals("Waited "+timeWaited+"ms.", expectEvent, listener.eventSeen); } }
Example #2
Source File: JavaEditorExtension.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
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 ArrayList<Boolean> changed = CollectionLiterals.<Boolean>newArrayList(Boolean.valueOf(false)); final IElementChangedListener _function = new IElementChangedListener() { @Override public void elementChanged(final ElementChangedEvent it) { JavaCore.removeElementChangedListener(this); Boolean _head = IterableExtensions.<Boolean>head(changed); boolean _not = (!(_head).booleanValue()); if (_not) { changed.set(0, Boolean.valueOf(true)); if ((JavaEditorExtension.VERBOSE).booleanValue()) { InputOutput.<ElementChangedEvent>println(it); } } } }; JavaCore.addElementChangedListener(_function, eventMask); producer.apply(); while ((!(IterableExtensions.<Boolean>head(changed)).booleanValue())) { } 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; }