독립형 자바 코드 포맷터 / 미용 / 예쁜 프린터? [닫은]
Java 용으로 사용할 수있는 고품질 독립형 소스 코드 포맷터에 대해 알아보고 싶습니다 .
포맷터는 독립형이어야합니다. 즉, 특정 개발 환경에서 분리 된 "배치"모드 를 지원해야 합니다 . 이상적으로는 특정 운영 체제 와도 독립적 이어야합니다 . 따라서 IDE du jour 용 내장 포맷터는 여기서 거의 관심이 없습니다 (IDE가 명령 줄에서 배치 모드 포맷터 호출을 지원하지 않는 한). Windows에서만 실행되는 폐쇄 소스 C / C ++로 작성된 포맷터는 이상적이지는 않지만 다소 흥미 롭습니다.
명확하게 말하면, "포맷터"(또는 "미용사")는 "스타일 검사기"와 동일하지 않습니다. 포맷터는 소스 코드를 입력으로 받아들이고 스타일 지정 규칙을 적용하며 원래 소스 코드와 의미 상 동일한 스타일이 지정된 소스 코드를 생성합니다. 구문 수정은 공백을 변경하거나 import
명령문을 구성하는 것과 같은 코드 레이아웃 수정과 같은 것으로 제한됩니다 . 다른 리팩토링은 거의 수행되지 않습니다. 스타일 검사기도 스타일 규칙을 적용하지만 수정 된 소스 코드 를 출력으로 생성하지 않고 규칙 위반 을 보고 합니다. 따라서 그림은 다음과 같습니다.
포맷터 (스타일링 규칙을 준수하는 수정 된 소스 코드 생성)
소스 코드 읽기 → 스타일 규칙 적용 → 스타일 소스 코드 쓰기
스타일 검사기 (수정 된 소스 코드를 생성하지 않음)
소스 코드 읽기 → 스타일링 규칙 적용 → 규칙 위반 쓰기
추가 설명
솔루션은 고도로 구성 가능해야합니다. 단순히 프리셋 목록에서 선택하는 것이 아니라 나만의 스타일을 지정할 수 있기를 원합니다.
또한 많은 것을 예쁘게 인쇄 할 수 있는 Java로 작성된 범용 예쁜 프린터를 찾고 있지 않습니다 . Java 코드 스타일을 지정하고 싶습니다.
나는 또한 많은 언어를위한 그랜드 통합 포맷터 에 반드시 관심이있는 것은 아닙니다 . 솔루션이 Java 이외의 언어를 지원하는 것이 좋을 수도 있지만 필수 사항은 아닙니다.
또한 코드 강조 표시 만 수행하는 도구 도 바로 사용할 수 있습니다.
웹 서비스 에도 관심이 없습니다. 로컬에서 실행할 수있는 도구를 원합니다.
마지막으로, 솔루션은 오픈 소스, 공개 도메인, 쉐어웨어, 무료 소프트웨어, 상업용 또는 그 밖의 다른 것으로 제한 될 필요가 없습니다. 모든 형태의 라이센스가 허용 됩니다.
JIndent (Commercial)는 원하는 작업을 수행합니다.
나는 또한 과거에 Jalopy를 사용하여이 작업을 수행했으며 오픈 소스입니다.
http://jalopy.sourceforge.net/
편집 : Jalopy가 상당히 오래되었고 최근 업데이트가없는 것 같습니다. Java 5/6에서 작동하는지 잘 모르겠습니다. 대신 Jacobe를 살펴볼 수 있습니다.
http://www.tiobe.com/index.php/content/products/jacobe/Jacobe.html
Roedy Green의 사이트에는 더 완전한 포맷터 목록도 있습니다.
http://mindprod.com/jgloss/beautifier.html
명령 줄에서 Eclipse 개혁자를 실행할 수도 있습니다.
다음은 기능에 대한 Eclipse 문서입니다.
먼저 Java 코드 포맷터 설정의 프로젝트에 특정한 구성 파일 을 만들어야합니다.
그런 다음 {projectDirectory}/.settings/org.eclipse.jdt.core.prefs
다른 위치에 저장하십시오 .
이제 포맷터를 호출합니다.
"c:\path\to\eclipse\eclipse.exe" -vm "C:\path\to\jdk\bin\java.exe" -application org.eclipse.jdt.core.JavaCodeFormatter -config "c:\path\to\org.eclipse.jdt.core.prefs" "C:\path\to\your\src"
[경고] Eclipse 2018에서 작동이 중지 된 것 같습니다. Eclipse Oxygen을 사용하세요.
Jalopy 가 흥미로울 수 있습니다. Ant에 연결되므로 IDE와 독립적입니다.
Astyle 도 유용 할 수 있습니다. 오픈 소스 (예 : Jalopy)이지만 C ++로 작성되었습니다. Java / C / C ++ 형식화에 맞춰져 있으며 일괄 처리 (셸 스크립트 또는 유사)를 통해 구동 될 수 있습니다.
업데이트 : 내가 제출 한 잘못된 버그 보고서를 기반으로 한 새로운 이해에 따라 : https://bugs.eclipse.org/bugs/show_bug.cgi?id=325289 OpenMRSFormatter.xml 파일은 실제로 XML이 아닌 기본 설정 파일이어야합니다. 파일.
https://bugs.eclipse.org/bugs/attachment.cgi?id=178874 에서 이러한 파일을 찾을 수 있습니다.
또는 다음을 사용하여 XML로 내 보낸 포맷터 파일을 변환하십시오. cat formatter.xml | grep 설정 | sed 's / @@'> formatter.asprefs
미샤 감사합니다
다음은 Eclipse 3.6 jar를 사용하여 만든 것입니다. Java 전용 명령 줄이며 플랫폼 간 호환이 가능해야합니다.
http://www.sendspace.com/file/nm4ptt
번들 OpenMRSCodeFormatter.xml 파일을 사용하는 쉘 스크립트가 있습니다. 샘플 출력 :
misha@misha-d630:~/openmrs-code-formatter$ cat ../Test.java
public class Test {
public a() {
System.out.println("! I did not format this right!");
}
}misha@misha-d630:~/openmrs-code-formatter$ ./format.sh ../Test.java
Configuration Name: OpenMRSFormatter.xml
Starting format job ...
Done.
cat ../misha@misha-d630:~/openmrs-code-formatter$ cat ../Test.java
public class Test {
public a() {
System.out.println("! I did not format this right!");
}
}misha@misha-d630:~/openmrs-code-formatter$
이것은 http://www.peterfriese.de/formatting-your-code-using-the-eclipse-code-formatter/ 게시물을 기반으로합니다 .
링크가 얼마나 오래 유지 될지 모르기 때문에 아래 내용을 설명하겠습니다.
이것은 Eclipse 3.6 Helios 배포판을 기반으로합니다. Linux x86 용으로 사용했지만 플랫폼 별 JAR 파일을 사용하지 않았기 때문에 모든 버전에서 작동합니다.
tar 아카이브의 내용은 다음과 같습니다.
misha@misha-d630:~$ tar tvjf openmrs-code-formatter.tar.bz2 | sort
tar: Record size = 8 blocks
drwxr-xr-x misha/misha 0 2010-09-11 19:32 openmrs-code-formatter/plugins/
drwxr-xr-x misha/misha 0 2010-09-11 19:33 openmrs-code-formatter/configuration/org.eclipse.equinox.simpleconfigurator/
drwxr-xr-x misha/misha 0 2010-09-11 19:38 openmrs-code-formatter/configuration/
-rw-r--r-- misha/misha 101957 2010-09-11 19:03 openmrs-code-formatter/plugins/org.eclipse.equinox.common_3.6.0.v20100503.jar
-rw-r--r-- misha/misha 107210 2010-09-11 19:32 openmrs-code-formatter/plugins/org.eclipse.core.commands_3.6.0.I20100512-1500.jar
-rw-r--r-- misha/misha 111098 2010-09-11 19:06 openmrs-code-formatter/plugins/org.eclipse.equinox.preferences_3.3.0.v20100503.jar
-rw-r--r-- misha/misha 1147220 2010-09-11 18:45 openmrs-code-formatter/plugins/org.eclipse.osgi_3.6.0.v20100517.jar
-rw-r--r-- misha/misha 1812 2010-09-11 19:33 openmrs-code-formatter/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info
-rw-r--r-- misha/misha 182596 2010-09-11 19:05 openmrs-code-formatter/plugins/org.eclipse.equinox.registry_3.5.0.v20100503.jar
-rw-r--r-- misha/misha 248071 2010-09-11 19:29 openmrs-code-formatter/plugins/org.eclipse.text_3.5.0.v20100601-1300.jar
-rw-r--r-- misha/misha 265 2010-09-11 19:21 openmrs-code-formatter/configuration/config.ini
-rw-r--r-- misha/misha 28554 2010-09-11 19:34 openmrs-code-formatter/OpenMRSFormatter.xml
-rw-r--r-- misha/misha 39331 2010-09-11 19:17 openmrs-code-formatter/plugins/org.eclipse.equinox.simpleconfigurator_1.0.200.v20100503.jar
-rw-r--r-- misha/misha 4504121 2010-09-11 19:27 openmrs-code-formatter/plugins/org.eclipse.jdt.core_3.6.0.v_A58.jar
-rw-r--r-- misha/misha 47023 2010-09-11 18:42 openmrs-code-formatter/plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar
-rw-r--r-- misha/misha 52710 2010-09-11 19:29 openmrs-code-formatter/plugins/org.eclipse.core.filesystem_1.3.0.v20100526-0737.jar
-rw-r--r-- misha/misha 6451211 2010-09-11 19:32 openmrs-code-formatter/plugins/com.ibm.icu_4.2.1.v20100412.jar
-rw-r--r-- misha/misha 70928 2010-09-11 19:01 openmrs-code-formatter/plugins/org.eclipse.core.runtime_3.6.0.v20100505.jar
-rw-r--r-- misha/misha 769898 2010-09-11 19:29 openmrs-code-formatter/plugins/org.eclipse.core.resources_3.6.0.v20100526-0737.jar
-rw-r--r-- misha/misha 83817 2010-09-11 19:07 openmrs-code-formatter/plugins/org.eclipse.equinox.app_1.3.0.v20100512.jar
-rw-r--r-- misha/misha 86986 2010-09-11 19:31 openmrs-code-formatter/plugins/org.eclipse.core.expressions_3.4.200.v20100505.jar
-rw-r--r-- misha/misha 90837 2010-09-11 19:05 openmrs-code-formatter/plugins/org.eclipse.core.jobs_3.5.0.v20100515.jar
-rw-r--r-- misha/misha 91928 2010-09-11 19:06 openmrs-code-formatter/plugins/org.eclipse.core.contenttype_3.4.100.v20100505-1235.jar
-rwxr-xr-x misha/misha 111 2010-09-11 19:39 openmrs-code-formatter/format.sh
플러그인 디렉토리의 관련 jar는 Eclipse 3.6 플러그인 디렉토리에서 직접 가져옵니다.
config.ini의 내용은 다음과 같습니다.
misha@misha-d630:~$ more openmrs-code-formatter/configuration/config.ini
osgi.bundles=reference\:file\:org.eclipse.equinox.simpleconfigurator_1.0.200.v20100503.jar@1\:start
org.eclipse.equinox.simpleconfigurator.configUrl=file\:org.eclipse.equinox.simpleconfigurator/bundles.info
eclipse.application=org.eclipse.jdt.core.JavaCodeFormatter
format.sh는 다음과 같습니다.
misha@misha-d630:~$ more openmrs-code-formatter/format.sh
#!/bin/bash
java -jar plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar -config OpenMRSFormatter.xml $*
and OpenMRSFormatter.xml is available here: http://wiki.openmrs.org/download/attachments/3346087/OpenMRSFormatter.xml?version=1&modificationDate=1282168038000
I believe that should be sufficient to reproduce.
An interesting project based on the same concept is found here: http://code.google.com/p/maven-java-formatter-plugin/
Thank you Misha
Try "Jacobe Code Beautifier":
http://www.tiobe.com/index.php/content/products/jacobe/Jacobe.html
The personal edition is free.
I used to use Dr. Java to code in and with a quick ctrl+A + tab it formats it all nicely with syntax highlighting. Ive used it on a Mac and Windows, dont know if they support linux. And it's open source, stand alone, and free.
I also used a lot the PrettyPrinter embedded inside JRefactory (http://jrefactory.sourceforge.net/). I discovered it through its plugin for JEdit. I appreciated it as it had the better javadoc coverage I ever saw.
Unfortunately it seems dead (no evolution since 2004) and actually it does not support Java5.
By the way I confirm that Triemax is a commercial suite based on dead open-source Jalopy.
See our Java Formatter for a tool that handles all dialects of Java, including version 7.
Jalopy does not handle Statements like List stuff<MyClass> ... and lint comments starting with @
I have been able to force it to format by changing all the <MyClass> into LTLTLTMyClassGTGTGT and then @ into //@//@//@ (I just repeat the LT, GT or //@ to make sure they don't already exist. Then I was able to Jalopy, and obviously I have to replace everything back to what it was.
Also, prior to changing the < or > you have to make sure you won't change compares like <= or >= etc.
So, you might call this the poor man solution because it involves many manual steps. If I was to do Jalopy more often, I would probably write a script using sed that would make those changes automatically for me.
참고URL : https://stackoverflow.com/questions/996646/stand-alone-java-code-formatter-beautifier-pretty-printer
'program tip' 카테고리의 다른 글
Android-활동 생성자 대 onCreate (0) | 2020.10.06 |
---|---|
C #에서 권투 발생 (0) | 2020.10.06 |
요청 리퍼러 경로를 얻는 방법은 무엇입니까? (0) | 2020.10.05 |
PHP의 DateTime 클래스에서 DateTime-> date에 액세스 할 수없는 이유는 무엇입니까? (0) | 2020.10.05 |
React는 클릭시 중첩 된 구성 요소에서 이벤트 버블 링을 방지합니다. (0) | 2020.10.05 |