Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Denis Zhdanov
2010-05-11 18:30:01 +04:00
15 changed files with 5513 additions and 1201 deletions
@@ -1,40 +0,0 @@
/*
* Copyright 2000-2009 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.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import javax.swing.*;
public class CodeStyleIndentAndBracesConfigurable extends CodeStyleAbstractConfigurable {
public CodeStyleIndentAndBracesConfigurable(CodeStyleSettings settings, CodeStyleSettings cloneSettings) {
super(settings, cloneSettings, ApplicationBundle.message("title.alignment.and.braces"));
}
public Icon getIcon() {
return StdFileTypes.JAVA.getIcon();
}
protected CodeStyleAbstractPanel createPanel(final CodeStyleSettings settings) {
return new CodeStyleIndentAndBracesPanel(settings);
}
public String getHelpTopic() {
return "preferences.sourceCode.indentBrace";
}
}
@@ -1,514 +0,0 @@
/*
* Copyright 2000-2009 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.ide.highlighter.JavaHighlighterFactory;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiUtil;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.OptionGroup;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
public class CodeStyleIndentAndBracesPanel extends CodeStyleAbstractPanel {
private static final String[] BRACE_PLACEMENT_OPTIONS = new String[]{
ApplicationBundle.message("combobox.brace.placement.end.of.line"),
ApplicationBundle.message("combobox.brace.placement.next.line.if.wrapped"),
ApplicationBundle.message("combobox.brace.placement.next.line"),
ApplicationBundle.message("combobox.brace.placement.next.line.shifted"),
ApplicationBundle.message("combobox.brace.placement.next.line.shifted2")
};
private static final int[] BRACE_PLACEMENT_VALUES = new int[] {
CodeStyleSettings.END_OF_LINE,
CodeStyleSettings.NEXT_LINE_IF_WRAPPED,
CodeStyleSettings.NEXT_LINE,
CodeStyleSettings.NEXT_LINE_SHIFTED,
CodeStyleSettings.NEXT_LINE_SHIFTED2
};
private static final String[] BRACE_FORCE_OPTIONS = new String[]{
ApplicationBundle.message("combobox.force.braces.do.not.force"),
ApplicationBundle.message("combobox.force.braces.when.multiline"),
ApplicationBundle.message("combobox.force.braces.always")
};
private static final int[] BRACE_FORCE_VALUES = new int[]{
CodeStyleSettings.DO_NOT_FORCE,
CodeStyleSettings.FORCE_BRACES_IF_MULTILINE,
CodeStyleSettings.FORCE_BRACES_ALWAYS
};
private JComboBox myClassDeclarationCombo = new JComboBox();
private JComboBox myMethodDeclarationCombo = new JComboBox();
private JComboBox myOtherCombo = new JComboBox();
private JCheckBox myCbElseOnNewline;
private JCheckBox myCbWhileOnNewline;
private JCheckBox myCbCatchOnNewline;
private JCheckBox myCbFinallyOnNewline;
private JCheckBox myCbSpecialElseIfTreatment;
private JCheckBox myCbIndentCaseFromSwitch;
private JComboBox myIfForceCombo;
private JComboBox myForForceCombo;
private JComboBox myWhileForceCombo;
private JComboBox myDoWhileForceCombo;
private JCheckBox myAlignDeclarationParameters;
private JCheckBox myAlignCallParameters;
private JCheckBox myAlignExtendsList;
private JCheckBox myAlignForStatement;
private JCheckBox myAlignThrowsList;
private JCheckBox myAlignParenthesizedExpression;
private JCheckBox myAlignBinaryExpression;
private JCheckBox myAlignTernaryExpression;
private JCheckBox myAlignAssignment;
private JCheckBox myAlignArrayInitializerExpression;
private JCheckBox myKeepLineBreaks;
private JCheckBox myKeepCommentAtFirstColumn;
private JCheckBox myKeepMethodsInOneLine;
private JCheckBox myKeepSimpleBlocksInOneLine;
private JCheckBox myKeepControlStatementInOneLine;
private final JPanel myPanel = new JPanel(new GridBagLayout());
public CodeStyleIndentAndBracesPanel(CodeStyleSettings settings) {
super(settings);
myPanel.add(createKeepWhenReformatingPanel(),
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(0, 4, 0, 4), 0, 0));
myPanel.add(createBracesPanel(),
new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(0, 4, 0, 4), 0, 0));
myPanel.add(createAlignmentsPanel(),
new GridBagConstraints(1, 0, 1, 2, 0, 0, GridBagConstraints.NORTH, GridBagConstraints.BOTH,
new Insets(0, 4, 0, 4), 0, 0));
myPanel.add(createPlaceOnNewLinePanel(),
new GridBagConstraints(1, 2, 1, 1, 0, 0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(0, 4, 0, 4), 0, 0));
myPanel.add(createForceBracesPanel(),
new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.NORTH, GridBagConstraints.BOTH,
new Insets(0, 4, 0, 4), 0, 0));
myPanel.add(new JPanel() {
public Dimension getPreferredSize() {
return new Dimension(1, 1);
}
}, new GridBagConstraints(0, 3, 2, 1, 0, 0, GridBagConstraints.NORTH, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
final JPanel previewPanel = createPreviewPanel();
myPanel.add(previewPanel,
new GridBagConstraints(2, 0, 1, 4, 1, 1, GridBagConstraints.NORTH, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 4), 0, 0));
installPreviewPanel(previewPanel);
addPanelToWatch(myPanel);
}
private Component createKeepWhenReformatingPanel() {
OptionGroup optionGroup = new OptionGroup(ApplicationBundle.message("title.keep.when.reformatting"));
myKeepLineBreaks = createCheckBox(ApplicationBundle.message("checkbox.keep.when.reformatting.line.breaks"));
optionGroup.add(myKeepLineBreaks);
myKeepCommentAtFirstColumn = createCheckBox(ApplicationBundle.message("checkbox.keep.when.reformatting.comment.at.first.column"));
optionGroup.add(myKeepCommentAtFirstColumn);
myKeepMethodsInOneLine = createCheckBox(ApplicationBundle.message("checkbox.keep.when.reformatting.simple.methods.in.one.line"));
optionGroup.add(myKeepMethodsInOneLine);
myKeepSimpleBlocksInOneLine = createCheckBox(ApplicationBundle.message("checkbox.keep.when.reformatting.simple.blocks.in.one.line"));
optionGroup.add(myKeepSimpleBlocksInOneLine);
myKeepControlStatementInOneLine = createCheckBox(ApplicationBundle.message("checkbox.keep.when.reformatting.control.statement.in.one.line"));
optionGroup.add(myKeepControlStatementInOneLine);
return optionGroup.createPanel();
}
private JPanel createBracesPanel() {
OptionGroup optionGroup = new OptionGroup(ApplicationBundle.message("title.braces.placement"));
myClassDeclarationCombo = createBraceStyleCombo();
optionGroup.add(new JLabel(ApplicationBundle.message("combobox.brace.placement.class.declaration")), myClassDeclarationCombo);
myMethodDeclarationCombo = createBraceStyleCombo();
optionGroup.add(new JLabel(ApplicationBundle.message("combobox.brace.placement.method.declaration")), myMethodDeclarationCombo);
myOtherCombo = createBraceStyleCombo();
optionGroup.add(new JLabel(ApplicationBundle.message("combobox.brace.placement.other")), myOtherCombo);
myCbSpecialElseIfTreatment = createCheckBox(ApplicationBundle.message("checkbox.brace.special.else.if.treatment"));
optionGroup.add(myCbSpecialElseIfTreatment);
myCbIndentCaseFromSwitch = createCheckBox(ApplicationBundle.message("checkbox.brace.indent.case.from.switch"));
optionGroup.add(myCbIndentCaseFromSwitch);
return optionGroup.createPanel();
}
private JPanel createForceBracesPanel() {
OptionGroup optionGroup = new OptionGroup(ApplicationBundle.message("title.force.braces"));
myIfForceCombo = createForceBracesCombo();
optionGroup.add(new JLabel(ApplicationBundle.message("combobox.force.braces.if")), myIfForceCombo);
myForForceCombo = createForceBracesCombo();
optionGroup.add(new JLabel(ApplicationBundle.message("combobox.force.braces.for")), myForForceCombo);
myWhileForceCombo = createForceBracesCombo();
optionGroup.add(new JLabel(ApplicationBundle.message("combobox.force.braces.while")), myWhileForceCombo);
myDoWhileForceCombo = createForceBracesCombo();
optionGroup.add(new JLabel(ApplicationBundle.message("combobox.force.braces.do.while")), myDoWhileForceCombo);
return optionGroup.createPanel();
}
private JPanel createAlignmentsPanel() {
OptionGroup optionGroup = new OptionGroup(ApplicationBundle.message("title.align.when.multiline"));
myAlignDeclarationParameters = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.method.parameters"));
optionGroup.add(myAlignDeclarationParameters);
myAlignCallParameters = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.call.arguments"));
optionGroup.add(myAlignCallParameters);
myAlignExtendsList = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.extends.list"));
optionGroup.add(myAlignExtendsList);
myAlignThrowsList = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.throws.list"));
optionGroup.add(myAlignThrowsList);
myAlignParenthesizedExpression = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.parenthesized.expression"));
optionGroup.add(myAlignParenthesizedExpression);
myAlignBinaryExpression = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.binary.operation"));
optionGroup.add(myAlignBinaryExpression);
myAlignTernaryExpression = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.ternary.operation"));
optionGroup.add(myAlignTernaryExpression);
myAlignAssignment = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.assignments"));
optionGroup.add(myAlignAssignment);
myAlignForStatement = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.for.statement"));
optionGroup.add(myAlignForStatement);
myAlignArrayInitializerExpression = createCheckBox(ApplicationBundle.message("checkbox.align.multiline.array.initializer"));
optionGroup.add(myAlignArrayInitializerExpression);
return optionGroup.createPanel();
}
private JPanel createPlaceOnNewLinePanel() {
OptionGroup optionGroup = new OptionGroup(ApplicationBundle.message("title.place.on.new.line"));
myCbElseOnNewline = createCheckBox(ApplicationBundle.message("checkbox.place.else.on.new.line"));
optionGroup.add(myCbElseOnNewline);
myCbWhileOnNewline = createCheckBox(ApplicationBundle.message("checkbox.place.while.on.new.line"));
optionGroup.add(myCbWhileOnNewline);
myCbCatchOnNewline = createCheckBox(ApplicationBundle.message("checkbox.place.catch.on.new.line"));
optionGroup.add(myCbCatchOnNewline);
myCbFinallyOnNewline = createCheckBox(ApplicationBundle.message("checkbox.place.finally.on.new.line"));
optionGroup.add(myCbFinallyOnNewline);
return optionGroup.createPanel();
}
private static JCheckBox createCheckBox(String text) {
return new JCheckBox(text);
}
private static JComboBox createForceBracesCombo() {
return new JComboBox(BRACE_FORCE_OPTIONS);
}
private static void setForceBracesComboValue(JComboBox comboBox, int value) {
for (int i = 0; i < BRACE_FORCE_VALUES.length; i++) {
int forceValue = BRACE_FORCE_VALUES[i];
if (forceValue == value) {
comboBox.setSelectedItem(BRACE_FORCE_OPTIONS[i]);
}
}
}
private static int getForceBracesValue(JComboBox comboBox) {
String selected = (String)comboBox.getSelectedItem();
for (int i = 0; i < BRACE_FORCE_OPTIONS.length; i++) {
String s = BRACE_FORCE_OPTIONS[i];
if (s.equals(selected)) {
return BRACE_FORCE_VALUES[i];
}
}
return 0;
}
private static JComboBox createBraceStyleCombo() {
return new JComboBox(BRACE_PLACEMENT_OPTIONS);
}
private static void setBraceStyleComboValue(JComboBox comboBox, int value) {
for (int i = 0; i < BRACE_PLACEMENT_OPTIONS.length; i++) {
if (BRACE_PLACEMENT_VALUES[i] == value) {
comboBox.setSelectedItem(BRACE_PLACEMENT_OPTIONS[i]);
return;
}
}
}
private static int getBraceComboValue(JComboBox comboBox) {
Object item = comboBox.getSelectedItem();
for (int i = 1; i < BRACE_PLACEMENT_OPTIONS.length; i++) {
if (BRACE_PLACEMENT_OPTIONS[i].equals(item)) {
return BRACE_PLACEMENT_VALUES[i];
}
}
return BRACE_PLACEMENT_VALUES[0];
}
private static JPanel createPreviewPanel() {
JPanel p = new JPanel(new BorderLayout());
p.setBorder(IdeBorderFactory.createTitledBorder(ApplicationBundle.message("title.preview")));
return p;
}
@NonNls
protected String getPreviewText() {
return
"public class Foo {\n" +
" public int[] X = new int[] { 1, 3, 5\n" +
" 7, 9, 11};\n" +
" public void foo(boolean a, int x,\n" +
" int y, int z) {\n" +
" label1: do {\n" +
" try {\n" +
" if(x > 0) {\n" +
" int someVariable = a ? \n" +
" x : \n" +
" y;\n" +
" int anotherVariable = a ? x\n" +
" : y;\n" +
" } else if (x < 0) {\n" +
" int someVariable = (y +\n" +
" z\n" +
" );\n" +
" someVariable = x = \n" +
" x +\n" +
" y;\n" +
" } else {\n" +
" label2:\n" +
" for (int i = 0;\n" +
" i < 5;\n" +
" i++) doSomething(i);\n" +
" }\n" +
" switch(a) {\n" +
" case 0: \n" +
" doCase0();\n" +
" break;\n" +
" default: \n" +
" doDefault();\n" +
" }\n" +
" }catch(Exception e) {\n" +
" processException(e.getMessage(),\n" +
" x + y, z, a);\n" +
" }finally {\n" +
" processFinally();\n" +
" }\n" +
" }while(true);\n" +
"\n" +
" if (2 < 3) return;\n" +
" if (3 < 4)\n" +
" return;\n" +
" do x++ while (x < 10000);\n" +
" while (x < 50000) x++;\n" +
" for (int i = 0; i < 5; i++) System.out.println(i);\n" +
" }\n" +
" private class InnerClass implements I1,\n" +
" I2 {\n" +
" public void bar() throws E1,\n" +
" E2 {\n" +
" }\n" +
" }\n" +
"}";
}
public boolean isModified(CodeStyleSettings settings) {
boolean isModified;
isModified = isModified(myCbElseOnNewline, settings.ELSE_ON_NEW_LINE);
isModified |= isModified(myCbWhileOnNewline, settings.WHILE_ON_NEW_LINE);
isModified |= isModified(myCbCatchOnNewline, settings.CATCH_ON_NEW_LINE);
isModified |= isModified(myCbFinallyOnNewline, settings.FINALLY_ON_NEW_LINE);
isModified |= isModified(myCbSpecialElseIfTreatment, settings.SPECIAL_ELSE_IF_TREATMENT);
isModified |= isModified(myCbIndentCaseFromSwitch, settings.INDENT_CASE_FROM_SWITCH);
isModified |= settings.BRACE_STYLE != getBraceComboValue(myOtherCombo);
isModified |= settings.CLASS_BRACE_STYLE != getBraceComboValue(myClassDeclarationCombo);
isModified |= settings.METHOD_BRACE_STYLE != getBraceComboValue(myMethodDeclarationCombo);
isModified |= isModified(myAlignAssignment, settings.ALIGN_MULTILINE_ASSIGNMENT);
isModified |= isModified(myAlignBinaryExpression, settings.ALIGN_MULTILINE_BINARY_OPERATION);
isModified |= isModified(myAlignCallParameters, settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS);
isModified |= isModified(myAlignDeclarationParameters, settings.ALIGN_MULTILINE_PARAMETERS);
isModified |= isModified(myAlignExtendsList, settings.ALIGN_MULTILINE_EXTENDS_LIST);
isModified |= isModified(myAlignForStatement, settings.ALIGN_MULTILINE_FOR);
isModified |= isModified(myAlignParenthesizedExpression, settings.ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION);
isModified |= isModified(myAlignTernaryExpression, settings.ALIGN_MULTILINE_TERNARY_OPERATION);
isModified |= isModified(myAlignThrowsList, settings.ALIGN_MULTILINE_THROWS_LIST);
isModified |= isModified(myAlignArrayInitializerExpression, settings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION);
isModified |= settings.FOR_BRACE_FORCE != getForceBracesValue(myForForceCombo);
isModified |= settings.IF_BRACE_FORCE != getForceBracesValue(myIfForceCombo);
isModified |= settings.WHILE_BRACE_FORCE != getForceBracesValue(myWhileForceCombo);
isModified |= settings.DOWHILE_BRACE_FORCE != getForceBracesValue(myDoWhileForceCombo);
isModified |= isModified(myKeepLineBreaks, settings.KEEP_LINE_BREAKS);
isModified |= isModified(myKeepCommentAtFirstColumn, settings.KEEP_FIRST_COLUMN_COMMENT);
isModified |= isModified(myKeepControlStatementInOneLine, settings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE);
isModified |= isModified(myKeepSimpleBlocksInOneLine, settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE);
isModified |= isModified(myKeepMethodsInOneLine, settings.KEEP_SIMPLE_METHODS_IN_ONE_LINE);
return isModified;
}
private static boolean isModified(JCheckBox checkBox, boolean value) {
return checkBox.isSelected() != value;
}
protected void resetImpl(final CodeStyleSettings settings) {
myCbElseOnNewline.setSelected(settings.ELSE_ON_NEW_LINE);
myCbWhileOnNewline.setSelected(settings.WHILE_ON_NEW_LINE);
myCbCatchOnNewline.setSelected(settings.CATCH_ON_NEW_LINE);
myCbFinallyOnNewline.setSelected(settings.FINALLY_ON_NEW_LINE);
myCbSpecialElseIfTreatment.setSelected(settings.SPECIAL_ELSE_IF_TREATMENT);
myCbIndentCaseFromSwitch.setSelected(settings.INDENT_CASE_FROM_SWITCH);
setBraceStyleComboValue(myOtherCombo, settings.BRACE_STYLE);
setBraceStyleComboValue(myClassDeclarationCombo, settings.CLASS_BRACE_STYLE);
setBraceStyleComboValue(myMethodDeclarationCombo, settings.METHOD_BRACE_STYLE);
myAlignAssignment.setSelected(settings.ALIGN_MULTILINE_ASSIGNMENT);
myAlignBinaryExpression.setSelected(settings.ALIGN_MULTILINE_BINARY_OPERATION);
myAlignCallParameters.setSelected(settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS);
myAlignDeclarationParameters.setSelected(settings.ALIGN_MULTILINE_PARAMETERS);
myAlignExtendsList.setSelected(settings.ALIGN_MULTILINE_EXTENDS_LIST);
myAlignForStatement.setSelected(settings.ALIGN_MULTILINE_FOR);
myAlignParenthesizedExpression.setSelected(settings.ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION);
myAlignTernaryExpression.setSelected(settings.ALIGN_MULTILINE_TERNARY_OPERATION);
myAlignThrowsList.setSelected(settings.ALIGN_MULTILINE_THROWS_LIST);
myAlignArrayInitializerExpression.setSelected(settings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION);
setForceBracesComboValue(myForForceCombo, settings.FOR_BRACE_FORCE);
setForceBracesComboValue(myIfForceCombo, settings.IF_BRACE_FORCE);
setForceBracesComboValue(myWhileForceCombo, settings.WHILE_BRACE_FORCE);
setForceBracesComboValue(myDoWhileForceCombo, settings.DOWHILE_BRACE_FORCE);
myKeepLineBreaks.setSelected(settings.KEEP_LINE_BREAKS);
myKeepCommentAtFirstColumn.setSelected(settings.KEEP_FIRST_COLUMN_COMMENT);
myKeepControlStatementInOneLine.setSelected(settings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE);
myKeepSimpleBlocksInOneLine.setSelected(settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE);
myKeepMethodsInOneLine.setSelected(settings.KEEP_SIMPLE_METHODS_IN_ONE_LINE);
}
protected EditorHighlighter createHighlighter(final EditorColorsScheme scheme) {
return JavaHighlighterFactory.createJavaHighlighter(scheme, LanguageLevel.HIGHEST);
}
public void apply(CodeStyleSettings settings) {
settings.ELSE_ON_NEW_LINE = myCbElseOnNewline.isSelected();
settings.WHILE_ON_NEW_LINE = myCbWhileOnNewline.isSelected();
settings.CATCH_ON_NEW_LINE = myCbCatchOnNewline.isSelected();
settings.FINALLY_ON_NEW_LINE = myCbFinallyOnNewline.isSelected();
settings.SPECIAL_ELSE_IF_TREATMENT = myCbSpecialElseIfTreatment.isSelected();
settings.INDENT_CASE_FROM_SWITCH = myCbIndentCaseFromSwitch.isSelected();
settings.BRACE_STYLE = getBraceComboValue(myOtherCombo);
settings.CLASS_BRACE_STYLE = getBraceComboValue(myClassDeclarationCombo);
settings.METHOD_BRACE_STYLE = getBraceComboValue(myMethodDeclarationCombo);
settings.ALIGN_MULTILINE_ASSIGNMENT = myAlignAssignment.isSelected();
settings.ALIGN_MULTILINE_BINARY_OPERATION = myAlignBinaryExpression.isSelected();
settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = myAlignCallParameters.isSelected();
settings.ALIGN_MULTILINE_PARAMETERS = myAlignDeclarationParameters.isSelected();
settings.ALIGN_MULTILINE_EXTENDS_LIST = myAlignExtendsList.isSelected();
settings.ALIGN_MULTILINE_FOR = myAlignForStatement.isSelected();
settings.ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION = myAlignParenthesizedExpression.isSelected();
settings.ALIGN_MULTILINE_TERNARY_OPERATION = myAlignTernaryExpression.isSelected();
settings.ALIGN_MULTILINE_THROWS_LIST = myAlignThrowsList.isSelected();
settings.ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION = myAlignArrayInitializerExpression.isSelected();
// mySettings.LABEL_INDENT =
settings.FOR_BRACE_FORCE = getForceBracesValue(myForForceCombo);
settings.IF_BRACE_FORCE = getForceBracesValue(myIfForceCombo);
settings.WHILE_BRACE_FORCE = getForceBracesValue(myWhileForceCombo);
settings.DOWHILE_BRACE_FORCE = getForceBracesValue(myDoWhileForceCombo);
settings.KEEP_LINE_BREAKS = myKeepLineBreaks.isSelected();
settings.KEEP_FIRST_COLUMN_COMMENT = myKeepCommentAtFirstColumn.isSelected();
settings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE = myKeepControlStatementInOneLine.isSelected();
settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = myKeepSimpleBlocksInOneLine.isSelected();
settings.KEEP_SIMPLE_METHODS_IN_ONE_LINE = myKeepMethodsInOneLine.isSelected();
}
@NotNull
protected FileType getFileType() {
return StdFileTypes.JAVA;
}
protected int getRightMargin() {
return -1;
}
public JComponent getPanel() {
return myPanel;
}
protected void prepareForReformat(final PsiFile psiFile) {
psiFile.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST);
}
}
@@ -1,606 +0,0 @@
/*
* Copyright 2000-2009 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.ide.highlighter.JavaHighlighterFactory;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiUtil;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.util.containers.HashMap;
import com.intellij.util.ui.AbstractTableCellEditor;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.UIUtil;
import com.intellij.ui.treeStructure.treetable.ListTreeTableModel;
import com.intellij.ui.treeStructure.treetable.TreeTable;
import com.intellij.ui.treeStructure.treetable.TreeTableCellRenderer;
import com.intellij.ui.treeStructure.treetable.TreeTableModel;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
/**
* @author max
*/
public abstract class OptionTableWithPreviewPanel extends CodeStyleAbstractPanel {
private static final Logger LOG = Logger.getInstance("#com.intellij.application.options.CodeStyleSpacesPanel");
@SuppressWarnings({"HardCodedStringLiteral"})
public final ColumnInfo TITLE = new ColumnInfo("TITLE") {
public Object valueOf(Object o) {
if (o instanceof MyTreeNode) {
MyTreeNode node = (MyTreeNode)o;
return node.getText();
}
return o.toString();
}
public Class getColumnClass() {
return TreeTableModel.class;
}
};
@SuppressWarnings({"HardCodedStringLiteral"})
public final ColumnInfo VALUE = new ColumnInfo("VALUE") {
private final TableCellEditor myEditor = new MyValueEditor();
private final TableCellRenderer myRenderer = new MyValueRenderer();
public Object valueOf(Object o) {
if (o instanceof MyTreeNode) {
MyTreeNode node = (MyTreeNode)o;
return node.getValue();
}
return null;
}
public TableCellRenderer getRenderer(Object o) {
return myRenderer;
}
public TableCellEditor getEditor(Object item) {
return myEditor;
}
public boolean isCellEditable(Object o) {
return o instanceof MyTreeNode;
}
public void setValue(Object o, Object o1) {
MyTreeNode node = (MyTreeNode)o;
node.setValue(o1);
}
};
public final ColumnInfo[] COLUMNS = new ColumnInfo[]{TITLE, VALUE};
private final TreeCellRenderer myTitleRenderer = new TreeCellRenderer() {
private final JLabel myLabel = new JLabel();
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
if (value instanceof MyTreeNode) {
MyTreeNode node = (MyTreeNode)value;
myLabel.setText(node.getText());
myLabel.setFont(
myLabel.getFont().deriveFont(node.getKey() instanceof IntSelectionOptionKey ? Font.BOLD : Font.PLAIN));
}
else {
myLabel.setText(value.toString());
myLabel.setFont(myLabel.getFont().deriveFont(Font.BOLD));
}
Color foreground = selected
? UIUtil.getTableSelectionForeground()
: UIUtil.getTableForeground();
myLabel.setForeground(foreground);
return myLabel;
}
};
private final TreeTable myTreeTable;
private final HashMap myKeyToFieldMap = new HashMap();
private final ArrayList myKeys = new ArrayList();
private final JPanel myPanel = new JPanel();
public OptionTableWithPreviewPanel(CodeStyleSettings settings) {
super(settings);
myPanel.setLayout(new GridBagLayout());
initTables();
myTreeTable = createOptionsTree(settings);
myPanel.add(ScrollPaneFactory.createScrollPane(myTreeTable),
new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH,
new Insets(7, 7, 3, 4), 0, 0));
final JPanel previewPanel = createPreviewPanel();
myPanel.add(previewPanel,
new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 4), 0, 0));
installPreviewPanel(previewPanel);
addPanelToWatch(myPanel);
}
protected TreeTable createOptionsTree(CodeStyleSettings settings) {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
String groupName = "";
DefaultMutableTreeNode groupNode = null;
for (int i = 0; i < myKeys.size(); i++) {
if (myKeys.get(i) instanceof BooleanOptionKey) {
BooleanOptionKey key = (BooleanOptionKey)myKeys.get(i);
String newGroupName = key.groupName;
if (!newGroupName.equals(groupName) || groupNode == null) {
groupName = newGroupName;
groupNode = new DefaultMutableTreeNode(newGroupName);
rootNode.add(groupNode);
}
groupNode.add(new MyTreeNode(key, key.cbName, settings));
}
else if (myKeys.get(i) instanceof IntSelectionOptionKey) {
IntSelectionOptionKey key = (IntSelectionOptionKey)myKeys.get(i);
String newGroupName = key.groupName;
if (!newGroupName.equals(groupName) || groupNode == null) {
groupName = newGroupName;
groupNode = new MyTreeNode(key, key.groupName, settings);
rootNode.add(groupNode);
}
else {
LOG.assertTrue(false);
}
}
}
ListTreeTableModel model = new ListTreeTableModel(rootNode, COLUMNS);
TreeTable treeTable = new TreeTable(model) {
public TreeTableCellRenderer createTableRenderer(TreeTableModel treeTableModel) {
TreeTableCellRenderer tableRenderer = super.createTableRenderer(treeTableModel);
UIUtil.setLineStyleAngled(tableRenderer);
tableRenderer.setRootVisible(false);
tableRenderer.setShowsRootHandles(true);
return tableRenderer;
}
public TableCellRenderer getCellRenderer(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null) return super.getCellRenderer(row, column);
Object node = treePath.getLastPathComponent();
TableCellRenderer renderer = COLUMNS[column].getRenderer(node);
return renderer == null ? super.getCellRenderer(row, column) : renderer;
}
public TableCellEditor getCellEditor(int row, int column) {
TreePath treePath = getTree().getPathForRow(row);
if (treePath == null) return super.getCellEditor(row, column);
Object node = treePath.getLastPathComponent();
TableCellEditor editor = COLUMNS[column].getEditor(node);
return editor == null ? super.getCellEditor(row, column) : editor;
}
};
treeTable.setRootVisible(false);
final JTree tree = treeTable.getTree();
tree.setCellRenderer(myTitleRenderer);
tree.setShowsRootHandles(true);
//myTreeTable.setRowHeight(new JComboBox(new String[]{"Sample Text"}).getPreferredSize().height);
treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
treeTable.setTableHeader(null);
expandTree(tree);
int maxWidth = tree.getPreferredScrollableViewportSize().width + 10;
final TableColumn titleColumn = treeTable.getColumnModel().getColumn(0);
titleColumn.setPreferredWidth(maxWidth);
titleColumn.setMinWidth(maxWidth);
titleColumn.setMaxWidth(maxWidth);
titleColumn.setResizable(false);
final TableColumn levelColumn = treeTable.getColumnModel().getColumn(1);
//TODO[max]: better preffered size...
JLabel value = new JLabel(ApplicationBundle.message("option.table.sizing.text"));
final Dimension valueSize = value.getPreferredSize();
levelColumn.setPreferredWidth(valueSize.width);
levelColumn.setMaxWidth(valueSize.width);
levelColumn.setMinWidth(valueSize.width);
levelColumn.setResizable(false);
treeTable.setPreferredScrollableViewportSize(new Dimension(maxWidth + valueSize.width + 10, 20));
return treeTable;
}
private void expandTree(final JTree tree) {
int oldRowCount = 0;
do {
int rowCount = tree.getRowCount();
if (rowCount == oldRowCount) break;
oldRowCount = rowCount;
for (int i = 0; i < rowCount; i++) {
tree.expandRow(i);
}
}
while (true);
}
protected JPanel createPreviewPanel() {
JPanel p = new JPanel(new BorderLayout()) {
public Dimension getPreferredSize() {
return new Dimension(200, 0);
}
};
p.setBorder(IdeBorderFactory.createTitledBorder(ApplicationBundle.message("title.preview")));
return p;
}
protected abstract void initTables();
private void resetNode(TreeNode node, CodeStyleSettings settings) {
if (node instanceof MyTreeNode) {
((MyTreeNode)node).reset(settings);
}
for (int j = 0; j < node.getChildCount(); j++) {
TreeNode child = node.getChildAt(j);
resetNode(child, settings);
}
}
private void applyNode(TreeNode node, final CodeStyleSettings settings) {
if (node instanceof MyTreeNode) {
((MyTreeNode)node).apply(settings);
}
for (int j = 0; j < node.getChildCount(); j++) {
TreeNode child = node.getChildAt(j);
applyNode(child, settings);
}
}
private boolean isModified(TreeNode node, final CodeStyleSettings settings) {
if (node instanceof MyTreeNode) {
if (((MyTreeNode)node).isModified(settings)) return true;
}
for (int j = 0; j < node.getChildCount(); j++) {
TreeNode child = node.getChildAt(j);
if (isModified(child, settings)) {
return true;
}
}
return false;
}
protected void initBooleanField(@NonNls String fieldName, String cbName, String groupName) {
try {
Class styleSettingsClass = CodeStyleSettings.class;
Field field = styleSettingsClass.getField(fieldName);
BooleanOptionKey key = new BooleanOptionKey(groupName, cbName);
myKeyToFieldMap.put(key, field);
myKeys.add(key);
}
catch (NoSuchFieldException e) {
}
catch (SecurityException e) {
}
}
protected void initRadioGroupField(@NonNls String fieldName, String groupName, String[] rbNames, int[] values) {
try {
Class styleSettingsClass = CodeStyleSettings.class;
Field field = styleSettingsClass.getField(fieldName);
IntSelectionOptionKey key = new IntSelectionOptionKey(groupName, rbNames, values);
myKeyToFieldMap.put(key, field);
myKeys.add(key);
}
catch (NoSuchFieldException e) {
}
catch (SecurityException e) {
}
}
protected void prepareForReformat(final PsiFile psiFile) {
psiFile.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST);
}
private static class BooleanOptionKey {
final String groupName;
final String cbName;
public BooleanOptionKey(String groupName, String cbName) {
this.groupName = groupName;
this.cbName = cbName;
}
public boolean equals(Object obj) {
if (!(obj instanceof BooleanOptionKey)) return false;
BooleanOptionKey key = (BooleanOptionKey)obj;
return groupName.equals(key.groupName) && cbName.equals(key.cbName);
}
public int hashCode() {
return cbName.hashCode();
}
}
private static class IntSelectionOptionKey {
final String groupName;
final String[] rbNames;
final int[] values;
public IntSelectionOptionKey(String groupName, String[] rbNames, int[] values) {
this.groupName = groupName;
this.rbNames = rbNames;
this.values = values;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IntSelectionOptionKey)) return false;
final IntSelectionOptionKey intSelectionOptionKey = (IntSelectionOptionKey)o;
if (!groupName.equals(intSelectionOptionKey.groupName)) return false;
if (!Arrays.equals(rbNames, intSelectionOptionKey.rbNames)) return false;
return true;
}
public int hashCode() {
return groupName.hashCode() + rbNames[0].hashCode() * 29;
}
}
private Object getSettingsValue(Object key, final CodeStyleSettings settings) {
try {
if (key instanceof BooleanOptionKey) {
Field field = (Field)myKeyToFieldMap.get(key);
return field.getBoolean(settings) ? Boolean.TRUE : Boolean.FALSE;
}
else if (key instanceof IntSelectionOptionKey) {
Field field = (Field)myKeyToFieldMap.get(key);
IntSelectionOptionKey intKey = (IntSelectionOptionKey)key;
int[] values = intKey.values;
int value = field.getInt(settings);
for (int i = 0; i < values.length; i++) {
if (values[i] == value) return intKey.rbNames[i];
}
}
}
catch (IllegalAccessException e) {
}
return null;
}
public void setSettingsValue(Object key, Object value, final CodeStyleSettings settings) {
try {
if (key instanceof BooleanOptionKey) {
Field field = (Field)myKeyToFieldMap.get(key);
field.setBoolean(settings, ((Boolean)value).booleanValue());
}
else if (key instanceof IntSelectionOptionKey) {
Field field = (Field)myKeyToFieldMap.get(key);
IntSelectionOptionKey intKey = (IntSelectionOptionKey)key;
int[] values = intKey.values;
for (int i = 0; i < values.length; i++) {
if (intKey.rbNames[i].equals(value)) {
field.setInt(settings, values[i]);
return;
}
}
}
}
catch (IllegalAccessException e) {
}
}
private class MyTreeNode extends DefaultMutableTreeNode {
private final Object myKey;
private final String myText;
private Object myValue;
public MyTreeNode(Object key, String text, CodeStyleSettings settings) {
myKey = key;
myText = text;
myValue = getSettingsValue(key, settings);
}
public Object getKey() { return myKey; }
public String getText() { return myText; }
public Object getValue() { return myValue; }
public void setValue(Object value) {
myValue = value;
}
public void reset(CodeStyleSettings settings) {
setValue(getSettingsValue(myKey, settings));
}
public boolean isModified(final CodeStyleSettings settings) {
return !myValue.equals(getSettingsValue(myKey, settings));
}
public void apply(final CodeStyleSettings settings) {
setSettingsValue(myKey, myValue, settings);
}
}
private class MyValueRenderer implements TableCellRenderer {
private final JLabel myComboBox = new JLabel();
private final JCheckBox myCheckBox = new JCheckBox();
private final JPanel myEmptyLabel = new JPanel();
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
Color background = table.getBackground();
if (value instanceof Boolean) {
myCheckBox.setSelected(((Boolean)value).booleanValue());
myCheckBox.setBackground(background);
return myCheckBox;
}
else if (value instanceof String) {
/*
myComboBox.removeAllItems();
myComboBox.addItem(value);
*/
myComboBox.setText((String)value);
myComboBox.setBackground(background);
return myComboBox;
}
myCheckBox.putClientProperty("JComponent.sizeVariant", "small");
myComboBox.putClientProperty("JComponent.sizeVariant", "small");
myEmptyLabel.setBackground(background);
return myEmptyLabel;
}
}
private class MyValueEditor extends AbstractTableCellEditor {
private final JComboBox myComboBox = new JComboBox();
private final JCheckBox myCheckBox = new JCheckBox();
private Component myCurrentEditor = null;
private MyTreeNode myCurrentNode = null;
public MyValueEditor() {
ActionListener synchronizer = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (myCurrentNode != null) {
myCurrentNode.setValue(getCellEditorValue());
}
}
};
myComboBox.addActionListener(synchronizer);
myCheckBox.addActionListener(synchronizer);
myComboBox.putClientProperty("JComponent.sizeVariant", "small");
myCheckBox.putClientProperty("JComponent.sizeVariant", "small");
}
public Object getCellEditorValue() {
if (myCurrentEditor == myComboBox) {
return myComboBox.getSelectedItem();
}
else if (myCurrentEditor == myCheckBox) {
return myCheckBox.isSelected() ? Boolean.TRUE : Boolean.FALSE;
}
return null;
}
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
final DefaultMutableTreeNode defaultNode = (DefaultMutableTreeNode)((TreeTable)table).getTree().
getPathForRow(row).getLastPathComponent();
myCurrentEditor = null;
myCurrentNode = null;
if (defaultNode instanceof MyTreeNode) {
MyTreeNode node = (MyTreeNode)defaultNode;
if (node.getKey() instanceof BooleanOptionKey) {
myCurrentEditor = myCheckBox;
myCheckBox.setSelected(node.getValue() == Boolean.TRUE);
}
else {
myCurrentEditor = myComboBox;
myComboBox.removeAllItems();
IntSelectionOptionKey key = (IntSelectionOptionKey)node.getKey();
String[] values = key.rbNames;
for (int i = 0; i < values.length; i++) {
myComboBox.addItem(values[i]);
}
myComboBox.setSelectedItem(node.getValue());
}
myCurrentNode = node;
}
myCurrentEditor.setBackground(table.getBackground());
return myCurrentEditor;
}
}
protected EditorHighlighter createHighlighter(final EditorColorsScheme scheme) {
return JavaHighlighterFactory.createJavaHighlighter(scheme, LanguageLevel.HIGHEST);
}
@NotNull
protected FileType getFileType() {
return StdFileTypes.JAVA;
}
public void apply(CodeStyleSettings settings) {
TreeModel treeModel = myTreeTable.getTree().getModel();
TreeNode root = (TreeNode)treeModel.getRoot();
applyNode(root, settings);
}
public boolean isModified(CodeStyleSettings settings) {
TreeModel treeModel = myTreeTable.getTree().getModel();
TreeNode root = (TreeNode)treeModel.getRoot();
if (isModified(root, settings)) {
return true;
}
return false;
}
public JComponent getPanel() {
return myPanel;
}
protected void resetImpl(final CodeStyleSettings settings) {
TreeModel treeModel = myTreeTable.getTree().getModel();
TreeNode root = (TreeNode)treeModel.getRoot();
resetNode(root, settings);
}
}
@@ -47,7 +47,6 @@ public class StaticImportMethodFix implements IntentionAction {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.StaticImportMethodFix");
private final SmartPsiElementPointer<PsiMethodCallExpression> myMethodCall;
private List<PsiMethod> candidates;
private static final int OPTIONS = PsiFormatUtil.SHOW_NAME;
public StaticImportMethodFix(@NotNull PsiMethodCallExpression methodCallExpression) {
myMethodCall = SmartPointerManager.getInstance(methodCallExpression.getProject()).createSmartPsiElementPointer(methodCallExpression);
@@ -57,7 +56,7 @@ public class StaticImportMethodFix implements IntentionAction {
public String getText() {
String text = QuickFixBundle.message("static.import.method.text");
if (candidates.size() == 1) {
text += " '" + PsiFormatUtil.formatMethod(candidates.get(0), PsiSubstitutor.EMPTY, OPTIONS, 0)+"'";
text += " '" + PsiFormatUtil.formatMethod(candidates.get(0), PsiSubstitutor.EMPTY, PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_CONTAINING_CLASS | PsiFormatUtil.SHOW_FQ_NAME, 0)+"'";
}
else {
text += "...";
@@ -164,7 +163,7 @@ public class StaticImportMethodFix implements IntentionAction {
private void chooseAndImport(Editor editor) {
final JList list = new JList(new Vector<PsiMethod>(candidates));
list.setCellRenderer(new MethodCellRenderer(true, OPTIONS));
list.setCellRenderer(new MethodCellRenderer(true, PsiFormatUtil.SHOW_NAME));
new PopupChooserBuilder(list).
setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")).
setMovable(true).
@@ -15,18 +15,9 @@
*/
package com.intellij.application.options.codeStyle;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.OptionGroup;
import javax.swing.*;
@@ -49,8 +40,6 @@ public class CodeStyleBlankLinesPanel extends MultilanguageCodeStyleAbstractPane
private final JPanel myPanel = new JPanel(new GridBagLayout());
private static final LanguageFileType myFileType = StdFileTypes.JSP; //TODO: Replace hardcoded value
public CodeStyleBlankLinesPanel(CodeStyleSettings settings) {
super(settings);
@@ -216,4 +205,4 @@ public class CodeStyleBlankLinesPanel extends MultilanguageCodeStyleAbstractPane
protected void prepareForReformat(final PsiFile psiFile) {
//psiFile.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST);
}
}
}
@@ -164,7 +164,11 @@ public class CodeStyleMainPanel extends JPanel {
if (selectedPanel == null) {
return "reference.settingsdialog.IDE.globalcodestyle";
}
return selectedPanel.getHelpTopic();
String helpTopic = selectedPanel.getHelpTopic();
if (helpTopic != null) {
return helpTopic;
}
return "";
}
private NewCodeStyleSettingsPanel ensureCurrentPanel() {
@@ -16,8 +16,8 @@
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.editor.Editor;
//import com.intellij.openapi.editor.EditorSettings;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import javax.swing.*;
@@ -100,6 +100,7 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel {
initBooleanField("SPACE_AFTER_TYPE_CAST", ApplicationBundle.message("checkbox.spaces.after.type.cast"), OTHER);
}
/*
protected void setupEditorSettings(Editor editor) {
EditorSettings editorSettings = editor.getSettings();
editorSettings.setWhitespacesShown(true);
@@ -110,6 +111,7 @@ public class CodeStyleSpacesPanel extends OptionTreeWithPreviewPanel {
editorSettings.setAdditionalColumnsCount(0);
editorSettings.setAdditionalLinesCount(1);
}
*/
public JComponent getPanel() {
return getInternalPanel();
@@ -32,13 +32,12 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.LocalTimeCounter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.AncestorEvent;
@@ -72,7 +71,7 @@ public abstract class MultilanguageCodeStyleAbstractPanel extends CodeStyleAbstr
}
public void setLanguage(Language language) {
myLanguage = language;
setCurrLanguage(language);
updatePreviewEditor();
}
@@ -81,26 +80,32 @@ public abstract class MultilanguageCodeStyleAbstractPanel extends CodeStyleAbstr
@Override
protected String getPreviewText() {
if (myLanguage == null) return "";
return LanguageCodeStyleSettingsProvider.getCodeSample(myLanguage, getSettingsType());
String sample = LanguageCodeStyleSettingsProvider.getCodeSample(myLanguage, getSettingsType());
if (sample == null) return "";
return sample;
}
@NotNull
@Override
protected final FileType getFileType() {
if (myLanguage != null) {
return myLanguage.getAssociatedFileType();
FileType assocType = myLanguage.getAssociatedFileType();
if (assocType != null) {
return assocType;
}
}
Language langs[] = LanguageCodeStyleSettingsProvider.getLanguagesWithCodeStyleSettings();
Language[] langs = LanguageCodeStyleSettingsProvider.getLanguagesWithCodeStyleSettings();
if (langs.length > 0) {
myLanguage = langs[0];
setCurrLanguage(langs[0]);
FileType type = langs[0].getAssociatedFileType();
if (type != null) return type;
}
return StdFileTypes.JAVA;
}
@Nullable
protected EditorHighlighter createHighlighter(final EditorColorsScheme scheme) {
Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(this.getPanel()));
if (project == null) {
project = ProjectManager.getInstance().getDefaultProject();
}
@@ -132,7 +137,9 @@ public abstract class MultilanguageCodeStyleAbstractPanel extends CodeStyleAbstr
});
}
}, "", "");
manager.commitDocument(doc);
if (doc != null) {
manager.commitDocument(doc);
}
return psiFile;
}
@@ -205,9 +212,13 @@ public abstract class MultilanguageCodeStyleAbstractPanel extends CodeStyleAbstr
}
private JComponent createDummy() {
private static JComponent createDummy() {
return new JLabel("");
}
private static void setCurrLanguage(Language lang) {
myLanguage = lang;
}
}
@@ -210,7 +210,7 @@ public abstract class RemoteProcessSupport<Target, EntryPoint, Parameters> {
return RemoteUtil.castToLocal(remote, myValueClass);
}
}
}, myValueClass.getClassLoader());
}, getClass().getClassLoader()); // should be the loader of client plugin
}
private static <T> T narrowImpl(Remote remote, Class<T> to) {
@@ -24,15 +24,16 @@ import com.intellij.history.core.revisions.Revision;
import com.intellij.history.core.tree.Entry;
import com.intellij.history.utils.RunnableAdapter;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.*;
import com.intellij.util.SmartList;
import com.intellij.util.io.ReadOnlyAttributeUtil;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class FileListeningTest extends IntegrationTestCase {
@@ -75,10 +76,16 @@ public class FileListeningTest extends IntegrationTestCase {
List<Change> changes = getVcs().getChangeListInTests().getChangesInTests().get(0).getChanges();
assertEquals(4, changes.size());
assertEquals(dir1, ((StructuralChange)changes.get(0)).getPath());
assertEquals(dir2, ((StructuralChange)changes.get(1)).getPath());
assertEquals(f2, ((StructuralChange)changes.get(2)).getPath());
assertEquals(f1, ((StructuralChange)changes.get(3)).getPath());
List<String> actual = new SmartList<String>();
for (Change each : changes) {
actual.add(((StructuralChange)each).getPath());
}
List<String> expected = new ArrayList<String>(Arrays.asList(dir1, dir2, f1, f2));
Collections.sort(actual);
Collections.sort(expected);
assertOrderedEquals(actual, expected);
}
public void testChangingFileContent() throws Exception {
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.IconDeferrer;
import com.intellij.ui.RowIcon;
@@ -84,6 +85,22 @@ public class IconUtil {
}
}
private static Key<Boolean> PROJECT_WAS_EVER_INTIALIZED = Key.create("iconDeferrer:projectWasEverInitialized");
private static boolean wasEverInitialized(Project project) {
Boolean was = project.getUserData(PROJECT_WAS_EVER_INTIALIZED);
if (was == null) {
if (project.isInitialized()) {
was = Boolean.valueOf(true);
project.putUserData(PROJECT_WAS_EVER_INTIALIZED, was);
} else {
was = Boolean.valueOf(false);
}
}
return was.booleanValue();
}
public static Icon getIcon(final VirtualFile file, final int flags, final Project project) {
Icon lastIcon = Iconable.LastComputedIcon.get(file, flags);
@@ -93,7 +110,7 @@ public class IconUtil {
int flags = key.getFlags();
Project project = key.getProject();
if (!file.isValid() || project != null && project.isDisposed()) return null;
if (!file.isValid() || project != null && (project.isDisposed() || !wasEverInitialized(project))) return null;
Icon providersIcon = getProvidersIcon(file, flags, project);
Icon icon = providersIcon == null ? file.getIcon() : providersIcon;
@@ -56,7 +56,7 @@ public abstract class ParsingTestCase extends LightPlatformTestCase {
protected void doTest(boolean checkResult) throws Exception{
String name = getTestName(false);
String text = loadFile(name + "." + myFileExt);
myFile = createFile(name + "." + myFileExt, text);
myFile = createPsiFile(name, text);
myFile.accept(new PsiRecursiveElementVisitor(){});
assertEquals(text, myFile.getText());
if (checkResult){
@@ -67,6 +67,10 @@ public abstract class ParsingTestCase extends LightPlatformTestCase {
}
}
protected PsiFile createPsiFile(String name, String text) {
return createFile(name + "." + myFileExt, text);
}
protected void checkResult(@NonNls @TestDataFile String targetDataName, final PsiFile file) throws Exception {
doCheckResult(myFullDataPath, file, targetDataName, includeRanges());
}
@@ -941,7 +941,8 @@ public class MavenProjectsManager extends SimpleProjectComponent
VirtualFileManager.getInstance().refresh(isNormalProject());
schedulePostImportTasks(postTasks.get());
if (postTasks.get() != null /*may be null if importing is cancelled*/)
schedulePostImportTasks(postTasks.get());
// do not block user too often
myImportingQueue.restartTimer();
File diff suppressed because it is too large Load Diff
@@ -16,9 +16,11 @@
package com.intellij.psi.impl.source.xml;
import com.intellij.javaee.ExternalResourceManager;
import com.intellij.javaee.ExternalResourceManagerImpl;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.pom.PomManager;
import com.intellij.pom.PomModel;
import com.intellij.pom.event.PomModelEvent;
@@ -47,6 +49,7 @@ import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -57,6 +60,7 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.xml.XmlDocumentImpl");
private volatile XmlProlog myProlog;
private volatile XmlTag myRootTag;
private static final String HTML5_SCHEMA = "html5/xhtml5.xsd";
public XmlDocumentImpl() {
this(XmlElementType.XML_DOCUMENT);
@@ -248,10 +252,21 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument {
}
final String dtdUri = doctype.getDtdUri();
if (dtdUri != null && dtdUri.length() > 0){
final XmlFile xmlFile = XmlUtil.findNamespace(containingFile, dtdUri);
if (dtdUri == null || dtdUri.length() > 0) {
XmlFile xmlFile;
if (dtdUri == null) {
// it is HTML5
URL schemaLocation = getClass().getResource(ExternalResourceManagerImpl.STANDARD_SCHEMAS + HTML5_SCHEMA);
String path = FileUtil.toSystemIndependentName(schemaLocation.getPath().substring(1));
xmlFile = XmlUtil.findXmlFile(containingFile, path);
}
else {
xmlFile = XmlUtil.findNamespace(containingFile, dtdUri);
}
final XmlNSDescriptor descr1 = xmlFile == null ? null : (XmlNSDescriptor)xmlFile.getDocument().getMetaData();
if (descr != null && descr1 != null){
if (descr != null && descr1 != null) {
descr = new XmlNSDescriptorSequence(new XmlNSDescriptor[]{descr, descr1});
}
else if (descr1 != null) {