Search in sources :

Example 51 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class TypeProviderTest method testParameterizedExtension_06.

@Test
public void testParameterizedExtension_06() throws Exception {
    XtendFile file = file("package testPackage\n" + "import org.eclipse.xtext.testing.util.ParseHelper\n" + "import org.eclipse.xtend.core.xtend.XtendFile\n" + "class C extends ParseHelper<XtendFile> {\n" + "	def m() {" + "		parse('')\n" + "	}\n" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XAbstractFeatureCall parse = findSingleFeatureCall(c);
    assertEquals("org.eclipse.xtext.testing.util.ParseHelper.parse(java.lang.CharSequence)", parse.getFeature().getIdentifier());
    assertEquals("XtendFile", getType(parse).getSimpleName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 52 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class TypeProviderTest method testTypeOfRichStringWithExpectedString_2.

@Ignore("TODO improve expectation if the expected type is an unresolved type parameter")
@Test
public void testTypeOfRichStringWithExpectedString_2() throws Exception {
    XtendFunction function = function("def String foo(String x) {" + "println('''someString''')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XAbstractFeatureCall call = (XAbstractFeatureCall) block.getExpressions().get(0);
    XExpression expression = call.getExplicitArguments().get(0);
    assertEquals("java.lang.String", getType(expression).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 53 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class TypeProviderTest method testTypeOfRichStringWithExpectedString_1.

@Test
public void testTypeOfRichStringWithExpectedString_1() throws Exception {
    XtendFunction function = function("def String foo(String x) {" + "foo('''someString''')" + "}");
    XBlockExpression block = (XBlockExpression) function.getExpression();
    XAbstractFeatureCall call = (XAbstractFeatureCall) block.getExpressions().get(0);
    XExpression expression = call.getExplicitArguments().get(0);
    assertEquals("java.lang.String", getType(expression).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 54 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class XtendHyperlinkHelper method createHyperlinksForCrossRef.

@Override
protected void createHyperlinksForCrossRef(XtextResource resource, INode crossRefNode, IHyperlinkAcceptor acceptor) {
    EObject crossLinkedEObject = getEObjectAtOffsetHelper().getCrossReferencedElement(crossRefNode);
    if (crossLinkedEObject != null && !crossLinkedEObject.eIsProxy()) {
        EObject containedElementAt = getEObjectAtOffsetHelper().resolveContainedElementAt(resource, crossRefNode.getOffset());
        if (containedElementAt instanceof XAbstractFeatureCall) {
            XAbstractFeatureCall casted = (XAbstractFeatureCall) containedElementAt;
            if (casted.getFeature() == crossLinkedEObject) {
                IFeatureLinkingCandidate candidate = getBatchTypeResolver().resolveTypes(casted).getLinkingCandidate(casted);
                if (candidate instanceof IAmbiguousLinkingCandidate) {
                    createMultipleLinks(resource, crossRefNode, ((IAmbiguousLinkingCandidate) candidate).getAlternatives(), acceptor);
                } else if (candidate instanceof ISuspiciouslyOverloadedCandidate) {
                    ISuspiciouslyOverloadedCandidate castedCandidate = (ISuspiciouslyOverloadedCandidate) candidate;
                    createMultipleLinks(resource, crossRefNode, Lists.newArrayList(castedCandidate.getChosenCandidate(), castedCandidate.getRejectedCandidate()), acceptor);
                }
            }
        } else if (containedElementAt instanceof XConstructorCall) {
            XConstructorCall casted = (XConstructorCall) containedElementAt;
            if (casted.getConstructor() == crossLinkedEObject) {
                IConstructorLinkingCandidate candidate = getBatchTypeResolver().resolveTypes(casted).getLinkingCandidate(casted);
                if (candidate instanceof IAmbiguousLinkingCandidate) {
                    createMultipleLinks(resource, crossRefNode, ((IAmbiguousLinkingCandidate) candidate).getAlternatives(), acceptor);
                }
            }
        }
    }
    super.createHyperlinksForCrossRef(resource, crossRefNode, acceptor);
}
Also used : ISuspiciouslyOverloadedCandidate(org.eclipse.xtext.xbase.typesystem.computation.ISuspiciouslyOverloadedCandidate) IConstructorLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IConstructorLinkingCandidate) IAmbiguousLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IAmbiguousLinkingCandidate) EObject(org.eclipse.emf.ecore.EObject) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) IFeatureLinkingCandidate(org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)

Example 55 with XAbstractFeatureCall

use of org.eclipse.xtext.xbase.XAbstractFeatureCall in project xtext-xtend by eclipse.

the class XtendHoverDocumentationProviderTest method testJavaDocWithLinkToXtendFunctionOnReference.

@Test
public void testJavaDocWithLinkToXtendFunctionOnReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testpackage");
        _builder.newLine();
        _builder.newLine();
        _builder.append("import java.util.List");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* SimpleJavaDoc");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("* {@link testpackage.Foo#foo(java.util.List)}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(String a, String b){");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo(List a){");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("bar(\"42\",\"43\")");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendMember _get = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers().get(1);
        final XtendFunction function = ((XtendFunction) _get);
        XExpression _expression = function.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XAbstractFeatureCall call = ((XAbstractFeatureCall) _get_1);
        final String docu = this.documentationProvider.getDocumentation(call.getFeature());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("SimpleJavaDoc");
        _builder_1.newLine();
        _builder_1.append("<code><a href=\"eclipse-xtext-doc:__synthetic0.xtend%23/1/@members.2\">testpackage.Foo#foo(java.util.List)</a></code><dl><dt>Parameters:</dt><dd><b>a</b> </dd><dd><b>b</b> </dd></dl>");
        Assert.assertEquals(_builder_1.toString(), docu);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Aggregations

XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)122 Test (org.junit.Test)105 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)104 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)42 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)21 XExpression (org.eclipse.xtext.xbase.XExpression)17 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)11 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)9 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)6 EObject (org.eclipse.emf.ecore.EObject)5 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)4 IFeatureLinkingCandidate (org.eclipse.xtext.xbase.typesystem.computation.IFeatureLinkingCandidate)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)3 AbstractDiagnostic (org.eclipse.xtext.diagnostics.AbstractDiagnostic)3 XClosure (org.eclipse.xtext.xbase.XClosure)3