1 /*
  2  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package jdk.incubator.code.tools.renderer;
 27 
 28 /**
 29  * Created by gfrost
 30  */
 31 public class CommonRenderer<T extends CommonRenderer<T>> extends TextRenderer<T> {
 32 
 33     public CommonRenderer() {
 34     }
 35 
 36     public CommonRenderer(TextRenderer<?> renderer) {
 37         super(renderer);
 38     }
 39 
 40     public T semicolon() {
 41         return op(";");
 42     }
 43 
 44     public T comma() {
 45         return op(",");
 46     }
 47 
 48     public T commaSeparatedList() {
 49         return startList();
 50     }
 51 
 52     public T commaSeparator() {
 53         if (!first()) {
 54             comma().space();
 55         }
 56         return self();
 57     }
 58 
 59     public T commaSpaceSeparatedList() {
 60         return startList();
 61     }
 62 
 63     public T commaSpaceSeparator() {
 64         if (!first()) {
 65             comma().space();
 66         }
 67         return self();
 68     }
 69 
 70     public T spaceSeparatedList() {
 71         return startList();
 72     }
 73 
 74     public T spaceSeparator() {
 75         if (!first()) {
 76             space();
 77         }
 78         return self();
 79     }
 80 
 81     public T newlineSeparatedList() {
 82         return startList();
 83     }
 84 
 85     public T newlineSeparator() {
 86         if (!first()) {
 87             nl();
 88         }
 89         return self();
 90     }
 91 
 92     public T semicolonSeparatedList() {
 93         return startList();
 94     }
 95 
 96     public T semicolonSeparator() {
 97         if (!first()) {
 98             semicolon();
 99         }
100         return self();
101     }
102 
103     public T semicolonSpaceSeparatedList() {
104         return startList();
105     }
106 
107     public T semicolonSpaceSeparator() {
108         if (!first()) {
109             semicolon().space();
110         }
111         return self();
112     }
113 
114     public T dot() {
115         return op(".");
116     }
117 
118 
119     public T equal() {
120         return op("=");
121     }
122 
123 
124     public T plusplus() {
125         return op("++");
126     }
127 
128 
129     public T minusminus() {
130         return op("--");
131     }
132 
133     public T lineComment(String line) {
134         return op("//").space().comment(line).nl();
135     }
136 
137 
138     public T blockComment(String block) {
139         return op("/*").nl().comment(block).nl().op("*/").nl();
140     }
141 
142     public T newKeyword() {
143         return keyword("new");
144     }
145 
146 
147     public T staticKeyword() {
148         return keyword("static");
149     }
150 
151 
152     public T constKeyword() {
153         return keyword("const");
154     }
155 
156     public T ifKeyword() {
157         return keyword("if");
158 
159     }
160 
161 
162     public T whileKeyword() {
163         return keyword("while");
164     }
165 
166 
167     public T breakKeyword() {
168         return keyword("break");
169 
170     }
171 
172 
173     public T continueKeyword() {
174         return keyword("continue");
175     }
176 
177 
178     public T query() {
179         return op("?");
180     }
181 
182 
183     public T colon() {
184         return op(":");
185     }
186 
187 
188     public T nullKeyword() {
189         return keyword("null");
190 
191     }
192 
193 
194     public T elseKeyword() {
195         return keyword("else");
196     }
197 
198 
199     public T returnKeyword() {
200         return keyword("return");
201     }
202 
203 
204     public T switchKeyword() {
205         return keyword("switch");
206     }
207 
208 
209     public T caseKeyword() {
210         return keyword("case");
211     }
212 
213 
214     public T defaultKeyword() {
215         return keyword("default");
216     }
217 
218     public T doKeyword() {
219         return keyword("do");
220     }
221 
222     public T forKeyword() {
223         return keyword("for");
224     }
225 
226     public T ampersand() {
227         return op("&");
228     }
229 
230     public T braced(NestedRendererSAM<T> nb) {
231         return nb.build(obrace().nl().in()).out().cbrace().self();
232     }
233 
234     public T osbrace() {
235         return open("[");
236     }
237 
238 
239     public T csbrace() {
240         return close("]");
241     }
242 
243 
244     public T parenthesized(NestedRendererSAM<T> nb) {
245         return nb.build(oparen().in()).out().cparen().self();
246     }
247 
248     public T underscore() {
249         return op("_");
250     }
251 
252     public T oparen() {
253         return open("(");
254     }
255 
256     public T cparen() {
257         return close(")");
258     }
259 
260     public T obrace() {
261         return open("{");
262     }
263 
264     public T cbrace() {
265         return close("}");
266     }
267 
268     public T at() {
269         return op("@").self();
270     }
271 
272     public T caret() {
273         return op("^").self();
274     }
275 
276     public T percent() {
277         return op("%").self();
278     }
279 
280     public T pipe() {
281         return op("|").self();
282     }
283 
284     public T rarrow() {
285         return op("->").self();
286     }
287 
288     public T larrow() {
289         return op("<-").self();
290     }
291 
292     public T lt() {
293         return op("<").self();
294     }
295 
296     public T gt() {
297         return op(">").self();
298     }
299 
300     public T asterisk() {
301         return op("*").self();
302     }
303 }