Java Code Examples for org.eclipse.xtext.resource.IResourceDescriptions#getResourceDescription()

The following examples show how to use org.eclipse.xtext.resource.IResourceDescriptions#getResourceDescription() . 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: ReferenceFinder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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);
				}
			}
		});
	}
}
 
Example 2
Source File: EditorContentExtractor.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private Optional<TModule> loadTModuleFromURI(final URI uri) {
	if (null == uri) {
		return absent();
	}

	final URI trimmedUri = uri.hasFragment() ? uri.trimFragment() : uri;
	final IN4JSProject project = core.findProject(trimmedUri).orNull();
	if (project == null) {
		return absent();
	}
	final ResourceSet resSet = core.createResourceSet(Optional.of(project));
	final IResourceDescriptions index = core.getXtextIndex(resSet);
	final IResourceDescription resDesc = index.getResourceDescription(trimmedUri);

	if (null == resDesc) {
		return absent();
	}

	final TModule module = core.loadModuleFromIndex(resSet, resDesc, false);
	if (null == module || null == module.eResource() || null == module.eResource().getResourceSet()) {
		return absent();
	}
	return Optional.of(module);
}
 
Example 3
Source File: JdtTypesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.8
 */
protected Set<String> getDirtyTypeNames(){
	Iterable<IEObjectDescription> dirtyTypes = dirtyStateManager.getExportedObjectsByType(TypesPackage.Literals.JVM_TYPE);
	final Set<String> dirtyNames = new HashSet<String>();
	for(IEObjectDescription description: dirtyTypes) {
		dirtyNames.add(description.getQualifiedName().toString());
	}
	for(URI dirtyURI : ((IDirtyStateManagerExtension) dirtyStateManager).getDirtyResourceURIs()){
		IResourceDescriptions index = resourceDescriptionsProvider.createPersistedResourceDescriptions();
		IResourceDescription indexedResourceDescription = index.getResourceDescription(dirtyURI);
		if(indexedResourceDescription != null)
			for(IEObjectDescription desc : indexedResourceDescription.getExportedObjectsByType(TypesPackage.Literals.JVM_TYPE)){
				dirtyNames.add(desc.getQualifiedName().toString());
			}
	}
	return dirtyNames;
}
 
Example 4
Source File: BuilderUtil.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/***/
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;
}
 
Example 5
Source File: TestDiscoveryHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private Map<URI, TModule> loadModules(final Iterable<URI> moduleUris,
		Function<? super URI, ? extends ResourceSet> resourceSetAccess) {

	final Map<URI, TModule> uri2Modules = newHashMap();
	for (final URI moduleUri : moduleUris) {
		ResourceSet resSet = resourceSetAccess.apply(moduleUri);
		IResourceDescriptions index = n4jsCore.getXtextIndex(resSet);
		final IResourceDescription resDesc = index.getResourceDescription(moduleUri);
		uri2Modules.put(moduleUri, n4jsCore.loadModuleFromIndex(resSet, resDesc, false));
	}
	return uri2Modules;
}
 
Example 6
Source File: ExternalIndexSynchronizer.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return true iff the given project (i.e. its package.json) is contained in the index */
public boolean isInIndex(FileURI projectLocation) {
	if (projectLocation == null) {
		return false;
	}
	final ResourceSet resourceSet = core.createResourceSet(Optional.absent());
	final IResourceDescriptions index = core.getXtextIndex(resourceSet);
	IResourceDescription resourceDescription = index.getResourceDescription(projectLocation.toURI());
	return resourceDescription != null;
}
 
Example 7
Source File: AbstractLiveContainerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source File: ProjectCompareHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: ProjectCompareHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private TModule findImplementation(TModule moduleApi, IN4JSProject projectImpl,
		ResourceSet resourceSet, IResourceDescriptions index) {
	final String fqnStr = moduleApi.getQualifiedName();
	final URI uri = artifactHelper.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;
}
 
Example 10
Source File: AbstractScopeResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertExportedObject(Resource resource, String name) {
	IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource);
	IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.getURI());
	assertNotNull(resourceDescription);
	QualifiedName qname = QualifiedName.create(name);
	assertFalse(isEmpty(resourceDescription.getExportedObjects(EcorePackage.Literals.EOBJECT, qname, false)));
}
 
Example 11
Source File: AbstractScopeResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertLiveModelScopeLocal(boolean enabled) throws IOException {
	final URI resourceURI = URI.createPlatformResourceURI("test/assertLiveModelScopeLocal." + fileExt.getPrimaryFileExtension(), true);
	Resource resource = resourceSet.createResource(resourceURI);
	resource.load(new StringInputStream("stuff foo"), null);
	Stuff stuffFoo = ((File) resource.getContents().get(0)).getStuff().get(0);
	if (enabled) {
		assertExportedObject(resource, "foo");
		stuffFoo.setName("bar");
		assertExportedObject(resource, "bar");
	} else {
		IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource);
		IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.getURI());
		assertNull(resourceDescription);
	}
}
 
Example 12
Source File: BuilderUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: ValidationJobScheduler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void doScheduleInitialValidation(XtextDocument document) {
	URI uri = document.getResourceURI();
	if (uri == null)
		return;
	IResourceDescription documentDescription = resourceDescriptions.getResourceDescription(uri);
	if (documentDescription == null) {
		// resource was just created - build is likely to be running in background
		return;
	}
	if (dirtyStateManager instanceof IDirtyStateManagerExtension && builderStateProvider != null) {
		IResourceDescriptions persistedDescriptions = builderStateProvider.get();
		List<URI> dirtyResourceURIs = ((IDirtyStateManagerExtension) dirtyStateManager).getDirtyResourceURIs();
		for(URI dirtyResourceURI: dirtyResourceURIs) {
			IResourceDescription dirtyDescription = dirtyStateManager.getDirtyResourceDescription(dirtyResourceURI);
			if (dirtyDescription != null) {
				IResourceDescription persistedDescription = persistedDescriptions.getResourceDescription(dirtyResourceURI);
				// Shortcut to make sure we don't waste time with more involving haveEObjectDescriptionChanged computation
				ChangedResourceDescriptionDelta delta = new ChangedResourceDescriptionDelta(persistedDescription, dirtyDescription);
				if(resourceDescriptionManager.isAffected(delta, documentDescription)) {
					document.checkAndUpdateAnnotations();
					return;
				}
			}
		}
	} else {
		Set<URI> outgoingReferences = descriptionUtils.collectOutgoingReferences(documentDescription);
		for(URI outgoing: outgoingReferences) {
			if (isDirty(outgoing)) {
				document.checkAndUpdateAnnotations();
				return;
			}
		}
	}
}
 
Example 14
Source File: PortableURIs.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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(EObject obj) {
	IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(obj.eResource());
	IResourceDescription desc = descriptions.getResourceDescription(obj.eResource().getURI());
	if (desc == null) {
		return null;
	}
	return Streams.stream(desc.getExportedObjects()).filter(description -> {
		EObject possibleContainer = EcoreUtil.resolve(description.getEObjectOrProxy(), obj.eResource());
		return EcoreUtil.isAncestor(obj, possibleContainer);
	}).map(containerDesc -> {
		PortableFragmentDescription fragmentDescription = createPortableFragmentDescription(containerDesc, obj);
		return toFragmentString(fragmentDescription);
	}).findFirst().orElse(null);
}
 
Example 15
Source File: WorkingCopyOwnerProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public WorkingCopyOwner getWorkingCopyOwner(final IJavaProject javaProject, final ResourceSet resourceSet) {
	return new WorkingCopyOwner() {
		@Override
		public String findSource(String typeName, String packageName) {
			if (packageName.startsWith("java"))
				return super.findSource(typeName, packageName);
			QualifiedName qn = toQualifiedName(packageName, typeName);
			final IResourceDescriptions descriptions = descriptionsProvider.getResourceDescriptions(resourceSet);
			Iterator<IEObjectDescription> exportedObjects = descriptions.getExportedObjects(TypesPackage.Literals.JVM_DECLARED_TYPE, qn, false).iterator();
			while (exportedObjects.hasNext()) {
				IEObjectDescription candidate = exportedObjects.next();
				URI uri = candidate.getEObjectURI();
				if (uri.isPlatformResource() && URI.decode(uri.segment(1)).equals(javaProject.getElementName())) {
					IResourceDescription resourceDescription = descriptions.getResourceDescription(uri.trimFragment());
					return getSource(typeName, packageName, candidate, resourceSet, resourceDescription);
				}
			}
			return super.findSource(typeName, packageName);
		}
		
		
		/**
		 * not implemented because we don't have a proper index for Java package names and the very rare cases in which this would
		 * cause trouble are not worth the general degrade in performance.
		 */
		@Override public boolean isPackage(String[] pkg) {
			return super.isPackage(pkg);
		}
	};
}
 
Example 16
Source File: ImportUriGlobalScopeProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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);
}
 
Example 17
Source File: ClusteringBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Put all resources that depend on some changes onto the queue of resources to be processed.
 * Updates notInDelta by removing all URIs put into the queue.
 *
 * @param allRemainingURIs
 *            URIs that were not considered by prior operations.
 * @param oldState
 *            State before the build
 * @param newState
 *            The current state
 * @param changedDeltas
 *            the deltas that have changed {@link IEObjectDescription}s
 * @param allDeltas 
 *            All deltas 
 * @param buildData
 *            the underlying data for this build run.
 * @param monitor
 *            The progress monitor used for user feedback
 */
protected void queueAffectedResources(
        Set<URI> allRemainingURIs,
        IResourceDescriptions oldState,
        CurrentDescriptions newState,
        Collection<Delta> changedDeltas,
        Collection<Delta> allDeltas,
        BuildData buildData,
        final IProgressMonitor monitor) {
    if (allDeltas.isEmpty()) {
        return;
    }
    final SubMonitor progress = SubMonitor.convert(monitor, allRemainingURIs.size() + 1);
    Iterator<URI> iter = allRemainingURIs.iterator();
    while (iter.hasNext()) {
        if (progress.isCanceled()) {
            throw new OperationCanceledException();
        }
        final URI candidateURI = iter.next();
        final IResourceDescription candidateDescription = oldState.getResourceDescription(candidateURI);
        final IResourceDescription.Manager manager = getResourceDescriptionManager(candidateURI);
        if (candidateDescription == null || manager == null) {
            // If there is no description in the old state, there's no need to re-check this over and over.
            iter.remove();
        } else {
        	boolean affected;
        	if ((manager instanceof IResourceDescription.Manager.AllChangeAware)) {
        		affected = ((AllChangeAware) manager).isAffectedByAny(allDeltas, candidateDescription, newState);
        	} else {
        		if (changedDeltas.isEmpty()) {
        			affected = false;
        		} else {
        			affected = manager.isAffected(changedDeltas, candidateDescription, newState);
        		}
        	}
            if (affected) {
                buildData.queueURI(candidateURI);
                iter.remove();
            }
        }
        progress.split(1);
    }
}
 
Example 18
Source File: ClusteringBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create new resource descriptions for a set of resources given by their URIs.
 *
 * @param buildData
 *            The underlying data for the write operation.
 * @param oldState
 *            The old index
 * @param newState
 *            The new index
 * @param monitor
 *            The progress monitor used for user feedback
 */
protected void writeNewResourceDescriptions(
        BuildData buildData,
        IResourceDescriptions oldState,
        CurrentDescriptions newState,
        final IProgressMonitor monitor) {
    int index = 0;
    ResourceSet resourceSet = buildData.getResourceSet();
    Set<URI> toBeUpdated = buildData.getToBeUpdated();
    final SubMonitor subMonitor = SubMonitor.convert(monitor, "Write new resource descriptions", toBeUpdated.size() + 1); // TODO: NLS
    IProject currentProject = getBuiltProject(buildData);
    LoadOperation loadOperation = null;
    try {
    	compilerPhases.setIndexing(resourceSet, true);
        loadOperation = globalIndexResourceLoader.create(resourceSet, currentProject);
        loadOperation.load(toBeUpdated);

        while (loadOperation.hasNext()) {
            if (subMonitor.isCanceled()) {
                loadOperation.cancel();
                throw new OperationCanceledException();
            }

            if (!clusteringPolicy.continueProcessing(resourceSet, null, index)) {
                clearResourceSet(resourceSet);
            }

            URI uri = null;
            Resource resource = null;
            try {
                LoadResult loadResult = loadOperation.next();
                uri = loadResult.getUri();
                resource = addResource(loadResult.getResource(), resourceSet);
                subMonitor.subTask("Writing new resource description " + resource.getURI().lastSegment());
                if (LOGGER.isDebugEnabled()) {
                	LOGGER.debug("Writing new resource description " + uri);
                }

                final IResourceDescription.Manager manager = getResourceDescriptionManager(uri);
                if (manager != null) {
                    // We don't care here about links, we really just want the exported objects so that we can link in the
                    // next phase.
                    final IResourceDescription description = manager.getResourceDescription(resource);
                    final IResourceDescription copiedDescription = new CopiedResourceDescription(description);
                    // We also don't care what kind of Delta we get here; it's just a temporary transport vehicle. That interface
                    // could do with some clean-up, too, because all we actually want to do is register the new resource
                    // description, not the delta.
                    newState.register(new DefaultResourceDescriptionDelta(oldState.getResourceDescription(uri), copiedDescription));
                    buildData.queueURI(uri);
                }
            } catch (final RuntimeException ex) {
                if(ex instanceof LoadOperationException) {
                    uri = ((LoadOperationException) ex).getUri();
                }
                if (uri == null) {
                    LOGGER.error("Error loading resource", ex); //$NON-NLS-1$
                } else {
                    if (resourceSet.getURIConverter().exists(uri, Collections.emptyMap())) {
                        LOGGER.error("Error loading resource from: " + uri.toString(), ex); //$NON-NLS-1$
                    }
                    if (resource != null) {
                        resourceSet.getResources().remove(resource);
                    }
                    final IResourceDescription oldDescription = oldState.getResourceDescription(uri);
                    if (oldDescription != null) {
                        newState.register(new DefaultResourceDescriptionDelta(oldDescription, null));
                    }
                }
                // If we couldn't load it, there's no use trying again: do not add it to the queue
            }
            index++;
            subMonitor.split(1);
        }
    } finally {
    	compilerPhases.setIndexing(resourceSet, false);
        if(loadOperation != null) loadOperation.cancel();
    }
}
 
Example 19
Source File: N4ClusteringBuilderState.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Put all resources that depend on some changes onto the queue of resources to be processed. Updates notInDelta by
 * removing all URIs put into the queue.
 *
 * @param allRemainingURIs
 *            URIs that were not considered by prior operations.
 * @param oldState
 *            State before the build
 * @param newState
 *            The current state
 * @param changedDeltas
 *            the deltas that have changed {@link IEObjectDescription}s
 * @param allDeltas
 *            All deltas
 * @param buildData
 *            the underlying data for this build run.
 * @param monitor
 *            The progress monitor used for user feedback
 */
protected void queueAffectedResources(
		Set<URI> allRemainingURIs,
		IResourceDescriptions oldState,
		CurrentDescriptions newState,
		Collection<Delta> changedDeltas,
		Collection<Delta> allDeltas,
		BuildData buildData,
		final IProgressMonitor monitor) {
	if (allDeltas.isEmpty()) {
		return;
	}
	final SubMonitor progress = SubMonitor.convert(monitor, allRemainingURIs.size());
	Iterator<URI> iter = allRemainingURIs.iterator();
	while (iter.hasNext()) {
		if (progress.isCanceled()) {
			throw new OperationCanceledException();
		}
		final URI candidateURI = iter.next();
		final IResourceDescription candidateDescription = oldState.getResourceDescription(candidateURI);
		final IResourceDescription.Manager manager = getResourceDescriptionManager(candidateURI);
		if (candidateDescription == null || manager == null) {
			// If there is no description in the old state, there's no need to re-check this over and over.
			iter.remove();
		} else {
			boolean affected;
			if ((manager instanceof IResourceDescription.Manager.AllChangeAware)) {
				affected = ((AllChangeAware) manager).isAffectedByAny(allDeltas, candidateDescription, newState);
			} else {
				if (changedDeltas.isEmpty()) {
					affected = false;
				} else {
					affected = manager.isAffected(changedDeltas, candidateDescription, newState);
				}
			}
			if (affected) {
				buildData.queueURI(candidateURI);
				// since the candidate is affected by any of the currently changed resources, we disable
				// the module data of the candidate to ensure that no code will see it later on by accident
				// Related tests:
				// - IncrementalBuilderCornerCasesPluginTest#testMissingReloadBug()
				// - ReproduceInvalidIndexPluginTest
				if (!N4JSGlobals.PACKAGE_JSON.equals(candidateURI.lastSegment())) {
					ResourceDescriptionWithoutModuleUserData noModuleData = new ResourceDescriptionWithoutModuleUserData(
							candidateDescription);
					newState.register(manager.createDelta(candidateDescription, noModuleData));
					// also we ensure that we do run a subsequent build.
					buildData.requestRebuild();
				}
				iter.remove();
			}
		}
		progress.worked(1);
	}
}
 
Example 20
Source File: TestDiscoveryHelper.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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;
		}
	}
}