use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class DefaultCoreFactory method createWildcardReference.
@Override
public CtWildcardReference createWildcardReference() {
CtWildcardReference e = new CtWildcardReferenceImpl();
e.setFactory(getMainFactory());
return e;
}
use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class GenericsTest method checkFakeTpl.
private void checkFakeTpl(CtInterface<?> fakeTplItf) {
assertNotNull(fakeTplItf);
CtMethod<?> applyMethod = fakeTplItf.getMethodsByName("apply").get(0);
CtTypeReference<?> returnType = applyMethod.getType();
assertEquals("T", returnType.getSimpleName());
assertTrue(returnType instanceof CtTypeParameterReference);
assertEquals("CtElement", returnType.getSuperclass().getSimpleName());
CtParameter<?> targetType = applyMethod.getParameters().get(0);
List<CtTypeReference<?>> targetTypeArgument = targetType.getType().getActualTypeArguments();
assertEquals(1, targetTypeArgument.size());
assertTrue(targetTypeArgument.get(0) instanceof CtWildcardReference);
CtMethod<?> testMethod = fakeTplItf.getMethodsByName("test").get(0);
List<CtParameter<?>> parameters = testMethod.getParameters();
assertEquals(3, parameters.size());
CtParameter thirdParam = parameters.get(2);
assertTrue(thirdParam.getType() instanceof CtTypeParameterReference);
}
use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class JavaReflectionTreeBuilder method visitType.
@Override
public void visitType(WildcardType type) {
final CtWildcardReference wildcard = factory.Core().createWildcardReference();
wildcard.setUpper(type.getUpperBounds() != null && !type.getUpperBounds()[0].equals(Object.class));
enter(new TypeReferenceRuntimeBuilderContext(wildcard));
super.visitType(type);
exit();
contexts.peek().addTypeName(wildcard);
}
use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class ClassTypingContext method isSubTypeArg.
/**
* @return true if actualType argument `subArg` is fitting as a subtype of actual type argument `superArg`
*/
private boolean isSubTypeArg(CtTypeReference<?> subArg, CtTypeReference<?> superArg) {
if (superArg instanceof CtWildcardReference) {
CtWildcardReference wr = (CtWildcardReference) superArg;
CtTypeReference<?> superBound = wr.getBoundingType();
if (superBound.equals(wr.getFactory().Type().OBJECT)) {
// everything extends from object, nothing is super of Object
return wr.isUpper();
}
if (subArg instanceof CtWildcardReference) {
CtWildcardReference subWr = (CtWildcardReference) subArg;
CtTypeReference<?> subBound = subWr.getBoundingType();
if (subBound.equals(wr.getFactory().Type().OBJECT)) {
// nothing is super of object
return false;
}
if (wr.isUpper() != subWr.isUpper()) {
// one is "super" second is "extends"
return false;
}
if (wr.isUpper()) {
// both are extends
return subBound.isSubtypeOf(superBound);
}
// both are super
return superBound.isSubtypeOf(subBound);
}
if (wr.isUpper()) {
return subArg.isSubtypeOf(superBound);
} else {
return superBound.isSubtypeOf(subArg);
}
}
// superArg is not a wildcard. Only same type is matching
return subArg.equals(superArg);
}
use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class LambdaTest method testGetDeclarationOnTypeParameterFromLambda.
@Test
public void testGetDeclarationOnTypeParameterFromLambda() {
List<CtTypeParameterReference> listCtTPR = launcher.getModel().getElements(new TypeFilter<>(CtTypeParameterReference.class));
for (CtTypeParameterReference typeParameterReference : listCtTPR) {
if (!(typeParameterReference instanceof CtWildcardReference) && typeParameterReference.getDeclaration() == null) {
System.err.println(typeParameterReference.getSimpleName() + " from parent " + typeParameterReference.getParent(CtClass.class).getPosition() + " has null declaration");
typeParameterReference.getDeclaration();
fail();
}
}
}
Aggregations