Added generated code for package org.eclipse.xtext.build

This commit is contained in:
Miro Spönemann 2016-06-14 15:24:46 +02:00
parent 886754f3c7
commit b612f2d437
8 changed files with 1456 additions and 0 deletions

View file

@ -1 +1,2 @@
bin
!xtend-gen/org/eclipse/xtext/build

View file

@ -0,0 +1,95 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.build;
import com.google.common.base.Objects;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
import org.eclipse.xtext.build.ClusteringStorageAwareResourceLoader;
import org.eclipse.xtext.build.IndexState;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.resource.clustering.IResourceClusteringPolicy;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* @author Jan Koehnlein - Initial contribution and API
* @since 2.9
*/
@FinalFieldsConstructor
@SuppressWarnings("all")
public class BuildContext {
private final Function1<? super URI, ? extends IResourceServiceProvider> resourceServiceProviderProvider;
@Accessors
private final XtextResourceSet resourceSet;
@Accessors
private final IndexState oldState;
@Accessors
private final IResourceClusteringPolicy clusteringPolicy;
@Accessors
private final CancelIndicator cancelIndicator;
private ClusteringStorageAwareResourceLoader loader;
public <T extends Object> Iterable<T> executeClustered(final Iterable<URI> uri, final Function1<? super Resource, ? extends T> operation) {
boolean _equals = Objects.equal(this.loader, null);
if (_equals) {
ClusteringStorageAwareResourceLoader _clusteringStorageAwareResourceLoader = new ClusteringStorageAwareResourceLoader(this);
this.loader = _clusteringStorageAwareResourceLoader;
}
final Function1<URI, Boolean> _function = (URI it) -> {
IResourceServiceProvider _resourceServiceProvider = this.getResourceServiceProvider(it);
return Boolean.valueOf((!Objects.equal(_resourceServiceProvider, null)));
};
Iterable<URI> _filter = IterableExtensions.<URI>filter(uri, _function);
return this.loader.<T>executeClustered(_filter, operation);
}
public IResourceServiceProvider getResourceServiceProvider(final URI uri) {
final IResourceServiceProvider resourceServiceProvider = this.resourceServiceProviderProvider.apply(uri);
return resourceServiceProvider;
}
public BuildContext(final Function1<? super URI, ? extends IResourceServiceProvider> resourceServiceProviderProvider, final XtextResourceSet resourceSet, final IndexState oldState, final IResourceClusteringPolicy clusteringPolicy, final CancelIndicator cancelIndicator) {
super();
this.resourceServiceProviderProvider = resourceServiceProviderProvider;
this.resourceSet = resourceSet;
this.oldState = oldState;
this.clusteringPolicy = clusteringPolicy;
this.cancelIndicator = cancelIndicator;
}
@Pure
public XtextResourceSet getResourceSet() {
return this.resourceSet;
}
@Pure
public IndexState getOldState() {
return this.oldState;
}
@Pure
public IResourceClusteringPolicy getClusteringPolicy() {
return this.clusteringPolicy;
}
@Pure
public CancelIndicator getCancelIndicator() {
return this.cancelIndicator;
}
}

View file

@ -0,0 +1,222 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.build;
import com.google.common.base.Objects;
import java.io.File;
import java.util.List;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.build.IndexState;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.UriUtil;
import org.eclipse.xtext.util.internal.Log;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure2;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* @author Jan Koehnlein - Initial contribution and API
* @since 2.9
*/
@Accessors
@SuppressWarnings("all")
public class BuildRequest {
public interface IPostValidationCallback {
/**
* @return whether the build can proceed, <code>false</code> if the build should be interrupted
*/
public abstract boolean afterValidate(final URI validated, final Iterable<Issue> issues);
}
@Log
private static class DefaultValidationCallback implements BuildRequest.IPostValidationCallback {
@Override
public boolean afterValidate(final URI validated, final Iterable<Issue> issues) {
boolean errorFree = true;
for (final Issue issue : issues) {
Severity _severity = issue.getSeverity();
if (_severity != null) {
switch (_severity) {
case ERROR:
String _string = issue.toString();
BuildRequest.DefaultValidationCallback.LOG.error(_string);
errorFree = false;
break;
case WARNING:
String _string_1 = issue.toString();
BuildRequest.DefaultValidationCallback.LOG.warn(_string_1);
break;
case INFO:
String _string_2 = issue.toString();
BuildRequest.DefaultValidationCallback.LOG.info(_string_2);
break;
case IGNORE:
String _string_3 = issue.toString();
BuildRequest.DefaultValidationCallback.LOG.debug(_string_3);
break;
default:
break;
}
}
}
return errorFree;
}
private final static Logger LOG = Logger.getLogger(DefaultValidationCallback.class);
}
private URI baseDir;
public URI getBaseDir() {
boolean _equals = Objects.equal(this.baseDir, null);
if (_equals) {
final String userDir = System.getProperty("user.dir");
File _file = new File(userDir);
URI _createFolderURI = UriUtil.createFolderURI(_file);
this.baseDir = _createFolderURI;
}
return this.baseDir;
}
private List<URI> dirtyFiles = CollectionLiterals.<URI>newArrayList();
private List<URI> deletedFiles = CollectionLiterals.<URI>newArrayList();
private List<IResourceDescription.Delta> externalDeltas = CollectionLiterals.<IResourceDescription.Delta>newArrayList();
/**
* call back after validation, return <code>false</code> will stop the build.
*/
private BuildRequest.IPostValidationCallback afterValidate = new BuildRequest.DefaultValidationCallback();
private Procedure2<? super URI, ? super URI> afterGenerateFile = ((Procedure2<URI, URI>) (URI $0, URI $1) -> {
});
private Procedure1<? super URI> afterDeleteFile = ((Procedure1<URI>) (URI it) -> {
});
private IndexState state = new IndexState();
private boolean writeStorageResources = false;
private boolean indexOnly = false;
private XtextResourceSet resourceSet;
private CancelIndicator cancelIndicator = CancelIndicator.NullImpl;
public void setBaseDir(final URI baseDir) {
this.baseDir = baseDir;
}
@Pure
public List<URI> getDirtyFiles() {
return this.dirtyFiles;
}
public void setDirtyFiles(final List<URI> dirtyFiles) {
this.dirtyFiles = dirtyFiles;
}
@Pure
public List<URI> getDeletedFiles() {
return this.deletedFiles;
}
public void setDeletedFiles(final List<URI> deletedFiles) {
this.deletedFiles = deletedFiles;
}
@Pure
public List<IResourceDescription.Delta> getExternalDeltas() {
return this.externalDeltas;
}
public void setExternalDeltas(final List<IResourceDescription.Delta> externalDeltas) {
this.externalDeltas = externalDeltas;
}
@Pure
public BuildRequest.IPostValidationCallback getAfterValidate() {
return this.afterValidate;
}
public void setAfterValidate(final BuildRequest.IPostValidationCallback afterValidate) {
this.afterValidate = afterValidate;
}
@Pure
public Procedure2<? super URI, ? super URI> getAfterGenerateFile() {
return this.afterGenerateFile;
}
public void setAfterGenerateFile(final Procedure2<? super URI, ? super URI> afterGenerateFile) {
this.afterGenerateFile = afterGenerateFile;
}
@Pure
public Procedure1<? super URI> getAfterDeleteFile() {
return this.afterDeleteFile;
}
public void setAfterDeleteFile(final Procedure1<? super URI> afterDeleteFile) {
this.afterDeleteFile = afterDeleteFile;
}
@Pure
public IndexState getState() {
return this.state;
}
public void setState(final IndexState state) {
this.state = state;
}
@Pure
public boolean isWriteStorageResources() {
return this.writeStorageResources;
}
public void setWriteStorageResources(final boolean writeStorageResources) {
this.writeStorageResources = writeStorageResources;
}
@Pure
public boolean isIndexOnly() {
return this.indexOnly;
}
public void setIndexOnly(final boolean indexOnly) {
this.indexOnly = indexOnly;
}
@Pure
public XtextResourceSet getResourceSet() {
return this.resourceSet;
}
public void setResourceSet(final XtextResourceSet resourceSet) {
this.resourceSet = resourceSet;
}
@Pure
public CancelIndicator getCancelIndicator() {
return this.cancelIndicator;
}
public void setCancelIndicator(final CancelIndicator cancelIndicator) {
this.cancelIndicator = cancelIndicator;
}
}

View file

@ -0,0 +1,120 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.build;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
import org.eclipse.xtext.build.BuildContext;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.resource.IResourceServiceProviderExtension;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.resource.clustering.IResourceClusteringPolicy;
import org.eclipse.xtext.resource.persistence.SourceLevelURIsAdapter;
import org.eclipse.xtext.resource.persistence.StorageAwareResource;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.ListExtensions;
/**
* @author Jan Koehnlein - Initial contribution and API
*/
@FinalFieldsConstructor
@SuppressWarnings("all")
public class ClusteringStorageAwareResourceLoader {
@Extension
private final BuildContext context;
public <T extends Object> Iterable<T> executeClustered(final Iterable<URI> uris, final Function1<? super Resource, ? extends T> operation) {
ArrayList<T> _xblockexpression = null;
{
final ArrayList<URI> loadedURIs = CollectionLiterals.<URI>newArrayList();
final ArrayList<URI> sourceLevelURIs = CollectionLiterals.<URI>newArrayList();
final ArrayList<Resource> resources = CollectionLiterals.<Resource>newArrayList();
final ArrayList<T> result = CollectionLiterals.<T>newArrayList();
final Iterator<URI> iter = uris.iterator();
while (iter.hasNext()) {
{
final URI uri = iter.next();
IResourceClusteringPolicy _clusteringPolicy = this.context.getClusteringPolicy();
XtextResourceSet _resourceSet = this.context.getResourceSet();
int _size = loadedURIs.size();
boolean _continueProcessing = _clusteringPolicy.continueProcessing(_resourceSet, uri, _size);
boolean _not = (!_continueProcessing);
if (_not) {
final Function1<Resource, T> _function = (Resource it) -> {
return operation.apply(it);
};
List<T> _map = ListExtensions.<Resource, T>map(resources, _function);
Iterables.<T>addAll(result, _map);
resources.clear();
this.clearResourceSet();
loadedURIs.clear();
}
loadedURIs.add(uri);
boolean _isSource = this.isSource(uri);
if (_isSource) {
sourceLevelURIs.add(uri);
XtextResourceSet _resourceSet_1 = this.context.getResourceSet();
final Resource existingResource = _resourceSet_1.getResource(uri, false);
if ((existingResource instanceof StorageAwareResource)) {
boolean _isLoadedFromStorage = ((StorageAwareResource)existingResource).isLoadedFromStorage();
if (_isLoadedFromStorage) {
((StorageAwareResource)existingResource).unload();
}
}
XtextResourceSet _resourceSet_2 = this.context.getResourceSet();
SourceLevelURIsAdapter.setSourceLevelUris(_resourceSet_2, sourceLevelURIs);
}
XtextResourceSet _resourceSet_3 = this.context.getResourceSet();
Resource _resource = _resourceSet_3.getResource(uri, true);
resources.add(_resource);
}
}
final Function1<Resource, T> _function = (Resource it) -> {
return operation.apply(it);
};
List<T> _map = ListExtensions.<Resource, T>map(resources, _function);
Iterables.<T>addAll(result, _map);
_xblockexpression = result;
}
return _xblockexpression;
}
protected boolean isSource(final URI uri) {
final IResourceServiceProvider provider = this.context.getResourceServiceProvider(uri);
return ((provider instanceof IResourceServiceProviderExtension) &&
((IResourceServiceProviderExtension) provider).isSource(uri));
}
protected void clearResourceSet() {
XtextResourceSet _resourceSet = this.context.getResourceSet();
final boolean wasDeliver = _resourceSet.eDeliver();
try {
XtextResourceSet _resourceSet_1 = this.context.getResourceSet();
_resourceSet_1.eSetDeliver(false);
XtextResourceSet _resourceSet_2 = this.context.getResourceSet();
EList<Resource> _resources = _resourceSet_2.getResources();
_resources.clear();
} finally {
XtextResourceSet _resourceSet_3 = this.context.getResourceSet();
_resourceSet_3.eSetDeliver(wasDeliver);
}
}
public ClusteringStorageAwareResourceLoader(final BuildContext context) {
super();
this.context = context;
}
}

View file

@ -0,0 +1,446 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.build;
import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.xtend.lib.annotations.AccessorType;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtend.lib.annotations.Data;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.build.BuildContext;
import org.eclipse.xtext.build.BuildRequest;
import org.eclipse.xtext.build.IndexState;
import org.eclipse.xtext.build.Indexer;
import org.eclipse.xtext.build.Source2GeneratedMapping;
import org.eclipse.xtext.generator.GeneratorContext;
import org.eclipse.xtext.generator.GeneratorDelegate;
import org.eclipse.xtext.generator.IContextualOutputConfigurationProvider;
import org.eclipse.xtext.generator.IContextualOutputConfigurationProvider2;
import org.eclipse.xtext.generator.IFilePostProcessor;
import org.eclipse.xtext.generator.IShouldGenerate;
import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.generator.URIBasedFileSystemAccess;
import org.eclipse.xtext.generator.trace.TraceFileNameProvider;
import org.eclipse.xtext.generator.trace.TraceRegionSerializer;
import org.eclipse.xtext.parser.IEncodingProvider;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.resource.clustering.DisabledClusteringPolicy;
import org.eclipse.xtext.resource.clustering.IResourceClusteringPolicy;
import org.eclipse.xtext.resource.impl.ResourceDescriptionsData;
import org.eclipse.xtext.resource.persistence.IResourceStorageFacade;
import org.eclipse.xtext.resource.persistence.SerializableResourceDescription;
import org.eclipse.xtext.resource.persistence.StorageAwareResource;
import org.eclipse.xtext.service.OperationCanceledManager;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.internal.Log;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.workspace.IProjectConfig;
import org.eclipse.xtext.workspace.IProjectConfigProvider;
import org.eclipse.xtext.workspace.ISourceFolder;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure2;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
/**
* @author Jan Koehnlein - Initial contribution and API
* @since 2.9
*/
@Log
@SuppressWarnings("all")
public class IncrementalBuilder {
@Data
public static class Result {
private final IndexState indexState;
private final List<IResourceDescription.Delta> affectedResources;
public Result(final IndexState indexState, final List<IResourceDescription.Delta> affectedResources) {
super();
this.indexState = indexState;
this.affectedResources = affectedResources;
}
@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.indexState== null) ? 0 : this.indexState.hashCode());
result = prime * result + ((this.affectedResources== null) ? 0 : this.affectedResources.hashCode());
return result;
}
@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
IncrementalBuilder.Result other = (IncrementalBuilder.Result) obj;
if (this.indexState == null) {
if (other.indexState != null)
return false;
} else if (!this.indexState.equals(other.indexState))
return false;
if (this.affectedResources == null) {
if (other.affectedResources != null)
return false;
} else if (!this.affectedResources.equals(other.affectedResources))
return false;
return true;
}
@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("indexState", this.indexState);
b.add("affectedResources", this.affectedResources);
return b.toString();
}
@Pure
public IndexState getIndexState() {
return this.indexState;
}
@Pure
public List<IResourceDescription.Delta> getAffectedResources() {
return this.affectedResources;
}
}
@Log
protected static class InternalStatefulIncrementalBuilder {
@Accessors(AccessorType.PROTECTED_SETTER)
@Extension
private BuildContext context;
@Accessors(AccessorType.PROTECTED_SETTER)
private BuildRequest request;
@Inject
private Indexer indexer;
@Inject
@Extension
private OperationCanceledManager _operationCanceledManager;
public IncrementalBuilder.Result launch() {
IndexState _state = this.request.getState();
final Source2GeneratedMapping newSource2GeneratedMapping = _state.getFileMappings();
List<URI> _deletedFiles = this.request.getDeletedFiles();
final Consumer<URI> _function = (URI source) -> {
Set<URI> _deleteSource = newSource2GeneratedMapping.deleteSource(source);
final Consumer<URI> _function_1 = (URI generated) -> {
try {
boolean _isInfoEnabled = IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.isInfoEnabled();
if (_isInfoEnabled) {
IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.info(("Deleting " + generated));
}
final IResourceServiceProvider serviceProvider = this.context.getResourceServiceProvider(source);
IContextualOutputConfigurationProvider2 _get = serviceProvider.<IContextualOutputConfigurationProvider2>get(IContextualOutputConfigurationProvider2.class);
XtextResourceSet _resourceSet = this.request.getResourceSet();
final Set<OutputConfiguration> configs = _get.getOutputConfigurations(_resourceSet);
final String configName = newSource2GeneratedMapping.getOutputConfigName(generated);
final Function1<OutputConfiguration, Boolean> _function_2 = (OutputConfiguration it) -> {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, configName));
};
final OutputConfiguration config = IterableExtensions.<OutputConfiguration>findFirst(configs, _function_2);
if (((!Objects.equal(config, null)) && config.isCleanUpDerivedResources())) {
XtextResourceSet _resourceSet_1 = this.context.getResourceSet();
URIConverter _uRIConverter = _resourceSet_1.getURIConverter();
Map<Object, Object> _emptyMap = CollectionLiterals.<Object, Object>emptyMap();
_uRIConverter.delete(generated, _emptyMap);
Procedure1<? super URI> _afterDeleteFile = this.request.getAfterDeleteFile();
_afterDeleteFile.apply(generated);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
_deleteSource.forEach(_function_1);
};
_deletedFiles.forEach(_function);
final Indexer.IndexResult result = this.indexer.computeAndIndexAffected(this.request, this.context);
CancelIndicator _cancelIndicator = this.request.getCancelIndicator();
this._operationCanceledManager.checkCanceled(_cancelIndicator);
final ArrayList<IResourceDescription.Delta> resolvedDeltas = CollectionLiterals.<IResourceDescription.Delta>newArrayList();
List<IResourceDescription.Delta> _resourceDeltas = result.getResourceDeltas();
final Function1<IResourceDescription.Delta, Boolean> _function_1 = (IResourceDescription.Delta it) -> {
IResourceDescription _new = it.getNew();
return Boolean.valueOf(Objects.equal(_new, null));
};
Iterable<IResourceDescription.Delta> _filter = IterableExtensions.<IResourceDescription.Delta>filter(_resourceDeltas, _function_1);
Iterables.<IResourceDescription.Delta>addAll(resolvedDeltas, _filter);
List<IResourceDescription.Delta> _resourceDeltas_1 = result.getResourceDeltas();
final Function1<IResourceDescription.Delta, Boolean> _function_2 = (IResourceDescription.Delta it) -> {
IResourceDescription _new = it.getNew();
return Boolean.valueOf((!Objects.equal(_new, null)));
};
Iterable<IResourceDescription.Delta> _filter_1 = IterableExtensions.<IResourceDescription.Delta>filter(_resourceDeltas_1, _function_2);
final Function1<IResourceDescription.Delta, URI> _function_3 = (IResourceDescription.Delta it) -> {
return it.getUri();
};
Iterable<URI> _map = IterableExtensions.<IResourceDescription.Delta, URI>map(_filter_1, _function_3);
final Function1<Resource, IResourceDescription.Delta> _function_4 = (Resource resource) -> {
CancelIndicator _cancelIndicator_1 = this.request.getCancelIndicator();
this._operationCanceledManager.checkCanceled(_cancelIndicator_1);
resource.getContents();
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
CancelIndicator _cancelIndicator_2 = this.request.getCancelIndicator();
this._operationCanceledManager.checkCanceled(_cancelIndicator_2);
URI _uRI = resource.getURI();
final IResourceServiceProvider serviceProvider = this.context.getResourceServiceProvider(_uRI);
final IResourceDescription.Manager manager = serviceProvider.getResourceDescriptionManager();
final IResourceDescription description = manager.getResourceDescription(resource);
final SerializableResourceDescription copiedDescription = SerializableResourceDescription.createCopy(description);
ResourceDescriptionsData _newIndex = result.getNewIndex();
URI _uRI_1 = resource.getURI();
_newIndex.addDescription(_uRI_1, copiedDescription);
CancelIndicator _cancelIndicator_3 = this.request.getCancelIndicator();
this._operationCanceledManager.checkCanceled(_cancelIndicator_3);
if ((((!this.request.isIndexOnly()) && this.validate(resource)) && serviceProvider.<IShouldGenerate>get(IShouldGenerate.class).shouldGenerate(resource, CancelIndicator.NullImpl))) {
CancelIndicator _cancelIndicator_4 = this.request.getCancelIndicator();
this._operationCanceledManager.checkCanceled(_cancelIndicator_4);
this.generate(resource, this.request, newSource2GeneratedMapping);
}
IndexState _oldState = this.context.getOldState();
ResourceDescriptionsData _resourceDescriptions = _oldState.getResourceDescriptions();
URI _uRI_2 = resource.getURI();
final IResourceDescription old = _resourceDescriptions.getResourceDescription(_uRI_2);
return manager.createDelta(old, copiedDescription);
};
Iterable<IResourceDescription.Delta> _executeClustered = this.context.<IResourceDescription.Delta>executeClustered(_map, _function_4);
Iterables.<IResourceDescription.Delta>addAll(resolvedDeltas, _executeClustered);
IndexState _state_1 = this.request.getState();
return new IncrementalBuilder.Result(_state_1, resolvedDeltas);
}
protected boolean validate(final Resource resource) {
URI _uRI = resource.getURI();
IResourceServiceProvider _resourceServiceProvider = this.context.getResourceServiceProvider(_uRI);
final IResourceValidator resourceValidator = _resourceServiceProvider.getResourceValidator();
boolean _equals = Objects.equal(resourceValidator, null);
if (_equals) {
return true;
}
URI _uRI_1 = resource.getURI();
String _lastSegment = _uRI_1.lastSegment();
String _plus = ("Starting validation for input: \'" + _lastSegment);
String _plus_1 = (_plus + "\'");
IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.info(_plus_1);
final List<Issue> validationResult = resourceValidator.validate(resource, CheckMode.ALL, null);
BuildRequest.IPostValidationCallback _afterValidate = this.request.getAfterValidate();
URI _uRI_2 = resource.getURI();
return _afterValidate.afterValidate(_uRI_2, validationResult);
}
protected void generate(final Resource resource, final BuildRequest request, final Source2GeneratedMapping newMappings) {
URI _uRI = resource.getURI();
final IResourceServiceProvider serviceProvider = this.context.getResourceServiceProvider(_uRI);
final GeneratorDelegate generator = serviceProvider.<GeneratorDelegate>get(GeneratorDelegate.class);
boolean _equals = Objects.equal(generator, null);
if (_equals) {
return;
}
URI _uRI_1 = resource.getURI();
final Set<URI> previous = newMappings.deleteSource(_uRI_1);
URIBasedFileSystemAccess _createFileSystemAccess = this.createFileSystemAccess(serviceProvider, resource);
final Procedure1<URIBasedFileSystemAccess> _function = (URIBasedFileSystemAccess it) -> {
final URIBasedFileSystemAccess.BeforeWrite _function_1 = (URI uri, String outputCfgName, InputStream contents) -> {
URI _uRI_2 = resource.getURI();
newMappings.addSource2Generated(_uRI_2, uri, outputCfgName);
previous.remove(uri);
Procedure2<? super URI, ? super URI> _afterGenerateFile = request.getAfterGenerateFile();
URI _uRI_3 = resource.getURI();
_afterGenerateFile.apply(_uRI_3, uri);
return contents;
};
it.setBeforeWrite(_function_1);
final URIBasedFileSystemAccess.BeforeDelete _function_2 = (URI uri) -> {
newMappings.deleteGenerated(uri);
Procedure1<? super URI> _afterDeleteFile = request.getAfterDeleteFile();
_afterDeleteFile.apply(uri);
return true;
};
it.setBeforeDelete(_function_2);
};
final URIBasedFileSystemAccess fileSystemAccess = ObjectExtensions.<URIBasedFileSystemAccess>operator_doubleArrow(_createFileSystemAccess, _function);
fileSystemAccess.setContext(resource);
boolean _isWriteStorageResources = request.isWriteStorageResources();
if (_isWriteStorageResources) {
boolean _matched = false;
if (resource instanceof StorageAwareResource) {
IResourceStorageFacade _resourceStorageFacade = ((StorageAwareResource)resource).getResourceStorageFacade();
boolean _notEquals = (!Objects.equal(_resourceStorageFacade, null));
if (_notEquals) {
_matched=true;
IResourceStorageFacade _resourceStorageFacade_1 = ((StorageAwareResource)resource).getResourceStorageFacade();
_resourceStorageFacade_1.saveResource(((StorageAwareResource)resource), fileSystemAccess);
}
}
}
final GeneratorContext generatorContext = new GeneratorContext();
CancelIndicator _cancelIndicator = request.getCancelIndicator();
generatorContext.setCancelIndicator(_cancelIndicator);
generator.generate(resource, fileSystemAccess, generatorContext);
final Consumer<URI> _function_1 = (URI it) -> {
try {
IncrementalBuilder.InternalStatefulIncrementalBuilder.LOG.info(("Deleting stale generated file " + it));
XtextResourceSet _resourceSet = this.context.getResourceSet();
URIConverter _uRIConverter = _resourceSet.getURIConverter();
Map<Object, Object> _emptyMap = CollectionLiterals.<Object, Object>emptyMap();
_uRIConverter.delete(it, _emptyMap);
Procedure1<? super URI> _afterDeleteFile = request.getAfterDeleteFile();
_afterDeleteFile.apply(it);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
previous.forEach(_function_1);
}
protected URIBasedFileSystemAccess createFileSystemAccess(final IResourceServiceProvider serviceProvider, final Resource resource) {
URIBasedFileSystemAccess _xblockexpression = null;
{
final IProjectConfigProvider projectConfigProvider = serviceProvider.<IProjectConfigProvider>get(IProjectConfigProvider.class);
IProjectConfig _projectConfig = null;
if (projectConfigProvider!=null) {
ResourceSet _resourceSet = resource.getResourceSet();
_projectConfig=projectConfigProvider.getProjectConfig(_resourceSet);
}
final IProjectConfig projectConfig = _projectConfig;
ISourceFolder _findSourceFolderContaining = null;
if (projectConfig!=null) {
URI _uRI = resource.getURI();
_findSourceFolderContaining=projectConfig.findSourceFolderContaining(_uRI);
}
final ISourceFolder sourceFolder = _findSourceFolderContaining;
URIBasedFileSystemAccess _uRIBasedFileSystemAccess = new URIBasedFileSystemAccess();
final Procedure1<URIBasedFileSystemAccess> _function = (URIBasedFileSystemAccess it) -> {
final IContextualOutputConfigurationProvider outputConfigProvider = serviceProvider.<IContextualOutputConfigurationProvider>get(IContextualOutputConfigurationProvider.class);
Set<OutputConfiguration> _outputConfigurations = outputConfigProvider.getOutputConfigurations(resource);
final Function1<OutputConfiguration, String> _function_1 = (OutputConfiguration it_1) -> {
return it_1.getName();
};
Map<String, OutputConfiguration> _map = IterableExtensions.<String, OutputConfiguration>toMap(_outputConfigurations, _function_1);
it.setOutputConfigurations(_map);
IFilePostProcessor _get = serviceProvider.<IFilePostProcessor>get(IFilePostProcessor.class);
it.setPostProcessor(_get);
final IEncodingProvider newEncodingProvider = serviceProvider.<IEncodingProvider>get(IEncodingProvider.class);
boolean _notEquals = (!Objects.equal(newEncodingProvider, null));
if (_notEquals) {
it.setEncodingProvider(newEncodingProvider);
}
TraceFileNameProvider _get_1 = serviceProvider.<TraceFileNameProvider>get(TraceFileNameProvider.class);
it.setTraceFileNameProvider(_get_1);
TraceRegionSerializer _get_2 = serviceProvider.<TraceRegionSerializer>get(TraceRegionSerializer.class);
it.setTraceRegionSerializer(_get_2);
it.setGenerateTraces(true);
URI _baseDir = this.request.getBaseDir();
it.setBaseDir(_baseDir);
String _name = null;
if (sourceFolder!=null) {
_name=sourceFolder.getName();
}
it.setCurrentSource(_name);
ResourceSet _resourceSet_1 = resource.getResourceSet();
URIConverter _uRIConverter = _resourceSet_1.getURIConverter();
it.setConverter(_uRIConverter);
};
_xblockexpression = ObjectExtensions.<URIBasedFileSystemAccess>operator_doubleArrow(_uRIBasedFileSystemAccess, _function);
}
return _xblockexpression;
}
private final static Logger LOG = Logger.getLogger(InternalStatefulIncrementalBuilder.class);
protected void setContext(final BuildContext context) {
this.context = context;
}
protected void setRequest(final BuildRequest request) {
this.request = request;
}
}
@Inject
private Provider<IncrementalBuilder.InternalStatefulIncrementalBuilder> provider;
@Inject
@Extension
private OperationCanceledManager _operationCanceledManager;
public IncrementalBuilder.Result build(final BuildRequest request, final Function1<? super URI, ? extends IResourceServiceProvider> languages) {
DisabledClusteringPolicy _disabledClusteringPolicy = new DisabledClusteringPolicy();
return this.build(request, languages, _disabledClusteringPolicy);
}
public IncrementalBuilder.Result build(final BuildRequest request, final Function1<? super URI, ? extends IResourceServiceProvider> languages, final IResourceClusteringPolicy clusteringPolicy) {
try {
final XtextResourceSet resourceSet = request.getResourceSet();
IndexState _state = request.getState();
ResourceDescriptionsData _resourceDescriptions = _state.getResourceDescriptions();
ResourceDescriptionsData _copy = _resourceDescriptions.copy();
IndexState _state_1 = request.getState();
Source2GeneratedMapping _fileMappings = _state_1.getFileMappings();
Source2GeneratedMapping _copy_1 = _fileMappings.copy();
final IndexState oldState = new IndexState(_copy, _copy_1);
CancelIndicator _cancelIndicator = request.getCancelIndicator();
final BuildContext context = new BuildContext(languages, resourceSet, oldState, clusteringPolicy, _cancelIndicator);
final IncrementalBuilder.InternalStatefulIncrementalBuilder builder = this.provider.get();
builder.context = context;
builder.request = request;
try {
return builder.launch();
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable)_t;
this._operationCanceledManager.propagateIfCancelException(t);
throw t;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
private final static Logger LOG = Logger.getLogger(IncrementalBuilder.class);
}

View file

@ -0,0 +1,48 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.build;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
import org.eclipse.xtext.build.Source2GeneratedMapping;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.impl.ResourceDescriptionsData;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* @author Sven Efftinge - Initial contribution and API
*/
@FinalFieldsConstructor
@Accessors
@SuppressWarnings("all")
public class IndexState {
private final ResourceDescriptionsData resourceDescriptions;
private final Source2GeneratedMapping fileMappings;
public IndexState() {
this(new ResourceDescriptionsData(CollectionLiterals.<IResourceDescription>emptySet()), new Source2GeneratedMapping());
}
public IndexState(final ResourceDescriptionsData resourceDescriptions, final Source2GeneratedMapping fileMappings) {
super();
this.resourceDescriptions = resourceDescriptions;
this.fileMappings = fileMappings;
}
@Pure
public ResourceDescriptionsData getResourceDescriptions() {
return this.resourceDescriptions;
}
@Pure
public Source2GeneratedMapping getFileMappings() {
return this.fileMappings;
}
}

View file

@ -0,0 +1,350 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.build;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtend.lib.annotations.AccessorType;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtend.lib.annotations.Data;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.build.BuildContext;
import org.eclipse.xtext.build.BuildRequest;
import org.eclipse.xtext.build.IndexState;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.CompilerPhases;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.IReferenceDescription;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceDescriptions;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.resource.impl.AbstractResourceDescription;
import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta;
import org.eclipse.xtext.resource.impl.ResourceDescriptionsData;
import org.eclipse.xtext.service.OperationCanceledManager;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.internal.Log;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
/**
* @author Jan Koehnlein - Initial contribution and API
* @since 2.9
*/
@Log
@SuppressWarnings("all")
public class Indexer {
@Data
public static class IndexResult {
private final List<IResourceDescription.Delta> resourceDeltas;
private final ResourceDescriptionsData newIndex;
public IndexResult(final List<IResourceDescription.Delta> resourceDeltas, final ResourceDescriptionsData newIndex) {
super();
this.resourceDeltas = resourceDeltas;
this.newIndex = newIndex;
}
@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.resourceDeltas== null) ? 0 : this.resourceDeltas.hashCode());
result = prime * result + ((this.newIndex== null) ? 0 : this.newIndex.hashCode());
return result;
}
@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Indexer.IndexResult other = (Indexer.IndexResult) obj;
if (this.resourceDeltas == null) {
if (other.resourceDeltas != null)
return false;
} else if (!this.resourceDeltas.equals(other.resourceDeltas))
return false;
if (this.newIndex == null) {
if (other.newIndex != null)
return false;
} else if (!this.newIndex.equals(other.newIndex))
return false;
return true;
}
@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("resourceDeltas", this.resourceDeltas);
b.add("newIndex", this.newIndex);
return b.toString();
}
@Pure
public List<IResourceDescription.Delta> getResourceDeltas() {
return this.resourceDeltas;
}
@Pure
public ResourceDescriptionsData getNewIndex() {
return this.newIndex;
}
}
@Log
protected static class ResolvedResourceDescription extends AbstractResourceDescription {
@Accessors(AccessorType.PUBLIC_GETTER)
private URI URI;
private ImmutableList<IEObjectDescription> exported;
public ResolvedResourceDescription(final IResourceDescription original) {
URI _uRI = original.getURI();
this.URI = _uRI;
Iterable<IEObjectDescription> _exportedObjects = original.getExportedObjects();
final Function1<IEObjectDescription, IEObjectDescription> _function = (IEObjectDescription from) -> {
EObject _eObjectOrProxy = from.getEObjectOrProxy();
boolean _eIsProxy = _eObjectOrProxy.eIsProxy();
if (_eIsProxy) {
return from;
}
EClass _eClass = from.getEClass();
EObject _create = EcoreUtil.create(_eClass);
InternalEObject result = ((InternalEObject) _create);
URI _eObjectURI = from.getEObjectURI();
result.eSetProxyURI(_eObjectURI);
Map<String, String> userData = null;
String[] _userDataKeys = from.getUserDataKeys();
for (final String key : _userDataKeys) {
{
boolean _equals = Objects.equal(userData, null);
if (_equals) {
HashMap<String, String> _newHashMapWithExpectedSize = Maps.<String, String>newHashMapWithExpectedSize(2);
userData = _newHashMapWithExpectedSize;
}
String _userData = from.getUserData(key);
userData.put(key, _userData);
}
}
QualifiedName _name = from.getName();
return EObjectDescription.create(_name, result, userData);
};
Iterable<IEObjectDescription> _map = IterableExtensions.<IEObjectDescription, IEObjectDescription>map(_exportedObjects, _function);
ImmutableList<IEObjectDescription> _copyOf = ImmutableList.<IEObjectDescription>copyOf(_map);
this.exported = _copyOf;
}
@Override
protected List<IEObjectDescription> computeExportedObjects() {
return this.exported;
}
@Override
public Iterable<QualifiedName> getImportedNames() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("getImportedNames ");
_builder.append(this.URI, "");
IllegalStateException exception = new IllegalStateException(_builder.toString());
Indexer.ResolvedResourceDescription.LOG.error(exception, exception);
return CollectionLiterals.<QualifiedName>emptyList();
}
@Override
public Iterable<IReferenceDescription> getReferenceDescriptions() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("getReferenceDescriptions ");
_builder.append(this.URI, "");
IllegalStateException exception = new IllegalStateException(_builder.toString());
Indexer.ResolvedResourceDescription.LOG.error(exception, exception);
return CollectionLiterals.<IReferenceDescription>emptyList();
}
private final static Logger LOG = Logger.getLogger(ResolvedResourceDescription.class);
@Pure
public URI getURI() {
return this.URI;
}
}
@Inject
private CompilerPhases compilerPhases;
@Inject
@Extension
private OperationCanceledManager _operationCanceledManager;
public Indexer.IndexResult computeAndIndexAffected(final BuildRequest request, @Extension final BuildContext context) {
IndexState _oldState = context.getOldState();
final ResourceDescriptionsData previousIndex = _oldState.getResourceDescriptions();
IndexState _state = request.getState();
final ResourceDescriptionsData newIndex = _state.getResourceDescriptions();
final List<IResourceDescription.Delta> deltas = CollectionLiterals.<IResourceDescription.Delta>newArrayList();
boolean _isInfoEnabled = Indexer.LOG.isInfoEnabled();
if (_isInfoEnabled) {
List<URI> _deletedFiles = request.getDeletedFiles();
Set<URI> _set = IterableExtensions.<URI>toSet(_deletedFiles);
String _plus = ("Creating Deltas for changes. Deleted : " + _set);
String _plus_1 = (_plus + ", Changed : ");
List<URI> _dirtyFiles = request.getDirtyFiles();
Set<URI> _set_1 = IterableExtensions.<URI>toSet(_dirtyFiles);
String _plus_2 = (_plus_1 + _set_1);
String _plus_3 = (_plus_2 + ".");
Indexer.LOG.info(_plus_3);
}
List<IResourceDescription.Delta> _deltasForDeletedResources = this.getDeltasForDeletedResources(request, previousIndex, context);
deltas.addAll(_deltasForDeletedResources);
List<URI> _dirtyFiles_1 = request.getDirtyFiles();
List<IResourceDescription.Delta> _deltasForChangedResources = this.getDeltasForChangedResources(_dirtyFiles_1, previousIndex, context);
deltas.addAll(_deltasForChangedResources);
for (final IResourceDescription.Delta delta : deltas) {
newIndex.register(delta);
}
final HashSet<IResourceDescription.Delta> allDeltas = new HashSet<IResourceDescription.Delta>(deltas);
List<IResourceDescription.Delta> _externalDeltas = request.getExternalDeltas();
boolean _isEmpty = _externalDeltas.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
List<IResourceDescription.Delta> _externalDeltas_1 = request.getExternalDeltas();
allDeltas.addAll(_externalDeltas_1);
}
Iterable<IResourceDescription> _allResourceDescriptions = previousIndex.getAllResourceDescriptions();
final Function1<IResourceDescription, URI> _function = (IResourceDescription it) -> {
return it.getURI();
};
Iterable<URI> _map = IterableExtensions.<IResourceDescription, URI>map(_allResourceDescriptions, _function);
final Set<URI> remainingURIs = IterableExtensions.<URI>toSet(_map);
final Function1<IResourceDescription.Delta, URI> _function_1 = (IResourceDescription.Delta it) -> {
return it.getUri();
};
List<URI> _map_1 = ListExtensions.<IResourceDescription.Delta, URI>map(deltas, _function_1);
remainingURIs.removeAll(_map_1);
final Function1<URI, Boolean> _function_2 = (URI it) -> {
IResourceServiceProvider _resourceServiceProvider = context.getResourceServiceProvider(it);
final IResourceDescription.Manager manager = _resourceServiceProvider.getResourceDescriptionManager();
final IResourceDescription resourceDescription = previousIndex.getResourceDescription(it);
final boolean isAffected = this.isAffected(resourceDescription, manager, allDeltas, allDeltas, newIndex);
return Boolean.valueOf(isAffected);
};
Iterable<URI> _filter = IterableExtensions.<URI>filter(remainingURIs, _function_2);
final List<URI> allAffected = IterableExtensions.<URI>toList(_filter);
if ((Indexer.LOG.isInfoEnabled() && (!allAffected.isEmpty()))) {
Set<URI> _set_2 = IterableExtensions.<URI>toSet(allAffected);
String _plus_4 = ("Creating Deltas for affected resources : " + _set_2);
String _plus_5 = (_plus_4 + ".");
Indexer.LOG.info(_plus_5);
}
List<IResourceDescription.Delta> _deltasForChangedResources_1 = this.getDeltasForChangedResources(allAffected, previousIndex, context);
deltas.addAll(_deltasForChangedResources_1);
return new Indexer.IndexResult(deltas, newIndex);
}
protected List<IResourceDescription.Delta> getDeltasForDeletedResources(final BuildRequest request, final ResourceDescriptionsData oldIndex, @Extension final BuildContext context) {
final ArrayList<IResourceDescription.Delta> deltas = CollectionLiterals.<IResourceDescription.Delta>newArrayList();
List<URI> _deletedFiles = request.getDeletedFiles();
final Function1<URI, Boolean> _function = (URI it) -> {
IResourceServiceProvider _resourceServiceProvider = context.getResourceServiceProvider(it);
return Boolean.valueOf((!Objects.equal(_resourceServiceProvider, null)));
};
Iterable<URI> _filter = IterableExtensions.<URI>filter(_deletedFiles, _function);
final Consumer<URI> _function_1 = (URI it) -> {
CancelIndicator _cancelIndicator = context.getCancelIndicator();
this._operationCanceledManager.checkCanceled(_cancelIndicator);
IResourceDescription _resourceDescription = null;
if (oldIndex!=null) {
_resourceDescription=oldIndex.getResourceDescription(it);
}
final IResourceDescription oldDescription = _resourceDescription;
boolean _notEquals = (!Objects.equal(oldDescription, null));
if (_notEquals) {
final DefaultResourceDescriptionDelta delta = new DefaultResourceDescriptionDelta(oldDescription, null);
deltas.add(delta);
}
};
_filter.forEach(_function_1);
return deltas;
}
protected List<IResourceDescription.Delta> getDeltasForChangedResources(final Iterable<URI> affectedUris, final ResourceDescriptionsData oldIndex, @Extension final BuildContext context) {
try {
XtextResourceSet _resourceSet = context.getResourceSet();
this.compilerPhases.setIndexing(_resourceSet, true);
final Function1<Resource, IResourceDescription.Delta> _function = (Resource it) -> {
return this.addToIndex(it, true, oldIndex, context);
};
Iterable<IResourceDescription.Delta> _executeClustered = context.<IResourceDescription.Delta>executeClustered(affectedUris, _function);
return IterableExtensions.<IResourceDescription.Delta>toList(_executeClustered);
} finally {
XtextResourceSet _resourceSet_1 = context.getResourceSet();
this.compilerPhases.setIndexing(_resourceSet_1, false);
}
}
protected IResourceDescription.Delta addToIndex(final Resource resource, final boolean isPreIndexing, final ResourceDescriptionsData oldIndex, final BuildContext context) {
CancelIndicator _cancelIndicator = context.getCancelIndicator();
this._operationCanceledManager.checkCanceled(_cancelIndicator);
final URI uri = resource.getURI();
final IResourceServiceProvider serviceProvider = context.getResourceServiceProvider(uri);
final IResourceDescription.Manager manager = serviceProvider.getResourceDescriptionManager();
final IResourceDescription newDescription = manager.getResourceDescription(resource);
final IResourceDescription toBeAdded = new Indexer.ResolvedResourceDescription(newDescription);
IResourceDescription _resourceDescription = null;
if (oldIndex!=null) {
_resourceDescription=oldIndex.getResourceDescription(uri);
}
final IResourceDescription.Delta delta = manager.createDelta(_resourceDescription, toBeAdded);
return delta;
}
protected boolean isAffected(final IResourceDescription affectionCandidate, final IResourceDescription.Manager manager, final Collection<IResourceDescription.Delta> newDeltas, final Collection<IResourceDescription.Delta> allDeltas, final IResourceDescriptions resourceDescriptions) {
if ((manager instanceof IResourceDescription.Manager.AllChangeAware)) {
return ((IResourceDescription.Manager.AllChangeAware)manager).isAffectedByAny(allDeltas, affectionCandidate, resourceDescriptions);
} else {
boolean _isEmpty = newDeltas.isEmpty();
if (_isEmpty) {
return false;
} else {
return manager.isAffected(newDeltas, affectionCandidate, resourceDescriptions);
}
}
}
private final static Logger LOG = Logger.getLogger(Indexer.class);
}

View file

@ -0,0 +1,174 @@
/**
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.xtext.build;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.ExclusiveRange;
/**
* @author Jan Koehnlein - Initial contribution and API
*/
@FinalFieldsConstructor
@SuppressWarnings("all")
public class Source2GeneratedMapping implements Externalizable {
private final Multimap<URI, URI> source2generated;
private final Multimap<URI, URI> generated2source;
private final Map<URI, String> generated2OutputConfigName;
public Source2GeneratedMapping() {
this(HashMultimap.<URI, URI>create(), HashMultimap.<URI, URI>create(), CollectionLiterals.<URI, String>newHashMap());
}
public Source2GeneratedMapping copy() {
HashMultimap<URI, URI> _create = HashMultimap.<URI, URI>create(this.source2generated);
HashMultimap<URI, URI> _create_1 = HashMultimap.<URI, URI>create(this.generated2source);
HashMap<URI, String> _hashMap = new HashMap<URI, String>(this.generated2OutputConfigName);
return new Source2GeneratedMapping(_create, _create_1, _hashMap);
}
public void addSource2Generated(final URI source, final URI generated) {
this.addSource2Generated(source, generated, IFileSystemAccess.DEFAULT_OUTPUT);
}
public void addSource2Generated(final URI source, final URI generated, final String outputCfgName) {
this.source2generated.put(source, generated);
this.generated2source.put(generated, source);
this.generated2OutputConfigName.put(generated, outputCfgName);
}
public void removeSource2Generated(final URI source, final URI generated) {
this.source2generated.remove(source, generated);
this.generated2source.remove(generated, source);
}
public Set<URI> deleteSource(final URI source) {
Collection<URI> _removeAll = this.source2generated.removeAll(source);
final HashSet<URI> generated = new HashSet<URI>(_removeAll);
final Consumer<URI> _function = (URI it) -> {
this.generated2source.remove(it, source);
};
generated.forEach(_function);
return generated;
}
public void deleteGenerated(final URI generated) {
Collection<URI> _removeAll = this.generated2source.removeAll(generated);
final Consumer<URI> _function = (URI it) -> {
this.source2generated.remove(it, generated);
};
_removeAll.forEach(_function);
this.generated2OutputConfigName.remove(generated);
}
public String getOutputConfigName(final URI generated) {
return this.generated2OutputConfigName.get(generated);
}
public List<URI> getGenerated(final URI source) {
Collection<URI> _get = this.source2generated.get(source);
return Lists.<URI>newArrayList(_get);
}
public List<URI> getSource(final URI generated) {
Collection<URI> _get = this.generated2source.get(generated);
return Lists.<URI>newArrayList(_get);
}
public List<URI> getAllGenerated() {
Set<URI> _keySet = this.generated2source.keySet();
return Lists.<URI>newArrayList(_keySet);
}
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
final int numEntries = in.readInt();
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, numEntries, true);
for (final Integer i : _doubleDotLessThan) {
{
String _readUTF = in.readUTF();
final URI source = URI.createURI(_readUTF);
final int numGenerated = in.readInt();
ExclusiveRange _doubleDotLessThan_1 = new ExclusiveRange(0, numGenerated, true);
for (final Integer j : _doubleDotLessThan_1) {
{
String _readUTF_1 = in.readUTF();
final URI generated = URI.createURI(_readUTF_1);
final String outputConfig = in.readUTF();
this.addSource2Generated(source, generated, outputConfig);
}
}
}
}
}
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
Map<URI, Collection<URI>> _asMap = this.source2generated.asMap();
final Set<Map.Entry<URI, Collection<URI>>> entries = _asMap.entrySet();
int _size = entries.size();
out.writeInt(_size);
final Consumer<Map.Entry<URI, Collection<URI>>> _function = (Map.Entry<URI, Collection<URI>> it) -> {
try {
URI _key = it.getKey();
String _string = _key.toString();
out.writeUTF(_string);
Collection<URI> _value = it.getValue();
int _size_1 = _value.size();
out.writeInt(_size_1);
Collection<URI> _value_1 = it.getValue();
final Consumer<URI> _function_1 = (URI it_1) -> {
try {
String _string_1 = it_1.toString();
out.writeUTF(_string_1);
String _elvis = null;
String _get = this.generated2OutputConfigName.get(it_1);
if (_get != null) {
_elvis = _get;
} else {
_elvis = IFileSystemAccess.DEFAULT_OUTPUT;
}
out.writeUTF(_elvis);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
_value_1.forEach(_function_1);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
};
entries.forEach(_function);
}
public Source2GeneratedMapping(final Multimap<URI, URI> source2generated, final Multimap<URI, URI> generated2source, final Map<URI, String> generated2OutputConfigName) {
super();
this.source2generated = source2generated;
this.generated2source = generated2source;
this.generated2OutputConfigName = generated2OutputConfigName;
}
}