1 13 14 15 package org.aspectj.runtime.reflect; 16 17 import java.lang.reflect.Modifier ; 18 19 class StringMaker { 20 boolean shortTypeNames = true; 21 boolean includeArgs = true; 22 boolean includeThrows = false; 23 boolean includeModifiers = false; 24 boolean shortPrimaryTypeNames = false; 25 26 boolean includeJoinPointTypeName = true; 27 boolean includeEnclosingPoint = true; 28 boolean shortKindName = true; 29 int cacheOffset; 30 31 static StringMaker shortStringMaker; 32 static { 33 shortStringMaker = new StringMaker(); 34 shortStringMaker.shortTypeNames = true; 35 shortStringMaker.includeArgs = false; 36 shortStringMaker.includeThrows = false; 37 shortStringMaker.includeModifiers = false; 38 shortStringMaker.shortPrimaryTypeNames = true; 39 40 shortStringMaker.includeJoinPointTypeName = false; 41 shortStringMaker.includeEnclosingPoint = false; 42 43 shortStringMaker.cacheOffset = 0; 44 } 45 46 static StringMaker middleStringMaker; 47 static { 48 middleStringMaker = new StringMaker(); 49 middleStringMaker.shortTypeNames = true; 50 middleStringMaker.includeArgs = true; 51 middleStringMaker.includeThrows = false; 52 middleStringMaker.includeModifiers = false; 53 middleStringMaker.shortPrimaryTypeNames = false; 54 55 shortStringMaker.cacheOffset = 1; 56 } 57 58 static StringMaker longStringMaker; 59 static { 60 longStringMaker = new StringMaker(); 61 longStringMaker.shortTypeNames = false; 62 longStringMaker.includeArgs = true; 63 longStringMaker.includeThrows = false; 64 longStringMaker.includeModifiers = true; 65 longStringMaker.shortPrimaryTypeNames = false; 66 longStringMaker.shortKindName = false; 67 68 longStringMaker.cacheOffset = 2; 69 } 70 71 String makeKindName(String name) { 72 int dash = name.lastIndexOf('-'); 73 if (dash == -1) return name; 74 return name.substring(dash+1); 75 } 76 77 String makeModifiersString(int modifiers) { 78 if (!includeModifiers) return ""; 79 String str = Modifier.toString(modifiers); 80 if (str.length() == 0) return ""; 81 return str + " "; 82 } 83 84 String stripPackageName(String name) { 85 int dot = name.lastIndexOf('.'); 86 if (dot == -1) return name; 87 return name.substring(dot+1); 88 } 89 90 String makeTypeName(Class type, String typeName, boolean shortName) { 91 if (type == null) return "ANONYMOUS"; 92 if (type.isArray()) { 93 Class componentType = type.getComponentType(); 94 return makeTypeName(componentType, componentType.getName(), shortName) + "[]"; 95 } 96 if (shortName) { 97 return stripPackageName(typeName).replace('$', '.'); 98 } else { 99 return typeName.replace('$', '.'); 100 } 101 } 102 103 public String makeTypeName(Class type) { 104 return makeTypeName(type, type.getName(),shortTypeNames); 105 } 106 107 public String makePrimaryTypeName(Class type, String typeName) { 108 return makeTypeName(type, typeName, shortPrimaryTypeNames); 109 } 110 111 public void addTypeNames(StringBuffer buf, Class [] types) { 112 for (int i = 0; i < types.length; i++) { 113 if (i > 0) buf.append(", "); 114 buf.append(makeTypeName(types[i])); 115 } 116 } 117 118 public void addSignature(StringBuffer buf, Class [] types) { 119 if (types == null) return; 120 if (!includeArgs) { 121 if (types.length == 0) { 122 buf.append("()"); 123 return; 124 } else { 125 buf.append("(..)"); 126 return; 127 } 128 } 129 buf.append("("); 130 addTypeNames(buf, types); 131 buf.append(")"); 132 } 133 134 public void addThrows(StringBuffer buf, Class [] types) { 135 if (!includeThrows || types == null || types.length == 0) return; 136 137 buf.append(" throws "); 138 addTypeNames(buf, types); 139 } 140 } 141 | Popular Tags |