mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Export visual guides to Json (IDEA-206789)
This commit is contained in:
@@ -257,6 +257,10 @@
|
||||
"use_single_class_imports": true,
|
||||
"variable_annotation_wrap": "off",
|
||||
"visibility": "public",
|
||||
"visual_guides": [
|
||||
11,
|
||||
22
|
||||
],
|
||||
"while_brace_force": "never",
|
||||
"while_on_new_line": false,
|
||||
"wrap_comments": false,
|
||||
|
||||
@@ -240,6 +240,10 @@
|
||||
"use_single_class_imports": true,
|
||||
"variable_annotation_wrap": "off",
|
||||
"visibility": "public",
|
||||
"visual_guides": [
|
||||
11,
|
||||
22
|
||||
],
|
||||
"while_brace_force": "never",
|
||||
"while_on_new_line": false,
|
||||
"wrap_comments": false,
|
||||
|
||||
@@ -80,6 +80,7 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
|
||||
CodeStyleScheme testScheme = createTestScheme();
|
||||
final CodeStyleSettings settings = testScheme.getCodeStyleSettings();
|
||||
final CommonCodeStyleSettings commonJavaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
settings.setSoftMargins(JavaLanguage.INSTANCE, Arrays.asList(11,22));
|
||||
commonJavaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
|
||||
commonJavaSettings.CALL_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
|
||||
commonJavaSettings.WRAP_ON_TYPING = CommonCodeStyleSettings.WrapOnTyping.WRAP.intValue;
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class GeneralCodeStylePropertyMapper extends AbstractCodeStylePropertyMapper {
|
||||
@@ -110,4 +111,9 @@ public class GeneralCodeStylePropertyMapper extends AbstractCodeStylePropertyMap
|
||||
String key = "codestyle.property.description." + externalName;
|
||||
return OptionsBundle.getBundle().containsKey(key) ? OptionsBundle.message("codestyle.property.description." + externalName) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionalAccessors(@NotNull Map<String, CodeStylePropertyAccessor> accessorMap) {
|
||||
accessorMap.put(VisualGuidesAccessor.VISUAL_GUIDES_PROPERTY_NAME, new VisualGuidesAccessor(getRootSettings(), null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public final class LanguageCodeStylePropertyMapper extends AbstractCodeStyleProp
|
||||
|
||||
@Override
|
||||
protected void addAdditionalAccessors(@NotNull Map<String, CodeStylePropertyAccessor> accessorMap) {
|
||||
accessorMap.put(VisualGuidesAccessor.VISUAL_GUIDES_PROPERTY_NAME, new VisualGuidesAccessor(getRootSettings(), myLanguage));
|
||||
if (mySettingsProvider != null) {
|
||||
for (CustomCodeStyleSettings customSettings : myCustomSettings) {
|
||||
for (CodeStylePropertyAccessor accessor : mySettingsProvider.getAdditionalAccessors(customSettings)) {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.application.options.codeStyle.properties;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class VisualGuidesAccessor extends CodeStylePropertyAccessor<List<Integer>> {
|
||||
private final CodeStyleSettings mySettings;
|
||||
@Nullable private final Language myLanguage;
|
||||
|
||||
public static final String VISUAL_GUIDES_PROPERTY_NAME = "visual_guides";
|
||||
|
||||
VisualGuidesAccessor(@NotNull CodeStyleSettings settings, @Nullable Language language)
|
||||
{
|
||||
mySettings = settings;
|
||||
myLanguage = language;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(@NotNull List<Integer> extVal) {
|
||||
if (myLanguage != null) {
|
||||
mySettings.setSoftMargins(myLanguage, extVal);
|
||||
}
|
||||
else {
|
||||
mySettings.setDefaultSoftMargins(extVal);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<Integer> get() {
|
||||
List<Integer> values =
|
||||
myLanguage != null ?
|
||||
mySettings.getCommonSettings(myLanguage).getSoftMargins() :
|
||||
mySettings.getDefaultSoftMargins();
|
||||
return !values.isEmpty() ? values : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Integer> parseString(@NotNull String string) {
|
||||
return ValueListPropertyAccessor.getValueList(string).stream()
|
||||
.map(s -> safeToInt(s))
|
||||
.filter(integer -> integer >= 0)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static int safeToInt(@NotNull String s) {
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertyName() {
|
||||
return VISUAL_GUIDES_PROPERTY_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGenericProperty() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,9 @@ public class CodeStyleSchemeJsonExporter extends SchemeExporter<CodeStyleScheme>
|
||||
if (element instanceof String) {
|
||||
array.add((String)element);
|
||||
}
|
||||
else if (element instanceof Integer) {
|
||||
array.add((Integer)element);
|
||||
}
|
||||
}
|
||||
o.add(name, array);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
"formatter_tags_accept_regexp": false,
|
||||
"formatter_tags_enabled": false,
|
||||
"max_line_length": 120,
|
||||
"visual_guides": [
|
||||
42,
|
||||
62
|
||||
],
|
||||
"wrap_on_typing": false
|
||||
},
|
||||
"html": {
|
||||
|
||||
@@ -14,6 +14,7 @@ public class JsonInterchangeTest extends CodeStyleTestCase {
|
||||
|
||||
public void testExportToJson() throws IOException {
|
||||
CodeStyleScheme testScheme = createTestScheme();
|
||||
testScheme.getCodeStyleSettings().setDefaultSoftMargins(Arrays.asList(42,62));
|
||||
CodeStyleSchemeJsonExporter exporter = new CodeStyleSchemeJsonExporter();
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
exporter.exportScheme(testScheme, outputStream, Arrays.asList(GeneralCodeStylePropertyMapper.COMMON_DOMAIN_ID, "html"));
|
||||
|
||||
Reference in New Issue
Block a user