HHH-12334 ASTUtil improvements in Map usage

This commit is contained in:
Sanne Grinovero 2018-03-01 13:45:37 +00:00
parent 5806d6639a
commit c3e5390048
2 changed files with 5 additions and 5 deletions

View File

@ -24,7 +24,7 @@ import antlr.collections.AST;
* @author Steve Ebersole
*/
public class ASTPrinter {
private final Map tokenTypeNameCache;
private final Map<Integer,String> tokenTypeNameCache;
private final boolean showClassNames;
/**
@ -54,7 +54,7 @@ public class ASTPrinter {
this( ASTUtil.generateTokenNameCache( tokenTypeConstants ), showClassNames );
}
private ASTPrinter(Map tokenTypeNameCache, boolean showClassNames) {
private ASTPrinter(Map<Integer,String> tokenTypeNameCache, boolean showClassNames) {
this.tokenTypeNameCache = tokenTypeNameCache;
this.showClassNames = showClassNames;
}
@ -119,7 +119,7 @@ public class ASTPrinter {
final Integer typeInteger = type;
String value = null;
if ( tokenTypeNameCache != null ) {
value = (String) tokenTypeNameCache.get( typeInteger );
value = tokenTypeNameCache.get( typeInteger );
}
if ( value == null ) {
value = typeInteger.toString();

View File

@ -389,13 +389,13 @@ public final class ASTUtil {
*
* @return The generated map.
*/
public static Map generateTokenNameCache(Class tokenTypeInterface) {
public static Map<Integer,String> generateTokenNameCache(Class tokenTypeInterface) {
final Field[] fields = tokenTypeInterface.getFields();
Map cache = new HashMap( (int) ( fields.length * .75 ) + 1 );
for ( final Field field : fields ) {
if ( Modifier.isStatic( field.getModifiers() ) ) {
try {
cache.put( field.get( null ), field.getName() );
cache.put( Integer.valueOf( field.getInt( null ) ), field.getName() );
}
catch (Throwable ignore) {
}