A tool to search and replace language constructs in source code, indifferent to formatting and comments. Structural Search & Replace is developed by JetBrains and available in IntelliJ IDEA, PhpStorm, WebStorm and Resharper.
Questions tagged [structural-search]
152 questions
17
votes
1 answer
How to add @Deprecated to every Class and every Constructor/Method of every class?
I have some legacy code and I want to mark all of them and all of their methods @Deprecated so that as we go and touch them we can remove these annotations so we can keep track of what has been modernized and what still is bad.
I am trying to use…
user177800
15
votes
3 answers
IntelliJ IDEA: how to find all instance creation of a class?
abstract class Base {}
class A extends Base
class B extends Base
How do I find all places in the code that create Base? (that is, have either new A() or new B())
UPDATE
To make it clear, the above is just and example. I'm interested in a way of…

IttayD
- 28,271
- 28
- 124
- 178
13
votes
4 answers
How to extract a method across files?
In all my java files of my project, I want to replace occurrences of this:
myObject.getName() == null
With that:
myObject.hasName()
Is there any action or strategy to do this with IntelliJ IDEA?
I want it to be specific to the getName method of…

slartidan
- 20,403
- 15
- 83
- 131
11
votes
1 answer
Is there a way to disable custom patterns with a comment in Resharper
In Resharper normal hints are able to be disabled by a comment via the
Disable once with comment
option on the context menu when you press
With custom structural search…

bradgonesurfing
- 30,949
- 17
- 114
- 217
10
votes
1 answer
How can I use Intellij Structural Search to find all methods that use two named classes?
Say I have two Java classes, TradeType and InstrumentType. I know that somewhere in my codebase there is a method that maps from TradeType to InstrumentType.
How can I use Structural Search in Intellij to say
"find me all methods that have a…

Mike Hogan
- 9,933
- 9
- 41
- 71
9
votes
1 answer
How to create structural replace in IDEA to add missing annotation to the class
I'm trying to figure out a Structural replacement template in IntelliJ IDEA (future inspection) for adding a missing annotation to a class/interface/enum without removing any other existing annotations.
So far I tried several varieties of…

imparente
- 151
- 5
9
votes
1 answer
Replace getters with property with IntelliJ Structural Search and Replace
Due to changes in a library I'm using, the getters were replaced with direct access to the property. Eg:
public class MyLibraryClass {
private String field;
public String getField() { return field; }
}
has become
public class MyLibraryClass…

kierans
- 2,034
- 1
- 16
- 43
8
votes
2 answers
IntelliJ/structural search: Remove useless methods that only call super method
In one of my Android projects (but not necessarily tied to Android) I have quite a few method calls that really do nothing but blow up the code and could be automatically removed. Examples:
@Override
public boolean onKeyDown(int keyCode, KeyEvent…

mreichelt
- 12,359
- 6
- 56
- 70
7
votes
3 answers
How do I search and replace structurally in Intellij
I am migrating my Junit tests from Junit v3 to Junit v4.
I was hoping to use the search and replace structurally "srs" to add an @Test annotation before all methods starting with test.* using my favorite IDE Intellij.
I just cant figura out how to…

Konstantin
- 3,626
- 2
- 33
- 45
6
votes
1 answer
How to automatically move annotations from methods to fields?
I have a large number of Java classes using JPA property access instead of field access, and converting them to use field access (moving the annotations from getters to fields) is time consuming. Re-generating them from database tables is also not…

Barry Pitman
- 3,087
- 1
- 24
- 32
6
votes
1 answer
Find all method calls with a specific parameter type with IntelliJ
I have this code base which is rather big ( +/- 500k lines). I'm looking in it to find all the method calls that use a single parameter and that parameter is a specific type.
This means, I want to be able to find method calls like the…

Olivier Grégoire
- 33,839
- 23
- 96
- 137
6
votes
2 answers
Use IntelliJ structural search to replace field and its expression with new field
I want to use ButterKnife for Android. I need to annotate some fields based on some expressions which are elsewhere in code. I have code like this
private String myField;
...
public myClassConstructor() {
...
myField =…

arberg
- 4,148
- 4
- 31
- 39
6
votes
2 answers
How to convert a C# object initializer to use a constructor using Resharper structural find and replace
I want to use a Resharper structural search and replace template to automatically replace examples of this:
new Fruit { Name = "Apple", IsTasty = true }
With this:
new Fruit("Apple", true)
(Note, the required constructor already exists)
I've tried…

Chris Brook
- 2,335
- 20
- 24
5
votes
1 answer
IntelliJ Structural Search to find classes that implement A but not B
I'm trying to use IntelliJ 10.5's "structural search" feature to find classes that implement an interface, A but do not implement another interface, B.
By searching first for classes that implement A, and then limiting the search scope to 'previous…

Fesler
- 1,812
- 1
- 13
- 5
5
votes
1 answer
Find all anonymous classes throughout my project in IntelliJ
Is there a way for IntelliJ to locate all the places in my code that define an anonymous class?
I am asking just about finding, not changing. I am not asking about converting to lambdas, lambdas are irrelevant here.

Basil Bourque
- 303,325
- 100
- 852
- 1,154