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.

structural-search
Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

Repetition in Structural Replace in PhpStorm

I'm working on quite old project and I would like to do some small refactoring. I have an if statement with condition like if ($a == 1 || $a == 2 || b == 3) and I want to replace it (or better write ...
LiTe's user avatar
  • 176
0 votes
2 answers
340 views

Intellij structural search for method invocation where class containing method is marked with specific annotation

Intellij structural search script to to find all method invocations where method source class is marked with @Internal annotation. As for example bellow - script should return a.a(); package com....
doleris's user avatar
  • 25
0 votes
1 answer
60 views

Structural search - find any final local variables?

I'm trying to work with IntelliJ's structural search to find any local variables declared final. I'm using the following: class $Class$ { $ReturnType$ $Method$ ($ParameterType$ $Parameter$) { ...
rb612's user avatar
  • 5,417
1 vote
1 answer
113 views

PhpStorm Structural Search

I have a bunch of li tags in PHP Blade templates that I want to convert to div tags and change the class name. Search/Replace would be an easy solution but it will only change the opening tag, not the ...
SupaMonkey's user avatar
1 vote
1 answer
152 views

Replacing Type with var for all 'Class class = new Class()' usages in Java project

I recently switched to Java 11 for a rather big project, and would like to switch to using var class = new Class() instead of Class class = new CLass(). I tried using Intellij Structural Search (and ...
RInverid's user avatar
0 votes
0 answers
39 views

Intellij SSR: how to extract structured information from initializer expressions

Is there a way to extract into some structured format (JSON, XML, whatever) partial information from a number of constructor calls expressions? Say we have code like: public enum Model { TOYOTA, ...
62mkv's user avatar
  • 1,494
0 votes
1 answer
115 views

how to find and replace annotations based on parameters?

I have a big java project using TestNG Test annotation. I want to add parameter timeOut=100L to all tests, that are not part of a group (defined via Test Annotation parameters). We use groups for ...
gabriel's user avatar
  • 317
2 votes
2 answers
159 views

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 ...
Quaris's user avatar
  • 361
1 vote
1 answer
104 views

Finding the annotated method call as a parameter to Logger methods

Suppose I have below Person class with one getAccountNumber() method having @ShouldNotBeLogged custom annotation. public class Person { private String name; private String accountNumber; @...
Mohit Charaya's user avatar
1 vote
0 answers
74 views

Intellij Idea Structural Replacement (replacing autowired annotation)

I wonder whether it's possible to replace all the Autowired fields with final ones and @RequiredArgsConstructor below the class declaration? For instance, replace the following code public class ...
Ultoret's user avatar
  • 11
0 votes
1 answer
72 views

Why does IntelliJ Structural Search find some of `(int) ($expr$ + 0.5f)`, but not all?

I'm trying to use Structural Search to replace a rounding anti-pattern with the correct pattern. I'm searching for: (int) ($expr$ + 0.5f) in order to replace it with: Math.round($expr$) Strangely, ...
Pepijn Schmitz's user avatar
1 vote
1 answer
68 views

Structural Search for log.debug(String.format.... not working as expected

I'm doing a search for the following $Instance$.debug(String.format($Parameter$)) and found lots of instances from before we have a sensible logging framework in our project, however some calls are ...
mjaggard's user avatar
  • 2,401
2 votes
1 answer
153 views

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 <T:Any> safeApiCall( apiCall: suspend () -> T ) ...
Ewei's user avatar
  • 31
0 votes
1 answer
468 views

how to negate search in intellij structural search

How can i exclude terms from intellij's structure search? (NOT text or regex seach!) for example, using the annotated field template, let's say i want to add @Lazy to all occurrences of @Autowired for ...
gabriel's user avatar
  • 317
2 votes
1 answer
140 views

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 ...
Alexandre de Champeaux's user avatar
0 votes
1 answer
106 views

IntelliJ Search Template /Custom Inspection: Analyse sibling annotations

in our project we have a custom annotation @DeprecationReason which should be used to document why a member/method/class is deprecated (and thus annotated with @Deprecated) So to have an IntelliJ ...
Manuel's user avatar
  • 3
0 votes
1 answer
178 views

Is there a way to add 1 to a string containing numbers in find and replace in intellij?

I have code that looks like this: public void testSomething1() { } public void testSomething2() { } public void testSomething3() { } And I want the result to look like this with find and replace: ...
Alex L's user avatar
  • 3
0 votes
1 answer
78 views

How to refactor Bootstrap 4 radiobuttons to Bootstrap 5 uinsg Intellij's Structural Replace

I am trying to update some Java Server Pages/Spring Webflow views from Twitter Bootstrap 4 to Bootstrap 5. I have lots of radiobuttons and the requisite HTML boilerplate has changed quite a bit from ...
Bob Brown's user avatar
  • 1,018
0 votes
1 answer
31 views

How to avoid assigning child instances to parent class type variables at declaration with Structural Search command in IntelliJ IDEA?

I'm trying to create an inspection based on Structural Search to avoid initializing ExecutorService to Executor Variables. The below is my template: <searchConfiguration name="Use an ...
Shankeerthan Kasilngam's user avatar
1 vote
1 answer
514 views

intellij idea structural search and replace - find all methods that call an api

I'm trying to find all methods in a large java project in which a specific static api is called, and then add an annotation those methods. The methods can have arbitrary complexity. It can be a simple ...
Zopper's user avatar
  • 132
0 votes
1 answer
147 views

IntelliJ TypeScript Structural Search

Is it possible to define a structural search in IntelliJ to warn about the use of the native JavaScript String class instead of the Typescript string type? The typescript documentation recommends that ...
Michael's user avatar
  • 2,490
1 vote
2 answers
323 views

IntelliJ Structural Search to find all classes without given declarations

Consider we have a class public class MyTest() { @Inject private Class1 class1; @Inject private Class2 class2; } and a class public class MyTest2() { @Inject private Class1 class1; @...
Artem Krosheninnikov's user avatar
0 votes
1 answer
177 views

How to find functional interface candidates in IntelliJ

I'm trying to use search structurally to find interfaces that could be annotated with @FunctionalInterface since they only contain a single abstract method but aren't annotated yet. My current ...
jimonthebarn's user avatar
0 votes
0 answers
107 views

How to use structural search in IDEA to find lines without a trailing comment or comment that doesn't match a pattern

The requirement is that all static and not final variables are marked with a corresponding trailing comment, that contains a certain text (e.g. "TEXT") I used the already existing template ...
Eugenerator's user avatar
0 votes
0 answers
56 views

IntelliJ Structural Search in PhpStorm to find 2 default statements within Switch block

I need to find all switch blocks which has 2 default cases: switch (1) { default: echo "Default 1"; break; default: echo "Default 2"; break; ...
sachin deshmukh's user avatar
0 votes
1 answer
84 views

IntelliJ Structural Search in PhpStorm to find specific function used within foreach block

I need to find all foreach blocks wherever I have used current() function inside of it. Below is sample code block, which should get find. $x=12; foreach ($array as &$val) { $cur=current($...
sachin deshmukh's user avatar
1 vote
0 answers
70 views

PhpStorm structural searching to find a self-assignment in a foreach loop

I have noticed a pattern among some of my team's developers where we will do a self-assignment of an array in a foreach loop, and I am looking for the proper search parameters to pass into PhpStorm's ...
Aaron Morefield's user avatar
1 vote
1 answer
104 views

Does IntelliJ's search template language have a way to identify function calls not wrapped by an if statement

I'm looking at some legacy code in PhpStorm and there are some instances within the codebase where a particular function call is wrapped by another function call within an if statement e.g. if (...
connrs's user avatar
  • 283
0 votes
1 answer
148 views

IntelliJ IDEA: How to create a new class field during Structural replace

I have many calls to static class method E.g. LegacyLogger.println (ERROR_LEVEL, "Simple string parameter"); I have found all the needed code occurrences by using the template: LegacyLogger....
ngranin's user avatar
  • 181
4 votes
1 answer
242 views

Is there a list of all keywords used in structural search and replace?

Recently I've needed to use something more powerful than refactoring using regexes. IntelliJ Idea has structural search and replace and some examples but I didn't manage to find a list of all keywords ...
Artem Krosheninnikov's user avatar
1 vote
1 answer
253 views

How to convert Java primitive to boxed type in IntelliJ Structural Replace

I'm trying to use IntelliJ Structural Search and Replace to overload a suite of setter methods with Optional variants. This needs to honour that the target value may be primitive (e.g. boolean to ...
drekbour's user avatar
  • 2,991
0 votes
1 answer
196 views

Replace HTML tag based on attribute value

I need to replace vanilla <a> tag by different tag (<router-link>) in whole project. The main problem is to do it with some conditions based on href value (e.g. it should ignore href with "...
Alexandr Vysotsky's user avatar
0 votes
0 answers
139 views

Structural Search IntelliJ IDEA

I want to perform a structural search from IntelliJ IDEA. My research is made up of two criteria: Find all classes with custom @CustomAnnotate annotation This annotation is placed exclusively on ...
Eliot's user avatar
  • 1
0 votes
1 answer
858 views

How to find usage of deprecated java classes with Structural Search command in Intellij IDEA?

I'm trying to create inspection based on Structural Search And Replace feature. So, I need to create search template to find all usages of deprecated classes in java code but I can't understand how to ...
Михайло Тітов's user avatar
1 vote
2 answers
69 views

Replace all <a> elements *without* an attribute

I want to use structural search to find e.g.: <a data-foo="bar" style="width: 1px;"> <a data-bar="foo"> But not: <a data-foo="bar" style="width: 1px;" href="https://google.com"> &...
Adam Williams's user avatar
2 votes
1 answer
454 views

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 ...
khmarbaise's user avatar
  • 95.2k
2 votes
1 answer
372 views

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 ...
cygnus's user avatar
  • 305
2 votes
1 answer
196 views

Trying to do a structural replace in IntelliJ

I want to replace my annotations from @RequestMapping to @GetMapping, @PutMapping ... annotations. When I looked at the Structural Find/Replace in IntelliJ looked like it could do the job. I tried ...
Imran's user avatar
  • 413
0 votes
0 answers
93 views

Can I use structural search in HTML files to find nested tags?

I want to find and replace some child tags that are nested inside parent tag. Here is my template: <$tag$ $attribute$=$value$> <$childTag$ $childAttr$=$childValue$ /> <$tag$/> ...
Dmitry Davydov's user avatar
1 vote
1 answer
153 views

When using a reference in a structural search, how do I filter its fields?

I've found how to search for all fields and variables of a type that implements a given interface, in my case AutoCloseable. My current way to do this is first creating a filter for classes that ...
SQB's user avatar
  • 4,021
0 votes
1 answer
66 views

How to find the usage of method in Java code where the arguments are compound expressions?

Probably a duplicate, but I don't know how to search for it.. I use IntelliJ to find method usages. Now I want to find these usages (method calls) where in the method call itself the argument is an ...
Bart van Berkel's user avatar
3 votes
1 answer
2k views

Replace import of constant by static import in IntelliJ Idea

I have a code with some constants in format ClassName.CONSTANT_NAME. I want to quickly replace this by CONSTANT_NAME. But I have not found any efficient way of doing that. Every time I want to static ...
Demiteli's user avatar
0 votes
1 answer
83 views

Structurally Replace Intellij Jsp

I want replace structurally an attribute html with its value. The example is the following. I want replace this instruction <IMG SRC="<%=immagineGes%>" title="<%=toolTipGes%>"> ...
Mirko's user avatar
  • 13
0 votes
2 answers
365 views

IntelliJ structural search find derived classes if base class matches criteria

Suppose I have a base class with a field refCount. I accidentally create a derived class which ALSO declares a field with the same name. (Actually, the name is not important: what matters is the ...
Mark VY's user avatar
  • 1,587
0 votes
1 answer
248 views

How to find all usages of name() related to specific enum type

I need to find all usages of name() method called on specific enum type. Let's say I've got the enum: enum MyEnum { A, B, C; } I want to receive all places where the method is called on any of ...
Jakub Ch.'s user avatar
  • 3,687
0 votes
2 answers
302 views

How to use IntelliJ's structural replacement for "all matches, except..."?

Lets say I want to replace print(x) with print(wrapper(x)). I can match print($Argument$) and replace it with print(wrapper($Argument$)) However, if I already have a call to print(wrapper(x)), I ...
kc2001's user avatar
  • 5,120
6 votes
1 answer
431 views

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 ...
Basil Bourque's user avatar
0 votes
1 answer
89 views

Intellij Structurally replace `thows OneException, TwoException` with only Exception

With IntelliJ's s Structural Search and Replace I want to replace the following snippet: @Test public void myTest() throws ExecutionException, InterruptedException {} with: @Test public void myTest(...
Joe's user avatar
  • 3,490
1 vote
1 answer
314 views

Replace only one XML attribute with Structural Replace

I want to replace attributes android:fontFamily="sans-serif-medium" with android:fontFamily="@font/roboto_medium" in all TextView tags. So I tried to use Structural Replace with search template: <...
KursoR's user avatar
  • 1,615
0 votes
2 answers
427 views

How to check classes have @CompileStatic annotation?

I want to perform an automated static check analysis on my Groovy code to identify which clases doesn't have the @CompileStatic annotation. I'd like to know how that can be done either with IntelliJ ...
rvazquezglez's user avatar
  • 2,424