mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Autogenerate indent options' accessors
This commit is contained in:
@@ -43,38 +43,6 @@ public abstract class CodeStyleBean implements Serializable {
|
||||
myRootSettings.setRightMargin(getLanguage(), rightMargin);
|
||||
}
|
||||
|
||||
public int getIndentSize() {
|
||||
return getIndentOptions(false).INDENT_SIZE;
|
||||
}
|
||||
|
||||
public void setIndentSize(int indentSize) {
|
||||
getIndentOptions(true).INDENT_SIZE = indentSize;
|
||||
}
|
||||
|
||||
public int getTabSize() {
|
||||
return getIndentOptions(false).TAB_SIZE;
|
||||
}
|
||||
|
||||
public void setTabSize(int tabSize) {
|
||||
getIndentOptions(true).TAB_SIZE = tabSize;
|
||||
}
|
||||
|
||||
public boolean isUseSmartTabs() {
|
||||
return getIndentOptions(false).SMART_TABS;
|
||||
}
|
||||
|
||||
public void setUseSmartTabs(boolean useSmartTabs) {
|
||||
getIndentOptions(true).SMART_TABS = useSmartTabs;
|
||||
}
|
||||
|
||||
public boolean isUseTabCharacter() {
|
||||
return getIndentOptions(false).USE_TAB_CHARACTER;
|
||||
}
|
||||
|
||||
public void setUseTabCharacter(boolean useTabCharacter) {
|
||||
getIndentOptions(true).USE_TAB_CHARACTER = useTabCharacter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CommonCodeStyleSettings.WrapOnTyping getWrapOnTyping() {
|
||||
for (CommonCodeStyleSettings.WrapOnTyping c : CommonCodeStyleSettings.WrapOnTyping.values()) {
|
||||
|
||||
@@ -48,6 +48,9 @@ public class CodeStyleBeanAccessorGenerator {
|
||||
addMapping("LBRACE", "LeftBrace");
|
||||
addMapping("INSTANCEOF", "InstanceOf");
|
||||
addMapping("DOWHILE", "DoWhile");
|
||||
addMapping("INDENT_SIZE", "Indent");
|
||||
addMapping("CONTINUATION_INDENT_SIZE", "ContinuationIndent");
|
||||
addMapping("PARM", "Param");
|
||||
}
|
||||
|
||||
public CodeStyleBeanAccessorGenerator(@NotNull Field field) {
|
||||
@@ -156,10 +159,13 @@ public class CodeStyleBeanAccessorGenerator {
|
||||
myField.getAnnotation(Deprecated.class) == null;
|
||||
}
|
||||
|
||||
String getContainerClassAccessor() {
|
||||
String getContainerClassAccessor(boolean isWriteAccess) {
|
||||
if (myContainerClass == CommonCodeStyleSettings.class) {
|
||||
return "getCommonSettings()";
|
||||
}
|
||||
else if (myContainerClass == CommonCodeStyleSettings.IndentOptions.class) {
|
||||
return "getIndentOptions(" + isWriteAccess + ")";
|
||||
}
|
||||
myImports.add(myContainerClass.getName());
|
||||
return "getCustomSettings(" + myContainerClass.getSimpleName() + ".class)";
|
||||
}
|
||||
@@ -177,21 +183,21 @@ public class CodeStyleBeanAccessorGenerator {
|
||||
if (valueType == ValueType.WRAP) {
|
||||
output
|
||||
.append("return intToWrapType(")
|
||||
.append(getContainerClassAccessor())
|
||||
.append(getContainerClassAccessor(false))
|
||||
.append(".").append(myFieldName)
|
||||
.append(");\n");
|
||||
}
|
||||
else if (valueType == ValueType.BRACE_STYLE || valueType == ValueType.FORCE_BRACES) {
|
||||
output
|
||||
.append("return ").append(typeString).append(".fromInt(")
|
||||
.append(getContainerClassAccessor())
|
||||
.append(getContainerClassAccessor(false))
|
||||
.append(".").append(myFieldName)
|
||||
.append(");\n");
|
||||
}
|
||||
else {
|
||||
output
|
||||
.append("return ")
|
||||
.append((getContainerClassAccessor()))
|
||||
.append((getContainerClassAccessor(false)))
|
||||
.append(".").append(myFieldName).append(";\n");
|
||||
}
|
||||
output
|
||||
@@ -214,7 +220,7 @@ public class CodeStyleBeanAccessorGenerator {
|
||||
.append(typeString).append(" value")
|
||||
.append("){");
|
||||
output
|
||||
.append(getContainerClassAccessor())
|
||||
.append(getContainerClassAccessor(true))
|
||||
.append(".").append(myFieldName).append("= ");
|
||||
final ValueType valueType = getValueType();
|
||||
if (valueType == ValueType.WRAP) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// 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.jetbrains.idea.devkit.codeStyle.bean;
|
||||
|
||||
import com.intellij.application.options.IndentOptionsEditor;
|
||||
import com.intellij.application.options.SmartIndentOptionsEditor;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -35,9 +37,28 @@ public class CodeStyleBeanGenerator {
|
||||
for (CustomCodeStyleSettings customSettings : getCustomSettings()) {
|
||||
generateMethodsFor(customSettings.getClass(), sb, null);
|
||||
}
|
||||
generateMethodsFor(CommonCodeStyleSettings.IndentOptions.class, sb, getSupportedIndentOptions());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private Set<String> getSupportedIndentOptions() {
|
||||
LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(myLanguage);
|
||||
if (provider == null) return Collections.emptySet();
|
||||
Set<String> indentOptions = ContainerUtil.newHashSet();
|
||||
IndentOptionsEditor editor = provider.getIndentOptionsEditor();
|
||||
if (editor != null) {
|
||||
indentOptions.add("TAB_SIZE");
|
||||
indentOptions.add("USE_TAB_CHARACTER");
|
||||
indentOptions.add("INDENT_SIZE");
|
||||
if (editor instanceof SmartIndentOptionsEditor) {
|
||||
indentOptions.add("CONTINUATION_INDENT_SIZE");
|
||||
indentOptions.add("SMART_TABS");
|
||||
indentOptions.add("KEEP_INDENTS_ON_EMPTY_LINES");
|
||||
}
|
||||
}
|
||||
return indentOptions;
|
||||
}
|
||||
|
||||
private Set<String> getSupportedFields() {
|
||||
LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(myLanguage);
|
||||
return provider == null ? Collections.emptySet() : provider.getSupportedFields();
|
||||
|
||||
Reference in New Issue
Block a user