Search in sources :

Example 86 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.

the class LinkingTest method testImplicitFirstArgument_00_b.

@Test
public void testImplicitFirstArgument_00_b() throws Exception {
    XtendClass clazz = clazz("class MyXtendClass {\n" + "  def prependHello(String myString) {\n" + "  }\n" + "  def testExtensionMethods(String it) {\n" + "    prependHello\n" + "  }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(1);
    XFeatureCall first = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation firstFeature = (JvmOperation) first.getFeature();
    assertEquals("prependHello", firstFeature.getSimpleName());
    assertNull(first.getInvalidFeatureIssueCode(), first.getInvalidFeatureIssueCode());
    assertNotNull(first.getImplicitFirstArgument());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) Test(org.junit.Test)

Example 87 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.

the class LinkingTest method testImplicitFirstArgument_06.

@Test
public void testImplicitFirstArgument_06() throws Exception {
    XtendClass clazz = clazz("import static extension test.ImplicitFirstArgumentStatics.*\n" + "class MyXtendClass {\n" + "  def testExtensionMethods(CharSequence it) {\n" + "    contains\n" + "  }\n" + "  extension String" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XFeatureCall sixth = (XFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmOperation sixthFeature = (JvmOperation) sixth.getFeature();
    assertEquals("java.lang.String.contains(java.lang.CharSequence)", sixthFeature.getIdentifier());
    assertEquals("java.lang.String", sixthFeature.getDeclaringType().getQualifiedName());
    assertNotNull(sixth.getImplicitFirstArgument());
    assertEquals("it", ((XAbstractFeatureCall) sixth.getImplicitFirstArgument()).getFeature().getSimpleName());
    XMemberFeatureCall sixthReceiver = (XMemberFeatureCall) sixth.getImplicitReceiver();
    assertTrue(sixthReceiver.getFeature() instanceof JvmField);
    assertNull(sixth.getInvalidFeatureIssueCode(), sixth.getInvalidFeatureIssueCode());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) JvmField(org.eclipse.xtext.common.types.JvmField) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) Test(org.junit.Test)

Example 88 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.

the class XtendHoverDocumentationProvider method handleSuperMethodReferences.

@Override
protected void handleSuperMethodReferences(EObject context) {
    if (context instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) context;
        if (function.isOverride()) {
            JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function);
            if (inferredOperation != null) {
                JvmOperation overridden = overrideHelper.findOverriddenOperation(inferredOperation);
                if (overridden != null) {
                    // $NON-NLS-1$
                    buffer.append("<div>");
                    // $NON-NLS-1$
                    buffer.append("<b>");
                    // $NON-NLS-1$
                    buffer.append("Overrides:");
                    // $NON-NLS-1$
                    buffer.append("</b> ");
                    buffer.append(createMethodInTypeLinks(overridden));
                    // $NON-NLS-1$
                    buffer.append("</div>");
                }
            }
        }
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation)

Example 89 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.

the class XtendHoverSignatureProvider method _signature.

protected String _signature(XtendFunction function, boolean typeAtEnd) {
    JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function);
    if (inferredOperation != null) {
        String returnTypeString = "void";
        JvmTypeReference returnType = inferredOperation.getReturnType();
        if (returnType != null) {
            if (returnType instanceof JvmAnyTypeReference) {
                throw new IllegalStateException();
            } else {
                returnTypeString = getTypeName(returnType);
            }
        }
        StringBuilder signature = new StringBuilder();
        String typeParameter = uiStrings.typeParameters(function.getTypeParameters());
        if (typeParameter != null && typeParameter.length() > 0) {
            signature.append(typeParameter).append(" ");
        }
        signature.append(returnTypeString).append(" ");
        signature.append(function.getName()).append(hoverUiStrings.parameters(inferredOperation));
        signature.append(getThrowsDeclaration(inferredOperation));
        return signature.toString();
    }
    return function.getName() + "()";
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmAnyTypeReference(org.eclipse.xtext.common.types.JvmAnyTypeReference)

Example 90 with JvmOperation

use of org.eclipse.xtext.common.types.JvmOperation in project xtext-xtend by eclipse.

the class XtendHoverSignatureProvider method getSimpleSignature.

@Override
protected String getSimpleSignature(EObject container) {
    if (container instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) container;
        JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function);
        if (inferredOperation != null) {
            return function.getName() + uiStrings.parameters(inferredOperation);
        }
    } else if (container instanceof XtendConstructor) {
        XtendConstructor constructor = (XtendConstructor) container;
        XtendClass xtendClazz = EcoreUtil2.getContainerOfType(constructor, XtendClass.class);
        JvmConstructor inferredConstructor = associations.getInferredConstructor(constructor);
        return xtendClazz.getName() + " " + uiStrings.parameters(inferredConstructor);
    }
    return super.getSimpleSignature(container);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor)

Aggregations

JvmOperation (org.eclipse.xtext.common.types.JvmOperation)202 Test (org.junit.Test)127 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)101 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)73 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)38 EObject (org.eclipse.emf.ecore.EObject)30 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)26 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)22 XExpression (org.eclipse.xtext.xbase.XExpression)20 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)20 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)20 JvmField (org.eclipse.xtext.common.types.JvmField)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)15 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)15 JvmMember (org.eclipse.xtext.common.types.JvmMember)15 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10