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();
}
}
}
use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class GenericsTest method testDiamondComplexGenericsRxJava.
@Test
public void testDiamondComplexGenericsRxJava() {
Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/generics/testclasses/rxjava/");
launcher.setSourceOutputDirectory("./target/spooned-rxjava");
launcher.run();
Factory factory = launcher.getFactory();
List<CtConstructorCall> invocations = factory.getModel().getElements(new TypeFilter<>(CtConstructorCall.class));
boolean invocationDetected = false;
for (CtConstructorCall call : invocations) {
if (call.getType().getSimpleName().equals("ToNotificationSubscriber")) {
assertEquals(1, call.getType().getActualTypeArguments().size());
CtTypeReference actualTA = call.getType().getActualTypeArguments().get(0);
assertTrue(actualTA instanceof CtWildcardReference);
assertEquals("?", actualTA.getSimpleName());
assertTrue(((CtWildcardReference) actualTA).isDefaultBoundingType());
invocationDetected = true;
}
}
canBeBuilt("./target/spooned-rxjava", 8);
assertTrue(invocationDetected);
}
use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class RoleHandlersGenerator method fixValueType.
private CtTypeReference<?> fixValueType(CtTypeReference<?> valueType) {
valueType = valueType.clone();
if (valueType instanceof CtTypeParameterReference) {
if (valueType instanceof CtWildcardReference) {
CtTypeReference<?> boundingType = ((CtTypeParameterReference) valueType).getBoundingType();
if (boundingType instanceof CtTypeParameterReference) {
((CtTypeParameterReference) valueType).setBoundingType(null);
}
return valueType;
}
CtTypeParameterReference tpr = (CtTypeParameterReference) valueType;
return getFactory().createWildcardReference();
}
for (int i = 0; i < valueType.getActualTypeArguments().size(); i++) {
valueType.getActualTypeArguments().set(i, fixValueType(valueType.getActualTypeArguments().get(i)));
}
valueType = valueType.box();
return valueType;
}
use of spoon.reflect.reference.CtWildcardReference in project spoon by INRIA.
the class MethodTypingContext method isSameMethodFormalTypeParameter.
private boolean isSameMethodFormalTypeParameter(CtTypeParameter scopeParam, CtTypeParameter superParam) {
CtTypeReference<?> scopeBound = getBound(scopeParam);
CtTypeReference<?> superBound = getBound(superParam);
int idxOfScopeBoundTypeParam = getIndexOfTypeParam(scopeParam.getTypeParameterDeclarer(), scopeBound);
if (idxOfScopeBoundTypeParam >= 0) {
int idxOfSuperBoundTypeParam = getIndexOfTypeParam(superParam.getTypeParameterDeclarer(), superBound);
if (idxOfSuperBoundTypeParam >= 0) {
/*
* Both type parameters have bound defined as sibling type parameter.
* Do not try to adaptType, because it would end with StackOverflowError
* They are same formal type parameters if index is same
*/
return idxOfScopeBoundTypeParam == idxOfSuperBoundTypeParam;
}
}
if (scopeBound.getActualTypeArguments().size() != superBound.getActualTypeArguments().size()) {
return false;
}
for (int i = 0; i < scopeBound.getActualTypeArguments().size(); i++) {
CtTypeReference scopeBoundATArg = scopeBound.getActualTypeArguments().get(i);
CtTypeReference superBoundATArg = superBound.getActualTypeArguments().get(i);
if (scopeBoundATArg instanceof CtWildcardReference && superBoundATArg instanceof CtWildcardReference) {
CtWildcardReference scopeBoundWildcard = (CtWildcardReference) scopeBoundATArg;
// T extends Comparable<? super T>
if (scopeBoundWildcard.getBoundingType().equals(scopeMethod.getFactory().Type().getDefaultBoundingType())) {
return true;
}
}
}
CtTypeReference<?> superBoundAdapted = adaptType(superBound);
if (superBoundAdapted == null) {
return false;
}
return scopeBound.getQualifiedName().equals(superBoundAdapted.getQualifiedName());
}
Aggregations