Search in sources :

Example 1 with ResourceImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceImpl in project xtext-eclipse by eclipse.

the class TraceResourceFactory method createResource.

@Override
public Resource createResource(URI uri) {
    Resource result = new ResourceImpl(uri) {

        @Override
        protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOException {
            TraceRegionSerializer serializer = new TraceRegionSerializer();
            DebugTraceRegion result = serializer.doReadFrom(inputStream, new Strategy());
            getContents().add(result);
        }

        @Override
        protected void doSave(OutputStream outputStream, Map<?, ?> options) throws IOException {
            TraceRegionSerializer serializer = new TraceRegionSerializer();
            serializer.doWriteTo(new Strategy(), (DebugTraceRegion) getContents().get(0), outputStream);
        }
    };
    return result;
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) InputStream(java.io.InputStream) TraceRegionSerializer(org.eclipse.xtext.generator.trace.TraceRegionSerializer) OutputStream(java.io.OutputStream) Resource(org.eclipse.emf.ecore.resource.Resource) Map(java.util.Map)

Example 2 with ResourceImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceImpl in project dsl-devkit by dsldevkit.

the class ShortFragmentProviderTest method testLongFragment2.

@Test
public void testLongFragment2() {
    int reps = 10;
    EObject root = EcoreUtil.create(testClass);
    EObject parent = root;
    for (int i = 0; i < reps; i++) {
        EObject child = EcoreUtil.create(testClass);
        parent.eSet(testReference, child);
        parent = child;
    }
    EObject child = EcoreUtil.create(testClass);
    parent.eSet(testReference2, child);
    parent = child;
    ResourceImpl resource = new ResourceImpl();
    resource.getContents().add(root);
    String fragment = fragmentProvider.getFragment(parent, fragmentFallback);
    Assert.assertEquals("/0*" + (reps + 1) + "/1", fragment);
    Assert.assertEquals(parent, fragmentProvider.getEObject(resource, fragment, fragmentFallback));
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EObject(org.eclipse.emf.ecore.EObject) BugTest(com.avaloq.tools.ddk.test.core.BugTest) Test(org.junit.Test) AbstractTest(com.avaloq.tools.ddk.xtext.test.AbstractTest)

Example 3 with ResourceImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceImpl in project xtext-core by eclipse.

the class NamesAreUniqueValidatorTest method setUp.

@SuppressWarnings("deprecation")
@Override
public void setUp() throws Exception {
    super.setUp();
    context = Maps.newHashMap();
    validator = new NamesAreUniqueValidator() {

        @Override
        protected Map<Object, Object> getContext() {
            return context;
        }
    };
    validator.setResourceServiceProviderRegistry(this);
    validator.setHelper(this);
    final DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            return QualifiedName.create(SimpleAttributeResolver.NAME_RESOLVER.getValue(obj));
        }
    });
    resourceDescriptionManager = new DefaultResourceDescriptionManager() {

        @Override
        public IResourceDescription getResourceDescription(Resource resource) {
            DefaultResourceDescription resourceDescription = new DefaultResourceDescription(resource, strategy);
            return resourceDescription;
        }
    };
    callCount = 0;
    resource = new ResourceImpl();
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    for (int i = 0; i < resource.getContents().size(); i++) {
        EClass clazz = (EClass) resource.getContents().get(i);
        clazz.setName(String.valueOf(i));
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) EClass(org.eclipse.emf.ecore.EClass) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EObject(org.eclipse.emf.ecore.EObject) DefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy) Map(java.util.Map)

Example 4 with ResourceImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceImpl in project xtext-core by eclipse.

the class DeclarativeValidatorTest method testDontSwallowNPEInValidation.

// configure validator to forward NPEs occurring in validation code
@Test
public void testDontSwallowNPEInValidation() {
    AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {

        @Override
        protected void handleExceptionDuringValidation(Throwable targetException) throws RuntimeException {
            Exceptions.throwUncheckedException(targetException);
        }

        @Check
        public void foo(Object x) {
            throw new NullPointerException();
        }
    };
    BasicDiagnostic chain = new BasicDiagnostic();
    Resource r = new ResourceImpl(URI.createURI("http://foo"));
    EObject x = EcoreFactory.eINSTANCE.createEAttribute();
    r.getContents().add(x);
    try {
        test.validate(x, chain, Collections.emptyMap());
        fail("NPE expected");
    } catch (NullPointerException expected) {
        // this is expected
        ;
    }
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Example 5 with ResourceImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceImpl in project xtext-core by eclipse.

the class DeclarativeValidatorTest method testSwallowNPEInValidation.

// By default, NPEs occurring in validation code are swallowed
@Test
public void testSwallowNPEInValidation() {
    AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {

        @Check
        public void foo(Object x) {
            throw new NullPointerException();
        }
    };
    BasicDiagnostic chain = new BasicDiagnostic();
    Resource r = new ResourceImpl(URI.createURI("http://foo"));
    EObject x = EcoreFactory.eINSTANCE.createEAttribute();
    r.getContents().add(x);
    test.validate(x, chain, Collections.emptyMap());
    assertTrue(chain.getChildren().isEmpty());
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) Test(org.junit.Test)

Aggregations

ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)18 Resource (org.eclipse.emf.ecore.resource.Resource)12 Test (org.junit.Test)11 EObject (org.eclipse.emf.ecore.EObject)9 EClass (org.eclipse.emf.ecore.EClass)5 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)3 EcoreFactory (org.eclipse.emf.ecore.EcoreFactory)3 CacheAdapter (org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter)3 Before (org.junit.Before)3 BugTest (com.avaloq.tools.ddk.test.core.BugTest)2 AbstractTest (com.avaloq.tools.ddk.xtext.test.AbstractTest)2 Map (java.util.Map)2 EReference (org.eclipse.emf.ecore.EReference)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 INode (org.eclipse.xtext.nodemodel.INode)2 DefaultResourceDescription (org.eclipse.xtext.resource.impl.DefaultResourceDescription)2 DefaultResourceDescriptionManager (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager)2 DefaultResourceDescriptionStrategy (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy)2