Search in sources :

Example 1 with XtendExecutable

use of org.eclipse.xtend.core.xtend.XtendExecutable 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 2 with XtendExecutable

use of org.eclipse.xtend.core.xtend.XtendExecutable 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 3 with XtendExecutable

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

the class XtendQuickfixProvider method addThrowsDeclaration.

@Fix(org.eclipse.xtext.xbase.validation.IssueCodes.UNHANDLED_EXCEPTION)
public void addThrowsDeclaration(final Issue issue, IssueResolutionAcceptor acceptor) {
    if (issue.getData() != null && issue.getData().length > 0)
        acceptor.accept(issue, "Add throws declaration", "Add throws declaration", "fix_indent.gif", new ISemanticModification() {

            @Override
            public void apply(EObject element, IModificationContext context) throws Exception {
                String[] issueData = issue.getData();
                XtendExecutable xtendExecutable = EcoreUtil2.getContainerOfType(element, XtendExecutable.class);
                XtextResource xtextResource = (XtextResource) xtendExecutable.eResource();
                List<JvmType> exceptions = getExceptions(issueData, xtextResource);
                if (exceptions.size() > 0) {
                    int insertPosition;
                    if (xtendExecutable.getExpression() == null) {
                        ICompositeNode functionNode = NodeModelUtils.findActualNodeFor(xtendExecutable);
                        if (functionNode == null)
                            throw new IllegalStateException("functionNode may not be null");
                        insertPosition = functionNode.getEndOffset();
                    } else {
                        ICompositeNode expressionNode = NodeModelUtils.findActualNodeFor(xtendExecutable.getExpression());
                        if (expressionNode == null)
                            throw new IllegalStateException("expressionNode may not be null");
                        insertPosition = expressionNode.getOffset();
                    }
                    ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) xtendExecutable.eResource(), insertPosition, 0);
                    if (xtendExecutable.getExpression() == null)
                        appendable.append(" ");
                    EList<JvmTypeReference> thrownExceptions = xtendExecutable.getExceptions();
                    if (thrownExceptions.isEmpty())
                        appendable.append("throws ");
                    else
                        appendable.append(", ");
                    for (int i = 0; i < exceptions.size(); i++) {
                        appendable.append(exceptions.get(i));
                        if (i != exceptions.size() - 1) {
                            appendable.append(", ");
                        }
                    }
                    if (xtendExecutable.getExpression() != null)
                        appendable.append(" ");
                    appendable.commitChanges();
                }
            }
        });
}
Also used : ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) XtextResource(org.eclipse.xtext.resource.XtextResource) JvmType(org.eclipse.xtext.common.types.JvmType) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) XtendExecutable(org.eclipse.xtend.core.xtend.XtendExecutable) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)3 XtendExecutable (org.eclipse.xtend.core.xtend.XtendExecutable)3 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)2 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)2 INode (org.eclipse.xtext.nodemodel.INode)2 XExpression (org.eclipse.xtext.xbase.XExpression)2 JvmType (org.eclipse.xtext.common.types.JvmType)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)1 ISemanticModification (org.eclipse.xtext.ui.editor.model.edit.ISemanticModification)1 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)1 ReplacingAppendable (org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable)1