Search in sources :

Example 11 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 12 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 13 with XtendParameter

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

the class XtendUIValidationTests method testParameterizedTypeReference.

@Test
public void testParameterizedTypeReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(org.eclipse.xtend.core.tests.restricted.RestrictedClass<org.eclipse.xtend.core.tests.internal.InternalClass> x) {}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
        XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
        final XtendFunction function = ((XtendFunction) _head);
        final XtendParameter parameter = function.getParameters().get(0);
        JvmTypeReference _parameterType = parameter.getParameterType();
        final JvmParameterizedTypeReference type = ((JvmParameterizedTypeReference) _parameterType);
        final JvmTypeReference typeParameter = type.getArguments().get(0);
        this.helper.assertError(type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
        this.helper.assertWarning(typeParameter, TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.DISCOURAGED_REFERENCE);
    } 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) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 14 with XtendParameter

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

the class XtendProposalProvider method completeParameter_Name.

@Override
public void completeParameter_Name(final EObject model, Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
    if (model instanceof XtendParameter) {
        final List<XtendParameter> siblings = EcoreUtil2.getSiblingsOfType(model, XtendParameter.class);
        Set<String> alreadyTaken = Sets.newHashSet();
        for (XtendParameter sibling : siblings) {
            alreadyTaken.add(sibling.getName());
        }
        alreadyTaken.addAll(getAllKeywords());
        completions.getVariableProposals(model, XtendPackage.Literals.XTEND_PARAMETER__PARAMETER_TYPE, VariableType.PARAMETER, alreadyTaken, new JdtVariableCompletions.CompletionDataAcceptor() {

            @Override
            public void accept(String replaceText, StyledString label, Image img) {
                acceptor.accept(createCompletionProposal(replaceText, label, img, context));
            }
        });
    } else {
        super.completeParameter_Name(model, assignment, context, acceptor);
    }
}
Also used : XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) JdtVariableCompletions(org.eclipse.xtext.common.types.xtext.ui.JdtVariableCompletions) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image)

Example 15 with XtendParameter

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

the class XtendHoverSignatureProviderTest method testEnumReference.

@Test
public void testEnumReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def baz(Foo f){}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("enum Foo { BAR, BAZ }");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers());
        final JvmType en = IterableExtensions.<XtendParameter>head(((XtendFunction) _head).getParameters()).getParameterType().getType();
        Assert.assertEquals("Foo", this.signatureProvider.getSignature(en));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) 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