@author Jonathan Feinberg <jdf@pobox.com>
| 10 | * |
| 11 | */ |
| 12 | public class TokenUtil { |
| 13 | private static final String[] tokenNames= new String[200]; |
| 14 | static { |
| 15 | for (int i = 0; i < tokenNames.length; i++) { |
| 16 | tokenNames[i] = "ERROR:" + i; |
| 17 | } |
| 18 | for (final Field f : PdeTokenTypes.class.getDeclaredFields()) { |
| 19 | try { |
| 20 | tokenNames[f.getInt(null)] = f.getName(); |
| 21 | } catch (Exception unexpected) { |
| 22 | throw new RuntimeException(unexpected); |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | public static String nameOf(final AST node) { |
| 28 | return tokenNames[node.getType()]; |
| 29 | } |
| 30 | } |