Search in sources :

Example 51 with MapBasedPreferenceValues

use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-core by eclipse.

the class FormattableDocumentTest method autowrapNotInPreviousLineBetweenFormattedRegions.

@Test
public void autowrapNotInPreviousLineBetweenFormattedRegions() {
    final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(5));
        };
        it.preferences(_function_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("kwlist kw1");
        _builder.newLine();
        _builder.append("kw2 kw3 kw4  kw5");
        _builder.newLine();
        it.setToBeFormatted(_builder);
        final GenericFormatter<KWList> _function_2 = new GenericFormatter<KWList>() {

            @Override
            protected void format(final KWList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
                final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it_1) -> {
                    it_1.autowrap();
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("kwlist"), _function);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
                    it_1.oneSpace();
                };
                document.append(regions.regionFor(model).keyword("kw4"), _function_1);
            }
        };
        it.setFormatter(_function_2);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("kwlist kw1");
        _builder_1.newLine();
        _builder_1.append("kw2 kw3 kw4 kw5");
        _builder_1.newLine();
        it.setExpectation(_builder_1);
    };
    this._genericFormatterTester.assertFormatted(_function);
}
Also used : GenericFormatterTestRequest(org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest) KWList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 52 with MapBasedPreferenceValues

use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-xtend by eclipse.

the class XtendFormatterPreview method doUpdate.

@SuppressWarnings("deprecation")
public void doUpdate(final Map<String, String> map) {
    checkEditorHandleIsSet();
    final MapBasedPreferenceValues values = new MapBasedPreferenceValues(map);
    String maxLineWidthValue = values.getPreference(maxLineWidth);
    if (maxLineWidthValue != null) {
        moveMarginToColumn(maxLineWidthValue);
    }
    StyledText widget = null;
    try {
        widget = (StyledText) editorHandle.getViewer().getControl();
        // disable redraw, otherwise this would causes funny animation effects during formating.
        widget.setRedraw(false);
        this.modelAccess.updateModel("", previewContent, "");
        XtextDocument document = editorHandle.getDocument();
        ContentFormatter formatter = formatterProvider.get();
        formatter.setPreferencesProvider(values);
        formatter.format(document, new Region(0, document.getLength()));
        // reset selection, otherwise the whole new content will be selected
        editorHandle.getViewer().setSelection(null);
    } finally {
        if (widget != null)
            widget.setRedraw(true);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) Region(org.eclipse.jface.text.Region) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) ContentFormatter(org.eclipse.xtext.ui.editor.formatting2.ContentFormatter)

Example 53 with MapBasedPreferenceValues

use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-xtend by eclipse.

the class AbstractXtendFormatterTest method assertFormatted.

public void assertFormatted(final Procedure1<? super MapBasedPreferenceValues> cfg, final CharSequence expectation, final CharSequence toBeFormatted, final String prefix, final String postfix, final boolean allowErrors) {
    final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
        final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
            it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(80));
            it_1.<Boolean>put(XtendFormatterPreferenceKeys.keepOneLineMethods, Boolean.valueOf(false));
            if (cfg != null) {
                cfg.apply(it_1);
            }
        };
        it.preferences(_function_1);
        it.setExpectation(((prefix + expectation) + postfix));
        it.setToBeFormatted(((prefix + toBeFormatted) + postfix));
        Collection<ITextRegion> _regions = it.getRequest().getRegions();
        int _length = prefix.length();
        int _length_1 = toBeFormatted.length();
        TextRegion _textRegion = new TextRegion(_length, _length_1);
        _regions.add(_textRegion);
        it.setAllowSyntaxErrors(allowErrors);
    };
    this.tester.assertFormatted(_function);
}
Also used : TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) FormatterTestRequest(org.eclipse.xtext.testing.formatter.FormatterTestRequest) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) Collection(java.util.Collection)

Example 54 with MapBasedPreferenceValues

use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-xtend by eclipse.

the class AnonymousClassFormatterTest method formatNested.

@Test
public void formatNested() {
    final Procedure1<MapBasedPreferenceValues> _function = (MapBasedPreferenceValues it) -> {
        it.<Boolean>put(XbaseFormatterPreferenceKeys.bracesInNewLine, Boolean.valueOf(false));
    };
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.util.Iterator");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val foo = new Iterable<String>() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("override iterator() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("new Iterator<String>() {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("override hasNext() {");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("true");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("override next() {");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("null");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("override remove() {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.assertFormatted(_function, _builder);
}
Also used : MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractXtendFormatterTest(org.eclipse.xtend.core.tests.formatting.AbstractXtendFormatterTest) Test(org.junit.Test)

Example 55 with MapBasedPreferenceValues

use of org.eclipse.xtext.preferences.MapBasedPreferenceValues in project xtext-xtend by eclipse.

the class XtendAnnotationTypeFormatterTest method formatPublicAbstract.

@Test
public void formatPublicAbstract() {
    final Procedure1<MapBasedPreferenceValues> _function = (MapBasedPreferenceValues it) -> {
    };
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public abstract annotation Bar {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.assertFormatted(_function, _builder);
}
Also used : MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractXtendFormatterTest(org.eclipse.xtend.core.tests.formatting.AbstractXtendFormatterTest) Test(org.junit.Test)

Aggregations

MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)106 Test (org.junit.Test)100 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)99 AbstractXtendFormatterTest (org.eclipse.xtend.core.tests.formatting.AbstractXtendFormatterTest)91 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)14 IFormattableDocument (org.eclipse.xtext.formatting2.IFormattableDocument)8 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)8 GenericFormatter (org.eclipse.xtext.formatting2.internal.GenericFormatter)8 GenericFormatterTestRequest (org.eclipse.xtext.formatting2.internal.GenericFormatterTestRequest)8 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)8 KWList (org.eclipse.xtext.formatting2.internal.formattertestlanguage.KWList)7 FormatterTestRequest (org.eclipse.xtext.testing.formatter.FormatterTestRequest)6 Ignore (org.junit.Ignore)5 IAutowrapFormatter (org.eclipse.xtext.formatting2.IAutowrapFormatter)2 IFormattableSubDocument (org.eclipse.xtext.formatting2.IFormattableSubDocument)2 IHiddenRegionFormatting (org.eclipse.xtext.formatting2.IHiddenRegionFormatting)2 ISubFormatter (org.eclipse.xtext.formatting2.ISubFormatter)2 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)2 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)2 ITextRegion (org.eclipse.xtext.util.ITextRegion)2