diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IReadAccess.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IReadAccess.java index 4288cc73e..3089f2437 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IReadAccess.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IReadAccess.java @@ -50,7 +50,24 @@ public interface IReadAccess { return work.exec(state); }); } - + + /** + * Tries to get a read-only copy of the State and execute {@code work} on it. + * + * @param work Work to execute on the State + * + * @return The result of executing {@code work}, or + * null if the State is null + * @since 2.15 + */ + default Result tryReadOnly(IUnitOfWork work) { + return readOnly((state) -> { + if (state == null) return null; + + return work.exec(state); + }); + } + /** * Tries to get a read-only copy of the State and execute {@code work} on it. * @@ -116,7 +133,27 @@ public interface IReadAccess { return work.exec(state); }); } - + + /** + * Tries to get a read-only copy of the State and execute {@code work} on it. + * Cancels all cancelable readers before executing the {@link IUnitOfWork}. + * For interactive jobs that need fastest possible execution. + * + * @param work Work to execute on the State + * + * @return The result of executing {@code work}, or + * null if the State is null + * @since 2.15 + * @see CancelableUnitOfWork + */ + default Result tryPriorityReadOnly(IUnitOfWork work) { + return priorityReadOnly((state) -> { + if (state == null) return null; + + return work.exec(state); + }); + } + /** * Tries to get a read-only copy of the State and execute {@code work} on it. * Cancels all cancelable readers before executing the {@link IUnitOfWork}. diff --git a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IWriteAccess.java b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IWriteAccess.java index dca57df5c..b51209a73 100644 --- a/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IWriteAccess.java +++ b/org.eclipse.xtext.util/src/org/eclipse/xtext/util/concurrent/IWriteAccess.java @@ -49,7 +49,24 @@ public interface IWriteAccess { return work.exec(state); }); } - + + /** + * Tries to modify the State by executing {@code work} on it. + * + * @param work Work that modifies the State + * + * @return The result of executing {@code work}, or + * null if the State is null + * @since 2.15 + */ + default Result tryModify(IUnitOfWork work) { + return modify((state) -> { + if (state == null) return null; + + return work.exec(state); + }); + } + /** * Tries to modify the State by executing {@code work} on it. *