use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class RefactoringIntegrationTest method performRenameTest.
protected void performRenameTest(IFile file, String originalContents, String oldName, String newName, IFile newFile) throws Exception {
IResourcesSetupUtil.waitForBuild();
ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
XtextResource resource = (XtextResource) resourceSet.getResource(testHelper.uri(file), true);
EObject target = eObjectAtOffsetHelper.resolveElementAt(resource, originalContents.indexOf(oldName));
doRename(target, newName);
String contentsAfterRename = WorkbenchTestHelper.getContentsAsString(newFile);
assertEquals(originalContents.replace(oldName, newName), contentsAfterRename);
}
use of org.eclipse.emf.ecore.resource.ResourceSet 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());
}
use of org.eclipse.emf.ecore.resource.ResourceSet 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());
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class ResourceStorageTest method testWriteAndLoad.
@Test
public void testWriteAndLoad() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package foo");
_builder.newLine();
_builder.newLine();
_builder.append("class Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("def dispatch myMethod(String s) {}");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* Hello myMethod ");
_builder.newLine();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("def dispatch myMethod(CharSequence cs) {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def dispatch other(String it) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("var x = \"\"");
_builder.newLine();
_builder.append("\t\t");
_builder.append("x = length.toString");
_builder.newLine();
_builder.append("\t\t");
_builder.append("println(x)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String contents = _builder.toString();
final XtendFile file = this.file(contents);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
Resource _eResource = file.eResource();
this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
byte[] _byteArray = bout.toByteArray();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
final StorageAwareResource resource = ((StorageAwareResource) _createResource);
final InMemoryURIConverter converter = new InMemoryURIConverter();
converter.addModel(resource.getURI().toString(), contents);
ResourceSet _resourceSet = resource.getResourceSet();
_resourceSet.setURIConverter(converter);
EList<Resource> _resources = file.eResource().getResourceSet().getResources();
_resources.add(resource);
resource.loadFromStorage(in);
EObject _get = resource.getContents().get(1);
final JvmGenericType jvmClass = ((JvmGenericType) _get);
Assert.assertEquals("java.lang.CharSequence", IterableExtensions.<JvmFormalParameter>head(((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2].getParameters()).getParameterType().getQualifiedName());
Assert.assertEquals("java.lang.Object", ((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2].getReturnType().getQualifiedName());
Assert.assertEquals("Hello myMethod", IterableExtensions.<DocumentationAdapter>head(Iterables.<DocumentationAdapter>filter(((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[1].eAdapters(), DocumentationAdapter.class)).getDocumentation());
Assert.assertEquals(resource.getURI(), resource.getResourceDescription().getURI());
Assert.assertEquals(2, IterableExtensions.size(resource.getResourceDescription().getExportedObjects()));
Assert.assertEquals("foo.Bar", IterableExtensions.<IEObjectDescription>head(resource.getResourceDescription().getExportedObjects()).getQualifiedName().toString());
final BidiTreeIterator<INode> restoredNodes = NodeModelUtils.findActualNodeFor(IterableExtensions.<EObject>head(resource.getContents())).getAsTreeIterable().iterator();
final BidiTreeIterator<INode> originalNodes = NodeModelUtils.findActualNodeFor(file).getAsTreeIterable().iterator();
while (restoredNodes.hasNext()) {
{
final INode rest = restoredNodes.next();
final INode orig = originalNodes.next();
Assert.assertEquals(orig.getStartLine(), rest.getStartLine());
Assert.assertEquals(orig.getEndLine(), rest.getEndLine());
Assert.assertEquals(orig.getOffset(), rest.getOffset());
Assert.assertEquals(orig.getEndOffset(), rest.getEndOffset());
Assert.assertEquals(orig.getLength(), rest.getLength());
Assert.assertEquals(orig.getTotalStartLine(), rest.getTotalStartLine());
Assert.assertEquals(orig.getTotalEndLine(), rest.getTotalEndLine());
Assert.assertEquals(orig.getTotalOffset(), rest.getTotalOffset());
Assert.assertEquals(orig.getTotalEndOffset(), rest.getTotalEndOffset());
Assert.assertEquals(orig.getTotalLength(), rest.getTotalLength());
Assert.assertSame(orig.getGrammarElement(), rest.getGrammarElement());
Assert.assertEquals(file.eResource().getURIFragment(orig.getSemanticElement()), resource.getURIFragment(rest.getSemanticElement()));
Assert.assertEquals(orig.getText(), rest.getText());
}
}
Assert.assertFalse(originalNodes.hasNext());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class ResourceStorageTest method testConstantValueIsPersisted_01.
@Test
public void testConstantValueIsPersisted_01() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class C {");
_builder.newLine();
_builder.append("\t");
_builder.append("static val CONSTANT = Object");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String contents = _builder.toString();
final XtendFile file = this.file(contents);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
Resource _eResource = file.eResource();
this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
byte[] _byteArray = bout.toByteArray();
ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
final StorageAwareResource resource = ((StorageAwareResource) _createResource);
final InMemoryURIConverter converter = new InMemoryURIConverter();
converter.addModel(resource.getURI().toString(), contents);
ResourceSet _resourceSet = resource.getResourceSet();
_resourceSet.setURIConverter(converter);
EList<Resource> _resources = file.eResource().getResourceSet().getResources();
_resources.add(resource);
resource.loadFromStorage(in);
EObject _get = resource.getContents().get(1);
final JvmGenericType jvmClass = ((JvmGenericType) _get);
JvmMember _last = IterableExtensions.<JvmMember>last(jvmClass.getMembers());
final JvmField field = ((JvmField) _last);
Assert.assertFalse(field.isConstant());
Assert.assertTrue(field.isSetConstant());
Assert.assertNull(field.getConstantValue());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations