Search in sources :

Example 1 with XMemberFeatureCall

use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-eclipse by eclipse.

the class XbaseProposalProvider method completeXFeatureCall_Feature.

@Override
public void completeXFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (model != null) {
        if (typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN)) {
            return;
        }
    }
    if (model instanceof XMemberFeatureCall) {
        ICompositeNode node = NodeModelUtils.getNode(model);
        int endOffset = node.getEndOffset();
        if (isInMemberFeatureCall(model, endOffset, context)) {
            return;
        }
    }
    createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor);
}
Also used : XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 2 with XMemberFeatureCall

use of org.eclipse.xtext.xbase.XMemberFeatureCall in project xtext-eclipse by eclipse.

the class XbaseQuickfixProvider method fixInvisibleFeature.

@Fix(IssueCodes.FEATURE_NOT_VISIBLE)
public void fixInvisibleFeature(final Issue issue, IssueResolutionAcceptor acceptor) {
    if (issue.getData() != null && issue.getData().length >= 1 && "subclass-context".equals(issue.getData()[0])) {
        String fixup;
        if (issue.getData().length == 1)
            fixup = "Add type cast.";
        else
            fixup = "Add cast to " + issue.getData()[1] + ".";
        acceptor.accept(issue, fixup, fixup, null, new ISemanticModification() {

            @Override
            public void apply(EObject element, IModificationContext context) throws Exception {
                if (!(element instanceof XAbstractFeatureCall))
                    return;
                XAbstractFeatureCall featureCall = (XAbstractFeatureCall) element;
                if (!(featureCall.getFeature() instanceof JvmMember))
                    return;
                JvmType declaringType = ((JvmMember) featureCall.getFeature()).getDeclaringType();
                if (featureCall instanceof XMemberFeatureCall) {
                    addTypeCastToExplicitReceiver(featureCall, context, declaringType, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET);
                } else if (featureCall instanceof XAssignment) {
                    addTypeCastToExplicitReceiver(featureCall, context, declaringType, XbasePackage.Literals.XASSIGNMENT__ASSIGNABLE);
                } else if (featureCall instanceof XFeatureCall) {
                    addTypeCastToImplicitReceiver((XFeatureCall) featureCall, context, declaringType);
                }
            }
        });
    }
}
Also used : XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) EObject(org.eclipse.emf.ecore.EObject) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmType(org.eclipse.xtext.common.types.JvmType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) WrappedException(org.eclipse.emf.common.util.WrappedException) BadLocationException(org.eclipse.jface.text.BadLocationException) XAssignment(org.eclipse.xtext.xbase.XAssignment) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 3 with XMemberFeatureCall

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

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

the class LinkingTest method testExtensionMethodCall_Bug351827_04.

@Test
public void testExtensionMethodCall_Bug351827_04() throws Exception {
    XtendClass clazz = clazz("" + "class Foo {" + "  extension testdata.Properties1 p\n" + "  def setProp1(String s) { s }" + "  def foo(String s) {\n" + "    s.setProp1()\n" + "  }\n" + "}");
    XtendFunction func = (XtendFunction) clazz.getMembers().get(2);
    final XMemberFeatureCall call = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    assertEquals("Foo.setProp1(java.lang.String)", call.getFeature().getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 5 with XMemberFeatureCall

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

the class LinkingTest method testBug405144_01.

@Test
public void testBug405144_01() throws Exception {
    XtendFile file = file("import com.google.inject.Injector\n" + "class C {\n" + "	def m(Injector i, Class<? extends CharSequence> c) {\n" + "		i.getInstance(c)\n" + "	}\n" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement method = featureCall.getFeature();
    assertEquals("com.google.inject.Injector.getInstance(java.lang.Class)", method.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Aggregations

XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)95 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)84 Test (org.junit.Test)83 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)78 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)74 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)46 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)22 XExpression (org.eclipse.xtext.xbase.XExpression)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)6 XIfExpression (org.eclipse.xtext.xbase.XIfExpression)6 XSwitchExpression (org.eclipse.xtext.xbase.XSwitchExpression)6 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)5 XAssignment (org.eclipse.xtext.xbase.XAssignment)5 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)4 XClosure (org.eclipse.xtext.xbase.XClosure)4