Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use modern syntax for types - use diamonds #2296

Merged
merged 1 commit into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/test/java/spoon/test/api/NoClasspathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void test() throws Exception {
{
CtMethod<?> method = clazz.getMethod("method", new CtTypeReference[0]);
assertNotNull(method);
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class));
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<>(CtInvocation.class));
assertEquals(1, invocations.size());
CtInvocation<?> c = invocations.get(0);
assertEquals("method", c.getExecutable().getSimpleName());
Expand All @@ -80,7 +80,7 @@ public void test() throws Exception {
{
CtMethod<?> method = clazz.getMethod("m2", new CtTypeReference[0]);
assertNotNull(method);
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class));
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<>(CtInvocation.class));
assertEquals(3, invocations.size());
CtInvocation<?> c = invocations.get(1);
assertEquals("second", c.getExecutable().getSimpleName());
Expand All @@ -90,7 +90,7 @@ public void test() throws Exception {
{
CtMethod<?> method = clazz.getMethod("m1", new CtTypeReference[0]);
assertNotNull(method);
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class));
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<>(CtInvocation.class));
assertEquals(1, invocations.size());
invocations.get(0);
assertEquals("x.y.z.method()", method.getBody().getStatement(0).toString());
Expand All @@ -99,7 +99,7 @@ public void test() throws Exception {
{
CtMethod<?> method = clazz.getMethod("m3", new CtTypeReference[0]);
assertNotNull(method);
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class));
List<CtInvocation<?>> invocations = method.getElements(new TypeFilter<>(CtInvocation.class));
assertEquals(1, invocations.size());
invocations.get(0);
CtLocalVariable<?> statement = method.getBody().getStatement(0);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/model/SwitchCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testIterationStatements() {
assertEquals(0, ((CtLiteral<?>) c.getCaseExpression()).getValue());
assertEquals(2, c.getStatements().size());

List<CtStatement> l = new ArrayList<CtStatement>();
List<CtStatement> l = new ArrayList<>();

// this compiles (thanks to the new CtCase extends CtStatementList)
for (CtStatement s : c) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/spoon/test/parent/ParentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static void checkParentContract(CtPackage pack) {

// the scanner and the parent are in correspondence
new CtScanner() {
Deque<CtElement> elementStack = new ArrayDeque<CtElement>();
Deque<CtElement> elementStack = new ArrayDeque<>();
@Override
public void scan(CtElement e) {
if (e==null) { return; }
Expand All @@ -243,7 +243,7 @@ public void testGetParentWithFilter() throws Exception {
CtMethod<Object> m = clazz.getMethod("m");
// get three = "" in one = two = three = "";
CtExpression statement = ((CtAssignment)((CtAssignment)m.getBody().getStatement(3)).getAssignment()).getAssignment();
CtPackage ctPackage = statement.getParent(new TypeFilter<CtPackage>(CtPackage.class));
CtPackage ctPackage = statement.getParent(new TypeFilter<>(CtPackage.class));
assertEquals(Foo.class.getPackage().getName(), ctPackage.getQualifiedName());

CtStatement ctStatement = statement
Expand Down Expand Up @@ -278,7 +278,7 @@ public boolean matches(CtType element) {
assertNotEquals(ctStatement1.getParent(CtType.class), parent);

// not present element
CtWhile ctWhile = ctStatement1.getParent(new TypeFilter<CtWhile>(CtWhile.class));
CtWhile ctWhile = ctStatement1.getParent(new TypeFilter<>(CtWhile.class));
assertEquals(null, ctWhile);

CtStatement statementParent = statement
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/spoon/test/pkg/PackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public void testRenamePackageAndPrettyPrint() throws Exception {
spoon.addInputResource("./src/test/java/spoon/test/pkg/testclasses/Foo.java");
spoon.buildModel();

CtPackage ctPackage = spoon.getModel().getElements(new NamedElementFilter<CtPackage>(CtPackage.class, "spoon")).get(0);
CtPackage ctPackage = spoon.getModel().getElements(new NamedElementFilter<>(CtPackage.class, "spoon")).get(0);
ctPackage.setSimpleName("otherName");

CtClass foo = spoon.getModel().getElements(new NamedElementFilter<CtClass>(CtClass.class, "Foo")).get(0);
CtClass foo = spoon.getModel().getElements(new NamedElementFilter<>(CtClass.class, "Foo")).get(0);
assertEquals("otherName.test.pkg.testclasses.Foo", foo.getQualifiedName());

PrettyPrinter prettyPrinter = new DefaultJavaPrettyPrinter(spoon.getEnvironment());
Expand All @@ -163,10 +163,10 @@ public void testRenamePackageAndPrettyPrintNoclasspath() throws Exception {
spoon.getEnvironment().setNoClasspath(true);
spoon.buildModel();

CtPackage ctPackage = spoon.getModel().getElements(new NamedElementFilter<CtPackage>(CtPackage.class, "app")).get(0);
CtPackage ctPackage = spoon.getModel().getElements(new NamedElementFilter<>(CtPackage.class, "app")).get(0);
ctPackage.setSimpleName("otherName");

CtClass foo = spoon.getModel().getElements(new NamedElementFilter<CtClass>(CtClass.class, "Test")).get(0);
CtClass foo = spoon.getModel().getElements(new NamedElementFilter<>(CtClass.class, "Test")).get(0);
assertEquals("otherName.Test", foo.getQualifiedName());

PrettyPrinter prettyPrinter = new DefaultJavaPrettyPrinter(spoon.getEnvironment());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/position/PositionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public void getPositionOfImplicitBlock() {
launcher.addInputResource("./src/test/java/spoon/test/position/testclasses/ImplicitBlock.java");
launcher.buildModel();

CtIf ifElement = launcher.getModel().getElements(new TypeFilter<CtIf>(CtIf.class)).get(0);
CtIf ifElement = launcher.getModel().getElements(new TypeFilter<>(CtIf.class)).get(0);
CtStatement thenStatement = ifElement.getThenStatement();

assertTrue(thenStatement instanceof CtBlock);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/reference/TypeReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void loadReferencedClassFromClasspath() throws Exception {

// now we retrieve the reference to ReferencedClass
CtTypeReference referencedType = null;
ReferenceTypeFilter<CtTypeReference> referenceTypeFilter = new ReferenceTypeFilter<CtTypeReference>(CtTypeReference.class);
ReferenceTypeFilter<CtTypeReference> referenceTypeFilter = new ReferenceTypeFilter<>(CtTypeReference.class);
List<CtTypeReference> elements = Query.getElements(theClass, referenceTypeFilter);
for (CtTypeReference reference : elements) {
if (reference.getQualifiedName().equals(referencedQualifiedName)) {
Expand Down Expand Up @@ -635,7 +635,7 @@ public void testTypeReferenceWithGenerics() throws Exception {
launcher.getEnvironment().setNoClasspath(true);
launcher.buildModel();

CtField field = launcher.getModel().getElements(new TypeFilter<CtField>(CtField.class)).get(0);
CtField field = launcher.getModel().getElements(new TypeFilter<>(CtField.class)).get(0);
CtTypeReference fieldTypeRef = field.getType();

assertEquals("spoon.test.imports.testclasses.withgenerics.Target", fieldTypeRef.getQualifiedName());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/reference/VariableAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testDeclarationArray() throws Exception {
final CtType<Pozole> aPozole = ModelUtils.buildClass(Pozole.class);
final CtMethod<Object> m2 = aPozole.getMethod("m2");
final CtArrayWrite<?> ctArrayWrite = m2.getElements(new TypeFilter<CtArrayWrite<?>>(CtArrayWrite.class)).get(0);
final CtLocalVariable expected = m2.getElements(new TypeFilter<CtLocalVariable>(CtLocalVariable.class)).get(0);
final CtLocalVariable expected = m2.getElements(new TypeFilter<>(CtLocalVariable.class)).get(0);

assertEquals(expected, ((CtVariableAccess) ctArrayWrite.getTarget()).getVariable().getDeclaration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ReferenceQueryTest {
@Test
public void getAllTypeReferencesInEnum() throws Exception {
CtEnum<ReferenceQueryTestEnum> testEnum = build("spoon.test.reflect.visitor.testclasses", "ReferenceQueryTestEnum");
List< CtTypeReference<?> > enumTypeRefs = Query.getElements(testEnum, new ReferenceTypeFilter< CtTypeReference<?> >(CtTypeReference.class));
List< CtTypeReference<?> > enumTypeRefs = Query.getElements(testEnum, new ReferenceTypeFilter<>(CtTypeReference.class));
TypeFactory typeFactory = testEnum.getFactory().Type();
for (Class<?> c : new Class<?>[]{Integer.class, Long.class, Boolean.class, Number.class, String.class, Void.class}) {
Assert.assertTrue("the reference query on the enum should return all the types defined in the enum declaration", enumTypeRefs.contains(typeFactory.createReference(c)));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/signature/SignatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testNullSignature() throws Exception {
// since the signature is null, CtElement.equals throws an exception and
// should not
CtLiteral<?> lit2 = ((CtLiteral<?>) lit).clone();
HashSet<CtExpression<?>> s = new HashSet<CtExpression<?>>();
HashSet<CtExpression<?>> s = new HashSet<>();
s.add(lit);
s.add(lit2);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public void testMethodInvocationSignatureWithVariableAccess() throws Exception{

//**FIRST PART: passing local variable access.
///--------From the first method we take the method invocations
TreeSet<CtMethod<?>> ts = new TreeSet<CtMethod<?>>(new DeepRepresentationComparator());
TreeSet<CtMethod<?>> ts = new TreeSet<>(new DeepRepresentationComparator());
ts.addAll(clazz1.getMethods());
CtMethod[] methodArray = ts.toArray(new CtMethod[0]);
CtMethod<?> methodInteger = methodArray[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void equalPositionsHaveSameHashcode() throws Exception {
String sampleClassName = "SampleClass";
String qualifiedName = packageName + "." + sampleClassName;

Filter<CtMethod<?>> methodFilter = new TypeFilter<CtMethod<?>>(CtMethod.class);
Filter<CtMethod<?>> methodFilter = new TypeFilter<>(CtMethod.class);

Factory aFactory = factoryFor(packageName, sampleClassName);
List<CtMethod<?>> methods = aFactory.Class().get(qualifiedName).getElements(methodFilter);
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/spoon/test/targeted/TargetedExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testTargetOfFieldAccess() throws Exception {
final CtClass<Object> type = factory.Class().get(Foo.class);
CtConstructor<?> constructor = type.getConstructors().toArray(new CtConstructor<?>[0])[0];

final List<CtFieldAccess<?>> elements = constructor.getElements(new TypeFilter<CtFieldAccess<?>>(CtFieldAccess.class));
final List<CtFieldAccess<?>> elements = constructor.getElements(new TypeFilter<>(CtFieldAccess.class));
assertEquals(2, elements.size());

assertEquals("Target is CtThisAccessImpl if there is a 'this' explicit.", CtThisAccessImpl.class, elements.get(0).getTarget().getClass());
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testTargetsOfFieldAccess() throws Exception {

final CtThisAccess<Foo> expectedThisAccess = type.getFactory().Code().createThisAccess(expectedType);

final List<CtFieldAccess<?>> elements = fieldMethod.getElements(new TypeFilter<CtFieldAccess<?>>(CtFieldAccess.class));
final List<CtFieldAccess<?>> elements = fieldMethod.getElements(new TypeFilter<>(CtFieldAccess.class));
assertEquals(10, elements.size());
assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.i"), elements.get(0));
assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("i"), elements.get(1));
Expand All @@ -157,7 +157,7 @@ public void testTargetsOfStaticFieldAccess() throws Exception {
final CtTypeAccess<Foo> expectedTypeAccess = type.getFactory().Code().createTypeAccess(expectedType);
final CtTypeAccess<Bar> expectedBarTypeAccess = type.getFactory().Code().createTypeAccess(expectedBarType);

final List<CtFieldAccess<?>> elements = constructor.getElements(new TypeFilter<CtFieldAccess<?>>(CtFieldAccess.class));
final List<CtFieldAccess<?>> elements = constructor.getElements(new TypeFilter<>(CtFieldAccess.class));
assertEquals(10, elements.size());
assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldRead.class).declaringType(expectedType).target(expectedThisAccess).result("this.k"), elements.get(0));
assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldRead.class).declaringType(expectedType).target(expectedTypeAccess).result("spoon.test.targeted.testclasses.Foo.k"), elements.get(1));
Expand Down Expand Up @@ -281,7 +281,7 @@ public void testTargetsOfInv() throws Exception {
final CtThisAccess<Foo> expectedSuperThisAccess = factory.Code().createThisAccess(expectedType);
expectedSuperThisAccess.setTarget(superClassTypeAccess);

final List<CtInvocation<?>> elements = type.getMethodsByName("inv").get(0).getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class));
final List<CtInvocation<?>> elements = type.getMethodsByName("inv").get(0).getElements(new TypeFilter<>(CtInvocation.class));
assertEquals(7, elements.size());

assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(CtConstructorCallImpl.class).result("new spoon.test.targeted.testclasses.Foo(0, 0).method()"), elements.get(0));
Expand Down Expand Up @@ -311,7 +311,7 @@ public void testStaticTargetsOfInv() throws Exception {
final CtTypeAccess<Bar> expectedBarTypeAccess = type.getFactory().Code().createTypeAccess(expectedBarType);

final CtMethod<?> invMethod = type.getMethodsByName("invStatic").get(0);
final List<CtInvocation<?>> elements = invMethod.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class));
final List<CtInvocation<?>> elements = invMethod.getElements(new TypeFilter<>(CtInvocation.class));
assertEquals(8, elements.size());
assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(CtConstructorCallImpl.class).result("new spoon.test.targeted.testclasses.Foo(0, 0).staticMethod()"), elements.get(0));
assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(CtFieldReadImpl.class).result("foo.staticMethod()"), elements.get(1));
Expand Down Expand Up @@ -342,7 +342,7 @@ public void testTargetsOfInvInInnerClass() throws Exception {
final CtThisAccess expectedNestedAccess = factory.Code().createThisAccess(expectedNested);

final CtMethod<?> innerInvMethod = innerClass.getMethodsByName("innerInv").get(0);
final List<CtInvocation<?>> elements = innerInvMethod.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class));
final List<CtInvocation<?>> elements = innerInvMethod.getElements(new TypeFilter<>(CtInvocation.class));
assertEquals(8, elements.size());
expectedThisAccess.setType(expectedInnerClass);
assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("inv()"), elements.get(0));
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/spoon/test/trycatch/TryCatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void testRethrowingExceptionsJava7() throws Exception {
// Checks we throw 2 exceptions and not one.
assertEquals(2, thrownTypes.size());

CtTry ctTry = clazz.getElements(new TypeFilter<CtTry>(CtTry.class))
CtTry ctTry = clazz.getElements(new TypeFilter<>(CtTry.class))
.get(0);

Class<? extends CtCatchVariableReference> exceptionClass = ctTry
Expand All @@ -154,7 +154,7 @@ public void testTryWithOneResource() throws Exception {

CtMethod<?> method = clazz.getMethodsByName("readFirstLineFromFile").get(0);
CtTryWithResource ctTryWithResource = method.getElements(
new TypeFilter<CtTryWithResource>(CtTryWithResource.class)).get(0);
new TypeFilter<>(CtTryWithResource.class)).get(0);

// Checks try has only one resource.
assertTrue(ctTryWithResource.getResources().size() == 1);
Expand All @@ -166,7 +166,7 @@ public void testTryWithResources() throws Exception {

CtMethod<?> method = clazz.getMethodsByName("writeToFileZipFileContents").get(0);
CtTryWithResource ctTryWithResource = method.getElements(
new TypeFilter<CtTryWithResource>(CtTryWithResource.class)).get(0);
new TypeFilter<>(CtTryWithResource.class)).get(0);

// Checks try has more than one resource.
assertTrue(ctTryWithResource.getResources().size() > 1);
Expand Down Expand Up @@ -301,7 +301,7 @@ public void testCatchWithUnknownExceptions() {
launcher.getEnvironment().setNoClasspath(true);
CtModel model = launcher.buildModel();

List<CtCatch> catches = model.getElements(new TypeFilter<CtCatch>(CtCatch.class));
List<CtCatch> catches = model.getElements(new TypeFilter<>(CtCatch.class));
assertNotNull(catches.get(0).getParameter().getType()); // catch with single UnknownException
assertNull(catches.get(1).getParameter().getType()); // multicatch with UnknownException
assertNull(catches.get(2).getParameter().getType()); // multicatch with UnknownException
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/spoon/test/type/TypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void testTypeAccessForTypeAccessInInstanceOf() throws Exception {
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));
final List<CtTypeAccess<?>> typeAccesses = eat.getElements(new TypeFilter<>(CtTypeAccess.class));
assertEquals(2, typeAccesses.size());

assertTrue(typeAccesses.get(0).getParent() instanceof CtBinaryOperator);
Expand All @@ -148,7 +148,7 @@ public void testTypeAccessOfArrayObjectInFullyQualifiedName() throws Exception {
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));
final List<CtTypeAccess<?>> typeAccesses = season.getElements(new TypeFilter<>(CtTypeAccess.class));
assertEquals(2, typeAccesses.size());

assertTrue(typeAccesses.get(0).getParent() instanceof CtBinaryOperator);
Expand Down Expand Up @@ -201,7 +201,7 @@ public void testIntersectionTypeReferenceInGenericsAndCasts() throws Exception {
assertIntersectionTypeForPozolePrepareMethod(aPozole, typeParameter.getSuperclass());

// Intersection type in casts.
final List<CtLambda<?>> lambdas = prepare.getElements(new TypeFilter<CtLambda<?>>(CtLambda.class));
final List<CtLambda<?>> lambdas = prepare.getElements(new TypeFilter<>(CtLambda.class));
assertEquals(1, lambdas.size());

assertEquals(1, lambdas.get(0).getTypeCasts().size());
Expand Down Expand Up @@ -246,7 +246,7 @@ public void testTypeReferenceInGenericsAndCasts() throws Exception {
assertIntersectionTypeForPozoleFinishMethod(aPozole, typeParameter.getSuperclass());

// Intersection type in casts.
final List<CtLambda<?>> lambdas = prepare.getElements(new TypeFilter<CtLambda<?>>(CtLambda.class));
final List<CtLambda<?>> lambdas = prepare.getElements(new TypeFilter<>(CtLambda.class));
assertEquals(1, lambdas.size());

assertEquals(1, lambdas.get(0).getTypeCasts().size());
Expand Down