KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.text.Document JavaDoc;
22
23 import org.netbeans.api.gsf.ParserResult;
24
25
26 /**
27  * Implementations of this interface can be registered such that the formatter
28  * helps indent or reformat source code, or even determine where the caret should
29  * be placed on a newly created line.
30  *
31  * @author Tor Norbye
32  */

33 public interface Formatter {
34     /**
35      * The line at the given offset has been entered (e.g. a newline pressed);
36      * process it if you want. Some implementations may want to for example
37      * change capitalization of tokens on the line.
38      */

39
40     //void processLine(Document doc, int offset);
41

42     /**
43      * Compute the desired indent (in spaces) for the line containing the given offset.
44      */

45     int getLineIndent(Document JavaDoc doc, int offset, FormattingPreferences preferences);
46
47     /**
48      * Reformat the given portion of source code from startOffset to endOffset in the document.
49      * You may use the provided parse tree information, if available, to guide formatting decisions.
50      */

51     void reformat(Document JavaDoc doc, ParserResult result, FormattingPreferences preferences);
52
53     /**
54      * Reindent the source code. Adjusts indentation and strips trailing whitespace but
55      * does not otherwise change the code.
56      */

57     void reindent(Document JavaDoc doc, int startOffset, int endOffset, ParserResult result,
58         FormattingPreferences preferences);
59
60     /**
61      * Return the preferred size in characters of each indentation level for this language.
62      * This is not necessarily going to mean spaces since the IDE may use tabs to perform
63      * part of the indentation, but the number should reflect the number of spaces it would
64      * visually correspond to. For example, the Sun JDK Java style guidelines would return
65      * "4" here, and Ruby would return "2".
66      *
67      * @return The size in characters of each indentation level.
68      */

69     int indentSize();
70 }
71
Popular Tags