Eclipse 포맷터가 모든 열거 형을 한 줄에 배치하는 것을 중지하는 방법
다음과 같은 열거 형이 있습니다.
public static enum Command
{
login,
register,
logout,
newMessage
}
파일 형식을 지정할 때 출력은 다음과 같습니다.
public static enum Command
{
login, register, logout, newMessage
}
@wjans의 대답은 일반 열거 형에서는 잘 작동했지만 인수가있는 열거 형에서는 작동하지 않았습니다. 그의 대답을 조금 확장하기 위해 Eclipse Juno에서 나에게 가장 합리적인 형식을 제공 한 설정은 다음과 같습니다.
Window
>Preferences
>Java
>Code Style
>Formatter
- 딸깍 하는 소리
Edit
Line Wrapping
탭 선택enum
선언 트리 노드 선택- 이제 괄호 안에 3/3이 표시되도록 설정
Line wrapping policy
합니다Wrap all elements, every element on a new line (...)
. Force split, even if line shorter than maximum line width (...)
이제 괄호 안에 3/3이 표시 되도록 선택 취소 합니다.- 트리
Constants
노드 선택 - 검사
Force split, even if line shorter than maximum line width
이렇게하면 열거 형 트리 노드의 3 개의 하위 노드가 동일한 래핑 정책으로 설정되고 트리 노드를 제외하고 동일한 강제 분할 정책이 설정 Constants
되므로 인수가있는 열거 형은 각 줄에 형식이 지정됩니다. 인수는 최대 선 너비를 초과하는 경우에만 줄 바꿈됩니다.
예 :
@wjans
enum Example {
CANCELLED,
RUNNING,
WAITING,
FINISHED
}
enum Example {
GREEN(
0,
255,
0),
RED(
255,
0,
0)
}
위에 설명 된 솔루션 :
enum Example {
CANCELLED,
RUNNING,
WAITING,
FINISHED
}
enum Example {
GREEN(0, 255, 0),
RED(255, 0, 0)
}
포맷터 기본 설정에서이를 지정할 수 있습니다.
- 환경 설정 : Java-코드 스타일-포맷터
- 편집을 클릭하십시오.
- '줄 바꿈'탭을 선택합니다.
- 왼쪽 상자에서 '열거 형'선언-> 상수를 선택합니다.
- 줄 바꿈 정책을 '새 줄의 모든 요소, 모든 요소 래핑'으로 설정합니다.
- '강제 분할 ...'을 확인하십시오.
약간 못 생겼지 만 회사 정책으로 인해 포맷터를 변경할 수없는 경우 줄 바꿈하지 않으려는 줄 끝에 주석을 추가 할 수 있습니다.
public static enum Command
{
login,//
register,//
logout,//
newMessage//
};
It's not nice but you can turn the Eclipse formatter off for some sections of code...
// @formatter:off
public static enum Command {
login,
register,
logout,
newMessage
};
// @formatter:on
the option is in the Windows->Preferences->Java->Code Style->Formatter->Edit->Off/On Tags panel
You need to set the line wrapping policy under enum declaration for "Constants."
Set the wrapping policy to
- Wrap all elements, every element on a new line
AND
- Check the box that says "Force Split, even if line shorter than,,,,,
Just adding latest Eclipse 2018.9
Window > Preferences > Java > Code Style > Formatter
-Edit
- Expand
Line Wrapping
tree node. - Expand
Wrapping settings
- Expand
'enum' declaration
- Edit
Constants
andConstant arguments
.
Constants need to be Wrap all elements, every element on a new line
. Constant arguments need to be Wrap where necessary
.
'Programming' 카테고리의 다른 글
RSpec : 메서드가 호출되었는지 테스트하는 방법은 무엇입니까? (0) | 2020.08.15 |
---|---|
ASP.NET 리피터 바인딩 목록 (0) | 2020.08.15 |
표 셀에 여러 줄 문자를 표시하는 방법 (0) | 2020.08.15 |
런타임에 특정 하위보기에 대한 자동 레이아웃을 비활성화 할 수 있습니까? (0) | 2020.08.15 |
Swift make 메서드 매개 변수를 변경할 수 있습니까? (0) | 2020.08.15 |