Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322977 - Documentation about use of "SearchPattern.R_REGEXP_MATCH" is wrong
Summary: Documentation about use of "SearchPattern.R_REGEXP_MATCH" is wrong
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5.1   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 3.8 M7   Edit
Assignee: Satyam Kandula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-18 02:33 EDT by joerg CLA
Modified: 2012-05-03 02:25 EDT (History)
5 users (show)

See Also:
stephan.herrmann: review+


Attachments
code patch (777 bytes, patch)
2012-05-02 03:00 EDT, Satyam Kandula CLA
no flags Details | Diff
plugin to verify (6.10 KB, application/octet-stream)
2012-05-03 02:25 EDT, Ayushman Jain CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description joerg CLA 2010-08-18 02:33:51 EDT
Build Identifier: M20090917-0800

Obviously support for SearchPattern.R_REGEXP_MATCH is not implemented. Yet, the documentation of SearchPatter.createPattern(String stringPattern, int searchFor, int limitTo, int matchRule) does not mention it. Worse, createPattern() does not return null, but treats the regular expression as a normal pattern which leads to very unexpected behaviour.

The JavaDoc of SearchPattern.validateMatchRule(String stringPattern, int matchRule) says: "when the R_REGEXP_MATCH flag is set, then the pattern is rejected as this kind of match is not supported yet and-1 is returned". This is not the way it is implemented. This is very confusing as well.

I am not requesting that this feature be implemented (even thought that would be nice), but a hint in the API that R_REGEXP_MATCH is not ready for use would have saved me some hours.

Reproducible: Always

Steps to Reproduce:
1. Create a file Test.java:
class Test {
 private void a(){
   Object o = new Object();
   String s = o.toString();
 }
}
2. In your search implementation:
String regex = "java\\.lang\\.((String)|(Object));
SearchPattern pattern = SearchPattern.createPattern(regex,
IJavaSearchConstants.REFERENCES,IJavaSearchConstants.TYPE,
SearchPattern.R_REGEXP_MATCH);
...
SearchEngine se = new SearchEngine();
se.search(pattern, ..., ...,  ..., null);

you will notice that the respective SearchRequestor is never called.
Comment 1 Satyam Kandula CLA 2012-04-26 23:06:05 EDT
Fixed the comment and released using commit 6a31f7b894cb57eee0afe92309b5b578eca7edb4
Comment 2 Stephan Herrmann CLA 2012-05-01 06:01:05 EDT
OK, the docs for R_REGEXP_MATCH and createPattern(..) (two versions) are updated.

But what about validateMatchRule(..)? That still looks wrong to me, as per comment 0:
> The JavaDoc of SearchPattern.validateMatchRule(String stringPattern, int matchRule) says: "when the R_REGEXP_MATCH flag is set, then the pattern is rejected as this kind of match is not supported yet and-1 is returned". This is not the way it is implemented.

The implementation checks whether R_REGEXP_MATCH is set *together with* one of the other flags. Perhaps in this place the implementation should be adjusted to the spec?
Comment 3 Satyam Kandula CLA 2012-05-02 03:00:32 EDT
Created attachment 214902 [details]
code patch

Fix to validateMatchRule to return -1 if this expression is set. Thanks Stephan for catching this. Can you also review the change?
Comment 4 Stephan Herrmann CLA 2012-05-02 03:55:20 EDT
Patch looks good.
Comment 5 Satyam Kandula CLA 2012-05-02 04:39:09 EDT
Thanks Stephan. Released the patch via commit 20fa95b73616c543b99afd6d679821c3656bc2c0
Comment 6 Ayushman Jain CLA 2012-05-03 02:25:38 EDT
Created attachment 214973 [details]
plugin to verify

Verified using attached plugin and build I20120502-1800.