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

Add a few Collection templates #8

Merged
merged 15 commits into from
Feb 14, 2021
Merged

Conversation

rickie
Copy link
Member

@rickie rickie commented Dec 28, 2020

I'm not sure about everything but I wanted to try some things out!
Let me know what can be improved or why I should do things differently :).

There are a few questions in the code, I'll remove them later on.

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just FYI: I did see this PR, but didn't get around to a closer look yet. Aiming for some time today :)

@Stephan202 Stephan202 force-pushed the rossendrijver/try_out_templates branch from fdeb80a to 2b3496b Compare December 30, 2020 12:52
@Stephan202
Copy link
Member

👀 Test failure.

(I did not forget about this PR. Hopefully can do a proper review round later this week :) )

@BeforeTemplate
Object[] before(ImmutableCollection<T> immutableCollection, S[] elem) {
return Refaster.anyOf(
immutableCollection.asList().toArray(elem), immutableCollection.asList().toArray(elem));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stephan202 , you are right. I tried to fix the test, the problem is in this template.
Half of the testcases for this one work.
I don't understand why the other half doesn't.
I wanted to discuss it on Thursday ;).

@rickie
Copy link
Member Author

rickie commented Jan 10, 2021

Currently there is a bug where it doesn't apply matches. Perhaps because it can apply multiple rules?
Maybe we can take a look together? I'm not sure where to look now haha @Stephan202

@Stephan202 Stephan202 force-pushed the rossendrijver/try_out_templates branch from 25ed983 to 0d11b92 Compare February 14, 2021 13:33
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see I had two old unflushed comments; I think we already discussed these during a previous meeting. Rebased and added a commit; will merge once built! 🚀

Comment on lines 353 to 354
// XXX: @Stephan, I'm still not sure about this one. Since it is actually an
// UnmodifiableIterator...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both do; LGTM :)

Comment on lines 304 to 283
/** Prefer calling {@link Collection#toArray(Object[])} without a size parameter. */
static final class CollectionToObjectArray<T> {
@BeforeTemplate
Object[] before(Collection<T> collection, int size) {
return collection.toArray(new Object[size]);
}

@AfterTemplate
Object[] after(Collection<T> collection, int size) {
return collection.toArray(Object[]::new);
}
}

/** Prefer {@link Collection#toArray()} over {@link Collection#toArray(Object[])}. */
static final class CollectionToArray<T> {
@BeforeTemplate
Object[] before(Collection<T> collection) {
return collection.toArray(Object[]::new);
}

@AfterTemplate
Object[] after(Collection<T> collection) {
return collection.toArray();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of the first one is rewritten to the second one. Ideally we generalize the first to any T[], but while the @BeforeTemplate expression could use Refaster.newArray(size), there is currently no equivalent placeholder for T[]::new. Something for the project idea list :)

So for now we can collapse these rules.

@Stephan202 Stephan202 merged commit 89033e2 into master Feb 14, 2021
@Stephan202 Stephan202 deleted the rossendrijver/try_out_templates branch February 14, 2021 13:57
@Stephan202 Stephan202 added this to the 0.1.0 milestone Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants