Skip to content

Commit

Permalink
refactor(api): Handles null and empty list for setBounds(List).
Browse files Browse the repository at this point in the history
Closes #593
  • Loading branch information
GerardPaligot committed Apr 19, 2016
1 parent 5c33091 commit c23a63e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface CtTypeParameterReference extends CtTypeReference<Object> {

/**
* Sets the bounds (aka generics) of the referenced parameter.
*
* If you give null or an empty list, it'll clear bounds of the reference.
*/
@Deprecated
<T extends CtTypeParameterReference> T setBounds(List<CtTypeReference<?>> bounds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public boolean isUpper() {

@Override
public <T extends CtTypeParameterReference> T setBounds(List<CtTypeReference<?>> bounds) {
if (bounds == null) {
if (bounds == null || bounds.isEmpty()) {
setBoundingType(null);
return (T) this;
}
if (getBoundingType() instanceof CtIntersectionTypeReference<?>) {
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/spoon/test/reference/TypeReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import spoon.test.reference.testclasses.EnumValue;
import spoon.testing.utils.ModelUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
Expand All @@ -37,6 +38,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static spoon.testing.utils.ModelUtils.canBeBuilt;
import static spoon.testing.utils.ModelUtils.createFactory;

/**
* @author Lionel Seinturier
Expand Down Expand Up @@ -474,6 +476,27 @@ public void testShortTypeReference() throws Exception {

}

@Test
public void testClearBoundsForTypeParameterReference() throws Exception {
final Factory factory = createFactory();
final CtTypeParameterReference reference = factory.Type().createTypeParameterReference("T");
reference.addBound(factory.Type().createReference(String.class));

assertEquals(1, reference.getBounds().size());

reference.setBounds(null);

assertEquals(0, reference.getBounds().size());

reference.addBound(factory.Type().createReference(String.class));

assertEquals(1, reference.getBounds().size());

reference.setBounds(new ArrayList<>());

assertEquals(0, reference.getBounds().size());
}

class A {
class Tacos<K> {
}
Expand Down

0 comments on commit c23a63e

Please sign in to comment.