Copilot commented on code in PR #53:
URL: https://github.com/apache/netbeans-jackpot30/pull/53#discussion_r4334771586


##########
cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java:
##########
@@ -659,7 +660,17 @@ public FilteringWorker(PatchDescription patch, Worker 
delegate) {
             @Override
             public Collection<? extends ErrorDescription> 
createErrors(HintContext ctx) {
                 Collection<? extends ErrorDescription> errors = 
delegate.createErrors(ctx);
-                return errors != null ? errors.stream().filter(ed -> 
patch.included(ed)).collect(Collectors.toList()) : null;
+                if (errors == null) return null;
+                //ErrorDescriptionFactory never produces a multi-line span: 
forTree clamps the
+                //end of the description to the end of its first line, forName 
uses the (short)
+                //name span. A match that starts on a line the patch did not 
add but ends on a
+                //line it did add would therefore be filtered out when judged 
by the description's
+                //range. Use the span of the tree the hint matched instead; 
fall back to the
+                //description's own range if the tree positions cannot be 
determined.
+                Tree tree = ctx.getPath().getLeaf();
+                int start = (int) 
ctx.getInfo().getTrees().getSourcePositions().getStartPosition(ctx.getInfo().getCompilationUnit(),
 tree);
+                int end = (int) 
ctx.getInfo().getTrees().getSourcePositions().getEndPosition(ctx.getInfo().getCompilationUnit(),
 tree);
+                return errors.stream().filter(ed -> patch.included(ed, start, 
end)).collect(Collectors.toList());

Review Comment:
   `SourcePositions#getStartPosition/#getEndPosition` return `long` and `end` 
is typically an exclusive offset; casting to `int` can overflow on large 
sources and using an exclusive `end` when computing end-line can incorrectly 
include the next line (e.g., when `end` points at the start of the following 
line). Prefer keeping these as `long` until validated/clamped, and when 
converting to a line-range treat `end` as inclusive (commonly `end - 1` when 
`end > start`). Also treat out-of-range/unknown positions as “unknown” (e.g., 
pass `-1`) to preserve the fallback behavior.



##########
cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java:
##########
@@ -1246,15 +1257,20 @@ public boolean included(FileObject file) {
             return file2AddedLines.containsKey(file);
         }
 
-        public boolean included(ErrorDescription error) {
-            int startLine = findLineForPos(file2LineStarts, error.getFile(), 
error.getRange().getBegin());
-            int endLine = findLineForPos(file2LineStarts, error.getFile(), 
error.getRange().getBegin());
+        /**@param matchStart start offset of the matched tree, or -1 if unknown
+         * @param matchEnd end offset of the matched tree, or -1 if unknown*/
+        public boolean included(ErrorDescription error, int matchStart, int 
matchEnd) {

Review Comment:
   This Javadoc is missing standard formatting (space after `/**`, leading `*` 
on each line, and closing `*/` on its own line). Reformat to conventional 
Javadoc so it renders correctly in IDEs and generated docs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to