Search in sources :

Example 1 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, int baseIndentationLevel, boolean ensureEmptyLinesAround) {
    OptionalParameters parameters = createOptionalParameters();
    parameters.ensureEmptyLinesAround = ensureEmptyLinesAround;
    parameters.baseIndentationLevel = baseIndentationLevel;
    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 2 with OptionalParameters

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

the class CreateMemberQuickfixes method newLocalVariableQuickfix.

protected void newLocalVariableQuickfix(final String variableName, XAbstractFeatureCall call, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    LightweightTypeReference variableType = getNewMemberType(call);
    final StringBuilderBasedAppendable localVarDescriptionBuilder = new StringBuilderBasedAppendable();
    localVarDescriptionBuilder.append("...").newLine();
    final String defaultValueLiteral = getDefaultValueLiteral(variableType);
    localVarDescriptionBuilder.append("val ").append(variableName).append(" = ").append(defaultValueLiteral);
    localVarDescriptionBuilder.newLine().append("...");
    issueResolutionAcceptor.accept(issue, "Create local variable '" + variableName + "'", localVarDescriptionBuilder.toString(), "fix_local_var.png", new SemanticModificationWrapper(issue.getUriToProblem(), new ISemanticModification() {

        @Override
        public void apply(/* @Nullable */
        final EObject element, /* @Nullable */
        final IModificationContext context) throws Exception {
            if (element != null) {
                XtendMember xtendMember = EcoreUtil2.getContainerOfType(element, XtendMember.class);
                if (xtendMember != null) {
                    int offset = getFirstOffsetOfKeyword(xtendMember, "{");
                    IXtextDocument xtextDocument = context.getXtextDocument();
                    if (offset != -1 && xtextDocument != null) {
                        final ReplacingAppendable appendable = appendableFactory.create(xtextDocument, (XtextResource) element.eResource(), offset, 0, new OptionalParameters() {

                            {
                                baseIndentationLevel = 1;
                            }
                        });
                        appendable.increaseIndentation().newLine().append("val ").append(variableName).append(" = ").append(defaultValueLiteral);
                        appendable.commitChanges();
                    }
                }
            }
        }
    }));
}
Also used : OptionalParameters(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) SemanticModificationWrapper(org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper) EObject(org.eclipse.emf.ecore.EObject) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) StringBuilderBasedAppendable(org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 3 with OptionalParameters

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

the class CreateMemberQuickfixes method newLocalVariableQuickfix.

protected void newLocalVariableQuickfix(final String variableName, boolean isFinal, XAbstractFeatureCall call, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
    LightweightTypeReference variableType = getNewMemberType(call);
    final StringBuilderBasedAppendable localVarDescriptionBuilder = new StringBuilderBasedAppendable();
    localVarDescriptionBuilder.append("...").newLine();
    final String defaultValueLiteral = getDefaultValueLiteral(variableType);
    localVarDescriptionBuilder.append(isFinal ? "val " : "var ").append(variableName).append(" = ").append(defaultValueLiteral);
    localVarDescriptionBuilder.newLine().append("...");
    issueResolutionAcceptor.accept(issue, "Create local " + (isFinal ? "value" : "variable") + " '" + variableName + "'", localVarDescriptionBuilder.toString(), "fix_local_var.png", new SemanticModificationWrapper(issue.getUriToProblem(), new ISemanticModification() {

        @Override
        public void apply(/* @Nullable */
        final EObject element, /* @Nullable */
        final IModificationContext context) throws Exception {
            if (element != null) {
                XtendMember xtendMember = EcoreUtil2.getContainerOfType(element, XtendMember.class);
                if (xtendMember != null) {
                    int offset = getFirstOffsetOfKeyword(xtendMember, "{");
                    IXtextDocument xtextDocument = context.getXtextDocument();
                    if (offset != -1 && xtextDocument != null) {
                        final ReplacingAppendable appendable = appendableFactory.create(xtextDocument, (XtextResource) element.eResource(), offset, 0, new OptionalParameters() {

                            {
                                baseIndentationLevel = 1;
                            }
                        });
                        appendable.increaseIndentation().newLine().append(isFinal ? "val " : "var ").append(variableName).append(" = ").append(defaultValueLiteral);
                        appendable.commitChanges();
                    }
                }
            }
        }
    }));
}
Also used : OptionalParameters(org.eclipse.xtext.xbase.ui.document.DocumentSourceAppender.Factory.OptionalParameters) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) SemanticModificationWrapper(org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper) EObject(org.eclipse.emf.ecore.EObject) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) StringBuilderBasedAppendable(org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 4 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)

Example 5 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)

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