use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class DispatchHelperTest method testVisibility_00.
@Test
public void testVisibility_00() throws Exception {
XtendClass superClazz = clazz("class Super {\n" + " def private dispatch foo(Object x) {} \n" + "}");
Resource subResource = superClazz.eResource().getResourceSet().createResource(URI.createURI("Sub.xtend", true));
subResource.load(new StringInputStream("class Sub extends Super {\n" + " def dispatch foo(String x) {}\n" + " def dispatch foo(Number x) {}\n" + "}"), null);
JvmGenericType type = (JvmGenericType) subResource.getContents().get(1);
ListMultimap<DispatchSignature, JvmOperation> multimap = dispatchHelper.getDeclaredOrEnhancedDispatchMethods(type);
List<JvmOperation> list = multimap.get(new DispatchHelper.DispatchSignature("foo", 1));
assertEquals(2, list.size());
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class LinkingErrorTest method assertNoExceptions.
protected void assertNoExceptions(EObject object) {
Resource resource = object.eResource();
if (resource instanceof LazyLinkingResource)
((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl);
List<Diagnostic> errors = object.eResource().getErrors();
for (Diagnostic error : errors) {
if (error instanceof ExceptionDiagnostic) {
((ExceptionDiagnostic) error).getException().printStackTrace();
}
assertFalse(error.toString(), error instanceof ExceptionDiagnostic);
}
validateWithoutException((XtextResource) resource);
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class UTF8ParserErrorTest method file.
@Override
protected XtendFile file(String string, boolean validate) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string, "UTF-8"), Collections.singletonMap(XtextResource.OPTION_ENCODING, "UTF-8"));
assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
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 IndexingTest method justLoad.
protected XtextResource justLoad(String contents) throws IOException {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(contents);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(contents), null);
return (XtextResource) resource;
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class URIsInEcoreFilesXtendTest method doTestResource.
protected void doTestResource(String platformPath, String... packageNames) {
Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
assertNotNull(resource);
assertEquals(1, resource.getContents().size());
EObject obj = resource.getContents().get(0);
if (obj instanceof EPackage) {
assertEquals(packageNames[0], ((EPackage) obj).getName());
} else if (obj instanceof GenModel) {
GenModel model = (GenModel) obj;
List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
assertEquals(packageNames.length, packages.size());
ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
@Override
public String apply(GenPackage p) {
return p.getEcorePackage().getName();
}
});
List<String> packageNamesList = Arrays.asList(packageNames);
Collections.sort(packageNamesList);
for (int i = 0; i < packageNamesList.size(); i++) {
assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
}
IStatus status = model.validate();
assertTrue(printLeafs(status), status.isOK());
EObject orig = EcoreUtil.copy(obj);
((GenModel) obj).reconcile();
if (!EcoreUtil.equals(orig, obj)) {
Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
@Override
public boolean apply(EStructuralFeature f) {
if (f instanceof EReference) {
EReference casted = (EReference) f;
return !casted.isContainment();
}
return false;
}
};
String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
}
} else {
fail("Unexpected root element type: " + obj.eClass().getName());
}
}
Aggregations