1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.tools.javafx.tree; |
27 | |
|
28 | |
import java.io.IOException; |
29 | |
import java.io.Writer; |
30 | |
import java.util.HashSet; |
31 | |
|
32 | |
import com.sun.tools.javac.tree.JCTree; |
33 | |
import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
34 | |
import com.sun.tools.javac.tree.JCTree.JCImport; |
35 | |
import com.sun.tools.javac.tree.Pretty; |
36 | |
import com.sun.tools.javac.tree.TreeInfo; |
37 | |
import com.sun.tools.javac.util.Context; |
38 | |
import com.sun.tools.javac.util.Name; |
39 | |
import com.sun.tools.javafx.comp.JavafxDefs; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public class JavaPretty extends Pretty { |
51 | 0 | private HashSet<Name> importedPackages = new HashSet<Name>(); |
52 | 0 | private HashSet<Name> importedClasses = new HashSet<Name>(); |
53 | |
|
54 | |
public JavaPretty(Writer out, boolean sourceOutput, Context context) { |
55 | 0 | super(out, sourceOutput); |
56 | |
|
57 | 0 | JavafxDefs defs = JavafxDefs.instance(context); |
58 | 0 | importedPackages.add(defs.runtimePackageName); |
59 | 0 | importedPackages.add(defs.locationPackageName); |
60 | 0 | importedPackages.add(defs.sequencePackageName); |
61 | 0 | importedPackages.add(defs.functionsPackageName); |
62 | 0 | importedPackages.add(defs.javaLangPackageName); |
63 | 0 | } |
64 | |
|
65 | |
public void visitBlockExpression(JFXBlockExpression tree) { |
66 | 0 | visitBlockExpression(this, tree); |
67 | 0 | } |
68 | |
|
69 | |
public static void visitBlockExpression(Pretty pretty, JFXBlockExpression tree) { |
70 | |
try { |
71 | 0 | pretty.printFlags(tree.flags); |
72 | 0 | pretty.print("{"); |
73 | 0 | pretty.println(); |
74 | 0 | pretty.indent(); |
75 | 0 | pretty.printStats(tree.stats); |
76 | 0 | if (tree.value != null) { |
77 | 0 | pretty.align(); |
78 | 0 | pretty.printExpr(tree.value); |
79 | |
} |
80 | 0 | pretty.undent(); |
81 | 0 | pretty.println(); |
82 | 0 | pretty.align(); |
83 | 0 | pretty.print("}"); |
84 | 0 | } catch (IOException e) { |
85 | 0 | throw new UncheckedIOException(e); |
86 | 0 | } |
87 | 0 | } |
88 | |
|
89 | |
@Override |
90 | |
public void visitImport(JCImport tree) { |
91 | 0 | super.visitImport(tree); |
92 | |
|
93 | |
|
94 | 0 | Name name = TreeInfo.name(tree.qualid); |
95 | 0 | if (name == name.table.asterisk) |
96 | 0 | if (tree.qualid.getTag() == JCTree.SELECT) |
97 | 0 | importedPackages.add(TreeInfo.fullName(((JCFieldAccess) tree.qualid).selected)); |
98 | |
else; |
99 | |
else |
100 | 0 | importedClasses.add(TreeInfo.fullName(tree.qualid)); |
101 | 0 | } |
102 | |
|
103 | |
@Override |
104 | |
public void visitSelect(JCFieldAccess tree) { |
105 | |
try { |
106 | 0 | if (!importedPackages.contains(TreeInfo.fullName(tree.selected)) |
107 | |
&& !importedClasses.contains(TreeInfo.fullName(tree))) { |
108 | 0 | printExpr(tree.selected, TreeInfo.postfixPrec); |
109 | 0 | print("."); |
110 | |
} |
111 | 0 | print(tree.name); |
112 | 0 | } catch (IOException e) { |
113 | 0 | throw new UncheckedIOException(e); |
114 | 0 | } |
115 | 0 | } |
116 | |
} |