mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
Bug 477068 generator2 should expose a CancelIndicator
This commit is contained in:
parent
8aa96eeb3a
commit
7dfaaf17d8
5 changed files with 34 additions and 38 deletions
|
@ -138,9 +138,7 @@ import org.eclipse.xtext.workspace.IProjectConfigProvider
|
|||
}
|
||||
}
|
||||
}
|
||||
generator.beforeGenerate(resource, fileSystemAccess)
|
||||
generator.doGenerate(resource, fileSystemAccess)
|
||||
generator.afterGenerate(resource, fileSystemAccess)
|
||||
generator.generate(resource, fileSystemAccess, request.cancelIndicator)
|
||||
// delete everything that was previously generated, but not this time
|
||||
previous.forEach[
|
||||
LOG.info('Deleting stale generated file ' + it)
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.emf.ecore.resource.Resource;
|
|||
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent;
|
||||
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext;
|
||||
import org.eclipse.xtext.ISetup;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Injector;
|
||||
|
@ -127,7 +128,7 @@ public class GeneratorComponent implements IWorkflowComponent {
|
|||
if (!(object2 instanceof Resource)) {
|
||||
throw new IllegalStateException("Slot contents was not a Resource but a '"+object.getClass().getSimpleName()+"'!");
|
||||
}
|
||||
instance.generate((Resource) object2, fileSystemAccess);
|
||||
instance.generate((Resource) object2, fileSystemAccess, CancelIndicator.NullImpl);
|
||||
}
|
||||
} else if (object instanceof Resource) {
|
||||
instance.doGenerate((Resource) object, fileSystemAccess);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
package org.eclipse.xtext.generator;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
@ -26,36 +27,36 @@ public class GeneratorDelegate implements IGenerator, IGenerator2 {
|
|||
public IGenerator getLegacyGenerator() {
|
||||
return legacyGenerator;
|
||||
}
|
||||
|
||||
public void generate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) {
|
||||
try {
|
||||
beforeGenerate(input, fsa, cancelIndicator);
|
||||
doGenerate(input, fsa, cancelIndicator);
|
||||
} finally {
|
||||
afterGenerate(input, fsa, cancelIndicator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGenerate(Resource input, IFileSystemAccess2 fsa) {
|
||||
public void doGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) {
|
||||
if (generator != null) {
|
||||
generator.doGenerate(input, fsa);
|
||||
generator.doGenerate(input, fsa, cancelIndicator);
|
||||
} else if (getLegacyGenerator() != null) {
|
||||
getLegacyGenerator().doGenerate(input, fsa);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeGenerate(Resource input, IFileSystemAccess2 fsa) {
|
||||
public void beforeGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) {
|
||||
if (generator != null) {
|
||||
generator.beforeGenerate(input, fsa);
|
||||
generator.beforeGenerate(input, fsa, cancelIndicator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterGenerate(Resource input, IFileSystemAccess2 fsa) {
|
||||
public void afterGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) {
|
||||
if (generator != null) {
|
||||
generator.afterGenerate(input, fsa);
|
||||
}
|
||||
}
|
||||
|
||||
public void generate(Resource input, IFileSystemAccess2 fsa) {
|
||||
try {
|
||||
beforeGenerate(input, fsa);
|
||||
doGenerate(input, fsa);
|
||||
} finally {
|
||||
afterGenerate(input, fsa);
|
||||
generator.afterGenerate(input, fsa, cancelIndicator);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,11 +64,10 @@ public class GeneratorDelegate implements IGenerator, IGenerator2 {
|
|||
public void doGenerate(Resource input, IFileSystemAccess fsa) {
|
||||
IFileSystemAccess2 casted = (IFileSystemAccess2) fsa;
|
||||
try {
|
||||
beforeGenerate(input, casted);
|
||||
doGenerate(input, casted);
|
||||
beforeGenerate(input, casted, CancelIndicator.NullImpl);
|
||||
doGenerate(input, casted, CancelIndicator.NullImpl);
|
||||
} finally {
|
||||
afterGenerate(input, casted);
|
||||
afterGenerate(input, casted, CancelIndicator.NullImpl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,16 +8,17 @@
|
|||
package org.eclipse.xtext.generator;
|
||||
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
|
||||
/**
|
||||
* Replacement interface for the {@link IGenerator} that adds support for parallel code generation.
|
||||
*
|
||||
* Clients of {@link IGenerator} that want to perform the code generation in the background will check for this
|
||||
* extension interface and use {@link #beforeGenerate(Resource, IFileSystemAccess2)} to prepare the resource set. That
|
||||
* extension interface and use {@link #beforeGenerate(Resource, IFileSystemAccess2, CancelIndicator)} to prepare the resource set. That
|
||||
* is, implementors may alter the state of the resource set in the before hook. This may happen implicitly by resolving
|
||||
* proxies or explicitly by loading new resources into the resource set. No changes are allowed while
|
||||
* {@link #doGenerate(Resource, IFileSystemAccess2)} is executed since this may be parallelized by the caller. The
|
||||
* {@link #afterGenerate(Resource, IFileSystemAccess2)} is used to cleanup state. Also access to the file system is
|
||||
* {@link #doGenerate(Resource, IFileSystemAccess2, CancelIndicator)} is executed since this may be parallelized by the caller. The
|
||||
* {@link #afterGenerate(Resource, IFileSystemAccess2, CancelIndicator)} is used to cleanup state. Also access to the file system is
|
||||
* guaranteed to be synchronous in the before and after hook.
|
||||
*
|
||||
* @author Sebastian Zarnekow - Initial contribution and API
|
||||
|
@ -32,24 +33,19 @@ public interface IGenerator2 {
|
|||
* are non-blocking if the given fsa is implementing that pattern.
|
||||
* Read operations will happen in the background but
|
||||
* are blocking.
|
||||
*
|
||||
* @param input
|
||||
* the input for which to generate artefacts
|
||||
* @param fsa
|
||||
* file system access to be used to generate files
|
||||
*/
|
||||
void doGenerate(Resource input, IFileSystemAccess2 fsa);
|
||||
void doGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator);
|
||||
|
||||
/**
|
||||
* Before the generation is triggered, the resource or the entire resource set
|
||||
* may be prepared such that no modification will happen while {@link #doGenerate(Resource, IFileSystemAccess2)}
|
||||
* may be prepared such that no modification will happen while {@link #doGenerate(Resource, IFileSystemAccess2, CancelIndicator)}
|
||||
* is executed.
|
||||
*/
|
||||
void beforeGenerate(Resource input, IFileSystemAccess2 fsa);
|
||||
void beforeGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator);
|
||||
|
||||
/**
|
||||
* Release any data that is no longer necessary after the generator ran.
|
||||
*/
|
||||
void afterGenerate(Resource input, IFileSystemAccess2 fsa);
|
||||
void afterGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,13 +4,14 @@ import org.eclipse.emf.ecore.resource.Resource
|
|||
import org.eclipse.xtext.generator.IFileSystemAccess2
|
||||
import org.eclipse.xtext.generator.IGenerator2
|
||||
import org.eclipse.xtext.index.indexTestLanguage.Entity
|
||||
import org.eclipse.xtext.util.CancelIndicator
|
||||
|
||||
class IndexTestLanguageGenerator implements IGenerator2 {
|
||||
|
||||
override beforeGenerate(Resource input, IFileSystemAccess2 fsa) {
|
||||
override beforeGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) {
|
||||
}
|
||||
|
||||
override doGenerate(Resource input, IFileSystemAccess2 fsa) {
|
||||
override doGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) {
|
||||
val iter = input.allContents
|
||||
while (iter.hasNext) {
|
||||
switch e : iter.next {
|
||||
|
@ -22,7 +23,7 @@ class IndexTestLanguageGenerator implements IGenerator2 {
|
|||
}
|
||||
}
|
||||
|
||||
override afterGenerate(Resource input, IFileSystemAccess2 fsa) {
|
||||
override afterGenerate(Resource input, IFileSystemAccess2 fsa, CancelIndicator cancelIndicator) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue