当前位置: 首页>>代码示例>>Java>>正文


Java IUnitOfWork类代码示例

本文整理汇总了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;
        }
      });
    }
  });
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:25,代码来源:FormatQuickfixProvider.java

示例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);
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:28,代码来源:N4JSEditorResourceAccess.java

示例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);
		}
	});
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:N4ModificationWrapper.java

示例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);
		}
	});
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:31,代码来源:N4JSLinker.java

示例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);
        }

    });
}
 
开发者ID:mduft,项目名称:lcdsl,代码行数:17,代码来源:AbstractLaunchConfigGeneratorHandler.java

示例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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:27,代码来源:CachingBatchTypeResolver.java

示例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);
				}
			}
		});
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:ReferenceFinder.java

示例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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:ReferenceFinder.java

示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:LazyLinker.java

示例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);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:22,代码来源:AllContentsPerformanceTest.java

示例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;
				}
			});
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:ReadWriteAccessTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:25,代码来源:DefaultCallHierarchyBuilder.java

示例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;
        }
      });
    }
  });
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:25,代码来源:FormatQuickfixProvider.java

示例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();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:EObjectContentProvider.java

示例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;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:38,代码来源:EObjectContentProviderTest.java


注:本文中的org.eclipse.xtext.util.concurrent.IUnitOfWork类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。