Search in sources :

Example 6 with XConstructorCall

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

the class UIStringsTest method testReferenceToString_0.

/**
 * Only the simple name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_0() throws Exception {
    XtendFile file = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "public interface InterfaceA { }\n" + "public class ClassB implements InterfaceA { }\n" + "public class ClassC extends ClassB {\n" + "}\n" + "class XtendClass1 {\n" + "  def test() {\n" + "    val x = new List<ClassC>\n" + "  }\n" + "}\n");
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
    XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
    XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
    XConstructorCall cons = (XConstructorCall) declaration.getRight();
    JvmTypeReference reference = cons.getTypeArguments().get(0);
    assertNotNull(reference);
    assertNotNull(reference.getType());
    assertFalse(reference.getType().eIsProxy());
    assertNotNull(reference.eResource());
    assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) Test(org.junit.Test)

Example 7 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall 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 8 with XConstructorCall

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

the class XtendHoverSignatureProviderTest method testSignatureConstructorCall_02.

@Test
public void testSignatureConstructorCall_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo<S> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Foo(StringBuilder, StringBuffer)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new <X>(Class<X> c, Class<S> c2) {}");
        _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);
        XExpression _expression = xtendFunction.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XConstructorCall constructorCall = ((XConstructorCall) _get_1);
        final String signature = this.signatureProvider.getSignature(constructorCall);
        Assert.assertEquals("<StringBuilder> Foo<StringBuffer>(Class<StringBuilder> c, Class<StringBuffer> c2)", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 9 with XConstructorCall

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

the class XtendHoverSignatureProviderTest method testSignatureConstructorCall_01.

@Test
public void testSignatureConstructorCall_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo<S extends CharSequence> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Foo()");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _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);
        XExpression _expression = xtendFunction.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XConstructorCall constructorCall = ((XConstructorCall) _get_1);
        final String signature = this.signatureProvider.getSignature(constructorCall);
        Assert.assertEquals("Foo<CharSequence>()", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 10 with XConstructorCall

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

the class XtendHoverSignatureProviderTest method testSignatureConstructorCall_03.

@Test
public void testSignatureConstructorCall_03() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo<S> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Foo<String>()");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _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);
        XExpression _expression = xtendFunction.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XConstructorCall constructorCall = ((XConstructorCall) _get_1);
        final String signature = this.signatureProvider.getSignature(constructorCall);
        Assert.assertEquals("Foo<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) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)24 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)12 Test (org.junit.Test)11 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 XExpression (org.eclipse.xtext.xbase.XExpression)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)6 EObject (org.eclipse.emf.ecore.EObject)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)3 RichString (org.eclipse.xtend.core.xtend.RichString)2 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2