use of org.eclipse.xtext.xbase.resource.BatchLinkableResource in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method infer.
@Override
public void infer(/* @Nullable */
EObject object, final /* @NonNull */
IJvmDeclaredTypeAcceptor acceptor, boolean preIndexingPhase) {
if (!(object instanceof XtendFile))
return;
final Set<JvmDeclaredType> types = new LinkedHashSet<JvmDeclaredType>();
final IJvmDeclaredTypeAcceptor wrapper = new IJvmDeclaredTypeAcceptor() {
@SuppressWarnings("deprecation")
@Override
public <T extends JvmDeclaredType> IPostIndexingInitializing<T> accept(T type) {
types.add(type);
return acceptor.accept(type);
}
@Override
public <T extends JvmDeclaredType> void accept(T type, Procedure1<? super T> lateInitialization) {
types.add(type);
acceptor.accept(type, lateInitialization);
}
};
final XtendFile xtendFile = (XtendFile) object;
generatorConfig = generatorConfigProvider.get(xtendFile);
final List<Runnable> doLater = newArrayList();
for (final XtendTypeDeclaration declaration : xtendFile.getXtendTypes()) {
inferTypeSceleton(declaration, wrapper, preIndexingPhase, xtendFile, doLater, null);
}
ActiveAnnotationContexts contexts = null;
BatchLinkableResource resource = (BatchLinkableResource) xtendFile.eResource();
try {
compilerPhases.setIndexing(xtendFile, true);
try {
contexts = contextProvider.computeContext(xtendFile);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
logger.error("Couldn't create annotation contexts", t);
return;
}
try {
contexts.before(ActiveAnnotationContexts.AnnotationCallback.INDEXING);
for (ActiveAnnotationContext ctx : contexts.getContexts().values()) {
try {
annotationProcessor.indexingPhase(ctx, wrapper, CancelIndicator.NullImpl);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
ctx.handleProcessingError(xtendFile.eResource(), t);
}
}
} finally {
contexts.after(ActiveAnnotationContexts.AnnotationCallback.INDEXING);
}
} finally {
compilerPhases.setIndexing(xtendFile, false);
resource.getCache().clear(resource);
}
if (!preIndexingPhase) {
final ActiveAnnotationContexts finalContexts = contexts;
Runnable lateInit = new Runnable() {
@Override
public void run() {
for (Runnable runnable : doLater) {
runnable.run();
}
try {
finalContexts.before(ActiveAnnotationContexts.AnnotationCallback.INFERENCE);
for (ActiveAnnotationContext ctx : finalContexts.getContexts().values()) {
try {
annotationProcessor.inferencePhase(ctx, CancelIndicator.NullImpl);
} catch (Throwable t) {
operationCanceledManager.propagateAsErrorIfCancelException(t);
ctx.handleProcessingError(xtendFile.eResource(), t);
}
}
} finally {
finalContexts.after(ActiveAnnotationContexts.AnnotationCallback.INFERENCE);
}
}
};
resource.addJvmMemberInitializer(lateInit);
}
}
use of org.eclipse.xtext.xbase.resource.BatchLinkableResource in project xtext-xtend by eclipse.
the class ResourceStorageTest method testFailedWrite.
@Test(expected = IOException.class)
public void testFailedWrite() throws Exception {
final XtendFile file = this.file("class C{}");
ByteArrayOutputStream _byteArrayOutputStream = new ByteArrayOutputStream();
Resource _eResource = file.eResource();
new BatchLinkableResourceStorageWritable(_byteArrayOutputStream, false) {
@Override
protected void writeAssociationsAdapter(final BatchLinkableResource resource, final OutputStream zipOut) throws IOException {
final Function1<Adapter, Boolean> _function = (Adapter it) -> {
return Boolean.valueOf((it instanceof JvmModelAssociator.Adapter));
};
final Adapter removeMe = IterableExtensions.<Adapter>findFirst(resource.eAdapters(), _function);
Assert.assertTrue(resource.eAdapters().remove(removeMe));
super.writeAssociationsAdapter(resource, zipOut);
}
}.writeResource(((StorageAwareResource) _eResource));
}
use of org.eclipse.xtext.xbase.resource.BatchLinkableResource in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testNonConstant.
@Test
public void testNonConstant() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("public static final Class<?> REF = D.testFoo;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class D {");
_builder.newLine();
_builder.append("\t");
_builder.append("public static final Class<?> testFoo = Object");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
Resource _eResource = file.eResource();
((BatchLinkableResource) _eResource).resolveLazyCrossReferences(null);
final XtendField field = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
try {
this.interpreter.evaluate(field.getInitialValue(), field.getType());
Assert.fail("exception expected");
} catch (final Throwable _t) {
if (_t instanceof ConstantExpressionEvaluationException) {
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations