org.eclipse.lsp4j.FormattingOptions的实例源码

项目:eclipse.jdt.ls    文件FormatterHandlerTest.java   
@Test
public void testJavaFormatEnable() throws Exception {
    String text =
    //@formatter:off
            "package org.sample   ;\n\n" +
            "      public class Baz {  String name;}\n";
        //@formatter:on"
    Icompilationunit unit = getWorkingcopy("src/org/sample/Baz.java",text);
    preferenceManager.getPreferences().setJavaFormatEnabled(false);
    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
    FormattingOptions options = new FormattingOptions(4,true);// ident == 4 spaces
    DocumentFormattingParams params = new DocumentFormattingParams(textDocument,options);
    List<? extends TextEdit> edits = server.formatting(params).get();
    assertNotNull(edits);
    String newText = TextEditUtil.apply(unit,edits);
    assertEquals(text,newText);
}
项目:eclipse.jdt.ls    文件FormatterHandlerTest.java   
@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"
    //@formatter:on
    );

    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);

    Range range = new Range(new Position(2,0),new Position(3,5));// range around foo()
    DocumentRangeFormattingParams params = new DocumentRangeFormattingParams(range);
    params.setTextDocument(textDocument);
    params.setoptions(new FormattingOptions(3,true));// ident == 3 spaces

    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);
}
项目:eclipse.jdt.ls    文件FormatterHandler.java   
private static Map<String,String> getoptions(FormattingOptions options,Icompilationunit cu) {
    Map<String,String> eclipSEOptions = cu.getJavaProject().getoptions(true);
    Integer tabSize = options.getTabSize();
    if (tabSize != null) {
        int tSize = tabSize.intValue();
        if (tSize > 0) {
            eclipSEOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE,Integer.toString(tSize));
        }
    }
    boolean insertSpaces = options.isInsertSpaces();
    if (insertSpaces) {
        eclipSEOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR,insertSpaces ? JavaCore.SPACE : JavaCore.TAB);
    }
    return eclipSEOptions;
}
项目:eclipse.jdt.ls    文件FormatterHandlerTest.java   
@Test
public void testDocumentFormatting() throws Exception {
    Icompilationunit unit = getWorkingcopy("src/org/sample/Baz.java",//@formatter:off
        "package org.sample   ;\n\n" +
        "      public class Baz {  String name;}\n"
    //@formatter:on
    );

    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
    FormattingOptions options = new FormattingOptions(4,options);
    List<? extends TextEdit> edits = server.formatting(params).get();
    assertNotNull(edits);

    //@formatter:off
    String expectedText =
        "package org.sample;\n"
        + "\n"
        + "public class Baz {\n"
        + "    String name;\n"
        + "}\n";
    //@formatter:on

    String newText = TextEditUtil.apply(unit,newText);
}
项目:eclipse.jdt.ls    文件FormatterHandlerTest.java   
@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"
    //@formatter:on
    );

    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
    FormattingOptions options = new FormattingOptions(2,false);// ident == tab
    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,newText);
}
项目:eclipse.jdt.ls    文件FormatterHandlerTest.java   
@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"
    //@formatter:off
    );

    String uri = JDTUtils.toURI(unit);
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
    FormattingOptions options = new FormattingOptions(4,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,newText);

}
项目:SOMns-vscode    文件DocumentFormattingParams.java   
public DocumentFormattingParams(@NonNull final TextDocumentIdentifier textDocument,@NonNull final FormattingOptions options) {
  this.textDocument = textDocument;
  this.options = options;
}
项目:SOMns-vscode    文件DocumentFormattingParams.java   
/**
 * The format options
 */
@Pure
@NonNull
public FormattingOptions getoptions() {
  return this.options;
}
项目:SOMns-vscode    文件DocumentFormattingParams.java   
/**
 * The format options
 */
public void setoptions(@NonNull final FormattingOptions options) {
  this.options = options;
}
项目:lsp4j    文件DocumentFormattingParams.java   
public DocumentFormattingParams(@NonNull final TextDocumentIdentifier textDocument,@NonNull final FormattingOptions options) {
  this.textDocument = textDocument;
  this.options = options;
}
项目:lsp4j    文件DocumentFormattingParams.java   
/**
 * The format options
 */
@Pure
@NonNull
public FormattingOptions getoptions() {
  return this.options;
}
项目:lsp4j    文件DocumentFormattingParams.java   
/**
 * The format options
 */
public void setoptions(@NonNull final FormattingOptions options) {
  this.options = options;
}
项目:che    文件LanguageServerFormatter.java   
private FormattingOptions getFormattingOptions() {
  FormattingOptions options = dtoFactory.createDto(FormattingOptions.class);
  options.setInsertSpaces(Boolean.parseBoolean(getEditorProperty(EditorProperties.EXPAND_TAB)));
  options.setTabSize(Integer.parseInt(getEditorProperty(EditorProperties.TAB_SIZE)));
  return options;
}

相关文章

买水果
比较全面的redis工具类
gson 反序列化到多态子类
java 版本的 mb_strwidth
JAVA 反转字符串的最快方法,大概比StringBuffer.reverse()性...
com.google.gson.internal.bind.ArrayTypeAdapter的实例源码...