本文整理汇总了Java中org.eclipse.xtext.resource.IResourceDescriptions.getResourceDescription方法的典型用法代码示例。如果您正苦于以下问题:Java IResourceDescriptions.getResourceDescription方法的具体用法?Java IResourceDescriptions.getResourceDescription怎么用?Java IResourceDescriptions.getResourceDescription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.resource.IResourceDescriptions
的用法示例。
在下文中一共展示了IResourceDescriptions.getResourceDescription方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFindReferencesWith
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的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);
}
}
});
}
}
示例2: getPortableURIFragment
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
/**
* @return a portable URI fragment, or <code>null</code> if the give EObject isn't itself or is not contained in an exported EObjectDescription
*/
protected String getPortableURIFragment(final EObject obj) {
final IResourceDescriptions descriptions = this.resourceDescriptionsProvider.getResourceDescriptions(obj.eResource());
final IResourceDescription desc = descriptions.getResourceDescription(obj.eResource().getURI());
if ((desc == null)) {
return null;
}
final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
boolean _xblockexpression = false;
{
final EObject possibleContainer = EcoreUtil.resolve(it.getEObjectOrProxy(), obj.eResource());
_xblockexpression = (Objects.equal(obj, possibleContainer) || EcoreUtil.isAncestor(obj, possibleContainer));
}
return Boolean.valueOf(_xblockexpression);
};
final IEObjectDescription containerDesc = IterableExtensions.<IEObjectDescription>findFirst(desc.getExportedObjects(), _function);
if ((containerDesc != null)) {
final PortableURIs.PortableFragmentDescription fragmentDescription = this.createPortableFragmentDescription(containerDesc, obj);
return this.toFragmentString(fragmentDescription);
}
return null;
}
示例3: indexContainsElement
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
/***/
public static boolean indexContainsElement(final String fileUri, final String eObjectName) {
IResourceDescriptions descriptions = getBuilderState();
URI uri = URI.createURI("platform:/resource" + fileUri);
IResourceDescription description = descriptions.getResourceDescription(uri);
if (description != null) {
return description
.getExportedObjects(EcorePackage.Literals.EOBJECT, QualifiedName.create(eObjectName), false)
.iterator().hasNext();
}
return false;
}
示例4: loadModules
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
private Map<URI, TModule> loadModules(final Iterable<URI> moduleUris, final IResourceDescriptions index,
final ResourceSet resSet) {
final Map<URI, TModule> uri2Modules = newHashMap();
for (final URI moduleUri : moduleUris) {
final IResourceDescription resDesc = index.getResourceDescription(moduleUri);
uri2Modules.put(moduleUri, n4jsCore.loadModuleFromIndex(resSet, resDesc, false));
}
return uri2Modules;
}
示例5: createEntries
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
private ProjectComparisonEntry createEntries(
ProjectComparison root,
IN4JSProject api, IN4JSProject[] impls,
ResourceSet resourceSet, IResourceDescriptions index) {
final ProjectComparisonEntry entry = new ProjectComparisonEntry(root, api, impls);
for (IN4JSSourceContainer currSrcConti : api.getSourceContainers()) {
for (URI uri : currSrcConti) {
final String uriStr = uri.toString();
if (uriStr.endsWith("." + N4JSGlobals.N4JS_FILE_EXTENSION)
|| uriStr.endsWith("." + N4JSGlobals.N4JSD_FILE_EXTENSION)) {
final IResourceDescription resDesc = index.getResourceDescription(uri);
final TModule moduleApi = getModuleFrom(resourceSet, resDesc);
if (moduleApi != null) {
final TModule[] moduleImpls = new TModule[impls.length];
for (int idx = 0; idx < impls.length; idx++) {
final IN4JSProject projectImpl = impls[idx];
if (projectImpl != null)
moduleImpls[idx] = findImplementation(moduleApi, projectImpl, resourceSet, index);
else
moduleImpls[idx] = null;
}
createEntries(entry, -1, moduleApi, moduleImpls, false);
}
}
}
}
return entry;
}
示例6: findImplementation
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
private TModule findImplementation(TModule moduleApi, IN4JSProject projectImpl,
ResourceSet resourceSet, IResourceDescriptions index) {
final String fqnStr = moduleApi.getQualifiedName();
final URI uri = projectUtils.findArtifact(projectImpl, fqnStr, Optional.of(N4JSGlobals.N4JS_FILE_EXTENSION));
if (uri == null)
return null;
final IResourceDescription resDesc = index.getResourceDescription(uri);
if (resDesc == null)
return null;
final TModule moduleImpl = getModuleFrom(resourceSet, resDesc);
return moduleImpl;
}
示例7: testNonNormalizedURIs
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
@Test
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
public void testNonNormalizedURIs() throws Exception {
ResourceSet resourceSet = new XtextResourceSet();
parser.parse("B", URI.createURI("a." + parser.fileExtension), resourceSet);
parser.parse("B", URI.createURI("b." + parser.fileExtension), resourceSet);
IResourceDescriptions index = descriptionsProvider.getResourceDescriptions(resourceSet);
IResourceDescription rd = index.getResourceDescription(URI.createURI("a." + parser.fileExtension));
List<IContainer> containers = containerManager.getVisibleContainers(rd, index);
List<IEObjectDescription> objects = Lists.newArrayList();
EClass type = (EClass) grammarAccess.getGrammar().getRules().get(0).getType().getClassifier();
for (IContainer container : containers)
Iterables.addAll(objects, container.getExportedObjects(type, QualifiedName.create("B"), false));
assertEquals(2, objects.size());
}
示例8: isTestable
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
/**
* Checks if the resource at the given location can be executed as a test. The location may point to an N4JS project
* or a folder or file within an N4JS project.
* <p>
* This method is intended as a very first check to decide if the user should be given the option to launch a test
* or not; for example, to enable or disable a "Run as test" context menu item). This method does not check all
* details because many checks are better handled at later stages when meaningful error messages can be provided to
* the user.
*/
public boolean isTestable(final URI location) {
if (null == location) {
return false;
}
if (isProject(location)) {
// location points an N4JS project
// --> must contain at least 1 source container of type "test"
// (do *not* check if the folder contains test classes (for performance reasons and
// to show better error messages; same behavior as in JUnit support in Eclipse))
final IN4JSProject p = n4jsCore.create(location);
return p.getSourceContainers().stream().anyMatch(IN4JSSourceContainer::isTest);
} else {
// otherwise:
// (1) if the location URI contains the special test method fragment
// then extract the fragment and check the location for the module.
if (location.hasFragment()) {
return isTestable(location.trimFragment());
}
// (2) location must lie in a source container of type "test"
final IN4JSSourceContainer c = n4jsCore.findN4JSSourceContainer(location).orNull();
if (c == null || !c.isTest())
return false;
// (3) if the location points to an n4js-file, it must contain at least one test class
final ResourceSet resourceSet = n4jsCore.createResourceSet(Optional.of(c.getProject()));
final IResourceDescriptions index = n4jsCore.getXtextIndex(resourceSet);
final IResourceDescription rdesc = index.getResourceDescription(location);
if (rdesc != null) {
return stream(rdesc.getExportedObjectsByType(T_CLASS))
.anyMatch(desc -> hasTestMethods(resourceSet, desc));
} else {
// we did not find the nestedLocation in the index but test (1) above passed, so
// we assume that nestedLocation points to a folder within a test source container
// (do *not* check if the folder contains test classes (for performance reasons and
// to show better error messages; same behavior as in JUnit support in Eclipse))
return true;
}
}
}
示例9: doResolveProxy
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
/**
* Invoked from {@link ProxyResolvingEObjectImpl#eResolveProxy(InternalEObject)} whenever an EMF proxy inside an
* N4JSResource is being resolved. The receiving resource is the resource containing the proxy, not necessarily the
* resource the proxy points to.
*
* @param proxy
* the proxy to resolve.
* @param objectContext
* the {@code EObject} contained in this resource that holds the given proxy.
*/
@Override
public EObject doResolveProxy(InternalEObject proxy, EObject objectContext) {
// step 1: trigger post processing of the resource containing 'proxy' iff it is the first proxy being resolved
// (if another proxy has been resolved before, post processing will already be running/completed, and in that
// case the next line will simply do nothing, cf. #performPostProcessing())
this.performPostProcessing();
// step 2: now turn to resolving the proxy at hand
final URI targetUri = proxy.eProxyURI();
final boolean isLazyLinkingProxy = getEncoder().isCrossLinkFragment(this, targetUri.fragment());
if (!isLazyLinkingProxy) {
// we have an ordinary EMF proxy (not one of Xtext's lazy linking proxies) ...
final ResourceSet resSet = getResourceSet();
final URI targetResourceUri = targetUri.trimFragment();
final String targetFileExt = targetResourceUri.fileExtension();
if (N4JSGlobals.N4JS_FILE_EXTENSION.equals(targetFileExt)
|| N4JSGlobals.N4JSD_FILE_EXTENSION.equals(targetFileExt)
|| N4JSGlobals.N4JSX_FILE_EXTENSION.equals(targetFileExt)) {
// proxy is pointing into an .n4js or .n4jsd file ...
// check if we can work with the TModule from the index or if it is mandatory to load from source
final boolean canLoadFromDescription = !targetUri.fragment().startsWith("/0")
&& canLoadFromDescriptionHelper.canLoadFromDescription(targetResourceUri, getResourceSet());
if (canLoadFromDescription) {
final String targetFragment = targetUri.fragment();
final Resource targetResource = resSet.getResource(targetResourceUri, false);
// special handling #1:
// if targetResource is not loaded yet, try to load it from index first
if (targetResource == null) {
if (targetFragment != null
&& (targetFragment.equals("/1") || targetFragment.startsWith("/1/"))) {
// uri points to a TModule element in a resource not yet contained in our resource set
// --> try to load target resource from index
final IResourceDescriptions index = n4jsCore.getXtextIndex(resSet);
final IResourceDescription resDesc = index.getResourceDescription(targetResourceUri);
if (resDesc != null) {
// next line will add the new resource to resSet.resources
n4jsCore.loadModuleFromIndex(resSet, resDesc, false);
}
}
}
}
// standard behavior:
// obtain target EObject from targetResource in the usual way
// (might load targetResource from disk if it wasn't loaded from index above)
final EObject targetObject = resSet.getEObject(targetUri, true);
// special handling #2:
// if targetResource exists, make sure it is post-processed *iff* this resource is post-processed
// (only relevant in case targetResource wasn't loaded from index, because after loading from index it
// is always marked as fullyPostProcessed==true)
if (targetObject != null && (this.isPostProcessing() || this.isFullyProcessed())) {
final Resource targetResource2 = targetObject.eResource();
if (targetResource2 instanceof N4JSResource) {
// no harm done, if already running/completed
((N4JSResource) targetResource2).performPostProcessing();
}
}
// return resolved target object
return targetObject != null ? targetObject : proxy; // important: return proxy itself if unresolvable!
}
}
// we will get here if
// a) we have an Xtext lazy linking proxy or
// b) targetUri points to an n4ts resource or some other, non-N4JS resource
// --> above special handling not required, so just apply EMF's default resolution behavior
return EcoreUtil.resolve(proxy, this);
}
示例10: createLazyResourceScope
import org.eclipse.xtext.resource.IResourceDescriptions; //导入方法依赖的package包/类
protected IScope createLazyResourceScope(IScope parent, final URI uri, final IResourceDescriptions descriptions,
EClass type, final Predicate<IEObjectDescription> filter, boolean ignoreCase) {
IResourceDescription description = descriptions.getResourceDescription(uri);
return SelectableBasedScope.createScope(parent, description, filter, type, ignoreCase);
}