|
9 | 9 |
|
10 | 10 | import spoon.SpoonException;
|
11 | 11 | import spoon.processing.FactoryAccessor;
|
12 |
| -import spoon.reflect.code.CtBlock; |
13 | 12 | import spoon.reflect.declaration.CtConstructor;
|
14 | 13 | import spoon.reflect.declaration.CtElement;
|
15 | 14 | import spoon.reflect.declaration.CtExecutable;
|
@@ -249,12 +248,27 @@ private static boolean supertypeReachableInInheritanceTree(CtType<?> base, Strin
|
249 | 248 | * @return the input method but with the return type, parameter types and thrown types adapted to
|
250 | 249 | * the context of this type adapter
|
251 | 250 | */
|
252 |
| - @SuppressWarnings("unchecked") |
253 | 251 | public CtMethod<?> adaptMethod(CtMethod<?> inputMethod) {
|
| 252 | + return adaptMethod(inputMethod, true); |
| 253 | + } |
| 254 | + |
| 255 | + @SuppressWarnings("unchecked") |
| 256 | + private CtMethod<?> adaptMethod(CtMethod<?> inputMethod, boolean cloneBody) { |
254 | 257 | if (useLegacyTypeAdaption(inputMethod)) {
|
255 | 258 | return legacyAdaptMethod(inputMethod);
|
256 | 259 | }
|
257 |
| - CtMethod<?> clonedMethod = inputMethod.clone(); |
| 260 | + CtMethod<?> clonedMethod; |
| 261 | + if (cloneBody) { |
| 262 | + clonedMethod = inputMethod.clone(); |
| 263 | + } else { |
| 264 | + clonedMethod = inputMethod.getFactory().createMethod().setSimpleName(inputMethod.getSimpleName()); |
| 265 | + for (CtParameter<?> parameter : inputMethod.getParameters()) { |
| 266 | + clonedMethod.addParameter(parameter.clone()); |
| 267 | + } |
| 268 | + for (CtTypeParameter parameter : inputMethod.getFormalCtTypeParameters()) { |
| 269 | + clonedMethod.addFormalCtTypeParameter(parameter.clone()); |
| 270 | + } |
| 271 | + } |
258 | 272 |
|
259 | 273 | for (int i = 0; i < clonedMethod.getFormalCtTypeParameters().size(); i++) {
|
260 | 274 | CtTypeParameter clonedParameter = clonedMethod.getFormalCtTypeParameters().get(i);
|
@@ -450,13 +464,9 @@ public boolean isOverriding(CtMethod<?> subMethod, CtMethod<?> superMethod) {
|
450 | 464 | if (!isSubtype(subDeclaringType, superDeclaringType.getReference())) {
|
451 | 465 | return false;
|
452 | 466 | }
|
453 |
| - |
454 | 467 | // We don't need to clone the body here, so leave it out
|
455 |
| - CtBlock<?> superBody = superMethod.getBody(); |
456 |
| - superMethod.setBody(null); |
457 | 468 | CtMethod<?> adapted = new TypeAdaptor(subMethod.getDeclaringType())
|
458 |
| - .adaptMethod(superMethod); |
459 |
| - superMethod.setBody(superBody); |
| 469 | + .adaptMethod(superMethod, false); |
460 | 470 |
|
461 | 471 | for (int i = 0; i < subMethod.getParameters().size(); i++) {
|
462 | 472 | CtParameter<?> subParam = subMethod.getParameters().get(i);
|
|
0 commit comments