96 sb.append(Modifier.toString(access_mod)).append(' '); 97 if (isDefault) 98 sb.append("default "); 99 mod = (mod & ~Modifier.ACCESS_MODIFIERS); 100 if (mod != 0) 101 sb.append(Modifier.toString(mod)).append(' '); 102 } 103 } 104 105 String sharedToString(int modifierMask, 106 boolean isDefault, 107 Class<?>[] parameterTypes, 108 Class<?>[] exceptionTypes) { 109 try { 110 StringBuilder sb = new StringBuilder(); 111 112 printModifiersIfNonzero(sb, modifierMask, isDefault); 113 specificToStringHeader(sb); 114 sb.append('('); 115 116 sb.append(Stream.of(parameterTypes).map(Type::getTypeName). 117 collect(Collectors.joining(","))); 118 119 sb.append(')'); 120 121 if (exceptionTypes.length > 0) { 122 sb.append(Stream.of(exceptionTypes).map(Type::getTypeName). 123 collect(Collectors.joining(",", " throws ", ""))); 124 } 125 return sb.toString(); 126 } catch (Exception e) { 127 return "<" + e + ">"; 128 } 129 } 130 131 /** 132 * Generate toString header information specific to a method or 133 * constructor. 134 */ 135 abstract void specificToStringHeader(StringBuilder sb); 136 137 static String typeVarBounds(TypeVariable<?> typeVar) { 138 Type[] bounds = typeVar.getBounds(); 139 if (bounds.length == 1 && bounds[0].equals(Object.class)) { 140 return typeVar.getName(); 141 } else { 142 return typeVar.getName() + " extends " + 143 Stream.of(bounds).map(Type::getTypeName). 144 collect(Collectors.joining(" & ")); 145 } 146 } 147 148 String sharedToGenericString(int modifierMask, boolean isDefault) { 149 try { 150 StringBuilder sb = new StringBuilder(); 151 152 printModifiersIfNonzero(sb, modifierMask, isDefault); 153 154 TypeVariable<?>[] typeparms = getTypeParameters(); 155 if (typeparms.length > 0) { 156 sb.append(Stream.of(typeparms).map(Executable::typeVarBounds). 157 collect(Collectors.joining(",", "<", "> "))); 158 } 159 160 specificToGenericStringHeader(sb); 161 162 sb.append('('); 163 StringJoiner sj = new StringJoiner(","); 164 Type[] params = getGenericParameterTypes(); 165 for (int j = 0; j < params.length; j++) { 166 String param = params[j].getTypeName(); 167 if (isVarArgs() && (j == params.length - 1)) // replace T[] with T... 168 param = param.replaceFirst("\\[\\]$", "..."); 169 sj.add(param); 170 } 171 sb.append(sj.toString()); 172 sb.append(')'); 173 174 Type[] exceptionTypes = getGenericExceptionTypes(); 175 if (exceptionTypes.length > 0) { 176 sb.append(Stream.of(exceptionTypes).map(Type::getTypeName). 177 collect(Collectors.joining(",", " throws ", ""))); 178 } 179 return sb.toString(); 180 } catch (Exception e) { 181 return "<" + e + ">"; 182 } 183 } 184 185 /** 186 * Generate toGenericString header information specific to a 187 * method or constructor. 188 */ 189 abstract void specificToGenericStringHeader(StringBuilder sb); 190 191 /** 192 * Returns the {@code Class} object representing the class or interface 193 * that declares the executable represented by this object. 194 */ 195 public abstract Class<?> getDeclaringClass(); 196 197 /** | 96 sb.append(Modifier.toString(access_mod)).append(' '); 97 if (isDefault) 98 sb.append("default "); 99 mod = (mod & ~Modifier.ACCESS_MODIFIERS); 100 if (mod != 0) 101 sb.append(Modifier.toString(mod)).append(' '); 102 } 103 } 104 105 String sharedToString(int modifierMask, 106 boolean isDefault, 107 Class<?>[] parameterTypes, 108 Class<?>[] exceptionTypes) { 109 try { 110 StringBuilder sb = new StringBuilder(); 111 112 printModifiersIfNonzero(sb, modifierMask, isDefault); 113 specificToStringHeader(sb); 114 sb.append('('); 115 116 sb.append(Arrays.stream(parameterTypes) 117 .map(Type::getTypeName) 118 .collect(Collectors.joining(","))); 119 120 sb.append(')'); 121 122 if (exceptionTypes.length > 0) { 123 sb.append(Arrays.stream(exceptionTypes) 124 .map(Type::getTypeName) 125 .collect(Collectors.joining(",", " throws ", ""))); 126 } 127 return sb.toString(); 128 } catch (Exception e) { 129 return "<" + e + ">"; 130 } 131 } 132 133 /** 134 * Generate toString header information specific to a method or 135 * constructor. 136 */ 137 abstract void specificToStringHeader(StringBuilder sb); 138 139 static String typeVarBounds(TypeVariable<?> typeVar) { 140 Type[] bounds = typeVar.getBounds(); 141 if (bounds.length == 1 && bounds[0].equals(Object.class)) { 142 return typeVar.getName(); 143 } else { 144 return typeVar.getName() + " extends " + 145 Arrays.stream(bounds) 146 .map(Type::getTypeName) 147 .collect(Collectors.joining(" & ")); 148 } 149 } 150 151 String sharedToGenericString(int modifierMask, boolean isDefault) { 152 try { 153 StringBuilder sb = new StringBuilder(); 154 155 printModifiersIfNonzero(sb, modifierMask, isDefault); 156 157 TypeVariable<?>[] typeparms = getTypeParameters(); 158 if (typeparms.length > 0) { 159 sb.append(Arrays.stream(typeparms) 160 .map(Executable::typeVarBounds) 161 .collect(Collectors.joining(",", "<", "> "))); 162 } 163 164 specificToGenericStringHeader(sb); 165 166 sb.append('('); 167 StringJoiner sj = new StringJoiner(","); 168 Type[] params = getGenericParameterTypes(); 169 for (int j = 0; j < params.length; j++) { 170 String param = params[j].getTypeName(); 171 if (isVarArgs() && (j == params.length - 1)) // replace T[] with T... 172 param = param.replaceFirst("\\[\\]$", "..."); 173 sj.add(param); 174 } 175 sb.append(sj.toString()); 176 sb.append(')'); 177 178 Type[] exceptionTypes = getGenericExceptionTypes(); 179 if (exceptionTypes.length > 0) { 180 sb.append(Arrays.stream(exceptionTypes) 181 .map(Type::getTypeName) 182 .collect(Collectors.joining(",", " throws ", ""))); 183 } 184 return sb.toString(); 185 } catch (Exception e) { 186 return "<" + e + ">"; 187 } 188 } 189 190 /** 191 * Generate toGenericString header information specific to a 192 * method or constructor. 193 */ 194 abstract void specificToGenericStringHeader(StringBuilder sb); 195 196 /** 197 * Returns the {@code Class} object representing the class or interface 198 * that declares the executable represented by this object. 199 */ 200 public abstract Class<?> getDeclaringClass(); 201 202 /** |