001 
002 /*
003  *  JavaDoq 1.0 - DOCUment JAVA In Source
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.javadoq.com>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package com.javadoq.jjtree.ast;
021 
022 import com.javadoq.jjtree.JJTreeParserConstants;
023 import com.javadoq.jjtree.Token;
024 
025 /**
026  * <p>An abstract base class for JJTree visitors to colorize JJTree node at token level.</p>
027  * 
028  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.javadoq.com" target="_blank">http://www.javadoq.com</a>
029  */
030 public abstract class HTMLColorizeVisitor extends TokenTransformVisitor implements JJTreeParserConstants
031 {
032     /**
033      * <p>Visits a token before transformation.</p>
034      * @param t The JJTree token to visit.
035      * @since 1.0
036      */
037     @Override
038     protected void start(Token t) {
039         switch (t.kind) {
040             case ABSTRACT:
041                 write("<font id=\"abstract\">");
042                 break;
043             case BOOLEAN:
044                 write("<font id=\"boolean\">");
045                 break;
046             case BREAK:
047                 write("<font id=\"break\">");
048                 break;
049             case BYTE:
050                 write("<font id=\"byte\">");
051                 break;
052             case CASE:
053                 write("<font id=\"case\">");
054                 break;
055             case CATCH:
056                 write("<font id=\"catch\">");
057                 break;
058             case CHAR:
059                 write("<font id=\"char\">");
060                 break;
061             case CLASS:
062                 write("<font id=\"class\">");
063                 break;
064             case CONST:
065                 write("<font id=\"const\">");
066                 break;
067             case CONTINUE:
068                 write("<font id=\"continue\">");
069                 break;
070             case _DEFAULT:
071                 write("<font id=\"default\">");
072                 break;
073             case DO:
074                 write("<font id=\"do\">");
075                 break;
076             case DOUBLE:
077                 write("<font id=\"double\">");
078                 break;
079             case ELSE:
080                 write("<font id=\"else\">");
081                 break;
082             case EXTENDS:
083                 write("<font id=\"extends\">");
084                 break;
085             case FALSE:
086                 write("<font id=\"false\">");
087                 break;
088             case FINAL:
089                 write("<font id=\"final\">");
090                 break;
091             case FINALLY:
092                 write("<font id=\"finally\">");
093                 break;
094             case FLOAT:
095                 write("<font id=\"float\">");
096                 break;
097             case FOR:
098                 write("<font id=\"for\">");
099                 break;
100             case GOTO:
101                 write("<font id=\"goto\">");
102                 break;
103             case IF:
104                 write("<font id=\"if\">");
105                 break;
106             case IMPLEMENTS:
107                 write("<font id=\"implements\">");
108                 break;
109             case IMPORT:
110                 write("<font id=\"import\">");
111                 break;
112             case INSTANCEOF:
113                 write("<font id=\"instanceof\">");
114                 break;
115             case INT:
116                 write("<font id=\"int\">");
117                 break;
118             case INTERFACE:
119                 write("<font id=\"interface\">");
120                 break;
121             case LONG:
122                 write("<font id=\"long\">");
123                 break;
124             case NATIVE:
125                 write("<font id=\"native\">");
126                 break;
127             case NEW:
128                 write("<font id=\"new\">");
129                 break;
130             case NULL:
131                 write("<font id=\"null\">");
132                 break;
133             case PACKAGE:
134                 write("<font id=\"package\">");
135                 break;
136             case PRIVATE:
137                 write("<font id=\"private\">");
138                 break;
139             case PROTECTED:
140                 write("<font id=\"protected\">");
141                 break;
142             case PUBLIC:
143                 write("<font id=\"public\">");
144                 break;
145             case RETURN:
146                 write("<font id=\"return\">");
147                 break;
148             case SHORT:
149                 write("<font id=\"short\">");
150                 break;
151             case STATIC:
152                 write("<font id=\"static\">");
153                 break;
154             case STRICTFP:
155                 write("<font id=\"strictfp\">");
156                 break;
157             case SUPER:
158                 write("<font id=\"super\">");
159                 break;
160             case SWITCH:
161                 write("<font id=\"switch\">");
162                 break;
163             case SYNCHRONIZED:
164                 write("<font id=\"synchronized\">");
165                 break;
166             case THIS:
167                 write("<font id=\"this\">");
168                 break;
169             case THROW:
170                 write("<font id=\"throw\">");
171                 break;
172             case THROWS:
173                 write("<font id=\"throws\">");
174                 break;
175             case TRANSIENT:
176                 write("<font id=\"transient\">");
177                 break;
178             case TRUE:
179                 write("<font id=\"true\">");
180                 break;
181             case TRY:
182                 write("<font id=\"try\">");
183                 break;
184             case VOID:
185                 write("<font id=\"void\">");
186                 break;
187             case VOLATILE:
188                 write("<font id=\"volatile\">");
189                 break;
190             case WHILE:
191                 write("<font id=\"while\">");
192                 break;
193             case CHARACTER_LITERAL:
194                 write("<font id=\"characer-literal\">");
195                 break;
196             case DECIMAL_LITERAL:
197                 write("<font id=\"decimal-literal\">");
198                 break;
199             case FLOATING_POINT_LITERAL:
200                 write("<font id=\"floating-point-literal\">");
201                 break;
202             case DECIMAL_FLOATING_POINT_LITERAL:
203                 write("<font id=\"decimal-floating-point-literal\">");
204                 break;
205             case DECIMAL_EXPONENT:
206                 write("<font id=\"decimal-exponent\">");
207                 break;
208             case HEXADECIMAL_FLOATING_POINT_LITERAL:
209                 write("<font id=\"hexa-decimal-floating-point-literal\">");
210                 break;
211             case HEXADECIMAL_EXPONENT:
212                 write("<font id=\"hexa-decimal-exponent\">");
213                 break;
214             case HEX_LITERAL:
215                 write("<font id=\"hex-literal\">");
216                 break;
217             case INTEGER_LITERAL:
218                 write("<font id=\"integer-literal\">");
219                 break;
220             case OCTAL_LITERAL:
221                 write("<font id=\"octal-literal\">");
222                 break;
223             case STRING_LITERAL:
224                 write("<font id=\"string-literal\">");
225                 break;
226             case SINGLE_LINE_COMMENT:
227                 write("<font id=\"single-line-comment\">");
228                 break;
229             case FORMAL_COMMENT:
230                 write("<font id=\"formal-comment\">");
231                 break;
232             case MULTI_LINE_COMMENT:
233                 write("<font id=\"multi-line-comment\">");
234                 break;
235             case _LOOKAHEAD:
236                 write("<font id=\"lookahead\">");
237                 break;
238             case _IGNORE_CASE:
239                 write("<font id=\"ignore-case\">");
240                 break;
241             case _PARSER_BEGIN:
242                 write("<font id=\"parser-begin\">");
243                 break;
244             case _PARSER_END:
245                 write("<font id=\"parser-end\">");
246                 break;
247             case _JAVACODE:
248                 write("<font id=\"javacode\">");
249                 break;
250             case _TOKEN:
251                 write("<font id=\"token\">");
252                 break;
253             case _SPECIAL_TOKEN:
254                 write("<font id=\"special-token\">");
255                 break;
256             case _MORE:
257                 write("<font id=\"more\">");
258                 break;
259             case _SKIP:
260                 write("<font id=\"skip\">");
261                 break;
262             case _TOKEN_MGR_DECLS:
263                 write("<font id=\"token-mgr-decls\">");
264                 break;
265             case _EOF:
266                 write("<font id=\"eof\">");
267                 break;
268             case LPAREN:
269                 write("<font id=\"left-paren\">");
270                 break;
271             case RPAREN:
272                 write("<font id=\"right-paren\">");
273                 break;
274             case LBRACE:
275                 write("<font id=\"left-brace\">");
276                 break;
277             case RBRACE:
278                 write("<font id=\"right-brace\">");
279                 break;
280             case LBRACKET:
281                 write("<font id=\"left-bracket\">");
282                 break;
283             case RBRACKET:
284                 write("<font id=\"right-bracket\">");
285                 break;
286             case SEMICOLON:
287                 write("<font id=\"semi-colon\">");
288                 break;
289             case COMMA:
290                 write("<font id=\"comma\">");
291                 break;
292             case DOT:
293                 write("<font id=\"dot\">");
294                 break;
295             case AT:
296                 write("<font id=\"at\">");
297                 break;
298             case ASSIGN:
299                 write("<font id=\"assign\">");
300                 break;
301             case LT:
302                 write("<font id=\"lt\">");
303                 break;
304             case BANG:
305                 write("<font id=\"bang\">");
306                 break;
307             case TILDE:
308                 write("<font id=\"tilde\">");
309                 break;
310             case HOOK:
311                 write("<font id=\"hook\">");
312                 break;
313             case COLON:
314                 write("<font id=\"colon\">");
315                 break;
316             case EQ:
317                 write("<font id=\"eq\">");
318                 break;
319             case LE:
320                 write("<font id=\"le\">");
321                 break;
322             case GE:
323                 write("<font id=\"ge\">");
324                 break;
325             case NE:
326                 write("<font id=\"ne\">");
327                 break;
328             case SC_OR:
329                 write("<font id=\"sc-or\">");
330                 break;
331             case SC_AND:
332                 write("<font id=\"sc-and\">");
333                 break;
334             case INCR:
335                 write("<font id=\"incr\">");
336                 break;
337             case DECR:
338                 write("<font id=\"decr\">");
339                 break;
340             case PLUS:
341                 write("<font id=\"plus\">");
342                 break;
343             case MINUS:
344                 write("<font id=\"minus\">");
345                 break;
346             case STAR:
347                 write("<font id=\"star\">");
348                 break;
349             case SLASH:
350                 write("<font id=\"slash\">");
351                 break;
352             case BIT_AND:
353                 write("<font id=\"bit-and\">");
354                 break;
355             case BIT_OR:
356                 write("<font id=\"bit-or\">");
357                 break;
358             case XOR:
359                 write("<font id=\"xor\">");
360                 break;
361             case REM:
362                 write("<font id=\"rem\">");
363                 break;
364             case PLUSASSIGN:
365                 write("<font id=\"plus-assign\">");
366                 break;
367             case MINUSASSIGN:
368                 write("<font id=\"minus-assign\">");
369                 break;
370             case STARASSIGN:
371                 write("<font id=\"star-assign\">");
372                 break;
373             case SLASHASSIGN:
374                 write("<font id=\"slash-assign\">");
375                 break;
376             case ANDASSIGN:
377                 write("<font id=\"and-assign\">");
378                 break;
379             case ORASSIGN:
380                 write("<font id=\"or-assign\">");
381                 break;
382             case XORASSIGN:
383                 write("<font id=\"xor-assign\">");
384                 break;
385             case REMASSIGN:
386                 write("<font id=\"rem-assign\">");
387                 break;
388             case ELLIPSIS:
389                 write("<font id=\"ellipsis\">");
390                 break;
391             case RUNSIGNEDSHIFT:
392                 write("<font id=\"right-unsigned-shift\">");
393                 break;
394             case RSIGNEDSHIFT:
395                 write("<font id=\"right-signed-shift\">");
396                 break;
397             case GT:
398                 write("<font id=\"gt\">");
399                 break;
400             case IDENTIFIER:
401                 write("<font id=\"identifier\">");
402                 break;
403             case LETTER:
404                 write("<font id=\"letter\">");
405                 break;
406             case PART_LETTER:
407                 write("<font id=\"part-letter\">");
408                 break;
409             default:
410                 break;
411         }
412     }
413 
414     /**
415      * <p>Visits a token after transformation.</p>
416      * @param t The JJTree token to visit.
417      * @since 1.0
418      */
419     @Override
420     protected void close(Token t) {
421         switch (t.kind) {
422             case ABSTRACT:
423             case BOOLEAN:
424             case BREAK:
425             case BYTE:
426             case CASE:
427             case CATCH:
428             case CHAR:
429             case CLASS:
430             case CONST:
431             case CONTINUE:
432             case _DEFAULT:
433             case DO:
434             case DOUBLE:
435             case ELSE:
436             case EXTENDS:
437             case FALSE:
438             case FINAL:
439             case FINALLY:
440             case FLOAT:
441             case FOR:
442             case GOTO:
443             case IF:
444             case IMPLEMENTS:
445             case IMPORT:
446             case INSTANCEOF:
447             case INT:
448             case INTERFACE:
449             case LONG:
450             case NATIVE:
451             case NEW:
452             case NULL:
453             case PACKAGE:
454             case PRIVATE:
455             case PROTECTED:
456             case PUBLIC:
457             case RETURN:
458             case SHORT:
459             case STATIC:
460             case SUPER:
461             case SWITCH:
462             case SYNCHRONIZED:
463             case THIS:
464             case THROW:
465             case THROWS:
466             case TRANSIENT:
467             case TRUE:
468             case TRY:
469             case VOID:
470             case VOLATILE:
471             case WHILE:
472             case STRICTFP:
473             case DECIMAL_LITERAL:
474             case CHARACTER_LITERAL:
475             case FLOATING_POINT_LITERAL:
476             case DECIMAL_FLOATING_POINT_LITERAL:
477             case DECIMAL_EXPONENT:
478             case HEXADECIMAL_FLOATING_POINT_LITERAL:
479             case HEXADECIMAL_EXPONENT:
480             case HEX_LITERAL:
481             case INTEGER_LITERAL:
482             case OCTAL_LITERAL:
483             case STRING_LITERAL:
484             case SINGLE_LINE_COMMENT:
485             case FORMAL_COMMENT:
486             case MULTI_LINE_COMMENT:
487             case _LOOKAHEAD:
488             case _IGNORE_CASE:
489             case _PARSER_BEGIN:
490             case _PARSER_END:
491             case _JAVACODE:
492             case _TOKEN:
493             case _SPECIAL_TOKEN:
494             case _MORE:
495             case _SKIP:
496             case _TOKEN_MGR_DECLS:
497             case _EOF:
498             case LPAREN:
499             case RPAREN:
500             case LBRACE:
501             case RBRACE:
502             case LBRACKET:
503             case RBRACKET:
504             case SEMICOLON:
505             case COMMA:
506             case DOT:
507             case AT:
508             case ASSIGN:
509             case LT:
510             case BANG:
511             case TILDE:
512             case HOOK:
513             case COLON:
514             case EQ:
515             case LE:
516             case GE:
517             case NE:
518             case SC_OR:
519             case SC_AND:
520             case INCR:
521             case DECR:
522             case PLUS:
523             case MINUS:
524             case STAR:
525             case SLASH:
526             case BIT_AND:
527             case BIT_OR:
528             case XOR:
529             case REM:
530             case PLUSASSIGN:
531             case MINUSASSIGN:
532             case STARASSIGN:
533             case SLASHASSIGN:
534             case ANDASSIGN:
535             case ORASSIGN:
536             case XORASSIGN:
537             case REMASSIGN:
538             case ELLIPSIS:
539             case RUNSIGNEDSHIFT:
540             case RSIGNEDSHIFT:
541             case GT:
542             case IDENTIFIER:
543             case LETTER:
544             case PART_LETTER:
545                 write("</font>");
546             default:
547                 break;
548         }
549     }
550 }