From e880a0f45efc8e6bdfe5c183361f167abcd114eb Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Wed, 21 Jun 2017 15:59:28 +0200 Subject: [PATCH 01/11] Create a unit test to expose #1407 --- .../spoon/test/generics/GenericsTest.java | 21 +++++++++++++++++++ .../generics/testclasses/SameSignature.java | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/test/java/spoon/test/generics/testclasses/SameSignature.java diff --git a/src/test/java/spoon/test/generics/GenericsTest.java b/src/test/java/spoon/test/generics/GenericsTest.java index a7bb8fea7cd..34be80f9c2b 100644 --- a/src/test/java/spoon/test/generics/GenericsTest.java +++ b/src/test/java/spoon/test/generics/GenericsTest.java @@ -49,6 +49,7 @@ import spoon.test.generics.testclasses.Orange; import spoon.test.generics.testclasses.Paella; import spoon.test.generics.testclasses.Panini; +import spoon.test.generics.testclasses.SameSignature; import spoon.test.generics.testclasses.Spaghetti; import spoon.test.generics.testclasses.Tacos; import spoon.testing.utils.ModelUtils; @@ -1094,4 +1095,24 @@ public void testGetDeclarationOfTypeParameterReference() { assertSame(innerTotoFormatCtType.get(0), paramInnerToto.getDeclaration()); assertSame(innerTypeParametersList.get(0), returnInnerToto.getDeclaration()); } + + @Test + public void testIsSameSignatureWithGenerics() { + Launcher launcher = new Launcher(); + launcher.addInputResource("./src/test/java/spoon/test/generics/testclasses/SameSignature.java"); + launcher.buildModel(); + + CtClass ctClass = launcher.getFactory().Class().get(SameSignature.class); + + List methods = ctClass.getMethodsByName("forEach"); + assertEquals(1, methods.size()); + + CtType iterableItf = launcher.getFactory().Type().get(Iterable.class); + + List> methodsItf = iterableItf.getMethodsByName("forEach"); + assertEquals(1, methodsItf.size()); + + ClassTypingContext ctc = new ClassTypingContext(ctClass.getReference()); + assertTrue(ctc.isSameSignature(methods.get(0), methodsItf.get(0))); + } } diff --git a/src/test/java/spoon/test/generics/testclasses/SameSignature.java b/src/test/java/spoon/test/generics/testclasses/SameSignature.java new file mode 100644 index 00000000000..1ce91d21b9a --- /dev/null +++ b/src/test/java/spoon/test/generics/testclasses/SameSignature.java @@ -0,0 +1,19 @@ +package spoon.test.generics.testclasses; + +import java.util.Iterator; +import java.util.function.Consumer; + +/** + * Created by urli on 21/06/2017. + */ +public class SameSignature implements Iterable { + @Override + public Iterator iterator() { + return null; + } + + @Override + public void forEach(Consumer action) { + + } +} From 7992304e6ed78419820fb5e65321a7a02e2b92a1 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Wed, 21 Jun 2017 16:32:19 +0200 Subject: [PATCH 02/11] Explicit the test --- src/test/java/spoon/test/generics/GenericsTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/spoon/test/generics/GenericsTest.java b/src/test/java/spoon/test/generics/GenericsTest.java index 34be80f9c2b..be0079d1ada 100644 --- a/src/test/java/spoon/test/generics/GenericsTest.java +++ b/src/test/java/spoon/test/generics/GenericsTest.java @@ -1113,6 +1113,9 @@ public void testIsSameSignatureWithGenerics() { assertEquals(1, methodsItf.size()); ClassTypingContext ctc = new ClassTypingContext(ctClass.getReference()); - assertTrue(ctc.isSameSignature(methods.get(0), methodsItf.get(0))); + assertTrue(ctc.isOverriding(methods.get(0), methodsItf.get(0))); + assertTrue(ctc.isSubSignature(methods.get(0), methodsItf.get(0))); + + // assertTrue(ctc.isSameSignature(methods.get(0), methodsItf.get(0))); } } From 400221a467914efbdf52285cc98988b1787be608 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Wed, 21 Jun 2017 21:42:25 +0200 Subject: [PATCH 03/11] fix creation of TypeParameterReference by java reflection --- .../support/visitor/java/JavaReflectionTreeBuilder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/spoon/support/visitor/java/JavaReflectionTreeBuilder.java b/src/main/java/spoon/support/visitor/java/JavaReflectionTreeBuilder.java index e380bbbed68..3f410c13920 100644 --- a/src/main/java/spoon/support/visitor/java/JavaReflectionTreeBuilder.java +++ b/src/main/java/spoon/support/visitor/java/JavaReflectionTreeBuilder.java @@ -329,7 +329,12 @@ public void visitTypeParameterReference(TypeVaria @Override public void visitType(Type type) { - final CtTypeReference ctTypeReference = factory.Core().createTypeReference(); + CtTypeReference ctTypeReference; + if (type instanceof TypeVariable) { + ctTypeReference = factory.Core().createTypeParameterReference(); + } else { + ctTypeReference = factory.Core().createTypeReference(); + } enter(new TypeReferenceRuntimeBuilderContext(ctTypeReference)); ctTypeReference.setSimpleName(getTypeName(type)); From efa7f2fdd563c188b2db04efaa21dd68cd38310c Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Wed, 21 Jun 2017 21:45:57 +0200 Subject: [PATCH 04/11] fix: do not adapt boundingType of typeParamReference --- .../java/spoon/support/visitor/AbstractTypingContext.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/spoon/support/visitor/AbstractTypingContext.java b/src/main/java/spoon/support/visitor/AbstractTypingContext.java index 46d99826181..ca330ccf685 100644 --- a/src/main/java/spoon/support/visitor/AbstractTypingContext.java +++ b/src/main/java/spoon/support/visitor/AbstractTypingContext.java @@ -71,9 +71,11 @@ private CtTypeReference adaptTypeParameterReference(CtTypeParameterReference return adaptTypeParameterReferenceBoundingType(typeParamRef, typeParamRef.getBoundingType()); } CtTypeReference typeRefAdapted = adaptTypeParameter(typeParamRef.getDeclaration()); - if (typeRefAdapted instanceof CtTypeParameterReference) { - return adaptTypeParameterReferenceBoundingType((CtTypeParameterReference) typeRefAdapted, typeParamRef.getBoundingType()); - } + //Do not adapt bounding type of TypeParameterReference. That bounding type is already adapted as part of typeParamRef adaptation + //... at least in case of GenericsTest#testIsSameSignatureWithGenerics of Iterator +// if (typeRefAdapted instanceof CtTypeParameterReference) { +// return adaptTypeParameterReferenceBoundingType((CtTypeParameterReference) typeRefAdapted, typeParamRef.getBoundingType()); +// } return typeRefAdapted; } From 1a1564c3bad034514836688e3466da4ebbcc0f5f Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Wed, 21 Jun 2017 22:45:16 +0200 Subject: [PATCH 05/11] short test which reproduces problem found by MainTest.testMain --- .../java/spoon/test/generics/GenericsTest.java | 14 ++++++++++++++ .../spoon/test/generics/testclasses/EnumSetOf.java | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/test/java/spoon/test/generics/testclasses/EnumSetOf.java diff --git a/src/test/java/spoon/test/generics/GenericsTest.java b/src/test/java/spoon/test/generics/GenericsTest.java index be0079d1ada..7b6faf83715 100644 --- a/src/test/java/spoon/test/generics/GenericsTest.java +++ b/src/test/java/spoon/test/generics/GenericsTest.java @@ -14,6 +14,7 @@ import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtField; import spoon.reflect.declaration.CtInterface; import spoon.reflect.declaration.CtMethod; @@ -43,6 +44,7 @@ import spoon.test.generics.testclasses.Banana; import spoon.test.generics.testclasses.CelebrationLunch; import spoon.test.generics.testclasses.CelebrationLunch.WeddingLunch; +import spoon.test.generics.testclasses.EnumSetOf; import spoon.test.generics.testclasses.FakeTpl; import spoon.test.generics.testclasses.Lunch; import spoon.test.generics.testclasses.Mole; @@ -1118,4 +1120,16 @@ public void testIsSameSignatureWithGenerics() { // assertTrue(ctc.isSameSignature(methods.get(0), methodsItf.get(0))); } + @Test + public void testGetExecDeclarationOfEnumSetOf() { + Launcher launcher = new Launcher(); + launcher.addInputResource("./src/test/java/spoon/test/generics/testclasses/EnumSetOf.java"); + launcher.buildModel(); + + CtClass ctClass = launcher.getFactory().Class().get(EnumSetOf.class); + + CtInvocation invocation = ctClass.getMethodsByName("m").get(0).getBody().getStatement(0); + CtExecutable decl = invocation.getExecutable().getDeclaration(); + assertNotNull(decl); + } } diff --git a/src/test/java/spoon/test/generics/testclasses/EnumSetOf.java b/src/test/java/spoon/test/generics/testclasses/EnumSetOf.java new file mode 100644 index 00000000000..7234206409c --- /dev/null +++ b/src/test/java/spoon/test/generics/testclasses/EnumSetOf.java @@ -0,0 +1,13 @@ +package spoon.test.generics.testclasses; + +import java.util.EnumSet; + +import spoon.reflect.declaration.ModifierKind; + +public class EnumSetOf { + + public void m() { + EnumSet.of(ModifierKind.STATIC); + } + +} From d87dd2838841f34aedeb123178b029a43f9b4302 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Mon, 26 Jun 2017 16:23:15 +0200 Subject: [PATCH 06/11] Change to get the proper type declaration in CtExecutableReference. Add a new convention in ReferenceBuilder to only check 2 levels in case of reflexive type parameter like E extends Enum: it will only get E -> Enum -> E. --- .../spoon/support/compiler/jdt/ReferenceBuilder.java | 9 ++++++++- .../reflect/reference/CtExecutableReferenceImpl.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java index 3e81dbc25db..44a10645ea3 100644 --- a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java @@ -632,6 +632,7 @@ CtTypeReference getTypeReference(TypeBinding binding) { ref = getTypeReference(binding.actualType()); } else { ref = this.jdtTreeBuilder.getFactory().Core().createTypeReference(); + this.exploringParameterizedBindings.put(binding, ref); if (binding.isAnonymousType()) { ref.setSimpleName(""); } else { @@ -702,7 +703,13 @@ CtTypeReference getTypeReference(TypeBinding binding) { // if the type parameter has a super class other than java.lang.Object, we get it // superClass.superclass() is null if it's java.lang.Object if (superClass != null && !(superClass.superclass() == null)) { - refSuperClass = this.getTypeReference(superClass); + + // this case could happen with Enum> for example: + // in that case we only want to have E -> Enum -> E + // to conserve the same behavior as JavaReflectionTreeBuilder + if (!this.exploringParameterizedBindings.containsKey(superClass)) { + refSuperClass = this.getTypeReference(superClass); + } // if the type parameter has a super interface, then we'll get it too, as a superclass // type parameter can only extends an interface or a class, so we don't make the distinction diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 94d6a336e60..60fbf08e0d0 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -145,7 +145,7 @@ public boolean isConstructor() { @SuppressWarnings("unchecked") public CtExecutable getDeclaration() { final CtTypeReference typeRef = getDeclaringType(); - return typeRef == null ? null : getCtExecutable(typeRef.getDeclaration()); + return typeRef == null ? null : getCtExecutable(typeRef.getTypeDeclaration()); } @Override From f9d5dae6d5724a10c800401d8dd42a26563b9886 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Mon, 26 Jun 2017 16:59:17 +0200 Subject: [PATCH 07/11] Change the tests to respect the new specification --- .../spoon/support/compiler/jdt/ReferenceBuilder.java | 2 +- .../reflect/reference/CtExecutableReferenceImpl.java | 12 +++++++++++- .../reflect/declaration/UnknownDeclarationTest.java | 8 +++++++- src/test/java/spoon/test/filters/FilterTest.java | 4 +++- .../reference/ExecutableReferenceGenericTest.java | 5 ++++- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java index 44a10645ea3..d7797f1bb02 100644 --- a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java @@ -707,7 +707,7 @@ CtTypeReference getTypeReference(TypeBinding binding) { // this case could happen with Enum> for example: // in that case we only want to have E -> Enum -> E // to conserve the same behavior as JavaReflectionTreeBuilder - if (!this.exploringParameterizedBindings.containsKey(superClass)) { + if (!(superClass instanceof ParameterizedTypeBinding) || !this.exploringParameterizedBindings.containsKey(superClass)) { refSuperClass = this.getTypeReference(superClass); } diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 60fbf08e0d0..ce974eab776 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -30,6 +30,7 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; import spoon.reflect.visitor.filter.NameFilter; +import spoon.support.SpoonClassNotFoundException; import spoon.support.reflect.declaration.CtElementImpl; import spoon.support.util.RtHelper; import spoon.support.visitor.ClassTypingContext; @@ -145,7 +146,16 @@ public boolean isConstructor() { @SuppressWarnings("unchecked") public CtExecutable getDeclaration() { final CtTypeReference typeRef = getDeclaringType(); - return typeRef == null ? null : getCtExecutable(typeRef.getTypeDeclaration()); + if (typeRef == null) { + return null; + } + + try { + return getCtExecutable(typeRef.getTypeDeclaration()); + } catch (SpoonClassNotFoundException e) { + return null; + } + } @Override diff --git a/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java b/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java index dae109b392f..68dc31cb986 100644 --- a/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java +++ b/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java @@ -6,6 +6,7 @@ import spoon.reflect.visitor.CtScanner; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; /** @@ -20,7 +21,12 @@ private static class ExecutableReferenceVisitor extends CtScanner { @Override public void visitCtExecutableReference(final CtExecutableReference reference) { final CtExecutable executable = reference.getDeclaration(); - assertNull(executable); + if (reference.getType() != null && reference.getType().getSimpleName().equals("Object")) { + assertNotNull(executable); + } else { + assertNull(executable); + } + referenceCounter++; } } diff --git a/src/test/java/spoon/test/filters/FilterTest.java b/src/test/java/spoon/test/filters/FilterTest.java index ae1e5098f8a..2891a04fd7c 100644 --- a/src/test/java/spoon/test/filters/FilterTest.java +++ b/src/test/java/spoon/test/filters/FilterTest.java @@ -447,7 +447,9 @@ public boolean matches(CtInvocation element) { final CtExecutableReference expectedExecutable = expectedInv.getExecutable(); assertNotNull(expectedExecutable); assertEquals("size", expectedExecutable.getSimpleName()); - assertNull(expectedExecutable.getDeclaration()); + CtExecutable exec = expectedExecutable.getDeclaration(); + assertEquals("size", exec.getSimpleName()); + assertEquals("ArrayList", ((CtClass)exec.getParent()).getSimpleName()); final CtExecutable declaration = expectedExecutable.getExecutableDeclaration(); assertNotNull(declaration); assertEquals("size", declaration.getSimpleName()); diff --git a/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java b/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java index 41067a06592..34d2ced82eb 100644 --- a/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java +++ b/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java @@ -86,7 +86,10 @@ public void testReferencesBetweenConstructorsInOtherClass() throws Exception { assertEquals(3, refConstructors.size()); assertEquals(0, emptyConstructorClass1.getParameters().size()); assertEquals(0, emptyConstructorClass3.getParameters().size()); - assertNull(refConstructors.get(0).getDeclaration()); // reference to Object constructor. + + CtExecutable decl = refConstructors.get(0).getDeclaration(); + assertEquals("Object", decl.getType().getSimpleName()); + assertEquals(0, decl.getParameters().size()); assertNotNull(refConstructors.get(0).getExecutableDeclaration()); assertEquals(emptyConstructorClass1, refConstructors.get(1).getDeclaration()); assertEquals(emptyConstructorClass3, refConstructors.get(2).getDeclaration()); From f95a298190bd0707c5adfe43d03f0c45e4f2c9ee Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Mon, 26 Jun 2017 17:22:55 +0200 Subject: [PATCH 08/11] Change the wrongly defined test due to issue #1407. Remove commented lines. --- .../spoon/support/visitor/AbstractTypingContext.java | 5 ----- .../spoon/reflect/declaration/CtTypeInformationTest.java | 9 ++------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/spoon/support/visitor/AbstractTypingContext.java b/src/main/java/spoon/support/visitor/AbstractTypingContext.java index ca330ccf685..1cbb2ea1262 100644 --- a/src/main/java/spoon/support/visitor/AbstractTypingContext.java +++ b/src/main/java/spoon/support/visitor/AbstractTypingContext.java @@ -71,11 +71,6 @@ private CtTypeReference adaptTypeParameterReference(CtTypeParameterReference return adaptTypeParameterReferenceBoundingType(typeParamRef, typeParamRef.getBoundingType()); } CtTypeReference typeRefAdapted = adaptTypeParameter(typeParamRef.getDeclaration()); - //Do not adapt bounding type of TypeParameterReference. That bounding type is already adapted as part of typeParamRef adaptation - //... at least in case of GenericsTest#testIsSameSignatureWithGenerics of Iterator -// if (typeRefAdapted instanceof CtTypeParameterReference) { -// return adaptTypeParameterReferenceBoundingType((CtTypeParameterReference) typeRefAdapted, typeParamRef.getBoundingType()); -// } return typeRefAdapted; } diff --git a/src/test/java/spoon/reflect/declaration/CtTypeInformationTest.java b/src/test/java/spoon/reflect/declaration/CtTypeInformationTest.java index 9f22519c4f1..4b2c011e1f4 100644 --- a/src/test/java/spoon/reflect/declaration/CtTypeInformationTest.java +++ b/src/test/java/spoon/reflect/declaration/CtTypeInformationTest.java @@ -137,18 +137,13 @@ public void testGetSuperclass() throws Exception { // + 48 of ArrayList (in library) // + 12 of java.lang.Object - // The final +1 is the result of the only usage of `ClassTypingContext#isSameSignature` in `getAllMethods` - // (see: https://github.com/INRIA/spoon/pull/1375) - // now it gets both `ArrayList#forEach` and `Iterable#forEach` - // this has been spotted as an issue in https://github.com/INRIA/spoon/issues/1407 - Assert.assertEquals(1+12+48+1, extendObject.getAllMethods().size()); + Assert.assertEquals(1+12+48, extendObject.getAllMethods().size()); final CtType subClass = this.factory.Type().get(Subclass.class); assertEquals(2, subClass.getMethods().size()); // the abstract method from Comparable which is overridden should not be present in the model - // The +1 happens for the same reason as below - assertEquals(61+2+1, subClass.getAllMethods().size()); + assertEquals(61+2, subClass.getAllMethods().size()); CtTypeReference superclass = subClass.getSuperclass(); Assert.assertEquals(ExtendsObject.class.getName(), superclass.getQualifiedName()); From fc0cc6577aaab9d5ed544446c2ba3b8e7f79cac0 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Tue, 27 Jun 2017 16:46:49 +0200 Subject: [PATCH 09/11] Change back the getDeclaration method in CtExecutableReference. Fix tests accordingly. --- .../reference/CtExecutableReferenceImpl.java | 10 ++------- .../declaration/UnknownDeclarationTest.java | 6 +---- .../java/spoon/test/filters/FilterTest.java | 4 +++- .../spoon/test/generics/GenericsTest.java | 22 ++++++++++++++++--- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index ce974eab776..67f2d7a03e5 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -146,16 +146,10 @@ public boolean isConstructor() { @SuppressWarnings("unchecked") public CtExecutable getDeclaration() { final CtTypeReference typeRef = getDeclaringType(); - if (typeRef == null) { + if (typeRef == null || typeRef.getDeclaration() == null) { return null; } - - try { - return getCtExecutable(typeRef.getTypeDeclaration()); - } catch (SpoonClassNotFoundException e) { - return null; - } - + return getCtExecutable(typeRef.getDeclaration()); } @Override diff --git a/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java b/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java index 68dc31cb986..f834a455ecc 100644 --- a/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java +++ b/src/test/java/spoon/reflect/declaration/UnknownDeclarationTest.java @@ -21,11 +21,7 @@ private static class ExecutableReferenceVisitor extends CtScanner { @Override public void visitCtExecutableReference(final CtExecutableReference reference) { final CtExecutable executable = reference.getDeclaration(); - if (reference.getType() != null && reference.getType().getSimpleName().equals("Object")) { - assertNotNull(executable); - } else { - assertNull(executable); - } + assertNull(executable); referenceCounter++; } diff --git a/src/test/java/spoon/test/filters/FilterTest.java b/src/test/java/spoon/test/filters/FilterTest.java index 2891a04fd7c..44825eb0840 100644 --- a/src/test/java/spoon/test/filters/FilterTest.java +++ b/src/test/java/spoon/test/filters/FilterTest.java @@ -447,7 +447,9 @@ public boolean matches(CtInvocation element) { final CtExecutableReference expectedExecutable = expectedInv.getExecutable(); assertNotNull(expectedExecutable); assertEquals("size", expectedExecutable.getSimpleName()); - CtExecutable exec = expectedExecutable.getDeclaration(); + + assertNull(expectedExecutable.getDeclaration()); + CtExecutable exec = expectedExecutable.getExecutableDeclaration(); assertEquals("size", exec.getSimpleName()); assertEquals("ArrayList", ((CtClass)exec.getParent()).getSimpleName()); final CtExecutable declaration = expectedExecutable.getExecutableDeclaration(); diff --git a/src/test/java/spoon/test/generics/GenericsTest.java b/src/test/java/spoon/test/generics/GenericsTest.java index 7b6faf83715..ada8fc6c7f8 100644 --- a/src/test/java/spoon/test/generics/GenericsTest.java +++ b/src/test/java/spoon/test/generics/GenericsTest.java @@ -58,6 +58,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import static org.junit.Assert.assertEquals; @@ -65,6 +66,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static spoon.testing.utils.ModelUtils.build; @@ -1117,8 +1119,7 @@ public void testIsSameSignatureWithGenerics() { ClassTypingContext ctc = new ClassTypingContext(ctClass.getReference()); assertTrue(ctc.isOverriding(methods.get(0), methodsItf.get(0))); assertTrue(ctc.isSubSignature(methods.get(0), methodsItf.get(0))); - - // assertTrue(ctc.isSameSignature(methods.get(0), methodsItf.get(0))); + assertTrue(ctc.isSameSignature(methods.get(0), methodsItf.get(0))); } @Test public void testGetExecDeclarationOfEnumSetOf() { @@ -1130,6 +1131,21 @@ public void testGetExecDeclarationOfEnumSetOf() { CtInvocation invocation = ctClass.getMethodsByName("m").get(0).getBody().getStatement(0); CtExecutable decl = invocation.getExecutable().getDeclaration(); - assertNotNull(decl); + assertNull(decl); + + CtClass enumClass = launcher.getFactory().Class().get(EnumSet.class); + List> methods = enumClass.getMethodsByName("of"); + + CtMethod rightOfMethod = null; + for (CtMethod method : methods) { + if (method.getParameters().size() == 1) { + rightOfMethod = method; + } + } + + assertNotNull(rightOfMethod); + + decl = invocation.getExecutable().getExecutableDeclaration(); + assertEquals(rightOfMethod, decl); } } From de230e2de7bf6d2ffabbe4f10471d3b8dd92f96a Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Tue, 27 Jun 2017 16:58:16 +0200 Subject: [PATCH 10/11] Fix last test --- .../spoon/test/reference/ExecutableReferenceGenericTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java b/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java index 34d2ced82eb..a3aa8ddc516 100644 --- a/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java +++ b/src/test/java/spoon/test/reference/ExecutableReferenceGenericTest.java @@ -87,7 +87,8 @@ public void testReferencesBetweenConstructorsInOtherClass() throws Exception { assertEquals(0, emptyConstructorClass1.getParameters().size()); assertEquals(0, emptyConstructorClass3.getParameters().size()); - CtExecutable decl = refConstructors.get(0).getDeclaration(); + assertNull(refConstructors.get(0).getDeclaration()); + CtExecutable decl = refConstructors.get(0).getExecutableDeclaration(); assertEquals("Object", decl.getType().getSimpleName()); assertEquals(0, decl.getParameters().size()); assertNotNull(refConstructors.get(0).getExecutableDeclaration()); From 65d68fe291d5f8a307477ce2e079975fa71ec996 Mon Sep 17 00:00:00 2001 From: Pavel Vojtechovsky Date: Tue, 27 Jun 2017 21:08:11 +0200 Subject: [PATCH 11/11] fix checkstyle --- .../support/reflect/reference/CtExecutableReferenceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java index 67f2d7a03e5..f5dcbb315eb 100644 --- a/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtExecutableReferenceImpl.java @@ -30,7 +30,6 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; import spoon.reflect.visitor.filter.NameFilter; -import spoon.support.SpoonClassNotFoundException; import spoon.support.reflect.declaration.CtElementImpl; import spoon.support.util.RtHelper; import spoon.support.visitor.ClassTypingContext;