1 /*
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
118
119 if (exceptionTypes.length > 0) {
120 StringJoiner joiner = new StringJoiner(",", " throws ", "");
121 for (Class<?> exceptionType : exceptionTypes) {
122 joiner.add(exceptionType.getTypeName());
123 }
124 sb.append(joiner.toString());
125 }
126 return sb.toString();
127 } catch (Exception e) {
128 return "<" + e + ">";
129 }
130 }
131
132 /**
133 * Generate toString header information specific to a method or
134 * constructor.
135 */
136 abstract void specificToStringHeader(StringBuilder sb);
137
138 String sharedToGenericString(int modifierMask, boolean isDefault) {
139 try {
140 StringBuilder sb = new StringBuilder();
141
142 printModifiersIfNonzero(sb, modifierMask, isDefault);
143
144 TypeVariable<?>[] typeparms = getTypeParameters();
145 if (typeparms.length > 0) {
146 StringJoiner sj = new StringJoiner(",", "<", "> ");
147 for(TypeVariable<?> typeparm: typeparms) {
148 sj.add(typeparm.getTypeName());
149 }
150 sb.append(sj.toString());
151 }
152
153 specificToGenericStringHeader(sb);
154
155 sb.append('(');
156 StringJoiner sj = new StringJoiner(",");
157 Type[] params = getGenericParameterTypes();
158 for (int j = 0; j < params.length; j++) {
159 String param = params[j].getTypeName();
160 if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
161 param = param.replaceFirst("\\[\\]$", "...");
162 sj.add(param);
163 }
164 sb.append(sj.toString());
165 sb.append(')');
166
167 Type[] exceptionTypes = getGenericExceptionTypes();
168 if (exceptionTypes.length > 0) {
|
1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
118
119 if (exceptionTypes.length > 0) {
120 StringJoiner joiner = new StringJoiner(",", " throws ", "");
121 for (Class<?> exceptionType : exceptionTypes) {
122 joiner.add(exceptionType.getTypeName());
123 }
124 sb.append(joiner.toString());
125 }
126 return sb.toString();
127 } catch (Exception e) {
128 return "<" + e + ">";
129 }
130 }
131
132 /**
133 * Generate toString header information specific to a method or
134 * constructor.
135 */
136 abstract void specificToStringHeader(StringBuilder sb);
137
138 String typeVarBounds(TypeVariable<?> typeVar) {
139 Type[] bounds = typeVar.getBounds();
140 if (bounds.length == 1 && bounds[0].equals(Object.class)) {
141 return typeVar.getName();
142 } else {
143 StringJoiner sj = new StringJoiner(" & ");
144 for (Type bound : bounds) {
145 sj.add(bound.getTypeName());
146 }
147 return typeVar.getName() + " extends " + sj.toString();
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 StringJoiner sj = new StringJoiner(",", "<", "> ");
160 for(TypeVariable<?> typeparm: typeparms) {
161 sj.add(typeVarBounds(typeparm));
162 }
163 sb.append(sj.toString());
164 }
165
166 specificToGenericStringHeader(sb);
167
168 sb.append('(');
169 StringJoiner sj = new StringJoiner(",");
170 Type[] params = getGenericParameterTypes();
171 for (int j = 0; j < params.length; j++) {
172 String param = params[j].getTypeName();
173 if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
174 param = param.replaceFirst("\\[\\]$", "...");
175 sj.add(param);
176 }
177 sb.append(sj.toString());
178 sb.append(')');
179
180 Type[] exceptionTypes = getGenericExceptionTypes();
181 if (exceptionTypes.length > 0) {
|