[java] Make nodes have access to their text#2166
Merged
Merged
Conversation
Generated by 🚫 Danger |
…s to underlying text for all java nodes
Nobody cares and they make up a significant part of token sequences. Alternatively we could intern them which would most likely yield near 100% cache hit, because of indentation patterns.
d92a6f7 to
4ce104a
Compare
oowekyala
added a commit
that referenced
this pull request
Jan 10, 2020
* Make Java nodes text-available * Introduce shared JavaccToken in pmd-core * Use factory to produce char streams Tests are still on java-grammar, since they use the DSL & newer AST structure. This is to prepare for other changes that concern all javacc languages and should not be done on java-grammar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Java nodes now have a method
getText(), which provides access to the full text of the node. This is mostly intended as a debugging aid, and not as a way of writing rules (hence the@NoAttribute).This implementation uses:
Both of these classes are added to pmd-core instead of generated by Javacc then hacked through Ant search/replace. I think, most of our javacc parser implementations could use the same token implementations and get the feature for nearly free. It's also nice to remove the duplication of the Token class (currently one per javacc module).
Future work: