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;
}
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));
}
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));
}
}
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
;
}
}
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());
}
Aggregations