Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Feature Support
|----------------------------|---------|---------------------------------------------|
| `indent_style` | Yes | tested with Java, XML, Ant and text editors |
| `indent_size` | Yes | tested with Java, XML, Ant and text editors |
| `tab_width` | No | |
| `tab_width` | Yes | tested with Java, XML, Ant and text editors |
| `end_of_line` | No | applies to files created after similar file opened |
| `charset` | Yes | untested |
| `trim_trailing_whitespace` | No | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,16 @@ public void testIndentStyleTab() throws Exception {
assertThat(context.fileContents(fileName), equalTo("\t"));
}

@Test
public void testIndentStyleTabWithSize() throws Exception {
context.editorConfig(
"root = true",
"[*]",
"indent_style = tab",
"indent_size = 2"
);
context.editFile(fileName, "\t");
assertThat(context.fileContents(fileName), equalTo("\t"));
}

}
2 changes: 1 addition & 1 deletion org.eclipse.editorconfig.core/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source.. = src/main/java/,\
editorconfig-core-java/src/
editorconfig-core-java/src/main/java
output.. = bin/
bin.includes = META-INF/,\
.,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public void editorActivated(final IFile editorFile) {
if (editorFile != null) {
final EditorFileConfig fileEditorConfig = getEditorFileConfig(editorFile);
System.out.println("Editor activated: " + fileEditorConfig);
EditorConfigVisitor visitor = new EditorConfigVisitor(fileEditorConfig);
for (final ConfigProperty<?> configProperty : fileEditorConfig.getConfigProperties()) {
configProperty.accept(new EditorConfigVisitor());
configProperty.accept(visitor);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.editorconfig.core.ConfigProperty;
import org.eclipse.editorconfig.core.ConfigPropertyType;
import org.eclipse.editorconfig.core.ConfigPropertyVisitor;
import org.eclipse.editorconfig.core.EditorFileConfig;
import org.eclipse.editorconfig.core.EndOfLineOption;
import org.eclipse.editorconfig.core.IndentStyleOption;

public class EditorConfigVisitor implements ConfigPropertyVisitor {

private final EditorFileConfig config;

public EditorConfigVisitor(EditorFileConfig config) {
this.config = config;
}

private void setPreference(final String prefsNodeName, final String key, final String value) {
System.out.println(String.format("Setting preference: %s/%s=%s", prefsNodeName, key, value));
final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(prefsNodeName);
Expand All @@ -44,14 +52,20 @@ public void visitIndentStyle(final ConfigProperty<IndentStyleOption> property) {
@Override
public void visitIndentSize(final ConfigProperty<Integer> property) {
final String indentSizeString = property.getValue().toString();
setPreference("org.eclipse.ui.editors", "tabWidth", indentSizeString);
setPreference("org.eclipse.jdt.core", "org.eclipse.jdt.core.formatter.tabulation.size", indentSizeString);
setPreference("org.eclipse.wst.xml.core", "indentationSize", indentSizeString);
setPreference("org.eclipse.ant.ui", "formatter_tab_size", indentSizeString);
// this represents the number of tabs, not their width
setPreference("org.eclipse.wst.xml.core", "indentationSize",
config.getConfigProperty(ConfigPropertyType.INDENT_STYLE.getName()).getValue().equals(IndentStyleOption.SPACE)
? indentSizeString
: "1");
}

@Override
public void visitTabWidth(final ConfigProperty<Integer> property) {
final String tabWidth = property.getValue().toString();
// xml editor will follow this
setPreference("org.eclipse.ui.editors", "tabWidth", tabWidth);
setPreference("org.eclipse.jdt.core", "org.eclipse.jdt.core.formatter.tabulation.size", tabWidth);
setPreference("org.eclipse.ant.ui", "formatter_tab_size", tabWidth);
}

@Override
Expand Down