From 366bcc02ae4a178ee761531e401fc9ace285e9e3 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 24 Aug 2016 14:05:06 +0200 Subject: [PATCH 1/5] fix(method): Search method with generics. Closes #573 --- .../reflect/declaration/CtTypeImpl.java | 26 +++++++++++++----- .../java/spoon/test/method/MethodTest.java | 27 +++++++++++++------ .../spoon/test/method/testclasses/Tacos.java | 12 +++++++++ 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 src/test/java/spoon/test/method/testclasses/Tacos.java diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index ead958c3231..63be775ff72 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -35,6 +35,7 @@ import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtFieldReference; +import spoon.reflect.reference.CtIntersectionTypeReference; import spoon.reflect.reference.CtPackageReference; import spoon.reflect.reference.CtTypeParameterReference; import spoon.reflect.reference.CtTypeReference; @@ -672,17 +673,30 @@ public CtMethod getMethod(String name, CtTypeReference... parameterTyp return null; } - private boolean isSameParameter(CtTypeReference ctParameterType, CtTypeReference parameterType) { - if (parameterType instanceof CtTypeParameterReference && ctParameterType instanceof CtTypeParameterReference) { + private boolean isSameParameter(CtTypeReference ctParameterType, CtTypeReference expectedType) { + if (expectedType instanceof CtTypeParameterReference && ctParameterType instanceof CtTypeParameterReference) { // Check if Object or extended. - if (!ctParameterType.equals(parameterType)) { + if (!ctParameterType.equals(expectedType)) { return false; } - } else if (parameterType instanceof CtTypeParameterReference) { - if (!ctParameterType.isSubtypeOf(factory.Type().createReference(parameterType.getActualClass()))) { + } else if (expectedType instanceof CtTypeParameterReference) { + if (!ctParameterType.isSubtypeOf(factory.Type().createReference(expectedType.getActualClass()))) { return false; } - } else if (!parameterType.equals(ctParameterType)) { + } else if (ctParameterType instanceof CtTypeParameterReference) { + CtTypeParameter declaration = (CtTypeParameter) ctParameterType.getDeclaration(); + if (declaration.getSuperclass() instanceof CtIntersectionTypeReference) { + for (CtTypeReference ctTypeReference : declaration.getSuperclass().asCtIntersectionTypeReference().getBounds()) { + if (ctTypeReference.equals(expectedType)) { + return true; + } + } + } else if (declaration.getSuperclass() != null) { + return declaration.getSuperclass().equals(expectedType); + } else { + return getFactory().Type().objectType().equals(expectedType); + } + } else if (!expectedType.equals(ctParameterType)) { return false; } return true; diff --git a/src/test/java/spoon/test/method/MethodTest.java b/src/test/java/spoon/test/method/MethodTest.java index b366127f4cd..f04aa723ca2 100644 --- a/src/test/java/spoon/test/method/MethodTest.java +++ b/src/test/java/spoon/test/method/MethodTest.java @@ -17,29 +17,40 @@ package spoon.test.method; -import static org.junit.Assert.assertEquals; -import static spoon.testing.utils.ModelUtils.build; - import org.junit.Test; - import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtMethod; +import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.factory.Factory; import spoon.test.delete.testclasses.Adobada; +import spoon.test.method.testclasses.Tacos; + +import static org.junit.Assert.assertEquals; +import static spoon.testing.utils.ModelUtils.build; +import static spoon.testing.utils.ModelUtils.buildClass; public class MethodTest { - @Test public void testClone() throws Exception { - final Factory factory = build(Adobada.class); final CtClass adobada = factory.Class().get(Adobada.class); final CtMethod m2 = adobada.getMethod("m2"); - + CtMethod clone = m2.clone(); clone.setVisibility(ModifierKind.PRIVATE); - + assertEquals(ModifierKind.PUBLIC, m2.getModifiers().iterator().next()); } + + @Test + public void testSearchMethodWithGeneric() throws Exception { + CtType aTacos = buildClass(Tacos.class); + CtMethod method1 = aTacos.getMethod("method1", aTacos.getFactory().Type().integerType()); + assertEquals("public void method1(T t) {" + System.lineSeparator() + "}", method1.toString()); + method1 = aTacos.getMethod("method1", aTacos.getFactory().Type().stringType()); + assertEquals("public void method1(T t) {" + System.lineSeparator() + "}", method1.toString()); + method1 = aTacos.getMethod("method1", aTacos.getFactory().Type().objectType()); + assertEquals("public void method1(T t) {" + System.lineSeparator() + "}", method1.toString()); + } } diff --git a/src/test/java/spoon/test/method/testclasses/Tacos.java b/src/test/java/spoon/test/method/testclasses/Tacos.java new file mode 100644 index 00000000000..d2a8869a3b0 --- /dev/null +++ b/src/test/java/spoon/test/method/testclasses/Tacos.java @@ -0,0 +1,12 @@ +package spoon.test.method.testclasses; + +public class Tacos { + public void method1(T t) { + } + + public void method1(T t) { + } + + public void method1(T t) { + } +} From a503174647f519cfe812b57170cd75293381c29d Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 24 Aug 2016 14:29:55 +0200 Subject: [PATCH 2/5] test(generic): Adds check on bound and unbound type ref. Closes #597 --- pom.xml | 2 +- .../reference/CtTypeParameterReference.java | 7 +++++++ .../reference/CtTypeParameterReferenceImpl.java | 4 ++-- src/test/java/spoon/test/main/MainTest.java | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 22a8263cd13..a8f593e8ec5 100644 --- a/pom.xml +++ b/pom.xml @@ -165,7 +165,7 @@ - 1.7 + 1.8 1.8 target/velocity.log UTF-8 diff --git a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java index 25c82e6063b..4deb3b0b5a4 100644 --- a/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java +++ b/src/main/java/spoon/reflect/reference/CtTypeParameterReference.java @@ -16,6 +16,8 @@ */ package spoon.reflect.reference; +import spoon.reflect.declaration.CtTypeParameter; + import java.util.List; /** @@ -68,6 +70,11 @@ public interface CtTypeParameterReference extends CtTypeReference { */ T setBoundingType(CtTypeReference superType); + // override the return + @Override + CtTypeParameter getDeclaration(); + + // override the return @Override CtTypeParameterReference clone(); } diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index f20670154d0..16ac8ce7b5a 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -178,14 +178,14 @@ protected AnnotatedElement getActualAnnotatedElement() { } @Override - public CtType getDeclaration() { + public CtTypeParameter getDeclaration() { if (!isParentInitialized()) { return null; } return getRecursiveDeclaration(this); } - private CtType getRecursiveDeclaration(CtElement element) { + private CtTypeParameter getRecursiveDeclaration(CtElement element) { final CtFormalTypeDeclarer formalTypeDeclarer = element.getParent(CtFormalTypeDeclarer.class); if (formalTypeDeclarer == null) { return null; diff --git a/src/test/java/spoon/test/main/MainTest.java b/src/test/java/spoon/test/main/MainTest.java index 3fe995d34f9..3c5318a30a0 100644 --- a/src/test/java/spoon/test/main/MainTest.java +++ b/src/test/java/spoon/test/main/MainTest.java @@ -18,6 +18,7 @@ import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtShadowable; import spoon.reflect.declaration.CtType; +import spoon.reflect.declaration.CtTypeParameter; import spoon.reflect.declaration.ParentNotInitializedException; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtExecutableReference; @@ -91,6 +92,22 @@ public void checkGenericContracts(CtPackage pack) { // clone checkEqualityBetweenOriginalAndClone(pack); + + // type parameter reference. + checkBoundAndUnboundTypeReference(pack); + } + + private void checkBoundAndUnboundTypeReference(CtPackage pack) { + new CtScanner() { + @Override + public void visitCtTypeParameterReference(CtTypeParameterReference ref) { + CtTypeParameter declaration = ref.getDeclaration(); + if (declaration != null) { + assertEquals(ref.getSimpleName(), declaration.getSimpleName()); + } + super.visitCtTypeParameterReference(ref); + } + }.scan(pack); } private void checkEqualityBetweenOriginalAndClone(CtPackage pack) { From cfa078ae6650efdbec3bec7df2e8f2f305253acd Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 24 Aug 2016 15:40:34 +0200 Subject: [PATCH 3/5] feat(actual): Throws an exception for actual types in CtTypeParameterRef. Closes #600 --- .../reflect/visitor/CtBiScannerDefault.java | 1 - .../java/spoon/reflect/visitor/CtScanner.java | 1 - .../compiler/jdt/ReferenceBuilder.java | 24 +++++++------------ .../CtTypeParameterReferenceImpl.java | 22 ++++++----------- .../support/visitor/clone/CloneVisitor.java | 1 - .../visitor/replace/ReplacementVisitor.java | 1 - .../test/reference/TypeReferenceTest.java | 3 +-- 7 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java b/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java index 86d7712ce57..f62a27f6c4c 100644 --- a/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java +++ b/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java @@ -626,7 +626,6 @@ public void visitCtTypeParameterReference(final spoon.reflect.reference.CtTypePa enter(ref); biScan(ref.getPackage(), other.getPackage()); biScan(ref.getDeclaringType(), other.getDeclaringType()); - biScan(ref.getActualTypeArguments(), other.getActualTypeArguments()); biScan(ref.getAnnotations(), other.getAnnotations()); biScan(ref.getBoundingType(), other.getBoundingType()); exit(ref); diff --git a/src/main/java/spoon/reflect/visitor/CtScanner.java b/src/main/java/spoon/reflect/visitor/CtScanner.java index c6e2a7dc243..5ec98cc08a1 100644 --- a/src/main/java/spoon/reflect/visitor/CtScanner.java +++ b/src/main/java/spoon/reflect/visitor/CtScanner.java @@ -720,7 +720,6 @@ public void visitCtTypeParameterReference(final CtTypeParameterReference ref) { enter(ref); scan(ref.getPackage()); scan(ref.getDeclaringType()); - scan(ref.getActualTypeArguments()); scan(ref.getAnnotations()); scan(ref.getBoundingType()); exit(ref); diff --git a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java index eec0af6757d..4845f573b17 100644 --- a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java @@ -69,7 +69,6 @@ import spoon.reflect.code.CtLocalVariable; import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.ModifierKind; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.reference.CtExecutableReference; @@ -464,7 +463,6 @@ CtTypeReference getTypeParameterReference(TypeBinding binding, TypeRefer typeParameterRef.setSimpleName(ctRef.getSimpleName()); typeParameterRef.setDeclaringType(ctRef.getDeclaringType()); typeParameterRef.setPackage(ctRef.getPackage()); - typeParameterRef.setActualTypeArguments(ctRef.getActualTypeArguments()); ctRef = typeParameterRef; } insertGenericTypesInNoClasspathFromJDTInSpoon(ref, ctRef); @@ -580,16 +578,17 @@ private CtTypeReference getTypeReference(String name) { * Try to build a CtTypeParameterReference from a single name with specified generic types but * keep in mind that if you give wrong data in the strong, reference will be wrong. */ - private CtTypeParameterReference getTypeParameterReference(String name) { - CtTypeParameterReference param = this.jdtTreeBuilder.getFactory().Core().createTypeParameterReference(); + private CtTypeReference getTypeParameterReference(String name) { + CtTypeReference param = null; if (name.contains("extends") || name.contains("super")) { String[] split = name.contains("extends") ? name.split("extends") : name.split("super"); param = getTypeParameterReference(split[0].trim()); - param.setBoundingType(getTypeReference(split[split.length - 1].trim())); + ((CtTypeParameterReference) param).setBoundingType(getTypeReference(split[split.length - 1].trim())); } else if (name.matches(".*(<.+>)")) { Pattern pattern = Pattern.compile("([^<]+)<(.+)>"); Matcher m = pattern.matcher(name); if (m.find()) { + param = this.jdtTreeBuilder.getFactory().Core().createTypeReference(); param.setSimpleName(m.group(1)); final String[] split = m.group(2).split(","); for (String parameter : split) { @@ -599,6 +598,7 @@ private CtTypeParameterReference getTypeParameterReference(String name) { } else if (name.contains("?")) { param = this.jdtTreeBuilder.getFactory().Core().createWildcardReference(); } else { + param = this.jdtTreeBuilder.getFactory().Core().createTypeParameterReference(); param.setSimpleName(name); } return param; @@ -717,8 +717,7 @@ CtTypeReference getTypeReference(TypeBinding binding) { if (((WildcardBinding) binding).bound != null && ref instanceof CtTypeParameterReference) { if (bindingCache.containsKey(((WildcardBinding) binding).bound)) { - final CtCircularTypeReference circularRef = getCtCircularTypeReference(((WildcardBinding) binding).bound); - ((CtTypeParameterReference) ref).setBoundingType(circularRef); + ((CtTypeParameterReference) ref).setBoundingType(getCtCircularTypeReference(((WildcardBinding) binding).bound)); } else { ((CtTypeParameterReference) ref).setBoundingType(getTypeReference(((WildcardBinding) binding).bound)); } @@ -790,15 +789,8 @@ CtTypeReference getTypeReference(TypeBinding binding) { return (CtTypeReference) ref; } - private CtCircularTypeReference getCtCircularTypeReference(TypeBinding b) { - final CtCircularTypeReference circularRef = this.jdtTreeBuilder.getFactory().Internal().createCircularTypeReference(); - final CtTypeReference originalRef = bindingCache.get(b).clone(); - circularRef.setPackage(originalRef.getPackage()); - circularRef.setSimpleName(originalRef.getSimpleName()); - circularRef.setDeclaringType(originalRef.getDeclaringType()); - circularRef.setActualTypeArguments(originalRef.getActualTypeArguments()); - circularRef.setAnnotations(originalRef.getAnnotations()); - return circularRef; + private CtTypeReference getCtCircularTypeReference(TypeBinding b) { + return bindingCache.get(b).clone(); } @SuppressWarnings("unchecked") diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index 16ac8ce7b5a..ae6362f552e 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -25,16 +25,12 @@ import spoon.reflect.reference.CtTypeParameterReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.support.reflect.declaration.CtElementImpl; import java.lang.reflect.AnnotatedElement; -import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet; -import static spoon.reflect.ModelElementContainerDefaultCapacities.TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; - public class CtTypeParameterReferenceImpl extends CtTypeReferenceImpl implements CtTypeParameterReference { private static final long serialVersionUID = 1L; @@ -107,23 +103,19 @@ public Class getActualClass() { return null; } + @Override + public C setActualTypeArguments(List> actualTypeArguments) { + throw new UnsupportedOperationException("Type parameter can't have an actual type argument"); + } + @Override public C addActualTypeArgument(CtTypeReference actualTypeArgument) { - if (actualTypeArgument == null) { - return (C) this; - } - if (actualTypeArguments == CtElementImpl.>emptyList()) { - actualTypeArguments = new ArrayList<>(TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY); - } - actualTypeArgument.setParent(this); - actualTypeArguments.add(actualTypeArgument); - return (C) this; + throw new UnsupportedOperationException("Type parameter can't have an actual type argument"); } @Override public boolean removeActualTypeArgument(CtTypeReference actualTypeArgument) { - return actualTypeArguments != CtElementImpl.>emptyList() - && actualTypeArguments.remove(actualTypeArgument); + throw new UnsupportedOperationException("Type parameter can't have an actual type argument"); } @Override diff --git a/src/main/java/spoon/support/visitor/clone/CloneVisitor.java b/src/main/java/spoon/support/visitor/clone/CloneVisitor.java index 157d8a0573e..2e7eb42230a 100644 --- a/src/main/java/spoon/support/visitor/clone/CloneVisitor.java +++ b/src/main/java/spoon/support/visitor/clone/CloneVisitor.java @@ -629,7 +629,6 @@ public void visitCtTypeParameterReference(final spoon.reflect.reference.CtTypePa spoon.reflect.reference.CtTypeParameterReference aCtTypeParameterReference = spoon.support.visitor.clone.CloneBuilder.build(this.builder, ref, ref.getFactory().Core().createTypeParameterReference()); aCtTypeParameterReference.setPackage(spoon.support.visitor.equals.CloneHelper.clone(ref.getPackage())); aCtTypeParameterReference.setDeclaringType(spoon.support.visitor.equals.CloneHelper.clone(ref.getDeclaringType())); - aCtTypeParameterReference.setActualTypeArguments(spoon.support.visitor.equals.CloneHelper.clone(ref.getActualTypeArguments())); aCtTypeParameterReference.setAnnotations(spoon.support.visitor.equals.CloneHelper.clone(ref.getAnnotations())); aCtTypeParameterReference.setBoundingType(spoon.support.visitor.equals.CloneHelper.clone(ref.getBoundingType())); this.other = aCtTypeParameterReference; diff --git a/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java b/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java index a4bda619b38..485be82528a 100644 --- a/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java +++ b/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java @@ -1759,7 +1759,6 @@ public void visitCtTryWithResource(final spoon.reflect.code.CtTryWithResource tr public void visitCtTypeParameterReference(final spoon.reflect.reference.CtTypeParameterReference ref) { replaceElementIfExist(ref.getPackage(), new spoon.support.visitor.replace.ReplacementVisitor.CtTypeReferencePackageReplaceListener(ref)); replaceElementIfExist(ref.getDeclaringType(), new spoon.support.visitor.replace.ReplacementVisitor.CtTypeReferenceDeclaringTypeReplaceListener(ref)); - replaceInListIfExist(ref.getActualTypeArguments(), new spoon.support.visitor.replace.ReplacementVisitor.CtActualTypeContainerActualTypeArgumentsReplaceListener(ref)); replaceInListIfExist(ref.getAnnotations(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementAnnotationsReplaceListener(ref)); replaceElementIfExist(ref.getBoundingType(), new spoon.support.visitor.replace.ReplacementVisitor.CtTypeParameterReferenceBoundingTypeReplaceListener(ref)); } diff --git a/src/test/java/spoon/test/reference/TypeReferenceTest.java b/src/test/java/spoon/test/reference/TypeReferenceTest.java index 7469854e305..04eec0cb4a5 100644 --- a/src/test/java/spoon/test/reference/TypeReferenceTest.java +++ b/src/test/java/spoon/test/reference/TypeReferenceTest.java @@ -21,7 +21,6 @@ import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.CtTypeParameter; import spoon.reflect.factory.Factory; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtFieldReference; import spoon.reflect.reference.CtTypeParameterReference; @@ -258,7 +257,7 @@ public boolean matches(CtInvocation element) { assertNotNull(genericExtends); assertNotNull(genericExtends.getBoundingType()); - assertTrue(genericExtends.getBoundingType() instanceof CtCircularTypeReference); + assertTrue(genericExtends.getBoundingType() instanceof CtTypeReference); } @Test From 62ad2cdfcdcae596b5587d2c5bbb1beea0698614 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 24 Aug 2016 15:50:30 +0200 Subject: [PATCH 4/5] refactor(ref): Removes unused CtCircularTypeReference. --- .../java/spoon/reflect/factory/Factory.java | 2 - .../spoon/reflect/factory/FactoryImpl.java | 11 ----- .../reflect/factory/InternalFactory.java | 31 -------------- .../internal/CtCircularTypeReference.java | 34 ---------------- .../reflect/visitor/CtAbstractVisitor.java | 6 --- .../reflect/visitor/CtBiScannerDefault.java | 7 ---- .../reflect/visitor/CtInheritanceScanner.java | 6 --- .../java/spoon/reflect/visitor/CtScanner.java | 7 ---- .../java/spoon/reflect/visitor/CtVisitor.java | 6 --- .../visitor/DefaultJavaPrettyPrinter.java | 6 --- .../spoon/support/DefaultInternalFactory.java | 37 ----------------- .../reflect/eval/VisitorPartialEvaluator.java | 6 --- .../internal/CtCircularTypeReferenceImpl.java | 40 ------------------- .../spoon/support/visitor/EqualVisitor.java | 6 --- .../visitor/ShortRepresentationPrinter.java | 6 --- .../support/visitor/clone/CloneVisitor.java | 7 ---- .../support/visitor/equals/EqualsVisitor.java | 7 ---- .../visitor/replace/ReplacementVisitor.java | 4 -- 18 files changed, 229 deletions(-) delete mode 100644 src/main/java/spoon/reflect/factory/InternalFactory.java delete mode 100644 src/main/java/spoon/reflect/internal/CtCircularTypeReference.java delete mode 100644 src/main/java/spoon/support/DefaultInternalFactory.java delete mode 100644 src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java diff --git a/src/main/java/spoon/reflect/factory/Factory.java b/src/main/java/spoon/reflect/factory/Factory.java index af433807fa8..65d5201893b 100644 --- a/src/main/java/spoon/reflect/factory/Factory.java +++ b/src/main/java/spoon/reflect/factory/Factory.java @@ -60,6 +60,4 @@ public interface Factory { EvalFactory Eval(); // used 4 times ConstructorFactory Constructor(); // used 3 times - - InternalFactory Internal(); } diff --git a/src/main/java/spoon/reflect/factory/FactoryImpl.java b/src/main/java/spoon/reflect/factory/FactoryImpl.java index f635d4e78ec..c9818986dc0 100644 --- a/src/main/java/spoon/reflect/factory/FactoryImpl.java +++ b/src/main/java/spoon/reflect/factory/FactoryImpl.java @@ -31,7 +31,6 @@ import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtType; import spoon.support.DefaultCoreFactory; -import spoon.support.DefaultInternalFactory; import spoon.support.StandardEnvironment; import java.io.Serializable; @@ -256,16 +255,6 @@ public TypeFactory Type() { return type; } - private transient InternalFactory internal; - - @Override - public InternalFactory Internal() { - if (internal == null) { - internal = new DefaultInternalFactory(this); - } - return internal; - } - /** * A constructor that takes the parent factory */ diff --git a/src/main/java/spoon/reflect/factory/InternalFactory.java b/src/main/java/spoon/reflect/factory/InternalFactory.java deleted file mode 100644 index 074a3b44e50..00000000000 --- a/src/main/java/spoon/reflect/factory/InternalFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (C) 2006-2016 INRIA and contributors - * Spoon - http://spoon.gforge.inria.fr/ - * - * This software is governed by the CeCILL-C License under French law and - * abiding by the rules of distribution of free software. You can use, modify - * and/or redistribute the software under the terms of the CeCILL-C license as - * circulated by CEA, CNRS and INRIA at http://www.cecill.info. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL-C license and that you accept its terms. - */ -package spoon.reflect.factory; - -import spoon.reflect.internal.CtCircularTypeReference; - -/** - * This interface defines the creation methods for internal nodes of the - * meta-model. These nodes are available in the AST provided by Spoon - * but their creation should be used only in internal of Spoon. - */ -public interface InternalFactory { - /** - * Creates a circular type reference. - */ - CtCircularTypeReference createCircularTypeReference(); -} diff --git a/src/main/java/spoon/reflect/internal/CtCircularTypeReference.java b/src/main/java/spoon/reflect/internal/CtCircularTypeReference.java deleted file mode 100644 index 9eb92cc32f0..00000000000 --- a/src/main/java/spoon/reflect/internal/CtCircularTypeReference.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (C) 2006-2016 INRIA and contributors - * Spoon - http://spoon.gforge.inria.fr/ - * - * This software is governed by the CeCILL-C License under French law and - * abiding by the rules of distribution of free software. You can use, modify - * and/or redistribute the software under the terms of the CeCILL-C license as - * circulated by CEA, CNRS and INRIA at http://www.cecill.info. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL-C license and that you accept its terms. - */ -package spoon.reflect.internal; - -import spoon.reflect.reference.CtTypeParameterReference; -import spoon.reflect.reference.CtTypeReference; - -/** - * When we build a {@link CtTypeReference}, we can have a circular when - * we got this kind of generic type: {@code >}. - * In this case, where we are at the last T, we come back at the first - * one and we are in a circular. - * - * Now, the last T is a CtCircularTypeReference and we stop the circular - * when we build the generic or when we scan an AST given. - */ -public interface CtCircularTypeReference extends CtTypeParameterReference { - @Override - CtCircularTypeReference clone(); -} diff --git a/src/main/java/spoon/reflect/visitor/CtAbstractVisitor.java b/src/main/java/spoon/reflect/visitor/CtAbstractVisitor.java index f919768551d..85a64deb4d6 100644 --- a/src/main/java/spoon/reflect/visitor/CtAbstractVisitor.java +++ b/src/main/java/spoon/reflect/visitor/CtAbstractVisitor.java @@ -76,7 +76,6 @@ import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtParameter; import spoon.reflect.declaration.CtTypeParameter; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.reference.CtExecutableReference; @@ -393,11 +392,6 @@ public void visitCtTypeReference(CtTypeReference reference) { } - @Override - public void visitCtCircularTypeReference(CtCircularTypeReference reference) { - - } - @Override public void visitCtTypeAccess(CtTypeAccess typeAccess) { diff --git a/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java b/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java index f62a27f6c4c..40c60eb3cd2 100644 --- a/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java +++ b/src/main/java/spoon/reflect/visitor/CtBiScannerDefault.java @@ -659,13 +659,6 @@ public void visitCtTypeReference(final spoon.reflect.reference.CtTypeReferen exit(reference); } - @java.lang.Override - public void visitCtCircularTypeReference(final spoon.reflect.internal.CtCircularTypeReference reference) { - spoon.reflect.internal.CtCircularTypeReference other = ((spoon.reflect.internal.CtCircularTypeReference) (stack.peek())); - enter(reference); - exit(reference); - } - @java.lang.Override public void visitCtTypeAccess(final spoon.reflect.code.CtTypeAccess typeAccess) { spoon.reflect.code.CtTypeAccess other = ((spoon.reflect.code.CtTypeAccess) (stack.peek())); diff --git a/src/main/java/spoon/reflect/visitor/CtInheritanceScanner.java b/src/main/java/spoon/reflect/visitor/CtInheritanceScanner.java index ff01aa23bc1..de25027170e 100644 --- a/src/main/java/spoon/reflect/visitor/CtInheritanceScanner.java +++ b/src/main/java/spoon/reflect/visitor/CtInheritanceScanner.java @@ -97,7 +97,6 @@ import spoon.reflect.declaration.CtTypeParameter; import spoon.reflect.declaration.CtTypedElement; import spoon.reflect.declaration.CtVariable; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtActualTypeContainer; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; @@ -805,11 +804,6 @@ public void visitCtTypeReference(CtTypeReference e) { scanCtVisitable(e); } - @Override - public void visitCtCircularTypeReference(CtCircularTypeReference e) { - visitCtTypeParameterReference(e); - } - @Override public void visitCtTypeAccess(CtTypeAccess e) { scanCtExpression(e); diff --git a/src/main/java/spoon/reflect/visitor/CtScanner.java b/src/main/java/spoon/reflect/visitor/CtScanner.java index 5ec98cc08a1..fb7357a7664 100644 --- a/src/main/java/spoon/reflect/visitor/CtScanner.java +++ b/src/main/java/spoon/reflect/visitor/CtScanner.java @@ -78,7 +78,6 @@ import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtParameter; import spoon.reflect.declaration.CtTypeParameter; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.reference.CtExecutableReference; @@ -750,12 +749,6 @@ public void visitCtTypeReference(final CtTypeReference reference) { exit(reference); } - @Override - public void visitCtCircularTypeReference(final CtCircularTypeReference reference) { - enter(reference); - exit(reference); - } - @Override public void visitCtTypeAccess(final CtTypeAccess typeAccess) { enter(typeAccess); diff --git a/src/main/java/spoon/reflect/visitor/CtVisitor.java b/src/main/java/spoon/reflect/visitor/CtVisitor.java index d8e32ea7153..519a1863ef2 100644 --- a/src/main/java/spoon/reflect/visitor/CtVisitor.java +++ b/src/main/java/spoon/reflect/visitor/CtVisitor.java @@ -76,7 +76,6 @@ import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtParameter; import spoon.reflect.declaration.CtTypeParameter; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.reference.CtExecutableReference; @@ -406,11 +405,6 @@ void visitCtOperatorAssignment( */ void visitCtTypeReference(CtTypeReference reference); - /** - * Visits a circular reference. - */ - void visitCtCircularTypeReference(CtCircularTypeReference reference); - /** * Visits a type access. */ diff --git a/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java b/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java index 6c3d4d3933d..5ee3f8f2302 100644 --- a/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java +++ b/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java @@ -89,7 +89,6 @@ import spoon.reflect.declaration.CtTypeParameter; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.declaration.ParentNotInitializedException; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.reference.CtExecutableReference; @@ -1644,11 +1643,6 @@ public void visitCtTypeReference(CtTypeReference ref) { visitCtTypeReference(ref, true); } - @Override - public void visitCtCircularTypeReference(CtCircularTypeReference reference) { - visitCtTypeReference(reference); - } - @Override public void visitCtTypeAccess(CtTypeAccess typeAccess) { if (typeAccess.isImplicit()) { diff --git a/src/main/java/spoon/support/DefaultInternalFactory.java b/src/main/java/spoon/support/DefaultInternalFactory.java deleted file mode 100644 index 47e44a7f197..00000000000 --- a/src/main/java/spoon/support/DefaultInternalFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (C) 2006-2016 INRIA and contributors - * Spoon - http://spoon.gforge.inria.fr/ - * - * This software is governed by the CeCILL-C License under French law and - * abiding by the rules of distribution of free software. You can use, modify - * and/or redistribute the software under the terms of the CeCILL-C license as - * circulated by CEA, CNRS and INRIA at http://www.cecill.info. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL-C license and that you accept its terms. - */ -package spoon.support; - -import spoon.reflect.factory.Factory; -import spoon.reflect.factory.InternalFactory; -import spoon.reflect.internal.CtCircularTypeReference; -import spoon.support.reflect.internal.CtCircularTypeReferenceImpl; - -public class DefaultInternalFactory implements InternalFactory { - private final Factory mainFactory; - - public DefaultInternalFactory(Factory factory) { - mainFactory = factory; - } - - @Override - public CtCircularTypeReference createCircularTypeReference() { - CtCircularTypeReference e = new CtCircularTypeReferenceImpl(); - e.setFactory(mainFactory); - return e; - } -} diff --git a/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java b/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java index 60d943f07af..2bfc1a97bd5 100644 --- a/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java +++ b/src/main/java/spoon/support/reflect/eval/VisitorPartialEvaluator.java @@ -90,7 +90,6 @@ import spoon.reflect.declaration.CtVariable; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.eval.PartialEvaluator; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtActualTypeContainer; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; @@ -744,11 +743,6 @@ public void visitCtTypeReference(CtTypeReference reference) { throw new RuntimeException("Unknown Element"); } - @Override - public void visitCtCircularTypeReference(CtCircularTypeReference reference) { - throw new RuntimeException("Unknown Element"); - } - @Override public void visitCtComment(CtComment comment) { throw new RuntimeException("Unknown Element"); diff --git a/src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java b/src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java deleted file mode 100644 index e851f3b62f3..00000000000 --- a/src/main/java/spoon/support/reflect/internal/CtCircularTypeReferenceImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (C) 2006-2016 INRIA and contributors - * Spoon - http://spoon.gforge.inria.fr/ - * - * This software is governed by the CeCILL-C License under French law and - * abiding by the rules of distribution of free software. You can use, modify - * and/or redistribute the software under the terms of the CeCILL-C license as - * circulated by CEA, CNRS and INRIA at http://www.cecill.info. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL-C license and that you accept its terms. - */ -package spoon.support.reflect.internal; - -import spoon.reflect.internal.CtCircularTypeReference; -import spoon.reflect.reference.CtReference; -import spoon.reflect.visitor.CtVisitor; -import spoon.support.reflect.reference.CtTypeParameterReferenceImpl; - -public class CtCircularTypeReferenceImpl extends CtTypeParameterReferenceImpl implements CtCircularTypeReference { - @Override - public void accept(CtVisitor visitor) { - visitor.visitCtCircularTypeReference(this); - } - - @Override - public T setSimpleName(String simplename) { - this.simplename = simplename; - return (T) this; - } - - @Override - public CtCircularTypeReference clone() { - return (CtCircularTypeReference) super.clone(); - } -} diff --git a/src/main/java/spoon/support/visitor/EqualVisitor.java b/src/main/java/spoon/support/visitor/EqualVisitor.java index d1d126c898f..2344b5da226 100644 --- a/src/main/java/spoon/support/visitor/EqualVisitor.java +++ b/src/main/java/spoon/support/visitor/EqualVisitor.java @@ -74,7 +74,6 @@ import spoon.reflect.declaration.CtMethod; import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtParameter; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.reference.CtExecutableReference; @@ -600,11 +599,6 @@ public void visitCtTypeReference(CtTypeReference reference) { write(" "); } - @Override - public void visitCtCircularTypeReference(CtCircularTypeReference reference) { - visitCtTypeReference(reference); - } - @Override public void visitCtTypeAccess(CtTypeAccess typeAccess) { write(typeAccess.getAccessedType().getQualifiedName()); diff --git a/src/main/java/spoon/support/visitor/ShortRepresentationPrinter.java b/src/main/java/spoon/support/visitor/ShortRepresentationPrinter.java index 605167a514e..f0417ecc674 100644 --- a/src/main/java/spoon/support/visitor/ShortRepresentationPrinter.java +++ b/src/main/java/spoon/support/visitor/ShortRepresentationPrinter.java @@ -80,7 +80,6 @@ import spoon.reflect.declaration.CtPackage; import spoon.reflect.declaration.CtParameter; import spoon.reflect.declaration.CtTypeParameter; -import spoon.reflect.internal.CtCircularTypeReference; import spoon.reflect.reference.CtArrayTypeReference; import spoon.reflect.reference.CtCatchVariableReference; import spoon.reflect.reference.CtExecutableReference; @@ -664,11 +663,6 @@ public void visitCtTypeReference(CtTypeReference reference) { write(reference.getQualifiedName()); } - @Override - public void visitCtCircularTypeReference(CtCircularTypeReference reference) { - visitCtTypeReference(reference); - } - @Override public void visitCtTypeAccess(CtTypeAccess typeAccess) { scan(typeAccess.getAccessedType()); diff --git a/src/main/java/spoon/support/visitor/clone/CloneVisitor.java b/src/main/java/spoon/support/visitor/clone/CloneVisitor.java index 2e7eb42230a..45e95b2e119 100644 --- a/src/main/java/spoon/support/visitor/clone/CloneVisitor.java +++ b/src/main/java/spoon/support/visitor/clone/CloneVisitor.java @@ -662,13 +662,6 @@ public void visitCtTypeReference(final spoon.reflect.reference.CtTypeReferen this.other = aCtTypeReference; } - // auto-generated, see spoon.generating.CloneVisitorGenerator - @java.lang.Override - public void visitCtCircularTypeReference(final spoon.reflect.internal.CtCircularTypeReference reference) { - spoon.reflect.internal.CtCircularTypeReference aCtCircularTypeReference = spoon.support.visitor.clone.CloneBuilder.build(this.builder, reference, reference.getFactory().Internal().createCircularTypeReference()); - this.other = aCtCircularTypeReference; - } - // auto-generated, see spoon.generating.CloneVisitorGenerator @java.lang.Override public void visitCtTypeAccess(final spoon.reflect.code.CtTypeAccess typeAccess) { diff --git a/src/main/java/spoon/support/visitor/equals/EqualsVisitor.java b/src/main/java/spoon/support/visitor/equals/EqualsVisitor.java index 5f641ca4138..15e235db63e 100644 --- a/src/main/java/spoon/support/visitor/equals/EqualsVisitor.java +++ b/src/main/java/spoon/support/visitor/equals/EqualsVisitor.java @@ -617,13 +617,6 @@ public void visitCtTypeReference(final spoon.reflect.reference.CtTypeReferen exit(reference); } - @java.lang.Override - public void visitCtCircularTypeReference(final spoon.reflect.internal.CtCircularTypeReference reference) { - spoon.reflect.internal.CtCircularTypeReference other = ((spoon.reflect.internal.CtCircularTypeReference) (stack.peek())); - enter(reference); - exit(reference); - } - @java.lang.Override public void visitCtTypeAccess(final spoon.reflect.code.CtTypeAccess typeAccess) { spoon.reflect.code.CtTypeAccess other = ((spoon.reflect.code.CtTypeAccess) (stack.peek())); diff --git a/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java b/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java index 485be82528a..7acd7d81eac 100644 --- a/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java +++ b/src/main/java/spoon/support/visitor/replace/ReplacementVisitor.java @@ -1785,10 +1785,6 @@ public void visitCtTypeReference(final spoon.reflect.reference.CtTypeReferen replaceInListIfExist(reference.getComments(), new spoon.support.visitor.replace.ReplacementVisitor.CtElementCommentsReplaceListener(reference)); } - @java.lang.Override - public void visitCtCircularTypeReference(final spoon.reflect.internal.CtCircularTypeReference reference) { - } - // auto-generated, see spoon.generating.ReplacementVisitorGenerator @java.lang.Override public void visitCtTypeAccess(final spoon.reflect.code.CtTypeAccess typeAccess) { From a1c266b308ed634d9a350dacf05be0b6449a9e3f Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Wed, 24 Aug 2016 17:22:40 +0200 Subject: [PATCH 5/5] feat(ast): Adds CtTypeInformation#isGenerics method. --- pom.xml | 2 +- .../reflect/declaration/CtTypeInformation.java | 5 +++++ .../support/reflect/declaration/CtTypeImpl.java | 5 +++++ .../reflect/declaration/CtTypeParameterImpl.java | 5 +++++ .../reference/CtTypeParameterReferenceImpl.java | 5 +++++ .../reflect/reference/CtTypeReferenceImpl.java | 5 +++++ src/test/java/spoon/test/generics/GenericsTest.java | 13 +++++++++++++ 7 files changed, 39 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a8f593e8ec5..22a8263cd13 100644 --- a/pom.xml +++ b/pom.xml @@ -165,7 +165,7 @@ - 1.8 + 1.7 1.8 target/velocity.log UTF-8 diff --git a/src/main/java/spoon/reflect/declaration/CtTypeInformation.java b/src/main/java/spoon/reflect/declaration/CtTypeInformation.java index 068b15e38e8..457724addd0 100644 --- a/src/main/java/spoon/reflect/declaration/CtTypeInformation.java +++ b/src/main/java/spoon/reflect/declaration/CtTypeInformation.java @@ -90,6 +90,11 @@ 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") + */ + boolean isGenerics(); + /** * Returns true if the referenced type is a sub-type of the given type. */ diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index 63be775ff72..9aeb0223fc2 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -434,6 +434,11 @@ public boolean isAnnotationType() { return false; } + @Override + public boolean isGenerics() { + return false; + } + @Override public List> getAllFields() { List> l = new ArrayList<>(getFields().size()); diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java index 7ce68576c2b..97e4c626856 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeParameterImpl.java @@ -67,6 +67,11 @@ public CtTypeParameterReference getReference() { return getFactory().Type().createReference(this); } + @Override + public boolean isGenerics() { + return true; + } + @Override public CtTypeParameter clone() { return (CtTypeParameter) super.clone(); diff --git a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java index ae6362f552e..15efcfa476e 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeParameterReferenceImpl.java @@ -81,6 +81,11 @@ public boolean isAssignableFrom(CtTypeReference type) { return false; } + @Override + public boolean isGenerics() { + return true; + } + @Override public boolean isSubtypeOf(CtTypeReference type) { 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 3251b2dda82..3e77b0edb7e 100644 --- a/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java +++ b/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java @@ -550,6 +550,11 @@ public boolean isAnnotationType() { } } + @Override + public boolean isGenerics() { + return false; + } + boolean isShadow; @Override diff --git a/src/test/java/spoon/test/generics/GenericsTest.java b/src/test/java/spoon/test/generics/GenericsTest.java index ba1b2340c80..491fadb72bc 100644 --- a/src/test/java/spoon/test/generics/GenericsTest.java +++ b/src/test/java/spoon/test/generics/GenericsTest.java @@ -42,6 +42,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static spoon.testing.utils.ModelUtils.build; @@ -557,4 +558,16 @@ public boolean matches(CtTypeParameterReference element) { assertNotNull(parameterReference.getDeclaration()); } } + + @Test + public void testIsGenericsMethod() throws Exception { + CtType aTacos = buildNoClasspath(Tacos.class).Type().get(Tacos.class); + CtTypeParameter typeParameter = aTacos.getFormalCtTypeParameters().get(0); + assertTrue(typeParameter.isGenerics()); + assertTrue(typeParameter.getReference().isGenerics()); + + CtTypeReference ctTypeReference = aTacos.getSuperInterfaces().toArray(new CtTypeReference[aTacos.getSuperInterfaces().size()])[0]; + assertFalse(aTacos.isGenerics()); + assertFalse(ctTypeReference.isGenerics()); + } }