1 /*
2  * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
3  * Use of this file is governed by the BSD 3-clause license that
4  * can be found in the LICENSE.txt file in the project root.
5  */
6 
7 package org.antlr.v4.runtime.atn;
8 
9 import org.antlr.v4.runtime.Lexer;
10 import org.antlr.v4.runtime.misc.MurmurHash;
11 
12 /**
13  * Implements the {@code popMode} lexer action by calling {@link Lexer#popMode}.
14  *
15  * <p>The {@code popMode} command does not have any parameters, so this action is
16  * implemented as a singleton instance exposed by {@link #INSTANCE}.</p>
17  *
18  * @author Sam Harwell
19  * @since 4.2
20  */
21 public final class LexerPopModeAction implements LexerAction {
22 	/**
23 	 * Provides a singleton instance of this parameterless lexer action.
24 	 */
25 	public static final LexerPopModeAction INSTANCE = new LexerPopModeAction();
26 
27 	/**
28 	 * Constructs the singleton instance of the lexer {@code popMode} command.
29 	 */
LexerPopModeAction()30 	private LexerPopModeAction() {
31 	}
32 
33 	/**
34 	 * {@inheritDoc}
35 	 * @return This method returns {@link LexerActionType#POP_MODE}.
36 	 */
37 	@Override
getActionType()38 	public LexerActionType getActionType() {
39 		return LexerActionType.POP_MODE;
40 	}
41 
42 	/**
43 	 * {@inheritDoc}
44 	 * @return This method returns {@code false}.
45 	 */
46 	@Override
isPositionDependent()47 	public boolean isPositionDependent() {
48 		return false;
49 	}
50 
51 	/**
52 	 * {@inheritDoc}
53 	 *
54 	 * <p>This action is implemented by calling {@link Lexer#popMode}.</p>
55 	 */
56 	@Override
execute(Lexer lexer)57 	public void execute(Lexer lexer) {
58 		lexer.popMode();
59 	}
60 
61 	@Override
hashCode()62 	public int hashCode() {
63 		int hash = MurmurHash.initialize();
64 		hash = MurmurHash.update(hash, getActionType().ordinal());
65 		return MurmurHash.finish(hash, 1);
66 	}
67 
68 	@Override
69 	@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
equals(Object obj)70 	public boolean equals(Object obj) {
71 		return obj == this;
72 	}
73 
74 	@Override
toString()75 	public String toString() {
76 		return "popMode";
77 	}
78 }
79