Bug 237123 - [search] And/OrPatterns miss to override one overload
Summary: [search] And/OrPatterns miss to override one overload
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: Other Linux
: P3 normal (vote)
Target Milestone: 3.5 M1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-13 13:38 EDT by Stephan Herrmann CLA
Modified: 2008-08-06 13:07 EDT (History)
0 users

See Also:


Attachments
proposed patch (simpler variant, perhaps incomplete) (2.70 KB, patch)
2008-06-13 13:38 EDT, Stephan Herrmann CLA
no flags Details | Diff
New proposed patch (2.29 KB, patch)
2008-06-17 02:07 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2008-06-13 13:38:42 EDT
Created attachment 104897 [details]
proposed patch (simpler variant, perhaps incomplete)

Build ID: I20080530-1730

The AndPattern and OrPattern classes both override a method
matchReportReference from PatternLocator, but they seem to 
override the wrong version. See in PatternLocator:

  protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {

	matchReportReference(reference, element, elementBinding, accuracy, locator);
  }

i.e., the "long version" delegates to the "short" one, but mentioned classes
override only the long version, thus missing to intercept calls to the
short version. When instead the short version is overridden, all calls
are intercepted. 
However, some other subclasses of PatternLocator do override the long version
(and seem to require the full argument list). For those to properly work,
it might be necessary to have And/OrPattern actually override both versions?


I detected this while debugging an adapted version of MethodLocator, 
which was never called when embedded into an OrPattern (during search
all occurrences on behalf of a rename method refactoring). 
Instead of MethodLocator the default behavior in PatternLocator was triggered.

Attaching a proposed patch (tests are currently running ...)
Comment 1 Frederic Fusier CLA 2008-06-16 02:56:10 EDT
Well spotted! However, I do not agree with your patch. We still need to carry localElement and otherElements arguments value to the or/and patterns if they are not null...

Instead, it would be better to override the matchReportReference(ASTNode, IJavaElement, Binding, int, MatchLocator) method as follows both in AndLocator and OrLocator classes:

protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
	matchReportReference(reference, element, null, null, elementBinding, accuracy, locator);
}

I'll post a complete patch with additional test.
Comment 2 Frederic Fusier CLA 2008-06-16 03:31:37 EDT
Hmmm, I have some difficulties to find a path to reproduce the issue. Could you give me your test case for which the problem occurred?
TIA
Comment 3 Stephan Herrmann CLA 2008-06-16 13:22:36 EDT
(In reply to comment #1)
> Instead, it would be better to override ...
Totally agree. I was trying to be too smart ;-)

(In reply to comment #2)
> Hmmm, I have some difficulties to find a path to reproduce the issue. Could you
> give me your test case for which the problem occurred?

The original test case involves some non-java constructs, so it cannot
be used in a plain JDT.
FYI, it occurred when renaming a method with overrides and with
different references from clients => searching for references to
Super.m() OR Sub.m().

As I can't find a test case to reproduce in a plain JDT, I could see
the following implicit design rules:
 * Methods in MatchLocator must only invoke the long version of
   matchReportReference, the short version is only used as a utility
   when delegating within PatternLocator and Subclasses.
 * All methods from PatternLocator that may call the short version of
   matchReportReference must be overridden in And/OrPattern
   (all these relate to static things like packages/imports/supertypes).

Since the And/OrPatterns will be the first to receive calls from MatchLocator
before they can then delegate to other PatternLocators, overriding the
long version effectively suffices, ...
...  until someone adds code to MatchLocator that violates the above
implicit rules. That's exactly what happened in our case :)

Comment 4 Frederic Fusier CLA 2008-06-17 01:50:03 EDT
(In reply to comment #3)
Thanks for the feedback. As MatchLocator currently matches these rules and you also couldn't find a plain JDT test case, this issue should not go into the maintenance but only in the next release...
Comment 5 Frederic Fusier CLA 2008-06-17 02:07:00 EDT
Created attachment 105136 [details]
New proposed patch

As discussed in previous comments, there's no test case for this patch. It's just a protection against possible misbehavior if the rules Stephan described in comment 3 would not be respected in the future (or by some users overriding internal code...;-)).
Comment 6 Frederic Fusier CLA 2008-06-24 11:35:32 EDT
Released for 3.5M1.
Comment 7 Kent Johnson CLA 2008-08-06 13:07:15 EDT
Verified for 3.5M1 using I20080805-1307