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 / +10 lines)
Lines 1-6 Link Here
1
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
2
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
3
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4
4
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8
5
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80
6
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap=none
7
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project
8
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceBeforeMethodCallParen=true
9
auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceBeforeMethodDeclParen=true
1
javac.compilerargs=-Xlint -Xlint:-serial
10
javac.compilerargs=-Xlint -Xlint:-serial
2
javac.source=1.6
11
javac.source=1.6
3
spec.version.base=1.22.0
12
spec.version.base=1.23
4
13
5
test.config.stableBTD.includes=**/*Test.class
14
test.config.stableBTD.includes=**/*Test.class
6
test.config.stableBTD.excludes=\
15
test.config.stableBTD.excludes=\
(-)a/cnd.editor/nbproject/project.xml (+9 lines)
Lines 112-117 Link Here
112
                    </run-dependency>
112
                    </run-dependency>
113
                </dependency>
113
                </dependency>
114
                <dependency>
114
                <dependency>
115
                    <code-name-base>org.netbeans.modules.editor.settings.storage</code-name-base>
116
                    <build-prerequisite/>
117
                    <compile-dependency/>
118
                    <run-dependency>
119
                        <release-version>1</release-version>
120
                        <specification-version>1.38</specification-version>
121
                    </run-dependency>
122
                </dependency>
123
                <dependency>
115
                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
124
                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
116
                    <build-prerequisite/>
125
                    <build-prerequisite/>
117
                    <compile-dependency/>
126
                    <compile-dependency/>
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/api/CodeStyle.java (-44 / +51 lines)
Lines 58-98 Link Here
58
        EditorOptions.codeStyleFactory = new FactoryImpl();
58
        EditorOptions.codeStyleFactory = new FactoryImpl();
59
    }
59
    }
60
60
61
    private static CodeStyle INSTANCE_C;
61
    private final Language language;
62
    private static CodeStyle INSTANCE_H;
63
    private static CodeStyle INSTANCE_CPP;
64
    private Language language;
65
    private Preferences preferences;
62
    private Preferences preferences;
63
    private String styleID;
66
    private final boolean useOverrideOptions;
64
    private final boolean useOverrideOptions;
67
65
68
    private CodeStyle(Language language, Preferences preferences, boolean useOverrideOptions) {
66
    private CodeStyle(Language language, Preferences preferences, String styleID, boolean useOverrideOptions) {
67
        assert language != null;
69
        this.language = language;
68
        this.language = language;
69
        assert preferences != null;
70
        this.preferences = preferences;
70
        this.preferences = preferences;
71
        assert styleID != null;
72
        this.styleID = styleID;
71
        this.useOverrideOptions = useOverrideOptions;
73
        this.useOverrideOptions = useOverrideOptions;
72
    }
74
    }
73
75
74
    public synchronized static CodeStyle getDefault(Language language) {
76
    public synchronized static CodeStyle getDefault(Language language, Document doc) {
75
        switch(language) {
77
        assert doc != null;
76
            case C:
78
        CodeStyle aCodeStyle = create(language, doc);
77
                if (INSTANCE_C == null) {
79
        setSimplePreferences(language, aCodeStyle);
78
                    INSTANCE_C = create(language);
80
        return aCodeStyle;
79
                    setSimplePreferences(language, INSTANCE_C);
81
    }
80
                }
82
81
                return INSTANCE_C;
83
    public synchronized static CodeStyle getDefault(Language language, Preferences pref) {
82
            case HEADER:
84
        CodeStyle aCodeStyle = create(language, pref);
83
                if (INSTANCE_H == null) {
85
        setSimplePreferences(language, aCodeStyle);
84
                    INSTANCE_H = create(language);
86
        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
    }
87
    }
97
    
88
    
98
    private static void setSimplePreferences(Language language, CodeStyle codeStyle){
89
    private static void setSimplePreferences(Language language, CodeStyle codeStyle){
Lines 110-127 Link Here
110
            //}
101
            //}
111
        } else {
102
        } else {
112
            if (mimeType.equals(MIMENames.C_MIME_TYPE)) {
103
            if (mimeType.equals(MIMENames.C_MIME_TYPE)) {
113
                return getDefault(Language.C);
104
                return getDefault(Language.C, doc);
114
            } else if (mimeType.equals(MIMENames.HEADER_MIME_TYPE)) {
105
            } else if (mimeType.equals(MIMENames.HEADER_MIME_TYPE)) {
115
                return getDefault(Language.HEADER);
106
                return getDefault(Language.HEADER, doc);
116
            }
107
            }
117
        }
108
        }
118
        return getDefault(Language.CPP);
109
        return getDefault(Language.CPP, doc);
119
    }
110
    }
120
111
121
    private static CodeStyle create(Language language) {
112
    private static CodeStyle create(Language language, Document doc) {
122
        return new CodeStyle(language, EditorOptions.getPreferences(language, EditorOptions.getCurrentProfileId(language)), true);
113
        final String currentProfileId = EditorOptions.getCurrentProfileId(language, doc);
114
        return new CodeStyle(language, EditorOptions.getPreferences(language, currentProfileId, doc), currentProfileId, true);
123
    }
115
    }
124
116
117
    private static CodeStyle create(Language language, Preferences pref) {
118
        final String currentProfileId = EditorOptions.getCurrentProfileId(language, pref);
119
        return new CodeStyle(language, pref, currentProfileId, true);
120
    }
121
    
125
    // General indents ------------------------------------------------
122
    // General indents ------------------------------------------------
126
    
123
    
127
    private boolean isOverideTabIndents(){
124
    private boolean isOverideTabIndents(){
Lines 522-547 Link Here
522
//    }
519
//    }
523
520
524
    private boolean getOption(String key, boolean defaultValue) {
521
    private boolean getOption(String key, boolean defaultValue) {
525
        defaultValue = (Boolean)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language), key);
522
        defaultValue = (Boolean)EditorOptions.getDefault(language, styleID, key);
526
        return getPreferences().getBoolean(key, defaultValue);
523
        return getPreferences().getBoolean(styleID+'.'+key, defaultValue);
527
    }
524
    }
528
525
529
    private int getOption(String key, int defaultValue) {
526
    private int getOption(String key, int defaultValue) {
530
        defaultValue = (Integer)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language), key);
527
        defaultValue = (Integer)EditorOptions.getDefault(language, styleID, key);
531
        return getPreferences().getInt(key, defaultValue);
528
        return getPreferences().getInt(styleID+'.'+key, defaultValue);
532
    }
529
    }
533
530
534
    private String getOption(String key, String defaultValue) {
531
    private String getOption(String key, String defaultValue) {
535
        defaultValue = (String)EditorOptions.getDefault(language, EditorOptions.getCurrentProfileId(language), key);
532
        defaultValue = (String)EditorOptions.getDefault(language, styleID, key);
536
        return getPreferences().get(key, defaultValue);
533
        return getPreferences().get(styleID+'.'+key, defaultValue);
537
    }
534
    }
538
535
539
    private Preferences getPreferences(){
536
    private Preferences getPreferences(){
540
        return preferences;
537
        return preferences;
541
    }
538
    }
542
539
543
    private void setPreferences(Preferences preferences){
540
    private String getStyleID(){
541
        return styleID;
542
    }
543
544
    private void setPreferences(Preferences preferences, String styleID){
544
        this.preferences = preferences;
545
        this.preferences = preferences;
546
        this.styleID = styleID;
545
    }
547
    }
546
548
547
    @Override
549
    @Override
Lines 597-612 Link Here
597
    // Communication with non public packages ----------------------------------
599
    // Communication with non public packages ----------------------------------
598
    private static class FactoryImpl implements EditorOptions.CodeStyleFactory {
600
    private static class FactoryImpl implements EditorOptions.CodeStyleFactory {
599
        @Override
601
        @Override
600
        public CodeStyle create(Language language, Preferences preferences, boolean useOverrideOptions) {
602
        public CodeStyle create(Language language, Preferences preferences, String styleID, boolean useOverrideOption) {
601
            return new CodeStyle(language, preferences, useOverrideOptions);
603
            return new CodeStyle(language, preferences, styleID, useOverrideOption);
602
        }
604
        }
603
        @Override
605
        @Override
604
        public Preferences getPreferences(CodeStyle codeStyle) {
606
        public Preferences getPreferences(CodeStyle codeStyle) {
605
            return codeStyle.getPreferences();
607
            return codeStyle.getPreferences();
606
        }
608
        }
607
        @Override
609
        @Override
608
        public void setPreferences(CodeStyle codeStyle, Preferences preferences) {
610
        public void setPreferences(CodeStyle codeStyle, Preferences preferences, String styleID) {
609
            codeStyle.setPreferences(preferences);
611
            codeStyle.setPreferences(preferences, styleID);
610
        }
612
        }
611
    } 
613
614
        @Override
615
        public String getStyleID(CodeStyle codeStyle) {
616
            return codeStyle.getStyleID();
617
        }
618
    }
612
}
619
}
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/layer.xml (-18 / +36 lines)
Lines 21-117 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="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_TabsIndents.c"/>
26
                            <attr name="position" intvalue="100"/>
27
                            <attr name="position" intvalue="100"/>
27
                        </file>
28
                        </file>
28
                        <file name="TabsAndIndents.instance">
29
                        <file name="TabsAndIndents.instance">
29
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
30
                            <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"/>
31
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerTabs"/>
32
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_TabsIndents.cpp"/>
31
                            <attr name="position" intvalue="200"/>
33
                            <attr name="position" intvalue="200"/>
32
                        </file>
34
                        </file>
33
                        <file name="Alignment.instance">
35
                        <file name="Alignment.instance">
34
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
36
                            <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"/>
37
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerAlignment"/>
38
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_AlignBraces.c"/>
36
                            <attr name="position" intvalue="300"/>
39
                            <attr name="position" intvalue="300"/>
37
                        </file>
40
                        </file>
38
                        <file name="Braces.instance">
41
                        <file name="Braces.instance">
39
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
42
                            <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"/>
43
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerBraces"/>
44
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_AlignBraces.c"/>
41
                            <attr name="position" intvalue="400"/>
45
                            <attr name="position" intvalue="400"/>
42
                        </file>
46
                        </file>
43
                        <file name="BlankLines.instance">
47
                        <file name="BlankLines.instance">
44
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
48
                            <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"/>
49
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerBlank"/>
50
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_BlankLines.c"/>
46
                            <attr name="position" intvalue="500"/>
51
                            <attr name="position" intvalue="500"/>
47
                        </file>
52
                        </file>
48
                        <file name="Spaces.instance">
53
                        <file name="Spaces.instance">
49
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
54
                            <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"/>
55
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCControllerSpaces"/>
56
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_Spaces.c"/>
51
                            <attr name="position" intvalue="600"/>
57
                            <attr name="position" intvalue="600"/>
52
                        </file>
58
                        </file>
53
                    </folder>
59
                    </folder>
54
                    <folder name="x-h">
60
                    <folder name="x-h">
55
                        <file name="All.instance">
61
                        <file name="All.instance">
56
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
62
                            <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"/>
63
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHController"/>
64
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_TabsIndents.cpp"/>
58
                            <attr name="position" intvalue="100"/>
65
                            <attr name="position" intvalue="100"/>
59
                        </file>
66
                        </file>
60
                        <file name="TabsAndIndents.instance">
67
                        <file name="TabsAndIndents.instance">
61
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
68
                            <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"/>
69
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerTabs"/>
70
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_TabsIndents.cpp"/>
63
                            <attr name="position" intvalue="200"/>
71
                            <attr name="position" intvalue="200"/>
64
                        </file>
72
                        </file>
65
                        <file name="Alignment.instance">
73
                        <file name="Alignment.instance">
66
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
74
                            <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"/>
75
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerAlignment"/>
76
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_AlignBraces.cpp"/>
68
                            <attr name="position" intvalue="300"/>
77
                            <attr name="position" intvalue="300"/>
69
                        </file>
78
                        </file>
70
                        <file name="Braces.instance">
79
                        <file name="Braces.instance">
71
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
80
                            <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"/>
81
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerBraces"/>
82
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_AlignBraces.cpp"/>
73
                            <attr name="position" intvalue="400"/>
83
                            <attr name="position" intvalue="400"/>
74
                        </file>
84
                        </file>
75
                        <file name="BlankLines.instance">
85
                        <file name="BlankLines.instance">
76
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
86
                            <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"/>
87
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerBlank"/>
88
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_BlankLines.cpp"/>
78
                            <attr name="position" intvalue="500"/>
89
                            <attr name="position" intvalue="500"/>
79
                        </file>
90
                        </file>
80
                        <file name="Spaces.instance">
91
                        <file name="Spaces.instance">
81
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
92
                            <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"/>
93
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getHControllerSpaces"/>
94
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_Spaces.cpp"/>
83
                            <attr name="position" intvalue="600"/>
95
                            <attr name="position" intvalue="600"/>
84
                        </file>
96
                        </file>
85
                    </folder>
97
                    </folder>
86
                    <folder name="x-c++">
98
                    <folder name="x-c++">
87
                        <file name="All.instance">
99
                        <file name="All.instance">
88
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
100
                            <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"/>
101
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCController"/>
102
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_TabsIndents.cpp"/>
90
                            <attr name="position" intvalue="100"/>
103
                            <attr name="position" intvalue="100"/>
91
                        </file>
104
                        </file>
92
                        <file name="TabsAndIndents.instance">
105
                        <file name="TabsAndIndents.instance">
93
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
106
                            <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"/>
107
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerTabs"/>
108
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_TabsIndents.cpp"/>
95
                            <attr name="position" intvalue="200"/>
109
                            <attr name="position" intvalue="200"/>
96
                        </file>
110
                        </file>
97
                        <file name="Alignment.instance">
111
                        <file name="Alignment.instance">
98
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
112
                            <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"/>
113
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerAlignment"/>
114
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_AlignBraces.cpp"/>
100
                            <attr name="position" intvalue="300"/>
115
                            <attr name="position" intvalue="300"/>
101
                        </file>
116
                        </file>
102
                        <file name="Braces.instance">
117
                        <file name="Braces.instance">
103
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
118
                            <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"/>
119
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerBraces"/>
120
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_AlignBraces.cpp"/>
105
                            <attr name="position" intvalue="400"/>
121
                            <attr name="position" intvalue="400"/>
106
                        </file>
122
                        </file>
107
                        <file name="BlankLines.instance">
123
                        <file name="BlankLines.instance">
108
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
124
                            <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"/>
125
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerBlank"/>
126
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_BlankLines.cpp"/>
110
                            <attr name="position" intvalue="500"/>
127
                            <attr name="position" intvalue="500"/>
111
                        </file>
128
                        </file>
112
                        <file name="Spaces.instance">
129
                        <file name="Spaces.instance">
113
                            <attr name="instanceOf" stringvalue="org.netbeans.spi.options.OptionsPanelController"/>
130
                            <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"/>
131
                            <attr name="instanceCreate" methodvalue="org.netbeans.modules.cnd.editor.options.EditorOptionsPanelController.getCCControllerSpaces"/>
132
                            <attr name="previewTextFile" stringvalue="OptionsDialog/CPlusPlus/FormatterPreviewExamples/SAMPLE_Spaces.cpp"/>
115
                            <attr name="position" intvalue="600"/>
133
                            <attr name="position" intvalue="600"/>
116
                        </file>
134
                        </file>
117
                    </folder>
135
                    </folder>
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/CodeStylePreferencesProvider.java (+90 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.cnd.editor.options;
43
44
import java.util.prefs.Preferences;
45
import javax.swing.text.Document;
46
import org.netbeans.api.editor.mimelookup.MimeLookup;
47
import org.netbeans.api.editor.mimelookup.MimePath;
48
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
49
import org.netbeans.modules.cnd.utils.MIMENames;
50
import org.netbeans.modules.cnd.utils.MIMESupport;
51
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
52
import org.openide.filesystems.FileObject;
53
54
/**
55
 *
56
 * @author alsimon
57
 */
58
public class CodeStylePreferencesProvider implements CodeStylePreferences.Provider {
59
60
        @Override
61
        public Preferences forFile(FileObject file, String mimeType) {
62
            if (mimeType == null) {
63
                mimeType = MIMESupport.getSourceFileMIMEType(file);
64
            }
65
            if (MIMENames.C_MIME_TYPE.equals(mimeType)) {
66
                return MimeLookup.getLookup(MimePath.parse(MIMENames.C_MIME_TYPE)).lookup(Preferences.class);
67
            } else if (MIMENames.CPLUSPLUS_MIME_TYPE.equals(mimeType)) {
68
                return MimeLookup.getLookup(MimePath.parse(MIMENames.CPLUSPLUS_MIME_TYPE)).lookup(Preferences.class);
69
            } else if (MIMENames.HEADER_MIME_TYPE.equals(mimeType)) {
70
                return MimeLookup.getLookup(MimePath.parse(MIMENames.HEADER_MIME_TYPE)).lookup(Preferences.class);
71
            }
72
            return null;
73
        }
74
75
        @Override
76
        public Preferences forDocument(Document doc, String mimeType) {
77
            if (mimeType == null) {
78
                mimeType = DocumentUtilities.getMimeType(doc);
79
            }
80
            if (MIMENames.C_MIME_TYPE.equals(mimeType)) {
81
                return MimeLookup.getLookup(MimePath.parse(MIMENames.C_MIME_TYPE)).lookup(Preferences.class);
82
            } else if (MIMENames.CPLUSPLUS_MIME_TYPE.equals(mimeType)) {
83
                return MimeLookup.getLookup(MimePath.parse(MIMENames.CPLUSPLUS_MIME_TYPE)).lookup(Preferences.class);
84
            } else if (MIMENames.HEADER_MIME_TYPE.equals(mimeType)) {
85
                return MimeLookup.getLookup(MimePath.parse(MIMENames.HEADER_MIME_TYPE)).lookup(Preferences.class);
86
            }
87
            return null;
88
        }
89
    
90
}
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorOptions.java (-36 / +258 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 327-332 Link Here
327
    
331
    
328
    private static final String APACHE_PROFILE = "Apache"; // NOI18N
332
    private static final String APACHE_PROFILE = "Apache"; // NOI18N
329
    private static final String DEFAULT_PROFILE = "Default"; // NOI18N
333
    private static final String DEFAULT_PROFILE = "Default"; // NOI18N
334
    
330
    private static final String GNU_PROFILE = "GNU"; // NOI18N
335
    private static final String GNU_PROFILE = "GNU"; // NOI18N
331
    private static final String LUNIX_PROFILE = "Linux"; // NOI18N
336
    private static final String LUNIX_PROFILE = "Linux"; // NOI18N
332
    private static final String ANSI_PROFILE = "ANSI"; // NOI18N
337
    private static final String ANSI_PROFILE = "ANSI"; // NOI18N
Lines 335-340 Link Here
335
    private static final String MYSQL_PROFILE = "MySQL"; // NOI18N
340
    private static final String MYSQL_PROFILE = "MySQL"; // NOI18N
336
    private static final String WHITESMITHS_PROFILE = "Whitesmiths"; // NOI18N
341
    private static final String WHITESMITHS_PROFILE = "Whitesmiths"; // NOI18N
337
342
343
    public static final String CODE_STYLE_PROFILE = "CodeStyle"; // NOI18N
344
    public static final String CODE_STYLE_PROFILE_ID = "Profile_ID"; // NOI18N
345
    public static final String CODE_STYLE_DISPLAY_NAME_SUFFIX = "Style_Name"; // NOI18N
346
338
    static final String[] PREDEFINED_STYLES = new String[] {
347
    static final String[] PREDEFINED_STYLES = new String[] {
339
                                 DEFAULT_PROFILE, APACHE_PROFILE, GNU_PROFILE,
348
                                 DEFAULT_PROFILE, APACHE_PROFILE, GNU_PROFILE,
340
                                 LUNIX_PROFILE, ANSI_PROFILE, OPEN_SOLARIS_PROFILE,
349
                                 LUNIX_PROFILE, ANSI_PROFILE, OPEN_SOLARIS_PROFILE,
Lines 617-645 Link Here
617
        return defaults.get(id);
626
        return defaults.get(id);
618
    }
627
    }
619
    
628
    
620
    public static String getCurrentProfileId(CodeStyle.Language language) {
629
    public static String getCurrentProfileId(CodeStyle.Language language, Document doc) {
621
        switch(language){
630
        switch(language){
622
            case C:
631
            case C:
623
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("C_Style", DEFAULT_PROFILE); // NOI18N
632
                return CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().get(EditorOptions.CODE_STYLE_PROFILE_ID, DEFAULT_PROFILE); // NOI18N
633
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get("C_Style", DEFAULT_PROFILE); // NOI18N
624
            case HEADER:
634
            case HEADER:
625
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("H_Style", DEFAULT_PROFILE); // NOI18N
635
                return CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().get(EditorOptions.CODE_STYLE_PROFILE_ID, DEFAULT_PROFILE); // NOI18N
636
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get("H_Style", DEFAULT_PROFILE); // NOI18N
626
            case CPP:
637
            case CPP:
627
            default:
638
            default:
628
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get("CPP_Style", DEFAULT_PROFILE); // NOI18N
639
                return CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().get(EditorOptions.CODE_STYLE_PROFILE_ID, DEFAULT_PROFILE); // NOI18N
640
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get("CPP_Style", DEFAULT_PROFILE); // NOI18N
641
        }
642
    }
643
    
644
    public static String getCurrentProfileId(CodeStyle.Language language, Preferences pref) {
645
        switch(language){
646
            case C:
647
                if (pref == null) {
648
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
649
                }
650
                return pref.get(EditorOptions.CODE_STYLE_PROFILE_ID, DEFAULT_PROFILE); // NOI18N
651
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get("C_Style", DEFAULT_PROFILE); // NOI18N
652
            case HEADER:
653
                if (pref == null) {
654
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
655
                }
656
                return pref.get(EditorOptions.CODE_STYLE_PROFILE_ID, DEFAULT_PROFILE); // NOI18N
657
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get("H_Style", DEFAULT_PROFILE); // NOI18N
658
            case CPP:
659
            default:
660
                if (pref == null) {
661
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
662
                }
663
                return pref.get(EditorOptions.CODE_STYLE_PROFILE_ID, DEFAULT_PROFILE); // NOI18N
664
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get("CPP_Style", DEFAULT_PROFILE); // NOI18N
629
        }
665
        }
630
    }
666
    }
631
667
632
    public static void setCurrentProfileId(CodeStyle.Language language, String style) {
668
    public static void setCurrentProfileId(CodeStyle.Language language, String style, Document doc) {
633
        switch(language){
669
        switch(language){
634
            case C:
670
            case C:
635
                NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("C_Style", style); // NOI18N
671
                CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().put(EditorOptions.CODE_STYLE_PROFILE_ID, style); // NOI18N
672
                //NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).put("C_Style", style); // NOI18N
636
                break;
673
                break;
637
            case HEADER:
674
            case HEADER:
638
                NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("H_Style", style); // NOI18N
675
                CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().put(EditorOptions.CODE_STYLE_PROFILE_ID, style); // NOI18N
676
                //NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).put("H_Style", style); // NOI18N
639
                break;
677
                break;
640
            case CPP:
678
            case CPP:
641
            default:
679
            default:
642
                NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put("CPP_Style", style); // NOI18N
680
                CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().put(EditorOptions.CODE_STYLE_PROFILE_ID, style); // NOI18N
681
                //NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).put("CPP_Style", style); // NOI18N
682
                break;
683
        }
684
    }
685
686
    public static void setCurrentProfileId(CodeStyle.Language language, String style, Preferences pref) {
687
        switch(language){
688
            case C:
689
                if (pref == null) {
690
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
691
                }
692
                pref.put(EditorOptions.CODE_STYLE_PROFILE_ID, style); // NOI18N
693
                //NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).put("C_Style", style); // NOI18N
694
                break;
695
            case HEADER:
696
                if (pref == null) {
697
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
698
                }
699
                pref.put(EditorOptions.CODE_STYLE_PROFILE_ID, style); // NOI18N
700
                //NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).put("H_Style", style); // NOI18N
701
                break;
702
            case CPP:
703
            default:
704
                if (pref == null) {
705
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
706
                }
707
                pref.put(EditorOptions.CODE_STYLE_PROFILE_ID, style); // NOI18N
708
                //NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).put("CPP_Style", style); // NOI18N
643
                break;
709
                break;
644
        }
710
        }
645
    }
711
    }
Lines 648-654 Link Here
648
        return NbBundle.getMessage(EditorOptions.class, key);
714
        return NbBundle.getMessage(EditorOptions.class, key);
649
    }
715
    }
650
716
651
    public static String getStyleDisplayName(CodeStyle.Language language, String style) {
717
    public static String getStyleDisplayName(CodeStyle.Language language, String style, Document doc) {
652
        for (String name : EditorOptions.PREDEFINED_STYLES) {
718
        for (String name : EditorOptions.PREDEFINED_STYLES) {
653
            if (style.equals(name)) {
719
            if (style.equals(name)) {
654
                return getString(style + "_Name"); // NOI18N
720
                return getString(style + "_Name"); // NOI18N
Lines 656-683 Link Here
656
        }
722
        }
657
        switch(language){
723
        switch(language){
658
            case C:
724
            case C:
659
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
725
                return CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().get(style+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX, style); // NOI18N
726
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get(style+"_Style_Name", style); // NOI18N
660
            case HEADER:
727
            case HEADER:
661
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
728
                return CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().get(style+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX, style); // NOI18N
729
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get(style+"_Style_Name", style); // NOI18N
662
            case CPP:
730
            case CPP:
663
            default:
731
            default:
664
                return NbPreferences.forModule(CodeStyle.class).node("CodeStyle").get(style+"_Style_Name", style); // NOI18N
732
                return CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().get(style+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX, style); // NOI18N
733
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get(style+"_Style_Name", style); // NOI18N
734
        }
735
    }
736
737
    public static String getStyleDisplayName(CodeStyle.Language language, String style, Preferences pref) {
738
        for (String name : EditorOptions.PREDEFINED_STYLES) {
739
            if (style.equals(name)) {
740
                return getString(style + "_Name"); // NOI18N
741
            }
742
        }
743
        switch(language){
744
            case C:
745
                if (pref == null) {
746
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
747
                }
748
                return pref.get(style+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX, style); // NOI18N
749
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get(style+"_Style_Name", style); // NOI18N
750
            case HEADER:
751
                if (pref == null) {
752
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
753
                }
754
                return pref.get(style+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX, style); // NOI18N
755
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE).get(style+"_Style_Name", style); // NOI18N
756
            case CPP:
757
            default:
758
                if (pref == null) {
759
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
760
                }
761
                return pref.get(style+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX, style); // NOI18N
762
                //return NbPreferences.forModule(CodeStyle.class).node(EditorOptions.CODE_STYLE_PROFILE").get(style+"_Style_Name", style); // NOI18N
665
        }
763
        }
666
    }
764
    }
667
    
765
    
668
    public static Preferences getPreferences(CodeStyle.Language language, String profileId) {
766
    public static Preferences getPreferences(CodeStyle.Language language, String profileId, Document doc) {
669
        switch(language){
767
        switch(language){
670
            case C:
768
            case C:
671
                return NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").node(profileId); // NOI18N
769
                return CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences();
770
                //return NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").node(profileId); // NOI18N
672
            case HEADER:
771
            case HEADER:
673
                return NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").node(profileId); // NOI18N
772
                return CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences();
773
                //return NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").node(profileId); // NOI18N
674
            case CPP:
774
            case CPP:
675
            default:
775
            default:
676
                return NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").node(profileId); // NOI18N
776
                return CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences();
777
                //return NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").node(profileId); // NOI18N
677
        }
778
        }
678
    }
779
    }
679
780
680
    public static List<String> getAllStyles(CodeStyle.Language language) {
781
    public static Preferences getPreferences(CodeStyle.Language language, String profileId, Preferences pref) {
782
        switch(language){
783
            case C:
784
                if (pref == null) {
785
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
786
                }
787
                return pref;
788
                //return NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").node(profileId); // NOI18N
789
            case HEADER:
790
                if (pref == null) {
791
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
792
                }
793
                return pref;
794
                //return NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").node(profileId); // NOI18N
795
            case CPP:
796
            default:
797
                if (pref == null) {
798
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
799
                }
800
                return pref;
801
                //return NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").node(profileId); // NOI18N
802
        }
803
    }
804
805
806
    public static List<String> getAllStyles(CodeStyle.Language language, Document doc) {
681
        String styles = null;
807
        String styles = null;
682
        StringBuilder def = new StringBuilder();
808
        StringBuilder def = new StringBuilder();
683
        for(String s: PREDEFINED_STYLES){
809
        for(String s: PREDEFINED_STYLES){
Lines 688-701 Link Here
688
        }
814
        }
689
        switch(language){
815
        switch(language){
690
            case C:
816
            case C:
691
                styles = NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
817
                styles = CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().get("List_Of_Styles", def.toString()); // NOI18N
818
                //styles = NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
692
                break;
819
                break;
693
            case HEADER:
820
            case HEADER:
694
                styles = NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
821
                styles = CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().get("List_Of_Styles", def.toString()); // NOI18N
822
                //styles = NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
695
                break;
823
                break;
696
            case CPP:
824
            case CPP:
697
            default:
825
            default:
698
                styles = NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
826
                styles = CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().get("List_Of_Styles", def.toString()); // NOI18N
827
                //styles = NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
699
                break;
828
                break;
700
        }
829
        }
701
        List<String> res = new ArrayList<String>();
830
        List<String> res = new ArrayList<String>();
Lines 706-737 Link Here
706
        return res;
835
        return res;
707
    }
836
    }
708
837
709
    public static void setAllStyles(CodeStyle.Language language, String list) {
838
    public static List<String> getAllStyles(CodeStyle.Language language, Preferences pref) {
839
        String styles = null;
840
        StringBuilder def = new StringBuilder();
841
        for(String s: PREDEFINED_STYLES){
842
            if (def.length() > 0){
843
                def.append(',');
844
            }
845
            def.append(s);
846
        }
710
        switch(language){
847
        switch(language){
711
            case C:
848
            case C:
712
                NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").put("List_Of_Styles", list); // NOI18N
849
                if (pref == null) {
850
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
851
                }
852
                styles = pref.get("List_Of_Styles", def.toString()); // NOI18N
853
                //styles = NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
713
                break;
854
                break;
714
            case HEADER:
855
            case HEADER:
715
                NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").put("List_Of_Styles", list); // NOI18N
856
                if (pref == null) {
857
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
858
                }
859
                styles = pref.get("List_Of_Styles", def.toString()); // NOI18N
860
                //styles = NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
716
                break;
861
                break;
717
            case CPP:
862
            case CPP:
718
            default:
863
            default:
719
                NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").put("List_Of_Styles", list); // NOI18N
864
                if (pref == null) {
865
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
866
                }
867
                styles = pref.get("List_Of_Styles", def.toString()); // NOI18N
868
                //styles = NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").get("List_Of_Styles", def.toString()); // NOI18N
869
                break;
870
        }
871
        List<String> res = new ArrayList<String>();
872
        StringTokenizer st = new StringTokenizer(styles,","); // NOI18N
873
        while(st.hasMoreTokens()) {
874
            res.add(st.nextToken());
875
        }
876
        return res;
877
    }
878
879
    public static void setAllStyles(CodeStyle.Language language, String list, Document doc) {
880
        switch(language){
881
            case C:
882
                CodeStylePreferences.get(doc, MIMENames.C_MIME_TYPE).getPreferences().put("List_Of_Styles", list); // NOI18N
883
                //NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").put("List_Of_Styles", list); // NOI18N
884
                break;
885
            case HEADER:
886
                CodeStylePreferences.get(doc, MIMENames.HEADER_MIME_TYPE).getPreferences().put("List_Of_Styles", list); // NOI18N
887
                //NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").put("List_Of_Styles", list); // NOI18N
888
                break;
889
            case CPP:
890
            default:
891
                CodeStylePreferences.get(doc, MIMENames.CPLUSPLUS_MIME_TYPE).getPreferences().put("List_Of_Styles", list); // NOI18N
892
                //NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").put("List_Of_Styles", list); // NOI18N
720
                break;
893
                break;
721
        }
894
        }
722
    }
895
    }
723
896
724
    public static CodeStyle createCodeStyle(CodeStyle.Language language, Preferences p, boolean useOverrideOption) {
897
    public static void setAllStyles(CodeStyle.Language language, String list, Preferences pref) {
725
        CodeStyle.getDefault(language);
898
        switch(language){
726
        return codeStyleFactory.create(language, p, useOverrideOption);
899
            case C:
900
                if (pref == null) {
901
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.C_MIME_TYPE);
902
                }
903
                pref.put("List_Of_Styles", list); // NOI18N
904
                //NbPreferences.forModule(CodeStyle.class).node("C_CodeStyles").put("List_Of_Styles", list); // NOI18N
905
                break;
906
            case HEADER:
907
                if (pref == null) {
908
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.HEADER_MIME_TYPE);
909
                }
910
                pref.put("List_Of_Styles", list); // NOI18N
911
                //NbPreferences.forModule(CodeStyle.class).node("H_CodeStyles").put("List_Of_Styles", list); // NOI18N
912
                break;
913
            case CPP:
914
            default:
915
                if (pref == null) {
916
                    pref = new CodeStylePreferencesProvider().forDocument(null, MIMENames.CPLUSPLUS_MIME_TYPE);
917
                }
918
                pref.put("List_Of_Styles", list); // NOI18N
919
                //NbPreferences.forModule(CodeStyle.class).node("CPP_CodeStyles").put("List_Of_Styles", list); // NOI18N
920
                break;
921
        }
727
    }
922
    }
728
923
729
    public static Preferences getPreferences(CodeStyle codeStyle){
924
    public static CodeStyle createCodeStyle(CodeStyle.Language language, Preferences pref, String styleID, boolean useOverrideOption) {
730
        return codeStyleFactory.getPreferences(codeStyle);
925
        CodeStyle.getDefault(language, pref);
926
        return codeStyleFactory.create(language, pref, styleID, useOverrideOption);
927
    }
928
929
    public static PreferencesWrapper getPreferences(CodeStyle codeStyle){
930
        return new PreferencesWrapper(codeStyleFactory.getPreferences(codeStyle), codeStyleFactory.getStyleID(codeStyle));
731
    }
931
    }
732
932
733
    public static void resetToDefault(CodeStyle codeStyle){
933
    public static void resetToDefault(CodeStyle codeStyle){
734
        Preferences preferences = getPreferences(codeStyle);
934
        PreferencesWrapper preferences = getPreferences(codeStyle);
735
        for(Map.Entry<String,Object> entry : defaults.entrySet()){
935
        for(Map.Entry<String,Object> entry : defaults.entrySet()){
736
            if (entry.getValue() instanceof Boolean){
936
            if (entry.getValue() instanceof Boolean){
737
                preferences.putBoolean(entry.getKey(), (Boolean)entry.getValue());
937
                preferences.putBoolean(entry.getKey(), (Boolean)entry.getValue());
Lines 744-750 Link Here
744
    }
944
    }
745
945
746
    public static void resetToDefault(CodeStyle codeStyle, String name){
946
    public static void resetToDefault(CodeStyle codeStyle, String name){
747
        Preferences preferences = getPreferences(codeStyle);
947
        PreferencesWrapper preferences = getPreferences(codeStyle);
748
        for(Map.Entry<String,Object> entry : namedDefaults.get(name).entrySet()){
948
        for(Map.Entry<String,Object> entry : namedDefaults.get(name).entrySet()){
749
            if (entry.getValue() instanceof Boolean){
949
            if (entry.getValue() instanceof Boolean){
750
                preferences.putBoolean(entry.getKey(), (Boolean)entry.getValue());
950
                preferences.putBoolean(entry.getKey(), (Boolean)entry.getValue());
Lines 760-767 Link Here
760
        return defaults.keySet();
960
        return defaults.keySet();
761
    }
961
    }
762
962
763
    public static void setPreferences(CodeStyle codeStyle, Preferences preferences){
963
    public static void setPreferences(CodeStyle codeStyle, Preferences preferences, String styleID){
764
        codeStyleFactory.setPreferences(codeStyle, preferences);
964
        codeStyleFactory.setPreferences(codeStyle, preferences, styleID);
765
    }
965
    }
766
966
767
    public static void updateSimplePreferences(CodeStyle.Language language, CodeStyle codeStyle) {
967
    public static void updateSimplePreferences(CodeStyle.Language language, CodeStyle codeStyle) {
Lines 849-856 Link Here
849
    }
1049
    }
850
1050
851
    public static interface CodeStyleFactory {
1051
    public static interface CodeStyleFactory {
852
        CodeStyle create(CodeStyle.Language language, Preferences preferences, boolean useOverrideOption);
1052
        CodeStyle create(CodeStyle.Language language, Preferences preferences, String styleID, boolean useOverrideOption);
853
        Preferences getPreferences(CodeStyle codeStyle);
1053
        Preferences getPreferences(CodeStyle codeStyle);
854
        void setPreferences(CodeStyle codeStyle, Preferences preferences);
1054
        String getStyleID(CodeStyle codeStyle);
1055
        void setPreferences(CodeStyle codeStyle, Preferences preferences, String styleID);
1056
    }
1057
    
1058
    public static final class PreferencesWrapper {
1059
        private final Preferences delegate;
1060
        private final String styleID;
1061
        private PreferencesWrapper(Preferences delegate, String styleID) {
1062
            this.delegate = delegate;
1063
            this.styleID = styleID;
1064
        }
1065
        
1066
        public void put(String key, String value) {
1067
            delegate.put(styleID+'.'+key, value);
1068
        }
1069
        
1070
        public void putInt(String key, int value) {
1071
            delegate.putInt(styleID+'.'+key, value);
1072
        }
1073
        
1074
        public void putBoolean(String key, boolean value) {
1075
            delegate.putBoolean(styleID+'.'+key, value);
1076
        }
855
    }
1077
    }
856
}
1078
}
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorOptionsPanelController.java (-104 / +144 lines)
Lines 39-226 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;
135
            pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
99
            pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
136
        }
100
        }
137
        pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
101
        pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
102
        prefModel.storeTo(customizer.preferences);
138
    }
103
    }
139
104
140
    @Override
105
    private static class PreferencesCustomizerImpl implements PreferencesCustomizer, PreviewProvider {
141
    public JComponent getPreviewComponent() {
106
142
        if (previewPane == null) {
107
        private final CodeStyle.Language language;
143
            previewPane = new JEditorPane();
108
        private final PreviewPreferencesModel.Filter filter;
144
            previewPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(EditorOptionsPanelController.class, "AN_Preview")); //NOI18N
109
        private final EditorOptionsPanelController top;
145
            previewPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EditorOptionsPanelController.class, "AD_Preview")); //NOI18N
110
        private final Preferences preferences;
146
            previewPane.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$"); //NOI18N
111
        private EditorPropertySheet panel;
147
            switch (language){
112
        private JEditorPane previewPane;
148
                case C:
113
149
                    previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.C_MIME_TYPE));
114
        public PreferencesCustomizerImpl(EditorOptionsPanelController top, CodeStyle.Language language, PreviewPreferencesModel.Filter filter, Preferences preferences) {
150
                    break;
115
            this.language = language;
151
                case HEADER:
116
            this.filter = filter;
152
                    previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.HEADER_MIME_TYPE));
117
            this.top = top;
153
                    break;
118
            this.preferences = preferences;
154
                case CPP:
119
        }
155
                default:
120
156
                    previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.CPLUSPLUS_MIME_TYPE));
121
        @Override
157
                    break;
122
        public String getId() {
123
            return filter.name();
124
//            switch (filter) {
125
//                case TabsAndIndents:
126
//                    return PreferencesCustomizer.TABS_AND_INDENTS_ID;
127
//                default:
128
//                    return filter.name();
129
//            }
130
        }
131
132
        @Override
133
        public String getDisplayName() {
134
            switch (filter) {
135
                case Alignment:
136
                    return EditorPropertySheet.getString("Filter_Alignment_name"); // NOI18N
137
                case All:
138
                    return EditorPropertySheet.getString("Filter_All_name"); // NOI18N
139
                case BlankLines:
140
                    return EditorPropertySheet.getString("Filter_BlankLines_name"); // NOI18N
141
                case Braces:
142
                    return EditorPropertySheet.getString("Filter_Braces_name"); // NOI18N
143
                case Spaces:
144
                    return EditorPropertySheet.getString("Filter_Spaces_name"); // NOI18N
145
                case TabsAndIndents:
146
                    return EditorPropertySheet.getString("Filter_TabsAndIndents_name"); // NOI18N
158
            }
147
            }
159
            previewPane.setEditable(false);
148
            return null;
160
        }
149
        }
161
        return previewPane;
150
151
        @Override
152
        public HelpCtx getHelpCtx() {
153
            return HelpCtx.DEFAULT_HELP;
154
        }
155
156
        @Override
157
        public JComponent getComponent() {
158
            if (panel == null) {
159
                prefModel.setPreferences(language, filter, preferences);
160
                panel = new EditorPropertySheet(top, language, EditorOptionsPanelController.prefModel, filter);
161
            }
162
            return panel;
163
        }
164
165
        @Override
166
        public JComponent getPreviewComponent() {
167
            if (previewPane == null) {
168
                previewPane = new JEditorPane();
169
                previewPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(EditorOptionsPanelController.class, "AN_Preview")); //NOI18N
170
                previewPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EditorOptionsPanelController.class, "AD_Preview")); //NOI18N
171
                previewPane.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$"); //NOI18N
172
                switch (language) {
173
                    case C:
174
                        previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.C_MIME_TYPE));
175
                        break;
176
                    case HEADER:
177
                        previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.HEADER_MIME_TYPE));
178
                        break;
179
                    case CPP:
180
                    default:
181
                        previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(MIMENames.CPLUSPLUS_MIME_TYPE));
182
                        break;
183
                }
184
                previewPane.setEditable(false);
185
            }
186
            return previewPane;
187
        }
188
189
        @Override
190
        public void refreshPreview() {
191
            panel.repaintPreview();
192
        }
162
    }
193
    }
163
194
164
    @Override
195
    public static PreferencesCustomizer.Factory getCController() {
165
    public void refreshPreview() {
196
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.All);
166
        panel.repaintPreview();
167
    }
197
    }
168
198
169
    public static OptionsPanelController getCController() {
199
    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);
200
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.TabsAndIndents);
174
    }
201
    }
175
    public static OptionsPanelController getCControllerAlignment() {
202
203
    public static PreferencesCustomizer.Factory getCControllerAlignment() {
176
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Alignment);
204
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Alignment);
177
    }
205
    }
178
    public static OptionsPanelController getCControllerBraces() {
206
207
    public static PreferencesCustomizer.Factory getCControllerBraces() {
179
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Braces);
208
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Braces);
180
    }
209
    }
181
    public static OptionsPanelController getCControllerBlank() {
210
211
    public static PreferencesCustomizer.Factory getCControllerBlank() {
182
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.BlankLines);
212
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.BlankLines);
183
    }
213
    }
184
    public static OptionsPanelController getCControllerSpaces() {
214
215
    public static PreferencesCustomizer.Factory getCControllerSpaces() {
185
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Spaces);
216
        return new EditorOptionsPanelController(CodeStyle.Language.C, PreviewPreferencesModel.Filter.Spaces);
186
    }
217
    }
187
218
188
    public static OptionsPanelController getCCController() {
219
    public static PreferencesCustomizer.Factory getCCController() {
189
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.All);
220
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.All);
190
    }
221
    }
191
    public static OptionsPanelController getCCControllerTabs() {
222
223
    public static PreferencesCustomizer.Factory getCCControllerTabs() {
192
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.TabsAndIndents);
224
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.TabsAndIndents);
193
    }
225
    }
194
    public static OptionsPanelController getCCControllerAlignment() {
226
227
    public static PreferencesCustomizer.Factory getCCControllerAlignment() {
195
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Alignment);
228
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Alignment);
196
    }
229
    }
197
    public static OptionsPanelController getCCControllerBraces() {
230
231
    public static PreferencesCustomizer.Factory getCCControllerBraces() {
198
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Braces);
232
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Braces);
199
    }
233
    }
200
    public static OptionsPanelController getCCControllerBlank() {
234
235
    public static PreferencesCustomizer.Factory getCCControllerBlank() {
201
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.BlankLines);
236
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.BlankLines);
202
    }
237
    }
203
    public static OptionsPanelController getCCControllerSpaces() {
238
239
    public static PreferencesCustomizer.Factory getCCControllerSpaces() {
204
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Spaces);
240
        return new EditorOptionsPanelController(CodeStyle.Language.CPP, PreviewPreferencesModel.Filter.Spaces);
205
    }
241
    }
206
242
207
    public static OptionsPanelController getHController() {
243
    public static PreferencesCustomizer.Factory getHController() {
208
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.All);
244
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.All);
209
    }
245
    }
210
    public static OptionsPanelController getHControllerTabs() {
246
247
    public static PreferencesCustomizer.Factory getHControllerTabs() {
211
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.TabsAndIndents);
248
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.TabsAndIndents);
212
    }
249
    }
213
    public static OptionsPanelController getHControllerAlignment() {
250
251
    public static PreferencesCustomizer.Factory getHControllerAlignment() {
214
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Alignment);
252
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Alignment);
215
    }
253
    }
216
    public static OptionsPanelController getHControllerBraces() {
254
255
    public static PreferencesCustomizer.Factory getHControllerBraces() {
217
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Braces);
256
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Braces);
218
    }
257
    }
219
    public static OptionsPanelController getHControllerBlank() {
258
259
    public static PreferencesCustomizer.Factory getHControllerBlank() {
220
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.BlankLines);
260
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.BlankLines);
221
    }
261
    }
222
    public static OptionsPanelController getHControllerSpaces() {
262
263
    public static PreferencesCustomizer.Factory getHControllerSpaces() {
223
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Spaces);
264
        return new EditorOptionsPanelController(CodeStyle.Language.HEADER, PreviewPreferencesModel.Filter.Spaces);
224
    }
265
    }
225
226
}
266
}
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorPropertySheet.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
  <Properties>
4
  <Properties>
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorPropertySheet.java (-21 / +27 lines)
Lines 68-73 Link Here
68
import org.netbeans.editor.BaseDocument;
68
import org.netbeans.editor.BaseDocument;
69
import org.netbeans.modules.cnd.editor.api.CodeStyle;
69
import org.netbeans.modules.cnd.editor.api.CodeStyle;
70
import org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter;
70
import org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter;
71
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.Alignment;
72
import static org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter.All;
71
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
73
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
72
import org.openide.DialogDescriptor;
74
import org.openide.DialogDescriptor;
73
import org.openide.DialogDisplayer;
75
import org.openide.DialogDisplayer;
Lines 157-163 Link Here
157
159
158
    private void initLanguageCategory(){
160
    private void initLanguageCategory(){
159
        styleComboBox.removeActionListener(this);
161
        styleComboBox.removeActionListener(this);
160
        final Map<String, PreviewPreferences> prefences = preferencesModel.getPrefences(language);
162
        final Map<String, PreviewPreferences> prefences = preferencesModel.getLanguagePreferences(language);
161
        if (prefences == null) {
163
        if (prefences == null) {
162
            return;
164
            return;
163
        }
165
        }
Lines 182-187 Link Here
182
        initSheets(entry.preferences);
184
        initSheets(entry.preferences);
183
        preferencesModel.setLanguageDefaultStyle(language, entry.name);
185
        preferencesModel.setLanguageDefaultStyle(language, entry.name);
184
        styleComboBox.addActionListener(this);
186
        styleComboBox.addActionListener(this);
187
        loaded = true;
185
        repaintPreview();
188
        repaintPreview();
186
    }
189
    }
187
190
Lines 384-390 Link Here
384
        lastSheetPreferences = preferences;
387
        lastSheetPreferences = preferences;
385
    }
388
    }
386
389
387
    void load() {
390
    private void load() {
388
        loaded = false;
391
        loaded = false;
389
        initLanguageMap();
392
        initLanguageMap();
390
        initLanguageCategory();
393
        initLanguageCategory();
Lines 392-402 Link Here
392
        repaintPreview();
395
        repaintPreview();
393
    }
396
    }
394
397
395
    void store() {
398
    private void store() {
396
        if (filter != Filter.All) {
399
        if (filter != Filter.All) {
397
            return;
400
            return;
398
        }
401
        }
399
        EditorOptions.setCurrentProfileId(language, preferencesModel.getLanguageDefaultStyle(language));
402
        EditorOptions.setCurrentProfileId(language, preferencesModel.getLanguageDefaultStyle(language), (Preferences)null);
400
        StringBuilder buf = new StringBuilder();
403
        StringBuilder buf = new StringBuilder();
401
        for(Map.Entry<String, PreviewPreferences> prefEntry : preferencesModel.getLanguagePreferences(language).entrySet()){
404
        for(Map.Entry<String, PreviewPreferences> prefEntry : preferencesModel.getLanguagePreferences(language).entrySet()){
402
            String style = prefEntry.getKey();
405
            String style = prefEntry.getKey();
Lines 405-413 Link Here
405
            }
408
            }
406
            buf.append(style);
409
            buf.append(style);
407
            PreviewPreferences pref = prefEntry.getValue();
410
            PreviewPreferences pref = prefEntry.getValue();
408
            Preferences toSave = EditorOptions.getPreferences(language, style);
411
            Preferences toSave = EditorOptions.getPreferences(language, style, (Preferences)null);
409
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
412
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
410
                EditorOptions.setPreferences(CodeStyle.getDefault(language), toSave);
413
                EditorOptions.setPreferences(CodeStyle.getDefault(language, toSave), toSave, style);
411
            }
414
            }
412
            for(String key : EditorOptions.keys()){
415
            for(String key : EditorOptions.keys()){
413
                Object o = EditorOptions.getDefault(language, style, key);
416
                Object o = EditorOptions.getDefault(language, style, key);
Lines 435-444 Link Here
435
                }
438
                }
436
            }
439
            }
437
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
440
            if (style.equals(preferencesModel.getLanguageDefaultStyle(language))){
438
                EditorOptions.updateSimplePreferences(language, CodeStyle.getDefault(language));
441
                EditorOptions.updateSimplePreferences(language, CodeStyle.getDefault(language, toSave));
439
            }
442
            }
440
        }
443
        }
441
        EditorOptions.setAllStyles(language, buf.toString());
444
        EditorOptions.setAllStyles(language, buf.toString(), (Preferences)null);
442
        preferencesModel.clear(language);
445
        preferencesModel.clear(language);
443
        holder.setNodes(null);
446
        holder.setNodes(null);
444
    }
447
    }
Lines 512-518 Link Here
512
            category = (EntryWrapper)styleComboBox.getItemAt(0);
515
            category = (EntryWrapper)styleComboBox.getItemAt(0);
513
        }
516
        }
514
        JEditorPane previewPane = (JEditorPane) topController.getPreviewComponent();
517
        JEditorPane previewPane = (JEditorPane) topController.getPreviewComponent();
515
        if (loaded) {
518
        //if (loaded) {
516
            PreviewPreferences p = new PreviewPreferences(category.preferences,
519
            PreviewPreferences p = new PreviewPreferences(category.preferences,
517
                    category.preferences.getLanguage(), category.preferences.getStyleId());
520
                    category.preferences.getLanguage(), category.preferences.getStyleId());
518
            p.makeAllKeys(category.preferences);
521
            p.makeAllKeys(category.preferences);
Lines 531-537 Link Here
531
            previewPane.setIgnoreRepaint(false);
534
            previewPane.setIgnoreRepaint(false);
532
            previewPane.scrollRectToVisible(new Rectangle(0,0,10,10) );
535
            previewPane.scrollRectToVisible(new Rectangle(0,0,10,10) );
533
            previewPane.repaint(100);
536
            previewPane.repaint(100);
534
        }
537
        //}
535
    }
538
    }
536
539
537
    private String getPreviewText(){
540
    private String getPreviewText(){
Lines 548-562 Link Here
548
                suffix = ".cpp"; // NOI18N
551
                suffix = ".cpp"; // NOI18N
549
                break;
552
                break;
550
        }
553
        }
551
        if (lastChangedproperty != null) {
554
        switch (filter) {
552
            if (lastChangedproperty.startsWith("space")) { // NOI18N
555
            case BlankLines:
556
                return loadPreviewExample("SAMPLE_BlankLines"+suffix); // NOI18N
557
            case Alignment:
558
            case Braces:
559
                return loadPreviewExample("SAMPLE_AlignBraces"+suffix); // NOI18N
560
            case Spaces:
553
                return loadPreviewExample("SAMPLE_Spaces"+suffix); // NOI18N
561
                return loadPreviewExample("SAMPLE_Spaces"+suffix); // NOI18N
554
            } else if (lastChangedproperty.startsWith("blank")) { // NOI18N
562
            case All:
555
                return loadPreviewExample("SAMPLE_BlankLines"+suffix); // NOI18N
563
            case TabsAndIndents:
556
            }  else if (lastChangedproperty.startsWith("align") || // NOI18N
564
                return loadPreviewExample("SAMPLE_TabsIndents"+suffix); // NOI18N
557
                        lastChangedproperty.startsWith("new")) { // NOI18N
558
                return loadPreviewExample("SAMPLE_AlignBraces"+suffix); // NOI18N
559
            }
560
        }
565
        }
561
        return loadPreviewExample("SAMPLE_TabsIndents"+suffix); // NOI18N
566
        return loadPreviewExample("SAMPLE_TabsIndents"+suffix); // NOI18N
562
    }
567
    }
Lines 588-594 Link Here
588
    private void refreshPreview(JEditorPane pane, Preferences p) {
593
    private void refreshPreview(JEditorPane pane, Preferences p) {
589
        pane.setText(getPreviewText());
594
        pane.setText(getPreviewText());
590
        final BaseDocument bd = (BaseDocument) pane.getDocument();
595
        final BaseDocument bd = (BaseDocument) pane.getDocument();
591
        final CodeStyle codeStyle = EditorOptions.createCodeStyle(language, p, false);
596
        EntryWrapper entry = (EntryWrapper)styleComboBox.getSelectedItem();
597
        final CodeStyle codeStyle = EditorOptions.createCodeStyle(language, p, entry.name, false);
592
        bd.runAtomicAsUser(new Runnable() {
598
        bd.runAtomicAsUser(new Runnable() {
593
599
594
            @Override
600
            @Override
Lines 602-608 Link Here
602
        });
608
        });
603
    }
609
    }
604
610
605
    private static String getString(String key) {
611
    static String getString(String key) {
606
        return NbBundle.getMessage(EditorPropertySheet.class, key);
612
        return NbBundle.getMessage(EditorPropertySheet.class, key);
607
    }
613
    }
608
614
Lines 709-715 Link Here
709
        private EntryWrapper(Map.Entry<String, PreviewPreferences> enrty){
715
        private EntryWrapper(Map.Entry<String, PreviewPreferences> enrty){
710
            this.name = enrty.getKey();
716
            this.name = enrty.getKey();
711
            this.preferences = enrty.getValue();
717
            this.preferences = enrty.getValue();
712
            displayName = EditorOptions.getStyleDisplayName(preferences.getLanguage(),name);
718
            displayName = EditorOptions.getStyleDisplayName(preferences.getLanguage(),name, preferences);
713
        }
719
        }
714
720
715
        @Override
721
        @Override
(-)a/options.editor/src/org/netbeans/modules/options/indentation/FormattingSettingsFromNbPreferences.java (-3 / +4 lines)
Lines 40-46 Link Here
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.netbeans.modules.options.indentation;
43
package org.netbeans.modules.cnd.editor.options;
44
44
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.util.HashMap;
46
import java.util.HashMap;
Lines 134-141 Link Here
134
    
134
    
135
    private static final Map<String, String> affectedMimeTypes = new HashMap<String, String>();
135
    private static final Map<String, String> affectedMimeTypes = new HashMap<String, String>();
136
    static {
136
    static {
137
        affectedMimeTypes.put("text/x-java", "org.netbeans.api.java.source.CodeStyle"); //NOI18N
137
        affectedMimeTypes.put("text/x-c", "org.netbeans.modules.cnd.editor.api.CodeStyle"); //NOI18N
138
        affectedMimeTypes.put("text/x-ruby", "org.netbeans.modules.ruby.options.CodeStyle"); //NOI18N
138
        affectedMimeTypes.put("text/x-c++", "org.netbeans.modules.cnd.editor.api.CodeStyle"); //NOI18N
139
        affectedMimeTypes.put("text/x-h", "org.netbeans.modules.cnd.editor.api.CodeStyle"); //NOI18N
139
    }
140
    }
140
141
141
    private Preferences getNbPreferences(String mimeType) {
142
    private Preferences getNbPreferences(String mimeType) {
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/ManageStylesPanel.java (-21 / +18 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 188-198 Link Here
188
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
189
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
189
    PreviewPreferences pp = preferences.get("Default"); // NOI18N
190
    PreviewPreferences pp = preferences.get("Default"); // NOI18N
190
    String id = nextId();
191
    String id = nextId();
191
    String resourceId = id+"_Style_Name"; // NOI18N
192
    String resourceId = id+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX; // NOI18N
192
    String displayName = getString("Custom_Name"); // NOI18N
193
    String displayName = getString("Custom_Name"); // NOI18N
193
    displayName = getDisplayName(displayName);
194
    displayName = getDisplayName(displayName);
194
    if (displayName != null && checkUniqueStyleName(displayName)) {
195
    if (displayName != null && checkUniqueStyleName(displayName)) {
195
        NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put(resourceId, displayName); // NOI18N
196
        pp.put(resourceId, displayName); // NOI18N
196
        PreviewPreferences np = new PreviewPreferences(pp, language, id);
197
        PreviewPreferences np = new PreviewPreferences(pp, language, id);
197
        np.makeAllKeys(pp);
198
        np.makeAllKeys(pp);
198
        preferences.put(id, np);
199
        preferences.put(id, np);
Lines 206-216 Link Here
206
        MyListItem item = (MyListItem) stylesList.getModel().getElementAt(i);
207
        MyListItem item = (MyListItem) stylesList.getModel().getElementAt(i);
207
        PreviewPreferences pp = preferences.get(item.id);
208
        PreviewPreferences pp = preferences.get(item.id);
208
        String id = nextId();
209
        String id = nextId();
209
        String resourceId = id+"_Style_Name"; // NOI18N
210
        String resourceId = id+'.'+EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX; // NOI18N
210
        String displayName = NbBundle.getMessage(ManageStylesPanel.class, "CopyOfStyle", item.name); // NOI18N
211
        String displayName = NbBundle.getMessage(ManageStylesPanel.class, "CopyOfStyle", item.name); // NOI18N
211
        displayName = getDisplayName(displayName);
212
        displayName = getDisplayName(displayName);
212
        if (displayName != null && checkUniqueStyleName(displayName)) {
213
        if (displayName != null && checkUniqueStyleName(displayName)) {
213
            NbPreferences.forModule(CodeStyle.class).node("CodeStyle").put(resourceId, displayName); // NOI18N
214
            pp.put(resourceId, displayName); // NOI18N
214
            PreviewPreferences np = new PreviewPreferences(pp, language, id);
215
            PreviewPreferences np = new PreviewPreferences(pp, language, id);
215
            np.makeAllKeys(pp);
216
            np.makeAllKeys(pp);
216
            preferences.put(id, np);
217
            preferences.put(id, np);
Lines 245-274 Link Here
245
246
246
    private String nextId(){
247
    private String nextId(){
247
        int maxId = 0;
248
        int maxId = 0;
248
        try {
249
        for (String key : preferences.keySet()) {// NOI18N
249
            for (String key : NbPreferences.forModule(ManageStylesPanel.class).node("CodeStyle").keys()) {// NOI18N
250
            if (key.endsWith(EditorOptions.CODE_STYLE_DISPLAY_NAME_SUFFIX) && key.startsWith("Style_")) { // NOI18N
250
                if (key.endsWith("_Style_Name") && key.startsWith("Style_")) { // NOI18N
251
                String v = key.substring(6, key.length() - 11);
251
                    String v = key.substring(6, key.length() - 11);
252
                int n = 0;
252
                    int n = 0;
253
                try {
253
                    try {
254
                    n = Integer.parseInt(v);
254
                        n = Integer.parseInt(v);
255
                } catch (NumberFormatException e) {
255
                    } catch (NumberFormatException e) {
256
                    e.printStackTrace(System.err);
256
                        e.printStackTrace(System.err);
257
                }
257
                    }
258
                if (maxId <= n) {
258
                    if (maxId <= n) {
259
                    maxId = n + 1;
259
                        maxId = n + 1;
260
                    }
261
                }
260
                }
262
            }
261
            }
263
        } catch (BackingStoreException ex) {
264
            Exceptions.printStackTrace(ex);
265
        }
262
        }
266
        return "Style_" + maxId; // NOI18N
263
        return "Style_" + maxId; // NOI18N
267
    }
264
    }
268
265
269
    private boolean checkUniqueStyleName(String styleName) {
266
    private boolean checkUniqueStyleName(String styleName) {
270
        for (String key : preferences.keySet()) {
267
        for (String key : preferences.keySet()) {
271
            String name = EditorOptions.getStyleDisplayName(language, key);
268
            String name = EditorOptions.getStyleDisplayName(language, key, (Preferences)null);
272
            if (name.equals(styleName)) {
269
            if (name.equals(styleName)) {
273
                NotifyDescriptor descriptor = new NotifyDescriptor.Message(
270
                NotifyDescriptor descriptor = new NotifyDescriptor.Message(
274
                        NbBundle.getMessage(ManageStylesPanel.class, "Duplicate_Style_Warning", styleName), // NOI18N
271
                        NbBundle.getMessage(ManageStylesPanel.class, "Duplicate_Style_Warning", styleName), // NOI18N
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/PreviewPreferencesModel.java (-20 / +28 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
89
    void storeTo (Preferences preferences) {
90
        preferences.put ("HelloFrom", "CND");
91
    }
92
85
    public Map<String, PreviewPreferences> getLanguagePreferences(CodeStyle.Language language) {
93
    public Map<String, PreviewPreferences> getLanguagePreferences(CodeStyle.Language language) {
86
        return preferences.get(language);
94
        return styles.get(language);
87
    }
95
    }
88
96
89
    public String getLanguageDefaultStyle(CodeStyle.Language language) {
97
    public String getLanguageDefaultStyle(CodeStyle.Language language) {
Lines 94-109 Link Here
94
        defaultStyles.put(language, def);
102
        defaultStyles.put(language, def);
95
    }
103
    }
96
104
97
    private void initLanguageStylePreferences(CodeStyle.Language language, String styleId) {
105
    private void initLanguageStylePreferences(CodeStyle.Language language, String styleId, Preferences pref) {
98
        Map<String, PreviewPreferences> prefs = preferences.get(language);
106
        Map<String, PreviewPreferences> style = styles.get(language);
99
        if (prefs == null) {
107
        if (style == null) {
100
            prefs = new HashMap<String, PreviewPreferences>();
108
            style = new HashMap<String, PreviewPreferences>();
101
            preferences.put(language, prefs);
109
            styles.put(language, style);
102
        }
110
        }
103
        PreviewPreferences clone = prefs.get(styleId);
111
        PreviewPreferences clone = style.get(styleId);
104
        if (clone == null) {
112
        if (clone == null) {
105
            clone = new PreviewPreferences(EditorOptions.getPreferences(language, styleId), language, styleId);
113
            clone = new PreviewPreferences(EditorOptions.getPreferences(language, styleId, pref), language, styleId);
106
            prefs.put(styleId, clone);
114
            style.put(styleId, clone);
107
        }
115
        }
108
    }
116
    }
109
117
Lines 118-128 Link Here
118
    }
126
    }
119
127
120
    public void resetPreferences(CodeStyle.Language language, Map<String, PreviewPreferences> newPreferences) {
128
    public void resetPreferences(CodeStyle.Language language, Map<String, PreviewPreferences> newPreferences) {
121
        preferences.put(language, newPreferences);
129
        styles.put(language, newPreferences);
122
    }
130
    }
123
131
124
    public void clear(CodeStyle.Language language) {
132
    public void clear(CodeStyle.Language language) {
125
        preferences.remove(language);
133
        styles.remove(language);
126
        defaultStyles.remove(language);
134
        defaultStyles.remove(language);
127
    }
135
    }
128
}
136
}
(-)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.alignMult