use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.
the class XtendTypeDeclarationImpl method getQualifiedName.
private String getQualifiedName(final XtendTypeDeclaration decl) {
boolean _isAnonymous = decl.isAnonymous();
if (_isAnonymous) {
return null;
}
final EObject container = decl.eContainer();
if ((container instanceof XtendFile)) {
final String package_ = ((XtendFile) container).getPackage();
if ((package_ == null)) {
return decl.getName();
}
String _name = decl.getName();
return ((package_ + ".") + _name);
}
if ((container instanceof XtendTypeDeclaration)) {
final String containerName = this.getQualifiedName(((XtendTypeDeclaration) container));
if ((containerName == null)) {
return null;
}
String _name_1 = decl.getName();
return ((containerName + ".") + _name_1);
}
return null;
}
use of org.eclipse.xtend.core.xtend.XtendFile 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.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 ConstantExpressionsInterpreterTest method testEnumLiteral_WithStaticImport.
@Test
public void testEnumLiteral_WithStaticImport() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static test.Enum1.* ");
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("Enum1 testFoo = RED");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XtendField field = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
Object _evaluate = this.interpreter.evaluate(field.getInitialValue(), field.getType());
final JvmEnumerationLiteral blue = ((JvmEnumerationLiteral) _evaluate);
Assert.assertEquals("RED", blue.getSimpleName());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreterTest method testConstants_WithStaticImport.
@Test
public void testConstants_WithStaticImport() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static test.Constants1.* ");
_builder.newLine();
_builder.append("class C { ");
_builder.newLine();
_builder.append("\t");
_builder.append("val someString = STRING_CONSTANT");
_builder.newLine();
_builder.append("\t");
_builder.append("val someInt = INT_CONSTANT");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.file(_builder.toString());
final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
final XtendField intField = ((XtendField[]) Conversions.unwrapArray(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class), XtendField.class))[1];
Assert.assertEquals(Constants1.STRING_CONSTANT, this.interpreter.evaluate(stringField.getInitialValue(), null));
Assert.assertEquals(Integer.valueOf(Constants1.INT_CONSTANT), this.interpreter.evaluate(intField.getInitialValue(), null));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations