Search in sources :

Example 26 with JvmTypeParameter

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

the class LinkingTest method testTypeParameterReference.

@Test
public void testTypeParameterReference() throws Exception {
    XtendFunction func = function("def <X> X foo(X x) {x}");
    JvmTypeReference returnType = func.getReturnType();
    JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
    assertEquals("X", typeParamDecl.getIdentifier());
    assertEquals("X", typeParamDecl.getName());
    JvmTypeReference paramType = func.getParameters().get(0).getParameterType();
    assertEquals(typeParamDecl, paramType.getType());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 27 with JvmTypeParameter

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

the class LinkingTest method testTypeParameterShadowsType_2.

@Test
public void testTypeParameterShadowsType_2() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class A {} class B<A>  { def A foo(A x) {x}}").getXtendTypes().get(1)).getMembers().get(0);
    JvmTypeReference returnType = func.getReturnType();
    JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
    assertEquals("A", typeParamDecl.getIdentifier());
    JvmTypeParameter param = (JvmTypeParameter) func.getParameters().get(0).getParameterType().getType();
    assertSame(typeParamDecl, param);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 28 with JvmTypeParameter

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

the class LinkingTest method testTypeParameterShadowsType_1.

@Test
public void testTypeParameterShadowsType_1() throws Exception {
    XtendFunction func = (XtendFunction) ((XtendClass) file("class A {} class B { def <A> A foo(A x) {x}}").getXtendTypes().get(1)).getMembers().get(0);
    JvmTypeReference returnType = func.getReturnType();
    JvmTypeParameter typeParamDecl = (JvmTypeParameter) returnType.getType();
    assertEquals("A", typeParamDecl.getIdentifier());
    JvmTypeParameter param = (JvmTypeParameter) func.getParameters().get(0).getParameterType().getType();
    assertSame(typeParamDecl, param);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Test(org.junit.Test)

Example 29 with JvmTypeParameter

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

the class MethodBuilderTest method testXtendTypeParameter.

@Test
public void testXtendTypeParameter() {
    AbstractMethodBuilder _createMethodBuilder = this._codeBuilderFactory.createMethodBuilder(this.getXtendClass());
    final Procedure1<AbstractMethodBuilder> _function = (AbstractMethodBuilder it) -> {
        it.setContext(this.getXtendClass());
        it.setMethodName("foo");
        JvmTypeParameter _createJvmTypeParameter = this._typesFactory.createJvmTypeParameter();
        final Procedure1<JvmTypeParameter> _function_1 = (JvmTypeParameter it_1) -> {
            it_1.setName("T");
        };
        JvmTypeParameter _doubleArrow = ObjectExtensions.<JvmTypeParameter>operator_doubleArrow(_createJvmTypeParameter, _function_1);
        JvmTypeParameter _createJvmTypeParameter_1 = this._typesFactory.createJvmTypeParameter();
        final Procedure1<JvmTypeParameter> _function_2 = (JvmTypeParameter it_1) -> {
            it_1.setName("U");
        };
        JvmTypeParameter _doubleArrow_1 = ObjectExtensions.<JvmTypeParameter>operator_doubleArrow(_createJvmTypeParameter_1, _function_2);
        it.setTypeParameters(Collections.<JvmTypeParameter>unmodifiableList(CollectionLiterals.<JvmTypeParameter>newArrayList(_doubleArrow, _doubleArrow_1)));
    };
    AbstractMethodBuilder _doubleArrow = ObjectExtensions.<AbstractMethodBuilder>operator_doubleArrow(_createMethodBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def <T,U> foo() {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 30 with JvmTypeParameter

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

the class ExtractMethodRefactoring method appendMethodSignature.

protected void appendMethodSignature(ISourceAppender appendable) {
    if (visibility != JvmVisibility.PUBLIC)
        appendable.append(getVisibility().getName().toLowerCase()).append(" ");
    appendable.append("def ");
    if (isStatic)
        appendable.append("static ");
    if (!neededTypeParameters.isEmpty()) {
        JvmOperation operation = associations.getDirectlyInferredOperation(originalMethod);
        if (operation != null) {
            appendable.append("<");
            boolean isFirst = true;
            for (JvmTypeParameter typeParameter : operation.getTypeParameters()) {
                if (neededTypeParameters.contains(typeParameter)) {
                    if (!isFirst)
                        appendable.append(", ");
                    isFirst = false;
                    appendable.append(typeParameter);
                }
            }
            appendable.append("> ");
        }
    }
    if (isExplicitlyDeclareReturnType) {
        appendable.append(returnType).append(" ");
    }
    appendable.append(methodName).append("(");
    boolean isFirst = true;
    for (ParameterInfo parameterInfo : getParameterInfos()) {
        if (!isFirst)
            appendable.append(", ");
        isFirst = false;
        appendable.append(parameter2type.get(parameterInfo)).append(" ").append(parameterInfo.getNewName());
    }
    appendable.append(")");
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)

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