Search in sources :

Example 71 with Resource

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

the class DispatchHelperTest method testVisibility_00.

@Test
public void testVisibility_00() throws Exception {
    XtendClass superClazz = clazz("class Super {\n" + "  def private dispatch foo(Object x) {} \n" + "}");
    Resource subResource = superClazz.eResource().getResourceSet().createResource(URI.createURI("Sub.xtend", true));
    subResource.load(new StringInputStream("class Sub extends Super {\n" + "  def dispatch foo(String x) {}\n" + "  def dispatch foo(Number x) {}\n" + "}"), null);
    JvmGenericType type = (JvmGenericType) subResource.getContents().get(1);
    ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
    List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
    assertEquals(2, list.size());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) DispatchSignature(org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature) DispatchHelper(org.eclipse.xtend.core.jvmmodel.DispatchHelper) Test(org.junit.Test)

Example 72 with Resource

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

the class LinkingErrorTest method assertNoExceptions.

protected void assertNoExceptions(EObject object) {
    Resource resource = object.eResource();
    if (resource instanceof LazyLinkingResource)
        ((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
    List<Diagnostic> errors = object.eResource().getErrors();
    for (Diagnostic error : errors) {
        if (error instanceof ExceptionDiagnostic) {
            ((ExceptionDiagnostic) error).getException().printStackTrace();
        }
        assertFalse(error.toString(), error instanceof ExceptionDiagnostic);
    }
    validateWithoutException((XtextResource) resource);
}
Also used : LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic)

Example 73 with Resource

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

the class UTF8ParserErrorTest method file.

@Override
protected XtendFile file(String string, boolean validate) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string, "UTF-8"), Collections.singletonMap(XtextResource.OPTION_ENCODING, "UTF-8"));
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    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 74 with Resource

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

the class IndexingTest method justLoad.

protected XtextResource justLoad(String contents) throws IOException {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(contents);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(contents), null);
    return (XtextResource) resource;
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 75 with Resource

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

the class URIsInEcoreFilesXtendTest method doTestResource.

protected void doTestResource(String platformPath, String... packageNames) {
    Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
    assertNotNull(resource);
    assertEquals(1, resource.getContents().size());
    EObject obj = resource.getContents().get(0);
    if (obj instanceof EPackage) {
        assertEquals(packageNames[0], ((EPackage) obj).getName());
    } else if (obj instanceof GenModel) {
        GenModel model = (GenModel) obj;
        List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
        assertEquals(packageNames.length, packages.size());
        ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {

            @Override
            public String apply(GenPackage p) {
                return p.getEcorePackage().getName();
            }
        });
        List<String> packageNamesList = Arrays.asList(packageNames);
        Collections.sort(packageNamesList);
        for (int i = 0; i < packageNamesList.size(); i++) {
            assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
        }
        IStatus status = model.validate();
        assertTrue(printLeafs(status), status.isOK());
        EObject orig = EcoreUtil.copy(obj);
        ((GenModel) obj).reconcile();
        if (!EcoreUtil.equals(orig, obj)) {
            Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {

                @Override
                public boolean apply(EStructuralFeature f) {
                    if (f instanceof EReference) {
                        EReference casted = (EReference) f;
                        return !casted.isContainment();
                    }
                    return false;
                }
            };
            String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
            String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
            throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
        }
    } else {
        fail("Unexpected root element type: " + obj.eClass().getName());
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) EPackage(org.eclipse.emf.ecore.EPackage) Predicate(com.google.common.base.Predicate) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) GenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

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