Search in sources :

Example 46 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.

the class AbstractXtendTestCase method files.

protected Iterable<XtendFile> files(boolean validate, String... contents) throws Exception {
    XtextResourceSet set = getResourceSet();
    List<XtendFile> result = newArrayList();
    for (String string : contents) {
        String fileName = getFileName(string);
        Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
        resource.load(new StringInputStream(string), null);
        assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    }
    for (Resource resource : new ArrayList<Resource>(set.getResources())) {
        XtendFile file = (XtendFile) resource.getContents().get(0);
        result.add(file);
    }
    if (validate) {
        for (XtendFile file : result) {
            List<Issue> issues = ((XtextResource) file.eResource()).getResourceServiceProvider().getResourceValidator().validate(file.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
            assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
        }
    }
    return result;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) Issue(org.eclipse.xtext.validation.Issue) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 47 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.

the class AbstractXtendTestCase method fileWithErrors.

protected XtendFile fileWithErrors(String string) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string), null);
    assertTrue(resource.getErrors().toString(), resource.getErrors().size() > 0);
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 48 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.

the class JavaLinkingTest method testGetXtendClassAsArray.

@Test
public void testGetXtendClassAsArray() throws Exception {
    IFile xtendFile = testHelper.createFile("test/XtendClass", "package test\nclass XtendClass {}");
    waitForBuild();
    assertNumberOfMarkers(xtendFile, 0);
    ResourceSet resourceSet = resourceSetProvider.get(testHelper.getProject());
    IJvmTypeProvider jvmTypeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
    JvmType xtendArrayType = jvmTypeProvider.findTypeByName("test.XtendClass[][]");
    assertNotNull(xtendArrayType);
    assertTrue(xtendArrayType instanceof JvmArrayType);
    assertEquals("test.XtendClass[][]", xtendArrayType.getQualifiedName());
    Resource xtendResource = xtendArrayType.eResource();
    assertEquals("platform:/resource" + xtendFile.getFullPath(), xtendResource.getURI().toString());
}
Also used : IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 49 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.

the class JavaLinkingTest method testNavigateToXtendClassArray.

@Test
public void testNavigateToXtendClassArray() throws Exception {
    IFile xtendFile = testHelper.createFile("test/XtendClass", "package test\nclass XtendClass {}");
    IFile javaFile = testHelper.createFileImpl(WorkbenchTestHelper.TESTPROJECT_NAME + "/src/test/JavaClass.java", "package test;\npublic class JavaClass extends java.util.ArrayList<XtendClass[]> {}");
    waitForBuild();
    assertNumberOfMarkers(xtendFile, 0);
    assertNumberOfMarkers(javaFile, 0);
    ResourceSet resourceSet = resourceSetProvider.get(testHelper.getProject());
    IJvmTypeProvider jvmTypeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
    JvmType javaType = jvmTypeProvider.findTypeByName("test.JavaClass");
    assertNotNull(javaType);
    assertTrue(javaType instanceof JvmDeclaredType);
    JvmDeclaredType declaredJavaType = (JvmDeclaredType) javaType;
    JvmParameterizedTypeReference arrayList = (JvmParameterizedTypeReference) declaredJavaType.getSuperTypes().get(0);
    JvmTypeReference arrayReference = arrayList.getArguments().get(0);
    assertTrue(arrayReference instanceof JvmGenericArrayTypeReference);
    JvmType arrayType = arrayReference.getType();
    assertTrue(arrayType instanceof JvmArrayType);
    JvmType xtendType = ((JvmArrayType) arrayType).getComponentType();
    assertNotNull(xtendType);
    assertEquals("test.XtendClass", xtendType.getQualifiedName());
    Resource xtendResource = xtendType.eResource();
    assertEquals("platform:/resource" + xtendFile.getFullPath(), xtendResource.getURI().toString());
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) IFile(org.eclipse.core.resources.IFile) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) Resource(org.eclipse.emf.ecore.resource.Resource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 50 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.

the class JvmElementAtOffsetHelperTest method testdeclaration.

@Test
public void testdeclaration() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class TestCase {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def fo|o(String a){");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("bar(a)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(String a){}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String content = _builder.toString();
        final XtendFile file = this.file(content.replace("|", ""));
        Resource _eResource = file.eResource();
        JvmIdentifiableElement jvmIdentifiableElement = this.jvmElementAtOffsetHelper.getJvmIdentifiableElement(((XtextResource) _eResource), content.indexOf("|"));
        Assert.assertTrue((jvmIdentifiableElement instanceof JvmOperation));
        Assert.assertEquals("testPackage.TestCase.foo", jvmIdentifiableElement.getQualifiedName());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

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