├── .ci.settings.xml ├── .github └── workflows │ ├── linux_maven.yml │ ├── release_maven.yml │ └── windows_maven.yml ├── .gitignore ├── FUNDING.yml ├── LICENSE ├── README.md ├── eclipse_formatter_template.xml ├── licenseheader.txt ├── nb-configuration.xml ├── nbactions.xml ├── pom.xml └── src ├── changes └── changes.xml ├── main ├── java │ └── de │ │ └── funfried │ │ └── netbeans │ │ └── plugins │ │ └── external │ │ └── formatter │ │ ├── AbstractFormatJob.java │ │ ├── FormatJob.java │ │ ├── FormatterService.java │ │ ├── FormatterServiceDelegate.java │ │ ├── MimeType.java │ │ ├── css │ │ ├── base │ │ │ ├── AbstractCssFormatterService.java │ │ │ └── package-info.java │ │ └── cssparser │ │ │ ├── CssParserFormatJob.java │ │ │ ├── CssParserFormatterService.java │ │ │ ├── CssParserFormatterSettings.java │ │ │ ├── CssParserFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ ├── CssParserFormatterOptionsPanel.form │ │ │ ├── CssParserFormatterOptionsPanel.java │ │ │ └── package-info.java │ │ ├── eclipse │ │ ├── AbstractEclipseFormatJob.java │ │ ├── mechanic │ │ │ └── WorkspaceMechanicConfigParser.java │ │ ├── package-info.java │ │ └── xml │ │ │ ├── ConfigReader.java │ │ │ ├── EclipseFormatterUtils.java │ │ │ └── package-info.java │ │ ├── exceptions │ │ ├── CannotLoadConfigurationException.java │ │ ├── ConfigReadException.java │ │ ├── FormattingFailedException.java │ │ ├── ProfileNotFoundException.java │ │ └── package-info.java │ │ ├── html │ │ ├── base │ │ │ ├── AbstractHtmlFormatterService.java │ │ │ └── package-info.java │ │ └── jsoup │ │ │ ├── JsoupHtmlFormatJob.java │ │ │ ├── JsoupHtmlFormatterService.java │ │ │ ├── JsoupHtmlFormatterSettings.java │ │ │ ├── JsoupHtmlFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ ├── JsoupHtmlFormatterOptionsPanel.form │ │ │ ├── JsoupHtmlFormatterOptionsPanel.java │ │ │ └── package-info.java │ │ ├── java │ │ ├── base │ │ │ ├── AbstractJavaFormatterService.java │ │ │ ├── actions │ │ │ │ ├── JavaFixImportsAction.java │ │ │ │ ├── JavaOrganizeImportsAction.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── eclipse │ │ │ ├── EclipseFormatJob.java │ │ │ ├── EclipseFormatterConfig.java │ │ │ ├── EclipseJavaFormatterService.java │ │ │ ├── EclipseJavaFormatterSettings.java │ │ │ ├── EclipseJavaFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ │ ├── EclipseJavaFormatterOptionsPanel.form │ │ │ │ ├── EclipseJavaFormatterOptionsPanel.java │ │ │ │ └── package-info.java │ │ ├── google │ │ │ ├── GoogleFormatJob.java │ │ │ ├── GoogleJavaFormatterService.java │ │ │ ├── GoogleJavaFormatterSettings.java │ │ │ ├── GoogleJavaFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ │ ├── GoogleJavaFormatterOptionsPanel.form │ │ │ │ ├── GoogleJavaFormatterOptionsPanel.java │ │ │ │ └── package-info.java │ │ ├── palantir │ │ │ ├── PalantirFormatJob.java │ │ │ ├── PalantirJavaFormatterService.java │ │ │ ├── PalantirJavaFormatterSettings.java │ │ │ ├── PalantirJavaFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ │ ├── PalantirJavaFormatterOptionsPanel.form │ │ │ │ ├── PalantirJavaFormatterOptionsPanel.java │ │ │ │ └── package-info.java │ │ └── spring │ │ │ ├── SpringFormatJob.java │ │ │ ├── SpringJavaFormatterService.java │ │ │ ├── SpringJavaFormatterSettings.java │ │ │ ├── SpringJavaFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ ├── SpringJavaFormatterOptionsPanel.form │ │ │ ├── SpringJavaFormatterOptionsPanel.java │ │ │ └── package-info.java │ │ ├── javascript │ │ ├── base │ │ │ ├── AbstractJavascriptFormatterService.java │ │ │ └── package-info.java │ │ └── eclipse │ │ │ ├── EclipseFormatJob.java │ │ │ ├── EclipseFormatterConfig.java │ │ │ ├── EclipseJavascriptFormatterService.java │ │ │ ├── EclipseJavascriptFormatterSettings.java │ │ │ ├── EclipseJavascriptFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ ├── EclipseJavascriptFormatterOptionsPanel.form │ │ │ ├── EclipseJavascriptFormatterOptionsPanel.java │ │ │ └── package-info.java │ │ ├── json │ │ ├── base │ │ │ ├── AbstractJsonFormatterService.java │ │ │ └── package-info.java │ │ └── jackson │ │ │ ├── JacksonFormatJob.java │ │ │ ├── JacksonJsonFormatterService.java │ │ │ ├── JacksonJsonFormatterSettings.java │ │ │ ├── JacksonJsonFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ ├── JacksonJsonFormatterOptionsPanel.form │ │ │ ├── JacksonJsonFormatterOptionsPanel.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── sql │ │ ├── dbeaver │ │ │ ├── DBeaverFormatterJob.java │ │ │ ├── DBeaverFormatterService.java │ │ │ ├── DBeaverFormatterSettings.java │ │ │ ├── DBeaverFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ │ ├── DBeaverFormatterOptionsPanel.form │ │ │ │ ├── DBeaverFormatterOptionsPanel.java │ │ │ │ └── package-info.java │ │ ├── jsqlformatter │ │ │ ├── JSQLFormatterJob.java │ │ │ ├── JSQLFormatterService.java │ │ │ ├── JSQLFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ │ ├── JSQLFormatterOptionsPanel.form │ │ │ │ ├── JSQLFormatterOptionsPanel.java │ │ │ │ └── package-info.java │ │ └── sqlformatter │ │ │ ├── SQLFormatterJob.java │ │ │ ├── SQLFormatterService.java │ │ │ ├── SQLFormatterSettings.java │ │ │ ├── SQLFormatterWrapper.java │ │ │ ├── package-info.java │ │ │ └── ui │ │ │ ├── SQLFormatterOptionsPanel.form │ │ │ ├── SQLFormatterOptionsPanel.java │ │ │ └── package-info.java │ │ ├── ui │ │ ├── Icons.java │ │ ├── customizer │ │ │ ├── ExternalFormatterCustomizerTab.java │ │ │ ├── ProjectSpecificSettingsPanel.form │ │ │ ├── ProjectSpecificSettingsPanel.java │ │ │ ├── VerifiableConfigPanel.java │ │ │ └── package-info.java │ │ ├── editor │ │ │ ├── EditorConstants.java │ │ │ ├── EditorUtils.java │ │ │ ├── ExternalFormatterCodeStylePreferencesProvider.java │ │ │ ├── ExternalFormatterIndentTaskFactory.java │ │ │ ├── ExternalFormatterReformatTaskFactory.java │ │ │ ├── TaskFactoryUtils.java │ │ │ ├── diff │ │ │ │ ├── Diff.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ ├── options │ │ │ ├── AbstractFormatterOptionsPanel.java │ │ │ ├── ExternalFormatterOptionsPanelController.java │ │ │ ├── ExternalFormatterPanel.form │ │ │ ├── ExternalFormatterPanel.java │ │ │ ├── ExternalFormatterPreferencesChangeSupport.java │ │ │ ├── ExternalFormatterSupportDialog.form │ │ │ ├── ExternalFormatterSupportDialog.java │ │ │ ├── FormatterOptionsPanel.java │ │ │ ├── Settings.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ └── xml │ │ ├── base │ │ ├── AbstractXmlFormatterService.java │ │ └── package-info.java │ │ ├── jsoup │ │ ├── JsoupXmlFormatJob.java │ │ ├── JsoupXmlFormatterService.java │ │ ├── JsoupXmlFormatterSettings.java │ │ ├── JsoupXmlFormatterWrapper.java │ │ ├── package-info.java │ │ └── ui │ │ │ ├── JsoupXmlFormatterOptionsPanel.form │ │ │ ├── JsoupXmlFormatterOptionsPanel.java │ │ │ └── package-info.java │ │ └── revelc │ │ ├── RevelcFormatJob.java │ │ ├── RevelcXmlFormatterService.java │ │ ├── RevelcXmlFormatterSettings.java │ │ ├── RevelcXmlFormatterWrapper.java │ │ ├── package-info.java │ │ └── ui │ │ ├── RevelcXmlFormatterOptionsPanel.form │ │ ├── RevelcXmlFormatterOptionsPanel.java │ │ └── package-info.java ├── nbm │ └── manifest.mf └── resources │ └── de │ └── funfried │ └── netbeans │ └── plugins │ └── external │ └── formatter │ ├── Bundle.properties │ ├── css │ └── cssparser │ │ └── ui │ │ └── Bundle.properties │ ├── dbeaver.png │ ├── eclipse-formatter-templates.xml │ ├── eclipse.gif │ ├── epl-v20.html │ ├── external.gif │ ├── google.gif │ ├── html │ └── jsoup │ │ └── ui │ │ └── Bundle.properties │ ├── jackson.gif │ ├── java │ ├── base │ │ └── actions │ │ │ └── Bundle.properties │ ├── eclipse │ │ └── ui │ │ │ └── Bundle.properties │ ├── google │ │ └── ui │ │ │ └── Bundle.properties │ ├── palantir │ │ └── ui │ │ │ └── Bundle.properties │ └── spring │ │ └── ui │ │ └── Bundle.properties │ ├── javascript │ └── eclipse │ │ └── ui │ │ └── Bundle.properties │ ├── json │ └── jackson │ │ └── ui │ │ └── Bundle.properties │ ├── jsoup.gif │ ├── layer.xml │ ├── manticore.png │ ├── netbeans.gif │ ├── revelc.gif │ ├── spring.gif │ ├── sql │ ├── dbeaver │ │ └── ui │ │ │ └── Bundle.properties │ ├── jsqlformatter │ │ └── ui │ │ │ └── Bundle.properties │ └── sqlformatter │ │ └── ui │ │ └── Bundle.properties │ ├── ui │ └── options │ │ ├── Bundle.properties │ │ ├── become_a_patron.png │ │ ├── buy_me_a_drink.png │ │ ├── donate.gif │ │ └── say_thanks.png │ └── xml │ ├── jsoup │ └── ui │ │ └── Bundle.properties │ └── revelc │ └── ui │ └── Bundle.properties ├── site ├── resources │ └── imgs │ │ ├── global.png │ │ ├── logos │ │ ├── become_a_patron_button.png │ │ ├── buy_me_a_drink.png │ │ ├── externalcodeformatter.png │ │ ├── netbeans.png │ │ ├── netbeans_small.png │ │ └── say_thanks.png │ │ ├── onsave.png │ │ └── project.png ├── site.xml └── xdoc │ ├── downloads.xml │ ├── index.xml │ ├── known_issues.xml │ └── usage.xml └── test ├── java └── de │ └── funfried │ └── netbeans │ └── plugins │ └── external │ └── formatter │ ├── FormatterServiceDelegateTest.java │ ├── css │ └── cssparser │ │ ├── CssParserFormatterServiceTest.java │ │ ├── CssParserFormatterWrapperTest.java │ │ └── package-info.java │ ├── eclipse │ ├── mechanic │ │ └── WorkspaceMechanicConfigParserTest.java │ └── xml │ │ ├── ConfigReaderTest.java │ │ └── package-info.java │ ├── html │ └── jsoup │ │ ├── JsoupHtmlFormatterServiceTest.java │ │ ├── JsoupHtmlFormatterWrapperTest.java │ │ └── package-info.java │ ├── java │ ├── eclipse │ │ ├── EclipseJavaFormatterServiceTest.java │ │ ├── EclipseJavaFormatterWrapperTest.java │ │ └── package-info.java │ ├── google │ │ ├── FormatterTest.java │ │ ├── GoogleJavaFormatterServiceTest.java │ │ ├── GoogleJavaFormatterWrapperTest.java │ │ └── package-info.java │ ├── palantir │ │ ├── FormatterTest.java │ │ ├── PalantirJavaFormatterServiceTest.java │ │ ├── PalantirJavaFormatterWrapperTest.java │ │ └── package-info.java │ └── spring │ │ ├── SpringJavaFormatterServiceTest.java │ │ ├── SpringJavaFormatterWrapperTest.java │ │ └── package-info.java │ ├── javascript │ └── eclipse │ │ ├── EclipseJavascriptFormatterServiceTest.java │ │ ├── EclipseJavascriptFormatterWrapperTest.java │ │ └── package-info.java │ ├── json │ └── jackson │ │ ├── JacksonJsonFormatterServiceTest.java │ │ ├── JacksonJsonFormatterWrapperTest.java │ │ └── package-info.java │ ├── package-info.java │ ├── sql │ ├── dbeaver │ │ ├── DBeaverFormatterServiceTest.java │ │ ├── DBeaverFormatterWrapperTest.java │ │ └── package-info.java │ ├── jsqlformatter │ │ ├── JSQLFormatterServiceTest.java │ │ ├── JSQLFormatterWrapperTest.java │ │ └── package-info.java │ └── sqlformatter │ │ ├── SQLFormatterServiceTest.java │ │ ├── SQLFormatterWrapperTest.java │ │ └── package-info.java │ └── xml │ ├── jsoup │ ├── JsoupXmlFormatterServiceTest.java │ ├── JsoupXmlFormatterWrapperTest.java │ └── package-info.java │ └── revelc │ ├── RevelcXmlFormatterServiceTest.java │ ├── RevelcXmlFormatterWrapperTest.java │ └── package-info.java └── resources ├── 3rdPartyFormatter_org.eclipse.jdt.core.prefs ├── 4.4.xml ├── complex-org.eclipse.jdt.core.prefs ├── defaultformatter_org.eclipse.jdt.core.prefs ├── defectformattersampleeclipse.xml ├── defectjsformattersampleeclipse.xml ├── formatteronoffsampleeclipse.xml ├── formattersampleeclipse.xml ├── jsformattersampleeclipse.xml ├── jsmechanic-formatter.epf ├── mechanic-formatter-complex.epf ├── mechanic-formatter.epf ├── noprofilesampleeclipse.xml ├── org.eclipse.jdt.core.prefs ├── org.eclipse.wst.jsdt.core.prefs └── wrongprofilekindsampleeclipse.xml /.github/workflows/linux_maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Linux Build 5 | 6 | on: 7 | push: 8 | branches: 9 | - release/* 10 | pull_request: 11 | branches: 12 | - master 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Set up JDK 17 20 | uses: actions/setup-java@v3 21 | with: 22 | java-version: '17' 23 | distribution: 'adopt' 24 | cache: maven 25 | - name: Build with Maven 26 | run: mvn -s .ci.settings.xml --no-transfer-progress -Dgh_username=${{ secrets.GH_USERNAME }} -Dgh_token=${{ secrets.GH_TOKEN }} -Prelease-commons,sonatype-oss-release package site 27 | env: 28 | MAVEN_OPTS: -Xms128m -Xmx512m --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED 29 | nvd_api_key: ${{ secrets.NVD_API_KEY }} 30 | -------------------------------------------------------------------------------- /.github/workflows/release_maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Release Build 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up JDK 17 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '17' 20 | distribution: 'adopt' 21 | cache: maven 22 | - name: Build and Deploy with Maven 23 | run: | 24 | git config --global user.email "info@funfried.de" 25 | git config --global user.name "funfried" 26 | echo ${{ secrets.GPG_SIGNING_SECRET_KEY }} | base64 --decode | gpg --batch --import 27 | echo ${{ secrets.GPG_SIGNING_OWNERTRUST }} | base64 --decode | gpg --import-ownertrust 28 | mvn -s .ci.settings.xml --no-transfer-progress -Prelease-commons,sonatype-oss-release deploy site site:stage scm-publish:publish-scm 29 | mvn -s .ci.settings.xml -Pcoveralls coveralls:report 30 | mvn -s .ci.settings.xml --no-transfer-progress -Prelease-commons,github clean deploy 31 | bash <(curl -s https://codecov.io/bash) 32 | env: 33 | GPG_TTY: $(tty) 34 | MAVEN_OPTS: -Xms128m -Xmx512m --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED 35 | gh_username: ${{ secrets.GH_USERNAME }} 36 | gh_token: ${{ secrets.GH_TOKEN }} 37 | sonatype_username: ${{ secrets.SONATYPE_USERNAME }} 38 | sonatype_password: ${{ secrets.SONATYPE_PASSWORD }} 39 | repoToken: ${{ secrets.COVERALLS_REPOTOKEN }} 40 | signing_keypass: ${{ secrets.GPG_PASSPHRASE }} 41 | skipRemoteStaging: ${{ secrets.SKIP_REMOTE_STAGING }} 42 | nvd_api_key: ${{ secrets.NVD_API_KEY }} 43 | -------------------------------------------------------------------------------- /.github/workflows/windows_maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Windows Build 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | - release/* 11 | pull_request: 12 | branches: 13 | - master 14 | 15 | jobs: 16 | build: 17 | runs-on: windows-latest 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Set up JDK 17 21 | uses: actions/setup-java@v3 22 | with: 23 | java-version: '17' 24 | distribution: 'adopt' 25 | cache: maven 26 | - name: Build with Maven 27 | run: mvn -s .ci.settings.xml --no-transfer-progress clean package site 28 | env: 29 | MAVEN_OPTS: -Xms128m -Xmx512m --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED 30 | gh_username: ${{ secrets.GH_USERNAME }} 31 | gh_token: ${{ secrets.GH_TOKEN }} 32 | sonatype_username: ${{ secrets.SONATYPE_USERNAME }} 33 | sonatype_password: ${{ secrets.SONATYPE_PASSWORD }} 34 | repoToken: ${{ secrets.GH_REPOTOKEN }} 35 | signing_keypass: ${{ secrets.GPG_PASSPHRASE }} 36 | skipRemoteStaging: ${{ secrets.SKIP_REMOTE_STAGING }} 37 | nvd_api_key: ${{ secrets.NVD_API_KEY }} 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/windows,linux,macos,java,maven,netbeans 3 | # Edit at https://www.gitignore.io/?templates=windows,linux,macos,java,maven,netbeans 4 | 5 | ### Java ### 6 | # Compiled class file 7 | *.class 8 | 9 | # Log file 10 | *.log 11 | 12 | # BlueJ files 13 | *.ctxt 14 | 15 | # Mobile Tools for Java (J2ME) 16 | .mtj.tmp/ 17 | 18 | # Package Files # 19 | *.jar 20 | *.war 21 | *.nar 22 | *.ear 23 | *.zip 24 | *.tar.gz 25 | *.rar 26 | 27 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 28 | hs_err_pid* 29 | 30 | ### Maven ### 31 | target/ 32 | pom.xml.tag 33 | pom.xml.releaseBackup 34 | pom.xml.versionsBackup 35 | pom.xml.next 36 | release.properties 37 | dependency-reduced-pom.xml 38 | buildNumber.properties 39 | .mvn/timing.properties 40 | .mvn/wrapper/maven-wrapper.jar 41 | .flattened-pom.xml 42 | 43 | ### NetBeans ### 44 | **/nbproject/ 45 | build/ 46 | nbbuild/ 47 | dist/ 48 | nbdist/ 49 | .nb-gradle/ 50 | 51 | ### Linux ### 52 | *~ 53 | 54 | # temporary files which can be created if a process still has a handle open of a deleted file 55 | .fuse_hidden* 56 | 57 | # KDE directory preferences 58 | .directory 59 | 60 | # Linux trash folder which might appear on any partition or disk 61 | .Trash-* 62 | 63 | # .nfs files are created when an open file is removed but is still being accessed 64 | .nfs* 65 | 66 | ### macOS ### 67 | # General 68 | .DS_Store 69 | .AppleDouble 70 | .LSOverride 71 | 72 | # Icon must end with two \r 73 | Icon 74 | 75 | # Thumbnails 76 | ._* 77 | 78 | # Files that might appear in the root of a volume 79 | .DocumentRevisions-V100 80 | .fseventsd 81 | .Spotlight-V100 82 | .TemporaryItems 83 | .Trashes 84 | .VolumeIcon.icns 85 | .com.apple.timemachine.donotpresent 86 | 87 | # Directories potentially created on remote AFP share 88 | .AppleDB 89 | .AppleDesktop 90 | Network Trash Folder 91 | Temporary Items 92 | .apdisk 93 | 94 | ### Windows ### 95 | # Windows thumbnail cache files 96 | Thumbs.db 97 | Thumbs.db:encryptable 98 | ehthumbs.db 99 | ehthumbs_vista.db 100 | 101 | # Dump file 102 | *.stackdump 103 | 104 | # Folder config file 105 | [Dd]esktop.ini 106 | 107 | # Recycle Bin used on file shares 108 | $RECYCLE.BIN/ 109 | 110 | # Windows Installer files 111 | *.cab 112 | *.msi 113 | *.msix 114 | *.msm 115 | *.msp 116 | 117 | # Windows shortcuts 118 | *.lnk 119 | 120 | # End of https://www.gitignore.io/api/windows,linux,macos,java,maven,netbeans -------------------------------------------------------------------------------- /FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [funfried] 2 | patreon: funfried 3 | custom: ["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=926F5XBCTK2LQ&source=url"] 4 | -------------------------------------------------------------------------------- /licenseheader.txt: -------------------------------------------------------------------------------- 1 | <#if licenseFirst??> 2 | ${licenseFirst} 3 | 4 | ${licensePrefix}Copyright (c) ${date?date?string("yyyy")} ${project.organization!user}. 5 | ${licensePrefix}All rights reserved. This program and the accompanying materials 6 | ${licensePrefix}are made available under the terms of the Eclipse Public License v2.0 7 | ${licensePrefix}which accompanies this distribution, and is available at 8 | ${licensePrefix}http://www.eclipse.org/legal/epl-v20.html 9 | ${licensePrefix?replace(" +$", "", "r")} 10 | ${licensePrefix}Contributors: 11 | ${licensePrefix} ${project.organization!user} - initial API and implementation and/or initial documentation 12 | <#if licenseLast??> 13 | ${licenseLast} 14 | 15 | -------------------------------------------------------------------------------- /nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-format 5 | format 6 | 7 | formatter:format 8 | 9 | 10 | 11 | CUSTOM-site 12 | site 13 | 14 | site:site 15 | 16 | 17 | 18 | CUSTOM-site and deploy 19 | site and deploy 20 | 21 | verify 22 | site 23 | site:stage 24 | scm-publish:publish-scm 25 | 26 | 27 | 28 | CUSTOM-deploy to maven central 29 | deploy to maven central 30 | 31 | clean 32 | deploy 33 | 34 | 35 | release-commons 36 | sonatype-oss-release 37 | 38 | 39 | 40 | CUSTOM-deploy to GitHub 41 | deploy to GitHub 42 | 43 | clean 44 | deploy 45 | 46 | 47 | release-commons 48 | github 49 | 50 | 51 | 52 | CUSTOM-release site to GitHub and artifact to maven central 53 | release site to GitHub and artifact to maven central 54 | 55 | clean 56 | deploy 57 | site 58 | site:stage 59 | scm-publish:publish-scm 60 | 61 | 62 | release-commons 63 | sonatype-oss-release 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/FormatJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | package de.funfried.netbeans.plugins.external.formatter; 12 | 13 | import javax.swing.text.BadLocationException; 14 | 15 | /** 16 | * 17 | * @author bahlef 18 | */ 19 | public interface FormatJob { 20 | /** 21 | * Executes the formatting of this {@link FormatJob}. 22 | * 23 | * @throws BadLocationException if something goes wrong while applying the formatted code 24 | */ 25 | void format() throws BadLocationException; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/MimeType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | package de.funfried.netbeans.plugins.external.formatter; 12 | 13 | import java.util.List; 14 | import java.util.Objects; 15 | import java.util.regex.Pattern; 16 | 17 | import javax.swing.text.Document; 18 | 19 | import org.apache.commons.lang3.StringUtils; 20 | import org.netbeans.api.java.lexer.JavaTokenId; 21 | import org.netbeans.modules.editor.NbEditorUtilities; 22 | import org.openide.util.NbBundle; 23 | 24 | /** 25 | * Enum describing the supported mime types for external formatters. 26 | * 27 | * @author bahlef 28 | */ 29 | @NbBundle.Messages({ 30 | "CSS=CSS", 31 | "HTML=HTML", 32 | "JAVA=Java", 33 | "JAVASCRIPT=JavaScript", 34 | "JSON=Json", 35 | "XML=XML", 36 | "SQL=SQL" 37 | }) 38 | public enum MimeType { 39 | CSS("text/css"), HTML("application/xhtml+xml", "text/html", "text/xhtml"), JAVA(JavaTokenId.language().mimeType()), JAVASCRIPT("text/javascript"), JSON("text/x-json", 40 | "^text/(.*)\\+x-json$"), XML("text/xml", "^text/(.*)\\+xml$"), SQL("application/sql", "text/sql", "text/x-sql", "text/plain"); 41 | 42 | private final String[] mimeTypes; 43 | 44 | MimeType(String... mimeTypes) { 45 | this.mimeTypes = mimeTypes; 46 | } 47 | 48 | public String getDisplayName() { 49 | return NbBundle.getMessage(MimeType.class, this.toString()); 50 | } 51 | 52 | public boolean canHandle(String mimeType) { 53 | if (StringUtils.isBlank(mimeType)) { 54 | return false; 55 | } 56 | 57 | for (String type : mimeTypes) { 58 | if (type.startsWith("^") && Pattern.matches(type, mimeType)) { 59 | return true; 60 | } else if (Objects.equals(type, mimeType)) { 61 | return true; 62 | } 63 | } 64 | 65 | return false; 66 | } 67 | 68 | public static boolean canHandle(List types, String mimeType) { 69 | if (StringUtils.isBlank(mimeType)) { 70 | return false; 71 | } 72 | 73 | for (MimeType t : types) { 74 | for (String type : t.mimeTypes) { 75 | if (type.startsWith("^") && Pattern.matches(type, mimeType)) { 76 | return true; 77 | } else if (Objects.equals(type, mimeType)) { 78 | return true; 79 | } 80 | } 81 | } 82 | 83 | return false; 84 | } 85 | 86 | public static MimeType getByMimeType(String mimeType) { 87 | for (MimeType mime : MimeType.values()) { 88 | if (mime.canHandle(mimeType)) { 89 | return mime; 90 | } 91 | } 92 | 93 | return null; 94 | } 95 | 96 | public static MimeType getMimeType(Document document) { 97 | return getByMimeType(getMimeTypeAsString(document)); 98 | } 99 | 100 | public static String getMimeTypeAsString(Document document) { 101 | if (document != null) { 102 | return NbEditorUtilities.getMimeType(document); 103 | } 104 | 105 | return null; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/css/base/AbstractCssFormatterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.css.base; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.apache.commons.lang3.tuple.Pair; 20 | import org.netbeans.api.annotations.common.CheckForNull; 21 | 22 | import de.funfried.netbeans.plugins.external.formatter.FormatJob; 23 | import de.funfried.netbeans.plugins.external.formatter.FormatterService; 24 | import de.funfried.netbeans.plugins.external.formatter.MimeType; 25 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 26 | 27 | /** 28 | * Abstract base implementation of {@link FormatterService} for CSS formatters. 29 | * 30 | * @author bahlef 31 | */ 32 | public abstract class AbstractCssFormatterService implements FormatterService { 33 | /** 34 | * Returns the {@link FormatJob}. 35 | * 36 | * @param document the {@link StyledDocument} which should be formatted 37 | */ 38 | protected abstract FormatJob getFormatJob(StyledDocument document); 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public boolean format(StyledDocument document, SortedSet> changedElements) throws BadLocationException, FormattingFailedException { 45 | if (!canHandle(document)) { 46 | throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported"); 47 | } 48 | 49 | getFormatJob(document).format(); 50 | 51 | return true; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public List getSupportedMimeTypes() { 59 | return Collections.singletonList(MimeType.CSS); 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | @CheckForNull 67 | public Boolean organizeImports(StyledDocument document, boolean afterFixImports) throws BadLocationException { 68 | return null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/css/base/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for common CSS formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.css.base; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/css/cssparser/CssParserFormatJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.css.cssparser; 11 | 12 | import java.util.prefs.Preferences; 13 | 14 | import javax.swing.SwingUtilities; 15 | import javax.swing.text.BadLocationException; 16 | import javax.swing.text.StyledDocument; 17 | 18 | import org.openide.awt.NotificationDisplayer; 19 | import org.openide.awt.StatusDisplayer; 20 | 21 | import de.funfried.netbeans.plugins.external.formatter.AbstractFormatJob; 22 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 23 | import de.funfried.netbeans.plugins.external.formatter.ui.Icons; 24 | import de.funfried.netbeans.plugins.external.formatter.ui.options.Settings; 25 | 26 | /** 27 | * Google formatter implementation of the {@link AbstractFormatJob} to 28 | * format a given document using the {@link CssParserFormatterWrapper}. 29 | * 30 | * @author bahlef 31 | */ 32 | class CssParserFormatJob extends AbstractFormatJob { 33 | /** * The {@link CssParserFormatterWrapper} implementation. */ 34 | private final CssParserFormatterWrapper formatter; 35 | 36 | /** 37 | * Package private constructor to create a new instance of {@link CssParserFormatJob}. 38 | * 39 | * @param document the {@link StyledDocument} which sould be formatted 40 | * @param formatter the {@link CssParserFormatterWrapper} to use 41 | */ 42 | CssParserFormatJob(StyledDocument document, CssParserFormatterWrapper formatter) { 43 | super(document, null); 44 | 45 | this.formatter = formatter; 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | @Override 52 | public void format() throws BadLocationException { 53 | Preferences pref = Settings.getActivePreferences(document); 54 | 55 | int indentPref = pref.getInt(CssParserFormatterSettings.INDENT, CssParserFormatterSettings.INDENT_DEFAULT); 56 | boolean rgbAsHexPref = pref.getBoolean(CssParserFormatterSettings.RGB_AS_HEX, CssParserFormatterSettings.RGB_AS_HEX_DEFAULT); 57 | boolean useSingleQuotesPref = pref.getBoolean(CssParserFormatterSettings.USE_SINGLE_QUOTES, CssParserFormatterSettings.USE_SINGLE_QUOTES_DEFAULT); 58 | boolean useSourceStringValuesPref = pref.getBoolean(CssParserFormatterSettings.USE_SOURCE_STRING_VALUES, CssParserFormatterSettings.USE_SOURCE_STRING_VALUES_DEFAULT); 59 | 60 | String code = getCode(); 61 | 62 | try { 63 | String formattedContent = formatter.format(code, indentPref, rgbAsHexPref, useSingleQuotesPref, useSourceStringValuesPref); 64 | 65 | if (setFormattedCode(code, formattedContent)) { 66 | SwingUtilities.invokeLater(() -> { 67 | if (pref.getBoolean(Settings.SHOW_NOTIFICATIONS, false)) { 68 | NotificationDisplayer.getDefault().notify("Format using CssParser", Icons.ICON_EXTERNAL, "", null); 69 | } 70 | 71 | StatusDisplayer.getDefault().setStatusText("Format using CssParser"); 72 | }); 73 | } 74 | } catch (FormattingFailedException ex) { 75 | SwingUtilities.invokeLater(() -> { 76 | StatusDisplayer.getDefault().setStatusText("Failed to format using CssParser: " + ex.getMessage()); 77 | }); 78 | 79 | throw ex; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/css/cssparser/CssParserFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.css.cssparser; 11 | 12 | /** 13 | * Utility class for CssParser formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class CssParserFormatterSettings { 18 | /** 19 | * 4 by default. 20 | * 21 | * @since 1.15.3 22 | */ 23 | public static final String INDENT = "cssParserIndent"; 24 | 25 | /** 26 | * Default value for {@link #INDENT}: 4. 27 | * 28 | * @since 1.15.3 29 | */ 30 | public static final int INDENT_DEFAULT = 4; 31 | 32 | /** 33 | * {@code true} by default. 34 | * 35 | * @since 1.15.3 36 | */ 37 | public static final String RGB_AS_HEX = "cssParserRgbAsHex"; 38 | 39 | /** 40 | * Default value for {@link #RGB_AS_HEX}: {@code true}. 41 | * 42 | * @since 1.15.3 43 | */ 44 | public static final boolean RGB_AS_HEX_DEFAULT = true; 45 | 46 | /** 47 | * {@code false} by default. 48 | * 49 | * @since 1.15.3 50 | */ 51 | public static final String USE_SINGLE_QUOTES = "cssParserUseSingleQuotes"; 52 | 53 | /** 54 | * Default value for {@link #USE_SINGLE_QUOTES}: {@code false}. 55 | * 56 | * @since 1.15.3 57 | */ 58 | public static final boolean USE_SINGLE_QUOTES_DEFAULT = false; 59 | 60 | /** 61 | * {@code false} by default. 62 | * 63 | * @since 1.15.3 64 | */ 65 | public static final String USE_SOURCE_STRING_VALUES = "cssParserUseSourceStringValues"; 66 | 67 | /** 68 | * Default value for {@link #USE_SOURCE_STRING_VALUES}: {@code false}. 69 | * 70 | * @since 1.15.3 71 | */ 72 | public static final boolean USE_SOURCE_STRING_VALUES_DEFAULT = false; 73 | 74 | /** 75 | * Private contructor because of static methods only. 76 | */ 77 | private CssParserFormatterSettings() { 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/css/cssparser/CssParserFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.css.cssparser; 11 | 12 | import java.io.IOException; 13 | import java.io.StringReader; 14 | 15 | import org.netbeans.api.annotations.common.CheckForNull; 16 | import org.w3c.css.sac.InputSource; 17 | 18 | import com.steadystate.css.dom.CSSStyleSheetImpl; 19 | import com.steadystate.css.format.CSSFormat; 20 | import com.steadystate.css.parser.CSSOMParser; 21 | import com.steadystate.css.parser.SACParserCSS3; 22 | 23 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 24 | 25 | /** 26 | * Delegation class to the CssParser formatter implementation. 27 | * 28 | * @author bahlef 29 | */ 30 | public final class CssParserFormatterWrapper { 31 | /** 32 | * Package private Constructor for creating a new instance of {@link CssParserFormatterWrapper}. 33 | */ 34 | CssParserFormatterWrapper() { 35 | } 36 | 37 | /** 38 | * Formats the given {@code code} with the given configurations and returns 39 | * the formatted code. 40 | * 41 | * @param code the unformatted code 42 | * @param indent the indent to use 43 | * @param rgbAsHex {@code true} to prefer hex over rgb, otherwise {@code false} 44 | * @param useSingleQuotes {@code true} to prefer single quotes over double quotes, otherwise {@code false} 45 | * @param useSourceStringValues {@code true} to use source string values, otherwise {@code false} 46 | * 47 | * @return the formatted code 48 | * 49 | * @throws FormattingFailedException if the external formatter failed to format the given code 50 | */ 51 | @CheckForNull 52 | public String format(String code, int indent, boolean rgbAsHex, boolean useSingleQuotes, boolean useSourceStringValues) throws FormattingFailedException { 53 | if (code == null) { 54 | return null; 55 | } 56 | 57 | CSSFormat formatter = new CSSFormat() 58 | .setPropertiesInSeparateLines(indent) 59 | .setRgbAsHex(rgbAsHex) 60 | .setUseSingleQuotes(useSingleQuotes) 61 | .setUseSourceStringValues(useSourceStringValues); 62 | 63 | try (StringReader reader = new StringReader(code)) { 64 | InputSource source = new InputSource(reader); 65 | CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); 66 | CSSStyleSheetImpl sheet = (CSSStyleSheetImpl) parser.parseStyleSheet(source, null, null); 67 | 68 | String formattedCode = sheet.getCssText(formatter); 69 | 70 | // Patch converted 'tab' back to '\9' for IE 7,8, and 9 hack. Cssparser switches it to 'tab'. 71 | return formattedCode.replace("\t;", "\\9;"); 72 | } catch (IOException ex) { 73 | throw new FormattingFailedException(ex); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/css/cssparser/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for CSSParser CSS formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.css.cssparser; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/css/cssparser/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for CssParser CSS formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.css.cssparser.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/eclipse/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing common classes for all kinds of Eclipse formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.eclipse; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/eclipse/xml/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Eclipse formatter XML configuration parsing. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.eclipse.xml; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/exceptions/CannotLoadConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * markiewb - initial API and implementation and/or initial documentation 9 | * bahlef 10 | */ 11 | package de.funfried.netbeans.plugins.external.formatter.exceptions; 12 | 13 | /** 14 | * {@link RuntimeException} which is thrown when a configuration file could not be 15 | * parsed or even loaded. 16 | * 17 | * @author bahlef 18 | */ 19 | public class CannotLoadConfigurationException extends RuntimeException { 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * Creates a new instance of {@link CannotLoadConfigurationException}. 24 | * 25 | * @param message the detail message 26 | */ 27 | public CannotLoadConfigurationException(String message) { 28 | super(message); 29 | } 30 | 31 | /** 32 | * Creates a new instance of {@link CannotLoadConfigurationException}. 33 | * 34 | * @param cause the original cause of the exceptio 35 | */ 36 | public CannotLoadConfigurationException(Throwable cause) { 37 | super(cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/exceptions/ConfigReadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * Matt Blanchette - initial API and implementation 9 | * bahlef - initial documentation 10 | */ 11 | package de.funfried.netbeans.plugins.external.formatter.exceptions; 12 | 13 | /** 14 | * An exception thrown when there is an error reading settings from the code 15 | * formatter profile of an Eclipse formatter config file. 16 | * 17 | * @author Matt Blanchette 18 | * @author bahlef 19 | */ 20 | public class ConfigReadException extends RuntimeException { 21 | private static final long serialVersionUID = 1L; 22 | 23 | /** 24 | * Creates a new instance of the {@link ConfigReadException}. 25 | * 26 | * @param message the message 27 | */ 28 | public ConfigReadException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/exceptions/FormattingFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.exceptions; 11 | 12 | /** 13 | * {@link RuntimeException} which is thrown when an external formatter 14 | * failed to format a given code. 15 | * 16 | * @author bahlef 17 | */ 18 | public class FormattingFailedException extends RuntimeException { 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * Creates a new instance of {@link FormattingFailedException}. 23 | * 24 | * @param message the detail message 25 | */ 26 | public FormattingFailedException(String message) { 27 | super(message); 28 | } 29 | 30 | /** 31 | * Creates a new instance of {@link FormattingFailedException}. 32 | * 33 | * @param cause the original cause of the exception 34 | */ 35 | public FormattingFailedException(Throwable cause) { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/exceptions/ProfileNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.exceptions; 11 | 12 | /** 13 | * {@link RuntimeException} which is thrown when a given profile name could not be 14 | * found in a formatter configuration. 15 | * 16 | * @author bahlef 17 | */ 18 | public class ProfileNotFoundException extends RuntimeException { 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * Creates a new instance of {@link ProfileNotFoundException}. 23 | * 24 | * @param message the detail message 25 | */ 26 | public ProfileNotFoundException(String message) { 27 | super(message); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/exceptions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Exceptions package for External Code Formatters. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.exceptions; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/html/base/AbstractHtmlFormatterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.html.base; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.apache.commons.lang3.tuple.Pair; 20 | import org.netbeans.api.annotations.common.CheckForNull; 21 | 22 | import de.funfried.netbeans.plugins.external.formatter.FormatJob; 23 | import de.funfried.netbeans.plugins.external.formatter.FormatterService; 24 | import de.funfried.netbeans.plugins.external.formatter.MimeType; 25 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 26 | 27 | /** 28 | * Abstract base implementation of {@link FormatterService} for HTML formatters. 29 | * 30 | * @author bahlef 31 | */ 32 | public abstract class AbstractHtmlFormatterService implements FormatterService { 33 | /** 34 | * Returns the {@link FormatJob}. 35 | * 36 | * @param document the {@link StyledDocument} which should be formatted 37 | */ 38 | protected abstract FormatJob getFormatJob(StyledDocument document); 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public boolean format(StyledDocument document, SortedSet> changedElements) throws BadLocationException, FormattingFailedException { 45 | if (!canHandle(document)) { 46 | throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported"); 47 | } 48 | 49 | getFormatJob(document).format(); 50 | 51 | return true; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public List getSupportedMimeTypes() { 59 | return Collections.singletonList(MimeType.HTML); 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | @CheckForNull 67 | public Boolean organizeImports(StyledDocument document, boolean afterFixImports) throws BadLocationException { 68 | return null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/html/base/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for common HTML formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.html.base; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/html/jsoup/JsoupHtmlFormatJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.html.jsoup; 11 | 12 | import java.nio.charset.Charset; 13 | import java.util.prefs.Preferences; 14 | 15 | import javax.swing.SwingUtilities; 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.jsoup.nodes.Document; 20 | import org.netbeans.api.queries.FileEncodingQuery; 21 | import org.netbeans.editor.BaseDocument; 22 | import org.netbeans.modules.editor.NbEditorUtilities; 23 | import org.openide.awt.NotificationDisplayer; 24 | import org.openide.awt.StatusDisplayer; 25 | import org.openide.filesystems.FileObject; 26 | 27 | import de.funfried.netbeans.plugins.external.formatter.AbstractFormatJob; 28 | import de.funfried.netbeans.plugins.external.formatter.ui.Icons; 29 | import de.funfried.netbeans.plugins.external.formatter.ui.options.Settings; 30 | 31 | /** 32 | * Jsoup formatter implementation of the {@link AbstractFormatJob} to 33 | * format a given document using the {@link JsoupHtmlFormatterWrapper}. 34 | * 35 | * @author bahlef 36 | */ 37 | class JsoupHtmlFormatJob extends AbstractFormatJob { 38 | /** * The {@link JsoupHtmlFormatterWrapper} implementation. */ 39 | private final JsoupHtmlFormatterWrapper formatter; 40 | 41 | /** 42 | * Package private constructor to create a new instance of {@link JsoupFormatJob}. 43 | * 44 | * @param document the {@link StyledDocument} which sould be formatted 45 | * @param formatter the {@link JsoupHtmlFormatterWrapper} to use 46 | */ 47 | JsoupHtmlFormatJob(StyledDocument document, JsoupHtmlFormatterWrapper formatter) { 48 | super(document, null); 49 | 50 | this.formatter = formatter; 51 | } 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | @Override 57 | public void format() throws BadLocationException { 58 | Preferences pref = Settings.getActivePreferences(document); 59 | 60 | boolean prettyPrint = pref.getBoolean(JsoupHtmlFormatterSettings.PRETTY_PRINT, true); 61 | boolean outline = pref.getBoolean(JsoupHtmlFormatterSettings.OUTLINE, false); 62 | int indentSize = pref.getInt(JsoupHtmlFormatterSettings.INDENT_SIZE, 1); 63 | String lineFeedSetting = pref.get(JsoupHtmlFormatterSettings.LINEFEED, ""); 64 | 65 | Document.OutputSettings options = new Document.OutputSettings(); 66 | options.indentAmount(indentSize); 67 | options.outline(outline); 68 | options.prettyPrint(prettyPrint); 69 | 70 | FileObject fileObj = NbEditorUtilities.getFileObject(document); 71 | if (fileObj != null) { 72 | Charset charset = FileEncodingQuery.getEncoding(fileObj); 73 | if (charset != null) { 74 | options.charset(charset); 75 | } 76 | } 77 | 78 | //save with configured linefeed 79 | String lineFeed = Settings.getLineFeed(lineFeedSetting, System.getProperty("line.separator")); 80 | if (null != lineFeed) { 81 | document.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, lineFeed); 82 | document.putProperty(BaseDocument.WRITE_LINE_SEPARATOR_PROP, lineFeed); 83 | } 84 | 85 | String code = getCode(); 86 | 87 | String formattedContent = formatter.format(code, lineFeed, options); 88 | if (setFormattedCode(code, formattedContent)) { 89 | SwingUtilities.invokeLater(() -> { 90 | if (pref.getBoolean(Settings.SHOW_NOTIFICATIONS, false)) { 91 | NotificationDisplayer.getDefault().notify("Format using Jsoup HTML formatter", Icons.ICON_JSOUP, "", null); 92 | } 93 | 94 | StatusDisplayer.getDefault().setStatusText("Format using Jsoup HTML formatter"); 95 | }); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/html/jsoup/JsoupHtmlFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.html.jsoup; 11 | 12 | /** 13 | * Utility class for Jsoup HTML formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class JsoupHtmlFormatterSettings { 18 | /** 19 | * Property key which defines whether to use pretty print or not for the Jsoup HTML formatter. 20 | * 21 | * @since 1.15.3 22 | */ 23 | public static final String PRETTY_PRINT = "jsoupHtmlPrettyPrint"; 24 | 25 | /** 26 | * Property key which defines amount of spaces for indentation for the Jsoup HTML formatter. 27 | * 28 | * @since 1.15.3 29 | */ 30 | public static final String INDENT_SIZE = "jsoupHtmlIndentSize"; 31 | 32 | /** 33 | * Property key which defines whether to outline or not for the Jsoup HTML formatter. 34 | * 35 | * @since 1.15.3 36 | */ 37 | public static final String OUTLINE = "jsoupHtmlOutline"; 38 | 39 | /** 40 | * Property key which defines the line feed setting for the Jsoup HTML formatter. 41 | * 42 | * @since 1.15.3 43 | */ 44 | public static final String LINEFEED = "jsoupHtmlLinefeed"; 45 | 46 | /** 47 | * Private contructor because of static methods only. 48 | */ 49 | private JsoupHtmlFormatterSettings() { 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/html/jsoup/JsoupHtmlFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.html.jsoup; 11 | 12 | import java.util.Objects; 13 | 14 | import org.apache.commons.lang3.StringUtils; 15 | import org.jsoup.Jsoup; 16 | import org.jsoup.nodes.Document; 17 | import org.jsoup.nodes.Entities; 18 | import org.jsoup.parser.Parser; 19 | import org.netbeans.api.annotations.common.CheckForNull; 20 | import org.netbeans.api.annotations.common.NonNull; 21 | 22 | /** 23 | * Wrapper class to the Jsoup formatter implementation. 24 | * 25 | * @author bahlef 26 | */ 27 | public final class JsoupHtmlFormatterWrapper { 28 | /** Default system line separator. */ 29 | private static final String DEFAULT_LINE_SEPARATOR = "\n"; 30 | 31 | /** 32 | * Package private Constructor for creating a new instance of {@link JsoupHtmlFormatterWrapper}. 33 | */ 34 | JsoupHtmlFormatterWrapper() { 35 | } 36 | 37 | /** 38 | * Formats the given {@code code} with the given configurations and returns 39 | * the formatted code. 40 | * 41 | * @param code the unformatted code 42 | * @param lineFeed the line feed to use for formatting 43 | * @param options the {@link Document.OutputSettings} 44 | * 45 | * @return the formatted code 46 | */ 47 | @CheckForNull 48 | public String format(String code, String lineFeed, Document.OutputSettings options) { 49 | if (code == null) { 50 | return null; 51 | } 52 | 53 | if (lineFeed == null) { 54 | lineFeed = System.getProperty("line.separator"); 55 | } 56 | 57 | if (options == null) { 58 | options = new Document.OutputSettings(); 59 | } 60 | 61 | options.escapeMode(Entities.EscapeMode.xhtml); 62 | options.syntax(Document.OutputSettings.Syntax.html); 63 | 64 | return format(options, code, lineFeed); 65 | } 66 | 67 | /** 68 | * Formats the given {@code code} with the given configurations and returns 69 | * the formatted code. 70 | * 71 | * @param options the {@link Document.OutputSettings} 72 | * @param code the unformatted code 73 | * @param lineFeed the line feed to use for formatting 74 | * 75 | * @return the formatted code 76 | */ 77 | @CheckForNull 78 | private String format(Document.OutputSettings options, @NonNull String code, String lineFeed) { 79 | Document document = Jsoup.parse(code, "", Parser.htmlParser()); 80 | document.outputSettings(options); 81 | 82 | String formattedCode = document.outerHtml(); 83 | if (Objects.equals(code, formattedCode)) { 84 | return null; 85 | } else if (!DEFAULT_LINE_SEPARATOR.equals(lineFeed)) { 86 | formattedCode = StringUtils.replace(formattedCode, DEFAULT_LINE_SEPARATOR, lineFeed); 87 | } 88 | 89 | return formattedCode; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/html/jsoup/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Jsoup HTML formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.html.jsoup; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/html/jsoup/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Jsoup HTML formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.html.jsoup.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/base/AbstractJavaFormatterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.base; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.apache.commons.lang3.tuple.Pair; 20 | 21 | import de.funfried.netbeans.plugins.external.formatter.FormatJob; 22 | import de.funfried.netbeans.plugins.external.formatter.FormatterService; 23 | import de.funfried.netbeans.plugins.external.formatter.MimeType; 24 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 25 | 26 | /** 27 | * Abstract base implementation of {@link FormatterService} for Java formatters. 28 | * 29 | * @param the {@link FormatJob} type 30 | * 31 | * @author bahlef 32 | */ 33 | public abstract class AbstractJavaFormatterService implements FormatterService { 34 | /** 35 | * Returns the {@link F}. 36 | * 37 | * @param document the {@link StyledDocument} which should be formatted 38 | * @param changedElements a {@link SortedSet} containing ranges as {@link Pair} objects that should be formatted 39 | */ 40 | protected abstract F getFormatJob(StyledDocument document, SortedSet> changedElements); 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | @Override 46 | public boolean format(StyledDocument document, SortedSet> changedElements) throws BadLocationException, FormattingFailedException { 47 | if (!canHandle(document)) { 48 | throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported"); 49 | } 50 | 51 | getFormatJob(document, changedElements).format(); 52 | 53 | return true; 54 | } 55 | 56 | /** 57 | * {@inheritDoc} 58 | */ 59 | @Override 60 | public List getSupportedMimeTypes() { 61 | return Collections.singletonList(MimeType.JAVA); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/base/actions/JavaFixImportsAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 fbahle. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * fbahle - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | package de.funfried.netbeans.plugins.external.formatter.java.base.actions; 12 | 13 | import java.awt.event.ActionEvent; 14 | 15 | import javax.swing.text.Document; 16 | import javax.swing.text.JTextComponent; 17 | 18 | import org.netbeans.api.editor.EditorActionRegistration; 19 | import org.netbeans.editor.BaseAction; 20 | import org.netbeans.editor.ext.ExtKit; 21 | import org.openide.util.Lookup; 22 | import org.openide.util.NbBundle; 23 | import org.openide.util.lookup.Lookups; 24 | 25 | import de.funfried.netbeans.plugins.external.formatter.FormatterServiceDelegate; 26 | import de.funfried.netbeans.plugins.external.formatter.ui.editor.EditorUtils; 27 | 28 | /** 29 | * {@link BaseAction} for fixing imports which overrides the NetBeans original action. 30 | * 31 | * @author fbahle 32 | */ 33 | @EditorActionRegistration(name = "fix-imports", mimeType = "text/x-java", shortDescription = "#desc-fix-imports", popupText = "#popup-fix-imports") 34 | public class JavaFixImportsAction extends BaseAction { 35 | private static final long serialVersionUID = -3969332137881749109L; 36 | 37 | public JavaFixImportsAction() { 38 | super(BaseAction.ABBREV_RESET | BaseAction.MAGIC_POSITION_RESET | BaseAction.UNDO_MERGE_RESET); 39 | putValue(ExtKit.TRIMMED_TEXT, NbBundle.getMessage(JavaFixImportsAction.class, "fix-imports-trimmed")); 40 | putValue(BaseAction.SHORT_DESCRIPTION, NbBundle.getMessage(JavaFixImportsAction.class, "desc-fix-imports")); // NOI18N 41 | putValue(BaseAction.POPUP_MENU_TEXT, NbBundle.getMessage(JavaFixImportsAction.class, "popup-fix-imports")); // NOI18N 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | @Override 48 | public void actionPerformed(ActionEvent evt, JTextComponent target) { 49 | if (target != null) { 50 | Document document = target.getDocument(); 51 | Lookup lookup = Lookups.forPath("extFormatters/backupOrgActions/fixImports"); 52 | BaseAction action = lookup.lookup(BaseAction.class); 53 | action.actionPerformed(evt, target); 54 | 55 | FormatterServiceDelegate.getInstance().organizeImports(EditorUtils.toStyledDocument(document), true); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/base/actions/JavaOrganizeImportsAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 fbahle. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * fbahle - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | package de.funfried.netbeans.plugins.external.formatter.java.base.actions; 12 | 13 | import java.awt.event.ActionEvent; 14 | import java.util.prefs.Preferences; 15 | 16 | import javax.swing.SwingUtilities; 17 | import javax.swing.text.Document; 18 | import javax.swing.text.JTextComponent; 19 | 20 | import org.netbeans.api.editor.EditorActionNames; 21 | import org.netbeans.api.editor.EditorActionRegistration; 22 | import org.netbeans.editor.BaseAction; 23 | import org.openide.awt.NotificationDisplayer; 24 | import org.openide.awt.StatusDisplayer; 25 | import org.openide.util.Lookup; 26 | import org.openide.util.lookup.Lookups; 27 | 28 | import de.funfried.netbeans.plugins.external.formatter.FormatterServiceDelegate; 29 | import de.funfried.netbeans.plugins.external.formatter.ui.Icons; 30 | import de.funfried.netbeans.plugins.external.formatter.ui.editor.EditorUtils; 31 | import de.funfried.netbeans.plugins.external.formatter.ui.options.Settings; 32 | 33 | /** 34 | * {@link BaseAction} for organizing imports which overrides the NetBeans original action. 35 | * 36 | * @author fbahle 37 | */ 38 | @EditorActionRegistration(name = EditorActionNames.organizeImports, mimeType = "text/x-java", menuPath = "Source", menuPosition = 2430, menuText = "#" + EditorActionNames.organizeImports 39 | + "_menu_text") 40 | public class JavaOrganizeImportsAction extends BaseAction { 41 | private static final long serialVersionUID = 2459410245945401241L; 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public void actionPerformed(ActionEvent evt, JTextComponent target) { 48 | if (target != null) { 49 | Document document = target.getDocument(); 50 | Boolean ret = FormatterServiceDelegate.getInstance().organizeImports(EditorUtils.toStyledDocument(document), false); 51 | if (!Boolean.TRUE.equals(ret)) { 52 | Lookup lookup = Lookups.forPath("extFormatters/backupOrgActions/organizeImports"); 53 | BaseAction action = lookup.lookup(BaseAction.class); 54 | action.actionPerformed(evt, target); 55 | 56 | Preferences pref = Settings.getActivePreferences(document); 57 | 58 | SwingUtilities.invokeLater(() -> { 59 | if (pref.getBoolean(Settings.SHOW_NOTIFICATIONS, false)) { 60 | NotificationDisplayer.getDefault().notify("Organized imports using NetBeans internal logic", Icons.ICON_NETBEANS, "", null); 61 | } 62 | 63 | StatusDisplayer.getDefault().setStatusText("Organized imports using NetBeans internal logic"); 64 | }); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/base/actions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing global Java actions. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.base.actions; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/base/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for common Java formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.base; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/eclipse/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Eclipse Java formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.eclipse; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/eclipse/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Eclipse Java formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.eclipse.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/google/GoogleJavaFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.google; 11 | 12 | /** 13 | * Utility class for Google Java formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class GoogleJavaFormatterSettings { 18 | /** 19 | * Property key which defines which code style should be used for the Google formatter. 20 | * 21 | * @since 1.13 22 | */ 23 | public static final String CODE_STYLE = "googleFormatterCodeStyle"; 24 | 25 | /** 26 | * Property key which defines if the Google formatter internal organize imports action should be used. 27 | * 28 | * @since 1.15.2 29 | */ 30 | public static final String ORGANIZE_IMPORTS = "googleFormatterOrganizeImports"; 31 | 32 | /** 33 | * Property key which defines if the Google formatter internal organize imports action should be used after NetBeans fix import action was executed. 34 | * 35 | * @since 1.15.2 36 | */ 37 | public static final String ORGANIZE_IMPORTS_AFTER_FIX_IMPORTS = "googleFormatterOrganizeImportsAfterFixImports"; 38 | 39 | /** 40 | * Private contructor because of static methods only. 41 | */ 42 | private GoogleJavaFormatterSettings() { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/google/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Google formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.google; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/google/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Google formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.google.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/palantir/PalantirJavaFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.palantir; 11 | 12 | /** 13 | * Utility class for Palantir Java formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class PalantirJavaFormatterSettings { 18 | 19 | /** 20 | * Property key which defines if the Palantir formatter internal organize imports action should be used. 21 | * 22 | * @since 1.15.2 23 | */ 24 | public static final String ORGANIZE_IMPORTS = "palantirFormatterOrganizeImports"; 25 | 26 | /** 27 | * Property key which defines if the Palantir formatter internal organize imports action should be used after NetBeans fix import action was executed. 28 | * 29 | * @since 1.15.2 30 | */ 31 | public static final String ORGANIZE_IMPORTS_AFTER_FIX_IMPORTS = "palantirFormatterOrganizeImportsAfterFixImports"; 32 | 33 | /** 34 | * Private contructor because of static methods only. 35 | */ 36 | private PalantirJavaFormatterSettings() { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/palantir/PalantirJavaFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.palantir; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | import java.util.SortedSet; 15 | 16 | import org.apache.commons.collections4.CollectionUtils; 17 | import org.apache.commons.lang3.tuple.Pair; 18 | import org.netbeans.api.annotations.common.CheckForNull; 19 | 20 | import com.google.common.collect.Range; 21 | import com.palantir.javaformat.java.Formatter; 22 | import com.palantir.javaformat.java.FormatterException; 23 | import com.palantir.javaformat.java.ImportOrderer; 24 | import com.palantir.javaformat.java.JavaFormatterOptions; 25 | import com.palantir.javaformat.java.RemoveUnusedImports; 26 | 27 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 28 | 29 | /** 30 | * Delegation class to the Palantir formatter implementation. 31 | * 32 | * @author bahlef 33 | */ 34 | public final class PalantirJavaFormatterWrapper { 35 | /** 36 | * Package private Constructor for creating a new instance of {@link PalantirJavaFormatterWrapper}. 37 | */ 38 | PalantirJavaFormatterWrapper() { 39 | } 40 | 41 | /** 42 | * Formats the given {@code code} with the given configurations and returns 43 | * the formatted code. 44 | * 45 | * @param code the unformatted code 46 | * @param changedElements a {@link SortedSet} containing ranges as {@link Pair} 47 | * objects defining the offsets which should be formatted 48 | * 49 | * @return the formatted code 50 | * 51 | * @throws FormattingFailedException if the external formatter failed to format the given code 52 | */ 53 | @CheckForNull 54 | public String format(String code, SortedSet> changedElements) throws FormattingFailedException { 55 | if (code == null) { 56 | return null; 57 | } 58 | 59 | Collection> characterRanges = new ArrayList<>(); 60 | if (changedElements == null) { 61 | characterRanges.add(Range.closedOpen(0, code.length())); 62 | } else if (!CollectionUtils.isEmpty(changedElements)) { // empty changed elements means nothing's left which can be formatted due to guarded sections 63 | for (Pair changedElement : changedElements) { 64 | int start = changedElement.getLeft(); 65 | int end = changedElement.getRight(); 66 | 67 | if (start == end) { 68 | end++; 69 | } 70 | 71 | characterRanges.add(Range.open(start, end)); 72 | } 73 | } 74 | 75 | if (changedElements == null || !CollectionUtils.isEmpty(changedElements)) { 76 | try { 77 | Formatter formatter = Formatter.createFormatter(JavaFormatterOptions.builder().style(JavaFormatterOptions.Style.PALANTIR).build()); 78 | code = formatter.formatSource(code, characterRanges); 79 | } catch (FormatterException ex) { 80 | throw new FormattingFailedException(ex); 81 | } 82 | } 83 | 84 | return code; 85 | } 86 | 87 | @CheckForNull 88 | public String organizeImports(String code) throws FormattingFailedException { 89 | if (code == null) { 90 | return null; 91 | } 92 | 93 | try { 94 | code = RemoveUnusedImports.removeUnusedImports(code); 95 | } catch (FormatterException ex) { 96 | throw new FormattingFailedException(ex); 97 | } 98 | 99 | try { 100 | code = ImportOrderer.reorderImports(code, JavaFormatterOptions.Style.PALANTIR); 101 | } catch (FormatterException ex) { 102 | throw new FormattingFailedException(ex); 103 | } 104 | 105 | return code; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/palantir/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Palantir formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.palantir; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/palantir/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Palantir formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.palantir.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/spring/SpringFormatJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.spring; 11 | 12 | import java.util.SortedSet; 13 | import java.util.prefs.Preferences; 14 | 15 | import javax.swing.SwingUtilities; 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.apache.commons.lang3.tuple.Pair; 20 | import org.netbeans.editor.BaseDocument; 21 | import org.openide.awt.NotificationDisplayer; 22 | import org.openide.awt.StatusDisplayer; 23 | 24 | import de.funfried.netbeans.plugins.external.formatter.AbstractFormatJob; 25 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 26 | import de.funfried.netbeans.plugins.external.formatter.ui.Icons; 27 | import de.funfried.netbeans.plugins.external.formatter.ui.options.Settings; 28 | 29 | /** 30 | * Spring formatter implementation of the {@link AbstractFormatJob} to 31 | * format a given document using the {@link SpringJavaFormatterWrapper}. 32 | * 33 | * @author bahlef 34 | */ 35 | class SpringFormatJob extends AbstractFormatJob { 36 | /** The {@link SpringJavaFormatterWrapper} implementation. */ 37 | private final SpringJavaFormatterWrapper formatter; 38 | 39 | /** 40 | * Package private constructor to create a new instance of {@link SpringFormatJob}. 41 | * 42 | * @param document the {@link StyledDocument} which sould be formatted 43 | * @param formatter the {@link SpringJavaFormatterWrapper} to use 44 | * @param changedElements the ranges which should be formatted 45 | */ 46 | SpringFormatJob(StyledDocument document, SpringJavaFormatterWrapper formatter, SortedSet> changedElements) { 47 | super(document, changedElements); 48 | 49 | this.formatter = formatter; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public void format() throws BadLocationException { 57 | Preferences pref = Settings.getActivePreferences(document); 58 | 59 | String lineFeedSetting = pref.get(SpringJavaFormatterSettings.LINEFEED, ""); 60 | String lineFeed = Settings.getLineFeed(lineFeedSetting, System.getProperty("line.separator")); 61 | 62 | //save with configured linefeed 63 | if (null != lineFeed) { 64 | document.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, lineFeed); 65 | document.putProperty(BaseDocument.WRITE_LINE_SEPARATOR_PROP, lineFeed); 66 | } 67 | 68 | String code = getCode(); 69 | 70 | SortedSet> regions = getFormatableSections(code); 71 | 72 | try { 73 | String formattedContent = formatter.format(code, lineFeed, regions); 74 | if (setFormattedCode(code, formattedContent)) { 75 | SwingUtilities.invokeLater(() -> { 76 | if (pref.getBoolean(Settings.SHOW_NOTIFICATIONS, false)) { 77 | NotificationDisplayer.getDefault().notify("Format using Spring formatter", Icons.ICON_SPRING, "", null); 78 | } 79 | 80 | StatusDisplayer.getDefault().setStatusText("Format using Spring formatter"); 81 | }); 82 | } 83 | } catch (FormattingFailedException ex) { 84 | SwingUtilities.invokeLater(() -> { 85 | StatusDisplayer.getDefault().setStatusText("Failed to format using Spring formatter: " + ex.getMessage()); 86 | }); 87 | 88 | throw ex; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/spring/SpringJavaFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.spring; 11 | 12 | /** 13 | * Utility class for Spring Java formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class SpringJavaFormatterSettings { 18 | 19 | /** 20 | * Property key which defines the line feed setting for the Spring formatter. 21 | * 22 | * @since 1.14 23 | */ 24 | public static final String LINEFEED = "spring-linefeed"; 25 | 26 | /** 27 | * Private contructor because of static methods only. 28 | */ 29 | private SpringJavaFormatterSettings() { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/spring/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Spring formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.spring; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/java/spring/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Spring formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.spring.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/javascript/base/AbstractJavascriptFormatterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.javascript.base; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.apache.commons.lang3.tuple.Pair; 20 | 21 | import de.funfried.netbeans.plugins.external.formatter.FormatJob; 22 | import de.funfried.netbeans.plugins.external.formatter.FormatterService; 23 | import de.funfried.netbeans.plugins.external.formatter.MimeType; 24 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 25 | 26 | /** 27 | * Abstract base implementation of {@link FormatterService} for javascript formatters. 28 | * 29 | * @author bahlef 30 | */ 31 | public abstract class AbstractJavascriptFormatterService implements FormatterService { 32 | /** 33 | * Returns the {@link FormatJob}. 34 | * 35 | * @param document the {@link StyledDocument} which should be formatted 36 | * @param changedElement an optional range as a {@link Pair} object defining the offsets which should be formatted 37 | */ 38 | protected abstract FormatJob getFormatJob(StyledDocument document, Pair changedElement); 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public boolean format(StyledDocument document, SortedSet> changedElements) throws BadLocationException, FormattingFailedException { 45 | if (!canHandle(document)) { 46 | throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported"); 47 | } 48 | 49 | getFormatJob(document, changedElements != null ? changedElements.first() : null).format(); 50 | 51 | return true; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public List getSupportedMimeTypes() { 59 | return Collections.singletonList(MimeType.JAVASCRIPT); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/javascript/base/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for common javascript formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.javascript.base; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/javascript/eclipse/EclipseFormatterConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.javascript.eclipse; 11 | 12 | import java.util.Map; 13 | 14 | import org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants; 15 | 16 | import de.funfried.netbeans.plugins.external.formatter.eclipse.xml.EclipseFormatterUtils; 17 | import de.funfried.netbeans.plugins.external.formatter.exceptions.CannotLoadConfigurationException; 18 | import de.funfried.netbeans.plugins.external.formatter.exceptions.ConfigReadException; 19 | import de.funfried.netbeans.plugins.external.formatter.exceptions.ProfileNotFoundException; 20 | 21 | /** 22 | * Class used for parsing an Eclipse code formatter configuration. 23 | * 24 | * @author bahlef 25 | */ 26 | public final class EclipseFormatterConfig { 27 | /** Prefix for workspace mechanic files. */ 28 | private static final String WORKSPACE_MECHANIC_PREFIX = "/instance/org.eclipse.wst.jsdt.core/"; 29 | 30 | /** Default configuration of the Eclipse Javascript formatter. */ 31 | @SuppressWarnings("unchecked") 32 | private static final Map ECLIPSE_JAVASCRIPT_FORMATTER_DEFAULTS = DefaultCodeFormatterConstants.getJSLintConventionsSettings(); 33 | 34 | /** 35 | * Private constructor due to static methods only. 36 | */ 37 | private EclipseFormatterConfig() { 38 | } 39 | 40 | /** 41 | * Parses the configuration parameters from the given {@code profile} of the 42 | * given formatter configuration file and returns it as a {@link Map} 43 | * containing the configuration as key value pairs. 44 | * 45 | * @param formatterFile the path to the formatter configuration file 46 | * @param formatterProfile the name of the formatter configuration profile 47 | * 48 | * @return a {@link Map} containing the configuration as key value pairs 49 | * 50 | * @throws ConfigReadException if there is an issue parsing the formatter configuration 51 | * @throws ProfileNotFoundException if the given {@code profile} could not be found 52 | * @throws CannotLoadConfigurationException if there is any issue accessing or reading the formatter configuration 53 | */ 54 | public static Map parseConfig(String formatterFile, String formatterProfile) 55 | throws ProfileNotFoundException, ConfigReadException, CannotLoadConfigurationException { 56 | return EclipseFormatterUtils.parseConfig(formatterFile, formatterProfile, ECLIPSE_JAVASCRIPT_FORMATTER_DEFAULTS, null, WORKSPACE_MECHANIC_PREFIX, 57 | EclipseJavascriptFormatterSettings.PROJECT_PREF_FILE); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/javascript/eclipse/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Eclipse javascript formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.javascript.eclipse; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/javascript/eclipse/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Eclipse javascript formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.javascript.eclipse.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/json/base/AbstractJsonFormatterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.json.base; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.apache.commons.lang3.tuple.Pair; 20 | import org.netbeans.api.annotations.common.CheckForNull; 21 | 22 | import de.funfried.netbeans.plugins.external.formatter.FormatJob; 23 | import de.funfried.netbeans.plugins.external.formatter.FormatterService; 24 | import de.funfried.netbeans.plugins.external.formatter.MimeType; 25 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 26 | 27 | /** 28 | * Abstract base implementation of {@link FormatterService} for Json formatters. 29 | * 30 | * @author bahlef 31 | */ 32 | public abstract class AbstractJsonFormatterService implements FormatterService { 33 | /** 34 | * Returns the {@link FormatJob}. 35 | * 36 | * @param document the {@link StyledDocument} which should be formatted 37 | */ 38 | protected abstract FormatJob getFormatJob(StyledDocument document); 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public boolean format(StyledDocument document, SortedSet> changedElements) throws BadLocationException, FormattingFailedException { 45 | if (!canHandle(document)) { 46 | throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported"); 47 | } 48 | 49 | getFormatJob(document).format(); 50 | 51 | return true; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public List getSupportedMimeTypes() { 59 | return Collections.singletonList(MimeType.JSON); 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | @CheckForNull 67 | public Boolean organizeImports(StyledDocument document, boolean afterFixImports) throws BadLocationException { 68 | return null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/json/base/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for common Json formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.json.base; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/json/jackson/JacksonJsonFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.json.jackson; 11 | 12 | /** 13 | * Utility class for Jackson Json formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class JacksonJsonFormatterSettings { 18 | /** 19 | * Property key which defines to use tabs or spaces for the Jackson Json formatter. 20 | * 21 | * @since 1.14 22 | */ 23 | public static final String EXPAND_TABS_TO_SPACES = "jacksonJsonExpandTabsToSpaces"; 24 | 25 | /** 26 | * Property key which defines amount of spaces per tabs for the Jackson Json formatter. 27 | * 28 | * @since 1.14 29 | */ 30 | public static final String SPACES_PER_TAB = "jacksonJsonSpacesPerTab"; 31 | 32 | /** 33 | * Property key which defines the amount of spaces for indentation for the Jackson Json formatter. 34 | * 35 | * @since 1.14 36 | */ 37 | public static final String INDENT_SIZE = "jacksonJsonIndentSize"; 38 | 39 | /** 40 | * Property key which defines whether or not adding a spaces between the key and value separator for the Jackson Json formatter. 41 | * 42 | * @since 1.14 43 | */ 44 | public static final String SPACE_BEFORE_SEPARATOR = "jacksonJsonSpaceBeforeSeparator"; 45 | 46 | /** 47 | * Property key which defines the line feed setting for the Jackson Json formatter. 48 | * 49 | * @since 1.14 50 | */ 51 | public static final String LINEFEED = "jacksonJsonLinefeed"; 52 | 53 | /** 54 | * Private contructor because of static methods only. 55 | */ 56 | private JacksonJsonFormatterSettings() { 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/json/jackson/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Jackson Json formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.json.jackson; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/json/jackson/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Jackson Json formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.json.jackson.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for common formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/DBeaverFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver; 11 | 12 | /** 13 | * Utility class for DBeaver SQL formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class DBeaverFormatterSettings { 18 | /** 19 | * UPPER, LOWER or ORIGINAL. 20 | */ 21 | public static final String KEYWORD_CASE = "sql.formatter.keyword.case"; 22 | 23 | /** 24 | * Default value for {@link #KEYWORD_CASE}: UPPER. 25 | */ 26 | public static final String KEYWORD_CASE_DEFAULT = "UPPER"; 27 | 28 | /** 29 | * ';' by default. 30 | */ 31 | public static final String STATEMENT_DELIMITER = "sql.formatter.statement.delimiter"; 32 | 33 | /** 34 | * Default value for {@link #STATEMENT_DELIMITER}: ;. 35 | */ 36 | public static final String STATEMENT_DELIMITER_DEFAULT = ";"; 37 | 38 | /** 39 | * space or tab. 40 | */ 41 | public static final String INDENT_TYPE = "sql.formatter.indent.type"; 42 | 43 | /** 44 | * Default value for {@link #INDENT_TYPE}: space. 45 | */ 46 | public static final String INDENT_TYPE_DEFAULT = "space"; 47 | 48 | /** 49 | * 4 by default. 50 | */ 51 | public static final String INDENT_SIZE = "sql.formatter.indent.size"; 52 | 53 | /** 54 | * Default value for {@link #INDENT_SIZE}: 4. 55 | */ 56 | public static final int INDENT_SIZE_DEFAULT = 4; 57 | 58 | /** 59 | * Private contructor because of static methods only. 60 | */ 61 | private DBeaverFormatterSettings() { 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/DBeaverFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver; 11 | 12 | import java.util.Properties; 13 | 14 | import org.netbeans.api.annotations.common.CheckForNull; 15 | 16 | import com.diffplug.spotless.sql.dbeaver.DBeaverSQLFormatterConfiguration; 17 | import com.diffplug.spotless.sql.dbeaver.SQLTokenizedFormatter; 18 | 19 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 20 | 21 | /** 22 | * Delegation class to the DBeaver SQL formatter implementation. 23 | * 24 | * @author bahlef 25 | */ 26 | public final class DBeaverFormatterWrapper { 27 | /** 28 | * Package private Constructor for creating a new instance of {@link DBeaverFormatterWrapper}. 29 | */ 30 | DBeaverFormatterWrapper() { 31 | } 32 | 33 | /** 34 | * Formats the given {@code code} with the given configurations and returns 35 | * the formatted code. 36 | * 37 | * @param code the unformatted SQL code 38 | * @param properties Formatting Options as {@link Properties} 39 | * 40 | * @return the formatted SQL code 41 | * 42 | * @throws FormattingFailedException if the external formatter failed to format the given code 43 | */ 44 | @CheckForNull 45 | public String format(String code, Properties properties) throws FormattingFailedException { 46 | if (code == null) { 47 | return null; 48 | } 49 | 50 | try { 51 | DBeaverSQLFormatterConfiguration configuration = new DBeaverSQLFormatterConfiguration(properties); 52 | SQLTokenizedFormatter sqlTokenizedFormatter = new SQLTokenizedFormatter(configuration); 53 | return sqlTokenizedFormatter.format(code); 54 | } catch (Exception ex) { 55 | throw new FormattingFailedException(ex); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for DBeaver SQL formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for DBeaver SQL formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/jsqlformatter/JSQLFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.jsqlformatter; 11 | 12 | import org.netbeans.api.annotations.common.CheckForNull; 13 | 14 | import com.manticore.jsqlformatter.JSQLFormatter; 15 | 16 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 17 | 18 | /** 19 | * Delegation class to the JSQLFormatter implementation. 20 | * 21 | * @author Andreas Reichel andreas@manticore-projects.com 22 | */ 23 | public final class JSQLFormatterWrapper { 24 | /** 25 | * Package private Constructor for creating a new instance of {@link JSQLFormatterWrapper}. 26 | */ 27 | JSQLFormatterWrapper() { 28 | } 29 | 30 | /** 31 | * Formats the given {@code code} with the given configurations and returns 32 | * the formatted code. 33 | * 34 | * @param code the unformatted SQL code 35 | * @param options an array of Formatting Options expressed as Key=Value pairs 36 | * 37 | * @return the formatted SQL code 38 | * 39 | * @throws FormattingFailedException if the external formatter failed to format the given code 40 | */ 41 | @CheckForNull 42 | public String format(String code, String... options) throws FormattingFailedException { 43 | if (code == null) { 44 | return null; 45 | } 46 | 47 | try { 48 | return JSQLFormatter.format(code, options); 49 | } catch (Exception ex) { 50 | throw new FormattingFailedException(ex); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/jsqlformatter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for JSQLFormatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.jsqlformatter; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/jsqlformatter/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for JSQLFormatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.jsqlformatter.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/SQLFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.sqlformatter; 11 | 12 | import com.github.vertical_blank.sqlformatter.languages.Dialect; 13 | 14 | /** 15 | * Utility class for Vertical Blank SQL formatter specific settings. 16 | * 17 | * @author bahlef 18 | */ 19 | public class SQLFormatterSettings { 20 | /** 21 | * Database to use. 22 | */ 23 | public static final String DIALECT = "sqlFormatterDialect"; 24 | 25 | /** 26 | * Default value for {@link #DIALECT}: {@link Dialect#StandardSql}. 27 | */ 28 | public static final String DIALECT_DEFAULT = Dialect.StandardSql.name(); 29 | 30 | /** 31 | * Convert query to uppercase, default is {@code false}. 32 | */ 33 | public static final String UPPERCASE = "sqlFormatterUppercase"; 34 | 35 | /** 36 | * Default value for {@link #UPPERCASE}: false. 37 | */ 38 | public static final boolean UPPERCASE_DEFAULT = false; 39 | 40 | /** 41 | * Expand tabs to spaces, default is {@code true}. 42 | */ 43 | public static final String EXPAND_TABS_TO_SPACES = "sqlFormatterExpandTabsToSpaces"; 44 | 45 | /** 46 | * Default value for {@link #EXPAND_TABS_TO_SPACES}: true. 47 | */ 48 | public static final boolean EXPAND_TABS_TO_SPACES_DEFAULT = true; 49 | 50 | /** 51 | * 2 by default. 52 | */ 53 | public static final String INDENT_SIZE = "sqlFormatterIndentSize"; 54 | 55 | /** 56 | * Default value for {@link #INDENT_SIZE}: 2. 57 | */ 58 | public static final int INDENT_SIZE_DEFAULT = 2; 59 | 60 | /** 61 | * 1 by default. 62 | */ 63 | public static final String LINES_BETWEEN_QUERIES = "sqlFormatterLinesBetweenQueries"; 64 | 65 | /** 66 | * Default value for {@link #LINES_BETWEEN_QUERIES}: 1. 67 | */ 68 | public static final int LINES_BETWEEN_QUERIES_DEFAULT = 1; 69 | 70 | /** 71 | * 50 by default. 72 | */ 73 | public static final String MAX_COLUMN_LENGTH = "sqlFormatterMaxColumnLength"; 74 | 75 | /** 76 | * Default value for {@link #MAX_COLUMN_LENGTH}: 50. 77 | */ 78 | public static final int MAX_COLUMN_LENGTH_DEFAULT = 50; 79 | 80 | /** 81 | * Private contructor because of static methods only. 82 | */ 83 | private SQLFormatterSettings() { 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/SQLFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.sqlformatter; 11 | 12 | import org.netbeans.api.annotations.common.CheckForNull; 13 | 14 | import com.github.vertical_blank.sqlformatter.SqlFormatter; 15 | import com.github.vertical_blank.sqlformatter.core.FormatConfig; 16 | import com.github.vertical_blank.sqlformatter.languages.Dialect; 17 | 18 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 19 | 20 | /** 21 | * Delegation class to the Vertical Blank SQL formatter implementation. 22 | * 23 | * @author bahlef 24 | */ 25 | public final class SQLFormatterWrapper { 26 | /** 27 | * Package private Constructor for creating a new instance of {@link SQLFormatterWrapper}. 28 | */ 29 | SQLFormatterWrapper() { 30 | } 31 | 32 | /** 33 | * Formats the given {@code code} with the given configurations and returns 34 | * the formatted code. 35 | * 36 | * @param code the unformatted SQL code 37 | * @param dialect the {@link Dialect} to use 38 | * @param formatConfig Formatting options as a {@link FormatConfig} object 39 | * 40 | * @return the formatted SQL code 41 | * 42 | * @throws FormattingFailedException if the external formatter failed to format the given code 43 | */ 44 | @CheckForNull 45 | public String format(String code, Dialect dialect, FormatConfig formatConfig) throws FormattingFailedException { 46 | if (code == null) { 47 | return null; 48 | } 49 | 50 | try { 51 | return SqlFormatter.of(dialect).format(code, formatConfig); 52 | } catch (Exception ex) { 53 | throw new FormattingFailedException(ex); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Vertical Blank SQL formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.sqlformatter; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Andreas Reichel andreas@manticore-projects.com 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Vertical Blank SQL formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.sqlformatter.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/customizer/VerifiableConfigPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * markiewb - initial API and implementation and/or initial documentation 9 | * bahlef 10 | */ 11 | package de.funfried.netbeans.plugins.external.formatter.ui.customizer; 12 | 13 | /** 14 | * Interface to define a verifiable configuration panel. 15 | * 16 | * @author markiewb 17 | */ 18 | public interface VerifiableConfigPanel { 19 | /** 20 | * Returns {@code true} if and only if the configuration is valid, otherwise 21 | * {@code false}. 22 | * 23 | * @return {@code true} if and only if the configuration is valid, otherwise 24 | * {@code false} 25 | */ 26 | boolean valid(); 27 | 28 | /** 29 | * Loads the configuration and sets the values to the UI components. 30 | */ 31 | void load(); 32 | 33 | /** 34 | * Stores the configuration from the current state of UI components. 35 | */ 36 | void store(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/customizer/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing project customization classes for External Code Formatters. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.ui.customizer; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/editor/EditorConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.ui.editor; 11 | 12 | /** 13 | * Copied from private NetBeans classes FmtOptions and SimpleValueNames. 14 | * 15 | * @author bahlef 16 | */ 17 | public interface EditorConstants { 18 | /** 19 | * Whether expand typed tabs to spaces. The number of spaces to substitute 20 | * per one typed tab is determined by SPACES_PER_TAB setting. 21 | * Values: java.lang.Boolean instances 22 | */ 23 | String EXPAND_TABS = "expand-tabs"; 24 | 25 | /** 26 | * Number of spaces to draw when the '\t' character 27 | * is found in the text. Better said when the drawing-engine 28 | * finds a '\t' character it computes the next multiple 29 | * of TAB_SIZE and continues drawing from that position. 30 | * Values: java.lang.Integer instances 31 | */ 32 | String TAB_SIZE = "tab-size"; 33 | 34 | /** 35 | * How many spaces substitute per one typed tab. This parameter has 36 | * effect only when EXPAND_TABS setting is set to true. 37 | * This parameter has no influence on how 38 | * the existing tabs are displayed. 39 | * Values: java.lang.Integer instances 40 | */ 41 | String SPACES_PER_TAB = "spaces-per-tab"; 42 | 43 | /** 44 | * Shift-width says how many spaces should the formatter use 45 | * to indent the more inner level of code. This setting is independent of TAB_SIZE 46 | * and SPACES_PER_TAB. 47 | * Values: java.lang.Integer instances 48 | */ 49 | String INDENT_SHIFT_WIDTH = "indent-shift-width"; 50 | 51 | /** 52 | * Continuation ident size says how many spaces should the formatter use 53 | * to indent after a new line of the more inner level of code. This setting 54 | * is independent of TAB_SIZE and SPACES_PER_TAB. 55 | * Values: java.lang.Integer instances 56 | */ 57 | String CONTINUATION_INDENT_SIZE = "continuationIndentSize"; 58 | 59 | /** 60 | * After how many characters the text limit line should be displayed. 61 | * Values: java.awt.Integer instances 62 | */ 63 | String TEXT_LIMIT_WIDTH = "text-limit-width"; 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/editor/EditorUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | package de.funfried.netbeans.plugins.external.formatter.ui.editor; 12 | 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | import java.util.TreeSet; 16 | 17 | import javax.swing.text.Document; 18 | import javax.swing.text.StyledDocument; 19 | 20 | import org.apache.commons.lang3.tuple.Pair; 21 | import org.netbeans.api.annotations.common.CheckForNull; 22 | import org.netbeans.api.annotations.common.NonNull; 23 | import org.netbeans.modules.editor.NbEditorUtilities; 24 | import org.netbeans.modules.editor.indent.spi.Context; 25 | import org.openide.loaders.DataObject; 26 | import org.openide.text.NbDocument; 27 | 28 | /** 29 | * 30 | * @author bahlef 31 | */ 32 | public class EditorUtils { 33 | /** 34 | * Private constructor due to static methods only. 35 | */ 36 | private EditorUtils() { 37 | } 38 | 39 | /** 40 | * Returns the {@link Context#indentRegions()} from the given {@link Context} as a 41 | * {@link SortedSet}. 42 | * 43 | * @param context the {@link Context} 44 | * 45 | * @return the {@link Context#indentRegions()} from the given {@link Context} as a 46 | * {@link SortedSet} 47 | */ 48 | @NonNull 49 | public static SortedSet> getChangedElements(Context context) { 50 | SortedSet> changedElements = new TreeSet<>(); 51 | 52 | if (context != null) { 53 | Document document = context.document(); 54 | if (document != null) { 55 | int documentLength = document.getLength(); 56 | 57 | List regions = context.indentRegions(); 58 | for (Context.Region region : regions) { 59 | int start = region.getStartOffset(); 60 | if (start < 0) { 61 | continue; 62 | } 63 | 64 | int end = region.getEndOffset(); 65 | if (end >= documentLength) { 66 | end = documentLength - 1; 67 | } 68 | 69 | changedElements.add(Pair.of(start, end)); 70 | } 71 | } 72 | } 73 | 74 | return changedElements; 75 | } 76 | 77 | /** 78 | * Returns the given {@link Document} as a {@link StyledDocument} or {@code null} if 79 | * the given {@link Document} isn't a {@link StyledDocument}. 80 | * 81 | * @param document the {@link Document} 82 | * 83 | * @return the given {@link Document} as a {@link StyledDocument} or {@code null} if 84 | * the given {@link Document} isn't a {@link StyledDocument} 85 | */ 86 | @CheckForNull 87 | public static StyledDocument toStyledDocument(Document document) { 88 | StyledDocument styledDocument = null; 89 | if (document != null) { 90 | if (document instanceof StyledDocument) { 91 | styledDocument = (StyledDocument) document; 92 | } else { 93 | DataObject dataObject = NbEditorUtilities.getDataObject(document); 94 | if (dataObject != null) { 95 | styledDocument = NbDocument.getDocument(dataObject); 96 | } 97 | } 98 | } 99 | 100 | return styledDocument; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/editor/TaskFactoryUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.ui.editor; 11 | 12 | import org.netbeans.api.annotations.common.NonNull; 13 | import org.netbeans.modules.editor.indent.spi.IndentTask; 14 | import org.netbeans.modules.editor.indent.spi.ReformatTask; 15 | import org.openide.util.Lookup; 16 | 17 | /** 18 | * Custom implementation of the {@link IndentTask.Factory} which delegates the indenting 19 | * tasks to the configured external formatter or to the internal NetBeans formatter. 20 | * 21 | * @author bahlef 22 | */ 23 | public class TaskFactoryUtils { 24 | /** 25 | * Returns the cached default implementation of {@link IndentTask.Factory} 26 | * for the given {@code mimePath}. 27 | * 28 | * @param mimePath the mime path for which to get the {@link IndentTask.Factory} 29 | * 30 | * @return the cached default implementation of {@link IndentTask.Factory} 31 | * for the given {@code mimePath} 32 | */ 33 | @NonNull 34 | public static IndentTask.Factory getDefaultIndentTaskForMimePath(String mimePath) { 35 | ExternalFormatterIndentTaskFactory indentTaskFactory = Lookup.getDefault().lookup(ExternalFormatterIndentTaskFactory.class); 36 | if (indentTaskFactory != null) { 37 | return indentTaskFactory.getDefaultForMimePath(mimePath); 38 | } 39 | 40 | throw new IllegalStateException("Could not find NetBeans default implementation of IndentTask for mime path '" + mimePath + "'"); 41 | } 42 | 43 | /** 44 | * Returns the cached default implementation of {@link ReformatTask.Factory} 45 | * for the given {@code mimePath}. 46 | * 47 | * @param mimePath the mime path for which to get the {@link ReformatTask.Factory} 48 | * 49 | * @return the cached default implementation of {@link ReformatTask.Factory} 50 | * for the given {@code mimePath} 51 | */ 52 | @NonNull 53 | public ReformatTask.Factory getDefaultReformatTaskForMimePath(String mimePath) { 54 | ExternalFormatterReformatTaskFactory reformatTaskFactory = Lookup.getDefault().lookup(ExternalFormatterReformatTaskFactory.class); 55 | if (reformatTaskFactory != null) { 56 | return reformatTaskFactory.getDefaultForMimePath(mimePath); 57 | } 58 | 59 | throw new IllegalStateException("Could not find NetBeans default implementation of IndentTask for mime path '" + mimePath + "'"); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/editor/diff/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing implementation for creating a diff between two string arrays. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.ui.editor.diff; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/editor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing editor customizations and extensions. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.ui.editor; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/options/AbstractFormatterOptionsPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | package de.funfried.netbeans.plugins.external.formatter.ui.options; 12 | 13 | import javax.swing.JPanel; 14 | import javax.swing.event.ChangeListener; 15 | 16 | import org.netbeans.api.project.Project; 17 | import org.openide.util.ChangeSupport; 18 | 19 | /** 20 | * Abstract base implementation of {@link FormatterOptionsPanel}. 21 | * 22 | * @author bahlef 23 | */ 24 | public abstract class AbstractFormatterOptionsPanel extends JPanel implements FormatterOptionsPanel { 25 | /** {@link ChangeSupport} to notify about changed preference components. */ 26 | protected final ChangeSupport changeSupport; 27 | 28 | /** The {@link Project} which this panel is used to change the settings for or {@code null} if this panel is used to change the global settings. */ 29 | protected final Project project; 30 | 31 | /** 32 | * Default constructor of {@link AbstractFormatterOptionsPanel}. 33 | * 34 | * @param project the {@link Project} if the panel is used to modify project 35 | * specific settings, otherwise {@code null} 36 | */ 37 | public AbstractFormatterOptionsPanel(Project project) { 38 | this.project = project; 39 | 40 | this.changeSupport = new ChangeSupport(this); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | @Override 47 | public JPanel getComponent() { 48 | return this; 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | @Override 55 | public void addChangeListener(ChangeListener listener) { 56 | changeSupport.addChangeListener(listener); 57 | } 58 | 59 | /** 60 | * Fires a change event to all registered {@link ChangeListener}s. 61 | */ 62 | protected void fireChangedListener() { 63 | changeSupport.fireChange(); 64 | } 65 | 66 | /** 67 | * {@inheritDoc} 68 | */ 69 | @Override 70 | public void removeChangeListener(ChangeListener listener) { 71 | changeSupport.removeChangeListener(listener); 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | */ 77 | @Override 78 | public boolean valid() { 79 | return true; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/options/ExternalFormatterPreferencesChangeSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.ui.options; 11 | 12 | import javax.swing.event.ChangeListener; 13 | 14 | import org.openide.util.ChangeSupport; 15 | import org.openide.util.lookup.ServiceProvider; 16 | 17 | /** 18 | * Holder of a {@link ChangeSupport} to fire and listen on property changes. 19 | * 20 | * @author bahlef 21 | */ 22 | @ServiceProvider(service = ExternalFormatterPreferencesChangeSupport.class) 23 | public class ExternalFormatterPreferencesChangeSupport { 24 | private final ChangeSupport cs; 25 | 26 | /** 27 | * Creates a new instance of the {@link ExternalFormatterPreferencesChangeSupport}. 28 | */ 29 | public ExternalFormatterPreferencesChangeSupport() { 30 | cs = new ChangeSupport(this); 31 | } 32 | 33 | /** 34 | * Registers a {@link ChangeListener} to this {@link ExternalFormatterPreferencesChangeSupport}. 35 | * 36 | * @param listener the {@link ChangeListener} to register 37 | */ 38 | public void addChangeListener(ChangeListener listener) { 39 | cs.addChangeListener(listener); 40 | } 41 | 42 | /** 43 | * Notifies about changes to all registered {@link ChangeListener}s. 44 | */ 45 | public void fireChange() { 46 | cs.fireChange(); 47 | } 48 | 49 | /** 50 | * Unregisters a {@link ChangeListener} from this {@link ExternalFormatterPreferencesChangeSupport}. 51 | * 52 | * @param listener the {@link ChangeListener} to unregister 53 | */ 54 | public void removeChangeListener(ChangeListener listener) { 55 | cs.removeChangeListener(listener); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/options/FormatterOptionsPanel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | package de.funfried.netbeans.plugins.external.formatter.ui.options; 12 | 13 | import java.util.prefs.Preferences; 14 | 15 | import javax.swing.JPanel; 16 | import javax.swing.event.ChangeListener; 17 | 18 | /** 19 | * 20 | * @author bahlef 21 | */ 22 | public interface FormatterOptionsPanel { 23 | /** 24 | * Returns the {@link JPanel} component for this {@link FormatterOptionsPanel}. 25 | * 26 | * @return the {@link JPanel} component for this {@link FormatterOptionsPanel} 27 | */ 28 | JPanel getComponent(); 29 | 30 | /** 31 | * Adds a {@link ChangeListener} to this {@link FormatterOptionsPanel} which 32 | * will be informed if a user makes changes to the shown components. 33 | * 34 | * @param listener the {@link ChangeListener} to add 35 | * 36 | * @see #removeChangeListener(javax.swing.event.ChangeListener) 37 | */ 38 | void addChangeListener(ChangeListener listener); 39 | 40 | /** 41 | * Loads the current settings from the given {@link Preferences} and sets those 42 | * to the components of this {@link FormatterOptionsPanel}. 43 | * 44 | * @param preferences the {@link Preferences} to load from 45 | */ 46 | void load(Preferences preferences); 47 | 48 | /** 49 | * Removes a {@link ChangeListener} from this {@link FormatterOptionsPanel}. 50 | * 51 | * @param listener the {@link ChangeListener} to remove 52 | * 53 | * @see #addChangeListener(javax.swing.event.ChangeListener) 54 | */ 55 | void removeChangeListener(ChangeListener listener); 56 | 57 | /** 58 | * Stores all the currently set values of all components to the given 59 | * {@link Preferences}. 60 | * 61 | * @param preferences the {@link Preferences} where to store to 62 | */ 63 | void store(Preferences preferences); 64 | 65 | /** 66 | * Returns {@code true} if the settings that are currently made are valid, 67 | * otherwise {@code false}. 68 | * 69 | * @return {@code true} if the settings that are currently made are valid, 70 | * otherwise {@code false} 71 | */ 72 | boolean valid(); 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/options/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for the External Formatter option panel. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.ui.options; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Main UI package for External Code Formatters. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/base/AbstractXmlFormatterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.xml.base; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.SortedSet; 15 | 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.apache.commons.lang3.tuple.Pair; 20 | import org.netbeans.api.annotations.common.CheckForNull; 21 | 22 | import de.funfried.netbeans.plugins.external.formatter.FormatJob; 23 | import de.funfried.netbeans.plugins.external.formatter.FormatterService; 24 | import de.funfried.netbeans.plugins.external.formatter.MimeType; 25 | import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException; 26 | 27 | /** 28 | * Abstract base implementation of {@link FormatterService} for XML formatters. 29 | * 30 | * @author bahlef 31 | */ 32 | public abstract class AbstractXmlFormatterService implements FormatterService { 33 | /** 34 | * Returns the {@link FormatJob}. 35 | * 36 | * @param document the {@link StyledDocument} which should be formatted 37 | */ 38 | protected abstract FormatJob getFormatJob(StyledDocument document); 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | @Override 44 | public boolean format(StyledDocument document, SortedSet> changedElements) throws BadLocationException, FormattingFailedException { 45 | if (!canHandle(document)) { 46 | throw new FormattingFailedException("The file type '" + MimeType.getMimeTypeAsString(document) + "' is not supported"); 47 | } 48 | 49 | getFormatJob(document).format(); 50 | 51 | return true; 52 | } 53 | 54 | /** 55 | * {@inheritDoc} 56 | */ 57 | @Override 58 | public List getSupportedMimeTypes() { 59 | return Collections.singletonList(MimeType.XML); 60 | } 61 | 62 | /** 63 | * {@inheritDoc} 64 | */ 65 | @Override 66 | @CheckForNull 67 | public Boolean organizeImports(StyledDocument document, boolean afterFixImports) throws BadLocationException { 68 | return null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/base/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for common XML formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.xml.base; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/jsoup/JsoupXmlFormatJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.xml.jsoup; 11 | 12 | import java.nio.charset.Charset; 13 | import java.util.prefs.Preferences; 14 | 15 | import javax.swing.SwingUtilities; 16 | import javax.swing.text.BadLocationException; 17 | import javax.swing.text.StyledDocument; 18 | 19 | import org.jsoup.nodes.Document; 20 | import org.netbeans.api.queries.FileEncodingQuery; 21 | import org.netbeans.editor.BaseDocument; 22 | import org.netbeans.modules.editor.NbEditorUtilities; 23 | import org.openide.awt.NotificationDisplayer; 24 | import org.openide.awt.StatusDisplayer; 25 | import org.openide.filesystems.FileObject; 26 | 27 | import de.funfried.netbeans.plugins.external.formatter.AbstractFormatJob; 28 | import de.funfried.netbeans.plugins.external.formatter.ui.Icons; 29 | import de.funfried.netbeans.plugins.external.formatter.ui.options.Settings; 30 | 31 | /** 32 | * Jsoup formatter implementation of the {@link AbstractFormatJob} to 33 | * format a given document using the {@link JsoupXmlFormatterWrapper}. 34 | * 35 | * @author bahlef 36 | */ 37 | class JsoupXmlFormatJob extends AbstractFormatJob { 38 | /** * The {@link JsoupXmlFormatterWrapper} implementation. */ 39 | private final JsoupXmlFormatterWrapper formatter; 40 | 41 | /** 42 | * Package private constructor to create a new instance of {@link JsoupFormatJob}. 43 | * 44 | * @param document the {@link StyledDocument} which sould be formatted 45 | * @param formatter the {@link JsoupXmlFormatterWrapper} to use 46 | */ 47 | JsoupXmlFormatJob(StyledDocument document, JsoupXmlFormatterWrapper formatter) { 48 | super(document, null); 49 | 50 | this.formatter = formatter; 51 | } 52 | 53 | /** 54 | * {@inheritDoc} 55 | */ 56 | @Override 57 | public void format() throws BadLocationException { 58 | Preferences pref = Settings.getActivePreferences(document); 59 | 60 | boolean prettyPrint = pref.getBoolean(JsoupXmlFormatterSettings.PRETTY_PRINT, true); 61 | boolean outline = pref.getBoolean(JsoupXmlFormatterSettings.OUTLINE, false); 62 | int indentSize = pref.getInt(JsoupXmlFormatterSettings.INDENT_SIZE, 1); 63 | String lineFeedSetting = pref.get(JsoupXmlFormatterSettings.LINEFEED, ""); 64 | 65 | Document.OutputSettings options = new Document.OutputSettings(); 66 | options.indentAmount(indentSize); 67 | options.outline(outline); 68 | options.prettyPrint(prettyPrint); 69 | 70 | FileObject fileObj = NbEditorUtilities.getFileObject(document); 71 | if (fileObj != null) { 72 | Charset charset = FileEncodingQuery.getEncoding(fileObj); 73 | if (charset != null) { 74 | options.charset(charset); 75 | } 76 | } 77 | 78 | //save with configured linefeed 79 | String lineFeed = Settings.getLineFeed(lineFeedSetting, System.getProperty("line.separator")); 80 | if (null != lineFeed) { 81 | document.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP, lineFeed); 82 | document.putProperty(BaseDocument.WRITE_LINE_SEPARATOR_PROP, lineFeed); 83 | } 84 | 85 | String code = getCode(); 86 | 87 | String formattedContent = formatter.format(code, lineFeed, options); 88 | if (setFormattedCode(code, formattedContent)) { 89 | SwingUtilities.invokeLater(() -> { 90 | if (pref.getBoolean(Settings.SHOW_NOTIFICATIONS, false)) { 91 | NotificationDisplayer.getDefault().notify("Format using Jsoup XML formatter", Icons.ICON_JSOUP, "", null); 92 | } 93 | 94 | StatusDisplayer.getDefault().setStatusText("Format using Jsoup XML formatter"); 95 | }); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/jsoup/JsoupXmlFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.xml.jsoup; 11 | 12 | /** 13 | * Utility class for Jsoup XML formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class JsoupXmlFormatterSettings { 18 | /** 19 | * Property key which defines whether to use pretty print or not for the Jsoup XML formatter. 20 | * 21 | * @since 1.14 22 | */ 23 | public static final String PRETTY_PRINT = "jsoupXmlPrettyPrint"; 24 | 25 | /** 26 | * Property key which defines amount of spaces for indentation for the Jsoup XML formatter. 27 | * 28 | * @since 1.14 29 | */ 30 | public static final String INDENT_SIZE = "jsoupXmlIndentSize"; 31 | 32 | /** 33 | * Property key which defines whether to outline or not for the Jsoup XML formatter. 34 | * 35 | * @since 1.14 36 | */ 37 | public static final String OUTLINE = "jsoupXmlOutline"; 38 | 39 | /** 40 | * Property key which defines the line feed setting for the Jsoup XML formatter. 41 | * 42 | * @since 1.14 43 | */ 44 | public static final String LINEFEED = "jsoupXmlLinefeed"; 45 | 46 | /** 47 | * Private contructor because of static methods only. 48 | */ 49 | private JsoupXmlFormatterSettings() { 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/jsoup/JsoupXmlFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.xml.jsoup; 11 | 12 | import java.util.Objects; 13 | 14 | import org.apache.commons.lang3.StringUtils; 15 | import org.jsoup.Jsoup; 16 | import org.jsoup.nodes.Document; 17 | import org.jsoup.nodes.Entities; 18 | import org.jsoup.parser.Parser; 19 | import org.netbeans.api.annotations.common.CheckForNull; 20 | import org.netbeans.api.annotations.common.NonNull; 21 | 22 | /** 23 | * Wrapper class to the Jsoup formatter implementation. 24 | * 25 | * @author bahlef 26 | */ 27 | public final class JsoupXmlFormatterWrapper { 28 | /** Default system line separator. */ 29 | private static final String DEFAULT_LINE_SEPARATOR = "\n"; 30 | 31 | /** 32 | * Package private Constructor for creating a new instance of {@link JsoupXmlFormatterWrapper}. 33 | */ 34 | JsoupXmlFormatterWrapper() { 35 | } 36 | 37 | /** 38 | * Formats the given {@code code} with the given configurations and returns 39 | * the formatted code. 40 | * 41 | * @param code the unformatted code 42 | * @param lineFeed the line feed to use for formatting 43 | * @param options the {@link Document.OutputSettings} 44 | * 45 | * @return the formatted code 46 | */ 47 | @CheckForNull 48 | public String format(String code, String lineFeed, Document.OutputSettings options) { 49 | if (code == null) { 50 | return null; 51 | } 52 | 53 | if (lineFeed == null) { 54 | lineFeed = System.getProperty("line.separator"); 55 | } 56 | 57 | if (options == null) { 58 | options = new Document.OutputSettings(); 59 | } 60 | 61 | options.escapeMode(Entities.EscapeMode.xhtml); 62 | options.syntax(Document.OutputSettings.Syntax.xml); 63 | 64 | return format(options, code, lineFeed); 65 | } 66 | 67 | /** 68 | * Formats the given {@code code} with the given configurations and returns 69 | * the formatted code. 70 | * 71 | * @param options the {@link Document.OutputSettings} 72 | * @param code the unformatted code 73 | * @param lineFeed the line feed to use for formatting 74 | * 75 | * @return the formatted code 76 | */ 77 | @CheckForNull 78 | private String format(Document.OutputSettings options, @NonNull String code, String lineFeed) { 79 | Document document = Jsoup.parse(code, "", Parser.xmlParser()); 80 | document.outputSettings(options); 81 | 82 | String formattedCode = document.outerHtml(); 83 | if (Objects.equals(code, formattedCode)) { 84 | return null; 85 | } else if (!DEFAULT_LINE_SEPARATOR.equals(lineFeed)) { 86 | formattedCode = StringUtils.replace(formattedCode, DEFAULT_LINE_SEPARATOR, lineFeed); 87 | } 88 | 89 | return formattedCode; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/jsoup/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Jsoup XML formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.xml.jsoup; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/jsoup/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for Jsoup XML formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.xml.jsoup.ui; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/revelc/RevelcXmlFormatterSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.xml.revelc; 11 | 12 | /** 13 | * Utility class for revelc.net XML formatter specific settings. 14 | * 15 | * @author bahlef 16 | */ 17 | public class RevelcXmlFormatterSettings { 18 | /** 19 | * Property key which defines the maximum line length for the revelc.net XML formatter. 20 | * 21 | * @since 1.14 22 | */ 23 | public static final String MAX_LINE_LENGTH = "revelcXmlMaxLineLength"; 24 | 25 | /** 26 | * Property key which defines the line feed setting for the revelc.net XML formatter. 27 | * 28 | * @since 1.14 29 | */ 30 | public static final String SPLIT_MULTI_ATTRIBUTES = "revelcXmlSplitMultiAttrs"; 31 | 32 | /** 33 | * Property key which defines to use tabs or spaces for the revelc.net XML formatter. 34 | * 35 | * @since 1.14 36 | */ 37 | public static final String TAB_INSTEAD_OF_SPACES = "revelcXmlTabInsteadOfSpaces"; 38 | 39 | /** 40 | * Property key which defines amount of tabs for the revelc.net XML formatter. 41 | * 42 | * @since 1.14 43 | */ 44 | public static final String TAB_WIDTH = "revelcXmlTabWidth"; 45 | 46 | /** 47 | * Property key which defines the handling of well formed validation for the revelc.net XML formatter. 48 | * 49 | * @since 1.14 50 | */ 51 | public static final String WELL_FORMED_VALIDATION = "revelcXmlWellFormedValidation"; 52 | 53 | /** 54 | * Property key which defines whether to wrap long lines or not for the revelc.net XML formatter. 55 | * 56 | * @since 1.14 57 | */ 58 | public static final String WRAP_LONG_LINES = "revelcXmlWrapLongLines"; 59 | 60 | /** 61 | * Property key which defines the line feed setting for the revelc.net XML formatter. 62 | * 63 | * @since 1.14 64 | */ 65 | public static final String LINEFEED = "revelcXmlLinefeed"; 66 | 67 | /** 68 | * Private contructor because of static methods only. 69 | */ 70 | private RevelcXmlFormatterSettings() { 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/revelc/RevelcXmlFormatterWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.xml.revelc; 11 | 12 | import java.util.Objects; 13 | 14 | import org.netbeans.api.annotations.common.CheckForNull; 15 | import org.netbeans.api.annotations.common.NonNull; 16 | 17 | import net.revelc.code.formatter.xml.lib.FormattingPreferences; 18 | import net.revelc.code.formatter.xml.lib.XmlDocumentFormatter; 19 | 20 | /** 21 | * Wrapper class to the revelc.net formatter implementation. 22 | * 23 | * @author bahlef 24 | */ 25 | public final class RevelcXmlFormatterWrapper { 26 | /** 27 | * Package private Constructor for creating a new instance of {@link RevelcXmlFormatterWrapper}. 28 | */ 29 | RevelcXmlFormatterWrapper() { 30 | } 31 | 32 | /** 33 | * Formats the given {@code code} with the given configurations and returns 34 | * the formatted code. 35 | * 36 | * @param code the unformatted code 37 | * @param lineFeed the line feed to use for formatting 38 | * @param prefs the {@link FormattingPreferences} 39 | * 40 | * @return the formatted code 41 | */ 42 | @CheckForNull 43 | public String format(String code, String lineFeed, FormattingPreferences prefs) { 44 | if (code == null) { 45 | return null; 46 | } 47 | 48 | if (lineFeed == null) { 49 | lineFeed = System.getProperty("line.separator"); 50 | } 51 | 52 | if (prefs == null) { 53 | prefs = new FormattingPreferences(); 54 | } 55 | 56 | XmlDocumentFormatter xmlFormatter = new XmlDocumentFormatter(lineFeed, prefs); 57 | 58 | return format(xmlFormatter, code); 59 | } 60 | 61 | /** 62 | * Formats the given {@code code} with the given configurations and returns 63 | * the formatted code. 64 | * 65 | * @param xmlFormatter the {@link XmlDocumentFormatter} 66 | * @param code the unformatted code 67 | * 68 | * @return the formatted code 69 | */ 70 | @CheckForNull 71 | private String format(XmlDocumentFormatter xmlFormatter, @NonNull String code) { 72 | String formattedCode = xmlFormatter.format(code); 73 | if (Objects.equals(code, formattedCode)) { 74 | return null; 75 | } 76 | 77 | return formattedCode; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/revelc/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for revelc.net XML formatter strategy logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.xml.revelc; 15 | -------------------------------------------------------------------------------- /src/main/java/de/funfried/netbeans/plugins/external/formatter/xml/revelc/ui/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Package containing classes for revelc.net XML formatter UI components. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.xml.revelc.ui; 15 | -------------------------------------------------------------------------------- /src/main/nbm/manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | OpenIDE-Module-Layer: de/funfried/netbeans/plugins/external/formatter/layer.xml 3 | OpenIDE-Module-Localizing-Bundle: de/funfried/netbeans/plugins/external/formatter/Bundle.properties 4 | OpenIDE-Module-Java-Dependencies: Java > 17 5 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/css/cssparser/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | CssParserFormatterOptionsPanel.rgbAsHexChkBox.text=RGB as HEX 10 | CssParserFormatterOptionsPanel.rgbAsHexChkBox.toolTipText=Select this checkbox to convert RGB color codes into HEX values 11 | CssParserFormatterOptionsPanel.useSingleQuotesChkBox.text=Use single quotes 12 | CssParserFormatterOptionsPanel.useSingleQuotesChkBox.toolTipText=Select this checkbox to use single quotes instead of double quotes 13 | CssParserFormatterOptionsPanel.useSourceStringValuesChkBox.text=Use source string values 14 | CssParserFormatterOptionsPanel.useSourceStringValuesChkBox.toolTipText=Select this checkbox to use source string values 15 | CssParserFormatterOptionsPanel.indentSizeLbl.text=Number of Spaces per Indent: 16 | CssParserFormatterOptionsPanel.indentSizeLbl.toolTipText=Enter here the number of spaces per indent 17 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/dbeaver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/dbeaver.png -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/eclipse-formatter-templates.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/eclipse.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/eclipse.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/external.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/external.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/google.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/google.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/html/jsoup/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/jackson.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/jackson.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/java/base/actions/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022 fbahle. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | # 7 | # Contributors: 8 | # fbahle - initial API and implementation and/or initial documentation 9 | # FixImports 10 | fix-imports=Fix Imports 11 | fix-imports-trimmed=Fix Imports 12 | desc-fix-imports=Fix Imports 13 | popup-fix-imports=Fix Imports 14 | fix-imports-main-menu-source-item=Fix Imp&orts... 15 | 16 | # OrganizeImports 17 | DN_org.netbeans.modules.java.hints.OrganizeImports=Organize imports 18 | DESC_org.netbeans.modules.java.hints.OrganizeImports=Checks whether import statements correspond to the specified code style rules 19 | MSG_OragnizeImports=Import section does not correspond to the specified code style rules 20 | FIX_OrganizeImports=Organize imports 21 | organize-imports=Organize Imports 22 | organize-imports_menu_text=Organize Imports 23 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/java/eclipse/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | # 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | 10 | EclipseJavaFormatterOptionsPanel.lblSourceLevel.text=Source level: 11 | EclipseJavaFormatterOptionsPanel.lblLinefeed.toolTipText=Select the line feed character(s) to use for formatting 12 | EclipseJavaFormatterOptionsPanel.lblLinefeed.text=Linefeed: 13 | EclipseJavaFormatterOptionsPanel.cbUseProjectPref.toolTipText=If activated and if a ${projectdir}/.settings/org.eclipse.jdt.core.prefs file is available, use this instead of the configured file 14 | EclipseJavaFormatterOptionsPanel.cbUseProjectPref.text=Use ${projectdir}/.settings/org.eclipse.jdt.core.prefs, when available 15 | EclipseJavaFormatterOptionsPanel.lblProfile.text=Profile: 16 | EclipseJavaFormatterOptionsPanel.jLabel2.text=Supported formats:
  • exportedProfiles.xml
  • workspacemechanic.epf
  • org.eclipse.jdt.core.prefs
  • 17 | EclipseJavaFormatterOptionsPanel.errorLabel.text= 18 | EclipseJavaFormatterOptionsPanel.browseButton.toolTipText=Browse for a Eclipse code formatter configuration 19 | EclipseJavaFormatterOptionsPanel.browseButton.toolTipText.projectSpecific=Browse for a Eclipse code formatter configuration or enter the relative path to a configuration file 20 | EclipseJavaFormatterOptionsPanel.browseButton.text=Browse... 21 | EclipseJavaFormatterOptionsPanel.formatterLocField.text= 22 | EclipseJavaFormatterOptionsPanel.lblFormatterFile.toolTipText=Browse for a Eclipse code formatter configuration 23 | EclipseJavaFormatterOptionsPanel.lblFormatterFile.toolTipText.projectSpecific=Browse for a Eclipse code formatter configuration or enter the relative path to a configuration file 24 | EclipseJavaFormatterOptionsPanel.lblFormatterFile.text=Configuration file: 25 | EclipseJavaFormatterOptionsPanel.chooseProfile=--Choose profile-- 26 | EclipseJavaFormatterOptionsPanel.formatterLocField.toolTipText.projectSpecific=Browse for a Eclipse code formatter configuration or enter the relative path to a configuration file 27 | EclipseJavaFormatterOptionsPanel.lblProfile.toolTipText=Select an Eclipse code formatter profile 28 | EclipseJavaFormatterOptionsPanel.lblSourceLevel.toolTipText=Select the source level to use for formatting 29 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/java/google/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | # 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | 10 | GoogleJavaFormatterOptionsPanel.googleCodeStyleRdBtn.text=Google 11 | GoogleJavaFormatterOptionsPanel.googleCodeStyleLbl.text=Code Style: 12 | GoogleJavaFormatterOptionsPanel.aospRdBtn.text=Android Open Source Project (AOSP) 13 | GoogleJavaFormatterOptionsPanel.googleCodeStyleRdBtn.toolTipText=Google 14 | GoogleJavaFormatterOptionsPanel.aospRdBtn.toolTipText=Android Open Source Project (AOSP) 15 | GoogleJavaFormatterOptionsPanel.googleCodeStyleLbl.toolTipText=Select the code style to use. 16 | GoogleJavaFormatterOptionsPanel.organizeImportsAfterFixImportsChkBox.text=Organize imports after imports were fixed 17 | GoogleJavaFormatterOptionsPanel.organizeImportsChkBox.text=Let the Google Formatter organize imports 18 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/java/palantir/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | PalantirJavaFormatterOptionsPanel.organizeImportsChkBox.text=Let the Palantir Formatter organize imports 2 | # Copyright (c) 2020 bahlef. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the Eclipse Public License v2.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.eclipse.org/legal/epl-v20.html 7 | 8 | # Contributors: 9 | # bahlef - initial API and implementation and/or initial documentation 10 | PalantirJavaFormatterOptionsPanel.organizeImportsAfterFixImportsChkBox.text=Organize imports after imports were fixed 11 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/java/spring/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | SpringJavaFormatterOptionsPanel.lblSpringLinefeed.toolTipText=Select the line feed character(s) to use for formatting 2 | SpringJavaFormatterOptionsPanel.lblSpringLinefeed.text=Linefeed: 3 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/javascript/eclipse/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | # 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | 10 | EclipseJavascriptFormatterOptionsPanel.lblLinefeed.text=Linefeed: 11 | EclipseJavascriptFormatterOptionsPanel.cbUseProjectPref.toolTipText=If activated and if a ${projectdir}/.settings/org.eclipse.jdt.core.prefs file is available, use this instead of the configured file 12 | EclipseJavascriptFormatterOptionsPanel.cbUseProjectPref.text=Use ${projectdir}/.settings/org.eclipse.jdt.core.prefs, when available 13 | EclipseJavascriptFormatterOptionsPanel.lblProfile.text=Profile: 14 | EclipseJavascriptFormatterOptionsPanel.jLabel2.text=Supported formats:
    • exportedProfiles.xml
    • workspacemechanic.epf
    • org.eclipse.wst.jsdt.core.prefs
    • 15 | EclipseJavascriptFormatterOptionsPanel.errorLabel.text= 16 | EclipseJavascriptFormatterOptionsPanel.browseButton.toolTipText=Browse for a Eclipse code formatter configuration 17 | EclipseJavascriptFormatterOptionsPanel.browseButton.toolTipText.projectSpecific=Browse for a Eclipse code formatter configuration or enter the relative path to a configuration file 18 | EclipseJavascriptFormatterOptionsPanel.browseButton.text=Browse... 19 | EclipseJavascriptFormatterOptionsPanel.formatterLocField.text= 20 | EclipseJavascriptFormatterOptionsPanel.lblFormatterFile.toolTipText=Browse for a Eclipse code formatter configuration 21 | EclipseJavascriptFormatterOptionsPanel.lblFormatterFile.toolTipText.projectSpecific=Browse for a Eclipse code formatter configuration or enter the relative path to a configuration file 22 | EclipseJavascriptFormatterOptionsPanel.lblFormatterFile.text=Configuration file: 23 | EclipseJavascriptFormatterOptionsPanel.lblLinefeed.toolTipText=Select the line feed character(s) to use for formatting 24 | EclipseJavascriptFormatterOptionsPanel.chooseProfile=--Choose profile-- 25 | EclipseJavascriptFormatterOptionsPanel.formatterLocField.toolTipText.projectSpecific=Browse for a Eclipse code formatter configuration or enter the relative path to a configuration file 26 | EclipseJavascriptFormatterOptionsPanel.lblProfile.toolTipText=Select an Eclipse code formatter profile 27 | EclipseJavascriptFormatterOptionsPanel.cbOrganizeImports.text=Organize imports while formatting 28 | EclipseJavascriptFormatterOptionsPanel.netbeansOnSaveActionsWarnLbl.text=Note: This will skip the NetBeans internal "On Save" actions for remove unused imports and organize imports 29 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/json/jackson/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | 10 | JacksonJsonFormatterOptionsPanel.linefeedLbl.text=Linefeed: 11 | JacksonJsonFormatterOptionsPanel.expandTabsToSpacesChkBox.text=Expand Tabs to Spaces 12 | JacksonJsonFormatterOptionsPanel.linefeedCmbBox.toolTipText=Select the line feed character(s) to use for formatting 13 | JacksonJsonFormatterOptionsPanel.indentSizeLbl.text=Number of Spaces per Indent: 14 | JacksonJsonFormatterOptionsPanel.spacesPerTabLbl.text=Tab Size: 15 | JacksonJsonFormatterOptionsPanel.spacesPerTabSpn.toolTipText= 16 | JacksonJsonFormatterOptionsPanel.spacesBeforeSeparatorChkBox.text=Space before separator 17 | JacksonJsonFormatterOptionsPanel.linefeedLbl.toolTipText= 18 | JacksonJsonFormatterOptionsPanel.expandTabsToSpacesChkBox.toolTipText=Select this checkbox to expand tabs to spaces 19 | JacksonJsonFormatterOptionsPanel.spacesBeforeSeparatorChkBox.toolTipText=Select this checkbox to add a space before a separator 20 | JacksonJsonFormatterOptionsPanel.indentSizeLbl.toolTipText=Enter here the number of spaces per indent 21 | JacksonJsonFormatterOptionsPanel.spacesPerTabLbl.toolTipText=Enter here the width in spaces per tab 22 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/jsoup.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/jsoup.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/manticore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/manticore.png -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/netbeans.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/netbeans.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/revelc.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/revelc.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/spring.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/spring.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | 10 | DBeaverFormatterOptionsPanel.keywordsLbl.text=Keywords: 11 | DBeaverFormatterOptionsPanel.spellingLbl.text=Spelling 12 | DBeaverFormatterOptionsPanel.dialectLbl.text=Dialect 13 | DBeaverFormatterOptionsPanel.indentWidthLbl.text=Indent Width: 14 | DBeaverFormatterOptionsPanel.positioningLbl.text=Positioning 15 | DBeaverFormatterOptionsPanel.expandTabsToSpacesChkBox.text=Expand tabs to spaces 16 | DBeaverFormatterOptionsPanel.statementDelimiterLbl.text=Statement delimiter: 17 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/sql/jsqlformatter/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | # 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | 10 | JSQLFormatterOptionsPanel.outputLbl.text=Output 11 | JSQLFormatterOptionsPanel.formatLbl.text=Format: 12 | JSQLFormatterOptionsPanel.spellingLbl.text=Spelling 13 | JSQLFormatterOptionsPanel.keywordsLbl.text=Keywords: 14 | JSQLFormatterOptionsPanel.functionsLbl.text=Functions: 15 | JSQLFormatterOptionsPanel.objectsLbl.text=Objects: 16 | JSQLFormatterOptionsPanel.positioningLbl.text=Positioning 17 | JSQLFormatterOptionsPanel.indentWidthLbl.text=Indent Width: 18 | JSQLFormatterOptionsPanel.separationLbl.text=Separation: 19 | JSQLFormatterOptionsPanel.separationBeforeRdBtn.text=Before 20 | JSQLFormatterOptionsPanel.dialectLbl.text=Dialect 21 | JSQLFormatterOptionsPanel.sbqAutoRdBtn.text=Auto 22 | JSQLFormatterOptionsPanel.sbqLbl.text=Squared Brackets Quotation: 23 | JSQLFormatterOptionsPanel.sbqYesRdBtn.text=Yes 24 | JSQLFormatterOptionsPanel.sbqNoRdBtn.text=No 25 | JSQLFormatterOptionsPanel.separationAfterRdBtn.text=After 26 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | 2 | SQLFormatterOptionsPanel.spellingLbl.text=Spelling 3 | SQLFormatterOptionsPanel.uppercaseChkBox.text=Convert into uppercase 4 | # Copyright (c) 2020 bahlef. 5 | # All rights reserved. This program and the accompanying materials 6 | # are made available under the terms of the Eclipse Public License v2.0 7 | # which accompanies this distribution, and is available at 8 | # http://www.eclipse.org/legal/epl-v20.html 9 | 10 | # Contributors: 11 | # bahlef - initial API and implementation and/or initial documentation 12 | SQLFormatterOptionsPanel.outputLbl.text=Output 13 | SQLFormatterOptionsPanel.linesBetweenQueriesLbl.text=Lines between queries: 14 | SQLFormatterOptionsPanel.maxColumnLengthLbl.text=Maximum column length: 15 | SQLFormatterOptionsPanel.positioningLbl.text=Positioning 16 | SQLFormatterOptionsPanel.indentWidthLbl.text=Indent Width: 17 | SQLFormatterOptionsPanel.expandTabsToSpacesChkBox.text=Expand tabs to spaces 18 | SQLFormatterOptionsPanel.dialectLbl.text=Dialect 19 | SQLFormatterOptionsPanel.dbDialectLbl.text=Database dialect: 20 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | # 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | 10 | ExternalFormatterPanel.use=Use 11 | ExternalFormatterPanel.btnVisitHomePage.text=Visit homepage/issue tracker... 12 | ExternalFormatterPanel.btnDonate.text=Support this plugin... 13 | ExternalFormatterPanel.cbShowNotifications.toolTipText=Show notifications of the used formatter configuration when formatting 14 | ExternalFormatterPanel.cbShowNotifications.text=Show notifications (about used formatter) 15 | ExternalFormatterPanel.txtProjectSpecificHint.text=Hint: You can override the configuration at project-level. 16 | ExternalFormatterPanel.useIndentationSettingsChkBox.text=Use indentation settings from external formatter 17 | ExternalFormatterPanel.useIndentationSettingsChkBox.toolTipText=If activated the number of spaces per indent, tab size and expand tabs to spaces in an editor window will be used from the configured external formatter configuration, if there is an external formatter activated for that mime type 18 | ExternalFormatterPanel.overrideTabSizeChkBox.text=Override Tab Size: 19 | ExternalFormatterPanel.overrideTabSizeChkBox.toolTipText=Activate to override the Tab Size of the external formatter configuration 20 | ExternalFormatterPanel.overrideTabSizeSpn.toolTipText=Custom Tab Size 21 | ExternalFormatterPanel.chooseLanguageLbl.text=Language: 22 | ExternalFormatterPanel.useFormatterLbl.text=Use Formatter: 23 | ExternalFormatterPanel.btnVisitHomePage.toolTipText=https://github.com/funfried/externalcodeformatter_for_netbeans/ 24 | ExternalFormatterPanel.btnDonate.toolTipText=Support the developer behind the plugin 25 | ExternalFormatterSupportDialog.title.text=Support this plugin... 26 | ExternalFormatterSupportDialog.paypalBtn.text=Donate via PayPal 27 | ExternalFormatterSupportDialog.patronBtn.text=Become a Patron 28 | ExternalFormatterSupportDialog.buyMeACoffeeBtn.text=Buy me a drink 29 | ExternalFormatterSupportDialog.sayThanksBtn.text=Say thanks 30 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/become_a_patron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/become_a_patron.png -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/buy_me_a_drink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/buy_me_a_drink.png -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/donate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/donate.gif -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/say_thanks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/main/resources/de/funfried/netbeans/plugins/external/formatter/ui/options/say_thanks.png -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/xml/jsoup/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | JsoupXmlFormatterOptionsPanel.linefeedCmbBox.toolTipText=Select the line feed character(s) to use for formatting 10 | JsoupXmlFormatterOptionsPanel.prettyPrintChkBox.text=Pretty print 11 | JsoupXmlFormatterOptionsPanel.linefeedLbl.text=Linefeed: 12 | JsoupXmlFormatterOptionsPanel.indentSizeLbl.text=Number of Spaces per Indent: 13 | JsoupXmlFormatterOptionsPanel.outlineChkBox.text=Outline 14 | JsoupXmlFormatterOptionsPanel.linefeedLbl.toolTipText=Select the line feed character(s) to use for formatting 15 | JsoupXmlFormatterOptionsPanel.prettyPrintChkBox.toolTipText=Select this checkbox to enable pretty print 16 | JsoupXmlFormatterOptionsPanel.outlineChkBox.toolTipText=Select this checkbox to enable outline 17 | JsoupXmlFormatterOptionsPanel.indentSizeLbl.toolTipText=Enter here the number of spaces per indent 18 | JsoupHtmlFormatterOptionsPanel.linefeedLbl.text=Linefeed: 19 | JsoupHtmlFormatterOptionsPanel.indentSizeLbl.toolTipText=Enter here the number of spaces per indent 20 | JsoupHtmlFormatterOptionsPanel.indentSizeLbl.text=Number of Spaces per Indent: 21 | JsoupHtmlFormatterOptionsPanel.outlineChkBox.toolTipText=Select this checkbox to enable outline 22 | JsoupHtmlFormatterOptionsPanel.outlineChkBox.text=Outline 23 | JsoupHtmlFormatterOptionsPanel.prettyPrintChkBox.toolTipText=Select this checkbox to enable pretty print 24 | JsoupHtmlFormatterOptionsPanel.prettyPrintChkBox.text=Pretty print 25 | JsoupHtmlFormatterOptionsPanel.linefeedLbl.toolTipText=Select the line feed character(s) to use for formatting 26 | -------------------------------------------------------------------------------- /src/main/resources/de/funfried/netbeans/plugins/external/formatter/xml/revelc/ui/Bundle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 bahlef. 2 | # All rights reserved. This program and the accompanying materials 3 | # are made available under the terms of the Eclipse Public License v2.0 4 | # which accompanies this distribution, and is available at 5 | # http://www.eclipse.org/legal/epl-v20.html 6 | 7 | # Contributors: 8 | # bahlef - initial API and implementation and/or initial documentation 9 | RevelcXmlFormatterOptionsPanel.linefeedLbl.text=Linefeed: 10 | RevelcXmlFormatterOptionsPanel.rightMarginLbl.text=Right margin: 11 | RevelcXmlFormatterOptionsPanel.wrapLongLinesChkBox.text=Wrap long lines 12 | RevelcXmlFormatterOptionsPanel.wellFormedValidationLbl.text=Well formed validation: 13 | RevelcXmlFormatterOptionsPanel.expandTabsToSpacesChkBox.text=Expand Tabs to Spaces 14 | RevelcXmlFormatterOptionsPanel.splitMultiAttrsChkBox.text=Split multi attributes 15 | RevelcXmlFormatterOptionsPanel.tabWidthLbl.text=Tab width: 16 | RevelcXmlFormatterOptionsPanel.rightMarginSpn.toolTipText= 17 | RevelcXmlFormatterOptionsPanel.linefeedCmbBox.toolTipText=Select the line feed character(s) to use for formatting 18 | RevelcXmlFormatterOptionsPanel.linefeedLbl.toolTipText= 19 | JacksonJsonFormatterOptionsPanel.linefeedLbl.toolTipText=Select the line feed character(s) to use for formatting 20 | RevelcXmlFormatterOptionsPanel.tabWidthLbl.toolTipText=Enter here the width in spaces per tab 21 | RevelcXmlFormatterOptionsPanel.rightMarginLbl.toolTipText=Enter here the maximum of characters per line 22 | RevelcXmlFormatterOptionsPanel.wellFormedValidationLbl.toolTipText=Select the validation level 23 | RevelcXmlFormatterOptionsPanel.expandTabsToSpacesChkBox.toolTipText=Select this checkbox to expand tabs to spaces 24 | RevelcXmlFormatterOptionsPanel.splitMultiAttrsChkBox.toolTipText=Select this checkbox to split multi attributes 25 | RevelcXmlFormatterOptionsPanel.wrapLongLinesChkBox.toolTipText=Select this checkbox to wrap long lines 26 | -------------------------------------------------------------------------------- /src/site/resources/imgs/global.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/global.png -------------------------------------------------------------------------------- /src/site/resources/imgs/logos/become_a_patron_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/logos/become_a_patron_button.png -------------------------------------------------------------------------------- /src/site/resources/imgs/logos/buy_me_a_drink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/logos/buy_me_a_drink.png -------------------------------------------------------------------------------- /src/site/resources/imgs/logos/externalcodeformatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/logos/externalcodeformatter.png -------------------------------------------------------------------------------- /src/site/resources/imgs/logos/netbeans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/logos/netbeans.png -------------------------------------------------------------------------------- /src/site/resources/imgs/logos/netbeans_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/logos/netbeans_small.png -------------------------------------------------------------------------------- /src/site/resources/imgs/logos/say_thanks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/logos/say_thanks.png -------------------------------------------------------------------------------- /src/site/resources/imgs/onsave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/onsave.png -------------------------------------------------------------------------------- /src/site/resources/imgs/project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/funfried/externalcodeformatter_for_netbeans/b2e102640df93d88fabc2d4397d2047486bf2028/src/site/resources/imgs/project.png -------------------------------------------------------------------------------- /src/site/xdoc/downloads.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Downloads 8 | Fabian Bahle 9 | 10 | 11 | 12 |
      13 |

      14 | Here is a list of mirrors where you can find the latest stable and development builds: 15 |

      16 | 17 | 28 | 29 | 30 | 38 | 39 | 40 | 54 | 55 |
      56 | 57 |
      58 | -------------------------------------------------------------------------------- /src/site/xdoc/known_issues.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Known issues 8 | Fabian Bahle 9 | 10 | 11 | 12 |
      13 |
        14 |
      • 15 | Updating the breakpoints after formatting acts not exactly the same way as for the internal 16 | NetBeans formatter, but it's pretty close. 17 |
      • 18 |
      • 19 | Guarded blocks are not supported for the Google Java Code Formatter. There seems to be a bug 20 | in the Google Java Code Formatter which prevents this feature to work. Further details on 21 | this bug can be watched here: 22 | https://github.com/google/google-java-format/issues/433 23 |
      • 24 |
      • 25 | It's not possible to sort the imports with the Eclipse Formatter as it needs some OSGi/Eclipse 26 | Equinox Runtime related classes to initialize the related objects. But you can configure 27 | NetBeans to do the sorting exactly as Eclipse does by default. Just go to "e;Preferences"e; 28 | -> "e;Editor"e; -> "e;Formatting"e; -> Choose "e;Java"e; as the 29 | "e;Language"e; and "e;Imports"e; as the "e;Category"e; and configure the 30 | following "e;Import Layout"e;: 31 |
          32 |
        1. java
        2. 33 |
        3. javax
        4. 34 |
        5. org
        6. 35 |
        7. com
        8. 36 |
        9. <all other imports>
        10. 37 |
        38 | and make a check "e;Separate Groups"e; 39 |
      • 40 |
      41 |
      42 | 43 |
      44 | -------------------------------------------------------------------------------- /src/site/xdoc/usage.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Usage 8 | Fabian Bahle 9 | 10 | 11 | 12 |
      13 |

      14 | Just open the preferences dialog in NetBeans after the installation and go to Options -> 15 | Editor -> External Formatter, select the programming language you want to change 16 | the formatter for and setup the formatter as you like. 17 |

      18 | Global options 19 |

      20 | You can also setup the formatters per programming language individually per project, just right 21 | click on the project and click on Properties, navigate to Project properties -> 22 | Formatting -> External Formatting. Make it a tick in Override global settings. 23 |

      24 | Project options 25 |

      26 | If you want to automatically format on saving your files, go to Options -> 27 | Editor -> On Save and either select All Languages or the programming 28 | language you want to enable the formatting when saving a file and choose either All Lines 29 | or Modified Lines Only. 30 |

      31 | On Save 32 |

      33 | If you select a specfic programming language in the Languages dropdown, make sure to untick 34 | the Use All Languages Settings for that programming language. 35 |

      36 |
      37 | 38 |
      39 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/css/cssparser/CssParserFormatterWrapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * markiewb - initial API and implementation and/or initial documentation 9 | * bahlef 10 | */ 11 | package de.funfried.netbeans.plugins.external.formatter.css.cssparser; 12 | 13 | import org.junit.Assert; 14 | import org.junit.BeforeClass; 15 | import org.junit.Test; 16 | 17 | /** 18 | * 19 | * @author markiewb 20 | * @author bahlef 21 | */ 22 | public class CssParserFormatterWrapperTest { 23 | private static CssParserFormatterWrapper instance; 24 | 25 | @BeforeClass 26 | public static void setUpClass() { 27 | instance = new CssParserFormatterWrapper(); 28 | } 29 | 30 | @Test 31 | public void testFormatUsingDefaults() { 32 | final String text = ".foo { width: 100%; height: 200px; color: rgb(255, 0, 255); background: url(\"../test.png\"); } span.bar { width: 20pt; height: 80%; display: flow; }\n"; 33 | final String expected = ".foo {\n" 34 | + " width: 100%;\n" 35 | + " height: 200px;\n" 36 | + " color: #ff00ff;\n" 37 | + " background: url(../test.png)\n" 38 | + "}\n" 39 | + "span.bar {\n" 40 | + " width: 20pt;\n" 41 | + " height: 80%;\n" 42 | + " display: flow\n" 43 | + "}"; 44 | 45 | String actual = instance.format(text, CssParserFormatterSettings.INDENT_DEFAULT, CssParserFormatterSettings.RGB_AS_HEX_DEFAULT, CssParserFormatterSettings.USE_SINGLE_QUOTES_DEFAULT, 46 | CssParserFormatterSettings.USE_SOURCE_STRING_VALUES_DEFAULT); 47 | 48 | Assert.assertNotNull("Formatting should not return null value", actual); 49 | Assert.assertEquals("Formatting should change the code", expected, actual.replaceAll("\r", "")); 50 | } 51 | 52 | @Test 53 | public void testFormatUsingNoRgbAsHex() { 54 | final String text = ".foo { width: 100%; height: 200px; color: rgb(255, 0, 255); background: url(\"../test.png\"); } span.bar { width: 20pt; height: 80%; display: flow; }\n"; 55 | final String expected = ".foo {\n" 56 | + " width: 100%;\n" 57 | + " height: 200px;\n" 58 | + " color: rgb(255, 0, 255);\n" 59 | + " background: url(../test.png)\n" 60 | + "}\n" 61 | + "span.bar {\n" 62 | + " width: 20pt;\n" 63 | + " height: 80%;\n" 64 | + " display: flow\n" 65 | + "}"; 66 | 67 | String actual = instance.format(text, CssParserFormatterSettings.INDENT_DEFAULT, false, CssParserFormatterSettings.USE_SINGLE_QUOTES_DEFAULT, 68 | CssParserFormatterSettings.USE_SOURCE_STRING_VALUES_DEFAULT); 69 | 70 | Assert.assertNotNull("Formatting should not return null value", actual); 71 | Assert.assertEquals("Formatting should change the code", expected, actual.replaceAll("\r", "")); 72 | } 73 | 74 | @Test 75 | public void testFormatUsingSingleQuotes() { 76 | final String text = ".foo { width: 100%; height: 200px; color: rgb(255, 0, 255); background: url(\"../test.png\"); } span.bar { width: 20pt; height: 80%; display: flow; }\n"; 77 | final String expected = ".foo {\n" 78 | + " width: 100%;\n" 79 | + " height: 200px;\n" 80 | + " color: #ff00ff;\n" 81 | + " background: url(../test.png)\n" 82 | + "}\n" 83 | + "span.bar {\n" 84 | + " width: 20pt;\n" 85 | + " height: 80%;\n" 86 | + " display: flow\n" 87 | + "}"; 88 | 89 | String actual = instance.format(text, CssParserFormatterSettings.INDENT_DEFAULT, CssParserFormatterSettings.RGB_AS_HEX_DEFAULT, true, CssParserFormatterSettings.USE_SOURCE_STRING_VALUES_DEFAULT); 90 | 91 | Assert.assertNotNull("Formatting should not return null value", actual); 92 | Assert.assertEquals("Formatting should change the code", expected, actual.replaceAll("\r", "")); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/css/cssparser/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for CssParser CSS formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.css.cssparser; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/eclipse/xml/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Eclipse formatter XML configuration parsing. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.eclipse.xml; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/html/jsoup/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Jsoup HTML formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.html.jsoup; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/java/eclipse/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Eclipse Java formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.eclipse; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/java/google/FormatterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.google; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Ignore; 17 | import org.junit.Test; 18 | 19 | import com.google.common.collect.Range; 20 | import com.google.googlejavaformat.java.Formatter; 21 | import com.google.googlejavaformat.java.JavaFormatterOptions; 22 | 23 | /** 24 | * 25 | * @author bahlef 26 | */ 27 | public class FormatterTest { 28 | public FormatterTest() { 29 | } 30 | 31 | @Test 32 | @Ignore 33 | public void testCharaterRangesFormatWithAnnotation() throws Exception { 34 | final String text = "package foo; public class Bar {\n" + 35 | " @SuppressWarnings(\"unchecked\")\n" + 36 | " // some comment \n" + 37 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); } public boolean doSomethingElse(Object obj) { return false; } }"; 38 | final String expected = "package foo;\n" + 39 | "\n" + 40 | "public class Bar {\n" + 41 | // START -- this should not be formatted 42 | " @SuppressWarnings(\"unchecked\")\n" + 43 | " // some comment \n" + 44 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); }\n" + 45 | // END -- this should not be formatted 46 | "\n" + 47 | " public boolean doSomethingElse(Object obj) {\n" + 48 | " return false;\n" + 49 | " }\n" + 50 | "}\n" + 51 | ""; 52 | 53 | Collection> characterRanges = new ArrayList<>(); 54 | characterRanges.add(Range.open(0, 66)); 55 | characterRanges.add(Range.open(171, 234)); 56 | 57 | Formatter formatter = new Formatter(JavaFormatterOptions.builder().style(JavaFormatterOptions.Style.GOOGLE).build()); 58 | 59 | String actual = formatter.formatSource(text, characterRanges); 60 | Assert.assertEquals("Formatting should change the code", expected, actual); 61 | } 62 | 63 | @Test 64 | public void testCharaterRangesFormatWithoutAnnotation() throws Exception { 65 | final String text = "package foo; public class Bar {\n" + 66 | " @SuppressWarnings(\"unchecked\")\n" + 67 | " // some comment \n" + 68 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); } public boolean doSomethingElse(Object obj) { return false; } }"; 69 | final String expected = "package foo;\n" + 70 | "\n" + 71 | "public class Bar {\n" + 72 | " @SuppressWarnings(\"unchecked\")\n" + 73 | // START -- this should not be formatted 74 | " // some comment \n" + 75 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); }\n" + 76 | // END -- this should not be formatted 77 | "\n" + 78 | " public boolean doSomethingElse(Object obj) {\n" + 79 | " return false;\n" + 80 | " }\n" + 81 | "}\n" + 82 | ""; 83 | 84 | Collection> characterRanges = new ArrayList<>(); 85 | characterRanges.add(Range.open(0, 31)); 86 | characterRanges.add(Range.open(171, 234)); 87 | 88 | Formatter formatter = new Formatter(JavaFormatterOptions.builder().style(JavaFormatterOptions.Style.GOOGLE).build()); 89 | 90 | String actual = formatter.formatSource(text, characterRanges); 91 | Assert.assertEquals("Formatting should change the code", expected, actual); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/java/google/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Google Java formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.google; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/java/palantir/FormatterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.java.palantir; 11 | 12 | import java.util.ArrayList; 13 | import java.util.Collection; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Ignore; 17 | import org.junit.Test; 18 | 19 | import com.google.common.collect.Range; 20 | import com.palantir.javaformat.java.Formatter; 21 | import com.palantir.javaformat.java.JavaFormatterOptions; 22 | 23 | /** 24 | * 25 | * @author bahlef 26 | */ 27 | public class FormatterTest { 28 | public FormatterTest() { 29 | } 30 | 31 | @Test 32 | @Ignore 33 | public void testCharaterRangesFormatWithAnnotation() throws Exception { 34 | final String text = "package foo; public class Bar {\n" + 35 | " @SuppressWarnings(\"unchecked\")\n" + 36 | " // some comment \n" + 37 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); } public boolean doSomethingElse(Object obj) { return false; } }"; 38 | final String expected = "package foo;\n" + 39 | "\n" + 40 | "public class Bar {\n" + 41 | // START -- this should not be formatted 42 | " @SuppressWarnings(\"unchecked\")\n" + 43 | " // some comment \n" + 44 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); }\n" + 45 | // END -- this should not be formatted 46 | "\n" + 47 | " public boolean doSomethingElse(Object obj) {\n" + 48 | " return false;\n" + 49 | " }\n" + 50 | "}\n" + 51 | ""; 52 | 53 | Collection> characterRanges = new ArrayList<>(); 54 | characterRanges.add(Range.open(0, 66)); 55 | characterRanges.add(Range.open(171, 234)); 56 | 57 | Formatter formatter = Formatter.createFormatter(JavaFormatterOptions.builder().style(JavaFormatterOptions.Style.PALANTIR).build()); 58 | 59 | String actual = formatter.formatSource(text, characterRanges); 60 | Assert.assertEquals("Formatting should change the code", expected, actual); 61 | } 62 | 63 | @Test 64 | public void testCharaterRangesFormatWithoutAnnotation() throws Exception { 65 | final String text = "package foo; public class Bar {\n" + 66 | " @SuppressWarnings(\"unchecked\")\n" + 67 | " // some comment \n" + 68 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); } public boolean doSomethingElse(Object obj) { return false; } }"; 69 | final String expected = "package foo;\n" + 70 | "\n" + 71 | "public class Bar {\n" + 72 | " @SuppressWarnings(\"unchecked\")\n" + 73 | // START -- this should not be formatted 74 | " // some comment \n" + 75 | " public void doSomething(String arg) { System.out.println(\"Hello World\"); }\n" + 76 | // END -- this should not be formatted 77 | "\n" + 78 | " public boolean doSomethingElse(Object obj) {\n" + 79 | " return false;\n" + 80 | " }\n" + 81 | "}\n" + 82 | ""; 83 | 84 | Collection> characterRanges = new ArrayList<>(); 85 | characterRanges.add(Range.open(0, 31)); 86 | characterRanges.add(Range.open(171, 234)); 87 | 88 | Formatter formatter = Formatter.createFormatter(JavaFormatterOptions.builder().style(JavaFormatterOptions.Style.PALANTIR).build()); 89 | 90 | String actual = formatter.formatSource(text, characterRanges); 91 | Assert.assertEquals("Formatting should change the code", expected, actual); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/java/palantir/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Palantir Java formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.palantir; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/java/spring/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Spring Java formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.java.spring; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/javascript/eclipse/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Eclipse Javascript formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.javascript.eclipse; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/json/jackson/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Jackson Json formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.json.jackson; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for common formatter logic. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/DBeaverFormatterWrapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver; 11 | 12 | import java.util.Properties; 13 | 14 | import org.junit.Assert; 15 | import org.junit.BeforeClass; 16 | import org.junit.Test; 17 | 18 | /** 19 | * 20 | * @author bahlef 21 | */ 22 | public class DBeaverFormatterWrapperTest { 23 | private static DBeaverFormatterWrapper instance; 24 | 25 | @BeforeClass 26 | public static void setUpClass() { 27 | instance = new DBeaverFormatterWrapper(); 28 | } 29 | 30 | @Test 31 | public void testFormat() { 32 | final String text = "SELECT FOO FROM BAR WHERE FOO = 'BAR' ORDER BY FOO LIMIT 1"; 33 | final String expected = "SELECT\n" + 34 | " FOO\n" + 35 | "FROM\n" + 36 | " BAR\n" + 37 | "WHERE\n" + 38 | " FOO = 'BAR'\n" + 39 | "ORDER BY\n" + 40 | " FOO LIMIT 1"; 41 | 42 | Properties props = new Properties(); 43 | props.put(DBeaverFormatterSettings.INDENT_SIZE, DBeaverFormatterSettings.INDENT_SIZE_DEFAULT); 44 | props.put(DBeaverFormatterSettings.INDENT_TYPE, DBeaverFormatterSettings.INDENT_TYPE_DEFAULT); 45 | props.put(DBeaverFormatterSettings.KEYWORD_CASE, DBeaverFormatterSettings.KEYWORD_CASE_DEFAULT); 46 | props.put(DBeaverFormatterSettings.STATEMENT_DELIMITER, DBeaverFormatterSettings.STATEMENT_DELIMITER_DEFAULT); 47 | 48 | String actual = instance.format(text, props); 49 | Assert.assertNotNull("Formatting should not return null value", actual); 50 | Assert.assertEquals("Formatting should change the code", expected, actual.replaceAll("\r", "")); 51 | } 52 | 53 | @Test 54 | public void testNullCode() { 55 | Properties props = new Properties(); 56 | props.put(DBeaverFormatterSettings.INDENT_SIZE, DBeaverFormatterSettings.INDENT_SIZE_DEFAULT); 57 | props.put(DBeaverFormatterSettings.INDENT_TYPE, DBeaverFormatterSettings.INDENT_TYPE_DEFAULT); 58 | props.put(DBeaverFormatterSettings.KEYWORD_CASE, DBeaverFormatterSettings.KEYWORD_CASE_DEFAULT); 59 | props.put(DBeaverFormatterSettings.STATEMENT_DELIMITER, DBeaverFormatterSettings.STATEMENT_DELIMITER_DEFAULT); 60 | 61 | String actual = instance.format(null, props); 62 | Assert.assertNull("Formatting shouldn't change the code, should still be null", actual); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/sql/dbeaver/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for DBeaver SQL formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/sql/jsqlformatter/JSQLFormatterWrapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.jsqlformatter; 11 | 12 | import org.junit.Assert; 13 | import org.junit.BeforeClass; 14 | import org.junit.Test; 15 | 16 | /** 17 | * 18 | * @author bahlef 19 | */ 20 | public class JSQLFormatterWrapperTest { 21 | private static JSQLFormatterWrapper instance; 22 | 23 | @BeforeClass 24 | public static void setUpClass() { 25 | instance = new JSQLFormatterWrapper(); 26 | } 27 | 28 | @Test 29 | public void testFormat() { 30 | final String text = "SELECT FOO FROM BAR WHERE FOO = 'BAR' ORDER BY FOO LIMIT 1"; 31 | final String expected = "SELECT foo\n" + 32 | "FROM bar\n" + 33 | "WHERE foo = 'BAR'\n" + 34 | "ORDER BY foo\n" + 35 | "LIMIT 1\n" + 36 | ";"; 37 | 38 | String actual = instance.format(text); 39 | Assert.assertNotNull("Formatting should not return null value", actual); 40 | Assert.assertEquals("Formatting should change the code", expected, actual.replaceAll("\r", "")); 41 | } 42 | 43 | @Test 44 | public void testNullCode() { 45 | String actual = instance.format(null); 46 | Assert.assertNull("Formatting shouldn't change the code, should still be null", actual); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/sql/jsqlformatter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for manticore JSQL formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.jsqlformatter; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/SQLFormatterWrapperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | package de.funfried.netbeans.plugins.external.formatter.sql.sqlformatter; 11 | 12 | import org.junit.Assert; 13 | import org.junit.BeforeClass; 14 | import org.junit.Test; 15 | 16 | import com.github.vertical_blank.sqlformatter.core.FormatConfig; 17 | import com.github.vertical_blank.sqlformatter.languages.Dialect; 18 | 19 | /** 20 | * 21 | * @author bahlef 22 | */ 23 | public class SQLFormatterWrapperTest { 24 | private static SQLFormatterWrapper instance; 25 | 26 | @BeforeClass 27 | public static void setUpClass() { 28 | instance = new SQLFormatterWrapper(); 29 | } 30 | 31 | @Test 32 | public void testFormat() { 33 | final String text = "SELECT FOO FROM BAR WHERE FOO = 'BAR' ORDER BY FOO LIMIT 1"; 34 | final String expected = "SELECT\n" + 35 | " FOO\n" + 36 | "FROM\n" + 37 | " BAR\n" + 38 | "WHERE\n" + 39 | " FOO = 'BAR'\n" + 40 | "ORDER BY\n" + 41 | " FOO\n" + 42 | "LIMIT\n" + 43 | " 1"; 44 | 45 | FormatConfig formatConfig = FormatConfig.builder().indent(" ").maxColumnLength(120).uppercase(true).build(); 46 | String actual = instance.format(text, Dialect.PostgreSql, formatConfig); 47 | Assert.assertNotNull("Formatting should not return null value", actual); 48 | Assert.assertEquals("Formatting should change the code", expected, actual.replaceAll("\r", "")); 49 | } 50 | 51 | @Test 52 | public void testNullCode() { 53 | FormatConfig formatConfig = FormatConfig.builder().indent(" ").maxColumnLength(120).uppercase(true).build(); 54 | String actual = instance.format(null, Dialect.PostgreSql, formatConfig); 55 | Assert.assertNull("Formatting shouldn't change the code, should still be null", actual); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/sql/sqlformatter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Vertical Blank SQL formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.sql.sqlformatter; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/xml/jsoup/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for Jsoup XML formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.xml.jsoup; 15 | -------------------------------------------------------------------------------- /src/test/java/de/funfried/netbeans/plugins/external/formatter/xml/revelc/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 bahlef. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v2.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v20.html 7 | * Contributors: 8 | * bahlef - initial API and implementation and/or initial documentation 9 | */ 10 | 11 | /** 12 | * Test package containing test classes for revelc.net XML formatter. 13 | */ 14 | package de.funfried.netbeans.plugins.external.formatter.xml.revelc; 15 | -------------------------------------------------------------------------------- /src/test/resources/3rdPartyFormatter_org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | org.eclipse.jdt.core.formatter.alignment_for_enum_constants=70 2 | org.eclipse.jdt.core.javaFormatter=unknownXXX -------------------------------------------------------------------------------- /src/test/resources/defaultformatter_org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | org.eclipse.jdt.core.formatter.alignment_for_enum_constants=70 2 | org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter 3 | -------------------------------------------------------------------------------- /src/test/resources/defectformattersampleeclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/test/resources/defectjsformattersampleeclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/test/resources/formatteronoffsampleeclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/test/resources/formattersampleeclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/test/resources/jsformattersampleeclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/test/resources/jsmechanic-formatter.epf: -------------------------------------------------------------------------------- 1 | # @title Formatter 2 | # @description Formatter DEsc 3 | # @task_type LASTMOD 4 | # 5 | # Created by the Workspace Mechanic Preference Recorder 6 | #Tue Jan 05 21:49:39 CET 2016 7 | /instance/org.eclipse.wst.jsdt.core/org.eclipse.wst.jsdt.core.formatter.alignment_for_enum_constants=70 8 | -------------------------------------------------------------------------------- /src/test/resources/mechanic-formatter.epf: -------------------------------------------------------------------------------- 1 | # @title Formatter 2 | # @description Formatter DEsc 3 | # @task_type LASTMOD 4 | # 5 | # Created by the Workspace Mechanic Preference Recorder 6 | #Tue Jan 05 21:49:39 CET 2016 7 | /instance/org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.alignment_for_enum_constants=70 8 | -------------------------------------------------------------------------------- /src/test/resources/noprofilesampleeclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/test/resources/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | org.eclipse.jdt.core.formatter.alignment_for_enum_constants=70 2 | -------------------------------------------------------------------------------- /src/test/resources/org.eclipse.wst.jsdt.core.prefs: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.core.formatter.alignment_for_enum_constants=70 2 | -------------------------------------------------------------------------------- /src/test/resources/wrongprofilekindsampleeclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | --------------------------------------------------------------------------------