use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method file.
protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
if (shouldBeSyntacticallyValid) {
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
}
if (validate) {
List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {
@Override
public boolean apply(Issue issue) {
return issue.getSeverity() == Severity.ERROR;
}
}));
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
use of org.eclipse.xtend.core.xtend.XtendFile 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.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.
the class ModelExtensionsTest method testXtendFunction.
@Test
public void testXtendFunction() throws Exception {
XtendFile file = file("package foo class Bar { def int foo() {1}}");
XtendFunction xtendFunction = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
assertEquals("foo", xtendFunction.getName());
}
use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method file.
protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
if (shouldBeSyntacticallyValid) {
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
}
if (validate) {
List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {
@Override
public boolean apply(Issue issue) {
return issue.getSeverity() == Severity.ERROR;
}
}));
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.
the class XtendQualifiedNameProvider method getFullyQualifiedName.
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
if (obj instanceof XtendTypeDeclaration) {
XtendTypeDeclaration typeDecl = (XtendTypeDeclaration) obj;
String typeName = typeDecl.getName();
if (typeDecl.eContainer() instanceof XtendFile) {
if (typeName == null)
return null;
XtendFile file = (XtendFile) typeDecl.eContainer();
String packageName = file.getPackage();
if (packageName != null) {
return qualifiedNameConverter.toQualifiedName(packageName).append(typeName);
}
return QualifiedName.create(typeName);
} else {
return concatNames(obj, typeName);
}
}
if (obj instanceof XtendConstructor) {
return getFullyQualifiedName(obj.eContainer());
}
if (obj instanceof JvmIdentifiableElement && !(obj instanceof JvmTypeParameter)) {
return getFullyQualifiedName((JvmIdentifiableElement) obj);
}
if (obj instanceof XtendField) {
return concatNames(obj, ((XtendField) obj).getName());
}
if (obj instanceof XtendFunction) {
return concatNames(obj, ((XtendFunction) obj).getName());
}
if (obj instanceof XtendEnumLiteral) {
return concatNames(obj, ((XtendEnumLiteral) obj).getName());
}
return null;
}
Aggregations