Search in sources :

Example 6 with OptionalParameters

use of org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters in project xtext-xtend by eclipse.

the class XtendQuickfixProvider method doOverrideMethods.

protected void doOverrideMethods(final Issue issue, IssueResolutionAcceptor acceptor, String label, final String[] operationUris) {
    acceptor.accept(issue, label, label, "fix_indent.gif", new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            XtendTypeDeclaration clazz = (XtendTypeDeclaration) element;
            JvmGenericType inferredType = (JvmGenericType) associations.getInferredType(clazz);
            ResolvedFeatures resolvedOperations = overrideHelper.getResolvedFeatures(inferredType);
            IXtextDocument document = context.getXtextDocument();
            final int offset = insertionOffsets.getNewMethodInsertOffset(null, clazz);
            int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, (XtextResource) clazz.eResource());
            final int indentationToUse = clazz.getMembers().isEmpty() ? currentIndentation + 1 : currentIndentation;
            ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(), offset, 0, new OptionalParameters() {

                {
                    ensureEmptyLinesAround = true;
                    baseIndentationLevel = indentationToUse;
                }
            });
            boolean isFirst = true;
            for (String operationUriAsString : operationUris) {
                URI operationURI = URI.createURI(operationUriAsString);
                EObject overridden = clazz.eResource().getResourceSet().getEObject(operationURI, true);
                if (overridden instanceof JvmOperation) {
                    if (!isFirst)
                        appendable.newLine().newLine();
                    isFirst = false;
                    superMemberImplementor.appendOverrideFunction(clazz, resolvedOperations.getResolvedOperation((JvmOperation) overridden), appendable);
                }
            }
            appendable.commitChanges();
        }
    });
}
Also used : ResolvedFeatures(org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) URI(org.eclipse.emf.common.util.URI) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) OptionalParameters(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters) EObject(org.eclipse.emf.ecore.EObject) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 7 with OptionalParameters

use of org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters in project xtext-eclipse by eclipse.

the class DocumentRewriter method newSection.

public Section newSection(int offset, int length) {
    OptionalParameters parameters = createOptionalParameters();
    Section section = factory.sectionFactory.create(document, resource, offset, length, parameters);
    addSection(section);
    return section;
}
Also used : OptionalParameters(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters) RewritableImportSection(org.eclipse.xtext.xbase.imports.RewritableImportSection)

Example 8 with OptionalParameters

use of org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters in project xtext-eclipse by eclipse.

the class DocumentRewriter method createOptionalParameters.

protected OptionalParameters createOptionalParameters() {
    OptionalParameters parameters = new OptionalParameters();
    parameters.importSection = importSection;
    return parameters;
}
Also used : OptionalParameters(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters)

Aggregations

OptionalParameters (org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters)8 ReplacingAppendable (org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable)5 EObject (org.eclipse.emf.ecore.EObject)4 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)4 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)4 ISemanticModification (org.eclipse.xtext.ui.editor.model.edit.ISemanticModification)4 XtextResource (org.eclipse.xtext.resource.XtextResource)3 CoreException (org.eclipse.core.runtime.CoreException)2 URI (org.eclipse.emf.common.util.URI)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 SemanticModificationWrapper (org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper)2 StringBuilderBasedAppendable (org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable)2 RewritableImportSection (org.eclipse.xtext.xbase.imports.RewritableImportSection)2 ResolvedFeatures (org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 Matcher (java.util.regex.Matcher)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1