-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
There was a problem hiding this 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 :)
fdeb80a
to
2b3496b
Compare
👀 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)); |
There was a problem hiding this comment.
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 ;).
Currently there is a bug where it doesn't apply matches. Perhaps because it can apply multiple rules? |
… be updated and checked - that is for tomorrow
…und matches for some cases...
25ed983
to
0d11b92
Compare
There was a problem hiding this 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! 🚀
// XXX: @Stephan, I'm still not sure about this one. Since it is actually an | ||
// UnmodifiableIterator... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both do; LGTM :)
/** 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(); | ||
} | ||
} |
There was a problem hiding this comment.
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.
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.