����ȭ�� �˻� �� ��ü

 

�� ������ �� ���������� �ſ� ������ ���� ��Ҹ� �̿��ϴ� ���� ����� �����ϴ� ���� �����ϴ� ������ �� ���� Usecases�� ������ �Ӹ� �ƴ϶� Structured Search&Replace Æ¯Â¡, �� ���, ������ ����մϴ�.


Structured Search&Replace ï¿½ï¿½ ����� �˻��ϴ� ���� �����ϰ� �ϰ�, �ʿ��ϴٸ� ������ ����Ͽ� �ڹ� �ڵ��� ������ ��ü�ϱ� ���� ����ϰ� �ִ� �ڹ�-��� �ִ� �˻� �� ��ü ��Ŀ�����Դϴ�.

������ Structured Search&Replace�� 2 ���̾�α׸� �����մϴ�.  Ã¹ ��°�� ������ ����ϰ� �ִ� �ڹ� �ڵ� ������ �˻��ϴ� Structural Search ï¿½Ô´Ï´ï¿½.  ï¿½×°ï¿½ï¿½ï¿½ Search | Search structurally  ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Å³ï¿½ Ctrl + Shift + S ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ �ҷ��� �� �ֽ��ϴ��װ��� ���ϰ� �Բ� �ڹ� �ڵ带 ���� �˻��ϱ� ���� ���˴ϴ�.



�ٸ� ���� ������ ����ϰ� �ִ� �ڹ� �ڵ带 �˻��ϰ�, ��ü�ϴ� Structural Replace�Դϴ�.  ï¿½×°ï¿½ï¿½ï¿½ Search | Replace structurally�� �����ϰų� Ctrl + Shift + M�� ������ �ҷ����ϴ�.



���̾�α״� ������ ��Ʈ�� ������, Structured Search&Replace�� ���� �ʿ��� �߰��� �Բ� ����� ���Դϴ�.

 

���̾�α��� �ֿ� ��� Search template�� Search template/Replacement template �Դϴ�.  ï¿½×µï¿½ï¿½ï¿½ ��ġ�ϴ� ������ �˻��ϰų� ��ü�ϴ� �� ����ϴ� ���ø��� �����մϴ�. ������ Search ���ø��� Ŭ����/�������̽�/������Ʈ��Ʈ/������Ʈ��Ʈ ��Ʈ/ǥ����/�ڸ�Ʈ/Javadoc �ڸ�Ʈ ��� �������� ������ Replace ���ø��� �ڹ� �������� ��Ȯ�� ������ �Բ� ������Ʈ��Ʈ/������Ʈ��Ʈ ��Ʈ/ǥ������ �Ǵ� ������ �����մϴ�. ï¿½×¸ï¿½ï¿½ï¿½ ���ø� ���� � �̸��̶� ������ �Բ� ġȯ�� �� �ֽ��ϴ�.  ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ $ ��ȣ ���� ������ �̸��Դϴ�. ���� ���, $Variable$ ï¿½Ô´Ï´ï¿½.  IDEA�� ������ ���ø��� �м��ϰ� ������ ��Ȯ�� �ڹ� ������ �����߸� �Ѵٶ�� ��Ȯ�� �˻� ����� ��� ���� �ڹ� ��� ������ ����մϴ�.


Replacement template ï¿½ï¿½ Search template���� ���Ǵ� �������� ������ �� �ֽ��ϴ�.



���ø��� ���鼭, �� ���� ����Ű�� �̿��� �� �ֽ��ϴ�:

*   �޼ҵ� ����� ������ �� �ֽ��ϴ�.

*   ���� � ���� �������� ǥ�õ��� ������, � ���� �����ڶ� ���� ���� ���Դϴ�.

*   ���� �ʵ忡���Ӹ� �ƴ϶� ���ø����� ª�� Ŭ���� �̸�(����� �ڰ��� �־����� �� ��ſ�)�� ����Ͻʽÿ�.

*   ���ø����μ� class $Class$�� ����ϸ鼭, �͸��� Ŭ������ �� �߰ߵ� ���Դϴ�.

*   �ڸ�Ʈ�� Javadoc�� ���� ���ø��� ��Ȯ�� �ڸ�Ʈ�� Javadoc ������ �Բ� ������ �����Ҹ� �����ؾ߸� �մϴ�.

IDEA��  ï¿½ï¿½ï¿½ï¿½ ���ø� ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¿ï¿½ ����Ʈ �� �� ��Ʈ�� ����Ʈ ���ø��� �����ϴ�.  ï¿½ï¿½ï¿½ï¿½Ú´ï¿½ user defined �Ʒ� �ű⿡�� ���� �������� �ڱ� �ڽ��� ���ø��� ������ �� �ֽ��ϴ�.

�׵��� �߰��ߴ� ���ø��� ������ ���ø� â �Ʒ��� ��ġ�ϴ� 4���� ��ư�� ����ϸ鼭 ������ �� �ֽ��ϴ�.

Save template...  

���� ��������, Save template ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¸ï¿½ �θ��ʽÿ�.



Input template name ï¿½Ø½ï¿½Æ® �ʵ忡 ���ϴ� ���ø� �̸��� �ٸ� ����� ������ ���ø��� �����ϱ� ���� �Է��Ͻʽÿ�.

Edit variables...  

���ø� ������ ���� ������ �����ϴ� ���� ���� ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¸ï¿½ �θ��ʽÿ�.

History...  

Used Templates History ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¸ï¿½ �θ��ʽÿ�.



����� �ְ� 25���� ���� ȣ��� ���ø��� �� �� �ֽ��ϴ�.  ï¿½×°ï¿½ï¿½ï¿½ �ٽ� ��� Template preview �ؽ�Ʈ �ʵ忡�� ����� �ʿ��� �ϳ��� �����Ͻʽÿ�.

Copy existing  template...  

���� ���� �Ǵ� ����� ���� ���ø��� �����ϰ� �Ǵ� �����ϵ��� Existing Template�� �θ��ʽÿ�.



���̾�α״� �����ϴ� Ʈ�� �� ���� �Բ� ��ũ�� �� ���� �׷����� �������� ���� ������ ���ø��� �����մϴ� (expressions, operators, class-based, generics ��� ����).  ï¿½ï¿½ï¿½ï¿½ ����� ������ ���ø��� �����ϱ� ���� Ư���� ���, user defined�� �ֽ��ϴ�

���ø��� �����ϸ鼭, ����� Template preview ï¿½Êµå¿¡ï¿½ï¿½ �װ��� �� ���Դϴ�.  Search template ï¿½Ç´ï¿½ Search/Replacement template ï¿½Ø½ï¿½Æ® �ʵ忡�� ���ø��� �����ϱ� ����, OK �� �����ʽÿ�.


���� ����� ���ø� �׷��� ���̾�α� Ÿ��Ʋ �ٿ� ��Ÿ���ϴ�.


���̾�α״� Options ï¿½É¼ï¿½ �׷��� �����ϴ�.

Recursive  matching  

���� ���õǸ�, ��������� ��������� �����մϴ�. ������ �˻����� �̿��� �� �ִ�.

Case sensitive  

���� ���õǸ�, �˻��� �����ϰ� �ִ� �빮�ڿ� �ҹ��ڴ� Ʋ���ϴ�.

Maximum matches  

���� ���õǸ�, ������� �Ͽ��� ����� ���� ���� ��ġ�� ������ �� �ֵ��� �մϴ�.

����Ʈ��, �װ��� 1000�Դϴ�.

Shorten fully  qualified names  

���� �ؽ�Ʈ�� ����� �ڰ��� �־����� Ŭ���� �̸��� ������ ��쿡 �� �ɼ��� ���� ���մϴ�.
���� üũ �ڽ��� ���õǸ�, IDEA�� ���� ������ �� �̸��� �ڵ������� ���� ���Դϴ�.  ï¿½×·ï¿½ï¿½ï¿½ ������, ����� �ڰ��� �־����� Ŭ���� �̸��� ���˴ϴ�.
Structured search and replace������ �̿��� �� �ִ�.

Format according  to style  

���� IDEA�� ����� �ڵ� ��Ÿ�� ����(���� ����, ���� ï¿½Úµï¿½ ��Ÿ�� �ɼ� ï¿½ï¿½ ����)�� ���� Ȯ���Ű�� �Ǵ� �ڵ� �����׸�Ʈ�� �ڵ������� �������ϱ� �ٶ�� �� üũ �ڽ��� �����Ͻʽÿ�.

���� üũ �ڽ��� ���õ��� ������, �� �������� �״�� ���� �װ��� Ȯ���Ű�� �Ǵ� �ڵ忡�� IDEA�� ���� ��ġ�� ���� ��ü�� ���ø��� �鿩���� �� ���Դϴ�.
Structured search and replace������ �̿��� �� �ִ�.


Scope ���-�ٿ� ����� �˻�/��ü�� ������ �ϰ� �Ǵ� ������ ����� �����մϴ�.  ï¿½ï¿½ï¿½ï¿½ ������ ������ �����ϰų� �Ǵ� ellipsis ��ư�� ���� �ҷ����� ���� ���� ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¸ï¿½ ����Ͽ� ��� �ڽ��� ���� �����Ͻʽÿ������ ���� ������ ���� ��Ͽ� ��Ÿ�� ���Դϴ�.

���̾�α׿��� ���ο� �˻� ����� ������ ���� ��ü�� ���̵���, �Ǵ� ���ο� ���� ���� ���̵� ���ο� �� üũ �ڽ����� ������ Open in new tab Ã¼Å© �ڽ��� �����Ͻʽÿ�.

Edit ���� ���̾�α�  


���̾�α״� ����� ���ø����� ����� ���¸� ��� ������ ���ߴ� ���� �����ϰ� �մϴ�.  ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ 3���� �ɼ� �׷����� �������ϴ�.



Text constraints�� ��Ģ���̰� ��(Perl)�� ���� ǥ���� ���·� �Ǵ� Ŭ���� �̸����μ� ������ �����Դϴ�.

Text/regular expression  

�ް� ���� ǥ���� �Ǵ� Ŭ���� �̸��� ���� �������μ� ���DZ� ���� Ÿ�����Ͻʽÿ�.  Å¬ï¿½ï¿½ï¿½ï¿½ �̸��� ���� ����� �⺻ �ڵ� �ϼ��� �̿��� �� �ֽ��ϴ�.

Invert condition  

���� ���õǸ�, �ؽ�Ʈ ������ ��ȯ��Ű�� �˴ϴ�.

Apply constraint  within type hierarchy  

��� ������ Ÿ�� �̸��� �� �װ��� �ǹ̸� �����ϴ�.  ï¿½ï¿½ï¿½ï¿½ ���õǸ�, ���� ��ġ�� ���� Ÿ�� �̸�������  ï¿½Æ´Ï¶ï¿½  ï¿½Î¸ð¿¡¼ï¿½(���� ������) �˻��˴ϴ�.

Whole words  only  

���� ���õǸ�, �ؽ�Ʈ ���� ��ü�� �ܾ �˻��˴ϴ�.  ï¿½×°ï¿½ï¿½ï¿½ ���ڿ� ���ͷ��� �ڸ�Ʈ�� ���� �ǹ̸� �����ϴ�.



Occurrences count ï¿½ï¿½ �󸶳� ���� ������ ���(�� ����, ���� �Ǵ� ������Ʈ��Ʈ ��Ͽ�)�� ������ ������ �� �ִ� ���� �����մϴ�.

Minimum count  

����� �ּ��� ��� ��.

Maximum count  

����� �ִ����� ��� ��.

 


������ �ְų� �Ǵ� ���� ���� �����ϱ� ���ؼ� Minimum count �� 0 �׸��� Maximum count �� 1�� �����Ͻʽÿ�.



Expression constraints ï¿½ï¿½ï¿½ï¿½ ǥ������ ���� ������ �����մϴ�.

Value is read  

���� ���õǸ�, ��ġ�ϰ� �ִ� ������ �����ϴ�.

Value is written  

���� ���õǸ�, ��ġ�ϰ� �ִ� ������ �����ϴ�.

Text/regular  expression for java expression type  

���� �ԷµǸ�, ǥ���� Ÿ���� �������� �˻��˴ϴ�.

Apply constraint  within type hierarchy  

��� ������ Ÿ�� �̸��� �� �װ��� �ǹ̸� �����ϴ�.  ï¿½ï¿½ï¿½ï¿½ ���õǸ�, ���� ��ġ�� ���� Ÿ�� �̸�������  ï¿½Æ´Ï¶ï¿½  ï¿½Î¸ð¿¡¼ï¿½(���� ������) �˻��˴ϴ�.

Invert condition  


���� ���õǸ�, �����ϴ� üũ �ڽ� ���� ��ȯ��Ű�� �˴ϴ�.


���� üũ(This variable is target of the search) �� ���õǸ�, �˻� ����� ��ü ǥ������ �ƴϰ� ���õ� �������� ������ ���Դϴ�.

Usecases  

 


���� ���� ������ ï¿½ï¿½ï¿½ï¿½ ���ø� ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¿ï¿½ ���� �����մϴ�.


*   Search patterns

1.   Elementary patterns:

$Statement$; pattern matches one statement. Increasing Occurrences count | Maximum count to, for instance, 5, makes it to find sequences having 1 to 5 statements.
$Instance$.$MethodCall$($Arguments$) pattern matches method call expressions. We can specify that method call could be absent by specifying that Occurrences count | Minimal count for the Instance variable is set to zero. Also we could request finding method calls with 3 to 5 parameters by specifying Minimal count = 3, Maximum count = 5 for the Argument variable.

2.   To search for all if statements we could specify the following pattern:

if ($Expr$) {
$ThenStatements$;
}
else {
$ElseStatements$;
}

Occurrences count minimum and maximum values for the ThenStatements and ElseStatements variables are set to 0 and MaxIntValue, respectively.

3.   Search in comments and/or string literals:

Consider one wants to find comments or literal containing '
foo'. Search pattern would be like $SomethingWeWantToFind$ or "$SomethingWeWantToFind$".

Text pattern for
"$SomethingWeWantToFind$" should define comment / literal content of interest (for our example .*foo.*).

In case one wants to find comments/string containing some particular words (say,
foo as word), then Whole words only option for a variable constraint should be set. Text constraint contains word(s) one want to find (foo for our example).

4.   More specific usages of class/interface methods (fields), for instance, equals, etc. which are accessed through descendants (e.g. searching equals called from instances of BaseComponentClass type descendants).

The pattern would be
$Instance$.equals($Parameter$). The Instance variable will have name of the java expression type set to short name of the class (BaseComponentClass), the Apply constraint in type hierarchy option in the Expression constraints group should be set as well.

5.   Let's consider finding all method implementations (say, all methods named show in JComponent descendants):

The search query should be as follows:

class $Class$ extends $JComponent$ {
public void $Show$();
}

Text constraint for the JComponent variable should be JComponent, with type hierarchy in the Text constraint group set to true. Text constraint for the Show variable should be shown with the This variable is target of the search option set to true (since we are looking for methods) as well. Class members will be searched without regard to the order of members in the classes being searched.

*   Replace patterns

oReplacement of empty length array creation with constant static ones.

The search pattern could be following:

new PsiElement[0]

And the replacement pattern:

PsiElement.EMPTY_ARRAY

oAdd try/catch/finally code.

The search pattern is
$Statements$; where the Occurrences count maximum value is Integer.MAX_VALUE.

The replacement pattern is the following:

try {
$Statements$;
}
catch (Exception ex) {
}

To remove such code one needs to revert replace/search patterns.