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 189638
Collapse All | Expand All

(-)a/apisupport.project/nbproject/project.xml (-2 / +2 lines)
Lines 139-146 Link Here
139
                    <build-prerequisite/>
139
                    <build-prerequisite/>
140
                    <compile-dependency/>
140
                    <compile-dependency/>
141
                    <run-dependency>
141
                    <run-dependency>
142
                        <release-version>2</release-version>
142
                        <release-version>3</release-version>
143
                        <specification-version>2.1</specification-version>
143
                        <specification-version>3.1</specification-version>
144
                    </run-dependency>
144
                    </run-dependency>
145
                </dependency>
145
                </dependency>
146
                <dependency>
146
                <dependency>
(-)a/beans/nbproject/project.xml (-2 / +2 lines)
Lines 116-123 Link Here
116
                    <build-prerequisite/>
116
                    <build-prerequisite/>
117
                    <compile-dependency/>
117
                    <compile-dependency/>
118
                    <run-dependency>
118
                    <run-dependency>
119
                        <release-version>2</release-version>
119
                        <release-version>3</release-version>
120
                        <specification-version>2.1</specification-version>
120
                        <specification-version>3.1</specification-version>
121
                    </run-dependency>
121
                    </run-dependency>
122
                </dependency>
122
                </dependency>
123
                <dependency>
123
                <dependency>
(-)a/bpel.debugger.ui/nbproject/project.xml (-2 / +2 lines)
Lines 96-103 Link Here
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
99
                        <release-version>3</release-version>
100
                        <specification-version>2.1</specification-version>
100
                        <specification-version>3.1</specification-version>
101
                    </run-dependency>
101
                    </run-dependency>
102
                </dependency>
102
                </dependency>
103
                <dependency>
103
                <dependency>
(-)a/bugtracking.bridge/nbproject/project.xml (-2 / +2 lines)
Lines 36-43 Link Here
36
                    <build-prerequisite/>
36
                    <build-prerequisite/>
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>2</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>2.1</specification-version>
40
                        <specification-version>3.1</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
(-)a/cnd.asm/nbproject/project.xml (-3 / +3 lines)
Lines 27-33 Link Here
27
                    <compile-dependency/>
27
                    <compile-dependency/>
28
                    <run-dependency>
28
                    <run-dependency>
29
                        <release-version>3</release-version>
29
                        <release-version>3</release-version>
30
                        <specification-version>1.41</specification-version>
30
                        <specification-version>1.53</specification-version>
31
                    </run-dependency>
31
                    </run-dependency>
32
                </dependency>
32
                </dependency>
33
                <dependency>
33
                <dependency>
Lines 44-51 Link Here
44
                    <build-prerequisite/>
44
                    <build-prerequisite/>
45
                    <compile-dependency/>
45
                    <compile-dependency/>
46
                    <run-dependency>
46
                    <run-dependency>
47
                        <release-version>2</release-version>
47
                        <release-version>3</release-version>
48
                        <specification-version>2.1</specification-version>
48
                        <specification-version>3.1</specification-version>
49
                    </run-dependency>
49
                    </run-dependency>
50
                </dependency>
50
                </dependency>
51
                <dependency>
51
                <dependency>
(-)a/cnd.completion/nbproject/project.xml (-3 / +3 lines)
Lines 87-93 Link Here
87
                    <compile-dependency/>
87
                    <compile-dependency/>
88
                    <run-dependency>
88
                    <run-dependency>
89
                        <release-version>3</release-version>
89
                        <release-version>3</release-version>
90
                        <specification-version>1.41</specification-version>
90
                        <specification-version>1.53</specification-version>
91
                    </run-dependency>
91
                    </run-dependency>
92
                </dependency>
92
                </dependency>
93
                <dependency>
93
                <dependency>
Lines 122-129 Link Here
122
                    <build-prerequisite/>
122
                    <build-prerequisite/>
123
                    <compile-dependency/>
123
                    <compile-dependency/>
124
                    <run-dependency>
124
                    <run-dependency>
125
                        <release-version>2</release-version>
125
                        <release-version>3</release-version>
126
                        <specification-version>2.1</specification-version>
126
                        <specification-version>3.1</specification-version>
127
                    </run-dependency>
127
                    </run-dependency>
128
                </dependency>
128
                </dependency>
129
                <dependency>
129
                <dependency>
(-)a/cnd.debugger.common/nbproject/project.xml (-2 / +2 lines)
Lines 79-86 Link Here
79
                    <build-prerequisite/>
79
                    <build-prerequisite/>
80
                    <compile-dependency/>
80
                    <compile-dependency/>
81
                    <run-dependency>
81
                    <run-dependency>
82
                        <release-version>2</release-version>
82
                        <release-version>3</release-version>
83
                        <specification-version>2.7</specification-version>
83
                        <specification-version>3.1</specification-version>
84
                    </run-dependency>
84
                    </run-dependency>
85
                </dependency>
85
                </dependency>
86
                <dependency>
86
                <dependency>
(-)a/cnd.debugger.gdb/nbproject/project.xml (-2 / +2 lines)
Lines 124-131 Link Here
124
                    <build-prerequisite/>
124
                    <build-prerequisite/>
125
                    <compile-dependency/>
125
                    <compile-dependency/>
126
                    <run-dependency>
126
                    <run-dependency>
127
                        <release-version>2</release-version>
127
                        <release-version>3</release-version>
128
                        <specification-version>2.7</specification-version>
128
                        <specification-version>3.1</specification-version>
129
                    </run-dependency>
129
                    </run-dependency>
130
                </dependency>
130
                </dependency>
131
                <dependency>
131
                <dependency>
(-)a/cnd.editor/nbproject/project.xml (-3 / +3 lines)
Lines 36-42 Link Here
36
                    <compile-dependency/>
36
                    <compile-dependency/>
37
                    <run-dependency>
37
                    <run-dependency>
38
                        <release-version>3</release-version>
38
                        <release-version>3</release-version>
39
                        <specification-version>1.41</specification-version>
39
                        <specification-version>1.53</specification-version>
40
                    </run-dependency>
40
                    </run-dependency>
41
                </dependency>
41
                </dependency>
42
                <dependency>
42
                <dependency>
Lines 71-78 Link Here
71
                    <build-prerequisite/>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <release-version>2</release-version>
74
                        <release-version>3</release-version>
75
                        <specification-version>2.1</specification-version>
75
                        <specification-version>3.1</specification-version>
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/CCKit.java (-40 / +38 lines)
Lines 47-53 Link Here
47
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionEvent;
48
import javax.swing.Action;
48
import javax.swing.Action;
49
import javax.swing.text.Caret;
49
import javax.swing.text.Caret;
50
import javax.swing.text.Position;
51
import javax.swing.text.Document;
50
import javax.swing.text.Document;
52
import javax.swing.text.JTextComponent;
51
import javax.swing.text.JTextComponent;
53
import javax.swing.text.TextAction;
52
import javax.swing.text.TextAction;
Lines 228-279 Link Here
228
                    return;
227
                    return;
229
                }
228
                }
230
229
231
                final BaseDocument doc = (BaseDocument) target.getDocument();
230
		final BaseDocument doc = (BaseDocument)target.getDocument();
231
                final Reformat formatter = Reformat.get(doc);
232
232
                // Set hourglass cursor
233
                // Set hourglass cursor
233
                Cursor origCursor = target.getCursor();
234
                Cursor origCursor = target.getCursor();
234
                target.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
235
                target.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
236
                
237
                formatter.lock();
238
                try {
239
                    doc.runAtomic(new Runnable() {
235
240
236
                doc.runAtomicAsUser(new Runnable() {
241
                        public void run() {
242
                            try {
243
                                Caret caret = target.getCaret();
237
244
238
                    public void run() {
245
                                int caretLine = Utilities.getLineOffset(doc, caret.getDot());
239
                        try {
246
                                int start;
240
                            Caret caret = target.getCaret();
247
                                int end;
248
                                //if (caret.isSelectionVisible()) {
249
                                if (Utilities.isSelectionShowing(caret)) {
250
                                    start = target.getSelectionStart();
251
                                    end = target.getSelectionEnd();
252
                                } else {
253
                                    start = 0;
254
                                    end = doc.getLength();
255
                                }
241
256
242
                            int caretLine = Utilities.getLineOffset(doc, caret.getDot());
257
                                formatter.reformat(start, end);
243
                            int startPos;
258
244
                            Position endPosition;
259
                                // Restore the line
245
                            //if (caret.isSelectionVisible()) {
260
                                int pos = Utilities.getRowStartFromLineOffset(doc, caretLine);
246
                            if (Utilities.isSelectionShowing(caret)) {
261
                                if (pos >= 0) {
247
                                startPos = target.getSelectionStart();
262
                                    caret.setDot(pos);
248
                                endPosition = doc.createPosition(target.getSelectionEnd());
263
                                }
249
                            } else {
264
                            } catch (BadLocationException e) {
250
                                startPos = 0;
265
                                //failed to format
251
                                endPosition = doc.createPosition(doc.getLength());
252
                            }
266
                            }
267
                        }
268
                    });
269
                } finally {
270
                    formatter.unlock();
271
                }
253
272
254
                            int pos = startPos;
255
                            Reformat reformat = Reformat.get(doc);
256
                            reformat.lock();
257
                            try {
258
                                reformat.reformat(pos, endPosition.getOffset());
259
                            } finally {
260
                                reformat.unlock();
261
                            }
262
263
                            // Restore the line
264
                            pos = Utilities.getRowStartFromLineOffset(doc, caretLine);
265
                            if (pos >= 0) {
266
                                caret.setDot(pos);
267
                            }
268
                        } catch (BadLocationException e) {
269
                            //failed to format
270
                        }
271
                    }
272
                });
273
                target.setCursor(origCursor);
273
                target.setCursor(origCursor);
274
274
	    }
275
            }
275
	}
276
        }
277
    }
276
    }
278
277
279
    public static class CCDefaultKeyTypedAction extends ExtDefaultKeyTypedAction {
278
    public static class CCDefaultKeyTypedAction extends ExtDefaultKeyTypedAction {
Lines 372-379 Link Here
372
                        }
371
                        }
373
                        doc.insertString(end, "\n" + insString, null); // NOI18N
372
                        doc.insertString(end, "\n" + insString, null); // NOI18N
374
                        // Lock does not need because method is invoked from BaseKit that already lock indent.
373
                        // Lock does not need because method is invoked from BaseKit that already lock indent.
375
                        Indent indent = Indent.get(doc);
374
                        Indent.get(doc).indentNewLine(end);
376
                        indent.reindent(end + 1);
377
                        caret.setDot(dotPos);
375
                        caret.setDot(dotPos);
378
                        return Boolean.TRUE;
376
                        return Boolean.TRUE;
379
                    }
377
                    }
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/cplusplus/InsertSemicolonAction.java (-15 / +20 lines)
Lines 38-43 Link Here
38
import org.netbeans.editor.BaseDocument;
38
import org.netbeans.editor.BaseDocument;
39
import org.netbeans.editor.Utilities;
39
import org.netbeans.editor.Utilities;
40
import org.netbeans.modules.editor.indent.api.Indent;
40
import org.netbeans.modules.editor.indent.api.Indent;
41
import org.openide.util.Exceptions;
41
import org.openide.util.NbBundle;
42
import org.openide.util.NbBundle;
42
43
43
/**
44
/**
Lines 72-101 Link Here
72
            return;
73
            return;
73
        }
74
        }
74
        final BaseDocument doc = (BaseDocument) target.getDocument();
75
        final BaseDocument doc = (BaseDocument) target.getDocument();
76
        final Indent indenter = Indent.get(doc);
75
        final class R implements Runnable {
77
        final class R implements Runnable {
76
            public void run() {
78
            public void run() {
77
                Caret caret = target.getCaret();
78
                int dotpos = caret.getDot();
79
                try {
79
                try {
80
                    Caret caret = target.getCaret();
81
                    int dotpos = caret.getDot();
80
                    int eoloffset = Utilities.getRowEnd(target, dotpos);
82
                    int eoloffset = Utilities.getRowEnd(target, dotpos);
81
                    String insertString = "" + what;
83
                    doc.insertString(eoloffset, "" + what, null); //NOI18N
82
                    doc.insertString(eoloffset, insertString, null); //NOI18N
83
                    if (withNewline) {
84
                    if (withNewline) {
84
                        Indent indent = Indent.get(doc);
85
                        //This is code from the editor module, but it is
85
                        indent.lock();
86
                        //a pretty strange way to do this:
86
                        try {
87
                        doc.insertString(dotpos, "-", null); //NOI18N
87
                            int eolDot = Utilities.getRowEnd(target, caret.getDot());
88
                        doc.remove(dotpos, 1);
88
                            doc.insertString(eolDot, "\n", null); // NOI18N
89
                        int eolDot = Utilities.getRowEnd(target, caret.getDot());
89
                            caret.setDot(eolDot+1);
90
                        int newDotPos = indenter.indentNewLine(eolDot);
90
                            indent.reindent(eolDot+1);
91
                        caret.setDot(newDotPos);
91
                        } finally {
92
                            indent.unlock();
93
                        }
94
                    }
92
                    }
95
                } catch (BadLocationException ex) {
93
                } catch (BadLocationException ex) {
94
                    Exceptions.printStackTrace(ex);
96
                }
95
                }
97
            }
96
            }
98
        }
97
        }
99
        doc.runAtomicAsUser(new R());
98
99
        indenter.lock();
100
        try {
101
            doc.runAtomicAsUser(new R());
102
        } finally {
103
            indenter.lock();
104
        }
100
    }
105
    }
101
}
106
}
(-)a/cnd.editor/src/org/netbeans/modules/cnd/editor/options/EditorPropertySheet.java (-129 / +3 lines)
Lines 55-60 Link Here
55
import java.util.Collections;
55
import java.util.Collections;
56
import java.util.List;
56
import java.util.List;
57
import java.util.Map;
57
import java.util.Map;
58
import java.util.logging.Level;
59
import java.util.logging.Logger;
58
import java.util.prefs.PreferenceChangeEvent;
60
import java.util.prefs.PreferenceChangeEvent;
59
import java.util.prefs.PreferenceChangeListener;
61
import java.util.prefs.PreferenceChangeListener;
60
import java.util.prefs.Preferences;
62
import java.util.prefs.Preferences;
Lines 62-75 Link Here
62
import javax.swing.JEditorPane;
64
import javax.swing.JEditorPane;
63
import javax.swing.SwingUtilities;
65
import javax.swing.SwingUtilities;
64
import javax.swing.text.BadLocationException;
66
import javax.swing.text.BadLocationException;
65
import org.netbeans.api.editor.mimelookup.MimeLookup;
66
import org.netbeans.api.editor.settings.SimpleValueNames;
67
import org.netbeans.api.editor.settings.SimpleValueNames;
67
import org.netbeans.editor.BaseDocument;
68
import org.netbeans.editor.BaseDocument;
68
import org.netbeans.modules.cnd.editor.api.CodeStyle;
69
import org.netbeans.modules.cnd.editor.api.CodeStyle;
69
import org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter;
70
import org.netbeans.modules.cnd.editor.options.PreviewPreferencesModel.Filter;
70
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
71
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
71
import org.netbeans.modules.cnd.utils.MIMENames;
72
import org.netbeans.modules.editor.indent.api.IndentUtils;
73
import org.openide.DialogDescriptor;
72
import org.openide.DialogDescriptor;
74
import org.openide.DialogDisplayer;
73
import org.openide.DialogDisplayer;
75
import org.openide.explorer.propertysheet.PropertySheet;
74
import org.openide.explorer.propertysheet.PropertySheet;
Lines 98-104 Link Here
98
    private PreviewPreferencesModel preferencesModel;
97
    private PreviewPreferencesModel preferencesModel;
99
    private Filter filter;
98
    private Filter filter;
100
    private PropertySheet holder;
99
    private PropertySheet holder;
101
    private Object[] originalEditorProperties = null;
102
100
103
    EditorPropertySheet(EditorOptionsPanelController topControler, CodeStyle.Language language, PreviewPreferencesModel preferencesModel, Filter filter) {
101
    EditorPropertySheet(EditorOptionsPanelController topControler, CodeStyle.Language language, PreviewPreferencesModel preferencesModel, Filter filter) {
104
        this.topController = topControler;
102
        this.topController = topControler;
Lines 383-391 Link Here
383
381
384
    void load() {
382
    void load() {
385
        loaded = false;
383
        loaded = false;
386
        if (filter == Filter.All) {
387
            originalEditorProperties = preserveEditorProperties();
388
        }
389
        initLanguageMap();
384
        initLanguageMap();
390
        initLanguageCategory();
385
        initLanguageCategory();
391
        loaded = true;
386
        loaded = true;
Lines 449-458 Link Here
449
        if (filter != Filter.All) {
444
        if (filter != Filter.All) {
450
            return;
445
            return;
451
        }
446
        }
452
        if (originalEditorProperties != null) {
453
            restoreEditorProperties(originalEditorProperties);
454
            originalEditorProperties = null;
455
        }
456
        preferencesModel.clear(language);
447
        preferencesModel.clear(language);
457
    }
448
    }
458
449
Lines 581-587 Link Here
581
                    is.close();
572
                    is.close();
582
                }
573
                }
583
            } catch (IOException ioe) {
574
            } catch (IOException ioe) {
584
                ioe.printStackTrace();
575
                Logger.getLogger(EditorPropertySheet.class.getName()).log(Level.FINE, null, ioe);
585
            }
576
            }
586
            return sb.toString();
577
            return sb.toString();
587
        } else {
578
        } else {
Lines 593-719 Link Here
593
        pane.setText(getPreviewText());
584
        pane.setText(getPreviewText());
594
        BaseDocument bd = (BaseDocument) pane.getDocument();
585
        BaseDocument bd = (BaseDocument) pane.getDocument();
595
        CodeStyle codeStyle = EditorOptions.createCodeStyle(language, p, false);
586
        CodeStyle codeStyle = EditorOptions.createCodeStyle(language, p, false);
596
        setEditorProperties(p);
597
        try {
587
        try {
598
            if (TRACE) {
599
                System.err.println("Refreshing preview"); // NOI18N
600
                System.err.println("          tabSize=" + IndentUtils.tabSize(bd)+"/"+codeStyle.getTabSize()); // NOI18N
601
                System.err.println("       expandTabs=" + IndentUtils.isExpandTabs(bd)+"/"+codeStyle.expandTabToSpaces()); // NOI18N
602
                System.err.println("  indentLevelSize=" + IndentUtils.indentLevelSize(bd)+"/"+codeStyle.indentSize()); // NOI18N
603
                System.err.println("  doc=" + bd); //NOI18N
604
            }
605
            new Reformatter(bd, codeStyle).reformat();
588
            new Reformatter(bd, codeStyle).reformat();
606
        } catch (BadLocationException ex) {
589
        } catch (BadLocationException ex) {
607
            Exceptions.printStackTrace(ex);
590
            Exceptions.printStackTrace(ex);
608
        } catch (Throwable ex) {
609
            ex.printStackTrace();
610
        }
611
    }
612
613
    private void setEditorProperties(Preferences p) {
614
        Preferences def = null;
615
        switch (language){
616
            case C:
617
                def = MimeLookup.getLookup(MIMENames.C_MIME_TYPE).lookup(Preferences.class);
618
                break;
619
            case HEADER:
620
                def = MimeLookup.getLookup(MIMENames.HEADER_MIME_TYPE).lookup(Preferences.class);
621
                break;
622
            case CPP:
623
            default:
624
                def = MimeLookup.getLookup(MIMENames.CPLUSPLUS_MIME_TYPE).lookup(Preferences.class);
625
                break;
626
        }
627
        if (def != null) {
628
            def.putInt(SimpleValueNames.TAB_SIZE, p.getInt(EditorOptions.tabSize, EditorOptions.tabSizeDefault));
629
            def.putInt(SimpleValueNames.SPACES_PER_TAB, p.getInt(EditorOptions.tabSize, EditorOptions.tabSizeDefault));
630
            def.putBoolean(SimpleValueNames.EXPAND_TABS, p.getBoolean(EditorOptions.expandTabToSpaces, EditorOptions.expandTabToSpacesDefault));
631
            def.putInt(SimpleValueNames.INDENT_SHIFT_WIDTH, p.getInt(EditorOptions.indentSize, EditorOptions.indentSizeDefault));
632
        }
633
    }
634
635
    private Object[] preserveEditorProperties() {
636
        Preferences def = null;
637
        Object oldValues[] = null;
638
        switch (language){
639
            case C:
640
                def = MimeLookup.getLookup(MIMENames.C_MIME_TYPE).lookup(Preferences.class);
641
                break;
642
            case HEADER:
643
                def = MimeLookup.getLookup(MIMENames.HEADER_MIME_TYPE).lookup(Preferences.class);
644
                break;
645
            case CPP:
646
            default:
647
                def = MimeLookup.getLookup(MIMENames.CPLUSPLUS_MIME_TYPE).lookup(Preferences.class);
648
                break;
649
        }
650
        if (def != null) {
651
            oldValues = new Object[]{null, null, null, null};
652
            if (null != def.get(SimpleValueNames.TAB_SIZE, null)) {
653
                oldValues[0] = def.getInt(SimpleValueNames.TAB_SIZE, EditorOptions.tabSizeDefault);
654
            }
655
            if (null != def.get(SimpleValueNames.SPACES_PER_TAB, null)) {
656
                oldValues[1] = def.getInt(SimpleValueNames.SPACES_PER_TAB, EditorOptions.tabSizeDefault);
657
            }
658
            if (null != def.get(SimpleValueNames.EXPAND_TABS, null)) {
659
                oldValues[2] = def.getBoolean(SimpleValueNames.EXPAND_TABS, EditorOptions.expandTabToSpacesDefault);
660
            }
661
            if (null != def.get(SimpleValueNames.INDENT_SHIFT_WIDTH, null)) {
662
                oldValues[3] = def.getInt(SimpleValueNames.INDENT_SHIFT_WIDTH, EditorOptions.indentSizeDefault);
663
            }
664
            if (TRACE) {
665
                System.err.println("Preserving editor properties:"); //NOI18N
666
                System.err.println("           tabSize=" + oldValues[0]); //NOI18N
667
                System.err.println("      spacesPerTab=" + oldValues[1]); //NOI18N
668
                System.err.println("        expandTabs=" + oldValues[2]); //NOI18N
669
                System.err.println("  indentShiftWidth=" + oldValues[3]); //NOI18N
670
            }
671
        }
672
        return oldValues;
673
    }
674
675
    private void restoreEditorProperties(Object[] oldValues) {
676
        Preferences def = null;
677
        switch (language){
678
            case C:
679
                def = MimeLookup.getLookup(MIMENames.C_MIME_TYPE).lookup(Preferences.class);
680
                break;
681
            case HEADER:
682
                def = MimeLookup.getLookup(MIMENames.HEADER_MIME_TYPE).lookup(Preferences.class);
683
                break;
684
            case CPP:
685
            default:
686
                def = MimeLookup.getLookup(MIMENames.CPLUSPLUS_MIME_TYPE).lookup(Preferences.class);
687
                break;
688
        }
689
        if (def != null && oldValues != null) {
690
            if (TRACE) {
691
                System.err.println("Restoring editor properties:"); //NOI18N
692
                System.err.println("           tabSize=" + oldValues[0]); //NOI18N
693
                System.err.println("      spacesPerTab=" + oldValues[1]); //NOI18N
694
                System.err.println("        expandTabs=" + oldValues[2]); //NOI18N
695
                System.err.println("  indentShiftWidth=" + oldValues[3]); //NOI18N
696
            }
697
            if (oldValues[0] == null) {
698
                def.remove(SimpleValueNames.TAB_SIZE);
699
            } else {
700
                def.putInt(SimpleValueNames.TAB_SIZE, ((Integer)oldValues[0]).intValue());
701
            }
702
            if (oldValues[1] == null) {
703
                def.remove(SimpleValueNames.SPACES_PER_TAB);
704
            } else {
705
                def.putInt(SimpleValueNames.SPACES_PER_TAB, ((Integer)oldValues[1]).intValue());
706
            }
707
            if (oldValues[2] == null) {
708
                def.remove(SimpleValueNames.EXPAND_TABS);
709
            } else {
710
                def.putBoolean(SimpleValueNames.EXPAND_TABS, ((Boolean)oldValues[2]).booleanValue());
711
            }
712
            if (oldValues[3] == null) {
713
                def.remove(SimpleValueNames.INDENT_SHIFT_WIDTH);
714
            } else {
715
                def.putInt(SimpleValueNames.INDENT_SHIFT_WIDTH, ((Integer)oldValues[3]).intValue());
716
            }
717
        }
591
        }
718
    }
592
    }
719
593
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/BracketCompletionTestCase.java (+2 lines)
Lines 33-38 Link Here
33
33
34
import org.netbeans.modules.cnd.editor.api.CodeStyle;
34
import org.netbeans.modules.cnd.editor.api.CodeStyle;
35
import org.netbeans.modules.cnd.editor.options.EditorOptions;
35
import org.netbeans.modules.cnd.editor.options.EditorOptions;
36
import org.netbeans.modules.editor.indent.api.Indent;
37
import org.openide.util.Exceptions;
36
38
37
/**
39
/**
38
 * Class was taken from java
40
 * Class was taken from java
(-)a/cnd.editor/test/unit/src/org/netbeans/modules/cnd/editor/cplusplus/EditorBase.java (-4 / +13 lines)
Lines 42-47 Link Here
42
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
42
import org.netbeans.modules.cnd.editor.reformat.Reformatter;
43
import org.netbeans.modules.cnd.test.base.BaseDocumentUnitTestCase;
43
import org.netbeans.modules.cnd.test.base.BaseDocumentUnitTestCase;
44
import org.netbeans.modules.editor.indent.api.Indent;
44
import org.netbeans.modules.editor.indent.api.Indent;
45
import org.netbeans.modules.editor.indent.api.Reformat;
45
import org.openide.util.Exceptions;
46
import org.openide.util.Exceptions;
46
47
47
/**
48
/**
Lines 145-158 Link Here
145
    /**
146
    /**
146
     * Perform reformatting of the whole document's text.
147
     * Perform reformatting of the whole document's text.
147
     */
148
     */
148
    protected final void reformat() {
149
    protected void reformat() {
149
        Reformatter f = new Reformatter(getDocument(), CodeStyle.getDefault(getDocument()));
150
        Reformat f = Reformat.get(getDocument());
151
        f.lock();
150
        try {
152
        try {
151
            f.reformat();
153
            getDocument().atomicLock();
154
            try {
155
                f.reformat(0, getDocument().getLength());
156
            } finally {
157
                getDocument().atomicUnlock();
158
            }
152
        } catch (BadLocationException e) {
159
        } catch (BadLocationException e) {
153
            e.printStackTrace(getLog());
160
            e.printStackTrace(getLog());
154
            fail(e.getMessage());
161
            fail(e.getMessage());
155
    	}
162
        } finally {
163
            f.unlock();
164
        }
156
    }
165
    }
157
166
158
    // ------- help methods -------------
167
    // ------- help methods -------------
(-)a/cnd.gizmo/nbproject/project.xml (-2 / +2 lines)
Lines 152-159 Link Here
152
                    <build-prerequisite/>
152
                    <build-prerequisite/>
153
                    <compile-dependency/>
153
                    <compile-dependency/>
154
                    <run-dependency>
154
                    <run-dependency>
155
                        <release-version>2</release-version>
155
                        <release-version>3</release-version>
156
                        <specification-version>2.1</specification-version>
156
                        <specification-version>3.1</specification-version>
157
                    </run-dependency>
157
                    </run-dependency>
158
                </dependency>
158
                </dependency>
159
                <dependency>
159
                <dependency>
(-)a/cnd.gotodeclaration/nbproject/project.xml (+27 lines)
Lines 50-55 Link Here
50
                    </run-dependency>
50
                    </run-dependency>
51
                </dependency>
51
                </dependency>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.modules.editor.completion</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
58
                        <specification-version>1.6.12</specification-version>
59
                    </run-dependency>
60
                </dependency>
61
                <dependency>
62
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
69
                </dependency>
70
                <dependency>
71
                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
74
                    <run-dependency>
75
                        <release-version>1</release-version>
76
                        <specification-version>1.4.12</specification-version>
77
                    </run-dependency>
78
                </dependency>
79
                <dependency>
53
                    <code-name-base>org.netbeans.modules.jumpto</code-name-base>
80
                    <code-name-base>org.netbeans.modules.jumpto</code-name-base>
54
                    <build-prerequisite/>
81
                    <build-prerequisite/>
55
                    <compile-dependency/>
82
                    <compile-dependency/>
(-)a/cnd.highlight/nbproject/project.xml (-2 / +2 lines)
Lines 106-113 Link Here
106
                    <build-prerequisite/>
106
                    <build-prerequisite/>
107
                    <compile-dependency/>
107
                    <compile-dependency/>
108
                    <run-dependency>
108
                    <run-dependency>
109
                        <release-version>2</release-version>
109
                        <release-version>3</release-version>
110
                        <specification-version>2.1</specification-version>
110
                        <specification-version>3.1</specification-version>
111
                    </run-dependency>
111
                    </run-dependency>
112
                </dependency>
112
                </dependency>
113
                <dependency>
113
                <dependency>
(-)a/cnd.modelimpl/nbproject/project.xml (-2 / +2 lines)
Lines 105-112 Link Here
105
                    <build-prerequisite/>
105
                    <build-prerequisite/>
106
                    <compile-dependency/>
106
                    <compile-dependency/>
107
                    <run-dependency>
107
                    <run-dependency>
108
                        <release-version>2</release-version>
108
                        <release-version>3</release-version>
109
                        <specification-version>2.10</specification-version>
109
                        <specification-version>3.1</specification-version>
110
                    </run-dependency>
110
                    </run-dependency>
111
                </dependency>
111
                </dependency>
112
                <dependency>
112
                <dependency>
(-)a/cnd.modelutil/nbproject/project.xml (-3 / +3 lines)
Lines 46-52 Link Here
46
                    <compile-dependency/>
46
                    <compile-dependency/>
47
                    <run-dependency>
47
                    <run-dependency>
48
                        <release-version>3</release-version>
48
                        <release-version>3</release-version>
49
                        <specification-version>1.41</specification-version>
49
                        <specification-version>1.53</specification-version>
50
                    </run-dependency>
50
                    </run-dependency>
51
                </dependency>
51
                </dependency>
52
                <dependency>
52
                <dependency>
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/cnd.navigation/nbproject/project.xml (-3 / +3 lines)
Lines 54-60 Link Here
54
                    <compile-dependency/>
54
                    <compile-dependency/>
55
                    <run-dependency>
55
                    <run-dependency>
56
                        <release-version>3</release-version>
56
                        <release-version>3</release-version>
57
                        <specification-version>1.42</specification-version>
57
                        <specification-version>1.53</specification-version>
58
                    </run-dependency>
58
                    </run-dependency>
59
                </dependency>
59
                </dependency>
60
                <dependency>
60
                <dependency>
Lines 62-69 Link Here
62
                    <build-prerequisite/>
62
                    <build-prerequisite/>
63
                    <compile-dependency/>
63
                    <compile-dependency/>
64
                    <run-dependency>
64
                    <run-dependency>
65
                        <release-version>2</release-version>
65
                        <release-version>3</release-version>
66
                        <specification-version>2.1</specification-version>
66
                        <specification-version>3.1</specification-version>
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
(-)a/cnd.refactoring/nbproject/project.xml (-3 / +3 lines)
Lines 73-79 Link Here
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>3</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>1.41</specification-version>
76
                        <specification-version>1.53</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
Lines 90-97 Link Here
90
                    <build-prerequisite/>
90
                    <build-prerequisite/>
91
                    <compile-dependency/>
91
                    <compile-dependency/>
92
                    <run-dependency>
92
                    <run-dependency>
93
                        <release-version>2</release-version>
93
                        <release-version>3</release-version>
94
                        <specification-version>2.1</specification-version>
94
                        <specification-version>3.1</specification-version>
95
                    </run-dependency>
95
                    </run-dependency>
96
                </dependency>
96
                </dependency>
97
                <dependency>
97
                <dependency>
(-)a/cnd.script/nbproject/project.xml (-3 / +3 lines)
Lines 37-43 Link Here
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>3</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>1.48</specification-version>
40
                        <specification-version>1.53</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.2</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/cnd.testrunner/nbproject/project.xml (-2 / +2 lines)
Lines 95-102 Link Here
95
                    <build-prerequisite/>
95
                    <build-prerequisite/>
96
                    <compile-dependency/>
96
                    <compile-dependency/>
97
                    <run-dependency>
97
                    <run-dependency>
98
                        <release-version>2</release-version>
98
                        <release-version>3</release-version>
99
                        <specification-version>2.1</specification-version>
99
                        <specification-version>3.1</specification-version>
100
                    </run-dependency>
100
                    </run-dependency>
101
                </dependency>
101
                </dependency>
102
                <dependency>
102
                <dependency>
(-)a/cnd/nbproject/project.xml (-1 / +28 lines)
Lines 61-67 Link Here
61
                    <compile-dependency/>
61
                    <compile-dependency/>
62
                    <run-dependency>
62
                    <run-dependency>
63
                        <release-version>2</release-version>
63
                        <release-version>2</release-version>
64
                        <specification-version>1.9</specification-version>
64
                        <specification-version>1.10</specification-version>
65
                    </run-dependency>
66
                </dependency>
67
                <dependency>
68
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
69
                    <build-prerequisite/>
70
                    <compile-dependency/>
71
                    <run-dependency>
72
                        <release-version>1</release-version>
73
                        <specification-version>1.10</specification-version>
74
                    </run-dependency>
75
                </dependency>
76
                <dependency>
77
                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
78
                    <build-prerequisite/>
79
                    <compile-dependency/>
80
                    <run-dependency>
81
                        <release-version>1</release-version>
82
                        <specification-version>1.22</specification-version>
65
                    </run-dependency>
83
                    </run-dependency>
66
                </dependency>
84
                </dependency>
67
                <dependency>
85
                <dependency>
Lines 70-75 Link Here
70
                    <compile-dependency/>
88
                    <compile-dependency/>
71
                    <run-dependency>
89
                    <run-dependency>
72
                        <release-version>2</release-version>
90
                        <release-version>2</release-version>
91
                        <specification-version>1.22</specification-version>
92
                    </run-dependency>
93
                </dependency>
94
                <dependency>
95
                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
73
                        <specification-version>1.16</specification-version>
100
                        <specification-version>1.16</specification-version>
74
                    </run-dependency>
101
                    </run-dependency>
75
                </dependency>
102
                </dependency>
(-)a/collab.channel.chat/nbproject/project.xml (-4 / +4 lines)
Lines 65-71 Link Here
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>3</release-version>
67
                        <release-version>3</release-version>
68
                    <specification-version>1.41</specification-version>
68
                    <specification-version>1.53</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
Lines 73-80 Link Here
73
                    <build-prerequisite/>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
74
                    <compile-dependency/>
75
                    <run-dependency>
75
                    <run-dependency>
76
                        <release-version>2</release-version>
76
                        <release-version>3</release-version>
77
                    <specification-version>2.1</specification-version>
77
                    <specification-version>3.1</specification-version>
78
                    </run-dependency>
78
                    </run-dependency>
79
                </dependency>
79
                </dependency>
80
                <dependency>
80
                <dependency>
Lines 125-131 Link Here
125
                        <specification-version>6.2</specification-version>
125
                        <specification-version>6.2</specification-version>
126
                    </run-dependency>
126
                    </run-dependency>
127
                </dependency>
127
                </dependency>
128
                </module-dependencies>
128
            </module-dependencies>
129
            <public-packages>
129
            <public-packages>
130
                <package>org.netbeans.modules.collab.channel.chat</package>
130
                <package>org.netbeans.modules.collab.channel.chat</package>
131
                <package>org.netbeans.modules.collab.channel.chat.messagetype</package>
131
                <package>org.netbeans.modules.collab.channel.chat.messagetype</package>
(-)a/compapp.casaeditor/nbproject/project.xml (-2 / +2 lines)
Lines 123-130 Link Here
123
                    <build-prerequisite/>
123
                    <build-prerequisite/>
124
                    <compile-dependency/>
124
                    <compile-dependency/>
125
                    <run-dependency>
125
                    <run-dependency>
126
                        <release-version>2</release-version>
126
                        <release-version>3</release-version>
127
                        <specification-version>2.1</specification-version>
127
                        <specification-version>3.1</specification-version>
128
                    </run-dependency>
128
                    </run-dependency>
129
                </dependency>
129
                </dependency>
130
                <dependency>
130
                <dependency>
(-)a/compapp.projects.base/nbproject/project.xml (-2 / +2 lines)
Lines 64-71 Link Here
64
                    <build-prerequisite/>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>2</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>2.1</specification-version>
68
                        <specification-version>3.1</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
(-)a/compapp.projects.jbi/nbproject/project.xml (-2 / +2 lines)
Lines 174-181 Link Here
174
                    <build-prerequisite/>
174
                    <build-prerequisite/>
175
                    <compile-dependency/>
175
                    <compile-dependency/>
176
                    <run-dependency>
176
                    <run-dependency>
177
                        <release-version>2</release-version>
177
                        <release-version>3</release-version>
178
                        <specification-version>2.1</specification-version>
178
                        <specification-version>3.1</specification-version>
179
                    </run-dependency>
179
                    </run-dependency>
180
                </dependency>
180
                </dependency>
181
                <dependency>
181
                <dependency>
(-)a/csl.api/nbproject/project.xml (-3 / +3 lines)
Lines 56-62 Link Here
56
                    <compile-dependency/>
56
                    <compile-dependency/>
57
                    <run-dependency>
57
                    <run-dependency>
58
                        <release-version>3</release-version>
58
                        <release-version>3</release-version>
59
                        <specification-version>1.41</specification-version>
59
                        <specification-version>1.53</specification-version>
60
                    </run-dependency>
60
                    </run-dependency>
61
                </dependency>
61
                </dependency>
62
                <dependency>
62
                <dependency>
Lines 118-125 Link Here
118
                    <build-prerequisite/>
118
                    <build-prerequisite/>
119
                    <compile-dependency/>
119
                    <compile-dependency/>
120
                    <run-dependency>
120
                    <run-dependency>
121
                        <release-version>2</release-version>
121
                        <release-version>3</release-version>
122
                        <specification-version>2.1</specification-version>
122
                        <specification-version>3.1</specification-version>
123
                    </run-dependency>
123
                    </run-dependency>
124
                </dependency>
124
                </dependency>
125
                <dependency>
125
                <dependency>
(-)a/css.editor/nbproject/project.xml (-3 / +3 lines)
Lines 29-35 Link Here
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>3</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>1.41</specification-version>
32
                        <specification-version>1.53</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
Lines 55-62 Link Here
55
                    <build-prerequisite/>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
56
                    <compile-dependency/>
57
                    <run-dependency>
57
                    <run-dependency>
58
                        <release-version>2</release-version>
58
                        <release-version>3</release-version>
59
                        <specification-version>2.1</specification-version>
59
                        <specification-version>3.1</specification-version>
60
                    </run-dependency>
60
                    </run-dependency>
61
                </dependency>
61
                </dependency>
62
                <dependency>
62
                <dependency>
(-)a/css.visual/nbproject/project.xml (-3 / +12 lines)
Lines 82-88 Link Here
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>3</release-version>
84
                        <release-version>3</release-version>
85
                        <specification-version>1.41</specification-version>
85
                        <specification-version>1.53</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
Lines 95-106 Link Here
95
                    </run-dependency>
95
                    </run-dependency>
96
                </dependency>
96
                </dependency>
97
                <dependency>
97
                <dependency>
98
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
99
                    <build-prerequisite/>
100
                    <compile-dependency/>
101
                    <run-dependency>
102
                        <release-version>2</release-version>
103
                        <specification-version>1.9</specification-version>
104
                    </run-dependency>
105
                </dependency>
106
                <dependency>
98
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
107
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
99
                    <build-prerequisite/>
108
                    <build-prerequisite/>
100
                    <compile-dependency/>
109
                    <compile-dependency/>
101
                    <run-dependency>
110
                    <run-dependency>
102
                        <release-version>2</release-version>
111
                        <release-version>3</release-version>
103
                        <specification-version>2.1</specification-version>
112
                        <specification-version>3.1</specification-version>
104
                    </run-dependency>
113
                    </run-dependency>
105
                </dependency>
114
                </dependency>
106
                <dependency>
115
                <dependency>
(-)a/css.visual/src/org/netbeans/modules/css/editor/CssEditorSupport.java (-9 / +18 lines)
Lines 63-68 Link Here
63
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable;
63
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable;
64
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable.Listener;
64
import org.netbeans.modules.css.visual.ui.preview.CssPreviewable.Listener;
65
import org.netbeans.modules.editor.NbEditorDocument;
65
import org.netbeans.modules.editor.NbEditorDocument;
66
import org.netbeans.modules.editor.indent.api.IndentUtils;
67
import org.openide.cookies.EditorCookie;
68
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileUtil;
69
import org.openide.filesystems.FileUtil;
67
70
68
/**
71
/**
Lines 139-145 Link Here
139
                            } else if (oldRule == null && newRule != null) {
142
                            } else if (oldRule == null && newRule != null) {
140
                                //add the new rule at the end of the rule block:
143
                                //add the new rule at the end of the rule block:
141
                                List<CssRuleItem> items = myRule.items();
144
                                List<CssRuleItem> items = myRule.items();
142
                                final int INDENT = doc.getFormatter().getShiftWidth();
145
                                final int INDENT = IndentUtils.indentLevelSize(document);
143
                                int insertOffset = myRule.getRuleCloseBracketOffset();
146
                                int insertOffset = myRule.getRuleCloseBracketOffset();
144
147
145
                                boolean initialNewLine = false;
148
                                boolean initialNewLine = false;
Lines 160-166 Link Here
160
                                }
163
                                }
161
164
162
                                String text = (initialNewLine ? LINE_SEPARATOR : "") +
165
                                String text = (initialNewLine ? LINE_SEPARATOR : "") +
163
                                        makeIndentString(INDENT) +
166
// XXX: see the method comment
167
//                                        makeIndentString(INDENT) +
168
                                        IndentUtils.createIndentString(document, INDENT) +
164
                                        newRule.key().name() + ": " + newRule.value().name() + ";" +
169
                                        newRule.key().name() + ": " + newRule.value().name() + ";" +
165
                                        LINE_SEPARATOR;
170
                                        LINE_SEPARATOR;
166
171
Lines 189-201 Link Here
189
        }
194
        }
190
    };
195
    };
191
196
192
    private String makeIndentString(int level) {
197
    // XXX: This is most likely wrong! Unless CSS only allows spaces for indentation.
193
        StringBuffer sb = new StringBuffer();
198
    // But even then the same should be achieved by correctly setting the indentation
194
        for (int i = 0; i < level; i++) {
199
    // settings. Otherwise a simple Reformat.get(doc).reformat(...) call on a CSS document
195
            sb.append(' ');
200
    // could break its structure.
196
        }
201
//    private String makeIndentString(int level) {
197
        return sb.toString();
202
//        StringBuffer sb = new StringBuffer();
198
    }
203
//        for (int i = 0; i < level; i++) {
204
//            sb.append(' ');
205
//        }
206
//        return sb.toString();
207
//    }
199
208
200
    void parsed(final CssParserResult result, final int caretOffset) {
209
    void parsed(final CssParserResult result, final int caretOffset) {
201
        d("model updated");
210
        d("model updated");
(-)a/db.core/nbproject/project.xml (-2 / +2 lines)
Lines 80-87 Link Here
80
                    <build-prerequisite/>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
81
                    <compile-dependency/>
82
                    <run-dependency>
82
                    <run-dependency>
83
                        <release-version>2</release-version>
83
                        <release-version>3</release-version>
84
                        <specification-version>2.1</specification-version>
84
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
85
                    </run-dependency>
86
                </dependency>
86
                </dependency>
87
                <dependency>
87
                <dependency>
(-)a/db.sql.editor/nbproject/project.xml (-3 / +12 lines)
Lines 98-104 Link Here
98
                    <compile-dependency/>
98
                    <compile-dependency/>
99
                    <run-dependency>
99
                    <run-dependency>
100
                        <release-version>3</release-version>
100
                        <release-version>3</release-version>
101
                        <specification-version>1.41</specification-version>
101
                    <specification-version>1.53</specification-version>
102
                    </run-dependency>
102
                    </run-dependency>
103
                </dependency>
103
                </dependency>
104
                <dependency>
104
                <dependency>
Lines 115-122 Link Here
115
                    <build-prerequisite/>
115
                    <build-prerequisite/>
116
                    <compile-dependency/>
116
                    <compile-dependency/>
117
                    <run-dependency>
117
                    <run-dependency>
118
                        <release-version>2</release-version>
118
                        <release-version>3</release-version>
119
                        <specification-version>2.1</specification-version>
119
                        <specification-version>3.1</specification-version>
120
                    </run-dependency>
120
                    </run-dependency>
121
                </dependency>
121
                </dependency>
122
                <dependency>
122
                <dependency>
Lines 232-237 Link Here
232
                        <specification-version>8.0</specification-version>
232
                        <specification-version>8.0</specification-version>
233
                    </run-dependency>
233
                    </run-dependency>
234
                </dependency>
234
                </dependency>
235
                <dependency>
236
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
237
                    <build-prerequisite/>
238
                    <compile-dependency/>
239
                    <run-dependency>
240
                        <release-version>0-1</release-version>
241
                        <specification-version>1.0</specification-version>
242
                    </run-dependency>
243
                </dependency>
235
            </module-dependencies>
244
            </module-dependencies>
236
            <test-dependencies>
245
            <test-dependencies>
237
                <test-type>
246
                <test-type>
(-)a/debugger.jpda.ant/nbproject/project.xml (-5 / +5 lines)
Lines 101-108 Link Here
101
                    <build-prerequisite/>
101
                    <build-prerequisite/>
102
                    <compile-dependency/>
102
                    <compile-dependency/>
103
                    <run-dependency>
103
                    <run-dependency>
104
                        <release-version>2</release-version>
104
                        <release-version>3</release-version>
105
                        <specification-version>2.1</specification-version>
105
                        <specification-version>3.1</specification-version>
106
                    </run-dependency>
106
                    </run-dependency>
107
                </dependency>
107
                </dependency>
108
                <dependency>
108
                <dependency>
Lines 147-155 Link Here
147
                    <code-name-base>org.openide.util.lookup</code-name-base>
147
                    <code-name-base>org.openide.util.lookup</code-name-base>
148
                    <build-prerequisite/>
148
                    <build-prerequisite/>
149
                    <compile-dependency/>
149
                    <compile-dependency/>
150
		    <run-dependency>
150
                    <run-dependency>
151
                       <specification-version>8.0</specification-version>
151
                        <specification-version>8.0</specification-version>
152
	             </run-dependency>
152
                    </run-dependency>
153
                </dependency>
153
                </dependency>
154
            </module-dependencies>
154
            </module-dependencies>
155
            <public-packages/>
155
            <public-packages/>
(-)a/debugger.jpda.projects/nbproject/project.xml (-2 / +2 lines)
Lines 96-103 Link Here
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
99
                        <release-version>3</release-version>
100
                        <specification-version>2.10</specification-version>
100
                        <specification-version>3.1</specification-version>
101
                    </run-dependency>
101
                    </run-dependency>
102
                </dependency>
102
                </dependency>
103
                <dependency>
103
                <dependency>
(-)a/debugger.jpda.ui/nbproject/project.xml (-2 / +2 lines)
Lines 103-110 Link Here
103
                    <build-prerequisite/>
103
                    <build-prerequisite/>
104
                    <compile-dependency/>
104
                    <compile-dependency/>
105
                    <run-dependency>
105
                    <run-dependency>
106
                        <release-version>2</release-version>
106
                        <release-version>3</release-version>
107
                        <specification-version>2.1</specification-version>
107
                        <specification-version>3.1</specification-version>
108
                    </run-dependency>
108
                    </run-dependency>
109
                </dependency>
109
                </dependency>
110
                <dependency>
110
                <dependency>
(-)a/debugger.jpda/nbproject/project.xml (-2 / +2 lines)
Lines 96-103 Link Here
96
                    <build-prerequisite/>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
97
                    <compile-dependency/>
98
                    <run-dependency>
98
                    <run-dependency>
99
                        <release-version>2</release-version>
99
                        <release-version>3</release-version>
100
                        <specification-version>2.1</specification-version>
100
                        <specification-version>3.1</specification-version>
101
                    </run-dependency>
101
                    </run-dependency>
102
                </dependency>
102
                </dependency>
103
                <dependency>
103
                <dependency>
(-)a/diff/nbproject/project.xml (-2 / +2 lines)
Lines 87-94 Link Here
87
                    <build-prerequisite/>
87
                    <build-prerequisite/>
88
                    <compile-dependency/>
88
                    <compile-dependency/>
89
                    <run-dependency>
89
                    <run-dependency>
90
                        <release-version>2</release-version>
90
                        <release-version>3</release-version>
91
                        <specification-version>2.1</specification-version>
91
                        <specification-version>3.1</specification-version>
92
                    </run-dependency>
92
                    </run-dependency>
93
                </dependency>
93
                </dependency>
94
                <dependency>
94
                <dependency>
(-)a/dlight.annotationsupport/nbproject/project.xml (-2 / +2 lines)
Lines 60-67 Link Here
60
                    <build-prerequisite/>
60
                    <build-prerequisite/>
61
                    <compile-dependency/>
61
                    <compile-dependency/>
62
                    <run-dependency>
62
                    <run-dependency>
63
                        <release-version>2</release-version>
63
                        <release-version>3</release-version>
64
                        <specification-version>2.1</specification-version>
64
                        <specification-version>3.1</specification-version>
65
                    </run-dependency>
65
                    </run-dependency>
66
                </dependency>
66
                </dependency>
67
                <dependency>
67
                <dependency>
(-)a/editor.actions/nbproject/project.xml (-2 / +2 lines)
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/editor.bookmarks/nbproject/project.xml (-4 / +4 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.41</specification-version>
58
                        <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
Lines 152-158 Link Here
152
                    <build-prerequisite/>
152
                    <build-prerequisite/>
153
                    <compile-dependency/>
153
                    <compile-dependency/>
154
                    <run-dependency>
154
                    <run-dependency>
155
                        <specification-version>8.0</specification-version>
155
                        <specification-version>8.4</specification-version>
156
                    </run-dependency>
156
                    </run-dependency>
157
                </dependency>
157
                </dependency>
158
            </module-dependencies>
158
            </module-dependencies>
(-)a/editor.bracesmatching/nbproject/project.xml (-3 / +3 lines)
Lines 20-26 Link Here
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>3</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>1.41</specification-version>
23
                        <specification-version>1.53</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
Lines 28-35 Link Here
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>2.1</specification-version>
32
                        <specification-version>3.1</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/editor.codetemplates/nbproject/project.xml (-3 / +12 lines)
Lines 64-70 Link Here
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>1.41</specification-version>
67
                        <specification-version>1.53</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
Lines 76-87 Link Here
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
79
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
82
                    <run-dependency>
83
                        <release-version>2</release-version>
84
                        <specification-version>1.9</specification-version>
85
                    </run-dependency>
86
                </dependency>
87
                <dependency>
79
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
88
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
80
                    <build-prerequisite/>
89
                    <build-prerequisite/>
81
                    <compile-dependency/>
90
                    <compile-dependency/>
82
                    <run-dependency>
91
                    <run-dependency>
83
                        <release-version>2</release-version>
92
                        <release-version>3</release-version>
84
                        <specification-version>2.1</specification-version>
93
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
94
                    </run-dependency>
86
                </dependency>
95
                </dependency>
87
                <dependency>
96
                <dependency>
(-)a/editor.codetemplates/src/org/netbeans/lib/editor/codetemplates/CodeTemplateInsertHandler.java (-22 / +10 lines)
Lines 61-67 Link Here
61
import javax.swing.undo.CannotUndoException;
61
import javax.swing.undo.CannotUndoException;
62
import org.netbeans.api.editor.completion.Completion;
62
import org.netbeans.api.editor.completion.Completion;
63
import org.netbeans.editor.BaseDocument;
63
import org.netbeans.editor.BaseDocument;
64
import org.netbeans.editor.Formatter;
65
import org.netbeans.editor.Utilities;
64
import org.netbeans.editor.Utilities;
66
import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
65
import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
67
import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateInsertRequest;
66
import org.netbeans.lib.editor.codetemplates.spi.CodeTemplateInsertRequest;
Lines 77-82 Link Here
77
import org.netbeans.lib.editor.util.CharSequenceUtilities;
76
import org.netbeans.lib.editor.util.CharSequenceUtilities;
78
import org.netbeans.lib.editor.util.CharacterConversions;
77
import org.netbeans.lib.editor.util.CharacterConversions;
79
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
78
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
79
import org.netbeans.modules.editor.indent.api.Reformat;
80
80
81
/**
81
/**
82
 * Code template allows the client to paste itself into the given
82
 * Code template allows the client to paste itself into the given
Lines 125-131 Link Here
125
125
126
    private String completeInsertString;
126
    private String completeInsertString;
127
127
128
    private Formatter formatter;
128
    private Reformat formatter;
129
    
129
    
130
    private TextSyncGroup textSyncGroup;
130
    private TextSyncGroup textSyncGroup;
131
    
131
    
Lines 247-276 Link Here
247
        // Build insert string outside of the atomic lock
247
        // Build insert string outside of the atomic lock
248
        completeInsertString = getInsertText();
248
        completeInsertString = getInsertText();
249
249
250
        BaseDocument bdoc = (doc instanceof BaseDocument)
250
251
                ? (BaseDocument)doc
252
                : null;
253
        // Need to lock formatter first because CT's multiline text will be reformatted
251
        // Need to lock formatter first because CT's multiline text will be reformatted
254
        formatter = null;
252
        formatter = Reformat.get(doc);
255
        if (bdoc != null) {
253
        formatter.lock();
256
            formatter = bdoc.getFormatter();
257
            if (formatter != null) {
258
                formatter.reformatLock();
259
            }
260
        }
261
        try {
254
        try {
262
            if (bdoc != null) {
255
            if (doc instanceof BaseDocument) {
263
                bdoc.runAtomicAsUser(this);
256
                ((BaseDocument) doc).runAtomicAsUser(this);
264
            } else { // Otherwise run without atomic locking
257
            } else { // Otherwise run without atomic locking
265
                this.run();
258
                this.run();
266
            }
259
            }
267
        } finally {
260
        } finally {
268
            if (bdoc != null) {
261
            formatter.unlock();
269
                if (formatter != null) {
262
            formatter = null;
270
                    formatter.reformatUnlock();
271
                }
272
                formatter = null;
273
            }
274
            completeInsertString = null;
263
            completeInsertString = null;
275
        }
264
        }
276
    }
265
    }
Lines 344-351 Link Here
344
            this.inserted = true;
333
            this.inserted = true;
345
            
334
            
346
            if (bdoc != null) {
335
            if (bdoc != null) {
347
                formatter.reformat(bdoc, pos.getOffset(),
336
                formatter.reformat(pos.getOffset(), pos.getOffset() + completeInsertString.length());
348
                        pos.getOffset() + completeInsertString.length());
349
            }
337
            }
350
338
351
            if (!released) {
339
            if (!released) {
(-)a/editor.completion/nbproject/project.xml (-3 / +3 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.41</specification-version>
58
                        <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/editor.deprecated.pre61completion/nbproject/project.xml (-2 / +2 lines)
Lines 19-26 Link Here
19
                    <build-prerequisite/>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>2.1</specification-version>
23
                        <specification-version>3.1</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/editor.deprecated.pre61settings/nbproject/project.xml (-1 / +10 lines)
Lines 59-69 Link Here
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
62
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <release-version>0-1</release-version>
67
                        <specification-version>1.0</specification-version>
68
                    </run-dependency>
69
                </dependency>
70
                <dependency>
62
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
71
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
63
                    <build-prerequisite/>
72
                    <build-prerequisite/>
64
                    <compile-dependency/>
73
                    <compile-dependency/>
65
                    <run-dependency>
74
                    <run-dependency>
66
                        <release-version>2</release-version>
75
                        <release-version>3</release-version>
67
                        <implementation-version/>
76
                        <implementation-version/>
68
                    </run-dependency>
77
                    </run-dependency>
69
                </dependency>
78
                </dependency>
(-)a/editor.deprecated.pre65formatting/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="editor.deprecated.pre65formatting">
3
    <description>Builds, tests, and runs the project org.netbeans.modules.editor.deprecated.pre65formatting</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)a/editor.deprecated.pre65formatting/manifest.mf (+6 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.deprecated.pre65formatting/0
3
OpenIDE-Module-Implementation-Version: 1
4
OpenIDE-Module-Layer: org/netbeans/modules/editor/deprecated/pre65formatting/layer.xml
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/deprecated/pre65formatting/Bundle.properties
6
OpenIDE-Module-Deprecated: true
(-)a/editor.deprecated.pre65formatting/nbproject/project.properties (+4 lines)
Line 0 Link Here
1
is.autoload=true
2
javac.source=1.5
3
javac.compilerargs=-Xlint -Xlint:-serial
4
spec.version.base=1.0
(-)a/editor.deprecated.pre65formatting/nbproject/project.xml (+103 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.modules.editor</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
14
                        <implementation-version/>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
18
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
23
                        <specification-version>1.10</specification-version>
24
                    </run-dependency>
25
                </dependency>
26
                <dependency>
27
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
30
                    <run-dependency>
31
                        <release-version>3</release-version>
32
                        <implementation-version/>
33
                    </run-dependency>
34
                </dependency>
35
                <dependency>
36
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
39
                    <run-dependency>
40
                        <release-version>1</release-version>
41
                        <implementation-version/>
42
                    </run-dependency>
43
                </dependency>
44
                <dependency>
45
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
48
                    <run-dependency>
49
                        <release-version>1</release-version>
50
                        <specification-version>1.10</specification-version>
51
                    </run-dependency>
52
                </dependency>
53
                <dependency>
54
                    <code-name-base>org.netbeans.modules.editor.settings</code-name-base>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
57
                    <run-dependency>
58
                        <release-version>1</release-version>
59
                        <specification-version>1.22</specification-version>
60
                    </run-dependency>
61
                </dependency>
62
                <dependency>
63
                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
66
                    <run-dependency>
67
                        <release-version>1</release-version>
68
                        <specification-version>1.25</specification-version>
69
                    </run-dependency>
70
                </dependency>
71
                <dependency>
72
                    <code-name-base>org.openide.text</code-name-base>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
75
                    <run-dependency>
76
                        <specification-version>6.21</specification-version>
77
                    </run-dependency>
78
                </dependency>
79
                <dependency>
80
                    <code-name-base>org.openide.util</code-name-base>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
83
                    <run-dependency>
84
                        <specification-version>7.18</specification-version>
85
                    </run-dependency>
86
                </dependency>
87
                <dependency>
88
                    <code-name-base>org.openide.util.lookup</code-name-base>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
91
                    <run-dependency>
92
                        <specification-version>8.4</specification-version>
93
                    </run-dependency>
94
                </dependency>
95
            </module-dependencies>
96
            <public-packages>
97
                <package>org.netbeans.editor</package>
98
                <package>org.netbeans.editor.ext</package>
99
                <package>org.netbeans.modules.editor</package>
100
            </public-packages>
101
        </data>
102
    </configuration>
103
</project>
(-)a/editor.lib/src/org/netbeans/editor/Formatter.java (-48 / +29 lines)
Lines 48-57 Link Here
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.io.Writer;
49
import java.io.Writer;
50
import java.io.CharArrayWriter;
50
import java.io.CharArrayWriter;
51
import java.lang.ref.Reference;
52
import java.lang.ref.WeakReference;
51
import java.lang.ref.WeakReference;
53
import java.lang.reflect.Method;
52
import java.lang.reflect.Method;
54
import java.util.Stack;
55
import java.util.WeakHashMap;
53
import java.util.WeakHashMap;
56
import java.util.prefs.PreferenceChangeEvent;
54
import java.util.prefs.PreferenceChangeEvent;
57
import java.util.prefs.PreferenceChangeListener;
55
import java.util.prefs.PreferenceChangeListener;
Lines 64-69 Link Here
64
import org.netbeans.api.editor.settings.SimpleValueNames;
62
import org.netbeans.api.editor.settings.SimpleValueNames;
65
import org.netbeans.lib.editor.util.CharSequenceUtilities;
63
import org.netbeans.lib.editor.util.CharSequenceUtilities;
66
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
64
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
65
import org.netbeans.modules.editor.deprecated.pre65formatting.LegacyFormattersProvider;
67
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
66
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
68
import org.netbeans.modules.editor.lib.KitsTracker;
67
import org.netbeans.modules.editor.lib.KitsTracker;
69
import org.netbeans.modules.editor.lib.SettingsConversions;
68
import org.netbeans.modules.editor.lib.SettingsConversions;
Lines 106-112 Link Here
106
        } else {
105
        } else {
107
            Formatter formatter = kitClass2Formatter.get(kitClass);
106
            Formatter formatter = kitClass2Formatter.get(kitClass);
108
            if (formatter == null) {
107
            if (formatter == null) {
109
                formatter = BaseKit.getKit(kitClass).createFormatter();
108
                BaseKit kit = BaseKit.getKit(kitClass);
109
                formatter = callCreateFormatterMethod(kit);
110
                kitClass2Formatter.put(kitClass, formatter);
110
                kitClass2Formatter.put(kitClass, formatter);
111
            }
111
            }
112
            return formatter;
112
            return formatter;
Lines 130-138 Link Here
130
        if (formatter == null) {
130
        if (formatter == null) {
131
            EditorKit editorKit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
131
            EditorKit editorKit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
132
            if (editorKit instanceof BaseKit) {
132
            if (editorKit instanceof BaseKit) {
133
                formatter = ((BaseKit) editorKit).createFormatter();
133
                formatter = callCreateFormatterMethod((BaseKit) editorKit);
134
            } else {
134
            } else {
135
                formatter = BaseKit.getKit(BaseKit.class).createFormatter();
135
                formatter = callCreateFormatterMethod(BaseKit.getKit(BaseKit.class));
136
            }
136
            }
137
            mimePath2Formatter.put(mimePath, formatter);
137
            mimePath2Formatter.put(mimePath, formatter);
138
        }
138
        }
Lines 264-270 Link Here
264
     * @see BaseDocument.getTabSize()
264
     * @see BaseDocument.getTabSize()
265
     */
265
     */
266
    public int getTabSize() {
266
    public int getTabSize() {
267
        Document doc = getFormattingContextDocument();
267
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
268
        if (doc != null) {
268
        if (doc != null) {
269
            Object ret = callIndentUtils("tabSize", doc); //NOI18N
269
            Object ret = callIndentUtils("tabSize", doc); //NOI18N
270
            if (ret instanceof Integer) {
270
            if (ret instanceof Integer) {
Lines 300-306 Link Here
300
     * @see getSpacesPerTab()
300
     * @see getSpacesPerTab()
301
     */
301
     */
302
    public int getShiftWidth() {
302
    public int getShiftWidth() {
303
        Document doc = getFormattingContextDocument();
303
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
304
        if (doc != null) {
304
        if (doc != null) {
305
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
305
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
306
            if (ret instanceof Integer) {
306
            if (ret instanceof Integer) {
Lines 329-335 Link Here
329
329
330
    /** Should the typed tabs be expanded to the spaces? */
330
    /** Should the typed tabs be expanded to the spaces? */
331
    public boolean expandTabs() {
331
    public boolean expandTabs() {
332
        Document doc = getFormattingContextDocument();
332
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
333
        if (doc != null) {
333
        if (doc != null) {
334
            Object ret = callIndentUtils("isExpandTabs", doc); //NOI18N
334
            Object ret = callIndentUtils("isExpandTabs", doc); //NOI18N
335
            if (ret instanceof Boolean) {
335
            if (ret instanceof Boolean) {
Lines 353-359 Link Here
353
    * instead of one typed tab.
353
    * instead of one typed tab.
354
    */
354
    */
355
    public int getSpacesPerTab() {
355
    public int getSpacesPerTab() {
356
        Document doc = getFormattingContextDocument();
356
        Document doc = LegacyFormattersProvider.getFormattingContextDocument();
357
        if (doc != null) {
357
        if (doc != null) {
358
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
358
            Object ret = callIndentUtils("indentLevelSize", doc); //NOI18N
359
            if (ret instanceof Integer) {
359
            if (ret instanceof Integer) {
Lines 378-388 Link Here
378
    // ------------------------------------------------------------------------
378
    // ------------------------------------------------------------------------
379
379
380
    public String getIndentString(BaseDocument doc, int indent) {
380
    public String getIndentString(BaseDocument doc, int indent) {
381
        pushFormattingContextDocument(doc);
381
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
382
        try {
382
        try {
383
            return getIndentString(indent, expandTabs(), doc.getTabSize());
383
            return getIndentString(indent, expandTabs(), doc.getTabSize());
384
        } finally {
384
        } finally {
385
            popFormattingContextDocument(doc);
385
            LegacyFormattersProvider.popFormattingContextDocument(doc);
386
        }
386
        }
387
    }
387
    }
388
        
388
        
Lines 403-409 Link Here
403
     */
403
     */
404
    public void insertTabString (final BaseDocument doc, final int dotPos)
404
    public void insertTabString (final BaseDocument doc, final int dotPos)
405
    throws BadLocationException {
405
    throws BadLocationException {
406
        pushFormattingContextDocument(doc);
406
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
407
        try {
407
        try {
408
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
408
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
409
            doc.runAtomic (new Runnable () {
409
            doc.runAtomic (new Runnable () {
Lines 436-442 Link Here
436
            if (badLocationExceptions[0] != null)
436
            if (badLocationExceptions[0] != null)
437
                throw badLocationExceptions [0];
437
                throw badLocationExceptions [0];
438
        } finally {
438
        } finally {
439
            popFormattingContextDocument(doc);
439
            LegacyFormattersProvider.popFormattingContextDocument(doc);
440
        }
440
        }
441
    }
441
    }
442
442
Lines 445-451 Link Here
445
    */
445
    */
446
    public void changeRowIndent (final BaseDocument doc, final int pos, final int newIndent)
446
    public void changeRowIndent (final BaseDocument doc, final int pos, final int newIndent)
447
    throws BadLocationException {
447
    throws BadLocationException {
448
        pushFormattingContextDocument(doc);
448
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
449
        try {
449
        try {
450
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
450
            final BadLocationException[] badLocationExceptions = new BadLocationException [1];
451
            doc.runAtomic (new Runnable () {
451
            doc.runAtomic (new Runnable () {
Lines 484-490 Link Here
484
            if (badLocationExceptions[0] != null)
484
            if (badLocationExceptions[0] != null)
485
                throw badLocationExceptions [0];
485
                throw badLocationExceptions [0];
486
        } finally {
486
        } finally {
487
            popFormattingContextDocument(doc);
487
            LegacyFormattersProvider.popFormattingContextDocument(doc);
488
        }
488
        }
489
    }
489
    }
490
490
Lines 498-504 Link Here
498
    */
498
    */
499
    public void changeBlockIndent (final BaseDocument doc, final int startPos, final int endPos,
499
    public void changeBlockIndent (final BaseDocument doc, final int startPos, final int endPos,
500
                                  final int shiftCnt) throws BadLocationException {
500
                                  final int shiftCnt) throws BadLocationException {
501
        pushFormattingContextDocument(doc);
501
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
502
        try {
502
        try {
503
            GuardedDocument gdoc = (doc instanceof GuardedDocument)
503
            GuardedDocument gdoc = (doc instanceof GuardedDocument)
504
                                   ? (GuardedDocument)doc : null;
504
                                   ? (GuardedDocument)doc : null;
Lines 538-551 Link Here
538
            if (badLocationExceptions[0] != null)
538
            if (badLocationExceptions[0] != null)
539
                throw badLocationExceptions [0];
539
                throw badLocationExceptions [0];
540
        } finally {
540
        } finally {
541
            popFormattingContextDocument(doc);
541
            LegacyFormattersProvider.popFormattingContextDocument(doc);
542
        }
542
        }
543
    }
543
    }
544
544
545
    /** Shift line either left or right */
545
    /** Shift line either left or right */
546
    public void shiftLine(BaseDocument doc, int dotPos, boolean right)
546
    public void shiftLine(BaseDocument doc, int dotPos, boolean right)
547
    throws BadLocationException {
547
    throws BadLocationException {
548
        pushFormattingContextDocument(doc);
548
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
549
        try {
549
        try {
550
            int ind = doc.getShiftWidth();
550
            int ind = doc.getShiftWidth();
551
            if (!right) {
551
            if (!right) {
Lines 560-566 Link Here
560
            ind = Math.max(ind, 0);
560
            ind = Math.max(ind, 0);
561
            changeRowIndent(doc, dotPos, ind);
561
            changeRowIndent(doc, dotPos, ind);
562
        } finally {
562
        } finally {
563
            popFormattingContextDocument(doc);
563
            LegacyFormattersProvider.popFormattingContextDocument(doc);
564
        }
564
        }
565
    }
565
    }
566
566
Lines 572-578 Link Here
572
    */
572
    */
573
    public int reformat(BaseDocument doc, int startOffset, int endOffset)
573
    public int reformat(BaseDocument doc, int startOffset, int endOffset)
574
    throws BadLocationException {
574
    throws BadLocationException {
575
        pushFormattingContextDocument(doc);
575
        LegacyFormattersProvider.pushFormattingContextDocument(doc);
576
        try {
576
        try {
577
            try {
577
            try {
578
                CharArrayWriter cw = new CharArrayWriter();
578
                CharArrayWriter cw = new CharArrayWriter();
Lines 594-600 Link Here
594
                return 0;
594
                return 0;
595
            }
595
            }
596
        } finally {
596
        } finally {
597
            popFormattingContextDocument(doc);
597
            LegacyFormattersProvider.popFormattingContextDocument(doc);
598
        }
598
        }
599
    }
599
    }
600
600
Lines 772-804 Link Here
772
    // private implementation
772
    // private implementation
773
    // ------------------------------------------------------------------------
773
    // ------------------------------------------------------------------------
774
774
775
    private static ThreadLocal<Stack<Reference<Document>>> FORMATTING_CONTEXT_DOCUMENT = new ThreadLocal<Stack<Reference<Document>>>() {
776
        @Override
777
        protected Stack<Reference<Document>> initialValue() {
778
            return new Stack<Reference<Document>>();
779
        }
780
    };
781
782
    private static Document getFormattingContextDocument() {
783
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
784
        return stack.isEmpty() ? null : stack.peek().get();
785
    }
786
787
    /* package */ static void pushFormattingContextDocument(Document doc) {
788
        FORMATTING_CONTEXT_DOCUMENT.get().push(new WeakReference<Document>(doc));
789
    }
790
791
    /* package */ static void popFormattingContextDocument(Document doc) {
792
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
793
        assert !stack.empty() : "Calling popFormattingContextDocument without pushFormattingContextDocument"; //NOI18N
794
795
        Reference<Document> ref = stack.pop();
796
        Document docFromStack = ref.get();
797
        assert docFromStack == doc : "Popping " + doc + ", but the stack contains " + docFromStack;
798
799
        ref.clear();
800
    }
801
802
    private static boolean noIndentUtils = false;
775
    private static boolean noIndentUtils = false;
803
    private static WeakReference<Class> indentUtilsClassRef = null;
776
    private static WeakReference<Class> indentUtilsClassRef = null;
804
    private static Object callIndentUtils(String methodName, Document doc) {
777
    private static Object callIndentUtils(String methodName, Document doc) {
Lines 861-864 Link Here
861
        }
834
        }
862
    }
835
    }
863
836
837
    private static Formatter callCreateFormatterMethod(BaseKit kit) {
838
        try {
839
            Method m = kit.getClass().getMethod("createFormatter"); //NOI18N
840
            return (Formatter) m.invoke(kit);
841
        } catch (Exception e) {
842
            return new Formatter(kit.getClass());
843
        }
844
    }
864
}
845
}
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/Bundle.properties (+38 lines)
Line 0 Link Here
1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
#
3
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4
#
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License.  When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
22
#
23
# If you wish your version of this file to be governed by only the CDDL
24
# or only the GPL Version 2, indicate your decision by adding
25
# "[Contributor] elects to include this software in this distribution
26
# under the [CDDL or GPL Version 2] license." If you do not indicate a
27
# single choice of license, a recipient has the option to distribute
28
# your version of this file under either the CDDL, the GPL Version 2 or
29
# to extend the choice of license to its licensees as provided above.
30
# However, if you add GPL Version 2 code and therefore, elected the GPL
31
# Version 2 license, then the option applies only if the new code is
32
# made subject to such option by the copyright holder.
33
#
34
# Contributor(s):
35
#
36
# Portions Copyrighted 2008 Sun Microsystems, Inc.
37
38
MSG_NegativeValue=Negative value is not allowed
(-)a/editor/src/org/netbeans/modules/editor/FormatterIndentEngine.java (-2 / +13 lines)
Lines 44-55 Link Here
44
44
45
package org.netbeans.modules.editor;
45
package org.netbeans.modules.editor;
46
46
47
import java.awt.Toolkit;
47
import java.io.*;
48
import java.io.*;
48
import javax.swing.text.Document;
49
import javax.swing.text.Document;
49
import org.netbeans.api.editor.settings.SimpleValueNames;
50
import org.netbeans.api.editor.settings.SimpleValueNames;
50
import org.netbeans.editor.BaseKit;
51
import org.netbeans.editor.BaseKit;
51
import org.netbeans.editor.ext.ExtFormatter;
52
import org.netbeans.editor.ext.ExtFormatter;
53
import org.openide.ErrorManager;
52
import org.openide.text.IndentEngine;
54
import org.openide.text.IndentEngine;
55
import org.openide.util.Lookup;
56
import org.openide.util.NbBundle;
53
57
54
/**
58
/**
55
 * Indent engine that delegates to formatter
59
 * Indent engine that delegates to formatter
Lines 168-175 Link Here
168
172
169
    public void setSpacesPerTab(int spacesPerTab) {
173
    public void setSpacesPerTab(int spacesPerTab) {
170
        if (spacesPerTab <= 0) {
174
        if (spacesPerTab <= 0) {
171
            NbEditorUtilities.invalidArgument("MSG_NegativeValue"); // NOI18N
175
            IllegalArgumentException iae = new IllegalArgumentException("Invalid argument"); //NOI18N
172
            return; // value unchanged
176
            ErrorManager errMan = Lookup.getDefault().lookup(ErrorManager.class);
177
178
            if (errMan != null) {
179
                Toolkit.getDefaultToolkit().beep();
180
                errMan.annotate(iae, ErrorManager.USER, iae.getMessage(), NbBundle.getMessage(FormatterIndentEngine.class, "MSG_NegativeValue"), null, null); //NOI18N
181
            } else {
182
                throw iae;
183
            }
173
        }
184
        }
174
185
175
        int old = getFormatter().getSpacesPerTab();
186
        int old = getFormatter().getSpacesPerTab();
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/Bundle.properties (+2 lines)
Line 0 Link Here
1
OpenIDE-Module-Display-Category=Editing
2
OpenIDE-Module-Name=Editor Formatting Prior 6.5 Separation
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/ComplexValueSettingsFactory.java (+85 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.editor.deprecated.pre65formatting;
44
45
import javax.swing.text.EditorKit;
46
import org.netbeans.api.editor.mimelookup.MimeLookup;
47
import org.netbeans.api.editor.mimelookup.MimePath;
48
import org.netbeans.modules.editor.FormatterIndentEngine;
49
import org.netbeans.modules.editor.IndentEngineFormatter;
50
import org.netbeans.modules.editor.NbEditorDocument;
51
import org.openide.text.IndentEngine;
52
53
/**
54
 *
55
 * @author vita
56
 */
57
public final class ComplexValueSettingsFactory {
58
59
    private ComplexValueSettingsFactory() {
60
        // no-op
61
    }
62
    
63
    // -----------------------------------------------------------------------
64
    // 'formatter' setting
65
    // -----------------------------------------------------------------------
66
67
    public static Object getFormatterValue(MimePath mimePath, String settingName) {
68
        assert settingName.equals(NbEditorDocument.FORMATTER) : "The getFormatter factory called for '" + settingName + "'"; //NOI18N
69
70
        IndentEngine eng = org.netbeans.modules.editor.impl.ComplexValueSettingsFactory.getIndentEngine(mimePath);
71
72
        if (eng != null) {
73
            if (eng instanceof FormatterIndentEngine) {
74
                return ((FormatterIndentEngine)eng).getFormatter();
75
            } else {
76
                EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
77
                if (kit != null) {
78
                    return new IndentEngineFormatter(kit.getClass(), eng);
79
                }
80
            }
81
        }
82
        
83
        return null;
84
    }
85
}
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/LegacyFormattersProvider.java (+379 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.deprecated.pre65formatting;
41
42
import java.io.IOException;
43
import java.lang.ref.Reference;
44
import java.lang.ref.WeakReference;
45
import java.lang.reflect.Method;
46
import java.util.Map;
47
import java.util.Stack;
48
import java.util.WeakHashMap;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
import javax.swing.text.BadLocationException;
52
import javax.swing.text.Document;
53
import javax.swing.text.EditorKit;
54
import javax.swing.text.Element;
55
import javax.swing.text.Position;
56
import javax.swing.text.StyledDocument;
57
import org.netbeans.api.editor.mimelookup.MimeLookup;
58
import org.netbeans.api.editor.mimelookup.MimePath;
59
import org.netbeans.editor.BaseDocument;
60
import org.netbeans.editor.Formatter;
61
import org.netbeans.editor.Utilities;
62
import org.netbeans.editor.ext.ExtFormatter;
63
import org.netbeans.modules.editor.indent.spi.Context;
64
import org.netbeans.modules.editor.indent.spi.ExtraLock;
65
import org.netbeans.modules.editor.indent.spi.IndentTask;
66
import org.netbeans.modules.editor.indent.spi.ReformatTask;
67
import org.netbeans.modules.editor.lib.KitsTracker;
68
import org.netbeans.spi.editor.mimelookup.MimeDataProvider;
69
import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor;
70
import org.openide.util.Lookup;
71
import org.openide.util.lookup.Lookups;
72
73
/**
74
 *
75
 * @author vita
76
 */
77
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.editor.mimelookup.MimeDataProvider.class)
78
public final class LegacyFormattersProvider implements MimeDataProvider {
79
80
    public LegacyFormattersProvider() {
81
        // no-op
82
    }
83
84
    // ------------------------------------------------------------------------
85
    // MimeDataProvider implementation
86
    // ------------------------------------------------------------------------
87
88
    public Lookup getLookup(MimePath mimePath) {
89
        if (mimePath.size() == 1) {
90
            IndentReformatTaskFactoriesProvider provider = IndentReformatTaskFactoriesProvider.get(mimePath);
91
            if (provider != null) {
92
                IndentTask.Factory legacyIndenter = provider.getIndentTaskFactory();
93
                ReformatTask.Factory legacyFormatter = provider.getReformatTaskFactory();
94
                TypedTextInterceptor.Factory legacyAutoIndenter = provider.getTypedTextInterceptorFactory();
95
96
                if (LOG.isLoggable(Level.FINE)) {
97
                    LOG.fine("'" + mimePath.getPath() + "' uses legacyIndenter=" + legacyIndenter //NOI18N
98
                            + ", legacyFormatter=" + legacyFormatter //NOI18N
99
                            + ", legacyAutoIndenter=" + legacyAutoIndenter); //NOI18N
100
                }
101
102
                return Lookups.fixed(legacyIndenter, legacyFormatter, legacyAutoIndenter);
103
            }
104
        }
105
106
        return null;
107
    }
108
109
    // ------------------------------------------------------------------------
110
    // Formatting context manipulation methods
111
    // ------------------------------------------------------------------------
112
113
    public static Document getFormattingContextDocument() {
114
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
115
        return stack.isEmpty() ? null : stack.peek().get();
116
    }
117
118
    public static void pushFormattingContextDocument(Document doc) {
119
        FORMATTING_CONTEXT_DOCUMENT.get().push(new WeakReference<Document>(doc));
120
    }
121
122
    public static void popFormattingContextDocument(Document doc) {
123
        Stack<Reference<Document>> stack = FORMATTING_CONTEXT_DOCUMENT.get();
124
        assert !stack.empty() : "Calling popFormattingContextDocument without pushFormattingContextDocument"; //NOI18N
125
126
        Reference<Document> ref = stack.pop();
127
        Document docFromStack = ref.get();
128
        assert docFromStack == doc : "Popping " + doc + ", but the stack contains " + docFromStack;
129
130
        ref.clear();
131
    }
132
133
    // ------------------------------------------------------------------------
134
    // Private implementation
135
    // ------------------------------------------------------------------------
136
137
    private static final Logger LOG = Logger.getLogger(LegacyFormattersProvider.class.getName());
138
    
139
    private static ThreadLocal<Stack<Reference<Document>>> FORMATTING_CONTEXT_DOCUMENT = new ThreadLocal<Stack<Reference<Document>>>() {
140
        @Override
141
        protected Stack<Reference<Document>> initialValue() {
142
            return new Stack<Reference<Document>>();
143
        }
144
    };
145
146
    private static final class IndentReformatTaskFactoriesProvider {
147
148
        public static IndentReformatTaskFactoriesProvider get(MimePath mimePath) {
149
            Reference<IndentReformatTaskFactoriesProvider> ref = cache.get(mimePath);
150
            IndentReformatTaskFactoriesProvider provider = ref == null ? null : ref.get();
151
            if (provider == null) {
152
                try {
153
                    Class kitClass = KitsTracker.getInstance().findKitClass(mimePath.getPath());
154
                    Method createFormatterMethod = kitClass.getDeclaredMethod("createFormatter"); //NOI18N
155
                    provider = new IndentReformatTaskFactoriesProvider(mimePath);
156
                    cache.put(mimePath, new WeakReference<IndentReformatTaskFactoriesProvider>(provider));
157
                } catch (Exception e) {
158
                    // ignore
159
                }
160
            }
161
            return provider;
162
        }
163
164
        public IndentTask.Factory getIndentTaskFactory() {
165
            if (indentTaskFactory == null) {
166
                indentTaskFactory = new IndentTask.Factory() {
167
                    public IndentTask createTask(Context context) {
168
                        Formatter formatter = getFormatter();
169
                        if (formatter != null && context.document() instanceof BaseDocument) {
170
                            return new Indenter(context, formatter);
171
                        } else {
172
                            return null;
173
                        }
174
                    }
175
                };
176
            }
177
            return indentTaskFactory;
178
        }
179
180
        public ReformatTask.Factory getReformatTaskFactory() {
181
            if (reformatTaskFactory == null) {
182
                reformatTaskFactory = new ReformatTask.Factory() {
183
                    public ReformatTask createTask(Context context) {
184
                        Formatter formatter = getFormatter();
185
                        if (formatter != null && context.document() instanceof BaseDocument) {
186
                            return new Reformatter(context, formatter);
187
                        } else {
188
                            return null;
189
                        }
190
                    }
191
                };
192
            }
193
            return reformatTaskFactory;
194
        }
195
196
        public TypedTextInterceptor.Factory getTypedTextInterceptorFactory() {
197
            if (typedTextInterceptorFactory == null) {
198
                typedTextInterceptorFactory = new TypedTextInterceptor.Factory() {
199
                    public TypedTextInterceptor createTypedTextInterceptor(MimePath mimePath) {
200
                        Formatter formatter = getFormatter();
201
                        if (formatter instanceof ExtFormatter) {
202
                            return new AutoIndenter((ExtFormatter)formatter);
203
                        } else {
204
                            return null;
205
                        }
206
                    }
207
                };
208
            }
209
            return typedTextInterceptorFactory;
210
        }
211
212
        // -------------------------------------------------------------------
213
        // private implementation
214
        // -------------------------------------------------------------------
215
216
        private static final Map<MimePath, Reference<IndentReformatTaskFactoriesProvider>> cache = new WeakHashMap<MimePath, Reference<IndentReformatTaskFactoriesProvider>>();
217
        private static final String NO_FORMATTER = new String("NO_FORMATTER"); //NOI18N
218
219
        private final MimePath mimePath;
220
221
        private IndentTask.Factory indentTaskFactory;
222
        private ReformatTask.Factory reformatTaskFactory;
223
        private TypedTextInterceptor.Factory typedTextInterceptorFactory;
224
        private Object legacyFormatter;
225
226
        private IndentReformatTaskFactoriesProvider(MimePath mimePath) {
227
            this.mimePath = mimePath;
228
        }
229
230
        private Formatter getFormatter() {
231
            if (legacyFormatter == null) {
232
                EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
233
                if (kit != null) {
234
                    try {
235
                        Method createFormatterMethod = kit.getClass().getDeclaredMethod("createFormatter"); //NOI18N
236
                        legacyFormatter = createFormatterMethod.invoke(kit);
237
                    } catch (Exception e) {
238
                        legacyFormatter = e;
239
                    }
240
                } else {
241
                    legacyFormatter = NO_FORMATTER;
242
                }
243
            }
244
            return legacyFormatter instanceof Formatter ? (Formatter) legacyFormatter : null;
245
        }
246
247
    } // End of IndentReformatTaskFactoriesProvider class
248
249
    private static final class Indenter implements IndentTask {
250
251
        private final Context context;
252
        private final Formatter formatter;
253
254
        public Indenter(Context context, Formatter formatter) {
255
            this.context = context;
256
            this.formatter = formatter;
257
        }
258
259
        public void reindent() throws BadLocationException {
260
            Document doc = context.document();
261
            int startOffset = context.startOffset();
262
            int endOffset = context.endOffset();
263
            
264
            pushFormattingContextDocument(doc);
265
            try {
266
                // Original formatter does not have reindentation of multiple lines
267
                // so reformat start line and continue for each line.
268
                Element lineRootElem = lineRootElement(doc);
269
                Position endPos = doc.createPosition(endOffset);
270
                do {
271
                    startOffset = formatter.indentLine(doc, startOffset);
272
                    int startLineIndex = lineRootElem.getElementIndex(startOffset) + 1;
273
                    if (startLineIndex >= lineRootElem.getElementCount())
274
                        break;
275
                    Element lineElem = lineRootElem.getElement(startLineIndex);
276
                    startOffset = lineElem.getStartOffset(); // Move to next line
277
                } while (startOffset < endPos.getOffset());
278
            } finally {
279
                popFormattingContextDocument(doc);
280
            }
281
        }
282
283
        public ExtraLock indentLock() {
284
            return new ExtraLock() {
285
                public void lock() {
286
                    formatter.indentLock();
287
                }
288
289
                public void unlock() {
290
                    formatter.indentUnlock();
291
                }
292
            };
293
        }
294
295
        private static Element lineRootElement(Document doc) {
296
            return (doc instanceof StyledDocument)
297
                ? ((StyledDocument)doc).getParagraphElement(0).getParentElement()
298
                : doc.getDefaultRootElement();
299
        }
300
    } // End of Indenter class
301
302
    private static final class Reformatter implements ReformatTask {
303
304
        private final Context context;
305
        private final Formatter formatter;
306
307
        public Reformatter(Context context, Formatter formatter) {
308
            this.context = context;
309
            this.formatter = formatter;
310
        }
311
312
        public void reformat() throws BadLocationException {
313
            pushFormattingContextDocument(context.document());
314
            try {
315
                formatter.reformat((BaseDocument) context.document(), context.startOffset(), context.endOffset());
316
            } finally {
317
                popFormattingContextDocument(context.document());
318
            }
319
        }
320
321
        public ExtraLock reformatLock() {
322
            return new ExtraLock() {
323
                public void lock() {
324
                    formatter.reformatLock();
325
                }
326
327
                public void unlock() {
328
                    formatter.reformatUnlock();
329
                }
330
            };
331
        }
332
    } // End of Reformatter class
333
334
    private static final class AutoIndenter implements TypedTextInterceptor {
335
336
        private final ExtFormatter formatter;
337
338
        public AutoIndenter(ExtFormatter formatter) {
339
            this.formatter = formatter;
340
        }
341
342
        public boolean beforeInsert(Context context) throws BadLocationException {
343
            // no-op
344
            return false;
345
        }
346
347
        public void insert(MutableContext context) throws BadLocationException {
348
            // no-op
349
        }
350
351
        public void afterInsert(Context context) throws BadLocationException {
352
            if (context.getDocument() instanceof BaseDocument) {
353
                BaseDocument doc = (BaseDocument) context.getDocument();
354
                int [] fmtBlk = formatter.getReformatBlock(context.getComponent(), context.getText());
355
                if (fmtBlk != null) {
356
                    try {
357
358
                        fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]);
359
                        fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]);
360
361
                        //this was the of #18922, that causes the bug #20198
362
                        //ef.reformat(doc, fmtBlk[0], fmtBlk[1]);
363
364
                        //bugfix of the bug #20198. Bug #18922 is fixed too as well as #6968
365
                        formatter.reformat(doc, fmtBlk[0], fmtBlk[1], true);
366
367
                    } catch (BadLocationException e) {
368
                    } catch (IOException e) {
369
                    }
370
                }
371
            }
372
        }
373
374
        public void cancelled(Context context) {
375
            // no-op
376
        }
377
378
    } // End of AutoIndenter class
379
}
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/layer.xml (+55 lines)
Line 0 Link Here
1
<?xml version="1.0"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.0//EN" "http://www.netbeans.org/dtds/filesystem-1_0.dtd">
47
<filesystem>
48
    <folder name="Editors">
49
        <folder name="Preferences">
50
            <folder name="Defaults">
51
                <file name="org-netbeans-modules-editor-deprecated-pre65formatting-preferences.xml" url="preferences.xml"/>
52
            </folder>
53
        </folder>
54
    </folder>
55
</filesystem>
(-)a/editor.deprecated.pre65formatting/src/org/netbeans/modules/editor/deprecated/pre65formatting/preferences.xml (+52 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
11
The contents of this file are subject to the terms of either the GNU
12
General Public License Version 2 only ("GPL") or the Common
13
Development and Distribution License("CDDL") (collectively, the
14
"License"). You may not use this file except in compliance with the
15
License. You can obtain a copy of the License at
16
http://www.netbeans.org/cddl-gplv2.html
17
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
specific language governing permissions and limitations under the
19
License.  When distributing the software, include this License Header
20
Notice in each file and include the License file at
21
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
particular file as subject to the "Classpath" exception as provided
23
by Oracle in the GPL Version 2 section of the License file that
24
accompanied this code. If applicable, add the following below the
25
License Header, with the fields enclosed by brackets [] replaced by
26
your own identifying information:
27
"Portions Copyrighted [year] [name of copyright owner]"
28
29
Contributor(s):
30
31
The Original Software is NetBeans. The Initial Developer of the Original
32
Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
33
Microsystems, Inc. All Rights Reserved.
34
35
If you wish your version of this file to be governed by only the CDDL
36
or only the GPL Version 2, indicate your decision by adding
37
"[Contributor] elects to include this software in this distribution
38
under the [CDDL or GPL Version 2] license." If you do not indicate a
39
single choice of license, a recipient has the option to distribute
40
your version of this file under either the CDDL, the GPL Version 2 or
41
to extend the choice of license to its licensees as provided above.
42
However, if you add GPL Version 2 code and therefore, elected the GPL
43
Version 2 license, then the option applies only if the new code is
44
made subject to such option by the copyright holder.
45
-->
46
<!DOCTYPE editor-preferences PUBLIC "-//NetBeans//DTD Editor Preferences 1.0//EN" "http://www.netbeans.org/dtds/EditorPreferences-1_0.dtd">
47
48
<editor-preferences>
49
    <entry category="deprecated" javaType="methodvalue" name="formatter" xml:space="preserve">
50
        <value><![CDATA[org.netbeans.modules.editor.deprecated.pre65formatting.ComplexValueSettingsFactory.getFormatterValue]]></value>
51
    </entry>
52
</editor-preferences>
(-)a/editor.errorstripe/nbproject/project.xml (-2 / +2 lines)
Lines 71-78 Link Here
71
                    <build-prerequisite/>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <release-version>2</release-version>
74
                        <release-version>3</release-version>
75
                        <specification-version>2.1</specification-version>
75
                        <specification-version>3.1</specification-version>
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
(-)a/editor.highlights/nbproject/project.xml (-2 / +11 lines)
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>1</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.27</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
Lines 115-120 Link Here
115
                        <specification-version>1.0</specification-version>
115
                        <specification-version>1.0</specification-version>
116
                    </run-dependency>
116
                    </run-dependency>
117
                </dependency>
117
                </dependency>
118
            <dependency>
119
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
120
                    <build-prerequisite/>
121
                    <compile-dependency/>
122
                    <run-dependency>
123
                        <release-version>0-1</release-version>
124
                        <specification-version>1.0</specification-version>
125
                    </run-dependency>
126
                </dependency>
118
            </module-dependencies>
127
            </module-dependencies>
119
            <test-dependencies>
128
            <test-dependencies>
120
                <test-type>
129
                <test-type>
(-)a/editor.indent/apichanges.xml (+30 lines)
Lines 108-113 Link Here
108
108
109
    <changes>
109
    <changes>
110
110
111
        <change id="AutomatedIndentation.added">
112
            <summary>Adding org.netbeans.modules.editor.indent.spi.support.AutomatedIndenting</summary>
113
            <version major="1" minor="20"/>
114
            <date day="23" month="10" year="2008"/>
115
            <author login="vstejskal"/>
116
            <compatibility source="compatible" binary="compatible" deletion="no" addition="yes" modification="no"/>
117
            <description>
118
                The <code>AutomatedIndenting</code> support class provides regex-based
119
                automatic re-indentation of lines as user types. This is a replacement for
120
                the deprecated <code>ExtFormatter.getReformatBlock</code> and <code>INDENT_HOT_CHARS_ACCEPTOR</code>
121
                setting.
122
            </description>
123
            <class package="org.netbeans.modules.editor.indent.spi.support" name="AutomatedIndenting"/>
124
            <issue number="120357"/>
125
        </change>
126
127
        <change id="Indent.indentNewLine.added">
128
            <summary>Adding org.netbeans.modules.editor.indent.api.Indent.indentNewLine</summary>
129
            <version major="1" minor="19"/>
130
            <date day="15" month="10" year="2008"/>
131
            <author login="vstejskal"/>
132
            <compatibility source="compatible" binary="compatible" deletion="no" addition="yes" modification="no"/>
133
            <description>
134
                The new method <code>int Indent.indentNewLine(int)</code> was added as
135
                a replacement for the old <code>int Formatter.indentNewLine(BaseDocument, int)</code>.
136
            </description>
137
            <class package="org.netbeans.modules.editor.indent.api" name="Indent"/>
138
            <issue number="120357"/>
139
        </change>
140
111
        <change id="CodeStylePreferences.Provider">
141
        <change id="CodeStylePreferences.Provider">
112
            <summary>Adding CodeStylePreferences.Provider</summary>
142
            <summary>Adding CodeStylePreferences.Provider</summary>
113
            <version major="1" minor="18"/>
143
            <version major="1" minor="18"/>
(-)a/editor.indent/manifest.mf (+1 lines)
Lines 4-6 Link Here
4
OpenIDE-Module-Layer: org/netbeans/modules/editor/indent/resources/layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/editor/indent/resources/layer.xml
5
AutoUpdate-Show-In-Client: false
5
AutoUpdate-Show-In-Client: false
6
OpenIDE-Module-Recommends: org.netbeans.modules.editor.indent.spi.CodeStylePreferences.Provider
6
OpenIDE-Module-Recommends: org.netbeans.modules.editor.indent.spi.CodeStylePreferences.Provider
7
OpenIDE-Module-Specification-Version: 1.20.0
(-)a/editor.indent/nbproject/project.properties (-1 lines)
Lines 42-48 Link Here
42
42
43
javac.source=1.6
43
javac.source=1.6
44
javac.compilerargs=-Xlint:unchecked
44
javac.compilerargs=-Xlint:unchecked
45
spec.version.base=1.20.0
46
45
47
javadoc.arch=${basedir}/arch.xml
46
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
47
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.indent/nbproject/project.xml (-3 / +4 lines)
Lines 50-61 Link Here
50
            <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
50
            <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
53
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>1</release-version>
58
                        <implementation-version/>
58
                        <specification-version>1.31</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
Lines 176-181 Link Here
176
            <public-packages>
176
            <public-packages>
177
                <package>org.netbeans.modules.editor.indent.api</package>
177
                <package>org.netbeans.modules.editor.indent.api</package>
178
                <package>org.netbeans.modules.editor.indent.spi</package>
178
                <package>org.netbeans.modules.editor.indent.spi</package>
179
                <package>org.netbeans.modules.editor.indent.spi.support</package>
179
            </public-packages>
180
            </public-packages>
180
        </data>
181
        </data>
181
    </configuration>
182
    </configuration>
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/FormatterImpl.java (-218 lines)
Lines 1-218 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.editor.indent;
46
47
import java.io.IOException;
48
import java.io.Writer;
49
import java.lang.reflect.Method;
50
import javax.swing.text.BadLocationException;
51
import javax.swing.text.Document;
52
import javax.swing.text.JTextComponent;
53
import org.netbeans.editor.BaseDocument;
54
import org.netbeans.editor.Formatter;
55
import org.netbeans.editor.GuardedException;
56
import org.netbeans.editor.ext.ExtFormatter;
57
import org.netbeans.modules.editor.indent.api.IndentUtils;
58
59
/**
60
 * Indentation and code reformatting services for a swing text document.
61
 *
62
 * @author Miloslav Metelka
63
 */
64
public final class FormatterImpl extends ExtFormatter {
65
    
66
    private final Document doc;
67
    private final Formatter defaultFormatter;
68
    private final IndentImpl indentImpl;
69
    
70
    private final boolean tabSizeOverriden;
71
    private final boolean shiftWidthOverriden;
72
    private final boolean expandTabsOverriden;
73
    
74
    FormatterImpl(Formatter defaultFormatter, Document doc) {
75
        super(defaultFormatter.getKitClass());
76
        
77
        this.defaultFormatter = defaultFormatter;
78
        this.tabSizeOverriden = isOverriden(defaultFormatter.getClass(), "getTabSize"); //NOI18N
79
        this.shiftWidthOverriden = isOverriden(defaultFormatter.getClass(), "getShiftWidth"); //NOI18N
80
        this.expandTabsOverriden = isOverriden(defaultFormatter.getClass(), "expandTabs"); //NOI18N
81
82
        this.doc = doc;
83
        assert doc != null;
84
        
85
        this.indentImpl = IndentImpl.get(doc);
86
        indentImpl.setDefaultFormatter(defaultFormatter);
87
    }
88
    
89
    @Override
90
    public int[] getReformatBlock(JTextComponent target, String typedText) {
91
        return (defaultFormatter instanceof ExtFormatter)
92
                ? ((ExtFormatter)defaultFormatter).getReformatBlock(target, typedText)
93
                : null;
94
    }
95
    
96
    @Override
97
    public void indentLock() {
98
        indentImpl.indentLock();
99
    }
100
    
101
    @Override
102
    public void indentUnlock() {
103
        indentImpl.indentUnlock();
104
    }
105
    
106
    @Override
107
    public void reformatLock() {
108
        indentImpl.reformatLock();
109
    }
110
    
111
    @Override
112
    public void reformatUnlock() {
113
        indentImpl.reformatUnlock();
114
    }
115
116
    @Override
117
    public int getTabSize() {
118
        if (tabSizeOverriden) {
119
            return defaultFormatter.getTabSize();
120
        } else {
121
            return IndentUtils.tabSize(doc);
122
        }
123
    }
124
125
    @Override
126
    public int getSpacesPerTab() {
127
        return defaultFormatter.getSpacesPerTab();
128
    }
129
130
    @Override
131
    public int getShiftWidth() {
132
        if (shiftWidthOverriden) {
133
            return defaultFormatter.getShiftWidth();
134
        } else {
135
            return IndentUtils.indentLevelSize(doc);
136
        }
137
    }
138
139
    @Override
140
    public boolean expandTabs() {
141
        if (expandTabsOverriden) {
142
            return defaultFormatter.expandTabs();
143
        } else {
144
            return IndentUtils.isExpandTabs(doc);
145
        }
146
    }
147
148
    @Override
149
    public int indentLine(Document doc, int offset) {
150
        return indentLine(doc, offset, false);
151
    }
152
153
    /** Inserts new line at given position and indents the new line with
154
    * spaces.
155
    *
156
    * @param doc the document to work on
157
    * @param offset the offset of a character on the line
158
    * @return new offset to place cursor to
159
    */
160
    @Override
161
    public int indentNewLine(Document doc, int offset) {
162
        return indentLine(doc, offset, true);
163
    }
164
165
    private int indentLine(Document doc, int offset, boolean indentNewLine) {
166
        try {
167
            return indentImpl.reindent(offset, offset, offset, indentNewLine);
168
        } catch (GuardedException e) {
169
            java.awt.Toolkit.getDefaultToolkit().beep();
170
        } catch (BadLocationException e) {
171
            throw new IllegalStateException(e);
172
        }
173
        return offset;
174
    }
175
176
    @Override
177
    public Writer reformat(BaseDocument doc, int startOffset, int endOffset,
178
    boolean indentOnly) throws BadLocationException, IOException {
179
        // TBD delegate somehow
180
        return (defaultFormatter instanceof ExtFormatter)
181
                ? ((ExtFormatter)defaultFormatter).reformat(doc, startOffset, endOffset, indentOnly)
182
                : null;
183
    }
184
    
185
    @Override
186
    public int reformat(BaseDocument doc, int startOffset, int endOffset)
187
    throws BadLocationException {
188
        if (doc != indentImpl.document())
189
            return endOffset - startOffset; // should not happen in reality
190
        indentImpl.reformat(startOffset, endOffset);
191
        TaskHandler handler = indentImpl.reformatHandler();
192
        return (handler != null && handler.hasItems())
193
                ? Math.max(handler.endPos().getOffset() - startOffset, 0)
194
                : endOffset - startOffset;
195
    }
196
197
    @Override
198
    public Writer createWriter(Document doc, int offset, Writer writer) {
199
        if (doc != indentImpl.document()) {
200
            throw new IllegalStateException("Unexpected document doc=" + doc); //NOI18N
201
        }
202
        return new FormatterWriterImpl(indentImpl, offset, writer);
203
    }
204
205
    private static boolean isOverriden(Class clazz, String methodName) {
206
        while (clazz != Formatter.class && clazz != ExtFormatter.class) {
207
            for(Method m : clazz.getDeclaredMethods()) {
208
                if (m.getName().equals(methodName) && m.getParameterTypes().length == 0) {
209
                    return true;
210
                }
211
            }
212
213
            clazz = clazz.getSuperclass();
214
        }
215
216
        return false;
217
    }
218
}
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/FormatterOverrideImpl.java (-64 lines)
Lines 1-64 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.editor.indent;
46
47
import javax.swing.text.Document;
48
import org.netbeans.editor.Formatter;
49
import org.netbeans.modules.editor.lib.FormatterOverride;
50
51
/**
52
 * Indentation and code reformatting services for a swing text document.
53
 *
54
 * @author Miloslav Metelka
55
 */
56
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.modules.editor.lib.FormatterOverride.class)
57
public final class FormatterOverrideImpl implements FormatterOverride {
58
59
    public Formatter getFormatter(Document doc, Formatter defaultFormatter) {
60
        // Always override and possibly delegate to default formatter
61
        return new FormatterImpl(defaultFormatter, doc);
62
    }
63
64
}
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/IndentImpl.java (-58 / +65 lines)
Lines 49-60 Link Here
49
import javax.swing.text.BadLocationException;
49
import javax.swing.text.BadLocationException;
50
import javax.swing.text.Document;
50
import javax.swing.text.Document;
51
import javax.swing.text.Element;
51
import javax.swing.text.Element;
52
import javax.swing.text.Position;
53
import javax.swing.text.StyledDocument;
52
import javax.swing.text.StyledDocument;
54
import org.netbeans.modules.editor.indent.api.Indent;
53
import org.netbeans.modules.editor.indent.api.Indent;
55
import org.netbeans.modules.editor.indent.api.Reformat;
54
import org.netbeans.modules.editor.indent.api.Reformat;
56
import org.netbeans.editor.BaseDocument;
57
import org.netbeans.editor.Formatter;
58
55
59
/**
56
/**
60
 * Indentation and code reformatting services for a swing text document.
57
 * Indentation and code reformatting services for a swing text document.
Lines 72-78 Link Here
72
            indentImpl = new IndentImpl(doc);
69
            indentImpl = new IndentImpl(doc);
73
            doc.putProperty(IndentImpl.class, indentImpl);
70
            doc.putProperty(IndentImpl.class, indentImpl);
74
        }
71
        }
75
        indentImpl.refresh();
72
// XXX: formatting infra cleanup
73
//        indentImpl.refresh();
76
        return indentImpl;
74
        return indentImpl;
77
    }
75
    }
78
    
76
    
Lines 85-93 Link Here
85
    private TaskHandler indentHandler;
83
    private TaskHandler indentHandler;
86
    
84
    
87
    private TaskHandler reformatHandler;
85
    private TaskHandler reformatHandler;
86
87
// XXX: formatting infra cleanup
88
//    private Formatter defaultFormatter;
88
    
89
    
89
    private Formatter defaultFormatter;
90
91
    private Thread lockThread;
90
    private Thread lockThread;
92
91
93
    private int lockExtraDepth;
92
    private int lockExtraDepth;
Lines 116-132 Link Here
116
        this.reformat = reformat;
115
        this.reformat = reformat;
117
    }
116
    }
118
    
117
    
119
    void setDefaultFormatter(Formatter defaultFormatter) {
118
// XXX: formatting infra cleanup
120
        this.defaultFormatter = defaultFormatter;
119
//    void setDefaultFormatter(Formatter defaultFormatter) {
121
    }
120
//        this.defaultFormatter = defaultFormatter;
122
    
121
//    }
123
    void refresh() {
122
//
124
        if (defaultFormatter == null) {
123
//    void refresh() {
125
            if (doc instanceof BaseDocument) {
124
//        if (defaultFormatter == null) {
126
                defaultFormatter = ((BaseDocument)doc).getLegacyFormatter();
125
//            if (doc instanceof BaseDocument) {
127
            }
126
//                defaultFormatter = ((BaseDocument)doc).getLegacyFormatter();
128
        }
127
//            }
129
    }
128
//        }
129
//    }
130
    
130
    
131
    public synchronized void indentLock() {
131
    public synchronized void indentLock() {
132
        if (LOG.isLoggable(Level.FINE)) {
132
        if (LOG.isLoggable(Level.FINE)) {
Lines 221-227 Link Here
221
            // Find begining of line
221
            // Find begining of line
222
            Element lineRootElem = lineRootElement(doc);
222
            Element lineRootElem = lineRootElement(doc);
223
            // Correct the start offset to point to the begining of the start line
223
            // Correct the start offset to point to the begining of the start line
224
            boolean done = false;
224
// XXX: formatting infra cleanup
225
//            boolean done = false;
225
            if (indentHandler.hasItems()) {
226
            if (indentHandler.hasItems()) {
226
                // When indenting newline first insert a plain newline
227
                // When indenting newline first insert a plain newline
227
                if (indentNewLine) {
228
                if (indentNewLine) {
Lines 257-293 Link Here
257
258
258
                // Perform whole reindent on top and possibly embedded levels
259
                // Perform whole reindent on top and possibly embedded levels
259
                indentHandler.runTasks();
260
                indentHandler.runTasks();
260
                done = true;
261
// XXX: formatting infra cleanup
262
//                done = true;
261
            }
263
            }
262
264
263
            // Fallback to Formatter
265
// XXX: formatting infra cleanup
264
            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
266
//            // Fallback to Formatter
265
                if (indentNewLine) {
267
//            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
266
                    if (LOG.isLoggable(Level.FINE)) {
268
//                if (indentNewLine) {
267
                        LOG.fine("Defaulting reindent() to indentNewLine() in legacy formatter " + // NOI18N
269
//                    if (LOG.isLoggable(Level.FINE)) {
268
                                defaultFormatter + '\n');
270
//                        LOG.fine("Defaulting reindent() to indentNewLine() in legacy formatter " + // NOI18N
269
                    }
271
//                                defaultFormatter + '\n');
270
                    // Fallback to indentNewLine() will insert '\n'
272
//                    }
271
                    int newCaretOffset = defaultFormatter.indentNewLine(doc, caretOffset);
273
//                    // Fallback to indentNewLine() will insert '\n'
272
                    indentHandler.setCaretOffset(newCaretOffset);
274
//                    int newCaretOffset = defaultFormatter.indentNewLine(doc, caretOffset);
273
                } else { // Indent line
275
//                    indentHandler.setCaretOffset(newCaretOffset);
274
                    // Original formatter does not have reindentation of multiple lines
276
//                } else { // Indent line
275
                    // so reformat start line and continue for each line.
277
//                    // Original formatter does not have reindentation of multiple lines
276
                    Position endPos = doc.createPosition(endOffset);
278
//                    // so reformat start line and continue for each line.
277
                    if (LOG.isLoggable(Level.FINE)) {
279
//                    Position endPos = doc.createPosition(endOffset);
278
                        LOG.fine("Defaulting reindent() to indentLine() in legacy formatter " + // NOI18N
280
//                    if (LOG.isLoggable(Level.FINE)) {
279
                                defaultFormatter + '\n');
281
//                        LOG.fine("Defaulting reindent() to indentLine() in legacy formatter " + // NOI18N
280
                    }
282
//                                defaultFormatter + '\n');
281
                    do {
283
//                    }
282
                        startOffset = defaultFormatter.indentLine(doc, startOffset);
284
//                    do {
283
                        int startLineIndex = lineRootElem.getElementIndex(startOffset) + 1;
285
//                        startOffset = defaultFormatter.indentLine(doc, startOffset);
284
                        if (startLineIndex >= lineRootElem.getElementCount())
286
//                        int startLineIndex = lineRootElem.getElementIndex(startOffset) + 1;
285
                            break;
287
//                        if (startLineIndex >= lineRootElem.getElementCount())
286
                        Element lineElem = lineRootElem.getElement(startLineIndex);
288
//                            break;
287
                        startOffset = lineElem.getStartOffset(); // Move to next line
289
//                        Element lineElem = lineRootElem.getElement(startLineIndex);
288
                    } while (startOffset < endPos.getOffset());
290
//                        startOffset = lineElem.getStartOffset(); // Move to next line
289
                }
291
//                    } while (startOffset < endPos.getOffset());
290
            }
292
//                }
293
//            }
294
291
            return indentHandler.caretOffset();
295
            return indentHandler.caretOffset();
292
        } finally {
296
        } finally {
293
            if (runUnlocked)
297
            if (runUnlocked)
Lines 310-316 Link Here
310
            if (runUnlocked) {
314
            if (runUnlocked) {
311
                reformatHandler.collectTasks();
315
                reformatHandler.collectTasks();
312
            }
316
            }
313
            boolean done = false;
317
// XXX: formatting infra cleanup
318
//            boolean done = false;
314
            if (reformatHandler.hasItems()) {
319
            if (reformatHandler.hasItems()) {
315
                reformatHandler.setGlobalBounds(
320
                reformatHandler.setGlobalBounds(
316
                        doc.createPosition(startOffset),
321
                        doc.createPosition(startOffset),
Lines 320-337 Link Here
320
                reformatHandler.runTasks();
325
                reformatHandler.runTasks();
321
326
322
                // Perform reformatting of the top section and possible embedded sections
327
                // Perform reformatting of the top section and possible embedded sections
323
                done = true;
328
// XXX: formatting infra cleanup
329
//                done = true;
324
            }
330
            }
325
331
326
            // Fallback to Formatter
332
// XXX: formatting infra cleanup
327
            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
333
//            // Fallback to Formatter
328
                if (LOG.isLoggable(Level.FINE)) {
334
//            if (!done && doc instanceof BaseDocument && defaultFormatter != null) {
329
                    LOG.fine("Defaulting reformat() to reformat() in legacy formatter " + // NOI18N
335
//                if (LOG.isLoggable(Level.FINE)) {
330
                            defaultFormatter + '\n');
336
//                    LOG.fine("Defaulting reformat() to reformat() in legacy formatter " + // NOI18N
331
                }
337
//                            defaultFormatter + '\n');
332
                BaseDocument bdoc = (BaseDocument)doc;
338
//                }
333
                defaultFormatter.reformat(bdoc, startOffset, endOffset);
339
//                BaseDocument bdoc = (BaseDocument)doc;
334
            }
340
//                defaultFormatter.reformat(bdoc, startOffset, endOffset);
341
//            }
335
        } finally {
342
        } finally {
336
            if (runUnlocked)
343
            if (runUnlocked)
337
                reformatHandler = null;
344
                reformatHandler = null;
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/TaskHandler.java (-6 / +5 lines)
Lines 62-68 Link Here
62
import org.netbeans.api.lexer.LanguagePath;
62
import org.netbeans.api.lexer.LanguagePath;
63
import org.netbeans.api.lexer.TokenHierarchy;
63
import org.netbeans.api.lexer.TokenHierarchy;
64
import org.netbeans.api.lexer.TokenSequence;
64
import org.netbeans.api.lexer.TokenSequence;
65
import org.netbeans.editor.GuardedDocument;
66
import org.netbeans.lib.editor.util.swing.MutablePositionRegion;
65
import org.netbeans.lib.editor.util.swing.MutablePositionRegion;
67
import org.netbeans.modules.editor.indent.spi.Context;
66
import org.netbeans.modules.editor.indent.spi.Context;
68
import org.netbeans.modules.editor.indent.spi.ExtraLock;
67
import org.netbeans.modules.editor.indent.spi.ExtraLock;
Lines 464-473 Link Here
464
                }
463
                }
465
                
464
                
466
                // Filter out guarded regions
465
                // Filter out guarded regions
467
                if (indentRegions.size() > 0 && doc instanceof GuardedDocument) {
466
//                if (indentRegions.size() > 0 && doc instanceof GuardedDocument) {
468
                    MutablePositionRegion region = IndentSpiPackageAccessor.get().positionRegion(indentRegions.get(0));
467
//                    MutablePositionRegion region = IndentSpiPackageAccessor.get().positionRegion(indentRegions.get(0));
469
                    int regionStartOffset = region.getStartOffset();
468
//                    int regionStartOffset = region.getStartOffset();
470
                    GuardedDocument gdoc = (GuardedDocument)doc;
469
//                    GuardedDocument gdoc = (GuardedDocument)doc;
471
//                    int gbStartOffset = guardedBlocks.adjustToBlockEnd(region.getEndOffset());
470
//                    int gbStartOffset = guardedBlocks.adjustToBlockEnd(region.getEndOffset());
472
//                    MarkBlockChain guardedBlocks = gdoc.getGuardedBlockChain();
471
//                    MarkBlockChain guardedBlocks = gdoc.getGuardedBlockChain();
473
//                    if (guardedBlocks != null && guardedBlocks.getChain() != null) {
472
//                    if (guardedBlocks != null && guardedBlocks.getChain() != null) {
Lines 500-506 Link Here
500
//                            }
499
//                            }
501
//                        }
500
//                        }
502
//                    }
501
//                    }
503
                }
502
//                }
504
            } catch (BadLocationException e) {
503
            } catch (BadLocationException e) {
505
                Exceptions.printStackTrace(e);
504
                Exceptions.printStackTrace(e);
506
                indentRegions = Collections.emptyList();
505
                indentRegions = Collections.emptyList();
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/api/Indent.java (+19 lines)
Lines 171-174 Link Here
171
        impl.reindent(startOffset, endOffset, startOffset, false);
171
        impl.reindent(startOffset, endOffset, startOffset, false);
172
    }
172
    }
173
173
174
    /**
175
     * Creates new line at <code>offset</code> and reindents it.
176
     *
177
     * <p>This method will insert a line break (ie EOL character) at the specified
178
     * offset and then reindent the newly created line. The method will return the
179
     * offset of the indented beginning of the new line. That is the offset where
180
     * the new text should appear when typing in the document.
181
     *
182
     * @param offset The document offset where the new line will be created.
183
     *
184
     * @return The offset of the first non-white character (or the EOL character)
185
     *   on the new line. This is basically where the caret should be moved to.
186
     * @throws javax.swing.text.BadLocationException
187
     * @since 1.10
188
     */
189
    public int indentNewLine(int offset) throws BadLocationException {
190
        return impl.reindent(offset, offset, offset, true);
191
    }
192
174
}
193
}
(-)a/editor.indent/src/org/netbeans/modules/editor/indent/spi/support/AutomatedIndenting.java (+238 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.indent.spi.support;
41
42
import java.lang.reflect.Method;
43
import java.util.ArrayList;
44
import java.util.Map;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
47
import java.util.regex.Pattern;
48
import java.util.regex.PatternSyntaxException;
49
import javax.swing.text.BadLocationException;
50
import javax.swing.text.Document;
51
import javax.swing.text.Element;
52
import org.netbeans.api.editor.mimelookup.MimePath;
53
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
54
import org.netbeans.modules.editor.indent.api.Indent;
55
import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor;
56
57
/**
58
 * This class contains factory methods for typing interceptor implementations
59
 * that can be used for automated text indenting.
60
 *
61
 * <p>The interceptors provided by this class are implementations of Typing Hooks SPI
62
 * interfaces that can be registered in <code>MimeLookup</code>. Typically there are
63
 * two factory methods for each interceptor implementation. One factory method creates
64
 * the implementated interceptor and is suitable for direct use from java code. The
65
 * other factory method creates a factory object that can be registred in an XML layer
66
 * as an <code>.instance</code> file.
67
 *
68
 * @author Vita Stejskal
69
 * @since 1.11
70
 */
71
public final class AutomatedIndenting {
72
73
    /**
74
     * Creates <code>TypedTextInterceptor</code> that automatically
75
     * indents a line depending on text typed on that line.
76
     *
77
     * <p>The text patterns recognized by the intercetor are defined in form
78
     * of regular expressions passed to this method. The interceptor will match
79
     * all text before the caret on the line where a user is typing (including
80
     * the last typed character) against the regular expression patterns. If the text
81
     * matches at least one pattern the interceptor will reindent the line by
82
     * calling {@link Indent#reindent(int)} method.
83
     *
84
     * @param linePatterns The regular expressions that will be used for matching
85
     *   text typed on a line. Any matching pattern will trigger the line reindentation.
86
     *
87
     * @return The interceptor that checks text typed on a line and reindents the line
88
     *   if it matches any of the <code>linePatterns</code>.
89
     *
90
     * @since 1.11
91
     */
92
    public static TypedTextInterceptor createHotCharsIndenter(Pattern... linePatterns) {
93
        return new RegExBasedIndenter(linePatterns);
94
    }
95
96
    /**
97
     * This is a version of {@link #createHotCharsIndenter(java.util.regex.Pattern[])} method suitable
98
     * for XML layers registration.
99
     *
100
     * <div class="nonnormative">
101
     * <p>Here is an example of an XML layer registration done
102
     * for <code>text/x-java</code> mime type. The registered interceptor will indent
103
     * any line that contains whitespace followed by 'else'. The ending 'e' character is
104
     * the last character typed on the line.
105
     *
106
     * <pre>
107
     * &lt;folder name="Editors"&gt;
108
     *  &lt;folder name="text"&gt;
109
     *   &lt;folder name="x-java"&gt;
110
     *    &lt;file name="org-something-AutoIndenter.instance"&gt;
111
     *     &lt;attr name="instanceOf" stringvalue="org.netbeans.spi.editor.typinghooks.TypedTextInterceptor"/&gt;
112
     *     &lt;attr name="instanceCreate"
113
     *              methodvalue="org.netbeans.modules.editor.indent.spi.support.AutomatedIndenting.createHotCharsIndenter"/&gt;
114
     *     &lt;attr name="regex1" stringvalue="\s*else"/&gt;
115
     *    &lt;/file&gt;
116
     *   &lt;/folder&gt;
117
     *  &lt;/folder&gt;
118
     * &lt;/folder&gt;
119
     * </pre>
120
     * </div>
121
     *
122
     * @param fileAttributes The map of <code>FileObject</code> attributes. This method
123
     *   will recognize any attributes, which name starts with <code>regex</code> and will
124
     *   try to interpret their value as a regular expression. These regular expressions
125
     *   will then be used as <code>linePatterns</code> when calling <code>createHotCharsIndenter(Pattern...)</code> method.
126
     * 
127
     * @return The interceptor factory that will provide a regular expressions based
128
     *   automated indenter returned from the {@link #createHotCharsIndenter(java.util.regex.Pattern[])} method.
129
     *   The list of line patterns will be recovered from the <code>fileAttributes</code>.
130
     * 
131
     * @since 1.11
132
     */
133
    public static TypedTextInterceptor.Factory createHotCharsIndenter(Map<Object, Object> fileAttributes) {
134
        final ArrayList<Pattern> linePatterns = new ArrayList<Pattern>();
135
136
        for(Object key : fileAttributes.keySet()) {
137
            if (key.toString().startsWith("regex")) { //NOI18N
138
                Object value = fileAttributes.get(key);
139
                try {
140
                    Pattern pattern = Pattern.compile(value.toString());
141
                    linePatterns.add(pattern);
142
                } catch (PatternSyntaxException pse) {
143
                    LOG.log(Level.WARNING, null, pse);
144
                }
145
            }
146
        }
147
148
        return new TypedTextInterceptor.Factory() {
149
            public TypedTextInterceptor createTypedTextInterceptor(MimePath mimePath) {
150
                return createHotCharsIndenter(linePatterns.toArray(new Pattern [linePatterns.size()]));
151
            }
152
        };
153
    }
154
155
    // ------------------------------------------------------------------------
156
    // private
157
    // ------------------------------------------------------------------------
158
159
    private static final Logger LOG = Logger.getLogger(AutomatedIndenting.class.getName());
160
    
161
    private static final class RegExBasedIndenter implements TypedTextInterceptor {
162
163
        private final Pattern [] linePatterns;
164
165
        public RegExBasedIndenter(Pattern... linePatterns) {
166
            this.linePatterns = linePatterns;
167
        }
168
169
        public boolean beforeInsert(Context context) {
170
            // no-op
171
            return false;
172
        }
173
174
        public void insert(MutableContext context) {
175
            // no-op
176
        }
177
178
        public void afterInsert(Context context) {
179
            int textLen = context.getText().length();
180
            if (textLen > 0) {
181
                CharSequence lineText;
182
                final int lineStartOffset;
183
                final int lineEndOffset;
184
185
                try {
186
                    Element lineElement = DocumentUtilities.getParagraphElement(context.getDocument(), context.getOffset());
187
                    lineText = DocumentUtilities.getText(context.getDocument(),
188
                        lineElement.getStartOffset(),
189
                        context.getOffset() - lineElement.getStartOffset() + textLen);
190
                    lineStartOffset = lineElement.getStartOffset();
191
                    lineEndOffset = Math.max(lineStartOffset, lineElement.getEndOffset() - 1); // without EOL
192
                } catch (Exception e) {
193
                    LOG.log(Level.INFO, null, e);
194
                    return;
195
                }
196
197
                for(Pattern p : linePatterns) {
198
                    if (p.matcher(lineText).matches()) {
199
                        if (LOG.isLoggable(Level.FINE)) {
200
                            LOG.fine("The line '" + lineText + "' matches '" + p.pattern() //NOI18N
201
                                + "' -> calling Indent.reindent(" + lineStartOffset + ", " + lineEndOffset + ")"); //NOI18N
202
                        }
203
204
                        final Indent indenter = Indent.get(context.getDocument());
205
                        indenter.lock();
206
                        try {
207
                            runAtomicAsUser(context.getDocument(), new Runnable() {
208
                                public void run() {
209
                                    try {
210
                                        indenter.reindent(lineStartOffset, lineEndOffset);
211
                                    } catch (BadLocationException ble) {
212
                                        LOG.log(Level.INFO, null, ble);
213
                                    }
214
                                }
215
                            });
216
                        } finally {
217
                            indenter.unlock();
218
                        }
219
                        break;
220
                    }
221
                }
222
            }
223
        }
224
225
        public void cancelled(Context context) {
226
            // no-op
227
        }
228
229
        private static void runAtomicAsUser(Document doc, Runnable run) {
230
            try {
231
                Method runAtomicAsUserMethod = doc.getClass().getMethod("runAtomicAsUser", Runnable.class); //NOI18N
232
                runAtomicAsUserMethod.invoke(doc, run);
233
            } catch (Exception e) {
234
                LOG.log(Level.INFO, null, e);
235
            }
236
        }
237
    } // End of RegExBasedIndenter class
238
}
(-)a/editor.lib/apichanges.xml (+84 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
111
        <change id="deprecating-formatting">
112
            <summary>Deprecating old formatting API</summary>
113
            <version major="3" minor="1"/>
114
            <date day="24" month="8" year="2010"/>
115
            <author login="vstejskal"/>
116
            <compatibility binary="incompatible" source="incompatible" semantic="incompatible" addition="yes" deprecation="yes" deletion="yes" modification="yes"/>
117
            <description>
118
                <p>
119
                    The old formatting API (<code>org.netbeans.editor.Formatter</code> &amp; co.)
120
                    has been deprecated and moved to <code>editor.deprecated.pre65formatting</code> module.
121
                </p>
122
                <p>The exact API changes are listed in the sigtest report below.</p>
123
<pre>
124
-sigtest-init:
125
     [echo] sigtest check: editor.lib; cnb: org-netbeans-modules-editor-lib; email: api-changes@netbeans.org; type: check
126
127
check-sigtest:
128
    [mkdir] Created dir: /work/netbeans/main2m/editor.lib/build/test/sigtest/results
129
  [sigtest] /work/netbeans/main2m/editor.lib/build/test/sigtest/results/org.netbeans.modules.editor.lib
130
  [sigtest] Packages: org.netbeans.editor.*, org.netbeans.editor.ext.*, org.netbeans.editor.view.spi.*, org.netbeans.lib.editor.hyperlink.spi.*, org.netbeans.lib.editor.view.*
131
  [sigtest] Missing /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/rt.jar
132
  [sigtest] 
133
  [sigtest] email: api-changes@netbeans.org
134
  [sigtest] SignatureTest report
135
  [sigtest] Base version: 2.11.0
136
  [sigtest] Tested version: 2.11.0
137
  [sigtest] Check mode: bin [throws removed]
138
  [sigtest] Constant checking: on
139
  [sigtest] 
140
  [sigtest] 
141
  [sigtest] Class org.netbeans.editor.BaseDocument
142
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getFormatter()
143
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getLegacyFormatter()
144
  [sigtest] 
145
  [sigtest] Class org.netbeans.editor.BaseKit
146
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseKit.createFormatter()
147
  [sigtest] 
148
  [sigtest] Class org.netbeans.editor.BaseKit$PasteAction
149
  [sigtest]   "E1.2 - API type removed" : method public static void org.netbeans.editor.BaseKit$PasteAction.indentBlock(org.netbeans.editor.BaseDocument,int,int)
150
  [sigtest] 
151
  [sigtest] Class org.netbeans.editor.Formatter
152
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.Formatter
153
  [sigtest] 
154
  [sigtest] Class org.netbeans.editor.GuardedDocument
155
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getFormatter()
156
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getLegacyFormatter()
157
  [sigtest] 
158
  [sigtest] Class org.netbeans.editor.ext.AbstractFormatLayer
159
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract org.netbeans.editor.ext.AbstractFormatLayer
160
  [sigtest] 
161
  [sigtest] Class org.netbeans.editor.ext.ExtFormatSupport
162
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.ExtFormatSupport
163
  [sigtest] 
164
  [sigtest] Class org.netbeans.editor.ext.ExtFormatter
165
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.ExtFormatter
166
  [sigtest] 
167
  [sigtest] Class org.netbeans.editor.ext.ExtFormatter$Simple
168
  [sigtest]   "E1.2 - API type removed" : CLASS public static org.netbeans.editor.ext.ExtFormatter$Simple
169
  [sigtest] 
170
  [sigtest] Class org.netbeans.editor.ext.ExtKit
171
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseKit.createFormatter()
172
  [sigtest] 
173
  [sigtest] Class org.netbeans.editor.ext.FormatLayer
174
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract interface org.netbeans.editor.ext.FormatLayer
175
  [sigtest] 
176
  [sigtest] Class org.netbeans.editor.ext.FormatSupport
177
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.editor.ext.FormatSupport
178
  [sigtest] 
179
  [sigtest] Class org.netbeans.editor.ext.FormatTokenPosition
180
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract interface org.netbeans.editor.ext.FormatTokenPosition
181
  [sigtest] 
182
  [sigtest] Class org.netbeans.editor.ext.FormatWriter
183
  [sigtest]   "E1.2 - API type removed" : CLASS public final org.netbeans.editor.ext.FormatWriter
184
  [sigtest] 
185
  [sigtest] /work/netbeans/main2m/editor.lib/build/test/sigtest/results/org-netbeans-modules-editor-lib.xml: 1 failures in /work/netbeans/main2m/editor.lib/nbproject/org-netbeans-modules-editor-lib.sig
186
187
BUILD FAILED
188
Signature tests return code is wrong (1), check the messages above
189
</pre>                
190
            </description>
191
            <issue number="189638"/>
192
        </change>
193
        
110
        <change id="ToolTipSupport-heavyweight-tooltips">
194
        <change id="ToolTipSupport-heavyweight-tooltips">
111
            <summary>Support for heavyweight tooltips</summary>
195
            <summary>Support for heavyweight tooltips</summary>
112
            <version major="2" minor="10"/>
196
            <version major="2" minor="10"/>
(-)a/editor.lib/manifest.mf (-2 / +2 lines)
Lines 1-4 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.lib/2
2
OpenIDE-Module: org.netbeans.modules.editor.lib/3
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib/Bundle.properties
4
OpenIDE-Module-Implementation-Version: 10
4
OpenIDE-Module-Implementation-Version: 11
(-)a/editor.lib/module-auto-deps.xml (-1 / +3 lines)
Lines 48-54 Link Here
48
48
49
<transformations version="1.0">
49
<transformations version="1.0">
50
    <transformationgroup>
50
    <transformationgroup>
51
        <description>Old editor settings and completion APIs have been deprecated, see http://wiki.netbeans.org/EditorSettingsUpgrade and update your module.</description>
51
        <description>The old editor settings and completion APIs have been deprecated, see http://wiki.netbeans.org/EditorSettingsUpgrade and update your module.</description>
52
        <transformation>
52
        <transformation>
53
            <trigger-dependency type="older">
53
            <trigger-dependency type="older">
54
                <module-dependency codenamebase="org.netbeans.modules.editor.lib" major="1" spec="1.27"/>
54
                <module-dependency codenamebase="org.netbeans.modules.editor.lib" major="1" spec="1.27"/>
Lines 56-61 Link Here
56
            <implies>
56
            <implies>
57
                <result>
57
                <result>
58
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61completion" major="0" spec="1.0"/>
58
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61completion" major="0" spec="1.0"/>
59
                </result>
60
                <result>
59
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61settings" major="0" spec="1.0"/>
61
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61settings" major="0" spec="1.0"/>
60
                </result>
62
                </result>
61
            </implies>
63
            </implies>
(-)a/editor.lib/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint:unchecked
43
javac.compilerargs=-Xlint:unchecked
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=2.11.0
45
spec.version.base=3.1
46
is.autoload=true
46
is.autoload=true
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
(-)a/editor.lib/nbproject/project.xml (+17 lines)
Lines 67-72 Link Here
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
70
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
73
                    <run-dependency>
74
                        <release-version>2</release-version>
75
                        <specification-version>1.9</specification-version>
76
                    </run-dependency>
77
                </dependency>
78
                <dependency>
70
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
79
                    <code-name-base>org.netbeans.modules.editor.lib2</code-name-base>
71
                    <build-prerequisite/>
80
                    <build-prerequisite/>
72
                    <compile-dependency/>
81
                    <compile-dependency/>
Lines 136-141 Link Here
136
                    </run-dependency>
145
                    </run-dependency>
137
                </dependency>
146
                </dependency>
138
                <dependency>
147
                <dependency>
148
                    <code-name-base>org.openide.filesystems</code-name-base>
149
                    <build-prerequisite/>
150
                    <compile-dependency/>
151
                    <run-dependency>
152
                        <specification-version>7.13</specification-version>
153
                    </run-dependency>
154
                </dependency>
155
                <dependency>
139
                    <code-name-base>org.openide.util</code-name-base>
156
                    <code-name-base>org.openide.util</code-name-base>
140
                    <build-prerequisite/>
157
                    <build-prerequisite/>
141
                    <compile-dependency/>
158
                    <compile-dependency/>
(-)a/editor.lib/src/org/netbeans/editor/Abbrev.java (-4 / +10 lines)
Lines 56-61 Link Here
56
import javax.swing.text.Caret;
56
import javax.swing.text.Caret;
57
import org.netbeans.lib.editor.util.CharSequenceUtilities;
57
import org.netbeans.lib.editor.util.CharSequenceUtilities;
58
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
58
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
59
import org.netbeans.modules.editor.indent.api.Reformat;
59
60
60
/** 
61
/** 
61
 * Abbreviation support allowing to expand defined character sequences
62
 * Abbreviation support allowing to expand defined character sequences
Lines 296-307 Link Here
296
            }
297
            }
297
298
298
            if(ins.indexOf("\n") != -1) { // NOI18N
299
            if(ins.indexOf("\n") != -1) { // NOI18N
299
                Formatter formatter = doc.getFormatter();
300
                Reformat formatter = Reformat.get(doc);
300
                formatter.reformatLock();
301
                formatter.lock();
301
                try {
302
                try {
302
                    formatter.reformat(doc, dotPos, dotPos + ins.length());
303
                    doc.atomicLock();
304
                    try {
305
                        formatter.reformat(dotPos, dotPos + ins.length());
306
                    } finally {
307
                        doc.atomicUnlock();
308
                    }
303
                } finally {
309
                } finally {
304
                    formatter.reformatUnlock();
310
                    formatter.unlock();
305
                }
311
                }
306
            }
312
            }
307
            
313
            
(-)a/editor.lib/src/org/netbeans/editor/ActionFactory.java (-48 / +142 lines)
Lines 45-50 Link Here
45
package org.netbeans.editor;
45
package org.netbeans.editor;
46
46
47
import java.awt.Component;
47
import java.awt.Component;
48
import java.awt.Cursor;
48
import java.awt.Rectangle;
49
import java.awt.Rectangle;
49
import java.awt.event.ActionEvent;
50
import java.awt.event.ActionEvent;
50
import java.beans.PropertyChangeEvent;
51
import java.beans.PropertyChangeEvent;
Lines 52-57 Link Here
52
import java.util.Map;
53
import java.util.Map;
53
import java.util.HashMap;
54
import java.util.HashMap;
54
import java.util.HashSet;
55
import java.util.HashSet;
56
import java.util.logging.Level;
55
import javax.swing.Action;
57
import javax.swing.Action;
56
import javax.swing.ActionMap;
58
import javax.swing.ActionMap;
57
import javax.swing.ButtonModel;
59
import javax.swing.ButtonModel;
Lines 77-82 Link Here
77
import java.util.concurrent.atomic.AtomicBoolean;
79
import java.util.concurrent.atomic.AtomicBoolean;
78
import java.util.logging.Level;
80
import java.util.logging.Level;
79
import java.util.logging.Logger;
81
import java.util.logging.Logger;
82
import javax.swing.ImageIcon;
80
import javax.swing.JToggleButton;
83
import javax.swing.JToggleButton;
81
import javax.swing.event.ChangeListener;
84
import javax.swing.event.ChangeListener;
82
import javax.swing.text.AbstractDocument;
85
import javax.swing.text.AbstractDocument;
Lines 89-94 Link Here
89
import org.netbeans.api.progress.ProgressUtils;
92
import org.netbeans.api.progress.ProgressUtils;
90
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
93
import org.netbeans.modules.editor.lib2.search.EditorFindSupport;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
94
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
95
import org.netbeans.modules.editor.indent.api.Indent;
96
import org.netbeans.modules.editor.indent.api.Reformat;
97
import org.netbeans.modules.editor.lib2.typinghooks.TypedBreakInterceptorsManager;
92
import org.openide.util.ImageUtilities;
98
import org.openide.util.ImageUtilities;
93
import org.openide.util.NbBundle;
99
import org.openide.util.NbBundle;
94
import org.openide.util.WeakListeners;
100
import org.openide.util.WeakListeners;
Lines 107-112 Link Here
107
113
108
public class ActionFactory {
114
public class ActionFactory {
109
115
116
    // -J-Dorg.netbeans.editor.ActionFactory.level=FINE
117
    private static final Logger LOG = Logger.getLogger(ActionFactory.class.getName());
118
    
110
    private ActionFactory() {
119
    private ActionFactory() {
111
        // no instantiation
120
        // no instantiation
112
    }
121
    }
Lines 133-144 Link Here
133
                doc.runAtomicAsUser (new Runnable () {
142
                doc.runAtomicAsUser (new Runnable () {
134
                    public void run () {
143
                    public void run () {
135
                        DocumentUtilities.setTypingModification(doc, true);
144
                        DocumentUtilities.setTypingModification(doc, true);
136
                        Formatter.pushFormattingContextDocument(doc);
137
                        try {
145
                        try {
138
                            if (Utilities.isSelectionShowing(caret)) { // block selected
146
                            if (Utilities.isSelectionShowing(caret)) { // block selected
139
                                try {
147
                                try {
140
                                    doc.getFormatter().changeBlockIndent(doc,
148
                                    BaseKit.changeBlockIndent(
141
                                            target.getSelectionStart(), target.getSelectionEnd(), -1);
149
                                        doc,
150
                                        target.getSelectionStart(),
151
                                        target.getSelectionEnd(),
152
                                        -1);
142
                                } catch (GuardedException e) {
153
                                } catch (GuardedException e) {
143
                                    target.getToolkit().beep();
154
                                    target.getToolkit().beep();
144
                                } catch (BadLocationException e) {
155
                                } catch (BadLocationException e) {
Lines 150-156 Link Here
150
                                    int firstNW = Utilities.getRowFirstNonWhite(doc, caret.getDot());
161
                                    int firstNW = Utilities.getRowFirstNonWhite(doc, caret.getDot());
151
                                    int endOffset = Utilities.getRowEnd(doc, caret.getDot());
162
                                    int endOffset = Utilities.getRowEnd(doc, caret.getDot());
152
                                    if (firstNW == -1 || (firstNW >= caret.getDot()))
163
                                    if (firstNW == -1 || (firstNW >= caret.getDot()))
153
                                        doc.getFormatter().changeBlockIndent(doc, startOffset, endOffset, -1);
164
                                        BaseKit.changeBlockIndent(doc, startOffset, endOffset, -1);
154
                                    else {
165
                                    else {
155
                                        // TODO:
166
                                        // TODO:
156
                                        // after we will have action which will do opposite to "tab" action
167
                                        // after we will have action which will do opposite to "tab" action
Lines 164-170 Link Here
164
                                }
175
                                }
165
                            }
176
                            }
166
                        } finally {
177
                        } finally {
167
                            Formatter.popFormattingContextDocument(doc);
168
                            DocumentUtilities.setTypingModification(doc, false);
178
                            DocumentUtilities.setTypingModification(doc, false);
169
                        }
179
                        }
170
                    }
180
                    }
Lines 1447-1468 Link Here
1447
                doc.runAtomicAsUser (new Runnable () {
1457
                doc.runAtomicAsUser (new Runnable () {
1448
                    public void run () {
1458
                    public void run () {
1449
                        DocumentUtilities.setTypingModification(doc, true);
1459
                        DocumentUtilities.setTypingModification(doc, true);
1450
                        Formatter.pushFormattingContextDocument(doc);
1451
                        try {
1460
                        try {
1452
                            boolean right = BaseKit.shiftLineRightAction.equals(getValue(Action.NAME));
1461
                            boolean right = BaseKit.shiftLineRightAction.equals(getValue(Action.NAME));
1453
                            if (Utilities.isSelectionShowing(caret)) {
1462
                            if (Utilities.isSelectionShowing(caret)) {
1454
                                doc.getFormatter().changeBlockIndent(doc,
1463
                                BaseKit.changeBlockIndent(
1455
                                target.getSelectionStart(), target.getSelectionEnd(),
1464
                                    doc,
1456
                                right ? +1 : -1);
1465
                                    target.getSelectionStart(), target.getSelectionEnd(),
1466
                                    right ? +1 : -1);
1457
                            } else {
1467
                            } else {
1458
                                doc.getFormatter().shiftLine(doc, caret.getDot(), right);
1468
                                BaseKit.shiftLine(doc, caret.getDot(), right);
1459
                            }
1469
                            }
1460
                        } catch (GuardedException e) {
1470
                        } catch (GuardedException e) {
1461
                            target.getToolkit().beep();
1471
                            target.getToolkit().beep();
1462
                        } catch (BadLocationException e) {
1472
                        } catch (BadLocationException e) {
1463
                            e.printStackTrace();
1473
                            e.printStackTrace();
1464
                        } finally {
1474
                        } finally {
1465
                            Formatter.popFormattingContextDocument(doc);
1466
                            DocumentUtilities.setTypingModification(doc, false);
1475
                            DocumentUtilities.setTypingModification(doc, false);
1467
                        }
1476
                        }
1468
                    }
1477
                    }
Lines 1494-1502 Link Here
1494
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1503
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1495
                                       ? (GuardedDocument)doc : null;
1504
                                       ? (GuardedDocument)doc : null;
1496
1505
1497
                final Formatter formatter = doc.getFormatter();
1506
                final Reformat formatter = Reformat.get(doc);
1498
                formatter.reformatLock();
1507
                formatter.lock();
1499
                Formatter.pushFormattingContextDocument(doc);
1500
                try {
1508
                try {
1501
                    doc.runAtomicAsUser (new Runnable () {
1509
                    doc.runAtomicAsUser (new Runnable () {
1502
                        public void run () {
1510
                        public void run () {
Lines 1527-1534 Link Here
1527
                                        }
1535
                                        }
1528
                                    }
1536
                                    }
1529
1537
1530
                                    int reformattedLen = formatter.reformat(doc, pos, stopPos);
1538
                                    Position stopPosition = doc.createPosition(stopPos);
1531
                                    pos = pos + reformattedLen;
1539
                                    formatter.reformat(pos, stopPos);
1540
                                    pos = pos + Math.max(stopPosition.getOffset() - pos, 0);
1532
1541
1533
                                    if (gdoc != null) { // adjust to end of current block
1542
                                    if (gdoc != null) { // adjust to end of current block
1534
                                        pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
1543
                                        pos = gdoc.getGuardedBlockChain().adjustToBlockEnd(pos);
Lines 1542-1549 Link Here
1542
                        }
1551
                        }
1543
                    });
1552
                    });
1544
                } finally {
1553
                } finally {
1545
                    Formatter.popFormattingContextDocument(doc);
1554
                    formatter.unlock();
1546
                    formatter.reformatUnlock();
1547
                }
1555
                }
1548
            }
1556
            }
1549
        }
1557
        }
Lines 1637-1651 Link Here
1637
                    return;
1645
                    return;
1638
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1646
                final GuardedDocument gdoc = (doc instanceof GuardedDocument)
1639
                                       ? (GuardedDocument)doc : null;
1647
                                       ? (GuardedDocument)doc : null;
1648
                
1649
                // Set hourglass cursor
1650
                final Cursor origCursor = target.getCursor();
1651
                target.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1640
1652
1641
                try {
1653
                try {
1642
                final AtomicBoolean canceled = new AtomicBoolean();
1654
                final AtomicBoolean canceled = new AtomicBoolean();
1643
                ProgressUtils.runOffEventDispatchThread(new Runnable() {
1655
                ProgressUtils.runOffEventDispatchThread(new Runnable() {
1644
                    public void run() {
1656
                    public void run() {
1645
                        if (canceled.get()) return;
1657
                        if (canceled.get()) return;
1646
                        final Formatter formatter = doc.getFormatter();
1658
                        final Reformat formatter = Reformat.get(doc);
1647
                        formatter.reformatLock();
1659
                        formatter.lock();
1648
                        Formatter.pushFormattingContextDocument(doc);
1649
                        try {
1660
                        try {
1650
                            if (canceled.get()) return;
1661
                            if (canceled.get()) return;
1651
                            doc.runAtomicAsUser (new Runnable () {
1662
                            doc.runAtomicAsUser (new Runnable () {
Lines 1680-1687 Link Here
1680
                                            }
1691
                                            }
1681
1692
1682
                                            if (pos < stopPos) {
1693
                                            if (pos < stopPos) {
1683
                                                int reformattedLen = formatter.reformat(doc, pos, stopPos);
1694
                                                Position stopPosition = doc.createPosition(stopPos);
1684
                                                pos = pos + reformattedLen;
1695
                                                formatter.reformat(pos, stopPos);
1696
                                                pos = pos + Math.max(stopPosition.getOffset() - pos, 0);
1685
                                            } else {
1697
                                            } else {
1686
                                                pos++; //ensure to make progress
1698
                                                pos++; //ensure to make progress
1687
                                            }
1699
                                            }
Lines 1695-1706 Link Here
1695
                                        target.getToolkit().beep();
1707
                                        target.getToolkit().beep();
1696
                                    } catch (BadLocationException e) {
1708
                                    } catch (BadLocationException e) {
1697
                                        Utilities.annotateLoggable(e);
1709
                                        Utilities.annotateLoggable(e);
1710
                                    } finally {
1711
                                        target.setCursor(origCursor);
1698
                                    }
1712
                                    }
1699
                                }
1713
                                }
1700
                            });
1714
                            });
1701
                        } finally {
1715
                        } finally {
1702
                            Formatter.popFormattingContextDocument(doc);
1716
                            formatter.unlock();
1703
                            formatter.reformatUnlock();
1704
                        }
1717
                        }
1705
                    }
1718
                    }
1706
                }, NbBundle.getMessage(FormatAction.class, "Format_in_progress"), canceled, false); //NOI18N
1719
                }, NbBundle.getMessage(FormatAction.class, "Format_in_progress"), canceled, false); //NOI18N
Lines 1710-1716 Link Here
1710
                }
1723
                }
1711
            }
1724
            }
1712
        }
1725
        }
1713
        
1714
    }
1726
    }
1715
1727
1716
    @EditorActionRegistrations({
1728
    @EditorActionRegistrations({
Lines 2331-2337 Link Here
2331
        }
2343
        }
2332
    }
2344
    }
2333
    
2345
    
2334
    /** Starts a new line in code. */
2346
    /** 
2347
     * Starts a new line in code.
2348
     * 
2349
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
2350
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
2351
     */
2335
    @EditorActionRegistration(name = BaseKit.startNewLineAction)
2352
    @EditorActionRegistration(name = BaseKit.startNewLineAction)
2336
    public static class StartNewLine extends LocalBaseAction {
2353
    public static class StartNewLine extends LocalBaseAction {
2337
        public StartNewLine(){
2354
        public StartNewLine(){
Lines 2345-2379 Link Here
2345
                return;
2362
                return;
2346
            }
2363
            }
2347
            
2364
            
2365
            final int caretOffset;
2366
            final int insertionOffset;
2367
            
2368
            try {
2369
                caretOffset = target.getCaretPosition();
2370
                insertionOffset = Utilities.getRowEnd(target, caretOffset);
2371
            } catch (BadLocationException ble) {
2372
                LOG.log(Level.FINE, null, ble);
2373
                return;
2374
            }
2348
            
2375
            
2349
            final BaseDocument doc = (BaseDocument)target.getDocument();
2376
            final BaseDocument doc = (BaseDocument)target.getDocument();
2350
            final Formatter formatter = doc.getFormatter();
2377
            final TypedBreakInterceptorsManager.Transaction transaction = TypedBreakInterceptorsManager.getInstance().openTransaction(
2351
            formatter.indentLock();
2378
                    target, caretOffset, insertionOffset);
2379
2352
            try {
2380
            try {
2353
                doc.runAtomicAsUser (new Runnable () {
2381
                if (!transaction.beforeInsertion()) {
2354
                    public void run () {
2382
                    final Boolean [] result = new Boolean [] { Boolean.FALSE }; //NOI18N
2355
                        try {
2383
                    final Indent indenter = Indent.get(doc);
2356
                            //target.replaceSelection(""); //NOI18N -fix of issue #52485
2384
                    indenter.lock();
2357
                            Caret caret = target.getCaret();
2385
                    try {
2386
                        doc.runAtomicAsUser (new Runnable () {
2387
                            public void run () {
2388
                                Object [] r = transaction.textTyped();
2389
                                String insertionText = r == null ? "\n" : (String) r[0]; //NOI18N
2390
                                int breakInsertPosition = r == null ? -1 : (Integer) r[1];
2391
                                int caretPosition = r == null ? -1 : (Integer) r[2];
2392
                                int [] reindentBlocks = r == null ? null : (int []) r[3];
2358
2393
2359
                            // insert and remove '-' to remember caret
2394
                                try {
2360
                            // position
2395
                                    performLineBreakInsertion(target, insertionOffset, insertionText, breakInsertPosition, caretPosition, reindentBlocks, indenter);
2361
                            int dotpos = caret.getDot();
2396
                                    result[0] = Boolean.TRUE;
2362
                            doc.insertString(dotpos,"-",null); //NOI18N
2397
                                } catch (BadLocationException ble) {
2363
                            doc.remove(dotpos,1);
2398
                                    LOG.log(Level.FINE, null, ble);
2364
                            int eolDot = Utilities.getRowEnd(target, caret.getDot());
2399
                                    target.getToolkit().beep();
2365
                            int newDotPos = formatter.indentNewLine(doc,eolDot);
2400
                                }
2366
                            caret.setDot(newDotPos);
2401
                            }
2367
                        } catch (BadLocationException ex) {
2402
                        });
2368
                            ex.printStackTrace();
2403
                    } finally {
2369
                        }
2404
                        indenter.unlock();
2370
                    }
2405
                    }
2371
                });
2406
2407
                    if (result[0].booleanValue()) {
2408
                        transaction.afterInsertion();
2409
                    } // else line-break insertion failed
2410
2411
                }
2372
            } finally {
2412
            } finally {
2373
                formatter.indentUnlock();
2413
                transaction.close();
2374
            }
2414
            }
2375
        }
2415
        }
2376
    }
2416
        
2417
        // --------------------------------------------------------------------
2418
        // Private implementation
2419
        // --------------------------------------------------------------------
2420
2421
        private void performLineBreakInsertion(
2422
                JTextComponent target, 
2423
                int insertionOffset, 
2424
                String insertionText, 
2425
                int breakInsertPosition, 
2426
                int caretPosition, 
2427
                int [] reindentBlocks,
2428
                Indent indenter) throws BadLocationException
2429
        {
2430
            BaseDocument doc = (BaseDocument) target.getDocument();
2431
            DocumentUtilities.setTypingModification(doc, true);
2432
            try {
2433
                //target.replaceSelection(""); //NOI18N -fix of issue #52485
2434
                Caret caret = target.getCaret();
2435
2436
                // XXX: WTF is this?
2437
                // insert and remove '-' to remember caret
2438
                // position
2439
                int dotPos = caret.getDot();
2440
                doc.insertString(dotPos, "-", null); //NOI18N
2441
                doc.remove(dotPos, 1);
2442
2443
                // insert new line, caret moves to the new line
2444
//                int eolDot = Utilities.getRowEnd(target, caret.getDot());
2445
//                doc.insertString(eolDot, "\n", null); //NOI18N
2446
                doc.insertString(insertionOffset, insertionText, null);
2447
                dotPos = insertionOffset;
2448
                dotPos += caretPosition != -1 ? caretPosition :
2449
                          breakInsertPosition != -1 ? breakInsertPosition + 1 :
2450
                          insertionText.indexOf('\n') + 1; //NOI18N
2451
2452
                // reindent the new line
2453
                Position newDotPos = doc.createPosition(dotPos);
2454
                if (reindentBlocks != null && reindentBlocks.length > 0) {
2455
                    for(int i = 0; i < reindentBlocks.length / 2; i++) {
2456
                        int startOffset = insertionOffset + reindentBlocks[2 * i];
2457
                        int endOffset = insertionOffset + reindentBlocks[2 * i + 1];
2458
                        indenter.reindent(startOffset, endOffset);
2459
                    }
2460
                } else {
2461
                    indenter.reindent(dotPos);
2462
                }
2463
2464
                caret.setDot(newDotPos.getOffset());
2465
            } finally {
2466
                DocumentUtilities.setTypingModification(doc, false);
2467
            }
2468
        }
2469
        
2470
    } // End of StartNewLine class
2377
    
2471
    
2378
    /**
2472
    /**
2379
     * Cut text from the caret position to either begining or end
2473
     * Cut text from the caret position to either begining or end
(-)a/editor.lib/src/org/netbeans/editor/BaseDocument.java (-47 / +39 lines)
Lines 100-106 Link Here
100
import org.netbeans.modules.editor.lib.EditorPackageAccessor;
100
import org.netbeans.modules.editor.lib.EditorPackageAccessor;
101
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
101
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
102
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
102
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
103
import org.netbeans.modules.editor.lib.FormatterOverride;
104
import org.netbeans.modules.editor.lib.TrailingWhitespaceRemove;
103
import org.netbeans.modules.editor.lib.TrailingWhitespaceRemove;
105
import org.netbeans.modules.editor.lib.SettingsConversions;
104
import org.netbeans.modules.editor.lib.SettingsConversions;
106
import org.netbeans.modules.editor.lib.drawing.DrawEngine;
105
import org.netbeans.modules.editor.lib.drawing.DrawEngine;
Lines 253-263 Link Here
253
            new Integer(3)
252
            new Integer(3)
254
        };
253
        };
255
254
256
    /** Size of one indentation level. If this variable is null (value
257
     * is not set in Settings, then the default algorithm will be used.
258
     */
259
    private Integer shiftWidth;
260
261
    /** How many times current writer requested writing */
255
    /** How many times current writer requested writing */
262
    private int writeDepth;
256
    private int writeDepth;
263
257
Lines 353-361 Link Here
353
347
354
    private Position lastPositionEditedByTyping = null;
348
    private Position lastPositionEditedByTyping = null;
355
349
356
    /** Formatter being used. */
350
    /** Size of one indentation level. If this variable is null (value
357
    private Formatter formatter;
351
     * is not set in Settings, then the default algorithm will be used.
358
352
     */
353
    private int shiftWidth = -1;
359
    private int tabSize;
354
    private int tabSize;
360
355
361
    private Preferences prefs;
356
    private Preferences prefs;
Lines 367-375 Link Here
367
            }
362
            }
368
363
369
            if (key == null || SimpleValueNames.INDENT_SHIFT_WIDTH.equals(key)) {
364
            if (key == null || SimpleValueNames.INDENT_SHIFT_WIDTH.equals(key)) {
370
                int shw = prefs.getInt(SimpleValueNames.INDENT_SHIFT_WIDTH, -1);
365
                shiftWidth = prefs.getInt(SimpleValueNames.INDENT_SHIFT_WIDTH, -1);
371
                if (shw >= 0) {
366
            }
372
                    shiftWidth = shw;
367
368
            if (key == null || SimpleValueNames.SPACES_PER_TAB.equals(key)) {
369
                if (shiftWidth == -1) {
370
                    shiftWidth = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
373
                }
371
                }
374
            }
372
            }
375
373
Lines 457-465 Link Here
457
                putProperty(EditorPreferencesKeys.PREVIOUS_WORD_FINDER, finder != null ? finder : new FinderFactory.PreviousWordBwdFinder(BaseDocument.this, stopOnEOL, false));
455
                putProperty(EditorPreferencesKeys.PREVIOUS_WORD_FINDER, finder != null ? finder : new FinderFactory.PreviousWordBwdFinder(BaseDocument.this, stopOnEOL, false));
458
            }
456
            }
459
457
460
            // Refresh formatter
461
            formatter = null;
462
463
            SettingsConversions.callSettingsChange(BaseDocument.this);
458
            SettingsConversions.callSettingsChange(BaseDocument.this);
464
        }
459
        }
465
    };
460
    };
Lines 621-651 Link Here
621
//        }
616
//        }
622
    }
617
    }
623
618
624
    /**
619
// XXX: formatting cleanup
625
     * @deprecated Please use Editor Indentation API instead, for details see
620
//    /**
626
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
621
//     * @deprecated Please use Editor Indentation API instead, for details see
627
     */
622
//     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
628
    public Formatter getLegacyFormatter() {
623
//     */
629
        if (formatter == null) {
624
//    public Formatter getLegacyFormatter() {
630
            formatter = (Formatter) SettingsConversions.callFactory(prefs, MimePath.parse(mimeType), FORMATTER, null);
625
//        if (formatter == null) {
631
            if (formatter == null) {
626
//            formatter = (Formatter) SettingsConversions.callFactory(prefs, MimePath.parse(mimeType), FORMATTER, null);
632
                formatter = Formatter.getFormatter(mimeType);
627
//            if (formatter == null) {
633
            }
628
//                formatter = Formatter.getFormatter(mimeType);
634
        }
629
//            }
635
        return formatter;
630
//        }
636
    }
631
//        return formatter;
637
632
//    }
638
    /**
633
//
639
     * Gets the formatter for this document.
634
//    /**
640
     *
635
//     * Gets the formatter for this document.
641
     * @deprecated Please use Editor Indentation API instead, for details see
636
//     *
642
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
637
//     * @deprecated Please use Editor Indentation API instead, for details see
643
     */
638
//     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
644
    public Formatter getFormatter() {
639
//     */
645
        Formatter f = getLegacyFormatter();
640
//    public Formatter getFormatter() {
646
        FormatterOverride fp = Lookup.getDefault().lookup(FormatterOverride.class);
641
//        Formatter f = getLegacyFormatter();
647
        return (fp != null) ? fp.getFormatter(this, f) : f;
642
//        FormatterOverride fp = Lookup.getDefault().lookup(FormatterOverride.class);
648
    }
643
//        return (fp != null) ? fp.getFormatter(this, f) : f;
644
//    }
649
645
650
    /**
646
    /**
651
     * @deprecated Please use Lexer instead, for details see
647
     * @deprecated Please use Lexer instead, for details see
Lines 1570-1584 Link Here
1570
     * setting. If so it uses it, otherwise it uses <code>formatter.getSpacesPerTab()</code>.
1566
     * setting. If so it uses it, otherwise it uses <code>formatter.getSpacesPerTab()</code>.
1571
     *
1567
     *
1572
     * @see getTabSize()
1568
     * @see getTabSize()
1573
     * @see Formatter.getSpacesPerTab()
1569
     * @deprecated Please use Editor Indentation API instead, for details see
1570
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
1574
     */
1571
     */
1575
    public int getShiftWidth() {
1572
    public int getShiftWidth() {
1576
        if (shiftWidth != null) {
1573
        return shiftWidth;
1577
            return shiftWidth.intValue();
1578
1579
        } else {
1580
            return getFormatter().getSpacesPerTab();
1581
        }
1582
    }
1574
    }
1583
1575
1584
    /**
1576
    /**
(-)a/editor.lib/src/org/netbeans/editor/BaseKit.java (-242 / +603 lines)
Lines 67-76 Link Here
67
import javax.swing.text.ViewFactory;
67
import javax.swing.text.ViewFactory;
68
import javax.swing.text.Caret;
68
import javax.swing.text.Caret;
69
import javax.swing.text.JTextComponent;
69
import javax.swing.text.JTextComponent;
70
import java.io.CharArrayWriter;
71
import java.lang.reflect.Method;
70
import java.lang.reflect.Method;
72
import java.util.Set;
71
import java.util.Set;
73
import java.util.Vector;
74
import java.util.WeakHashMap;
72
import java.util.WeakHashMap;
75
import java.util.logging.Level;
73
import java.util.logging.Level;
76
import java.util.logging.Logger;
74
import java.util.logging.Logger;
Lines 87-100 Link Here
87
import org.netbeans.api.editor.mimelookup.MimeLookup;
85
import org.netbeans.api.editor.mimelookup.MimeLookup;
88
import org.netbeans.api.editor.mimelookup.MimePath;
86
import org.netbeans.api.editor.mimelookup.MimePath;
89
import org.netbeans.api.editor.settings.KeyBindingSettings;
87
import org.netbeans.api.editor.settings.KeyBindingSettings;
88
import org.netbeans.api.editor.settings.SimpleValueNames;
89
import org.netbeans.lib.editor.util.CharSequenceUtilities;
90
import org.netbeans.lib.editor.util.ListenerList;
90
import org.netbeans.lib.editor.util.ListenerList;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
91
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
92
import org.netbeans.modules.editor.indent.api.Indent;
93
import org.netbeans.modules.editor.indent.api.IndentUtils;
94
import org.netbeans.modules.editor.indent.api.Reformat;
95
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
92
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
96
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
93
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
97
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
94
import org.netbeans.modules.editor.lib.KitsTracker;
98
import org.netbeans.modules.editor.lib.KitsTracker;
95
import org.netbeans.modules.editor.lib.NavigationHistory;
99
import org.netbeans.modules.editor.lib.NavigationHistory;
96
import org.netbeans.modules.editor.lib.SettingsConversions;
100
import org.netbeans.modules.editor.lib.SettingsConversions;
97
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
101
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
102
import org.netbeans.modules.editor.lib2.typinghooks.DeletedTextInterceptorsManager;
103
import org.netbeans.modules.editor.lib2.typinghooks.TypedBreakInterceptorsManager;
104
import org.netbeans.modules.editor.lib2.typinghooks.TypedTextInterceptorsManager;
98
import org.openide.awt.StatusDisplayer;
105
import org.openide.awt.StatusDisplayer;
99
import org.openide.util.HelpCtx;
106
import org.openide.util.HelpCtx;
100
import org.openide.util.Lookup;
107
import org.openide.util.Lookup;
Lines 616-629 Link Here
616
        return new SyntaxSupport(doc);
623
        return new SyntaxSupport(doc);
617
    }
624
    }
618
625
619
    /** 
626
// XXX: formatting cleanup
620
     * Create the formatter appropriate for this kit
627
//    /**
621
     * @deprecated Please use Editor Indentation API instead, for details see
628
//     * Create the formatter appropriate for this kit
622
     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
629
//     * @deprecated Please use Editor Indentation API instead, for details see
623
     */
630
//     *   <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation</a>.
624
    public Formatter createFormatter() {
631
//     */
625
        return new Formatter(this.getClass());
632
//    public Formatter createFormatter() {
626
    }
633
//        return new Formatter(this.getClass());
634
//    }
627
635
628
    /** Create text UI */
636
    /** Create text UI */
629
    protected BaseTextUI createTextUI() {
637
    protected BaseTextUI createTextUI() {
Lines 1020-1030 Link Here
1020
1028
1021
1029
1022
1030
1023
    /** Default typed action */
1031
    /** 
1032
     * Default typed action
1033
     *
1034
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1035
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1036
     */
1024
//    @EditorActionRegistration(name = defaultKeyTypedAction)
1037
//    @EditorActionRegistration(name = defaultKeyTypedAction)
1025
    public static class DefaultKeyTypedAction extends LocalBaseAction {
1038
    public static class DefaultKeyTypedAction extends LocalBaseAction {
1026
1039
1027
        static final long serialVersionUID =3069164318144463899L;
1040
        static final long serialVersionUID = 3069164318144463899L;
1028
1041
1029
        public DefaultKeyTypedAction() {
1042
        public DefaultKeyTypedAction() {
1030
            // Construct with defaultKeyTypedAction name to retain full compatibility for extending actions
1043
            // Construct with defaultKeyTypedAction name to retain full compatibility for extending actions
Lines 1033-1040 Link Here
1033
            LOG.fine("DefaultKeyTypedAction with enhanced logging, see issue #145306"); //NOI18N
1046
            LOG.fine("DefaultKeyTypedAction with enhanced logging, see issue #145306"); //NOI18N
1034
        }
1047
        }
1035
1048
1036
        private static final boolean isMac = System.getProperty("mrj.version") != null; //NOI18N
1037
1038
        public void actionPerformed (final ActionEvent evt, final JTextComponent target) {
1049
        public void actionPerformed (final ActionEvent evt, final JTextComponent target) {
1039
            if ((target != null) && (evt != null)) {
1050
            if ((target != null) && (evt != null)) {
1040
1051
Lines 1043-1049 Link Here
1043
                boolean ctrl = ((mod & ActionEvent.CTRL_MASK) != 0);
1054
                boolean ctrl = ((mod & ActionEvent.CTRL_MASK) != 0);
1044
                // On the mac, norwegian and french keyboards use Alt to do bracket characters.
1055
                // On the mac, norwegian and french keyboards use Alt to do bracket characters.
1045
                // This replicates Apple's modification DefaultEditorKit.DefaultKeyTypedAction
1056
                // This replicates Apple's modification DefaultEditorKit.DefaultKeyTypedAction
1046
                boolean alt = isMac ? ((mod & ActionEvent.META_MASK) != 0) : 
1057
                boolean alt = org.openide.util.Utilities.isMac() ? ((mod & ActionEvent.META_MASK) != 0) :
1047
                    ((mod & ActionEvent.ALT_MASK) != 0);
1058
                    ((mod & ActionEvent.ALT_MASK) != 0);
1048
                
1059
                
1049
                
1060
                
Lines 1057-1123 Link Here
1057
                    return;
1068
                    return;
1058
                }
1069
                }
1059
1070
1060
                final Caret caret = target.getCaret();
1061
                final BaseDocument doc = (BaseDocument)target.getDocument();
1062
                final EditorUI editorUI = Utilities.getEditorUI(target);
1063
                // determine if typed char is valid
1071
                // determine if typed char is valid
1064
                final String cmd = evt.getActionCommand();
1072
                final String cmd = evt.getActionCommand();
1065
                if ((cmd != null) && (cmd.length() == 1)) {
1073
                if (cmd != null && cmd.length() == 1 && cmd.charAt(0) >= 0x20 && cmd.charAt(0) != 0x7F) {
1066
                    //          Utilities.clearStatusText(target);
1074
                    if (LOG.isLoggable(Level.FINE)) {
1075
                        LOG.log(Level.FINE, "Processing command char: {0}", Integer.toHexString(cmd.charAt(0))); //NOI18N
1076
                    }
1067
1077
1078
                    final BaseDocument doc = (BaseDocument)target.getDocument();
1079
                    final int insertionOffset = computeInsertionOffset(target.getCaret());
1080
                    final TypedTextInterceptorsManager.Transaction transaction = TypedTextInterceptorsManager.getInstance().openTransaction(
1081
                            target, insertionOffset, cmd);
1082
                    
1068
                    try {
1083
                    try {
1069
                        NavigationHistory.getEdits().markWaypoint(target, caret.getDot(), false, true);
1084
                        if (!transaction.beforeInsertion()) {
1070
                    } catch (BadLocationException e) {
1085
                            final Object [] result = new Object [] { Boolean.FALSE, "" }; //NOI18N
1071
                        LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1086
                            doc.runAtomicAsUser (new Runnable () {
1072
                    }
1087
                                public void run () {
1073
                    
1088
                                    Object [] r = transaction.textTyped();
1074
                    doc.runAtomicAsUser (new Runnable () {
1089
                                    String insertionText = r == null ? cmd : (String) r[0];
1075
                        public void run () {
1090
                                    int caretPosition = r == null ? -1 : (Integer) r[1];
1076
                            DocumentUtilities.setTypingModification(doc, true);
1091
                                    
1077
                            try {
1078
                                char ch = cmd.charAt(0);
1079
                                if ((ch >= 0x20) && (ch != 0x7F)) { // valid character
1080
                                    LOG.fine("Processing command char: " + Integer.toHexString(ch)); //NOI18N
1081
1082
                                    editorUI.getWordMatch().clear(); // reset word matching
1083
                                    Boolean overwriteMode = (Boolean)editorUI.getProperty(
1084
                                                                EditorUI.OVERWRITE_MODE_PROPERTY);
1085
                                    try {
1092
                                    try {
1086
                                        boolean doInsert = true; // editorUI.getAbbrev().checkAndExpand(ch, evt);
1093
                                        performTextInsertion(target, insertionOffset, insertionText, caretPosition);
1087
                                        if (doInsert) {
1094
                                        result[0] = Boolean.TRUE;
1088
                                            if (Utilities.isSelectionShowing(caret)) { // valid selection
1095
                                        result[1] = insertionText;
1089
                                                boolean ovr = (overwriteMode != null && overwriteMode.booleanValue());
1096
                                    } catch (BadLocationException ble) {
1090
                                                try {
1097
                                        LOG.log(Level.FINE, null, ble);
1091
                                                    doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, true);
1092
                                                    replaceSelection(target, caret.getDot(), caret, cmd, ovr);
1093
                                                } finally {
1094
                                                    doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, null);
1095
                                                }
1096
                                            } else { // no selection
1097
                                                int dotPos = caret.getDot();
1098
                                                if (overwriteMode != null && overwriteMode.booleanValue()
1099
                                                        && dotPos < doc.getLength() && doc.getChars(dotPos, 1)[0] != '\n'
1100
                                                   ) { // overwrite current char
1101
                                                    insertString(doc, dotPos, caret, cmd, true); 
1102
                                                } else { // insert mode
1103
                                                    insertString(doc, dotPos, caret, cmd, false);
1104
                                                }
1105
                                            }
1106
                                        }
1107
                                    } catch (BadLocationException e) {
1108
                                        LOG.log(Level.FINE, null, e);
1109
                                        target.getToolkit().beep();
1098
                                        target.getToolkit().beep();
1110
                                    }
1099
                                    }
1111
                                } else {
1112
                                    LOG.fine("Invalid command char: " + Integer.toHexString(ch)); //NOI18N
1113
                                }
1100
                                }
1101
                            });
1102
                            
1103
                            if (((Boolean)result[0]).booleanValue()) {
1104
                                transaction.afterInsertion();
1114
1105
1115
                                checkIndent(target, cmd);
1106
                                // XXX: this is potentially wrong and we may need to call this with
1116
                            } finally {
1107
                                // the original cmd; or maybe only if insertionText == cmd; but maybe
1117
                                DocumentUtilities.setTypingModification(doc, false);
1108
                                // it does not matter, because nobody seems to be overwriting this method anyway
1118
                            }
1109
                                checkIndent(target, (String)result[1]);
1110
                            } // else text insertion failed
1119
                        }
1111
                        }
1120
                    });
1112
                    } finally {
1113
                        transaction.close();
1114
                    }
1121
                } else {
1115
                } else {
1122
                    if (LOG.isLoggable(Level.FINE)) {
1116
                    if (LOG.isLoggable(Level.FINE)) {
1123
                        StringBuilder sb = new StringBuilder();
1117
                        StringBuilder sb = new StringBuilder();
Lines 1128-1181 Link Here
1128
                                sb.append(" ");
1122
                                sb.append(" ");
1129
                            }
1123
                            }
1130
                        }
1124
                        }
1131
                        LOG.fine("Invalid command: '" + sb + "'"); //NOI18N
1125
                        LOG.log(Level.FINE, "Invalid command: {0}", sb); //NOI18N
1132
                    }                    
1126
                    }                    
1133
                }
1127
                }
1134
            }
1128
            }
1135
        }
1129
        }
1136
1130
1137
      /** 
1131
        // --------------------------------------------------------------------
1138
       * Hook to insert the given string at the given position into
1132
        // SPI
1139
       * the given document in insert-mode, no selection, writeable
1133
        // --------------------------------------------------------------------
1140
       * document. Designed to be overridden by subclasses that want
1134
1141
       * to intercept inserted characters.
1135
        /**
1142
       */
1136
         * Hook to insert the given string at the given position into
1143
      protected void insertString(BaseDocument doc,  
1137
         * the given document in insert-mode, no selection, writeable
1138
         * document. Designed to be overridden by subclasses that want
1139
         * to intercept inserted characters.
1140
         *
1141
         * @deprecated Please use Typing Hooks instead, for details see
1142
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1143
         */
1144
        protected void insertString(BaseDocument doc,
1144
				  int dotPos, 
1145
				  int dotPos, 
1145
				  Caret caret,
1146
				  Caret caret,
1146
				  String str, 
1147
				  String str, 
1147
				  boolean overwrite) 
1148
				  boolean overwrite) throws BadLocationException 
1148
	throws BadLocationException 
1149
        {
1149
      {
1150
            if (overwrite) {
1150
	if (overwrite) doc.remove(dotPos, 1);
1151
                doc.remove(dotPos, 1);
1151
	doc.insertString(dotPos, str, null);
1152
            }
1152
      }
1153
            
1154
            doc.insertString(dotPos, str, null);
1155
        }
1153
1156
1154
      /** 
1157
        /**
1155
       * Hook to insert the given string at the given position into
1158
         * Hook to insert the given string at the given position into
1156
       * the given document in insert-mode with selection visible
1159
         * the given document in insert-mode with selection visible
1157
       * Designed to be overridden by subclasses that want
1160
         * Designed to be overridden by subclasses that want
1158
       * to intercept inserted characters.
1161
         * to intercept inserted characters.
1159
       */
1162
         *
1160
      protected void replaceSelection(JTextComponent target,  
1163
         * @deprecated Please use Typing Hooks instead, for details see
1161
				  int dotPos, 
1164
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1162
				  Caret caret,
1165
         */
1163
				  String str, 
1166
        protected void replaceSelection(
1164
				  boolean overwrite) 
1167
                JTextComponent target,
1165
	throws BadLocationException 
1168
                int dotPos,
1166
      {
1169
                Caret caret,
1167
          target.replaceSelection(str);
1170
                String str,
1168
      }
1171
                boolean overwrite) throws BadLocationException
1172
        {
1173
            target.replaceSelection(str);
1174
        }
1169
1175
1170
1176
        /**
1171
        /** Check whether there was any important character typed
1177
         * Check whether there was any important character typed
1172
        * so that the line should be possibly reformatted.
1178
         * so that the line should be possibly reformatted.
1173
        */
1179
         *
1180
         * @deprecated Please use <a href="@org-netbeans-modules-editor-indent@/org/netbeans/modules/editor/indent/spi/AutomatedIndenting.html">AutomatedIndentig</a>
1181
         *   or Typing Hooks instead, for details see
1182
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1183
         */
1174
        protected void checkIndent(JTextComponent target, String typedText) {
1184
        protected void checkIndent(JTextComponent target, String typedText) {
1175
        }
1185
        }
1176
1186
1177
    }
1187
        // --------------------------------------------------------------------
1188
        // Private implementation
1189
        // --------------------------------------------------------------------
1178
1190
1191
        private void performTextInsertion(JTextComponent target, int insertionOffset, String insertionText, int caretPosition) throws BadLocationException {
1192
            final BaseDocument doc = (BaseDocument)target.getDocument();
1193
            
1194
            try {
1195
                NavigationHistory.getEdits().markWaypoint(target, insertionOffset, false, true);
1196
            } catch (BadLocationException e) {
1197
                LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1198
            }
1199
1200
            DocumentUtilities.setTypingModification(doc, true);
1201
            try {
1202
                EditorUI editorUI = Utilities.getEditorUI(target);
1203
                Caret caret = target.getCaret();
1204
1205
                editorUI.getWordMatch().clear(); // reset word matching
1206
                Boolean overwriteMode = (Boolean)editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY);
1207
                boolean ovr = (overwriteMode != null && overwriteMode.booleanValue());
1208
                if (Utilities.isSelectionShowing(caret)) { // valid selection
1209
                    try {
1210
                        doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, true);
1211
                        replaceSelection(target, insertionOffset, caret, insertionText, ovr);
1212
                    } finally {
1213
                        doc.putProperty(DOC_REPLACE_SELECTION_PROPERTY, null);
1214
                    }
1215
                } else { // no selection
1216
                    if (ovr && insertionOffset < doc.getLength() && doc.getChars(insertionOffset, 1)[0] != '\n') { //NOI18N
1217
                        // overwrite current char
1218
                        insertString(doc, insertionOffset, caret, insertionText, true);
1219
                    } else { // insert mode
1220
                        insertString(doc, insertionOffset, caret, insertionText, false);
1221
                    }
1222
                }
1223
1224
                if (caretPosition != -1) {
1225
                    assert caretPosition >= 0 && caretPosition < insertionText.length();
1226
                    caret.setDot(insertionOffset + caretPosition);
1227
                }
1228
            } finally {
1229
                DocumentUtilities.setTypingModification(doc, false);
1230
            }
1231
        }
1232
1233
        private int computeInsertionOffset(Caret caret) {
1234
            if (Utilities.isSelectionShowing(caret)) {
1235
                return Math.min(caret.getMark(), caret.getDot());
1236
            } else {
1237
                return caret.getDot();
1238
            }
1239
        }
1240
    } // End of DefaultKeyTypedAction class
1241
1242
    /** 
1243
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1244
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1245
     */
1179
    public static class InsertBreakAction extends LocalBaseAction {
1246
    public static class InsertBreakAction extends LocalBaseAction {
1180
1247
1181
        static final long serialVersionUID =7966576342334158659L;
1248
        static final long serialVersionUID =7966576342334158659L;
Lines 1192-1242 Link Here
1192
                }
1259
                }
1193
1260
1194
                final BaseDocument doc = (BaseDocument)target.getDocument();
1261
                final BaseDocument doc = (BaseDocument)target.getDocument();
1195
                final Formatter formatter = doc.getFormatter();
1262
                final int insertionOffset = computeInsertionOffset(target.getCaret());
1196
                formatter.indentLock();
1263
                final TypedBreakInterceptorsManager.Transaction transaction = TypedBreakInterceptorsManager.getInstance().openTransaction(
1264
                        target, insertionOffset, insertionOffset);
1265
                
1197
                try {
1266
                try {
1198
                    doc.runAtomicAsUser (new Runnable () {
1267
                    if (!transaction.beforeInsertion()) {
1199
                        public void run () {
1268
                        final Boolean [] result = new Boolean [] { Boolean.FALSE }; //NOI18N
1200
                            DocumentUtilities.setTypingModification(doc, true);
1269
                        final Indent indenter = Indent.get(doc);
1201
                            try {
1270
                        indenter.lock();
1202
                                target.replaceSelection("");
1271
                        try {
1203
                                Caret caret = target.getCaret();
1272
                            doc.runAtomicAsUser (new Runnable () {
1204
                                Object cookie = beforeBreak(target, doc, caret);
1273
                                public void run () {
1274
                                    Object [] r = transaction.textTyped();
1275
                                    String insertionText = r == null ? "\n" : (String) r[0]; //NOI18N
1276
                                    int breakInsertPosition = r == null ? -1 : (Integer) r[1];
1277
                                    int caretPosition = r == null ? -1 : (Integer) r[2];
1278
                                    int [] reindentBlocks = r == null ? null : (int []) r[3];
1205
1279
1206
                                int dotPos = caret.getDot();
1280
                                    try {
1207
                                int newDotPos = formatter.indentNewLine(doc, dotPos);
1281
                                        performLineBreakInsertion(target, insertionOffset, insertionText, breakInsertPosition, caretPosition, reindentBlocks, indenter);
1208
                                caret.setDot(newDotPos);
1282
                                        result[0] = Boolean.TRUE;
1209
1283
                                    } catch (BadLocationException ble) {
1210
                                afterBreak(target, doc, caret, cookie);
1284
                                        LOG.log(Level.FINE, null, ble);
1211
                            } finally {
1285
                                        target.getToolkit().beep();
1212
                                DocumentUtilities.setTypingModification(doc, false);
1286
                                    }
1213
                            }
1287
                                }
1288
                            });
1289
                        } finally {
1290
                            indenter.unlock();
1214
                        }
1291
                        }
1215
                    });
1292
                        
1293
                        if (result[0].booleanValue()) {
1294
                            transaction.afterInsertion();
1295
                        } // else line-break insertion failed
1296
                        
1297
                    }
1216
                } finally {
1298
                } finally {
1217
                    formatter.indentUnlock();
1299
                    transaction.close();
1218
                }
1300
                }
1301
                
1219
            }
1302
            }
1220
        }
1303
        }
1221
1304
1222
      /**
1305
        // --------------------------------------------------------------------
1223
       * Hook called before any changes to the document. The value
1306
        // SPI
1224
       * returned is passed intact to the other hook.
1307
        // --------------------------------------------------------------------
1225
       */
1226
      protected Object beforeBreak(JTextComponent target, BaseDocument doc, Caret caret) { 
1227
	return null;
1228
      }
1229
1308
1230
      /**
1309
        /**
1231
       * Hook called after the enter was inserted and cursor
1310
         * Hook called before any changes to the document. The value
1232
       * repositioned. *data* is the object returned previously by
1311
         * returned is passed intact to the other hook.
1233
       * *beforeBreak* hook. By default null.
1312
         * 
1234
       */
1313
         * @deprecated Please use Typing Hooks instead, for details see
1235
      protected void afterBreak(JTextComponent target, BaseDocument doc, Caret caret, Object data) {
1314
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1236
      }
1315
         */
1237
    }
1316
        protected Object beforeBreak(JTextComponent target, BaseDocument doc, Caret caret) {
1317
            return null;
1318
        }
1238
1319
1239
    @EditorActionRegistration(name = splitLineAction)
1320
        /**
1321
         * Hook called after the enter was inserted and cursor
1322
         * repositioned.
1323
         *
1324
         * @param data the object returned from previously called 
1325
         * {@link #beforeBreak(javax.swing.text.JTextComponent, org.netbeans.editor.BaseDocument, javax.swing.text.Caret)} hook.
1326
         * By default <code>null</code>.
1327
         * 
1328
         * @deprecated Please use Typing Hooks instead, for details see
1329
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1330
         */
1331
        protected void afterBreak(JTextComponent target, BaseDocument doc, Caret caret, Object data) {
1332
        }
1333
        
1334
        // --------------------------------------------------------------------
1335
        // Private implementation
1336
        // --------------------------------------------------------------------
1337
1338
        private void performLineBreakInsertion(
1339
                JTextComponent target, 
1340
                int insertionOffset, 
1341
                String insertionText, 
1342
                int breakInsertPosition, 
1343
                int caretPosition, 
1344
                int [] reindentBlocks,
1345
                Indent indenter) throws BadLocationException
1346
        {
1347
            BaseDocument doc = (BaseDocument) target.getDocument();
1348
            DocumentUtilities.setTypingModification(doc, true);
1349
            try {
1350
                target.replaceSelection(""); // NOI18N
1351
                Caret caret = target.getCaret();
1352
                Object cookie = beforeBreak(target, doc, caret);
1353
1354
                // insert new line, caret moves to the new line
1355
                int dotPos = caret.getDot();
1356
                assert dotPos == insertionOffset : "dotPos=" + dotPos + " != " + "insertionOffset=" + insertionOffset; //NOI18N
1357
//                doc.insertString(dotPos, "\n", null); //NOI18N
1358
//                dotPos++;
1359
                doc.insertString(dotPos, insertionText, null);
1360
                dotPos += caretPosition != -1 ? caretPosition :
1361
                          breakInsertPosition != -1 ? breakInsertPosition + 1 :
1362
                          insertionText.indexOf('\n') + 1; //NOI18N
1363
1364
                // reindent the new line
1365
                Position newDotPos = doc.createPosition(dotPos);
1366
                if (reindentBlocks != null && reindentBlocks.length > 0) {
1367
                    for(int i = 0; i < reindentBlocks.length / 2; i++) {
1368
                        int startOffset = insertionOffset + reindentBlocks[2 * i];
1369
                        int endOffset = insertionOffset + reindentBlocks[2 * i + 1];
1370
                        indenter.reindent(startOffset, endOffset);
1371
                    }
1372
                } else {
1373
                    indenter.reindent(dotPos);
1374
                }
1375
1376
                // adjust the caret
1377
                caret.setDot(newDotPos.getOffset());
1378
1379
                afterBreak(target, doc, caret, cookie);
1380
            } finally {
1381
                DocumentUtilities.setTypingModification(doc, false);
1382
            }
1383
        }
1384
        
1385
        private int computeInsertionOffset(Caret caret) {
1386
            if (Utilities.isSelectionShowing(caret)) {
1387
                return Math.min(caret.getMark(), caret.getDot());
1388
            } else {
1389
                return caret.getDot();
1390
            }
1391
        }
1392
        
1393
    } // End of InsertBreakAction class
1394
1395
    @EditorActionRegistration(name = splitLineAction)    
1240
    public static class SplitLineAction extends LocalBaseAction {
1396
    public static class SplitLineAction extends LocalBaseAction {
1241
1397
1242
        static final long serialVersionUID =7966576342334158659L;
1398
        static final long serialVersionUID =7966576342334158659L;
Lines 1255-1278 Link Here
1255
                final BaseDocument doc = (BaseDocument)target.getDocument();
1411
                final BaseDocument doc = (BaseDocument)target.getDocument();
1256
                final Caret caret = target.getCaret();
1412
                final Caret caret = target.getCaret();
1257
1413
1258
                final Formatter formatter = doc.getFormatter();
1414
                final Indent formatter = Indent.get(doc);
1259
                formatter.indentLock();
1415
                formatter.lock();
1260
                try {
1416
                try {
1261
                    doc.runAtomicAsUser (new Runnable () {
1417
                    doc.runAtomicAsUser (new Runnable () {
1262
                        public void run () {
1418
                        public void run () {
1263
                            DocumentUtilities.setTypingModification(doc, true);
1419
                            DocumentUtilities.setTypingModification(doc, true);
1264
                            try{
1420
                            try{
1265
                                target.replaceSelection("");
1421
                                target.replaceSelection(""); //NOI18N
1266
                                final int dotPos = caret.getDot();      // dot stays where it was
1422
1267
                                formatter.indentNewLine(doc, dotPos);   // newline
1423
                                // insert new line, caret stays where it is
1424
                                int dotPos = caret.getDot();
1425
                                doc.insertString(dotPos, "\n", null); //NOI18N
1426
1427
                                // reindent the new line
1428
                                formatter.reindent(dotPos + 1);   // newline
1429
1430
                                // make sure the caret stays on its original position
1268
                                caret.setDot(dotPos);
1431
                                caret.setDot(dotPos);
1432
                            } catch (BadLocationException ble) {
1433
                                LOG.log(Level.WARNING, null, ble);
1269
                            } finally {
1434
                            } finally {
1270
                                DocumentUtilities.setTypingModification(doc, false);
1435
                                DocumentUtilities.setTypingModification(doc, false);
1271
                            }
1436
                            }
1272
                        }
1437
                        }
1273
                    });
1438
                    });
1274
                } finally {
1439
                } finally {
1275
                    formatter.indentUnlock();
1440
                    formatter.unlock();
1276
                }
1441
                }
1277
            }
1442
            }
1278
        }
1443
        }
Lines 1300-1311 Link Here
1300
                doc.runAtomicAsUser (new Runnable () {
1465
                doc.runAtomicAsUser (new Runnable () {
1301
                    public void run () {
1466
                    public void run () {
1302
                        DocumentUtilities.setTypingModification(doc, true);
1467
                        DocumentUtilities.setTypingModification(doc, true);
1303
                        Formatter.pushFormattingContextDocument(doc);
1304
                        try {
1468
                        try {
1305
                        if (Utilities.isSelectionShowing(caret)) { // block selected
1469
                        if (Utilities.isSelectionShowing(caret)) { // block selected
1306
                            try {
1470
                            try {
1307
                                doc.getFormatter().changeBlockIndent(doc,
1471
                                changeBlockIndent(doc, target.getSelectionStart(), target.getSelectionEnd(), +1);
1308
                                        target.getSelectionStart(), target.getSelectionEnd(), +1);
1309
                            } catch (GuardedException e) {
1472
                            } catch (GuardedException e) {
1310
                                target.getToolkit().beep();
1473
                                target.getToolkit().beep();
1311
                            } catch (BadLocationException e) {
1474
                            } catch (BadLocationException e) {
Lines 1341-1347 Link Here
1341
                                    // Fix of #32240 - #1 of 2
1504
                                    // Fix of #32240 - #1 of 2
1342
                                    int rowStart = Utilities.getRowStart(doc, dotPos);
1505
                                    int rowStart = Utilities.getRowStart(doc, dotPos);
1343
1506
1344
                                    doc.getFormatter().changeRowIndent(doc, dotPos, indent);
1507
                                    changeRowIndent(doc, dotPos, indent);
1345
1508
1346
                                    // Fix of #32240 - #2 of 2
1509
                                    // Fix of #32240 - #2 of 2
1347
                                    int newDotPos = doc.getOffsetFromVisCol(indent, rowStart);
1510
                                    int newDotPos = doc.getOffsetFromVisCol(indent, rowStart);
Lines 1350-1356 Link Here
1350
                                    }
1513
                                    }
1351
1514
1352
                                } else { // already chars on the line
1515
                                } else { // already chars on the line
1353
                                    doc.getFormatter().insertTabString(doc, dotPos);
1516
                                    insertTabString(doc, dotPos);
1354
1517
1355
                                }
1518
                                }
1356
                            } catch (BadLocationException e) {
1519
                            } catch (BadLocationException e) {
Lines 1358-1364 Link Here
1358
                            }
1521
                            }
1359
                        }
1522
                        }
1360
                        } finally {
1523
                        } finally {
1361
                            Formatter.popFormattingContextDocument(doc);
1362
                            DocumentUtilities.setTypingModification(doc, false);
1524
                            DocumentUtilities.setTypingModification(doc, false);
1363
                        }
1525
                        }
1364
                    }
1526
                    }
Lines 1507-1513 Link Here
1507
        }
1669
        }
1508
    }
1670
    }
1509
1671
1510
    /** Remove previous or next character */
1672
    /** 
1673
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1674
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1675
     */
1511
    public static class DeleteCharAction extends LocalBaseAction {
1676
    public static class DeleteCharAction extends LocalBaseAction {
1512
1677
1513
        protected boolean nextChar;
1678
        protected boolean nextChar;
Lines 1531-1574 Link Here
1531
		final int dot = caret.getDot();
1696
		final int dot = caret.getDot();
1532
		final int mark = caret.getMark();
1697
		final int mark = caret.getMark();
1533
1698
1534
                doc.runAtomicAsUser (new Runnable () {
1699
                if (dot != mark) {
1535
                    public void run () {
1700
                    // remove selection
1536
                    DocumentUtilities.setTypingModification(doc, true);
1701
                    doc.runAtomicAsUser (new Runnable () {
1537
1702
                        public void run () {
1538
                    try {
1703
                            DocumentUtilities.setTypingModification(doc, true);
1539
                        if (dot != mark) { // remove selection
1704
                            try {
1540
                            doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
1705
                                doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
1541
                        } else {
1706
                            } catch (BadLocationException e) {
1542
                            if (nextChar) { // remove next char
1707
                                target.getToolkit().beep();
1543
                                char ch = doc.getChars(dot, 1)[0];
1708
                            } finally {
1544
                                doc.remove(dot, 1);
1709
                                DocumentUtilities.setTypingModification(doc, false);
1545
                                charDeleted(doc, dot, caret, ch);
1546
                            } else { // remove previous char
1547
                                char ch = doc.getChars(dot-1, 1)[0];
1548
                                doc.remove(dot - 1, 1);
1549
                                charBackspaced(doc, dot-1, caret, ch);
1550
                            }
1710
                            }
1551
                        }
1711
                        }
1552
                    } catch (BadLocationException e) {
1712
                    });
1713
                } else {
1714
                    char [] removedChar = null;
1715
                    
1716
                    try {
1717
                        removedChar = nextChar ? 
1718
                        dot < doc.getLength() - 1 ? doc.getChars(dot, 1) : null : 
1719
                        dot > 0 ? doc.getChars(dot - 1, 1) : null;
1720
                    } catch (BadLocationException ble) {
1553
                        target.getToolkit().beep();
1721
                        target.getToolkit().beep();
1554
                    } finally {
1555
                        DocumentUtilities.setTypingModification(doc, false);
1556
                    }
1722
                    }
1723
                    
1724
                    if (removedChar != null) {
1725
                        final String removedText = String.valueOf(removedChar);
1726
                        final DeletedTextInterceptorsManager.Transaction t = DeletedTextInterceptorsManager.getInstance().openTransaction(target, dot, removedText, !nextChar);
1727
                        try {
1728
                            if (!t.beforeRemove()) {
1729
                                final boolean [] result = new boolean [] { false };
1730
                                doc.runAtomicAsUser (new Runnable () {
1731
                                    public void run () {
1732
                                        DocumentUtilities.setTypingModification(doc, true);
1733
                                        try {
1734
                                            if (nextChar) { // remove next char
1735
                                                doc.remove(dot, 1);
1736
                                            } else { // remove previous char
1737
                                                doc.remove(dot - 1, 1);
1738
                                            }
1739
1740
                                            t.textDeleted();
1741
1742
                                            if (nextChar) {
1743
                                                charDeleted(doc, dot, caret, removedText.charAt(0));
1744
                                            } else {
1745
                                                charBackspaced(doc, dot - 1, caret, removedText.charAt(0));
1746
                                            }
1747
1748
                                            result[0] = true;
1749
                                        } catch (BadLocationException e) {
1750
                                            target.getToolkit().beep();
1751
                                        } finally {
1752
                                            DocumentUtilities.setTypingModification(doc, false);
1753
                                        }
1754
                                    }
1755
                                });
1756
1757
                                if (result[0]) {
1758
                                    t.afterRemove();
1759
                                }
1760
                            }
1761
                        } finally {
1762
                            t.close();
1763
                        }
1557
                    }
1764
                    }
1558
                });
1765
                }
1559
            }
1766
            }
1560
        }
1767
        }
1561
1768
1562
      protected void charBackspaced(BaseDocument doc, int dotPos, Caret caret, char ch) 
1769
        /**
1563
	throws BadLocationException
1770
         * @deprecated Please use Typing Hooks instead, for details see
1564
      {
1771
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1565
      }
1772
         */
1566
      
1773
        protected void charBackspaced(BaseDocument doc, int dotPos, Caret caret, char ch) throws BadLocationException {
1567
      protected void charDeleted(BaseDocument doc, int dotPos, Caret caret, char ch) 
1774
        }
1568
	throws BadLocationException
1775
1569
      {
1776
        /**
1570
      }
1777
         * @deprecated Please use Typing Hooks instead, for details see
1571
    }
1778
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1779
         */
1780
        protected void charDeleted(BaseDocument doc, int dotPos, Caret caret, char ch) throws BadLocationException {
1781
        }
1782
    } // End of DeleteCharAction class
1572
1783
1573
    /**
1784
    /**
1574
     * @deprecated this action is no longer used. It is reimplemented in editor.actions module.
1785
     * @deprecated this action is no longer used. It is reimplemented in editor.actions module.
Lines 1734-1743 Link Here
1734
                    LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1945
                    LOG.log(Level.WARNING, "Can't add position to the history of edits.", e); //NOI18N
1735
                }
1946
                }
1736
1947
1737
                final Formatter formatter = doc.getFormatter();
1948
                final Reformat formatter = Reformat.get(doc);
1738
                final boolean formatted = pasteFormatedAction.equals(getValue(Action.NAME));
1949
                final boolean formatted = pasteFormatedAction.equals(getValue(Action.NAME));
1739
                if (formatted) {
1950
                if (formatted) {
1740
                    formatter.reformatLock();
1951
                    formatter.lock();
1741
                }
1952
                }
1742
                try {
1953
                try {
1743
                    doc.runAtomicAsUser (new Runnable () {
1954
                    doc.runAtomicAsUser (new Runnable () {
Lines 1758-1764 Link Here
1758
                            }
1969
                            }
1759
                            int endOffset = caret.getDot();
1970
                            int endOffset = caret.getDot();
1760
                            if (formatted) {
1971
                            if (formatted) {
1761
                                formatter.reformat(doc, startOffset, endOffset);
1972
                                formatter.reformat(startOffset, endOffset);
1762
                            }
1973
                            }
1763
                        } catch (Exception e) {
1974
                        } catch (Exception e) {
1764
                            target.getToolkit().beep();
1975
                            target.getToolkit().beep();
Lines 1769-1840 Link Here
1769
                    });
1980
                    });
1770
                } finally {
1981
                } finally {
1771
                    if (formatted) {
1982
                    if (formatted) {
1772
                        formatter.reformatUnlock();
1983
                        formatter.unlock();
1773
                    }
1984
                    }
1774
                }
1985
                }
1775
            }
1986
            }
1776
        }
1987
        }
1777
1988
1778
      public static void indentBlock(BaseDocument doc, int startOffset, int endOffset)
1989
//      public static void indentBlock(BaseDocument doc, int startOffset, int endOffset)
1779
	throws BadLocationException
1990
//	throws BadLocationException
1780
      {
1991
//      {
1781
	char [] text = doc.getChars(startOffset, endOffset-startOffset);
1992
//	char [] text = doc.getChars(startOffset, endOffset-startOffset);
1782
	String [] lines = toLines(new String(text));
1993
//	String [] lines = toLines(new String(text));
1783
1994
//
1784
	doc.remove(startOffset, endOffset - startOffset);
1995
//	doc.remove(startOffset, endOffset - startOffset);
1785
	//	System.out.println("Lines:\n"); // NOI18N
1996
//	//	System.out.println("Lines:\n"); // NOI18N
1786
	//	for (int j = 0 ; j < lines.length; j++) System.out.println(lines[j] + "<"); // NOI18N
1997
//	//	for (int j = 0 ; j < lines.length; j++) System.out.println(lines[j] + "<"); // NOI18N
1787
1998
//
1788
	int offset = startOffset;
1999
//	int offset = startOffset;
1789
	// handle the full lines
2000
//	// handle the full lines
1790
	for (int i = 0; i < lines.length - 1; i++) {
2001
//	for (int i = 0; i < lines.length - 1; i++) {
1791
	  String indent = getIndentString(doc, offset, lines[i]);
2002
//	  String indent = getIndentString(doc, offset, lines[i]);
1792
	  String fragment = indent + lines[i].trim() + '\n';
2003
//	  String fragment = indent + lines[i].trim() + '\n';
1793
	  //	  System.out.println(fragment + "|"); // NOI18N
2004
//	  //	  System.out.println(fragment + "|"); // NOI18N
1794
	  doc.insertString(offset, fragment, null);
2005
//	  doc.insertString(offset, fragment, null);
1795
	  offset += fragment.length();
2006
//	  offset += fragment.length();
1796
	}
2007
//	}
1797
2008
//
1798
	// the rest just paste without indenting
2009
//	// the rest just paste without indenting
1799
	doc.insertString(offset, lines[lines.length-1], null);
2010
//	doc.insertString(offset, lines[lines.length-1], null);
1800
2011
//
1801
      }
2012
//      }
1802
2013
//
1803
      /** Break string to lines */
2014
//      /** Break string to lines */
1804
      private static String [] toLines(String str) {
2015
//      private static String [] toLines(String str) {
1805
	Vector v = new Vector();
2016
//	Vector v = new Vector();
1806
	int p=0 , p0=0;
2017
//	int p=0 , p0=0;
1807
	for (; p < str.length() ; p++) {
2018
//	for (; p < str.length() ; p++) {
1808
	  if (str.charAt(p) == '\n') {
2019
//	  if (str.charAt(p) == '\n') {
1809
	    v.add(str.substring(p0, p+1));
2020
//	    v.add(str.substring(p0, p+1));
1810
	    p0 = p+1;
2021
//	    p0 = p+1;
1811
	  }
2022
//	  }
1812
	}
2023
//	}
1813
	if (p0 < str.length()) v.add(str.substring(p0, str.length())); else v.add("");
2024
//	if (p0 < str.length()) v.add(str.substring(p0, str.length())); else v.add("");
1814
2025
//
1815
	return (String [])v.toArray(new String [0]);
2026
//	return (String [])v.toArray(new String [0]);
1816
      }
2027
//      }
1817
2028
//
1818
      private static String getIndentString(BaseDocument doc, int startOffset, String str) {
2029
//      private static String getIndentString(BaseDocument doc, int startOffset, String str) {
1819
	try {
2030
//	try {
1820
	  Formatter f = doc.getFormatter();
2031
//	  Formatter f = doc.getFormatter();
1821
	  CharArrayWriter cw = new CharArrayWriter();
2032
//	  CharArrayWriter cw = new CharArrayWriter();
1822
	  Writer w = f.createWriter(doc, startOffset, cw);
2033
//	  Writer w = f.createWriter(doc, startOffset, cw);
1823
	  w.write(str, 0, str.length());
2034
//	  w.write(str, 0, str.length());
1824
	  w.close();
2035
//	  w.close();
1825
	  String out = new String(cw.toCharArray());
2036
//	  String out = new String(cw.toCharArray());
1826
	  int i = 0;
2037
//	  int i = 0;
1827
	  for (; i < out.length(); i++) {
2038
//	  for (; i < out.length(); i++) {
1828
	    if (out.charAt(i) != ' ' && out.charAt(i) != '\t') break;
2039
//	    if (out.charAt(i) != ' ' && out.charAt(i) != '\t') break;
1829
	  }
2040
//	  }
1830
	  //	  System.out.println(out+"|"); // NOI18N
2041
//	  //	  System.out.println(out+"|"); // NOI18N
1831
	  //	  System.out.println(out.substring(0,i)+"^"); // NOI18N
2042
//	  //	  System.out.println(out.substring(0,i)+"^"); // NOI18N
1832
2043
//
1833
	  return out.substring(0, i);
2044
//	  return out.substring(0, i);
1834
	} catch (java.io.IOException e) {
2045
//	} catch (java.io.IOException e) {
1835
	  return "";
2046
//	  return "";
1836
	}
2047
//	}
1837
      }
2048
//      }
1838
    }
2049
    }
1839
2050
1840
2051
Lines 2875-2878 Link Here
2875
3086
2876
    }
3087
    }
2877
3088
3089
3090
    /** Modify the line to move the text starting at dotPos one tab
3091
     * column to the right.  Whitespace preceeding dotPos may be
3092
     * replaced by a TAB character if tabs expanding is on.
3093
     * @param doc document to operate on
3094
     * @param dotPos insertion point
3095
     */
3096
    static void insertTabString (final BaseDocument doc, final int dotPos) throws BadLocationException {
3097
        final BadLocationException[] badLocationExceptions = new BadLocationException [1];
3098
        doc.runAtomic (new Runnable () {
3099
            public void run () {
3100
                try {
3101
                    // Determine first white char before dotPos
3102
                    int rsPos = Utilities.getRowStart(doc, dotPos);
3103
                    int startPos = Utilities.getFirstNonWhiteBwd(doc, dotPos, rsPos);
3104
                    startPos = (startPos >= 0) ? (startPos + 1) : rsPos;
3105
3106
                    int startCol = Utilities.getVisualColumn(doc, startPos);
3107
                    int endCol = Utilities.getNextTabColumn(doc, dotPos);
3108
                    Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
3109
                    String tabStr = Analyzer.getWhitespaceString(
3110
                            startCol, endCol,
3111
                            prefs.getBoolean(SimpleValueNames.EXPAND_TABS, EditorPreferencesDefaults.defaultExpandTabs),
3112
                            prefs.getInt(SimpleValueNames.TAB_SIZE, EditorPreferencesDefaults.defaultTabSize));
3113
3114
                    // Search for the first non-common char
3115
                    char[] removeChars = doc.getChars(startPos, dotPos - startPos);
3116
                    int ind = 0;
3117
                    while (ind < removeChars.length && removeChars[ind] == tabStr.charAt(ind)) {
3118
                        ind++;
3119
                    }
3120
3121
                    startPos += ind;
3122
                    doc.remove(startPos, dotPos - startPos);
3123
                    doc.insertString(startPos, tabStr.substring(ind), null);
3124
                } catch (BadLocationException ex) {
3125
                    badLocationExceptions [0] = ex;
3126
                }
3127
            }
3128
        });
3129
        if (badLocationExceptions[0] != null)
3130
            throw badLocationExceptions [0];
3131
    }
3132
3133
    /** Change the indent of the given row. Document is atomically locked
3134
     * during this operation.
3135
     */
3136
    static void changeRowIndent (final BaseDocument doc, final int pos, final int newIndent) throws BadLocationException {
3137
        final BadLocationException[] badLocationExceptions = new BadLocationException [1];
3138
        doc.runAtomic (new Runnable () {
3139
            public void run () {
3140
                try {
3141
                    int indent = newIndent < 0 ? 0 : newIndent;
3142
                    int firstNW = Utilities.getRowFirstNonWhite(doc, pos);
3143
                    if (firstNW == -1) { // valid first non-blank
3144
                        firstNW = Utilities.getRowEnd(doc, pos);
3145
                    }
3146
                    int replacePos = Utilities.getRowStart(doc, pos);
3147
                    int removeLen = firstNW - replacePos;
3148
                    CharSequence removeText = DocumentUtilities.getText(doc, replacePos, removeLen);
3149
                    String newIndentText = IndentUtils.createIndentString(doc, indent);
3150
                    if (CharSequenceUtilities.startsWith(newIndentText, removeText)) {
3151
                        // Skip removeLen chars at start
3152
                        newIndentText = newIndentText.substring(removeLen);
3153
                        replacePos += removeLen;
3154
                        removeLen = 0;
3155
                    } else if (CharSequenceUtilities.endsWith(newIndentText, removeText)) {
3156
                        // Skip removeLen chars at the end
3157
                        newIndentText = newIndentText.substring(0, newIndentText.length() - removeLen);
3158
                        removeLen = 0;
3159
                    }
3160
3161
                    if (removeLen != 0) {
3162
                        doc.remove(replacePos, removeLen);
3163
                    }
3164
3165
                    doc.insertString(replacePos, newIndentText, null);
3166
                } catch (BadLocationException ex) {
3167
                    badLocationExceptions [0] = ex;
3168
                }
3169
            }
3170
        });
3171
        if (badLocationExceptions[0] != null)
3172
            throw badLocationExceptions [0];
3173
    }
3174
3175
    /** Increase/decrease indentation of the block of the code. Document
3176
    * is atomically locked during the operation.
3177
    * @param doc document to operate on
3178
    * @param startPos starting line position
3179
    * @param endPos ending line position
3180
    * @param shiftCnt positive/negative count of shiftwidths by which indentation
3181
    *   should be shifted right/left
3182
    */
3183
    static void changeBlockIndent (final BaseDocument doc, final int startPos, final int endPos,
3184
                                  final int shiftCnt) throws BadLocationException {
3185
        GuardedDocument gdoc = (doc instanceof GuardedDocument)
3186
                               ? (GuardedDocument)doc : null;
3187
        if (gdoc != null){
3188
            for (int i = startPos; i<endPos; i++){
3189
                if (gdoc.isPosGuarded(i)){
3190
                    java.awt.Toolkit.getDefaultToolkit().beep();
3191
                    return;
3192
                }
3193
            }
3194
        }
3195
3196
        final BadLocationException[] badLocationExceptions = new BadLocationException [1];
3197
        doc.runAtomic (new Runnable () {
3198
            public void run () {
3199
                try {
3200
                    int indentDelta = shiftCnt * doc.getShiftWidth();
3201
                    int end = (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) ?
3202
                        endPos - 1 : endPos;
3203
3204
                    int pos = Utilities.getRowStart(doc, startPos );
3205
                    for (int lineCnt = Utilities.getRowCount(doc, startPos, end);
3206
                            lineCnt > 0; lineCnt--
3207
                        ) {
3208
                        int indent = Utilities.getRowIndent(doc, pos);
3209
                        if (Utilities.isRowWhite(doc, pos)) {
3210
                            indent = -indentDelta; // zero indentation for white line
3211
                        }
3212
                        changeRowIndent(doc, pos, Math.max(indent + indentDelta, 0));
3213
                        pos = Utilities.getRowStart(doc, pos, +1);
3214
                    }
3215
                } catch (BadLocationException ex) {
3216
                    badLocationExceptions [0] = ex;
3217
                }
3218
            }
3219
        });
3220
        if (badLocationExceptions[0] != null)
3221
            throw badLocationExceptions [0];
3222
    }
3223
3224
    /** Shift line either left or right */
3225
    static void shiftLine(BaseDocument doc, int dotPos, boolean right) throws BadLocationException {
3226
        int ind = doc.getShiftWidth();
3227
        if (!right) {
3228
            ind = -ind;
3229
        }
3230
3231
        if (Utilities.isRowWhite(doc, dotPos)) {
3232
            ind += Utilities.getVisualColumn(doc, dotPos);
3233
        } else {
3234
            ind += Utilities.getRowIndent(doc, dotPos);
3235
        }
3236
        ind = Math.max(ind, 0);
3237
        changeRowIndent(doc, dotPos, ind);
3238
    }
2878
}
3239
}
(-)a/editor.lib/src/org/netbeans/editor/Utilities.java (-17 / +27 lines)
Lines 58-63 Link Here
58
import java.util.Set;
58
import java.util.Set;
59
import java.util.logging.Level;
59
import java.util.logging.Level;
60
import java.util.logging.Logger;
60
import java.util.logging.Logger;
61
import java.util.prefs.Preferences;
61
import javax.swing.SwingUtilities;
62
import javax.swing.SwingUtilities;
62
import javax.swing.Action;
63
import javax.swing.Action;
63
import javax.swing.InputMap;
64
import javax.swing.InputMap;
Lines 79-90 Link Here
79
import javax.swing.plaf.TextUI;
80
import javax.swing.plaf.TextUI;
80
import javax.swing.text.AbstractDocument;
81
import javax.swing.text.AbstractDocument;
81
import javax.swing.text.Element;
82
import javax.swing.text.Element;
83
import javax.swing.text.Position;
82
import javax.swing.text.View;
84
import javax.swing.text.View;
83
import org.netbeans.api.editor.EditorRegistry;
85
import org.netbeans.api.editor.EditorRegistry;
84
import org.netbeans.api.editor.mimelookup.MimeLookup;
86
import org.netbeans.api.editor.mimelookup.MimeLookup;
87
import org.netbeans.api.editor.settings.SimpleValueNames;
85
import org.netbeans.lib.editor.util.CharSequenceUtilities;
88
import org.netbeans.lib.editor.util.CharSequenceUtilities;
86
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
89
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
90
import org.netbeans.modules.editor.indent.api.Reformat;
91
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
87
import org.netbeans.modules.editor.lib.drawing.DrawEngineDocView;
92
import org.netbeans.modules.editor.lib.drawing.DrawEngineDocView;
93
import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
88
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
94
import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
89
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
95
import org.netbeans.modules.editor.lib2.highlighting.HighlightingManager;
90
import org.netbeans.modules.editor.lib2.view.DocumentView;
96
import org.netbeans.modules.editor.lib2.view.DocumentView;
Lines 984-1009 Link Here
984
     * @param endOffset offset at which the formatting ends
990
     * @param endOffset offset at which the formatting ends
985
     * @return length of the reformatted code
991
     * @return length of the reformatted code
986
     */
992
     */
987
    public static int reformat (final BaseDocument doc, final int startOffset, final int endOffset)
993
    public static int reformat (final BaseDocument doc, final int startOffset, final int endOffset) throws BadLocationException {
988
    throws BadLocationException {
994
        final Reformat formatter = Reformat.get(doc);
989
        final Formatter formatter = doc.getFormatter();
995
        formatter.lock();
990
        formatter.reformatLock();
991
        try {
996
        try {
992
            final Object[] result = new Object [1];
997
            final Object[] result = new Object[1];
993
            doc.runAtomicAsUser (new Runnable () {
998
            doc.runAtomicAsUser(new Runnable() {
994
                public @Override void run () {
999
                public @Override void run() {
995
                    try {
1000
                    try {
996
                        result [0] = formatter.reformat (doc, startOffset, endOffset);
1001
                        Position endPos = doc.createPosition(endOffset);
1002
                        formatter.reformat(startOffset, endOffset);
1003
                        result[0] = Math.max(endPos.getOffset() - startOffset, 0);
997
                    } catch (BadLocationException ex) {
1004
                    } catch (BadLocationException ex) {
998
                        result [0] = ex;
1005
                        result[0] = ex;
999
                    }
1006
                    }
1000
                }
1007
                }
1001
            });
1008
            });
1002
            if (result [0] instanceof BadLocationException)
1009
            if (result[0] instanceof BadLocationException) {
1003
                throw (BadLocationException) result [0];
1010
                throw (BadLocationException) result[0];
1004
            return (Integer) result [0];
1011
            } else {
1012
                return (Integer) result[0];
1013
            }
1005
        } finally {
1014
        } finally {
1006
            formatter.reformatUnlock();
1015
            formatter.unlock();
1007
        }
1016
        }
1008
    }
1017
    }
1009
1018
Lines 1043-1052 Link Here
1043
    public static String getTabInsertString(BaseDocument doc, int offset)
1052
    public static String getTabInsertString(BaseDocument doc, int offset)
1044
    throws BadLocationException {
1053
    throws BadLocationException {
1045
        int col = getVisualColumn(doc, offset);
1054
        int col = getVisualColumn(doc, offset);
1046
        Formatter f = doc.getFormatter();
1055
        Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
1047
        boolean expandTabs = f.expandTabs();
1056
        boolean expandTabs = prefs.getBoolean(SimpleValueNames.EXPAND_TABS, EditorPreferencesDefaults.defaultExpandTabs);
1048
        if (expandTabs) {
1057
        if (expandTabs) {
1049
            int spacesPerTab = f.getSpacesPerTab();
1058
            int spacesPerTab = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
1050
            int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
1059
            int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
1051
            return new String(Analyzer.getSpacesBuffer(len), 0, len);
1060
            return new String(Analyzer.getSpacesBuffer(len), 0, len);
1052
        } else { // insert pure tab
1061
        } else { // insert pure tab
Lines 1062-1068 Link Here
1062
    public static int getNextTabColumn(BaseDocument doc, int offset)
1071
    public static int getNextTabColumn(BaseDocument doc, int offset)
1063
    throws BadLocationException {
1072
    throws BadLocationException {
1064
        int col = getVisualColumn(doc, offset);
1073
        int col = getVisualColumn(doc, offset);
1065
        int tabSize = doc.getFormatter().getSpacesPerTab();
1074
        Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
1075
        int tabSize = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
1066
        return (col + tabSize) / tabSize * tabSize;
1076
        return (col + tabSize) / tabSize * tabSize;
1067
    }
1077
    }
1068
1078
(-)a/editor.lib/src/org/netbeans/editor/ext/ExtKit.java (-61 / +20 lines)
Lines 46-52 Link Here
46
46
47
import java.awt.Rectangle;
47
import java.awt.Rectangle;
48
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionEvent;
49
import java.io.IOException;
50
import java.util.ArrayList;
49
import java.util.ArrayList;
51
import java.util.StringTokenizer;
50
import java.util.StringTokenizer;
52
import java.util.prefs.Preferences;
51
import java.util.prefs.Preferences;
Lines 67-73 Link Here
67
import org.netbeans.editor.Utilities;
66
import org.netbeans.editor.Utilities;
68
import org.netbeans.editor.BaseDocument;
67
import org.netbeans.editor.BaseDocument;
69
import org.netbeans.editor.SyntaxSupport;
68
import org.netbeans.editor.SyntaxSupport;
70
import org.netbeans.editor.Formatter;
71
import org.netbeans.lib.editor.util.CharSequenceUtilities;
69
import org.netbeans.lib.editor.util.CharSequenceUtilities;
72
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
70
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
73
import org.netbeans.modules.editor.lib.NavigationHistory;
71
import org.netbeans.modules.editor.lib.NavigationHistory;
Lines 370-376 Link Here
370
        
368
        
371
        protected final void debugPopupMenuItem(JMenuItem item, Action action) {
369
        protected final void debugPopupMenuItem(JMenuItem item, Action action) {
372
            if (debugPopupMenu) {
370
            if (debugPopupMenu) {
373
                StringBuffer sb = new StringBuffer("POPUP: "); // NOI18N
371
                StringBuilder sb = new StringBuilder("POPUP: "); // NOI18N
374
                if (item != null) {
372
                if (item != null) {
375
                    sb.append('"'); //NOI18N
373
                    sb.append('"'); //NOI18N
376
                    sb.append(item.getText());
374
                    sb.append(item.getText());
Lines 1043-1049 Link Here
1043
    }
1041
    }
1044
1042
1045
1043
1046
    // Completion customized actions
1044
    /** 
1045
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1046
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1047
     */
1047
//    @EditorActionRegistration(
1048
//    @EditorActionRegistration(
1048
//            name = defaultKeyTypedAction,
1049
//            name = defaultKeyTypedAction,
1049
//            shortDescription = editorBundleHash + defaultKeyTypedAction
1050
//            shortDescription = editorBundleHash + defaultKeyTypedAction
Lines 1081-1113 Link Here
1081
            }
1082
            }
1082
        }
1083
        }
1083
1084
1084
        /** Check the characters that should cause reindenting the line. */
1085
        // --------------------------------------------------------------------
1086
        // SPI
1087
        // --------------------------------------------------------------------
1088
1089
        /** 
1090
         * Check the characters that should cause reindenting the line. 
1091
         * 
1092
         * @deprecated Please use <a href="@org-netbeans-modules-editor-indent@/org/netbeans/modules/editor/indent/spi/AutomatedIndenting.html">AutomatedIndentig</a>
1093
         *   or Typing Hooks instead, for details see
1094
         *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1095
         */
1085
        protected void checkIndentHotChars(JTextComponent target, String typedText) {
1096
        protected void checkIndentHotChars(JTextComponent target, String typedText) {
1086
            BaseDocument doc = Utilities.getDocument(target);
1087
            if (doc != null) {
1088
                Caret caret = target.getCaret();
1089
                Formatter f = doc.getFormatter();
1090
                if (f instanceof ExtFormatter) {
1091
                    ExtFormatter ef = (ExtFormatter)f;
1092
                    int[] fmtBlk = ef.getReformatBlock(target, typedText);
1093
1094
                    if (fmtBlk != null) {
1095
                        try {
1096
                            fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]);
1097
                            fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]);
1098
1099
                            //this was the of #18922, that causes the bug #20198
1100
                            //ef.reformat(doc, fmtBlk[0], fmtBlk[1]);
1101
1102
                            //bugfix of the bug #20198. Bug #18922 is fixed too as well as #6968
1103
                            ef.reformat(doc, fmtBlk[0], fmtBlk[1], true);
1104
                            
1105
                        } catch (BadLocationException e) {
1106
                        } catch (IOException e) {
1107
                        }
1108
                    }
1109
                }
1110
            }
1111
        }
1097
        }
1112
1098
1113
1099
Lines 1117-1153 Link Here
1117
         *   <a href="@org-netbeans-modules-editor-completion@/overview-summary.html">Editor Code Completion</a>.
1103
         *   <a href="@org-netbeans-modules-editor-completion@/overview-summary.html">Editor Code Completion</a>.
1118
         */
1104
         */
1119
        protected void checkCompletion(JTextComponent target, String typedText) {
1105
        protected void checkCompletion(JTextComponent target, String typedText) {
1120
// XXX: remove
1121
//            Completion completion = ExtUtilities.getCompletion(target);
1122
//
1123
//            BaseDocument doc = (BaseDocument)target.getDocument();
1124
//            ExtSyntaxSupport extSup = (ExtSyntaxSupport)doc.getSyntaxSupport();
1125
//            
1126
//            if (completion != null && typedText.length() > 0) {
1127
//                if( !completion.isPaneVisible() ) {
1128
//                    if (completion.isAutoPopupEnabled()) {
1129
//                        int result = extSup.checkCompletion( target, typedText, false );
1130
//                        if ( result == ExtSyntaxSupport.COMPLETION_POPUP ) {
1131
//                            completion.popup(true);
1132
//                        } else if ( result == ExtSyntaxSupport.COMPLETION_CANCEL ) {
1133
//                            completion.cancelRequest();
1134
//                        }
1135
//                    }
1136
//                } else {
1137
//                    int result = extSup.checkCompletion( target, typedText, true );
1138
//                    switch( result ) {
1139
//                        case ExtSyntaxSupport.COMPLETION_HIDE:
1140
//                            completion.setPaneVisible(false);
1141
//                            break;
1142
//                        case ExtSyntaxSupport.COMPLETION_REFRESH:
1143
//                            completion.refresh(false);
1144
//                            break;
1145
//                        case ExtSyntaxSupport.COMPLETION_POST_REFRESH:
1146
//                            completion.refresh(true);
1147
//                            break;
1148
//                    }
1149
//                }
1150
//            }
1151
        }
1106
        }
1152
    }
1107
    }
1153
1108
Lines 1225-1230 Link Here
1225
1180
1226
    }
1181
    }
1227
1182
1183
    /** 
1184
     * @deprecated Please do not subclass this class. Use Typing Hooks instead, for details see
1185
     *   <a href="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
1186
     */
1228
  public static class ExtDeleteCharAction extends DeleteCharAction {
1187
  public static class ExtDeleteCharAction extends DeleteCharAction {
1229
1188
1230
    public ExtDeleteCharAction(String nm, boolean nextChar) {
1189
    public ExtDeleteCharAction(String nm, boolean nextChar) {
(-)a/editor.lib/src/org/netbeans/modules/editor/lib/FormatterOverride.java (-69 lines)
Lines 1-69 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 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
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.modules.editor.lib;
46
47
import javax.swing.text.Document;
48
import org.netbeans.editor.Formatter;
49
50
/**
51
 * Class to be searched in lookup that can override a formatter for the given document.
52
 * <br/>
53
 * It is a private contract between editor/lib and editor/indent.
54
 *
55
 * @author Miloslav Metelka
56
 */
57
public interface FormatterOverride {
58
59
    /**
60
     * Possibly override the default formatter used for the given document.
61
     * 
62
     * @param doc non-null document for which the formatter is being searched.
63
     * @param defaultFormatter default formatter found by the infrastructure
64
     *   or null if there is none.
65
     * @return overriden formatter or the default formatter passed as the argument.
66
     */
67
    Formatter getFormatter(Document doc, Formatter defaultFormatter);
68
69
}
(-)a/editor.lib2/apichanges.xml (+15 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
        <change id="typinghooks-spi-added">
111
            <summary>Typing Hooks SPI added</summary>
112
            <version major="1" minor="31"/>
113
            <date day="5" month="8" year="2010"/>
114
            <author login="vstejskal"/>
115
            <compatibility binary="compatible" source="compatible" semantic="compatible" addition="yes"/>
116
            <description>
117
                Typing Hooks SPI allows interception of various key typed events
118
                that are processed in the editor. The SPI is a replacement for
119
                subclassing editor actions such as <code>DefaultKeyTypedAction</code>,
120
                <code>InsertBreakAction</code>, etc.
121
            </description>
122
            <issue number="152655"/>
123
        </change>
124
110
        <change id="added-line-column-based-dialog-bindings">
125
        <change id="added-line-column-based-dialog-bindings">
111
            <summary>Adding line/column based dialog bindings</summary>
126
            <summary>Adding line/column based dialog bindings</summary>
112
            <version major="1" minor="24"/>
127
            <version major="1" minor="24"/>
(-)a/editor.lib2/arch.xml (-3 / +19 lines)
Lines 80-87 Link Here
80
80
81
<ul>
81
<ul>
82
<li>
82
<li>
83
    <api name="editor-code-generator" group="java" type="export" category="official" url="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/codegen/package-summary.html">Code Generator SPI</api>
84
</li>    
85
<li>
83
    <api name="editor-highlighting" group="java" type="export" category="official" url="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/highlighting/package-summary.html">Highlighting SPI</api>
86
    <api name="editor-highlighting" group="java" type="export" category="official" url="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/highlighting/package-summary.html">Highlighting SPI</api>
84
</li>    
87
</li>    
88
<li>
89
    <api name="editor-typing-hooks" group="java" type="export" category="official" url="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/typinghooks/package-summary.html">Typing Hooks SPI</api>
90
</li>    
85
</ul>
91
</ul>
86
</answer>
92
</answer>
87
93
Lines 120-128 Link Here
120
        </question>
126
        </question>
121
-->
127
-->
122
<answer id="arch-usecases">
128
<answer id="arch-usecases">
123
    At the moment the Editor Library 2 module contains only the Highlighting SPI,
129
    At the moment the Editor Library 2 module contains three distinct SPIs. Each SPI lives
124
    which use cases can be found in the <code>org.netbeans.spi.editor.highlighting</code> package 
130
    in its own package and the usecases can be found in the packages overview.
125
    <a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/highlighting/package-summary.html#usecases">overview</a>.
131
    <ul>
132
    <li>Code Generator SPI -
133
        <a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/codegen/package-summary.html#usecases">org.netbeans.spi.editor.codegen</a>
134
    </li>
135
    <li>Highlighting SPI -
136
        <a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/highlighting/package-summary.html#usecases">org.netbeans.spi.editor.highlighting</a>
137
    </li>
138
    <li>Typing Hooks SPI -
139
        <a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/typinghooks/package-summary.html#usecases">org.netbeans.spi.editor.typinghooks</a>
140
    </li>
141
    </ul>
126
</answer>
142
</answer>
127
143
128
144
(-)a/editor.lib2/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor.lib2/1
2
OpenIDE-Module: org.netbeans.modules.editor.lib2/1
3
OpenIDE-Module-Implementation-Version: 2
3
OpenIDE-Module-Implementation-Version: 3
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml
6
OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
6
OpenIDE-Module-Needs: org.netbeans.modules.editor.actions
(-)a/editor.lib2/nbproject/project.properties (-1 / +1 lines)
Lines 43-49 Link Here
43
is.autoload=true
43
is.autoload=true
44
javac.source=1.6
44
javac.source=1.6
45
javac.compilerargs=-Xlint:unchecked
45
javac.compilerargs=-Xlint:unchecked
46
spec.version.base=1.30.0
46
spec.version.base=1.31.0
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
49
javadoc.apichanges=${basedir}/apichanges.xml
(-)a/editor.lib2/nbproject/project.xml (+1 lines)
Lines 181-186 Link Here
181
                <package>org.netbeans.spi.editor.codegen</package>
181
                <package>org.netbeans.spi.editor.codegen</package>
182
                <package>org.netbeans.spi.editor.highlighting</package>
182
                <package>org.netbeans.spi.editor.highlighting</package>
183
                <package>org.netbeans.spi.editor.highlighting.support</package>
183
                <package>org.netbeans.spi.editor.highlighting.support</package>
184
                <package>org.netbeans.spi.editor.typinghooks</package>
184
            </public-packages>
185
            </public-packages>
185
        </data>
186
        </data>
186
    </configuration>
187
    </configuration>
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/DeletedTextInterceptorsManager.java (+215 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.editor.lib2.typinghooks;
44
45
import java.lang.ref.Reference;
46
import java.lang.ref.SoftReference;
47
import java.util.Collection;
48
import java.util.HashSet;
49
import java.util.List;
50
import java.util.Map;
51
import java.util.WeakHashMap;
52
import java.util.logging.Level;
53
import java.util.logging.Logger;
54
import javax.swing.text.Document;
55
import javax.swing.text.JTextComponent;
56
import org.netbeans.api.editor.mimelookup.MimeLookup;
57
import org.netbeans.api.editor.mimelookup.MimePath;
58
import org.netbeans.api.lexer.TokenHierarchy;
59
import org.netbeans.api.lexer.TokenSequence;
60
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
61
import org.netbeans.spi.editor.typinghooks.DeletedTextInterceptor;
62
63
/**
64
 *
65
 * @author vita
66
 */
67
public final class DeletedTextInterceptorsManager {
68
69
    public static DeletedTextInterceptorsManager getInstance() {
70
        if (instance == null) {
71
            instance = new DeletedTextInterceptorsManager();
72
        }
73
        return instance;
74
    }
75
76
    public Transaction openTransaction(JTextComponent c, int offset, String removedText, boolean backwardDelete) {
77
        synchronized (this) {
78
            if (transaction == null) {
79
                transaction = new Transaction(c, offset, removedText, backwardDelete);
80
                return transaction;
81
            } else {
82
                throw new IllegalStateException("Too many transactions; only one at a time is allowed!"); //NOI18N
83
            }
84
        }
85
    }
86
87
    public final class Transaction {
88
89
        public boolean beforeRemove() {
90
            for(DeletedTextInterceptor i : interceptors) {
91
                try {
92
                    if (i.beforeRemove(context)) {
93
                        return true;
94
                    }
95
                } catch (Exception e) {
96
                    LOG.log(Level.INFO, "DeletedTextInterceptor crashed in beforeRemove(): " + i, e); //NOI18N
97
                }
98
            }
99
100
            phase++;
101
            return false;
102
        }
103
104
        public void textDeleted() {
105
            Object [] data = null;
106
107
            for(DeletedTextInterceptor i : interceptors) {
108
                try {
109
                    i.remove(context);
110
                } catch (Exception e) {
111
                    LOG.log(Level.INFO, "DeletedTextInterceptor crashed in remove(): " + i, e); //NOI18N
112
                    continue;
113
                }
114
            }
115
116
            phase++;
117
        }
118
119
        public void afterRemove() {
120
            for(DeletedTextInterceptor i : interceptors) {
121
                try {
122
                    i.afterRemove(context);
123
                } catch (Exception e) {
124
                    LOG.log(Level.INFO, "DeletedTextInterceptor crashed in afterRemove(): " + i, e); //NOI18N
125
                }
126
            }
127
128
            phase++;
129
        }
130
131
        public void close() {
132
            if (phase < 3) {
133
                for(DeletedTextInterceptor i : interceptors) {
134
                    try {
135
                        i.cancelled(context);
136
                    } catch (Exception e) {
137
                        LOG.log(Level.INFO, "DeletedTextInterceptor crashed in cancelled(): " + i, e); //NOI18N
138
                    }
139
                }
140
            }
141
142
            synchronized (DeletedTextInterceptorsManager.this) {
143
                transaction = null;
144
            }
145
        }
146
147
        // ------------------------------------------------------------------------
148
        // Private implementation
149
        // ------------------------------------------------------------------------
150
151
        private final DeletedTextInterceptor.Context context;
152
        private final Collection<? extends DeletedTextInterceptor> interceptors;
153
        private int phase = 0;
154
155
        private Transaction(JTextComponent c, int offset, String removedText, boolean backwardDelete) {
156
            this.context = TypingHooksSpiAccessor.get().createDtiContext(c, offset, removedText, backwardDelete);
157
            this.interceptors = getInterceptors(c.getDocument(), offset);
158
        }
159
    } // End of Transaction class
160
161
    // ------------------------------------------------------------------------
162
    // Private implementation
163
    // ------------------------------------------------------------------------
164
165
    private static final Logger LOG = Logger.getLogger(DeletedTextInterceptorsManager.class.getName());
166
    
167
    private static DeletedTextInterceptorsManager instance;
168
169
    private Transaction transaction = null;
170
    private final Map<MimePath, Reference<Collection<DeletedTextInterceptor>>> cache = new WeakHashMap<MimePath, Reference<Collection<DeletedTextInterceptor>>>();
171
    
172
    private DeletedTextInterceptorsManager() {
173
174
    }
175
176
    // XXX: listne on changes in MimeLookup
177
    private Collection<? extends DeletedTextInterceptor> getInterceptors(Document doc, int offset) {
178
        List<TokenSequence<?>> seqs = TokenHierarchy.get(doc).embeddedTokenSequences(offset, true);
179
        TokenSequence<?> seq = seqs.isEmpty() ? null : seqs.get(seqs.size() - 1);
180
        MimePath mimePath = seq == null ? MimePath.parse(DocumentUtilities.getMimeType(doc)) : MimePath.parse(seq.languagePath().mimePath());
181
        
182
        synchronized (cache) {
183
            Reference<Collection<DeletedTextInterceptor>> ref = cache.get(mimePath);
184
            Collection<DeletedTextInterceptor> interceptors = ref == null ? null : ref.get();
185
186
            if (interceptors == null) {
187
                Collection<? extends DeletedTextInterceptor.Factory> factories = MimeLookup.getLookup(mimePath).lookupAll(DeletedTextInterceptor.Factory.class);
188
                interceptors = new HashSet<DeletedTextInterceptor>(factories.size());
189
190
                if (LOG.isLoggable(Level.FINE)) {
191
                    LOG.log(Level.FINE, "DeletedTextInterceptor.Factory instances for {0} {" , mimePath.getPath()); //NOI18N
192
                }
193
194
                for(DeletedTextInterceptor.Factory f : factories) {
195
                    DeletedTextInterceptor interceptor = f.createDeletedTextInterceptor(mimePath);
196
                    if (interceptor != null) {
197
                        interceptors.add(interceptor);
198
                    }
199
                    if (LOG.isLoggable(Level.FINE)) {
200
                        LOG.log(Level.FINE, "{0} created: {1}", new Object[] { f, interceptor }); //NOI18N
201
                    }
202
                }
203
204
                if (LOG.isLoggable(Level.FINE)) {
205
                    LOG.fine("}"); //NOI18N
206
                }
207
208
                // XXX: this should really be a timed WeakReference
209
                cache.put(mimePath, new SoftReference<Collection<DeletedTextInterceptor>>(interceptors));
210
            }
211
212
            return interceptors;
213
        }
214
    }
215
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypedBreakInterceptorsManager.java (+226 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.editor.lib2.typinghooks;
44
45
import java.lang.ref.Reference;
46
import java.lang.ref.SoftReference;
47
import java.util.Collection;
48
import java.util.HashSet;
49
import java.util.List;
50
import java.util.Map;
51
import java.util.WeakHashMap;
52
import java.util.logging.Level;
53
import java.util.logging.Logger;
54
import javax.swing.text.Document;
55
import javax.swing.text.JTextComponent;
56
import org.netbeans.api.editor.mimelookup.MimeLookup;
57
import org.netbeans.api.editor.mimelookup.MimePath;
58
import org.netbeans.api.lexer.TokenHierarchy;
59
import org.netbeans.api.lexer.TokenSequence;
60
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
61
import org.netbeans.spi.editor.typinghooks.TypedBreakInterceptor;
62
63
/**
64
 *
65
 * @author Vita Stejskal
66
 */
67
public final class TypedBreakInterceptorsManager {
68
69
    public static TypedBreakInterceptorsManager getInstance() {
70
        if (instance == null) {
71
            instance = new TypedBreakInterceptorsManager();
72
        }
73
        return instance;
74
    }
75
76
    public Transaction openTransaction(JTextComponent c, int caretOffset, int insertBreakOffset) {
77
        synchronized (this) {
78
            if (transaction == null) {
79
                transaction = new Transaction(c, caretOffset, insertBreakOffset);
80
                return transaction;
81
            } else {
82
                throw new IllegalStateException("Too many transactions; only one at a time is allowed!"); //NOI18N
83
            }
84
        }
85
    }
86
87
    public final class Transaction {
88
89
        public boolean beforeInsertion() {
90
            for(TypedBreakInterceptor i : interceptors) {
91
                try {
92
                    if (i.beforeInsert(context)) {
93
                        return true;
94
                    }
95
                } catch (Exception e) {
96
                    LOG.log(Level.INFO, "TypedBreakInterceptor crashed in beforeInsert(): " + i, e); //NOI18N
97
                }
98
            }
99
100
            phase++;
101
            return false;
102
        }
103
104
        /**
105
         *
106
         * @return [0] == insertionText, [1] == new caret position (!) within [0]
107
         */
108
        public Object [] textTyped() {
109
            Object [] data = null;
110
111
            for(TypedBreakInterceptor i : interceptors) {
112
                try {
113
                    i.insert(context);
114
                } catch (Exception e) {
115
                    LOG.log(Level.INFO, "TypedBreakInterceptor crashed in insert(): " + i, e); //NOI18N
116
                    TypingHooksSpiAccessor.get().resetTbiContextData(context);
117
                    continue;
118
                }
119
120
                data = TypingHooksSpiAccessor.get().getTbiContextData(context);
121
                if (data != null) {
122
                    break;
123
                }
124
            }
125
126
            phase++;
127
            return data;
128
        }
129
130
        public void afterInsertion() {
131
            for(TypedBreakInterceptor i : interceptors) {
132
                try {
133
                    i.afterInsert(context);
134
                } catch (Exception e) {
135
                    LOG.log(Level.INFO, "TypedBreakInterceptor crashed in afterInsert(): " + i, e); //NOI18N
136
                }
137
            }
138
139
            phase++;
140
        }
141
142
        public void close() {
143
            if (phase < 3) {
144
                for(TypedBreakInterceptor i : interceptors) {
145
                    try {
146
                        i.cancelled(context);
147
                    } catch (Exception e) {
148
                        LOG.log(Level.INFO, "TypedBreakInterceptor crashed in cancelled(): " + i, e); //NOI18N
149
                    }
150
                }
151
            }
152
153
            synchronized (TypedBreakInterceptorsManager.this) {
154
                transaction = null;
155
            }
156
        }
157
158
        // ------------------------------------------------------------------------
159
        // Private implementation
160
        // ------------------------------------------------------------------------
161
162
        private final TypedBreakInterceptor.MutableContext context;
163
        private final Collection<? extends TypedBreakInterceptor> interceptors;
164
        private int phase = 0;
165
166
        private Transaction(JTextComponent c, int caretOffset, int insertBreakOffset) {
167
            this.context = TypingHooksSpiAccessor.get().createTbiContext(c, caretOffset, insertBreakOffset);
168
            this.interceptors = getInterceptors(c.getDocument(), insertBreakOffset);
169
        }
170
    } // End of Transaction class
171
172
    // ------------------------------------------------------------------------
173
    // Private implementation
174
    // ------------------------------------------------------------------------
175
176
    private static final Logger LOG = Logger.getLogger(TypedBreakInterceptorsManager.class.getName());
177
    
178
    private static TypedBreakInterceptorsManager instance;
179
180
    private Transaction transaction = null;
181
    private final Map<MimePath, Reference<Collection<TypedBreakInterceptor>>> cache = new WeakHashMap<MimePath, Reference<Collection<TypedBreakInterceptor>>>();
182
    
183
    private TypedBreakInterceptorsManager() {
184
185
    }
186
187
    // XXX: listne on changes in MimeLookup
188
    private Collection<? extends TypedBreakInterceptor> getInterceptors(Document doc, int offset) {
189
        List<TokenSequence<?>> seqs = TokenHierarchy.get(doc).embeddedTokenSequences(offset, true);
190
        TokenSequence<?> seq = seqs.isEmpty() ? null : seqs.get(seqs.size() - 1);
191
        MimePath mimePath = seq == null ? MimePath.parse(DocumentUtilities.getMimeType(doc)) : MimePath.parse(seq.languagePath().mimePath());
192
        
193
        synchronized (cache) {
194
            Reference<Collection<TypedBreakInterceptor>> ref = cache.get(mimePath);
195
            Collection<TypedBreakInterceptor> interceptors = ref == null ? null : ref.get();
196
197
            if (interceptors == null) {
198
                Collection<? extends TypedBreakInterceptor.Factory> factories = MimeLookup.getLookup(mimePath).lookupAll(TypedBreakInterceptor.Factory.class);
199
                interceptors = new HashSet<TypedBreakInterceptor>(factories.size());
200
201
                if (LOG.isLoggable(Level.FINE)) {
202
                    LOG.log(Level.FINE, "TypedBreakInterceptor.Factory instances for {0} {" , mimePath.getPath()); //NOI18N
203
                }
204
205
                for(TypedBreakInterceptor.Factory f : factories) {
206
                    TypedBreakInterceptor interceptor = f.createTypedBreakInterceptor(mimePath);
207
                    if (interceptor != null) {
208
                        interceptors.add(interceptor);
209
                    }
210
                    if (LOG.isLoggable(Level.FINE)) {
211
                        LOG.log(Level.FINE, "{0} created: {1}", new Object[] { f, interceptor }); //NOI18N
212
                    }
213
                }
214
215
                if (LOG.isLoggable(Level.FINE)) {
216
                    LOG.fine("}"); //NOI18N
217
                }
218
219
                // XXX: this should really be a timed WeakReference
220
                cache.put(mimePath, new SoftReference<Collection<TypedBreakInterceptor>>(interceptors));
221
            }
222
223
            return interceptors;
224
        }
225
    }
226
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypedTextInterceptorsManager.java (+223 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.typinghooks;
41
42
import java.lang.ref.Reference;
43
import java.lang.ref.SoftReference;
44
import java.util.Collection;
45
import java.util.HashSet;
46
import java.util.List;
47
import java.util.Map;
48
import java.util.WeakHashMap;
49
import java.util.logging.Level;
50
import java.util.logging.Logger;
51
import javax.swing.text.Document;
52
import javax.swing.text.JTextComponent;
53
import org.netbeans.api.editor.mimelookup.MimeLookup;
54
import org.netbeans.api.editor.mimelookup.MimePath;
55
import org.netbeans.api.lexer.TokenHierarchy;
56
import org.netbeans.api.lexer.TokenSequence;
57
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
58
import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor;
59
60
/**
61
 *
62
 * @author vita
63
 */
64
public final class TypedTextInterceptorsManager {
65
66
    public static TypedTextInterceptorsManager getInstance() {
67
        if (instance == null) {
68
            instance = new TypedTextInterceptorsManager();
69
        }
70
        return instance;
71
    }
72
73
    public Transaction openTransaction(JTextComponent c, int offset, String typedText) {
74
        synchronized (this) {
75
            if (transaction == null) {
76
                transaction = new Transaction(c, offset, typedText);
77
                return transaction;
78
            } else {
79
                throw new IllegalStateException("Too many transactions; only one at a time is allowed!"); //NOI18N
80
            }
81
        }
82
    }
83
84
    public final class Transaction {
85
86
        public boolean beforeInsertion() {
87
            for(TypedTextInterceptor i : interceptors) {
88
                try {
89
                    if (i.beforeInsert(context)) {
90
                        return true;
91
                    }
92
                } catch (Exception e) {
93
                    LOG.log(Level.INFO, "TypedTextInterceptor crashed in beforeInsert(): " + i, e); //NOI18N
94
                }
95
            }
96
97
            phase++;
98
            return false;
99
        }
100
101
        /**
102
         *
103
         * @return [0] == insertionText, [1] == new caret position (!) within [0]
104
         */
105
        public Object [] textTyped() {
106
            Object [] data = null;
107
108
            for(TypedTextInterceptor i : interceptors) {
109
                try {
110
                    i.insert(context);
111
                } catch (Exception e) {
112
                    LOG.log(Level.INFO, "TypedTextInterceptor crashed in insert(): " + i, e); //NOI18N
113
                    TypingHooksSpiAccessor.get().resetTtiContextData(context);
114
                    continue;
115
                }
116
117
                data = TypingHooksSpiAccessor.get().getTtiContextData(context);
118
                if (data != null) {
119
                    break;
120
                }
121
            }
122
123
            phase++;
124
            return data;
125
        }
126
127
        public void afterInsertion() {
128
            for(TypedTextInterceptor i : interceptors) {
129
                try {
130
                    i.afterInsert(context);
131
                } catch (Exception e) {
132
                    LOG.log(Level.INFO, "TypedTextInterceptor crashed in afterInsert(): " + i, e); //NOI18N
133
                }
134
            }
135
136
            phase++;
137
        }
138
139
        public void close() {
140
            if (phase < 3) {
141
                for(TypedTextInterceptor i : interceptors) {
142
                    try {
143
                        i.cancelled(context);
144
                    } catch (Exception e) {
145
                        LOG.log(Level.INFO, "TypedTextInterceptor crashed in cancelled(): " + i, e); //NOI18N
146
                    }
147
                }
148
            }
149
150
            synchronized (TypedTextInterceptorsManager.this) {
151
                transaction = null;
152
            }
153
        }
154
155
        // ------------------------------------------------------------------------
156
        // Private implementation
157
        // ------------------------------------------------------------------------
158
159
        private final TypedTextInterceptor.MutableContext context;
160
        private final Collection<? extends TypedTextInterceptor> interceptors;
161
        private int phase = 0;
162
163
        private Transaction(JTextComponent c, int offset, String typedText) {
164
            this.context = TypingHooksSpiAccessor.get().createTtiContext(c, offset, typedText);
165
            this.interceptors = getInterceptors(c.getDocument(), offset);
166
        }
167
    } // End of Transaction class
168
169
    // ------------------------------------------------------------------------
170
    // Private implementation
171
    // ------------------------------------------------------------------------
172
173
    private static final Logger LOG = Logger.getLogger(TypedTextInterceptorsManager.class.getName());
174
    
175
    private static TypedTextInterceptorsManager instance;
176
177
    private Transaction transaction = null;
178
    private final Map<MimePath, Reference<Collection<TypedTextInterceptor>>> cache = new WeakHashMap<MimePath, Reference<Collection<TypedTextInterceptor>>>();
179
    
180
    private TypedTextInterceptorsManager() {
181
182
    }
183
184
    // XXX: listne on changes in MimeLookup
185
    private Collection<? extends TypedTextInterceptor> getInterceptors(Document doc, int offset) {
186
        List<TokenSequence<?>> seqs = TokenHierarchy.get(doc).embeddedTokenSequences(offset, true);
187
        TokenSequence<?> seq = seqs.isEmpty() ? null : seqs.get(seqs.size() - 1);
188
        MimePath mimePath = seq == null ? MimePath.parse(DocumentUtilities.getMimeType(doc)) : MimePath.parse(seq.languagePath().mimePath());
189
        
190
        synchronized (cache) {
191
            Reference<Collection<TypedTextInterceptor>> ref = cache.get(mimePath);
192
            Collection<TypedTextInterceptor> interceptors = ref == null ? null : ref.get();
193
194
            if (interceptors == null) {
195
                Collection<? extends TypedTextInterceptor.Factory> factories = MimeLookup.getLookup(mimePath).lookupAll(TypedTextInterceptor.Factory.class);
196
                interceptors = new HashSet<TypedTextInterceptor>(factories.size());
197
198
                if (LOG.isLoggable(Level.FINE)) {
199
                    LOG.log(Level.FINE, "TypedTextInterceptor.Factory instances for {0} {" , mimePath.getPath()); //NOI18N
200
                }
201
202
                for(TypedTextInterceptor.Factory f : factories) {
203
                    TypedTextInterceptor interceptor = f.createTypedTextInterceptor(mimePath);
204
                    if (interceptor != null) {
205
                        interceptors.add(interceptor);
206
                    }
207
                    if (LOG.isLoggable(Level.FINE)) {
208
                        LOG.log(Level.FINE, "{0} created: {1}", new Object[] { f, interceptor }); //NOI18N
209
                    }
210
                }
211
212
                if (LOG.isLoggable(Level.FINE)) {
213
                    LOG.fine("}"); //NOI18N
214
                }
215
216
                // XXX: this should really be a timed WeakReference
217
                cache.put(mimePath, new SoftReference<Collection<TypedTextInterceptor>>(interceptors));
218
            }
219
220
            return interceptors;
221
        }
222
    }
223
}
(-)a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java (+85 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.editor.lib2.typinghooks;
41
42
import javax.swing.text.JTextComponent;
43
import org.netbeans.spi.editor.typinghooks.DeletedTextInterceptor;
44
import org.netbeans.spi.editor.typinghooks.TypedBreakInterceptor;
45
import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor;
46
47
/**
48
 *
49
 * @author vita
50
 */
51
public abstract class TypingHooksSpiAccessor {
52
53
    private static TypingHooksSpiAccessor ACCESSOR = null;
54
55
    public static synchronized void register(TypingHooksSpiAccessor accessor) {
56
        assert ACCESSOR == null : "Can't register two package accessors!"; //NOI18N
57
        ACCESSOR = accessor;
58
    }
59
60
    public static synchronized TypingHooksSpiAccessor get() {
61
        // Trying to wake up HighlightsLayer ...
62
        try {
63
            Class clazz = Class.forName(TypedTextInterceptor.MutableContext.class.getName());
64
        } catch (ClassNotFoundException e) {
65
            // ignore
66
        }
67
68
        assert ACCESSOR != null : "There is no package accessor available!"; //NOI18N
69
        return ACCESSOR;
70
    }
71
72
    /** Creates a new instance of HighlightingSpiPackageAccessor */
73
    protected TypingHooksSpiAccessor() {
74
    }
75
76
    public abstract TypedTextInterceptor.MutableContext createTtiContext(JTextComponent c, int offset, String typedText);
77
    public abstract Object [] getTtiContextData(TypedTextInterceptor.MutableContext context);
78
    public abstract void resetTtiContextData(TypedTextInterceptor.MutableContext context);
79
    
80
    public abstract DeletedTextInterceptor.Context createDtiContext(JTextComponent c, int offset, String removedText, boolean backwardDelete);
81
    
82
    public abstract TypedBreakInterceptor.MutableContext createTbiContext(JTextComponent c, int caretOffset, int insertBreakOffset);
83
    public abstract Object [] getTbiContextData(TypedBreakInterceptor.MutableContext context);
84
    public abstract void resetTbiContextData(TypedBreakInterceptor.MutableContext context);
85
}
(-)a/editor.lib2/src/org/netbeans/spi/editor/codegen/package.html (-1 / +5 lines)
Lines 143-148 Link Here
143
  with the additional data and runs the task obtained as the parameter with the newly
143
  with the additional data and runs the task obtained as the parameter with the newly
144
  created context. 
144
  created context. 
145
  </p>
145
  </p>
146
  
146
147
  <h3><a name="usecases">Use cases</a></h3>
148
149
  <p style="color:red">TBD</p>
150
147
  </body>
151
  </body>
148
</html>
152
</html>
(-)a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/DeletedTextInterceptor.java (+311 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.spi.editor.typinghooks;
44
45
import javax.swing.text.BadLocationException;
46
import javax.swing.text.Document;
47
import javax.swing.text.JTextComponent;
48
import org.netbeans.api.editor.mimelookup.MimePath;
49
50
/**
51
 * An interceptor which is called when user deletes text from a document. You should
52
 * implement this interface if you want to hook in the keyboard input
53
 * processing done in the editor infrastructure that would normally result in removing text
54
 * from a document. Typically, implementations of this interface will be called
55
 * when processing <code>KeyEvent</code>s that reach the default editor actions bound to
56
 * <code>VK_DELETE</code> and <code>VK_BACK_SPACE</code> events.
57
 *
58
 * <p><b>Registration</b>: <code>DeletedTextInterceptor</code>s can be plugged in the editor infrastructure
59
 * by implementing the {@link Factory} interface and registering it in <code>MimeLookup</code>
60
 * under the appropriate mimetype (ie. <code>MimePath</code>).
61
 *
62
 * <p>The instances created from the <code>Factory</code> will be reused for processing
63
 * the relevant key events received by all documents of the same mime type, which the interceptor
64
 * instances were registered for (including documents that contain embedded sections
65
 * of that mime type). As described in the general concepts of Typing Hooks SPI
66
 * the interceptors are guaranteed to be called in AWT thread only, which means that
67
 * they should not need any internal synchronization model.
68
 *
69
 * <p><b>Processing rules</b>: If there are multiple instances of <code>DeletedTextInterceptor</code> registered
70
 * for the same mime type the infrastructure will queue them up in their registration
71
 * order and when processing an event it will call them all until the processing is done
72
 * or terminated. 
73
 *
74
 * <p>The interceptor has several methods that are called at different stages of
75
 * the key typed event processing. When processing an event the infrastructure will call
76
 * the methods in the order as they are listed below. Moreover if there are multiple
77
 * interceptors queued up for processing an event each method is first called on
78
 * all the queued interceptors before moving on to the next stage and calling next
79
 * method.
80
 *
81
 * <ul>
82
 * <li>{@link #beforeRemove(Context)} - It's called before any text is removed
83
 *   from a document. No document lock is held when this method is called. The method
84
 *   is not allowed to modify the document (and it's not supposed to do any tricks to
85
 *   break this rule). An interceptor can stop further processing of the event by returning
86
 *   <code>true</code> from this method. If it does so, no other interceptors'
87
 *   <code>beforeRemove</code> method will be called and the processing will be terminated
88
 *   without removing any text.
89
 *
90
 * <li>{@link #remove(Context)} - This method is called during the text
91
 *   removal stage immediately after the text was removed from a document. At this
92
 *   time the document is already write locked and the interceptors can modify it
93
 *   if they need to.
94
 *
95
 * <li>{@link #afterRemove(Context)} - This is the last method in the processing
96
 *   chain and it will be called when the text has already been removed from the document.
97
 *   Similarly as in <code>beforeRemove</code> the document is not locked when
98
 *   this method is called.
99
 * 
100
 * <li>{@link #cancelled(Context)} - This is an additional method that will be called
101
 *   when the processing is terminated in the before-removal stage (ie. by an interceptor
102
 *   returning <code>true</code> from its <code>beforeRemove</code> method).
103
 *   The infrastructure will only call this method on interceptors that have already
104
 *   had their <code>beforeRemove</code> method called, but not on those that
105
 *   have not yet been called at all.
106
 * </ul>
107
 *
108
 * <p><b>Errors recovery</b>: If an exception is thrown from any of the methods
109
 * when calling an interceptor the infrastructure will catch it and log it,
110
 * but it will not stop further processing. The infrastructure may blacklist the offending
111
 * interceptor and exclude it from processing future events.
112
 *
113
 * @author Vita Stejskal
114
 * @since 1.31
115
 */
116
public interface DeletedTextInterceptor {
117
118
    /**
119
     * This method is called before any text is removed from a document. The context object
120
     * passed to the method provides access to the document and its editor pane. The interceptors
121
     * are not allowed to modify the document in this method.
122
     *
123
     * <p>This method can be used for stopping further processing of the current
124
     * key typed event. If this method returns <code>true</code> the processing will
125
     * be terminated and {@link #cancelled(Context)} will be called for all the interceptors
126
     * that have already had their <code>beforeRemove</code> method called (including
127
     * the one that terminated the processing). The rest of the interceptors waiting
128
     * in the queue will not be called at all.
129
     *
130
     * <p><b>Locking</b>: When this method is called the document is not locked
131
     * by the infrastructure.
132
     * 
133
     * @param context The context object providing information necessary for processing
134
     *   the event.
135
     *
136
     * @return If <code>true</code> the further processing will be stopped. Normally
137
     *   the method should return <code>false</code>.
138
     * @throws BadLocationException Since the document is not locked prior calling this
139
     *   method the processing may fail when working with stale context data.
140
     */
141
    boolean beforeRemove(Context context) throws BadLocationException;
142
    
143
    /**
144
     * This method is called immediately after the text is removed from a document.
145
     * Implementors can modify the document as they need. The document and all
146
     * the other useful information is accessible from the <code>Context</code> object
147
     * passed in this method. The document is write-locked.
148
     *
149
     * <p><b>Locking</b>: When this method is called the infrastructure has already
150
     * write locked the document.
151
     *
152
     * @param context The context object providing information necessary for processing
153
     *   the event and allowing to modify the edited document.
154
     *
155
     * @throws BadLocationException If the processing fails.
156
     */
157
    void remove(Context context) throws BadLocationException;
158
159
    /**
160
     * This method is called after text is removed from a document and its editor's
161
     * caret is adjusted.
162
     *
163
     * <p><b>Locking</b>: When this method is called the document is not locked
164
     * by the infrastructure.
165
     *
166
     * @param context The context object providing information necessary for processing
167
     *   the event. The {@link Context#getText()} method will return text that was
168
     *   removed from the document at the beginning of the text-removal stage.
169
     * 
170
     * @throws BadLocationException Since the document is not locked prior calling this
171
     *   method the processing may fail when working with stale context data.
172
     */
173
    void afterRemove(Context context) throws BadLocationException;
174
175
    /**
176
     * This method is called when the normal processing is terminated by some
177
     * interceptor's <code>beforeRemove</code> method. Please note that this
178
     * method will not be called if the <code>beforeRemove</code> method was not
179
     * called.
180
     * 
181
     * @param context The context object used for calling the <code>beforeRemove</code>
182
     *   method.
183
     */
184
    void cancelled(Context context);
185
    
186
    /**
187
     * The context class providing information about the edited document, its
188
     * editor pane and the offset where the delete key event occurred.
189
     */
190
    public static final class Context {
191
192
        /**
193
         * Gets the editor component where the currently processed key typed event
194
         * occurred.
195
         *
196
         * @return The editor pane that contains the edited <code>Document</code>.
197
         */
198
        public JTextComponent getComponent() {
199
            return component;
200
        }
201
        
202
        /**
203
         * Gets the edited document. It's the document, where the text will be
204
         * removed.
205
         *
206
         * @return The edited document.
207
         */
208
        public Document getDocument() {
209
            return document;
210
        }
211
        
212
        /**
213
         * Gets the removal offset. This is the offset in the document where
214
         * a user performed the delete action (ie. where the currently processed <code>KeyEvent</code>
215
         * happened). This is also the offset with text, which will be removed.
216
         *
217
         * @return The offset in the edited document.
218
         */
219
        public int getOffset() {
220
            return offset;
221
        }
222
223
// XXX: since this is always one (character) it make no sense to have it
224
//        public int getLength() {
225
//            return lenght;
226
//        }
227
        
228
        /**
229
         * Determines the type of the character removal action performed by a user. The two
230
         * possible actions are called differently on different platforms,
231
         * but they are always defined by the position of a character, which they are
232
         * applied to. The <i>backspace</i> action deletes a character on the left hand
233
         * side of a caret, while the <i>delete</i> action deletes a character on
234
         * the right hand side of the caret.
235
         * 
236
         * <p>In other words one delete action removes characters backwards moving
237
         * the caret towards the beginning if a document and the other action leaves
238
         * the caret at the same position and removes characters towards the end
239
         * of the document.
240
         * 
241
         * @return <code>true</code> if the interceptor is called to handle the
242
         *   backspace action. <code>false</code> if the handled action is the
243
         *   delete action.
244
         */
245
        public boolean isBackwardDelete() {
246
            return backwardDelete;
247
        }
248
        
249
        /**
250
         * Gets the text being removed. In <code>beforeRemove</code> method this
251
         * text is still present in the document, while in the other methods this
252
         * text has already been removed from the document. Nevertheless this method
253
         * always returns a copy of the text.
254
         * 
255
         * @return The text being removed by the currently processed key typed event.
256
         */
257
        public String getText() {
258
            return removedText;
259
        }
260
        
261
        // -------------------------------------------------------------------
262
        // Private implementation
263
        // -------------------------------------------------------------------
264
265
        private final JTextComponent component;
266
        private final Document document;
267
        private final int offset;
268
        private final boolean backwardDelete;
269
        private final String removedText;
270
271
        /* package */ Context(JTextComponent component, int offset, String removedText, boolean backwardDelete) {
272
            this.component = component;
273
            this.document = component.getDocument();
274
            this.offset = offset;
275
            this.backwardDelete = backwardDelete;
276
            this.removedText = removedText;
277
        }
278
        
279
    } // End of Context class
280
281
    /**
282
     * The factory interface for registering <code>DeletedTextInterceptor</code>s
283
     * in <code>MimeLookup</code>. An example registration in an XML layer shown
284
     * below registers <code>Factory</code> implementation under <code>text/x-something</code>
285
     * mime type in <code>MimeLookup</code>.
286
     *
287
     * <pre>
288
     * &lt;folder name="Editors"&gt;
289
     *  &lt;folder name="text"&gt;
290
     *   &lt;folder name="x-something"&gt;
291
     *    &lt;file name="org-some-module-DTIFactory.instance" /&gt;
292
     *   &lt;/folder&gt;
293
     *  &lt;/folder&gt;
294
     * &lt;/folder&gt;
295
     * </pre>
296
     */
297
    public interface Factory {
298
299
        /**
300
         * Creates a new interceptor for the given <code>MimePath</code>.
301
         * 
302
         * @param mimePath The <code>MimePath</code> for which the infrastructure
303
         *   needs the new interceptor. Typically this is the same <code>MimePath</code>
304
         *   where this <code>Factory</code> was registered, but in embedded scenarios
305
         *   this can be a different <code>MimePath</code>.
306
         *
307
         * @return The new interceptor.
308
         */
309
        DeletedTextInterceptor createDeletedTextInterceptor(MimePath mimePath);
310
    } // End of Factory interface
311
}
(-)a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedBreakInterceptor.java (+424 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.spi.editor.typinghooks;
44
45
import javax.swing.text.BadLocationException;
46
import javax.swing.text.Document;
47
import javax.swing.text.JTextComponent;
48
import org.netbeans.api.editor.mimelookup.MimePath;
49
import org.openide.util.Parameters;
50
51
/**
52
 * An interceptor which is called when a line break is typed into a document. You should
53
 * implement this interface if you want to hook in the keyboard input
54
 * processing done in the editor infrastructure that would normally result in inserting a line break
55
 * into a document. This is in fact a specialized version of {@link TypedTextInterceptor} interface,
56
 * which works the same way, but handles inserting a line break rather than regular characters.
57
 * The {@link TypedTextInterceptor} implementations are never called to handle the line break insertion.
58
 *
59
 * <p><b>Registration</b>: <code>TypedBreakInterceptor</code>s can be plugged in the editor infrastructure
60
 * by implementing the {@link Factory} interface and registering it in <code>MimeLookup</code>
61
 * under the appropriate mimetype (ie <code>MimePath</code>).
62
 *
63
 * <p>The instances created from the <code>Factory</code> will be reused for processing
64
 * all keyboard input received by all documents of the same mime type, which the interceptor
65
 * instances were registered for (including documents that contain embedded sections
66
 * of that mime type). As described in the general concepts of Typing Hooks SPI
67
 * the interceptors are guaranteed to be called in AWT thread only, which means that
68
 * they should not need any internal synchronization model.
69
 *
70
 * <p><b>Processing rules</b>: If there are multiple instances of <code>TypedBreakInterceptor</code> registered
71
 * for the same mime type the infrastructure will queue them up in their registration
72
 * order and when processing an event it will call them all until the processing is done
73
 * or terminated. 
74
 *
75
 * <p>The interceptor has several methods that are called at different stages of
76
 * the key typed event processing. When processing an event the infrastructure will call
77
 * the methods in the order as they are listed below. Moreover, if there are multiple
78
 * interceptors queued up for processing an event each method is first called on
79
 * all the queued interceptors before moving on to the next stage and calling next
80
 * method.
81
 *
82
 * <ul>
83
 * <li>{@link #beforeInsert(Context)} - It's called before a line break is inserted
84
 *   into a document. No document lock is held when this method is called. The method
85
 *   can't modify the text that will be inserted (and it's not supposed to do any tricks to
86
 *   break this rule). An interceptor can stop further processing of the event by returning
87
 *   <code>true</code> from this method. If it does so, no other interceptors'
88
 *   <code>beforeInsert</code> method will be called and the processing will be terminated
89
 *   without inserting any text.
90
 *
91
 * <li>{@link #insert(MutableContext)} - This method is called during the text
92
 *   insertion stage immediately before the text is inserted into a document. At this
93
 *   time the document is already write locked, but the interceptors are not expected
94
 *   to modify its content directly. Instead they can change the text that will be
95
 *   inserted by calling {@link MutableContext#setText(java.lang.String, int)} method.
96
 *   The text insertion is strictly controlled by the infrastructure and has to obey some
97
 *   additional rules (eg. correctly replacing selected text, handling insert vs override
98
 *   modes of the caret, etc). The first interceptor that modifies the insertion text
99
 *   will win and no other interceptor's <code>insert</code> method will be called.
100
 *   <br/>
101
 *   The interceptors are allowed to insert more than just a line break, but the text
102
 *   they insert has to contain at least one line break. They can also request the
103
 *   inserted text to be reindented. Please see {@link MutableContext#setText(java.lang.String, int, int, int...)}
104
 *   for details. 
105
 *
106
 * <li>{@link #afterInsert(Context)} - This is the last method in the processing
107
 *   chain and it will be called when the text is already inserted in the document.
108
 *   Similarly as in <code>beforeInsert</code> the document is not locked when
109
 *   this method is called.
110
 * 
111
 * <li>{@link #cancelled(Context)} - This is an additional method that will be called
112
 *   when the processing is terminated in the before-insertion stage (ie. by an interceptor
113
 *   returning <code>true</code> from its <code>beforeInsert</code> method).
114
 *   The infrastructure will only call this method on interceptors that have already
115
 *   had their <code>beforeInsert</code> method called, but not on those that
116
 *   have not yet been called at all.
117
 * </ul>
118
 *
119
 * <p><b>Errors recovery</b>: If an exception is thrown from any of the methods
120
 * when calling an interceptor the infrastructure will catch it and log it,
121
 * but it will not stop further processing. The infrastructure may blacklist the offending
122
 * interceptor and exclude it from processing future events.
123
 *
124
 * @author Vita Stejskal
125
 * @since 1.31
126
 */
127
public interface TypedBreakInterceptor {
128
129
    /**
130
     * This method is called before any text is inserted into a document. The context object
131
     * passed to the method provides access to the editor pane and the edited document,
132
     * but does not allow to modify the text that will be inserted.
133
     *
134
     * <p>This method can be used for stopping further processing of the current
135
     * key typed event. If this method returns <code>true</code> the processing will
136
     * be terminated and {@link #cancelled(Context)} will be called for all the intercetors
137
     * that have already had their <code>beforeInsert</code> method called (including
138
     * the one that terminated the processing). The rest of the interceptors waiting
139
     * in the queue will not be called at all.
140
     *
141
     * <p><b>Locking</b>: When this method is called the document is not locked
142
     * by the infrastructure.
143
     * 
144
     * @param context The context object providing information necessary for processing
145
     *   the event.
146
     *
147
     * @return If <code>true</code> the further processing will be stopped. Normally
148
     *   the method should return <code>false</code>.
149
     * @throws BadLocationException Since the document is not locked prior calling this
150
     *   method the processing may fail when working with stale context data.
151
     */
152
    boolean beforeInsert(Context context) throws BadLocationException;
153
    
154
    /**
155
     * This method is called immediately before a line break is inserted into a document.
156
     * Implementors can use special <code>MutableContext</code> to modify the text
157
     * that will be inserted into a document. The first interceptor that sets
158
     * the insertion text will win and the method will not be called on the rest
159
     * of the queued interceptors. The interceptors are not supposed to modify the
160
     * document directly.
161
     *
162
     * <p><b>Locking</b>: When this method is called the infrastructure has already
163
     * write locked the document.
164
     *
165
     * @param context The context object providing information necessary for processing
166
     *   the event and allowing to modify the insertion text.
167
     *
168
     * @throws BadLocationException If the processing fails.
169
     */
170
    void insert(MutableContext context) throws BadLocationException;
171
    
172
    /**
173
     * This method is called after the text is inserted into a document and its editor's
174
     * caret is adjusted.
175
     *
176
     * <p><b>Locking</b>: When this method is called the document is not locked
177
     * by the infrastructure.
178
     *
179
     * @param context The context object providing information necessary for processing
180
     *   the event. The {@link Context#getText()} method will return text that was
181
     *   inserted into the document at the end of the text-insertion stage.
182
     * 
183
     * @throws BadLocationException Since the document is not locked prior calling this
184
     *   method the processing may fail when working with stale context data.
185
     */
186
    void afterInsert(Context context) throws BadLocationException;
187
    
188
    /**
189
     * This method is called when the normal processing is terminated by some
190
     * interceptor's <code>beforeInsert</code> method. Please note that this
191
     * method will not be called if the <code>beforeInsert</code> method was not
192
     * called.
193
     * 
194
     * @param context The context object used for calling the <code>beforeInsert</code>
195
     *   method.
196
     */
197
    void cancelled(Context context);
198
    
199
    /**
200
     * The context class providing information about the edited document, its
201
     * editor pane, caret offset, line break insertion offset and text.
202
     */
203
    public static class Context {
204
        
205
        /**
206
         * Gets the editor component where the currently processed key typed event
207
         * occurred.
208
         *
209
         * @return The editor pane that contains the edited <code>Document</code>.
210
         */
211
        public JTextComponent getComponent() {
212
            return component;
213
        }
214
215
        /**
216
         * Gets the edited document. It's the document where the line break is going to
217
         * be inserted.
218
         *
219
         * @return The edited document.
220
         */
221
        public Document getDocument() {
222
            return document;
223
        }
224
225
        /**
226
         * Gets the caret offset. This is the offset in the document where
227
         * the caret is at the time when a user performed an action resulting in
228
         * the insertion of a line break (ie. where the currently processed <code>KeyEvent</code>
229
         * happened). This may or may not be the same offset, where the line break
230
         * will be inserted.
231
         *
232
         * @return The offset in the edited document.
233
         */
234
        public int getCaretOffset() {
235
            return caretOffset;
236
        }
237
        
238
        /**
239
         * Gets the line break insertion offset. This is the offset in the document where
240
         * the line break will be inserted.
241
         *
242
         * @return The offset in the edited document.
243
         */
244
        public int getBreakInsertOffset() {
245
            return breakInsertOffset;
246
        }
247
        
248
        // -------------------------------------------------------------------
249
        // Private implementation
250
        // -------------------------------------------------------------------
251
        
252
        private final JTextComponent component;
253
        private final Document document;
254
        private final int caretOffset;
255
        private final int breakInsertOffset;
256
        
257
        private Context(JTextComponent component, int caretOffset, int breakInsertOffset) {
258
            this.component = component;
259
            this.document = component.getDocument();
260
            this.caretOffset = caretOffset;
261
            this.breakInsertOffset = breakInsertOffset;
262
        }
263
        
264
    } // End of Context class
265
    
266
    /**
267
     * This context class allows to modify the insertion text and the caret position
268
     * after the text is inserted into a document. Apart from that it provides exactly the same
269
     * information as its superclass <code>Context</code>.
270
     */
271
    public static final class MutableContext extends Context {
272
        
273
        /**
274
         * Sets the insertion text and adjusted caret position. This method can
275
         * be used for inserting additional text that accompanies the line break typed
276
         * in by a user.
277
         *
278
         * <p>There is no restriction on the new text
279
         * set by this method, except that it must not be <code>null</code> and must contain at least
280
         * one line break. It can be of any length and can even span multiple lines.
281
         *
282
         * <p>It is important to remember that the values of the position parameters are
283
         * relative to the new text. Therefore valid values for the <code>caretPosition</code>
284
         * parameter, for example, are <code>&lt;0, text.getLength()&gt;</code>! The position parameters
285
         * are <b>not</b> document offsets.
286
         * 
287
         * <p>The following rules have to be obeyed otherwise an <code>IllegalArgumentException</code>
288
         * will be thrown:
289
         * 
290
         * <ul>
291
         * <li>The <code>text</code> has to contain at least one line break '\n' character.
292
         * <li>The <code>breakInsertPosition</code>, if specified, has to point to the most
293
         *   important line break character in the <code>text</code> (eg. an interceptor can actually insert
294
         *   several lines, but one of them is always considered the most significant and its
295
         *   line break character position is where <code>breakInsertPosition</code> should point at.
296
         * <li>The <code>caretPosition</code>, if specified, has to point somewhere within the <code>text</code>.
297
         * <li>The <code>reindentBlocks</code>, if specified, are pairs of positions within the
298
         *   <code>text</code>. In each pair the first number denotes the starting position of a
299
         *   region that will be reindented. The ending position of that region is denoted by the
300
         *   second number in the pair. Therfore the first number has to be lower or equal to the
301
         *   second number.
302
         * </ul>
303
         * 
304
         * @param text The new text that will be inserted to a document. It must contain at least
305
         *   one line break '\n' character.
306
         * @param breakInsertPosition The position within the <code>text</code> where the most significant
307
         *   line break character is. If <code>-1</code>, the position of the first line break character
308
         *   in the <code>text</code> will be used.
309
         * @param caretPosition The position within the <code>text</code> where the caret will be placed
310
         *   after the text is inserted in the document. If <code>-1</code>, the <code>breakInsertPosition + 1</code>
311
         *   will be used.
312
         * @param reindentBlocks The list of position pairs that determine areas within the <code>text</code>
313
         *   that will be reindented after the <code>text</code> is inserted in the document. Can be <code>null</code>
314
         *   or zero length array in which case only the line containing the <code>caretPosition</code> will
315
         *   be reindented. If specified, it must contain an even number of elements.
316
         * 
317
         * @throws IllegalArgumentException If the parameters passed in violate the rules specified above.
318
         */
319
        public void setText(String text, int breakInsertPosition, int caretPosition, int... reindentBlocks) {
320
            Parameters.notNull("text", text); //NOI18N
321
            
322
            if (text.indexOf('\n') == -1) {
323
                throw new IllegalArgumentException("The text must contain a new line (\\n) character."); //NOI18N
324
            }
325
            
326
            if (breakInsertPosition != -1) {
327
                if (breakInsertPosition < 0 || breakInsertPosition >= text.length()) {
328
                    throw new IllegalArgumentException("The breakInsertPosition=" + breakInsertPosition + " must point in the text=<0, " + text.length() + ")."); //NOI18N
329
                }
330
                if (text.charAt(breakInsertPosition) != '\n') {
331
                    throw new IllegalArgumentException("The character at breakInsertPosition=" + breakInsertPosition + " must be the new line (\\n) character."); //NOI18N
332
                }
333
            }
334
            
335
            if (caretPosition != -1) {
336
                if (caretPosition < 0 || caretPosition > text.length()) {
337
                    throw new IllegalArgumentException("The caretPosition=" + caretPosition + " must point in the text=<0, " + text.length() + ">."); //NOI18N
338
                }
339
            }
340
341
            if (reindentBlocks != null && reindentBlocks.length > 0) {
342
                if (reindentBlocks.length % 2 != 0) {
343
                    throw new IllegalArgumentException("The reindentBlocks must contain even number of positions within the text: " + reindentBlocks.length); //NOI18N
344
                }
345
                for(int i = 0; i < reindentBlocks.length / 2; i++) {
346
                    int s = reindentBlocks[2 * i];
347
                    if (s < 0 || s > text.length()) {
348
                        throw new IllegalArgumentException("The reindentBlocks[" + (2 * i) + "]=" + s + " must point in the text=<0, " + text.length() + ")."); //NOI18N
349
                    }
350
                    int e = reindentBlocks[2 * i + 1];
351
                    if (e < 0 || e > text.length()) {
352
                        throw new IllegalArgumentException("The reindentBlocks[" + (2 * i + 1) + "]=" + e + " must point in the text=<0, " + text.length() + ")."); //NOI18N
353
                    }
354
                    if (s > e) {
355
                        throw new IllegalArgumentException("The reindentBlocks[" + (2 * i) + "]=" + s + " must be smaller than reindentBlocks[" + (2 * i + 1) + "]=" + e); //NOI18N
356
                    }
357
                }
358
                
359
            }
360
            
361
            this.insertionText = text;
362
            this.breakInsertPosition = breakInsertPosition;
363
            this.caretPosition = caretPosition;
364
            this.reindentBlocks = reindentBlocks;
365
        }
366
        
367
        // -------------------------------------------------------------------
368
        // Private implementation
369
        // -------------------------------------------------------------------
370
        
371
        private String insertionText = null;
372
        private int breakInsertPosition = -1;
373
        private int caretPosition = -1;
374
        private int [] reindentBlocks = null;
375
        
376
        /* package */ MutableContext(JTextComponent component, int caretOffset, int insertBreakOffset) {
377
            super(component, caretOffset, insertBreakOffset);
378
        }
379
        
380
        /* package */ Object [] getData() {
381
            return insertionText != null ?
382
                new Object [] { insertionText, breakInsertPosition, caretPosition, reindentBlocks } :
383
                null;
384
        }
385
        
386
        /* package */ void resetData() {
387
            insertionText = null;
388
            breakInsertPosition = -1;
389
            caretPosition = -1;
390
            reindentBlocks = null;
391
        }
392
    } // End of MutableContext class
393
394
    /**
395
     * The factory interface for registering <code>TypedBreakInterceptor</code>s
396
     * in <code>MimeLookup</code>. An example registration in an XML layer shown
397
     * below registers <code>Factory</code> implementation under <code>text/x-something</code>
398
     * mime type in <code>MimeLookup</code>.
399
     *
400
     * <pre>
401
     * &lt;folder name="Editors"&gt;
402
     *  &lt;folder name="text"&gt;
403
     *   &lt;folder name="x-something"&gt;
404
     *    &lt;file name="org-some-module-TBIFactory.instance" /&gt;
405
     *   &lt;/folder&gt;
406
     *  &lt;/folder&gt;
407
     * &lt;/folder&gt;
408
     * </pre>
409
     */
410
    public interface Factory {
411
412
        /**
413
         * Creates a new interceptor for the given <code>MimePath</code>.
414
         * 
415
         * @param mimePath The <code>MimePath</code> for which the infrastructure
416
         *   needs the new interceptor. Typically this is the same <code>MimePath</code>
417
         *   where this <code>Factory</code> was registered, but in embedded scenarios
418
         *   this can be a different <code>MimePath</code>.
419
         *
420
         * @return The new interceptor.
421
         */
422
        TypedBreakInterceptor createTypedBreakInterceptor(MimePath mimePath);
423
    } // End of Factory interface
424
}
(-)a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java (+394 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.editor.typinghooks;
41
42
import javax.swing.text.BadLocationException;
43
import javax.swing.text.Document;
44
import javax.swing.text.JTextComponent;
45
import org.netbeans.api.editor.mimelookup.MimePath;
46
import org.netbeans.modules.editor.lib2.typinghooks.TypingHooksSpiAccessor;
47
48
/**
49
 * An interceptor which is called when text is typed into a document. You should
50
 * implement this interface if you want to hook in the keyboard input
51
 * processing done in the editor infrastructure that would normally result in inserting text
52
 * into a document. Typically, implementations of this interface will be called
53
 * when processing <code>KeyEvent</code>s that reach a default keymap action (ie.
54
 * there is no entry in the editor's keymap for this particular <code>KeyEvent</code>).
55
 *
56
 * <p><b>Registration</b>: <code>TypedTextInterceptor</code>s can be plugged in the editor infrastructure
57
 * by implementing the {@link Factory} interface and registering it in <code>MimeLookup</code>
58
 * under the appropriate mimetype (ie <code>MimePath</code>).
59
 *
60
 * <p>The instances created from the <code>Factory</code> will be reused for processing
61
 * all keyboard input received by all documents of the same mime type, which the interceptor
62
 * instances were registered for (including documents that contain embedded sections
63
 * of that mime type). As described in the general concepts of Typing Hooks SPI
64
 * the interceptors are guaranteed to be called in AWT thread only, which means that
65
 * they should not need any internal synchronization model.
66
 *
67
 * <p><b>Processing rules</b>: If there are multiple instances of <code>TypedTextInterceptor</code> registered
68
 * for the same mime type the infrastructure will queue them up in their registration
69
 * order and when processing an event it will call them all until the processing is done
70
 * or terminated. 
71
 *
72
 * <p>The interceptor has several methods that are called at different stages of
73
 * the key typed event processing. When processing an event the infrastructure will call
74
 * the methods in the order as they are listed below. Moreover, if there are multiple
75
 * interceptors queued up for processing an event each method is first called on
76
 * all the queued interceptors before moving on to the next stage and calling next
77
 * method.
78
 *
79
 * <ul>
80
 * <li>{@link #beforeInsert(Context)} - It's called before any text is inserted
81
 *   into a document. No document lock is held when this method is called. The method
82
 *   can't modify the text that will be inserted (and it's not supposed to do any tricks to
83
 *   break this rule). An interceptor can stop further processing of the event by returning
84
 *   <code>true</code> from this method. If it does so, no other interceptors'
85
 *   <code>beforeInsert</code> method will be called and the processing will be terminated
86
 *   without inserting any text.
87
 *
88
 * <li>{@link #insert(MutableContext)} - This method is called during the text
89
 *   insertion stage immediately before the text is inserted into a document. At this
90
 *   time the document is already write locked, but the interceptors are not expected
91
 *   to modify its content directly. Instead they can change the text that will be
92
 *   inserted by calling {@link MutableContext#setText(java.lang.String, int)} method.
93
 *   The text insertion is strictly controlled by the infrastructure and has to obey some
94
 *   additional rules (eg. correctly replacing selected text, handling insert vs override
95
 *   modes of the caret, etc). The first interceptor that modifies the insertion text
96
 *   will win and no other interceptor's <code>insert</code> method will be called.
97
 *
98
 * <li>{@link #afterInsert(Context)} - This is the last method in the processing
99
 *   chain and it will be called when the text is already inserted in the document.
100
 *   Similarly as in <code>beforeInsert</code> the document is not locked when
101
 *   this method is called.
102
 * 
103
 * <li>{@link #cancelled(Context)} - This is an additional method that will be called
104
 *   when the processing is terminated in the before-insertion stage (ie. by an interceptor
105
 *   returning <code>true</code> from its <code>beforeInsert</code> method).
106
 *   The infrastructure will only call this method on interceptors that have already
107
 *   had their <code>beforeInsert</code> method called, but not on those that
108
 *   have not yet been called at all.
109
 * </ul>
110
 *
111
 * <p><b>Errors recovery</b>: If an exception is thrown from any of the methods
112
 * when calling an interceptor the infrastructure will catch it and log it,
113
 * but it will not stop further processing. The infrastructure may blacklist the offending
114
 * interceptor and exclude it from processing future events.
115
 *
116
 * @author Vita Stejskal
117
 * @since 1.31
118
 */
119
public interface TypedTextInterceptor {
120
121
    /**
122
     * This method is called before any text is inserted into a document. The context object
123
     * passed to the method provides access to the editor pane and the edited document,
124
     * but does not allow to modify the text that will be inserted.
125
     *
126
     * <p>This method can be used for stopping further processing of the current
127
     * key typed event. If this method returns <code>true</code> the processing will
128
     * be terminated and {@link #cancelled(Context)} will be called for all the intercetors
129
     * that have already had their <code>beforeInsert</code> method called (including
130
     * the one that terminated the processing). The rest of the interceptors waiting
131
     * in the queue will not be called at all.
132
     *
133
     * <p><b>Locking</b>: When this method is called the document is not locked
134
     * by the infrastructure.
135
     * 
136
     * @param context The context object providing information necessary for processing
137
     *   the event.
138
     *
139
     * @return If <code>true</code> the further processing will be stopped. Normally
140
     *   the method should return <code>false</code>.
141
     * @throws BadLocationException Since the document is not locked prior calling this
142
     *   method the processing may fail when working with stale context data.
143
     */
144
    boolean beforeInsert(Context context) throws BadLocationException;
145
146
    /**
147
     * This method is called immediately before the text is inserted into a document.
148
     * Implementors can use special <code>MutableContext</code> to modify the text
149
     * that will be inserted into a document. The first interceptor that mutates
150
     * the insertion text will win and the method will not be called on the rest
151
     * of the queued interceptors. The interceptors are not supposed to modify the
152
     * document directly.
153
     *
154
     * <p><b>Locking</b>: When this method is called the infrastructure has already
155
     * write locked the document.
156
     *
157
     * @param context The context object providing information necessary for processing
158
     *   the event and allowing to modify the insertion text.
159
     *
160
     * @throws BadLocationException If the processing fails.
161
     */
162
    void insert(MutableContext context) throws BadLocationException;
163
164
    /**
165
     * This method is called after text is inserted into a document and its editor's
166
     * caret is adjusted.
167
     *
168
     * <p><b>Locking</b>: When this method is called the document is not locked
169
     * by the infrastructure.
170
     *
171
     * @param context The context object providing information necessary for processing
172
     *   the event. The {@link Context#getText()} method will return text that was
173
     *   inserted into the document at the end of the text-insertion stage.
174
     * 
175
     * @throws BadLocationException Since the document is not locked prior calling this
176
     *   method the processing may fail when working with stale context data.
177
     */
178
    void afterInsert(Context context) throws BadLocationException;
179
180
    /**
181
     * This method is called when the normal processing is terminated by some
182
     * interceptor's <code>beforeInsert</code> method. Please note that this
183
     * method will not be called if the <code>beforeInsert</code> method was not
184
     * called.
185
     * 
186
     * @param context The context object used for calling the <code>beforeInsert</code>
187
     *   method.
188
     */
189
    void cancelled(Context context);
190
191
    /**
192
     * The context class providing information about the edited document, its
193
     * editor pane, insertion offset and text.
194
     */
195
    public static class Context {
196
197
        /**
198
         * Gets the editor component where the currently processed key typed event
199
         * occurred.
200
         *
201
         * @return The editor pane that contains the edited <code>Document</code>.
202
         */
203
        public JTextComponent getComponent() {
204
            return component;
205
        }
206
207
        /**
208
         * Gets the edited document. It's the document that will receive the insertion
209
         * text (ie the text typed by a user or its modification provided by an
210
         * interceptor).
211
         *
212
         * @return The edited document.
213
         */
214
        public Document getDocument() {
215
            return document;
216
        }
217
218
        /**
219
         * Gets the insertion offset. This is the offset in the document where
220
         * user typed the text (ie. where the currently processed <code>KeyEvent</code>
221
         * happened). This is also the offset where the insertion text will end up.
222
         *
223
         * @return The offset in the edited document.
224
         */
225
        public int getOffset() {
226
            return offset;
227
        }
228
229
        /**
230
         * Gets the insertion text. This is the text that was typed
231
         * by the user or its modification provided by one of the interceptors.
232
         *
233
         * <p>It is guaranteed that the text will have length equal to 1 for contexts
234
         * that are passed to <code>beforeInsert</code> and <code>insert</code>
235
         * methods. In these methods <code>getText</code> returns exactly what
236
         * a user typed in the editor.
237
         *
238
         * <p>In the <code>afterInsert</code> method the text returned from <code>getText</code>
239
         * method can have any length and will correspond to either the originally typed
240
         * text or to text supplied by one of the interceptors participating in
241
         * the key typed event processing.
242
         * 
243
         * @return The insertion text.
244
         */
245
        public String getText() {
246
            return originallyTypedText;
247
        }
248
249
        // -------------------------------------------------------------------
250
        // Private implementation
251
        // -------------------------------------------------------------------
252
253
        private final JTextComponent component;
254
        private final Document document;
255
        private final int offset;
256
        private final String originallyTypedText;
257
258
        /* package */ Context(JTextComponent component, int offset, String typedText) {
259
            this.component = component;
260
            this.document = component.getDocument();
261
            this.offset = offset;
262
            this.originallyTypedText = typedText;
263
        }
264
        
265
    } // End of Context class
266
267
    /**
268
     * This context class allows to modify the insertion text and the caret position
269
     * after the text is inserted into a document. Apart from that it provides exactly the same
270
     * information as its superclass <code>Context</code>.
271
     */
272
    public static final class MutableContext extends Context {
273
274
        public @Override String getText() {
275
            return insertionText != null ? insertionText : super.getText();
276
        }
277
278
        /**
279
         * Sets the insertion text and adjusted caret position. This method can
280
         * be used for modifying text typed by a user that would normally be
281
         * inserted into a document.
282
         *
283
         * <p>There is no restriction on the new text
284
         * set by this method, except that it must not be <code>null</code>. It can
285
         * be of any length (including an empty string) and can even span  multiple lines.
286
         *
287
         * <p>It is important to remember that the adjusted caret position is
288
         * relative to the new text. Therefore valid values for the <code>caretPosition</code>
289
         * parameter are <code>&lt;0, text.getLength()&gt;</code>! The adjusted position
290
         * is <b>not</b> a document offset.
291
         * 
292
         * @param text The new text that will be inserted to a document.
293
         * @param caretPosition The adjusted caret position <b>inside</b> the new text.
294
         *   This position is relative to the new text. Valid values for this parameter
295
         *   are <code>&lt;0, text.getLength()&gt;</code>.
296
         */
297
        public void setText(String text, int caretPosition) {
298
            assert text != null : "Invalid text, it must not be null."; //NOI18N
299
            assert caretPosition >= 0 && caretPosition <= text.length() : "Invalid caretPostion=" + caretPosition + ", text.length=" + text.length(); //NOI18N
300
301
            this.insertionText = text;
302
            this.caretPosition = caretPosition;
303
        }
304
305
        // -------------------------------------------------------------------
306
        // Private implementation
307
        // -------------------------------------------------------------------
308
309
        private String insertionText = null;
310
        private int caretPosition = -1;
311
        
312
        private MutableContext(JTextComponent c, int offset, String typedText) {
313
            super(c, offset, typedText);
314
        }
315
316
        private static final class Accessor extends TypingHooksSpiAccessor {
317
318
            @Override
319
            public MutableContext createTtiContext(JTextComponent c, int offset, String typedText) {
320
                return new MutableContext(c, offset, typedText);
321
            }
322
323
            @Override
324
            public Object[] getTtiContextData(MutableContext context) {
325
                return context.insertionText != null ?
326
                    new Object [] { context.insertionText, context.caretPosition } :
327
                    null;
328
            }
329
330
            @Override
331
            public void resetTtiContextData(MutableContext context) {
332
                context.insertionText = null;
333
                context.caretPosition = -1;
334
            }
335
336
            @Override
337
            public DeletedTextInterceptor.Context createDtiContext(JTextComponent c, int offset, String removedText, boolean backwardDelete) {
338
                return new DeletedTextInterceptor.Context(c, offset, removedText, backwardDelete);
339
            }
340
            
341
            @Override
342
            public TypedBreakInterceptor.MutableContext createTbiContext(JTextComponent c, int caretOffset, int insertBreakOffset) {
343
                return new TypedBreakInterceptor.MutableContext(c, caretOffset, insertBreakOffset);
344
            }
345
            
346
            @Override
347
            public Object [] getTbiContextData(TypedBreakInterceptor.MutableContext context) {
348
                return context.getData();
349
            }
350
            
351
            @Override
352
            public void resetTbiContextData(TypedBreakInterceptor.MutableContext context) {
353
                context.resetData();
354
            }
355
        } // End of Accessor class
356
357
        static {
358
            TypingHooksSpiAccessor.register(new Accessor());
359
        }
360
361
    } // End of MutableContext class
362
363
    /**
364
     * The factory interface for registering <code>TypedTextInterceptor</code>s
365
     * in <code>MimeLookup</code>. An example registration in an XML layer shown
366
     * below registers <code>Factory</code> implementation under <code>text/x-something</code>
367
     * mime type in <code>MimeLookup</code>.
368
     *
369
     * <pre>
370
     * &lt;folder name="Editors"&gt;
371
     *  &lt;folder name="text"&gt;
372
     *   &lt;folder name="x-something"&gt;
373
     *    &lt;file name="org-some-module-TTIFactory.instance" /&gt;
374
     *   &lt;/folder&gt;
375
     *  &lt;/folder&gt;
376
     * &lt;/folder&gt;
377
     * </pre>
378
     */
379
    public interface Factory {
380
381
        /**
382
         * Creates a new interceptor for the given <code>MimePath</code>.
383
         * 
384
         * @param mimePath The <code>MimePath</code> for which the infrastructure
385
         *   needs the new interceptor. Typically this is the same <code>MimePath</code>
386
         *   where this <code>Factory</code> was registered, but in embedded scenarios
387
         *   this can be a different <code>MimePath</code>.
388
         *
389
         * @return The new interceptor.
390
         */
391
        TypedTextInterceptor createTypedTextInterceptor(MimePath mimePath);
392
    } // End of Factory interface
393
394
}
(-)a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/package.html (+251 lines)
Line 0 Link Here
1
<!--
2
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
4
Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
6
7
The contents of this file are subject to the terms of either the GNU
8
General Public License Version 2 only ("GPL") or the Common
9
Development and Distribution License("CDDL") (collectively, the
10
"License"). You may not use this file except in compliance with the
11
License. You can obtain a copy of the License at
12
http://www.netbeans.org/cddl-gplv2.html
13
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
14
specific language governing permissions and limitations under the
15
License.  When distributing the software, include this License Header
16
Notice in each file and include the License file at
17
nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
18
particular file as subject to the "Classpath" exception as provided
19
by Sun in the GPL Version 2 section of the License file that
20
accompanied this code. If applicable, add the following below the
21
License Header, with the fields enclosed by brackets [] replaced by
22
your own identifying information:
23
"Portions Copyrighted [year] [name of copyright owner]"
24
25
Contributor(s):
26
27
The Original Software is NetBeans. The Initial Developer of the Original
28
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
29
Microsystems, Inc. All Rights Reserved.
30
31
If you wish your version of this file to be governed by only the CDDL
32
or only the GPL Version 2, indicate your decision by adding
33
"[Contributor] elects to include this software in this distribution
34
under the [CDDL or GPL Version 2] license." If you do not indicate a
35
single choice of license, a recipient has the option to distribute
36
your version of this file under either the CDDL, the GPL Version 2 or
37
to extend the choice of license to its licensees as provided above.
38
However, if you add GPL Version 2 code and therefore, elected the GPL
39
Version 2 license, then the option applies only if the new code is
40
made subject to such option by the copyright holder.
41
-->
42
43
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
44
45
<html>
46
  <head>
47
    <title>org.netbeans.spi.editor.lib2.typinghooks</title>
48
  </head>
49
  <body>
50
51
  <p>
52
  The Typing Hooks SPI allows modules to intercept various key typed events
53
  handled by the editor infrastructure. Historically, this was possible by subclassing
54
  editor actions such as <code>DefaultKeyTypedAction</code> or <code>InsertBrakeAction</code>
55
  and overwriting their <code>performAction</code> method. This however is not very
56
  flexible approach. It's main drawback is that modules can't easily intercept
57
  key typed events handled in editors (eg. <code>EditorKit</code>s) that are provided
58
  by other modules. The Typing Hooks SPI addresses these drawbacks while providing
59
  semantically compatible functionality with what used to be possible by subclassing editor actions.
60
  </p>
61
62
  <p>
63
  The editor actions superceded by Typing Hooks SPI are still available and the code
64
  that uses them should still work. But they will be deprecated and eventually removed.
65
  </p>
66
67
68
  <h3>Keyboard input processing</h3>
69
70
  <p>
71
  Netbeans editor panes are ordinary <code>JTextComponent</code>s and therefore
72
  they fully follow keyboard events processing scheme defined by Swing (please read
73
  more about <i>Text Input</i> in <code>JTextComponent</code>'s javadoc). For the
74
  purpose of understanding Typing Hooks SPI it is important to note that
75
  the SPI interceptors are at the very end of the <code>KeyEvent</code> processing
76
  pipeline, which means that some <code>KeyEvent</code>s may never reach
77
  them. However, in a typical environment these events will not present
78
  printable characters that could be inserted in an edited document. Typically they are
79
  shortcuts bound to special actions in the editor's <code>Keymap</code> (newly
80
  a pair of <code>InputMap</code>, <code>ActionMap</code>).
81
  </p>
82
83
  <p>
84
  In general the SPI provides several different types of interceptors (interfaces)
85
  that clients can implement and register for a document type (mimetype) of their
86
  interest. Each interceptor type is meant to process different types of keyboard
87
  input. The interceptor types currently available are listed below.
88
  </p>
89
90
  <ul>
91
  <li><code>TypedTextInterceptor</code> - processes <code>KeyTyped</code> events
92
  that would normally be processed by <code>DefaultKeyTypedAction</code> registered
93
  for a given editor type. Any other <code>KeyEvent</code> that has an <code>Action</code> associated
94
  in the editor pane's keymap will trigger that <code>Action</code> and will <b>not</b> reach
95
  registered interceptors of this type.
96
  </li>
97
  <li><code>TypedBreakInterceptor</code> - processes <code>KeyTyped</code> events
98
  that would normally result in inserting a line break in the edited document.
99
  </li>
100
  <li><code>DeletedTextInterceptor</code> - processes <code>KeyTyped</code> events
101
  that would normally remove text from the edited document.
102
  </li>
103
  </ul>
104
105
106
  <h3>Registering interceptors</h3>
107
  
108
  <p>
109
  Interceptors are created by calling a factory implementation registered in
110
  <code>MimeLookup</code>. For example an implementation of <code>TypedTextInterceptor</code>
111
  can be plugged in by registering <code>TypedTextInterceptor.Factory</code> instance
112
  for the appropriate mimetype in <code>MimeLookup</code>. The snippet below shows
113
  how this registration could look.
114
  </p>
115
  
116
  <pre>
117
&lt;folder name="Editors"&gt;
118
  &lt;folder name="text"&gt;
119
    &lt;folder name="x-something"&gt;
120
        &lt;file name="org-some-module-TTIFactory.instance" /&gt;
121
    &lt;/folder&gt;
122
  &lt;/folder&gt;
123
&lt;/folder&gt;
124
  </pre>
125
126
  <p>
127
  The <code>TTIFactory</code> class will simply return a new instance of
128
  the module's implementation of <code>TypedTextInterceptor</code> interface from its
129
  <code><a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.Factory.html#createTypedTextInterceptor(org.netbeans.api.editor.mimelookup.MimePath)">createTypedTextInterceptor</a></code>
130
  method. 
131
  </p>
132
133
  
134
  <h3>Interceptors lifecycle</h3>
135
136
  <p>
137
  In general interceptors are created as they are needed. However, unlike in other editor SPIs where SPI
138
  implementation objects are short lived and get all their information in the form of a context object
139
  from the factory that created them, the interceptors are long lived objects that are created with a minimal
140
  context and reused many times. The reason for this is mostly performance considerations. Typically
141
  there are many keyboard events as users type and their processing has to be as fast as possible.
142
  </p>
143
144
  <p>
145
  The interceptors are created for a document type or more precisely for a <code>MimePath</code>
146
  of the document fragment, where a user is typing. This allows to call different interceptors
147
  depending on where in the document a particular keyboard event happens. Therefore embedded
148
  sections can use different interceptors than the main document.
149
  </p>
150
151
  <p>
152
  The <code>MimePath</code> is the only context that the interceptor factory gets from
153
  the infrastructure and it is the only context that it is supposed to pass to interceptor
154
  instances that it creates. All the other information needed for a particular interceptor type
155
  to do its job will be provided at the time when an event happens and the interceptor is called
156
  to process it. This makes it possible to reuse one interceptor implementation many times
157
  for processing different events in different documents.
158
  </p>
159
160
161
  <h3>Threading and synchronization</h3>
162
163
  <p>
164
  As explained earlier Netbeans editors follow swing concepts for handling keyboard
165
  events. All keyboard events processing and editor actions invocation in swing
166
  editors is done in the AWT thread, which means that events are processed in one
167
  thread only and in the order as they happened. The same applies for interceptors
168
  and Typing Hooks SPI in general.
169
  </p>
170
171
  <p>
172
  In particular it is guaranteed that only one interceptor is used at a time and
173
  it's always called from AWT thread. Therefore a typical interceptor does not have to use
174
  any explicit synchronization code (unless it accesses a resource that
175
  can be simultaneously accessed from other threads of course).
176
  </p>
177
178
  <p>
179
  However, interceptor types may define a specific protocol, which determines how interceptors
180
  of that type are chained, what methods are called first, if and what document locks are
181
  acquired prior calling the interceptor, conditions when the event processing
182
  can be interrupted, what happens with the rest of the queued interceptors, etc.
183
  Please see documentation of each interceptor type interface for detailed information.
184
  </p>
185
186
187
  <h3><a name="usecases">Use cases</a></h3>
188
  
189
  <h4>Use case 1. - Automated indentation</h4>
190
191
  <p>
192
  Many languages need to automatically reindent lines as user types certain
193
  statements. For example in java language the 'case' statements in a 'switch' block
194
  should be aligned to the same column similarly as in the code snippet below.
195
  The java editor helps users to do that by automatically indenting the lines that
196
  contain 'case' statements as soon as a user types the double colon at the end of the statement.
197
  </p>
198
199
  <pre>
200
    switch(price) {
201
      case 100:
202
        // do something cheap
203
        break;
204
205
      case 1000:
206
        // do something more expensive
207
        break;
208
    }
209
  </pre>
210
211
  <p>
212
  This can easily be done by implementing
213
  <code><a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.html">TypedTextInterceptor</a></code>
214
  and its <code>afterInsert</code> method. The implementation can check the text
215
  inserted in the document as a result of the key typed event processing and reindent
216
  the line if its text matches required pattern.
217
  </p>
218
219
  <p>
220
  Moreover, the <a href="@org-netbeans-modules-editor-indent@/overview-summary.html">Editor Indentation API</a>
221
  provides an implementation of <code>TypedTextInterceptor</code>, which reindents lines that
222
  match provided regular expressions. Please see <code><a href="@org-netbeans-modules-editor-indent@/org/netbeans/modules/editor/indent/spi/support/AutomatedIndenting.html">AutomatedIndenting</a></code>
223
  class for more details.
224
  </p>
225
226
  <h4>Use case 2. - Pair characters completion</h4>
227
  
228
  <p>
229
  It can safe a lot of typing if the editor correctly completes pair characters
230
  such as <code>()</code>, <code>{}</code>, <code>""</code>, <code>''</code>, etc.
231
  For example when one of the pair character is typed or deleted the editor
232
  automatically adds or removes its couterpart. Additionally, the editor may wrap selected text in
233
  the pair characters such as quotes <code>""</code> if one of them is typed (eg. in java producing a string literal).
234
  </p>
235
236
  <p>
237
  These features can be implemented by providing specialized
238
  <code><a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.html">TypedTextInterceptor</a></code>
239
  and
240
  <code><a href="@org-netbeans-modules-editor-lib2@/org/netbeans/spi/editor/typinghooks/DeletedTextInterceptor.html">DeletedTextInterceptor</a></code>
241
  implementations.
242
  </p>
243
  
244
<!--
245
  
246
  
247
  <h4>Other usecases</h4>
248
-->
249
  
250
  </body>
251
</html>
(-)a/editor.macros/nbproject/project.xml (-2 / +2 lines)
Lines 20-26 Link Here
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>3</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>1.41</specification-version>
23
                        <specification-version>1.53</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
Lines 28-34 Link Here
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <implementation-version/>
32
                        <implementation-version/>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
(-)a/editor.mimelookup.impl/src/org/netbeans/modules/editor/mimelookup/impl/DefaultMimeDataProvider.java (-1 / +1 lines)
Lines 52-58 Link Here
52
 *
52
 *
53
 * @author vita
53
 * @author vita
54
 */
54
 */
55
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.editor.mimelookup.MimeDataProvider.class)
55
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.editor.mimelookup.MimeDataProvider.class, position=0)
56
public class DefaultMimeDataProvider implements MimeDataProvider {
56
public class DefaultMimeDataProvider implements MimeDataProvider {
57
57
58
    /** Creates a new instance of DefaultMimeDataProvider */
58
    /** Creates a new instance of DefaultMimeDataProvider */
(-)a/editor.mimelookup/src/org/netbeans/modules/editor/mimelookup/MimePathLookup.java (+14 lines)
Lines 113-123 Link Here
113
    private void rebuild() {
113
    private void rebuild() {
114
        ArrayList<Lookup> lookups = new ArrayList<Lookup>();
114
        ArrayList<Lookup> lookups = new ArrayList<Lookup>();
115
115
116
        if (LOG.isLoggable(Level.FINE)) {
117
            LOG.fine("Rebuilding MimeLookup for '" + mimePath.getPath() + "'..."); //NOI18N
118
        }
119
116
        // Add lookups from MimeDataProviders
120
        // Add lookups from MimeDataProviders
117
        for (MimeDataProvider provider : dataProviders.allInstances()) {
121
        for (MimeDataProvider provider : dataProviders.allInstances()) {
118
            if (mimePathBanned && !isDefaultProvider(provider)) {
122
            if (mimePathBanned && !isDefaultProvider(provider)) {
119
                continue;
123
                continue;
120
            }
124
            }
125
            if (LOG.isLoggable(Level.FINE)) {
126
                LOG.fine("- Querying MimeDataProvider(" + mimePath.getPath() + "): " + provider); //NOI18N
127
            }
121
            Lookup mimePathLookup = provider.getLookup(mimePath);
128
            Lookup mimePathLookup = provider.getLookup(mimePath);
122
            if (mimePathLookup != null) {
129
            if (mimePathLookup != null) {
123
                lookups.add(mimePathLookup);
130
                lookups.add(mimePathLookup);
Lines 160-165 Link Here
160
            }
167
            }
161
168
162
            for(MimeLookupInitializer mli : initializers) {
169
            for(MimeLookupInitializer mli : initializers) {
170
                if (LOG.isLoggable(Level.FINE)) {
171
                    LOG.fine("- Querying MimeLookupInitializer(" + path + "): " + mli); //NOI18N
172
                }
163
                Lookup mimePathLookup = mli.lookup();
173
                Lookup mimePathLookup = mli.lookup();
164
                if (mimePathLookup != null) {
174
                if (mimePathLookup != null) {
165
                    lookups.add(mimePathLookup);
175
                    lookups.add(mimePathLookup);
Lines 167-172 Link Here
167
            }
177
            }
168
        }
178
        }
169
179
180
        if (LOG.isLoggable(Level.FINE)) {
181
            LOG.fine("MimeLookup for '" + mimePath.getPath() + "' rebuilt."); //NOI18N
182
        }
183
170
        setLookups(lookups.toArray(new Lookup[lookups.size()]));
184
        setLookups(lookups.toArray(new Lookup[lookups.size()]));
171
    }
185
    }
172
186
(-)a/editor.plain.lib/nbproject/project.xml (-2 / +2 lines)
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
            </module-dependencies>
61
            </module-dependencies>
(-)a/editor.plain/nbproject/project.xml (-3 / +3 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.41</specification-version>
58
                        <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/editor.structure/nbproject/project.xml (-2 / +11 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
Lines 100-105 Link Here
100
                        <specification-version>8.0</specification-version>
100
                        <specification-version>8.0</specification-version>
101
                    </run-dependency>
101
                    </run-dependency>
102
                </dependency>
102
                </dependency>
103
                <dependency>
104
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
105
                    <build-prerequisite/>
106
                    <compile-dependency/>
107
                    <run-dependency>
108
                        <release-version>0-1</release-version>
109
                        <specification-version>1.0</specification-version>
110
                    </run-dependency>
111
                </dependency>
103
            </module-dependencies>
112
            </module-dependencies>
104
            <test-dependencies>
113
            <test-dependencies>
105
                <test-type>
114
                <test-type>
(-)a/editor/apichanges.xml (+62 lines)
Lines 108-113 Link Here
108
108
109
    <changes>
109
    <changes>
110
110
111
        <change id="deprecating-formatting">
112
            <api name="editor"/>
113
            <summary>Deprecating old formatting API</summary>
114
            <version major="1" minor="53"/>
115
            <date day="24" month="8" year="2010"/>
116
            <author login="vstejskal"/>
117
            <compatibility binary="compatible" source="incompatible" semantic="incompatible" addition="yes" deprecation="yes" modification="yes" deletion="yes"/>
118
            <description>
119
                <p>
120
                    The old formatting API (<code>org.netbeans.editor.Formatter</code> &amp; co.)
121
                    has been deprecated and moved to <code>editor.deprecated.pre65formatting</code> module.
122
                </p>
123
                <p>The exact API changes are listed in the sigtest report below.</p>
124
<pre>
125
-sigtest-init:
126
     [echo] sigtest check: editor; cnb: org-netbeans-modules-editor; email: api-changes@netbeans.org; type: check
127
128
check-sigtest:
129
    [mkdir] Created dir: /work/netbeans/main2m/editor/build/test/sigtest/results
130
  [sigtest] /work/netbeans/main2m/editor/build/test/sigtest/results/org.netbeans.modules.editor
131
  [sigtest] Packages: org.netbeans.modules.editor.*, org.netbeans.modules.editor.options.*
132
  [sigtest] Missing /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/rt.jar
133
  [sigtest] 
134
  [sigtest] email: api-changes@netbeans.org
135
  [sigtest] SignatureTest report
136
  [sigtest] Base version: 1.51.0
137
  [sigtest] Tested version: 1.51.0
138
  [sigtest] Check mode: bin [throws removed]
139
  [sigtest] Constant checking: on
140
  [sigtest] 
141
  [sigtest] 
142
  [sigtest] Class org.netbeans.modules.editor.FormatterIndentEngine
143
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract org.netbeans.modules.editor.FormatterIndentEngine
144
  [sigtest] 
145
  [sigtest] Class org.netbeans.modules.editor.FormatterIndentEngineBeanInfo
146
  [sigtest]   "E1.2 - API type removed" : CLASS public abstract org.netbeans.modules.editor.FormatterIndentEngineBeanInfo
147
  [sigtest] 
148
  [sigtest] Class org.netbeans.modules.editor.IndentEngineFormatter
149
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.modules.editor.IndentEngineFormatter
150
  [sigtest] 
151
  [sigtest] Class org.netbeans.modules.editor.NbEditorDocument
152
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getFormatter()
153
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseDocument.getLegacyFormatter()
154
  [sigtest] 
155
  [sigtest] Class org.netbeans.modules.editor.NbEditorKit
156
  [sigtest]   "E1.2 - API type removed" : method public org.netbeans.editor.Formatter org.netbeans.editor.BaseKit.createFormatter()
157
  [sigtest] 
158
  [sigtest] Class org.netbeans.modules.editor.SimpleIndentEngine
159
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.modules.editor.SimpleIndentEngine
160
  [sigtest] 
161
  [sigtest] Class org.netbeans.modules.editor.SimpleIndentEngineBeanInfo
162
  [sigtest]   "E1.2 - API type removed" : CLASS public org.netbeans.modules.editor.SimpleIndentEngineBeanInfo
163
  [sigtest] 
164
  [sigtest] /work/netbeans/main2m/editor/build/test/sigtest/results/org-netbeans-modules-editor.xml: 1 failures in /work/netbeans/main2m/editor/nbproject/org-netbeans-modules-editor.sig
165
166
BUILD FAILED
167
Signature tests return code is wrong (1), check the messages above
168
</pre>
169
            </description>
170
            <issue number="189638"/>
171
        </change>
172
        
111
        <change id="deprecating-settings">
173
        <change id="deprecating-settings">
112
            <api name="editor"/>
174
            <api name="editor"/>
113
            <summary>Deprecating old settings API</summary>
175
            <summary>Deprecating old settings API</summary>
(-)a/editor/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.editor/3
2
OpenIDE-Module: org.netbeans.modules.editor/3
3
OpenIDE-Module-Implementation-Version: 3
3
OpenIDE-Module-Implementation-Version: 5
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/Bundle.properties
5
OpenIDE-Module-Install: org/netbeans/modules/editor/EditorModule.class
5
OpenIDE-Module-Install: org/netbeans/modules/editor/EditorModule.class
6
OpenIDE-Module-Layer: org/netbeans/modules/editor/resources/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/editor/resources/layer.xml
(-)a/editor/module-auto-deps.xml (-1 / +17 lines)
Lines 48-54 Link Here
48
48
49
<transformations version="1.0">
49
<transformations version="1.0">
50
    <transformationgroup>
50
    <transformationgroup>
51
        <description>Old editor settings and completion APIs have been deprecated, see http://wiki.netbeans.org/EditorSettingsUpgrade and update your module.</description>
51
        <description>The old editor settings and completion APIs have been deprecated, see http://wiki.netbeans.org/EditorSettingsUpgrade and update your module.</description>
52
        <transformation>
52
        <transformation>
53
            <trigger-dependency type="older">
53
            <trigger-dependency type="older">
54
                <module-dependency codenamebase="org.netbeans.modules.editor" major="3" spec="1.41"/>
54
                <module-dependency codenamebase="org.netbeans.modules.editor" major="3" spec="1.41"/>
Lines 56-64 Link Here
56
            <implies>
56
            <implies>
57
                <result>
57
                <result>
58
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61completion" major="0" spec="1.0"/>
58
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61completion" major="0" spec="1.0"/>
59
                </result>
60
                <result>
59
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61settings" major="0" spec="1.0"/>
61
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre61settings" major="0" spec="1.0"/>
60
                </result>
62
                </result>
61
            </implies>
63
            </implies>
62
        </transformation>
64
        </transformation>
63
    </transformationgroup>
65
    </transformationgroup>
66
    
67
    <transformationgroup>
68
        <description>The old editor formatting API have been deprecated, see http://wiki.netbeans.org/EditorFormattingAPIUpgrade and update your module.</description>
69
        <transformation>
70
            <trigger-dependency type="older">
71
                <module-dependency codenamebase="org.netbeans.modules.editor" major="3" spec="1.53"/>
72
            </trigger-dependency>
73
            <implies>
74
                <result>
75
                    <module-dependency codenamebase="org.netbeans.modules.editor.deprecated.pre65formatting" major="0" spec="1.0"/>
76
                </result>
77
            </implies>
78
        </transformation>
79
    </transformationgroup>
64
</transformations>
80
</transformations>
(-)a/editor/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
42
43
javac.compilerargs=-Xlint:unchecked
43
javac.compilerargs=-Xlint:unchecked
44
javac.source=1.6
44
javac.source=1.6
45
spec.version.base=1.52.0
45
spec.version.base=1.53.0
46
is.autoload=true
46
is.autoload=true
47
47
48
javadoc.arch=${basedir}/arch.xml
48
javadoc.arch=${basedir}/arch.xml
(-)a/editor/nbproject/project.xml (-1 / +1 lines)
Lines 72-78 Link Here
72
                    <build-prerequisite/>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>2</release-version>
75
                        <release-version>3</release-version>
76
                        <implementation-version/>
76
                        <implementation-version/>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
(-)a/editor/src/org/netbeans/modules/editor/impl/ComplexValueSettingsFactory.java (-21 / +22 lines)
Lines 44-58 Link Here
44
44
45
import java.util.Collection;
45
import java.util.Collection;
46
import java.util.prefs.Preferences;
46
import java.util.prefs.Preferences;
47
import javax.swing.text.EditorKit;
48
import org.netbeans.api.editor.mimelookup.MimeLookup;
47
import org.netbeans.api.editor.mimelookup.MimeLookup;
49
import org.netbeans.api.editor.mimelookup.MimePath;
48
import org.netbeans.api.editor.mimelookup.MimePath;
50
import org.netbeans.api.editor.settings.EditorStyleConstants;
49
import org.netbeans.api.editor.settings.EditorStyleConstants;
51
import org.netbeans.api.editor.settings.FontColorNames;
50
import org.netbeans.api.editor.settings.FontColorNames;
52
import org.netbeans.api.editor.settings.FontColorSettings;
51
import org.netbeans.api.editor.settings.FontColorSettings;
53
import org.netbeans.editor.AcceptorFactory;
52
import org.netbeans.editor.AcceptorFactory;
54
import org.netbeans.modules.editor.FormatterIndentEngine;
55
import org.netbeans.modules.editor.IndentEngineFormatter;
56
import org.netbeans.modules.editor.NbEditorDocument;
53
import org.netbeans.modules.editor.NbEditorDocument;
57
import org.netbeans.modules.editor.lib.SettingsConversions;
54
import org.netbeans.modules.editor.lib.SettingsConversions;
58
import org.openide.text.IndentEngine;
55
import org.openide.text.IndentEngine;
Lines 86-110 Link Here
86
    // 'formatter' setting
83
    // 'formatter' setting
87
    // -----------------------------------------------------------------------
84
    // -----------------------------------------------------------------------
88
85
89
    public static final Object getFormatterValue(MimePath mimePath, String settingName) {
86
// This was moved to editor.deprecated.pre65formatting module as well as the layer preferences.xml
90
        assert settingName.equals(NbEditorDocument.FORMATTER) : "The getFormatter factory called for '" + settingName + "'"; //NOI18N
87
// which accesses this method.
88
//
89
//    public static final Object getFormatterValue(MimePath mimePath, String settingName) {
90
//        assert settingName.equals(NbEditorDocument.FORMATTER) : "The getFormatter factory called for '" + settingName + "'"; //NOI18N
91
//
92
//        IndentEngine eng = getIndentEngine(mimePath);
93
//
94
//        if (eng != null) {
95
//            if (eng instanceof FormatterIndentEngine) {
96
//                return ((FormatterIndentEngine)eng).getFormatter();
97
//            } else {
98
//                EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
99
//                if (kit != null) {
100
//                    return new IndentEngineFormatter(kit.getClass(), eng);
101
//                }
102
//            }
103
//        }
104
//        
105
//        return null;
106
//    }
91
107
92
        IndentEngine eng = getIndentEngine(mimePath);
108
    // This is not called from a layer, but from NbEditorDocument and e.d.pre65formatting/.../ComplexValueSettingsFactory.getFormatterValue
93
94
        if (eng != null) {
95
            if (eng instanceof FormatterIndentEngine) {
96
                return ((FormatterIndentEngine)eng).getFormatter();
97
            } else {
98
                EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
99
                if (kit != null) {
100
                    return new IndentEngineFormatter(kit.getClass(), eng);
101
                }
102
            }
103
        }
104
        
105
        return null;
106
    }
107
108
    public static final IndentEngine getIndentEngine(MimePath mimePath) {
109
    public static final IndentEngine getIndentEngine(MimePath mimePath) {
109
        IndentEngine eng = null;
110
        IndentEngine eng = null;
110
111
(-)a/editor/src/org/netbeans/modules/editor/resources/NetBeans-preferences.xml (-3 lines)
Lines 261-269 Link Here
261
        <value><![CDATA[none]]></value>
261
        <value><![CDATA[none]]></value>
262
    </entry>
262
    </entry>
263
    
263
    
264
    <entry category="deprecated" javaType="methodvalue" name="formatter" xml:space="preserve">
265
        <value><![CDATA[org.netbeans.modules.editor.impl.ComplexValueSettingsFactory.getFormatterValue]]></value>
266
    </entry>
267
    <entry category="deprecated" javaType="methodvalue" name="rendering-hints" xml:space="preserve">
264
    <entry category="deprecated" javaType="methodvalue" name="rendering-hints" xml:space="preserve">
268
        <value><![CDATA[org.netbeans.modules.editor.impl.ComplexValueSettingsFactory.getRenderingHintsValue]]></value>
265
        <value><![CDATA[org.netbeans.modules.editor.impl.ComplexValueSettingsFactory.getRenderingHintsValue]]></value>
269
    </entry>
266
    </entry>
(-)a/form/nbproject/project.xml (-2 / +2 lines)
Lines 149-156 Link Here
149
                    <build-prerequisite/>
149
                    <build-prerequisite/>
150
                    <compile-dependency/>
150
                    <compile-dependency/>
151
                    <run-dependency>
151
                    <run-dependency>
152
                        <release-version>2</release-version>
152
                        <release-version>3</release-version>
153
                        <specification-version>2.1</specification-version>
153
                        <specification-version>3.1</specification-version>
154
                    </run-dependency>
154
                    </run-dependency>
155
                </dependency>
155
                </dependency>
156
                <dependency>
156
                <dependency>
(-)a/gototest/nbproject/project.xml (-2 / +2 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/groovy.editor/nbproject/project.xml (-3 / +3 lines)
Lines 73-79 Link Here
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>3</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>1.41</specification-version>
76
                        <specification-version>1.53</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
Lines 99-106 Link Here
99
                    <build-prerequisite/>
99
                    <build-prerequisite/>
100
                    <compile-dependency/>
100
                    <compile-dependency/>
101
                    <run-dependency>
101
                    <run-dependency>
102
                        <release-version>2</release-version>
102
                        <release-version>3</release-version>
103
                        <specification-version>2.1</specification-version>
103
                        <specification-version>3.1</specification-version>
104
                    </run-dependency>
104
                    </run-dependency>
105
                </dependency>
105
                </dependency>
106
                <dependency>
106
                <dependency>
(-)a/groovy.grailsproject/nbproject/project.xml (-3 / +3 lines)
Lines 65-71 Link Here
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>3</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>1.41</specification-version>
68
                        <specification-version>1.53</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
Lines 73-80 Link Here
73
                    <build-prerequisite/>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
74
                    <compile-dependency/>
75
                    <run-dependency>
75
                    <run-dependency>
76
                        <release-version>2</release-version>
76
                        <release-version>3</release-version>
77
                        <specification-version>2.1</specification-version>
77
                        <specification-version>3.1</specification-version>
78
                    </run-dependency>
78
                    </run-dependency>
79
                </dependency>
79
                </dependency>
80
                <dependency>
80
                <dependency>
(-)a/groovy.gsp/nbproject/project.xml (-3 / +3 lines)
Lines 11-17 Link Here
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.41</specification-version>
14
                        <specification-version>1.53</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
Lines 37-44 Link Here
37
                    <build-prerequisite/>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>2</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>2.1</specification-version>
41
                        <specification-version>3.1</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
(-)a/groovy.refactoring/nbproject/project.xml (-2 / +2 lines)
Lines 36-43 Link Here
36
                    <build-prerequisite/>
36
                    <build-prerequisite/>
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>2</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>2.1</specification-version>
40
                        <specification-version>3.1</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
(-)a/gsf.api/nbproject/project.xml (-3 / +3 lines)
Lines 11-17 Link Here
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.42</specification-version>
14
                        <specification-version>1.53</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
Lines 28-35 Link Here
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>2.1</specification-version>
32
                        <specification-version>3.1</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/gsf.api/src/org/netbeans/modules/gsf/api/EditList.java (-44 / +37 lines)
Lines 49-54 Link Here
49
import javax.swing.text.Position;
49
import javax.swing.text.Position;
50
import javax.swing.text.StyledDocument;
50
import javax.swing.text.StyledDocument;
51
import org.netbeans.editor.BaseDocument;
51
import org.netbeans.editor.BaseDocument;
52
import org.netbeans.modules.editor.indent.api.Reformat;
52
import org.openide.text.NbDocument;
53
import org.openide.text.NbDocument;
53
import org.openide.util.Exceptions;
54
import org.openide.util.Exceptions;
54
55
Lines 139-196 Link Here
139
        Collections.sort(edits);
140
        Collections.sort(edits);
140
        Collections.reverse(edits);
141
        Collections.reverse(edits);
141
142
142
        doc.runAtomic(new Runnable() {
143
        final Reformat f = Reformat.get(doc);
144
        f.lock();
145
        try {
146
            doc.runAtomic(new Runnable() {
143
147
144
            public void run() {
148
                public void run() {
145
                try {
149
                    try {
146
                    int lastOffset = edits.get(0).offset;
150
                        int lastOffset = edits.get(0).offset;
147
                    Position lastPos = doc.createPosition(lastOffset, Position.Bias.Forward);
151
                        Position lastPos = doc.createPosition(lastOffset, Position.Bias.Forward);
148
152
149
                    // Apply edits in reverse order (to keep offsets accurate)
153
                        // Apply edits in reverse order (to keep offsets accurate)
150
                    for (Edit edit : edits) {
154
                        for (Edit edit : edits) {
151
                        if (edit.removeLen > 0) {
155
                            if (edit.removeLen > 0) {
152
                            doc.remove(edit.offset, edit.removeLen);
156
                                doc.remove(edit.offset, edit.removeLen);
153
                        }
157
                            }
154
                        if (edit.getInsertText() != null) {
158
                            if (edit.getInsertText() != null) {
155
                            doc.insertString(edit.offset, edit.insertText, null);
159
                                doc.insertString(edit.offset, edit.insertText, null);
156
                            int end = edit.offset + edit.insertText.length();
160
                                int end = edit.offset + edit.insertText.length();
157
                            for (int i = 0; i < positions.size(); i++) {
161
                                for (int i = 0; i < positions.size(); i++) {
158
                                DelegatedPosition pos = positions.get(i);
162
                                    DelegatedPosition pos = positions.get(i);
159
                                int positionOffset = pos.originalOffset;
163
                                    int positionOffset = pos.originalOffset;
160
                                if (edit.getOffset() <= positionOffset && end >= positionOffset) {
164
                                    if (edit.getOffset() <= positionOffset && end >= positionOffset) {
161
                                    pos.delegate = doc.createPosition(positionOffset, pos.bias); // Position of the comment
165
                                        pos.delegate = doc.createPosition(positionOffset, pos.bias); // Position of the comment
166
                                    }
162
                                }
167
                                }
163
                            }
168
                                if (edit.format) {
164
                            if (edit.format) {
169
                                    f.reformat(edit.offset, end);
165
                                @SuppressWarnings("deprecation") // For doc.getFormatter()
166
                                final org.netbeans.editor.Formatter f = doc.getFormatter();
167
                                try {
168
                                    f.reformatLock();
169
                                    f.reformat(doc, edit.offset, end);
170
                                } finally {
171
                                    f.reformatUnlock();
172
                                }
170
                                }
173
                            }
171
                            }
174
                        }
172
                        }
173
174
                        if (formatAll) {
175
                            int firstOffset = edits.get(edits.size() - 1).offset;
176
                            lastOffset = lastPos.getOffset();
177
                            f.reformat(firstOffset, lastOffset);
178
                        }
179
                    } catch (BadLocationException ble) {
180
                        Exceptions.printStackTrace(ble);
175
                    }
181
                    }
176
177
                    if (formatAll) {
178
                        int firstOffset = edits.get(edits.size() - 1).offset;
179
                        lastOffset = lastPos.getOffset();
180
                        @SuppressWarnings("deprecation")
181
                        final org.netbeans.editor.Formatter f = doc.getFormatter();
182
                        try {
183
                            f.reformatLock();
184
                            f.reformat(doc, firstOffset, lastOffset);
185
                        } finally {
186
                            f.reformatUnlock();
187
                        }
188
                    }
189
                } catch (BadLocationException ble) {
190
                    Exceptions.printStackTrace(ble);
191
                }
182
                }
192
            }
183
            });
193
        });
184
        } finally {
185
            f.unlock();
186
        }
194
    }
187
    }
195
    
188
    
196
    public OffsetRange getRange() {
189
    public OffsetRange getRange() {
(-)a/gsf.codecoverage/nbproject/project.xml (-2 / +2 lines)
Lines 28-35 Link Here
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>2.1</specification-version>
32
                        <specification-version>3.1</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/gsf/nbproject/project.xml (-3 / +3 lines)
Lines 38-44 Link Here
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>3</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>1.41</specification-version>
41
                        <specification-version>1.53</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
Lines 100-107 Link Here
100
                    <build-prerequisite/>
100
                    <build-prerequisite/>
101
                    <compile-dependency/>
101
                    <compile-dependency/>
102
                    <run-dependency>
102
                    <run-dependency>
103
                        <release-version>2</release-version>
103
                        <release-version>3</release-version>
104
                        <specification-version>2.1</specification-version>
104
                        <specification-version>3.1</specification-version>
105
                    </run-dependency>
105
                    </run-dependency>
106
                </dependency>
106
                </dependency>
107
                <dependency>
107
                <dependency>
(-)a/gsf/test/unit/src/org/netbeans/modules/gsf/GsfTestBase.java (-11 / +6 lines)
Lines 155-160 Link Here
155
import org.netbeans.editor.BaseKit;
155
import org.netbeans.editor.BaseKit;
156
import org.netbeans.editor.Utilities;
156
import org.netbeans.editor.Utilities;
157
import org.netbeans.junit.MockServices;
157
import org.netbeans.junit.MockServices;
158
import org.netbeans.modules.editor.indent.api.Reformat;
158
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
159
import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
159
import org.netbeans.modules.editor.indent.spi.IndentTask;
160
import org.netbeans.modules.editor.indent.spi.IndentTask;
160
import org.netbeans.modules.editor.indent.spi.ReformatTask;
161
import org.netbeans.modules.editor.indent.spi.ReformatTask;
Lines 1989-2006 Link Here
1989
        configureIndenters(document, formatter, compilationInfo, indentOnly);
1990
        configureIndenters(document, formatter, compilationInfo, indentOnly);
1990
1991
1991
//        formatter.reformat(doc, startPos, endPos, getInfoForText(source, "unittestdata"));
1992
//        formatter.reformat(doc, startPos, endPos, getInfoForText(source, "unittestdata"));
1992
        final org.netbeans.editor.Formatter f = document.getFormatter();
1993
        Reformat f = Reformat.get(document);
1993
        boolean locked = false;
1994
        f.lock();
1994
        try {
1995
        try {
1995
            f.reformatLock();
1996
            f.reformat(Math.min(document.getLength(), startPos), Math.min(document.getLength(), endPos));
1996
            locked = true;
1997
            int reformattedLen = f.reformat(document, 
1998
                    Math.min(document.getLength(), startPos),
1999
                    Math.min(document.getLength(), endPos));
2000
        } finally {
1997
        } finally {
2001
            if (locked) {
1998
            f.unlock();
2002
                f.reformatUnlock();
2003
            }
2004
        }
1999
        }
2005
    }
2000
    }
2006
2001
(-)a/hibernate/nbproject/project.xml (-3 / +3 lines)
Lines 150-156 Link Here
150
                    <compile-dependency/>
150
                    <compile-dependency/>
151
                    <run-dependency>
151
                    <run-dependency>
152
                        <release-version>3</release-version>
152
                        <release-version>3</release-version>
153
                        <specification-version>1.41</specification-version>
153
                        <specification-version>1.53</specification-version>
154
                    </run-dependency>
154
                    </run-dependency>
155
                </dependency>
155
                </dependency>
156
                <dependency>
156
                <dependency>
Lines 167-174 Link Here
167
                    <build-prerequisite/>
167
                    <build-prerequisite/>
168
                    <compile-dependency/>
168
                    <compile-dependency/>
169
                    <run-dependency>
169
                    <run-dependency>
170
                        <release-version>2</release-version>
170
                        <release-version>3</release-version>
171
                        <specification-version>2.1</specification-version>
171
                        <specification-version>3.1</specification-version>
172
                    </run-dependency>
172
                    </run-dependency>
173
                </dependency>
173
                </dependency>
174
                <dependency>
174
                <dependency>
(-)a/html.editor.lib/nbproject/project.xml (-2 / +2 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/html.editor/nbproject/project.xml (-3 / +3 lines)
Lines 73-79 Link Here
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>3</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>1.41</specification-version>
76
                        <specification-version>1.53</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
Lines 116-123 Link Here
116
                    <build-prerequisite/>
116
                    <build-prerequisite/>
117
                    <compile-dependency/>
117
                    <compile-dependency/>
118
                    <run-dependency>
118
                    <run-dependency>
119
                        <release-version>2</release-version>
119
                        <release-version>3</release-version>
120
                        <specification-version>2.1</specification-version>
120
                        <specification-version>3.1</specification-version>
121
                    </run-dependency>
121
                    </run-dependency>
122
                </dependency>
122
                </dependency>
123
                <dependency>
123
                <dependency>
(-)a/html/nbproject/project.xml (-3 / +3 lines)
Lines 73-79 Link Here
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>3</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>1.41</specification-version>
76
                        <specification-version>1.53</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
Lines 90-97 Link Here
90
                    <build-prerequisite/>
90
                    <build-prerequisite/>
91
                    <compile-dependency/>
91
                    <compile-dependency/>
92
                    <run-dependency>
92
                    <run-dependency>
93
                        <release-version>2</release-version>
93
                        <release-version>3</release-version>
94
                        <specification-version>2.1</specification-version>
94
                        <specification-version>3.1</specification-version>
95
                    </run-dependency>
95
                    </run-dependency>
96
                </dependency>
96
                </dependency>
97
                <dependency>
97
                <dependency>
(-)a/j2ee.common/nbproject/project.xml (-3 / +3 lines)
Lines 117-123 Link Here
117
                    <compile-dependency/>
117
                    <compile-dependency/>
118
                    <run-dependency>
118
                    <run-dependency>
119
                        <release-version>3</release-version>
119
                        <release-version>3</release-version>
120
                        <specification-version>1.41</specification-version>
120
                        <specification-version>1.53</specification-version>
121
                    </run-dependency>
121
                    </run-dependency>
122
                </dependency>
122
                </dependency>
123
                <dependency>
123
                <dependency>
Lines 133-140 Link Here
133
                    <build-prerequisite/>
133
                    <build-prerequisite/>
134
                    <compile-dependency/>
134
                    <compile-dependency/>
135
                    <run-dependency>
135
                    <run-dependency>
136
                        <release-version>2</release-version>
136
                        <release-version>3</release-version>
137
                        <specification-version>2.1</specification-version>
137
                        <specification-version>3.1</specification-version>
138
                    </run-dependency>
138
                    </run-dependency>
139
                </dependency>
139
                </dependency>
140
                <dependency>
140
                <dependency>
(-)a/j2ee.ejbcore/nbproject/project.xml (-3 / +3 lines)
Lines 149-155 Link Here
149
                    <compile-dependency/>
149
                    <compile-dependency/>
150
                    <run-dependency>
150
                    <run-dependency>
151
                        <release-version>3</release-version>
151
                        <release-version>3</release-version>
152
                        <specification-version>1.41</specification-version>
152
                        <specification-version>1.53</specification-version>
153
                    </run-dependency>
153
                    </run-dependency>
154
                </dependency>
154
                </dependency>
155
                <dependency>
155
                <dependency>
Lines 165-172 Link Here
165
                    <build-prerequisite/>
165
                    <build-prerequisite/>
166
                    <compile-dependency/>
166
                    <compile-dependency/>
167
                    <run-dependency>
167
                    <run-dependency>
168
                        <release-version>2</release-version>
168
                        <release-version>3</release-version>
169
                        <specification-version>2.1</specification-version>
169
                        <specification-version>3.1</specification-version>
170
                    </run-dependency>
170
                    </run-dependency>
171
                </dependency>
171
                </dependency>
172
                <dependency>
172
                <dependency>
(-)a/j2ee.ejbjarproject/nbproject/project.xml (-3 / +3 lines)
Lines 124-130 Link Here
124
                    <compile-dependency/>
124
                    <compile-dependency/>
125
                    <run-dependency>
125
                    <run-dependency>
126
                        <release-version>3</release-version>
126
                        <release-version>3</release-version>
127
                        <specification-version>1.41</specification-version>
127
                        <specification-version>1.53</specification-version>
128
                    </run-dependency>
128
                    </run-dependency>
129
                </dependency>
129
                </dependency>
130
                <dependency>
130
                <dependency>
Lines 149-156 Link Here
149
                    <build-prerequisite/>
149
                    <build-prerequisite/>
150
                    <compile-dependency/>
150
                    <compile-dependency/>
151
                    <run-dependency>
151
                    <run-dependency>
152
                        <release-version>2</release-version>
152
                        <release-version>3</release-version>
153
                        <specification-version>2.1</specification-version>
153
                        <specification-version>3.1</specification-version>
154
                    </run-dependency>
154
                    </run-dependency>
155
                </dependency>
155
                </dependency>
156
                <dependency>
156
                <dependency>
(-)a/j2ee.jpa.refactoring/nbproject/project.xml (-2 / +2 lines)
Lines 36-43 Link Here
36
                    <build-prerequisite/>
36
                    <build-prerequisite/>
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>2</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>2.1</specification-version>
40
                        <specification-version>3.1</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
(-)a/j2ee.persistence/nbproject/project.xml (-3 / +3 lines)
Lines 140-146 Link Here
140
                    <compile-dependency/>
140
                    <compile-dependency/>
141
                    <run-dependency>
141
                    <run-dependency>
142
                        <release-version>3</release-version>
142
                        <release-version>3</release-version>
143
                        <specification-version>1.41</specification-version>
143
                        <specification-version>1.53</specification-version>
144
                    </run-dependency>
144
                    </run-dependency>
145
                </dependency>
145
                </dependency>
146
                <dependency>
146
                <dependency>
Lines 156-163 Link Here
156
                    <build-prerequisite/>
156
                    <build-prerequisite/>
157
                    <compile-dependency/>
157
                    <compile-dependency/>
158
                    <run-dependency>
158
                    <run-dependency>
159
                        <release-version>2</release-version>
159
                        <release-version>3</release-version>
160
                        <specification-version>2.1</specification-version>
160
                        <specification-version>3.1</specification-version>
161
                    </run-dependency>
161
                    </run-dependency>
162
                </dependency>
162
                </dependency>
163
                <dependency>
163
                <dependency>
(-)a/j2ee.websphere6/nbproject/project.xml (+18 lines)
Lines 83-88 Link Here
83
                    </run-dependency>
83
                    </run-dependency>
84
                </dependency>
84
                </dependency>
85
                <dependency>
85
                <dependency>
86
                    <code-name-base>org.netbeans.modules.editor</code-name-base>
87
                    <build-prerequisite/>
88
                    <compile-dependency/>
89
                    <run-dependency>
90
                        <release-version>3</release-version>
91
                        <specification-version>1.53</specification-version>
92
                    </run-dependency>
93
                </dependency>
94
                <dependency>
95
                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
96
                    <build-prerequisite/>
97
                    <compile-dependency/>
98
                    <run-dependency>
99
                        <release-version>1</release-version>
100
                        <specification-version>1.8.1</specification-version>
101
                    </run-dependency>
102
                </dependency>
103
                <dependency>
86
                    <code-name-base>org.netbeans.modules.j2ee.api.ejbmodule</code-name-base>
104
                    <code-name-base>org.netbeans.modules.j2ee.api.ejbmodule</code-name-base>
87
                    <run-dependency>
105
                    <run-dependency>
88
                        <specification-version>1.7</specification-version>
106
                        <specification-version>1.7</specification-version>
(-)a/java.debug/nbproject/project.xml (-2 / +2 lines)
Lines 43-50 Link Here
43
                    <build-prerequisite/>
43
                    <build-prerequisite/>
44
                    <compile-dependency/>
44
                    <compile-dependency/>
45
                    <run-dependency>
45
                    <run-dependency>
46
                        <release-version>2</release-version>
46
                        <release-version>3</release-version>
47
                        <specification-version>2.1</specification-version>
47
                        <specification-version>3.1</specification-version>
48
                    </run-dependency>
48
                    </run-dependency>
49
                </dependency>
49
                </dependency>
50
                <dependency>
50
                <dependency>
(-)a/java.editor.lib/nbproject/project.xml (-2 / +11 lines)
Lines 71-78 Link Here
71
                    <build-prerequisite/>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <release-version>2</release-version>
74
                        <release-version>3</release-version>
75
                        <specification-version>2.1</specification-version>
75
                        <specification-version>3.1</specification-version>
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
Lines 108-113 Link Here
108
                        <specification-version>8.0</specification-version>
108
                        <specification-version>8.0</specification-version>
109
                    </run-dependency>
109
                    </run-dependency>
110
                </dependency>
110
                </dependency>
111
                <dependency>
112
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
113
                    <build-prerequisite/>
114
                    <compile-dependency/>
115
                    <run-dependency>
116
                        <release-version>0-1</release-version>
117
                        <specification-version>1.0</specification-version>
118
                    </run-dependency>
119
                </dependency>
111
            </module-dependencies>
120
            </module-dependencies>
112
            <public-packages>
121
            <public-packages>
113
                <package>org.netbeans.editor.ext.java</package>
122
                <package>org.netbeans.editor.ext.java</package>
(-)a/java.editor/nbproject/project.xml (-3 / +12 lines)
Lines 88-94 Link Here
88
                    <compile-dependency/>
88
                    <compile-dependency/>
89
                    <run-dependency>
89
                    <run-dependency>
90
                        <release-version>3</release-version>
90
                        <release-version>3</release-version>
91
                        <specification-version>1.41</specification-version>
91
                        <specification-version>1.53</specification-version>
92
                    </run-dependency>
92
                    </run-dependency>
93
                </dependency>
93
                </dependency>
94
                <dependency>
94
                <dependency>
Lines 118-123 Link Here
118
                    </run-dependency>
118
                    </run-dependency>
119
                </dependency>
119
                </dependency>
120
                <dependency>
120
                <dependency>
121
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
122
                    <build-prerequisite/>
123
                    <compile-dependency/>
124
                    <run-dependency>
125
                        <release-version>0-1</release-version>
126
                        <specification-version>1.0</specification-version>
127
                    </run-dependency>
128
                </dependency>
129
                <dependency>
121
                    <code-name-base>org.netbeans.modules.editor.errorstripe</code-name-base>
130
                    <code-name-base>org.netbeans.modules.editor.errorstripe</code-name-base>
122
                    <build-prerequisite/>
131
                    <build-prerequisite/>
123
                    <compile-dependency/>
132
                    <compile-dependency/>
Lines 148-155 Link Here
148
                    <build-prerequisite/>
157
                    <build-prerequisite/>
149
                    <compile-dependency/>
158
                    <compile-dependency/>
150
                    <run-dependency>
159
                    <run-dependency>
151
                        <release-version>2</release-version>
160
                        <release-version>3</release-version>
152
                        <specification-version>2.1</specification-version>
161
                        <specification-version>3.1</specification-version>
153
                    </run-dependency>
162
                    </run-dependency>
154
                </dependency>
163
                </dependency>
155
                <dependency>
164
                <dependency>
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java (-41 / +3 lines)
Lines 63-69 Link Here
63
import org.netbeans.api.java.source.CodeStyle;
63
import org.netbeans.api.java.source.CodeStyle;
64
import org.netbeans.editor.*;
64
import org.netbeans.editor.*;
65
import org.netbeans.editor.Utilities;
65
import org.netbeans.editor.Utilities;
66
import org.netbeans.editor.ext.ExtFormatter;
67
import org.netbeans.editor.ext.java.*;
66
import org.netbeans.editor.ext.java.*;
68
import org.netbeans.api.java.queries.SourceLevelQuery;
67
import org.netbeans.api.java.queries.SourceLevelQuery;
69
import org.netbeans.api.lexer.PartType;
68
import org.netbeans.api.lexer.PartType;
Lines 75-81 Link Here
75
import org.netbeans.modules.editor.MainMenuAction;
74
import org.netbeans.modules.editor.MainMenuAction;
76
import org.netbeans.modules.editor.NbEditorKit;
75
import org.netbeans.modules.editor.NbEditorKit;
77
import org.netbeans.modules.editor.NbEditorUtilities;
76
import org.netbeans.modules.editor.NbEditorUtilities;
78
import org.netbeans.modules.editor.indent.api.Reformat;
77
import org.netbeans.modules.editor.indent.api.Indent;
79
import org.netbeans.modules.java.editor.codegen.InsertSemicolonAction;
78
import org.netbeans.modules.java.editor.codegen.InsertSemicolonAction;
80
import org.netbeans.modules.java.editor.imports.FastImportAction;
79
import org.netbeans.modules.java.editor.imports.FastImportAction;
81
import org.netbeans.modules.java.editor.imports.JavaFixAllImports;
80
import org.netbeans.modules.java.editor.imports.JavaFixAllImports;
Lines 366-408 Link Here
366
                }
365
                }
367
            }
366
            }
368
        }
367
        }
369
370
        // TODO: remove this method once ExtKit uses the new Editor Indent API
371
        protected void checkIndentHotChars(JTextComponent target, String typedText) {
372
            BaseDocument doc = Utilities.getDocument(target);
373
            if (doc != null) {
374
                Formatter f = doc.getFormatter();
375
                if (f instanceof ExtFormatter) {
376
                    ExtFormatter ef = (ExtFormatter)f;
377
                    int[] fmtBlk = ef.getReformatBlock(target, typedText);
378
379
                    if (fmtBlk != null) {
380
                        try {
381
                            fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]);
382
                            fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]);
383
384
                            //this was the of #18922, that causes the bug #20198
385
                            //ef.reformat(doc, fmtBlk[0], fmtBlk[1]);
386
387
                            //bugfix of the bug #20198. Bug #18922 is fixed too as well as #6968
388
                            Reformat reformat = Reformat.get(doc);
389
                            reformat.lock();
390
                            try {
391
                                doc.atomicLock();
392
                                try {
393
                                    reformat.reformat(fmtBlk[0], fmtBlk[1]);
394
                                } finally {
395
                                    doc.atomicUnlock();
396
                                }
397
                            } finally {
398
                                reformat.unlock();
399
                            }
400
                        } catch (BadLocationException e) {
401
                        }
402
                    }
403
                }
404
            }
405
        }
406
    }
368
    }
407
369
408
    @EditorActionRegistration(name = generateGoToPopupAction, mimeType = JAVA_MIME_TYPE)
370
    @EditorActionRegistration(name = generateGoToPopupAction, mimeType = JAVA_MIME_TYPE)
Lines 647-653 Link Here
647
                        int end = BraceCompletion.getRowOrBlockEnd(doc, dotPos, insert);
609
                        int end = BraceCompletion.getRowOrBlockEnd(doc, dotPos, insert);
648
                        if (insert[0]) {
610
                        if (insert[0]) {
649
                            doc.insertString(end, "}", null); // NOI18N
611
                            doc.insertString(end, "}", null); // NOI18N
650
                            doc.getFormatter().indentNewLine(doc, end);
612
                            Indent.get(doc).indentNewLine(end);
651
                        }
613
                        }
652
                        caret.setDot(dotPos);
614
                        caret.setDot(dotPos);
653
                        return Boolean.TRUE;
615
                        return Boolean.TRUE;
Lines 688-694 Link Here
688
                        // complete open javadoc
650
                        // complete open javadoc
689
                        // note that the formater will add one line of javadoc
651
                        // note that the formater will add one line of javadoc
690
                        doc.insertString(dotPosition, "*/", null); // NOI18N
652
                        doc.insertString(dotPosition, "*/", null); // NOI18N
691
                        doc.getFormatter().indentNewLine(doc, dotPosition);
653
                        Indent.get(doc).indentNewLine(dotPosition);
692
                        target.setCaretPosition(dotPosition);
654
                        target.setCaretPosition(dotPosition);
693
655
694
                        isJavadocTouched = true;
656
                        isJavadocTouched = true;
(-)a/java.editor/src/org/netbeans/modules/java/editor/codegen/InsertSemicolonAction.java (-8 / +8 lines)
Lines 36-43 Link Here
36
import javax.swing.text.JTextComponent;
36
import javax.swing.text.JTextComponent;
37
import org.netbeans.editor.BaseAction;
37
import org.netbeans.editor.BaseAction;
38
import org.netbeans.editor.BaseDocument;
38
import org.netbeans.editor.BaseDocument;
39
import org.netbeans.editor.Formatter;
40
import org.netbeans.editor.Utilities;
39
import org.netbeans.editor.Utilities;
40
import org.netbeans.modules.editor.indent.api.Indent;
41
import org.openide.util.Exceptions;
41
import org.openide.util.Exceptions;
42
import org.openide.util.NbBundle;
42
import org.openide.util.NbBundle;
43
43
Lines 73-84 Link Here
73
            return;
73
            return;
74
        }
74
        }
75
        final BaseDocument doc = (BaseDocument) target.getDocument();
75
        final BaseDocument doc = (BaseDocument) target.getDocument();
76
        final Formatter formatter = doc.getFormatter();
76
        final Indent indenter = Indent.get(doc);
77
        final class R implements Runnable {
77
        final class R implements Runnable {
78
            public void run() {
78
            public @Override void run() {
79
                Caret caret = target.getCaret();
80
                int dotpos = caret.getDot();
81
                try {
79
                try {
80
                    Caret caret = target.getCaret();
81
                    int dotpos = caret.getDot();
82
                    int eoloffset = Utilities.getRowEnd(target, dotpos);
82
                    int eoloffset = Utilities.getRowEnd(target, dotpos);
83
                    doc.insertString(eoloffset, "" + what, null); //NOI18N
83
                    doc.insertString(eoloffset, "" + what, null); //NOI18N
84
                    if (withNewline) {
84
                    if (withNewline) {
Lines 87-93 Link Here
87
                        doc.insertString(dotpos, "-", null); //NOI18N
87
                        doc.insertString(dotpos, "-", null); //NOI18N
88
                        doc.remove(dotpos, 1);
88
                        doc.remove(dotpos, 1);
89
                        int eolDot = Utilities.getRowEnd(target, caret.getDot());
89
                        int eolDot = Utilities.getRowEnd(target, caret.getDot());
90
                        int newDotPos = formatter.indentNewLine(doc, eolDot);
90
                        int newDotPos = indenter.indentNewLine(eolDot);
91
                        caret.setDot(newDotPos);
91
                        caret.setDot(newDotPos);
92
                    }
92
                    }
93
                } catch (BadLocationException ex) {
93
                } catch (BadLocationException ex) {
Lines 95-105 Link Here
95
                }
95
                }
96
            }
96
            }
97
        }
97
        }
98
        formatter.indentLock();
98
        indenter.lock();
99
        try {
99
        try {
100
            doc.runAtomicAsUser(new R());
100
            doc.runAtomicAsUser(new R());
101
        } finally {
101
        } finally {
102
            formatter.indentUnlock();
102
            indenter.unlock();
103
        }
103
        }
104
    }
104
    }
105
}
105
}
(-)a/java.editor/test/unit/src/org/netbeans/modules/editor/java/JavaFormatterUnitTestCase.java (-4 / +11 lines)
Lines 46-52 Link Here
46
46
47
import javax.swing.text.BadLocationException;
47
import javax.swing.text.BadLocationException;
48
import org.netbeans.editor.BaseDocument;
48
import org.netbeans.editor.BaseDocument;
49
import org.netbeans.editor.Formatter;
49
import org.netbeans.modules.editor.indent.api.Indent;
50
import org.netbeans.modules.editor.indent.api.Reformat;
50
import org.netbeans.modules.editor.indent.api.Reformat;
51
51
52
/**
52
/**
Lines 70-78 Link Here
70
        // hooked through the ExtKit.ExtDefaultKeyTypedAction.checkIndentHotChars(),
70
        // hooked through the ExtKit.ExtDefaultKeyTypedAction.checkIndentHotChars(),
71
        // which calls f.getReformatBlock and f.reformat
71
        // which calls f.getReformatBlock and f.reformat
72
        // IMO this should just be replaced by simple doc.insertString(getCaretOffset(), "\n", null)
72
        // IMO this should just be replaced by simple doc.insertString(getCaretOffset(), "\n", null)
73
        Formatter f = getDocument().getFormatter();
73
        Indent indenter = Indent.get(getDocument());
74
        int offset = f.indentNewLine(getDocument(), getCaretOffset());
74
        indenter.lock();
75
        getCaret().setDot(offset);
75
        try {
76
            int offset = indenter.indentNewLine(getCaretOffset());
77
            getCaret().setDot(offset);
78
        } catch (BadLocationException ble) {
79
            throw new IllegalStateException(ble);
80
        } finally {
81
            indenter.unlock();
82
        }
76
    }
83
    }
77
    
84
    
78
    /**
85
    /**
(-)a/java.hints/nbproject/project.xml (-3 / +3 lines)
Lines 117-123 Link Here
117
                    <compile-dependency/>
117
                    <compile-dependency/>
118
                    <run-dependency>
118
                    <run-dependency>
119
                        <release-version>3</release-version>
119
                        <release-version>3</release-version>
120
                        <specification-version>1.41</specification-version>
120
                        <specification-version>1.53</specification-version>
121
                    </run-dependency>
121
                    </run-dependency>
122
                </dependency>
122
                </dependency>
123
                <dependency>
123
                <dependency>
Lines 134-141 Link Here
134
                    <build-prerequisite/>
134
                    <build-prerequisite/>
135
                    <compile-dependency/>
135
                    <compile-dependency/>
136
                    <run-dependency>
136
                    <run-dependency>
137
                        <release-version>2</release-version>
137
                        <release-version>3</release-version>
138
                        <specification-version>2.1</specification-version>
138
                        <specification-version>3.1</specification-version>
139
                    </run-dependency>
139
                    </run-dependency>
140
                </dependency>
140
                </dependency>
141
                <dependency>
141
                <dependency>
(-)a/java.navigation/nbproject/project.xml (-3 / +3 lines)
Lines 98-104 Link Here
98
                    <compile-dependency/>
98
                    <compile-dependency/>
99
                    <run-dependency>
99
                    <run-dependency>
100
                        <release-version>3</release-version>
100
                        <release-version>3</release-version>
101
                        <specification-version>1.41</specification-version>
101
                        <specification-version>1.53</specification-version>
102
                    </run-dependency>
102
                    </run-dependency>
103
                </dependency>
103
                </dependency>
104
                <dependency>
104
                <dependency>
Lines 106-113 Link Here
106
                    <build-prerequisite/>
106
                    <build-prerequisite/>
107
                    <compile-dependency/>
107
                    <compile-dependency/>
108
                    <run-dependency>
108
                    <run-dependency>
109
                        <release-version>2</release-version>
109
                        <release-version>3</release-version>
110
                        <specification-version>2.1</specification-version>
110
                        <specification-version>3.1</specification-version>
111
                    </run-dependency>
111
                    </run-dependency>
112
                </dependency>
112
                </dependency>
113
                <dependency>
113
                <dependency>
(-)a/java.source/nbproject/project.xml (-2 / +2 lines)
Lines 148-155 Link Here
148
                    <build-prerequisite/>
148
                    <build-prerequisite/>
149
                    <compile-dependency/>
149
                    <compile-dependency/>
150
                    <run-dependency>
150
                    <run-dependency>
151
                        <release-version>2</release-version>
151
                        <release-version>3</release-version>
152
                        <specification-version>2.1</specification-version>
152
                        <specification-version>3.1</specification-version>
153
                    </run-dependency>
153
                    </run-dependency>
154
                </dependency>
154
                </dependency>
155
                <dependency>
155
                <dependency>
(-)a/javascript.editing/nbproject/project.xml (-3 / +3 lines)
Lines 65-71 Link Here
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>3</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>1.41</specification-version>
68
                        <specification-version>1.53</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
Lines 91-98 Link Here
91
                    <build-prerequisite/>
91
                    <build-prerequisite/>
92
                    <compile-dependency/>
92
                    <compile-dependency/>
93
                    <run-dependency>
93
                    <run-dependency>
94
                        <release-version>2</release-version>
94
                        <release-version>3</release-version>
95
                        <specification-version>2.1</specification-version>
95
                        <specification-version>3.1</specification-version>
96
                    </run-dependency>
96
                    </run-dependency>
97
                </dependency>
97
                </dependency>
98
                <dependency>
98
                <dependency>
(-)a/javascript.hints/nbproject/project.xml (-2 / +2 lines)
Lines 46-53 Link Here
46
                    <build-prerequisite/>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>2</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>2.1</specification-version>
50
                        <specification-version>3.1</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
(-)a/javascript.refactoring/nbproject/project.xml (-2 / +2 lines)
Lines 46-53 Link Here
46
                    <build-prerequisite/>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>2</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>2.1</specification-version>
50
                        <specification-version>3.1</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
(-)a/jellytools.ide/nbproject/project.xml (-2 / +2 lines)
Lines 36-43 Link Here
36
                    <build-prerequisite/>
36
                    <build-prerequisite/>
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>2</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>2.1</specification-version>
40
                        <specification-version>3.1</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
(-)a/jumpto/nbproject/project.xml (-2 / +2 lines)
Lines 73-80 Link Here
73
                    <build-prerequisite/>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
74
                    <compile-dependency/>
75
                    <run-dependency>
75
                    <run-dependency>
76
                        <release-version>2</release-version>
76
                        <release-version>3</release-version>
77
                        <specification-version>2.1</specification-version>
77
                        <specification-version>3.1</specification-version>
78
                    </run-dependency>
78
                    </run-dependency>
79
                </dependency>
79
                </dependency>
80
                <dependency>
80
                <dependency>
(-)a/kenai.ui/nbproject/project.xml (-1 / +1 lines)
Lines 64-70 Link Here
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>1.43</specification-version>
67
                        <specification-version>1.53</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/languages.refactoring/nbproject/project.xml (-3 / +3 lines)
Lines 11-17 Link Here
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.41</specification-version>
14
                        <specification-version>1.53</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
Lines 19-26 Link Here
19
                    <build-prerequisite/>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>2.1</specification-version>
23
                        <specification-version>3.1</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/languages.yaml/nbproject/project.xml (-2 / +2 lines)
Lines 28-35 Link Here
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>2.1</specification-version>
32
                        <specification-version>3.1</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/languages/nbproject/project.xml (-3 / +3 lines)
Lines 20-26 Link Here
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>3</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>1.41</specification-version>
23
                        <specification-version>1.53</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
Lines 70-77 Link Here
70
                    <build-prerequisite/>
70
                    <build-prerequisite/>
71
                    <compile-dependency/>
71
                    <compile-dependency/>
72
                    <run-dependency>
72
                    <run-dependency>
73
                        <release-version>2</release-version>
73
                        <release-version>3</release-version>
74
                        <specification-version>2.1</specification-version>
74
                        <specification-version>3.1</specification-version>
75
                    </run-dependency>
75
                    </run-dependency>
76
                </dependency>
76
                </dependency>
77
                <dependency>
77
                <dependency>
(-)a/lexer.editorbridge/nbproject/project.xml (-3 / +12 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                    <specification-version>1.41</specification-version>
58
                    <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>1</release-version>
66
                        <release-version>3</release-version>
67
                    <specification-version>1.27</specification-version>
67
                    <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
Lines 133-138 Link Here
133
                        <specification-version>1.0</specification-version>
133
                        <specification-version>1.0</specification-version>
134
                    </run-dependency>
134
                    </run-dependency>
135
                </dependency>
135
                </dependency>
136
            <dependency>
137
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
138
                    <build-prerequisite/>
139
                    <compile-dependency/>
140
                    <run-dependency>
141
                        <release-version>0-1</release-version>
142
                        <specification-version>1.0</specification-version>
143
                    </run-dependency>
144
                </dependency>
136
            </module-dependencies>
145
            </module-dependencies>
137
            <public-packages>
146
            <public-packages>
138
                <package>org.netbeans.modules.lexer.editorbridge</package>
147
                <package>org.netbeans.modules.lexer.editorbridge</package>
(-)a/maven.grammar/nbproject/project.xml (-3 / +3 lines)
Lines 64-70 Link Here
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>1.41</specification-version>
67
                        <specification-version>1.53</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
Lines 72-79 Link Here
72
                    <build-prerequisite/>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>2</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>2.1</specification-version>
76
                        <specification-version>3.1</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
(-)a/maven.hints/nbproject/project.xml (-3 / +3 lines)
Lines 72-78 Link Here
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <release-version>3</release-version>
74
                        <release-version>3</release-version>
75
                        <specification-version>1.42</specification-version>
75
                        <specification-version>1.53</specification-version>
76
                    </run-dependency>
76
                    </run-dependency>
77
                </dependency>
77
                </dependency>
78
                <dependency>
78
                <dependency>
Lines 89-96 Link Here
89
                    <build-prerequisite/>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>2</release-version>
92
                        <release-version>3</release-version>
93
                        <specification-version>2.1</specification-version>
93
                        <specification-version>3.1</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/maven.jaxws/nbproject/project.xml (-1 / +1 lines)
Lines 90-96 Link Here
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>3</release-version>
92
                        <release-version>3</release-version>
93
                        <specification-version>1.42</specification-version>
93
                        <specification-version>1.53</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/maven.model/nbproject/project.xml (-2 / +2 lines)
Lines 10-17 Link Here
10
                    <build-prerequisite/>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>2</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>2.1</specification-version>
14
                        <specification-version>3.1</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
(-)a/mercurial/nbproject/project.xml (-2 / +2 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/mobility.editor/nbproject/project.xml (-3 / +3 lines)
Lines 79-85 Link Here
79
                    <compile-dependency/>
79
                    <compile-dependency/>
80
                    <run-dependency>
80
                    <run-dependency>
81
                        <release-version>3</release-version>
81
                        <release-version>3</release-version>
82
                        <specification-version>1.41</specification-version>
82
                        <specification-version>1.53</specification-version>
83
                    </run-dependency>
83
                    </run-dependency>
84
                </dependency>
84
                </dependency>
85
                <dependency>
85
                <dependency>
Lines 105-112 Link Here
105
                    <build-prerequisite/>
105
                    <build-prerequisite/>
106
                    <compile-dependency/>
106
                    <compile-dependency/>
107
                    <run-dependency>
107
                    <run-dependency>
108
                        <release-version>2</release-version>
108
                        <release-version>3</release-version>
109
                        <specification-version>2.1</specification-version>
109
                        <specification-version>3.1</specification-version>
110
                    </run-dependency>
110
                    </run-dependency>
111
                </dependency>
111
                </dependency>
112
                <dependency>
112
                <dependency>
(-)a/mobility.project.bridge.impl/nbproject/project.xml (-3 / +3 lines)
Lines 37-43 Link Here
37
                    <compile-dependency/>
37
                    <compile-dependency/>
38
                    <run-dependency>
38
                    <run-dependency>
39
                        <release-version>3</release-version>
39
                        <release-version>3</release-version>
40
                        <specification-version>1.41</specification-version>
40
                        <specification-version>1.53</specification-version>
41
                    </run-dependency>
41
                    </run-dependency>
42
                </dependency>
42
                </dependency>
43
                <dependency>
43
                <dependency>
Lines 45-52 Link Here
45
                    <build-prerequisite/>
45
                    <build-prerequisite/>
46
                    <compile-dependency/>
46
                    <compile-dependency/>
47
                    <run-dependency>
47
                    <run-dependency>
48
                        <release-version>2</release-version>
48
                        <release-version>3</release-version>
49
                        <specification-version>2.1</specification-version>
49
                        <specification-version>3.1</specification-version>
50
                    </run-dependency>
50
                    </run-dependency>
51
                </dependency>
51
                </dependency>
52
                <dependency>
52
                <dependency>
(-)a/mobility.svgcore/nbproject/project.xml (-3 / +3 lines)
Lines 47-53 Link Here
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>3</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>1.41</specification-version>
50
                        <specification-version>1.53</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
Lines 64-71 Link Here
64
                    <build-prerequisite/>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>2</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>2.1</specification-version>
68
                        <specification-version>3.1</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
(-)a/mobility.svgcore/src/org/netbeans/modules/mobility/svgcore/model/SVGFileModel.java (-2 / +2 lines)
Lines 849-855 Link Here
849
                            }
849
                            }
850
                        }
850
                        }
851
                        doc.insertString(insertPosition, str, null);
851
                        doc.insertString(insertPosition, str, null);
852
                        Reformat.get(doc).reformat(insertPosition, insertPosition + str.length()+1);
852
                        Reformat.get(doc).reformat(insertPosition, insertPosition + str.length() + 1);
853
                    } else {
853
                    } else {
854
                        String docText = doc.getText(0, doc.getLength());
854
                        String docText = doc.getText(0, doc.getLength());
855
                        int startOff = svgRoot.getStartOffset();
855
                        int startOff = svgRoot.getStartOffset();
Lines 862-868 Link Here
862
                        if (c == '/') {
862
                        if (c == '/') {
863
                            if (docText.charAt(insertPosition) == '<') {
863
                            if (docText.charAt(insertPosition) == '<') {
864
                                doc.insertString(insertPosition, insertString, null);
864
                                doc.insertString(insertPosition, insertString, null);
865
                                Reformat.get(doc).reformat(insertPosition, insertPosition + insertString.length()+1);
865
                                Reformat.get(doc).reformat(insertPosition, insertPosition + insertString.length() + 1);
866
                            } else {
866
                            } else {
867
                                StringBuilder sb = new StringBuilder(docText.substring(startOff, insertPosition + 1));
867
                                StringBuilder sb = new StringBuilder(docText.substring(startOff, insertPosition + 1));
868
                                sb.append(">\n"); //NOI18N
868
                                sb.append(">\n"); //NOI18N
(-)a/mobility.svgcore/src/org/netbeans/modules/mobility/svgcore/palette/SVGPaletteItemDataObject.java (-25 / +12 lines)
Lines 86-92 Link Here
86
        return new File( m_data.getFilePath());
86
        return new File( m_data.getFilePath());
87
    }
87
    }
88
    
88
    
89
    protected Node createNodeDelegate() {
89
    protected @Override Node createNodeDelegate() {
90
        return new SVGPaletteItemDataNode(this, getLookup());
90
        return new SVGPaletteItemDataNode(this, getLookup());
91
    }
91
    }
92
    
92
    
Lines 124-137 Link Here
124
    public static void insertToTextComponent( final String text, final JTextComponent target) {
124
    public static void insertToTextComponent( final String text, final JTextComponent target) {
125
        final Document doc = target.getDocument();
125
        final Document doc = target.getDocument();
126
        
126
        
127
        if ( doc instanceof BaseDocument) {
127
        if (doc instanceof BaseDocument) {
128
            BaseDocument bDoc = (BaseDocument) doc;
128
            final Reformat formatter = Reformat.get(doc);
129
            final Reformat formatter = Reformat.get(bDoc);
130
            formatter.lock();
129
            formatter.lock();
131
            try {
130
            try {
132
131
                final boolean [] ok = new boolean [] { false };
133
                Runnable run = new Runnable() {
132
                ((BaseDocument) doc).runAtomic(new Runnable() {
134
135
                    public void run() {
133
                    public void run() {
136
                        try {
134
                        try {
137
                            Caret caret = target.getCaret();
135
                            Caret caret = target.getCaret();
Lines 141-172 Link Here
141
139
142
                            int start = caret.getDot();
140
                            int start = caret.getDot();
143
                            doc.insertString(start, text, null);
141
                            doc.insertString(start, text, null);
144
                            
142
145
                            int end = start + text.length();
143
                            int end = start + text.length();
146
                            formatter.reformat(start, end);
144
                            formatter.reformat(start, end);
147
                        } catch (BadLocationException ex) {
145
                            ok[0] = true;
148
                            throw new DocumentModificationException(ex);
146
                        } catch (BadLocationException ble) {
147
                            // ignore
149
                        }
148
                        }
150
                    }
149
                    }
151
                };
150
                });
152
                try {
151
                if (!ok[0]) {
153
                    bDoc.runAtomic(run);
152
                    ((BaseDocument) doc).atomicUndo();
154
                } catch (DocumentModificationException ex) {
155
                    SceneManager.error("Transaction failed.", ex.getCause()); //NOI18N
156
                }
153
                }
157
158
            } finally {
154
            } finally {
159
                formatter.unlock();
155
                formatter.unlock();
160
            }
156
            }
161
            
162
        }
157
        }
163
    }
158
    }
164
165
    private static class DocumentModificationException extends RuntimeException {
166
167
        public DocumentModificationException(Throwable cause) {
168
            super(cause);
169
        }
170
    }
171
172
}
159
}
(-)a/nbbuild/cluster.properties (+1 lines)
Lines 302-307 Link Here
302
        editor.codetemplates,\
302
        editor.codetemplates,\
303
        editor.completion,\
303
        editor.completion,\
304
        editor.deprecated.pre61settings,\
304
        editor.deprecated.pre61settings,\
305
        editor.deprecated.pre65formatting,\
305
        editor.errorstripe,\
306
        editor.errorstripe,\
306
        editor.errorstripe.api,\
307
        editor.errorstripe.api,\
307
        editor.fold,\
308
        editor.fold,\
(-)a/options.editor/nbproject/project.xml (-3 / +3 lines)
Lines 64-70 Link Here
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>3</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>1.41</specification-version>
67
                        <specification-version>1.53</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
Lines 81-88 Link Here
81
                    <build-prerequisite/>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>2</release-version>
84
                        <release-version>3</release-version>
85
                        <specification-version>2.1</specification-version>
85
                        <specification-version>3.1</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/parsing.api/nbproject/project.xml (-2 / +2 lines)
Lines 46-53 Link Here
46
                    <build-prerequisite/>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>2</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>2.1</specification-version>
50
                        <specification-version>3.1</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
(-)a/php.editor/nbproject/project.xml (-3 / +3 lines)
Lines 73-79 Link Here
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>3</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>1.42</specification-version>
76
                        <specification-version>1.53</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
Lines 117-124 Link Here
117
                    <build-prerequisite/>
117
                    <build-prerequisite/>
118
                    <compile-dependency/>
118
                    <compile-dependency/>
119
                    <run-dependency>
119
                    <run-dependency>
120
                        <release-version>2</release-version>
120
                        <release-version>3</release-version>
121
                        <specification-version>2.1</specification-version>
121
                        <specification-version>3.1</specification-version>
122
                    </run-dependency>
122
                    </run-dependency>
123
                </dependency>
123
                </dependency>
124
                <dependency>
124
                <dependency>
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/indent/GeneratingBracketCompleterTest.java (-33 / +39 lines)
Lines 51-56 Link Here
51
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
51
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
52
import org.netbeans.modules.csl.spi.GsfUtilities;
52
import org.netbeans.modules.csl.spi.GsfUtilities;
53
import org.netbeans.modules.csl.spi.ParserResult;
53
import org.netbeans.modules.csl.spi.ParserResult;
54
import org.netbeans.modules.editor.indent.api.Reformat;
54
import org.netbeans.modules.parsing.api.ResultIterator;
55
import org.netbeans.modules.parsing.api.ResultIterator;
55
import org.netbeans.modules.parsing.api.UserTask;
56
import org.netbeans.modules.parsing.api.UserTask;
56
import org.netbeans.modules.php.api.util.FileUtils;
57
import org.netbeans.modules.php.api.util.FileUtils;
Lines 220-230 Link Here
220
    }
221
    }
221
    
222
    
222
    private void insertBreak(ParserResult info, String original, String expected, int insertOffset, int finalCaretPos) throws BadLocationException, DataObjectNotFoundException, IOException {
223
    private void insertBreak(ParserResult info, String original, String expected, int insertOffset, int finalCaretPos) throws BadLocationException, DataObjectNotFoundException, IOException {
223
        PHPBracketCompleter bc = new PHPBracketCompleter();
224
        
224
        
225
        BaseDocument doc = (BaseDocument) info.getSnapshot().getSource().getDocument(false);//PHPBracketCompleterTest.getDocument(original);
225
        BaseDocument doc = (BaseDocument) info.getSnapshot().getSource().getDocument(false);//PHPBracketCompleterTest.getDocument(original);
226
        assertNotNull(doc);
226
        assertNotNull(doc);
227
227
        
228
        doc.putProperty(org.netbeans.api.lexer.Language.class, PHPTokenId.language());
228
        doc.putProperty(org.netbeans.api.lexer.Language.class, PHPTokenId.language());
229
        doc.putProperty("mimeType", FileUtils.PHP_MIME_TYPE);
229
        doc.putProperty("mimeType", FileUtils.PHP_MIME_TYPE);
230
//        doc.putProperty(Document.StreamDescriptionProperty, DataObject.find(info.getFileObject()));
230
//        doc.putProperty(Document.StreamDescriptionProperty, DataObject.find(info.getFileObject()));
Lines 232-275 Link Here
232
        JTextArea ta = new JTextArea(doc);
232
        JTextArea ta = new JTextArea(doc);
233
        Caret caret = ta.getCaret();
233
        Caret caret = ta.getCaret();
234
        caret.setDot(insertOffset);
234
        caret.setDot(insertOffset);
235
        int newOffset = bc.beforeBreak(doc, insertOffset, ta);
236
        doc.atomicLock();
237
        DocumentUtilities.setTypingModification(doc, true);
238
235
236
        Reformat f = Reformat.get(doc);
237
        assertNotNull(f);
238
239
        f.lock();
239
        try {
240
        try {
240
            doc.insertString(caret.getDot(), "\n", null);
241
            doc.atomicLock();
241
            // Indent the new line
242
            try {
242
            PHPFormatter formatter = new PHPFormatter();
243
                DocumentUtilities.setTypingModification(doc, true);
243
            //ParserResult result = parse(fo);
244
                try {
245
                    PHPBracketCompleter bc = new PHPBracketCompleter();
246
                    int newOffset = bc.beforeBreak(doc, insertOffset, ta);
247
                    doc.insertString(caret.getDot(), "\n", null);
248
                    // Indent the new line
249
                    PHPFormatter formatter = new PHPFormatter();
250
                    //ParserResult result = parse(fo);
244
251
245
            int startPos = caret.getDot()+1;
252
                    int startPos = caret.getDot()+1;
246
            int endPos = startPos+1;
253
                    int endPos = startPos+1;
247
254
248
            //ParserResult result = parse(fo);
255
                    //ParserResult result = parse(fo);
249
            final org.netbeans.editor.Formatter f = doc.getFormatter();
256
                    f.reformat(startPos, endPos);
250
            try {
257
251
                f.reformatLock();
258
                    int indent = GsfUtilities.getLineIndent(doc, insertOffset+1);
252
                f.reformat(doc, startPos, endPos);
259
260
                    //bc.afterBreak(doc, insertOffset, caret);
261
                    String formatted = doc.getText(0, doc.getLength());
262
                    assertEquals(expected, formatted);
263
                    if (newOffset != -1) {
264
                        caret.setDot(newOffset);
265
                    } else {
266
                        caret.setDot(insertOffset+1+indent);
267
                    }
268
                    if (finalCaretPos != -1) {
269
                        assertEquals(finalCaretPos, caret.getDot());
270
                    }
271
                } finally {
272
                    DocumentUtilities.setTypingModification(doc, false);
273
                }
253
            } finally {
274
            } finally {
254
                f.reformatUnlock();
275
                doc.atomicUnlock();
255
            }
256
257
            int indent = GsfUtilities.getLineIndent(doc, insertOffset+1);
258
259
            //bc.afterBreak(doc, insertOffset, caret);
260
            String formatted = doc.getText(0, doc.getLength());
261
            assertEquals(expected, formatted);
262
            if (newOffset != -1) {
263
                caret.setDot(newOffset);
264
            } else {
265
                caret.setDot(insertOffset+1+indent);
266
            }
267
            if (finalCaretPos != -1) {
268
                assertEquals(finalCaretPos, caret.getDot());
269
            }
276
            }
270
        } finally {
277
        } finally {
271
            DocumentUtilities.setTypingModification(doc, false);
278
            f.unlock();
272
            doc.atomicUnlock();
273
        }
279
        }
274
    }
280
    }
275
}
281
}
(-)a/php.project/nbproject/project.xml (-3 / +3 lines)
Lines 100-106 Link Here
100
                    <compile-dependency/>
100
                    <compile-dependency/>
101
                    <run-dependency>
101
                    <run-dependency>
102
                        <release-version>3</release-version>
102
                        <release-version>3</release-version>
103
                        <specification-version>1.49</specification-version>
103
                        <specification-version>1.53</specification-version>
104
                    </run-dependency>
104
                    </run-dependency>
105
                </dependency>
105
                </dependency>
106
                <dependency>
106
                <dependency>
Lines 126-133 Link Here
126
                    <build-prerequisite/>
126
                    <build-prerequisite/>
127
                    <compile-dependency/>
127
                    <compile-dependency/>
128
                    <run-dependency>
128
                    <run-dependency>
129
                        <release-version>2</release-version>
129
                        <release-version>3</release-version>
130
                        <specification-version>2.1</specification-version>
130
                        <specification-version>3.1</specification-version>
131
                    </run-dependency>
131
                    </run-dependency>
132
                </dependency>
132
                </dependency>
133
                <dependency>
133
                <dependency>
(-)a/php.refactoring/nbproject/project.xml (-2 / +2 lines)
Lines 37-44 Link Here
37
                    <build-prerequisite/>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>2</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>2.1</specification-version>
41
                        <specification-version>3.1</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
(-)a/php.symfony/nbproject/project.xml (-1 / +1 lines)
Lines 20-26 Link Here
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>3</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>1.43</specification-version>
23
                        <specification-version>1.53</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/php.zend/nbproject/project.xml (-1 / +1 lines)
Lines 20-26 Link Here
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>3</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>1.47</specification-version>
23
                        <specification-version>1.53</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/print.editor/nbproject/project.xml (-2 / +2 lines)
Lines 61-68 Link Here
61
                    <build-prerequisite/>
61
                    <build-prerequisite/>
62
                    <compile-dependency/>
62
                    <compile-dependency/>
63
                    <run-dependency>
63
                    <run-dependency>
64
                        <release-version>2</release-version>
64
                        <release-version>3</release-version>
65
                        <specification-version>2.1</specification-version>
65
                        <specification-version>3.1</specification-version>
66
                    </run-dependency>
66
                    </run-dependency>
67
                </dependency>
67
                </dependency>
68
                <dependency>
68
                <dependency>
(-)a/profiler.oql.language/nbproject/project.xml (-3 / +3 lines)
Lines 29-35 Link Here
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>3</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>1.42</specification-version>
32
                        <specification-version>1.53</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
Lines 46-53 Link Here
46
                    <build-prerequisite/>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>2</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>2.1</specification-version>
50
                        <specification-version>3.1</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
(-)a/profiler.projectsupport/nbproject/project.xml (-2 / +2 lines)
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/profiler.utilities/nbproject/project.xml (-2 / +2 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/profiler/nbproject/project.xml (-3 / +3 lines)
Lines 126-132 Link Here
126
                    <compile-dependency/>
126
                    <compile-dependency/>
127
                    <run-dependency>
127
                    <run-dependency>
128
                        <release-version>3</release-version>
128
                        <release-version>3</release-version>
129
                        <specification-version>1.41</specification-version>
129
                        <specification-version>1.53</specification-version>
130
                    </run-dependency>
130
                    </run-dependency>
131
                </dependency>
131
                </dependency>
132
                <dependency>
132
                <dependency>
Lines 134-141 Link Here
134
                    <build-prerequisite/>
134
                    <build-prerequisite/>
135
                    <compile-dependency/>
135
                    <compile-dependency/>
136
                    <run-dependency>
136
                    <run-dependency>
137
                        <release-version>2</release-version>
137
                        <release-version>3</release-version>
138
                        <specification-version>2.1</specification-version>
138
                        <specification-version>3.1</specification-version>
139
                    </run-dependency>
139
                    </run-dependency>
140
                </dependency>
140
                </dependency>
141
                <dependency>
141
                <dependency>
(-)a/properties.syntax/nbproject/project.xml (-3 / +3 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.41</specification-version>
58
                        <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/python.debugger/nbproject/project.xml (-2 / +2 lines)
Lines 28-35 Link Here
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>2.1</specification-version>
32
                        <specification-version>3.1</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/python.editor/nbproject/project.xml (-2 / +2 lines)
Lines 55-62 Link Here
55
                    <build-prerequisite/>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
56
                    <compile-dependency/>
57
                    <run-dependency>
57
                    <run-dependency>
58
                        <release-version>2</release-version>
58
                        <release-version>3</release-version>
59
                        <specification-version>2.1</specification-version>
59
                        <specification-version>3.1</specification-version>
60
                    </run-dependency>
60
                    </run-dependency>
61
                </dependency>
61
                </dependency>
62
                <dependency>
62
                <dependency>
(-)a/python.editor/src/org/netbeans/modules/python/editor/PythonFormatter.java (-9 / +1 lines)
Lines 348-354 Link Here
348
348
349
            doc.runAtomic(new Runnable() {
349
            doc.runAtomic(new Runnable() {
350
                public void run() {
350
                public void run() {
351
                    org.netbeans.editor.Formatter editorFormatter = null;
352
                    int[] computedIndents = new int[offsets.size()];
351
                    int[] computedIndents = new int[offsets.size()];
353
                    // Process backwards so I don't have to worry about updating offsets affected by
352
                    // Process backwards so I don't have to worry about updating offsets affected by
354
                    // indentation changes
353
                    // indentation changes
Lines 409-422 Link Here
409
408
410
                        if (computedIndent != indent) {
409
                        if (computedIndent != indent) {
411
                            try {
410
                            try {
412
                                if (context != null) {
411
                                context.modifyIndent(offset, computedIndent);
413
                                    context.modifyIndent(offset, computedIndent);
414
                                } else {
415
                                    if (editorFormatter == null) {
416
                                        editorFormatter = doc.getFormatter();
417
                                    }
418
                                    editorFormatter.changeRowIndent(doc, offset, computedIndent);
419
                                }
420
                            } catch (BadLocationException ex) {
412
                            } catch (BadLocationException ex) {
421
                                Exceptions.printStackTrace(ex);
413
                                Exceptions.printStackTrace(ex);
422
                            }
414
                            }
(-)a/python.testrunner/nbproject/project.xml (-2 / +2 lines)
Lines 26-33 Link Here
26
                    <build-prerequisite/>
26
                    <build-prerequisite/>
27
                    <compile-dependency/>
27
                    <compile-dependency/>
28
                    <run-dependency>
28
                    <run-dependency>
29
                        <release-version>2</release-version>
29
                        <release-version>3</release-version>
30
                        <specification-version>2.1</specification-version>
30
                        <specification-version>3.1</specification-version>
31
                    </run-dependency>
31
                    </run-dependency>
32
                </dependency>
32
                </dependency>
33
                <dependency>
33
                <dependency>
(-)a/refactoring.api/nbproject/project.xml (-2 / +2 lines)
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/ruby.extrahints/nbproject/project.xml (-2 / +2 lines)
Lines 46-53 Link Here
46
                    <build-prerequisite/>
46
                    <build-prerequisite/>
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>2</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>2.1</specification-version>
50
                        <specification-version>3.1</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
(-)a/ruby.hints/nbproject/project.xml (-2 / +2 lines)
Lines 64-71 Link Here
64
                    <build-prerequisite/>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>2</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>2.1</specification-version>
68
                        <specification-version>3.1</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
(-)a/ruby.project/nbproject/project.xml (-2 / +2 lines)
Lines 73-80 Link Here
73
                    <build-prerequisite/>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
74
                    <compile-dependency/>
75
                    <run-dependency>
75
                    <run-dependency>
76
                        <release-version>2</release-version>
76
                        <release-version>3</release-version>
77
                        <specification-version>2.1</specification-version>
77
                        <specification-version>3.1</specification-version>
78
                    </run-dependency>
78
                    </run-dependency>
79
                </dependency>
79
                </dependency>
80
                <dependency>
80
                <dependency>
(-)a/ruby.railsprojects/nbproject/project.xml (-2 / +2 lines)
Lines 81-88 Link Here
81
                    <build-prerequisite/>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>2</release-version>
84
                        <release-version>3</release-version>
85
                        <specification-version>2.1</specification-version>
85
                        <specification-version>3.1</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/ruby.refactoring/nbproject/project.xml (-2 / +2 lines)
Lines 37-44 Link Here
37
                    <build-prerequisite/>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>2</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>2.1</specification-version>
41
                        <specification-version>3.1</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
(-)a/ruby.rhtml/nbproject/project.xml (-3 / +3 lines)
Lines 29-35 Link Here
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>3</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>1.41</specification-version>
32
                        <specification-version>1.53</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
Lines 73-80 Link Here
73
                    <build-prerequisite/>
73
                    <build-prerequisite/>
74
                    <compile-dependency/>
74
                    <compile-dependency/>
75
                    <run-dependency>
75
                    <run-dependency>
76
                        <release-version>2</release-version>
76
                        <release-version>3</release-version>
77
                        <specification-version>2.1</specification-version>
77
                        <specification-version>3.1</specification-version>
78
                    </run-dependency>
78
                    </run-dependency>
79
                </dependency>
79
                </dependency>
80
                <dependency>
80
                <dependency>
(-)a/ruby.rspec/nbproject/project.xml (-3 / +3 lines)
Lines 29-35 Link Here
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>3</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>1.41</specification-version>
32
                        <specification-version>1.53</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
Lines 37-44 Link Here
37
                    <build-prerequisite/>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>2</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>2.1</specification-version>
41
                        <specification-version>3.1</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
(-)a/ruby/nbproject/project.xml (-3 / +3 lines)
Lines 65-71 Link Here
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>3</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>1.41</specification-version>
68
                        <specification-version>1.53</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
Lines 91-98 Link Here
91
                    <build-prerequisite/>
91
                    <build-prerequisite/>
92
                    <compile-dependency/>
92
                    <compile-dependency/>
93
                    <run-dependency>
93
                    <run-dependency>
94
                        <release-version>2</release-version>
94
                        <release-version>3</release-version>
95
                        <specification-version>2.1</specification-version>
95
                        <specification-version>3.1</specification-version>
96
                    </run-dependency>
96
                    </run-dependency>
97
                </dependency>
97
                </dependency>
98
                <dependency>
98
                <dependency>
(-)a/ruby/src/org/netbeans/modules/ruby/RubyFormatter.java (-10 / +2 lines)
Lines 562-568 Link Here
562
                    try {
562
                    try {
563
                        // Iterate in reverse order such that offsets are not affected by our edits
563
                        // Iterate in reverse order such that offsets are not affected by our edits
564
                        assert indents.size() == offsets.size();
564
                        assert indents.size() == offsets.size();
565
                        org.netbeans.editor.Formatter editorFormatter = null;
566
                        for (int i = indents.size() - 1; i >= 0; i--) {
565
                        for (int i = indents.size() - 1; i >= 0; i--) {
567
                            int indent = indents.get(i);
566
                            int indent = indents.get(i);
568
                            int lineBegin = offsets.get(i);
567
                            int lineBegin = offsets.get(i);
Lines 598-612 Link Here
598
                            int currentIndent = GsfUtilities.getLineIndent(doc, lineBegin);
597
                            int currentIndent = GsfUtilities.getLineIndent(doc, lineBegin);
599
598
600
                            if (currentIndent != indent && indent >= 0) {
599
                            if (currentIndent != indent && indent >= 0) {
601
                                if (context != null) {
600
                                assert lineBegin == Utilities.getRowStart(doc, lineBegin);
602
                                    assert lineBegin == Utilities.getRowStart(doc, lineBegin);
601
                                context.modifyIndent(lineBegin, indent);
603
                                    context.modifyIndent(lineBegin, indent);
604
                                } else {
605
                                    if (editorFormatter == null) {
606
                                         editorFormatter = doc.getFormatter();
607
                                    }
608
                                    editorFormatter.changeRowIndent(doc, lineBegin, indent);
609
                                }
610
                            }
602
                            }
611
                        }
603
                        }
612
604
(-)a/ruby/src/org/netbeans/modules/ruby/options/FmtOptions.java (-6 / +23 lines)
Lines 70-81 Link Here
70
import javax.swing.JViewport;
70
import javax.swing.JViewport;
71
import javax.swing.event.DocumentEvent;
71
import javax.swing.event.DocumentEvent;
72
import javax.swing.event.DocumentListener;
72
import javax.swing.event.DocumentListener;
73
import javax.swing.text.BadLocationException;
74
import javax.swing.text.Document;
73
import org.netbeans.api.editor.settings.SimpleValueNames;
75
import org.netbeans.api.editor.settings.SimpleValueNames;
74
76
75
import org.netbeans.api.ruby.platform.RubyInstallation;
77
import org.netbeans.api.ruby.platform.RubyInstallation;
78
import org.netbeans.editor.BaseDocument;
79
import org.netbeans.modules.editor.indent.api.Reformat;
76
import org.netbeans.modules.options.editor.spi.PreferencesCustomizer;
80
import org.netbeans.modules.options.editor.spi.PreferencesCustomizer;
77
import org.netbeans.modules.options.editor.spi.PreviewProvider;
81
import org.netbeans.modules.options.editor.spi.PreviewProvider;
78
import org.netbeans.modules.ruby.RubyFormatter;
79
import org.openide.text.CloneableEditorSupport;
82
import org.openide.text.CloneableEditorSupport;
80
import org.openide.util.HelpCtx;
83
import org.openide.util.HelpCtx;
81
import org.openide.util.NbBundle;
84
import org.openide.util.NbBundle;
Lines 348-358 Link Here
348
351
349
            jep.setIgnoreRepaint(true);
352
            jep.setIgnoreRepaint(true);
350
            jep.setText(previewText);
353
            jep.setText(previewText);
351
            
354
352
            CodeStyle codeStyle = CodeStyle.get(previewPrefs);
355
            final Document doc = jep.getDocument();
353
            RubyFormatter formatter = new RubyFormatter(codeStyle, rm);
356
            final Reformat formatter = Reformat.get(doc);
354
            formatter.reindent(null, jep.getDocument(), 0, jep.getDocument().getLength(), null, false);
357
            formatter.lock();
355
            
358
            try {
359
                ((BaseDocument) doc).runAtomic(new Runnable() {
360
                    public void run() {
361
                        try {
362
                            // The formatter is automatically going to use the previewPrefs.
363
                            formatter.reformat(0, doc.getLength());
364
                        } catch (BadLocationException ble) {
365
                            // ignore
366
                        }
367
                    }
368
                });
369
            } finally {
370
                formatter.unlock();
371
            }
372
356
            jep.setIgnoreRepaint(false);
373
            jep.setIgnoreRepaint(false);
357
            jep.scrollRectToVisible(new Rectangle(0,0,10,10) );
374
            jep.scrollRectToVisible(new Rectangle(0,0,10,10) );
358
            jep.repaint(100);
375
            jep.repaint(100);
(-)a/soa.jca.base/nbproject/project.xml (-2 / +2 lines)
Lines 81-88 Link Here
81
                    <build-prerequisite/>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>2</release-version>
84
                        <release-version>3</release-version>
85
                        <specification-version>2.1</specification-version>
85
                        <specification-version>3.1</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/soa.palette.java/nbproject/project.xml (-2 / +2 lines)
Lines 81-88 Link Here
81
                    <build-prerequisite/>
81
                    <build-prerequisite/>
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>2</release-version>
84
                        <release-version>3</release-version>
85
                        <specification-version>2.1</specification-version>
85
                        <specification-version>3.1</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
(-)a/soa.pojo/nbproject/project.xml (-2 / +2 lines)
Lines 123-130 Link Here
123
                    <build-prerequisite/>
123
                    <build-prerequisite/>
124
                    <compile-dependency/>
124
                    <compile-dependency/>
125
                    <run-dependency>
125
                    <run-dependency>
126
                        <release-version>2</release-version>
126
                        <release-version>3</release-version>
127
                        <specification-version>2.1</specification-version>
127
                        <specification-version>3.1</specification-version>
128
                    </run-dependency>
128
                    </run-dependency>
129
                </dependency>
129
                </dependency>
130
                <dependency>
130
                <dependency>
(-)a/soa.ui/nbproject/project.xml (-2 / +2 lines)
Lines 239-246 Link Here
239
                    <build-prerequisite/>
239
                    <build-prerequisite/>
240
                    <compile-dependency/>
240
                    <compile-dependency/>
241
                    <run-dependency>
241
                    <run-dependency>
242
                        <release-version>2</release-version>
242
                        <release-version>3</release-version>
243
                        <specification-version>2.1</specification-version>
243
                        <specification-version>3.1</specification-version>
244
                    </run-dependency>
244
                    </run-dependency>
245
                </dependency>
245
                </dependency>
246
            </module-dependencies>
246
            </module-dependencies>
(-)a/spellchecker.bindings.htmlxml/nbproject/project.xml (-3 / +3 lines)
Lines 11-17 Link Here
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.41</specification-version>
14
                        <specification-version>1.53</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
Lines 19-26 Link Here
19
                    <build-prerequisite/>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>2.1</specification-version>
23
                        <specification-version>3.1</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/spellchecker.bindings.java/nbproject/project.xml (-3 / +3 lines)
Lines 19-25 Link Here
19
                    <compile-dependency/>
19
                    <compile-dependency/>
20
                    <run-dependency>
20
                    <run-dependency>
21
                        <release-version>3</release-version>
21
                        <release-version>3</release-version>
22
                        <specification-version>1.41</specification-version>
22
                        <specification-version>1.53</specification-version>
23
                    </run-dependency>
23
                    </run-dependency>
24
                </dependency>
24
                </dependency>
25
                <dependency>
25
                <dependency>
Lines 27-34 Link Here
27
                    <build-prerequisite/>
27
                    <build-prerequisite/>
28
                    <compile-dependency/>
28
                    <compile-dependency/>
29
                    <run-dependency>
29
                    <run-dependency>
30
                        <release-version>2</release-version>
30
                        <release-version>3</release-version>
31
                        <specification-version>2.1</specification-version>
31
                        <specification-version>3.1</specification-version>
32
                    </run-dependency>
32
                    </run-dependency>
33
                </dependency>
33
                </dependency>
34
                <dependency>
34
                <dependency>
(-)a/spellchecker.bindings.properties/nbproject/project.xml (-3 / +3 lines)
Lines 11-17 Link Here
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.41</specification-version>
14
                        <specification-version>1.53</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
Lines 19-26 Link Here
19
                    <build-prerequisite/>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>2.1</specification-version>
23
                        <specification-version>3.1</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/spellchecker.bindings.ruby/nbproject/project.xml (-3 / +3 lines)
Lines 11-17 Link Here
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.41</specification-version>
14
                        <specification-version>1.53</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
Lines 19-26 Link Here
19
                    <build-prerequisite/>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>2</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>2.1</specification-version>
23
                        <specification-version>3.1</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/spellchecker/nbproject/project.xml (-3 / +3 lines)
Lines 11-17 Link Here
11
                    <compile-dependency/>
11
                    <compile-dependency/>
12
                    <run-dependency>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.41</specification-version>
14
                        <specification-version>1.53</specification-version>
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
Lines 28-35 Link Here
28
                    <build-prerequisite/>
28
                    <build-prerequisite/>
29
                    <compile-dependency/>
29
                    <compile-dependency/>
30
                    <run-dependency>
30
                    <run-dependency>
31
                        <release-version>2</release-version>
31
                        <release-version>3</release-version>
32
                        <specification-version>2.1</specification-version>
32
                        <specification-version>3.1</specification-version>
33
                    </run-dependency>
33
                    </run-dependency>
34
                </dependency>
34
                </dependency>
35
                <dependency>
35
                <dependency>
(-)a/spi.debugger.ui/nbproject/project.xml (-2 / +2 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.7</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/spi.editor.hints/nbproject/project.xml (-2 / +2 lines)
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/spring.beans/nbproject/project.xml (-3 / +3 lines)
Lines 105-111 Link Here
105
                    <compile-dependency/>
105
                    <compile-dependency/>
106
                    <run-dependency>
106
                    <run-dependency>
107
                        <release-version>3</release-version>
107
                        <release-version>3</release-version>
108
                        <specification-version>1.41</specification-version>
108
                        <specification-version>1.53</specification-version>
109
                    </run-dependency>
109
                    </run-dependency>
110
                </dependency>
110
                </dependency>
111
                <dependency>
111
                <dependency>
Lines 131-138 Link Here
131
                    <build-prerequisite/>
131
                    <build-prerequisite/>
132
                    <compile-dependency/>
132
                    <compile-dependency/>
133
                    <run-dependency>
133
                    <run-dependency>
134
                        <release-version>2</release-version>
134
                        <release-version>3</release-version>
135
                        <specification-version>2.1</specification-version>
135
                        <specification-version>3.1</specification-version>
136
                    </run-dependency>
136
                    </run-dependency>
137
                </dependency>
137
                </dependency>
138
                <dependency>
138
                <dependency>
(-)a/spring.webmvc/nbproject/project.xml (-1 / +1 lines)
Lines 98-104 Link Here
98
                    <compile-dependency/>
98
                    <compile-dependency/>
99
                    <run-dependency>
99
                    <run-dependency>
100
                        <release-version>3</release-version>
100
                        <release-version>3</release-version>
101
                        <specification-version>1.48</specification-version>
101
                        <specification-version>1.53</specification-version>
102
                    </run-dependency>
102
                    </run-dependency>
103
                </dependency>
103
                </dependency>
104
                <dependency>
104
                <dependency>
(-)a/subversion/nbproject/project.xml (-2 / +2 lines)
Lines 80-87 Link Here
80
                    <build-prerequisite/>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
81
                    <compile-dependency/>
82
                    <run-dependency>
82
                    <run-dependency>
83
                        <release-version>2</release-version>
83
                        <release-version>3</release-version>
84
                        <specification-version>2.1</specification-version>
84
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
85
                    </run-dependency>
86
                </dependency>
86
                </dependency>
87
                <dependency>
87
                <dependency>
(-)a/versioning.system.cvss/nbproject/project.xml (-3 / +3 lines)
Lines 99-105 Link Here
99
                    <compile-dependency/>
99
                    <compile-dependency/>
100
                    <run-dependency>
100
                    <run-dependency>
101
                        <release-version>3</release-version>
101
                        <release-version>3</release-version>
102
                        <specification-version>1.41</specification-version>
102
                        <specification-version>1.53</specification-version>
103
                    </run-dependency>
103
                    </run-dependency>
104
                </dependency>
104
                </dependency>
105
                <dependency>
105
                <dependency>
Lines 124-131 Link Here
124
                    <build-prerequisite/>
124
                    <build-prerequisite/>
125
                    <compile-dependency/>
125
                    <compile-dependency/>
126
                    <run-dependency>
126
                    <run-dependency>
127
                        <release-version>2</release-version>
127
                        <release-version>3</release-version>
128
                        <specification-version>2.1</specification-version>
128
                        <specification-version>3.1</specification-version>
129
                    </run-dependency>
129
                    </run-dependency>
130
                </dependency>
130
                </dependency>
131
                <dependency>
131
                <dependency>
(-)a/versioning.util/nbproject/project.xml (-3 / +3 lines)
Lines 47-53 Link Here
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>3</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>1.44</specification-version>
50
                        <specification-version>1.53</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
Lines 72-79 Link Here
72
                    <build-prerequisite/>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>2</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>2.1</specification-version>
76
                        <specification-version>3.1</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
(-)a/versioning/nbproject/project.xml (-2 / +2 lines)
Lines 89-96 Link Here
89
                    <build-prerequisite/>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>2</release-version>
92
                        <release-version>3</release-version>
93
                        <specification-version>2.1</specification-version>
93
                        <specification-version>3.1</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/visualweb.designer.jsf/nbproject/project.xml (-2 / +2 lines)
Lines 90-97 Link Here
90
                    <build-prerequisite/>
90
                    <build-prerequisite/>
91
                    <compile-dependency/>
91
                    <compile-dependency/>
92
                    <run-dependency>
92
                    <run-dependency>
93
                        <release-version>2</release-version>
93
                        <release-version>3</release-version>
94
                        <specification-version>2.1</specification-version>
94
                        <specification-version>3.1</specification-version>
95
                    </run-dependency>
95
                    </run-dependency>
96
                </dependency>
96
                </dependency>
97
                <dependency>
97
                <dependency>
(-)a/visualweb.gravy/nbproject/project.xml (-2 / +2 lines)
Lines 89-96 Link Here
89
                    <build-prerequisite/>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>2</release-version>
92
                        <release-version>3</release-version>
93
                        <specification-version>2.1</specification-version>
93
                        <specification-version>3.1</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/visualweb.insync/nbproject/project.xml (-3 / +3 lines)
Lines 107-113 Link Here
107
                    <compile-dependency/>
107
                    <compile-dependency/>
108
                    <run-dependency>
108
                    <run-dependency>
109
                        <release-version>3</release-version>
109
                        <release-version>3</release-version>
110
                        <specification-version>1.41</specification-version>
110
                        <specification-version>1.53</specification-version>
111
                    </run-dependency>
111
                    </run-dependency>
112
                </dependency>
112
                </dependency>
113
                <dependency>
113
                <dependency>
Lines 115-122 Link Here
115
                    <build-prerequisite/>
115
                    <build-prerequisite/>
116
                    <compile-dependency/>
116
                    <compile-dependency/>
117
                    <run-dependency>
117
                    <run-dependency>
118
                        <release-version>2</release-version>
118
                        <release-version>3</release-version>
119
                        <specification-version>2.1</specification-version>
119
                        <specification-version>3.1</specification-version>
120
                    </run-dependency>
120
                    </run-dependency>
121
                </dependency>
121
                </dependency>
122
                <dependency>
122
                <dependency>
(-)a/visualweb.palette/nbproject/project.xml (-2 / +2 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/visualweb.project.jsfloader/nbproject/project.xml (-2 / +2 lines)
Lines 63-70 Link Here
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <release-version>2</release-version>
66
                        <release-version>3</release-version>
67
                        <specification-version>2.1</specification-version>
67
                        <specification-version>3.1</specification-version>
68
                    </run-dependency>
68
                    </run-dependency>
69
                </dependency>
69
                </dependency>
70
                <dependency>
70
                <dependency>
(-)a/vmd.midp/nbproject/project.xml (-2 / +2 lines)
Lines 114-121 Link Here
114
                    <build-prerequisite/>
114
                    <build-prerequisite/>
115
                    <compile-dependency/>
115
                    <compile-dependency/>
116
                    <run-dependency>
116
                    <run-dependency>
117
                        <release-version>2</release-version>
117
                        <release-version>3</release-version>
118
                        <specification-version>2.1</specification-version>
118
                        <specification-version>3.1</specification-version>
119
                    </run-dependency>
119
                    </run-dependency>
120
                </dependency>
120
                </dependency>
121
                <dependency>
121
                <dependency>
(-)a/wag.codegen.java/nbproject/project.xml (-1 / +1 lines)
Lines 46-52 Link Here
46
                    <compile-dependency/>
46
                    <compile-dependency/>
47
                    <run-dependency>
47
                    <run-dependency>
48
                        <release-version>3</release-version>
48
                        <release-version>3</release-version>
49
                        <specification-version>1.41</specification-version>
49
                        <specification-version>1.53</specification-version>
50
                    </run-dependency>
50
                    </run-dependency>
51
                </dependency>
51
                </dependency>
52
                <dependency>
52
                <dependency>
(-)a/wag.codegen.php/nbproject/project.xml (-1 / +1 lines)
Lines 12-18 Link Here
12
                    <compile-dependency/>
12
                    <compile-dependency/>
13
                    <run-dependency>
13
                    <run-dependency>
14
                        <release-version>3</release-version>
14
                        <release-version>3</release-version>
15
                        <specification-version>1.41</specification-version>
15
                        <specification-version>1.53</specification-version>
16
                    </run-dependency>
16
                    </run-dependency>
17
                </dependency>
17
                </dependency>
18
                <dependency>
18
                <dependency>
(-)a/wag.codegen/nbproject/project.xml (-3 / +3 lines)
Lines 38-44 Link Here
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>3</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>1.41</specification-version>
41
                        <specification-version>1.53</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
Lines 55-62 Link Here
55
                    <build-prerequisite/>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
56
                    <compile-dependency/>
57
                    <run-dependency>
57
                    <run-dependency>
58
                        <release-version>2</release-version>
58
                        <release-version>3</release-version>
59
                        <specification-version>2.1</specification-version>
59
                        <specification-version>3.1</specification-version>
60
                    </run-dependency>
60
                    </run-dependency>
61
                </dependency>
61
                </dependency>
62
                <dependency>
62
                <dependency>
(-)a/wag.manager/nbproject/project.xml (-2 / +2 lines)
Lines 37-44 Link Here
37
                    <build-prerequisite/>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>2</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>2.1</specification-version>
41
                        <specification-version>3.1</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
(-)a/web.beans/nbproject/project.xml (-3 / +3 lines)
Lines 45-51 Link Here
45
                    <compile-dependency/>
45
                    <compile-dependency/>
46
                    <run-dependency>
46
                    <run-dependency>
47
                        <release-version>3</release-version>
47
                        <release-version>3</release-version>
48
                        <specification-version>1.43</specification-version>
48
                        <specification-version>1.53</specification-version>
49
                    </run-dependency>
49
                    </run-dependency>
50
                </dependency>
50
                </dependency>
51
                <dependency>
51
                <dependency>
Lines 53-60 Link Here
53
                    <build-prerequisite/>
53
                    <build-prerequisite/>
54
                    <compile-dependency/>
54
                    <compile-dependency/>
55
                    <run-dependency>
55
                    <run-dependency>
56
                        <release-version>2</release-version>
56
                        <release-version>3</release-version>
57
                        <specification-version>2.1</specification-version>
57
                        <specification-version>3.1</specification-version>
58
                    </run-dependency>
58
                    </run-dependency>
59
                </dependency>
59
                </dependency>
60
                <dependency>
60
                <dependency>
(-)a/web.client.tools.impl/nbproject/project.xml (-2 / +2 lines)
Lines 37-44 Link Here
37
                    <build-prerequisite/>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
38
                    <compile-dependency/>
39
                    <run-dependency>
39
                    <run-dependency>
40
                        <release-version>2</release-version>
40
                        <release-version>3</release-version>
41
                        <specification-version>2.1</specification-version>
41
                        <specification-version>3.1</specification-version>
42
                    </run-dependency>
42
                    </run-dependency>
43
                </dependency>
43
                </dependency>
44
                <dependency>
44
                <dependency>
(-)a/web.core.syntax/nbproject/project.xml (-3 / +12 lines)
Lines 116-122 Link Here
116
                    <compile-dependency/>
116
                    <compile-dependency/>
117
                    <run-dependency>
117
                    <run-dependency>
118
                        <release-version>3</release-version>
118
                        <release-version>3</release-version>
119
                        <specification-version>1.41</specification-version>
119
                        <specification-version>1.53</specification-version>
120
                    </run-dependency>
120
                    </run-dependency>
121
                </dependency>
121
                </dependency>
122
                <dependency>
122
                <dependency>
Lines 167-174 Link Here
167
                    <build-prerequisite/>
167
                    <build-prerequisite/>
168
                    <compile-dependency/>
168
                    <compile-dependency/>
169
                    <run-dependency>
169
                    <run-dependency>
170
                        <release-version>2</release-version>
170
                        <release-version>3</release-version>
171
                        <specification-version>2.1</specification-version>
171
                        <specification-version>3.1</specification-version>
172
                    </run-dependency>
172
                    </run-dependency>
173
                </dependency>
173
                </dependency>
174
                <dependency>
174
                <dependency>
Lines 449-454 Link Here
449
                        <specification-version>6.2</specification-version>
449
                        <specification-version>6.2</specification-version>
450
                    </run-dependency>
450
                    </run-dependency>
451
                </dependency>
451
                </dependency>
452
            <dependency>
453
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
454
                    <build-prerequisite/>
455
                    <compile-dependency/>
456
                    <run-dependency>
457
                        <release-version>0-1</release-version>
458
                        <specification-version>1.0</specification-version>
459
                    </run-dependency>
460
                </dependency>
452
            </module-dependencies>
461
            </module-dependencies>
453
            <test-dependencies>
462
            <test-dependencies>
454
                <test-type>
463
                <test-type>
(-)a/web.core/nbproject/project.xml (-3 / +3 lines)
Lines 113-119 Link Here
113
                    <compile-dependency/>
113
                    <compile-dependency/>
114
                    <run-dependency>
114
                    <run-dependency>
115
                        <release-version>3</release-version>
115
                        <release-version>3</release-version>
116
                        <specification-version>1.41</specification-version>
116
                        <specification-version>1.53</specification-version>
117
                    </run-dependency>
117
                    </run-dependency>
118
                </dependency>
118
                </dependency>
119
                <dependency>
119
                <dependency>
Lines 130-137 Link Here
130
                    <build-prerequisite/>
130
                    <build-prerequisite/>
131
                    <compile-dependency/>
131
                    <compile-dependency/>
132
                    <run-dependency>
132
                    <run-dependency>
133
                        <release-version>2</release-version>
133
                        <release-version>3</release-version>
134
                        <specification-version>2.1</specification-version>
134
                        <specification-version>3.1</specification-version>
135
                    </run-dependency>
135
                    </run-dependency>
136
                </dependency>
136
                </dependency>
137
                <dependency>
137
                <dependency>
(-)a/web.el/nbproject/project.xml (-3 / +3 lines)
Lines 63-69 Link Here
63
                    <compile-dependency/>
63
                    <compile-dependency/>
64
                    <run-dependency>
64
                    <run-dependency>
65
                        <release-version>3</release-version>
65
                        <release-version>3</release-version>
66
                        <specification-version>1.43</specification-version>
66
                        <specification-version>1.53</specification-version>
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
Lines 89-96 Link Here
89
                    <build-prerequisite/>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>2</release-version>
92
                        <release-version>3</release-version>
93
                        <specification-version>2.1</specification-version>
93
                        <specification-version>3.1</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/web.jsf.editor/nbproject/project.xml (-3 / +3 lines)
Lines 112-118 Link Here
112
                    <compile-dependency/>
112
                    <compile-dependency/>
113
                    <run-dependency>
113
                    <run-dependency>
114
                        <release-version>3</release-version>
114
                        <release-version>3</release-version>
115
                        <specification-version>1.43</specification-version>
115
                        <specification-version>1.53</specification-version>
116
                    </run-dependency>
116
                    </run-dependency>
117
                </dependency>
117
                </dependency>
118
                <dependency>
118
                <dependency>
Lines 138-145 Link Here
138
                    <build-prerequisite/>
138
                    <build-prerequisite/>
139
                    <compile-dependency/>
139
                    <compile-dependency/>
140
                    <run-dependency>
140
                    <run-dependency>
141
                        <release-version>2</release-version>
141
                        <release-version>3</release-version>
142
                        <specification-version>2.1</specification-version>
142
                        <specification-version>3.1</specification-version>
143
                    </run-dependency>
143
                    </run-dependency>
144
                </dependency>
144
                </dependency>
145
                <dependency>
145
                <dependency>
(-)a/web.jsf.navigation/nbproject/project.xml (-3 / +3 lines)
Lines 45-51 Link Here
45
                    <compile-dependency/>
45
                    <compile-dependency/>
46
                    <run-dependency>
46
                    <run-dependency>
47
                        <release-version>3</release-version>
47
                        <release-version>3</release-version>
48
                        <specification-version>1.41</specification-version>
48
                        <specification-version>1.53</specification-version>
49
                    </run-dependency>
49
                    </run-dependency>
50
                </dependency>
50
                </dependency>
51
                <dependency>
51
                <dependency>
Lines 53-60 Link Here
53
                    <build-prerequisite/>
53
                    <build-prerequisite/>
54
                    <compile-dependency/>
54
                    <compile-dependency/>
55
                    <run-dependency>
55
                    <run-dependency>
56
                        <release-version>2</release-version>
56
                        <release-version>3</release-version>
57
                        <specification-version>2.1</specification-version>
57
                        <specification-version>3.1</specification-version>
58
                    </run-dependency>
58
                    </run-dependency>
59
                </dependency>
59
                </dependency>
60
                <dependency>
60
                <dependency>
(-)a/web.jsf/nbproject/project.xml (-4 / +4 lines)
Lines 124-130 Link Here
124
                    <compile-dependency/>
124
                    <compile-dependency/>
125
                    <run-dependency>
125
                    <run-dependency>
126
                        <release-version>3</release-version>
126
                        <release-version>3</release-version>
127
                        <specification-version>1.41</specification-version>
127
                        <specification-version>1.53</specification-version>
128
                    </run-dependency>
128
                    </run-dependency>
129
                </dependency>
129
                </dependency>
130
                <dependency>
130
                <dependency>
Lines 133-139 Link Here
133
                    <compile-dependency/>
133
                    <compile-dependency/>
134
                    <run-dependency>
134
                    <run-dependency>
135
                        <release-version>2</release-version>
135
                        <release-version>2</release-version>
136
                        <specification-version>1.5</specification-version>
136
                        <specification-version>1.10</specification-version>
137
                    </run-dependency>
137
                    </run-dependency>
138
                </dependency>
138
                </dependency>
139
                <dependency>
139
                <dependency>
Lines 141-148 Link Here
141
                    <build-prerequisite/>
141
                    <build-prerequisite/>
142
                    <compile-dependency/>
142
                    <compile-dependency/>
143
                    <run-dependency>
143
                    <run-dependency>
144
                        <release-version>2</release-version>
144
                        <release-version>3</release-version>
145
                        <specification-version>2.1</specification-version>
145
                        <specification-version>3.1</specification-version>
146
                    </run-dependency>
146
                    </run-dependency>
147
                </dependency>
147
                </dependency>
148
                <dependency>
148
                <dependency>
(-)a/web.jsf/src/org/netbeans/modules/web/jsf/api/editor/JSFEditorUtilities.java (-10 / +24 lines)
Lines 49-57 Link Here
49
import java.io.StringWriter;
49
import java.io.StringWriter;
50
import javax.swing.JEditorPane;
50
import javax.swing.JEditorPane;
51
import javax.swing.text.BadLocationException;
51
import javax.swing.text.BadLocationException;
52
import javax.swing.text.Position;
52
import org.netbeans.editor.BaseDocument;
53
import org.netbeans.editor.BaseDocument;
53
import org.netbeans.editor.TokenItem;
54
import org.netbeans.editor.TokenItem;
54
import org.netbeans.editor.ext.ExtSyntaxSupport;
55
import org.netbeans.editor.ext.ExtSyntaxSupport;
56
import org.netbeans.modules.editor.indent.api.Indent;
57
import org.netbeans.modules.editor.indent.api.Reformat;
55
import org.netbeans.modules.schema2beans.BaseBean;
58
import org.netbeans.modules.schema2beans.BaseBean;
56
import org.openide.cookies.EditorCookie;
59
import org.openide.cookies.EditorCookie;
57
import org.openide.loaders.DataObject;
60
import org.openide.loaders.DataObject;
Lines 338-354 Link Here
338
    
341
    
339
    private static int writeString(BaseDocument doc, String text, int offset){
342
    private static int writeString(BaseDocument doc, String text, int offset){
340
        int formatLength = 0;
343
        int formatLength = 0;
341
        try{
344
        Indent indenter = Indent.get(doc);
345
        Reformat formatter = Reformat.get(doc);
346
        indenter.lock();
347
        formatter.lock();
348
        try {
342
            doc.atomicLock();
349
            doc.atomicLock();
343
            offset = doc.getFormatter().indentNewLine(doc, offset+1);
350
            try{
344
            doc.insertString(offset, text, null );
351
                offset = indenter.indentNewLine(offset + 1);
345
            formatLength = doc.getFormatter().reformat(doc, offset, offset + text.length()-1);
352
                doc.insertString(offset, text, null );
346
        }
353
                Position endPos = doc.createPosition(offset + text.length() - 1);
347
        catch(BadLocationException ex){
354
                formatter.reformat(offset, endPos.getOffset());
348
            Exceptions.printStackTrace(ex);
355
                formatLength = Math.max(0, endPos.getOffset() - offset);
349
        }
356
            }
350
        finally {
357
            catch(BadLocationException ex){
351
            doc.atomicUnlock();
358
                Exceptions.printStackTrace(ex);
359
            }
360
            finally {
361
                doc.atomicUnlock();
362
            }
363
        } finally {
364
            formatter.unlock();
365
            indenter.unlock();
352
        }
366
        }
353
        return offset + formatLength + 1;
367
        return offset + formatLength + 1;
354
    }
368
    }
(-)a/web.refactoring/nbproject/project.xml (-2 / +2 lines)
Lines 44-51 Link Here
44
                    <build-prerequisite/>
44
                    <build-prerequisite/>
45
                    <compile-dependency/>
45
                    <compile-dependency/>
46
                    <run-dependency>
46
                    <run-dependency>
47
                        <release-version>2</release-version>
47
                        <release-version>3</release-version>
48
                        <specification-version>2.1</specification-version>
48
                        <specification-version>3.1</specification-version>
49
                    </run-dependency>
49
                    </run-dependency>
50
                </dependency>
50
                </dependency>
51
                <dependency>
51
                <dependency>
(-)a/web.struts/nbproject/project.xml (-3 / +12 lines)
Lines 104-110 Link Here
104
                    <compile-dependency/>
104
                    <compile-dependency/>
105
                    <run-dependency>
105
                    <run-dependency>
106
                        <release-version>3</release-version>
106
                        <release-version>3</release-version>
107
                        <specification-version>1.41</specification-version>
107
                        <specification-version>1.53</specification-version>
108
                    </run-dependency>
108
                    </run-dependency>
109
                </dependency>
109
                </dependency>
110
                <dependency>
110
                <dependency>
Lines 116-127 Link Here
116
                    </run-dependency>
116
                    </run-dependency>
117
                </dependency>
117
                </dependency>
118
                <dependency>
118
                <dependency>
119
                    <code-name-base>org.netbeans.modules.editor.indent</code-name-base>
120
                    <build-prerequisite/>
121
                    <compile-dependency/>
122
                    <run-dependency>
123
                        <release-version>2</release-version>
124
                        <specification-version>1.10</specification-version>
125
                    </run-dependency>
126
                </dependency>
127
                <dependency>
119
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
128
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
120
                    <build-prerequisite/>
129
                    <build-prerequisite/>
121
                    <compile-dependency/>
130
                    <compile-dependency/>
122
                    <run-dependency>
131
                    <run-dependency>
123
                        <release-version>2</release-version>
132
                        <release-version>3</release-version>
124
                        <specification-version>2.1</specification-version>
133
                        <specification-version>3.1</specification-version>
125
                    </run-dependency>
134
                    </run-dependency>
126
                </dependency>
135
                </dependency>
127
                <dependency>
136
                <dependency>
(-)a/web.struts/src/org/netbeans/modules/web/struts/editor/StrutsEditorUtilities.java (-15 / +22 lines)
Lines 48-57 Link Here
48
import java.io.IOException;
48
import java.io.IOException;
49
import java.io.StringWriter;
49
import java.io.StringWriter;
50
import javax.swing.text.BadLocationException;
50
import javax.swing.text.BadLocationException;
51
import javax.swing.text.Position;
51
import org.netbeans.editor.BaseDocument;
52
import org.netbeans.editor.BaseDocument;
52
import org.netbeans.editor.Formatter;
53
import org.netbeans.editor.TokenItem;
53
import org.netbeans.editor.TokenItem;
54
import org.netbeans.editor.ext.ExtSyntaxSupport;
54
import org.netbeans.editor.ext.ExtSyntaxSupport;
55
import org.netbeans.modules.editor.indent.api.Indent;
56
import org.netbeans.modules.editor.indent.api.Reformat;
55
import org.netbeans.modules.schema2beans.BaseBean;
57
import org.netbeans.modules.schema2beans.BaseBean;
56
import org.netbeans.modules.web.struts.config.model.FormProperty;
58
import org.netbeans.modules.web.struts.config.model.FormProperty;
57
import org.netbeans.modules.web.struts.config.model.Forward;
59
import org.netbeans.modules.web.struts.config.model.Forward;
Lines 219-239 Link Here
219
                    text.append(addNewLines(bean));
221
                    text.append(addNewLines(bean));
220
                    text.append(END_LINE);
222
                    text.append(END_LINE);
221
                    text.append("</"); text.append(father); text.append(">");           //NOI18N
223
                    text.append("</"); text.append(father); text.append(">");           //NOI18N
222
                    Formatter fmt = doc.getFormatter();
224
                    Reformat fmt = Reformat.get(doc);
223
                    fmt.reformatLock();
225
                    fmt.lock();
224
                    try {
226
                    try {
227
                        doc.atomicLock();
225
                        try{
228
                        try{
226
                            doc.atomicLock();
227
                            doc.remove(offset, 2);
229
                            doc.remove(offset, 2);
228
                            doc.insertString(offset, text.toString(), null);
230
                            doc.insertString(offset, text.toString(), null);
229
                            offset += doc.getFormatter().reformat(doc, offset, offset + text.length()-1);
231
                            Position endPos = doc.createPosition(offset + text.length() - 1);
232
                            fmt.reformat(offset, endPos.getOffset());
233
                            offset += Math.max(0, endPos.getOffset() - offset);
230
                            possition = offset;
234
                            possition = offset;
231
                        }
235
                        }
232
                        finally{
236
                        finally{
233
                            doc.atomicUnlock();
237
                            doc.atomicUnlock();
234
                        }
238
                        }
235
                    } finally {
239
                    } finally {
236
                        fmt.reformatUnlock();
240
                        fmt.unlock();
237
                    }
241
                    }
238
                }
242
                }
239
                if (token != null && token.getImage().equals(">")){                     //NOI18N
243
                if (token != null && token.getImage().equals(">")){                     //NOI18N
Lines 371-396 Link Here
371
    }
375
    }
372
    
376
    
373
    private static int writeString(BaseDocument doc, String text, int offset) throws BadLocationException {
377
    private static int writeString(BaseDocument doc, String text, int offset) throws BadLocationException {
374
        int formatLength = 0;      
378
        int formatLength = 0;
375
        Formatter fmt = doc.getFormatter();
379
        Indent indent = Indent.get(doc);
376
        fmt.indentLock();
380
        Reformat fmt = Reformat.get(doc);
381
        indent.lock();
377
        try {
382
        try {
378
            fmt.reformatLock();
383
            fmt.lock();
379
            try {
384
            try {
385
                doc.atomicLock();
380
                try{
386
                try{
381
                    doc.atomicLock();
387
                    offset = indent.indentNewLine(offset + 1);
382
                    offset = doc.getFormatter().indentNewLine(doc, offset+1);
383
                    doc.insertString(Math.min(offset, doc.getLength()), text, null );
388
                    doc.insertString(Math.min(offset, doc.getLength()), text, null );
384
                    formatLength = doc.getFormatter().reformat(doc, offset, offset + text.length()-1);
389
                    Position endPos = doc.createPosition(offset + text.length() - 1);
390
                    fmt.reformat(offset, endPos.getOffset());
391
                    formatLength = Math.max(0, endPos.getOffset() - offset);
385
                }
392
                }
386
                finally{
393
                finally{
387
                    doc.atomicUnlock();
394
                    doc.atomicUnlock();
388
                }
395
                }
389
            } finally {
396
            } finally {
390
                fmt.reformatUnlock();
397
                fmt.unlock();
391
            }
398
            }
392
        } finally {
399
        } finally {
393
            fmt.indentUnlock();
400
            indent.unlock();
394
        }
401
        }
395
        return Math.min(offset + formatLength + 1, doc.getLength());
402
        return Math.min(offset + formatLength + 1, doc.getLength());
396
    }
403
    }
(-)a/webpreview/nbproject/project.xml (-1 / +1 lines)
Lines 20-26 Link Here
20
                    <compile-dependency/>
20
                    <compile-dependency/>
21
                    <run-dependency>
21
                    <run-dependency>
22
                        <release-version>3</release-version>
22
                        <release-version>3</release-version>
23
                        <specification-version>1.43</specification-version>
23
                        <specification-version>1.53</specification-version>
24
                    </run-dependency>
24
                    </run-dependency>
25
                </dependency>
25
                </dependency>
26
                <dependency>
26
                <dependency>
(-)a/websvc.core/nbproject/project.xml (-3 / +3 lines)
Lines 124-130 Link Here
124
                    <compile-dependency/>
124
                    <compile-dependency/>
125
                    <run-dependency>
125
                    <run-dependency>
126
                        <release-version>3</release-version>
126
                        <release-version>3</release-version>
127
                        <specification-version>1.41</specification-version>
127
                        <specification-version>1.53</specification-version>
128
                    </run-dependency>
128
                    </run-dependency>
129
                </dependency>
129
                </dependency>
130
                <dependency>
130
                <dependency>
Lines 141-148 Link Here
141
                    <build-prerequisite/>
141
                    <build-prerequisite/>
142
                    <compile-dependency/>
142
                    <compile-dependency/>
143
                    <run-dependency>
143
                    <run-dependency>
144
                        <release-version>2</release-version>
144
                        <release-version>3</release-version>
145
                        <specification-version>2.1</specification-version>
145
                        <specification-version>3.1</specification-version>
146
                    </run-dependency>
146
                    </run-dependency>
147
                </dependency>
147
                </dependency>
148
                <dependency>
148
                <dependency>
(-)a/websvc.manager/nbproject/project.xml (-1 / +1 lines)
Lines 99-105 Link Here
99
                    <compile-dependency/>
99
                    <compile-dependency/>
100
                    <run-dependency>
100
                    <run-dependency>
101
                        <release-version>3</release-version>
101
                        <release-version>3</release-version>
102
                        <specification-version>1.41</specification-version>
102
                        <specification-version>1.53</specification-version>
103
                    </run-dependency>
103
                    </run-dependency>
104
                </dependency>
104
                </dependency>
105
                <dependency>
105
                <dependency>
(-)a/websvc.rest/nbproject/project.xml (-1 / +1 lines)
Lines 115-121 Link Here
115
                    <compile-dependency/>
115
                    <compile-dependency/>
116
                    <run-dependency>
116
                    <run-dependency>
117
                        <release-version>3</release-version>
117
                        <release-version>3</release-version>
118
                        <specification-version>1.41</specification-version>
118
                        <specification-version>1.53</specification-version>
119
                    </run-dependency>
119
                    </run-dependency>
120
                </dependency>
120
                </dependency>
121
                <dependency>
121
                <dependency>
(-)a/websvc.saas.codegen.j2ee/nbproject/project.xml (-1 / +1 lines)
Lines 36-42 Link Here
36
                    <compile-dependency/>
36
                    <compile-dependency/>
37
                    <run-dependency>
37
                    <run-dependency>
38
                        <release-version>3</release-version>
38
                        <release-version>3</release-version>
39
                        <specification-version>1.41</specification-version>
39
                        <specification-version>1.53</specification-version>
40
                    </run-dependency>
40
                    </run-dependency>
41
                </dependency>
41
                </dependency>
42
                <dependency>
42
                <dependency>
(-)a/websvc.saas.codegen.java/nbproject/project.xml (-1 / +1 lines)
Lines 55-61 Link Here
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>3</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>1.41</specification-version>
58
                        <specification-version>1.53</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/websvc.saas.codegen/nbproject/project.xml (-3 / +3 lines)
Lines 47-53 Link Here
47
                    <compile-dependency/>
47
                    <compile-dependency/>
48
                    <run-dependency>
48
                    <run-dependency>
49
                        <release-version>3</release-version>
49
                        <release-version>3</release-version>
50
                        <specification-version>1.41</specification-version>
50
                        <specification-version>1.53</specification-version>
51
                    </run-dependency>
51
                    </run-dependency>
52
                </dependency>
52
                </dependency>
53
                <dependency>
53
                <dependency>
Lines 64-71 Link Here
64
                    <build-prerequisite/>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>2</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>2.1</specification-version>
68
                        <specification-version>3.1</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>
(-)a/xml.retriever/nbproject/project.xml (-2 / +2 lines)
Lines 80-87 Link Here
80
                    <build-prerequisite/>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
81
                    <compile-dependency/>
82
                    <run-dependency>
82
                    <run-dependency>
83
                        <release-version>2</release-version>
83
                        <release-version>3</release-version>
84
                        <specification-version>2.1</specification-version>
84
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
85
                    </run-dependency>
86
                </dependency>
86
                </dependency>
87
                <dependency>
87
                <dependency>
(-)a/xml.schema.completion/nbproject/project.xml (-2 / +2 lines)
Lines 72-79 Link Here
72
                    <build-prerequisite/>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>2</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>2.1</specification-version>
76
                        <specification-version>3.1</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
(-)a/xml.schema.ui.basic/nbproject/project.xml (-1 / +64 lines)
Lines 58-63 Link Here
58
                    </run-dependency>
58
                    </run-dependency>
59
                </dependency>
59
                </dependency>
60
                <dependency>
60
                <dependency>
61
                    <code-name-base>org.netbeans.api.progress</code-name-base>
62
                    <build-prerequisite/>
63
                    <compile-dependency/>
64
                    <run-dependency>
65
                        <release-version>1</release-version>
66
                        <specification-version>1.5.1</specification-version>
67
                    </run-dependency>
68
                </dependency>
69
                <dependency>
70
                    <code-name-base>org.netbeans.core.multiview</code-name-base>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
73
                    <run-dependency>
74
                        <release-version>1</release-version>
75
                        <specification-version>1.6.1</specification-version>
76
                    </run-dependency>
77
                </dependency>
78
                <dependency>
79
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
82
                    <run-dependency>
83
                        <release-version>3</release-version>
84
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
86
                </dependency>
87
                <dependency>
88
                    <code-name-base>org.netbeans.modules.projectapi</code-name-base>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
91
                    <run-dependency>
92
                        <release-version>1</release-version>
93
                        <specification-version>1.7.1</specification-version>
94
                    </run-dependency>
95
                </dependency>
96
                <dependency>
97
                    <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
98
                    <build-prerequisite/>
99
                    <compile-dependency/>
100
                    <run-dependency>
101
                        <release-version>1</release-version>
102
                        <specification-version>1.11.1.5</specification-version>
103
                    </run-dependency>
104
                </dependency>
105
                <dependency>
106
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
107
                    <build-prerequisite/>
108
                    <compile-dependency/>
109
                    <run-dependency>
110
                        <release-version>1</release-version>
111
                        <specification-version>1.5.1</specification-version>
112
                    </run-dependency>
113
                </dependency>
114
                <dependency>
61
                    <code-name-base>org.netbeans.modules.refactoring.api</code-name-base>
115
                    <code-name-base>org.netbeans.modules.refactoring.api</code-name-base>
62
                    <build-prerequisite/>
116
                    <build-prerequisite/>
63
                    <compile-dependency/>
117
                    <compile-dependency/>
Lines 230-236 Link Here
230
                        <specification-version>6.2.1</specification-version>
284
                        <specification-version>6.2.1</specification-version>
231
                    </run-dependency>
285
                    </run-dependency>
232
                </dependency>
286
                </dependency>
233
                </module-dependencies>
287
                <dependency>
288
                    <code-name-base>org.openidex.util</code-name-base>
289
                    <build-prerequisite/>
290
                    <compile-dependency/>
291
                    <run-dependency>
292
                        <release-version>3</release-version>
293
                        <specification-version>3.7.1</specification-version>
294
                    </run-dependency>
295
                </dependency>
296
            </module-dependencies>
234
            <friend-packages>
297
            <friend-packages>
235
                <friend>org.netbeans.modules.bpel.editors</friend>
298
                <friend>org.netbeans.modules.bpel.editors</friend>
236
                <friend>org.netbeans.modules.bpel.editors.api</friend>
299
                <friend>org.netbeans.modules.bpel.editors.api</friend>
(-)a/xml.schema/nbproject/project.xml (-2 / +2 lines)
Lines 89-96 Link Here
89
                    <build-prerequisite/>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
90
                    <compile-dependency/>
91
                    <run-dependency>
91
                    <run-dependency>
92
                        <release-version>2</release-version>
92
                        <release-version>3</release-version>
93
                        <specification-version>2.1</specification-version>
93
                        <specification-version>3.1</specification-version>
94
                    </run-dependency>
94
                    </run-dependency>
95
                </dependency>
95
                </dependency>
96
                <dependency>
96
                <dependency>
(-)a/xml.text/nbproject/project.xml (-3 / +12 lines)
Lines 82-88 Link Here
82
                    <compile-dependency/>
82
                    <compile-dependency/>
83
                    <run-dependency>
83
                    <run-dependency>
84
                        <release-version>3</release-version>
84
                        <release-version>3</release-version>
85
                        <specification-version>1.41</specification-version>
85
                        <specification-version>1.53</specification-version>
86
                    </run-dependency>
86
                    </run-dependency>
87
                </dependency>
87
                </dependency>
88
                <dependency>
88
                <dependency>
Lines 126-133 Link Here
126
                    <build-prerequisite/>
126
                    <build-prerequisite/>
127
                    <compile-dependency/>
127
                    <compile-dependency/>
128
                    <run-dependency>
128
                    <run-dependency>
129
                        <release-version>2</release-version>
129
                        <release-version>3</release-version>
130
                        <specification-version>2.1</specification-version>
130
                        <specification-version>3.1</specification-version>
131
                    </run-dependency>
131
                    </run-dependency>
132
                </dependency>
132
                </dependency>
133
                <dependency>
133
                <dependency>
Lines 276-281 Link Here
276
                        <specification-version>6.2</specification-version>
276
                        <specification-version>6.2</specification-version>
277
                    </run-dependency>
277
                    </run-dependency>
278
                </dependency>
278
                </dependency>
279
            <dependency>
280
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre65formatting</code-name-base>
281
                    <build-prerequisite/>
282
                    <compile-dependency/>
283
                    <run-dependency>
284
                        <release-version>0-1</release-version>
285
                        <specification-version>1.0</specification-version>
286
                    </run-dependency>
287
                </dependency>
279
            </module-dependencies>
288
            </module-dependencies>
280
            <test-dependencies>
289
            <test-dependencies>
281
                <test-type>
290
                <test-type>
(-)a/xml.xdm/nbproject/project.xml (-2 / +2 lines)
Lines 54-61 Link Here
54
                    <build-prerequisite/>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
55
                    <compile-dependency/>
56
                    <run-dependency>
56
                    <run-dependency>
57
                        <release-version>2</release-version>
57
                        <release-version>3</release-version>
58
                        <specification-version>2.1</specification-version>
58
                        <specification-version>3.1</specification-version>
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
(-)a/xml/nbproject/project.xml (-2 / +2 lines)
Lines 72-79 Link Here
72
                    <build-prerequisite/>
72
                    <build-prerequisite/>
73
                    <compile-dependency/>
73
                    <compile-dependency/>
74
                    <run-dependency>
74
                    <run-dependency>
75
                        <release-version>2</release-version>
75
                        <release-version>3</release-version>
76
                        <specification-version>2.1</specification-version>
76
                        <specification-version>3.1</specification-version>
77
                    </run-dependency>
77
                    </run-dependency>
78
                </dependency>
78
                </dependency>
79
                <dependency>
79
                <dependency>
(-)a/xslt.core/nbproject/project.xml (-2 / +2 lines)
Lines 80-87 Link Here
80
                    <build-prerequisite/>
80
                    <build-prerequisite/>
81
                    <compile-dependency/>
81
                    <compile-dependency/>
82
                    <run-dependency>
82
                    <run-dependency>
83
                        <release-version>2</release-version>
83
                        <release-version>3</release-version>
84
                        <specification-version>2.1</specification-version>
84
                        <specification-version>3.1</specification-version>
85
                    </run-dependency>
85
                    </run-dependency>
86
                </dependency>
86
                </dependency>
87
                <dependency>
87
                <dependency>
(-)a/xslt.tmap/nbproject/project.xml (-2 / +2 lines)
Lines 64-71 Link Here
64
                    <build-prerequisite/>
64
                    <build-prerequisite/>
65
                    <compile-dependency/>
65
                    <compile-dependency/>
66
                    <run-dependency>
66
                    <run-dependency>
67
                        <release-version>2</release-version>
67
                        <release-version>3</release-version>
68
                        <specification-version>2.1</specification-version>
68
                        <specification-version>3.1</specification-version>
69
                    </run-dependency>
69
                    </run-dependency>
70
                </dependency>
70
                </dependency>
71
                <dependency>
71
                <dependency>

Return to bug 189638