KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > gsf > BracketCompletion


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.api.gsf;
20
21 import java.util.List JavaDoc;
22 import javax.swing.text.BadLocationException JavaDoc;
23 import javax.swing.text.Caret JavaDoc;
24 import javax.swing.text.Document JavaDoc;
25 import org.netbeans.api.gsf.OffsetRange;
26 import org.netbeans.api.gsf.annotations.NonNull;
27
28
29 /**
30  * Interface that a plugin can implement to assist with bracket completion during
31  * editing.
32  *
33  * @todo Rename Pair Completion? Or perhaps PairMatcher?
34  *
35  * @author Tor Norbye
36  */

37 public interface BracketCompletion {
38     /**
39      * (Based on BracketCompletion class in NetBeans' java editor support)
40      *
41      * A hook method called after a character was inserted into the
42      * document. The function checks for special characters for
43      * completion ()[]'"{} and other conditions and optionally performs
44      * changes to the doc and or caret (complets braces, moves caret,
45      * etc.)
46      *
47      * Return true if the character was already inserted (and the IDE
48      * should not further insert anything)
49      *
50      * XXX Fix javadoc.
51      */

52     boolean beforeCharInserted(Document JavaDoc doc, int caretOffset, Caret JavaDoc caret, char ch)
53         throws BadLocationException JavaDoc;
54
55     /** @todo Rip out the boolean return value? What does it mean? */
56     boolean afterCharInserted(Document JavaDoc doc, int caretOffset, Caret JavaDoc caret, char ch)
57         throws BadLocationException JavaDoc;
58
59     /**
60      * (Based on BracketCompletion class in NetBeans' java editor support)
61      *
62      * Hook called after a character *ch* was backspace-deleted from
63      * *doc*. The function possibly removes bracket or quote pair if
64      * appropriate.
65      * @todo Document why both caretOffset and caret is passed in!
66      * Return the new offset, or -1
67      */

68
69     /** @todo Split into before and after? */
70     public boolean charBackspaced(Document JavaDoc doc, int caretOffset, Caret JavaDoc caret, char ch)
71         throws BadLocationException JavaDoc;
72
73     /**
74      * A line break is being called. Return -1 to do nothing.
75      * If you want to modify the document first, you can do that, and then
76      * return the new offset to assign the caret to AFTER the newline has been
77      * inserted.
78      *
79      * @todo rip out return value
80      * @todo Document why both caretOffset and caret is passed in!
81      */

82     int beforeBreak(Document JavaDoc doc, int caretOffset, Caret JavaDoc caret)
83         throws BadLocationException JavaDoc;
84
85     /**
86      * Compute a range matching the caret position. If no eligible range
87      * is found, return {@link OffsetRange.NONE}.
88      */

89     @NonNull
90     OffsetRange findMatching(Document JavaDoc doc, int caretOffset);
91     
92     /**
93      * Compute set of selection ranges for the given parse tree (around the given offset),
94      * in leaf-to-root order.
95      */

96     @NonNull
97     List JavaDoc<OffsetRange> findLogicalRanges(CompilationInfo info, int caretOffset);
98 }
99
Popular Tags