1 2 29 package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify; 30 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 35 36 44 45 public class LiteralResolver { 46 47 private static Map intMap; 48 private static Map nameMap; 49 private static Map classMap; 50 51 static { 52 nameMap = new HashMap (); 53 54 nameMap.put("boolean", new ExternalClass(Boolean.TYPE)); 55 nameMap.put("byte", new ExternalClass(Byte.TYPE)); 56 nameMap.put("char", new ExternalClass(Character.TYPE)); 57 nameMap.put("short", new ExternalClass(Short.TYPE)); 58 nameMap.put("int", new ExternalClass(Integer.TYPE)); 59 nameMap.put("float", new ExternalClass(Float.TYPE)); 60 nameMap.put("long", new ExternalClass(Long.TYPE)); 61 nameMap.put("double", new ExternalClass(Double.TYPE)); 62 63 intMap = new HashMap (); 64 65 intMap.put( 66 new Integer (TokenTypes.LITERAL_BOOLEAN), 67 new ExternalClass(Boolean.TYPE)); 68 intMap.put( 69 new Integer (TokenTypes.LITERAL_BYTE), 70 new ExternalClass(Byte.TYPE)); 71 intMap.put( 72 new Integer (TokenTypes.LITERAL_CHAR), 73 new ExternalClass(Character.TYPE)); 74 intMap.put( 75 new Integer (TokenTypes.LITERAL_SHORT), 76 new ExternalClass(Short.TYPE)); 77 intMap.put( 78 new Integer (TokenTypes.LITERAL_INT), 79 new ExternalClass(Integer.TYPE)); 80 intMap.put( 81 new Integer (TokenTypes.LITERAL_FLOAT), 82 new ExternalClass(Float.TYPE)); 83 intMap.put( 84 new Integer (TokenTypes.LITERAL_LONG), 85 new ExternalClass(Long.TYPE)); 86 intMap.put( 87 new Integer (TokenTypes.LITERAL_DOUBLE), 88 new ExternalClass(Double.TYPE)); 89 intMap.put( 90 new Integer (TokenTypes.STRING_LITERAL), 91 new ExternalClass("".getClass())); 92 93 classMap = new HashMap (); 94 classMap.put( 95 new ExternalClass(Boolean.TYPE), 96 SymTabASTFactory.create(TokenTypes.LITERAL_BOOLEAN, "boolean")); 97 classMap.put( 98 new ExternalClass(Byte.TYPE), 99 SymTabASTFactory.create(TokenTypes.LITERAL_BYTE, "byte")); 100 classMap.put( 101 new ExternalClass(Character.TYPE), 102 SymTabASTFactory.create(TokenTypes.LITERAL_CHAR, "char")); 103 classMap.put( 104 new ExternalClass(Short.TYPE), 105 SymTabASTFactory.create(TokenTypes.LITERAL_SHORT, "short")); 106 classMap.put( 107 new ExternalClass(Integer.TYPE), 108 SymTabASTFactory.create(TokenTypes.LITERAL_INT, "int")); 109 classMap.put( 110 new ExternalClass(Float.TYPE), 111 SymTabASTFactory.create(TokenTypes.LITERAL_FLOAT, "float")); 112 classMap.put( 113 new ExternalClass(Long.TYPE), 114 SymTabASTFactory.create(TokenTypes.LITERAL_LONG, "long")); 115 classMap.put( 116 new ExternalClass(Double.TYPE), 117 SymTabASTFactory.create(TokenTypes.LITERAL_DOUBLE, "double")); 118 119 } 120 121 126 127 public static LiteralResolver getResolver() { 128 return new LiteralResolver(); 129 } 130 131 144 145 public static IClass getDefinition(int literalType) { 146 Integer key = new Integer (literalType); 147 return (IClass) intMap.get(key); 148 } 149 150 public static IClass getDefinition(String name) { 151 return (IClass) nameMap.get(name); 152 } 153 154 public static SymTabAST getASTNode(IClass primitive) { 155 return (SymTabAST) classMap.get(primitive); 156 } 157 } 158 | Popular Tags |