View Javadoc
1   package net.sourceforge.jenesis4java;
2   
3   /*
4    * #%L
5    * Jenesis 4 Java Code Generator
6    * %%
7    * Copyright (C) 2000 - 2015 jenesis4java
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * #L%
23   */
24  
25  import java.util.List;
26  
27  /**
28   * Copyright (C) 2008, 2010 Richard van Nieuwenhoven - ritchie [at] gmx [dot] at
29   * Copyright (C) 2000, 2001 Paul Cody Johnston - pcj@inxar.org <br>
30   * This file is part of Jenesis4java. Jenesis4java is free software: you can
31   * redistribute it and/or modify it under the terms of the GNU Lesser General
32   * Public License as published by the Free Software Foundation, either version 3
33   * of the License, or (at your option) any later version.<br>
34   * Jenesis4java is distributed in the hope that it will be useful, but WITHOUT
35   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
36   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
37   * details.<br>
38   * You should have received a copy of the GNU Lesser General Public License
39   * along with Jenesis4java. If not, see <http://www.gnu.org/licenses/>.
40   */
41  /**
42   * The {@code CodeWriter} is the object to which code is rendered. All methods
43   * that add content to the {@code CodeWriter} should return the same object
44   * passed to them though the {@code toCode()} method. This supports a coding
45   * style analogous to the {@code StringBuffer} class.
46   */
47  public interface CodeWriter {
48  
49      /**
50       * Decrements the tab and makes sure, a new line is started.
51       */
52      CodeWriter dedentLine();
53  
54      /**
55       * Returns the current number of characters in the current line. It does not
56       * take the indent into account. Therefore, only the write methods and the
57       * space method increment the column counter.
58       */
59      int getColumnNumber();
60  
61      /**
62       * gets the context compilation unit.
63       */
64      CompilationUnit getCompilationUnit();
65  
66      /**
67       * Returns the current number of indentation levels.
68       */
69      int getIndentNumber();
70  
71      /**
72       * Returns the number of lines of the current document.
73       */
74      int getLineNumber();
75  
76      /**
77       * Increments the tab and ensures that current line is empty.
78       */
79      CodeWriter indentLine();
80  
81      /**
82       * Returns true if no characters have been written since the last call of
83       * newLine().
84       */
85      boolean isLineNew();
86  
87      /**
88       * Starts a new line, if characters are present on the current line.
89       */
90      CodeWriter ensureNewLine();
91  
92      /**
93       * Adds a the newLine string according to
94       * {@code System.getProperty("line.separator")} and the line is padded with
95       * the n tab characters where n is the number returned by
96       * {@code getIndentNumber()}.
97       */
98      CodeWriter newLine();
99  
100     /**
101      * This method allows those codeable objects to inject a comment without
102      * interrupting the line-by-line code itself. For example, if an expression
103      * wants to express a comment, it cannot do it until the end of the line.
104      * Before the newline is called, all comments given to the code writer will
105      * be written.
106      */
107     CodeWriter queue(Comment comment);
108 
109     /**
110      * Resets the tab counter to zero and calls the newLine() method.
111      */
112     CodeWriter resetLine();
113 
114     /**
115      * sets the context compilation unit.
116      */
117     void setCompilationUnit(CompilationUnit mCompilationUnit);
118 
119     /**
120      * Writes a single space.
121      */
122     CodeWriter space();
123 
124     /**
125      * Writes a boolean.
126      */
127     CodeWriter write(boolean b);
128 
129     /**
130      * Writes a single character.
131      */
132     CodeWriter write(char c);
133 
134     /**
135      * Writes an array of characters.
136      */
137     CodeWriter write(char[] chars);
138 
139     /**
140      * Writes an array of characters starting at the offset with total length
141      * len.
142      */
143     CodeWriter write(char[] chars, int off, int len);
144 
145     /**
146      * Instead of calling the {@code Object.toString()} method, the
147      * {@code Object.toCode(CodeWriter)} method is invoked with {@code this} as
148      * the argument.
149      */
150     CodeWriter write(Codeable codeable);
151 
152     /**
153      * Iterates the array and sends each element to {@code write(Codeable)} .
154      */
155     CodeWriter write(Codeable[] codeables);
156 
157     /**
158      * Writes a double.
159      */
160     CodeWriter write(double d);
161 
162     /**
163      * Writes a float.
164      */
165     CodeWriter write(float f);
166 
167     /**
168      * Writes an integer.
169      */
170     CodeWriter write(int i);
171 
172     /**
173      * Iterates the array and sends each element to {@code write(Codeable)} .
174      */
175     CodeWriter write(List<? extends Codeable> codeables);
176 
177     /**
178      * Writes an object.
179      */
180     CodeWriter write(Object o);
181 
182     /**
183      * Writes a string.
184      */
185     CodeWriter write(String s);
186 
187 }