Example usage for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants FORMATTER_TAB_CHAR

List of usage examples for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants FORMATTER_TAB_CHAR

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants FORMATTER_TAB_CHAR.

Prototype

String FORMATTER_TAB_CHAR

To view the source code for org.eclipse.jdt.core.formatter DefaultCodeFormatterConstants FORMATTER_TAB_CHAR.

Click Source Link

Document

 FORMATTER / Option to specify the tabulation size - option id:         "org.eclipse.jdt.core.formatter.tabulation.char" - possible values:   { TAB, SPACE, MIXED } - default:           TAB 
More values may be added in the future.

Usage

From source file:edu.illinois.compositerefactorings.steps.tests.StepTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    @SuppressWarnings("unchecked")
    Hashtable<String, String> options = TestOptions.getDefaultOptions();
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");

    JavaCore.setOptions(options);//  w w  w . j  av a 2s  .c om

    IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();
    store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);
    store.setValue(PreferenceConstants.CODEGEN_KEYWORD_THIS, false);

    StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "//TODO\n${body_statement}", null);

    Preferences corePrefs = JavaPlugin.getJavaCorePluginPreferences();
    corePrefs.setValue(JavaCore.CODEASSIST_FIELD_PREFIXES, "");
    corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_PREFIXES, "");
    corePrefs.setValue(JavaCore.CODEASSIST_FIELD_SUFFIXES, "");
    corePrefs.setValue(JavaCore.CODEASSIST_STATIC_FIELD_SUFFIXES, "");

    fJProject1 = ProjectTestSetup.getProject();

    fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
}

From source file:krasa.formatter.eclipse.JsniFormattingUtilTest.java

License:Open Source License

@Test
public void testFormat() throws Exception {
    // Use GWT indentation settings
    Map javaPrefs = TestUtils.getJavaProperties();
    javaPrefs.put(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "2");
    javaPrefs.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    javaPrefs.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "2");
    javaPrefs.put(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AT_BEGINNING_OF_METHOD_BODY, "0");

    Map javaScriptPrefs = TestUtils.getJSProperties();
    javaScriptPrefs.put(//from  w w w.  jav a 2  s  . co m
            org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "2");
    javaScriptPrefs.put(org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR,
            JavaScriptCore.SPACE);
    javaScriptPrefs.put(org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE,
            "2");
    javaScriptPrefs.put(
            org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AT_BEGINNING_OF_METHOD_BODY,
            "0");

    // Get the IDocument for the test class

    IDocument document = new Document(createString(getTestClasses()));

    // Apply the formatting and test the result
    TextEdit formatEdit = JsniFormattingUtil.format(document, javaPrefs, javaScriptPrefs,
            new Range(0, document.get().length(), true));
    formatEdit.apply(document);
    Assert.assertEquals(getFormattedDocument(), document.get());
    System.err.println("---------------------------");
    System.err.println(getFormattedDocument());
    System.err.println("---------------------------");
    System.err.println(document.get());
}

From source file:org.antlr.eclipse.ui.editor.AntlrConfiguration.java

License:Open Source License

/** {@inheritDoc} */
@Override/* w  ww . jav  a2 s . c o  m*/
public String[] getIndentPrefixes(final ISourceViewer sourceViewer, final String contentType) {
    ArrayList<String> prefixes = new ArrayList<String>();
    int tabWidth = 0;
    boolean useSpaces;

    IJavaProject project = getProject();
    String tabSize;
    if (project != null) {
        tabSize = project.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, true);
        useSpaces = JavaCore.SPACE
                .equals(project.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true));
    } else {
        tabSize = JavaCore.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE);
        useSpaces = JavaCore.SPACE.equals(JavaCore.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR));
    }
    try {
        tabWidth = Integer.parseInt(tabSize);
    } catch (NumberFormatException e) {
        tabWidth = 4;
    }

    // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
    for (int i = 0; i <= tabWidth; i++) {
        StringBuffer prefix = new StringBuffer();

        if (useSpaces) {
            for (int j = 0; j + i < tabWidth; j++)
                prefix.append(' ');

            if (i != 0)
                prefix.append('\t');
        } else {
            for (int j = 0; j < i; j++)
                prefix.append(' ');

            if (i != tabWidth)
                prefix.append('\t');
        }

        prefixes.add(prefix.toString());
    }

    prefixes.add(""); //$NON-NLS-1$

    return prefixes.toArray(new String[prefixes.size()]);
}

From source file:org.codehaus.groovy.eclipse.refactoring.test.AbstractRefactoringTestSetup.java

License:Open Source License

protected void setUp() throws Exception {
    super.setUp();
    fWasOptions = JavaCore.getOptions();
    fWasAutobuild = CoreUtility.setAutoBuilding(false);
    //      if (JavaPlugin.getActivePage() != null)
    //         JavaPlugin.getActivePage().close();

    Hashtable options = TestOptions.getDefaultOptions();
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
    options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "0");
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
    options.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, String.valueOf(9999));

    JavaCore.setOptions(options);//  ww  w.  j a  v  a2  s  .c  o  m
    TestOptions.initializeCodeGenerationOptions();
    JavaPlugin.getDefault().getCodeTemplateStore().load();

    StringBuffer comment = new StringBuffer();
    comment.append("/**\n");
    comment.append(" * ${tags}\n");
    comment.append(" */");
    StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORCOMMENT_ID, comment.toString(), null);
}

From source file:org.codehaus.groovy.eclipse.test.ui.GroovyAutoIndenterTests.java

License:Apache License

@Override
protected void setUp() throws Exception {
    super.setUp();
    //Our tests are sensitive to tab/space settings so ensure they are
    //set to predictable default values.
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB);
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");

    //Also ensure that project specific settings on the test project are turned off
    // (or they will override our test settings on the plugin instance scope level)
    ProjectScope projectPrefScope = new ProjectScope(testProject.getProject());
    projectPrefScope.getNode(JavaCore.PLUGIN_ID).clear();
}

From source file:org.codehaus.groovy.eclipse.test.ui.GroovyAutoIndenterTests.java

License:Apache License

/**
 * Check whether we are picking up on changed tab/space preferences set
 * for the Java Editor./*from   w w  w .  j a  v  a  2 s  .co  m*/
 */
public void testSpaces() throws Exception {
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    makeEditor("class Foo {\n" + "\tdef foo() {<***>\n" + "}\n\n");
    send("\n");
    assertEditorContents("class Foo {\n" + "\tdef foo() {\n" + "        <***>\n" + "    }\n" + "}\n\n");
}

From source file:org.codehaus.groovy.eclipse.test.ui.GroovyAutoIndenterTests.java

License:Apache License

/**
 * Check whether we are also picking up on changed tab/space preferences \\
 * even if they are change happens after the editor was already opened.
 *//*from  w w w .  j  av  a2 s  .c  o m*/
public void testSpacesOptionSetAfterOpen() throws Exception {
    makeEditor("class Foo {\n" + "\tdef foo() {<***>\n" + "}\n\n");
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    send("\n");
    assertEditorContents("class Foo {\n" + "\tdef foo() {\n" + "        <***>\n" + "    }\n" + "}\n\n");
}

From source file:org.codehaus.groovy.eclipse.test.ui.GroovyAutoIndenterTests.java

License:Apache License

/**
 * Check whether autoindentor works correct for mixed tab/spaces mode.
 *//*from w  w w .  j a  va2 s.  co m*/
public void testMixedTabsAndSpaces() throws Exception {
    makeEditor("class Foo {\n" + "    def foo() {\n" + "        def bar {<***>\n" + "        }\n" + "    }\n"
            + "}\n\n");
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, DefaultCodeFormatterConstants.MIXED);
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "8");
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "4");
    send("\n");
    assertEditorContents("class Foo {\n" + "    def foo() {\n" + "        def bar {\n" + "\t    <***>\n"
            + "        }\n" + "    }\n" + "}\n\n");
}

From source file:org.codehaus.groovy.eclipse.test.ui.GroovyAutoIndenterTests.java

License:Apache License

/**
 * Similar to above, but also check whether it counts the tabs on previous lines correctly.
 *///from w  ww  .ja  v  a 2  s .c  o  m
public void testMixedTabsAndSpaces2() throws Exception {
    makeEditor("class Foo {\n" + "    def foo() {\n" + "\tdef bar {<***>\n" + "\t}\n" + "    }\n" + "}\n\n");
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, DefaultCodeFormatterConstants.MIXED);
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "8");
    setJavaPreference(DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE, "4");
    send("\n");
    assertEditorContents("class Foo {\n" + "    def foo() {\n" + "\tdef bar {\n" + "\t    <***>\n" + "\t}\n"
            + "    }\n" + "}\n\n");
}

From source file:org.codehaus.groovy.eclipse.test.wizards.AbstractNewGroovyWizardTest.java

License:Apache License

@Override
protected void setUp() throws Exception {
    Hashtable<String, String> options = JavaCore.getDefaultOptions();
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
    options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
    JavaCore.setOptions(options);// www .j  a v a  2 s .  c om

    IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();
    store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);
    store.setValue(PreferenceConstants.CODEGEN_USE_OVERRIDE_ANNOTATION, true);

    fProject = new TestProject("testWizards");
    fJProject = fProject.getJavaProject();
    fSourceFolder = fProject.getSourceFolder();

    GroovyRuntime.addGroovyRuntime(fJProject.getProject());
}