equal
deleted
inserted
replaced
20 * |
20 * |
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
23 * have any questions. |
23 * have any questions. |
24 */ |
24 */ |
|
25 |
25 package com.sun.codemodel.internal; |
26 package com.sun.codemodel.internal; |
26 |
27 |
27 import java.util.ArrayList; |
28 import java.util.ArrayList; |
28 import java.util.Collection; |
29 import java.util.Collection; |
29 import java.util.Iterator; |
30 import java.util.Iterator; |
75 /** |
76 /** |
76 * Writes this part into the formatter by using the specified indentation. |
77 * Writes this part into the formatter by using the specified indentation. |
77 */ |
78 */ |
78 protected void format( JFormatter f, String indent ) { |
79 protected void format( JFormatter f, String indent ) { |
79 if(!f.isPrinting()) { |
80 if(!f.isPrinting()) { |
80 // quickly pass the types to JFormatter |
81 // quickly pass the types to JFormatter, as that's all we care. |
|
82 // we don't need to worry about the exact formatting of text. |
81 for( Object o : this ) |
83 for( Object o : this ) |
82 if(o instanceof JClass) |
84 if(o instanceof JClass) |
83 f.g((JClass)o); |
85 f.g((JClass)o); |
84 return; |
86 return; |
85 } |
87 } |
95 int idx; |
97 int idx; |
96 String s = (String)o; |
98 String s = (String)o; |
97 while( (idx=s.indexOf('\n'))!=-1 ) { |
99 while( (idx=s.indexOf('\n'))!=-1 ) { |
98 String line = s.substring(0,idx); |
100 String line = s.substring(0,idx); |
99 if(line.length()>0) |
101 if(line.length()>0) |
100 f.p(line); |
102 f.p(escape(line)); |
101 s = s.substring(idx+1); |
103 s = s.substring(idx+1); |
102 f.nl().p(indent); |
104 f.nl().p(indent); |
103 } |
105 } |
104 if(s.length()!=0) |
106 if(s.length()!=0) |
105 f.p(s); |
107 f.p(escape(s)); |
106 } else |
108 } else |
107 if(o instanceof JClass) { |
109 if(o instanceof JClass) { |
108 // TODO: this doesn't print the parameterized type properly |
110 // TODO: this doesn't print the parameterized type properly |
109 ((JClass)o).printLink(f); |
111 ((JClass)o).printLink(f); |
110 } else |
112 } else |
115 } |
117 } |
116 |
118 |
117 if(!isEmpty()) |
119 if(!isEmpty()) |
118 f.nl(); |
120 f.nl(); |
119 } |
121 } |
|
122 |
|
123 /** |
|
124 * Escapes the appearance of the comment terminator. |
|
125 */ |
|
126 private String escape(String s) { |
|
127 while(true) { |
|
128 int idx = s.indexOf("*/"); |
|
129 if(idx <0) return s; |
|
130 |
|
131 s = s.substring(0,idx+1)+"<!---->"+s.substring(idx+1); |
|
132 } |
|
133 } |
120 } |
134 } |