Search in sources :

Example 86 with XtendTypeDeclaration

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

the class CodeBuilderQuickfix method getXtendModification.

protected IModification getXtendModification(final ICodeBuilder.Xtend builder) {
    final IModification _function = (IModificationContext it) -> {
        final XtendTypeDeclaration xtendClass = builder.getXtendType();
        final IEditorPart editor = this.editorOpener.open(EcoreUtil.getURI(xtendClass), false);
        if ((!(editor instanceof XtextEditor))) {
            return;
        }
        final XtextEditor xtextEditor = ((XtextEditor) editor);
        final IXtextDocument document = xtextEditor.getDocument();
        final Wrapper<Integer> wrapper = Wrapper.<Integer>forType(Integer.class);
        final IUnitOfWork<ReplacingAppendable, XtextResource> _function_1 = (XtextResource resource) -> {
            ReplacingAppendable _xblockexpression = null;
            {
                int offset = builder.getInsertOffset(resource);
                wrapper.set(Integer.valueOf(offset));
                final int typeIndentation = this.getTypeIndentation(resource, document, xtendClass);
                DocumentSourceAppender.Factory.OptionalParameters _optionalParameters = new DocumentSourceAppender.Factory.OptionalParameters();
                final Procedure1<DocumentSourceAppender.Factory.OptionalParameters> _function_2 = (DocumentSourceAppender.Factory.OptionalParameters it_1) -> {
                    int _indentationLevel = builder.getIndentationLevel();
                    int _plus = (_indentationLevel + typeIndentation);
                    it_1.baseIndentationLevel = _plus;
                    it_1.ensureEmptyLinesAround = true;
                };
                DocumentSourceAppender.Factory.OptionalParameters _doubleArrow = ObjectExtensions.<DocumentSourceAppender.Factory.OptionalParameters>operator_doubleArrow(_optionalParameters, _function_2);
                _xblockexpression = this.appendableFactory.create(document, resource, offset, 0, _doubleArrow);
            }
            return _xblockexpression;
        };
        final ReplacingAppendable appendable = document.<ReplacingAppendable>readOnly(_function_1);
        Integer offset = wrapper.get();
        builder.build(appendable);
        appendable.commitChanges();
        xtextEditor.setHighlightRange(((offset).intValue() + 1), appendable.length(), true);
    };
    return _function;
}
Also used : Wrapper(org.eclipse.xtext.util.Wrapper) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) XtextResource(org.eclipse.xtext.resource.XtextResource) IEditorPart(org.eclipse.ui.IEditorPart) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) DocumentSourceAppender(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 87 with XtendTypeDeclaration

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

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

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

the class CreateXtendTypeQuickfixes method newLocalXtendClassQuickfix.

protected void newLocalXtendClassQuickfix(String typeName, XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    EObject eObject = resource.getEObject(issue.getUriToProblem().fragment());
    XtendTypeDeclaration xtendType = getAnnotationTarget(eObject);
    if (xtendType != null) {
        JvmDeclaredType inferredType = associations.getInferredType(xtendType);
        if (inferredType != null) {
            AbstractClassBuilder classBuilder = codeBuilderFactory.createClassBuilder(inferredType);
            classBuilder.setClassName(typeName);
            classBuilder.setVisibility(JvmVisibility.PUBLIC);
            classBuilder.setContext(xtendType);
            classBuilder.setImage("xtend_file.png");
            codeBuilderQuickfix.addQuickfix(classBuilder, "Create local Xtend class '" + typeName + "'", issue, issueResolutionAcceptor);
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) AbstractClassBuilder(org.eclipse.xtend.ide.codebuilder.AbstractClassBuilder) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 90 with XtendTypeDeclaration

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

the class CreateXtendTypeQuickfixes method newLocalXtendAnnotationQuickfix.

protected void newLocalXtendAnnotationQuickfix(String typeName, XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    EObject eObject = resource.getEObject(issue.getUriToProblem().fragment());
    XtendTypeDeclaration xtendType = getAnnotationTarget(eObject);
    if (xtendType != null) {
        JvmDeclaredType inferredType = associations.getInferredType(xtendType);
        if (inferredType != null) {
            AbstractAnnotationBuilder annotationBuilder = codeBuilderFactory.createAnnotationBuilder(inferredType);
            annotationBuilder.setAnnotationName(typeName);
            annotationBuilder.setVisibility(JvmVisibility.PUBLIC);
            annotationBuilder.setContext(xtendType);
            codeBuilderQuickfix.addQuickfix(annotationBuilder, "Create local Xtend annotation '@" + typeName + "'", issue, issueResolutionAcceptor);
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) AbstractAnnotationBuilder(org.eclipse.xtend.ide.codebuilder.AbstractAnnotationBuilder)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)134 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)98 Test (org.junit.Test)91 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)77 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)34 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)12 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8