Search in sources :

Example 1 with XtendParameter

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

the class LinkingTest method testBug342848_02.

@Test
public void testBug342848_02() throws Exception {
    String fileAsText = "import org.eclipse.xtext.xbase.lib.Functions\n" + "class Clazz { def void method(Functions.Function0<Integer> f) { f.apply } }";
    XtendFile file = file(fileAsText, true);
    XtendFunction function = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
    XtendParameter parameter = function.getParameters().get(0);
    String identifier = parameter.getParameterType().getIdentifier();
    assertEquals(Functions.Function0.class.getName() + "<java.lang.Integer>", identifier);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Functions(org.eclipse.xtext.xbase.lib.Functions) Test(org.junit.Test)

Example 2 with XtendParameter

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

the class ErrorTest method testErrorModel_018.

@Test
public void testErrorModel_018() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def m(@");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
    final XtendFunction function = ((XtendFunction) _head);
    final XtendParameter param = IterableExtensions.<XtendParameter>head(function.getParameters());
    final XAnnotation annotation = IterableExtensions.<XAnnotation>head(param.getAnnotations());
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(annotation);
    Assert.assertNotNull(resolvedTypes.getActualType(annotation));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Example 3 with XtendParameter

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

the class XtendCopyQualifiedNameService method toQualifiedName.

protected String toQualifiedName(final XtendConstructor it) {
    StringConcatenation _builder = new StringConcatenation();
    String _fullyQualifiedName = this.toFullyQualifiedName(it);
    _builder.append(_fullyQualifiedName);
    _builder.append("(");
    final Function1<XtendParameter, String> _function = (XtendParameter it_1) -> {
        return it_1.getParameterType().getSimpleName();
    };
    CharSequence _qualifiedNames = this.<XtendParameter>toQualifiedNames(it.getParameters(), _function);
    _builder.append(_qualifiedNames);
    _builder.append(")");
    return _builder.toString();
}
Also used : XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 4 with XtendParameter

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

the class XtendJvmModelInferrer method transformCreateExtension.

protected void transformCreateExtension(XtendFunction source, CreateExtensionInfo createExtensionInfo, JvmGenericType container, JvmOperation operation, /* @Nullable */
JvmTypeReference returnType) {
    JvmField cacheVar = jvmTypesBuilder.toField(source, CREATE_CHACHE_VARIABLE_PREFIX + source.getName(), jvmTypesBuilder.inferredType());
    if (cacheVar != null) {
        cacheVar.setFinal(true);
        jvmTypesBuilder.setInitializer(cacheVar, compileStrategies.forCacheVariable(source));
        container.getMembers().add(cacheVar);
        JvmOperation initializer = typesFactory.createJvmOperation();
        container.getMembers().add(initializer);
        initializer.setSimpleName(CREATE_INITIALIZER_PREFIX + source.getName());
        initializer.setVisibility(JvmVisibility.PRIVATE);
        initializer.setReturnType(typeReferences.getTypeForName(Void.TYPE, source));
        for (JvmTypeReference exception : source.getExceptions()) {
            initializer.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
        }
        jvmTypesBuilder.setBody(operation, compileStrategies.forCacheMethod(createExtensionInfo, cacheVar, initializer));
        // the first parameter is the created object
        JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
        jvmParam.setName(createExtensionInfo.getName());
        // TODO consider type parameters
        jvmParam.setParameterType(jvmTypesBuilder.inferredType());
        initializer.getParameters().add(jvmParam);
        associator.associate(createExtensionInfo, jvmParam);
        // add all others
        for (XtendParameter parameter : source.getParameters()) {
            jvmParam = typesFactory.createJvmFormalParameter();
            jvmParam.setName(parameter.getName());
            jvmParam.setParameterType(jvmTypesBuilder.cloneWithProxies(parameter.getParameterType()));
            initializer.getParameters().add(jvmParam);
            associator.associate(parameter, jvmParam);
        }
        associator.associate(source, initializer);
        setBody(operation, createExtensionInfo.getCreateExpression());
        setBody(initializer, source.getExpression());
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField)

Example 5 with XtendParameter

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

the class InferredJvmModelTest method testInferredFunctionWithParameter.

@Test
public void testInferredFunctionWithParameter() throws Exception {
    XtendFile xtendFile = file("class Foo { def bar(Boolean baz) { true } }");
    JvmGenericType inferredType = getInferredType(xtendFile);
    JvmOperation jvmOperation = (JvmOperation) inferredType.getMembers().get(1);
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) xtendFile.getXtendTypes().get(0)).getMembers().get(0);
    assertEquals(1, jvmOperation.getParameters().size());
    JvmFormalParameter jvmParameter = jvmOperation.getParameters().get(0);
    XtendParameter xtendParameter = xtendFunction.getParameters().get(0);
    assertEquals(xtendParameter.getName(), jvmParameter.getSimpleName());
    assertEquals(xtendParameter.getParameterType().getType(), jvmParameter.getParameterType().getType());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Aggregations

XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)26 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)12 Test (org.junit.Test)12 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)11 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)11 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 XtendAnnotationTarget (org.eclipse.xtend.core.xtend.XtendAnnotationTarget)4 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)4 EObject (org.eclipse.emf.ecore.EObject)3 XtendField (org.eclipse.xtend.core.xtend.XtendField)3 Declaration (org.eclipse.xtend.lib.macro.declaration.Declaration)3 MutableNamedElement (org.eclipse.xtend.lib.macro.declaration.MutableNamedElement)3 NamedElement (org.eclipse.xtend.lib.macro.declaration.NamedElement)3 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)3 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)3 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 List (java.util.List)2