Here you can find the source of getTokenTypes(CommonTree tree)
public static List<Integer> getTokenTypes(CommonTree tree)
//package com.java2s; /*/*from w ww. j a v a 2 s. co m*/ * This file is part of the TSPHP project published under the Apache License 2.0 * For the full copyright and license information, please have a look at LICENSE in the * root folder or visit the project's website http://tsphp.ch/wiki/display/TSPHP/License */ import java.util.ArrayList; import java.util.List; import org.antlr.runtime.tree.CommonTree; public class Main { public static final int DOWN = -2; public static final int UP = -3; private static List<Integer> tokenTypes; public static List<Integer> getTokenTypes(CommonTree tree) { tokenTypes = new ArrayList<>(); generateTokenTypes(tree); return tokenTypes; } private static void generateTokenTypes(CommonTree tree) { int numChildren = tree.getChildCount(); if (numChildren == 0) { tokenTypes.add(tree.token.getType()); } else { if (!tree.isNil()) { tokenTypes.add(DOWN); tokenTypes.add(tree.token.getType()); } for (int i = 0; i < numChildren; i++) { CommonTree t = (CommonTree) tree.getChild(i); generateTokenTypes(t); } if (!tree.isNil()) { tokenTypes.add(UP); } } } }