�� ������ ��ſ��� Inline
Method �����丵 �󿡼� �������� overview�� how �� �����丵�� IntelliJ IDEA���� ���� �� �ִ°��� �����մϴ�.
�Ϲ������� �����ڸ�, Inline
Method �����丵�� Extract
Method �� �ݴ��Դϴ�. Extract Method �����丵 �����ϸ�
IDEA�� �� ȣ������ ���� �޼ҵ��� ���� ���� ���̰� �޼ҵ�� �����˴ϴ�.
�ݸ鿡, �� �����丵�� �����ϸ� ���� ����� ������ �ϳ��� �޼ҵ� ���� �����ϰ�, Inline�ϰ�, �ٸ� �ݰ� �޼ҵ� ���� �����մϴ�.
���� ���, �츮�� ���� �ڵ带 �����ϴ�:
public class AClass {
public int methodA( int param) {
return methodB() + param;
}
private int methodB() {
some code here
}
}
...
public class AnotherClass {
void foo (AClass aClass){
int res = aClass.methodA(1);
}
}
�׸��� ����� methodA�� ��� �ߺ��� ���� �˾ҽ��ϴ�. �̰��� �����丵�� ����ǰ� �� �Ŀ� �ڵ��Դϴ�:
public class AClass {
private int methodB() {
some code here
}
}
...
public class AnotherClass {
void foo (AClass aClass){
int res = aClass.methodB() + 1;
}
}
�޼ҵ带 inline �ϱ� ���ؼ�:
1. ���ϴ� �޼ҵ� �̸������� �� ���� �Ǵ� �κ����̼ǿ� �� ij���� ��ġ�ϰ�, �� �޴����� �Ǵ� �����Ϳ��� ������ ��ư�� Ŭ���Ͽ� �ҷ����� �˾� �޴����� Refactor | Inline... �� Ŭ���ϰų� OR Ctrl + Alt +
N �� �����ϴ�. �׸��� ����� ���� ���̾�α� �����츦 �� ���Դϴ�:


|
���� �����丵�� �޼ҵ� �������κ��� ȣ��Ǹ� This
invocation only and keep the method �ɼ� ��ư�� �Ұ����ϰ� �ϰ� �� �� �Դϴ�.
|
2. ���̾�α״� �ɼ� �׷�� üũ �ڽ��� �����ϴ�:
Inline
|
�޼ҵ尡 ��� Inline�Ǵ��� �����մϴ�:
All
invocations and remove the method - ��� �޼ҵ� �κ����̼��� �޼ҵ� ����� ��ü�� ���Դϴ�. �׸��� �޼ҵ� �� ��ü�� ���ŵ� ���Դϴ�.
This
invocation only and keep the method - �޼ҵ� �� ��ü�� ������ ���� ij���� �ִ� �κ����̼��� �޼ҵ� ����� ��ü�� ���Դϴ�.
|
Preview
invocations to be inlined
|
�� üũ �ڽ��� �����ϸ� ����� � ����� �߰ߵǾ����� �����ϰ�, �׵��� ��ü�� �����ϵ��� ����մϴ�.
�� üũ �ڽ��� ���õ��� ���� ��, IDEA�� ��ü ��ɸ� �ڵ������� �����մϴ�.

|
������ üũ �ڽ��� ���õ��� �ʾ��� ����, ���� �߰ߵ� ����� � �б� ���� ���Ͽ��� �����ϸ� ��ü ����� Ȯ���ϴ� ������Ʈ�� ��ſ� ���� �� �Դϴ�.
|
Refactoring Preview ���̾�α׿��� (���� �װ��� ��Ÿ����) ����� ����� ������ �м��� �� �ֽ��ϴ�. �����丵�� �Բ� �����ϱ� ���ؼ�, Do
Refactor�� Ŭ���մϴ�, �׷��� �ʴٸ� Cancel �� Ŭ���մϴ�. ���� ���� ������ Refactoring
Preview�� ���ʽÿ�.

|
���� This
invocation only and keep the method �ɼ� ��ư�� ���õǸ� Preview
invocations to be inlined üũ �ڽ��� �Ұ����ϰ� ���ϴ�.
|
|
|
3. OK�� Ŭ���Ͻʽÿ�. �׸��� ���ϴ� ������ inline �� ���Դϴ�.

|
Inline Method �����丵�� �����ϴµ� �Ϻ� ������ �ֽ��ϴ�. IDEA�� ���� �帧�� ���� ������Ʈ��Ʈ�� ���� �ߴܵ� ����� �޼ҵ� �Ǵ� �޼ҵ带 inline�� �� �����ϴ�.
���� ���:
private int methodA(){
int [] aaa = new int [10];
for ( int i = 0; i < aaa.length; i++) { i = aaa[i]; if (aaa[i] == 0) return i;
}
return -1;
}
���⿡���� methodA() �޼ҵ�� inline�� �� �����ϴ�. �׷� ��쿡 ��ſ��� ���� �޽����� ������Ʈ�� ���Դϴ�. �� ���� ����� �������� �ʿ��� �޼ҵ带 inline�ؾ߸� �ϰų�, �ڵ带 �����ϴ� ���� �����ؾ߸� �ϰų�, �̹��� Inline
Method �����丵�� �ϴ� ���� �ܳ��ؾ߸� �մϴ�.
|
|