1

In Eclipse File Search you have the possibility to search for "containing text" and filter the result with "Filename patterns". For example if you search for setValue(int x) with filename pattern "My*.java" you will find the setValue(int x) method in a File named MyGame.java, but not in a file named YourGame.java. Now i need a way to filter the search to only show results in a specific method. For example if i have 10 classes which override a init() method and a reset() method of the same superclass. Inside the init() and the reset() the setValue(int x) gets called. Now i want to search for all occurences of setValue(int x), but only inside the init() methods. Is there a way to do this? With regular expression maybe or does Eclipse have such a method? Thanks

Robert P
  • 9,398
  • 10
  • 58
  • 100
  • Some what related to my question [here](http://stackoverflow.com/questions/21577308/eclipse-file-search-regular-expression-for-group-unions-and-negation). You may get some clue from this. – Chandrayya G K Feb 06 '14 at 13:31

1 Answers1

0

I have found a more or less working expression:

(?s)methodname.*(?-s)set.*parma1, param2

Let me explain:

  • The "." (DOT) stands for 1 character except "\n" (Newline)
  • The "*" (asterisk) means, that the character before it can occure 0-n times, so n* matches "nnn", "n" and also "". In combination with "." (DOT) it matches 0-n occurences of any character, except "\n"
  • The (?s) modifies the function of "." (DOT), so that it accepts also "\n"
  • The (?-s) turns (?s) off, so that the "." (DOT) does not accept "\n" anymore.

So this expression searches for "methodname", followed by 0-n characters (also "\n"), followed by "set", followed by 0-n characters (without "\n"), followed by "param1, param2". It is possible, that it finds a methodcall after, but outside the "methodname" method, but i don't think you can controll this. Hope it helps

Robert P
  • 9,398
  • 10
  • 58
  • 100