本文整理汇总了Java中org.eclipse.xtext.util.concurrent.IUnitOfWork类的典型用法代码示例。如果您正苦于以下问题:Java IUnitOfWork类的具体用法?Java IUnitOfWork怎么用?Java IUnitOfWork使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IUnitOfWork类属于org.eclipse.xtext.util.concurrent包,在下文中一共展示了IUnitOfWork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setOverride
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
/**
* Semantic quickfix setting the override flag for a rule.
*
* @param issue
* the issue
* @param acceptor
* the acceptor
*/
@Fix(FormatJavaValidator.OVERRIDE_MISSING_CODE)
public void setOverride(final Issue issue, final IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Set override", "Set override flag.", null, new IModification() {
@Override
public void apply(final IModificationContext context) throws BadLocationException {
context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(final XtextResource state) {
Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment());
rule.setOverride(true);
return null;
}
});
}
});
}
示例2: readOnly
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
/***
* This method modifies the super method to handle NullPointerException when state is null.
*/
@Override
public <R> R readOnly(final URI targetURI, final IUnitOfWork<R, ResourceSet> work) {
IXtextDocument document = openDocumentTracker.getOpenDocument(targetURI.trimFragment());
if (document != null) {
return document.readOnly(new IUnitOfWork<R, XtextResource>() {
@Override
public R exec(XtextResource state) throws Exception {
// For some reason, sometimes state can be null at this point,
// The resource set must be retrieved by other means in delegate.readOnly
if (state == null) {
return delegate.readOnly(targetURI, work);
}
ResourceSet localContext = state.getResourceSet();
if (localContext != null)
return work.exec(localContext);
return null;
}
});
} else
{
return delegate.readOnly(targetURI, work);
}
}
示例3: apply
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
@Override
public final void apply(IModificationContext context) throws Exception {
context.getXtextDocument().modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
final IMarker marker = issue instanceof N4JSIssue ? ((N4JSIssue) issue).getMarker() : null;
final EObject element = resource.getEObject(issue.getUriToProblem().fragment());
final Collection<? extends IChange> changes = modification.computeChanges(
context,
marker,
issue.getOffset(),
issue.getLength(),
element);
modification.computeFinalChanges();
changeManager.applyAll(changes);
}
});
}
示例4: doLinkModel
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
/**
* Clears the list of encoded URIs in {@link N4JSResource}, installs proxies for all cross references inside the
* parsed model. If validation is enabled finally the {@link ASTStructureValidator} is triggered, that checks the
* now linked AST structure.
*/
@Override
protected void doLinkModel(final EObject model, final IDiagnosticConsumer consumer) {
final LinkingDiagnosticProducer producer = new LinkingDiagnosticProducer(consumer);
getCache().execWithoutCacheClear((N4JSResource) model.eResource(), new IUnitOfWork.Void<N4JSResource>() {
@Override
public void process(N4JSResource resource) throws Exception {
// actual linking
resource.clearLazyProxyInformation();
clearReferences(model);
installProxies(resource, model, producer);
TreeIterator<EObject> iterator = model.eAllContents();
while (iterator.hasNext()) {
EObject eObject = iterator.next();
clearReferences(eObject);
installProxies(resource, eObject, producer);
}
// pre-processing of AST
preProcessor.process(resource.getScript(), resource);
// AST structure validation
if (!resource.isValidationDisabled())
getStructureValidator().validate(model, consumer);
}
});
}
示例5: getLaunchConfigFromEditor
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
protected LaunchConfig getLaunchConfigFromEditor(ExecutionEvent event) {
XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event);
if (activeXtextEditor == null) {
return null;
}
final ITextSelection selection = (ITextSelection) activeXtextEditor.getSelectionProvider().getSelection();
return activeXtextEditor.getDocument().priorityReadOnly(new IUnitOfWork<LaunchConfig, XtextResource>() {
@Override
public LaunchConfig exec(XtextResource xTextResource) throws Exception {
EObject lc = eObjectAtOffsetHelper.resolveContainedElementAt(xTextResource, selection.getOffset());
return findParentLaunchConfig(lc);
}
});
}
示例6: doResolveTypes
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
@Override
/* @NonNull */
protected IResolvedTypes doResolveTypes(final /* @Nullable */ EObject object, final /* @Nullable */ CancelIndicator monitor) {
// TODO: remove when we switch to an Xtend scope provider without artificial feature calls
EObject nonArtificialObject = object;
if(object.eResource() == null && object instanceof XAbstractFeatureCall) {
nonArtificialObject = ((XAbstractFeatureCall) object).getFeature();
}
// TODO
final Resource resource = nonArtificialObject.eResource();
final LazyResolvedTypes result = cache.get(CachingBatchTypeResolver.class, resource, new Provider<LazyResolvedTypes>() {
@Override
public LazyResolvedTypes get() {
final IReentrantTypeResolver resolver = delegate.getTypeResolver(object);
return new LazyResolvedTypes(resolver, resource);
}
});
cache.execWithoutCacheClear(resource, new IUnitOfWork.Void<Resource>() {
@Override
public void process(Resource state) throws Exception {
// trigger the actual resolution after the thing was cached
result.resolveTypes(monitor == null ? CancelIndicator.NullImpl : monitor);
}
});
return result;
}
示例7: doFindReferencesWith
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
protected void doFindReferencesWith(final IReferenceFinder referenceFinder, final TargetURIs targetURIs, final URI candidate,
IResourceAccess resourceAccess, IResourceDescriptions descriptions, final Acceptor acceptor,
final IProgressMonitor monitor) {
IResourceDescription resourceDescription = null;
if (!targetURIs.getTargetResourceURIs().contains(candidate) && (resourceDescription = descriptions.getResourceDescription(candidate)) != null) {
referenceFinder.findReferences(targetURIs, resourceDescription, resourceAccess, acceptor, monitor);
} else if (resourceAccess != null) {
resourceAccess.readOnly(candidate, new IUnitOfWork.Void<ResourceSet>() {
@Override
public void process(final ResourceSet state) throws Exception {
Resource resource = state.getResource(candidate, false);
if (resource != null) {
referenceFinder.findReferences(targetURIs, resource, acceptor, monitor);
}
}
});
}
}
示例8: findReferences
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
@Override
public void findReferences(final TargetURIs targetURIs, IResourceDescription resourceDescription,
IResourceAccess resourceAccess, final Acceptor acceptor, final IProgressMonitor monitor) {
final URI resourceURI = resourceDescription.getURI();
if (resourceAccess != null && targetURIs.containsResource(resourceURI)) {
IUnitOfWork.Void<ResourceSet> finder = new IUnitOfWork.Void<ResourceSet>() {
@Override
public void process(final ResourceSet state) throws Exception {
Resource resource = state.getResource(resourceURI, true);
findReferences(targetURIs, resource, acceptor, monitor);
}
};
resourceAccess.readOnly(resourceURI, finder);
} else {
findReferencesInDescription(targetURIs, resourceDescription, resourceAccess, acceptor, monitor);
}
}
示例9: doLinkModel
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
@Override
protected void doLinkModel(final EObject model, IDiagnosticConsumer consumer) {
final Multimap<EStructuralFeature.Setting, INode> settingsToLink = ArrayListMultimap.create();
final LinkingDiagnosticProducer producer = new LinkingDiagnosticProducer(consumer);
cache.execWithoutCacheClear(model.eResource(), new IUnitOfWork.Void<Resource>() {
@Override
public void process(Resource state) throws Exception {
TreeIterator<EObject> iterator = getAllLinkableContents(model);
boolean clearAllReferencesRequired = isClearAllReferencesRequired(state);
while (iterator.hasNext()) {
EObject eObject = iterator.next();
if (clearAllReferencesRequired) {
clearReferences(eObject);
}
installProxies(eObject, producer, settingsToLink);
}
}
});
installQueuedLinks(settingsToLink);
}
示例10: doTestUoWImpl
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
private void doTestUoWImpl(EObject object, IUnitOfWork<Boolean, EObject> uow) throws Exception {
if (object == null)
return;
if (!uow.exec(object).booleanValue()) {
EClass clazz = object.eClass();
for(EReference reference: clazz.getEAllContainments()) {
// object.eIsSet(..) decreased performance - TODO: investigate the reason
// TODO: handle feature maps
// TODO: What's FeatureListIterator#useIsSet about?
if (reference.isMany()) {
@SuppressWarnings("unchecked")
List<EObject> values = (List<EObject>) object.eGet(reference);
for(int i = 0; i<values.size(); i++) {
doTestUoWImpl(values.get(i), uow);
}
} else {
doTestUoWImpl((EObject) object.eGet(reference), uow);
}
}
}
}
示例11: reader
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
private Runnable reader(final AbstractReadWriteAcces<Foo> access) {
return new Runnable() {
@Override
public void run() {
access.readOnly(new IUnitOfWork<Object, Foo>() {
// iterate 20 times { checking the state remains, wait 50 ms}
@Override
public Object exec(Foo state) throws Exception {
String val = state.val;
for (int i = 0; i < 10; i++) {
assertEquals(val, state.val);
Thread.sleep(50);
}
return null;
}
});
}
};
}
示例12: findTargetDeclarations
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
protected void findTargetDeclarations(final URI sourceDeclarationURI, final IProgressMonitor monitor, final Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) {
final IUnitOfWork<Object, EObject> _function = (EObject sourceDeclaration) -> {
Object _xblockexpression = null;
{
IResourceServiceProvider.Registry _resourceServiceProviderRegistry = this.getResourceServiceProviderRegistry();
final IAcceptor<IReferenceDescription> _function_1 = (IReferenceDescription reference) -> {
boolean _filterReference = this.filterReference(reference);
if (_filterReference) {
IEObjectDescription _findTargetDeclaration = null;
if (reference!=null) {
_findTargetDeclaration=this.findTargetDeclaration(reference);
}
final IEObjectDescription targetDeclaration = _findTargetDeclaration;
acceptor.apply(targetDeclaration, reference);
}
};
ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(_resourceServiceProviderRegistry, _function_1);
this.getReferenceFinder().findAllReferences(sourceDeclaration, _referenceAcceptor, monitor);
_xblockexpression = null;
}
return _xblockexpression;
};
this.<Object>readOnly(sourceDeclarationURI, _function);
}
示例13: removeOverride
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
/**
* Semantic quickfix removing the override flag for a rule.
*
* @param issue
* the issue
* @param acceptor
* the acceptor
*/
@Fix(FormatJavaValidator.OVERRIDE_ILLEGAL_CODE)
public void removeOverride(final Issue issue, final IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Remove override", "Remove override.", null, new IModification() {
@Override
public void apply(final IModificationContext context) throws BadLocationException {
context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(final XtextResource state) {
Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment());
rule.setOverride(false);
return null;
}
});
}
});
}
示例14: valuesForAttributes
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
/**
* Retrieve the object's values for the given EAttributes.
*
* @param attributes
* the EAttributes
* @return List<Pair<EAttribute, Object>> the attribute+values - possibly containing null entries
*/
private List<AttributeValuePair> valuesForAttributes(final EList<EAttribute> attributes) {
final URI elementUri = xtextElementSelectionListener.getSelectedElementUri();
XtextEditor editor = xtextElementSelectionListener.getEditor();
if (editor != null && elementUri != null) {
return editor.getDocument().readOnly(new IUnitOfWork<List<AttributeValuePair>, XtextResource>() {
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public List<AttributeValuePair> exec(final XtextResource state) throws Exception {
final EObject eObject = state.getEObject(elementUri.fragment());
List<AttributeValuePair> pairs = Lists.transform(attributes, new Function<EAttribute, AttributeValuePair>() {
public AttributeValuePair apply(final EAttribute from) {
return new AttributeValuePair(from, eObject.eGet(from));
}
});
return pairs;
}
});
}
return newArrayList();
}
示例15: mockSelectedElement
import org.eclipse.xtext.util.concurrent.IUnitOfWork; //导入依赖的package包/类
/**
* Mocks XtextEditor and XtextElementSelectionListener to return an element selection that has:
* - given EAttribute with a specific value (AttributeValuePair)
* - given EStructuralFeature
* - given EOperation.
*
* @param attributeValuePair
* EAttribute with a specific value
* @param feature
* the EStructuralFeature
* @param operation
* the EOperation
* @return the EClass of the "selected" element
*/
@SuppressWarnings("unchecked")
private EClass mockSelectedElement(final AttributeValuePair attributeValuePair, final EStructuralFeature feature, final EOperation operation) {
EClass mockSelectionEClass = mock(EClass.class);
when(mockSelectionListener.getSelectedElementType()).thenReturn(mockSelectionEClass);
// Mockups for returning AttributeValuePair
URI elementUri = URI.createURI("");
when(mockSelectionListener.getSelectedElementUri()).thenReturn(elementUri);
XtextEditor mockEditor = mock(XtextEditor.class);
when(mockSelectionListener.getEditor()).thenReturn(mockEditor);
IXtextDocument mockDocument = mock(IXtextDocument.class);
when(mockEditor.getDocument()).thenReturn(mockDocument);
when(mockDocument.<ArrayList<AttributeValuePair>> readOnly(any(IUnitOfWork.class))).thenReturn(newArrayList(attributeValuePair));
// Mockups for returning EOperation
BasicEList<EOperation> mockEOperationsList = new BasicEList<EOperation>();
mockEOperationsList.add(operation);
when(mockSelectionEClass.getEAllOperations()).thenReturn(mockEOperationsList);
// Mockups for returning EStructuralFeature
BasicEList<EStructuralFeature> mockEStructuralFeatureList = new BasicEList<EStructuralFeature>();
mockEStructuralFeatureList.add(feature);
mockEStructuralFeatureList.add(attributeValuePair.getAttribute());
when(mockSelectionEClass.getEAllStructuralFeatures()).thenReturn(mockEStructuralFeatureList);
return mockSelectionEClass;
}