微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。