|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
NodePrinter.java | 72.2% | 75% | 75% | 74.1% |
|
1 |
/*
|
|
2 |
* Copyright (c) 2001-2003 The XDoclet team
|
|
3 |
* All rights reserved.
|
|
4 |
*/
|
|
5 |
package xjavadoc;
|
|
6 |
|
|
7 |
import java.io.PrintWriter;
|
|
8 |
import java.io.Writer;
|
|
9 |
|
|
10 |
/**
|
|
11 |
* This visitor prints a node and all its children to a PrintWriter. The
|
|
12 |
* PrintWriter must be passed to the data variable in the jjtAccept method of
|
|
13 |
* the node from which printing should start. T print a whole class, call
|
|
14 |
* compilationUnit.jjtAccept( new PrintVisitor(), System.out );
|
|
15 |
*
|
|
16 |
* @author Aslak Hellesøy
|
|
17 |
* @created 8. januar 2002
|
|
18 |
* @todo replace PrintWriter with PrintWriter and remove the
|
|
19 |
* addUnicodeEscapes()
|
|
20 |
*/
|
|
21 |
public final class NodePrinter |
|
22 |
{ |
|
23 |
|
|
24 |
/**
|
|
25 |
* Describe what the method does
|
|
26 |
*
|
|
27 |
* @param node Describe what the parameter does
|
|
28 |
* @param o
|
|
29 |
* @todo-javadoc Write javadocs for method parameter
|
|
30 |
* @todo-javadoc Write javadocs for method
|
|
31 |
* @todo-javadoc Write javadocs for method parameter
|
|
32 |
* @todo-javadoc Write javadocs for method parameter
|
|
33 |
* @todo-javadoc Write javadocs for return value
|
|
34 |
*/
|
|
35 | 2448 |
public static void print( SimpleNode node, Writer o ) |
36 |
{ |
|
37 | 2448 |
PrintWriter out = new PrintWriter( o );
|
38 | 2448 |
Token t1 = node.getFirstToken(); |
39 | 2448 |
Token t = new Token();
|
40 |
|
|
41 | 2448 |
t.next = t1; |
42 |
|
|
43 | 2448 |
SimpleNode n; |
44 |
|
|
45 | 2448 |
for( int ord = 0; ord < node.jjtGetNumChildren(); ord++ ) |
46 |
{ |
|
47 | 2442 |
n = ( SimpleNode ) node.jjtGetChild( ord ); |
48 | 2442 |
while( true ) |
49 |
{ |
|
50 | 2839 |
t = t.next; |
51 | 2839 |
if( t == n.getFirstToken() )
|
52 |
{ |
|
53 | 2442 |
break;
|
54 |
} |
|
55 | 397 |
print( t, out ); |
56 |
} |
|
57 | 2442 |
print( n, out ); |
58 | 2442 |
t = n.getLastToken(); |
59 |
} |
|
60 |
|
|
61 | 2448 |
while( t != node.getLastToken() && t != null ) |
62 |
{ |
|
63 | 802 |
t = t.next; |
64 | 802 |
if( t != null ) |
65 |
{ |
|
66 | 802 |
print( t, out ); |
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
/**
|
|
72 |
* Describe what the method does
|
|
73 |
*
|
|
74 |
* @param t Describe what the parameter does
|
|
75 |
* @param out Describe what the parameter does
|
|
76 |
* @todo-javadoc Write javadocs for method
|
|
77 |
* @todo-javadoc Write javadocs for method parameter
|
|
78 |
* @todo-javadoc Write javadocs for method parameter
|
|
79 |
*/
|
|
80 | 1199 |
private final static void print( Token t, PrintWriter out ) |
81 |
{ |
|
82 | 1199 |
Token tt = t.specialToken; |
83 |
|
|
84 | 1199 |
if( tt != null ) |
85 |
{ |
|
86 | 706 |
while( tt.specialToken != null ) |
87 |
{ |
|
88 | 880 |
tt = tt.specialToken; |
89 |
} |
|
90 | 706 |
while( tt != null ) |
91 |
{ |
|
92 | 1588 |
out.print( addUnicodeEscapes( tt.image ) ); |
93 |
// out.print(tt.image);
|
|
94 | 1588 |
tt = tt.next; |
95 |
} |
|
96 |
} |
|
97 | 1199 |
out.print( addUnicodeEscapes( t.image ) ); |
98 |
// out.print(t.image);
|
|
99 |
} |
|
100 |
|
|
101 |
/**
|
|
102 |
* Describe the method
|
|
103 |
*
|
|
104 |
* @param str Describe the method parameter
|
|
105 |
* @return Describe the return value
|
|
106 |
* @todo-javadoc Describe the method
|
|
107 |
* @todo-javadoc Describe the method parameter
|
|
108 |
* @todo-javadoc Write javadocs for return value
|
|
109 |
*/
|
|
110 | 2787 |
private final static String addUnicodeEscapes( final String str ) |
111 |
{ |
|
112 | 2787 |
return str;
|
113 |
} |
|
114 |
|
|
115 |
/**
|
|
116 |
* Describe the method
|
|
117 |
*
|
|
118 |
* @param str Describe the method parameter
|
|
119 |
* @return Describe the return value
|
|
120 |
* @todo-javadoc Describe the method
|
|
121 |
* @todo-javadoc Describe the method parameter
|
|
122 |
* @todo-javadoc Write javadocs for return value
|
|
123 |
*/
|
|
124 | 0 |
protected String addUnicodeEscapesOld( String str )
|
125 |
{ |
|
126 | 0 |
String retval = "";
|
127 | 0 |
char ch;
|
128 |
|
|
129 | 0 |
for( int i = 0; i < str.length(); i++ ) |
130 |
{ |
|
131 | 0 |
ch = str.charAt( i ); |
132 | 0 |
if( ( ch < 0x20 || ch > 0x7e ) &&
|
133 |
ch != '\t' && ch != '\n' && ch != '\r' && ch != '\f' ) |
|
134 |
{ |
|
135 | 0 |
String s = "0000" + Integer.toString( ch, 16 );
|
136 |
|
|
137 | 0 |
retval += "\\u" + s.substring( s.length() - 4, s.length() );
|
138 |
} |
|
139 |
else
|
|
140 |
{ |
|
141 | 0 |
retval += ch; |
142 |
} |
|
143 |
} |
|
144 | 0 |
return retval;
|
145 |
} |
|
146 |
|
|
147 |
} |
|
148 |
|
|