1 /* |
1 /* |
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
109 try { |
109 try { |
110 StringBuilder sb = new StringBuilder(); |
110 StringBuilder sb = new StringBuilder(); |
111 |
111 |
112 printModifiersIfNonzero(sb, modifierMask, isDefault); |
112 printModifiersIfNonzero(sb, modifierMask, isDefault); |
113 specificToStringHeader(sb); |
113 specificToStringHeader(sb); |
114 sb.append('('); |
114 sb.append(Arrays.stream(parameterTypes) |
115 |
115 .map(Type::getTypeName) |
116 sb.append(Stream.of(parameterTypes).map(Type::getTypeName). |
116 .collect(Collectors.joining(",", "(", ")"))); |
117 collect(Collectors.joining(","))); |
|
118 |
|
119 sb.append(')'); |
|
120 |
|
121 if (exceptionTypes.length > 0) { |
117 if (exceptionTypes.length > 0) { |
122 sb.append(Stream.of(exceptionTypes).map(Type::getTypeName). |
118 sb.append(Arrays.stream(exceptionTypes) |
123 collect(Collectors.joining(",", " throws ", ""))); |
119 .map(Type::getTypeName) |
|
120 .collect(Collectors.joining(",", " throws ", ""))); |
124 } |
121 } |
125 return sb.toString(); |
122 return sb.toString(); |
126 } catch (Exception e) { |
123 } catch (Exception e) { |
127 return "<" + e + ">"; |
124 return "<" + e + ">"; |
128 } |
125 } |
138 Type[] bounds = typeVar.getBounds(); |
135 Type[] bounds = typeVar.getBounds(); |
139 if (bounds.length == 1 && bounds[0].equals(Object.class)) { |
136 if (bounds.length == 1 && bounds[0].equals(Object.class)) { |
140 return typeVar.getName(); |
137 return typeVar.getName(); |
141 } else { |
138 } else { |
142 return typeVar.getName() + " extends " + |
139 return typeVar.getName() + " extends " + |
143 Stream.of(bounds).map(Type::getTypeName). |
140 Arrays.stream(bounds) |
144 collect(Collectors.joining(" & ")); |
141 .map(Type::getTypeName) |
|
142 .collect(Collectors.joining(" & ")); |
145 } |
143 } |
146 } |
144 } |
147 |
145 |
148 String sharedToGenericString(int modifierMask, boolean isDefault) { |
146 String sharedToGenericString(int modifierMask, boolean isDefault) { |
149 try { |
147 try { |
151 |
149 |
152 printModifiersIfNonzero(sb, modifierMask, isDefault); |
150 printModifiersIfNonzero(sb, modifierMask, isDefault); |
153 |
151 |
154 TypeVariable<?>[] typeparms = getTypeParameters(); |
152 TypeVariable<?>[] typeparms = getTypeParameters(); |
155 if (typeparms.length > 0) { |
153 if (typeparms.length > 0) { |
156 sb.append(Stream.of(typeparms).map(Executable::typeVarBounds). |
154 sb.append(Arrays.stream(typeparms) |
157 collect(Collectors.joining(",", "<", "> "))); |
155 .map(Executable::typeVarBounds) |
|
156 .collect(Collectors.joining(",", "<", "> "))); |
158 } |
157 } |
159 |
158 |
160 specificToGenericStringHeader(sb); |
159 specificToGenericStringHeader(sb); |
161 |
160 |
162 sb.append('('); |
161 sb.append('('); |
171 sb.append(sj.toString()); |
170 sb.append(sj.toString()); |
172 sb.append(')'); |
171 sb.append(')'); |
173 |
172 |
174 Type[] exceptionTypes = getGenericExceptionTypes(); |
173 Type[] exceptionTypes = getGenericExceptionTypes(); |
175 if (exceptionTypes.length > 0) { |
174 if (exceptionTypes.length > 0) { |
176 sb.append(Stream.of(exceptionTypes).map(Type::getTypeName). |
175 sb.append(Arrays.stream(exceptionTypes) |
177 collect(Collectors.joining(",", " throws ", ""))); |
176 .map(Type::getTypeName) |
|
177 .collect(Collectors.joining(",", " throws ", ""))); |
178 } |
178 } |
179 return sb.toString(); |
179 return sb.toString(); |
180 } catch (Exception e) { |
180 } catch (Exception e) { |
181 return "<" + e + ">"; |
181 return "<" + e + ">"; |
182 } |
182 } |