use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class XtendBatchCompiler method compile.
public boolean compile() {
try {
if (!checkConfiguration()) {
return false;
}
ResourceSet resourceSet = resourceSetProvider.get();
if (!configureWorkspace(resourceSet)) {
return false;
}
generatorConfigProvider.install(resourceSet, generatorConfig);
File classDirectory = createTempDir("classes");
try {
compilerPhases.setIndexing(resourceSet, true);
// install a type provider without index lookup for the first phase
installJvmTypeProvider(resourceSet, classDirectory, true);
loadXtendFiles(resourceSet);
File sourceDirectory = createStubs(resourceSet);
if (!preCompileStubs(sourceDirectory, classDirectory)) {
log.warn("Compilation of stubs had errors.");
}
if (!preCompileJava(sourceDirectory, classDirectory)) {
log.debug("Compilation of Java code against stubs had errors. This is expected and usually is not a probblem.");
}
} finally {
compilerPhases.setIndexing(resourceSet, false);
}
// install a fresh type provider for the second phase, so we clear all previously cached classes and misses.
installJvmTypeProvider(resourceSet, classDirectory, false);
List<Resource> toBeResolved = new ArrayList<>(resourceSet.getResources().size());
for (Resource resource : resourceSet.getResources()) {
if (isSourceFile(resource)) {
toBeResolved.add(resource);
}
}
for (Resource resource : toBeResolved) {
EcoreUtil.resolveAll(resource);
}
List<Issue> issues = validate(resourceSet);
Iterable<Issue> errors = Iterables.filter(issues, SeverityFilter.ERROR);
Iterable<Issue> warnings = Iterables.filter(issues, SeverityFilter.WARNING);
reportIssues(Iterables.concat(errors, warnings));
if (!Iterables.isEmpty(errors)) {
return false;
}
generateJavaFiles(resourceSet);
} finally {
destroyClassLoader(jvmTypesClassLoader);
destroyClassLoader(annotationProcessingClassLoader);
if (isDeleteTempDirectory()) {
deleteTmpFolders();
}
}
return true;
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class XtendRenameContextFactory method createLocalRenameElementContext.
@Override
public IRenameElementContext createLocalRenameElementContext(EObject targetElement, XtextEditor editor, ITextSelection selection, XtextResource resource) {
EObject declarationTarget = getDeclarationTarget(targetElement);
if (declarationTarget instanceof XtendFunction && ((XtendFunction) declarationTarget).isDispatch()) {
IProject project = projectUtil.getProject(declarationTarget.eResource().getURI());
ResourceSet resourceSet = resourceSetProvider.get(project);
XtendFunction relaodedDispatchFunction = (XtendFunction) resourceSet.getEObject(EcoreUtil2.getPlatformResourceOrNormalizedURI(declarationTarget), true);
Iterable<JvmOperation> allDispatchOperations = dispatchRenameSupport.getAllDispatchOperations(relaodedDispatchFunction);
Map<URI, IJavaElement> jvm2javaElement = newLinkedHashMap();
for (JvmOperation jvmOperation : allDispatchOperations) {
IJavaElement javaElement = getJavaElementFinder().findExactElementFor(jvmOperation);
if (javaElement != null) {
URI jvmOperationURI = EcoreUtil.getURI(jvmOperation);
jvm2javaElement.put(jvmOperationURI, javaElement);
}
}
if (!jvm2javaElement.isEmpty()) {
return new DispatchMethodRenameContext(relaodedDispatchFunction, jvm2javaElement, editor, selection, resource);
}
}
return super.createLocalRenameElementContext(targetElement, editor, selection, resource);
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class JdtBasedProcessorProvider method getClassLoader.
@Override
public ClassLoader getClassLoader(final EObject ctx) {
ResourceSet _resourceSet = ctx.eResource().getResourceSet();
final XtextResourceSet rs = ((XtextResourceSet) _resourceSet);
final boolean isBuilder = ResourceSetContext.get(rs).isBuilder();
final boolean isEditor = ResourceSetContext.get(rs).isEditor();
if (isBuilder) {
final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(rs.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
if ((adapter != null)) {
return adapter.getClassLoader();
}
}
if (isEditor) {
final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter_1 = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(this.getEditorResource(ctx).eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
if ((adapter_1 != null)) {
ClassLoader _classLoader = adapter_1.getClassLoader();
boolean _tripleEquals = (_classLoader == null);
if (_tripleEquals) {
this.getEditorResource(ctx).eAdapters().remove(adapter_1);
} else {
return adapter_1.getClassLoader();
}
}
}
Object _classpathURIContext = rs.getClasspathURIContext();
final IJavaProject project = ((IJavaProject) _classpathURIContext);
final URLClassLoader classloader = this.createClassLoaderForJavaProject(project);
if (isBuilder) {
EList<Adapter> _eAdapters = rs.eAdapters();
ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
_eAdapters.add(_processorClassloaderAdapter);
}
if (isEditor) {
EList<Adapter> _eAdapters_1 = this.getEditorResource(ctx).eAdapters();
ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter_1 = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
_eAdapters_1.add(_processorClassloaderAdapter_1);
}
return classloader;
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class FormatterResourceProvider method createResource.
@Override
public XtextResource createResource() {
ResourceSet resourceSet = resourceSetProvider.get(null);
@SuppressWarnings("restriction") XtextResource result = (XtextResource) resourceSet.createResource(URI.createURI(org.eclipse.xtext.ui.codetemplates.ui.preferences.TemplateResourceProvider.SYNTHETIC_SCHEME + ":/" + "FormatterPreview.xtend"));
result.setValidationDisabled(true);
return result;
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class DispatchRenameSupport method getAllDispatchOperations.
/**
* Returns all operations of the declaring type that have to be renamed with the given Xtend function. I.e. all
* dispatch functions with the same name of all sub- and super types as well as the artificial dispatchers.
*
* The method will likely load all subtypes into the resource set of the dispatch function, so you might want to
* hand in a reloaded instance instead.
*/
public Iterable<JvmOperation> getAllDispatchOperations(XtendFunction dispatchFunction) {
Assert.isLegal(dispatchFunction.isDispatch());
IProject project = projectUtil.getProject(dispatchFunction.eResource().getURI());
final ResourceSet tempResourceSet = resourceSetProvider.get(project);
JvmOperation localDispatcher = associations.getDispatchOperation(dispatchFunction);
XtendClass xtendClass = (XtendClass) dispatchFunction.eContainer();
final Set<JvmOperation> dispatchCases = newLinkedHashSet();
IAcceptor<JvmOperation> operationAcceptor = new IAcceptor<JvmOperation>() {
@Override
public void accept(JvmOperation operation) {
dispatchCases.add(operation);
}
};
final Set<JvmGenericType> processedTypes = newHashSet();
addDispatcher(associations.getInferredType(xtendClass), new DispatchHelper.DispatchSignature(localDispatcher.getSimpleName(), localDispatcher.getParameters().size()), operationAcceptor, processedTypes, tempResourceSet);
return dispatchCases;
}
Aggregations