use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class LinkingErrorTest method testLinkError.
@Test
public void testLinkError() throws Exception {
XtextResource resource = getResourceFromStringAndExpect(" type A extends B \n type B extends C", 1);
Main model = (Main) getModel(resource);
assertEquals(2, model.getTypes().size());
assertEquals(1, resource.getErrors().size());
assertEquals(0, resource.getWarnings().size());
Diagnostic error = (Diagnostic) resource.getErrors().get(0);
assertEquals(2, error.getLine());
Diagnostic verboseError = error;
assertEquals(35, verboseError.getOffset());
assertEquals(1, verboseError.getLength());
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class Bug285381Test method _testSerializeReference_01.
public void _testSerializeReference_01() throws Exception {
String modelAsString = "type A extends A";
Main model = (Main) getModel(modelAsString);
Type parsedType = model.getTypes().get(0);
assertSame(parsedType, parsedType.getExtends());
Type newType = LangATestLanguageFactory.eINSTANCE.createType();
newType.setName("Foo");
parsedType.setExtends(newType);
String serialized = serialize(model);
// we use the existing value from the node model
// since there is not string representation of the newType
assertEquals(modelAsString, serialized);
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class Bug285381Test method _testSerializeReference_02.
public void _testSerializeReference_02() throws Exception {
String modelAsString = "type A";
Main model = (Main) getModel(modelAsString);
Type parsedType = model.getTypes().get(0);
assertNull(parsedType.getExtends());
Type newType = LangATestLanguageFactory.eINSTANCE.createType();
newType.setName("Foo");
parsedType.setExtends(newType);
try {
serialize(model);
fail("expected XtextSerializationException");
} catch (XtextSerializationException e) {
// expected
}
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class PortableURIsTest method testPortableUris.
@Test
public void testPortableUris() {
try {
final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class);
Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage"));
final StorageAwareResource resourceA = ((StorageAwareResource) _createResource);
Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage"));
final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1);
StringConcatenation _builder = new StringConcatenation();
_builder.append("type B");
_builder.newLine();
resourceB.load(this.getAsStream(_builder.toString()), null);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("import \'hubba:/bubba2.langatestlanguage\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("type A extends B");
_builder_1.newLine();
resourceA.load(this.getAsStream(_builder_1.toString()), null);
final Type extended = IterableExtensions.<Type>head(IterableExtensions.<Main>head(Iterables.<Main>filter(resourceA.getContents(), Main.class)).getTypes()).getExtends();
final URI uri = EcoreUtil.getURI(extended);
final URI portableURI = resourceA.getPortableURIs().toPortableURI(resourceA, uri);
Assert.assertEquals(resourceA.getURI(), portableURI.trimFragment());
Assert.assertTrue(resourceA.getPortableURIs().isPortableURIFragment(portableURI.fragment()));
Assert.assertSame(extended, resourceA.getEObject(portableURI.fragment()));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class PortableURIsTest method testPortableReferenceDescriptions.
@Test
public void testPortableReferenceDescriptions() {
try {
final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class);
Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage"));
final StorageAwareResource resourceA = ((StorageAwareResource) _createResource);
Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage"));
final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1);
StringConcatenation _builder = new StringConcatenation();
_builder.append("type B");
_builder.newLine();
resourceB.load(this.getAsStream(_builder.toString()), null);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("import \'hubba:/bubba2.langatestlanguage\'");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("type A extends B");
_builder_1.newLine();
resourceA.load(this.getAsStream(_builder_1.toString()), null);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
final ResourceStorageWritable writable = resourceA.getResourceStorageFacade().createResourceStorageWritable(bout);
writable.writeResource(resourceA);
byte[] _byteArray = bout.toByteArray();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
final ResourceStorageLoadable loadable = resourceA.getResourceStorageFacade().createResourceStorageLoadable(_byteArrayInputStream);
Resource _createResource_2 = resourceSet.createResource(URI.createURI("hubba:/bubba3.langatestlanguage"));
final StorageAwareResource resourceC = ((StorageAwareResource) _createResource_2);
resourceC.loadFromStorage(loadable);
final IReferenceDescription refDesc = IterableExtensions.<IReferenceDescription>head(resourceC.getResourceDescription().getReferenceDescriptions());
EObject _head = IterableExtensions.<EObject>head(resourceB.getContents());
Assert.assertSame(IterableExtensions.<Type>head(((Main) _head).getTypes()), resourceSet.getEObject(refDesc.getTargetEObjectUri(), false));
EObject _head_1 = IterableExtensions.<EObject>head(resourceC.getContents());
Assert.assertSame(IterableExtensions.<Type>head(((Main) _head_1).getTypes()), resourceSet.getEObject(refDesc.getSourceEObjectUri(), false));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations