Comments (5)
I'm not sure if there's a way to do this without overriding visitor methods that only exist on newer JDK versions, which I don't think we can't use until the minimum supported JDK version is increased.
It's possible we can use some combination of reflection or proxies, and that might have acceptable performance.
If that doesn't work, perhaps multi-release jars could help here.
from error-prone.
To support this feature while also still supporting running Error Prone on JDK 11, possibly an approach could be taken similar to how GJF supports switch
expressions (and other newer constructs):
from error-prone.
That seems like it could work.
Similarly, I had wondered at some point about providing matchSwitchExpressionTree(Tree switchExpressionTree)
, which of course would typically require users to cast inside their implementation. That would work well for people who are building with newer JDKs, and for people who don't want to do that, they can use reflection. Either way, I think it would work fine for people who are running under older JDKs. As for how Error Prone calls it, I could see the Java17InputAstVisitor
approach, or I could see calling the match method reflectively from within scan
(rather than by overriding visitSwitchExpression
, which I believe would be trouble similar to that that @msridhar describes)... I think? (Compare a roughly similar approach in NullnessUtils.defaultAction
.)
It would be a wart forever, though we could try to partially smooth it over in the future by making a binary-compatible but source-incompatible change of the method to <T extends Tree & SwitchExpressionTree> matchSwitchExpressionTree(T tree)
. Or we could introduce the interface and method as clearly temporary ("CompatibilityShimSwitchExpressionTreeMatcher
" and "compatibilitiyShimMatchSwitchExpressionTree
?") so that the prime naming real estate is available for the real thing later. (That approach could also apply to @msridhar 's idea.)
from error-prone.
Upon further thought, this may be a bit ugly to support on JDK 11. The issue is that the matchXXX()
methods in the matcher interfaces usually take as an argument a Tree
of the relevant type. But here, that type would be SwitchExpressionTree
, which does not exist in JDK 11. For backward compatibility Error Prone would have to do something like create its own JDK 11-compatible data type wrapping SwitchExpressionTree
, using reflection internally to access its components.
from error-prone.
FWIW, it seems Checker Framework has gone with the option of just passing in a Tree
to the relevant switch expression method, and then providing utility functions for reflectively accessing the parts of the switch expression:
And they override scan
to call into the appropriate method:
from error-prone.
Related Issues (20)
- NoSuchMethodError when building under JDK21 HOT 1
- ImmutableEnumChecker in Enum where an attribute is a Record type which is immutatble HOT 1
- java: An unhandled exception was thrown by the Error Prone static analysis plugin. HOT 1
- Index out of bound exception. HOT 1
- DeadException rule throws java.lang.NullPointerException
- error: [DoNotCall] Calling run on Thread runs work on this thread
- Consider using an embedded standalone javac compiler instead of relying on JVM internals
- False positive: FieldCanBeLocal reported when overriding default record constructor HOT 1
- How to avoid "overlaps with existing replacements"
- Patch should identify itself
- Allow DoNotCall annotation on constructors HOT 1
- False positives for OperatorPrecedence bug pattern HOT 3
- IllegalArgumentException with MustBeClosedChecker HOT 1
- NullPointerException in NestedInstanceOfConditions HOT 1
- NullPointerException in InstanceOfAndCastMatchWrongType HOT 1
- All checks should treat `String#formatted` the same as `String#format` HOT 2
- An unhandled exception was thrown by the Error Prone static analysis plugin.
- Unhandled Exception in InconsistentCapitalization
- Crash in UnnecessaryStringBuilder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from error-prone.