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

Improve XPathPathExpr code quality #307

Merged
merged 1 commit into from May 8, 2018
Merged

Improve XPathPathExpr code quality #307

merged 1 commit into from May 8, 2018

Conversation

dcbriccetti
Copy link
Contributor

@dcbriccetti dcbriccetti commented May 8, 2018

Move eval method from XPathPathExpr to new class, XPathPathExprEval, and modernize its code and make it much more understandable.

(cherry picked from commit 2d5998d)

What has been done to verify that this works as intended?

I saw that all tests still pass, and I stepped through the code in the debugger.

Why is this the best possible solution? Were any other approaches considered?

The goal was to separate the eval concern from the rest of XPathPathExpr, and to modernize code using automatic IDEA refactorings.

Are there any risks to merging this code? If so, what are they?

The risk seems low. I used refactorings like extract method, which are safe.

@codecov-io
Copy link

codecov-io commented May 8, 2018

Codecov Report

Merging #307 into master will increase coverage by 0.02%.
The diff coverage is 54.28%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #307      +/-   ##
============================================
+ Coverage     45.91%   45.94%   +0.02%     
- Complexity     2680     2684       +4     
============================================
  Files           233      234       +1     
  Lines         13316    13323       +7     
  Branches       2589     2580       -9     
============================================
+ Hits           6114     6121       +7     
- Misses         6390     6391       +1     
+ Partials        812      811       -1
Impacted Files Coverage Δ Complexity Δ
src/org/javarosa/core/model/ItemsetBinding.java 55.55% <100%> (ø) 11 <0> (ø) ⬇️
src/org/javarosa/xpath/expr/XPathPathExpr.java 54.59% <53.33%> (+2.04%) 40 <13> (-4) ⬇️
src/org/javarosa/xpath/expr/XPathPathExprEval.java 55.17% <55.17%> (ø) 9 <9> (?)
...rg/javarosa/core/model/instance/TreeReference.java 62.21% <0%> (-0.39%) 77% <0%> (-1%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8cf8568...3932c23. Read the comment docs.

}

return new XPathNodeset(nodesetRefs, m, ec);
public XPathNodeset eval(final DataInstance unusedDataInstance, final EvaluationContext ec) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would argue to remove these finals here. Maybe the one for TreeReference ref in getReference() is useful while it gets smaller but here it's just one line of code and those variables are just passed downstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I intended to remove them, and will now. They were part of the evolution of the code within this refactoring (originally the first parameter was never read, but reassigned!).

Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, it's great that you fixed that one :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least I made it obvious that all those callers are passing in something that is ignored.

return false;
}

return ExtUtil.arrayEquals(steps, x.steps) && (init_context == INIT_CONTEXT_EXPR ? filtExpr.equals(x.filtExpr) : true);
return ExtUtil.arrayEquals(steps, x.steps) && (init_context != INIT_CONTEXT_EXPR || filtExpr.equals(x.filtExpr));
Copy link
Contributor

Choose a reason for hiding this comment

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

I might have to wait for tomorrow to be fresh again to really be sure that this does the same, but I'm guessing you've just let IntelliJ simplify the boolean expression 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I would not be confident making that change on my own.


parentsAllowed = false;
if (func.args.length != 1) {
throw new XPathUnsupportedException("instance() function used with " + func.args.length + " arguments. Expecting 1 argument");
Copy link
Contributor

Choose a reason for hiding this comment

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

"arguement" sounds much more interesting. Spelling is overrated :D

…and clean up its code

(cherry picked from commit 2d5998d)
Copy link
Contributor

@ggalmazor ggalmazor left a comment

Choose a reason for hiding this comment

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

Thanks for caring about these things. Easier collaboration! Yay!

@lognaturel lognaturel merged commit 541a10c into getodk:master May 8, 2018
@dcbriccetti dcbriccetti deleted the improve-XPathPathExpr branch May 8, 2018 20:30
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

4 participants