Produced by Araxis Merge on 9/25/2018 2:13:08 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\tools\javac\tree | Pretty.java | Mon Jan 22 14:47:06 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\tools\javac\tree | Pretty.java | Wed Sep 12 16:50:20 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 2814 |
Changed | 2 | 4 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 199 9, 2013, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package co m.sun.tool s.javac.tr ee; | |
27 | ||
28 | import jav a.io.*; | |
29 | ||
30 | import com .sun.sourc e.tree.Mem berReferen ceTree.Ref erenceMode ; | |
31 | import com .sun.tools .javac.cod e.*; | |
32 | import com .sun.tools .javac.tre e.JCTree.* ; | |
33 | import com .sun.tools .javac.uti l.*; | |
34 | import com .sun.tools .javac.uti l.List; | |
35 | import sta tic com.su n.tools.ja vac.code.F lags.*; | |
36 | import sta tic com.su n.tools.ja vac.code.F lags.ANNOT ATION; | |
37 | import sta tic com.su n.tools.ja vac.tree.J CTree.Tag. *; | |
38 | ||
39 | /** Prints out a tre e as an in dented Jav a source p rogram. | |
40 | * | |
41 | * <p><b> This is NO T part of any suppor ted API. | |
42 | * If you write cod e that dep ends on th is, you do so at you r own risk . | |
43 | * This c ode and it s internal interface s are subj ect to cha nge or | |
44 | * deleti on without notice.</ b> | |
45 | */ | |
46 | public cla ss Pretty extends JC Tree.Visit or { | |
47 | ||
48 | public Pretty(Wr iter out, boolean so urceOutput ) { | |
49 | th is.out = o ut; | |
50 | th is.sourceO utput = so urceOutput ; | |
51 | } | |
52 | ||
53 | /** Se t when we are produc ing source output. If we're n ot | |
54 | * pr oducing so urce outpu t, we can sometimes give more detail in | |
55 | * th e output e ven though that deta il would n ot be vali d java | |
56 | * so urce. | |
57 | */ | |
58 | privat e final bo olean sour ceOutput; | |
59 | ||
60 | /** Th e output s tream on w hich trees are print ed. | |
61 | */ | |
62 | Writer out; | |
63 | ||
64 | /** In dentation width (can be reassi gned from outside). | |
65 | */ | |
66 | public int width = 4; | |
67 | ||
68 | /** Th e current left margi n. | |
69 | */ | |
70 | int lm argin = 0; | |
71 | ||
72 | /** Th e enclosin g class na me. | |
73 | */ | |
74 | Name e nclClassNa me; | |
75 | ||
76 | /** A table mapp ing trees to their d ocumentati on comment s | |
77 | * (c an be null ) | |
78 | */ | |
79 | DocCom mentTable docComment s = null; | |
80 | ||
81 | /** | |
82 | * A s tring sequ ence to be used when Pretty ou tput shoul d be const rained | |
83 | * to fit into a given siz e | |
84 | */ | |
85 | privat e final st atic Strin g trimSequ ence = "[. ..]"; | |
86 | ||
87 | /** | |
88 | * Max number of chars to be generat ed when ou tput shoul d fit into a single line | |
89 | */ | |
90 | privat e final st atic int P REFERRED_L ENGTH = 20 ; | |
91 | ||
92 | /** Al ign code t o be inden ted to lef t margin. | |
93 | */ | |
94 | void a lign() thr ows IOExce ption { | |
95 | fo r (int i = 0; i < lm argin; i++ ) out.writ e(" "); | |
96 | } | |
97 | ||
98 | /** In crease lef t margin b y indentat ion width. | |
99 | */ | |
100 | void i ndent() { | |
101 | lm argin = lm argin + wi dth; | |
102 | } | |
103 | ||
104 | /** De crease lef t margin b y indentat ion width. | |
105 | */ | |
106 | void u ndent() { | |
107 | lm argin = lm argin - wi dth; | |
108 | } | |
109 | ||
110 | /** En ter a new precedence level. Em it a `(' i f new prec edence lev el | |
111 | * is less than precedenc e level so far. | |
112 | * @p aram conte xtPrec The preced ence level in force so far. | |
113 | * @p aram ownPr ec The new pr ecedence l evel. | |
114 | */ | |
115 | void o pen(int co ntextPrec, int ownPr ec) throws IOExcepti on { | |
116 | if (ownPrec < contextP rec) out.w rite("("); | |
117 | } | |
118 | ||
119 | /** Le ave preced ence level . Emit a ` (' if inne r preceden ce level | |
120 | * is less than precedenc e level we revert to . | |
121 | * @p aram conte xtPrec The preced ence level we revert to. | |
122 | * @p aram ownPr ec The inner precedence level. | |
123 | */ | |
124 | void c lose(int c ontextPrec , int ownP rec) throw s IOExcept ion { | |
125 | if (ownPrec < contextP rec) out.w rite(")"); | |
126 | } | |
127 | ||
128 | /** Pr int string , replacin g all non- ascii char acter with unicode e scapes. | |
129 | */ | |
130 | public void prin t(Object s ) throws I OException { | |
131 | ou t.write(Co nvert.esca peUnicode( s.toString ())); | |
132 | } | |
133 | ||
134 | /** Pr int new li ne. | |
135 | */ | |
136 | public void prin tln() thro ws IOExcep tion { | |
137 | ou t.write(li neSep); | |
138 | } | |
139 | ||
140 | public static St ring toSim pleString( JCTree tre e) { | |
141 | re turn toSim pleString( tree, PREF ERRED_LENG TH); | |
142 | } | |
143 | ||
144 | public static St ring toSim pleString( JCTree tre e, int max Length) { | |
145 | St ringWriter s = new S tringWrite r(); | |
146 | tr y { | |
147 | new Pret ty(s, fals e).printEx pr(tree); | |
148 | } | |
149 | ca tch (IOExc eption e) { | |
150 | // shoul d never ha ppen, beca use String Writer is defined | |
151 | // never to throw any IOExce ptions | |
152 | throw ne w Assertio nError(e); | |
153 | } | |
154 | // we need to (i) repla ce all lin e terminat ors with a space and (ii) remo ve | |
155 | // occurrence s of 'miss ing' in th e Pretty o utput (gen erated whe n types ar e missing) | |
156 | St ring res = s.toStrin g().trim() .replaceAl l("\\s+", " ").repla ceAll("/\\ *missing\\ */", ""); | |
157 | if (res.leng th() < max Length) { | |
158 | return r es; | |
159 | } else { | |
160 | int head = (maxLen gth - trim Sequence.l ength()) * 2 / 3; | |
161 | int tail = maxLeng th - trimS equence.le ngth() - h ead; | |
162 | return r es.substri ng(0, head ) + trimSe quence + r es.substri ng(res.len gth() - ta il); | |
163 | } | |
164 | } | |
165 | ||
166 | String lineSep = System.ge tProperty( "line.sepa rator"); | |
167 | ||
168 | /***** ********** ********** ********** ********** ********** ********** ********* | |
169 | * Tra versal met hods | |
170 | ***** ********** ********** ********** ********** ********** ********** ********/ | |
171 | ||
172 | /** Ex ception to propogate IOExcepti on through visitXXX methods */ | |
173 | privat e static c lass Unche ckedIOExce ption exte nds Error { | |
174 | st atic final long seri alVersionU ID = -4032 6926791584 24751L; | |
175 | Un checkedIOE xception(I OException e) { | |
176 | super(e. getMessage (), e); | |
177 | } | |
178 | } | |
179 | ||
180 | /** Vi sitor argu ment: the current pr ecedence l evel. | |
181 | */ | |
182 | int pr ec; | |
183 | ||
184 | /** Vi sitor meth od: print expression tree. | |
185 | * @p aram prec The curre nt precede nce level. | |
186 | */ | |
187 | public void prin tExpr(JCTr ee tree, i nt prec) t hrows IOEx ception { | |
188 | in t prevPrec = this.pr ec; | |
189 | tr y { | |
190 | this.pre c = prec; | |
191 | if (tree == null) print("/*m issing*/") ; | |
192 | else { | |
193 | tree .accept(th is); | |
194 | } | |
195 | } catch (Unc heckedIOEx ception ex ) { | |
196 | IOExcept ion e = ne w IOExcept ion(ex.get Message()) ; | |
197 | e.initCa use(ex); | |
198 | throw e; | |
199 | } finally { | |
200 | this.pre c = prevPr ec; | |
201 | } | |
202 | } | |
203 | ||
204 | /** De rived visi tor method : print ex pression t ree at min imum prece dence leve l | |
205 | * fo r expressi on. | |
206 | */ | |
207 | public void prin tExpr(JCTr ee tree) t hrows IOEx ception { | |
208 | pr intExpr(tr ee, TreeIn fo.noPrec) ; | |
209 | } | |
210 | ||
211 | /** De rived visi tor method : print st atement tr ee. | |
212 | */ | |
213 | public void prin tStat(JCTr ee tree) t hrows IOEx ception { | |
214 | pr intExpr(tr ee, TreeIn fo.notExpr ession); | |
215 | } | |
216 | ||
217 | /** De rived visi tor method : print li st of expr ession tre es, separa ted by giv en string. | |
218 | * @p aram sep t he separat or string | |
219 | */ | |
220 | public <T extend s JCTree> void print Exprs(List <T> trees, String se p) throws IOExceptio n { | |
221 | if (trees.no nEmpty()) { | |
222 | printExp r(trees.he ad); | |
223 | for (Lis t<T> l = t rees.tail; l.nonEmpt y(); l = l .tail) { | |
224 | prin t(sep); | |
225 | prin tExpr(l.he ad); | |
226 | } | |
227 | } | |
228 | } | |
229 | ||
230 | /** De rived visi tor method : print li st of expr ession tre es, separa ted by com mas. | |
231 | */ | |
232 | public <T extend s JCTree> void print Exprs(List <T> trees) throws IO Exception { | |
233 | pr intExprs(t rees, ", " ); | |
234 | } | |
235 | ||
236 | /** De rived visi tor method : print li st of stat ements, ea ch on a se parate lin e. | |
237 | */ | |
238 | public void prin tStats(Lis t<? extend s JCTree> trees) thr ows IOExce ption { | |
239 | fo r (List<? extends JC Tree> l = trees; l.n onEmpty(); l = l.tai l) { | |
240 | align(); | |
241 | printSta t(l.head); | |
242 | println( ); | |
243 | } | |
244 | } | |
245 | ||
246 | /** Pr int a set of modifie rs. | |
247 | */ | |
248 | public void prin tFlags(lon g flags) t hrows IOEx ception { | |
249 | if ((flags & SYNTHETIC ) != 0) pr int("/*syn thetic*/ " ); | |
250 | pr int(TreeIn fo.flagNam es(flags)) ; | |
251 | if ((flags & ExtendedS tandardFla gs) != 0) print(" ") ; | |
252 | if ((flags & ANNOTATIO N) != 0) p rint("@"); | |
253 | } | |
254 | ||
255 | public void prin tAnnotatio ns(List<JC Annotation > trees) t hrows IOEx ception { | |
256 | fo r (List<JC Annotation > l = tree s; l.nonEm pty(); l = l.tail) { | |
257 | printSta t(l.head); | |
258 | println( ); | |
259 | align(); | |
260 | } | |
261 | } | |
262 | ||
263 | public void prin tTypeAnnot ations(Lis t<JCAnnota tion> tree s) throws IOExceptio n { | |
264 | fo r (List<JC Annotation > l = tree s; l.nonEm pty(); l = l.tail) { | |
265 | printExp r(l.head); | |
266 | print(" "); | |
267 | } | |
268 | } | |
269 | ||
270 | /** Pr int docume ntation co mment, if it exists | |
271 | * @p aram tree The tre e for whic h a docume ntation co mment shou ld be prin ted. | |
272 | */ | |
273 | public void prin tDocCommen t(JCTree t ree) throw s IOExcept ion { | |
274 | if (docComme nts != nul l) { | |
275 | String d c = docCom ments.getC ommentText (tree); | |
276 | if (dc ! = null) { | |
277 | prin t("/**"); println(); | |
278 | int pos = 0; | |
279 | int endpos = l ineEndPos( dc, pos); | |
280 | whil e (pos < d c.length() ) { | |
281 | align(); | |
282 | print(" *" ); | |
283 | if (pos < dc.length( ) && dc.ch arAt(pos) > ' ') pri nt(" "); | |
284 | print(dc.s ubstring(p os, endpos )); printl n(); | |
285 | pos = endp os + 1; | |
286 | endpos = l ineEndPos( dc, pos); | |
287 | } | |
288 | alig n(); print (" */"); p rintln(); | |
289 | alig n(); | |
290 | } | |
291 | } | |
292 | } | |
293 | //where | |
294 | static int lineE ndPos(Stri ng s, int start) { | |
295 | in t pos = s. indexOf('\ n', start) ; | |
296 | if (pos < 0) pos = s.l ength(); | |
297 | re turn pos; | |
298 | } | |
299 | ||
300 | /** If type para meter list is non-em pty, print it enclos ed in | |
301 | * {@ literal "< ...>"} bra ckets. | |
302 | */ | |
303 | public void prin tTypeParam eters(List <JCTypePar ameter> tr ees) throw s IOExcept ion { | |
304 | if (trees.no nEmpty()) { | |
305 | print("< "); | |
306 | printExp rs(trees); | |
307 | print("> "); | |
308 | } | |
309 | } | |
310 | ||
311 | /** Pr int a bloc k. | |
312 | */ | |
313 | public void prin tBlock(Lis t<? extend s JCTree> stats) thr ows IOExce ption { | |
314 | pr int("{"); | |
315 | pr intln(); | |
316 | in dent(); | |
317 | pr intStats(s tats); | |
318 | un dent(); | |
319 | al ign(); | |
320 | pr int("}"); | |
321 | } | |
322 | ||
323 | /** Pr int a bloc k. | |
324 | */ | |
325 | public void prin tEnumBody( List<JCTre e> stats) throws IOE xception { | |
326 | pr int("{"); | |
327 | pr intln(); | |
328 | in dent(); | |
329 | bo olean firs t = true; | |
330 | fo r (List<JC Tree> l = stats; l.n onEmpty(); l = l.tai l) { | |
331 | if (isEn umerator(l .head)) { | |
332 | if ( !first) { | |
333 | print(",") ; | |
334 | println(); | |
335 | } | |
336 | alig n(); | |
337 | prin tStat(l.he ad); | |
338 | firs t = false; | |
339 | } | |
340 | } | |
341 | pr int(";"); | |
342 | pr intln(); | |
343 | fo r (List<JC Tree> l = stats; l.n onEmpty(); l = l.tai l) { | |
344 | if (!isE numerator( l.head)) { | |
345 | alig n(); | |
346 | prin tStat(l.he ad); | |
347 | prin tln(); | |
348 | } | |
349 | } | |
350 | un dent(); | |
351 | al ign(); | |
352 | pr int("}"); | |
353 | } | |
354 | ||
355 | /** Is the given tree an e numerator definition ? */ | |
356 | boolea n isEnumer ator(JCTre e t) { | |
357 | return t.h asTag(
|
|
358 | } | |
359 | ||
360 | /** Pr int unit c onsisting of package clause an d import s tatements in topleve l, | |
361 | * fo llowed by class defi nition. if class def inition == null, | |
362 | * pr int all de finitions in topleve l. | |
363 | * @p aram tree The to plevel tre e | |
364 | * @p aram cdef The cl ass defini tion, whic h is assum ed to be p art of the | |
365 | * toplev el tree. | |
366 | */ | |
367 | public void prin tUnit(JCCo mpilationU nit tree, JCClassDec l cdef) th rows IOExc eption { | |
368 | do cComments = tree.doc Comments; | |
369 | pr intDocComm ent(tree); | |
370 | if (tree.pid != null) { | |
371 | print("p ackage "); | |
372 | printExp r(tree.pid ); | |
373 | print("; "); | |
374 | println( ); | |
375 | } | |
376 | bo olean firs tImport = true; | |
377 | fo r (List<JC Tree> l = tree.defs; | |
378 | l. nonEmpty() && (cdef == null || l.head.ha sTag(IMPOR T)); | |
379 | l = l.tail) { | |
380 | if (l.he ad.hasTag( IMPORT)) { | |
381 | JCIm port imp = (JCImport )l.head; | |
382 | Name name = Tr eeInfo.nam e(imp.qual id); | |
383 | if ( name == na me.table.n ames.aster isk || | |
384 | cdef = = null || | |
385 | isUsed (TreeInfo. symbol(imp .qualid), cdef)) { | |
386 | if (firstI mport) { | |
387 | firstI mport = fa lse; | |
388 | printl n(); | |
389 | } | |
390 | printStat( imp); | |
391 | } | |
392 | } else { | |
393 | prin tStat(l.he ad); | |
394 | } | |
395 | } | |
396 | if (cdef != null) { | |
397 | printSta t(cdef); | |
398 | println( ); | |
399 | } | |
400 | } | |
401 | // whe re | |
402 | boolea n isUsed(f inal Symbo l t, JCTre e cdef) { | |
403 | cl ass UsedVi sitor exte nds TreeSc anner { | |
404 | public v oid scan(J CTree tree ) { | |
405 | if ( tree!=null && !resul t) tree.ac cept(this) ; | |
406 | } | |
407 | boolean result = f alse; | |
408 | public v oid visitI dent(JCIde nt tree) { | |
409 | if ( tree.sym = = t) resul t = true; | |
410 | } | |
411 | } | |
412 | Us edVisitor v = new Us edVisitor( ); | |
413 | v. scan(cdef) ; | |
414 | re turn v.res ult; | |
415 | } | |
416 | ||
417 | /***** ********** ********** ********** ********** ********** ********** ********* | |
418 | * Vis itor metho ds | |
419 | ***** ********** ********** ********** ********** ********** ********** ********/ | |
420 | ||
421 | public void visi tTopLevel( JCCompilat ionUnit tr ee) { | |
422 | tr y { | |
423 | printUni t(tree, nu ll); | |
424 | } catch (IOE xception e ) { | |
425 | throw ne w Unchecke dIOExcepti on(e); | |
426 | } | |
427 | } | |
428 | ||
429 | public void visi tImport(JC Import tre e) { | |
430 | tr y { | |
431 | print("i mport "); | |
432 | if (tree .staticImp ort) print ("static " ); | |
433 | printExp r(tree.qua lid); | |
434 | print("; "); | |
435 | println( ); | |
436 | } catch (IOE xception e ) { | |
437 | throw ne w Unchecke dIOExcepti on(e); | |
438 | } | |
439 | } | |
440 | ||
441 | public void visi tClassDef( JCClassDec l tree) { | |
442 | tr y { | |
443 | println( ); align() ; | |
444 | printDoc Comment(tr ee); | |
445 | printAnn otations(t ree.mods.a nnotations ); | |
446 | printFla gs(tree.mo ds.flags & ~INTERFAC E); | |
447 | Name enc lClassName Prev = enc lClassName ; | |
448 | enclClas sName = tr ee.name; | |
449 | if ((tre e.mods.fla gs & INTER FACE) != 0 ) { | |
450 | prin t("interfa ce " + tre e.name); | |
451 | prin tTypeParam eters(tree .typarams) ; | |
452 | if ( tree.imple menting.no nEmpty()) { | |
453 | print(" ex tends "); | |
454 | printExprs (tree.impl ementing); | |
455 | } | |
456 | } else { | |
457 | if ( (tree.mods .flags & E NUM) != 0) | |
458 | print("enu m " + tree .name); | |
459 | else | |
460 | print("cla ss " + tre e.name); | |
461 | prin tTypeParam eters(tree .typarams) ; | |
462 | if ( tree.exten ding != nu ll) { | |
463 | print(" ex tends "); | |
464 | printExpr( tree.exten ding); | |
465 | } | |
466 | if ( tree.imple menting.no nEmpty()) { | |
467 | print(" im plements " ); | |
468 | printExprs (tree.impl ementing); | |
469 | } | |
470 | } | |
471 | print(" "); | |
472 | if ((tre e.mods.fla gs & ENUM) != 0) { | |
473 | prin tEnumBody( tree.defs) ; | |
474 | } else { | |
475 | prin tBlock(tre e.defs); | |
476 | } | |
477 | enclClas sName = en clClassNam ePrev; | |
478 | } catch (IOE xception e ) { | |
479 | throw ne w Unchecke dIOExcepti on(e); | |
480 | } | |
481 | } | |
482 | ||
483 | public void visi tMethodDef (JCMethodD ecl tree) { | |
484 | tr y { | |
485 | // when producing source out put, omit anonymous constructo rs | |
486 | if (tree .name == t ree.name.t able.names .init && | |
487 | enclClassN ame == nul l && | |
488 | sourceOutp ut) return ; | |
489 | println( ); align() ; | |
490 | printDoc Comment(tr ee); | |
491 | printExp r(tree.mod s); | |
492 | printTyp eParameter s(tree.typ arams); | |
493 | if (tree .name == t ree.name.t able.names .init) { | |
494 | prin t(enclClas sName != n ull ? encl ClassName : tree.nam e); | |
495 | } else { | |
496 | prin tExpr(tree .restype); | |
497 | prin t(" " + tr ee.name); | |
498 | } | |
499 | print("( "); | |
500 | if (tree .recvparam !=null) { | |
501 | prin tExpr(tree .recvparam ); | |
502 | if ( tree.param s.size() > 0) { | |
503 | print(", " ); | |
504 | } | |
505 | } | |
506 | printExp rs(tree.pa rams); | |
507 | print(") "); | |
508 | if (tree .thrown.no nEmpty()) { | |
509 | prin t(" throws "); | |
510 | prin tExprs(tre e.thrown); | |
511 | } | |
512 | if (tree .defaultVa lue != nul l) { | |
513 | prin t(" defaul t "); | |
514 | prin tExpr(tree .defaultVa lue); | |
515 | } | |
516 | if (tree .body != n ull) { | |
517 | prin t(" "); | |
518 | prin tStat(tree .body); | |
519 | } else { | |
520 | prin t(";"); | |
521 | } | |
522 | } catch (IOE xception e ) { | |
523 | throw ne w Unchecke dIOExcepti on(e); | |
524 | } | |
525 | } | |
526 | ||
527 | public void visi tVarDef(JC VariableDe cl tree) { | |
528 | tr y { | |
529 | if (docC omments != null && d ocComments .hasCommen t(tree)) { | |
530 | prin tln(); ali gn(); | |
531 | } | |
532 | printDoc Comment(tr ee); | |
533 | if ((tre e.mods.fla gs & ENUM) != 0) { | |
534 | prin t("/*publi c static f inal*/ "); | |
535 | prin t(tree.nam e); | |
536 | if ( tree.init != null) { | |
537 | if (source Output && tree.init. hasTag(NEW CLASS)) { | |
538 | print( " /*enum*/ "); | |
539 | JCNewC lass init = (JCNewCl ass) tree. init; | |
540 | if (in it.args != null && i nit.args.n onEmpty()) { | |
541 | pr int("("); | |
542 | pr int(init.a rgs); | |
543 | pr int(")"); | |
544 | } | |
545 | if (in it.def != null && in it.def.def s != null) { | |
546 | pr int(" "); | |
547 | pr intBlock(i nit.def.de fs); | |
548 | } | |
549 | return ; | |
550 | } | |
551 | print(" /* = "); | |
552 | printExpr( tree.init) ; | |
553 | print(" */ "); | |
554 | } | |
555 | } else { | |
556 | prin tExpr(tree .mods); | |
557 | if ( (tree.mods .flags & V ARARGS) != 0) { | |
558 | JCTree var type = tre e.vartype; | |
559 | List<JCAnn otation> t as = null; | |
560 | if (vartyp e instance of JCAnnot atedType) { | |
561 | tas = ((JCAnnota tedType)va rtype).ann otations; | |
562 | vartyp e = ((JCAn notatedTyp e)vartype) .underlyin gType; | |
563 | } | |
564 | printExpr( ((JCArrayT ypeTree) v artype).el emtype); | |
565 | if (tas != null) { | |
566 | print( ' '); | |
567 | printT ypeAnnotat ions(tas); | |
568 | } | |
569 | print("... " + tree. name); | |
570 | } el se { | |
571 | printExpr( tree.varty pe); | |
572 | print(" " + tree.nam e); | |
573 | } | |
574 | if ( tree.init != null) { | |
575 | print(" = "); | |
576 | printExpr( tree.init) ; | |
577 | } | |
578 | if ( prec == Tr eeInfo.not Expression ) print("; "); | |
579 | } | |
580 | } catch (IOE xception e ) { | |
581 | throw ne w Unchecke dIOExcepti on(e); | |
582 | } | |
583 | } | |
584 | ||
585 | public void visi tSkip(JCSk ip tree) { | |
586 | tr y { | |
587 | print("; "); | |
588 | } catch (IOE xception e ) { | |
589 | throw ne w Unchecke dIOExcepti on(e); | |
590 | } | |
591 | } | |
592 | ||
593 | public void visi tBlock(JCB lock tree) { | |
594 | tr y { | |
595 | printFla gs(tree.fl ags); | |
596 | printBlo ck(tree.st ats); | |
597 | } catch (IOE xception e ) { | |
598 | throw ne w Unchecke dIOExcepti on(e); | |
599 | } | |
600 | } | |
601 | ||
602 | public void visi tDoLoop(JC DoWhileLoo p tree) { | |
603 | tr y { | |
604 | print("d o "); | |
605 | printSta t(tree.bod y); | |
606 | align(); | |
607 | print(" while "); | |
608 | if (tree .cond.hasT ag(PARENS) ) { | |
609 | prin tExpr(tree .cond); | |
610 | } else { | |
611 | prin t("("); | |
612 | prin tExpr(tree .cond); | |
613 | prin t(")"); | |
614 | } | |
615 | print("; "); | |
616 | } catch (IOE xception e ) { | |
617 | throw ne w Unchecke dIOExcepti on(e); | |
618 | } | |
619 | } | |
620 | ||
621 | public void visi tWhileLoop (JCWhileLo op tree) { | |
622 | tr y { | |
623 | print("w hile "); | |
624 | if (tree .cond.hasT ag(PARENS) ) { | |
625 | prin tExpr(tree .cond); | |
626 | } else { | |
627 | prin t("("); | |
628 | prin tExpr(tree .cond); | |
629 | prin t(")"); | |
630 | } | |
631 | print(" "); | |
632 | printSta t(tree.bod y); | |
633 | } catch (IOE xception e ) { | |
634 | throw ne w Unchecke dIOExcepti on(e); | |
635 | } | |
636 | } | |
637 | ||
638 | public void visi tForLoop(J CForLoop t ree) { | |
639 | tr y { | |
640 | print("f or ("); | |
641 | if (tree .init.nonE mpty()) { | |
642 | if (tree.i nit.head.h asTag(
|
|
643 | printExpr( tree.init. head); | |
644 | for (List< JCStatemen t> l = tre e.init.tai l; l.nonEm pty(); l = l.tail) { | |
645 | JCVari ableDecl v def = (JCV ariableDec l)l.head; | |
646 | print( ", " + vde f.name + " = "); | |
647 | printE xpr(vdef.i nit); | |
648 | } | |
649 | } el se { | |
650 | printExprs (tree.init ); | |
651 | } | |
652 | } | |
653 | print("; "); | |
654 | if (tree .cond != n ull) print Expr(tree. cond); | |
655 | print("; "); | |
656 | printExp rs(tree.st ep); | |
657 | print(") "); | |
658 | printSta t(tree.bod y); | |
659 | } catch (IOE xception e ) { | |
660 | throw ne w Unchecke dIOExcepti on(e); | |
661 | } | |
662 | } | |
663 | ||
664 | public void visi tForeachLo op(JCEnhan cedForLoop tree) { | |
665 | tr y { | |
666 | print("f or ("); | |
667 | printExp r(tree.var ); | |
668 | print(" : "); | |
669 | printExp r(tree.exp r); | |
670 | print(") "); | |
671 | printSta t(tree.bod y); | |
672 | } catch (IOE xception e ) { | |
673 | throw ne w Unchecke dIOExcepti on(e); | |
674 | } | |
675 | } | |
676 | ||
677 | public void visi tLabelled( JCLabeledS tatement t ree) { | |
678 | tr y { | |
679 | print(tr ee.label + ": "); | |
680 | printSta t(tree.bod y); | |
681 | } catch (IOE xception e ) { | |
682 | throw ne w Unchecke dIOExcepti on(e); | |
683 | } | |
684 | } | |
685 | ||
686 | public void visi tSwitch(JC Switch tre e) { | |
687 | tr y { | |
688 | print("s witch "); | |
689 | if (tree .selector. hasTag(PAR ENS)) { | |
690 | prin tExpr(tree .selector) ; | |
691 | } else { | |
692 | prin t("("); | |
693 | prin tExpr(tree .selector) ; | |
694 | prin t(")"); | |
695 | } | |
696 | print(" {"); | |
697 | println( ); | |
698 | printSta ts(tree.ca ses); | |
699 | align(); | |
700 | print("} "); | |
701 | } catch (IOE xception e ) { | |
702 | throw ne w Unchecke dIOExcepti on(e); | |
703 | } | |
704 | } | |
705 | ||
706 | public void visi tCase(JCCa se tree) { | |
707 | tr y { | |
708 | if (tree .pat == nu ll) { | |
709 | prin t("default "); | |
710 | } else { | |
711 | prin t("case ") ; | |
712 | prin tExpr(tree .pat); | |
713 | } | |
714 | print(": "); | |
715 | println( ); | |
716 | indent() ; | |
717 | printSta ts(tree.st ats); | |
718 | undent() ; | |
719 | align(); | |
720 | } catch (IOE xception e ) { | |
721 | throw ne w Unchecke dIOExcepti on(e); | |
722 | } | |
723 | } | |
724 | ||
725 | public void visi tSynchroni zed(JCSync hronized t ree) { | |
726 | tr y { | |
727 | print("s ynchronize d "); | |
728 | if (tree .lock.hasT ag(PARENS) ) { | |
729 | prin tExpr(tree .lock); | |
730 | } else { | |
731 | prin t("("); | |
732 | prin tExpr(tree .lock); | |
733 | prin t(")"); | |
734 | } | |
735 | print(" "); | |
736 | printSta t(tree.bod y); | |
737 | } catch (IOE xception e ) { | |
738 | throw ne w Unchecke dIOExcepti on(e); | |
739 | } | |
740 | } | |
741 | ||
742 | public void visi tTry(JCTry tree) { | |
743 | tr y { | |
744 | print("t ry "); | |
745 | if (tree .resources .nonEmpty( )) { | |
746 | prin t("("); | |
747 | bool ean first = true; | |
748 | for (JCTree va r : tree.r esources) { | |
749 | if (!first ) { | |
750 | printl n(); | |
751 | indent (); | |
752 | } | |
753 | printStat( var); | |
754 | first = fa lse; | |
755 | } | |
756 | prin t(") "); | |
757 | } | |
758 | printSta t(tree.bod y); | |
759 | for (Lis t<JCCatch> l = tree. catchers; l.nonEmpty (); l = l. tail) { | |
760 | prin tStat(l.he ad); | |
761 | } | |
762 | if (tree .finalizer != null) { | |
763 | prin t(" finall y "); | |
764 | prin tStat(tree .finalizer ); | |
765 | } | |
766 | } catch (IOE xception e ) { | |
767 | throw ne w Unchecke dIOExcepti on(e); | |
768 | } | |
769 | } | |
770 | ||
771 | public void visi tCatch(JCC atch tree) { | |
772 | tr y { | |
773 | print(" catch ("); | |
774 | printExp r(tree.par am); | |
775 | print(") "); | |
776 | printSta t(tree.bod y); | |
777 | } catch (IOE xception e ) { | |
778 | throw ne w Unchecke dIOExcepti on(e); | |
779 | } | |
780 | } | |
781 | ||
782 | public void visi tCondition al(JCCondi tional tre e) { | |
783 | tr y { | |
784 | open(pre c, TreeInf o.condPrec ); | |
785 | printExp r(tree.con d, TreeInf o.condPrec + 1); | |
786 | print(" ? "); | |
787 | printExp r(tree.tru epart); | |
788 | print(" : "); | |
789 | printExp r(tree.fal separt, Tr eeInfo.con dPrec); | |
790 | close(pr ec, TreeIn fo.condPre c); | |
791 | } catch (IOE xception e ) { | |
792 | throw ne w Unchecke dIOExcepti on(e); | |
793 | } | |
794 | } | |
795 | ||
796 | public void visi tIf(JCIf t ree) { | |
797 | tr y { | |
798 | print("i f "); | |
799 | if (tree .cond.hasT ag(PARENS) ) { | |
800 | prin tExpr(tree .cond); | |
801 | } else { | |
802 | prin t("("); | |
803 | prin tExpr(tree .cond); | |
804 | prin t(")"); | |
805 | } | |
806 | print(" "); | |
807 | printSta t(tree.the npart); | |
808 | if (tree .elsepart != null) { | |
809 | prin t(" else " ); | |
810 | prin tStat(tree .elsepart) ; | |
811 | } | |
812 | } catch (IOE xception e ) { | |
813 | throw ne w Unchecke dIOExcepti on(e); | |
814 | } | |
815 | } | |
816 | ||
817 | public void visi tExec(JCEx pressionSt atement tr ee) { | |
818 | tr y { | |
819 | printExp r(tree.exp r); | |
820 | if (prec == TreeIn fo.notExpr ession) pr int(";"); | |
821 | } catch (IOE xception e ) { | |
822 | throw ne w Unchecke dIOExcepti on(e); | |
823 | } | |
824 | } | |
825 | ||
826 | public void visi tBreak(JCB reak tree) { | |
827 | tr y { | |
828 | print("b reak"); | |
829 | if (tree .label != null) prin t(" " + tr ee.label); | |
830 | print("; "); | |
831 | } catch (IOE xception e ) { | |
832 | throw ne w Unchecke dIOExcepti on(e); | |
833 | } | |
834 | } | |
835 | ||
836 | public void visi tContinue( JCContinue tree) { | |
837 | tr y { | |
838 | print("c ontinue"); | |
839 | if (tree .label != null) prin t(" " + tr ee.label); | |
840 | print("; "); | |
841 | } catch (IOE xception e ) { | |
842 | throw ne w Unchecke dIOExcepti on(e); | |
843 | } | |
844 | } | |
845 | ||
846 | public void visi tReturn(JC Return tre e) { | |
847 | tr y { | |
848 | print("r eturn"); | |
849 | if (tree .expr != n ull) { | |
850 | prin t(" "); | |
851 | prin tExpr(tree .expr); | |
852 | } | |
853 | print("; "); | |
854 | } catch (IOE xception e ) { | |
855 | throw ne w Unchecke dIOExcepti on(e); | |
856 | } | |
857 | } | |
858 | ||
859 | public void visi tThrow(JCT hrow tree) { | |
860 | tr y { | |
861 | print("t hrow "); | |
862 | printExp r(tree.exp r); | |
863 | print("; "); | |
864 | } catch (IOE xception e ) { | |
865 | throw ne w Unchecke dIOExcepti on(e); | |
866 | } | |
867 | } | |
868 | ||
869 | public void visi tAssert(JC Assert tre e) { | |
870 | tr y { | |
871 | print("a ssert "); | |
872 | printExp r(tree.con d); | |
873 | if (tree .detail != null) { | |
874 | prin t(" : "); | |
875 | prin tExpr(tree .detail); | |
876 | } | |
877 | print("; "); | |
878 | } catch (IOE xception e ) { | |
879 | throw ne w Unchecke dIOExcepti on(e); | |
880 | } | |
881 | } | |
882 | ||
883 | public void visi tApply(JCM ethodInvoc ation tree ) { | |
884 | tr y { | |
885 | if (!tre e.typeargs .isEmpty() ) { | |
886 | if ( tree.meth. hasTag(SEL ECT)) { | |
887 | JCFieldAcc ess left = (JCFieldA ccess)tree .meth; | |
888 | printExpr( left.selec ted); | |
889 | print(".<" ); | |
890 | printExprs (tree.type args); | |
891 | print(">" + left.nam e); | |
892 | } el se { | |
893 | print("<") ; | |
894 | printExprs (tree.type args); | |
895 | print(">") ; | |
896 | printExpr( tree.meth) ; | |
897 | } | |
898 | } else { | |
899 | prin tExpr(tree .meth); | |
900 | } | |
901 | print("( "); | |
902 | printExp rs(tree.ar gs); | |
903 | print(") "); | |
904 | } catch (IOE xception e ) { | |
905 | throw ne w Unchecke dIOExcepti on(e); | |
906 | } | |
907 | } | |
908 | ||
909 | public void visi tNewClass( JCNewClass tree) { | |
910 | tr y { | |
911 | if (tree .encl != n ull) { | |
912 | prin tExpr(tree .encl); | |
913 | prin t("."); | |
914 | } | |
915 | print("n ew "); | |
916 | if (!tre e.typeargs .isEmpty() ) { | |
917 | prin t("<"); | |
918 | prin tExprs(tre e.typeargs ); | |
919 | prin t(">"); | |
920 | } | |
921 | if (tree .def != nu ll && tree .def.mods. annotation s.nonEmpty ()) { | |
922 | prin tTypeAnnot ations(tre e.def.mods .annotatio ns); | |
923 | } | |
924 | printExp r(tree.cla zz); | |
925 | print("( "); | |
926 | printExp rs(tree.ar gs); | |
927 | print(") "); | |
928 | if (tree .def != nu ll) { | |
929 | Name enclClass NamePrev = enclClass Name; | |
930 | encl ClassName = | |
931 | tree.d ef.name != null ? tr ee.def.nam e : | |
932 | tr ee.type != null && t ree.type.t sym.name ! = tree.typ e.tsym.nam e.table.na mes.empty | |
933 | ? tree.t ype.tsym.n ame : null ; | |
934 | if ( (tree.def. mods.flags & Flags.E NUM) != 0) print("/* enum*/"); | |
935 | prin tBlock(tre e.def.defs ); | |
936 | encl ClassName = enclClas sNamePrev; | |
937 | } | |
938 | } catch (IOE xception e ) { | |
939 | throw ne w Unchecke dIOExcepti on(e); | |
940 | } | |
941 | } | |
942 | ||
943 | public void visi tNewArray( JCNewArray tree) { | |
944 | tr y { | |
945 | if (tree .elemtype != null) { | |
946 | prin t("new "); | |
947 | JCTr ee elem = tree.elemt ype; | |
948 | prin tBaseEleme ntType(ele m); | |
949 | ||
950 | if ( !tree.anno tations.is Empty()) { | |
951 | print(' ') ; | |
952 | printTypeA nnotations (tree.anno tations); | |
953 | } | |
954 | if ( tree.elems != null) { | |
955 | print("[]" ); | |
956 | } | |
957 | ||
958 | int i = 0; | |
959 | List <List<JCAn notation>> da = tree .dimAnnota tions; | |
960 | for (List<JCEx pression> l = tree.d ims; l.non Empty(); l = l.tail) { | |
961 | if (da.siz e() > i && !da.get(i ).isEmpty( )) { | |
962 | print( ' '); | |
963 | printT ypeAnnotat ions(da.ge t(i)); | |
964 | } | |
965 | print("[") ; | |
966 | i++; | |
967 | printExpr( l.head); | |
968 | print("]") ; | |
969 | } | |
970 | prin tBrackets( elem); | |
971 | } | |
972 | if (tree .elems != null) { | |
973 | prin t("{"); | |
974 | prin tExprs(tre e.elems); | |
975 | prin t("}"); | |
976 | } | |
977 | } catch (IOE xception e ) { | |
978 | throw ne w Unchecke dIOExcepti on(e); | |
979 | } | |
980 | } | |
981 | ||
982 | public void visi tLambda(JC Lambda tre e) { | |
983 | tr y { | |
984 | print("( "); | |
985 | if (tree .paramKind == JCLamb da.Paramet erKind.EXP LICIT) { | |
986 | prin tExprs(tre e.params); | |
987 | } else { | |
988 | Stri ng sep = " "; | |
989 | for (JCVariabl eDecl para m : tree.p arams) { | |
990 | print(sep) ; | |
991 | print(para m.name); | |
992 | sep = ","; | |
993 | } | |
994 | } | |
995 | print(") ->"); | |
996 | printExp r(tree.bod y); | |
997 | } catch (IOE xception e ) { | |
998 | throw ne w Unchecke dIOExcepti on(e); | |
999 | } | |
1000 | } | |
1001 | ||
1002 | public void visi tParens(JC Parens tre e) { | |
1003 | tr y { | |
1004 | print("( "); | |
1005 | printExp r(tree.exp r); | |
1006 | print(") "); | |
1007 | } catch (IOE xception e ) { | |
1008 | throw ne w Unchecke dIOExcepti on(e); | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | public void visi tAssign(JC Assign tre e) { | |
1013 | tr y { | |
1014 | open(pre c, TreeInf o.assignPr ec); | |
1015 | printExp r(tree.lhs , TreeInfo .assignPre c + 1); | |
1016 | print(" = "); | |
1017 | printExp r(tree.rhs , TreeInfo .assignPre c); | |
1018 | close(pr ec, TreeIn fo.assignP rec); | |
1019 | } catch (IOE xception e ) { | |
1020 | throw ne w Unchecke dIOExcepti on(e); | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | public String op eratorName (JCTree.Ta g tag) { | |
1025 | sw itch(tag) { | |
1026 | case POS : retu rn "+"; | |
1027 | case NEG : retu rn "-"; | |
1028 | case NOT : retu rn "!"; | |
1029 | case COM PL: retu rn "~"; | |
1030 | case PRE INC: retu rn "++"; | |
1031 | case PRE DEC: retu rn "--"; | |
1032 | case POS TINC: retu rn "++"; | |
1033 | case POS TDEC: retu rn "--"; | |
1034 | case NUL LCHK: retu rn "<*null chk*>"; | |
1035 | case OR: retu rn "||"; | |
1036 | case AND : retu rn "&&"; | |
1037 | case EQ: retu rn "=="; | |
1038 | case NE: retu rn "!="; | |
1039 | case LT: retu rn "<"; | |
1040 | case GT: retu rn ">"; | |
1041 | case LE: retu rn "<="; | |
1042 | case GE: retu rn ">="; | |
1043 | case BIT OR: retu rn "|"; | |
1044 | case BIT XOR: retu rn "^"; | |
1045 | case BIT AND: retu rn "&"; | |
1046 | case SL: retu rn "<<"; | |
1047 | case SR: retu rn ">>"; | |
1048 | case USR : retu rn ">>>"; | |
1049 | case PLU S: retu rn "+"; | |
1050 | case MIN US: retu rn "-"; | |
1051 | case MUL : retu rn "*"; | |
1052 | case DIV : retu rn "/"; | |
1053 | case MOD : retu rn "%"; | |
1054 | default: throw new Error(); | |
1055 | } | |
1056 | } | |
1057 | ||
1058 | public void visi tAssignop( JCAssignOp tree) { | |
1059 | tr y { | |
1060 | open(pre c, TreeInf o.assignop Prec); | |
1061 | printExp r(tree.lhs , TreeInfo .assignopP rec + 1); | |
1062 | print(" " + operat orName(tre e.getTag() .noAssignO p()) + "= "); | |
1063 | printExp r(tree.rhs , TreeInfo .assignopP rec); | |
1064 | close(pr ec, TreeIn fo.assigno pPrec); | |
1065 | } catch (IOE xception e ) { | |
1066 | throw ne w Unchecke dIOExcepti on(e); | |
1067 | } | |
1068 | } | |
1069 | ||
1070 | public void visi tUnary(JCU nary tree) { | |
1071 | tr y { | |
1072 | int ownp rec = Tree Info.opPre c(tree.get Tag()); | |
1073 | String o pname = op eratorName (tree.getT ag()); | |
1074 | open(pre c, ownprec ); | |
1075 | if (!tre e.getTag() .isPostUna ryOp()) { | |
1076 | prin t(opname); | |
1077 | prin tExpr(tree .arg, ownp rec); | |
1078 | } else { | |
1079 | prin tExpr(tree .arg, ownp rec); | |
1080 | prin t(opname); | |
1081 | } | |
1082 | close(pr ec, ownpre c); | |
1083 | } catch (IOE xception e ) { | |
1084 | throw ne w Unchecke dIOExcepti on(e); | |
1085 | } | |
1086 | } | |
1087 | ||
1088 | public void visi tBinary(JC Binary tre e) { | |
1089 | tr y { | |
1090 | int ownp rec = Tree Info.opPre c(tree.get Tag()); | |
1091 | String o pname = op eratorName (tree.getT ag()); | |
1092 | open(pre c, ownprec ); | |
1093 | printExp r(tree.lhs , ownprec) ; | |
1094 | print(" " + opname + " "); | |
1095 | printExp r(tree.rhs , ownprec + 1); | |
1096 | close(pr ec, ownpre c); | |
1097 | } catch (IOE xception e ) { | |
1098 | throw ne w Unchecke dIOExcepti on(e); | |
1099 | } | |
1100 | } | |
1101 | ||
1102 | public void visi tTypeCast( JCTypeCast tree) { | |
1103 | tr y { | |
1104 | open(pre c, TreeInf o.prefixPr ec); | |
1105 | print("( "); | |
1106 | printExp r(tree.cla zz); | |
1107 | print(") "); | |
1108 | printExp r(tree.exp r, TreeInf o.prefixPr ec); | |
1109 | close(pr ec, TreeIn fo.prefixP rec); | |
1110 | } catch (IOE xception e ) { | |
1111 | throw ne w Unchecke dIOExcepti on(e); | |
1112 | } | |
1113 | } | |
1114 | ||
1115 | public void visi tTypeTest( JCInstance Of tree) { | |
1116 | tr y { | |
1117 | open(pre c, TreeInf o.ordPrec) ; | |
1118 | printExp r(tree.exp r, TreeInf o.ordPrec) ; | |
1119 | print(" instanceof "); | |
1120 | printExp r(tree.cla zz, TreeIn fo.ordPrec + 1); | |
1121 | close(pr ec, TreeIn fo.ordPrec ); | |
1122 | } catch (IOE xception e ) { | |
1123 | throw ne w Unchecke dIOExcepti on(e); | |
1124 | } | |
1125 | } | |
1126 | ||
1127 | public void visi tIndexed(J CArrayAcce ss tree) { | |
1128 | tr y { | |
1129 | printExp r(tree.ind exed, Tree Info.postf ixPrec); | |
1130 | print("[ "); | |
1131 | printExp r(tree.ind ex); | |
1132 | print("] "); | |
1133 | } catch (IOE xception e ) { | |
1134 | throw ne w Unchecke dIOExcepti on(e); | |
1135 | } | |
1136 | } | |
1137 | ||
1138 | public void visi tSelect(JC FieldAcces s tree) { | |
1139 | tr y { | |
1140 | printExp r(tree.sel ected, Tre eInfo.post fixPrec); | |
1141 | print(". " + tree.n ame); | |
1142 | } catch (IOE xception e ) { | |
1143 | throw ne w Unchecke dIOExcepti on(e); | |
1144 | } | |
1145 | } | |
1146 | ||
1147 | public void visi tReference (JCMemberR eference t ree) { | |
1148 | tr y { | |
1149 | printExp r(tree.exp r); | |
1150 | print(": :"); | |
1151 | if (tree .typeargs != null) { | |
1152 | prin t("<"); | |
1153 | prin tExprs(tre e.typeargs ); | |
1154 | prin t(">"); | |
1155 | } | |
1156 | print(tr ee.getMode () == Refe renceMode. INVOKE ? t ree.name : "new"); | |
1157 | } catch (IOE xception e ) { | |
1158 | throw ne w Unchecke dIOExcepti on(e); | |
1159 | } | |
1160 | } | |
1161 | ||
1162 | public void visi tIdent(JCI dent tree) { | |
1163 | tr y { | |
1164 | print(tr ee.name); | |
1165 | } catch (IOE xception e ) { | |
1166 | throw ne w Unchecke dIOExcepti on(e); | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | public void visi tLiteral(J CLiteral t ree) { | |
1171 | tr y { | |
1172 | switch ( tree.typet ag) { | |
1173 | case INT: | |
1174 | print(tree .value.toS tring()); | |
1175 | break; | |
1176 | case LONG: | |
1177 | print(tree .value + " L"); | |
1178 | break; | |
1179 | case FLOAT: | |
1180 | print(tree .value + " F"); | |
1181 | break; | |
1182 | case DOUBLE: | |
1183 | print(tree .value.toS tring()); | |
1184 | break; | |
1185 | case CHAR: | |
1186 | print("\'" + | |
1187 | Co nvert.quot e( | |
1188 | St ring.value Of((char)( (Number)tr ee.value). intValue() )) + | |
1189 | "\ '"); | |
1190 | break; | |
1191 | case BOOLEAN: | |
1192 | print(((Nu mber)tree. value).int Value() == 1 ? "true " : "false "); | |
1193 | break; | |
1194 | case BOT: | |
1195 | print("nul l"); | |
1196 | break; | |
1197 | defa ult: | |
1198 | print("\"" + Convert .quote(tre e.value.to String()) + "\""); | |
1199 | break; | |
1200 | } | |
1201 | } catch (IOE xception e ) { | |
1202 | throw ne w Unchecke dIOExcepti on(e); | |
1203 | } | |
1204 | } | |
1205 | ||
1206 | public void visi tTypeIdent (JCPrimiti veTypeTree tree) { | |
1207 | tr y { | |
1208 | switch(t ree.typeta g) { | |
1209 | case BYTE: | |
1210 | print("byt e"); | |
1211 | break; | |
1212 | case CHAR: | |
1213 | print("cha r"); | |
1214 | break; | |
1215 | case SHORT: | |
1216 | print("sho rt"); | |
1217 | break; | |
1218 | case INT: | |
1219 | print("int "); | |
1220 | break; | |
1221 | case LONG: | |
1222 | print("lon g"); | |
1223 | break; | |
1224 | case FLOAT: | |
1225 | print("flo at"); | |
1226 | break; | |
1227 | case DOUBLE: | |
1228 | print("dou ble"); | |
1229 | break; | |
1230 | case BOOLEAN: | |
1231 | print("boo lean"); | |
1232 | break; | |
1233 | case VOID: | |
1234 | print("voi d"); | |
1235 | break; | |
1236 | defa ult: | |
1237 | print("err or"); | |
1238 | break; | |
1239 | } | |
1240 | } catch (IOE xception e ) { | |
1241 | throw ne w Unchecke dIOExcepti on(e); | |
1242 | } | |
1243 | } | |
1244 | ||
1245 | public void visi tTypeArray (JCArrayTy peTree tre e) { | |
1246 | tr y { | |
1247 | printBas eElementTy pe(tree); | |
1248 | printBra ckets(tree ); | |
1249 | } catch (IOE xception e ) { | |
1250 | throw ne w Unchecke dIOExcepti on(e); | |
1251 | } | |
1252 | } | |
1253 | ||
1254 | // Pri nts the in ner elemen t type of a nested a rray | |
1255 | privat e void pri ntBaseElem entType(JC Tree tree) throws IO Exception { | |
1256 | pr intExpr(Tr eeInfo.inn ermostType (tree)); | |
1257 | } | |
1258 | ||
1259 | // pri nts the br ackets of a nested a rray in re verse orde r | |
1260 | // tre e is eithe r JCArrayT ypeTree or JCAnnotat edTypeTree | |
1261 | privat e void pri ntBrackets (JCTree tr ee) throws IOExcepti on { | |
1262 | JC Tree elem = tree; | |
1263 | wh ile (true) { | |
1264 | if (elem .hasTag(AN NOTATED_TY PE)) { | |
1265 | JCAn notatedTyp e atype = (JCAnnotat edType) el em; | |
1266 | elem = atype.u nderlyingT ype; | |
1267 | if ( elem.hasTa g(TYPEARRA Y)) { | |
1268 | print(' ') ; | |
1269 | printTypeA nnotations (atype.ann otations); | |
1270 | } | |
1271 | } | |
1272 | if (elem .hasTag(TY PEARRAY)) { | |
1273 | prin t("[]"); | |
1274 | elem = ((JCArr ayTypeTree )elem).ele mtype; | |
1275 | } else { | |
1276 | brea k; | |
1277 | } | |
1278 | } | |
1279 | } | |
1280 | ||
1281 | public void visi tTypeApply (JCTypeApp ly tree) { | |
1282 | tr y { | |
1283 | printExp r(tree.cla zz); | |
1284 | print("< "); | |
1285 | printExp rs(tree.ar guments); | |
1286 | print("> "); | |
1287 | } catch (IOE xception e ) { | |
1288 | throw ne w Unchecke dIOExcepti on(e); | |
1289 | } | |
1290 | } | |
1291 | ||
1292 | public void visi tTypeUnion (JCTypeUni on tree) { | |
1293 | tr y { | |
1294 | printExp rs(tree.al ternatives , " | "); | |
1295 | } catch (IOE xception e ) { | |
1296 | throw ne w Unchecke dIOExcepti on(e); | |
1297 | } | |
1298 | } | |
1299 | ||
1300 | public void visi tTypeInter section(JC TypeInters ection tre e) { | |
1301 | tr y { | |
1302 | printExp rs(tree.bo unds, " & "); | |
1303 | } catch (IOE xception e ) { | |
1304 | throw ne w Unchecke dIOExcepti on(e); | |
1305 | } | |
1306 | } | |
1307 | ||
1308 | public void visi tTypeParam eter(JCTyp eParameter tree) { | |
1309 | tr y { | |
1310 | if (tree .annotatio ns.nonEmpt y()) { | |
1311 | this .printType Annotation s(tree.ann otations); | |
1312 | } | |
1313 | print(tr ee.name); | |
1314 | if (tree .bounds.no nEmpty()) { | |
1315 | prin t(" extend s "); | |
1316 | prin tExprs(tre e.bounds, " & "); | |
1317 | } | |
1318 | } catch (IOE xception e ) { | |
1319 | throw ne w Unchecke dIOExcepti on(e); | |
1320 | } | |
1321 | } | |
1322 | ||
1323 | @Overr ide | |
1324 | public void visi tWildcard( JCWildcard tree) { | |
1325 | tr y { | |
1326 | print(tr ee.kind); | |
1327 | if (tree .kind.kind != BoundK ind.UNBOUN D) | |
1328 | prin tExpr(tree .inner); | |
1329 | } catch (IOE xception e ) { | |
1330 | throw ne w Unchecke dIOExcepti on(e); | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | @Overr ide | |
1335 | public void visi tTypeBound Kind(TypeB oundKind t ree) { | |
1336 | tr y { | |
1337 | print(St ring.value Of(tree.ki nd)); | |
1338 | } catch (IOE xception e ) { | |
1339 | throw ne w Unchecke dIOExcepti on(e); | |
1340 | } | |
1341 | } | |
1342 | ||
1343 | public void visi tErroneous (JCErroneo us tree) { | |
1344 | tr y { | |
1345 | print("( ERROR)"); | |
1346 | } catch (IOE xception e ) { | |
1347 | throw ne w Unchecke dIOExcepti on(e); | |
1348 | } | |
1349 | } | |
1350 | ||
1351 | public void visi tLetExpr(L etExpr tre e) { | |
1352 | tr y { | |
1353 | print("( let " + tr ee.defs + " in " + t ree.expr + ")"); | |
1354 | } catch (IOE xception e ) { | |
1355 | throw ne w Unchecke dIOExcepti on(e); | |
1356 | } | |
1357 | } | |
1358 | ||
1359 | public void visi tModifiers (JCModifie rs mods) { | |
1360 | tr y { | |
1361 | printAnn otations(m ods.annota tions); | |
1362 | printFla gs(mods.fl ags); | |
1363 | } catch (IOE xception e ) { | |
1364 | throw ne w Unchecke dIOExcepti on(e); | |
1365 | } | |
1366 | } | |
1367 | ||
1368 | public void visi tAnnotatio n(JCAnnota tion tree) { | |
1369 | tr y { | |
1370 | print("@ "); | |
1371 | printExp r(tree.ann otationTyp e); | |
1372 | print("( "); | |
1373 | printExp rs(tree.ar gs); | |
1374 | print(") "); | |
1375 | } catch (IOE xception e ) { | |
1376 | throw ne w Unchecke dIOExcepti on(e); | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | public void visi tAnnotated Type(JCAnn otatedType tree) { | |
1381 | tr y { | |
1382 | if (tree .underlyin gType.hasT ag(SELECT) ) { | |
1383 | JCFi eldAccess access = ( JCFieldAcc ess) tree. underlying Type; | |
1384 | prin tExpr(acce ss.selecte d, TreeInf o.postfixP rec); | |
1385 | prin t("."); | |
1386 | prin tTypeAnnot ations(tre e.annotati ons); | |
1387 | prin t(access.n ame); | |
1388 | } else i f (tree.un derlyingTy pe.hasTag( TYPEARRAY) ) { | |
1389 | prin tBaseEleme ntType(tre e); | |
1390 | prin tBrackets( tree); | |
1391 | } else { | |
1392 | prin tTypeAnnot ations(tre e.annotati ons); | |
1393 | prin tExpr(tree .underlyin gType); | |
1394 | } | |
1395 | } catch (IOE xception e ) { | |
1396 | throw ne w Unchecke dIOExcepti on(e); | |
1397 | } | |
1398 | } | |
1399 | ||
1400 | public void visi tTree(JCTr ee tree) { | |
1401 | tr y { | |
1402 | print("( UNKNOWN: " + tree + ")"); | |
1403 | println( ); | |
1404 | } catch (IOE xception e ) { | |
1405 | throw ne w Unchecke dIOExcepti on(e); | |
1406 | } | |
1407 | } | |
1408 | ||
1409 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.