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

feature CtQuery#filterChildren(null) #1140

Merged
merged 2 commits into from
Jan 21, 2017

Conversation

pvojtechovsky
Copy link
Collaborator

Support for calling filterChildren without filter. It returns all visited elements.

@pvojtechovsky
Copy link
Collaborator Author

What is the problem? I do not know how to fix it.

@pvojtechovsky
Copy link
Collaborator Author

pvojtechovsky commented Jan 20, 2017

Filter filter = new ...;
element.map(new ParameterScopeQuery).map(e->filter.matches(e))...

Martin wrote: I like it, esp with lambdas, it's clear and explicit. Let's first aim at this simplest version.

There is one more problem when Filter is used in existing CtQuery#map(CtFunction). It is that query engine will throw ClassCastException, when Filter input type does not matches.

So you have to write

Filter filter = new ...;
element.map(new ParameterScopeQuery)
  .map(e->filter.matches(e))
  .failurePolicy(QueryFailurePolicy.IGNORE)...

Do you still like it? I vote for one of these methods

  • CtQuery#filter(Filter)
  • CtQuery#mapFilter(Filter)

Note: we cannot implement CtQuery#map(Filter), because it would avoid usage of lambdas, because of ambiguity with CtQuery#map(CtFunction)

Or any other solution - if somebody has one.

@monperrus
Copy link
Collaborator

super atomic PR, thanks.

Would you add one line of Javadoc in filterChildren to document the contract?

@monperrus
Copy link
Collaborator

It is that query engine will throw ClassCastException, when Filter input type does not matches.

which is the default behavior we want, because it's very explicit at runtime, right?

@pvojtechovsky
Copy link
Collaborator Author

It is that query engine will throw ClassCastException, when Filter input type does not matches.

which is the default behavior we want, because it's very explicit at runtime, right?

right. We want to throw CCE on standard mapping functions, because otherwise it is very hard to found "Why my query does not work and returns nothing..."

@pvojtechovsky
Copy link
Collaborator Author

Done from my point of view

@monperrus
Copy link
Collaborator

rebase?

@pvojtechovsky
Copy link
Collaborator Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants