mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EditorConfig support for list properties
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BooleanAccessor extends CodeStylePropertyAccessor<Boolean,String> implements CodeStyleChoiceList {
|
||||
public class BooleanAccessor extends ScalarPropertyAccessor<Boolean> implements CodeStyleChoiceList {
|
||||
|
||||
private final static List<String> BOOLEAN_VALS = Arrays.asList("false", "true");
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class BraceStyleAccessor extends CodeStylePropertyAccessor<Integer,String> implements CodeStyleChoiceList {
|
||||
class BraceStyleAccessor extends ScalarPropertyAccessor<Integer> implements CodeStyleChoiceList {
|
||||
private final static BidirectionalMap<Integer, String> BRACE_STYLE_MAP = new BidirectionalMap<>();
|
||||
|
||||
public static final String VALUE_END_OF_LINE = "end_of_line";
|
||||
|
||||
+11
@@ -47,6 +47,17 @@ public abstract class CodeStylePropertyAccessor<T,V> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final boolean setFromString(@NotNull String valueString) {
|
||||
V extValue = parseString(valueString);
|
||||
if (extValue != null) {
|
||||
return set(extValue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract V parseString(@NotNull String string);
|
||||
|
||||
@NotNull
|
||||
public Class getObjectClass() {
|
||||
return myObject.getClass();
|
||||
|
||||
+2
-7
@@ -21,7 +21,7 @@ public class CommaSeparatedValuesAccessor extends ValueListPropertyAccessor<Stri
|
||||
if (valueBuilder.length() > 0) {
|
||||
valueBuilder.append(",");
|
||||
}
|
||||
valueBuilder.append(extVal);
|
||||
valueBuilder.append(value);
|
||||
}
|
||||
return valueBuilder.toString();
|
||||
}
|
||||
@@ -29,11 +29,6 @@ public class CommaSeparatedValuesAccessor extends ValueListPropertyAccessor<Stri
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<String> toExternal(@NotNull String value) {
|
||||
List<String> valueList = ContainerUtil.newArrayList();
|
||||
String[] parts = value.split(",");
|
||||
for (String part : parts) {
|
||||
valueList.add(part.trim());
|
||||
}
|
||||
return valueList;
|
||||
return getValueList(value);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class EnumPropertyAccessor extends CodeStylePropertyAccessor<Enum,String> implements CodeStyleChoiceList{
|
||||
public class EnumPropertyAccessor extends ScalarPropertyAccessor<Enum> implements CodeStyleChoiceList{
|
||||
|
||||
private final Class myEnumClass;
|
||||
private final BidirectionalMap<String,Enum> myEnumMap = new BidirectionalMap<>();
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class ForceBracesAccessor extends CodeStylePropertyAccessor<Integer,String> implements CodeStyleChoiceList {
|
||||
class ForceBracesAccessor extends ScalarPropertyAccessor<Integer> implements CodeStyleChoiceList {
|
||||
|
||||
private final static BidirectionalMap<Integer, String> FORCE_BRACES_MAP = new BidirectionalMap<>();
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class IntegerAccessor extends CodeStylePropertyAccessor<Integer,String> {
|
||||
public class IntegerAccessor extends ScalarPropertyAccessor<Integer> {
|
||||
IntegerAccessor(@NotNull Object object, @NotNull Field field) {
|
||||
super(object, field);
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// 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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public abstract class ScalarPropertyAccessor<T> extends CodeStylePropertyAccessor<T,String> {
|
||||
|
||||
public ScalarPropertyAccessor(@NotNull Object object, @NotNull Field field) {
|
||||
super(object, field);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected abstract T fromExternal(@NotNull String extVal);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected abstract String toExternal(@NotNull T value);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected String parseString(@NotNull String string) {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
class StringAccessor extends CodeStylePropertyAccessor<String,String> {
|
||||
class StringAccessor extends ScalarPropertyAccessor<String> {
|
||||
|
||||
StringAccessor(@NotNull Object object, @NotNull Field field) {
|
||||
super(object, field);
|
||||
|
||||
+12
@@ -1,6 +1,7 @@
|
||||
// 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.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -19,4 +20,15 @@ public abstract class ValueListPropertyAccessor<T> extends CodeStylePropertyAcce
|
||||
@NotNull
|
||||
@Override
|
||||
protected abstract List<String> toExternal(@NotNull T value);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected List<String> parseString(@NotNull String string) {
|
||||
return getValueList(string);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static List<String> getValueList(@NotNull String string) {
|
||||
return ContainerUtil.map(string.split(","), s -> s.trim());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class WrappingAccessor extends CodeStylePropertyAccessor<Integer,String> implements CodeStyleChoiceList {
|
||||
class WrappingAccessor extends ScalarPropertyAccessor<Integer> implements CodeStyleChoiceList {
|
||||
private final static BidirectionalMap<Integer, String> WRAPPING_MAP = new BidirectionalMap<>();
|
||||
|
||||
public static final String VALUE_OFF = "off";
|
||||
|
||||
+5
-9
@@ -1,16 +1,15 @@
|
||||
// Copyright 2000-2018 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 org.editorconfig.configmanagement.extended;
|
||||
|
||||
import com.intellij.application.options.codeStyle.properties.CodeStylePropertyAccessor;
|
||||
import com.intellij.application.options.codeStyle.properties.ValueListPropertyAccessor;
|
||||
import com.intellij.psi.codeStyle.modifier.CodeStyleSettingsModifier;
|
||||
import com.intellij.application.options.codeStyle.properties.AbstractCodeStylePropertyMapper;
|
||||
import com.intellij.application.options.codeStyle.properties.CodeStylePropertyAccessor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.modifier.CodeStyleStatusBarUIContributor;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import com.intellij.psi.codeStyle.modifier.CodeStyleSettingsModifier;
|
||||
import com.intellij.psi.codeStyle.modifier.CodeStyleStatusBarUIContributor;
|
||||
import com.intellij.psi.codeStyle.modifier.TransientCodeStyleSettings;
|
||||
import org.editorconfig.Utils;
|
||||
import org.editorconfig.configmanagement.EditorConfigNavigationActionsFactory;
|
||||
@@ -82,11 +81,8 @@ public class EditorConfigCodeStyleSettingsModifier implements CodeStyleSettingsM
|
||||
String intellijName = EditorConfigIntellijNameUtil.toIntellijName(mapper, option.getKey());
|
||||
if (intellijName != null) {
|
||||
CodeStylePropertyAccessor accessor = mapper.getAccessor(intellijName);
|
||||
if (!(accessor instanceof ValueListPropertyAccessor)) {
|
||||
//noinspection unchecked
|
||||
if (accessor != null && accessor.set(option.getVal())) {
|
||||
isModified = true;
|
||||
}
|
||||
if (accessor != null) {
|
||||
isModified |= accessor.setFromString(option.getVal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -67,9 +67,12 @@ public class IntellijConfigOptionDescriptorProvider implements EditorConfigOptio
|
||||
return new EditorConfigNumberDescriptor(null, null);
|
||||
}
|
||||
else if (accessor instanceof ValueListPropertyAccessor) {
|
||||
return null; // No support yet
|
||||
return new EditorConfigListDescriptor(0, true, Collections.singletonList(new EditorConfigStringDescriptor(null, null)), null, null);
|
||||
}
|
||||
return new EditorConfigStringDescriptor(null, null);
|
||||
else if (accessor instanceof ScalarPropertyAccessor) {
|
||||
return new EditorConfigStringDescriptor(null, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<EditorConfigDescriptor> choicesToDescriptorList(@NotNull CodeStyleChoiceList list) {
|
||||
|
||||
Reference in New Issue
Block a user