Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Search for constructor invocations with parameters(jdt.core.search for constructor invocation with parameters)
Search for constructor invocations with parameters [message #757707] Mon, 21 November 2011 10:08 Go to next message
Konstantin Missing name is currently offline Konstantin Missing nameFriend
Messages: 8
Registered: September 2011
Junior Member
Hello,

I've got the following problem:
I'm trying to search for constructor invocations for constructors with parameters. I have tried searching for constructors without parameters and it worked fine. However searching for constructor invocations, when constructors have parameters doesn't find any searchMatches.

I tried the following code with variations:

public final static int GENERICS_AGNOSTIC_MATCH_RULE = SearchPattern.R_EXACT_MATCH
			| SearchPattern.R_CASE_SENSITIVE 
			| SearchPattern.R_EQUIVALENT_MATCH;


SearchPattern pattern = SearchPattern.createPattern(element,
  IJavaSearchConstants.REFERENCES, /* I also tried CLASS_INSTANCE_CREATION_TYPE_REFERENCE and even ALL_OCCURRENCES */
  GENERICS_AGNOSTIC_MATCH_RULE); 


// the scope is a PackageFragmentRoot for src folder - 
// obtained with ... getPackageFragmentRoot(sourceFolder);
IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(scope);

SearchEngine searchEngine = new SearchEngine();

searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
.getDefaultSearchParticipant() }, searchScope, requestor,
null /* progress monitor */);



This code works fine for searching method invocations and constructor invocations without parameters.

Please help.
Re: Search for constructor invocations with parameters [message #757716 is a reply to message #757707] Mon, 21 November 2011 10:48 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
This should work unless there is something else wrong. Did you make sure that the parameter type matches exactly?
Re: Search for constructor invocations with parameters [message #757724 is a reply to message #757716] Mon, 21 November 2011 11:08 Go to previous messageGo to next message
Konstantin Missing name is currently offline Konstantin Missing nameFriend
Messages: 8
Registered: September 2011
Junior Member
Yes.

For example I try to look for constructor:

public JavaClassExample(JavaClassExample exampleParameter) {

}


Which is invoked in the code like this:

JavaClassExample newconstructor = JavaClassExample(new JavaClassExample());


OR

JavaClassExample example = new JavaClassExample();
JavaClassExample newconstructor2 = JavaClassExample(element);
Re: Search for constructor invocations with parameters [message #757734 is a reply to message #757716] Mon, 21 November 2011 12:16 Go to previous messageGo to next message
Konstantin Missing name is currently offline Konstantin Missing nameFriend
Messages: 8
Registered: September 2011
Junior Member
Maybe I misunderstood your clarification question.

I'm using method:

SearchPattern.createPattern(IJavaElement element, int limitTo, int matchRule)


and you were probably referring to the method:

SearchPattern.createPattern(String stringPattern, int searchFor, int limitTo, int matchRule)


where you have to specify parameterTypes in the stringPattern.

Do I have to have any additional information, when I'm doing search by IJavaElement?
Re: Search for constructor invocations with parameters [message #758141 is a reply to message #757734] Tue, 22 November 2011 05:05 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
The string pattern can be something like JavaClassExample(JavaClassExample). In the element case, I hope your element is JavaClassExample(JavaClassExample) and not JavaClassExample().
Re: Search for constructor invocations with parameters [message #758203 is a reply to message #758141] Tue, 22 November 2011 10:28 Go to previous messageGo to next message
Konstantin Missing name is currently offline Konstantin Missing nameFriend
Messages: 8
Registered: September 2011
Junior Member
Unfortunately I get a strange behavior.
Whenever I use a
SearchPattern.createPattern(constructor, IJavaSearchConstants.REFERENCES,  GENERICS_AGNOSTIC_MATCH_RULE);
and pass in a IMethod reference to the constructor
public JavaClassExample(JavaClassExample exampleParameter) {}
I don't get matches at all.

When I use a
SearchPattern.createPattern(simpleMethodSignature, IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.REFERENCES, GENERICS_AGNOSTIC_MATCH_RULE);
with simpleMethodSignature = "JavaClassExample(JavaClassExample)" I don't get matches either.

However, if I pass a simpleMethodSignature = "JavaClassExample()" I get matches for both JavaClassExample() AND JavaClassExample(JavaClassExample).

Is anyone able to reproduce the issue, or am I using SearchPattern wrong?

Thanks in advance
Konstantin
Re: Search for constructor invocations with parameters [message #758515 is a reply to message #758141] Wed, 23 November 2011 14:34 Go to previous messageGo to next message
Konstantin Missing name is currently offline Konstantin Missing nameFriend
Messages: 8
Registered: September 2011
Junior Member
Satyam, can you reproduce the problem?
If yes, I will file a bug on this behavior.

Thanks,
Konstantin
Re: Search for constructor invocations with parameters [message #758775 is a reply to message #758515] Thu, 24 November 2011 14:13 Go to previous message
Konstantin Missing name is currently offline Konstantin Missing nameFriend
Messages: 8
Registered: September 2011
Junior Member
Resolved: the problem was due to compilation errors in the file, containing constructor being searched.
Thanks for your time.
Konstantin
Previous Topic:Update v3.6: "No repository found at ...": Which plugin is concerned?
Next Topic:Add new method and position cursor in body
Goto Forum:
  


Current Time: Thu Apr 18 11:26:31 GMT 2024

Powered by FUDForum. Page generated in 0.02380 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top