use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class XtendResourceSetBasedResourceDescriptionsTest method testBidirectionalRef.
@Test
public void testBidirectionalRef() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo class ClassA extends bar.ClassB {}");
Pair<String, String> _mappedTo = Pair.<String, String>of("foo/ClassA.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package bar class ClassB { public foo.ClassA myField }");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("bar/ClassB.xtend", _builder_1.toString());
final ResourceSet resourceSet = this.compiler.resourceSet(_mappedTo, _mappedTo_1);
final List<? extends Resource> resources = resourceSet.getResources();
ArrayList<Resource> _arrayList = new ArrayList<Resource>(resources);
for (final Resource res : _arrayList) {
{
final List<Issue> issues = this.validator.validate(res, CheckMode.ALL, CancelIndicator.NullImpl);
Assert.assertTrue(issues.toString(), issues.isEmpty());
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class ValueConverterExceptionProducesErrorTest method testUnclosedTerminal_01.
@Test
public void testUnclosedTerminal_01() throws Exception {
final Resource resource = this.toResource("class C { def m() \'\'\'");
Assert.assertEquals(1, resource.getErrors().size());
final Resource.Diagnostic error = IterableExtensions.<Resource.Diagnostic>head(resource.getErrors());
Assert.assertNotNull(error);
Assert.assertEquals("String literal is not closed", error.getMessage());
this.assertLiteral("", resource);
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class ValueConverterExceptionProducesErrorTest method testUnclosedTerminal_02.
@Test
public void testUnclosedTerminal_02() throws Exception {
final Resource resource = this.toResource("class C { def m() \'\'\'abc");
Assert.assertEquals(1, resource.getErrors().size());
final Resource.Diagnostic error = IterableExtensions.<Resource.Diagnostic>head(resource.getErrors());
Assert.assertNotNull(error);
Assert.assertEquals("String literal is not closed", error.getMessage());
this.assertLiteral("abc", resource);
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class XtendCompilerErrorHandlingTest method assertCompilesTo.
public void assertCompilesTo(final CharSequence input, final CharSequence expected, final boolean shouldBeSyntacticallyValid) {
try {
final XtendFile file = this.file(input.toString(), false, shouldBeSyntacticallyValid);
final Resource resource = file.eResource();
try {
this.issueProviderFactory.attachData(resource);
final JvmDeclaredType inferredType = IterableExtensions.<JvmDeclaredType>head(Iterables.<JvmDeclaredType>filter(resource.getContents(), JvmDeclaredType.class));
CharSequence javaCode = this.generator.generateType(inferredType, this.generatorConfigProvider.get(inferredType));
javaCode = this.postProcessor.postProcess(null, javaCode);
Assert.assertEquals(expected.toString(), javaCode.toString());
} finally {
this.issueProviderFactory.detachData(resource);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class TestCaseCompiler method compile.
public void compile(String qualifiedName) throws IOException {
ResourceSet set = injector.getInstance(ResourceSet.class);
final String from = "src/" + qualifiedName.replace('.', '/') + ".xtend";
final String to = "src-gen/" + qualifiedName.replace('.', '/') + ".java";
Resource res = set.getResource(org.eclipse.emf.common.util.URI.createFileURI(from), true);
EcoreUtil.resolveAll(res);
if (!res.getErrors().isEmpty())
throw new RuntimeException(res.getErrors().toString());
final File file = new File(to);
createFolders(file);
FileWriter writer = new FileWriter(file);
IXtendJvmAssociations associations = injector.getInstance(IXtendJvmAssociations.class);
JvmModelGenerator generator = injector.getInstance(JvmModelGenerator.class);
XtendFile xtendFile = (XtendFile) res.getContents().get(0);
JvmGenericType inferredType = associations.getInferredType((XtendClass) xtendFile.getXtendTypes().get(0));
GeneratorConfig config = injector.getInstance(IGeneratorConfigProvider.class).get(inferredType);
CharSequence javaCode = generator.generateType(inferredType, config);
writer.append(javaCode);
writer.close();
System.out.println("compiled " + from + " to " + to);
}
Aggregations