Questions tagged [structural-search]

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.

152 questions
3
votes
1 answer

Structural Search to match method call with generic parameter

Let's say that I have a class class Foo : Base and I want to perform a certain method call with signature public void someStuf(Iterable param) For the search template I just take as starting point the pre-existing…
3
votes
1 answer

IntelliJ inspection to find tags without 'id' attribute

I need to setup an inspection in IntelliJ that will find xhtml/html/jsf page elements without an `id attribute. I tried…
3
votes
1 answer

Structural Search and Replace with Groovy Script constraints

How can I search if a given method parameter that is an integer is greater or equal to a given value, in structural search and replace? or is this even possible? For example: Say I have 100 usages of this method public void sendString(String msg,…
JavaGuy
  • 33
  • 3
3
votes
1 answer

How do I write a robust structural search template to report Mockito times(1)/Times(1) passed to verify in IntelliJ IDEA?

In my project Mockito.times(1) is often used when verifying mocks: verify(mock, times(1)).call(); This is redundant since Mockito uses implicit times(1) for verify(Object), thus the following code does exactly what the code above…
Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105
3
votes
1 answer

Intellij Structural Search: How to find empty try catch blocks?

How can i find the empty try catch blocks? Using the Copy existing template... I found the structural search for try catch: try { $TryStatement$; } catch($ExceptionType$ $Exception$) { $CatchStatement$; } I want to enhance it so that it does…
user1167253
  • 813
  • 1
  • 11
  • 27
3
votes
2 answers

Find all 'public void' methods not annotated with '@Test'

I want to perform structural search on my tests to detect all methods that look like tests but are not annotated with @Test. I tried with this pattern with no success (no matching code found): @$Annotation$ public void $method$() $Annotation$ -…
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
3
votes
0 answers

Extract the type of expression with Resharper structural replace

I am trying to make a R# structural search and replace to offer the following foo.ToList() should be converted to the below if the user selects the refactoring foo as List ?? foo.ToList() so in R# I would try for the…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
3
votes
1 answer

How can you use structural search to find constructor calls for subclasses of a given type?

I have an abstract class called "com.foo.BaseFoo" I want to find anyone that calls new() on anything that extends from BaseFoo I've tried doing a search template of: new $BaseFoo$() and then edited the variables to have an expression constraint on…
Ryan
  • 584
  • 3
  • 13
3
votes
0 answers

ReSharper Search and Replace with Pattern

I would like to re-factor various blocks of code throughout a project using ReSharper 7.1 Search / Replace with pattern. The code blocks are similar to the following simplified example: someControl.StatusProgressBar.IsIndeterminate =…
skeandu
  • 155
  • 1
  • 6
2
votes
1 answer

resharper search with pattern square bracket

how can I escape "[" in Resharper 6s Structural Search (C#). If i am searching for a pattern which contains a square bracket i just got the info: pattern is ambiguous. Is there any documentation of the syntax? I can't find a syntax documentation on…
Daniel Bişar
  • 2,663
  • 7
  • 32
  • 54
2
votes
2 answers

How do I create a custom IntelliJ warning/error for import statements?

I want to add a custom warning/error to IntelliJ that triggers if my Java project contains imports to a certain package. I have looked into Search Templates/Replace Templates, but whenever I try to type code with an "import", it gives me an…
Quaris
  • 361
  • 2
  • 9
2
votes
1 answer

Structural search interface suspend function call

I have a custom function for wrapping Service api call I want to add some warning while some api call forget adding safeApiCall{} suspend fun safeApiCall( apiCall: suspend () -> T ) { //do something } interface Service { @Get …
Ewei
  • 31
  • 5
2
votes
1 answer

Intellij structural search: find field and corresponding getter (to migrate an annotation)

I am trying to migrate an annotation from a field to it's getter using Intellij's fancy structural replace: From: class MyClass { @SomeAnnotation private final double a; @SomeAnnotation private final double b; public double getA() { …
2
votes
1 answer

Searching/Replace attributes with the according getter/setters

Problem: Having a large number of classes which have attributes defined with names where the first character is uppercase. Example: class FirstClass { private Integer FirstValue; private Double SecondValue; private String ThirdValue; …
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
2
votes
1 answer

Can I use filters in Intellij structural search to reference variable counts?

I am trying to create a custom inspection in IntelliJ using structural search. The idea is to find all methods that have one or more parameters, of which at least one is not annotated. Bonus: Only hit non-primitive types of parameters. So far, I…
cygnus
  • 195
  • 1
  • 12
1 2
3
10 11