GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [apex] Fix for #3569 - Added new configuration properties allowCommentedBlocks and allowExceptionNameRegex to EmptyCatchBlock by SCWells72 · Pull Request #3574 · pmd/pmd Conversation
|
Generated by 🚫 Danger |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can you please add documentation changes needed for the new property to this PR?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…o go a different route and add the exact same configuration properties that the analogous Java rule offers, specifically 'allowCommentedBlocks' and 'allowExceptionNameRegex', both with the exact same defaults as the Java rule, i.e., 'false' and '(expected|ignored)' respectively. Adding 'allowExceptionNameRegex' was quite straightforward. However, 'allowCommentedBlocks' was a bit more challenging because there was no notion of whether a block contained comments. I had to augment the lexer/parser/tree builder logic to capture all comment tokens and then use them to denote whether a catch block contained comments of any sort. The way I did this with a new intermediate abstract base node class for comment containers, we could denote the same for the other Apex block node types. In the spirit of keeping these changes narrow in scope, though, I only changed the inheritance hierarchy for ASTCatchBlockStatement. If/when we need to be able to ask the same question about other block types, it should be trivial to update them to support it. Test cases have been updated accordingly.
|
New commit added that pretty much changes the approach so that it matches the existing Java precedent. I like this much better. Thanks for the suggestion and lead, @oowekyala! All reviewers and interested parties are invited to provide feedback on the new approach. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@SCWells72 thanks for the update. Could you please update the PR description to match the new properties? The PR description is very helpful for creating the release notes... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@rsoesemann Please don't forget to update the release notes when merging. See https://pmd.github.io/latest/pmd_projectdocs_committers_merging_pull_requests.html for the procedure on how to merge pull requests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@adangel definitely me and @SCWells72 will provide that in a separate PR. Sorry that I forget that there is a process that requires this to be part of each PR. Looks like you always did the merge for me. Let me know if you prefer to keep control over merges and rather not have me do it. I just wasn't sure what happens when I just let it linger around. We really wanted to get as much a possible into 6.40. Scott, can you please create a seperate PR with a Release note proposal. I will review it asap. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@rsoesemann and @adangel, no problem on the release notes update. I'm assuming a single set of changes for all of my merged PRs in a single new PR is okay? I won't get a chance to do it until this afternoon as I have an outage this morning, but I'll get it done shortly. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@rsoesemann regarding the request for additional documentation, both of these properties are documented in the rule definition XML: <property name="allowCommentedBlocks" type="Boolean" description="Empty blocks containing comments will be skipped" value="false"/> <property name="allowExceptionNameRegex" type="Regex" description="Empty blocks catching exceptions with names matching this regular expression will be skipped" value="^(ignored|expected)$"/> Was anything else needed, or is that sufficient? @adangel I've updated the PR information to reflect the actual changes vs. the original ones. Let me know if you need more than what I've provided. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Very cool, thanks! I'm not sure having an ASTCommentContainer is the best API in the long term, but for now this is a good enough solution
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| // If appropriate, determine whether this node contains comments or not | ||
| if (node instanceof ASTCommentContainer) { | ||
| ASTCommentContainer commentContainer = (ASTCommentContainer) node; | ||
| for (Token commentToken : allCommentTokens) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this looks quite inefficient, it iterates over all tokens in the file. I suppose the comment tokens are sorted, so one could do a binary search to find the first comment that is after the commentContainer.getBeginLine() (if any), then just check that that comment is also before commentContainer.getEndLine(). If you don't have time to do this, please add a //todo comment
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have to run to my son's soccer game but will take a look at this later today if possible. Minimally I'll add the requested TODO comment, but I don't think a more efficient determination should be difficult at all.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've just pushed another commit that includes an optimization for this check. It should also address the next comment about the selected data structure. A LinkedList should be more efficient for initial population as it avoids any need for resizing the underlying storage, and then it's converted into an ArrayList to guarantee the sort order (which is important because the highest line number must be the last element), and finally used to construct an array of flags denoting which lines in the file (up to the last reported comment) were for comments. At that point access is directly indexed, and the number of entries we ever have to examine is bounded by the number of lines in the catch block itself.
Please let me know if that doesn't address your remaining concerns.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ANTLRStringStream stream = new ANTLRStringStream(source); | ||
| ApexLexer lexer = new ApexLexer(stream); | ||
|
|
||
| List<Token> allCommentTokens = new LinkedList<>(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Given how it's used (append only, AFAICS), an ArrayList would be more efficient here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@adangel / @rsoesemann new PR #3580 opened with release notes update for this work. It looks like everything else has already been added to the release notes. Please let me know if I missed anything, and feel free to suggest (or even make) any changes to the release notes text that I've provided there. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ulation for 'setContainsComment' and marking the 'ASTCommentContainer' interface as experimental.
|
Merged as Release Note PR was provided, reviewed and merged. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@rsoesemann - please take this as a well-intentioned advice
Here are some comments/thoughts - although it is anyway already too late for this PR, but I hope it will be helpful to steer future contributions:
I don't think, it lingered around yet - the PR was only 2 or 3 days old. I think, when it's 7 days and there is no reaction, then we can start asking "Hey, what's up with this PR - any reasons why it is not merged yet?" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@adangel and @rsoesemann I'll certainly take responsibility for my part since I'm the one who bombarded you all with a number of pull requests in a very short period of time, all (unknowingly at the time) pretty close to the next release window. @adangel, for context, last week I added a real-time PMD Apex integration to my own project, Illuminated Cloud (a Salesforce dev plugin for JetBrains IDEs), and in the process of that work I recorded the various Apex rule-specific issues and omissions that I encountered while testing my own integration. Those were then logged as issues in GitHub, and finding myself with some time (and generally preferring not to report issues without being willing to help solve them), I decided to get my hands dirty, hence the resulting changes and pull requests. There was no real sense of urgency on getting those changes into a specific release, though. The rapid-fire nature of those PRs is just based on how I work on things. The good news is that I now have a better feel for what is requested/required in the PR process for this project, and I can apply those learnings to future contributions. I'm also happy to serialize my contributions a bit more, waiting for one to close before submitting another, if that helps. Just let me know and I'm happy to adjust accordingly. Apologies if I made the past few days more chaotic than necessary. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
All good @SCWells72. Being bombarded actually is a good thing. It was me not sticking with what I can and normally do but pushing things to get my stuff out of the door. I will stick with the role I always played here and not do deep code reviews or merges anymore. So the next time you need something asap count in more time. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[apex] EmptyCatchBlock rule should provide an option to ignore empty catch blocks in test methods
There was an error while loading. Please reload this page.