public TypeMapper(Class<?> classA, Class<?> classB, String... fieldNames) { map = new TreeMap<Integer,Integer>(); Map<Integer,Integer> inverseMap = new TreeMap<Integer,Integer>(); for (String f : fieldNames) { try { int a = classA.getField(f).getInt(null); int b = classB.getField(f).getInt(null); map.put(a, b); inverseMap.put(b, a); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } } inverse = new TypeMapper(inverseMap, this); } public int get(int type) throws NullPointerException {
public CSSTokenRecovery(Lexer lexer, CharStream input, RecognizerSharedState state, CSSLexerState ls, Logger log) { this.lexer = lexer; this.input = input; this.state = state; this.ls = ls; this.log = log; this.expectedToken = new Stack<Integer>(); typeMapper = new CSSToken.TypeMapper(CSSTokenRecovery.class, lexer.getClass(), "APOS", "QUOT", "RPAREN", "RCURLY", "IMPORT", "CHARSET", "STRING", "INVALID_STRING"); }
/** * Creates CSSToken, this is base {@code emit()} constructor * @param input Input stream * @param type Type of token * @param channel Channel of token * @param start Start position in stream * @param stop End position in stream */ public CSSToken(CharStream input, int type, int channel, int start, int stop, Class<? extends Lexer> lexerClass) { super(input, type, channel, start, stop); typeMapper = new TypeMapper(CSSToken.class, lexerClass, "FUNCTION", "URI", "STRING", "CLASSKEYWORD", "HASH"); }