Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JFXTree |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 | * | |
5 | * This code is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License version 2 only, as | |
7 | * published by the Free Software Foundation. Sun designates this | |
8 | * particular file as subject to the "Classpath" exception as provided | |
9 | * by Sun in the LICENSE file that accompanied this code. | |
10 | * | |
11 | * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | * version 2 for more details (a copy is included in the LICENSE file that | |
15 | * accompanied this code). | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License version | |
18 | * 2 along with this work; if not, write to the Free Software Foundation, | |
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 | * | |
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 | |
23 | * have any questions. | |
24 | */ | |
25 | ||
26 | package com.sun.tools.javafx.tree; | |
27 | ||
28 | import com.sun.javafx.api.tree.JavaFXTree; | |
29 | import com.sun.javafx.api.tree.JavaFXTreeVisitor; | |
30 | import com.sun.tools.javac.tree.JCTree; | |
31 | import com.sun.tools.javac.tree.JCTree.Visitor; | |
32 | ||
33 | import com.sun.source.tree.TreeVisitor; | |
34 | import java.io.IOException; | |
35 | import java.io.StringWriter; | |
36 | import java.util.Map; | |
37 | ||
38 | /** | |
39 | * The base of the JavaFX AST | |
40 | * well... except for things like statement which (at least for now) have to be subclassed | |
41 | * off other parts of the JCTree. | |
42 | */ | |
43 | public abstract class JFXTree extends JCTree implements JavaFXTree { | |
44 | ||
45 | /** Initialize tree with given tag. | |
46 | */ | |
47 | 246 | protected JFXTree() { |
48 | 246 | } |
49 | ||
50 | public abstract void accept(JavafxVisitor v); | |
51 | ||
52 | @Override | |
53 | public void accept(Visitor v) { | |
54 | 1061 | if (v instanceof JavafxVisitor) { |
55 | 1061 | this.accept((JavafxVisitor)v); |
56 | } else { | |
57 | 0 | v.visitTree(this); |
58 | } | |
59 | 1061 | } |
60 | ||
61 | // stuff to ignore | |
62 | ||
63 | public Kind getKind() { | |
64 | 0 | return Kind.OTHER; |
65 | } | |
66 | ||
67 | @Override | |
68 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { | |
69 | 0 | if (v instanceof JavaFXTreeVisitor) { |
70 | 0 | return (R)this.accept((JavaFXTreeVisitor)v, d); |
71 | } else { | |
72 | 0 | throw new UnsupportedOperationException(getClass().getSimpleName() + " support not implemented"); |
73 | } | |
74 | } | |
75 | ||
76 | @SuppressWarnings("unchecked") | |
77 | public static <T> java.util.List<T> convertList(Class<T> klass, com.sun.tools.javac.util.List<?> list) { | |
78 | 1340 | if (list == null) |
79 | 0 | return null; |
80 | 1340 | for (Object o : list) |
81 | 1399 | klass.cast(o); |
82 | 1340 | return (java.util.List<T>)list; |
83 | } | |
84 | ||
85 | /** Convert a tree to a pretty-printed string. */ | |
86 | @Override | |
87 | public String toString() { | |
88 | 0 | StringWriter s = new StringWriter(); |
89 | try { | |
90 | 0 | new JavafxPretty(s, false).printExpr(this); |
91 | } | |
92 | 0 | catch (IOException e) { |
93 | // should never happen, because StringWriter is defined | |
94 | // never to throw any IOExceptions | |
95 | 0 | throw new AssertionError(e); |
96 | 0 | } |
97 | 0 | return s.toString(); |
98 | } | |
99 | ||
100 | @Override | |
101 | public int getStartPosition() { | |
102 | 199 | return JavafxTreeInfo.getStartPos(this); |
103 | } | |
104 | ||
105 | @Override | |
106 | public int getEndPosition(Map<JCTree, Integer> endPosTable) { | |
107 | 0 | return JavafxTreeInfo.getEndPos(this, endPosTable); |
108 | } | |
109 | ||
110 | } |