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,
5077
                CodeStyle.BracePlacement.NEW_LINE.name());
5078
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5079
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
5080
        setLoadDocumentText(
5067
        setLoadDocumentText(
5081
                "int foo(){\n"
5068
                "int foo(){\n"
5082
                + "    switch(value)\n"
5069
                + "    switch(value)\n"
Lines 5095-5100 Link Here
5095
                + "  }\n"
5082
                + "  }\n"
5096
                + "    }\n"
5083
                + "    }\n"
5097
                + "}\n");
5084
                + "}\n");
5085
        setDefaultsOptions();
5086
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5087
                put(EditorOptions.newLineBeforeBraceDeclaration,
5088
                CodeStyle.BracePlacement.SAME_LINE.name());
5089
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5090
                put(EditorOptions.newLineBeforeBraceSwitch,
5091
                CodeStyle.BracePlacement.NEW_LINE.name());
5092
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5093
                putBoolean(EditorOptions.indentCasesFromSwitch, false);
5098
        reformat();
5094
        reformat();
5099
        assertDocumentText("Bug 180110 - Inconsistent C/C++ switch statement formatting",
5095
        assertDocumentText("Bug 180110 - Inconsistent C/C++ switch statement formatting",
5100
                "int foo() {\n"
5096
                "int foo() {\n"
Lines 5118-5124 Link Here
5118
5114
5119
    //  Bug 176820 -  Erroneous formatting of typecasting of reference
5115
    //  Bug 176820 -  Erroneous formatting of typecasting of reference
5120
    public void testIZ176820() {
5116
    public void testIZ176820() {
5121
        setDefaultsOptions();
5122
        setLoadDocumentText(
5117
        setLoadDocumentText(
5123
                "void m(char *a)\n" +
5118
                "void m(char *a)\n" +
5124
                "{\n"+
5119
                "{\n"+
Lines 5126-5131 Link Here
5126
                "    i=(int *) &a;\n"+
5121
                "    i=(int *) &a;\n"+
5127
                "}\n"
5122
                "}\n"
5128
                );
5123
                );
5124
        setDefaultsOptions();
5129
        reformat();
5125
        reformat();
5130
        assertDocumentText("Incorrect new-line indent",
5126
        assertDocumentText("Incorrect new-line indent",
5131
                "void m(char *a)\n" +
5127
                "void m(char *a)\n" +
Lines 5138-5148 Link Here
5138
5134
5139
    //  Bug 188117 - "alt+shift+f" and "\"
5135
    //  Bug 188117 - "alt+shift+f" and "\"
5140
    public void testIZ188117() {
5136
    public void testIZ188117() {
5141
        setDefaultsOptions();
5142
        setLoadDocumentText(
5137
        setLoadDocumentText(
5143
                "printf(\"example of %s issue\", \\\n" +
5138
                "printf(\"example of %s issue\", \\\n" +
5144
                "    \"this\");\n"
5139
                "    \"this\");\n"
5145
                );
5140
                );
5141
        setDefaultsOptions();
5146
        reformat();
5142
        reformat();
5147
        assertDocumentText("Incorrect \\ formatting",
5143
        assertDocumentText("Incorrect \\ formatting",
5148
                "printf(\"example of %s issue\", \\\n" +
5144
                "printf(\"example of %s issue\", \\\n" +
Lines 5150-5160 Link Here
5150
                    );
5146
                    );
5151
    }
5147
    }
5152
    public void testIZ188117_2() {
5148
    public void testIZ188117_2() {
5153
        setDefaultsOptions();
5154
        setLoadDocumentText(
5149
        setLoadDocumentText(
5155
                "printf(\"example of %s issue\",\\\n" +
5150
                "printf(\"example of %s issue\",\\\n" +
5156
                "    \"this\");\n"
5151
                "    \"this\");\n"
5157
                );
5152
                );
5153
        setDefaultsOptions();
5158
        reformat();
5154
        reformat();
5159
        assertDocumentText("Incorrect \\ formatting",
5155
        assertDocumentText("Incorrect \\ formatting",
5160
                "printf(\"example of %s issue\",\\\n" +
5156
                "printf(\"example of %s issue\",\\\n" +
Lines 5162-5173 Link Here
5162
                    );
5158
                    );
5163
    }
5159
    }
5164
    public void testIZ188117_3() {
5160
    public void testIZ188117_3() {
5165
        setDefaultsOptions();
5166
        setLoadDocumentText(
5161
        setLoadDocumentText(
5167
                "if ((data[readBytes - 2] == 05) && \\\n" +
5162
                "if ((data[readBytes - 2] == 05) && \\\n" +
5168
                "    (data[readBytes - 1] == 04)) {\n" +
5163
                "    (data[readBytes - 1] == 04)) {\n" +
5169
                "}\n"
5164
                "}\n"
5170
                );
5165
                );
5166
        setDefaultsOptions();
5171
        reformat();
5167
        reformat();
5172
        assertDocumentText("Incorrect \\ formatting",
5168
        assertDocumentText("Incorrect \\ formatting",
5173
                "if ((data[readBytes - 2] == 05) && \\\n" +
5169
                "if ((data[readBytes - 2] == 05) && \\\n" +
Lines 5177-5183 Link Here
5177
    }
5173
    }
5178
5174
5179
    public void test194239() {
5175
    public void test194239() {
5180
        setDefaultsOptions();
5181
        setLoadDocumentText(
5176
        setLoadDocumentText(
5182
                "class Foo\n" +
5177
                "class Foo\n" +
5183
                "{\n" +
5178
                "{\n" +
Lines 5186-5191 Link Here
5186
                "    Foo& xxx(const Foo& other);\n" +
5181
                "    Foo& xxx(const Foo& other);\n" +
5187
                "};\n"
5182
                "};\n"
5188
                );
5183
                );
5184
        setDefaultsOptions();
5189
        reformat();
5185
        reformat();
5190
        assertDocumentText("Incorrect \\ formatting",
5186
        assertDocumentText("Incorrect \\ formatting",
5191
                "class Foo\n" +
5187
                "class Foo\n" +
Lines 5198-5204 Link Here
5198
    }
5194
    }
5199
5195
5200
    public void test194813() {
5196
    public void test194813() {
5201
        setDefaultsOptions();
5202
        setLoadDocumentText(
5197
        setLoadDocumentText(
5203
                "class A\n" +
5198
                "class A\n" +
5204
                "{\n" +
5199
                "{\n" +
Lines 5209-5214 Link Here
5209
                "    return dynamic_cast< ::A * > (t);\n" +
5204
                "    return dynamic_cast< ::A * > (t);\n" +
5210
                "}\n"
5205
                "}\n"
5211
                );
5206
                );
5207
        setDefaultsOptions();
5212
        reformat();
5208
        reformat();
5213
        assertDocumentText("Incorrect < :: formatting",
5209
        assertDocumentText("Incorrect < :: formatting",
5214
                "class A\n" +
5210
                "class A\n" +
Lines 5223-5237 Link Here
5223
    }
5219
    }
5224
    
5220
    
5225
    public void test219414() {
5221
    public void test219414() {
5226
        setDefaultsOptions();
5227
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5228
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5229
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5230
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5231
                CodeStyle.BracePlacement.SAME_LINE.name());
5232
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5233
                put(EditorOptions.newLineBeforeBraceLambda, 
5234
                CodeStyle.BracePlacement.NEW_LINE.name());
5235
        setLoadDocumentText(
5222
        setLoadDocumentText(
5236
                "int foo() {\n" +
5223
                "int foo() {\n" +
5237
                "    result = ::std::accumulate(::std::begin(x), ::std::end(x), 0.0,\n" +
5224
                "    result = ::std::accumulate(::std::begin(x), ::std::end(x), 0.0,\n" +
Lines 5241-5246 Link Here
5241
                "       });\n" +
5228
                "       });\n" +
5242
                "}\n"
5229
                "}\n"
5243
                );
5230
                );
5231
        setDefaultsOptions();
5232
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5233
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5234
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5235
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5236
                CodeStyle.BracePlacement.SAME_LINE.name());
5237
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5238
                put(EditorOptions.newLineBeforeBraceLambda, 
5239
                CodeStyle.BracePlacement.NEW_LINE.name());
5244
        reformat();
5240
        reformat();
5245
        assertDocumentText("Incorrect < lambda formatting",
5241
        assertDocumentText("Incorrect < lambda formatting",
5246
                "int foo() {\n" +
5242
                "int foo() {\n" +
Lines 5254-5265 Link Here
5254
    }
5250
    }
5255
    
5251
    
5256
    public void test219414_2() {
5252
    public void test219414_2() {
5257
        setDefaultsOptions();
5258
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5259
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5260
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5261
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5262
                CodeStyle.BracePlacement.SAME_LINE.name());
5263
        setLoadDocumentText(
5253
        setLoadDocumentText(
5264
                "int foo() {\n" +
5254
                "int foo() {\n" +
5265
                "  [] () {\n" +
5255
                "  [] () {\n" +
Lines 5267-5272 Link Here
5267
                "  }\n" +
5257
                "  }\n" +
5268
                "}\n"
5258
                "}\n"
5269
                );
5259
                );
5260
        setDefaultsOptions();
5261
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5262
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5263
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5264
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5265
                CodeStyle.BracePlacement.SAME_LINE.name());
5270
        reformat();
5266
        reformat();
5271
        assertDocumentText("Incorrect < lambda formatting",
5267
        assertDocumentText("Incorrect < lambda formatting",
5272
                "int foo() {\n" +
5268
                "int foo() {\n" +
Lines 5278-5289 Link Here
5278
    }
5274
    }
5279
    
5275
    
5280
    public void test219414_3() {
5276
    public void test219414_3() {
5281
        setDefaultsOptions();
5282
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5283
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5284
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5285
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5286
                CodeStyle.BracePlacement.SAME_LINE.name());
5287
        setLoadDocumentText(
5277
        setLoadDocumentText(
5288
                "int foo() {\n" +
5278
                "int foo() {\n" +
5289
                "  [] {\n" +
5279
                "  [] {\n" +
Lines 5291-5296 Link Here
5291
                "  } ();\n" +
5281
                "  } ();\n" +
5292
                "}\n"
5282
                "}\n"
5293
                );
5283
                );
5284
        setDefaultsOptions();
5285
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5286
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5287
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5288
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5289
                CodeStyle.BracePlacement.SAME_LINE.name());
5294
        reformat();
5290
        reformat();
5295
        assertDocumentText("Incorrect < lambda formatting",
5291
        assertDocumentText("Incorrect < lambda formatting",
5296
                "int foo() {\n" +
5292
                "int foo() {\n" +
Lines 5302-5313 Link Here
5302
    }
5298
    }
5303
5299
5304
    public void test219414_4() {
5300
    public void test219414_4() {
5305
        setDefaultsOptions();
5306
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5307
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5308
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5309
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5310
                CodeStyle.BracePlacement.SAME_LINE.name());
5311
        setLoadDocumentText(
5301
        setLoadDocumentText(
5312
                "int foo() {\n" +
5302
                "int foo() {\n" +
5313
                "auto a = [&] {\n" +
5303
                "auto a = [&] {\n" +
Lines 5319-5324 Link Here
5319
                "  };\n" +
5309
                "  };\n" +
5320
                "}\n"
5310
                "}\n"
5321
                );
5311
                );
5312
        setDefaultsOptions();
5313
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5314
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5315
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5316
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5317
                CodeStyle.BracePlacement.SAME_LINE.name());
5322
        reformat();
5318
        reformat();
5323
        assertDocumentText("Incorrect < lambda formatting",
5319
        assertDocumentText("Incorrect < lambda formatting",
5324
                "int foo() {\n" +
5320
                "int foo() {\n" +
Lines 5334-5348 Link Here
5334
    }
5330
    }
5335
    
5331
    
5336
    public void test219414_5() {
5332
    public void test219414_5() {
5337
        setDefaultsOptions();
5338
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5339
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5340
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5341
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5342
                CodeStyle.BracePlacement.SAME_LINE.name());
5343
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5344
                put(EditorOptions.newLineBeforeBraceLambda, 
5345
                CodeStyle.BracePlacement.SAME_LINE.name());
5346
        setLoadDocumentText(
5333
        setLoadDocumentText(
5347
                "int foo() {\n" +
5334
                "int foo() {\n" +
5348
                "    for_each(v.begin(), v.end(),\n" +
5335
                "    for_each(v.begin(), v.end(),\n" +
Lines 5351-5356 Link Here
5351
                "             });\n" +
5338
                "             });\n" +
5352
                "}\n"
5339
                "}\n"
5353
                );
5340
                );
5341
        setDefaultsOptions();
5342
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5343
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5344
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5345
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5346
                CodeStyle.BracePlacement.SAME_LINE.name());
5347
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5348
                put(EditorOptions.newLineBeforeBraceLambda, 
5349
                CodeStyle.BracePlacement.SAME_LINE.name());
5354
        reformat();
5350
        reformat();
5355
        assertDocumentText("Incorrect < lambda formatting",
5351
        assertDocumentText("Incorrect < lambda formatting",
5356
                "int foo() {\n" +
5352
                "int foo() {\n" +
Lines 5363-5377 Link Here
5363
    }
5359
    }
5364
5360
5365
    public void test219414_6() {
5361
    public void test219414_6() {
5366
        setDefaultsOptions();
5367
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5368
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5369
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5370
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5371
                CodeStyle.BracePlacement.SAME_LINE.name());
5372
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5373
                put(EditorOptions.newLineBeforeBraceLambda, 
5374
                CodeStyle.BracePlacement.NEW_LINE.name());
5375
        setLoadDocumentText(
5362
        setLoadDocumentText(
5376
                "int foo() {\n" +
5363
                "int foo() {\n" +
5377
                "    for_each(v.begin(), v.end(),\n" +
5364
                "    for_each(v.begin(), v.end(),\n" +
Lines 5380-5385 Link Here
5380
                "             });\n" +
5367
                "             });\n" +
5381
                "}\n"
5368
                "}\n"
5382
                );
5369
                );
5370
        setDefaultsOptions();
5371
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5372
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5373
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5374
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5375
                CodeStyle.BracePlacement.SAME_LINE.name());
5376
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5377
                put(EditorOptions.newLineBeforeBraceLambda, 
5378
                CodeStyle.BracePlacement.NEW_LINE.name());
5383
        reformat();
5379
        reformat();
5384
        assertDocumentText("Incorrect < lambda formatting",
5380
        assertDocumentText("Incorrect < lambda formatting",
5385
                "int foo() {\n" +
5381
                "int foo() {\n" +
Lines 5393-5407 Link Here
5393
    }
5389
    }
5394
    
5390
    
5395
    public void test219414_7() {
5391
    public void test219414_7() {
5396
        setDefaultsOptions();
5397
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5398
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5399
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5400
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5401
                CodeStyle.BracePlacement.SAME_LINE.name());
5402
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5403
                put(EditorOptions.newLineBeforeBraceLambda, 
5404
                CodeStyle.BracePlacement.NEW_LINE_FULL_INDENTED.name());
5405
        setLoadDocumentText(
5392
        setLoadDocumentText(
5406
                "int foo() {\n" +
5393
                "int foo() {\n" +
5407
                "    for_each(v.begin(), v.end(),\n" +
5394
                "    for_each(v.begin(), v.end(),\n" +
Lines 5410-5415 Link Here
5410
                "             });\n" +
5397
                "             });\n" +
5411
                "}\n"
5398
                "}\n"
5412
                );
5399
                );
5400
        setDefaultsOptions();
5401
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5402
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5403
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5404
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5405
                CodeStyle.BracePlacement.SAME_LINE.name());
5406
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5407
                put(EditorOptions.newLineBeforeBraceLambda, 
5408
                CodeStyle.BracePlacement.NEW_LINE_FULL_INDENTED.name());
5413
        reformat();
5409
        reformat();
5414
        assertDocumentText("Incorrect < lambda formatting",
5410
        assertDocumentText("Incorrect < lambda formatting",
5415
                "int foo() {\n" +
5411
                "int foo() {\n" +
Lines 5423-5437 Link Here
5423
    }
5419
    }
5424
5420
5425
    public void test219414_8() {
5421
    public void test219414_8() {
5426
        setDefaultsOptions();
5427
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5428
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5429
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5430
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5431
                CodeStyle.BracePlacement.SAME_LINE.name());
5432
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5433
                put(EditorOptions.newLineBeforeBraceLambda, 
5434
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
5435
        setLoadDocumentText(
5422
        setLoadDocumentText(
5436
                "int foo() {\n" +
5423
                "int foo() {\n" +
5437
                "    for_each(v.begin(), v.end(),\n" +
5424
                "    for_each(v.begin(), v.end(),\n" +
Lines 5440-5445 Link Here
5440
                "             });\n" +
5427
                "             });\n" +
5441
                "}\n"
5428
                "}\n"
5442
                );
5429
                );
5430
        setDefaultsOptions();
5431
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5432
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
5433
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5434
                put(EditorOptions.newLineBeforeBraceDeclaration, 
5435
                CodeStyle.BracePlacement.SAME_LINE.name());
5436
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5437
                put(EditorOptions.newLineBeforeBraceLambda, 
5438
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
5443
        reformat();
5439
        reformat();
5444
        assertDocumentText("Incorrect < lambda formatting",
5440
        assertDocumentText("Incorrect < lambda formatting",
5445
                "int foo() {\n" +
5441
                "int foo() {\n" +
Lines 5453-5465 Link Here
5453
    }
5449
    }
5454
    
5450
    
5455
    public void test219417() {
5451
    public void test219417() {
5456
        setDefaultsOptions();
5457
        setLoadDocumentText(
5452
        setLoadDocumentText(
5458
                "int foo()\n" +
5453
                "int foo()\n" +
5459
                "{\n" +
5454
                "{\n" +
5460
                "    ::std::plus<Double>();\n" +
5455
                "    ::std::plus<Double>();\n" +
5461
                "}\n"
5456
                "}\n"
5462
                );
5457
                );
5458
        setDefaultsOptions();
5463
        reformat();
5459
        reformat();
5464
        assertDocumentText("Incorrect template formatting",
5460
        assertDocumentText("Incorrect template formatting",
5465
                "int foo()\n" +
5461
                "int foo()\n" +
Lines 5470-5476 Link Here
5470
    }
5466
    }
5471
5467
5472
    public void test216976() {
5468
    public void test216976() {
5473
        setDefaultsOptions();
5474
        setLoadDocumentText(
5469
        setLoadDocumentText(
5475
                "struct Compare\n" +
5470
                "struct Compare\n" +
5476
                "{\n" +
5471
                "{\n" +
Lines 5481-5486 Link Here
5481
                "    }\n" +
5476
                "    }\n" +
5482
                "}\n"
5477
                "}\n"
5483
                );
5478
                );
5479
        setDefaultsOptions();
5484
        reformat();
5480
        reformat();
5485
        assertDocumentText("Incorrect type reference formatting",
5481
        assertDocumentText("Incorrect type reference formatting",
5486
                "struct Compare\n" +
5482
                "struct Compare\n" +
Lines 5495-5501 Link Here
5495
    }
5491
    }
5496
    
5492
    
5497
    public void test219739() {
5493
    public void test219739() {
5498
        setDefaultsOptions();
5499
        setLoadDocumentText(
5494
        setLoadDocumentText(
5500
                "int foo()\n" +
5495
                "int foo()\n" +
5501
                "{\n" +
5496
                "{\n" +
Lines 5503-5508 Link Here
5503
                "        return 0;\n" +
5498
                "        return 0;\n" +
5504
                "}\n"
5499
                "}\n"
5505
                );
5500
                );
5501
        setDefaultsOptions();
5506
        reformat();
5502
        reformat();
5507
        assertDocumentText("Incorrect type reference formatting",
5503
        assertDocumentText("Incorrect type reference formatting",
5508
                "int foo()\n" +
5504
                "int foo()\n" +
Lines 5514-5526 Link Here
5514
    }
5510
    }
5515
    
5511
    
5516
    public void test216290() {
5512
    public void test216290() {
5517
        setDefaultsOptions();
5518
        setLoadDocumentText(
5513
        setLoadDocumentText(
5519
                "void someMethod(const string& s1, const string& s2)\n" +
5514
                "void someMethod(const string& s1, const string& s2)\n" +
5520
                "{\n" +
5515
                "{\n" +
5521
                "    std::get<0>(some_tuple);\n" +
5516
                "    std::get<0>(some_tuple);\n" +
5522
                "}\n"
5517
                "}\n"
5523
                );
5518
                );
5519
        setDefaultsOptions();
5524
        reformat();
5520
        reformat();
5525
        assertDocumentText("Incorrect type reference formatting",
5521
        assertDocumentText("Incorrect type reference formatting",
5526
                "void someMethod(const string& s1, const string& s2)\n" +
5522
                "void someMethod(const string& s1, const string& s2)\n" +
Lines 5531-5543 Link Here
5531
    }
5527
    }
5532
5528
5533
    public void test216290_1() {
5529
    public void test216290_1() {
5534
        setDefaultsOptions();
5535
        setLoadDocumentText(
5530
        setLoadDocumentText(
5536
                "void someMethod(const string& s1, const string& s2)\n" +
5531
                "void someMethod(const string& s1, const string& s2)\n" +
5537
                "{\n" +
5532
                "{\n" +
5538
                "    std::get<int>(some_tuple);\n" +
5533
                "    std::get<int>(some_tuple);\n" +
5539
                "}\n"
5534
                "}\n"
5540
                );
5535
                );
5536
        setDefaultsOptions();
5541
        reformat();
5537
        reformat();
5542
        assertDocumentText("Incorrect type reference formatting",
5538
        assertDocumentText("Incorrect type reference formatting",
5543
                "void someMethod(const string& s1, const string& s2)\n" +
5539
                "void someMethod(const string& s1, const string& s2)\n" +
Lines 5548-5560 Link Here
5548
    }
5544
    }
5549
5545
5550
    public void test216290_2() {
5546
    public void test216290_2() {
5551
        setDefaultsOptions();
5552
        setLoadDocumentText(
5547
        setLoadDocumentText(
5553
                "void someMethod(const string& s1, const string& s2)\n" +
5548
                "void someMethod(const string& s1, const string& s2)\n" +
5554
                "{\n" +
5549
                "{\n" +
5555
                "    std::get<class string>(some_tuple);\n" +
5550
                "    std::get<class string>(some_tuple);\n" +
5556
                "}\n"
5551
                "}\n"
5557
                );
5552
                );
5553
        setDefaultsOptions();
5558
        reformat();
5554
        reformat();
5559
        assertDocumentText("Incorrect type reference formatting",
5555
        assertDocumentText("Incorrect type reference formatting",
5560
                "void someMethod(const string& s1, const string& s2)\n" +
5556
                "void someMethod(const string& s1, const string& s2)\n" +
Lines 5565-5575 Link Here
5565
    }
5561
    }
5566
5562
5567
    public void test220196() {
5563
    public void test220196() {
5568
        setDefaultsOptions();
5569
        setLoadDocumentText(
5564
        setLoadDocumentText(
5570
                "template<typename N, typename TAG = struct asdfghjk>\n"
5565
                "template<typename N, typename TAG = struct asdfghjk>\n"
5571
              + "              void copy(){\n"
5566
              + "              void copy(){\n"
5572
              + "}\n");
5567
              + "}\n");
5568
        setDefaultsOptions();
5573
        reformat();
5569
        reformat();
5574
        assertDocumentText("Incorrect template formatting",
5570
        assertDocumentText("Incorrect template formatting",
5575
                "template<typename N, typename TAG = struct asdfghjk>\n"
5571
                "template<typename N, typename TAG = struct asdfghjk>\n"
Lines 5579-5588 Link Here
5579
    }
5575
    }
5580
    
5576
    
5581
    public void test217975() {
5577
    public void test217975() {
5582
        setDefaultsOptions();
5583
        setLoadDocumentText(
5578
        setLoadDocumentText(
5584
                "int v[] {1, 2, 3};\n"
5579
                "int v[] {1, 2, 3};\n"
5585
              + "\n");
5580
              + "\n");
5581
        setDefaultsOptions();
5586
        reformat();
5582
        reformat();
5587
        assertDocumentText("Incorrect uniform initialization",
5583
        assertDocumentText("Incorrect uniform initialization",
5588
                "int v[]{1, 2, 3};\n"
5584
                "int v[]{1, 2, 3};\n"
Lines 5590-5601 Link Here
5590
    }
5586
    }
5591
    
5587
    
5592
    public void test217975_1() {
5588
    public void test217975_1() {
5593
        setDefaultsOptions();
5594
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
5595
                putBoolean(EditorOptions.spaceBeforeArrayInitLeftBrace, true);
5596
        setLoadDocumentText(
5589
        setLoadDocumentText(
5597
                "int v[] {1, 2, 3};\n"
5590
                "int v[] {1, 2, 3};\n"
5598
              + "\n");
5591
              + "\n");
5592
        setDefaultsOptions();
5593
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
5594
                putBoolean(EditorOptions.spaceBeforeArrayInitLeftBrace, true);
5599
        reformat();
5595
        reformat();
5600
        assertDocumentText("Incorrect uniform initialization",
5596
        assertDocumentText("Incorrect uniform initialization",
5601
                "int v[] {1, 2, 3};\n"
5597
                "int v[] {1, 2, 3};\n"
Lines 5603-5614 Link Here
5603
    }
5599
    }
5604
    
5600
    
5605
    public void test217975_2() {
5601
    public void test217975_2() {
5606
        setDefaultsOptions();
5607
        setLoadDocumentText(
5602
        setLoadDocumentText(
5608
                "int &&a;\n" 
5603
                "int &&a;\n" 
5609
              + "int&& b;\n" 
5604
              + "int&& b;\n" 
5610
              + "int && c;\n"
5605
              + "int && c;\n"
5611
              + "\n");
5606
              + "\n");
5607
        setDefaultsOptions();
5612
        reformat();
5608
        reformat();
5613
        assertDocumentText("Incorrect rvalue reference",
5609
        assertDocumentText("Incorrect rvalue reference",
5614
                "int &&a;\n" 
5610
                "int &&a;\n" 
Lines 5618-5630 Link Here
5618
    }
5614
    }
5619
    
5615
    
5620
    public void test222396() {
5616
    public void test222396() {
5621
        setDefaultsOptions();
5622
        setLoadDocumentText(
5617
        setLoadDocumentText(
5623
                "if(0){\n" 
5618
                "if(0){\n" 
5624
              + "        int a=0;\n" 
5619
              + "        int a=0;\n" 
5625
              + "    }//sample comment\n"
5620
              + "    }//sample comment\n"
5626
              + "else\n"
5621
              + "else\n"
5627
              + "    int b = 1;");
5622
              + "    int b = 1;");
5623
        setDefaultsOptions();
5628
        reformat();
5624
        reformat();
5629
        assertDocumentText("Incorrect rvalue reference",
5625
        assertDocumentText("Incorrect rvalue reference",
5630
                "if (0) {\n" 
5626
                "if (0) {\n" 
Lines 5635-5646 Link Here
5635
    }
5631
    }
5636
    
5632
    
5637
    public void test222887() {
5633
    public void test222887() {
5638
        setDefaultsOptions();
5639
        setLoadDocumentText(
5634
        setLoadDocumentText(
5640
                "class A {\n" 
5635
                "class A {\n" 
5641
              + "public:\n" 
5636
              + "public:\n" 
5642
              + "    int a {(int)123};\n"
5637
              + "    int a {(int)123};\n"
5643
              + "};\n");
5638
              + "};\n");
5639
        setDefaultsOptions();
5644
        reformat();
5640
        reformat();
5645
        assertDocumentText("Incorrect C++11: brace-Initialization format",
5641
        assertDocumentText("Incorrect C++11: brace-Initialization format",
5646
                "class A\n"
5642
                "class A\n"
Lines 5651-5662 Link Here
5651
    }
5647
    }
5652
    
5648
    
5653
    public void test222887_2() {
5649
    public void test222887_2() {
5654
        setDefaultsOptions();
5655
        setLoadDocumentText(
5650
        setLoadDocumentText(
5656
                "int main()\n"
5651
                "int main()\n"
5657
              + "{\n" 
5652
              + "{\n" 
5658
              + "    int a {(int) 123};\n" 
5653
              + "    int a {(int) 123};\n" 
5659
              + "};\n");
5654
              + "};\n");
5655
        setDefaultsOptions();
5660
        reformat();
5656
        reformat();
5661
        assertDocumentText("ncorrect C++11: brace-Initialization format",
5657
        assertDocumentText("ncorrect C++11: brace-Initialization format",
5662
                "int main()\n"
5658
                "int main()\n"
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/IndentTestCase.java (-27 / +27 lines)
Lines 182-188 Link Here
182
182
183
    public void testEnterAfterIfHalf() {
183
    public void testEnterAfterIfHalf() {
184
        setDefaultsOptions();
184
        setDefaultsOptions();
185
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
185
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
186
                put(EditorOptions.newLineBeforeBrace, 
186
                put(EditorOptions.newLineBeforeBrace, 
187
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
187
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
188
        typeCharactersInText(
188
        typeCharactersInText(
Lines 195-201 Link Here
195
195
196
    public void testEnterAfterIfBraceHalf() {
196
    public void testEnterAfterIfBraceHalf() {
197
        setDefaultsOptions();
197
        setDefaultsOptions();
198
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
198
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
199
                put(EditorOptions.newLineBeforeBrace, 
199
                put(EditorOptions.newLineBeforeBrace, 
200
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
200
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
201
        typeCharactersInText(
201
        typeCharactersInText(
Lines 212-221 Link Here
212
212
213
    public void testEnterAfterIfBraceHalf2() {
213
    public void testEnterAfterIfBraceHalf2() {
214
        setDefaultsOptions();
214
        setDefaultsOptions();
215
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
215
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
216
                put(EditorOptions.newLineBeforeBraceDeclaration, 
216
                put(EditorOptions.newLineBeforeBraceDeclaration, 
217
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
217
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
218
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
218
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
219
                put(EditorOptions.newLineBeforeBrace, 
219
                put(EditorOptions.newLineBeforeBrace, 
220
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
220
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
221
        typeCharactersInText(
221
        typeCharactersInText(
Lines 248-254 Link Here
248
248
249
    public void testEnterAfterForHalf() {
249
    public void testEnterAfterForHalf() {
250
        setDefaultsOptions();
250
        setDefaultsOptions();
251
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
251
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
252
                put(EditorOptions.newLineBeforeBrace, 
252
                put(EditorOptions.newLineBeforeBrace, 
253
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
253
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
254
        typeCharactersInText(
254
        typeCharactersInText(
Lines 271-277 Link Here
271
271
272
    public void testEnterAfterWhileHalf() {
272
    public void testEnterAfterWhileHalf() {
273
        setDefaultsOptions();
273
        setDefaultsOptions();
274
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
274
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
275
                put(EditorOptions.newLineBeforeBrace, 
275
                put(EditorOptions.newLineBeforeBrace, 
276
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
276
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
277
        typeCharactersInText(
277
        typeCharactersInText(
Lines 294-300 Link Here
294
    
294
    
295
    public void testEnterAfterDoHalf() {
295
    public void testEnterAfterDoHalf() {
296
        setDefaultsOptions();
296
        setDefaultsOptions();
297
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
297
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
298
                put(EditorOptions.newLineBeforeBrace, 
298
                put(EditorOptions.newLineBeforeBrace, 
299
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
299
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
300
        typeCharactersInText(
300
        typeCharactersInText(
Lines 319-325 Link Here
319
    
319
    
320
    public void testEnterAfterIfStmtHalf() {
320
    public void testEnterAfterIfStmtHalf() {
321
        setDefaultsOptions();
321
        setDefaultsOptions();
322
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
322
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
323
                put(EditorOptions.newLineBeforeBrace, 
323
                put(EditorOptions.newLineBeforeBrace, 
324
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
324
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
325
        typeCharactersInText(
325
        typeCharactersInText(
Lines 348-354 Link Here
348
348
349
    public void testEnterAfterIfElseHalf() {
349
    public void testEnterAfterIfElseHalf() {
350
        setDefaultsOptions();
350
        setDefaultsOptions();
351
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
351
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
352
                put(EditorOptions.newLineBeforeBrace, 
352
                put(EditorOptions.newLineBeforeBrace, 
353
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
353
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
354
        typeCharactersInText(
354
        typeCharactersInText(
Lines 495-501 Link Here
495
    public void testIdentMainHalf() {
495
    public void testIdentMainHalf() {
496
        setCppEditorKit(false);
496
        setCppEditorKit(false);
497
        setDefaultsOptions();
497
        setDefaultsOptions();
498
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
498
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
499
                put(EditorOptions.newLineBeforeBraceDeclaration, 
499
                put(EditorOptions.newLineBeforeBraceDeclaration, 
500
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
500
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
501
        typeCharactersInText(
501
        typeCharactersInText(
Lines 509-515 Link Here
509
    public void testIdentMainHalf2() {
509
    public void testIdentMainHalf2() {
510
        setCppEditorKit(false);
510
        setCppEditorKit(false);
511
        setDefaultsOptions();
511
        setDefaultsOptions();
512
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
512
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
513
                put(EditorOptions.newLineBeforeBraceDeclaration, 
513
                put(EditorOptions.newLineBeforeBraceDeclaration, 
514
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
514
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
515
        typeCharactersInText(
515
        typeCharactersInText(
Lines 522-528 Link Here
522
    public void testIdentMainHalf3() {
522
    public void testIdentMainHalf3() {
523
        setCppEditorKit(false);
523
        setCppEditorKit(false);
524
        setDefaultsOptions();
524
        setDefaultsOptions();
525
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
525
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
526
                put(EditorOptions.newLineBeforeBraceDeclaration, 
526
                put(EditorOptions.newLineBeforeBraceDeclaration, 
527
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
527
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
528
        typeCharactersInText(
528
        typeCharactersInText(
Lines 578-584 Link Here
578
    public void testIdentMethodParameters2() {
578
    public void testIdentMethodParameters2() {
579
        setCppEditorKit(false);
579
        setCppEditorKit(false);
580
        setDefaultsOptions();
580
        setDefaultsOptions();
581
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
581
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
582
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
582
                putBoolean(EditorOptions.alignMultilineMethodParams, true);
583
        typeCharactersInText(
583
        typeCharactersInText(
584
            "int longmain(int a,|\n", // "Incorrect identing of main",
584
            "int longmain(int a,|\n", // "Incorrect identing of main",
Lines 605-611 Link Here
605
     */
605
     */
606
    public void testIdentCallParameters2() {
606
    public void testIdentCallParameters2() {
607
        setDefaultsOptions();
607
        setDefaultsOptions();
608
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
608
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
609
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
609
                putBoolean(EditorOptions.alignMultilineCallArgs, true);
610
        typeCharactersInText(
610
        typeCharactersInText(
611
            "a = longmain(a,|\n", // "Incorrect identing of main",
611
            "a = longmain(a,|\n", // "Incorrect identing of main",
Lines 728-734 Link Here
728
    public void testIZ150788() {
728
    public void testIZ150788() {
729
        setCppEditorKit(false);
729
        setCppEditorKit(false);
730
        setDefaultsOptions();
730
        setDefaultsOptions();
731
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
731
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
732
                putBoolean(EditorOptions.alignMultilineIfCondition, true);
732
                putBoolean(EditorOptions.alignMultilineIfCondition, true);
733
        typeCharactersInText(
733
        typeCharactersInText(
734
            "if (a &&|)", // "Incorrect identing IZ:150788 Slight flaw in apache-style indentation",
734
            "if (a &&|)", // "Incorrect identing IZ:150788 Slight flaw in apache-style indentation",
Lines 742-748 Link Here
742
    public void testIZ150788_2() {
742
    public void testIZ150788_2() {
743
        setCppEditorKit(false);
743
        setCppEditorKit(false);
744
        setDefaultsOptions();
744
        setDefaultsOptions();
745
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
745
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
746
                putBoolean(EditorOptions.alignMultilineWhileCondition, true);
746
                putBoolean(EditorOptions.alignMultilineWhileCondition, true);
747
        typeCharactersInText(
747
        typeCharactersInText(
748
            "while(a &&|)", // "Incorrect identing IZ:150788 Slight flaw in apache-style indentation",
748
            "while(a &&|)", // "Incorrect identing IZ:150788 Slight flaw in apache-style indentation",
Lines 757-763 Link Here
757
    public void testIZ150788_3() {
757
    public void testIZ150788_3() {
758
        setCppEditorKit(false);
758
        setCppEditorKit(false);
759
        setDefaultsOptions();
759
        setDefaultsOptions();
760
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
760
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
761
                putBoolean(EditorOptions.alignMultilineFor, true);
761
                putBoolean(EditorOptions.alignMultilineFor, true);
762
        typeCharactersInText(
762
        typeCharactersInText(
763
            "for  (int a = 0;|)", // "Incorrect identing IZ:150788 Slight flaw in apache-style indentation",
763
            "for  (int a = 0;|)", // "Incorrect identing IZ:150788 Slight flaw in apache-style indentation",
Lines 920-926 Link Here
920
    public void testIZ171413() {
920
    public void testIZ171413() {
921
        setCppEditorKit(false);
921
        setCppEditorKit(false);
922
        setDefaultsOptions();
922
        setDefaultsOptions();
923
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C)).
923
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.C, getDocument())).
924
                put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE.name());
924
                put(EditorOptions.newLineBeforeBrace, CodeStyle.BracePlacement.NEW_LINE.name());
925
        typeCharactersInText(
925
        typeCharactersInText(
926
            "for (Protein::bb_torsion_it_t _bbt_it = _prot_gap.Torsions().begin();\n"+
926
            "for (Protein::bb_torsion_it_t _bbt_it = _prot_gap.Torsions().begin();\n"+
Lines 952-958 Link Here
952
    // Bug 176850 -  Impossible to turn off C++ namespace indenting
952
    // Bug 176850 -  Impossible to turn off C++ namespace indenting
953
    public void testIZ176850() {
953
    public void testIZ176850() {
954
        setDefaultsOptions();
954
        setDefaultsOptions();
955
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
955
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
956
                putBoolean(EditorOptions.indentNamespace, false);
956
                putBoolean(EditorOptions.indentNamespace, false);
957
        typeCharactersInText(
957
        typeCharactersInText(
958
                  "namespace maths {|", // "Incorrect new-line indent",
958
                  "namespace maths {|", // "Incorrect new-line indent",
Lines 1127-1135 Link Here
1127
1127
1128
    public void testPreprocessorIndentTyping2() throws Exception {
1128
    public void testPreprocessorIndentTyping2() throws Exception {
1129
        setDefaultsOptions();
1129
        setDefaultsOptions();
1130
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1130
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1131
                putBoolean(EditorOptions.sharpAtStartLine, false);
1131
                putBoolean(EditorOptions.sharpAtStartLine, false);
1132
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1132
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1133
                put(EditorOptions.indentPreprocessorDirectives, CodeStyle.PreprocessorIndent.PREPROCESSOR_INDENT.name());
1133
                put(EditorOptions.indentPreprocessorDirectives, CodeStyle.PreprocessorIndent.PREPROCESSOR_INDENT.name());
1134
        typeCharactersInText(
1134
        typeCharactersInText(
1135
                "#ifdef AAA\n" +
1135
                "#ifdef AAA\n" +
Lines 1144-1152 Link Here
1144
1144
1145
    public void testPreprocessorIndentTyping3() throws Exception {
1145
    public void testPreprocessorIndentTyping3() throws Exception {
1146
        setDefaultsOptions();
1146
        setDefaultsOptions();
1147
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1147
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1148
                putBoolean(EditorOptions.sharpAtStartLine, false);
1148
                putBoolean(EditorOptions.sharpAtStartLine, false);
1149
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1149
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1150
                put(EditorOptions.indentPreprocessorDirectives, CodeStyle.PreprocessorIndent.PREPROCESSOR_INDENT.name());
1150
                put(EditorOptions.indentPreprocessorDirectives, CodeStyle.PreprocessorIndent.PREPROCESSOR_INDENT.name());
1151
        typeCharactersInText(
1151
        typeCharactersInText(
1152
                "#ifdef AAA\n" +
1152
                "#ifdef AAA\n" +
Lines 1219-1225 Link Here
1219
1219
1220
    public void testEnterAfterLambdaHalf() {
1220
    public void testEnterAfterLambdaHalf() {
1221
        setDefaultsOptions();
1221
        setDefaultsOptions();
1222
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1222
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1223
                put(EditorOptions.newLineBeforeBraceLambda, 
1223
                put(EditorOptions.newLineBeforeBraceLambda, 
1224
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1224
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1225
        typeCharactersInText(
1225
        typeCharactersInText(
Lines 1235-1241 Link Here
1235
1235
1236
    public void testEnterAfterLambdaHalf_1() {
1236
    public void testEnterAfterLambdaHalf_1() {
1237
        setDefaultsOptions();
1237
        setDefaultsOptions();
1238
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1238
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1239
                put(EditorOptions.newLineBeforeBraceLambda, 
1239
                put(EditorOptions.newLineBeforeBraceLambda, 
1240
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1240
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1241
        typeCharactersInText(
1241
        typeCharactersInText(
Lines 1250-1256 Link Here
1250
1250
1251
    public void testEnterAfterLambdaHalf_2() {
1251
    public void testEnterAfterLambdaHalf_2() {
1252
        setDefaultsOptions();
1252
        setDefaultsOptions();
1253
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1253
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1254
                put(EditorOptions.newLineBeforeBraceLambda, 
1254
                put(EditorOptions.newLineBeforeBraceLambda, 
1255
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1255
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1256
        typeCharactersInText(
1256
        typeCharactersInText(
Lines 1266-1272 Link Here
1266
1266
1267
    public void testEnterAfterLambdaHalf_3() {
1267
    public void testEnterAfterLambdaHalf_3() {
1268
        setDefaultsOptions();
1268
        setDefaultsOptions();
1269
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP)).
1269
        EditorOptions.getPreferences(CodeStyle.getDefault(CodeStyle.Language.CPP, getDocument())).
1270
                put(EditorOptions.newLineBeforeBraceLambda, 
1270
                put(EditorOptions.newLineBeforeBraceLambda, 
1271
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1271
                CodeStyle.BracePlacement.NEW_LINE_HALF_INDENTED.name());
1272
        typeCharactersInText(
1272
        typeCharactersInText(
(-)a/cnd.makeproject/nbproject/project.xml (+9 lines)
Lines 124-129 Link Here
124
                    </run-dependency>
124
                    </run-dependency>
125
                </dependency>
125
                </dependency>
126
                <dependency>
126
                <dependency>
127
                    <code-name-base>org.netbeans.modules.editor.indent.project</code-name-base>
128
                    <build-prerequisite/>
129
                    <compile-dependency/>
130
                    <run-dependency>
131
                        <release-version>0-1</release-version>
132
                        <specification-version>1.13</specification-version>
133
                    </run-dependency>
134
                </dependency>
135
                <dependency>
127
                    <code-name-base>org.netbeans.modules.extexecution</code-name-base>
136
                    <code-name-base>org.netbeans.modules.extexecution</code-name-base>
128
                    <build-prerequisite/>
137
                    <build-prerequisite/>
129
                    <compile-dependency/>
138
                    <compile-dependency/>
(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/api/configurations/ui/CustomizerNode.java (-2 / +2 lines)
Lines 44-50 Link Here
44
44
45
package org.netbeans.modules.cnd.makeproject.api.configurations.ui;
45
package org.netbeans.modules.cnd.makeproject.api.configurations.ui;
46
46
47
import javax.swing.JPanel;
47
import javax.swing.JComponent;
48
import org.netbeans.modules.cnd.makeproject.api.configurations.Configuration;
48
import org.netbeans.modules.cnd.makeproject.api.configurations.Configuration;
49
import org.netbeans.modules.cnd.makeproject.ui.customizer.MakeContext;
49
import org.netbeans.modules.cnd.makeproject.ui.customizer.MakeContext;
50
import org.openide.nodes.Sheet;
50
import org.openide.nodes.Sheet;
Lines 81-87 Link Here
81
        return null;
81
        return null;
82
    }
82
    }
83
    
83
    
84
    public JPanel getPanel(Configuration configuration) {
84
    public JComponent getPanel(Configuration configuration) {
85
        return null;
85
        return null;
86
    }
86
    }
87
87
(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/configurations/ui/ProjectPropPanel.form (-1 / +1 lines)
Lines 1-4 Link Here
1
<?xml version="1.1" encoding="UTF-8" ?>
1
<?xml version="1.0" encoding="UTF-8" ?>
2
2
3
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AuxValues>
4
  <AuxValues>
(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/configurations/ui/ProjectPropPanel.java (-1 / +2 lines)
Lines 49-54 Link Here
49
import java.util.List;
49
import java.util.List;
50
import java.util.regex.Pattern;
50
import java.util.regex.Pattern;
51
import java.util.regex.PatternSyntaxException;
51
import java.util.regex.PatternSyntaxException;
52
import org.netbeans.api.actions.Savable;
52
import org.netbeans.api.project.Project;
53
import org.netbeans.api.project.Project;
53
import org.netbeans.modules.cnd.makeproject.MakeProject;
54
import org.netbeans.modules.cnd.makeproject.MakeProject;
54
import org.netbeans.modules.cnd.makeproject.api.MakeCustomizerProvider;
55
import org.netbeans.modules.cnd.makeproject.api.MakeCustomizerProvider;
Lines 64-70 Link Here
64
import org.openide.NotifyDescriptor;
65
import org.openide.NotifyDescriptor;
65
import org.openide.util.NbBundle;
66
import org.openide.util.NbBundle;
66
67
67
public class ProjectPropPanel extends javax.swing.JPanel implements MakeContext.Savable {
68
public class ProjectPropPanel extends javax.swing.JPanel implements Savable {
68
69
69
    private SourceRootChooser sourceRootChooser;
70
    private SourceRootChooser sourceRootChooser;
70
//    private TestRootChooser testRootChooser;
71
//    private TestRootChooser testRootChooser;
(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/ui/customizer/GeneralCustomizerNode.java (-1 / +2 lines)
Lines 45-50 Link Here
45
package org.netbeans.modules.cnd.makeproject.ui.customizer;
45
package org.netbeans.modules.cnd.makeproject.ui.customizer;
46
46
47
import javax.swing.JPanel;
47
import javax.swing.JPanel;
48
import org.netbeans.api.actions.Savable;
48
import org.netbeans.modules.cnd.makeproject.api.configurations.Configuration;
49
import org.netbeans.modules.cnd.makeproject.api.configurations.Configuration;
49
import org.netbeans.modules.cnd.makeproject.api.configurations.ui.CustomizerNode;
50
import org.netbeans.modules.cnd.makeproject.api.configurations.ui.CustomizerNode;
50
import org.netbeans.modules.cnd.makeproject.configurations.ui.ProjectPropPanel;
51
import org.netbeans.modules.cnd.makeproject.configurations.ui.ProjectPropPanel;
Lines 63-69 Link Here
63
    public JPanel getPanel(Configuration configuration) {
64
    public JPanel getPanel(Configuration configuration) {
64
        if (projectPropPanel == null) {
65
        if (projectPropPanel == null) {
65
            projectPropPanel = new ProjectPropPanel(getContext().getProject(), getContext().getConfigurationDescriptor());
66
            projectPropPanel = new ProjectPropPanel(getContext().getProject(), getContext().getConfigurationDescriptor());
66
            getContext().registerSavable(projectPropPanel);
67
            getContext().registerSavable((Savable)projectPropPanel);
67
        }
68
        }
68
        return projectPropPanel;
69
        return projectPropPanel;
69
    }
70
    }
(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/ui/customizer/MakeContext.java (-5 / +8 lines)
Lines 42-49 Link Here
42
42
43
package org.netbeans.modules.cnd.makeproject.ui.customizer;
43
package org.netbeans.modules.cnd.makeproject.ui.customizer;
44
44
45
import java.io.IOException;
45
import java.util.Set;
46
import java.util.Set;
46
import javax.swing.JPanel;
47
import javax.swing.JPanel;
48
import org.netbeans.api.actions.Savable;
47
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.Project;
48
import org.netbeans.modules.cnd.api.toolchain.CompilerSet;
50
import org.netbeans.modules.cnd.api.toolchain.CompilerSet;
49
import org.netbeans.modules.cnd.api.toolchain.PredefinedToolKind;
51
import org.netbeans.modules.cnd.api.toolchain.PredefinedToolKind;
Lines 53-58 Link Here
53
import org.netbeans.modules.cnd.makeproject.api.configurations.ItemConfiguration;
55
import org.netbeans.modules.cnd.makeproject.api.configurations.ItemConfiguration;
54
import org.netbeans.modules.cnd.makeproject.api.configurations.MakeConfiguration;
56
import org.netbeans.modules.cnd.makeproject.api.configurations.MakeConfiguration;
55
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
57
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
58
import org.openide.util.Exceptions;
56
import org.openide.util.WeakSet;
59
import org.openide.util.WeakSet;
57
60
58
/**
61
/**
Lines 67-76 Link Here
67
        Item
70
        Item
68
    }
71
    }
69
72
70
    public static interface Savable {
71
        void save();
72
    }
73
74
    private final Kind kind;
73
    private final Kind kind;
75
    private final Project project;
74
    private final Project project;
76
    private final ExecutionEnvironment env;
75
    private final ExecutionEnvironment env;
Lines 169-175 Link Here
169
168
170
    public void save() {
169
    public void save() {
171
        for(Savable listener : listeners) {
170
        for(Savable listener : listeners) {
172
            listener.save();
171
            try {
172
                listener.save();
173
            } catch (IOException ex) {
174
                Exceptions.printStackTrace(ex);
175
            }
173
        }
176
        }
174
    }
177
    }
175
178
(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/ui/customizer/ProjectNodeFactory.java (-1 / +2 lines)
Lines 89-95 Link Here
89
        if (node != null) {
89
        if (node != null) {
90
            descriptions.add(node);
90
            descriptions.add(node);
91
        }
91
        }
92
93
        // Run customizers
92
        // Run customizers
94
        List<CustomizerNode> runCustomizers = CustomizerRootNodeProvider.getInstance().getCustomizerNodes("Run", lookup); // NOI18N
93
        List<CustomizerNode> runCustomizers = CustomizerRootNodeProvider.getInstance().getCustomizerNodes("Run", lookup); // NOI18N
95
        if (includeRunDebugDescriptions) {
94
        if (includeRunDebugDescriptions) {
Lines 125-130 Link Here
125
            descriptions.add(createCodeAssistantDescription(lookup));
124
            descriptions.add(createCodeAssistantDescription(lookup));
126
        }
125
        }
127
126
127
        descriptions.add(FormattingCustomizerNode.formattingFactory(lookup));
128
128
        CustomizerNode rootDescription = new CustomizerNode(
129
        CustomizerNode rootDescription = new CustomizerNode(
129
                "Configuration Properties", getString("CONFIGURATION_PROPERTIES"), descriptions.toArray(new CustomizerNode[descriptions.size()]), lookup);  // NOI18N
130
                "Configuration Properties", getString("CONFIGURATION_PROPERTIES"), descriptions.toArray(new CustomizerNode[descriptions.size()]), lookup);  // NOI18N
130
131
(-)a/cnd.makeproject/src/org/netbeans/modules/cnd/makeproject/ui/customizer/PropertyNode.java (-1 / +2 lines)
Lines 44-49 Link Here
44
44
45
package org.netbeans.modules.cnd.makeproject.ui.customizer;
45
package org.netbeans.modules.cnd.makeproject.ui.customizer;
46
46
47
import javax.swing.JComponent;
47
import javax.swing.JPanel;
48
import javax.swing.JPanel;
48
import org.netbeans.modules.cnd.makeproject.api.configurations.Configuration;
49
import org.netbeans.modules.cnd.makeproject.api.configurations.Configuration;
49
import org.netbeans.modules.cnd.makeproject.api.configurations.ui.CustomizerNode;
50
import org.netbeans.modules.cnd.makeproject.api.configurations.ui.CustomizerNode;
Lines 75-81 Link Here
75
        return description.getSheet(configuration);
76
        return description.getSheet(configuration);
76
    }
77
    }
77
78
78
    public JPanel getPanel(Configuration configuration) {
79
    public JComponent getPanel(Configuration configuration) {
79
        return description.getPanel(configuration);
80
        return description.getPanel(configuration);
80
    }
81
    }
81
82
(-)a/cnd.refactoring/nbproject/project.xml (-1 / +1 lines)
Lines 29-35 Link Here
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>1</release-version>
31
                        <release-version>1</release-version>
32
                        <specification-version>1.3</specification-version>
32
                        <specification-version>1.23</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/cnd.refactoring/src/org/netbeans/modules/cnd/refactoring/plugins/EncapsulateFieldRefactoringPlugin.java (-1 / +2 lines)
Lines 611-617 Link Here
611
                DeclarationGenerator.Kind declKind;
611
                DeclarationGenerator.Kind declKind;
612
                if (refactoring.isMethodInline()) {
612
                if (refactoring.isMethodInline()) {
613
                    declKind = DeclarationGenerator.Kind.INLINE_DEFINITION;
613
                    declKind = DeclarationGenerator.Kind.INLINE_DEFINITION;
614
                    if (CodeStyle.getDefault(CodeStyle.Language.CPP).getUseInlineKeyword()) {
614
                    Document doc = CsmUtilities.getDocument(fo);
615
                    if (CodeStyle.getDefault(CodeStyle.Language.CPP, doc).getUseInlineKeyword()) {
615
                        declKind = DeclarationGenerator.Kind.INLINE_DEFINITION_MAKRED_INLINE;
616
                        declKind = DeclarationGenerator.Kind.INLINE_DEFINITION_MAKRED_INLINE;
616
                    }
617
                    }
617
                } else {
618
                } else {
(-)a/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/preferences/PreferencesImpl.java (-53 / +89 lines)
Lines 80-86 Link Here
80
        PreferencesImpl prefs = INSTANCES.get(mimePath);
80
        PreferencesImpl prefs = INSTANCES.get(mimePath);
81
        
81
        
82
        if (prefs == null) {
82
        if (prefs == null) {
83
            prefs = new PreferencesImpl(mimePath.getPath());
83
            prefs = new PreferencesImpl(null, mimePath.getPath(), "");
84
            INSTANCES.put(mimePath, prefs);
84
            INSTANCES.put(mimePath, prefs);
85
        }
85
        }
86
        
86
        
Lines 91-135 Link Here
91
    // Preferences API
91
    // Preferences API
92
    // ---------------------------------------------------------------------
92
    // ---------------------------------------------------------------------
93
    
93
    
94
    public @Override String absolutePath() {
94
//    public @Override String absolutePath() {
95
        return SLASH;
95
//        return SLASH;
96
    }
96
//    }
97
97
//
98
    public @Override String[] childrenNames() throws BackingStoreException {
98
//    public @Override String[] childrenNames() throws BackingStoreException {
99
        return EMPTY_ARRAY;
99
//        return EMPTY_ARRAY;
100
    }
100
//    }
101
101
102
    public @Override boolean isUserNode() {
102
    public @Override boolean isUserNode() {
103
        return true;
103
        return true;
104
    }
104
    }
105
105
106
    public @Override String name() {
106
//    public @Override String name() {
107
        return EMPTY;
107
//        return EMPTY;
108
    }
108
//    }
109
109
110
    public @Override Preferences node(String path) {
110
//    public @Override Preferences node(String path) {
111
        if (path.length() == 0 || path.equals(SLASH)) {
111
//        if (path.length() == 0 || path.equals(SLASH)) {
112
            return this;
112
//            return this;
113
        } else {
113
//        } else {
114
            throw new IllegalStateException("Editor Preferences does not support children nodes."); //NOI18N
114
//            throw new IllegalStateException("Editor Preferences does not support children nodes."); //NOI18N
115
        }
115
//        }
116
    }
116
//    }
117
//
118
//    public @Override boolean nodeExists(String path) throws BackingStoreException {
119
//        if (path.length() == 0 || path.equals(SLASH)) {
120
//            return true;
121
//        } else {
122
//            return false;
123
//        }
124
//    }
117
125
118
    public @Override boolean nodeExists(String path) throws BackingStoreException {
126
//    public @Override Preferences parent() {
119
        if (path.length() == 0 || path.equals(SLASH)) {
127
//        return null;
120
            return true;
128
//    }
121
        } else {
122
            return false;
123
        }
124
    }
125
129
126
    public @Override Preferences parent() {
130
//    public @Override void removeNode() throws BackingStoreException {
127
        return null;
131
//        throw new IllegalStateException("Can't remove the root!"); //NOI18N
128
    }
132
//    }
129
130
    public @Override void removeNode() throws BackingStoreException {
131
        throw new IllegalStateException("Can't remove the root!"); //NOI18N
132
    }
133
133
134
    public @Override final void sync() throws BackingStoreException {
134
    public @Override final void sync() throws BackingStoreException {
135
        flushTask.waitFinished();
135
        flushTask.waitFinished();
Lines 257-284 Link Here
257
    // AbstractPreferences SPI
257
    // AbstractPreferences SPI
258
    // ---------------------------------------------------------------------
258
    // ---------------------------------------------------------------------
259
259
260
    @Override
260
//    @Override
261
    protected AbstractPreferences getChild(String nodeName) throws BackingStoreException {
261
//    protected AbstractPreferences getChild(String nodeName) throws BackingStoreException {
262
        throw new IllegalStateException("Should never be called."); //NOI18N
262
//        throw new IllegalStateException("Should never be called."); //NOI18N
263
//    }
264
//
265
//    @Override
266
//    protected boolean isRemoved() {
267
//        boolean superRemoved = super.isRemoved();
268
//        assert superRemoved == false : "super.isRemoved() should always == false"; //NOI18N
269
//        return superRemoved;
270
//    }
271
//    
272
    protected @Override void removeNodeSpi() throws BackingStoreException {
273
        for (String key : keys()) {
274
            remove(key);
275
        }
276
        PreferencesImpl parent = (PreferencesImpl) parent();
277
        String subnodes = parent.get(SUBNODES_KEY, null);
278
        StringBuilder nue = new StringBuilder();
279
        String name = name();
280
        if (subnodes != null) {
281
            for (String sn : subnodes.split(":")) {
282
                if (!sn.equals(name)) {
283
                    if (nue.length() > 0) nue.append(":");
284
                    nue.append(sn);
285
                }
286
            }
287
        }
288
        if (nue.length() == 0)
289
            parent.remove(SUBNODES_KEY);
290
        else
291
            parent.put(SUBNODES_KEY, nue.toString());
292
        
263
    }
293
    }
264
294
265
    @Override
295
    private static final String SUBNODES_KEY = "-private-sub-nodes-key";
266
    protected boolean isRemoved() {
267
        boolean superRemoved = super.isRemoved();
268
        assert superRemoved == false : "super.isRemoved() should always == false"; //NOI18N
269
        return superRemoved;
270
    }
271
    
272
    protected @Override void removeNodeSpi() throws BackingStoreException {
273
        throw new IllegalStateException("Should never be called."); //NOI18N
274
    }
275
276
    protected @Override String[] childrenNamesSpi() throws BackingStoreException {
296
    protected @Override String[] childrenNamesSpi() throws BackingStoreException {
277
        throw new IllegalStateException("Should never be called."); //NOI18N
297
        String subnodes = get(SUBNODES_KEY, null);
298
        if (subnodes == null) return new String[0];
299
        return subnodes.split(":");
278
    }
300
    }
279
301
280
    protected @Override AbstractPreferences childSpi(String name) {
302
    protected @Override AbstractPreferences childSpi(String name) {
281
        throw new IllegalStateException("Should never be called."); //NOI18N
303
        String subnodes = get(SUBNODES_KEY, null);
304
        boolean found = false;
305
        if (subnodes != null) {
306
            for (String sn : subnodes.split(":")) {
307
                if (sn.equals(name)) {
308
                    found = true;
309
                }
310
            }
311
            if (!found) {
312
                put(SUBNODES_KEY, subnodes + ":" + name);
313
            }
314
        } else {
315
            put(SUBNODES_KEY, name);
316
        }
317
        return new PreferencesImpl(this, mimePath, name);
282
    }
318
    }
283
319
284
    protected @Override void putSpi(String key, String value) {
320
    protected @Override void putSpi(String key, String value) {
Lines 353-359 Link Here
353
        // changing anything.
389
        // changing anything.
354
        if (local != null) {
390
        if (local != null) {
355
            try {
391
            try {
356
                storage.save(MimePath.parse(mimePath), null, false, local);
392
                storage.save(MimePath.parse(mimePath), absolutePath().substring(1), false, local);
357
            } catch (IOException ioe) {
393
            } catch (IOException ioe) {
358
                LOG.log(Level.WARNING, "Can't save editor preferences for '" + mimePath + "'", ioe); //NOI18N
394
                LOG.log(Level.WARNING, "Can't save editor preferences for '" + mimePath + "'", ioe); //NOI18N
359
            }
395
            }
Lines 381-387 Link Here
381
417
382
    private static final Logger LOG = Logger.getLogger(PreferencesImpl.class.getName());
418
    private static final Logger LOG = Logger.getLogger(PreferencesImpl.class.getName());
383
    
419
    
384
    private static final Map<MimePath, PreferencesImpl> INSTANCES =
420
    static final Map<MimePath, PreferencesImpl> INSTANCES =
385
        new WeakHashMap<MimePath, PreferencesImpl>();
421
        new WeakHashMap<MimePath, PreferencesImpl>();
386
422
387
    private static final String SLASH = "/"; //NOI18N
423
    private static final String SLASH = "/"; //NOI18N
Lines 451-458 Link Here
451
    private Map<String, TypedValue> local = null;
487
    private Map<String, TypedValue> local = null;
452
    private Preferences inherited = null;
488
    private Preferences inherited = null;
453
    
489
    
454
    private PreferencesImpl(String mimePath) {
490
    private PreferencesImpl(AbstractPreferences parent, String mimePath, String path) {
455
        super(null, EMPTY);
491
        super(parent, path);
456
        
492
        
457
        this.mimePath = mimePath;
493
        this.mimePath = mimePath;
458
        this.storage = EditorSettingsStorage.<String, TypedValue>get(PreferencesStorage.ID);
494
        this.storage = EditorSettingsStorage.<String, TypedValue>get(PreferencesStorage.ID);
Lines 462-468 Link Here
462
    private Map<String, TypedValue> getLocal() {
498
    private Map<String, TypedValue> getLocal() {
463
        if (local == null) {
499
        if (local == null) {
464
            try {
500
            try {
465
                local = new HashMap<String, TypedValue>(storage.load(MimePath.parse(mimePath), null, false));
501
                local = new HashMap<String, TypedValue>(storage.load(MimePath.parse(mimePath), absolutePath().substring(1), false));
466
            } catch (IOException ioe) {
502
            } catch (IOException ioe) {
467
                LOG.log(Level.WARNING, "Can't load editor preferences for '" + mimePath + "'", ioe); //NOI18N
503
                LOG.log(Level.WARNING, "Can't load editor preferences for '" + mimePath + "'", ioe); //NOI18N
468
                local = new HashMap<String, TypedValue>();
504
                local = new HashMap<String, TypedValue>();
(-)a/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/preferences/PreferencesStorage.java (-1 / +1 lines)
Lines 89-95 Link Here
89
    }
89
    }
90
90
91
    public boolean isUsingProfiles() {
91
    public boolean isUsingProfiles() {
92
        return false;
92
        return true;
93
    }
93
    }
94
94
95
    public String getMimeType() {
95
    public String getMimeType() {

Return to bug 186628