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

The following examples show how to use org.eclipse.xtext.resource.IResourceDescriptions#getAllResourceDescriptions() . 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: ExcludePckJson_PluginUITest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks that only one package.json is contained in the index. This one package.json is the one from the project
 * root folder.
 */
@Test
public void checkIndex() throws CoreException {
	final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
	assertTrue("Test project is not accessible.", project.isAccessible());

	IResourcesSetupUtil.fullBuild();
	waitForAutoBuild();

	ResourceSet resourceSet = core.createResourceSet(Optional.absent());
	IResourceDescriptions index = core.getXtextIndex(resourceSet);

	for (IResourceDescription res : index.getAllResourceDescriptions()) {
		String resLocation = res.getURI().toString();

		if (resLocation.endsWith(".json")) {
			System.out.println("Indexing found: " + resLocation);
		}
	}
}
 
Example 2
Source File: ExternalLibraryBuilder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Deletes all entries in the Xtext index that start with one of the given project URIs will be cleaned from the
 * index.
 *
 * @param toBeWiped
 *            URIs of project roots
 */
public void wipeURIsFromIndex(IProgressMonitor monitor, Collection<FileURI> toBeWiped) {
	Set<String> toBeWipedStrings = new HashSet<>();
	for (FileURI toWipe : toBeWiped) {
		toBeWipedStrings.add(toWipe.toString());
		N4JSProjectName projectName = toWipe.getProjectName();
		validatorExtension.clearAllMarkersOfExternalProject(projectName);
	}

	ResourceSet resourceSet = core.createResourceSet(Optional.absent());
	IResourceDescriptions index = core.getXtextIndex(resourceSet);

	Set<URI> toBeRemoved = new HashSet<>();
	for (IResourceDescription res : index.getAllResourceDescriptions()) {
		URI resUri = res.getURI();
		String resUriString = resUri.toString();
		for (String toWipeProject : toBeWipedStrings) {
			if (resUriString.startsWith(toWipeProject)) {
				toBeRemoved.add(resUri);
				break;
			}
		}
	}

	builderState.clean(toBeRemoved, monitor);
}
 
Example 3
Source File: ExternalIndexSynchronizer.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a map that maps the names of projects as they can be found in the index to their locations and versions.
 */
public Map<N4JSProjectName, Pair<FileURI, String>> findNpmsInIndex() {
	// keep map of all NPMs that were discovered in the index
	Map<N4JSProjectName, Pair<FileURI, String>> discoveredNpmsInIndex = new HashMap<>();

	final ResourceSet resourceSet = core.createResourceSet(Optional.absent());
	final IResourceDescriptions index = core.getXtextIndex(resourceSet);

	for (IResourceDescription resourceDescription : index.getAllResourceDescriptions()) {
		boolean isExternal = resourceDescription.getURI().isFile();
		if (isExternal) {
			addToIndex(discoveredNpmsInIndex, resourceDescription);
		}
	}

	return discoveredNpmsInIndex;
}
 
Example 4
Source File: ReferenceFinder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void findAllReferences(TargetURIs targetURIs, IResourceAccess resourceAccess,
		IResourceDescriptions indexData, Acceptor acceptor, IProgressMonitor monitor) {
	if (!targetURIs.isEmpty()) {
		Iterable<IResourceDescription> allResourceDescriptions = indexData.getAllResourceDescriptions();
		SubMonitor subMonitor = SubMonitor.convert(monitor, size(allResourceDescriptions) / MONITOR_CHUNK_SIZE + 1);
		IProgressMonitor useMe = subMonitor.newChild(1);
		int i = 0;
		for (IResourceDescription resourceDescription : allResourceDescriptions) {
			if (subMonitor.isCanceled())
				throw new OperationCanceledException();
			IReferenceFinder languageSpecific = getLanguageSpecificReferenceFinder(resourceDescription.getURI());
			languageSpecific.findReferences(targetURIs, resourceDescription, resourceAccess, acceptor, useMe);
			i++;
			if (i % MONITOR_CHUNK_SIZE == 0) {
				useMe = subMonitor.newChild(1);
			}
		}
	}
}
 
Example 5
Source File: WorkspaceSymbolService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public List<? extends SymbolInformation> getSymbols(
	String query,
	IResourceAccess resourceAccess,
	IResourceDescriptions indexData,
	CancelIndicator cancelIndicator
) {
	List<SymbolInformation> result = new LinkedList<>();
	for (IResourceDescription resourceDescription : indexData.getAllResourceDescriptions()) {
		operationCanceledManager.checkCanceled(cancelIndicator);
		IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(resourceDescription.getURI());
		if (resourceServiceProvider != null) {
			DocumentSymbolService documentSymbolService = resourceServiceProvider.get(DocumentSymbolService.class);
			if (documentSymbolService != null) {
				result.addAll(documentSymbolService.getSymbols(resourceDescription, query, resourceAccess, cancelIndicator));
			}
		}
	}
	return result;
}
 
Example 6
Source File: AbstractBuilderTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void assertXtextIndexIsValidInternal() {
	final IResourceDescriptions index = getXtextIndex();
	final StringBuilder sb = new StringBuilder();
	for (IResourceDescription desc : index.getAllResourceDescriptions()) {
		if (desc instanceof ResourceDescriptionWithoutModuleUserData) {
			sb.append("\n");
			sb.append(IResourceDescription.class.getSimpleName());
			sb.append(" in index must not be an instance of ");
			sb.append(ResourceDescriptionWithoutModuleUserData.class.getSimpleName());
			sb.append(" but it was. URI: ");
			sb.append(desc.getURI());
		}
	}
	assertTrue(sb.toString(), 0 == sb.length());
}
 
Example 7
Source File: BuilderUtil.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/***/
public static String toString(IResourceDescriptions index) {
	StringBuffer buff = new StringBuffer();
	for (IResourceDescription desc : index.getAllResourceDescriptions()) {
		buff.append(EmfFormatter.objToStr(desc, new EStructuralFeature[0]));
	}
	return buff.toString();
}
 
Example 8
Source File: BuilderUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static String toString(IResourceDescriptions index) {
	StringBuffer buff = new StringBuffer();
	for (IResourceDescription desc : index.getAllResourceDescriptions()) {
		buff.append(EmfFormatter.objToStr(desc, new EStructuralFeature[0]));
	}
	return buff.toString();
}
 
Example 9
Source File: Bug334456Test.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNoCopiedResourceDescription() throws Exception {
	createPluginProject("foo");
	build();
	IResourceDescriptions descriptions = BuilderUtil.getBuilderState();
	assertFalse(Iterables.isEmpty(descriptions.getAllResourceDescriptions()));
	for(IResourceDescription description: descriptions.getAllResourceDescriptions()) {
		if (description instanceof CopiedResourceDescription) {
			fail("Did not expect an instance of copied resource description in builder state");
		}
	}
}
 
Example 10
Source File: SlotEntry.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected List<EObject> findEObjectsOfType(Set<EClass> eClasses, IResourceDescriptions resourceDescriptions,
		ResourceSet resourceSet) {
	List<EObject> elements = Lists.newArrayList();
	Iterable<IResourceDescription> descriptions = resourceDescriptions.getAllResourceDescriptions();
	for (IResourceDescription resDesc : descriptions) {
		Iterable<IEObjectDescription> objects = resDesc.getExportedObjects();
		for (IEObjectDescription description : objects) {
			if (matches(eClasses, description))
				elements.add(resourceSet.getEObject(description.getEObjectURI(), true));
		}
	}
	return elements;
}
 
Example 11
Source File: ResourceDescriptionsUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns all URIs in the given resource descriptions object.
 *
 * @param descriptions
 *          {@link IResourceDescriptions} to get the URIs for
 * @return set of all URIs
 */
public static Set<URI> getAllURIs(final IResourceDescriptions descriptions) {
  Set<URI> allURIs = Sets.newHashSetWithExpectedSize(Iterables.size(descriptions.getAllResourceDescriptions()));
  for (IResourceDescription desc : descriptions.getAllResourceDescriptions()) {
    allURIs.add(desc.getURI());
  }
  return allURIs;
}