Search in sources :

Example 66 with Resource

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);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.Test)

Example 67 with Resource

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);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Test(org.junit.Test)

Example 68 with 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);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) Test(org.junit.Test)

Example 69 with 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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) Resource(org.eclipse.emf.ecore.resource.Resource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 70 with Resource

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);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmModelGenerator(org.eclipse.xtext.xbase.compiler.JvmModelGenerator) FileWriter(java.io.FileWriter) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) IGeneratorConfigProvider(org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider) IXtendJvmAssociations(org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations) File(java.io.File) XtendFile(org.eclipse.xtend.core.xtend.XtendFile)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)448 Test (org.junit.Test)210 XtextResource (org.eclipse.xtext.resource.XtextResource)157 EObject (org.eclipse.emf.ecore.EObject)109 URI (org.eclipse.emf.common.util.URI)85 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)76 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)71 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)66 StringInputStream (org.eclipse.xtext.util.StringInputStream)50 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)45 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)36 IOException (java.io.IOException)26 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)24 List (java.util.List)23 EClass (org.eclipse.emf.ecore.EClass)23 EPackage (org.eclipse.emf.ecore.EPackage)23 InternalEObject (org.eclipse.emf.ecore.InternalEObject)23 DerivedStateAwareResource (org.eclipse.xtext.resource.DerivedStateAwareResource)21 ArrayList (java.util.ArrayList)19 IFile (org.eclipse.core.resources.IFile)18