use of spoon.test.type.testclasses.Pozole in project spoon by INRIA.
the class TypeTest method testTypeAccessOfArrayObjectInFullyQualifiedName.
@Test
public void testTypeAccessOfArrayObjectInFullyQualifiedName() throws Exception {
// contract: A type access in fully qualified name must to rewrite well.
final String target = "./target/type";
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/type/testclasses");
launcher.setSourceOutputDirectory(target);
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Pozole> aPozole = launcher.getFactory().Class().get(Pozole.class);
final CtMethod<?> season = aPozole.getMethodsByName("season").get(0);
final List<CtTypeAccess<?>> typeAccesses = season.getElements(new TypeFilter<CtTypeAccess<?>>(CtTypeAccess.class));
assertEquals(2, typeAccesses.size());
assertTrue(typeAccesses.get(0).getParent() instanceof CtBinaryOperator);
assertEquals(BinaryOperatorKind.INSTANCEOF, ((CtBinaryOperator) typeAccesses.get(0).getParent()).getKind());
assertEquals("a instanceof java.lang.@spoon.test.annotation.testclasses.TypeAnnotation(integer = 1)" + System.lineSeparator() + "Object[]", typeAccesses.get(0).getParent().toString());
assertTrue(typeAccesses.get(1).getParent() instanceof CtBinaryOperator);
assertEquals(BinaryOperatorKind.INSTANCEOF, ((CtBinaryOperator) typeAccesses.get(1).getParent()).getKind());
assertEquals("a instanceof java.lang.Object[]", typeAccesses.get(1).getParent().toString());
canBeBuilt(target, 8, true);
}
use of spoon.test.type.testclasses.Pozole in project spoon by INRIA.
the class TypeTest method testIntersectionTypeReferenceInGenericsAndCasts.
@Test
public void testIntersectionTypeReferenceInGenericsAndCasts() throws Exception {
final String target = "./target/type";
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/type/testclasses");
launcher.setSourceOutputDirectory(target);
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Pozole> aPozole = launcher.getFactory().Class().get(Pozole.class);
final CtMethod<?> prepare = aPozole.getMethodsByName("prepare").get(0);
// Intersection type in generic types.
final List<CtClass> localTypes = prepare.getElements(new TypeFilter<>(CtClass.class));
assertEquals(1, localTypes.size());
// New type parameter declaration.
final CtTypeParameter typeParameter = localTypes.get(0).getFormalCtTypeParameters().get(0);
assertNotNull(typeParameter);
assertEquals("T", typeParameter.getSimpleName());
assertIntersectionTypeForPozolePrepareMethod(aPozole, typeParameter.getSuperclass());
// Intersection type in casts.
final List<CtLambda<?>> lambdas = prepare.getElements(new TypeFilter<CtLambda<?>>(CtLambda.class));
assertEquals(1, lambdas.size());
assertEquals(1, lambdas.get(0).getTypeCasts().size());
assertTrue(lambdas.get(0).getTypeCasts().get(0) instanceof CtIntersectionTypeReference);
final CtIntersectionTypeReference<?> intersectionType = lambdas.get(0).getTypeCasts().get(0).asCtIntersectionTypeReference();
assertEquals("java.lang.Runnable & java.io.Serializable", intersectionType.toString());
assertEquals(aPozole.getFactory().Type().createReference(Runnable.class), intersectionType.getBounds().stream().collect(Collectors.toList()).get(0));
assertEquals(aPozole.getFactory().Type().createReference(Serializable.class), intersectionType.getBounds().stream().collect(Collectors.toList()).get(1));
canBeBuilt(target, 8, true);
}
use of spoon.test.type.testclasses.Pozole in project spoon by INRIA.
the class TypeTest method testTypeAccessForDotClass.
@Test
public void testTypeAccessForDotClass() throws Exception {
// contract: When we use .class on a type, this must be a CtTypeAccess.
final String target = "./target/type";
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/type/testclasses");
launcher.setSourceOutputDirectory(target);
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Pozole> aPozole = launcher.getFactory().Class().get(Pozole.class);
final CtMethod<?> make = aPozole.getMethodsByName("make").get(0);
final List<CtFieldRead<?>> fieldClasses = make.getElements(new TypeFilter<CtFieldRead<?>>(CtFieldRead.class) {
@Override
public boolean matches(CtFieldRead<?> element) {
return "class".equals(element.getVariable().getSimpleName()) && super.matches(element);
}
});
assertEquals(4, fieldClasses.size());
for (CtFieldRead<?> fieldClass : fieldClasses) {
assertTrue(fieldClass.getTarget() instanceof CtTypeAccess);
}
canBeBuilt(target, 8, true);
}
use of spoon.test.type.testclasses.Pozole in project spoon by INRIA.
the class TypeTest method testTypeReferenceInGenericsAndCasts.
@Test
public void testTypeReferenceInGenericsAndCasts() throws Exception {
final String target = "./target/type";
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/type/testclasses");
launcher.setSourceOutputDirectory(target);
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Pozole> aPozole = launcher.getFactory().Class().get(Pozole.class);
final CtMethod<?> prepare = aPozole.getMethodsByName("finish").get(0);
// Intersection type in generic types.
final List<CtClass> localTypes = prepare.getElements(new TypeFilter<>(CtClass.class));
assertEquals(1, localTypes.size());
// New type parameter declaration.
final CtTypeParameter typeParameter = localTypes.get(0).getFormalCtTypeParameters().get(0);
assertNotNull(typeParameter);
assertEquals("T", typeParameter.getSimpleName());
assertIntersectionTypeForPozoleFinishMethod(aPozole, typeParameter.getSuperclass());
// Intersection type in casts.
final List<CtLambda<?>> lambdas = prepare.getElements(new TypeFilter<CtLambda<?>>(CtLambda.class));
assertEquals(1, lambdas.size());
assertEquals(1, lambdas.get(0).getTypeCasts().size());
assertEquals("java.lang.Runnable", lambdas.get(0).getTypeCasts().get(0).toString());
assertEquals(aPozole.getFactory().Type().createReference(Runnable.class), lambdas.get(0).getTypeCasts().get(0));
canBeBuilt(target, 8, true);
}
use of spoon.test.type.testclasses.Pozole in project spoon by INRIA.
the class TypeTest method testTypeAccessForTypeAccessInInstanceOf.
@Test
public void testTypeAccessForTypeAccessInInstanceOf() throws Exception {
// contract: the right hand operator must be a CtTypeAccess.
final String target = "./target/type";
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/java/spoon/test/type/testclasses");
launcher.setSourceOutputDirectory(target);
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final CtClass<Pozole> aPozole = launcher.getFactory().Class().get(Pozole.class);
final CtMethod<?> eat = aPozole.getMethodsByName("eat").get(0);
final List<CtTypeAccess<?>> typeAccesses = eat.getElements(new TypeFilter<CtTypeAccess<?>>(CtTypeAccess.class));
assertEquals(2, typeAccesses.size());
assertTrue(typeAccesses.get(0).getParent() instanceof CtBinaryOperator);
assertEquals(BinaryOperatorKind.INSTANCEOF, ((CtBinaryOperator) typeAccesses.get(0).getParent()).getKind());
assertEquals("a instanceof java.lang.String", typeAccesses.get(0).getParent().toString());
assertTrue(typeAccesses.get(1).getParent() instanceof CtBinaryOperator);
assertEquals(BinaryOperatorKind.INSTANCEOF, ((CtBinaryOperator) typeAccesses.get(1).getParent()).getKind());
assertEquals("a instanceof java.util.Collection<?>", typeAccesses.get(1).getParent().toString());
}
Aggregations