This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 186628
Collapse All | Expand All

(-)a/cnd.editor/nbproject/project.properties (-1 / +1 lines)
Lines 1-6 Link Here
1
javac.compilerargs=-Xlint -Xlint:-serial
1
javac.compilerargs=-Xlint -Xlint:-serial
2
javac.source=1.6
2
javac.source=1.6
3
spec.version.base=1.22.0
3
spec.version.base=1.23
4
4
5
test.config.stableBTD.includes=**/*Test.class
5
test.config.stableBTD.includes=**/*Test.class
6
test.config.stableBTD.excludes=\
6
test.config.stableBTD.excludes=\
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/api/CodeStyle.java (-33 / +23 lines)
Lines 58-66 Link Here
58
        EditorOptions.codeStyleFactory = new FactoryImpl();
58
        EditorOptions.codeStyleFactory = new FactoryImpl();
59
    }
59
    }
60
60
61
    private static CodeStyle INSTANCE_C;
62
    private static CodeStyle INSTANCE_H;
63
    private static CodeStyle INSTANCE_CPP;
64
    private Language language;
61
    private Language language;
65
    private Preferences preferences;
62
    private Preferences preferences;
66
    private final boolean useOverrideOptions;
63
    private final boolean useOverrideOptions;
Lines 71-98 Link Here
71
        this.useOverrideOptions = useOverrideOptions;
68
        this.useOverrideOptions = useOverrideOptions;
72
    }
69
    }
73
70
74
    public synchronized static CodeStyle getDefault(Language language) {
71
    public synchronized static CodeStyle getDefault(Language language, Document doc) {
75
        switch(language) {
72
        assert doc != null;
76
            case C:
73
        CodeStyle aCodeStyle = create(language, doc);
77
                if (INSTANCE_C == null) {
74
        setSimplePreferences(language, aCodeStyle);
78
                    INSTANCE_C = create(language);
75
        return aCodeStyle;
79
                    setSimplePreferences(language, INSTANCE_C);
76
    }
80
                }
77
81
                return INSTANCE_C;
78
    public synchronized static CodeStyle getDefault(Language language, Preferences pref) {
82
            case HEADER:
79
        CodeStyle aCodeStyle = create(language, pref);
83
                if (INSTANCE_H == null) {
80
        setSimplePreferences(language, aCodeStyle);
84
                    INSTANCE_H = create(language);
81
        return aCodeStyle;
85
                    setSimplePreferences(language, INSTANCE_H);
86
                }
87
                return INSTANCE_H;
88
            case CPP:
89
            default:
90
                if (INSTANCE_CPP == null) {
91
                    INSTANCE_CPP = create(language);
92
                    setSimplePreferences(language, INSTANCE_CPP);
93
                }
94
                return INSTANCE_CPP;
95
        }
96
    }
82
    }
97
    
83
    
98
    private static void setSimplePreferences(Language language, CodeStyle codeStyle){
84
    private static void setSimplePreferences(Language language, CodeStyle codeStyle){
Lines 110-127 Link Here
110
            //}
96
            //}
111
        } else {
97
        } else {
112
            if (mimeType.equals(MIMENames.C_MIME_TYPE)) {
98
            if (mimeType.equals(MIMENames.C_MIME_TYPE)) {
113
                return getDefault(Language.C);
99
                return getDefault(Language.C, doc);
114
            } else if (mimeType.equals(MIMENames.HEADER_MIME_TYPE)) {
100
            } else if (mimeType.equals(MIMENames.HEADER_MIME_TYPE)) {
115
                return getDefault(Language.HEADER);
101
                return getDefault(Language.HEADER, doc);
116
            }
102
            }
117
        }
103
        }
118
        return getDefault(Language.CPP);
104
        return getDefault(Language.CPP, doc);
119
    }
105
    }
120
106
121
    private static CodeStyle create(Language language) {
107
    private static CodeStyle create(Language language, Document doc) {
122
        return new CodeStyle(language, EditorOptions.getPreferences(language, EditorOptions.getCurrentProfileId(language)), true);
108
        return new CodeStyle(language, EditorOptions.getPreferences(language, EditorOptions.getCurrentProfileId(language, doc), doc), true);
123
    }
109
    }
124
110
111
    private static CodeStyle create(Language language, Preferences pref) {
112
        return new CodeStyle(language, pref, true);
113
    }
114
    
125
    // General indents ------------------------------------------------
115
    // General indents ------------------------------------------------
126
    
116
    
127
    private boolean isOverideTabIndents(){
117
    private boolean isOverideTabIndents(){
Lines 522-538 Link Here
522
//    }
512
//    }
523
513
524
    private boolean getOption(String key, boolean defaultValue) {
514
    private boolean getOption(String key, boolean defaultValue) {
525
        defaultValue = (Boolean)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language), key);
515
        defaultValue = (Boolean)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language, preferences), key);
526
        return getPreferences().getBoolean(key, defaultValue);
516
        return getPreferences().getBoolean(key, defaultValue);
527
    }
517
    }
528
518
529
    private int getOption(String key, int defaultValue) {
519
    private int getOption(String key, int defaultValue) {
530
        defaultValue = (Integer)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language), key);
520
        defaultValue = (Integer)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language, preferences), key);
531
        return getPreferences().getInt(key, defaultValue);
521
        return getPreferences().getInt(key, defaultValue);
532
    }
522
    }
533
523
534
    private String getOption(String key, String defaultValue) {
524
    private String getOption(String key, String defaultValue) {
535
        defaultValue = (String)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language), key);
525
        defaultValue = (String)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language, preferences), key);
536
        return getPreferences().get(key, defaultValue);
526
        return getPreferences().get(key, defaultValue);
537
    }
527
    }
538
528
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/layer.xml (-18 / +18 lines)
Lines 21-116 Link Here
21
                <folder name="text">
21
                <folder name="text">
22
                    <folder name="x-c">
22
                    <folder name="x-c">
23
                        <file name="All.instance">
23
                        <file name="All.instance">
24
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
24
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
25
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCController"/>
25
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCController"/>
26
                            <attr name="position" intvalue="100"/>
26
                            <attr name="position" intvalue="100"/>
27
                        </file>
27
                        </file>
28
                        <file name="TabsAndIndents.instance">
28
                        <file name="TabsAndIndents.instance">
29
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
29
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
30
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerTabs"/>
30
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerTabs"/>
31
                            <attr name="position" intvalue="200"/>
31
                            <attr name="position" intvalue="200"/>
32
                        </file>
32
                        </file>
33
                        <file name="Alignment.instance">
33
                        <file name="Alignment.instance">
34
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
34
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
35
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerAlignment"/>
35
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerAlignment"/>
36
                            <attr name="position" intvalue="300"/>
36
                            <attr name="position" intvalue="300"/>
37
                        </file>
37
                        </file>
38
                        <file name="Braces.instance">
38
                        <file name="Braces.instance">
39
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
39
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
40
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerBraces"/>
40
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerBraces"/>
41
                            <attr name="position" intvalue="400"/>
41
                            <attr name="position" intvalue="400"/>
42
                        </file>
42
                        </file>
43
                        <file name="BlankLines.instance">
43
                        <file name="BlankLines.instance">
44
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
44
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
45
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerBlank"/>
45
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerBlank"/>
46
                            <attr name="position" intvalue="500"/>
46
                            <attr name="position" intvalue="500"/>
47
                        </file>
47
                        </file>
48
                        <file name="Spaces.instance">
48
                        <file name="Spaces.instance">
49
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
49
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
50
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerSpaces"/>
50
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerSpaces"/>
51
                            <attr name="position" intvalue="600"/>
51
                            <attr name="position" intvalue="600"/>
52
                        </file>
52
                        </file>
53
                    </folder>
53
                    </folder>
54
                    <folder name="x-h">
54
                    <folder name="x-h">
55
                        <file name="All.instance">
55
                        <file name="All.instance">
56
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
56
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
57
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHController"/>
57
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHController"/>
58
                            <attr name="position" intvalue="100"/>
58
                            <attr name="position" intvalue="100"/>
59
                        </file>
59
                        </file>
60
                        <file name="TabsAndIndents.instance">
60
                        <file name="TabsAndIndents.instance">
61
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
61
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
62
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerTabs"/>
62
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerTabs"/>
63
                            <attr name="position" intvalue="200"/>
63
                            <attr name="position" intvalue="200"/>
64
                        </file>
64
                        </file>
65
                        <file name="Alignment.instance">
65
                        <file name="Alignment.instance">
66
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
66
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
67
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerAlignment"/>
67
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerAlignment"/>
68
                            <attr name="position" intvalue="300"/>
68
                            <attr name="position" intvalue="300"/>
69
                        </file>
69
                        </file>
70
                        <file name="Braces.instance">
70
                        <file name="Braces.instance">
71
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
71
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
72
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerBraces"/>
72
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerBraces"/>
73
                            <attr name="position" intvalue="400"/>
73
                            <attr name="position" intvalue="400"/>
74
                        </file>
74
                        </file>
75
                        <file name="BlankLines.instance">
75
                        <file name="BlankLines.instance">
76
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
76
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
77
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerBlank"/>
77
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerBlank"/>
78
                            <attr name="position" intvalue="500"/>
78
                            <attr name="position" intvalue="500"/>
79
                        </file>
79
                        </file>
80
                        <file name="Spaces.instance">
80
                        <file name="Spaces.instance">
81
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
81
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
82
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerSpaces"/>
82
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerSpaces"/>
83
                            <attr name="position" intvalue="600"/>
83
                            <attr name="position" intvalue="600"/>
84
                        </file>
84
                        </file>
85
                    </folder>
85
                    </folder>
86
                    <folder name="x-c++">
86
                    <folder name="x-c++">
87
                        <file name="All.instance">
87
                        <file name="All.instance">
88
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
88
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
89
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCController"/>
89
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCController"/>
90
                            <attr name="position" intvalue="100"/>
90
                            <attr name="position" intvalue="100"/>
91
                        </file>
91
                        </file>
92
                        <file name="TabsAndIndents.instance">
92
                        <file name="TabsAndIndents.instance">
93
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
93
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
94
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerTabs"/>
94
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerTabs"/>
95
                            <attr name="position" intvalue="200"/>
95
                            <attr name="position" intvalue="200"/>
96
                        </file>
96
                        </file>
97
                        <file name="Alignment.instance">
97
                        <file name="Alignment.instance">
98
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
98
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
99
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerAlignment"/>
99
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerAlignment"/>
100
                            <attr name="position" intvalue="300"/>
100
                            <attr name="position" intvalue="300"/>
101
                        </file>
101
                        </file>
102
                        <file name="Braces.instance">
102
                        <file name="Braces.instance">
103
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
103
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
104
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerBraces"/>
104
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerBraces"/>
105
                            <attr name="position" intvalue="400"/>
105
                            <attr name="position" intvalue="400"/>
106
                        </file>
106
                        </file>
107
                        <file name="BlankLines.instance">
107
                        <file name="BlankLines.instance">
108
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
108
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
109
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerBlank"/>
109
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerBlank"/>
110
                            <attr name="position" intvalue="500"/>
110
                            <attr name="position" intvalue="500"/>
111
                        </file>
111
                        </file>
112
                        <file name="Spaces.instance">
112
                        <file name="Spaces.instance">
113
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
113
                            <attr name="instanceOf" stringvalue="org.netbeans.modules.options.editor.spi.PreferencesCustomizer$Factory"/>
114
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerSpaces"/>
114
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerSpaces"/>
115
                            <attr name="position" intvalue="600"/>
115
                            <attr name="position" intvalue="600"/>
116
                        </file>
116
                        </file>
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorOptions.java (-28 / +223 lines)
Lines 52-66 Link Here
52
import java.util.prefs.PreferenceChangeEvent;
52
import java.util.prefs.PreferenceChangeEvent;
53
import java.util.prefs.PreferenceChangeListener;
53
import java.util.prefs.PreferenceChangeListener;
54
import java.util.prefs.Preferences;
54
import java.util.prefs.Preferences;
55
import javax.swing.text.Document;
55
import org.netbeans.api.editor.mimelookup.MimeLookup;
56
import org.netbeans.api.editor.mimelookup.MimeLookup;
56
import org.netbeans.api.editor.mimelookup.MimePath;
57
import org.netbeans.api.editor.mimelookup.MimePath;
57
import org.netbeans.api.editor.settings.SimpleValueNames;
58
import org.netbeans.api.editor.settings.SimpleValueNames;
58
import org.netbeans.modules.cnd.utils.MIMENames;
59
import org.netbeans.modules.cnd.utils.MIMENames;
59
import org.netbeans.modules.cnd.editor.api.CodeStyle;
60
import org.netbeans.modules.cnd.editor.api.CodeStyle;
60
import org.netbeans.modules.cnd.editor.api.CodeStyle.BracePlacement;
61
import org.netbeans.modules.cnd.editor.api.CodeStyle.BracePlacement;
62
import static org.netbeans.modules.cnd.editor.api.CodeStyle.Language.C;
63
import static org.netbeans.modules.cnd.editor.api.CodeStyle.Language.CPP;
64
import static org.netbeans.modules.cnd.editor.api.CodeStyle.Language.HEADER;
61
import org.netbeans.modules.cnd.editor.api.CodeStyle.PreprocessorIndent;
65
import org.netbeans.modules.cnd.editor.api.CodeStyle.PreprocessorIndent;
66
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
62
import org.openide.util.NbBundle;
67
import org.openide.util.NbBundle;
63
import org.openide.util.NbPreferences;
64
68
65
/**
69
/**
66
 *
70
 *
Lines 617-645 Link Here
617
        return defaults.get(id);
621
        return defaults.get(id);
618
    }
622
    }
619
    
623
    
620
    public static String getCurrentProfileId(CodeStyle.Language language) {
624
    public static String getCurrentProfileId(CodeStyle.Language language, Document doc) {
621
        switch(language){
625
        switch(language){
622
            case C:
626
            case C:
623
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("C_Style", DEFAULT_PROFILE); // NOI18N
627
                return CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().get("Profile_ID", DEFAULT_PROFILE); // NOI18N
628
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("C_Style", DEFAULT_PROFILE); // NOI18N
624
            case HEADER:
629
            case HEADER:
625
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("H_Style", DEFAULT_PROFILE); // NOI18N
630
                return CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().get("Profile_ID", DEFAULT_PROFILE); // NOI18N
631
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("H_Style", DEFAULT_PROFILE); // NOI18N
626
            case CPP:
632
            case CPP:
627
            default:
633
            default:
628
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("CPP_Style", DEFAULT_PROFILE); // NOI18N
634
                return CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().get("Profile_ID", DEFAULT_PROFILE); // NOI18N
635
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("CPP_Style", DEFAULT_PROFILE); // NOI18N
636
        }
637
    }
638
    
639
    public static String getCurrentProfileId(CodeStyle.Language language, Preferences pref) {
640
        switch(language){
641
            case C:
642
                if (pref == null) {
643
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
644
                }
645
                return pref.get("Profile_ID", DEFAULT_PROFILE); // NOI18N
646
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("C_Style", DEFAULT_PROFILE); // NOI18N
647
            case HEADER:
648
                if (pref == null) {
649
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
650
                }
651
                return pref.get("Profile_ID", DEFAULT_PROFILE); // NOI18N
652
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("H_Style", DEFAULT_PROFILE); // NOI18N
653
            case CPP:
654
            default:
655
                if (pref == null) {
656
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
657
                }
658
                return pref.get("Profile_ID", DEFAULT_PROFILE); // NOI18N
659
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("CPP_Style", DEFAULT_PROFILE); // NOI18N
629
        }
660
        }
630
    }
661
    }
631
662
632
    public static void setCurrentProfileId(CodeStyle.Language language, String style) {
663
    public static void setCurrentProfileId(CodeStyle.Language language, String style, Document doc) {
633
        switch(language){
664
        switch(language){
634
            case C:
665
            case C:
635
                NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("C_Style", style); // NOI18N
666
                CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().put("Profile_ID", style); // NOI18N
667
                //NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("C_Style", style); // NOI18N
636
                break;
668
                break;
637
            case HEADER:
669
            case HEADER:
638
                NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("H_Style", style); // NOI18N
670
                CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().put("Profile_ID", style); // NOI18N
671
                //NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("H_Style", style); // NOI18N
639
                break;
672
                break;
640
            case CPP:
673
            case CPP:
641
            default:
674
            default:
642
                NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("CPP_Style", style); // NOI18N
675
                CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().put("Profile_ID", style); // NOI18N
676
                //NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("CPP_Style", style); // NOI18N
677
                break;
678
        }
679
    }
680
681
    public static void setCurrentProfileId(CodeStyle.Language language, String style, Preferences pref) {
682
        switch(language){
683
            case C:
684
                if (pref == null) {
685
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
686
                }
687
                pref.put("Profile_ID", style); // NOI18N
688
                //NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("C_Style", style); // NOI18N
689
                break;
690
            case HEADER:
691
                if (pref == null) {
692
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
693
                }
694
                pref.put("Profile_ID", style); // NOI18N
695
                //NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("H_Style", style); // NOI18N
696
                break;
697
            case CPP:
698
            default:
699
                if (pref == null) {
700
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
701
                }
702
                pref.put("Profile_ID", style); // NOI18N
703
                //NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("CPP_Style", style); // NOI18N
643
                break;
704
                break;
644
        }
705
        }
645
    }
706
    }
Lines 648-654 Link Here
648
        return NbBundle.getMessage(EditorOptions.class, key);
709
        return NbBundle.getMessage(EditorOptions.class, key);
649
    }
710
    }
650
711
651
    public static String getStyleDisplayName(CodeStyle.Language language, String style) {
712
    public static String getStyleDisplayName(CodeStyle.Language language, String style, Document doc) {
652
        for (String name : EditorOptions.PREDEFINED_STYLES) {
713
        for (String name : EditorOptions.PREDEFINED_STYLES) {
653
            if (style.equals(name)) {
714
            if (style.equals(name)) {
654
                return getString(style + "_Name"); // NOI18N
715
                return getString(style + "_Name"); // NOI18N
Lines 656-683 Link Here
656
        }
717
        }
657
        switch(language){
718
        switch(language){
658
            case C:
719
            case C:
659
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
720
                return CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().get(style+"_Style_Name", style); // NOI18N
721
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
660
            case HEADER:
722
            case HEADER:
661
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
723
                return CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().get(style+"_Style_Name", style); // NOI18N
724
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
662
            case CPP:
725
            case CPP:
663
            default:
726
            default:
664
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
727
                return CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().get(style+"_Style_Name", style); // NOI18N
728
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
729
        }
730
    }
731
732
    public static String getStyleDisplayName(CodeStyle.Language language, String style, Preferences pref) {
733
        for (String name : EditorOptions.PREDEFINED_STYLES) {
734
            if (style.equals(name)) {
735
                return getString(style + "_Name"); // NOI18N
736
            }
737
        }
738
        switch(language){
739
            case C:
740
                if (pref == null) {
741
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
742
                }
743
                return pref.get(style+"_Style_Name", style); // NOI18N
744
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
745
            case HEADER:
746
                if (pref == null) {
747
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
748
                }
749
                return pref.get(style+"_Style_Name", style); // NOI18N
750
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
751
            case CPP:
752
            default:
753
                if (pref == null) {
754
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
755
                }
756
                return pref.get(style+"_Style_Name", style); // NOI18N
757
                //return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
665
        }
758
        }
666
    }
759
    }
667
    
760
    
668
    public static Preferences getPreferences(CodeStyle.Language language, String profileId) {
761
    public static Preferences getPreferences(CodeStyle.Language language, String profileId, Document doc) {
669
        switch(language){
762
        switch(language){
670
            case C:
763
            case C:
671
                return NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").node(profileId); // NOI18N
764
                return CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().node(profileId);
765
                //return NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").node(profileId); // NOI18N
672
            case HEADER:
766
            case HEADER:
673
                return NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").node(profileId); // NOI18N
767
                return CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().node(profileId);
768
                //return NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").node(profileId); // NOI18N
674
            case CPP:
769
            case CPP:
675
            default:
770
            default:
676
                return NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").node(profileId); // NOI18N
771
                return CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().node(profileId);
772
                //return NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").node(profileId); // NOI18N
677
        }
773
        }
678
    }
774
    }
679
775
680
    public static List<String> getAllStyles(CodeStyle.Language language) {
776
    public static Preferences getPreferences(CodeStyle.Language language, String profileId, Preferences pref) {
777
        switch(language){
778
            case C:
779
                if (pref == null) {
780
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
781
                }
782
                return pref.node(profileId);
783
                //return NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").node(profileId); // NOI18N
784
            case HEADER:
785
                if (pref == null) {
786
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
787
                }
788
                return pref.node(profileId);
789
                //return NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").node(profileId); // NOI18N
790
            case CPP:
791
            default:
792
                if (pref == null) {
793
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
794
                }
795
                return pref.node(profileId);
796
                //return NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").node(profileId); // NOI18N
797
        }
798
    }
799
800
801
    public static List<String> getAllStyles(CodeStyle.Language language, Document doc) {
681
        String styles = null;
802
        String styles = null;
682
        StringBuilder def = new StringBuilder();
803
        StringBuilder def = new StringBuilder();
683
        for(String s: PREDEFINED_STYLES){
804
        for(String s: PREDEFINED_STYLES){
Lines 688-701 Link Here
688
        }
809
        }
689
        switch(language){
810
        switch(language){
690
            case C:
811
            case C:
691
                styles = NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
812
                styles = CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().get("List_Of_Styles", def.toString()); // NOI18N
813
                //styles = NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
692
                break;
814
                break;
693
            case HEADER:
815
            case HEADER:
694
                styles = NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
816
                styles = CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().get("List_Of_Styles", def.toString()); // NOI18N
817
                //styles = NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
695
                break;
818
                break;
696
            case CPP:
819
            case CPP:
697
            default:
820
            default:
698
                styles = NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
821
                styles = CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().get("List_Of_Styles", def.toString()); // NOI18N
822
                //styles = NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
699
                break;
823
                break;
700
        }
824
        }
701
        List<String> res = new ArrayList<String>();
825
        List<String> res = new ArrayList<String>();
Lines 706-729 Link Here
706
        return res;
830
        return res;
707
    }
831
    }
708
832
709
    public static void setAllStyles(CodeStyle.Language language, String list) {
833
    public static List<String> getAllStyles(CodeStyle.Language language, Preferences pref) {
834
        String styles = null;
835
        StringBuilder def = new StringBuilder();
836
        for(String s: PREDEFINED_STYLES){
837
            if (def.length() > 0){
838
                def.append(',');
839
            }
840
            def.append(s);
841
        }
710
        switch(language){
842
        switch(language){
711
            case C:
843
            case C:
712
                NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").put("List_Of_Styles", list); // NOI18N
844
                if (pref == null) {
845
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
846
                }
847
                styles = pref.get("List_Of_Styles", def.toString()); // NOI18N
848
                //styles = NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
713
                break;
849
                break;
714
            case HEADER:
850
            case HEADER:
715
                NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").put("List_Of_Styles", list); // NOI18N
851
                if (pref == null) {
852
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
853
                }
854
                styles = pref.get("List_Of_Styles", def.toString()); // NOI18N
855
                //styles = NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
716
                break;
856
                break;
717
            case CPP:
857
            case CPP:
718
            default:
858
            default:
719
                NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").put("List_Of_Styles", list); // NOI18N
859
                if (pref == null) {
860
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
861
                }
862
                styles = pref.get("List_Of_Styles", def.toString()); // NOI18N
863
                //styles = NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
864
                break;
865
        }
866
        List<String> res = new ArrayList<String>();
867
        StringTokenizer st = new StringTokenizer(styles,","); // NOI18N
868
        while(st.hasMoreTokens()) {
869
            res.add(st.nextToken());
870
        }
871
        return res;
872
    }
873
874
    public static void setAllStyles(CodeStyle.Language language, String list, Document doc) {
875
        switch(language){
876
            case C:
877
                CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().put("List_Of_Styles", list); // NOI18N
878
                //NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").put("List_Of_Styles", list); // NOI18N
879
                break;
880
            case HEADER:
881
                CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().put("List_Of_Styles", list); // NOI18N
882
                //NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").put("List_Of_Styles", list); // NOI18N
883
                break;
884
            case CPP:
885
            default:
886
                CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().put("List_Of_Styles", list); // NOI18N
887
                //NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").put("List_Of_Styles", list); // NOI18N
720
                break;
888
                break;
721
        }
889
        }
722
    }
890
    }
723
891
724
    public static CodeStyle createCodeStyle(CodeStyle.Language language, Preferences p, boolean useOverrideOption) {
892
    public static void setAllStyles(CodeStyle.Language language, String list, Preferences pref) {
725
        CodeStyle.getDefault(language);
893
        switch(language){
726
        return codeStyleFactory.create(language, p, useOverrideOption);
894
            case C:
895
                if (pref == null) {
896
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
897
                }
898
                pref.put("List_Of_Styles", list); // NOI18N
899
                //NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").put("List_Of_Styles", list); // NOI18N
900
                break;
901
            case HEADER:
902
                if (pref == null) {
903
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
904
                }
905
                pref.put("List_Of_Styles", list); // NOI18N
906
                //NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").put("List_Of_Styles", list); // NOI18N
907
                break;
908
            case CPP:
909
            default:
910
                if (pref == null) {
911
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
912
                }
913
                pref.put("List_Of_Styles", list); // NOI18N
914
                //NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").put("List_Of_Styles", list); // NOI18N
915
                break;
916
        }
917
    }
918
919
    public static CodeStyle createCodeStyle(CodeStyle.Language language, Preferences pref, boolean useOverrideOption) {
920
        CodeStyle.getDefault(language, pref);
921
        return codeStyleFactory.create(language, pref, useOverrideOption);
727
    }
922
    }
728
923
729
    public static Preferences getPreferences(CodeStyle codeStyle){
924
    public static Preferences getPreferences(CodeStyle codeStyle){
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorOptionsPanelController.java (-104 / +143 lines)
Lines 39-134 Link Here
39
 * 
39
 * 
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
43
package org.netbeans.modules.cnd.editor.options;
42
package org.netbeans.modules.cnd.editor.options;
44
43
45
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyChangeSupport;
44
import java.beans.PropertyChangeSupport;
45
import java.util.prefs.Preferences;
47
import javax.swing.JComponent;
46
import javax.swing.JComponent;
48
import javax.swing.JEditorPane;
47
import javax.swing.JEditorPane;
49
import org.netbeans.modules.cnd.editor.api.CodeStyle;
48
import org.netbeans.modules.cnd.editor.api.CodeStyle;
49
import static org.netbeans.modules.cnd.editor.api.CodeStyle.Language.C;
50
import static org.netbeans.modules.cnd.editor.api.CodeStyle.Language.CPP;
51
import static org.netbeans.modules.cnd.editor.api.CodeStyle.Language.HEADER;
52
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.Alignment;
53
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.All;
54
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.BlankLines;
55
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.Braces;
56
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.Spaces;
57
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.TabsAndIndents;
50
import org.netbeans.modules.cnd.utils.MIMENames;
58
import org.netbeans.modules.cnd.utils.MIMENames;
59
import org.netbeans.modules.options.editor.spi.PreferencesCustomizer;
51
import org.netbeans.modules.options.editor.spi.PreviewProvider;
60
import org.netbeans.modules.options.editor.spi.PreviewProvider;
52
import org.netbeans.spi.options.OptionsPanelController;
61
import org.netbeans.spi.options.OptionsPanelController;
53
import org.openide.text.CloneableEditorSupport;
62
import org.openide.text.CloneableEditorSupport;
54
import org.openide.util.HelpCtx;
63
import org.openide.util.HelpCtx;
55
import org.openide.util.Lookup;
56
import org.openide.util.NbBundle;
64
import org.openide.util.NbBundle;
57
65
58
/**
66
/**
59
 *
67
 *
60
 * @author Alexander Simon
68
 * @author Alexander Simon
61
 */
69
 */
62
public class EditorOptionsPanelController extends OptionsPanelController implements PreviewProvider {
70
public class EditorOptionsPanelController implements PreferencesCustomizer.Factory {
63
71
64
    private JEditorPane previewPane;
65
    private final EditorPropertySheet panel;
66
    private final CodeStyle.Language language;
72
    private final CodeStyle.Language language;
67
    private static final boolean TRACE = false;
73
    private final PreviewPreferencesModel.Filter filter;
68
    private static final PreviewPreferencesModel preferencesModel = new PreviewPreferencesModel();
74
    private PreferencesCustomizerImpl customizer;
69
    
70
    private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
75
    private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
71
    private boolean changed;
76
    private boolean changed;
77
    private final static PreviewPreferencesModel prefModel = new PreviewPreferencesModel();
72
78
73
    
79
    public EditorOptionsPanelController(CodeStyle.Language language, PreviewPreferencesModel.Filter filter) {
74
    public EditorOptionsPanelController(CodeStyle.Language language, PreviewPreferencesModel.Filter filter){
75
        if (TRACE) {System.out.println("EditorOptionsPanelController.ctor()");} // NOI18N
76
        this.language = language;
80
        this.language = language;
77
        this.panel = new EditorPropertySheet(this, language, preferencesModel, filter);
81
        this.filter = filter;
78
    }
82
    }
79
83
80
    @Override
84
    @Override
81
    public void update() {
85
    public PreferencesCustomizer create(Preferences preferences) {
82
        if (TRACE) {System.out.println("EditorOptionsPanelController.update()");} // NOI18N
86
        if (customizer == null) {
83
        changed = false;
87
            customizer = new PreferencesCustomizerImpl(this, language, filter, preferences);
84
        panel.load();
88
        }
85
    }
89
        return customizer;
86
    
87
    @Override
88
    public void applyChanges() {
89
        if (TRACE) {System.out.println("EditorOptionsPanelController.applyChanges()");} // NOI18N
90
        panel.store();
91
    }
92
    
93
    @Override
94
    public void cancel() {
95
        if (TRACE) {System.out.println("EditorOptionsPanelController.cancel()");} // NOI18N
96
        panel.cancel();
97
    }
98
    
99
    @Override
100
    public boolean isValid() {
101
        if (TRACE) {System.out.println("EditorOptionsPanelController.isValid()");} // NOI18N
102
        return true;
103
    }
104
    
105
    @Override
106
    public boolean isChanged() {
107
        if (TRACE) {System.out.println("EditorOptionsPanelController.isChanged()");} // NOI18N
108
        return changed;
109
    }
90
    }
110
91
111
    @Override
92
    public JComponent getPreviewComponent() {
112
    public HelpCtx getHelpCtx() {
93
        return customizer.getPreviewComponent();
113
        return new HelpCtx("netbeans.optionsDialog.advanced.formEditor"); // NOI18N
114
    }
115
    
116
    @Override
117
    public JComponent getComponent(Lookup masterLookup) {
118
        if (TRACE) {System.out.println("EditorOptionsPanelController.getComponent()");} // NOI18N
119
        return panel;
120
    }
94
    }
121
95
122
    @Override
123
    public void addPropertyChangeListener(PropertyChangeListener l) {
124
        pcs.addPropertyChangeListener(l);
125
    }
126
    
127
    @Override
128
    public void removePropertyChangeListener(PropertyChangeListener l) {
129
        pcs.removePropertyChangeListener(l);
130
    }
131
        
132
    void changed() {
96
    void changed() {
133
        if (!changed) {
97
        if (!changed) {
134
            changed = true;
98
            changed = true;
Lines 137-226 Link Here
137
        pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
101
        pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
138
    }
102
    }
139
103
140
    @Override
104
    private static class PreferencesCustomizerImpl implements PreferencesCustomizer, PreviewProvider {
141
    public JComponent getPreviewComponent() {
105
142
        if (previewPane == null) {
106
        private final CodeStyle.Language language;
143
            previewPane = new JEditorPane();
107
        private final PreviewPreferencesModel.Filter filter;
144
            previewPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(EditorOptionsPanelController.class, "AN_Preview")); //NOI18N
108
        private final EditorOptionsPanelController top;
145
            previewPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EditorOptionsPanelController.class, "AD_Preview")); //NOI18N
109
        private final Preferences preferences;
146
            previewPane.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$"); //NOI18N
110
        private EditorPropertySheet panel;
147
            switch (language){
111
        private JEditorPane previewPane;
148
                case C:
112
149
                    previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.C_MIME_TYPE));
113
        public PreferencesCustomizerImpl(EditorOptionsPanelController top, CodeStyle.Language language, PreviewPreferencesModel.Filter filter, Preferences preferences) {
150
                    break;
114
            this.language = language;
151
                case HEADER:
115
            this.filter = filter;
152
                    previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.HEADER_MIME_TYPE));
116
            this.top = top;
153
                    break;
117
            this.preferences = preferences;
154
                case CPP:
118
        }
155
                default:
119
156
                    previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.CPLUSPLUS_MIME_TYPE));
120
        @Override
157
                    break;
121
        public String getId() {
122
            return filter.name();
123
//            switch (filter) {
124
//                case TabsAndIndents:
125
//                    return PreferencesCustomizer.TABS_AND_INDENTS_ID;
126
//                default:
127
//                    return filter.name();
128
//            }
129
        }
130
131
        @Override
132
        public String getDisplayName() {
133
            switch (filter) {
134
                case Alignment:
135
                    return EditorPropertySheet.getString("Filter_Alignment_name"); // NOI18N
136
                case All:
137
                    return EditorPropertySheet.getString("Filter_All_name"); // NOI18N
138
                case BlankLines:
139
                    return EditorPropertySheet.getString("Filter_BlankLines_name"); // NOI18N
140
                case Braces:
141
                    return EditorPropertySheet.getString("Filter_Braces_name"); // NOI18N
142
                case Spaces:
143
                    return EditorPropertySheet.getString("Filter_Spaces_name"); // NOI18N
144
                case TabsAndIndents:
145
                    return EditorPropertySheet.getString("Filter_TabsAndIndents_name"); // NOI18N
158
            }
146
            }
159
            previewPane.setEditable(false);
147
            return null;
160
        }
148
        }
161
        return previewPane;
149
150
        @Override
151
        public HelpCtx getHelpCtx() {
152
            return HelpCtx.DEFAULT_HELP;
153
        }
154
155
        @Override
156
        public JComponent getComponent() {
157
            if (panel == null) {
158
                prefModel.setPreferences(language, filter, preferences);
159
                panel = new EditorPropertySheet(top, language, EditorOptionsPanelController.prefModel, filter);
160
            }
161
            return panel;
162
        }
163
164
        @Override
165
        public JComponent getPreviewComponent() {
166
            if (previewPane == null) {
167
                previewPane = new JEditorPane();
168
                previewPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(EditorOptionsPanelController.class, "AN_Preview")); //NOI18N
169
                previewPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EditorOptionsPanelController.class, "AD_Preview")); //NOI18N
170
                previewPane.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$"); //NOI18N
171
                switch (language) {
172
                    case C:
173
                        previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.C_MIME_TYPE));
174
                        break;
175
                    case HEADER:
176
                        previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.HEADER_MIME_TYPE));
177
                        break;
178
                    case CPP:
179
                    default:
180
                        previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.CPLUSPLUS_MIME_TYPE));
181
                        break;
182
                }
183
                previewPane.setEditable(false);
184
            }
185
            return previewPane;
186
        }
187
188
        @Override
189
        public void refreshPreview() {
190
            panel.repaintPreview();
191
        }
162
    }
192
    }
163
193
164
    @Override
194
    public static PreferencesCustomizer.Factory getCController() {
165
    public void refreshPreview() {
195
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.All);
166
        panel.repaintPreview();
167
    }
196
    }
168
197
169
    public static OptionsPanelController getCController() {
198
    public static PreferencesCustomizer.Factory getCControllerTabs() {
170
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.All);
171
    }
172
    public static OptionsPanelController getCControllerTabs() {
173
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.TabsAndIndents);
199
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.TabsAndIndents);
174
    }
200
    }
175
    public static OptionsPanelController getCControllerAlignment() {
201
202
    public static PreferencesCustomizer.Factory getCControllerAlignment() {
176
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Alignment);
203
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Alignment);
177
    }
204
    }
178
    public static OptionsPanelController getCControllerBraces() {
205
206
    public static PreferencesCustomizer.Factory getCControllerBraces() {
179
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Braces);
207
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Braces);
180
    }
208
    }
181
    public static OptionsPanelController getCControllerBlank() {
209
210
    public static PreferencesCustomizer.Factory getCControllerBlank() {
182
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.BlankLines);
211
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.BlankLines);
183
    }
212
    }
184
    public static OptionsPanelController getCControllerSpaces() {
213
214
    public static PreferencesCustomizer.Factory getCControllerSpaces() {
185
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Spaces);
215
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Spaces);
186
    }
216
    }
187
217
188
    public static OptionsPanelController getCCController() {
218
    public static PreferencesCustomizer.Factory getCCController() {
189
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.All);
219
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.All);
190
    }
220
    }
191
    public static OptionsPanelController getCCControllerTabs() {
221
222
    public static PreferencesCustomizer.Factory getCCControllerTabs() {
192
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.TabsAndIndents);
223
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.TabsAndIndents);
193
    }
224
    }
194
    public static OptionsPanelController getCCControllerAlignment() {
225
226
    public static PreferencesCustomizer.Factory getCCControllerAlignment() {
195
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Alignment);
227
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Alignment);
196
    }
228
    }
197
    public static OptionsPanelController getCCControllerBraces() {
229
230
    public static PreferencesCustomizer.Factory getCCControllerBraces() {
198
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Braces);
231
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Braces);
199
    }
232
    }
200
    public static OptionsPanelController getCCControllerBlank() {
233
234
    public static PreferencesCustomizer.Factory getCCControllerBlank() {
201
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.BlankLines);
235
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.BlankLines);
202
    }
236
    }
203
    public static OptionsPanelController getCCControllerSpaces() {
237
238
    public static PreferencesCustomizer.Factory getCCControllerSpaces() {
204
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Spaces);
239
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Spaces);
205
    }
240
    }
206
241
207
    public static OptionsPanelController getHController() {
242
    public static PreferencesCustomizer.Factory getHController() {
208
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.All);
243
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.All);
209
    }
244
    }
210
    public static OptionsPanelController getHControllerTabs() {
245
246
    public static PreferencesCustomizer.Factory getHControllerTabs() {
211
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.TabsAndIndents);
247
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.TabsAndIndents);
212
    }
248
    }
213
    public static OptionsPanelController getHControllerAlignment() {
249
250
    public static PreferencesCustomizer.Factory getHControllerAlignment() {
214
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Alignment);
251
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Alignment);
215
    }
252
    }
216
    public static OptionsPanelController getHControllerBraces() {
253
254
    public static PreferencesCustomizer.Factory getHControllerBraces() {
217
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Braces);
255
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Braces);
218
    }
256
    }
219
    public static OptionsPanelController getHControllerBlank() {
257
258
    public static PreferencesCustomizer.Factory getHControllerBlank() {
220
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.BlankLines);
259
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.BlankLines);
221
    }
260
    }
222
    public static OptionsPanelController getHControllerSpaces() {
261
262
    public static PreferencesCustomizer.Factory getHControllerSpaces() {
223
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Spaces);
263
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Spaces);
224
    }
264
    }
225
226
}
265
}
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorPropertySheet.java (-8 / +8 lines)
Lines 157-163 Link Here
157
157
158
    private void initLanguageCategory(){
158
    private void initLanguageCategory(){
159
        styleComboBox.removeActionListener(this);
159
        styleComboBox.removeActionListener(this);
160
        final Map<String, PreviewPreferences> prefences = preferencesModel.getPrefences(language);
160
        final Map<String, PreviewPreferences> prefences = preferencesModel.getLanguagePreferences(language);
161
        if (prefences == null) {
161
        if (prefences == null) {
162
            return;
162
            return;
163
        }
163
        }
Lines 396-402 Link Here
396
        if (filter != Filter.All) {
396
        if (filter != Filter.All) {
397
            return;
397
            return;
398
        }
398
        }
399
        EditorOptions.setCurrentProfileId(language, preferencesModel.getLanguageDefaultStyle(language));
399
        EditorOptions.setCurrentProfileId(language, preferencesModel.getLanguageDefaultStyle(language), (Preferences)null);
400
        StringBuilder buf = new StringBuilder();
400
        StringBuilder buf = new StringBuilder();
401
        for(Map.Entry<String, PreviewPreferences> prefEntry : preferencesModel.getLanguagePreferences(language).entrySet()){
401
        for(Map.Entry<String, PreviewPreferences> prefEntry : preferencesModel.getLanguagePreferences(language).entrySet()){
402
            String style = prefEntry.getKey();
402
            String style = prefEntry.getKey();
Lines 405-413 Link Here
405
            }
405
            }
406
            buf.append(style);
406
            buf.append(style);
407
            PreviewPreferences pref = prefEntry.getValue();
407
            PreviewPreferences pref = prefEntry.getValue();
408
            Preferences toSave = EditorOptions.getPreferences(language, style);
408
            Preferences toSave = EditorOptions.getPreferences(language, style, (Preferences)null);
409
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
409
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
410
                EditorOptions.setPreferences(CodeStyle.getDefault(language), toSave);
410
                EditorOptions.setPreferences(CodeStyle.getDefault(language, toSave), toSave);
411
            }
411
            }
412
            for(String key : EditorOptions.keys()){
412
            for(String key : EditorOptions.keys()){
413
                Object o = EditorOptions.getDefault(language, style, key);
413
                Object o = EditorOptions.getDefault(language, style, key);
Lines 435-444 Link Here
435
                }
435
                }
436
            }
436
            }
437
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
437
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
438
                EditorOptions.updateSimplePreferences(language, CodeStyle.getDefault(language));
438
                EditorOptions.updateSimplePreferences(language, CodeStyle.getDefault(language, toSave));
439
            }
439
            }
440
        }
440
        }
441
        EditorOptions.setAllStyles(language, buf.toString());
441
        EditorOptions.setAllStyles(language, buf.toString(), (Preferences)null);
442
        preferencesModel.clear(language);
442
        preferencesModel.clear(language);
443
        holder.setNodes(null);
443
        holder.setNodes(null);
444
    }
444
    }
Lines 602-608 Link Here
602
        });
602
        });
603
    }
603
    }
604
604
605
    private static String getString(String key) {
605
    static String getString(String key) {
606
        return NbBundle.getMessage(EditorPropertySheet.class, key);
606
        return NbBundle.getMessage(EditorPropertySheet.class, key);
607
    }
607
    }
608
608
Lines 709-715 Link Here
709
        private EntryWrapper(Map.Entry<String, PreviewPreferences> enrty){
709
        private EntryWrapper(Map.Entry<String, PreviewPreferences> enrty){
710
            this.name = enrty.getKey();
710
            this.name = enrty.getKey();
711
            this.preferences = enrty.getValue();
711
            this.preferences = enrty.getValue();
712
            displayName = EditorOptions.getStyleDisplayName(preferences.getLanguage(),name);
712
            displayName = EditorOptions.getStyleDisplayName(preferences.getLanguage(),name, preferences);
713
        }
713
        }
714
714
715
        @Override
715
        @Override
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/ManageStylesPanel.java (-2 / +3 lines)
Lines 51-56 Link Here
51
import java.util.List;
51
import java.util.List;
52
import java.util.Map;
52
import java.util.Map;
53
import java.util.prefs.BackingStoreException;
53
import java.util.prefs.BackingStoreException;
54
import java.util.prefs.Preferences;
54
import javax.swing.AbstractListModel;
55
import javax.swing.AbstractListModel;
55
import javax.swing.ListSelectionModel;
56
import javax.swing.ListSelectionModel;
56
import javax.swing.event.ListSelectionEvent;
57
import javax.swing.event.ListSelectionEvent;
Lines 96-102 Link Here
96
    private void initListModel(){
97
    private void initListModel(){
97
        List<MyListItem> objects = new ArrayList<MyListItem>();
98
        List<MyListItem> objects = new ArrayList<MyListItem>();
98
        for(String style : preferences.keySet()){
99
        for(String style : preferences.keySet()){
99
            objects.add(new MyListItem(style, EditorOptions.getStyleDisplayName(language,style)));
100
            objects.add(new MyListItem(style, EditorOptions.getStyleDisplayName(language,style, (Preferences)null)));
100
        }
101
        }
101
        Collections.sort(objects);
102
        Collections.sort(objects);
102
        stylesList.setModel(new MyListModel(objects));
103
        stylesList.setModel(new MyListModel(objects));
Lines 268-274 Link Here
268
269
269
    private boolean checkUniqueStyleName(String styleName) {
270
    private boolean checkUniqueStyleName(String styleName) {
270
        for (String key : preferences.keySet()) {
271
        for (String key : preferences.keySet()) {
271
            String name = EditorOptions.getStyleDisplayName(language, key);
272
            String name = EditorOptions.getStyleDisplayName(language, key, (Preferences)null);
272
            if (name.equals(styleName)) {
273
            if (name.equals(styleName)) {
273
                NotifyDescriptor descriptor = new NotifyDescriptor.Message(
274
                NotifyDescriptor descriptor = new NotifyDescriptor.Message(
274
                        NbBundle.getMessage(ManageStylesPanel.class, "Duplicate_Style_Warning", styleName), // NOI18N
275
                        NbBundle.getMessage(ManageStylesPanel.class, "Duplicate_Style_Warning", styleName), // NOI18N
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/PreviewPreferencesModel.java (-20 / +24 lines)
Lines 41-49 Link Here
41
 */
41
 */
42
package org.netbeans.modules.cnd.editor.options;
42
package org.netbeans.modules.cnd.editor.options;
43
43
44
import java.util.EnumMap;
44
import java.util.HashMap;
45
import java.util.HashMap;
45
import java.util.Map;
46
import java.util.Map;
46
import java.util.concurrent.ConcurrentHashMap;
47
import java.util.prefs.Preferences;
47
import org.netbeans.modules.cnd.editor.api.CodeStyle;
48
import org.netbeans.modules.cnd.editor.api.CodeStyle;
48
49
49
/**
50
/**
Lines 61-89 Link Here
61
        All
62
        All
62
    }
63
    }
63
64
64
    private Map<CodeStyle.Language, Map<String, PreviewPreferences>> preferences = new ConcurrentHashMap<CodeStyle.Language, Map<String, PreviewPreferences>>();
65
    private Map<CodeStyle.Language, Preferences> master = new EnumMap<CodeStyle.Language, Preferences>(CodeStyle.Language.class);
65
    private Map<CodeStyle.Language, String> defaultStyles = new ConcurrentHashMap<CodeStyle.Language, String>();
66
    private Map<CodeStyle.Language, Map<String, PreviewPreferences>> styles = new EnumMap<CodeStyle.Language, Map<String, PreviewPreferences>>(CodeStyle.Language.class);
67
    private Map<CodeStyle.Language, String> defaultStyles = new EnumMap<CodeStyle.Language, String>(CodeStyle.Language.class);
66
68
67
    public PreviewPreferencesModel() {
69
    public PreviewPreferencesModel() {
68
    }
70
    }
69
71
    
70
    public Map<String, PreviewPreferences> getPrefences(CodeStyle.Language language) {
72
    public void setPreferences(CodeStyle.Language language, PreviewPreferencesModel.Filter filter, Preferences preferences) {
71
        return preferences.get(language);
73
        master.put(language, preferences);
74
        initLanguageMap(language);
72
    }
75
    }
73
76
74
    public synchronized void initLanguageMap(CodeStyle.Language language) {
77
    public synchronized void initLanguageMap(CodeStyle.Language language) {
75
        for (String style : EditorOptions.getAllStyles(language)) {
78
        Preferences pref = master.get(language);
76
            initLanguageStylePreferences(language, style);
79
        for (String style : EditorOptions.getAllStyles(language, pref)) {
80
            initLanguageStylePreferences(language, style, pref);
77
        }
81
        }
78
        String def = defaultStyles.get(language);
82
        String def = defaultStyles.get(language);
79
        if (def == null) {
83
        if (def == null) {
80
            def = EditorOptions.getCurrentProfileId(language);
84
            def = EditorOptions.getCurrentProfileId(language, pref);
81
            defaultStyles.put(language, def);
85
            defaultStyles.put(language, def);
82
        }
86
        }
83
    }
87
    }
84
88
85
    public Map<String, PreviewPreferences> getLanguagePreferences(CodeStyle.Language language) {
89
    public Map<String, PreviewPreferences> getLanguagePreferences(CodeStyle.Language language) {
86
        return preferences.get(language);
90
        return styles.get(language);
87
    }
91
    }
88
92
89
    public String getLanguageDefaultStyle(CodeStyle.Language language) {
93
    public String getLanguageDefaultStyle(CodeStyle.Language language) {
Lines 94-109 Link Here
94
        defaultStyles.put(language, def);
98
        defaultStyles.put(language, def);
95
    }
99
    }
96
100
97
    private void initLanguageStylePreferences(CodeStyle.Language language, String styleId) {
101
    private void initLanguageStylePreferences(CodeStyle.Language language, String styleId, Preferences pref) {
98
        Map<String, PreviewPreferences> prefs = preferences.get(language);
102
        Map<String, PreviewPreferences> style = styles.get(language);
99
        if (prefs == null) {
103
        if (style == null) {
100
            prefs = new HashMap<String, PreviewPreferences>();
104
            style = new HashMap<String, PreviewPreferences>();
101
            preferences.put(language, prefs);
105
            styles.put(language, style);
102
        }
106
        }
103
        PreviewPreferences clone = prefs.get(styleId);
107
        PreviewPreferences clone = style.get(styleId);
104
        if (clone == null) {
108
        if (clone == null) {
105
            clone = new PreviewPreferences(EditorOptions.getPreferences(language, styleId), language, styleId);
109
            clone = new PreviewPreferences(EditorOptions.getPreferences(language, styleId, pref), language, styleId);
106
            prefs.put(styleId, clone);
110
            style.put(styleId, clone);
107
        }
111
        }
108
    }
112
    }
109
113
Lines 118-128 Link Here
118
    }
122
    }
119
123
120
    public void resetPreferences(CodeStyle.Language language, Map<String, PreviewPreferences> newPreferences) {
124
    public void resetPreferences(CodeStyle.Language language, Map<String, PreviewPreferences> newPreferences) {
121
        preferences.put(language, newPreferences);
125
        styles.put(language, newPreferences);
122
    }
126
    }
123
127
124
    public void clear(CodeStyle.Language language) {
128
    public void clear(CodeStyle.Language language) {
125
        preferences.remove(language);
129
        styles.remove(language);
126
        defaultStyles.remove(language);
130
        defaultStyles.remove(language);
127
    }
131
    }
128
}
132
}
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/BracketCompletionTestCase.java (-1 / +1 lines)
Lines 808-814 Link Here
808
    
808
    
809
    public void testIZ102091() throws Exception {
809
    public void testIZ102091() throws Exception {
810
        setDefaultsOptions();
810
        setDefaultsOptions();
811
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
811
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
812
                put(EditorOptions.newLineBeforeBrace, 
812
                put(EditorOptions.newLineBeforeBrace, 
813
                CodeStyle.BracePlacement.NEW_LINE.name());
813
                CodeStyle.BracePlacement.NEW_LINE.name());
814
        typeCharactersInText (
814
        typeCharactersInText (
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/EditorBase.java (-12 / +12 lines)
Lines 117-152 Link Here
117
    protected final void setDefaultsOptions(){
117
    protected final void setDefaultsOptions(){
118
        // Note due to IZ#130533 the default style is changed. Hence we reset some properties.
118
        // Note due to IZ#130533 the default style is changed. Hence we reset some properties.
119
        if (isCPP) {
119
        if (isCPP) {
120
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.CPP));
120
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument()));
121
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
121
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
122
                put(EditorOptions.newLineBeforeBraceNamespace, 
122
                put(EditorOptions.newLineBeforeBraceNamespace, 
123
                CodeStyle.BracePlacement.NEW_LINE.name());
123
                CodeStyle.BracePlacement.NEW_LINE.name());
124
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
124
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
125
                put(EditorOptions.newLineBeforeBraceClass, 
125
                put(EditorOptions.newLineBeforeBraceClass, 
126
                CodeStyle.BracePlacement.NEW_LINE.name());
126
                CodeStyle.BracePlacement.NEW_LINE.name());
127
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
127
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
128
                put(EditorOptions.newLineBeforeBraceDeclaration, 
128
                put(EditorOptions.newLineBeforeBraceDeclaration, 
129
                CodeStyle.BracePlacement.NEW_LINE.name());
129
                CodeStyle.BracePlacement.NEW_LINE.name());
130
        } else {
130
        } else {
131
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.C));
131
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.C, getDocument()));
132
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
132
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
133
                put(EditorOptions.newLineBeforeBraceNamespace, 
133
                put(EditorOptions.newLineBeforeBraceNamespace, 
134
                CodeStyle.BracePlacement.NEW_LINE.name());
134
                CodeStyle.BracePlacement.NEW_LINE.name());
135
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
135
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
136
                put(EditorOptions.newLineBeforeBraceClass, 
136
                put(EditorOptions.newLineBeforeBraceClass, 
137
                CodeStyle.BracePlacement.NEW_LINE.name());
137
                CodeStyle.BracePlacement.NEW_LINE.name());
138
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
138
            EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
139
                put(EditorOptions.newLineBeforeBraceDeclaration, 
139
                put(EditorOptions.newLineBeforeBraceDeclaration, 
140
                CodeStyle.BracePlacement.NEW_LINE.name());
140
                CodeStyle.BracePlacement.NEW_LINE.name());
141
        }
141
        }
142
    }
142
    }
143
    protected final void setDefaultsOptions(String style){
143
    protected final void setDefaultsOptions(String style){
144
        if (isCPP) {
144
        if (isCPP) {
145
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.CPP));
145
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument()));
146
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.CPP), style);
146
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument()), style);
147
        } else {
147
        } else {
148
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.C));
148
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.C, getDocument()));
149
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.C), style);
149
            EditorOptions.resetToDefault(CodeStyle.getDefault(CodeStyle.Language.C, getDocument()), style);
150
        }
150
        }
151
    }
151
    }
152
152
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/FormatterTestCase.java (-610 / +606 lines)
Lines 57-63 Link Here
57
    // -------- Reformat tests -----------
57
    // -------- Reformat tests -----------
58
    
58
    
59
    public void testReformatMultiLineSystemOutPrintln() {
59
    public void testReformatMultiLineSystemOutPrintln() {
60
        setDefaultsOptions();
61
        setLoadDocumentText(
60
        setLoadDocumentText(
62
                "void m() {\n"
61
                "void m() {\n"
63
                + "    printf(\n"
62
                + "    printf(\n"
Lines 75-90 Link Here
75
    }
74
    }
76
75
77
    public void testReformatMultiLineSystemOutPrintln2() {
76
    public void testReformatMultiLineSystemOutPrintln2() {
78
        setDefaultsOptions();
79
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
80
                put(EditorOptions.newLineBeforeBraceDeclaration, 
81
                CodeStyle.BracePlacement.SAME_LINE.name());
82
        setLoadDocumentText(
77
        setLoadDocumentText(
83
                "void m() {\n"
78
                "void m() {\n"
84
                + "    printf(\n"
79
                + "    printf(\n"
85
                + "    \"haf\");\n"
80
                + "    \"haf\");\n"
86
                + "}\n"
81
                + "}\n"
87
                );
82
                );
83
        setDefaultsOptions();
84
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
85
                put(EditorOptions.newLineBeforeBraceDeclaration, 
86
                CodeStyle.BracePlacement.SAME_LINE.name());
88
        reformat();
87
        reformat();
89
        assertDocumentText("Incorrect new-line indent",
88
        assertDocumentText("Incorrect new-line indent",
90
                "void m() {\n"
89
                "void m() {\n"
Lines 95-112 Link Here
95
    }
94
    }
96
    
95
    
97
    public void testReformatMultiLineSystemOutPrintln3() {
96
    public void testReformatMultiLineSystemOutPrintln3() {
98
        setDefaultsOptions();
99
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
100
                put(EditorOptions.newLineBeforeBraceDeclaration, 
101
                CodeStyle.BracePlacement.SAME_LINE.name());
102
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
103
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
104
        setLoadDocumentText(
97
        setLoadDocumentText(
105
                "void m() {\n"
98
                "void m() {\n"
106
                + "    printf(\n"
99
                + "    printf(\n"
107
                + "    \"haf\");\n"
100
                + "    \"haf\");\n"
108
                + "}\n"
101
                + "}\n"
109
                );
102
                );
103
        setDefaultsOptions();
104
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
105
                put(EditorOptions.newLineBeforeBraceDeclaration, 
106
                CodeStyle.BracePlacement.SAME_LINE.name());
107
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
108
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
110
        reformat();
109
        reformat();
111
        assertDocumentText("Incorrect new-line indent",
110
        assertDocumentText("Incorrect new-line indent",
112
                "void m() {\n"
111
                "void m() {\n"
Lines 117-131 Link Here
117
    }
116
    }
118
117
119
    public void testReformatMultiLineClassDeclaration() {
118
    public void testReformatMultiLineClassDeclaration() {
120
        setDefaultsOptions();
121
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
122
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
123
        setLoadDocumentText(
119
        setLoadDocumentText(
124
                "class C\n"
120
                "class C\n"
125
                + ": public Runnable {\n"
121
                + ": public Runnable {\n"
126
                + "int printf(int);\n"
122
                + "int printf(int);\n"
127
                + "};\n"
123
                + "};\n"
128
                );
124
                );
125
        setDefaultsOptions();
126
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
127
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
129
        reformat();
128
        reformat();
130
        assertDocumentText("Incorrect new-line indent",
129
        assertDocumentText("Incorrect new-line indent",
131
                "class C\n"
130
                "class C\n"
Lines 143-152 Link Here
143
     * @see http://www.netbeans.org/issues/show_bug.cgi?id6065
142
     * @see http://www.netbeans.org/issues/show_bug.cgi?id6065
144
     */
143
     */
145
    public void testReformatNewOnTwoLines() {
144
    public void testReformatNewOnTwoLines() {
146
        setDefaultsOptions();
147
        setLoadDocumentText(
145
        setLoadDocumentText(
148
                "javax::swing::JPanel* panel =\n" +
146
                "javax::swing::JPanel* panel =\n" +
149
                "new java::swing::JPanel();");
147
                "new java::swing::JPanel();");
148
        setDefaultsOptions();
150
        reformat();
149
        reformat();
151
        assertDocumentText("Incorrect new on two lines reformating",
150
        assertDocumentText("Incorrect new on two lines reformating",
152
                "javax::swing::JPanel* panel =\n" +
151
                "javax::swing::JPanel* panel =\n" +
Lines 158-164 Link Here
158
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=23508
157
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=23508
159
     */
158
     */
160
    public void testReformatTernaryConditionalOperator() {
159
    public void testReformatTernaryConditionalOperator() {
161
        setDefaultsOptions();
162
        setLoadDocumentText(
160
        setLoadDocumentText(
163
                "void foo()\n"+
161
                "void foo()\n"+
164
                "{\n"+
162
                "{\n"+
Lines 166-171 Link Here
166
                "(aComplexCalculation) :\n" +
164
                "(aComplexCalculation) :\n" +
167
                "(anotherComplexCalculation);\n"+
165
                "(anotherComplexCalculation);\n"+
168
                "}\n");
166
                "}\n");
167
        setDefaultsOptions();
169
        reformat();
168
        reformat();
170
        assertDocumentText("Incorrect ternary conditional operator reformatting",
169
        assertDocumentText("Incorrect ternary conditional operator reformatting",
171
                "void foo()\n"+
170
                "void foo()\n"+
Lines 181-187 Link Here
181
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=47069
180
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=47069
182
     */
181
     */
183
    public void testReformatArrayInitializerWithNewline() {
182
    public void testReformatArrayInitializerWithNewline() {
184
        setDefaultsOptions();
185
        setLoadDocumentText(
183
        setLoadDocumentText(
186
                "int[] foo =  {1, 2, 3};\n" +
184
                "int[] foo =  {1, 2, 3};\n" +
187
                "int[] foo2 =  {1,\n" +
185
                "int[] foo2 =  {1,\n" +
Lines 190-195 Link Here
190
                "1, 2, 3\n" +
188
                "1, 2, 3\n" +
191
                "};\n" +
189
                "};\n" +
192
                "\n");
190
                "\n");
191
        setDefaultsOptions();
193
        reformat();
192
        reformat();
194
        assertDocumentText("Incorrect array initializer with newline reformatting",
193
        assertDocumentText("Incorrect array initializer with newline reformatting",
195
                "int[] foo = {1, 2, 3};\n" +
194
                "int[] foo = {1, 2, 3};\n" +
Lines 206-212 Link Here
206
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=47069
205
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=47069
207
     */
206
     */
208
    public void testReformatArrayInitializerWithNewline2() {
207
    public void testReformatArrayInitializerWithNewline2() {
209
        setDefaultsOptions();
210
        setLoadDocumentText(
208
        setLoadDocumentText(
211
                "int[][] foo4 =  {\n" +
209
                "int[][] foo4 =  {\n" +
212
                "{1, 2, 3},\n" +
210
                "{1, 2, 3},\n" +
Lines 214-219 Link Here
214
                "{7,8,9}\n" +
212
                "{7,8,9}\n" +
215
                "};\n" +
213
                "};\n" +
216
                "\n");
214
                "\n");
215
        setDefaultsOptions();
217
        reformat();
216
        reformat();
218
        assertDocumentText("Incorrect array initializer with newline reformatting",
217
        assertDocumentText("Incorrect array initializer with newline reformatting",
219
                "int[][] foo4 = {\n" +
218
                "int[][] foo4 = {\n" +
Lines 229-237 Link Here
229
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=48926
228
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=48926
230
     */
229
     */
231
    public void testReformatNewlineBracesToNormalOnes() {
230
    public void testReformatNewlineBracesToNormalOnes() {
232
        setDefaultsOptions();
233
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
234
                putBoolean(EditorOptions.newLineCatch, true);
235
        setLoadDocumentText(
231
        setLoadDocumentText(
236
                "try\n" +
232
                "try\n" +
237
                "{\n" +
233
                "{\n" +
Lines 241-246 Link Here
241
                "{\n" +
237
                "{\n" +
242
                "printf(\"exception\");\n" +
238
                "printf(\"exception\");\n" +
243
                "}");
239
                "}");
240
        setDefaultsOptions();
241
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
242
                putBoolean(EditorOptions.newLineCatch, true);
244
        reformat();
243
        reformat();
245
        assertDocumentText("Incorrect try-catch reformatting",
244
        assertDocumentText("Incorrect try-catch reformatting",
246
                "try {\n" +
245
                "try {\n" +
Lines 252-260 Link Here
252
    }
251
    }
253
252
254
    public void testReformatNewlineBracesToNormalOnes1() {
253
    public void testReformatNewlineBracesToNormalOnes1() {
255
        setDefaultsOptions();
256
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
257
                putBoolean(EditorOptions.newLineCatch, true);
258
        setLoadDocumentText(
254
        setLoadDocumentText(
259
                "try\n" +
255
                "try\n" +
260
                "{\n" +
256
                "{\n" +
Lines 264-269 Link Here
264
                "{\n" +
260
                "{\n" +
265
                "printf(\"exception\");\n" +
261
                "printf(\"exception\");\n" +
266
                "}");
262
                "}");
263
        setDefaultsOptions();
264
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
265
                putBoolean(EditorOptions.newLineCatch, true);
267
        reformat();
266
        reformat();
268
        assertDocumentText("Incorrect try-catch reformatting",
267
        assertDocumentText("Incorrect try-catch reformatting",
269
                "try {\n" +
268
                "try {\n" +
Lines 275-281 Link Here
275
    }
274
    }
276
    
275
    
277
    public void testReformatNewlineBracesToNormalOnes2() {
276
    public void testReformatNewlineBracesToNormalOnes2() {
278
        setDefaultsOptions();
279
        setLoadDocumentText(
277
        setLoadDocumentText(
280
                "	void testError(CuTest *tc){\n" +
278
                "	void testError(CuTest *tc){\n" +
281
                "		IndexReader* reader = NULL;\n" +
279
                "		IndexReader* reader = NULL;\n" +
Lines 288-293 Link Here
288
                "		}\n" +
286
                "		}\n" +
289
                "	}\n" +
287
                "	}\n" +
290
                "\n");
288
                "\n");
289
        setDefaultsOptions();
291
        reformat();
290
        reformat();
292
        assertDocumentText("Incorrect try-catch reformatting",
291
        assertDocumentText("Incorrect try-catch reformatting",
293
                "void testError(CuTest *tc)\n" +
292
                "void testError(CuTest *tc)\n" +
Lines 305-312 Link Here
305
    }
304
    }
306
305
307
    public void testReformatNewlineBracesToNormalOnes3() {
306
    public void testReformatNewlineBracesToNormalOnes3() {
308
        setDefaultsOptions();
309
            setDefaultsOptions();
310
        setLoadDocumentText(
307
        setLoadDocumentText(
311
                "try {\n" +
308
                "try {\n" +
312
                "    printf(\"test\");\n" +
309
                "    printf(\"test\");\n" +
Lines 314-319 Link Here
314
                "catch ( IllegalStateException illegalStateException  ) {\n" +
311
                "catch ( IllegalStateException illegalStateException  ) {\n" +
315
                "    illegalStateException.printStackTrace();\n" +
312
                "    illegalStateException.printStackTrace();\n" +
316
                "}\n");
313
                "}\n");
314
        setDefaultsOptions();
317
        reformat();
315
        reformat();
318
        assertDocumentText("Incorrect tabbed catch reformatting",
316
        assertDocumentText("Incorrect tabbed catch reformatting",
319
                "try {\n" +
317
                "try {\n" +
Lines 329-343 Link Here
329
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
327
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
330
     */
328
     */
331
    public void testReformatMultilineConstructor() {
329
    public void testReformatMultilineConstructor() {
332
        setDefaultsOptions();
333
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
334
                put(EditorOptions.newLineBeforeBraceClass, 
335
                CodeStyle.BracePlacement.SAME_LINE.name());
336
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
337
                put(EditorOptions.newLineBeforeBraceDeclaration, 
338
                CodeStyle.BracePlacement.SAME_LINE.name());
339
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
340
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
341
        setLoadDocumentText(
330
        setLoadDocumentText(
342
                "class Test {\n" +
331
                "class Test {\n" +
343
                "Test(int one,\n" +
332
                "Test(int one,\n" +
Lines 347-352 Link Here
347
                "this.one = one;\n" +
336
                "this.one = one;\n" +
348
                "}\n" +
337
                "}\n" +
349
                "};");
338
                "};");
339
        setDefaultsOptions();
340
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
341
                put(EditorOptions.newLineBeforeBraceClass, 
342
                CodeStyle.BracePlacement.SAME_LINE.name());
343
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
344
                put(EditorOptions.newLineBeforeBraceDeclaration, 
345
                CodeStyle.BracePlacement.SAME_LINE.name());
346
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
347
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
350
        reformat();
348
        reformat();
351
        assertDocumentText("Incorrect multiline constructor reformatting",
349
        assertDocumentText("Incorrect multiline constructor reformatting",
352
                "class Test {\n" +
350
                "class Test {\n" +
Lines 364-372 Link Here
364
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
362
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=49450
365
     */
363
     */
366
    public void testReformatMultilineConstructor2() {
364
    public void testReformatMultilineConstructor2() {
367
        setDefaultsOptions();
368
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
369
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
370
        setLoadDocumentText(
365
        setLoadDocumentText(
371
                "class Test {\n" +
366
                "class Test {\n" +
372
                "Test(int one,\n" +
367
                "Test(int one,\n" +
Lines 376-381 Link Here
376
                "this.one = one;\n" +
371
                "this.one = one;\n" +
377
                "}\n" +
372
                "}\n" +
378
                "};");
373
                "};");
374
        setDefaultsOptions();
375
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
376
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
379
        reformat();
377
        reformat();
380
        assertDocumentText("Incorrect multiline constructor reformatting",
378
        assertDocumentText("Incorrect multiline constructor reformatting",
381
                "class Test\n" +
379
                "class Test\n" +
Lines 395-406 Link Here
395
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
393
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
396
     */
394
     */
397
    public void testReformatIfElseWithoutBrackets() {
395
    public void testReformatIfElseWithoutBrackets() {
398
        setDefaultsOptions();
399
        setLoadDocumentText(
396
        setLoadDocumentText(
400
                "if (count == 0)\n" +
397
                "if (count == 0)\n" +
401
                "return 0.0f;\n" +
398
                "return 0.0f;\n" +
402
                "else\n" +
399
                "else\n" +
403
                "return performanceSum / getCount();\n");
400
                "return performanceSum / getCount();\n");
401
        setDefaultsOptions();
404
        reformat();
402
        reformat();
405
        assertDocumentText("Incorrect reformatting of if-else without brackets",
403
        assertDocumentText("Incorrect reformatting of if-else without brackets",
406
                "if (count == 0)\n" +
404
                "if (count == 0)\n" +
Lines 414-426 Link Here
414
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
412
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
415
     */
413
     */
416
    public void testReformatIfElseWithoutBrackets2() {
414
    public void testReformatIfElseWithoutBrackets2() {
417
        setDefaultsOptions();
418
        setLoadDocumentText(
415
        setLoadDocumentText(
419
                "if (count == 0)\n" +
416
                "if (count == 0)\n" +
420
                "return 0.0f;\n" +
417
                "return 0.0f;\n" +
421
                "else  {\n" +
418
                "else  {\n" +
422
                "return performanceSum / getCount();\n"+
419
                "return performanceSum / getCount();\n"+
423
                "}\n");
420
                "}\n");
421
        setDefaultsOptions();
424
        reformat();
422
        reformat();
425
        assertDocumentText("Incorrect reformatting of if-else without brackets",
423
        assertDocumentText("Incorrect reformatting of if-else without brackets",
426
                "if (count == 0)\n" +
424
                "if (count == 0)\n" +
Lines 435-446 Link Here
435
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
433
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
436
     */
434
     */
437
    public void testReformatIfElseWithoutBrackets3() {
435
    public void testReformatIfElseWithoutBrackets3() {
438
        setDefaultsOptions();
439
        setLoadDocumentText(
436
        setLoadDocumentText(
440
                "if (true) if (true) if (true)\n" +
437
                "if (true) if (true) if (true)\n" +
441
                "else return;\n" +
438
                "else return;\n" +
442
                "else return;\n" +
439
                "else return;\n" +
443
                "else return;\n");
440
                "else return;\n");
441
        setDefaultsOptions();
444
        reformat();
442
        reformat();
445
        assertDocumentText("Incorrect reformatting of if-else without brackets",
443
        assertDocumentText("Incorrect reformatting of if-else without brackets",
446
                "if (true) if (true) if (true)\n" +
444
                "if (true) if (true) if (true)\n" +
Lines 454-460 Link Here
454
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
452
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=50523
455
     */
453
     */
456
    public void testReformatIfElseWithoutBrackets4() {
454
    public void testReformatIfElseWithoutBrackets4() {
457
        setDefaultsOptions();
458
        setLoadDocumentText(
455
        setLoadDocumentText(
459
                "if (true)\n" +
456
                "if (true)\n" +
460
                "    if (true)\n" +
457
                "    if (true)\n" +
Lines 462-467 Link Here
462
                "else return;\n" +
459
                "else return;\n" +
463
                "else return;\n" +
460
                "else return;\n" +
464
                "else return;\n");
461
                "else return;\n");
462
        setDefaultsOptions();
465
        reformat();
463
        reformat();
466
        assertDocumentText("Incorrect reformatting of if-else without brackets",
464
        assertDocumentText("Incorrect reformatting of if-else without brackets",
467
                "if (true)\n" +
465
                "if (true)\n" +
Lines 477-488 Link Here
477
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
475
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
478
     */
476
     */
479
    public void testReformatSimpleClass() {
477
    public void testReformatSimpleClass() {
480
        setDefaultsOptions();
481
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
482
                put(EditorOptions.newLineBeforeBraceClass, 
483
                CodeStyle.BracePlacement.SAME_LINE.name());
484
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
485
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
486
        setLoadDocumentText(
478
        setLoadDocumentText(
487
            "class C {\n" +
479
            "class C {\n" +
488
            "protected:\n" +
480
            "protected:\n" +
Lines 493-498 Link Here
493
            "public:\n" +
485
            "public:\n" +
494
            "int k;\n" +
486
            "int k;\n" +
495
            "};\n");
487
            "};\n");
488
        setDefaultsOptions();
489
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
490
                put(EditorOptions.newLineBeforeBraceClass, 
491
                CodeStyle.BracePlacement.SAME_LINE.name());
492
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
493
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
496
        reformat();
494
        reformat();
497
        assertDocumentText("Incorrect reformatting of simple class",
495
        assertDocumentText("Incorrect reformatting of simple class",
498
            "class C {\n" +
496
            "class C {\n" +
Lines 511-519 Link Here
511
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
509
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=97544
512
     */
510
     */
513
    public void testReformatSimpleClass2() {
511
    public void testReformatSimpleClass2() {
514
        setDefaultsOptions();
515
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
516
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
517
        setLoadDocumentText(
512
        setLoadDocumentText(
518
            "class C {\n" +
513
            "class C {\n" +
519
            "protected:\n" +
514
            "protected:\n" +
Lines 524-529 Link Here
524
            "public:\n" +
519
            "public:\n" +
525
            "int k;\n" +
520
            "int k;\n" +
526
            "};\n");
521
            "};\n");
522
        setDefaultsOptions();
523
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
524
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
527
        reformat();
525
        reformat();
528
        assertDocumentText("Incorrect reformatting of simple class",
526
        assertDocumentText("Incorrect reformatting of simple class",
529
            "class C\n" +
527
            "class C\n" +
Lines 543-549 Link Here
543
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=98475
541
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=98475
544
     */
542
     */
545
    public void testReformatForWithoutBraces() {
543
    public void testReformatForWithoutBraces() {
546
        setDefaultsOptions();
547
        setLoadDocumentText(
544
        setLoadDocumentText(
548
            "for (i = 0; i < MAXBUCKET; i++) {\n" +
545
            "for (i = 0; i < MAXBUCKET; i++) {\n" +
549
	    "for (j = 0; j < MAXBUCKET; j++)\n" +
546
	    "for (j = 0; j < MAXBUCKET; j++)\n" +
Lines 554-559 Link Here
554
            "}\n" +
551
            "}\n" +
555
            "}\n" +
552
            "}\n" +
556
            "}\n");
553
            "}\n");
554
        setDefaultsOptions();
557
        reformat();
555
        reformat();
558
        assertDocumentText("Incorrect reformatting of For without braces",
556
        assertDocumentText("Incorrect reformatting of For without braces",
559
            "for (i = 0; i < MAXBUCKET; i++) {\n" +
557
            "for (i = 0; i < MAXBUCKET; i++) {\n" +
Lines 572-581 Link Here
572
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
570
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
573
     */
571
     */
574
    public void testReformatPreprocessorsDirectives() {
572
    public void testReformatPreprocessorsDirectives() {
575
        setDefaultsOptions();
576
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
577
                put(EditorOptions.newLineBeforeBraceDeclaration, 
578
                CodeStyle.BracePlacement.SAME_LINE.name());
579
        setLoadDocumentText(
573
        setLoadDocumentText(
580
            "main() {\n" +
574
            "main() {\n" +
581
            "#define AAA 1\n" +
575
            "#define AAA 1\n" +
Lines 585-590 Link Here
585
            "int ccc;\n" +
579
            "int ccc;\n" +
586
            "int ddd;\n" +
580
            "int ddd;\n" +
587
            "}\n");
581
            "}\n");
582
        setDefaultsOptions();
583
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
584
                put(EditorOptions.newLineBeforeBraceDeclaration, 
585
                CodeStyle.BracePlacement.SAME_LINE.name());
588
        reformat();
586
        reformat();
589
        assertDocumentText("Incorrect reformatting for preprocessors directives",
587
        assertDocumentText("Incorrect reformatting for preprocessors directives",
590
            "main() {\n" +
588
            "main() {\n" +
Lines 602-608 Link Here
602
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
600
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=100665
603
     */
601
     */
604
    public void testReformatPreprocessorsDirectives2() {
602
    public void testReformatPreprocessorsDirectives2() {
605
        setDefaultsOptions();
606
        setLoadDocumentText(
603
        setLoadDocumentText(
607
            "main() {\n" +
604
            "main() {\n" +
608
            "#define AAA 1\n" +
605
            "#define AAA 1\n" +
Lines 612-617 Link Here
612
            "int ccc;\n" +
609
            "int ccc;\n" +
613
            "int ddd;\n" +
610
            "int ddd;\n" +
614
            "}\n");
611
            "}\n");
612
        setDefaultsOptions();
615
        reformat();
613
        reformat();
616
        assertDocumentText("Incorrect reformatting for preprocessors directives",
614
        assertDocumentText("Incorrect reformatting for preprocessors directives",
617
            "main()\n" +
615
            "main()\n" +
Lines 630-638 Link Here
630
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=115628
628
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=115628
631
     */
629
     */
632
    public void testReformatFunctionArguments() {
630
    public void testReformatFunctionArguments() {
633
        setDefaultsOptions();
634
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
635
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
636
        setLoadDocumentText(
631
        setLoadDocumentText(
637
            "int foo(int z){\n" +
632
            "int foo(int z){\n" +
638
            "z += myfoo(a,\n" +
633
            "z += myfoo(a,\n" +
Lines 640-645 Link Here
640
            "c);\n" +
635
            "c);\n" +
641
            "}\n"
636
            "}\n"
642
            );
637
            );
638
        setDefaultsOptions();
639
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
640
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
643
        reformat();
641
        reformat();
644
        assertDocumentText("Incorrect reformatting of function arguments list",
642
        assertDocumentText("Incorrect reformatting of function arguments list",
645
            "int foo(int z)\n" +
643
            "int foo(int z)\n" +
Lines 655-669 Link Here
655
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
653
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
656
     */
654
     */
657
    public void testReformatConstructorInitializer() {
655
    public void testReformatConstructorInitializer() {
658
        setDefaultsOptions();
659
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
660
                put(EditorOptions.newLineBeforeBraceDeclaration, 
661
                CodeStyle.BracePlacement.SAME_LINE.name());
662
        setLoadDocumentText(
656
        setLoadDocumentText(
663
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
657
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
664
            "Module(\"CPU\", \"generic\", type, architecture, units) {\n" +
658
            "Module(\"CPU\", \"generic\", type, architecture, units) {\n" +
665
            "ComputeSupportMetric();\n" +
659
            "ComputeSupportMetric();\n" +
666
            "}\n");
660
            "}\n");
661
        setDefaultsOptions();
662
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
663
                put(EditorOptions.newLineBeforeBraceDeclaration, 
664
                CodeStyle.BracePlacement.SAME_LINE.name());
667
        reformat();
665
        reformat();
668
        assertDocumentText("Incorrect reformatting of constructor initializer",
666
        assertDocumentText("Incorrect reformatting of constructor initializer",
669
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
667
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
Lines 677-688 Link Here
677
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
675
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
678
     */
676
     */
679
    public void testReformatConstructorInitializer2() {
677
    public void testReformatConstructorInitializer2() {
680
        setDefaultsOptions();
681
        setLoadDocumentText(
678
        setLoadDocumentText(
682
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
679
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
683
            "Module(\"CPU\", \"generic\", type, architecture, units) {\n" +
680
            "Module(\"CPU\", \"generic\", type, architecture, units) {\n" +
684
            "ComputeSupportMetric();\n" +
681
            "ComputeSupportMetric();\n" +
685
            "}\n");
682
            "}\n");
683
        setDefaultsOptions();
686
        reformat();
684
        reformat();
687
        assertDocumentText("Incorrect reformatting of constructor initializer",
685
        assertDocumentText("Incorrect reformatting of constructor initializer",
688
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
686
            "Cpu::Cpu(int type, int architecture, int units) :\n" +
Lines 697-711 Link Here
697
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
695
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
698
     */
696
     */
699
    public void testReformatMultilineMainDefinition() {
697
    public void testReformatMultilineMainDefinition() {
700
        setDefaultsOptions();
701
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
702
                put(EditorOptions.newLineBeforeBraceDeclaration, 
703
                CodeStyle.BracePlacement.SAME_LINE.name());
704
        setLoadDocumentText(
698
        setLoadDocumentText(
705
            "int\n" +
699
            "int\n" +
706
            "main(int argc, char** argv) {\n" +
700
            "main(int argc, char** argv) {\n" +
707
            "return (EXIT_SUCCESS);\n" +
701
            "return (EXIT_SUCCESS);\n" +
708
            "};\n");
702
            "};\n");
703
        setDefaultsOptions();
704
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
705
                put(EditorOptions.newLineBeforeBraceDeclaration, 
706
                CodeStyle.BracePlacement.SAME_LINE.name());
709
        reformat();
707
        reformat();
710
        assertDocumentText("Incorrect reformatting of multi line main definition",
708
        assertDocumentText("Incorrect reformatting of multi line main definition",
711
            "int\n" +
709
            "int\n" +
Lines 719-730 Link Here
719
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
717
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91173
720
     */
718
     */
721
    public void testReformatMultilineMainDefinition2() {
719
    public void testReformatMultilineMainDefinition2() {
722
        setDefaultsOptions();
723
        setLoadDocumentText(
720
        setLoadDocumentText(
724
            "int\n" +
721
            "int\n" +
725
            "main(int argc, char** argv) {\n" +
722
            "main(int argc, char** argv) {\n" +
726
            "return (EXIT_SUCCESS);\n" +
723
            "return (EXIT_SUCCESS);\n" +
727
            "};\n");
724
            "};\n");
725
        setDefaultsOptions();
728
        reformat();
726
        reformat();
729
        assertDocumentText("Incorrect reformatting of multi line main definition",
727
        assertDocumentText("Incorrect reformatting of multi line main definition",
730
            "int\n" +
728
            "int\n" +
Lines 739-745 Link Here
739
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
737
     * @see http://www.netbeans.org/issues/show_bug.cgi?id=91561
740
     */
738
     */
741
    public void testReformatUnbalancedBraces() {
739
    public void testReformatUnbalancedBraces() {
742
        setDefaultsOptions();
743
        setLoadDocumentText(
740
        setLoadDocumentText(
744
            "void foo() {\n" +
741
            "void foo() {\n" +
745
            "#if A\n" +
742
            "#if A\n" +
Lines 749-754 Link Here
749
            "#endif\n" +
746
            "#endif\n" +
750
            "}\n" +
747
            "}\n" +
751
            "}\n");
748
            "}\n");
749
        setDefaultsOptions();
752
        reformat();
750
        reformat();
753
        assertDocumentText("Incorrect reformatting of unbalanced braces",
751
        assertDocumentText("Incorrect reformatting of unbalanced braces",
754
            "void foo()\n" +
752
            "void foo()\n" +
Lines 763-774 Link Here
763
    }
761
    }
764
762
765
    public void testIdentInnerEnum() {
763
    public void testIdentInnerEnum() {
766
        setDefaultsOptions();
767
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
768
                put(EditorOptions.newLineBeforeBraceClass, 
769
                CodeStyle.BracePlacement.SAME_LINE.name());
770
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
771
                putInt(EditorOptions.blankLinesBeforeClass, 1);
772
        setLoadDocumentText(
764
        setLoadDocumentText(
773
            "class NdbTransaction {\n" +
765
            "class NdbTransaction {\n" +
774
            "#ifndef D\n" +
766
            "#ifndef D\n" +
Lines 786-791 Link Here
786
            "};\n" +
778
            "};\n" +
787
            "};\n"
779
            "};\n"
788
            );
780
            );
781
        setDefaultsOptions();
782
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
783
                put(EditorOptions.newLineBeforeBraceClass, 
784
                CodeStyle.BracePlacement.SAME_LINE.name());
785
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
786
                putInt(EditorOptions.blankLinesBeforeClass, 1);
789
        reformat();
787
        reformat();
790
        assertDocumentText("Incorrect identing of inner enum",
788
        assertDocumentText("Incorrect identing of inner enum",
791
            "class NdbTransaction {\n" +
789
            "class NdbTransaction {\n" +
Lines 807-815 Link Here
807
    }
805
    }
808
806
809
    public void testIdentInnerEnum2() {
807
    public void testIdentInnerEnum2() {
810
        setDefaultsOptions();
811
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
812
                putInt(EditorOptions.blankLinesBeforeClass, 0);
813
        setLoadDocumentText(
808
        setLoadDocumentText(
814
            "class NdbTransaction {\n" +
809
            "class NdbTransaction {\n" +
815
            "#ifndef D\n" +
810
            "#ifndef D\n" +
Lines 827-832 Link Here
827
            "};\n" +
822
            "};\n" +
828
            "};\n"
823
            "};\n"
829
            );
824
            );
825
        setDefaultsOptions();
826
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
827
                putInt(EditorOptions.blankLinesBeforeClass, 0);
830
        reformat();
828
        reformat();
831
        assertDocumentText("Incorrect identing of inner enum",
829
        assertDocumentText("Incorrect identing of inner enum",
832
            "class NdbTransaction\n" +
830
            "class NdbTransaction\n" +
Lines 849-863 Link Here
849
    }
847
    }
850
848
851
    public void testTemplate() {
849
    public void testTemplate() {
852
        setDefaultsOptions();
853
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
854
                put(EditorOptions.newLineBeforeBraceClass, 
855
                CodeStyle.BracePlacement.SAME_LINE.name());
856
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
857
                put(EditorOptions.newLineBeforeBraceDeclaration, 
858
                CodeStyle.BracePlacement.SAME_LINE.name());
859
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
860
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
861
        setLoadDocumentText(
850
        setLoadDocumentText(
862
            "template <class T, class U>\n" +
851
            "template <class T, class U>\n" +
863
            "class KeyTable2 : public DLHashTable2<T, U> {\n" +
852
            "class KeyTable2 : public DLHashTable2<T, U> {\n" +
Lines 871-876 Link Here
871
            "}\n" +
860
            "}\n" +
872
            "};\n"
861
            "};\n"
873
            );
862
            );
863
        setDefaultsOptions();
864
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
865
                put(EditorOptions.newLineBeforeBraceClass, 
866
                CodeStyle.BracePlacement.SAME_LINE.name());
867
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
868
                put(EditorOptions.newLineBeforeBraceDeclaration, 
869
                CodeStyle.BracePlacement.SAME_LINE.name());
870
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
871
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
874
        reformat();
872
        reformat();
875
        assertDocumentText("Incorrect identing of template class",
873
        assertDocumentText("Incorrect identing of template class",
876
            "template <class T, class U>\n" +
874
            "template <class T, class U>\n" +
Lines 887-895 Link Here
887
    }
885
    }
888
886
889
    public void testTemplate2() {
887
    public void testTemplate2() {
890
        setDefaultsOptions();
891
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
892
                putInt(EditorOptions.blankLinesBeforeMethods, 1);
893
        setLoadDocumentText(
888
        setLoadDocumentText(
894
            "template <class T, class U>\n" +
889
            "template <class T, class U>\n" +
895
            "class KeyTable2 : public DLHashTable2<T, U> {\n" +
890
            "class KeyTable2 : public DLHashTable2<T, U> {\n" +
Lines 903-908 Link Here
903
            "}\n" +
898
            "}\n" +
904
            "};\n"
899
            "};\n"
905
            );
900
            );
901
        setDefaultsOptions();
902
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
903
                putInt(EditorOptions.blankLinesBeforeMethods, 1);
906
        reformat();
904
        reformat();
907
        assertDocumentText("Incorrect identing of template class",
905
        assertDocumentText("Incorrect identing of template class",
908
            "template <class T, class U>\n" +
906
            "template <class T, class U>\n" +
Lines 924-930 Link Here
924
    }
922
    }
925
    
923
    
926
    public void testIdentPreprocessorElase() {
924
    public void testIdentPreprocessorElase() {
927
        setDefaultsOptions();
928
        setLoadDocumentText(
925
        setLoadDocumentText(
929
            "#if defined(USE_MB)\n" +
926
            "#if defined(USE_MB)\n" +
930
            "if (use_mb(cs)) {\n" +
927
            "if (use_mb(cs)) {\n" +
Lines 934-939 Link Here
934
            "{\n" +
931
            "{\n" +
935
            "}\n"
932
            "}\n"
936
            );
933
            );
934
        setDefaultsOptions();
937
        reformat();
935
        reformat();
938
        assertDocumentText("Incorrect identing of preprocessor else",
936
        assertDocumentText("Incorrect identing of preprocessor else",
939
            "#if defined(USE_MB)\n" +
937
            "#if defined(USE_MB)\n" +
Lines 947-955 Link Here
947
    }
945
    }
948
    
946
    
949
    public void testIdentDefine() {
947
    public void testIdentDefine() {
950
        setDefaultsOptions();
951
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
952
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
953
        setLoadDocumentText(
948
        setLoadDocumentText(
954
            "int\n" +
949
            "int\n" +
955
            "main() {\n" +
950
            "main() {\n" +
Lines 961-966 Link Here
961
            "z++;\n" +
956
            "z++;\n" +
962
            "}\n"
957
            "}\n"
963
            );
958
            );
959
        setDefaultsOptions();
960
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
961
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
964
        reformat();
962
        reformat();
965
        assertDocumentText("Incorrect identing of preprocessor else",
963
        assertDocumentText("Incorrect identing of preprocessor else",
966
            "int\n" +
964
            "int\n" +
Lines 977-988 Link Here
977
    }
975
    }
978
976
979
    public void testIdentMultyLineMain() {
977
    public void testIdentMultyLineMain() {
980
        setDefaultsOptions();
981
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
982
                put(EditorOptions.newLineBeforeBraceDeclaration, 
983
                CodeStyle.BracePlacement.SAME_LINE.name());
984
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
985
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
986
        setLoadDocumentText(
978
        setLoadDocumentText(
987
            "long z;\n" +
979
            "long z;\n" +
988
            "int\n" +
980
            "int\n" +
Lines 990-995 Link Here
990
            "short a;\n" +
982
            "short a;\n" +
991
            "}\n"
983
            "}\n"
992
            );
984
            );
985
        setDefaultsOptions();
986
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
987
                put(EditorOptions.newLineBeforeBraceDeclaration, 
988
                CodeStyle.BracePlacement.SAME_LINE.name());
989
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
990
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
993
        reformat();
991
        reformat();
994
        assertDocumentText("Incorrect identing multyline main",
992
        assertDocumentText("Incorrect identing multyline main",
995
            "long z;\n" +
993
            "long z;\n" +
Lines 1001-1009 Link Here
1001
    }
999
    }
1002
1000
1003
    public void testIdentMultyLineMain2() {
1001
    public void testIdentMultyLineMain2() {
1004
        setDefaultsOptions();
1005
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1006
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1007
        setLoadDocumentText(
1002
        setLoadDocumentText(
1008
            "long z;\n" +
1003
            "long z;\n" +
1009
            "int\n" +
1004
            "int\n" +
Lines 1011-1016 Link Here
1011
            "short a;\n" +
1006
            "short a;\n" +
1012
            "}\n"
1007
            "}\n"
1013
            );
1008
            );
1009
        setDefaultsOptions();
1010
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1011
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1014
        reformat();
1012
        reformat();
1015
        assertDocumentText("Incorrect identing multyline main",
1013
        assertDocumentText("Incorrect identing multyline main",
1016
            "long z;\n" +
1014
            "long z;\n" +
Lines 1023-1032 Link Here
1023
    }
1021
    }
1024
    
1022
    
1025
    public void testIdentMultyConstructor() {
1023
    public void testIdentMultyConstructor() {
1026
        setDefaultsOptions();
1027
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1028
                put(EditorOptions.newLineBeforeBraceDeclaration, 
1029
                CodeStyle.BracePlacement.SAME_LINE.name());
1030
        setLoadDocumentText(
1024
        setLoadDocumentText(
1031
            "Log_event::Log_event(uint flags_arg, bool using_trans)\n" +
1025
            "Log_event::Log_event(uint flags_arg, bool using_trans)\n" +
1032
            "        :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg)\n" +
1026
            "        :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg), thd(thd_arg)\n" +
Lines 1034-1039 Link Here
1034
            "                server_id=thd->server_id;\n" +
1028
            "                server_id=thd->server_id;\n" +
1035
            "        }\n"
1029
            "        }\n"
1036
            );
1030
            );
1031
        setDefaultsOptions();
1032
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1033
                put(EditorOptions.newLineBeforeBraceDeclaration, 
1034
                CodeStyle.BracePlacement.SAME_LINE.name());
1037
        reformat();
1035
        reformat();
1038
        assertDocumentText("Incorrect identing multyline constructor",
1036
        assertDocumentText("Incorrect identing multyline constructor",
1039
            "Log_event::Log_event(uint flags_arg, bool using_trans)\n" +
1037
            "Log_event::Log_event(uint flags_arg, bool using_trans)\n" +
Lines 1044-1052 Link Here
1044
    }
1042
    }
1045
1043
1046
    public void testIdentMultyConstructor2() {
1044
    public void testIdentMultyConstructor2() {
1047
        setDefaultsOptions();
1048
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1049
                putBoolean(EditorOptions.spaceAfterColon, false);
1050
        setLoadDocumentText(
1045
        setLoadDocumentText(
1051
            "Log_event::Log_event(const char* buf,\n" +
1046
            "Log_event::Log_event(const char* buf,\n" +
1052
            "        const Format_description_log_event* description_event)\n" +
1047
            "        const Format_description_log_event* description_event)\n" +
Lines 1055-1060 Link Here
1055
            "                server_id=thd->server_id;\n" +
1050
            "                server_id=thd->server_id;\n" +
1056
            "        }\n"
1051
            "        }\n"
1057
            );
1052
            );
1053
        setDefaultsOptions();
1054
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1055
                putBoolean(EditorOptions.spaceAfterColon, false);
1058
        reformat();
1056
        reformat();
1059
        assertDocumentText("Incorrect identing multyline constructor",
1057
        assertDocumentText("Incorrect identing multyline constructor",
1060
            "Log_event::Log_event(const char* buf,\n" +
1058
            "Log_event::Log_event(const char* buf,\n" +
Lines 1067-1077 Link Here
1067
    }
1065
    }
1068
1066
1069
    public void testIdentMultyConstructor3() {
1067
    public void testIdentMultyConstructor3() {
1070
        setDefaultsOptions();
1071
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1072
                putBoolean(EditorOptions.spaceAfterColon, false);
1073
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1074
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
1075
        setLoadDocumentText(
1068
        setLoadDocumentText(
1076
            "Log_event::Log_event(const char* buf,\n" +
1069
            "Log_event::Log_event(const char* buf,\n" +
1077
            "        const Format_description_log_event* description_event)\n" +
1070
            "        const Format_description_log_event* description_event)\n" +
Lines 1080-1085 Link Here
1080
            "                server_id=thd->server_id;\n" +
1073
            "                server_id=thd->server_id;\n" +
1081
            "        }\n"
1074
            "        }\n"
1082
            );
1075
            );
1076
        setDefaultsOptions();
1077
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1078
                putBoolean(EditorOptions.spaceAfterColon, false);
1079
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1080
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
1083
        reformat();
1081
        reformat();
1084
        assertDocumentText("Incorrect identing multyline constructor",
1082
        assertDocumentText("Incorrect identing multyline constructor",
1085
            "Log_event::Log_event(const char* buf,\n" +
1083
            "Log_event::Log_event(const char* buf,\n" +
Lines 1092-1098 Link Here
1092
    }
1090
    }
1093
1091
1094
    public void testIdentMultyConstructor4() {
1092
    public void testIdentMultyConstructor4() {
1095
        setDefaultsOptions();
1096
        setLoadDocumentText(
1093
        setLoadDocumentText(
1097
            "class IndexReader : LUCENE_BASE\n" +
1094
            "class IndexReader : LUCENE_BASE\n" +
1098
            "{\n" +
1095
            "{\n" +
Lines 1105-1110 Link Here
1105
            "};\n" +
1102
            "};\n" +
1106
            "};\n"
1103
            "};\n"
1107
            );
1104
            );
1105
        setDefaultsOptions();
1108
        reformat();
1106
        reformat();
1109
        assertDocumentText("Incorrect identing multyline constructor",
1107
        assertDocumentText("Incorrect identing multyline constructor",
1110
            "class IndexReader : LUCENE_BASE\n" +
1108
            "class IndexReader : LUCENE_BASE\n" +
Lines 1123-1131 Link Here
1123
    
1121
    
1124
1122
1125
    public void testIdentDefineBrace() {
1123
    public void testIdentDefineBrace() {
1126
        setDefaultsOptions();
1127
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1128
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1129
        setLoadDocumentText(
1124
        setLoadDocumentText(
1130
            "#define BRACE {\n" +
1125
            "#define BRACE {\n" +
1131
            "int main() {\n" +
1126
            "int main() {\n" +
Lines 1133-1138 Link Here
1133
            "}\n" +
1128
            "}\n" +
1134
            "}\n"
1129
            "}\n"
1135
            );
1130
            );
1131
        setDefaultsOptions();
1132
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1133
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1136
        reformat();
1134
        reformat();
1137
        assertDocumentText("Incorrect identing define brace",
1135
        assertDocumentText("Incorrect identing define brace",
1138
            "#define BRACE {\n" +
1136
            "#define BRACE {\n" +
Lines 1145-1153 Link Here
1145
    }
1143
    }
1146
    
1144
    
1147
    public void testIdentDefineBrace2() {
1145
    public void testIdentDefineBrace2() {
1148
        setDefaultsOptions();
1149
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1150
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1151
        setLoadDocumentText(
1146
        setLoadDocumentText(
1152
            "#define BRACE }\n" +
1147
            "#define BRACE }\n" +
1153
            "int main() {\n" +
1148
            "int main() {\n" +
Lines 1155-1160 Link Here
1155
            "}\n" +
1150
            "}\n" +
1156
            "}\n"
1151
            "}\n"
1157
            );
1152
            );
1153
        setDefaultsOptions();
1154
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1155
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1158
        reformat();
1156
        reformat();
1159
        assertDocumentText("Incorrect identing define brace",
1157
        assertDocumentText("Incorrect identing define brace",
1160
            "#define BRACE }\n" +
1158
            "#define BRACE }\n" +
Lines 1167-1176 Link Here
1167
    }
1165
    }
1168
1166
1169
    public void testMacroDefineWithBrace() {
1167
    public void testMacroDefineWithBrace() {
1170
        setDefaultsOptions();
1171
        setLoadDocumentText(
1168
        setLoadDocumentText(
1172
            "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n"
1169
            "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n"
1173
            );
1170
            );
1171
        setDefaultsOptions();
1174
        reformat();
1172
        reformat();
1175
            assertDocumentText("Incorrect formatting for macro define with brace",
1173
            assertDocumentText("Incorrect formatting for macro define with brace",
1176
            "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n"
1174
            "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n"
Lines 1178-1188 Link Here
1178
    }
1176
    }
1179
1177
1180
    public void testMacroDefineWithBrace1() {
1178
    public void testMacroDefineWithBrace1() {
1181
        setDefaultsOptions();
1182
        setLoadDocumentText(
1179
        setLoadDocumentText(
1183
            "\n"+
1180
            "\n"+
1184
            "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n"
1181
            "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n"
1185
            );
1182
            );
1183
        setDefaultsOptions();
1186
        reformat();
1184
        reformat();
1187
            assertDocumentText("Incorrect formatting for macro define with brace",
1185
            assertDocumentText("Incorrect formatting for macro define with brace",
1188
            "\n"+
1186
            "\n"+
Lines 1191-1215 Link Here
1191
    };
1189
    };
1192
    
1190
    
1193
    public void testMacroDefineWithBrace2() {
1191
    public void testMacroDefineWithBrace2() {
1194
        setDefaultsOptions();
1192
        setLoadDocumentText(
1195
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1193
                "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
1194
        setDefaultsOptions();
1195
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1196
                put(EditorOptions.newLineBeforeBrace, 
1196
                put(EditorOptions.newLineBeforeBrace, 
1197
                CodeStyle.BracePlacement.NEW_LINE.name());
1197
                CodeStyle.BracePlacement.NEW_LINE.name());
1198
        setLoadDocumentText(
1199
                "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
1200
        reformat();
1198
        reformat();
1201
        assertDocumentText("Incorrect formatting for macro define with brace",
1199
        assertDocumentText("Incorrect formatting for macro define with brace",
1202
                "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
1200
                "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
1203
    }
1201
    }
1204
1202
1205
    public void testMacroDefineWithBrace3() {
1203
    public void testMacroDefineWithBrace3() {
1206
        setDefaultsOptions();
1204
        setLoadDocumentText(
1207
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1205
                "\n"+
1206
                "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
1207
        setDefaultsOptions();
1208
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1208
                put(EditorOptions.newLineBeforeBrace, 
1209
                put(EditorOptions.newLineBeforeBrace, 
1209
                CodeStyle.BracePlacement.NEW_LINE.name());
1210
                CodeStyle.BracePlacement.NEW_LINE.name());
1210
        setLoadDocumentText(
1211
                "\n"+
1212
                "#define SOME_IF(a, b) if ((a) > (b)) { /* do something */ }\n");
1213
        reformat();
1211
        reformat();
1214
        assertDocumentText("Incorrect formatting for macro define with brace",
1212
        assertDocumentText("Incorrect formatting for macro define with brace",
1215
                "\n"+
1213
                "\n"+
Lines 1217-1228 Link Here
1217
    }
1215
    }
1218
1216
1219
    public void testMacroDefineWithParen() {
1217
    public void testMacroDefineWithParen() {
1220
        setDefaultsOptions();
1221
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1222
                put(EditorOptions.newLineBeforeBraceDeclaration, 
1223
                CodeStyle.BracePlacement.SAME_LINE.name());
1224
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1225
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1226
        setLoadDocumentText(
1218
        setLoadDocumentText(
1227
                "#include <stdio.h>\n" +
1219
                "#include <stdio.h>\n" +
1228
                "#define M(x) puts(#x)\n" +
1220
                "#define M(x) puts(#x)\n" +
Lines 1230-1235 Link Here
1230
                "M(\"test\");\n" +
1222
                "M(\"test\");\n" +
1231
                "return 0;\n" +
1223
                "return 0;\n" +
1232
                "}\n");
1224
                "}\n");
1225
        setDefaultsOptions();
1226
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1227
                put(EditorOptions.newLineBeforeBraceDeclaration, 
1228
                CodeStyle.BracePlacement.SAME_LINE.name());
1229
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1230
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1233
        reformat();
1231
        reformat();
1234
        assertDocumentText("Incorrect formatting for macro define with paren",
1232
        assertDocumentText("Incorrect formatting for macro define with paren",
1235
                "#include <stdio.h>\n" +
1233
                "#include <stdio.h>\n" +
Lines 1241-1249 Link Here
1241
    }
1239
    }
1242
1240
1243
    public void testMacroDefineWithParen11() {
1241
    public void testMacroDefineWithParen11() {
1244
        setDefaultsOptions();
1245
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1246
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1247
        setLoadDocumentText(
1242
        setLoadDocumentText(
1248
                "#include <stdio.h>\n" +
1243
                "#include <stdio.h>\n" +
1249
                "#define M(x) puts(#x)\n" +
1244
                "#define M(x) puts(#x)\n" +
Lines 1251-1256 Link Here
1251
                "M(\"test\");\n" +
1246
                "M(\"test\");\n" +
1252
                "return 0;\n" +
1247
                "return 0;\n" +
1253
                "}\n");
1248
                "}\n");
1249
        setDefaultsOptions();
1250
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1251
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1254
        reformat();
1252
        reformat();
1255
        assertDocumentText("Incorrect formatting for macro define with paren",
1253
        assertDocumentText("Incorrect formatting for macro define with paren",
1256
                "#include <stdio.h>\n" +
1254
                "#include <stdio.h>\n" +
Lines 1263-1278 Link Here
1263
    }
1261
    }
1264
1262
1265
    public void testMacroDefineWithParen2() {
1263
    public void testMacroDefineWithParen2() {
1266
        setDefaultsOptions();
1267
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1268
                putBoolean(EditorOptions.spaceBeforeMethodCallParen, true);
1269
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1270
                putBoolean(EditorOptions.spaceBeforeMethodDeclParen, true);
1271
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1272
                put(EditorOptions.newLineBeforeBraceDeclaration, 
1273
                CodeStyle.BracePlacement.SAME_LINE.name());
1274
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1275
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1276
        setLoadDocumentText(
1264
        setLoadDocumentText(
1277
                "#include <stdio.h>\n" +
1265
                "#include <stdio.h>\n" +
1278
                "#define M(x) puts(#x)\n" +
1266
                "#define M(x) puts(#x)\n" +
Lines 1280-1285 Link Here
1280
                "    M(\"test\");\n" +
1268
                "    M(\"test\");\n" +
1281
                "    return 0;\n" +
1269
                "    return 0;\n" +
1282
                "}\n");
1270
                "}\n");
1271
        setDefaultsOptions();
1272
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1273
                putBoolean(EditorOptions.spaceBeforeMethodCallParen, true);
1274
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1275
                putBoolean(EditorOptions.spaceBeforeMethodDeclParen, true);
1276
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1277
                put(EditorOptions.newLineBeforeBraceDeclaration, 
1278
                CodeStyle.BracePlacement.SAME_LINE.name());
1279
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1280
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1283
        reformat();
1281
        reformat();
1284
        assertDocumentText("Incorrect formatting for macro define with paren",
1282
        assertDocumentText("Incorrect formatting for macro define with paren",
1285
                "#include <stdio.h>\n" +
1283
                "#include <stdio.h>\n" +
Lines 1291-1301 Link Here
1291
    }
1289
    }
1292
1290
1293
    public void testMacroDefineWithParen21() {
1291
    public void testMacroDefineWithParen21() {
1294
        setDefaultsOptions();
1295
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1296
                putBoolean(EditorOptions.spaceBeforeMethodCallParen, true);
1297
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1298
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1299
        setLoadDocumentText(
1292
        setLoadDocumentText(
1300
                "#include <stdio.h>\n" +
1293
                "#include <stdio.h>\n" +
1301
                "#define M(x) puts(#x)\n" +
1294
                "#define M(x) puts(#x)\n" +
Lines 1303-1308 Link Here
1303
                "    M(\"test\");\n" +
1296
                "    M(\"test\");\n" +
1304
                "    return 0;\n" +
1297
                "    return 0;\n" +
1305
                "}\n");
1298
                "}\n");
1299
        setDefaultsOptions();
1300
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1301
                putBoolean(EditorOptions.spaceBeforeMethodCallParen, true);
1302
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1303
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
1306
        reformat();
1304
        reformat();
1307
        assertDocumentText("Incorrect formatting for macro define with paren",
1305
        assertDocumentText("Incorrect formatting for macro define with paren",
1308
                "#include <stdio.h>\n" +
1306
                "#include <stdio.h>\n" +
Lines 1315-1321 Link Here
1315
    }
1313
    }
1316
1314
1317
    public void testSwitchFormatting() {
1315
    public void testSwitchFormatting() {
1318
        setDefaultsOptions();
1319
        setLoadDocumentText(
1316
        setLoadDocumentText(
1320
                "switch (GetTypeID()) {\n" +
1317
                "switch (GetTypeID()) {\n" +
1321
                "case FAST:\n" +
1318
                "case FAST:\n" +
Lines 1328-1333 Link Here
1328
                "default:\n" +
1325
                "default:\n" +
1329
                "break;\n" +
1326
                "break;\n" +
1330
                "}\n");
1327
                "}\n");
1328
        setDefaultsOptions();
1331
        reformat();
1329
        reformat();
1332
        assertDocumentText("Incorrect formatting for macro define with paren",
1330
        assertDocumentText("Incorrect formatting for macro define with paren",
1333
                "switch (GetTypeID()) {\n" +
1331
                "switch (GetTypeID()) {\n" +
Lines 1344-1352 Link Here
1344
    }
1342
    }
1345
1343
1346
    public void testSwitchFormatting2() {
1344
    public void testSwitchFormatting2() {
1347
        setDefaultsOptions();
1348
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1349
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1350
        setLoadDocumentText(
1345
        setLoadDocumentText(
1351
                "switch (GetTypeID()) {\n" +
1346
                "switch (GetTypeID()) {\n" +
1352
                "case FAST:\n" +
1347
                "case FAST:\n" +
Lines 1359-1364 Link Here
1359
                "default:\n" +
1354
                "default:\n" +
1360
                "break;\n" +
1355
                "break;\n" +
1361
                "}\n");
1356
                "}\n");
1357
        setDefaultsOptions();
1358
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1359
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1362
        reformat();
1360
        reformat();
1363
        assertDocumentText("Incorrect formatting for macro define with paren",
1361
        assertDocumentText("Incorrect formatting for macro define with paren",
1364
                "switch (GetTypeID()) {\n" +
1362
                "switch (GetTypeID()) {\n" +
Lines 1375-1381 Link Here
1375
    }
1373
    }
1376
1374
1377
    public void testSwitchFormatting3() {
1375
    public void testSwitchFormatting3() {
1378
        setDefaultsOptions();
1379
        setLoadDocumentText(
1376
        setLoadDocumentText(
1380
                "int main(int i)\n" +
1377
                "int main(int i)\n" +
1381
                "{\n" +
1378
                "{\n" +
Lines 1417-1422 Link Here
1417
                "            break;\n" +
1414
                "            break;\n" +
1418
                "     }\n" +
1415
                "     }\n" +
1419
                "}\n");
1416
                "}\n");
1417
        setDefaultsOptions();
1420
        reformat();
1418
        reformat();
1421
        assertDocumentText("Incorrect formatting for macro define with paren",
1419
        assertDocumentText("Incorrect formatting for macro define with paren",
1422
                "int main(int i)\n" +
1420
                "int main(int i)\n" +
Lines 1466-1480 Link Here
1466
    }
1464
    }
1467
1465
1468
    public void testSwitchFormatting3Half() {
1466
    public void testSwitchFormatting3Half() {
1469
        setDefaultsOptions();
1470
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1471
                putBoolean(EditorOptions.newLineElse, true);
1472
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1473
                put(EditorOptions.newLineBeforeBrace, 
1474
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1475
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1476
                put(EditorOptions.newLineBeforeBraceSwitch, 
1477
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1478
        setLoadDocumentText(
1467
        setLoadDocumentText(
1479
                "int main(int i)\n" +
1468
                "int main(int i)\n" +
1480
                "{\n" +
1469
                "{\n" +
Lines 1516-1521 Link Here
1516
                "            break;\n" +
1505
                "            break;\n" +
1517
                "     }\n" +
1506
                "     }\n" +
1518
                "}\n");
1507
                "}\n");
1508
        setDefaultsOptions();
1509
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1510
                putBoolean(EditorOptions.newLineElse, true);
1511
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1512
                put(EditorOptions.newLineBeforeBrace, 
1513
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1514
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1515
                put(EditorOptions.newLineBeforeBraceSwitch, 
1516
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1519
        reformat();
1517
        reformat();
1520
        assertDocumentText("Incorrect formatting for macro define with paren",
1518
        assertDocumentText("Incorrect formatting for macro define with paren",
1521
                "int main(int i)\n" +
1519
                "int main(int i)\n" +
Lines 1570-1584 Link Here
1570
    }
1568
    }
1571
1569
1572
    public void testSwitchFormatting3HalfSQL() {
1570
    public void testSwitchFormatting3HalfSQL() {
1573
        setDefaultsOptions();
1574
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1575
                putBoolean(EditorOptions.newLineElse, true);
1576
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1577
                put(EditorOptions.newLineBeforeBrace, 
1578
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1579
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1580
                put(EditorOptions.newLineBeforeBraceSwitch, 
1581
                CodeStyle.BracePlacement.SAME_LINE.name());
1582
        setLoadDocumentText(
1571
        setLoadDocumentText(
1583
                "int main(int i)\n" +
1572
                "int main(int i)\n" +
1584
                "{\n" +
1573
                "{\n" +
Lines 1620-1625 Link Here
1620
                "            break;\n" +
1609
                "            break;\n" +
1621
                "     }\n" +
1610
                "     }\n" +
1622
                "}\n");
1611
                "}\n");
1612
        setDefaultsOptions();
1613
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1614
                putBoolean(EditorOptions.newLineElse, true);
1615
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1616
                put(EditorOptions.newLineBeforeBrace, 
1617
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1618
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1619
                put(EditorOptions.newLineBeforeBraceSwitch, 
1620
                CodeStyle.BracePlacement.SAME_LINE.name());
1623
        reformat();
1621
        reformat();
1624
        assertDocumentText("Incorrect formatting for macro define with paren",
1622
        assertDocumentText("Incorrect formatting for macro define with paren",
1625
                "int main(int i)\n" +
1623
                "int main(int i)\n" +
Lines 1671-1685 Link Here
1671
    }
1669
    }
1672
1670
1673
    public void testSwitchFormatting3SQL() {
1671
    public void testSwitchFormatting3SQL() {
1674
        setDefaultsOptions();
1675
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1676
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1677
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1678
                put(EditorOptions.newLineBeforeBrace, 
1679
                CodeStyle.BracePlacement.NEW_LINE.name());
1680
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1681
                put(EditorOptions.newLineBeforeBraceSwitch, 
1682
                CodeStyle.BracePlacement.SAME_LINE.name());
1683
        setLoadDocumentText(
1672
        setLoadDocumentText(
1684
                "int main(int i)\n" +
1673
                "int main(int i)\n" +
1685
                "{\n" +
1674
                "{\n" +
Lines 1721-1726 Link Here
1721
                "            break;\n" +
1710
                "            break;\n" +
1722
                "     }\n" +
1711
                "     }\n" +
1723
                "}\n");
1712
                "}\n");
1713
        setDefaultsOptions();
1714
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1715
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1716
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1717
                put(EditorOptions.newLineBeforeBrace, 
1718
                CodeStyle.BracePlacement.NEW_LINE.name());
1719
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1720
                put(EditorOptions.newLineBeforeBraceSwitch, 
1721
                CodeStyle.BracePlacement.SAME_LINE.name());
1724
        reformat();
1722
        reformat();
1725
        assertDocumentText("Incorrect formatting for macro define with paren",
1723
        assertDocumentText("Incorrect formatting for macro define with paren",
1726
                "int main(int i)\n" +
1724
                "int main(int i)\n" +
Lines 1772-1780 Link Here
1772
    }
1770
    }
1773
1771
1774
    public void testSwitchFormatting4() {
1772
    public void testSwitchFormatting4() {
1775
        setDefaultsOptions();
1776
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1777
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1778
        setLoadDocumentText(
1773
        setLoadDocumentText(
1779
                "int main(int i)\n" +
1774
                "int main(int i)\n" +
1780
                "{\n" +
1775
                "{\n" +
Lines 1807-1812 Link Here
1807
                "            break;\n" +
1802
                "            break;\n" +
1808
                "     }\n" +
1803
                "     }\n" +
1809
                "}\n");
1804
                "}\n");
1805
        setDefaultsOptions();
1806
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1807
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1810
        reformat();
1808
        reformat();
1811
        assertDocumentText("Incorrect formatting for macro define with paren",
1809
        assertDocumentText("Incorrect formatting for macro define with paren",
1812
                "int main(int i)\n" +
1810
                "int main(int i)\n" +
Lines 1843-1859 Link Here
1843
    }
1841
    }
1844
1842
1845
    public void testSwitchFormatting4Half() {
1843
    public void testSwitchFormatting4Half() {
1846
        setDefaultsOptions();
1847
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1848
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1849
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1850
                putBoolean(EditorOptions.newLineElse, true);
1851
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1852
                put(EditorOptions.newLineBeforeBrace, 
1853
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1854
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1855
                put(EditorOptions.newLineBeforeBraceSwitch, 
1856
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1857
        setLoadDocumentText(
1844
        setLoadDocumentText(
1858
                "int main(int i)\n" +
1845
                "int main(int i)\n" +
1859
                "{\n" +
1846
                "{\n" +
Lines 1895-1900 Link Here
1895
                "            break;\n" +
1882
                "            break;\n" +
1896
                "     }\n" +
1883
                "     }\n" +
1897
                "}\n");
1884
                "}\n");
1885
        setDefaultsOptions();
1886
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1887
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
1888
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1889
                putBoolean(EditorOptions.newLineElse, true);
1890
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1891
                put(EditorOptions.newLineBeforeBrace, 
1892
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1893
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1894
                put(EditorOptions.newLineBeforeBraceSwitch, 
1895
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1898
        reformat();
1896
        reformat();
1899
        assertDocumentText("Incorrect formatting for macro define with paren",
1897
        assertDocumentText("Incorrect formatting for macro define with paren",
1900
                "int main(int i)\n" +
1898
                "int main(int i)\n" +
Lines 1949-1955 Link Here
1949
    }
1947
    }
1950
1948
1951
    public void testDoxyGenIdent() {
1949
    public void testDoxyGenIdent() {
1952
        setDefaultsOptions();
1953
        setLoadDocumentText(
1950
        setLoadDocumentText(
1954
            "        /**\n" +
1951
            "        /**\n" +
1955
            "         * Class for accessing a compound stream.\n" +
1952
            "         * Class for accessing a compound stream.\n" +
Lines 1959-1964 Link Here
1959
            "        class CompoundFileReader: public CL_NS(store)::Directory {\n" +
1956
            "        class CompoundFileReader: public CL_NS(store)::Directory {\n" +
1960
            "        }\n"
1957
            "        }\n"
1961
            );
1958
            );
1959
        setDefaultsOptions();
1962
        reformat();
1960
        reformat();
1963
        assertDocumentText("Incorrect identing doc comment",
1961
        assertDocumentText("Incorrect identing doc comment",
1964
            "/**\n" +
1962
            "/**\n" +
Lines 1973-1979 Link Here
1973
    }
1971
    }
1974
1972
1975
    public void testBlockCommentIdent() {
1973
    public void testBlockCommentIdent() {
1976
        setDefaultsOptions();
1977
        setLoadDocumentText(
1974
        setLoadDocumentText(
1978
            "        /*\n" +
1975
            "        /*\n" +
1979
            "         * Class for accessing a compound stream.\n" +
1976
            "         * Class for accessing a compound stream.\n" +
Lines 1983-1988 Link Here
1983
            "        class CompoundFileReader: public CL_NS(store)::Directory {\n" +
1980
            "        class CompoundFileReader: public CL_NS(store)::Directory {\n" +
1984
            "        }\n"
1981
            "        }\n"
1985
            );
1982
            );
1983
        setDefaultsOptions();
1986
        reformat();
1984
        reformat();
1987
        assertDocumentText("Incorrect identing block comment",
1985
        assertDocumentText("Incorrect identing block comment",
1988
            "/*\n" +
1986
            "/*\n" +
Lines 1997-2003 Link Here
1997
    }
1995
    }
1998
1996
1999
    public void testIdentElse() {
1997
    public void testIdentElse() {
2000
        setDefaultsOptions();
2001
        setLoadDocumentText(
1998
        setLoadDocumentText(
2002
            "    void FieldsWriter::addDocument(Document* doc)\n" +
1999
            "    void FieldsWriter::addDocument(Document* doc)\n" +
2003
            "    {\n" +
2000
            "    {\n" +
Lines 2007-2012 Link Here
2007
            "         fieldsStream->writeString(field->stringValue(), _tcslen(field->stringValue()));\n" +
2004
            "         fieldsStream->writeString(field->stringValue(), _tcslen(field->stringValue()));\n" +
2008
            "    }\n"
2005
            "    }\n"
2009
            );
2006
            );
2007
        setDefaultsOptions();
2010
        reformat();
2008
        reformat();
2011
        assertDocumentText("Incorrect identing eles without {}",
2009
        assertDocumentText("Incorrect identing eles without {}",
2012
            "void FieldsWriter::addDocument(Document* doc)\n" +
2010
            "void FieldsWriter::addDocument(Document* doc)\n" +
Lines 2020-2026 Link Here
2020
    }
2018
    }
2021
2019
2022
    public void testIdentDoWhile() {
2020
    public void testIdentDoWhile() {
2023
        setDefaultsOptions();
2024
        setLoadDocumentText(
2021
        setLoadDocumentText(
2025
            " int foo()\n" +
2022
            " int foo()\n" +
2026
            " {\n" +
2023
            " {\n" +
Lines 2034-2039 Link Here
2034
            " while (this.number < 2 && number != 3);\n"+ 
2031
            " while (this.number < 2 && number != 3);\n"+ 
2035
            " }\n"
2032
            " }\n"
2036
            );
2033
            );
2034
        setDefaultsOptions();
2037
        reformat();
2035
        reformat();
2038
        assertDocumentText("Incorrect identing doWhile",
2036
        assertDocumentText("Incorrect identing doWhile",
2039
            "int foo()\n" +
2037
            "int foo()\n" +
Lines 2050-2064 Link Here
2050
    }
2048
    }
2051
2049
2052
    public void testIdentInlineMethod() {
2050
    public void testIdentInlineMethod() {
2053
        setDefaultsOptions();
2054
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2055
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2056
        setLoadDocumentText(
2051
        setLoadDocumentText(
2057
            "class IndexReader : LUCENE_BASE\n" +
2052
            "class IndexReader : LUCENE_BASE\n" +
2058
            "{\n" +
2053
            "{\n" +
2059
            "    		CL_NS(store)::Directory* getDirectory() { return directory; }\n" +
2054
            "    		CL_NS(store)::Directory* getDirectory() { return directory; }\n" +
2060
            "};\n"
2055
            "};\n"
2061
            );
2056
            );
2057
        setDefaultsOptions();
2058
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2059
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2062
        reformat();
2060
        reformat();
2063
        assertDocumentText("Incorrect identing multyline constructor",
2061
        assertDocumentText("Incorrect identing multyline constructor",
2064
            "class IndexReader : LUCENE_BASE\n" +
2062
            "class IndexReader : LUCENE_BASE\n" +
Lines 2072-2081 Link Here
2072
    }
2070
    }
2073
2071
2074
    public void testIdentInlineMethod2() {
2072
    public void testIdentInlineMethod2() {
2075
        setDefaultsOptions();
2076
        setLoadDocumentText(
2073
        setLoadDocumentText(
2077
            "    		CL_NS(store)::Directory* getDirectory() { return directory; }\n"
2074
            "    		CL_NS(store)::Directory* getDirectory() { return directory; }\n"
2078
            );
2075
            );
2076
        setDefaultsOptions();
2079
        reformat();
2077
        reformat();
2080
        assertDocumentText("Incorrect identing multyline constructor",
2078
        assertDocumentText("Incorrect identing multyline constructor",
2081
            "CL_NS(store)::Directory* getDirectory()\n" +
2079
            "CL_NS(store)::Directory* getDirectory()\n" +
Lines 2088-2094 Link Here
2088
    // end line comment should prevent move left brace on same line by design
2086
    // end line comment should prevent move left brace on same line by design
2089
    // RFE: move brace before end line comment in future
2087
    // RFE: move brace before end line comment in future
2090
    public void testBraceBeforeLineComment() {
2088
    public void testBraceBeforeLineComment() {
2091
        setDefaultsOptions();
2092
        setLoadDocumentText(
2089
        setLoadDocumentText(
2093
            "int foo()\n" +
2090
            "int foo()\n" +
2094
            "{\n" +
2091
            "{\n" +
Lines 2099-2104 Link Here
2099
            "}\n" +
2096
            "}\n" +
2100
            "}\n"
2097
            "}\n"
2101
            );
2098
            );
2099
        setDefaultsOptions();
2102
        reformat();
2100
        reformat();
2103
        assertDocumentText("Incorrect formatting brace before line comment",
2101
        assertDocumentText("Incorrect formatting brace before line comment",
2104
            "int foo()\n" +
2102
            "int foo()\n" +
Lines 2113-2119 Link Here
2113
    }
2111
    }
2114
2112
2115
    public void testCaseIndentAftePreprocessor() {
2113
    public void testCaseIndentAftePreprocessor() {
2116
        setDefaultsOptions();
2117
        setLoadDocumentText(
2114
        setLoadDocumentText(
2118
            "int foo() {\n" +
2115
            "int foo() {\n" +
2119
            "     switch (optid) {\n" +
2116
            "     switch (optid) {\n" +
Lines 2133-2138 Link Here
2133
            "}\n" +
2130
            "}\n" +
2134
            "}\n"
2131
            "}\n"
2135
            );
2132
            );
2133
        setDefaultsOptions();
2136
        reformat();
2134
        reformat();
2137
        assertDocumentText("Incorrect identing case after preprocessor",
2135
        assertDocumentText("Incorrect identing case after preprocessor",
2138
            "int foo()\n" +
2136
            "int foo()\n" +
Lines 2157-2165 Link Here
2157
    }
2155
    }
2158
2156
2159
    public void testCaseIndentAftePreprocessor2() {
2157
    public void testCaseIndentAftePreprocessor2() {
2160
        setDefaultsOptions();
2161
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2162
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2163
        setLoadDocumentText(
2158
        setLoadDocumentText(
2164
            "int foo() {\n" +
2159
            "int foo() {\n" +
2165
            "     switch (optid) {\n" +
2160
            "     switch (optid) {\n" +
Lines 2182-2187 Link Here
2182
            "}\n" +
2177
            "}\n" +
2183
            "}\n"
2178
            "}\n"
2184
            );
2179
            );
2180
        setDefaultsOptions();
2181
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2182
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2185
        reformat();
2183
        reformat();
2186
        assertDocumentText("Incorrect identing case after preprocessor",
2184
        assertDocumentText("Incorrect identing case after preprocessor",
2187
            "int foo()\n" +
2185
            "int foo()\n" +
Lines 2208-2224 Link Here
2208
        );
2206
        );
2209
    }
2207
    }
2210
    public void testCaseIndentAftePreprocessorHalf() {
2208
    public void testCaseIndentAftePreprocessorHalf() {
2211
        setDefaultsOptions();
2212
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2213
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2214
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2215
                putBoolean(EditorOptions.newLineElse, true);
2216
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2217
                put(EditorOptions.newLineBeforeBrace, 
2218
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2219
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2220
                put(EditorOptions.newLineBeforeBraceSwitch, 
2221
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2222
        setLoadDocumentText(
2209
        setLoadDocumentText(
2223
            "int foo() {\n" +
2210
            "int foo() {\n" +
2224
            "     switch (optid) {\n" +
2211
            "     switch (optid) {\n" +
Lines 2238-2243 Link Here
2238
            "}\n" +
2225
            "}\n" +
2239
            "}\n"
2226
            "}\n"
2240
            );
2227
            );
2228
        setDefaultsOptions();
2229
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2230
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2231
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2232
                putBoolean(EditorOptions.newLineElse, true);
2233
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2234
                put(EditorOptions.newLineBeforeBrace, 
2235
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2236
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2237
                put(EditorOptions.newLineBeforeBraceSwitch, 
2238
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2241
        reformat();
2239
        reformat();
2242
        assertDocumentText("Incorrect identing case after preprocessor",
2240
        assertDocumentText("Incorrect identing case after preprocessor",
2243
            "int foo()\n" +
2241
            "int foo()\n" +
Lines 2263-2277 Link Here
2263
    }
2261
    }
2264
2262
2265
    public void testCaseIndentAftePreprocessorHalf2() {
2263
    public void testCaseIndentAftePreprocessorHalf2() {
2266
        setDefaultsOptions();
2267
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2268
                putBoolean(EditorOptions.newLineElse, true);
2269
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2270
                put(EditorOptions.newLineBeforeBrace, 
2271
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2272
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2273
                put(EditorOptions.newLineBeforeBraceSwitch, 
2274
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2275
        setLoadDocumentText(
2264
        setLoadDocumentText(
2276
            "int foo() {\n" +
2265
            "int foo() {\n" +
2277
            "     switch (optid) {\n" +
2266
            "     switch (optid) {\n" +
Lines 2291-2296 Link Here
2291
            "}\n" +
2280
            "}\n" +
2292
            "}\n"
2281
            "}\n"
2293
            );
2282
            );
2283
        setDefaultsOptions();
2284
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2285
                putBoolean(EditorOptions.newLineElse, true);
2286
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2287
                put(EditorOptions.newLineBeforeBrace, 
2288
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2289
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2290
                put(EditorOptions.newLineBeforeBraceSwitch, 
2291
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2294
        reformat();
2292
        reformat();
2295
        assertDocumentText("Incorrect identing case after preprocessor",
2293
        assertDocumentText("Incorrect identing case after preprocessor",
2296
            "int foo()\n" +
2294
            "int foo()\n" +
Lines 2316-2322 Link Here
2316
    }
2314
    }
2317
2315
2318
    public void testTypedefClassNameIndent() {
2316
    public void testTypedefClassNameIndent() {
2319
        setDefaultsOptions();
2320
        setLoadDocumentText(
2317
        setLoadDocumentText(
2321
            "typedef struct st_line_buffer\n" +
2318
            "typedef struct st_line_buffer\n" +
2322
            "{\n" +
2319
            "{\n" +
Lines 2325-2330 Link Here
2325
            "/* The buffer itself, grown as needed. */\n" +
2322
            "/* The buffer itself, grown as needed. */\n" +
2326
            "}LINE_BUFFER;\n" 
2323
            "}LINE_BUFFER;\n" 
2327
            );
2324
            );
2325
        setDefaultsOptions();
2328
        reformat();
2326
        reformat();
2329
        assertDocumentText("Incorrect identing case after preprocessor",
2327
        assertDocumentText("Incorrect identing case after preprocessor",
2330
            "typedef struct st_line_buffer\n" +
2328
            "typedef struct st_line_buffer\n" +
Lines 2337-2343 Link Here
2337
    }
2335
    }
2338
2336
2339
    public void testLabelIndent() {
2337
    public void testLabelIndent() {
2340
        setDefaultsOptions();
2341
        setLoadDocumentText(
2338
        setLoadDocumentText(
2342
            "int foo()\n" +
2339
            "int foo()\n" +
2343
            "{\n" +
2340
            "{\n" +
Lines 2347-2352 Link Here
2347
            "    return error;\n" +
2344
            "    return error;\n" +
2348
            "}\n" 
2345
            "}\n" 
2349
            );
2346
            );
2347
        setDefaultsOptions();
2350
        reformat();
2348
        reformat();
2351
        assertDocumentText("Incorrect label indent",
2349
        assertDocumentText("Incorrect label indent",
2352
            "int foo()\n" +
2350
            "int foo()\n" +
Lines 2360-2366 Link Here
2360
    }
2358
    }
2361
2359
2362
    public void testIdentBlockAfterDirective() {
2360
    public void testIdentBlockAfterDirective() {
2363
        setDefaultsOptions();
2364
        setLoadDocumentText(
2361
        setLoadDocumentText(
2365
            "int yyparse()\n" +
2362
            "int yyparse()\n" +
2366
            "{\n" +
2363
            "{\n" +
Lines 2379-2384 Link Here
2379
            "}\n" +
2376
            "}\n" +
2380
            "}\n"
2377
            "}\n"
2381
            );
2378
            );
2379
        setDefaultsOptions();
2382
        reformat();
2380
        reformat();
2383
        assertDocumentText("Incorrect identing coode block after directive",
2381
        assertDocumentText("Incorrect identing coode block after directive",
2384
            "int yyparse()\n" +
2382
            "int yyparse()\n" +
Lines 2401-2409 Link Here
2401
    }
2399
    }
2402
2400
2403
    public void testMacroBeforePrepricessor() {
2401
    public void testMacroBeforePrepricessor() {
2404
        setDefaultsOptions();
2405
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2406
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2407
        setLoadDocumentText(
2402
        setLoadDocumentText(
2408
            "int yyparse()\n" +
2403
            "int yyparse()\n" +
2409
            "{\n" +
2404
            "{\n" +
Lines 2423-2428 Link Here
2423
            "}\n" +
2418
            "}\n" +
2424
            "}\n"
2419
            "}\n"
2425
            );
2420
            );
2421
        setDefaultsOptions();
2422
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2423
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2426
        reformat();
2424
        reformat();
2427
        assertDocumentText("Incorrect identing macro before preoprocessor",
2425
        assertDocumentText("Incorrect identing macro before preoprocessor",
2428
            "int yyparse()\n" +
2426
            "int yyparse()\n" +
Lines 2446-2454 Link Here
2446
    }
2444
    }
2447
2445
2448
    public void testIdentElseBeforePreprocessor() {
2446
    public void testIdentElseBeforePreprocessor() {
2449
        setDefaultsOptions();
2450
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2451
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2452
        setLoadDocumentText(
2447
        setLoadDocumentText(
2453
            "int yyparse()\n" +
2448
            "int yyparse()\n" +
2454
            "{\n" +
2449
            "{\n" +
Lines 2463-2468 Link Here
2463
            "}\n" +
2458
            "}\n" +
2464
            "}\n"
2459
            "}\n"
2465
            );
2460
            );
2461
        setDefaultsOptions();
2462
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2463
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
2466
        reformat();
2464
        reformat();
2467
        assertDocumentText("Incorrect identing else before preprocessor",
2465
        assertDocumentText("Incorrect identing else before preprocessor",
2468
            "int yyparse()\n" +
2466
            "int yyparse()\n" +
Lines 2481-2487 Link Here
2481
    }
2479
    }
2482
2480
2483
    public void testIdentK_and_R_style() {
2481
    public void testIdentK_and_R_style() {
2484
        setDefaultsOptions();
2485
        setLoadDocumentText(
2482
        setLoadDocumentText(
2486
            "static void\n" +
2483
            "static void\n" +
2487
            "win_init(newp, oldp)\n" +
2484
            "win_init(newp, oldp)\n" +
Lines 2491-2496 Link Here
2491
            "    int i;\n" +
2488
            "    int i;\n" +
2492
            "}\n"
2489
            "}\n"
2493
            );
2490
            );
2491
        setDefaultsOptions();
2494
        reformat();
2492
        reformat();
2495
        assertDocumentText("Incorrect identing K&R declaration",
2493
        assertDocumentText("Incorrect identing K&R declaration",
2496
            "static void\n" +
2494
            "static void\n" +
Lines 2504-2512 Link Here
2504
    }
2502
    }
2505
2503
2506
    public void testIdentK_and_R_style2() {
2504
    public void testIdentK_and_R_style2() {
2507
        setDefaultsOptions();
2508
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2509
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2510
        setLoadDocumentText(
2505
        setLoadDocumentText(
2511
            "extern \"C\" {\n" +
2506
            "extern \"C\" {\n" +
2512
            "static void\n" +
2507
            "static void\n" +
Lines 2518-2523 Link Here
2518
            "}\n" +
2513
            "}\n" +
2519
            "}\n"
2514
            "}\n"
2520
            );
2515
            );
2516
        setDefaultsOptions();
2517
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2518
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2521
        reformat();
2519
        reformat();
2522
        assertDocumentText("Incorrect identing multyline constructor",
2520
        assertDocumentText("Incorrect identing multyline constructor",
2523
            "extern \"C\"\n" +
2521
            "extern \"C\"\n" +
Lines 2534-2542 Link Here
2534
    }
2532
    }
2535
2533
2536
    public void testIdentInBlockComment() {
2534
    public void testIdentInBlockComment() {
2537
        setDefaultsOptions();
2538
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2539
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2540
        setLoadDocumentText(
2535
        setLoadDocumentText(
2541
            "extern \"C\" {\n" +
2536
            "extern \"C\" {\n" +
2542
            "static void\n" +
2537
            "static void\n" +
Lines 2560-2565 Link Here
2560
            "}\n" +
2555
            "}\n" +
2561
            "}\n"
2556
            "}\n"
2562
            );
2557
            );
2558
        setDefaultsOptions();
2559
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2560
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2563
        reformat();
2561
        reformat();
2564
        assertDocumentText("Incorrect identing in block comment",
2562
        assertDocumentText("Incorrect identing in block comment",
2565
            "extern \"C\"\n" +
2563
            "extern \"C\"\n" +
Lines 2588-2596 Link Here
2588
    }
2586
    }
2589
2587
2590
    public void testIdentInBlockComment2() {
2588
    public void testIdentInBlockComment2() {
2591
        setDefaultsOptions();
2592
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2593
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2594
        setLoadDocumentText(
2589
        setLoadDocumentText(
2595
            "extern \"C\" {\n" +
2590
            "extern \"C\" {\n" +
2596
            "static void\n" +
2591
            "static void\n" +
Lines 2614-2619 Link Here
2614
            "}\n" +
2609
            "}\n" +
2615
            "}\n"
2610
            "}\n"
2616
            );
2611
            );
2612
        setDefaultsOptions();
2613
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2614
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2617
        reformat();
2615
        reformat();
2618
        assertDocumentText("Incorrect identing in block comment",
2616
        assertDocumentText("Incorrect identing in block comment",
2619
            "extern \"C\"\n" +
2617
            "extern \"C\"\n" +
Lines 2643-2649 Link Here
2643
    }
2641
    }
2644
2642
2645
    public void testAddNewLineAfterSemocolon() {
2643
    public void testAddNewLineAfterSemocolon() {
2646
        setDefaultsOptions();
2647
        setLoadDocumentText(
2644
        setLoadDocumentText(
2648
            "int foo(int i)\n" +
2645
            "int foo(int i)\n" +
2649
            "{\n" +
2646
            "{\n" +
Lines 2656-2661 Link Here
2656
            "}\n"
2653
            "}\n"
2657
            );
2654
            );
2658
        reformat();
2655
        reformat();
2656
        setDefaultsOptions();
2659
        assertDocumentText("Incorrect adding new line after semocolon",
2657
        assertDocumentText("Incorrect adding new line after semocolon",
2660
            "int foo(int i)\n" +
2658
            "int foo(int i)\n" +
2661
            "{\n" +
2659
            "{\n" +
Lines 2675-2686 Link Here
2675
    }
2673
    }
2676
2674
2677
    public void testAddNewLineAfterSemocolon2() {
2675
    public void testAddNewLineAfterSemocolon2() {
2678
        setDefaultsOptions();
2679
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2680
                putBoolean(EditorOptions.newLineElse, true);
2681
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2682
                put(EditorOptions.newLineBeforeBrace, 
2683
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2684
        setLoadDocumentText(
2676
        setLoadDocumentText(
2685
            "int foo(int i)\n" +
2677
            "int foo(int i)\n" +
2686
            "{\n" +
2678
            "{\n" +
Lines 2692-2697 Link Here
2692
            " else {break;}\n" +
2684
            " else {break;}\n" +
2693
            "}\n"
2685
            "}\n"
2694
            );
2686
            );
2687
        setDefaultsOptions();
2688
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2689
                putBoolean(EditorOptions.newLineElse, true);
2690
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2691
                put(EditorOptions.newLineBeforeBrace, 
2692
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
2695
        reformat();
2693
        reformat();
2696
        assertDocumentText("Incorrect adding new line after semocolon",
2694
        assertDocumentText("Incorrect adding new line after semocolon",
2697
            "int foo(int i)\n" +
2695
            "int foo(int i)\n" +
Lines 2713-2719 Link Here
2713
    }
2711
    }
2714
2712
2715
    public void testIdentFunctionDefinition() {
2713
    public void testIdentFunctionDefinition() {
2716
        setDefaultsOptions();
2717
        setLoadDocumentText(
2714
        setLoadDocumentText(
2718
            "uchar *\n" +
2715
            "uchar *\n" +
2719
            "        tokname(int n)\n" +
2716
            "        tokname(int n)\n" +
Lines 2722-2727 Link Here
2722
            "    return printname[n - 257];\n" +
2719
            "    return printname[n - 257];\n" +
2723
            "}\n"
2720
            "}\n"
2724
            );
2721
            );
2722
        setDefaultsOptions();
2725
        reformat();
2723
        reformat();
2726
        assertDocumentText("Incorrect identing function definition",
2724
        assertDocumentText("Incorrect identing function definition",
2727
            "uchar *\n" +
2725
            "uchar *\n" +
Lines 2735-2743 Link Here
2735
    
2733
    
2736
2734
2737
    public void testIdentFunctionDefinition2() {
2735
    public void testIdentFunctionDefinition2() {
2738
        setDefaultsOptions();
2739
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
2740
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2741
        setLoadDocumentText(
2736
        setLoadDocumentText(
2742
            "namespace A\n" +
2737
            "namespace A\n" +
2743
            "{\n" +
2738
            "{\n" +
Lines 2749-2754 Link Here
2749
            "}\n"+
2744
            "}\n"+
2750
            "}\n"
2745
            "}\n"
2751
            );
2746
            );
2747
        setDefaultsOptions();
2748
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
2749
                putInt(EditorOptions.blankLinesBeforeMethods, 0);
2752
        reformat();
2750
        reformat();
2753
        assertDocumentText("Incorrect identing function definition",
2751
        assertDocumentText("Incorrect identing function definition",
2754
            "namespace A\n" +
2752
            "namespace A\n" +
Lines 2764-2770 Link Here
2764
    }
2762
    }
2765
    
2763
    
2766
    public void testIdentElseAfterPreprocessor() {
2764
    public void testIdentElseAfterPreprocessor() {
2767
        setDefaultsOptions();
2768
        setLoadDocumentText(
2765
        setLoadDocumentText(
2769
            "getcmdline(int firstc)\n" +
2766
            "getcmdline(int firstc)\n" +
2770
            "{\n" +
2767
            "{\n" +
Lines 2780-2785 Link Here
2780
            "#endif\n" +
2777
            "#endif\n" +
2781
            "}\n"
2778
            "}\n"
2782
            );
2779
            );
2780
        setDefaultsOptions();
2783
        reformat();
2781
        reformat();
2784
        assertDocumentText("Incorrect identing else after preprocessor",
2782
        assertDocumentText("Incorrect identing else after preprocessor",
2785
            "getcmdline(int firstc)\n" +
2783
            "getcmdline(int firstc)\n" +
Lines 2798-2804 Link Here
2798
    }
2796
    }
2799
2797
2800
    public void testBlankLineBeforeMethod() {
2798
    public void testBlankLineBeforeMethod() {
2801
        setDefaultsOptions();
2802
        setLoadDocumentText(
2799
        setLoadDocumentText(
2803
                "int foo()\n" +
2800
                "int foo()\n" +
2804
                "{\n" +
2801
                "{\n" +
Lines 2812-2817 Link Here
2812
                "{\n" +
2809
                "{\n" +
2813
                "}\n"
2810
                "}\n"
2814
                );
2811
                );
2812
        setDefaultsOptions();
2815
        reformat();
2813
        reformat();
2816
        assertDocumentText("Incorrect blank line before method",
2814
        assertDocumentText("Incorrect blank line before method",
2817
                "int foo()\n" +
2815
                "int foo()\n" +
Lines 2830-2836 Link Here
2830
    }
2828
    }
2831
2829
2832
    public void testBlockCodeNewLine() {
2830
    public void testBlockCodeNewLine() {
2833
        setDefaultsOptions();
2834
        setLoadDocumentText(
2831
        setLoadDocumentText(
2835
                "int foo()\n" +
2832
                "int foo()\n" +
2836
                "{\n" +
2833
                "{\n" +
Lines 2843-2848 Link Here
2843
                "  }\n" +
2840
                "  }\n" +
2844
                "}\n"
2841
                "}\n"
2845
                );
2842
                );
2843
        setDefaultsOptions();
2846
        reformat();
2844
        reformat();
2847
        assertDocumentText("Incorrect block code new line",
2845
        assertDocumentText("Incorrect block code new line",
2848
                "int foo()\n" +
2846
                "int foo()\n" +
Lines 2861-2867 Link Here
2861
    }
2859
    }
2862
2860
2863
    public void testBlankLineAfterEndLineComment() {
2861
    public void testBlankLineAfterEndLineComment() {
2864
        setDefaultsOptions();
2865
        setLoadDocumentText(
2862
        setLoadDocumentText(
2866
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
2863
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
2867
                "{\n" +
2864
                "{\n" +
Lines 2875-2880 Link Here
2875
                "    return next;\n" +
2872
                "    return next;\n" +
2876
                "}//Ndb::getConnectedNdbTransaction()\n"
2873
                "}//Ndb::getConnectedNdbTransaction()\n"
2877
                );
2874
                );
2875
        setDefaultsOptions();
2878
        reformat();
2876
        reformat();
2879
        assertDocumentText("Incorrect blak line after end line comment",
2877
        assertDocumentText("Incorrect blak line after end line comment",
2880
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
2878
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
Lines 2894-2900 Link Here
2894
    
2892
    
2895
    
2893
    
2896
    public void testReformatCodeBlocks() {
2894
    public void testReformatCodeBlocks() {
2897
        setDefaultsOptions();
2898
        setLoadDocumentText(
2895
        setLoadDocumentText(
2899
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
2896
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
2900
                "{\n" +
2897
                "{\n" +
Lines 2918-2923 Link Here
2918
                "    }//if\n" +
2915
                "    }//if\n" +
2919
                "}//Ndb::getConnectedNdbTransaction()\n"
2916
                "}//Ndb::getConnectedNdbTransaction()\n"
2920
                );
2917
                );
2918
        setDefaultsOptions();
2921
        reformat();
2919
        reformat();
2922
        assertDocumentText("Incorrect code block formatting",
2920
        assertDocumentText("Incorrect code block formatting",
2923
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
2921
                "int Ndb::NDB_connect(Uint32 tNode)\n" +
Lines 2946-2952 Link Here
2946
    }
2944
    }
2947
2945
2948
    public void testSpaceBinaryOperator() {
2946
    public void testSpaceBinaryOperator() {
2949
        setDefaultsOptions();
2950
        setLoadDocumentText(
2947
        setLoadDocumentText(
2951
            "int foo()\n" +
2948
            "int foo()\n" +
2952
            "{\n" +
2949
            "{\n" +
Lines 2960-2965 Link Here
2960
            "    return(0);\n" +
2957
            "    return(0);\n" +
2961
            "}\n"
2958
            "}\n"
2962
            );
2959
            );
2960
        setDefaultsOptions();
2963
        reformat();
2961
        reformat();
2964
        assertDocumentText("Incorrect spaces in binary operators",
2962
        assertDocumentText("Incorrect spaces in binary operators",
2965
            "int foo()\n" +
2963
            "int foo()\n" +
Lines 2977-2983 Link Here
2977
    }
2975
    }
2978
2976
2979
    public void testSpaceBinaryOperator2() {
2977
    public void testSpaceBinaryOperator2() {
2980
        setDefaultsOptions();
2981
        setLoadDocumentText(
2978
        setLoadDocumentText(
2982
            "int foo()\n" +
2979
            "int foo()\n" +
2983
            "{\n" +
2980
            "{\n" +
Lines 2986-2991 Link Here
2986
            "            ((nc_result.end()-str1.begin()) == 6));\n" +
2983
            "            ((nc_result.end()-str1.begin()) == 6));\n" +
2987
            "}\n"
2984
            "}\n"
2988
            );
2985
            );
2986
        setDefaultsOptions();
2989
        reformat();
2987
        reformat();
2990
        assertDocumentText("Incorrect spaces in binary operators",
2988
        assertDocumentText("Incorrect spaces in binary operators",
2991
            "int foo()\n" +
2989
            "int foo()\n" +
Lines 2998-3010 Link Here
2998
    }
2996
    }
2999
2997
3000
    public void testSpaceTemplateSeparator() {
2998
    public void testSpaceTemplateSeparator() {
3001
        setDefaultsOptions();
3002
        setLoadDocumentText(
2999
        setLoadDocumentText(
3003
            "int foo()\n" +
3000
            "int foo()\n" +
3004
            "{\n" +
3001
            "{\n" +
3005
            "    vector<string> tokens1;\n" +
3002
            "    vector<string> tokens1;\n" +
3006
            "}\n"
3003
            "}\n"
3007
            );
3004
            );
3005
        setDefaultsOptions();
3008
        reformat();
3006
        reformat();
3009
        assertDocumentText("Incorrect spaces before template separator",
3007
        assertDocumentText("Incorrect spaces before template separator",
3010
            "int foo()\n" +
3008
            "int foo()\n" +
Lines 3015-3023 Link Here
3015
    }
3013
    }
3016
3014
3017
    public void testSpaceCastOperator() {
3015
    public void testSpaceCastOperator() {
3018
        setDefaultsOptions();
3019
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3020
                putBoolean(EditorOptions.spaceWithinTypeCastParens, true);
3021
        setLoadDocumentText(
3016
        setLoadDocumentText(
3022
            "int foo()\n" +
3017
            "int foo()\n" +
3023
            "{\n" +
3018
            "{\n" +
Lines 3030-3035 Link Here
3030
            "    put_short(s, (ush)~len);\n" +
3025
            "    put_short(s, (ush)~len);\n" +
3031
            "}\n"
3026
            "}\n"
3032
            );
3027
            );
3028
        setDefaultsOptions();
3029
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3030
                putBoolean(EditorOptions.spaceWithinTypeCastParens, true);
3033
        reformat();
3031
        reformat();
3034
        assertDocumentText("Incorrect spaces in cast operators",
3032
        assertDocumentText("Incorrect spaces in cast operators",
3035
            "int foo()\n" +
3033
            "int foo()\n" +
Lines 3046-3058 Link Here
3046
    }
3044
    }
3047
3045
3048
    public void testNoSpaceBeforeUnaryOperator() {
3046
    public void testNoSpaceBeforeUnaryOperator() {
3049
        setDefaultsOptions();
3050
        setLoadDocumentText(
3047
        setLoadDocumentText(
3051
            "int foo()\n" +
3048
            "int foo()\n" +
3052
            "{\n" +
3049
            "{\n" +
3053
            "    if (s == NULL ||| s->mode != 'r') return - 1;\n" +
3050
            "    if (s == NULL ||| s->mode != 'r') return - 1;\n" +
3054
            "}\n"
3051
            "}\n"
3055
            );
3052
            );
3053
        setDefaultsOptions();
3056
        reformat();
3054
        reformat();
3057
        assertDocumentText("Incorrect no space before unary operator",
3055
        assertDocumentText("Incorrect no space before unary operator",
3058
            "int foo()\n" +
3056
            "int foo()\n" +
Lines 3063-3069 Link Here
3063
    }
3061
    }
3064
3062
3065
    public void testNoEscapedSpaceSupport() {
3063
    public void testNoEscapedSpaceSupport() {
3066
        setDefaultsOptions();
3067
        setLoadDocumentText(
3064
        setLoadDocumentText(
3068
                "static const char* _dbname = \"TEST_DB\";\n" +
3065
                "static const char* _dbname = \"TEST_DB\";\n" +
3069
                "static void usage()\n" +
3066
                "static void usage()\n" +
Lines 3074-3079 Link Here
3074
                "    ndb_std_print_version();\n" +
3071
                "    ndb_std_print_version();\n" +
3075
                "}\n"
3072
                "}\n"
3076
                );
3073
                );
3074
        setDefaultsOptions();
3077
        reformat();
3075
        reformat();
3078
        assertDocumentText("Incorrect escaped space",
3076
        assertDocumentText("Incorrect escaped space",
3079
                "static const char* _dbname = \"TEST_DB\";\n" +
3077
                "static const char* _dbname = \"TEST_DB\";\n" +
Lines 3089-3095 Link Here
3089
    }
3087
    }
3090
 
3088
 
3091
    public void testIfDoWhile() {
3089
    public void testIfDoWhile() {
3092
        setDefaultsOptions();
3093
        setLoadDocumentText(
3090
        setLoadDocumentText(
3094
                "void foo()\n" +
3091
                "void foo()\n" +
3095
                "{\n" +
3092
                "{\n" +
Lines 3098-3103 Link Here
3098
                "    } while (--len);\n" +
3095
                "    } while (--len);\n" +
3099
                "}\n"
3096
                "}\n"
3100
                );
3097
                );
3098
        setDefaultsOptions();
3101
        reformat();
3099
        reformat();
3102
        assertDocumentText("Incorrect if-do-while indent",
3100
        assertDocumentText("Incorrect if-do-while indent",
3103
                "void foo()\n" +
3101
                "void foo()\n" +
Lines 3110-3116 Link Here
3110
    }
3108
    }
3111
3109
3112
    public void testIfIfDoWhile() {
3110
    public void testIfIfDoWhile() {
3113
        setDefaultsOptions();
3114
        setLoadDocumentText(
3111
        setLoadDocumentText(
3115
                "void foo()\n" +
3112
                "void foo()\n" +
3116
                "{\n" +
3113
                "{\n" +
Lines 3121-3126 Link Here
3121
                "    else return;\n" +
3118
                "    else return;\n" +
3122
                "}\n"
3119
                "}\n"
3123
                );
3120
                );
3121
        setDefaultsOptions();
3124
        reformat();
3122
        reformat();
3125
        assertDocumentText("Incorrect if-if-do-while indent",
3123
        assertDocumentText("Incorrect if-if-do-while indent",
3126
                "void foo()\n" +
3124
                "void foo()\n" +
Lines 3135-3141 Link Here
3135
    }
3133
    }
3136
3134
3137
    public void testDoubleFunctionComment() {
3135
    public void testDoubleFunctionComment() {
3138
        setDefaultsOptions();
3139
        setLoadDocumentText(
3136
        setLoadDocumentText(
3140
                "void foo();\n" +
3137
                "void foo();\n" +
3141
                "/* Stream status */\n" +
3138
                "/* Stream status */\n" +
Lines 3145-3150 Link Here
3145
                "    ush code;\n" +
3142
                "    ush code;\n" +
3146
                "} FAR ct_data;\n"
3143
                "} FAR ct_data;\n"
3147
                );
3144
                );
3145
        setDefaultsOptions();
3148
        reformat();
3146
        reformat();
3149
        assertDocumentText("Incorrect blank lines between block comments",
3147
        assertDocumentText("Incorrect blank lines between block comments",
3150
                "void foo();\n" +
3148
                "void foo();\n" +
Lines 3159-3165 Link Here
3159
    }
3157
    }
3160
3158
3161
    public void testArrayAsParameter() {
3159
    public void testArrayAsParameter() {
3162
        setDefaultsOptions();
3163
        setLoadDocumentText(
3160
        setLoadDocumentText(
3164
                "class ClassA : InterfaceA, InterfaceB, InterfaceC\n" +
3161
                "class ClassA : InterfaceA, InterfaceB, InterfaceC\n" +
3165
                "{\n" +
3162
                "{\n" +
Lines 3171-3176 Link Here
3171
                "    }\n" +
3168
                "    }\n" +
3172
                "} FAR ct_data;\n"
3169
                "} FAR ct_data;\n"
3173
                );
3170
                );
3171
        setDefaultsOptions();
3174
        reformat();
3172
        reformat();
3175
        assertDocumentText("Incorrect formatting of array as parameter",
3173
        assertDocumentText("Incorrect formatting of array as parameter",
3176
                "class ClassA : InterfaceA, InterfaceB, InterfaceC\n" +
3174
                "class ClassA : InterfaceA, InterfaceB, InterfaceC\n" +
Lines 3187-3195 Link Here
3187
    }
3185
    }
3188
3186
3189
    public void testArrayAsParameter2() {
3187
    public void testArrayAsParameter2() {
3190
        setDefaultsOptions();
3191
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3192
                putBoolean(EditorOptions.indentNamespace, false);
3193
        setLoadDocumentText(
3188
        setLoadDocumentText(
3194
                "namespace AC\n" +
3189
                "namespace AC\n" +
3195
                "{\n" +
3190
                "{\n" +
Lines 3204-3209 Link Here
3204
                "} FAR ct_data;\n" +
3199
                "} FAR ct_data;\n" +
3205
                "}\n"
3200
                "}\n"
3206
                );
3201
                );
3202
        setDefaultsOptions();
3203
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3204
                putBoolean(EditorOptions.indentNamespace, false);
3207
        reformat();
3205
        reformat();
3208
        assertDocumentText("Incorrect formatting of array as parameter",
3206
        assertDocumentText("Incorrect formatting of array as parameter",
3209
                "namespace AC\n" +
3207
                "namespace AC\n" +
Lines 3224-3235 Link Here
3224
    }
3222
    }
3225
3223
3226
    public void testIssue129747() {
3224
    public void testIssue129747() {
3227
        setDefaultsOptions();
3228
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3229
                putBoolean(EditorOptions.indentNamespace, false);
3230
        setLoadDocumentText(
3225
        setLoadDocumentText(
3231
                "enum CpuArch { OPTERON, INTEL, SPARC}; // CPU architecture\n"
3226
                "enum CpuArch { OPTERON, INTEL, SPARC}; // CPU architecture\n"
3232
                );
3227
                );
3228
        setDefaultsOptions();
3229
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3230
                putBoolean(EditorOptions.indentNamespace, false);
3233
        reformat();
3231
        reformat();
3234
        assertDocumentText("Issue 129747",
3232
        assertDocumentText("Issue 129747",
3235
                "enum CpuArch\n" +
3233
                "enum CpuArch\n" +
Lines 3240-3248 Link Here
3240
    }
3238
    }
3241
3239
3242
    public void tesIssue129608() {
3240
    public void tesIssue129608() {
3243
        setDefaultsOptions();
3244
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3245
                putBoolean(EditorOptions.indentNamespace, false);
3246
        setLoadDocumentText(
3241
        setLoadDocumentText(
3247
                "int foo()\n" +
3242
                "int foo()\n" +
3248
                "{\n" +
3243
                "{\n" +
Lines 3254-3259 Link Here
3254
                "};\n" +
3249
                "};\n" +
3255
                "}\n"
3250
                "}\n"
3256
                );
3251
                );
3252
        setDefaultsOptions();
3253
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3254
                putBoolean(EditorOptions.indentNamespace, false);
3257
        reformat();
3255
        reformat();
3258
        assertDocumentText("Issue 129608",
3256
        assertDocumentText("Issue 129608",
3259
                "int foo()\n" +
3257
                "int foo()\n" +
Lines 3268-3274 Link Here
3268
    }
3266
    }
3269
3267
3270
    public void testReformatIfElseElse() {
3268
    public void testReformatIfElseElse() {
3271
        setDefaultsOptions();
3272
        setLoadDocumentText(
3269
        setLoadDocumentText(
3273
                "int method()\n" +
3270
                "int method()\n" +
3274
                "{\n" +
3271
                "{\n" +
Lines 3280-3285 Link Here
3280
                "        number++;\n" +
3277
                "        number++;\n" +
3281
                "  }\n" +
3278
                "  }\n" +
3282
                "}\n");
3279
                "}\n");
3280
        setDefaultsOptions();
3283
        reformat();
3281
        reformat();
3284
        assertDocumentText("Incorrect indent if-else if-else",
3282
        assertDocumentText("Incorrect indent if-else if-else",
3285
                 "int method()\n" +
3283
                 "int method()\n" +
Lines 3295-3306 Link Here
3295
    }
3293
    }
3296
3294
3297
    public void testHalfIndent() {
3295
    public void testHalfIndent() {
3298
        setDefaultsOptions();
3299
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3300
                putBoolean(EditorOptions.newLineElse, true);
3301
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3302
                put(EditorOptions.newLineBeforeBrace, 
3303
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3304
        setLoadDocumentText(
3296
        setLoadDocumentText(
3305
                "int method()\n" +
3297
                "int method()\n" +
3306
                "{\n" +
3298
                "{\n" +
Lines 3311-3316 Link Here
3311
                "    else\n" +
3303
                "    else\n" +
3312
                "        number++;\n" +
3304
                "        number++;\n" +
3313
                "}\n");
3305
                "}\n");
3306
        setDefaultsOptions();
3307
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3308
                putBoolean(EditorOptions.newLineElse, true);
3309
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3310
                put(EditorOptions.newLineBeforeBrace, 
3311
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3314
        reformat();
3312
        reformat();
3315
        assertDocumentText("Incorrect block half indent",
3313
        assertDocumentText("Incorrect block half indent",
3316
                 "int method()\n" +
3314
                 "int method()\n" +
Lines 3325-3339 Link Here
3325
    }
3323
    }
3326
3324
3327
    public void testHalfIndentFull() {
3325
    public void testHalfIndentFull() {
3328
        setDefaultsOptions();
3329
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3330
                putBoolean(EditorOptions.newLineElse, true);
3331
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3332
                put(EditorOptions.newLineBeforeBrace, 
3333
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3334
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3335
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3336
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3337
        setLoadDocumentText(
3326
        setLoadDocumentText(
3338
                "int method()\n" +
3327
                "int method()\n" +
3339
                "{\n" +
3328
                "{\n" +
Lines 3344-3349 Link Here
3344
                "    else\n" +
3333
                "    else\n" +
3345
                "        number++;\n" +
3334
                "        number++;\n" +
3346
                "}\n");
3335
                "}\n");
3336
        setDefaultsOptions();
3337
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3338
                putBoolean(EditorOptions.newLineElse, true);
3339
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3340
                put(EditorOptions.newLineBeforeBrace, 
3341
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3342
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3343
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3344
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3347
        reformat();
3345
        reformat();
3348
        assertDocumentText("Incorrect block half indent",
3346
        assertDocumentText("Incorrect block half indent",
3349
                 "int method()\n" +
3347
                 "int method()\n" +
Lines 3358-3369 Link Here
3358
    }
3356
    }
3359
3357
3360
    public void testHalfIndent2() {
3358
    public void testHalfIndent2() {
3361
        setDefaultsOptions();
3362
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3363
                putBoolean(EditorOptions.newLineElse, true);
3364
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3365
                put(EditorOptions.newLineBeforeBrace, 
3366
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3367
        setLoadDocumentText(
3359
        setLoadDocumentText(
3368
                "int method()\n" +
3360
                "int method()\n" +
3369
                "{\n" +
3361
                "{\n" +
Lines 3375-3380 Link Here
3375
                "        number++;\n" +
3367
                "        number++;\n" +
3376
                "  }\n" +
3368
                "  }\n" +
3377
                "}\n");
3369
                "}\n");
3370
        setDefaultsOptions();
3371
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3372
                putBoolean(EditorOptions.newLineElse, true);
3373
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3374
                put(EditorOptions.newLineBeforeBrace, 
3375
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3378
        reformat();
3376
        reformat();
3379
        assertDocumentText("Incorrect block half indent",
3377
        assertDocumentText("Incorrect block half indent",
3380
                 "int method()\n" +
3378
                 "int method()\n" +
Lines 3395-3409 Link Here
3395
    }
3393
    }
3396
3394
3397
    public void testHalfIndent2Full() {
3395
    public void testHalfIndent2Full() {
3398
        setDefaultsOptions();
3399
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3400
                putBoolean(EditorOptions.newLineElse, true);
3401
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3402
                put(EditorOptions.newLineBeforeBrace, 
3403
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3404
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3405
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3406
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3407
        setLoadDocumentText(
3396
        setLoadDocumentText(
3408
                "int method()\n" +
3397
                "int method()\n" +
3409
                "{\n" +
3398
                "{\n" +
Lines 3415-3420 Link Here
3415
                "        number++;\n" +
3404
                "        number++;\n" +
3416
                "  }\n" +
3405
                "  }\n" +
3417
                "}\n");
3406
                "}\n");
3407
        setDefaultsOptions();
3408
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3409
                putBoolean(EditorOptions.newLineElse, true);
3410
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3411
                put(EditorOptions.newLineBeforeBrace, 
3412
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3413
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3414
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3415
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3418
        reformat();
3416
        reformat();
3419
        assertDocumentText("Incorrect block half indent",
3417
        assertDocumentText("Incorrect block half indent",
3420
                 "int method()\n" +
3418
                 "int method()\n" +
Lines 3435-3449 Link Here
3435
    }
3433
    }
3436
3434
3437
    public void testDoWhileHalf() {
3435
    public void testDoWhileHalf() {
3438
        setDefaultsOptions();
3439
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3440
                putBoolean(EditorOptions.newLineWhile, true);
3441
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3442
                put(EditorOptions.newLineBeforeBrace, 
3443
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3444
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3445
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3446
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3447
        setLoadDocumentText(
3436
        setLoadDocumentText(
3448
                "int main(int i)\n" +
3437
                "int main(int i)\n" +
3449
                "{\n" +
3438
                "{\n" +
Lines 3459-3466 Link Here
3459
                "   while (this.number < 2 &&\n" +
3448
                "   while (this.number < 2 &&\n" +
3460
                "   number != 3);\n" +
3449
                "   number != 3);\n" +
3461
                "}\n");
3450
                "}\n");
3462
3451
        setDefaultsOptions();
3463
        
3452
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3453
                putBoolean(EditorOptions.newLineWhile, true);
3454
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3455
                put(EditorOptions.newLineBeforeBrace, 
3456
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3457
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3458
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3459
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3464
        reformat();
3460
        reformat();
3465
        assertDocumentText("Incorrect formatting half do-while",
3461
        assertDocumentText("Incorrect formatting half do-while",
3466
                "int main(int i)\n" +
3462
                "int main(int i)\n" +
Lines 3480-3500 Link Here
3480
    }
3476
    }
3481
3477
3482
    public void testDoWhileHalf2() {
3478
    public void testDoWhileHalf2() {
3483
        setDefaultsOptions();
3484
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3485
                putBoolean(EditorOptions.newLineWhile, true);
3486
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3487
                put(EditorOptions.newLineBeforeBrace, 
3488
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3489
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3490
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3491
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3492
        setLoadDocumentText(
3479
        setLoadDocumentText(
3493
                "int foo() {\n" +
3480
                "int foo() {\n" +
3494
                "do {\n" +
3481
                "do {\n" +
3495
                "    i++;\n" +
3482
                "    i++;\n" +
3496
                "} while(true);\n" +
3483
                "} while(true);\n" +
3497
                "}\n");
3484
                "}\n");
3485
        setDefaultsOptions();
3486
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3487
                putBoolean(EditorOptions.newLineWhile, true);
3488
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3489
                put(EditorOptions.newLineBeforeBrace, 
3490
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3491
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3492
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3493
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3498
        reformat();
3494
        reformat();
3499
        assertDocumentText("Incorrect formatting do-while half indent",
3495
        assertDocumentText("Incorrect formatting do-while half indent",
3500
                "int foo()\n" +
3496
                "int foo()\n" +
Lines 3508-3520 Link Here
3508
    }
3504
    }
3509
3505
3510
    public void testDereferenceAfterIf() {
3506
    public void testDereferenceAfterIf() {
3511
        setDefaultsOptions();
3512
        setLoadDocumentText(
3507
        setLoadDocumentText(
3513
                "int main(int i)\n" +
3508
                "int main(int i)\n" +
3514
                "{\n" +
3509
                "{\n" +
3515
                "if (offset)\n" +
3510
                "if (offset)\n" +
3516
                "    *offset = layout->record_size/ BITS_PER_UNIT;\n" +
3511
                "    *offset = layout->record_size/ BITS_PER_UNIT;\n" +
3517
                "}\n");
3512
                "}\n");
3513
        setDefaultsOptions();
3518
        reformat();
3514
        reformat();
3519
        assertDocumentText("Incorrect space for dereference after if",
3515
        assertDocumentText("Incorrect space for dereference after if",
3520
                "int main(int i)\n" +
3516
                "int main(int i)\n" +
Lines 3525-3539 Link Here
3525
    }
3521
    }
3526
3522
3527
    public void testTryCatchHalf() {
3523
    public void testTryCatchHalf() {
3528
        setDefaultsOptions();
3529
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3530
                putBoolean(EditorOptions.newLineCatch, true);
3531
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3532
                put(EditorOptions.newLineBeforeBrace, 
3533
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3534
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3535
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3536
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3537
        setLoadDocumentText(
3524
        setLoadDocumentText(
3538
                "int foo() {\n" +
3525
                "int foo() {\n" +
3539
                "try {\n" +
3526
                "try {\n" +
Lines 3549-3554 Link Here
3549
                " catch (char e){\n" +
3536
                " catch (char e){\n" +
3550
                "    i--;}\n" +
3537
                "    i--;}\n" +
3551
                "}\n");
3538
                "}\n");
3539
        setDefaultsOptions();
3540
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3541
                putBoolean(EditorOptions.newLineCatch, true);
3542
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3543
                put(EditorOptions.newLineBeforeBrace, 
3544
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3545
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3546
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3547
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3552
        reformat();
3548
        reformat();
3553
        assertDocumentText("Incorrect formatting try-catch half indent",
3549
        assertDocumentText("Incorrect formatting try-catch half indent",
3554
                "int foo()\n" +
3550
                "int foo()\n" +
Lines 3575-3589 Link Here
3575
    }
3571
    }
3576
3572
3577
    public void testEndLineComments() {
3573
    public void testEndLineComments() {
3578
        setDefaultsOptions();
3579
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3580
                putBoolean(EditorOptions.newLineCatch, true);
3581
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3582
                put(EditorOptions.newLineBeforeBrace, 
3583
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3584
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3585
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3586
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3587
        setLoadDocumentText(
3574
        setLoadDocumentText(
3588
                "int foo()\n" +
3575
                "int foo()\n" +
3589
                "{\n" +
3576
                "{\n" +
Lines 3596-3601 Link Here
3596
                "  else\n" +
3583
                "  else\n" +
3597
                "    DECL_VISIBILITY (decl) = VISIBILITY_PROTECTED;\n" +
3584
                "    DECL_VISIBILITY (decl) = VISIBILITY_PROTECTED;\n" +
3598
                "}\n");
3585
                "}\n");
3586
        setDefaultsOptions();
3587
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3588
                putBoolean(EditorOptions.newLineCatch, true);
3589
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3590
                put(EditorOptions.newLineBeforeBrace, 
3591
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3592
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3593
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3594
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3599
        reformat();
3595
        reformat();
3600
        assertDocumentText("Incorrect unexpected new line after semicolomn",
3596
        assertDocumentText("Incorrect unexpected new line after semicolomn",
3601
                "int foo()\n" +
3597
                "int foo()\n" +
Lines 3612-3624 Link Here
3612
    }
3608
    }
3613
3609
3614
    public void testLabelIndentHalf() {
3610
    public void testLabelIndentHalf() {
3615
        setDefaultsOptions();
3616
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3617
                put(EditorOptions.newLineBeforeBrace, 
3618
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3619
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3620
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3621
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3622
        setLoadDocumentText(
3611
        setLoadDocumentText(
3623
                "int foo()\n" +
3612
                "int foo()\n" +
3624
                "{\n" +
3613
                "{\n" +
Lines 3633-3638 Link Here
3633
                "}\n" +
3622
                "}\n" +
3634
                "}\n" +
3623
                "}\n" +
3635
                "}\n");
3624
                "}\n");
3625
        setDefaultsOptions();
3626
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3627
                put(EditorOptions.newLineBeforeBrace, 
3628
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3629
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3630
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3631
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3636
        reformat();
3632
        reformat();
3637
        assertDocumentText("Incorrect label half indent",
3633
        assertDocumentText("Incorrect label half indent",
3638
                "int foo()\n" +
3634
                "int foo()\n" +
Lines 3654-3668 Link Here
3654
    }
3650
    }
3655
3651
3656
    public void testLabelIndentHalf2() {
3652
    public void testLabelIndentHalf2() {
3657
        setDefaultsOptions();
3658
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3659
                putBoolean(EditorOptions.absoluteLabelIndent, false);
3660
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3661
                put(EditorOptions.newLineBeforeBrace, 
3662
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3663
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3664
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3665
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3666
        setLoadDocumentText(
3653
        setLoadDocumentText(
3667
                "int foo()\n" +
3654
                "int foo()\n" +
3668
                "{\n" +
3655
                "{\n" +
Lines 3677-3682 Link Here
3677
                "}\n" +
3664
                "}\n" +
3678
                "}\n" +
3665
                "}\n" +
3679
                "}\n");
3666
                "}\n");
3667
        setDefaultsOptions();
3668
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3669
                putBoolean(EditorOptions.absoluteLabelIndent, false);
3670
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3671
                put(EditorOptions.newLineBeforeBrace, 
3672
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3673
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3674
                put(EditorOptions.newLineBeforeBraceDeclaration, 
3675
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
3680
        reformat();
3676
        reformat();
3681
        assertDocumentText("Incorrect label half indent",
3677
        assertDocumentText("Incorrect label half indent",
3682
                "int foo()\n" +
3678
                "int foo()\n" +
Lines 3698-3706 Link Here
3698
    }
3694
    }
3699
3695
3700
    public void testLabelStatementIndent() {
3696
    public void testLabelStatementIndent() {
3701
        setDefaultsOptions();
3702
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3703
                putBoolean(EditorOptions.absoluteLabelIndent, false);
3704
        setLoadDocumentText(
3697
        setLoadDocumentText(
3705
                "int foo()\n" +
3698
                "int foo()\n" +
3706
                "{\n" +
3699
                "{\n" +
Lines 3715-3720 Link Here
3715
                "}\n" +
3708
                "}\n" +
3716
                "}\n" +
3709
                "}\n" +
3717
                "}\n");
3710
                "}\n");
3711
        setDefaultsOptions();
3712
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3713
                putBoolean(EditorOptions.absoluteLabelIndent, false);
3718
        reformat();
3714
        reformat();
3719
        assertDocumentText("Incorrect label indent",
3715
        assertDocumentText("Incorrect label indent",
3720
                "int foo()\n" +
3716
                "int foo()\n" +
Lines 3734-3740 Link Here
3734
    }
3730
    }
3735
3731
3736
    public void testOperatorEQformatting() {
3732
    public void testOperatorEQformatting() {
3737
        setDefaultsOptions();
3738
        setLoadDocumentText(
3733
        setLoadDocumentText(
3739
                "class real_c_float\n" +
3734
                "class real_c_float\n" +
3740
                "{\n" +
3735
                "{\n" +
Lines 3742-3747 Link Here
3742
                "    return *this;\n" +
3737
                "    return *this;\n" +
3743
                "  }\n" +
3738
                "  }\n" +
3744
                "};\n");
3739
                "};\n");
3740
        setDefaultsOptions();
3745
        reformat();
3741
        reformat();
3746
        assertDocumentText("Incorrect operator = formatting",
3742
        assertDocumentText("Incorrect operator = formatting",
3747
                "class real_c_float\n" +
3743
                "class real_c_float\n" +
Lines 3756-3762 Link Here
3756
    }
3752
    }
3757
3753
3758
    public void testDereferenceFormatting() {
3754
    public void testDereferenceFormatting() {
3759
        setDefaultsOptions();
3760
        setLoadDocumentText(
3755
        setLoadDocumentText(
3761
                "int foo()\n" +
3756
                "int foo()\n" +
3762
                "{\n" +
3757
                "{\n" +
Lines 3766-3771 Link Here
3766
                "CL_NS_STD(ostream)* infoStream;\n" +
3761
                "CL_NS_STD(ostream)* infoStream;\n" +
3767
                "directory->deleteFile( *itr );\n" +
3762
                "directory->deleteFile( *itr );\n" +
3768
                "}\n");
3763
                "}\n");
3764
        setDefaultsOptions();
3769
        reformat();
3765
        reformat();
3770
        assertDocumentText("Incorrect * spacing",
3766
        assertDocumentText("Incorrect * spacing",
3771
                "int foo()\n" +
3767
                "int foo()\n" +
Lines 3779-3785 Link Here
3779
    }
3775
    }
3780
3776
3781
    public void testNewStyleCastFormatting() {
3777
    public void testNewStyleCastFormatting() {
3782
        setDefaultsOptions();
3783
        setLoadDocumentText(
3778
        setLoadDocumentText(
3784
                "int foo(char* a, class B* b)\n" +
3779
                "int foo(char* a, class B* b)\n" +
3785
                "{\n" +
3780
                "{\n" +
Lines 3788-3793 Link Here
3788
                "int i = reinterpret_cast< int > (a);\n" +
3783
                "int i = reinterpret_cast< int > (a);\n" +
3789
                "i = static_cast < int > (*a);\n" +
3784
                "i = static_cast < int > (*a);\n" +
3790
                "}\n");
3785
                "}\n");
3786
        setDefaultsOptions();
3791
        reformat();
3787
        reformat();
3792
        assertDocumentText("Incorrect new style cast formating",
3788
        assertDocumentText("Incorrect new style cast formating",
3793
                "int foo(char* a, class B* b)\n" +
3789
                "int foo(char* a, class B* b)\n" +
Lines 3800-3810 Link Here
3800
    }
3796
    }
3801
3797
3802
    public void testNewStyleCastFormatting2() {
3798
    public void testNewStyleCastFormatting2() {
3803
        setDefaultsOptions();
3804
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3805
                putBoolean(EditorOptions.spaceWithinTypeCastParens, true);
3806
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3807
                putBoolean(EditorOptions.spaceAfterTypeCast, false);
3808
        setLoadDocumentText(
3799
        setLoadDocumentText(
3809
                "int foo(char* a, class B* b)\n" +
3800
                "int foo(char* a, class B* b)\n" +
3810
                "{\n" +
3801
                "{\n" +
Lines 3813-3818 Link Here
3813
                "int i = reinterpret_cast< int > (a);\n" +
3804
                "int i = reinterpret_cast< int > (a);\n" +
3814
                "i = static_cast < int > (*a);\n" +
3805
                "i = static_cast < int > (*a);\n" +
3815
                "}\n");
3806
                "}\n");
3807
        setDefaultsOptions();
3808
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3809
                putBoolean(EditorOptions.spaceWithinTypeCastParens, true);
3810
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3811
                putBoolean(EditorOptions.spaceAfterTypeCast, false);
3816
        reformat();
3812
        reformat();
3817
        assertDocumentText("Incorrect new style cast formating",
3813
        assertDocumentText("Incorrect new style cast formating",
3818
                "int foo(char* a, class B* b)\n" +
3814
                "int foo(char* a, class B* b)\n" +
Lines 3825-3836 Link Here
3825
    }
3821
    }
3826
3822
3827
    public void testConcurrentSpacing() {
3823
    public void testConcurrentSpacing() {
3828
        setDefaultsOptions();
3829
        setLoadDocumentText(
3824
        setLoadDocumentText(
3830
                "int foo(char* a, class B* b)\n" +
3825
                "int foo(char* a, class B* b)\n" +
3831
                "{\n" +
3826
                "{\n" +
3832
                "              for (cnt = 0; domain->successor[cnt] != NULL;++cnt);\n" +
3827
                "              for (cnt = 0; domain->successor[cnt] != NULL;++cnt);\n" +
3833
                "}\n");
3828
                "}\n");
3829
        setDefaultsOptions();
3834
        reformat();
3830
        reformat();
3835
        assertDocumentText("Incorrect cpace after ; and befor ++",
3831
        assertDocumentText("Incorrect cpace after ; and befor ++",
3836
                "int foo(char* a, class B* b)\n" +
3832
                "int foo(char* a, class B* b)\n" +
Lines 3840-3854 Link Here
3840
    }
3836
    }
3841
3837
3842
    public void testIZ130538() {
3838
    public void testIZ130538() {
3843
        setDefaultsOptions();
3844
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3845
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
3846
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3847
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
3848
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3849
                putBoolean(EditorOptions.spaceBeforeMethodCallParen, true);
3850
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3851
                putBoolean(EditorOptions.spaceBeforeMethodDeclParen, true);
3852
        setLoadDocumentText(
3839
        setLoadDocumentText(
3853
                "int foooooooo(char* a,\n" +
3840
                "int foooooooo(char* a,\n" +
3854
                " class B* b)\n" +
3841
                " class B* b)\n" +
Lines 3856-3861 Link Here
3856
                "    foo(a,\n" +
3843
                "    foo(a,\n" +
3857
                "   b);\n" +
3844
                "   b);\n" +
3858
                "}\n");
3845
                "}\n");
3846
        setDefaultsOptions();
3847
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3848
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
3849
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3850
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
3851
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3852
                putBoolean(EditorOptions.spaceBeforeMethodCallParen, true);
3853
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3854
                putBoolean(EditorOptions.spaceBeforeMethodDeclParen, true);
3859
        reformat();
3855
        reformat();
3860
        assertDocumentText("Incorrect formating IZ#130538",
3856
        assertDocumentText("Incorrect formating IZ#130538",
3861
                "int foooooooo (char* a,\n" +
3857
                "int foooooooo (char* a,\n" +
Lines 3869-3881 Link Here
3869
    //IZ#130544:Multiline alignment works wrongly with complex expressions
3865
    //IZ#130544:Multiline alignment works wrongly with complex expressions
3870
    //IZ#130690:IDE cann't align multi-line expression on '('
3866
    //IZ#130690:IDE cann't align multi-line expression on '('
3871
    public void testAlignOtherParen() {
3867
    public void testAlignOtherParen() {
3872
        setDefaultsOptions();
3873
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3874
                putBoolean(EditorOptions.alignMultilineParen, true);
3875
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3876
                putBoolean(EditorOptions.alignMultilineIfCondition, true);
3877
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3878
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
3879
        setLoadDocumentText(
3868
        setLoadDocumentText(
3880
            "int foo()\n" +
3869
            "int foo()\n" +
3881
            "{\n" +
3870
            "{\n" +
Lines 3889-3894 Link Here
3889
            "    a++;\n" +
3878
            "    a++;\n" +
3890
            "}\n"
3879
            "}\n"
3891
            );
3880
            );
3881
        setDefaultsOptions();
3882
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3883
                putBoolean(EditorOptions.alignMultilineParen, true);
3884
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3885
                putBoolean(EditorOptions.alignMultilineIfCondition, true);
3886
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3887
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
3892
        reformat();
3888
        reformat();
3893
        assertDocumentText("Incorrect spaces in binary operators",
3889
        assertDocumentText("Incorrect spaces in binary operators",
3894
            "int foo()\n" +
3890
            "int foo()\n" +
Lines 3907-3915 Link Here
3907
3903
3908
    //IZ#130525:Formatter should move the name of the function in column one
3904
    //IZ#130525:Formatter should move the name of the function in column one
3909
    public void testNewLineFunctionDefinitionName() {
3905
    public void testNewLineFunctionDefinitionName() {
3910
        setDefaultsOptions();
3911
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3912
                putBoolean(EditorOptions.newLineFunctionDefinitionName, true);
3913
        setLoadDocumentText(
3906
        setLoadDocumentText(
3914
            "static char *concat (char *s1, char *s2)\n" +
3907
            "static char *concat (char *s1, char *s2)\n" +
3915
            "{\n" +
3908
            "{\n" +
Lines 3917-3922 Link Here
3917
            "   int j;\n" +
3910
            "   int j;\n" +
3918
            "}\n"
3911
            "}\n"
3919
            );
3912
            );
3913
        setDefaultsOptions();
3914
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3915
                putBoolean(EditorOptions.newLineFunctionDefinitionName, true);
3920
        reformat();
3916
        reformat();
3921
        assertDocumentText("Formatter should move the name of the function in column one",
3917
        assertDocumentText("Formatter should move the name of the function in column one",
3922
            "static char *\n" +
3918
            "static char *\n" +
Lines 3930-3936 Link Here
3930
3926
3931
    //IZ#130898:'Spaces around ternary operators' is not working
3927
    //IZ#130898:'Spaces around ternary operators' is not working
3932
    public void testSpacesAroundTernary() {
3928
    public void testSpacesAroundTernary() {
3933
        setDefaultsOptions();
3934
        setLoadDocumentText(
3929
        setLoadDocumentText(
3935
            "static char *concat (char *s1, char *s2)\n" +
3930
            "static char *concat (char *s1, char *s2)\n" +
3936
            "{\n" +
3931
            "{\n" +
Lines 3939-3944 Link Here
3939
            "  return (0);\n" +
3934
            "  return (0);\n" +
3940
            "}\n"
3935
            "}\n"
3941
            );
3936
            );
3937
        setDefaultsOptions();
3942
        reformat();
3938
        reformat();
3943
        assertDocumentText("\'Spaces around ternary operators\' is not working",
3939
        assertDocumentText("\'Spaces around ternary operators\' is not working",
3944
            "static char *concat(char *s1, char *s2)\n" +
3940
            "static char *concat(char *s1, char *s2)\n" +
Lines 3952-3960 Link Here
3952
3948
3953
    //IZ#130900:'Spaces around Operators|Unary Operators' doesn't work in some cases
3949
    //IZ#130900:'Spaces around Operators|Unary Operators' doesn't work in some cases
3954
    public void testSpaceAroundUnaryOperator() {
3950
    public void testSpaceAroundUnaryOperator() {
3955
        setDefaultsOptions();
3956
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
3957
                putBoolean(EditorOptions.spaceAroundUnaryOps, true);
3958
        setLoadDocumentText(
3951
        setLoadDocumentText(
3959
            "int main(int argc, char** argv)\n" +
3952
            "int main(int argc, char** argv)\n" +
3960
            "{\n" +
3953
            "{\n" +
Lines 3964-3969 Link Here
3964
            "    return (0);\n" +
3957
            "    return (0);\n" +
3965
            "}\n"
3958
            "}\n"
3966
            );
3959
            );
3960
        setDefaultsOptions();
3961
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
3962
                putBoolean(EditorOptions.spaceAroundUnaryOps, true);
3967
        reformat();
3963
        reformat();
3968
        assertDocumentText("Incorrect spaces in unary operators",
3964
        assertDocumentText("Incorrect spaces in unary operators",
3969
            "int main(int argc, char** argv)\n" +
3965
            "int main(int argc, char** argv)\n" +
Lines 3978-3984 Link Here
3978
3974
3979
    //IZ#130901:'Blank Lines|After Class Header' text field works wrongly
3975
    //IZ#130901:'Blank Lines|After Class Header' text field works wrongly
3980
    public void testNewLinesAterClassHeader() {
3976
    public void testNewLinesAterClassHeader() {
3981
        setDefaultsOptions();
3982
        setLoadDocumentText(
3977
        setLoadDocumentText(
3983
            "class A\n" +
3978
            "class A\n" +
3984
            "{\n" +
3979
            "{\n" +
Lines 3989-3994 Link Here
3989
            "    }\n" +
3984
            "    }\n" +
3990
            "}\n"
3985
            "}\n"
3991
            );
3986
            );
3987
        setDefaultsOptions();
3992
        reformat();
3988
        reformat();
3993
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
3989
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
3994
            "class A\n" +
3990
            "class A\n" +
Lines 4002-4008 Link Here
4002
            );
3998
            );
4003
    }
3999
    }
4004
    public void testNewLinesAterClassHeader2() {
4000
    public void testNewLinesAterClassHeader2() {
4005
        setDefaultsOptions();
4006
        setLoadDocumentText(
4001
        setLoadDocumentText(
4007
            "class A\n" +
4002
            "class A\n" +
4008
            "{\n" +
4003
            "{\n" +
Lines 4014-4019 Link Here
4014
            "    }\n" +
4009
            "    }\n" +
4015
            "}\n"
4010
            "}\n"
4016
            );
4011
            );
4012
        setDefaultsOptions();
4017
        reformat();
4013
        reformat();
4018
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
4014
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
4019
            "class A\n" +
4015
            "class A\n" +
Lines 4028-4034 Link Here
4028
    }
4024
    }
4029
4025
4030
    public void testNewLinesAterClassHeader3() {
4026
    public void testNewLinesAterClassHeader3() {
4031
        setDefaultsOptions();
4032
        setLoadDocumentText(
4027
        setLoadDocumentText(
4033
            "class A\n" +
4028
            "class A\n" +
4034
            "{\n" +
4029
            "{\n" +
Lines 4041-4046 Link Here
4041
            "    }\n" +
4036
            "    }\n" +
4042
            "}\n"
4037
            "}\n"
4043
            );
4038
            );
4039
        setDefaultsOptions();
4044
        reformat();
4040
        reformat();
4045
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
4041
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
4046
            "class A\n" +
4042
            "class A\n" +
Lines 4055-4063 Link Here
4055
    }
4051
    }
4056
4052
4057
    public void testNewLinesAterClassHeader4() {
4053
    public void testNewLinesAterClassHeader4() {
4058
        setDefaultsOptions();
4059
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4060
                putInt(EditorOptions.blankLinesAfterClassHeader, 1);
4061
        setLoadDocumentText(
4054
        setLoadDocumentText(
4062
            "class A\n" +
4055
            "class A\n" +
4063
            "{\n" +
4056
            "{\n" +
Lines 4070-4075 Link Here
4070
            "    }\n" +
4063
            "    }\n" +
4071
            "}\n"
4064
            "}\n"
4072
            );
4065
            );
4066
        setDefaultsOptions();
4067
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4068
                putInt(EditorOptions.blankLinesAfterClassHeader, 1);
4073
        reformat();
4069
        reformat();
4074
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
4070
        assertDocumentText("Blank Lines \'After Class Header\' text field works wrongly",
4075
            "class A\n" +
4071
            "class A\n" +
Lines 4086-4099 Link Here
4086
4082
4087
    //IZ#130916:'Multiline Alignment|Array Initializer' checkbox works wrongly
4083
    //IZ#130916:'Multiline Alignment|Array Initializer' checkbox works wrongly
4088
    public void testMultilineArrayAlignment() {
4084
    public void testMultilineArrayAlignment() {
4089
        setDefaultsOptions();
4090
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4091
                putBoolean(EditorOptions.alignMultilineArrayInit, true);
4092
        setLoadDocumentText(
4085
        setLoadDocumentText(
4093
            "        int array[10] ={1, 2, 3, 4,\n" +
4086
            "        int array[10] ={1, 2, 3, 4,\n" +
4094
            "    5, 6, 7, 8, 9\n" +
4087
            "    5, 6, 7, 8, 9\n" +
4095
            "};\n"
4088
            "};\n"
4096
            );
4089
            );
4090
        setDefaultsOptions();
4091
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4092
                putBoolean(EditorOptions.alignMultilineArrayInit, true);
4097
        reformat();
4093
        reformat();
4098
        assertDocumentText("\'Multiline Alignment|Array Initializer\' checkbox works wrongly",
4094
        assertDocumentText("\'Multiline Alignment|Array Initializer\' checkbox works wrongly",
4099
            "int array[10] = {1, 2, 3, 4,\n" +
4095
            "int array[10] = {1, 2, 3, 4,\n" +
Lines 4103-4113 Link Here
4103
4099
4104
    //IZ#131038:GNU style: reformat works wrongly with destructors
4100
    //IZ#131038:GNU style: reformat works wrongly with destructors
4105
    public void testGnuStuleNewLineName() {
4101
    public void testGnuStuleNewLineName() {
4106
        setDefaultsOptions("GNU");
4107
        setLoadDocumentText(
4102
        setLoadDocumentText(
4108
                "locale::~locale() throw()\n" +
4103
                "locale::~locale() throw()\n" +
4109
                "{ _M_impl->_M_remove_reference(); }\n"
4104
                "{ _M_impl->_M_remove_reference(); }\n"
4110
                );
4105
                );
4106
        setDefaultsOptions("GNU");
4111
        reformat();
4107
        reformat();
4112
        assertDocumentText("Incorrect formatting GNU new line name",
4108
        assertDocumentText("Incorrect formatting GNU new line name",
4113
                "locale::~locale () throw ()\n" +
4109
                "locale::~locale () throw ()\n" +
Lines 4119-4125 Link Here
4119
4115
4120
    //IZ#131043:GNU style: reformat works wrongly with function names
4116
    //IZ#131043:GNU style: reformat works wrongly with function names
4121
    public void testGnuStuleNewLineName2() {
4117
    public void testGnuStuleNewLineName2() {
4122
        setDefaultsOptions("GNU");
4123
        setLoadDocumentText(
4118
        setLoadDocumentText(
4124
                "void\n" +
4119
                "void\n" +
4125
                "__num_base::_S_format_float(const ios_base& __io, char* __fptr, char __mod)\n" +
4120
                "__num_base::_S_format_float(const ios_base& __io, char* __fptr, char __mod)\n" +
Lines 4127-4132 Link Here
4127
                "return;\n" +
4122
                "return;\n" +
4128
                "}\n"
4123
                "}\n"
4129
                );
4124
                );
4125
        setDefaultsOptions("GNU");
4130
        reformat();
4126
        reformat();
4131
        assertDocumentText("Incorrect formatting GNU new line name",
4127
        assertDocumentText("Incorrect formatting GNU new line name",
4132
                "void\n" +
4128
                "void\n" +
Lines 4139-4150 Link Here
4139
    
4135
    
4140
    //IZ#131059:GNU style: Multiline alignment works wrongly
4136
    //IZ#131059:GNU style: Multiline alignment works wrongly
4141
    public void testGnuStuleNewLineName3() {
4137
    public void testGnuStuleNewLineName3() {
4142
        setDefaultsOptions("GNU");
4143
        setLoadDocumentText(
4138
        setLoadDocumentText(
4144
                "int f(int a1, int a2,\n" +
4139
                "int f(int a1, int a2,\n" +
4145
                "      int a3) {\n" +
4140
                "      int a3) {\n" +
4146
                "}\n"
4141
                "}\n"
4147
                );
4142
                );
4143
        setDefaultsOptions("GNU");
4148
        reformat();
4144
        reformat();
4149
        assertDocumentText("Incorrect formatting GNU new line name",
4145
        assertDocumentText("Incorrect formatting GNU new line name",
4150
                "int\n" +
4146
                "int\n" +
Lines 4154-4160 Link Here
4154
    }
4150
    }
4155
4151
4156
    public void testGnuStuleNewLineName4() {
4152
    public void testGnuStuleNewLineName4() {
4157
        setDefaultsOptions("GNU");
4158
        setLoadDocumentText(
4153
        setLoadDocumentText(
4159
                "Db::Db (DbEnv *env, u_int32_t flags)\n" +
4154
                "Db::Db (DbEnv *env, u_int32_t flags)\n" +
4160
                ": imp_ (0)\n" +
4155
                ": imp_ (0)\n" +
Lines 4162-4167 Link Here
4162
                "{\n" +
4157
                "{\n" +
4163
                "}\n"
4158
                "}\n"
4164
                );
4159
                );
4160
        setDefaultsOptions("GNU");
4165
        reformat();
4161
        reformat();
4166
        assertDocumentText("Incorrect formatting GNU new line name",
4162
        assertDocumentText("Incorrect formatting GNU new line name",
4167
                "Db::Db (DbEnv *env, u_int32_t flags)\n" +
4163
                "Db::Db (DbEnv *env, u_int32_t flags)\n" +
Lines 4171-4183 Link Here
4171
    }
4167
    }
4172
4168
4173
    public void testGnuStuleNewLineName5() {
4169
    public void testGnuStuleNewLineName5() {
4174
        setDefaultsOptions("GNU");
4175
        setLoadDocumentText(
4170
        setLoadDocumentText(
4176
                "tree decl_shadowed_for_var_lookup (tree from)\n" +
4171
                "tree decl_shadowed_for_var_lookup (tree from)\n" +
4177
                "{\n" +
4172
                "{\n" +
4178
                "  return NULL_TREE;\n" +
4173
                "  return NULL_TREE;\n" +
4179
                "}\n"
4174
                "}\n"
4180
                );
4175
                );
4176
        setDefaultsOptions("GNU");
4181
        reformat();
4177
        reformat();
4182
        assertDocumentText("Incorrect formatting GNU new line name",
4178
        assertDocumentText("Incorrect formatting GNU new line name",
4183
                "tree\n" +
4179
                "tree\n" +
Lines 4189-4195 Link Here
4189
    }
4185
    }
4190
4186
4191
    public void testGnuStuleNewLineName6() {
4187
    public void testGnuStuleNewLineName6() {
4192
        setDefaultsOptions("GNU");
4193
        setLoadDocumentText(
4188
        setLoadDocumentText(
4194
                "B::tree A::\n" +
4189
                "B::tree A::\n" +
4195
                "decl_shadowed_for_var_lookup (tree from)\n" +
4190
                "decl_shadowed_for_var_lookup (tree from)\n" +
Lines 4197-4202 Link Here
4197
                "  return NULL_TREE;\n" +
4192
                "  return NULL_TREE;\n" +
4198
                "}\n"
4193
                "}\n"
4199
                );
4194
                );
4195
        setDefaultsOptions("GNU");
4200
        reformat();
4196
        reformat();
4201
        assertDocumentText("Incorrect formatting GNU new line name",
4197
        assertDocumentText("Incorrect formatting GNU new line name",
4202
                "B::tree\n" +
4198
                "B::tree\n" +
Lines 4209-4223 Link Here
4209
    
4205
    
4210
    //IZ#131158:"Spaces Within Parenthesis|Braces" checkbox works wrongly
4206
    //IZ#131158:"Spaces Within Parenthesis|Braces" checkbox works wrongly
4211
    public void testSpaceWithinBraces() {
4207
    public void testSpaceWithinBraces() {
4212
        setDefaultsOptions();
4213
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4214
                putBoolean(EditorOptions.spaceWithinBraces, true);
4215
        setLoadDocumentText(
4208
        setLoadDocumentText(
4216
                "int a[] = {1,(1+2),(2+ 3)};\n" +
4209
                "int a[] = {1,(1+2),(2+ 3)};\n" +
4217
                "int b[] = {  1,(1+2),(2+ 3)  };\n" +
4210
                "int b[] = {  1,(1+2),(2+ 3)  };\n" +
4218
                "int c[] = {  1,(1+2),(2+ 3)  \n" +
4211
                "int c[] = {  1,(1+2),(2+ 3)  \n" +
4219
                "};\n"
4212
                "};\n"
4220
                );
4213
                );
4214
        setDefaultsOptions();
4215
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4216
                putBoolean(EditorOptions.spaceWithinBraces, true);
4221
        reformat();
4217
        reformat();
4222
        assertDocumentText("Incorrect formatting array init",
4218
        assertDocumentText("Incorrect formatting array init",
4223
                "int a[] = { 1, (1 + 2), (2 + 3) };\n" +
4219
                "int a[] = { 1, (1 + 2), (2 + 3) };\n" +
Lines 4227-4239 Link Here
4227
    }
4223
    }
4228
4224
4229
    public void testSpaceWithinBraces2() {
4225
    public void testSpaceWithinBraces2() {
4230
        setDefaultsOptions();
4231
        setLoadDocumentText(
4226
        setLoadDocumentText(
4232
                "int a[] = {1,(1+2),(2+ 3)};\n" +
4227
                "int a[] = {1,(1+2),(2+ 3)};\n" +
4233
                "int b[] = {  1,(1+2),(2+ 3)  };\n" +
4228
                "int b[] = {  1,(1+2),(2+ 3)  };\n" +
4234
                "int c[] = {  1,(1+2),(2+ 3)  \n" +
4229
                "int c[] = {  1,(1+2),(2+ 3)  \n" +
4235
                "};\n"
4230
                "};\n"
4236
                );
4231
                );
4232
        setDefaultsOptions();
4237
        reformat();
4233
        reformat();
4238
        assertDocumentText("Incorrect formatting array init",
4234
        assertDocumentText("Incorrect formatting array init",
4239
                "int a[] = {1, (1 + 2), (2 + 3)};\n" +
4235
                "int a[] = {1, (1 + 2), (2 + 3)};\n" +
Lines 4243-4249 Link Here
4243
    }
4239
    }
4244
4240
4245
    public void testFunctionNameInNamespace() {
4241
    public void testFunctionNameInNamespace() {
4246
        setDefaultsOptions("GNU");
4247
        setLoadDocumentText(
4242
        setLoadDocumentText(
4248
                "namespace {\n" +
4243
                "namespace {\n" +
4249
                "void outCustomersList() {\n" +
4244
                "void outCustomersList() {\n" +
Lines 4251-4256 Link Here
4251
                "}\n" +
4246
                "}\n" +
4252
                "}\n"
4247
                "}\n"
4253
                );
4248
                );
4249
        setDefaultsOptions("GNU");
4254
        reformat();
4250
        reformat();
4255
        assertDocumentText("Incorrect formatting GNU new line name",
4251
        assertDocumentText("Incorrect formatting GNU new line name",
4256
                "namespace\n" +
4252
                "namespace\n" +
Lines 4267-4273 Link Here
4267
4263
4268
    // IZ#131286:Nondeterministic behavior of formatter
4264
    // IZ#131286:Nondeterministic behavior of formatter
4269
    public void testIZ131286() {
4265
    public void testIZ131286() {
4270
        setDefaultsOptions();
4271
        setLoadDocumentText(
4266
        setLoadDocumentText(
4272
                "int\n" +
4267
                "int\n" +
4273
                "foo() {\n" +
4268
                "foo() {\n" +
Lines 4278-4283 Link Here
4278
                "    };\n" +
4273
                "    };\n" +
4279
                "}\n"
4274
                "}\n"
4280
                );
4275
                );
4276
        setDefaultsOptions();
4281
        reformat();
4277
        reformat();
4282
        assertDocumentText("Nondeterministic behavior of formatter",
4278
        assertDocumentText("Nondeterministic behavior of formatter",
4283
                "int\n" +
4279
                "int\n" +
Lines 4294-4300 Link Here
4294
    
4290
    
4295
    // IZ#123656:Indenting behavior seems odd
4291
    // IZ#123656:Indenting behavior seems odd
4296
    public void testIZ123656() {
4292
    public void testIZ123656() {
4297
        setDefaultsOptions();
4298
        setLoadDocumentText(
4293
        setLoadDocumentText(
4299
                "int\n" +
4294
                "int\n" +
4300
                "foo() {\n" +
4295
                "foo() {\n" +
Lines 4303-4308 Link Here
4303
                "i=0;\n" +
4298
                "i=0;\n" +
4304
                "}\n"
4299
                "}\n"
4305
                );
4300
                );
4301
        setDefaultsOptions();
4306
        reformat();
4302
        reformat();
4307
        assertDocumentText("Indenting behavior seems odd",
4303
        assertDocumentText("Indenting behavior seems odd",
4308
                "int\n" +
4304
                "int\n" +
Lines 4317-4323 Link Here
4317
4313
4318
    // IZ#123656:Indenting behavior seems odd
4314
    // IZ#123656:Indenting behavior seems odd
4319
    public void testIZ123656_2() {
4315
    public void testIZ123656_2() {
4320
        setDefaultsOptions();
4321
        setLoadDocumentText(
4316
        setLoadDocumentText(
4322
                "int\n" +
4317
                "int\n" +
4323
                "foo() {\n" +
4318
                "foo() {\n" +
Lines 4326-4331 Link Here
4326
                "i=0;\n" +
4321
                "i=0;\n" +
4327
                "}\n"
4322
                "}\n"
4328
                );
4323
                );
4324
        setDefaultsOptions();
4329
        reformat();
4325
        reformat();
4330
        assertDocumentText("Indenting behavior seems odd",
4326
        assertDocumentText("Indenting behavior seems odd",
4331
                "int\n" +
4327
                "int\n" +
Lines 4340-4346 Link Here
4340
4336
4341
    // IZ#123656:Indenting behavior seems odd
4337
    // IZ#123656:Indenting behavior seems odd
4342
    public void testIZ123656_3() {
4338
    public void testIZ123656_3() {
4343
        setDefaultsOptions();
4344
        setLoadDocumentText(
4339
        setLoadDocumentText(
4345
            " C_MODE_START\n" +
4340
            " C_MODE_START\n" +
4346
            "#    include <decimal.h>\n" +
4341
            "#    include <decimal.h>\n" +
Lines 4357-4362 Link Here
4357
            "#    define DECIMAL_MAX_PRECISION ((DECIMAL_BUFF_LENGTH * 9) - 8*2)\n" +
4352
            "#    define DECIMAL_MAX_PRECISION ((DECIMAL_BUFF_LENGTH * 9) - 8*2)\n" +
4358
            "\n"
4353
            "\n"
4359
            );
4354
            );
4355
        setDefaultsOptions();
4360
        reformat();
4356
        reformat();
4361
        assertDocumentText("Incorrect identing case after preprocessor",
4357
        assertDocumentText("Incorrect identing case after preprocessor",
4362
            "C_MODE_START\n" +
4358
            "C_MODE_START\n" +
Lines 4377-4387 Link Here
4377
    }
4373
    }
4378
4374
4379
    public void testIdentMultyConstructor5() {
4375
    public void testIdentMultyConstructor5() {
4380
        setDefaultsOptions("MySQL");
4381
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4382
                putBoolean(EditorOptions.alignMultilineParen, true);
4383
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4384
                putBoolean(EditorOptions.spaceKeepExtra, false);
4385
        setLoadDocumentText(
4376
        setLoadDocumentText(
4386
            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" + 
4377
            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" + 
4387
            "				 ulong query_length, bool using_trans,\n" +
4378
            "				 ulong query_length, bool using_trans,\n" +
Lines 4406-4411 Link Here
4406
            "    time_t end_time;\n" +
4397
            "    time_t end_time;\n" +
4407
            "}\n"
4398
            "}\n"
4408
            );
4399
            );
4400
        setDefaultsOptions("MySQL");
4401
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4402
                putBoolean(EditorOptions.alignMultilineParen, true);
4403
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4404
                putBoolean(EditorOptions.spaceKeepExtra, false);
4409
        reformat();
4405
        reformat();
4410
        assertDocumentText("Incorrect identing multyline constructor",
4406
        assertDocumentText("Incorrect identing multyline constructor",
4411
            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" + 
4407
            "Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,\n" + 
Lines 4435-4441 Link Here
4435
4431
4436
    // IZ#131379:GNU style: formatter works wrong with functions if it returns struct
4432
    // IZ#131379:GNU style: formatter works wrong with functions if it returns struct
4437
    public void testIZ131379() {
4433
    public void testIZ131379() {
4438
        setDefaultsOptions("GNU");
4439
        setLoadDocumentText(
4434
        setLoadDocumentText(
4440
                "tree\n" +
4435
                "tree\n" +
4441
                "decl_shadowed_for_var_lookup (tree from)\n" +
4436
                "decl_shadowed_for_var_lookup (tree from)\n" +
Lines 4450-4455 Link Here
4450
                "}\n" +
4445
                "}\n" +
4451
                "\n"
4446
                "\n"
4452
                );
4447
                );
4448
        setDefaultsOptions("GNU");
4453
        reformat();
4449
        reformat();
4454
        assertDocumentText("Indenting behavior seems odd",
4450
        assertDocumentText("Indenting behavior seems odd",
4455
                "tree\n" +
4451
                "tree\n" +
Lines 4469-4477 Link Here
4469
4465
4470
    // IZ#130509:Formatter should ignore empty function body
4466
    // IZ#130509:Formatter should ignore empty function body
4471
    public void testIZ130509() {
4467
    public void testIZ130509() {
4472
        setDefaultsOptions();
4473
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4474
                putBoolean(EditorOptions.ignoreEmptyFunctionBody, true);
4475
        setLoadDocumentText(
4468
        setLoadDocumentText(
4476
                "int foo0() { \n" +
4469
                "int foo0() { \n" +
4477
                "  }\n" +
4470
                "  }\n" +
Lines 4484-4489 Link Here
4484
                "int foo5() { //\n" +
4477
                "int foo5() { //\n" +
4485
                "}\n"
4478
                "}\n"
4486
                );
4479
                );
4480
        setDefaultsOptions();
4481
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4482
                putBoolean(EditorOptions.ignoreEmptyFunctionBody, true);
4487
        reformat();
4483
        reformat();
4488
        assertDocumentText("Formatter should ignore empty function body",
4484
        assertDocumentText("Formatter should ignore empty function body",
4489
                "int foo0() { }\n" +
4485
                "int foo0() { }\n" +
Lines 4504-4510 Link Here
4504
    // IZ#130509:NPE on formatting unbalanced braces
4500
    // IZ#130509:NPE on formatting unbalanced braces
4505
    // Correct test case when macro will be taken into account
4501
    // Correct test case when macro will be taken into account
4506
    public void testIZ135015() {
4502
    public void testIZ135015() {
4507
        setDefaultsOptions();
4508
        setLoadDocumentText(
4503
        setLoadDocumentText(
4509
                "#define FOR(n) for (int i = 0; i < n; i++) {\n" +
4504
                "#define FOR(n) for (int i = 0; i < n; i++) {\n" +
4510
                "\n" +
4505
                "\n" +
Lines 4514-4519 Link Here
4514
                "    }\n" +
4509
                "    }\n" +
4515
                "}\n"
4510
                "}\n"
4516
                );
4511
                );
4512
        setDefaultsOptions();
4517
        reformat();
4513
        reformat();
4518
        assertDocumentText("IZ#130509:NPE on formatting unbalanced braces",
4514
        assertDocumentText("IZ#130509:NPE on formatting unbalanced braces",
4519
                "#define FOR(n) for (int i = 0; i < n; i++) {\n" +
4515
                "#define FOR(n) for (int i = 0; i < n; i++) {\n" +
Lines 4529-4535 Link Here
4529
    
4525
    
4530
    // IZ#135205:'Spaces Before Keywords|else' option works wrongly in some cases
4526
    // IZ#135205:'Spaces Before Keywords|else' option works wrongly in some cases
4531
    public void testIZ135205() {
4527
    public void testIZ135205() {
4532
        setDefaultsOptions();
4533
        setLoadDocumentText(
4528
        setLoadDocumentText(
4534
                "int main() {\n" +
4529
                "int main() {\n" +
4535
                "    int i = 0;\n" +
4530
                "    int i = 0;\n" +
Lines 4540-4545 Link Here
4540
                "    }\n" +
4535
                "    }\n" +
4541
                "}\n"
4536
                "}\n"
4542
                );
4537
                );
4538
        setDefaultsOptions();
4543
        reformat();
4539
        reformat();
4544
        assertDocumentText("IZ#135205:'Spaces Before Keywords|else' option works wrongly in some cases",
4540
        assertDocumentText("IZ#135205:'Spaces Before Keywords|else' option works wrongly in some cases",
4545
                "int main()\n" +
4541
                "int main()\n" +
Lines 4556-4562 Link Here
4556
    
4552
    
4557
    // IZ#131721:Comment moves on new line after reformat
4553
    // IZ#131721:Comment moves on new line after reformat
4558
    public void testIZ131721() {
4554
    public void testIZ131721() {
4559
        setDefaultsOptions();
4560
        setLoadDocumentText(
4555
        setLoadDocumentText(
4561
                "char seek_scrbuf[SEEKBUFSIZE]; /* buffer for seeking */\n" +
4556
                "char seek_scrbuf[SEEKBUFSIZE]; /* buffer for seeking */\n" +
4562
                "int cf_debug; /* non-zero enables debug prints */\n" +
4557
                "int cf_debug; /* non-zero enables debug prints */\n" +
Lines 4566-4571 Link Here
4566
                "    return (ptr);\n" +
4561
                "    return (ptr);\n" +
4567
                "}\n"
4562
                "}\n"
4568
                );
4563
                );
4564
        setDefaultsOptions();
4569
        reformat();
4565
        reformat();
4570
        assertDocumentText("IZ#131721:Comment moves on new line after reformat",
4566
        assertDocumentText("IZ#131721:Comment moves on new line after reformat",
4571
                "char seek_scrbuf[SEEKBUFSIZE]; /* buffer for seeking */\n" +
4567
                "char seek_scrbuf[SEEKBUFSIZE]; /* buffer for seeking */\n" +
Lines 4580-4588 Link Here
4580
    }
4576
    }
4581
4577
4582
    public void testTypecast() {
4578
    public void testTypecast() {
4583
        setDefaultsOptions();
4584
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4585
                putBoolean(EditorOptions.spaceWithinTypeCastParens, true);
4586
        setLoadDocumentText(
4579
        setLoadDocumentText(
4587
                "int i = (int)'a';\n"+
4580
                "int i = (int)'a';\n"+
4588
                "void *\n" +
4581
                "void *\n" +
Lines 4592-4597 Link Here
4592
                "    return(int)(ptr);\n" +
4585
                "    return(int)(ptr);\n" +
4593
                "}\n"
4586
                "}\n"
4594
                );
4587
                );
4588
        setDefaultsOptions();
4589
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4590
                putBoolean(EditorOptions.spaceWithinTypeCastParens, true);
4595
        reformat();
4591
        reformat();
4596
        assertDocumentText("Wrong type cast formatting",
4592
        assertDocumentText("Wrong type cast formatting",
4597
                "int i = ( int ) 'a';\n"+
4593
                "int i = ( int ) 'a';\n"+
Lines 4606-4621 Link Here
4606
    }
4602
    }
4607
4603
4608
    public void testReformatMultiLineAndSpacing() {
4604
    public void testReformatMultiLineAndSpacing() {
4609
        setDefaultsOptions();
4610
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4611
                put(EditorOptions.newLineBeforeBraceDeclaration, 
4612
                CodeStyle.BracePlacement.SAME_LINE.name());
4613
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4614
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
4615
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4616
                putBoolean(EditorOptions.spaceWithinMethodDeclParens, true);
4617
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4618
                putBoolean(EditorOptions.spaceWithinMethodCallParens, true);
4619
        setLoadDocumentText(
4605
        setLoadDocumentText(
4620
                  "void m(int a,\n"
4606
                  "void m(int a,\n"
4621
                + "int b) {\n"
4607
                + "int b) {\n"
Lines 4623-4628 Link Here
4623
                + "    \"haf\");\n"
4609
                + "    \"haf\");\n"
4624
                + "}\n"
4610
                + "}\n"
4625
                );
4611
                );
4612
        setDefaultsOptions();
4613
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4614
                put(EditorOptions.newLineBeforeBraceDeclaration, 
4615
                CodeStyle.BracePlacement.SAME_LINE.name());
4616
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4617
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
4618
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4619
                putBoolean(EditorOptions.spaceWithinMethodDeclParens, true);
4620
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4621
                putBoolean(EditorOptions.spaceWithinMethodCallParens, true);
4626
        reformat();
4622
        reformat();
4627
        assertDocumentText("Incorrect new-line indent",
4623
        assertDocumentText("Incorrect new-line indent",
4628
                  "void m( int a,\n" 
4624
                  "void m( int a,\n" 
Lines 4634-4640 Link Here
4634
    }
4630
    }
4635
    
4631
    
4636
    public void testQtExtension() {
4632
    public void testQtExtension() {
4637
        setDefaultsOptions();
4638
        setLoadDocumentText(
4633
        setLoadDocumentText(
4639
                "#define Q_OBJECT\n" +
4634
                "#define Q_OBJECT\n" +
4640
                "#define signals private\n" +
4635
                "#define signals private\n" +
Lines 4661-4666 Link Here
4661
                "    Menu();\n" +
4656
                "    Menu();\n" +
4662
                "};\n"
4657
                "};\n"
4663
                );
4658
                );
4659
        setDefaultsOptions();
4664
        reformat();
4660
        reformat();
4665
        assertDocumentText("Wrong QT formatting",
4661
        assertDocumentText("Wrong QT formatting",
4666
                "#define Q_OBJECT\n" +
4662
                "#define Q_OBJECT\n" +
Lines 4691-4704 Link Here
4691
    }
4687
    }
4692
4688
4693
    public void testExpandToTab() {
4689
    public void testExpandToTab() {
4694
        setDefaultsOptions();
4695
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4696
                put(EditorOptions.newLineBeforeBraceClass,
4697
                CodeStyle.BracePlacement.SAME_LINE.name());
4698
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4699
                putBoolean(EditorOptions.expandTabToSpaces, false);
4700
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4701
                putInt(EditorOptions.tabSize, 4);
4702
        setLoadDocumentText(
4690
        setLoadDocumentText(
4703
                "typedef struct pcihp {\n" +
4691
                "typedef struct pcihp {\n" +
4704
                "\n" +
4692
                "\n" +
Lines 4707-4712 Link Here
4707
                "\t} slotinfo[10];\n" +
4695
                "\t} slotinfo[10];\n" +
4708
                "} pcihp_t;\n"
4696
                "} pcihp_t;\n"
4709
                );
4697
                );
4698
        setDefaultsOptions();
4699
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4700
                put(EditorOptions.newLineBeforeBraceClass,
4701
                CodeStyle.BracePlacement.SAME_LINE.name());
4702
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4703
                putBoolean(EditorOptions.expandTabToSpaces, false);
4704
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4705
                putInt(EditorOptions.tabSize, 4);
4710
        for(int i = 0; i < 2; i++){
4706
        for(int i = 0; i < 2; i++){
4711
        reformat();
4707
        reformat();
4712
        assertDocumentText("Incorrect tab formatting",
4708
        assertDocumentText("Incorrect tab formatting",
Lines 4720-4733 Link Here
4720
    }
4716
    }
4721
4717
4722
    public void testExpandToTab2() {
4718
    public void testExpandToTab2() {
4723
        setDefaultsOptions();
4724
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4725
                put(EditorOptions.newLineBeforeBraceClass,
4726
                CodeStyle.BracePlacement.SAME_LINE.name());
4727
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4728
                putBoolean(EditorOptions.expandTabToSpaces, false);
4729
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4730
                putInt(EditorOptions.tabSize, 8);
4731
        setLoadDocumentText(
4719
        setLoadDocumentText(
4732
                "typedef struct pcihp {\n" +
4720
                "typedef struct pcihp {\n" +
4733
                "\n" +
4721
                "\n" +
Lines 4736-4741 Link Here
4736
                "\t} slotinfo[10];\n" +
4724
                "\t} slotinfo[10];\n" +
4737
                "} pcihp_t;\n"
4725
                "} pcihp_t;\n"
4738
                );
4726
                );
4727
        setDefaultsOptions();
4728
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4729
                put(EditorOptions.newLineBeforeBraceClass,
4730
                CodeStyle.BracePlacement.SAME_LINE.name());
4731
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4732
                putBoolean(EditorOptions.expandTabToSpaces, false);
4733
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4734
                putInt(EditorOptions.tabSize, 8);
4739
        reformat();
4735
        reformat();
4740
        assertDocumentText("Incorrect tab formatting",
4736
        assertDocumentText("Incorrect tab formatting",
4741
                "typedef struct pcihp {\n" +
4737
                "typedef struct pcihp {\n" +
Lines 4747-4761 Link Here
4747
    }
4743
    }
4748
4744
4749
    public void testIZ145529() {
4745
    public void testIZ145529() {
4750
        setDefaultsOptions();
4751
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4752
                put(EditorOptions.newLineBeforeBraceClass,
4753
                CodeStyle.BracePlacement.SAME_LINE.name());
4754
        setLoadDocumentText(
4746
        setLoadDocumentText(
4755
                "class Base {\n" +
4747
                "class Base {\n" +
4756
                "\n" +
4748
                "\n" +
4757
                "};\n"
4749
                "};\n"
4758
                );
4750
                );
4751
        setDefaultsOptions();
4752
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4753
                put(EditorOptions.newLineBeforeBraceClass,
4754
                CodeStyle.BracePlacement.SAME_LINE.name());
4759
        reformat();
4755
        reformat();
4760
        assertDocumentText("Incorrect empty class formatting",
4756
        assertDocumentText("Incorrect empty class formatting",
4761
                "class Base {\n" +
4757
                "class Base {\n" +
Lines 4764-4772 Link Here
4764
    }
4760
    }
4765
4761
4766
    public void testReformatConstructorInitializer3() {
4762
    public void testReformatConstructorInitializer3() {
4767
        setDefaultsOptions();
4768
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4769
                putInt(EditorOptions.constructorListContinuationIndent, 6);
4770
        setLoadDocumentText(
4763
        setLoadDocumentText(
4771
            "class ClipCost {\n" +
4764
            "class ClipCost {\n" +
4772
            "public:\n" +
4765
            "public:\n" +
Lines 4785-4790 Link Here
4785
            "              init(i);\n" +
4778
            "              init(i);\n" +
4786
            "    }\n" +
4779
            "    }\n" +
4787
            "}\n");
4780
            "}\n");
4781
        setDefaultsOptions();
4782
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4783
                putInt(EditorOptions.constructorListContinuationIndent, 6);
4788
        reformat();
4784
        reformat();
4789
        assertDocumentText("Incorrect reformatting of constructor initializer",
4785
        assertDocumentText("Incorrect reformatting of constructor initializer",
4790
            "class ClipCost\n" +
4786
            "class ClipCost\n" +
Lines 4850-4859 Link Here
4850
4846
4851
    // IZ#156015:'Format' works wrongly with 'while'
4847
    // IZ#156015:'Format' works wrongly with 'while'
4852
    public void testIZ156015() {
4848
    public void testIZ156015() {
4853
        setDefaultsOptions();
4854
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4855
                put(EditorOptions.newLineBeforeBraceDeclaration,
4856
                CodeStyle.BracePlacement.SAME_LINE.name());
4857
        setLoadDocumentText(
4849
        setLoadDocumentText(
4858
                "    int main() {\n" +
4850
                "    int main() {\n" +
4859
                "    \n" +
4851
                "    \n" +
Lines 4868-4873 Link Here
4868
                "    return (0);\n" +
4860
                "    return (0);\n" +
4869
                "}\n"
4861
                "}\n"
4870
                );
4862
                );
4863
        setDefaultsOptions();
4864
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4865
                put(EditorOptions.newLineBeforeBraceDeclaration,
4866
                CodeStyle.BracePlacement.SAME_LINE.name());
4871
        reformat();
4867
        reformat();
4872
        assertDocumentText("IZ#156015:'Format' works wrongly with 'while'",
4868
        assertDocumentText("IZ#156015:'Format' works wrongly with 'while'",
4873
                "int main() {\n" +
4869
                "int main() {\n" +
Lines 4887-4896 Link Here
4887
4883
4888
    // IZ#156015:'Format' works wrongly with 'while'
4884
    // IZ#156015:'Format' works wrongly with 'while'
4889
    public void testIZ156015_2() {
4885
    public void testIZ156015_2() {
4890
        setDefaultsOptions();
4891
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4892
                put(EditorOptions.newLineBeforeBraceDeclaration,
4893
                CodeStyle.BracePlacement.SAME_LINE.name());
4894
        setLoadDocumentText(
4886
        setLoadDocumentText(
4895
                "    int main() {\n" +
4887
                "    int main() {\n" +
4896
                "    \n" +
4888
                "    \n" +
Lines 4905-4910 Link Here
4905
                "    return (0);\n" +
4897
                "    return (0);\n" +
4906
                "}\n"
4898
                "}\n"
4907
                );
4899
                );
4900
        setDefaultsOptions();
4901
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4902
                put(EditorOptions.newLineBeforeBraceDeclaration,
4903
                CodeStyle.BracePlacement.SAME_LINE.name());
4908
        reformat();
4904
        reformat();
4909
        assertDocumentText("IZ#156015:'Format' works wrongly with 'while'",
4905
        assertDocumentText("IZ#156015:'Format' works wrongly with 'while'",
4910
                "int main() {\n" +
4906
                "int main() {\n" +
Lines 4942-4951 Link Here
4942
4938
4943
    // IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)
4939
    // IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)
4944
    public void testIZ166051_1() {
4940
    public void testIZ166051_1() {
4945
        setDefaultsOptions();
4946
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4947
                put(EditorOptions.newLineBeforeBraceDeclaration,
4948
                CodeStyle.BracePlacement.SAME_LINE.name());
4949
        setLoadDocumentText(
4941
        setLoadDocumentText(
4950
                "int main() {\n" +
4942
                "int main() {\n" +
4951
                "    do {\n" +
4943
                "    do {\n" +
Lines 4955-4960 Link Here
4955
                "    return 0;\n" +
4947
                "    return 0;\n" +
4956
                "}\n"
4948
                "}\n"
4957
                );
4949
                );
4950
        setDefaultsOptions();
4951
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4952
                put(EditorOptions.newLineBeforeBraceDeclaration,
4953
                CodeStyle.BracePlacement.SAME_LINE.name());
4958
        reformat();
4954
        reformat();
4959
        assertDocumentText("IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)",
4955
        assertDocumentText("IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)",
4960
                "int main() {\n" +
4956
                "int main() {\n" +
Lines 4970-4979 Link Here
4970
4966
4971
    // IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)
4967
    // IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)
4972
    public void testIZ166051_2() {
4968
    public void testIZ166051_2() {
4973
        setDefaultsOptions();
4974
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
4975
                put(EditorOptions.newLineBeforeBraceDeclaration,
4976
                CodeStyle.BracePlacement.SAME_LINE.name());
4977
        setLoadDocumentText(
4969
        setLoadDocumentText(
4978
                "int main() {\n" +
4970
                "int main() {\n" +
4979
                "  do{\n" +
4971
                "  do{\n" +
Lines 4984-4989 Link Here
4984
                "    return 0;\n" +
4976
                "    return 0;\n" +
4985
                "}\n"
4977
                "}\n"
4986
                );
4978
                );
4979
        setDefaultsOptions();
4980
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
4981
                put(EditorOptions.newLineBeforeBraceDeclaration,
4982
                CodeStyle.BracePlacement.SAME_LINE.name());
4987
        reformat();
4983
        reformat();
4988
        assertDocumentText("IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)",
4984
        assertDocumentText("IZ#166051:while blocks inside do..while are formatted incorrectly (Alt+Shift+F)",
4989
                "int main() {\n" +
4985
                "int main() {\n" +
Lines 5000-5011 Link Here
5000
4996
5001
    // IZ#159334:Cannot format initialization list the way I want
4997
    // IZ#159334:Cannot format initialization list the way I want
5002
    public void testIZ159334_1() {
4998
    public void testIZ159334_1() {
5003
        setDefaultsOptions();
5004
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5005
                put(EditorOptions.newLineBeforeBraceDeclaration,
5006
                CodeStyle.BracePlacement.NEW_LINE.name());
5007
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5008
                putInt(EditorOptions.constructorListContinuationIndent, 4);
5009
        setLoadDocumentText(
4999
        setLoadDocumentText(
5010
                "MyClass::MyClass(int param1, int param2)\n" +
5000
                "MyClass::MyClass(int param1, int param2)\n" +
5011
                "   : _var1(param1),\n" +
5001
                "   : _var1(param1),\n" +
Lines 5013-5018 Link Here
5013
                "{\n" +
5003
                "{\n" +
5014
                "}\n"
5004
                "}\n"
5015
                );
5005
                );
5006
        setDefaultsOptions();
5007
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5008
                put(EditorOptions.newLineBeforeBraceDeclaration,
5009
                CodeStyle.BracePlacement.NEW_LINE.name());
5010
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5011
                putInt(EditorOptions.constructorListContinuationIndent, 4);
5016
        reformat();
5012
        reformat();
5017
        assertDocumentText("IZ#159334:Cannot format initialization list the way I want",
5013
        assertDocumentText("IZ#159334:Cannot format initialization list the way I want",
5018
                "MyClass::MyClass(int param1, int param2)\n" +
5014
                "MyClass::MyClass(int param1, int param2)\n" +
Lines 5025-5036 Link Here
5025
5021
5026
    // IZ#159334:Cannot format initialization list the way I want
5022
    // IZ#159334:Cannot format initialization list the way I want
5027
    public void testIZ159334_2() {
5023
    public void testIZ159334_2() {
5028
        setDefaultsOptions();
5029
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5030
                put(EditorOptions.newLineBeforeBraceDeclaration,
5031
                CodeStyle.BracePlacement.SAME_LINE.name());
5032
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5033
                putInt(EditorOptions.constructorListContinuationIndent, 4);
5034
        setLoadDocumentText(
5024
        setLoadDocumentText(
5035
                "class Class\n" +
5025
                "class Class\n" +
5036
                "{\n" +
5026
                "{\n" +
Lines 5047-5052 Link Here
5047
                "\n" +
5037
                "\n" +
5048
                "};\n"
5038
                "};\n"
5049
                );
5039
                );
5040
        setDefaultsOptions();
5041
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5042
                put(EditorOptions.newLineBeforeBraceDeclaration,
5043
                CodeStyle.BracePlacement.SAME_LINE.name());
5044
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5045
                putInt(EditorOptions.constructorListContinuationIndent, 4);
5050
        reformat();
5046
        reformat();
5051
        assertDocumentText("IZ#159334:Cannot format initialization list the way I want",
5047
        assertDocumentText("IZ#159334:Cannot format initialization list the way I want",
5052
                "class Class\n" +
5048
                "class Class\n" +
Lines 5068-5082 Link Here
5068
    
5064
    
5069
    //  Bug 180110 - Inconsistent C/C++ switch statement formatting
5065
    //  Bug 180110 - Inconsistent C/C++ switch statement formatting
5070
    public void testIZ180110() {
5066
    public void testIZ180110() {
5071
        setDefaultsOptions();
5072
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5073
                put(EditorOptions.newLineBeforeBraceDeclaration,
5074
                CodeStyle.BracePlacement.SAME_LINE.name());
5075
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5076
                put(EditorOptions.newLineBeforeBraceSwitch,