Skip to content

Commit

Permalink
feat(ast): Adds CtTypeInformation#isGenerics method.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Aug 25, 2016
1 parent 62ad2cd commit a1c266b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
</scm>

<properties>
<java.src.version>1.8</java.src.version>
<java.src.version>1.7</java.src.version>
<java.test.version>1.8</java.test.version>
<runtime.log>target/velocity.log</runtime.log>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ public boolean isAnnotationType() {
return false;
}

@Override
public boolean isGenerics() {
return false;
}

@Override
public List<CtFieldReference<?>> getAllFields() {
List<CtFieldReference<?>> l = new ArrayList<>(getFields().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ public boolean isAnnotationType() {
}
}

@Override
public boolean isGenerics() {
return false;
}

boolean isShadow;

@Override
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/spoon/test/generics/GenericsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -557,4 +558,16 @@ public boolean matches(CtTypeParameterReference element) {
assertNotNull(parameterReference.getDeclaration());
}
}

@Test
public void testIsGenericsMethod() throws Exception {
CtType<Tacos> 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());
}
}

0 comments on commit a1c266b

Please sign in to comment.