Search in sources :

Example 21 with AnonymousClass

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

the class XtendProposalProvider method completeMember_Members.

@Override
public void completeMember_Members(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (isValidTypeForOverriding(model)) {
        INode node = context.getCurrentNode();
        EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
        if (!(eObject instanceof AnonymousClass)) {
            overrideAssist.createOverrideProposals((XtendTypeDeclaration) model, context, acceptor, getConflictHelper());
            return;
        }
    } else if (model instanceof XtendField) {
        /*
			 * class C {
			 *   static class C2 {
			 *     toS<|>
			 *   }
			 * }
			 *
			 * At this cursor position, we get a field without a name and the type 'toS' as the context.
			 * If there's a field decl preceding the cursor position, the field will have a name.
			 */
        XtendField field = (XtendField) model;
        if (isValidTypeForOverriding(field.eContainer())) {
            overrideAssist.createOverrideProposals((XtendTypeDeclaration) field.eContainer(), context, acceptor, getConflictHelper());
            return;
        }
    } else if (model instanceof XtendExecutable && context.getPrefix().length() == 0 && isValidTypeForOverriding(model.eContainer())) {
        overrideAssist.createOverrideProposals((XtendTypeDeclaration) model.eContainer(), context, acceptor, getConflictHelper());
        return;
    } else if (model instanceof XExpression) {
        XtendMember member = EcoreUtil2.getContainerOfType(model, XtendMember.class);
        INode memberNode = NodeModelUtils.findActualNodeFor(member);
        if (memberNode.getTotalEndOffset() <= context.getOffset()) {
            if (isValidTypeForOverriding(member.eContainer())) {
                overrideAssist.createOverrideProposals((XtendTypeDeclaration) member.eContainer(), context, acceptor, getConflictHelper());
                return;
            }
        }
    }
    INode node = context.getCurrentNode();
    EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
    if (isValidTypeForOverriding(eObject))
        overrideAssist.createOverrideProposals((XtendTypeDeclaration) eObject, context, acceptor, getConflictHelper());
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) XtendExecutable(org.eclipse.xtend.core.xtend.XtendExecutable) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 22 with AnonymousClass

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

the class XtendProposalProvider method completeXConstructorCall_Members.

@Override
public void completeXConstructorCall_Members(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (model instanceof AnonymousClass) {
        overrideAssist.createOverrideProposals((AnonymousClass) model, context, acceptor, getConflictHelper());
        return;
    } else if (model instanceof XtendField) {
        /*
			 * class C {
			 *   val x = new Object() {
			 *     toS<|>
			 *   }
			 * }
			 *
			 * At this cursor position, we get a field without a name and the type 'toS' as the context.
			 * If there's a field decl preceding the cursor position, the field will have a name.
			 */
        XtendField field = (XtendField) model;
        if (field.eContainer() instanceof AnonymousClass) {
            overrideAssist.createOverrideProposals((AnonymousClass) field.eContainer(), context, acceptor, getConflictHelper());
            return;
        }
    } else if (model instanceof XtendExecutable && context.getPrefix().length() == 0 && model.eContainer() instanceof AnonymousClass) {
        overrideAssist.createOverrideProposals((AnonymousClass) model.eContainer(), context, acceptor, getConflictHelper());
        return;
    } else if (model instanceof XExpression) {
        XtendMember member = EcoreUtil2.getContainerOfType(model, XtendMember.class);
        INode memberNode = NodeModelUtils.findActualNodeFor(member);
        if (memberNode.getTotalEndOffset() <= context.getOffset()) {
            if (member.eContainer() instanceof AnonymousClass) {
                overrideAssist.createOverrideProposals((AnonymousClass) member.eContainer(), context, acceptor, getConflictHelper());
                return;
            }
        }
    }
    INode node = context.getCurrentNode();
    EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
    if (eObject instanceof AnonymousClass)
        overrideAssist.createOverrideProposals((XtendTypeDeclaration) eObject, context, acceptor, getConflictHelper());
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) XtendExecutable(org.eclipse.xtend.core.xtend.XtendExecutable) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 23 with AnonymousClass

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

the class LinkingTest method testQualifiedThisOuter.

@Test
public void testQualifiedThisOuter() throws Exception {
    XtendFile file = file("class C {\n" + "  def void m() { new Object { def m3() { C.this.m2() } } }\n" + "  def void m2() {}\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression outer = (XBlockExpression) m.getExpression();
    AnonymousClass anonymousClass = (AnonymousClass) outer.getExpressions().get(0);
    XtendFunction m3 = (XtendFunction) anonymousClass.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m3.getExpression();
    XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("C.m2()", feature.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) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Aggregations

AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)23 XExpression (org.eclipse.xtext.xbase.XExpression)13 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)10 Test (org.junit.Test)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)9 EObject (org.eclipse.emf.ecore.EObject)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 JvmType (org.eclipse.xtext.common.types.JvmType)7 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)4 JvmMember (org.eclipse.xtext.common.types.JvmMember)3 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)3 INode (org.eclipse.xtext.nodemodel.INode)3 IScope (org.eclipse.xtext.scoping.IScope)3 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)3