diff --git a/java/java-impl/src/com/intellij/application/options/JavaCodeStyleOptionsCustomizer.java b/java/java-impl/src/com/intellij/application/options/JavaCodeStyleOptionsCustomizer.java new file mode 100644 index 000000000000..ffed019dcc69 --- /dev/null +++ b/java/java-impl/src/com/intellij/application/options/JavaCodeStyleOptionsCustomizer.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.application.options; + +import com.intellij.psi.codeStyle.SpacingOptionsConsumer; +import com.intellij.psi.codeStyle.CodeStyleOptionsCustomizer; + +/** + * @author yole + */ +public class JavaCodeStyleOptionsCustomizer implements CodeStyleOptionsCustomizer { + public void customizeSpacingOptions(SpacingOptionsConsumer consumer) { + consumer.showAllStandardOptions(); + } +} diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleOptionsCustomizer.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleOptionsCustomizer.java new file mode 100644 index 000000000000..7a8f0e39d3e9 --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleOptionsCustomizer.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.codeStyle; + +import com.intellij.openapi.extensions.ExtensionPointName; + +/** + * @author yole + */ +public interface CodeStyleOptionsCustomizer { + ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.codeStyleOptionsCustomizer"); + + void customizeSpacingOptions(SpacingOptionsConsumer consumer); +} diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/SpacingOptionsConsumer.java b/platform/lang-api/src/com/intellij/psi/codeStyle/SpacingOptionsConsumer.java new file mode 100644 index 000000000000..40d6f7cec3af --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/SpacingOptionsConsumer.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.codeStyle; + +import com.intellij.openapi.application.ApplicationBundle; + +/** + * @author yole + */ +public interface SpacingOptionsConsumer { + void showAllStandardOptions(); + void showStandardOptions(String... optionNames); + void showCustomOption(Class settingsClass, String fieldName, String optionName, String groupName); + + String AROUND_OPERATORS = ApplicationBundle.message("group.spaces.around.operators"); + String BEFORE_PARENTHESES = ApplicationBundle.message("group.spaces.before.parentheses"); + String BEFORE_LEFT_BRACE = ApplicationBundle.message("group.spaces.before.left.brace"); + String WITHIN_PARENTHESES = ApplicationBundle.message("group.spaces.within.parentheses"); + String TERNARY_OPERATOR = ApplicationBundle.message("group.spaces.in.ternary.operator"); + String TYPE_ARGUMENTS = ApplicationBundle.message("group.spaces.in.type.arguments"); + String OTHER = ApplicationBundle.message("group.spaces.other"); +} diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java index 670a6c25da5a..25572a80a435 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSpacesPanel.java @@ -16,13 +16,25 @@ package com.intellij.application.options.codeStyle; import com.intellij.openapi.application.ApplicationBundle; -//import com.intellij.openapi.editor.Editor; -//import com.intellij.openapi.editor.EditorSettings; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.util.Trinity; +import com.intellij.psi.codeStyle.CodeStyleOptionsCustomizer; import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CustomCodeStyleSettings; +import com.intellij.psi.codeStyle.SpacingOptionsConsumer; +import com.intellij.util.containers.MultiMap; +import org.jetbrains.annotations.NonNls; import javax.swing.*; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel implements SpacingOptionsConsumer { + private boolean myShowAllStandardOptions = false; + private Set myAllowedOptions; + private MultiMap, String, String>> myCustomOptions; -public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { public CodeStyleSpacesPanel(CodeStyleSettings settings) { super(settings); } @@ -32,15 +44,13 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { return LanguageCodeStyleSettingsProvider.SettingsType.SPACING_SETTINGS; } - private static final String AROUND_OPERATORS = ApplicationBundle.message("group.spaces.around.operators"); - private static final String BEFORE_PARENTHESES = ApplicationBundle.message("group.spaces.before.parentheses"); - private static final String BEFORE_LEFT_BRACE = ApplicationBundle.message("group.spaces.before.left.brace"); - private static final String WITHIN_PARENTHESES = ApplicationBundle.message("group.spaces.within.parentheses"); - private static final String TERNARY_OPERATOR = ApplicationBundle.message("group.spaces.in.ternary.operator"); - private static final String TYPE_ARGUMENTS = ApplicationBundle.message("group.spaces.in.type.arguments"); - private static final String OTHER = ApplicationBundle.message("group.spaces.other"); - protected void initTables() { + myAllowedOptions = new HashSet(); + myCustomOptions = new MultiMap, String, String>>(); + for(CodeStyleOptionsCustomizer contributor: Extensions.getExtensions(CodeStyleOptionsCustomizer.EP_NAME)) { + contributor.customizeSpacingOptions(this); + } + initBooleanField("SPACE_BEFORE_METHOD_CALL_PARENTHESES", ApplicationBundle.message("checkbox.spaces.method.call.parentheses"), BEFORE_PARENTHESES); initBooleanField("SPACE_BEFORE_METHOD_PARENTHESES", ApplicationBundle.message("checkbox.spaces.method.declaration.parentheses"), BEFORE_PARENTHESES); initBooleanField("SPACE_BEFORE_IF_PARENTHESES", ApplicationBundle.message("checkbox.spaces.if.parentheses"), BEFORE_PARENTHESES); @@ -50,6 +60,7 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { initBooleanField("SPACE_BEFORE_SWITCH_PARENTHESES", ApplicationBundle.message("checkbox.spaces.switch.parentheses"), BEFORE_PARENTHESES); initBooleanField("SPACE_BEFORE_SYNCHRONIZED_PARENTHESES", ApplicationBundle.message("checkbox.spaces.synchronized.parentheses"), BEFORE_PARENTHESES); initBooleanField("SPACE_BEFORE_ANOTATION_PARAMETER_LIST", ApplicationBundle.message("checkbox.spaces.annotation.parameters"), BEFORE_PARENTHESES); + initCustomOptions(BEFORE_PARENTHESES); initBooleanField("SPACE_AROUND_ASSIGNMENT_OPERATORS", ApplicationBundle.message("checkbox.spaces.assignment.operators"), AROUND_OPERATORS); initBooleanField("SPACE_AROUND_LOGICAL_OPERATORS", ApplicationBundle.message("checkbox.spaces.logical.operators"), AROUND_OPERATORS); @@ -59,6 +70,7 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { initBooleanField("SPACE_AROUND_ADDITIVE_OPERATORS", ApplicationBundle.message("checkbox.spaces.additive.operators"), AROUND_OPERATORS); initBooleanField("SPACE_AROUND_MULTIPLICATIVE_OPERATORS", ApplicationBundle.message("checkbox.spaces.multiplicative.operators"), AROUND_OPERATORS); initBooleanField("SPACE_AROUND_SHIFT_OPERATORS", ApplicationBundle.message("checkbox.spaces.shift.operators"), AROUND_OPERATORS); + initCustomOptions(AROUND_OPERATORS); initBooleanField("SPACE_BEFORE_CLASS_LBRACE", ApplicationBundle.message("checkbox.spaces.class.left.brace"), BEFORE_LEFT_BRACE); initBooleanField("SPACE_BEFORE_METHOD_LBRACE", ApplicationBundle.message("checkbox.spaces.method.left.brace"), BEFORE_LEFT_BRACE); @@ -73,6 +85,7 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { initBooleanField("SPACE_BEFORE_FINALLY_LBRACE", ApplicationBundle.message("checkbox.spaces.finally.left.brace"), BEFORE_LEFT_BRACE); initBooleanField("SPACE_BEFORE_SYNCHRONIZED_LBRACE", ApplicationBundle.message("checkbox.spaces.synchronized.left.brace"), BEFORE_LEFT_BRACE); initBooleanField("SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE", ApplicationBundle.message("checkbox.spaces.array.initializer.left.brace"), BEFORE_LEFT_BRACE); + initCustomOptions(BEFORE_LEFT_BRACE); initBooleanField("SPACE_WITHIN_PARENTHESES", ApplicationBundle.message("checkbox.spaces.parentheses"), WITHIN_PARENTHESES); initBooleanField("SPACE_WITHIN_METHOD_CALL_PARENTHESES", ApplicationBundle.message("checkbox.spaces.checkbox.spaces.method.call.parentheses"), WITHIN_PARENTHESES); @@ -85,13 +98,16 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { initBooleanField("SPACE_WITHIN_SYNCHRONIZED_PARENTHESES", ApplicationBundle.message("checkbox.spaces.synchronized.parentheses"), WITHIN_PARENTHESES); initBooleanField("SPACE_WITHIN_CAST_PARENTHESES", ApplicationBundle.message("checkbox.spaces.type.cast.parentheses"), WITHIN_PARENTHESES); initBooleanField("SPACE_WITHIN_ANNOTATION_PARENTHESES", ApplicationBundle.message("checkbox.spaces.annotation.parentheses"), WITHIN_PARENTHESES); + initCustomOptions(WITHIN_PARENTHESES); initBooleanField("SPACE_BEFORE_QUEST", ApplicationBundle.message("checkbox.spaces.before.question"), TERNARY_OPERATOR); initBooleanField("SPACE_AFTER_QUEST", ApplicationBundle.message("checkbox.spaces.after.question"), TERNARY_OPERATOR); initBooleanField("SPACE_BEFORE_COLON", ApplicationBundle.message("checkbox.spaces.before.colon"), TERNARY_OPERATOR); initBooleanField("SPACE_AFTER_COLON", ApplicationBundle.message("checkbox.spaces.after.colon"), TERNARY_OPERATOR); + initCustomOptions(TERNARY_OPERATOR); initBooleanField("SPACE_AFTER_COMMA_IN_TYPE_ARGUMENTS", ApplicationBundle.message("checkbox.spaces.after.comma"), TYPE_ARGUMENTS); + initCustomOptions(TYPE_ARGUMENTS); //TODO looks like this option is never implemented: initBooleanField("SPACE_AFTER_LABEL", ApplicationBundle.message("checkbox.spaces.after.colon.in.label.declaration"), OTHER); initBooleanField("SPACE_WITHIN_BRACKETS", ApplicationBundle.message("checkbox.spaces.within.brackets"), OTHER); @@ -102,6 +118,13 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { initBooleanField("SPACE_BEFORE_SEMICOLON", ApplicationBundle.message("checkbox.spaces.before.semicolon"), OTHER); initBooleanField("SPACE_AFTER_TYPE_CAST", ApplicationBundle.message("checkbox.spaces.after.type.cast"), OTHER); initBooleanField("SPACE_AFTER_UNARY_OPERATOR", ApplicationBundle.message("checkbox.spaces.after.unary.operator"), OTHER); + initCustomOptions(OTHER); + } + + private void initCustomOptions(String groupName) { + for(Trinity, String, String> option: myCustomOptions.get(groupName)) { + initCustomBooleanField(option.first, option.second, option.third, groupName); + } } /* @@ -117,7 +140,30 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel { } */ + @Override + protected void initBooleanField(@NonNls String fieldName, String cbName, String groupName) { + if (myShowAllStandardOptions || myAllowedOptions.contains(fieldName)) { + super.initBooleanField(fieldName, cbName, groupName); + } + } + public JComponent getPanel() { return getInternalPanel(); } + + public void showAllStandardOptions() { + myShowAllStandardOptions = true; + } + + public void showStandardOptions(String... optionNames) { + Collections.addAll(myAllowedOptions, optionNames); + } + + public void showCustomOption(Class settingsClass, + String fieldName, + String optionName, + String groupName) { + myCustomOptions.putValue(groupName, + Trinity., String, String>create(settingsClass, fieldName, optionName)); + } } diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTreeWithPreviewPanel.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTreeWithPreviewPanel.java index 452f5c48091c..d4a07cfb0f04 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTreeWithPreviewPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/OptionTreeWithPreviewPanel.java @@ -18,10 +18,12 @@ package com.intellij.application.options.codeStyle; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.PsiFile; import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CustomCodeStyleSettings; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.tree.*; @@ -198,7 +200,7 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA } - private boolean isModified(TreeNode node, final CodeStyleSettings settings) { + private static boolean isModified(TreeNode node, final CodeStyleSettings settings) { if (node instanceof MyToggleTreeNode) { if (isToggleNodeModified((MyToggleTreeNode)node, settings)) { return true; @@ -242,6 +244,19 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA } } + protected void initCustomBooleanField(@NotNull Class customClass, String fieldName, String cbName, String groupName) { + try { + Field field = customClass.getField(fieldName); + myKeys.add(new CustomBooleanOptionKey(groupName, cbName, customClass, field)); + } + catch (NoSuchFieldException e) { + LOG.error(e); + } + catch (SecurityException e) { + LOG.error(e); + } + } + protected void prepareForReformat(final PsiFile psiFile) { //psiFile.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST); } @@ -379,6 +394,32 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA } } + private static class CustomBooleanOptionKey extends BooleanOptionKey { + private final Class mySettingsClass; + + public CustomBooleanOptionKey(String groupName, String cbName, Class settingsClass, Field field) { + super(groupName, cbName, field); + mySettingsClass = settingsClass; + } + + @Override + public void setValue(CodeStyleSettings settings, Boolean aBoolean) { + final CustomCodeStyleSettings customSettings = settings.getCustomSettings(mySettingsClass); + try { + field.set(customSettings, aBoolean); + } + catch (IllegalAccessException e) { + LOG.error(e); + } + } + + @Override + public boolean getValue(CodeStyleSettings settings) throws IllegalAccessException { + final CustomCodeStyleSettings customSettings = settings.getCustomSettings(mySettingsClass); + return field.getBoolean(customSettings); + } + } + private static class MyToggleTreeNode extends DefaultMutableTreeNode { private final Object myKey; private final String myText; diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index 8e40f85f82df..b3792d05f479 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -59,6 +59,8 @@ + diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index dcdc083b16bd..b9d570152642 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -720,6 +720,8 @@ + +