use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method files.
protected Iterable<XtendFile> files(boolean validate, String... contents) throws Exception {
XtextResourceSet set = getResourceSet();
List<XtendFile> result = newArrayList();
for (String string : contents) {
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
}
for (Resource resource : new ArrayList<Resource>(set.getResources())) {
XtendFile file = (XtendFile) resource.getContents().get(0);
result.add(file);
}
if (validate) {
for (XtendFile file : result) {
List<Issue> issues = ((XtextResource) file.eResource()).getResourceServiceProvider().getResourceValidator().validate(file.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
}
return result;
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method fileWithErrors.
protected XtendFile fileWithErrors(String string) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
assertTrue(resource.getErrors().toString(), resource.getErrors().size() > 0);
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
use of org.eclipse.emf.ecore.resource.Resource 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.Resource 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.Resource in project xtext-xtend by eclipse.
the class JvmElementAtOffsetHelperTest method testdeclaration.
@Test
public void testdeclaration() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testPackage");
_builder.newLine();
_builder.append("class TestCase {");
_builder.newLine();
_builder.append("\t");
_builder.append("def fo|o(String a){");
_builder.newLine();
_builder.append("\t\t");
_builder.append("bar(a)");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("def bar(String a){}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final String content = _builder.toString();
final XtendFile file = this.file(content.replace("|", ""));
Resource _eResource = file.eResource();
JvmIdentifiableElement jvmIdentifiableElement = this.jvmElementAtOffsetHelper.getJvmIdentifiableElement(((XtextResource) _eResource), content.indexOf("|"));
Assert.assertTrue((jvmIdentifiableElement instanceof JvmOperation));
Assert.assertEquals("testPackage.TestCase.foo", jvmIdentifiableElement.getQualifiedName());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations