diff --git a/src/main/java/spoon/reflect/declaration/CtTypeInformation.java b/src/main/java/spoon/reflect/declaration/CtTypeInformation.java index b1ff0abfbd8..035030f5229 100644 --- a/src/main/java/spoon/reflect/declaration/CtTypeInformation.java +++ b/src/main/java/spoon/reflect/declaration/CtTypeInformation.java @@ -110,8 +110,9 @@ public interface CtTypeInformation { boolean isAnnotationType(); /** - * Returns true if this element is a generics (eg "T") and false if it is an actual type (eg 'Book" or "String") + * Returns true if it refers to a type parameter (ie not a concrete class, eg "T foo"). It can refer to it directly (eg T), or indirectly (eg List<T>, or Set<List<T>>). */ + @DerivedProperty boolean isGenerics(); /** diff --git a/src/main/java/spoon/reflect/reference/CtTypeReference.java b/src/main/java/spoon/reflect/reference/CtTypeReference.java index 59223103e4e..f0affa90ae6 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeReference.java @@ -210,11 +210,5 @@ public interface CtTypeReference extends CtReference, CtActualTypeContainer, @DerivedProperty CtTypeParameter getTypeParameterDeclaration(); - /** - * Returns true if it refers to at least one type parameter (ie not a concrete class). It can refer to it directly (eg T), or indirectly (eg List<T>, or Set<List<T>>). - */ - @DerivedProperty - boolean isGeneric(); - } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index f1d0262b7ff..c5daacad637 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -252,14 +252,4 @@ public CtTypeParameterReference clone() { return (CtTypeParameterReference) super.clone(); } - @Override - public boolean isGeneric() { - if (getDeclaration() instanceof CtTypeParameter) { - return true; - } - if (getBoundingType() != null && getBoundingType().isGeneric()) { - return true; - } - return false; - } } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java index d75845b7fc5..529924c9a38 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java @@ -622,11 +622,6 @@ public boolean isEnum() { } } - @Override - public boolean isGenerics() { - return false; - } - @Override public boolean canAccess(CtTypeReference type) { try { @@ -825,12 +820,12 @@ public CtTypeParameter getTypeParameterDeclaration() { } @Override - public boolean isGeneric() { + public boolean isGenerics() { if (getDeclaration() instanceof CtTypeParameter) { return true; } for (CtTypeReference ref : getActualTypeArguments()) { - if (ref.isGeneric()) { + if (ref.isGenerics()) { return true; } } diff --git a/src/test/java/spoon/test/generics/GenericsTest.java b/src/test/java/spoon/test/generics/GenericsTest.java index 83027825037..8021243f4aa 100644 --- a/src/test/java/spoon/test/generics/GenericsTest.java +++ b/src/test/java/spoon/test/generics/GenericsTest.java @@ -685,143 +685,143 @@ public boolean matches(CtTypeReference element) { // T CtTypeReference var1Ref = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "var1")).first(CtVariable.class).getType(); - assertEquals(true, var1Ref.isGeneric()); + assertEquals(true, var1Ref.isGenerics()); // spoon.test.generics.testclasses.rxjava.Subscriber CtTypeReference sRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "s")).first(CtVariable.class).getType(); - assertEquals(true, sRef.isGeneric()); + assertEquals(true, sRef.isGenerics()); // spoon.test.generics.testclasses.rxjava.Try> CtTypeReference notificationRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "notification")).first(CtVariable.class).getType(); - assertEquals(false, notificationRef.isGeneric()); + assertEquals(false, notificationRef.isGenerics()); // java.util.function.Function>>, ? extends spoon.test.generics.testclasses.rxjava.Publisher> CtTypeReference managerRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "manager")).first(CtVariable.class).getType(); - assertEquals(false, managerRef.isGeneric()); + assertEquals(false, managerRef.isGenerics()); // spoon.test.generics.testclasses.rxjava.BehaviorSubject>> CtTypeReference subjectRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "subject")).first(CtVariable.class).getType(); - assertEquals(false, subjectRef.isGeneric()); + assertEquals(false, subjectRef.isGenerics()); // spoon.test.generics.testclasses.rxjava.PublisherRedo.RedoSubscriber CtTypeReference parentRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "parent")).first(CtVariable.class).getType(); - assertEquals(true, parentRef.isGeneric()); + assertEquals(true, parentRef.isGenerics()); // spoon.test.generics.testclasses.rxjava.Publisher CtTypeReference actionRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "action")).first(CtVariable.class).getType(); - assertEquals(false, actionRef.isGeneric()); + assertEquals(false, actionRef.isGenerics()); // spoon.test.generics.testclasses.rxjava.ToNotificationSubscriber CtTypeReference trucRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "truc")).first(CtVariable.class).getType(); - assertEquals(false, trucRef.isGeneric()); + assertEquals(false, trucRef.isGenerics()); // java.util.function.Consumer>> CtTypeReference consumerRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "consumer")).first(CtVariable.class).getType(); - assertEquals(false, consumerRef.isGeneric()); + assertEquals(false, consumerRef.isGenerics()); // S CtTypeReference sectionRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "section")).first(CtVariable.class).getType(); - assertEquals(true, sectionRef.isGeneric()); + assertEquals(true, sectionRef.isGenerics()); // X CtTypeReference paramARef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "paramA")).first(CtVariable.class).getType(); - assertEquals(true, paramARef.isGeneric()); + assertEquals(true, paramARef.isGenerics()); // spoon.test.generics.testclasses.Tacos CtTypeReference paramBRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "paramB")).first(CtVariable.class).getType(); - assertEquals(false, paramBRef.isGeneric()); + assertEquals(false, paramBRef.isGenerics()); // C CtTypeReference paramCRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "paramC")).first(CtVariable.class).getType(); - assertEquals(true, paramCRef.isGeneric()); + assertEquals(true, paramCRef.isGenerics()); // R CtTypeReference cookRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "cook")).first(CtVariable.class).getType(); - assertEquals(true, cookRef.isGeneric()); + assertEquals(true, cookRef.isGenerics()); // spoon.test.generics.testclasses.CelebrationLunch CtTypeReference clRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "cl")).first(CtVariable.class).getType(); - assertEquals(false, clRef.isGeneric()); + assertEquals(false, clRef.isGenerics()); // spoon.test.generics.testclasses.CelebrationLunch.WeddingLunch CtTypeReference disgustRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "disgust")).first(CtVariable.class).getType(); - assertEquals(false, disgustRef.isGeneric()); + assertEquals(false, disgustRef.isGenerics()); // L CtTypeReference paramRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "param")).first(CtVariable.class).getType(); - assertEquals(true, paramRef.isGeneric()); + assertEquals(true, paramRef.isGenerics()); // spoon.reflect.declaration.CtType CtTypeReference targetTypeRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "targetType")).first(CtVariable.class).getType(); - assertEquals(false, targetTypeRef.isGeneric()); + assertEquals(false, targetTypeRef.isGenerics()); // spoon.reflect.declaration.CtType CtTypeReference somethingRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "something")).first(CtVariable.class).getType(); - assertEquals(false, somethingRef.isGeneric()); + assertEquals(false, somethingRef.isGenerics()); // int CtTypeReference iRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "i")).first(CtVariable.class).getType(); - assertEquals(false, iRef.isGeneric()); + assertEquals(false, iRef.isGenerics()); // T CtTypeReference biduleRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "bidule")).first(CtVariable.class).getType(); - assertEquals(true, biduleRef.isGeneric()); + assertEquals(true, biduleRef.isGenerics()); // Cook CtTypeReference aClassRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "aClass")).first(CtVariable.class).getType(); - assertEquals(false, aClassRef.isGeneric()); + assertEquals(false, aClassRef.isGenerics()); // java.util.List> CtTypeReference list2mRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "list2m")).first(CtVariable.class).getType(); - assertEquals(true, list2mRef.isGeneric()); + assertEquals(true, list2mRef.isGenerics()); // spoon.test.generics.testclasses.Panini.Subscriber CtTypeReference tRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "t")).first(CtVariable.class).getType(); - assertEquals(false, tRef.isGeneric()); + assertEquals(false, tRef.isGenerics()); // spoon.test.generics.testclasses.Spaghetti.Tester CtTypeReference testerRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "tester")).first(CtVariable.class).getType(); - assertEquals(false, testerRef.isGeneric()); + assertEquals(false, testerRef.isGenerics()); // spoon.test.generics.testclasses.Spaghetti.Tester CtTypeReference tester1Ref = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "tester1")).first(CtVariable.class).getType(); - assertEquals(false, tester1Ref.isGeneric()); + assertEquals(false, tester1Ref.isGenerics()); // spoon.test.generics.testclasses.Spaghetti.That CtTypeReference fieldRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "field")).first(CtVariable.class).getType(); - assertEquals(false, fieldRef.isGeneric()); + assertEquals(false, fieldRef.isGenerics()); // spoon.test.generics.testclasses.Spaghetti.That CtTypeReference field1Ref = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "field1")).first(CtVariable.class).getType(); - assertEquals(false, field1Ref.isGeneric()); + assertEquals(false, field1Ref.isGenerics()); // spoon.test.generics.testclasses.Spaghetti.That CtTypeReference field2Ref = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "field2")).first(CtVariable.class).getType(); - assertEquals(false, field2Ref.isGeneric()); + assertEquals(false, field2Ref.isGenerics()); // spoon.test.generics.testclasses.Tacos.Burritos CtTypeReference burritosRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "burritos")).first(CtVariable.class).getType(); - assertEquals(true, burritosRef.isGeneric()); + assertEquals(true, burritosRef.isGenerics()); // int CtTypeReference nbTacosRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "nbTacos")).first(CtVariable.class).getType(); - assertEquals(false, nbTacosRef.isGeneric()); + assertEquals(false, nbTacosRef.isGenerics()); // java.util.List CtTypeReference lRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "l")).first(CtVariable.class).getType(); - assertEquals(false, lRef.isGeneric()); + assertEquals(false, lRef.isGenerics()); // java.util.List CtTypeReference l2Ref = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "l2")).first(CtVariable.class).getType(); - assertEquals(false, l2Ref.isGeneric()); + assertEquals(false, l2Ref.isGenerics()); // java.util.List CtTypeReference l3Ref = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "l3")).first(CtVariable.class).getType(); - assertEquals(false, l3Ref.isGeneric()); + assertEquals(false, l3Ref.isGenerics()); // T CtTypeReference anObjectRef = factory.getModel().getRootPackage().filterChildren(new NamedElementFilter(CtVariable.class, "anObject")).first(CtVariable.class).getType(); - assertEquals(true, anObjectRef.isGeneric()); + assertEquals(true, anObjectRef.isGenerics()); } @Test