Search in sources :

Example 41 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class NonOverridableTypesProviderTest method assertTypeParameterInScope.

protected void assertTypeParameterInScope(final String typeName, final JvmMember context) {
    final JvmIdentifiableElement visibleType = this.typesFromHierarchy.getVisibleType(context, typeName);
    Assert.assertNotNull(visibleType);
    Assert.assertTrue((visibleType instanceof JvmTypeParameter));
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter)

Example 42 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class JavaConverterTest method testSimpleTypeParameterCase.

@Test
public void testSimpleTypeParameterCase() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class TestTypeParameter <T,U extends T> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("<D extends T>  T doStuff(Iterable<? super U> us, Iterable<? extends D> d, T t) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return t;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    XtendClass xtendClazz = this.toValidXtendClass(_builder);
    JvmTypeParameter typeParameter = xtendClazz.getTypeParameters().get(0);
    Assert.assertEquals("T", typeParameter.getName());
    typeParameter = xtendClazz.getTypeParameters().get(1);
    Assert.assertEquals("U", typeParameter.getName());
    Assert.assertEquals("extends T", typeParameter.getConstraints().get(0).getSimpleName());
    XtendFunction xtendMember = this.method(xtendClazz, 0);
    Assert.assertEquals("doStuff", xtendMember.getName());
    typeParameter = xtendMember.getTypeParameters().get(0);
    Assert.assertEquals("D", typeParameter.getName());
    Assert.assertEquals("extends T", typeParameter.getConstraints().get(0).getSimpleName());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 43 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class JvmModelTests method testJvmTypeParameter_06.

@Test
public void testJvmTypeParameter_06() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <> foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        final JvmOperation member = IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(clazz.getMembers(), JvmOperation.class));
        EList<JvmTypeParameter> _typeParameters = member.getTypeParameters();
        String _plus = ("" + _typeParameters);
        Assert.assertTrue(_plus, member.getTypeParameters().isEmpty());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 44 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class JvmModelTests method testJvmTypeParameter_02.

@Test
public void testJvmTypeParameter_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo<T> {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        EList<JvmTypeParameter> _typeParameters = clazz.getTypeParameters();
        String _plus = ("" + _typeParameters);
        Assert.assertEquals(_plus, 1, clazz.getTypeParameters().size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 45 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class JvmModelTests method testJvmTypeParameter_04.

@Test
public void testJvmTypeParameter_04() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new <T>() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.file(_builder.toString(), false, false).getXtendTypes());
        final JvmGenericType clazz = this._iXtendJvmAssociations.getInferredType(((XtendClass) _head));
        final JvmConstructor member = IterableExtensions.<JvmConstructor>head(Iterables.<JvmConstructor>filter(clazz.getMembers(), JvmConstructor.class));
        EList<JvmTypeParameter> _typeParameters = member.getTypeParameters();
        String _plus = ("" + _typeParameters);
        Assert.assertEquals(_plus, 1, member.getTypeParameters().size());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Test(org.junit.Test)

Aggregations

JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)57 Test (org.junit.Test)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)14 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)13 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)10 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)7 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)6 List (java.util.List)5 EList (org.eclipse.emf.common.util.EList)5 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)5 EObject (org.eclipse.emf.ecore.EObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 ArrayList (java.util.ArrayList)3 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)3 AbstractMethodBuilder (org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)3