Search in sources :

Example 16 with XtendParameter

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

the class XtendHoverSignatureProviderTest method testSignatureForXtendParameter.

@Test
public void testSignatureForXtendParameter() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(String a) throws NullPointerException");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        XtendMember _get = clazz.getMembers().get(0);
        final XtendFunction xtendFunction = ((XtendFunction) _get);
        final XtendParameter xtendParameter = xtendFunction.getParameters().get(0);
        final String signature = this.signatureProvider.getSignature(xtendParameter);
        Assert.assertEquals("String a - bar(String)", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
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) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 17 with XtendParameter

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

the class XtendHoverSignatureProviderTest method testAutcastExpressions_3.

@Test
public void testAutcastExpressions_3() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo(CharSequence c) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (c instanceof String) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("c.substring(1, 1)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("switch(c){");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("String : c.length");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head_1 = IterableExtensions.<XtendMember>head(((XtendClass) _head).getMembers());
        final XtendFunction func = ((XtendFunction) _head_1);
        Assert.assertEquals("CharSequence c - foo(CharSequence)", this.signatureProvider.getSignature(IterableExtensions.<XtendParameter>head(func.getParameters())));
        XExpression _expression = func.getExpression();
        final XBlockExpression block = ((XBlockExpression) _expression);
        XExpression _head_2 = IterableExtensions.<XExpression>head(block.getExpressions());
        final XIfExpression ifexpr = ((XIfExpression) _head_2);
        final XExpression then = ifexpr.getThen();
        XExpression _head_3 = IterableExtensions.<XExpression>head(((XBlockExpression) then).getExpressions());
        final XExpression target = ((XMemberFeatureCall) _head_3).getMemberCallTarget();
        Assert.assertEquals("String c", this.signatureProvider.getSignature(target));
        XExpression _get = block.getExpressions().get(1);
        final XSwitchExpression switchExpr = ((XSwitchExpression) _get);
        XExpression _then = IterableExtensions.<XCasePart>head(switchExpr.getCases()).getThen();
        final XExpression expr = ((XMemberFeatureCall) _then).getMemberCallTarget();
        Assert.assertEquals("String c", this.signatureProvider.getSignature(expr));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XIfExpression(org.eclipse.xtext.xbase.XIfExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XSwitchExpression(org.eclipse.xtext.xbase.XSwitchExpression) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 18 with XtendParameter

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

the class XtendReentrantTypeResolver method computeTypes.

protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, XtendMember member) {
    XExpression expression = null;
    if (member instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) member;
        expression = function.getExpression();
        CreateExtensionInfo createInfo = function.getCreateExtensionInfo();
        if (createInfo != null) {
            computeDanglingExpressionType(resolvedTypes, featureScopeSession, function, createInfo.getCreateExpression());
        }
        for (XtendParameter parameter : function.getParameters()) {
            computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
        }
    } else if (member instanceof XtendConstructor) {
        XtendConstructor constructor = (XtendConstructor) member;
        expression = constructor.getExpression();
        for (XtendParameter parameter : constructor.getParameters()) {
            computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
        }
    } else if (member instanceof XtendField) {
        expression = ((XtendField) member).getInitialValue();
    }
    if (expression != null) {
        computeDanglingExpressionType(resolvedTypes, featureScopeSession, member, expression);
    }
    computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, member.getAnnotations());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XExpression(org.eclipse.xtext.xbase.XExpression) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 19 with XtendParameter

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

the class XtendJvmModelInferrer method transform.

protected void transform(XtendConstructor source, JvmGenericType container) {
    JvmConstructor constructor = typesFactory.createJvmConstructor();
    container.getMembers().add(constructor);
    associator.associatePrimary(source, constructor);
    JvmVisibility visibility = source.getVisibility();
    constructor.setSimpleName(container.getSimpleName());
    constructor.setVisibility(visibility);
    for (XtendParameter parameter : source.getParameters()) {
        translateParameter(constructor, parameter);
    }
    copyAndFixTypeParameters(source.getTypeParameters(), constructor);
    for (JvmTypeReference exception : source.getExceptions()) {
        constructor.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
    }
    translateAnnotationsTo(source.getAnnotations(), constructor);
    setBody(constructor, source.getExpression());
    jvmTypesBuilder.copyDocumentationTo(source, constructor);
}
Also used : XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmVisibility(org.eclipse.xtext.common.types.JvmVisibility)

Example 20 with XtendParameter

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

the class XtendJvmModelInferrer method transform.

protected void transform(XtendFunction source, JvmGenericType container, boolean allowDispatch) {
    JvmOperation operation = typesFactory.createJvmOperation();
    operation.setAbstract(source.isAbstract());
    operation.setNative(source.isNative());
    operation.setSynchronized(source.isSynchonized());
    operation.setStrictFloatingPoint(source.isStrictFloatingPoint());
    if (!source.isAbstract())
        operation.setFinal(source.isFinal());
    container.getMembers().add(operation);
    associator.associatePrimary(source, operation);
    String sourceName = source.getName();
    JvmVisibility visibility = source.getVisibility();
    if (allowDispatch && source.isDispatch()) {
        if (source.getDeclaredVisibility() == null)
            visibility = JvmVisibility.PROTECTED;
        sourceName = "_" + sourceName;
    }
    operation.setSimpleName(sourceName);
    operation.setVisibility(visibility);
    operation.setStatic(source.isStatic());
    if (!operation.isAbstract() && !operation.isStatic() && container.isInterface())
        operation.setDefault(true);
    for (XtendParameter parameter : source.getParameters()) {
        translateParameter(operation, parameter);
    }
    XExpression expression = source.getExpression();
    CreateExtensionInfo createExtensionInfo = source.getCreateExtensionInfo();
    JvmTypeReference returnType = null;
    if (source.getReturnType() != null) {
        returnType = jvmTypesBuilder.cloneWithProxies(source.getReturnType());
    } else if (createExtensionInfo != null) {
        returnType = jvmTypesBuilder.inferredType(createExtensionInfo.getCreateExpression());
    } else if (expression != null) {
        returnType = jvmTypesBuilder.inferredType(expression);
    } else {
        returnType = jvmTypesBuilder.inferredType();
    }
    operation.setReturnType(returnType);
    copyAndFixTypeParameters(source.getTypeParameters(), operation);
    for (JvmTypeReference exception : source.getExceptions()) {
        operation.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
    }
    translateAnnotationsTo(source.getAnnotations(), operation);
    if (source.isOverride() && generatorConfig.getJavaSourceVersion().isAtLeast(JAVA6) && !containsAnnotation(operation, Override.class) && typeReferences.findDeclaredType(Override.class, source) != null) {
        operation.getAnnotations().add(_annotationTypesBuilder.annotationRef(Override.class));
    }
    if (createExtensionInfo != null) {
        transformCreateExtension(source, createExtensionInfo, container, operation, returnType);
    } else {
        setBody(operation, expression);
    }
    jvmTypesBuilder.copyDocumentationTo(source, operation);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmVisibility(org.eclipse.xtext.common.types.JvmVisibility) XExpression(org.eclipse.xtext.xbase.XExpression) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo)

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