use of org.eclipse.lsp4j.FormattingOptions in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testDocumentFormattingWithTabs.
@Test
public void testDocumentFormattingWithTabs() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
"package org.sample;\n\n" + "public class Baz {\n" + " void foo(){\n" + "}\n" + "}\n");
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
// ident == tab
FormattingOptions options = new FormattingOptions(2, false);
DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
List<? extends TextEdit> edits = server.formatting(params).get();
assertNotNull(edits);
// @formatter:off
String expectedText = "package org.sample;\n" + "\n" + "public class Baz {\n" + "\tvoid foo() {\n" + "\t}\n" + "}\n";
// @formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
use of org.eclipse.lsp4j.FormattingOptions in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testDocumentFormattingWithCustomOption.
@Test
public void testDocumentFormattingWithCustomOption() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
"@Deprecated package org.sample;\n\n" + "public class Baz {\n" + " /**Java doc @param a some parameter*/\n" + "\tvoid foo(int a){;;\n" + "}\n" + "}\n");
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
FormattingOptions options = new FormattingOptions(2, true);
options.putNumber("org.eclipse.jdt.core.formatter.blank_lines_before_package", Integer.valueOf(2));
options.putString("org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package", "do not insert");
options.putBoolean("org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line", Boolean.TRUE);
DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
List<? extends TextEdit> edits = server.formatting(params).get();
assertNotNull(edits);
String expectedText = "\n" + "\n" + "@Deprecated package org.sample;\n" + "\n" + "public class Baz {\n" + " /**Java doc @param a some parameter*/\n" + " void foo(int a) {\n" + " ;\n" + " ;\n" + " }\n" + "}\n";
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
use of org.eclipse.lsp4j.FormattingOptions in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testFormatting_onOffTags.
@Test
public void testFormatting_onOffTags() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
"package org.sample;\n\n" + " public class Baz {\n" + "// @formatter:off\n" + "\tvoid foo(){\n" + " }\n" + "// @formatter:on\n" + "}\n");
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
// ident == tab
FormattingOptions options = new FormattingOptions(4, false);
DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
List<? extends TextEdit> edits = server.formatting(params).get();
assertNotNull(edits);
// @formatter:off
String expectedText = "package org.sample;\n\n" + "public class Baz {\n" + "// @formatter:off\n" + "\tvoid foo(){\n" + " }\n" + "// @formatter:on\n" + "}\n";
// @formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
use of org.eclipse.lsp4j.FormattingOptions in project xtext-core by eclipse.
the class FormattingTest method testFormattingService_02.
@Test
public void testFormattingService_02() {
final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
FormattingOptions _formattingOptions = new FormattingOptions(4, true);
it.setOptions(_formattingOptions);
};
final Procedure1<FormattingConfiguration> _function_1 = (FormattingConfiguration it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
it.setModel(_builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Foo{");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("int bar");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("type Bar{");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("Foo foo");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
it.setExpectedText(_builder_1.toString());
};
this.testFormatting(_function, _function_1);
}
use of org.eclipse.lsp4j.FormattingOptions in project eclipse.jdt.ls by eclipse.
the class FormatterHandlerTest method testRangeFormatting.
@Test
public void testRangeFormatting() throws Exception {
ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", // @formatter:off
"package org.sample;\n" + " public class Baz {\n" + "\tvoid foo(){\n" + " }\n" + " }\n");
String uri = JDTUtils.toURI(unit);
TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
// range around foo()
Range range = new Range(new Position(2, 0), new Position(3, 5));
DocumentRangeFormattingParams params = new DocumentRangeFormattingParams(range);
params.setTextDocument(textDocument);
// ident == 3 spaces
params.setOptions(new FormattingOptions(3, true));
List<? extends TextEdit> edits = server.rangeFormatting(params).get();
// @formatter:off
String expectedText = "package org.sample;\n" + " public class Baz {\n" + " void foo() {\n" + " }\n" + " }\n";
// @formatter:on
String newText = TextEditUtil.apply(unit, edits);
assertEquals(expectedText, newText);
}
Aggregations