use of org.eclipse.lsp4j.DocumentFormattingParams 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.DocumentFormattingParams 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.DocumentFormattingParams 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.DocumentFormattingParams in project xtext-core by eclipse.
the class FormattingTest method doTestAPIMaintenanceLayer.
private void doTestAPIMaintenanceLayer(final FormattingService fs) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo{int bar} type Bar{Foo foo}");
final String model = _builder.toString();
final XtextResourceSet rs = this.rsp.get();
Resource _createResource = rs.createResource(URI.createURI("dummy.testlang"));
final XtextResource r = ((XtextResource) _createResource);
StringInputStream _stringInputStream = new StringInputStream(model);
r.load(_stringInputStream, null);
try {
Document _document = new Document(1, model);
DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
fs.format(_document, r, _documentFormattingParams, CancelIndicator.NullImpl);
Assert.fail("IllegalStateException expected");
} catch (final Throwable _t) {
if (_t instanceof IllegalStateException) {
final IllegalStateException e = (IllegalStateException) _t;
String _message = e.getMessage();
boolean _notEquals = (!Objects.equal(_message, "api maintenance layer broken"));
if (_notEquals) {
throw e;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.DocumentFormattingParams 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);
}
Aggregations