structural-search

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

Deadly 提交于 2021-02-07 10:35:56
问题 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 structural search to match the first workflow, but not the second in the following example: public function example() { $array = []; foreach ($array as $a) { $array[$a] = 1; //Match this one } $someOtherVariable = []; foreach($array as $ab) { $someOtherVariable[] = 2; //Don't match this one } }

Structural Search to match method call with generic parameter

浪子不回头ぞ 提交于 2020-01-14 02:11:08
问题 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<? extends Base> param) For the search template I just take as starting point the pre-existing one $Instance$.$MethodCall$($Parameter$) Is it possible to match a parameter of any kind Iterable of a specific Base subclass ( Foo in this example)?? List<Foo> fooList = new ArrayList<>(); fooList.add(new Foo("A")); List<Bar> barList = new ArrayList<>(); barList.add

Structural Search to match method call with generic parameter

◇◆丶佛笑我妖孽 提交于 2020-01-14 02:10:34
问题 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<? extends Base> param) For the search template I just take as starting point the pre-existing one $Instance$.$MethodCall$($Parameter$) Is it possible to match a parameter of any kind Iterable of a specific Base subclass ( Foo in this example)?? List<Foo> fooList = new ArrayList<>(); fooList.add(new Foo("A")); List<Bar> barList = new ArrayList<>(); barList.add

IntelliJ structural search and replace problems

跟風遠走 提交于 2020-01-02 08:58:34
问题 Is there an easy way to capture types? I can't seem to do basic things like use variable expressions side by side, such as $mapType$$mapEnd$ to do a simple replacement. Is there any reason this might be? That is, if I have a single expression, say .*\s*.*abc , and I break it into two variables, .*\s* and .*abc , the expression does not match any text. What could be going wrong? Example template: $var1$ = $impl$ Example second template: $var1$ = $type$$implEnd$ If $impl$ is a full regular

How to convert a C# object initializer to use a constructor using Resharper structural find and replace

╄→гoц情女王★ 提交于 2019-12-21 12:30:02
问题 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 various combinations like this: new $type$ { Name = $name$, IsTasty = $isTasty$ }; ...using various different Placeholder types, but R# doesn't find any of the examples in my code. Has anyone done this before? 回答1: So I just did this in resharper (9

ReSharper Search and Replace with Pattern

拟墨画扇 提交于 2019-12-12 16:05:33
问题 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 = false; someControl.StatusProgressBar.Visibility = Visibility.Visible; someControl.StatusProgressBar.Minimum = 0; someControl.StatusProgressBar.Maximum = 100; someControl.StatusProgressBar.Value = percentage; And I would like to change them to: someControl

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

旧街凉风 提交于 2019-12-12 15:42:41
问题 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 the type of the object to be com.foo.BaseFoo and clicked on the "Apply constraint within type hierarchy" but this hasn't worked. 回答1: You were almost there. Use a template like the following: new $BaseFoo$($argument$) Where $BaseFoo$ Text/regexp:

IntelliJ Structural Search in PhpStorm to find methods with specific return types

﹥>﹥吖頭↗ 提交于 2019-12-11 16:39:43
问题 How can I find the method foo with return type boolean in my example using PhpStorm's Structural Search ? <?php class test { public function hello() { return true; } /** * @return bool */ public function foo(): boolean { return true; } } $t = new test(); $t->foo(); I've tried the following search template : class $a$ { public function $show$(): boolean { $content$ } } Where can I learn more about these code/search templates? 回答1: I have recently been in contact with JetBrains support about

Replace one of annotation parameters with IntelliJ IDEA's Structural replace

谁说胖子不能爱 提交于 2019-12-11 08:01:56
问题 I have many classes with the Spring @ContextConfiguration annotation. The annotation has the classes parameter, which can be an array. Now most of my classes look like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { ThisShellBeTwoClassesInContextHierarchyConfig.class, SomeTest.SomeTestConfig.class, WhateverConfig.class }) @Transactional public class SomeTest { ... Desired output of some magical batch operation would be following: @RunWith

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

限于喜欢 提交于 2019-12-11 07:19:46
问题 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 implement AutoCloseable. This filter is derived from the pre-defined filter "implementors of interface (within hierarchy)" by adding a filter on the Interface. class $Class$ implements $Interface$ {} where $Interface$ is filtered with text=AutoCloseable . After saving that filter as