Search in sources :

Example 36 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class NonOverridableTypesProviderTest method testInheritOuterTypeParam.

@Test
public void testInheritOuterTypeParam() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import types.OuterClass");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo<MiddleClass, T> extends OuterClass<String> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <MiddleClass> foo() ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar()");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendClass xtendClass = this.clazz(_builder.toString());
        final JvmGenericType inferredType = this.associations.getInferredType(xtendClass);
        this.assertTypeInScope("Foo", inferredType);
        this.assertTypeInScope("MiddleClass", inferredType);
        this.assertNotInScope("MiddleClass.InnerMostClass", inferredType);
        this.assertTypeParameterInScope("T", inferredType);
        this.assertNotInScope("OuterClass", inferredType);
        final XtendMember method = xtendClass.getMembers().get(0);
        final JvmOperation operation = this.associations.getDirectlyInferredOperation(((XtendFunction) method));
        this.assertTypeInScope("Foo", operation);
        this.assertTypeParameterInScope("MiddleClass", operation);
        this.assertTypeParameterInScope("T", operation);
        this.assertNotInScope("MiddleClass.InnerMostClass", operation);
        this.assertNotInScope("OuterClass", operation);
        final XtendMember method2 = xtendClass.getMembers().get(0);
        final JvmOperation operation2 = this.associations.getDirectlyInferredOperation(((XtendFunction) method2));
        this.assertTypeInScope("Foo", operation2);
        this.assertTypeParameterInScope("MiddleClass", operation2);
        this.assertTypeParameterInScope("T", operation2);
        this.assertNotInScope("MiddleClass.InnerMostClass", operation2);
        this.assertNotInScope("OuterClass", operation2);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 37 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class JavaConverterTest method testStaticAccessCase.

@Test
public void testStaticAccessCase() throws Exception {
    this.j2x.useRobustSyntax();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Test2 {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("URI getURI(){");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("int i = URI.FRAGMENT_FIRST_SEPARATOR;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("if(URI.FRAGMENT_FIRST_SEPARATOR==0) return null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return URI.createURI(\"myURI\")");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static class URI {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("static int FRAGMENT_FIRST_SEPARATOR=0;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("static URI createURI(String str) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return (URI)null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    XtendFunction xtendMember = this.method(xtendClazz, 0);
    Assert.assertEquals("getURI", xtendMember.getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 38 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class JavaConverterTest method testNonFinalMethodParameterCase_01.

@Test
public void testNonFinalMethodParameterCase_01() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class JavaToConvert {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public boolean visit(Object node, Object node2, int[] array, int[] array2, String... varArgs) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("node = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("node2 = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("array[0] = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("array2 = null");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("varArgs = null");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return true;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    XtendFunction xtendMember = this.method(xtendClazz, 0);
    Assert.assertEquals(JvmVisibility.PUBLIC, xtendMember.getVisibility());
    Assert.assertEquals("node_finalParam_", xtendMember.getParameters().get(0).getName());
    Assert.assertEquals("node2_finalParam_", xtendMember.getParameters().get(1).getName());
    Assert.assertEquals("array", xtendMember.getParameters().get(2).getName());
    Assert.assertEquals("array2_finalParam_", xtendMember.getParameters().get(3).getName());
    Assert.assertEquals("varArgs_finalParam_", xtendMember.getParameters().get(4).getName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 39 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class ValueConverterExceptionProducesErrorTest method assertLiteral.

private void assertLiteral(final String expectation, final Resource resource) {
    EObject _head = IterableExtensions.<EObject>head(resource.getContents());
    final XtendFile file = ((XtendFile) _head);
    final XtendTypeDeclaration type = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _head_1 = IterableExtensions.<XtendMember>head(type.getMembers());
    final XtendFunction method = ((XtendFunction) _head_1);
    XExpression _expression = method.getExpression();
    final RichString body = ((RichString) _expression);
    XExpression _head_2 = IterableExtensions.<XExpression>head(body.getExpressions());
    final RichStringLiteral singleElement = ((RichStringLiteral) _head_2);
    Assert.assertEquals(expectation, singleElement.getValue());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) RichString(org.eclipse.xtend.core.xtend.RichString) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) RichStringLiteral(org.eclipse.xtend.core.xtend.RichStringLiteral) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 40 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class EObjectLocationTests method testFullLocationInFile.

@Test
public void testFullLocationInFile() throws Exception {
    String model = "class Foo extends Object { def Foo foo() {this }}";
    XtendClass clazz = clazz(model);
    JvmGenericType inferredType = xtendjvmAssociations.getInferredType(clazz);
    assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredType));
    JvmConstructor inferredConstructor = xtendjvmAssociations.getInferredConstructor(clazz);
    assertEquals(locationInFileProvider.getFullTextRegion(clazz), locationInFileProvider.getFullTextRegion(inferredConstructor));
    XtendFunction xtendFunction = (XtendFunction) clazz.getMembers().get(0);
    JvmOperation inferredOperation = xtendjvmAssociations.getDirectlyInferredOperation(xtendFunction);
    assertEquals(locationInFileProvider.getFullTextRegion(xtendFunction), locationInFileProvider.getFullTextRegion(inferredOperation));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Aggregations

XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)441 Test (org.junit.Test)374 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)248 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)198 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)182 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)116 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)101 XExpression (org.eclipse.xtext.xbase.XExpression)95 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)91 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)78 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)72 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)60 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)46 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)39 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)30 EObject (org.eclipse.emf.ecore.EObject)28 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)23 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)23 RichString (org.eclipse.xtend.core.xtend.RichString)17 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16