org.eclipse.xtext.resource.IResourceDescription.Delta Java Examples

The following examples show how to use org.eclipse.xtext.resource.IResourceDescription.Delta. 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: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.7
 */
protected Set<IFile> getDerivedResources(Delta delta, 
		final Map<String, OutputConfiguration> outputConfigurations,
		Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers) {
	String uri = delta.getUri().toString();
	if (generatorMarkers instanceof DerivedResourcesLookupMap) {
		return ((DerivedResourcesLookupMap) generatorMarkers).getDerivedResources(uri);
	}
	Set<IFile> derivedResources = newLinkedHashSet();
	for (OutputConfiguration config : outputConfigurations.values()) {
		if (config.isCleanUpDerivedResources()) {
			Iterable<IMarker> markers = generatorMarkers.get(config);
			for (IMarker marker : markers) {
				String source = derivedResourceMarkers.getSource(marker);
				if (source != null && source.equals(uri))
					derivedResources.add((IFile) marker.getResource());
			}
		}
	}
	return derivedResources;
}
 
Example #2
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * 
 * @param toBeBuilt the collected URIs that should be handled by this clean operation.
 * @param removedProjects additional projects that were available but do no longer have the Xtext nature or have been deleted
 * 
 * @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility
 *        to call done() on the given monitor. Accepts null, indicating that no progress should be
 *        reported and that the operation cannot be cancelled.
 */
protected void doClean(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor) throws CoreException {
	SubMonitor progress = SubMonitor.convert(monitor, 2);
	SetWithProjectNames toBeDeletedAndProjects = new SetWithProjectNames(toBeBuilt.getToBeDeleted(), getProject().getName(), removedProjects);
	ImmutableList<Delta> deltas = builderState.clean(toBeDeletedAndProjects, progress.split(1));
	if (participant != null) {
		Set<URI> sourceURIs = new SourceLevelURICache().getSourcesFrom(toBeBuilt.getToBeDeleted(), resourceServiceProvideRegistry);
		
		participant.build(new BuildContext(this, 
				getResourceSetProvider().get(getProject()), 
				deltas,
				sourceURIs,
				BuildType.CLEAN), 
				progress.split(1));
	} else {
		progress.worked(1);
	}
}
 
Example #3
Source File: XIndexer.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Compute deltas for resources affected by the given <code>newDeltas</code> and register them in the given
 * <code>newIndex</code>.
 *
 * @param index
 *            the current index; will be changed by this method.
 * @param remainingURIs
 *            set of URIs that were not processed yet.
 * @param newDeltas
 *            deltas representing the resources processed during the most recent build iteration.
 * @param allDeltas
 *            deltas representing all resources processed so far, including {@link XBuildRequest#getExternalDeltas()
 *            external deltas}.
 * @param context
 *            the build context.
 * @return list of deltas representing the affected resources.
 */
public List<Delta> computeAndIndexAffected(ResourceDescriptionsData index, Set<URI> remainingURIs,
		Collection<Delta> newDeltas, Collection<Delta> allDeltas, XBuildContext context) {

	ResourceDescriptionsData originalIndex = context.getOldState().getResourceDescriptions();
	List<URI> affectedURIs = new ArrayList<>();
	for (URI uri : remainingURIs) {
		IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(uri);
		IResourceDescription.Manager manager = resourceServiceProvider.getResourceDescriptionManager();
		IResourceDescription resourceDescription = originalIndex.getResourceDescription(uri);
		if (isAffected(resourceDescription, manager, newDeltas, allDeltas, index)) {
			affectedURIs.add(uri);
		}
	}

	List<Delta> affectedDeltas = getDeltasForChangedResources(affectedURIs, originalIndex, context);
	for (IResourceDescription.Delta delta : affectedDeltas) {
		index.register(delta);
	}
	return affectedDeltas;
}
 
Example #4
Source File: XBuildManager.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Run a full build on the workspace
 *
 * @return the delta.
 */
public List<IResourceDescription.Delta> doInitialBuild(List<ProjectDescription> projects,
		CancelIndicator indicator) {

	lspLogger.log("Initial build ...");

	ProjectBuildOrderInfo projectBuildOrderInfo = projectBuildOrderInfoProvider.get();
	ProjectBuildOrderIterator pboIterator = projectBuildOrderInfo.getIterator(projects);
	printBuildOrder();

	List<IResourceDescription.Delta> result = new ArrayList<>();

	while (pboIterator.hasNext()) {
		ProjectDescription description = pboIterator.next();
		String projectName = description.getName();
		XProjectManager projectManager = workspaceManager.getProjectManager(projectName);
		XBuildResult partialresult = projectManager.doInitialBuild(indicator);
		result.addAll(partialresult.getAffectedResources());
	}

	lspLogger.log("... initial build done.");

	return result;
}
 
Example #5
Source File: DirtyStateAwareResourceDescriptions.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void dirtyDescriptionsChanged(IResourceDescription.Event event) {
	if (event instanceof CoarseGrainedChangeEvent) {
		notifyListeners(event);
		return;
	}
	ResourceDescriptionChangeEvent changeEvent = new ResourceDescriptionChangeEvent(
			Iterables.transform(event.getDeltas(), new Function<IResourceDescription.Delta, IResourceDescription.Delta>() {
				@Override
				public IResourceDescription.Delta apply(IResourceDescription.Delta from) {
					IResourceDescription.Delta result = from;
					if (from.getNew() == null) {
						result = createDelta(from.getOld(), globalDescriptions.getResourceDescription(from.getUri()));
					} else if (from.getOld() == null) {
						result = createDelta(globalDescriptions.getResourceDescription(from.getUri()), from.getNew());
					}
					return result;
				}
			}));
	notifyListeners(changeEvent);
}
 
Example #6
Source File: XIndexer.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Process the changed resources.
 */
protected List<IResourceDescription.Delta> getDeltasForChangedResources(Iterable<URI> changedURIs,
		ResourceDescriptionsData oldIndex, XBuildContext context) {
	try {
		this.compilerPhases.setIndexing(context.getResourceSet(), true);
		List<IResourceDescription.Delta> result = new ArrayList<>();
		List<Delta> deltas = context.executeClustered(changedURIs, it -> addToIndex(it, true, oldIndex, context));
		for (IResourceDescription.Delta delta : deltas) {
			if (delta != null) {
				result.add(delta);
			}
		}
		return result;
	} finally {
		this.compilerPhases.setIndexing(context.getResourceSet(), false);
	}
}
 
Example #7
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.7
 */
protected String getCurrentSourceFolder(IBuildContext context, Delta delta) {
	Iterable<org.eclipse.xtext.util.Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(delta.getUri());
	for (org.eclipse.xtext.util.Pair<IStorage, IProject> pair : storages) {
		if (pair.getFirst() instanceof IResource) {
			final IResource resource = (IResource) pair.getFirst();
			IProject project = pair.getSecond();
			for (OutputConfiguration output : getOutputConfigurations(context).values()) {
				for (SourceMapping sourceMapping : output.getSourceMappings()) {
					IContainer folder = ResourceUtil.getContainer(project, sourceMapping.getSourceFolder());
					if (folder.contains(resource)) {
						return sourceMapping.getSourceFolder();
					}
				}
			}
		}
	}
	return null;
}
 
Example #8
Source File: Bug486584Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testFullBuildWhenClasspathChanged_2() throws CoreException, InterruptedException {
	IJavaProject project = setupProject();
	IFile libaryFile = copyAndGetXtendExampleJar(project);
	IClasspathEntry libraryEntry = JavaCore.newLibraryEntry(libaryFile.getFullPath(), null, null);
	addToClasspath(project, libraryEntry);
	build();
	assertFalse(getEvents().isEmpty());
	getEvents().clear();

	libaryFile.touch(null);
	libaryFile.refreshLocal(IResource.DEPTH_INFINITE, null);
	build();
	assertEquals(1, getEvents().size());
	Event singleEvent = getEvents().get(0);
	ImmutableList<Delta> deltas = singleEvent.getDeltas();
	assertEquals(1, deltas.size());
}
 
Example #9
Source File: AbstractUtilTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Prepare mocks for all tests.
 */
public static void prepareMocksBase() {
  oldDesc = mock(IResourceDescription.class);
  newDesc = mock(IResourceDescription.class);
  delta = mock(Delta.class);
  resource = mock(Resource.class);
  uriCorrect = mock(URI.class);
  when(uriCorrect.isPlatformResource()).thenReturn(true);
  when(uriCorrect.isFile()).thenReturn(true);
  when(uriCorrect.toFileString()).thenReturn(DUMMY_PATH);
  when(uriCorrect.toPlatformString(true)).thenReturn(DUMMY_PATH);
  when(delta.getNew()).thenReturn(newDesc);
  when(delta.getOld()).thenReturn(oldDesc);
  when(delta.getUri()).thenReturn(uriCorrect);
  when(resource.getURI()).thenReturn(uriCorrect);
  file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uriCorrect.toPlatformString(true)));
  Iterable<Pair<IStorage, IProject>> storages = singleton(Tuples.<IStorage, IProject> create(file, file.getProject()));
  mapperCorrect = mock(Storage2UriMapperImpl.class);
  when(mapperCorrect.getStorages(uriCorrect)).thenReturn(storages);
}
 
Example #10
Source File: PersistableResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testUpdate() throws Exception {
	addToFileSystem("bar", "namespace bar { object B }");
	addToFileSystem("foo", "namespace foo { object A references bar.B}");
	Map<URI, Delta> reload = update(uris("foo", "bar"), null); // add
	assertNull(reload.get(uri("bar")).getOld());
	assertNull(reload.get(uri("foo")).getOld());
	assertNotNull(reload.get(uri("bar")).getNew());
	assertNotNull(reload.get(uri("foo")).getNew());

	addToFileSystem("bar", "namespace bar { object C }");
	reload = update(uris("bar"), null); // update
	assertNotNull(reload.get(uri("bar")).getOld());
	assertNotNull(reload.get(uri("bar")).getNew());
	assertNotNull(reload.get(uri("foo")).getOld());
	assertNotNull(reload.get(uri("foo")).getNew());
}
 
Example #11
Source File: PersistableResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testUpdate_1() throws Exception {
	addToFileSystem("foo", "namespace foo { object A }");
	addToFileSystem("bar", "namespace bar { object B references foo.A}");
	addToFileSystem("baz", "namespace baz { object C references bar.B}");
	Map<URI, Delta> reload = update(uris("foo", "bar", "baz"), null); // add
	assertNull(reload.get(uri("foo")).getOld());
	assertNull(reload.get(uri("bar")).getOld());
	assertNull(reload.get(uri("baz")).getOld());
	assertNotNull(reload.get(uri("foo")).getNew());
	assertNotNull(reload.get(uri("bar")).getNew());
	assertNotNull(reload.get(uri("baz")).getNew());

	addToFileSystem("foo", "namespace foo { object X }");
	reload = update(uris("foo"), null); // update
	assertNotNull(reload.get(uri("foo")).getOld());
	assertNotNull(reload.get(uri("foo")).getNew());
	assertNotNull(reload.get(uri("bar")).getOld());
	assertNotNull(reload.get(uri("bar")).getNew());
	assertNull(reload.get(uri("baz")));
}
 
Example #12
Source File: Indexer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Process the deleted resources.
 */
protected List<IResourceDescription.Delta> getDeltasForDeletedResources(BuildRequest request,
		ResourceDescriptionsData oldIndex, BuildContext context) {
	List<IResourceDescription.Delta> deltas = new ArrayList<>();
	for (URI deleted : request.getDeletedFiles()) {
		IResourceServiceProvider resourceServiceProvider = context.getResourceServiceProvider(deleted);
		if (resourceServiceProvider != null) {
			operationCanceledManager.checkCanceled(context.getCancelIndicator());
			IResourceDescription oldDescription = oldIndex != null ? oldIndex.getResourceDescription(deleted)
					: null;
			if (oldDescription != null) {
				DefaultResourceDescriptionDelta delta = new DefaultResourceDescriptionDelta(oldDescription, null);
				deltas.add(delta);
			}
		}
	}
	return deltas;
}
 
Example #13
Source File: GamlResourceDescriptionManager.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean isAffected(final Collection<Delta> deltas, final IResourceDescription candidate,
		final IResourceDescriptions context) {
	// final boolean result = false;
	final URI newUri = candidate.getURI();
	try (ICollector<URI> deltaUris = Collector.getSet()) {
		for (final Delta d : deltas) {
			deltaUris.add(GamlResourceServices.properlyEncodedURI(d.getUri()));
		}
		final Iterator<URI> it = GamlResourceIndexer.allImportsOf(newUri);
		while (it.hasNext()) {
			final URI next = it.next();
			if (deltaUris.contains(next)) { return true; }
		}
		return super.isAffected(deltas, candidate, context);
	}
}
 
Example #14
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.5
 */
protected void convertAddedPackageFragment(IJavaElementDelta delta, List<IResourceDescription.Delta> result) {
	IPackageFragment fragment = (IPackageFragment) delta.getElement();
	try {
		for (ICompilationUnit cu : fragment.getCompilationUnits()) {
			convertNewTypes(cu, result);
		}
	} catch (JavaModelException e) {
		if (LOGGER.isDebugEnabled())
			LOGGER.debug(e, e);
	}
}
 
Example #15
Source File: PersistableResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testUpdateNoChange() throws Exception {
	addToFileSystem("bar", "namespace bar { object B }");
	addToFileSystem("foo", "namespace foo { object A references bar.B}");
	Map<URI, Delta> reload = update(uris("foo", "bar"), null); // add
	assertNull(reload.get(uri("bar")).getOld());
	assertNull(reload.get(uri("foo")).getOld());
	assertNotNull(reload.get(uri("bar")).getNew());
	assertNotNull(reload.get(uri("foo")).getNew());

	reload = update(uris("bar"), null); // delete
	assertEquals(1, reload.size());
	assertNotNull(reload.get(uri("bar")).getOld());
	assertNotNull(reload.get(uri("bar")).getNew());
}
 
Example #16
Source File: PersistableResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testDelete_1() throws Exception {
	addToFileSystem("bar", "namespace bar { object B }");
	addToFileSystem("foo", "namespace foo { object A references bar.B}");
	Map<URI, Delta> reload = update(uris("foo", "bar"), null); // add
	assertNull(reload.get(uri("bar")).getOld());
	assertNull(reload.get(uri("foo")).getOld());
	assertNotNull(reload.get(uri("bar")).getNew());
	assertNotNull(reload.get(uri("foo")).getNew());

	reload = update(null, uris("foo")); // delete
	assertNull(reload.get(uri("bar")));
	assertNotNull(reload.get(uri("foo")).getOld());
	assertNull(reload.get(uri("foo")).getNew());
}
 
Example #17
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param toBeBuilt
 *            the URIs that will be processed in this build run.
 * @param removedProjects
 *            the projects that are no longer considered by XtextBuilders but are yet to be removed from the index.
 * @param monitor
 *            the progress monitor for the build.
 * @param type
 *            indicates the kind of build that is running.
 * 
 * @since 2.18
 */
protected void doBuild(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor, BuildType type) throws CoreException {
	buildLogger.log("Building " + getProject().getName());
	// return early if there's nothing to do.
	// we reuse the isEmpty() impl from BuildData assuming that it doesnT access the ResourceSet which is still null 
	// and would be expensive to create.
	boolean indexingOnly = type == BuildType.RECOVERY;
	if (new BuildData(getProject().getName(), null, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects).isEmpty())
		return;
	SubMonitor progress = SubMonitor.convert(monitor, 2);
	ResourceSet resourceSet = getResourceSetProvider().get(getProject());
	resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
	BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects);
	ImmutableList<Delta> deltas = builderState.update(buildData, progress.split(1));
	if (participant != null && !indexingOnly) {
		SourceLevelURICache sourceLevelURIs = buildData.getSourceLevelURICache();
		Set<URI> sources = sourceLevelURIs.getSources();
		participant.build(new BuildContext(this, resourceSet, deltas, sources, type),
				progress.split(1));
		try {
			getProject().getWorkspace().checkpoint(false);
		} catch(NoClassDefFoundError e) { // guard against broken Eclipse installations / bogus project configuration
			log.error(e.getMessage(), e);
		}
	} else {
		progress.worked(1);
	}
	resourceSet.eSetDeliver(false);
	for (Resource resource : resourceSet.getResources()) {
		resource.eSetDeliver(false);
	}
	resourceSet.getResources().clear();
	resourceSet.eAdapters().clear();
}
 
Example #18
Source File: Indexer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Return true, if the given resource must be processed due to the given changes.
 */
protected boolean isAffected(IResourceDescription affectionCandidate, IResourceDescription.Manager manager,
		Collection<IResourceDescription.Delta> newDeltas, Collection<IResourceDescription.Delta> allDeltas,
		IResourceDescriptions resourceDescriptions) {
	if (manager instanceof IResourceDescription.Manager.AllChangeAware) {
		return ((IResourceDescription.Manager.AllChangeAware) manager).isAffectedByAny(allDeltas,
				affectionCandidate, resourceDescriptions);
	} else {
		if (newDeltas.isEmpty()) {
			return false;
		} else {
			return manager.isAffected(newDeltas, affectionCandidate, resourceDescriptions);
		}
	}
}
 
Example #19
Source File: MonitoredClusteringBuilderState.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.AvoidInstanceofChecksInCatchClause")
public synchronized ImmutableList<Delta> update(final BuildData buildData, final IProgressMonitor monitor) {
  ensureLoaded();
  final SubMonitor subMonitor = SubMonitor.convert(monitor, org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0, 1);
  subMonitor.subTask(org.eclipse.xtext.builder.builderState.Messages.AbstractBuilderState_0);

  checkForCancellation(monitor);

  final ResourceDescriptionsData newData = getCopiedResourceDescriptionsData();
  Collection<IResourceDescription.Delta> result = null;
  try {
    result = doUpdate(buildData, newData, subMonitor.newChild(1));
    // update the reference
    setResourceDescriptionsData(newData, monitor);
    // CHECKSTYLE:CHECK-OFF IllegalCatch
  } catch (Throwable t) {
    // CHECKSTYLE:CHECK-ON IllegalCatch
    if (!operationCanceledManager.isOperationCanceledException(t)) {
      LOGGER.error("Failed to update index. Executing rollback.", t); //$NON-NLS-1$
    }
    if (newData instanceof AbstractResourceDescriptionsData) {
      ((AbstractResourceDescriptionsData) newData).rollbackChanges();
    }
    throw t;
  }

  final ResourceDescriptionChangeEvent event = new ResourceDescriptionChangeEvent(result);
  notifyListeners(event);
  return event.getDeltas();
}
 
Example #20
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.7
 */
protected void doBuild(List<IResourceDescription.Delta> deltas, 
		Map<String, OutputConfiguration> outputConfigurations,
		Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers, IBuildContext context,
		EclipseResourceFileSystemAccess2 access, IProgressMonitor progressMonitor) throws CoreException {
	final int numberOfDeltas = deltas.size();
	SubMonitor subMonitor = SubMonitor.convert(progressMonitor, numberOfDeltas);
	SubMonitor currentMonitor = null;
	int clusterIndex = 0;
	for (int i = 0; i < numberOfDeltas; i++) {
		IResourceDescription.Delta delta = deltas.get(i);
		
		if (subMonitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		currentMonitor = subMonitor.split(1);
		access.setMonitor(currentMonitor);
		if (logger.isDebugEnabled()) {
			logger.debug("Compiling " + delta.getUri() + " (" + i + " of " + numberOfDeltas + ")");
		}
		if (delta.getNew() != null && !clusteringPolicy.continueProcessing(context.getResourceSet(), delta.getUri(), clusterIndex)) {
			clearResourceSet(context.getResourceSet());
			clusterIndex = 0;
		}

		Set<IFile> derivedResources = getDerivedResources(delta, outputConfigurations, generatorMarkers);
		access.setPostProcessor(getPostProcessor(delta, context, derivedResources));
		
		if (doGenerate(delta, context, access)) {
			clusterIndex++;
			access.flushSourceTraces();
		}
		
		cleanDerivedResources(delta, derivedResources, context, access, currentMonitor);
	}
}
 
Example #21
Source File: JavaResourceDescriptionManager.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isAffected(Collection<IResourceDescription.Delta> deltas, IResourceDescription candidate,
		IResourceDescriptions context) throws IllegalArgumentException {
	Collection<QualifiedName> importedNames = IterableExtensions.<QualifiedName>toSet(candidate.getImportedNames());
	for (IResourceDescription.Delta delta : deltas) {
		if (hasChanges(delta, candidate)) {
			if (isAffected(importedNames, delta.getNew()) || isAffected(importedNames, delta.getOld())) {
				return true;
			}
		}
	}
	return false;
}
 
Example #22
Source File: N4JSResourceDescriptionManager.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * This marks {@code n4js} as affected if the manifest of the project changes. In turn, they will be revalidated and
 * taken into consideration for the code generation step.
 */
@Override
public boolean isAffected(Collection<IResourceDescription.Delta> deltas, IResourceDescription candidate,
		IResourceDescriptions context) {
	URI candidateURI = candidate.getURI();

	// Opaque modules cannot contain any references to one of the deltas.
	// Thus, they will never be affected by any change.
	if (langHelper.isOpaqueModule(candidateURI)) {
		return false;
	}

	boolean result = basicIsAffected(deltas, candidate);
	if (!result) {
		for (IResourceDescription.Delta delta : deltas) {
			URI uri = delta.getUri();
			// if uri looks like a N4JS project description file (i.e. package.json)
			if (IN4JSProject.PACKAGE_JSON.equalsIgnoreCase(uri.lastSegment())) {
				URI prefixURI = uri.trimSegments(1).appendSegment("");
				if (candidateURI.replacePrefix(prefixURI, prefixURI) != null) {
					return true;
				}
			}
		}
	}
	return result;
}
 
Example #23
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void convertCompilationUnit(IJavaElementDelta delta, List<IResourceDescription.Delta> result) {
	if (delta.getKind() == IJavaElementDelta.ADDED) {
		convertAddedCompilationUnit(delta, result);
	} else if (delta.getKind() == IJavaElementDelta.REMOVED) {
		convertRemovedTypes(delta, result);
	} else {
		convertChangedCompilationUnit(delta, result);
	}
}
 
Example #24
Source File: DefaultResourceDescriptionManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Query all registered extensions.
 * 
 * @since 2.22
 */
@Beta
protected boolean isAffectedByExtensions(Collection<Delta> deltas, IResourceDescription candidate,
		IResourceDescriptions context) {
	for (int i = 0; i < isAffectedExtensions.size(); i++) {
		if (isAffectedExtensions.get(i).isAffected(deltas, candidate, context)) {
			return true;
		}
	}
	return false;
}
 
Example #25
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void convertCompilationUnits(IJavaElementDelta delta, List<IResourceDescription.Delta> result) {
	IJavaElement element = delta.getElement();
	if (element.getElementType() == IJavaElement.COMPILATION_UNIT) {
		convertCompilationUnit(delta, result);
	}
	if (element.getElementType() < IJavaElement.COMPILATION_UNIT) {
		for (IJavaElementDelta child : delta.getAffectedChildren()) {
			convertCompilationUnits(child, result);
		}
		if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
			convertPackageFragment(delta, result);
		}
	}
}
 
Example #26
Source File: BuilderUtil.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/***/
public static String print(ImmutableList<Delta> deltas) {
	int i = 1;
	String buff = "Deltas : \n";
	for (Delta delta : deltas) {
		buff += "Delta " + i + "[" + delta.getUri() + "]: {\n";
		buff += " old : " + toString(delta.getOld()) + "\n";
		buff += " new : " + toString(delta.getNew()) + "\n";
		buff += "}\n\n";
		i++;
	}
	return buff;
}
 
Example #27
Source File: DirtyStateAwareResourceDescriptions.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void globalDescriptionsChanged(IResourceDescription.Event event) {
	ResourceDescriptionChangeEvent changeEvent = new ResourceDescriptionChangeEvent(
			Iterables.filter(event.getDeltas(), new Predicate<IResourceDescription.Delta>() {
				@Override
				public boolean apply(Delta input) {
					URI uri = input.getUri();
					return !dirtyStateManager.hasContent(uri);
				}
			}));
	notifyListeners(changeEvent);
}
 
Example #28
Source File: DeltaConverter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.5
 */
protected void convertNewTypes(ICompilationUnit compilationUnit, List<IResourceDescription.Delta> result) {
	try {
		doForeachCompilationUnitChildType(compilationUnit, true, type -> {
			String typeName = type.getFullyQualifiedName();
			URI topLevelURI = uriHelper.createResourceURIForFQN(typeName);
			convertNewTypeAndChildren(topLevelURI, type, result);
		});
	} catch (JavaModelException e) {
		if (LOGGER.isDebugEnabled())
			LOGGER.debug(e, e);
	}
}
 
Example #29
Source File: XStatefulIncrementalBuilder.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private Delta buildClustured(Resource resource,
		XSource2GeneratedMapping newSource2GeneratedMapping,
		XIndexer.XIndexResult result) {

	CancelIndicator cancelIndicator = request.getCancelIndicator();
	operationCanceledManager.checkCanceled(cancelIndicator);

	// trigger init
	resource.getContents();
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	operationCanceledManager.checkCanceled(cancelIndicator);

	URI source = resource.getURI();
	IResourceServiceProvider serviceProvider = getResourceServiceProvider(resource);
	IResourceDescription.Manager manager = serviceProvider.getResourceDescriptionManager();
	IResourceValidator resourceValidator = serviceProvider.getResourceValidator();

	IResourceDescription description = manager.getResourceDescription(resource);
	SerializableResourceDescription copiedDescription = SerializableResourceDescription.createCopy(description);
	result.getNewIndex().addDescription(source, copiedDescription);
	operationCanceledManager.checkCanceled(cancelIndicator);

	if (request.canValidate()) {
		List<Issue> issues = resourceValidator.validate(resource, CheckMode.ALL, cancelIndicator);
		List<LSPIssue> lspIssues = lspIssueConverter.convertToLSPIssues(resource, issues, cancelIndicator);
		operationCanceledManager.checkCanceled(cancelIndicator);
		request.setResultIssues(request.getProjectName(), source, lspIssues);
		boolean proceedGenerate = !request.containsValidationErrors(source);

		if (proceedGenerate) {
			operationCanceledManager.checkCanceled(cancelIndicator);
			generate(resource, newSource2GeneratedMapping, serviceProvider);
		} else {
			removeGeneratedFiles(resource.getURI(), newSource2GeneratedMapping);
		}
	}

	IResourceDescription old = context.getOldState().getResourceDescriptions().getResourceDescription(source);
	return manager.createDelta(old, copiedDescription);
}
 
Example #30
Source File: ResourceDescriptionUpdaterTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private synchronized boolean affectedResourcesContain(final String projectName, final String fileName) {
	try {
		final URI expected = URI.createPlatformResourceURI(projectName + "/" + SRC_FOLDER + "/" + fileName + F_EXT, true);
		Iterables.find(getContext().getDeltas(), new Predicate<IResourceDescription.Delta>() {

			@Override
			public boolean apply(Delta actual) {
				return expected.equals(actual.getUri());
			}
		});
		return true;
	} catch (NoSuchElementException e) {
		return false;
	}
}