Search in sources :

Example 11 with XtendFile

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration)

Example 12 with XtendFile

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) Issue(org.eclipse.xtext.validation.Issue) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 13 with XtendFile

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource)

Example 14 with XtendFile

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 15 with XtendFile

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);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Aggregations

XtendFile (org.eclipse.xtend.core.xtend.XtendFile)855 Test (org.junit.Test)782 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)372 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)229 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)182 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)126 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)119 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)98 XExpression (org.eclipse.xtext.xbase.XExpression)82 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)64 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)62 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)62 EObject (org.eclipse.emf.ecore.EObject)50 Resource (org.eclipse.emf.ecore.resource.Resource)47 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)46 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)42 XtextResource (org.eclipse.xtext.resource.XtextResource)34 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)29 XtendField (org.eclipse.xtend.core.xtend.XtendField)23 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)21